home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / darwin / darwinx86.iso / usr / include / pexpert / ppc / dbdma.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-09-30  |  4.9 KB  |  177 lines

  1. /*
  2.  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
  3.  *
  4.  * @APPLE_LICENSE_HEADER_START@
  5.  * 
  6.  * The contents of this file constitute Original Code as defined in and
  7.  * are subject to the Apple Public Source License Version 1.1 (the
  8.  * "License").  You may not use this file except in compliance with the
  9.  * License.  Please obtain a copy of the License at
  10.  * http://www.apple.com/publicsource and read it before using this file.
  11.  * 
  12.  * This Original Code and all software distributed under the License are
  13.  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  14.  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  15.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  16.  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
  17.  * License for the specific language governing rights and limitations
  18.  * under the License.
  19.  * 
  20.  * @APPLE_LICENSE_HEADER_END@
  21.  */
  22. /*
  23.  * @OSF_COPYRIGHT@
  24.  */
  25.  
  26. #ifndef _PEXPERT_PPC_DBDMA_H_
  27. #define _PEXPERT_PPC_DBDMA_H_
  28.  
  29. #ifndef ASSEMBLER
  30.  
  31. #define    DBDMA_CMD_OUT_MORE    0
  32. #define    DBDMA_CMD_OUT_LAST    1
  33. #define    DBDMA_CMD_IN_MORE    2
  34. #define    DBDMA_CMD_IN_LAST    3
  35. #define    DBDMA_CMD_STORE_QUAD    4
  36. #define    DBDMA_CMD_LOAD_QUAD    5
  37. #define    DBDMA_CMD_NOP        6
  38. #define    DBDMA_CMD_STOP        7
  39.  
  40. /* Keys */
  41.  
  42. #define    DBDMA_KEY_STREAM0    0
  43. #define    DBDMA_KEY_STREAM1    1
  44. #define    DBDMA_KEY_STREAM2    2
  45. #define    DBDMA_KEY_STREAM3    3
  46.  
  47. /* value 4 is reserved */
  48. #define    DBDMA_KEY_REGS        5
  49. #define    DBDMA_KEY_SYSTEM    6
  50. #define    DBDMA_KEY_DEVICE    7
  51.  
  52. #define    DBDMA_INT_NEVER        0
  53. #define    DBDMA_INT_IF_TRUE    1
  54. #define    DBDMA_INT_IF_FALSE    2
  55. #define    DBDMA_INT_ALWAYS    3
  56.  
  57. #define    DBDMA_BRANCH_NEVER    0
  58. #define    DBDMA_BRANCH_IF_TRUE    1
  59. #define    DBDMA_BRANCH_IF_FALSE    2
  60. #define    DBDMA_BRANCH_ALWAYS    3
  61.  
  62. #define    DBDMA_WAIT_NEVER    0
  63. #define    DBDMA_WAIT_IF_TRUE    1
  64. #define DBDMA_WAIT_IF_FALSE    2
  65. #define    DBDMA_WAIT_ALWAYS    3
  66.  
  67. /* Control register values (in little endian) */
  68.  
  69. #define    DBDMA_STATUS_MASK    0x000000ff    /* Status Mask */
  70. #define    DBDMA_CNTRL_BRANCH    0x00000100
  71.                 /* 0x200 reserved */
  72. #define    DBDMA_CNTRL_ACTIVE    0x00000400
  73. #define    DBDMA_CNTRL_DEAD    0x00000800
  74. #define    DBDMA_CNTRL_WAKE    0x00001000
  75. #define    DBDMA_CNTRL_FLUSH    0x00002000
  76. #define    DBDMA_CNTRL_PAUSE    0x00004000
  77. #define    DBDMA_CNTRL_RUN        0x00008000
  78.  
  79. #define    DBDMA_SET_CNTRL(x)    ( ((x) | (x) << 16) )
  80. #define    DBDMA_CLEAR_CNTRL(x)    ( (x) << 16)
  81.  
  82. #define POWERMAC_IO(a) (a)
  83. #define    DBDMA_REGMAP(channel) \
  84.         (dbdma_regmap_t *)((v_u_char *) POWERMAC_IO(PCI_DMA_BASE_PHYS) \
  85.                 + (channel << 8))
  86.  
  87.  
  88. /* powermac_dbdma_channels hold the physical channel numbers for
  89.  * each dbdma device
  90.  */
  91.  
  92.  
  93. /* This struct is layout in little endian format */
  94.  
  95. struct dbdma_command {
  96.     unsigned long    d_cmd_count;
  97.     unsigned long    d_address;
  98.     unsigned long    d_cmddep;
  99.     unsigned long    d_status_resid;
  100. };
  101.  
  102. typedef struct dbdma_command dbdma_command_t;
  103.  
  104. #define    DBDMA_BUILD(d, cmd, key, count, address, interrupt, wait, branch) {\
  105.         DBDMA_ST4_ENDIAN(&d->d_address, address); \
  106.         (d)->d_status_resid = 0; \
  107.         (d)->d_cmddep = 0; \
  108.         DBDMA_ST4_ENDIAN(&d->d_cmd_count, \
  109.                 ((cmd) << 28) | ((key) << 24) |\
  110.                 ((interrupt) << 20) |\
  111.                 ((branch) << 18) | ((wait) << 16) | \
  112.                 (count)); \
  113.     }
  114.  
  115. static __inline__ void
  116. dbdma_st4_endian(volatile unsigned long *a, unsigned long x)
  117. {
  118.     __asm__ volatile
  119.         ("stwbrx %0,0,%1" : : "r" (x), "r" (a) : "memory");
  120.  
  121.     return;
  122. }
  123.  
  124. static __inline__ unsigned long
  125. dbdma_ld4_endian(volatile unsigned long *a)
  126. {
  127.     unsigned long swap;
  128.  
  129.     __asm__ volatile
  130.         ("lwbrx %0,0,%1" :  "=r" (swap) : "r" (a));
  131.  
  132.     return    swap;
  133. }
  134.  
  135. #define    DBDMA_LD4_ENDIAN(a)     dbdma_ld4_endian(a)
  136. #define    DBDMA_ST4_ENDIAN(a, x)     dbdma_st4_endian(a, x)
  137.  
  138. /*
  139.  * DBDMA Channel layout
  140.  *
  141.  * NOTE - This structure is in little-endian format. 
  142.  */
  143.  
  144. struct dbdma_regmap {
  145.     unsigned long    d_control;    /* Control Register */
  146.     unsigned long    d_status;    /* DBDMA Status Register */
  147.     unsigned long    d_cmdptrhi;    /* MSB of command pointer (not used yet) */
  148.     unsigned long    d_cmdptrlo;    /* LSB of command pointer */
  149.     unsigned long    d_intselect;    /* Interrupt Select */
  150.     unsigned long    d_branch;    /* Branch selection */
  151.     unsigned long    d_wait;        /* Wait selection */
  152.     unsigned long    d_transmode;    /* Transfer modes */
  153.     unsigned long    d_dataptrhi;    /* MSB of Data Pointer */
  154.     unsigned long    d_dataptrlo;    /* LSB of Data Pointer */
  155.     unsigned long    d_reserved;    /* Reserved for the moment */
  156.     unsigned long    d_branchptrhi;    /* MSB of Branch Pointer */
  157.     unsigned long    d_branchptrlo;    /* LSB of Branch Pointer */
  158.     /* The remaining fields are undefinied and unimplemented */
  159. };
  160.  
  161. typedef volatile struct dbdma_regmap dbdma_regmap_t;
  162.  
  163. /* DBDMA routines */
  164.  
  165. void    dbdma_start(dbdma_regmap_t *channel, dbdma_command_t *commands);
  166. void    dbdma_stop(dbdma_regmap_t *channel);    
  167. void    dbdma_flush(dbdma_regmap_t *channel);
  168. void    dbdma_reset(dbdma_regmap_t *channel);
  169. void    dbdma_continue(dbdma_regmap_t *channel);
  170. void    dbdma_pause(dbdma_regmap_t *channel);
  171.  
  172. dbdma_command_t    *dbdma_alloc(int);    /* Allocate command structures */
  173.  
  174. #endif /* ASSEMBLER */
  175.  
  176. #endif /* _PEXPERT_PPC_DBDMA_H_ */
  177.