au1xxx_dbdma.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. /*
  2. *
  3. * BRIEF MODULE DESCRIPTION
  4. * Include file for Alchemy Semiconductor's Au1550 Descriptor
  5. * Based DMA Controller.
  6. *
  7. * Copyright 2004 Embedded Edge, LLC
  8. * dan@embeddededge.com
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the License, or (at your
  13. * option) any later version.
  14. *
  15. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  16. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  17. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  18. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  19. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  20. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  21. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  22. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  24. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. *
  26. * You should have received a copy of the GNU General Public License along
  27. * with this program; if not, write to the Free Software Foundation, Inc.,
  28. * 675 Mass Ave, Cambridge, MA 02139, USA.
  29. */
  30. /*
  31. * Specifics for the Au1xxx Descriptor-Based DMA Controller,
  32. * first seen in the AU1550 part.
  33. */
  34. #ifndef _AU1000_DBDMA_H_
  35. #define _AU1000_DBDMA_H_
  36. #ifndef _LANGUAGE_ASSEMBLY
  37. typedef volatile struct dbdma_global {
  38. u32 ddma_config;
  39. u32 ddma_intstat;
  40. u32 ddma_throttle;
  41. u32 ddma_inten;
  42. } dbdma_global_t;
  43. /* General Configuration. */
  44. #define DDMA_CONFIG_AF (1 << 2)
  45. #define DDMA_CONFIG_AH (1 << 1)
  46. #define DDMA_CONFIG_AL (1 << 0)
  47. #define DDMA_THROTTLE_EN (1 << 31)
  48. /* The structure of a DMA Channel. */
  49. typedef volatile struct au1xxx_dma_channel {
  50. u32 ddma_cfg; /* See below */
  51. u32 ddma_desptr; /* 32-byte aligned pointer to descriptor */
  52. u32 ddma_statptr; /* word aligned pointer to status word */
  53. u32 ddma_dbell; /* A write activates channel operation */
  54. u32 ddma_irq; /* If bit 0 set, interrupt pending */
  55. u32 ddma_stat; /* See below */
  56. u32 ddma_bytecnt; /* Byte count, valid only when chan idle */
  57. /* Remainder, up to the 256 byte boundary, is reserved. */
  58. } au1x_dma_chan_t;
  59. #define DDMA_CFG_SED (1 << 9) /* source DMA level/edge detect */
  60. #define DDMA_CFG_SP (1 << 8) /* source DMA polarity */
  61. #define DDMA_CFG_DED (1 << 7) /* destination DMA level/edge detect */
  62. #define DDMA_CFG_DP (1 << 6) /* destination DMA polarity */
  63. #define DDMA_CFG_SYNC (1 << 5) /* Sync static bus controller */
  64. #define DDMA_CFG_PPR (1 << 4) /* PCI posted read/write control */
  65. #define DDMA_CFG_DFN (1 << 3) /* Descriptor fetch non-coherent */
  66. #define DDMA_CFG_SBE (1 << 2) /* Source big endian */
  67. #define DDMA_CFG_DBE (1 << 1) /* Destination big endian */
  68. #define DDMA_CFG_EN (1 << 0) /* Channel enable */
  69. /*
  70. * Always set when descriptor processing done, regardless of
  71. * interrupt enable state. Reflected in global intstat, don't
  72. * clear this until global intstat is read/used.
  73. */
  74. #define DDMA_IRQ_IN (1 << 0)
  75. #define DDMA_STAT_DB (1 << 2) /* Doorbell pushed */
  76. #define DDMA_STAT_V (1 << 1) /* Descriptor valid */
  77. #define DDMA_STAT_H (1 << 0) /* Channel Halted */
  78. /*
  79. * "Standard" DDMA Descriptor.
  80. * Must be 32-byte aligned.
  81. */
  82. typedef volatile struct au1xxx_ddma_desc {
  83. u32 dscr_cmd0; /* See below */
  84. u32 dscr_cmd1; /* See below */
  85. u32 dscr_source0; /* source phys address */
  86. u32 dscr_source1; /* See below */
  87. u32 dscr_dest0; /* Destination address */
  88. u32 dscr_dest1; /* See below */
  89. u32 dscr_stat; /* completion status */
  90. u32 dscr_nxtptr; /* Next descriptor pointer (mostly) */
  91. /*
  92. * First 32 bytes are HW specific!!!
  93. * Let's have some SW data following -- make sure it's 32 bytes.
  94. */
  95. u32 sw_status;
  96. u32 sw_context;
  97. u32 sw_reserved[6];
  98. } au1x_ddma_desc_t;
  99. #define DSCR_CMD0_V (1 << 31) /* Descriptor valid */
  100. #define DSCR_CMD0_MEM (1 << 30) /* mem-mem transfer */
  101. #define DSCR_CMD0_SID_MASK (0x1f << 25) /* Source ID */
  102. #define DSCR_CMD0_DID_MASK (0x1f << 20) /* Destination ID */
  103. #define DSCR_CMD0_SW_MASK (0x3 << 18) /* Source Width */
  104. #define DSCR_CMD0_DW_MASK (0x3 << 16) /* Destination Width */
  105. #define DSCR_CMD0_ARB (0x1 << 15) /* Set for Hi Pri */
  106. #define DSCR_CMD0_DT_MASK (0x3 << 13) /* Descriptor Type */
  107. #define DSCR_CMD0_SN (0x1 << 12) /* Source non-coherent */
  108. #define DSCR_CMD0_DN (0x1 << 11) /* Destination non-coherent */
  109. #define DSCR_CMD0_SM (0x1 << 10) /* Stride mode */
  110. #define DSCR_CMD0_IE (0x1 << 8) /* Interrupt Enable */
  111. #define DSCR_CMD0_SP (0x1 << 4) /* Status pointer select */
  112. #define DSCR_CMD0_CV (0x1 << 2) /* Clear Valid when done */
  113. #define DSCR_CMD0_ST_MASK (0x3 << 0) /* Status instruction */
  114. #define SW_STATUS_INUSE (1 << 0)
  115. /* Command 0 device IDs. */
  116. #define AU1550_DSCR_CMD0_UART0_TX 0
  117. #define AU1550_DSCR_CMD0_UART0_RX 1
  118. #define AU1550_DSCR_CMD0_UART3_TX 2
  119. #define AU1550_DSCR_CMD0_UART3_RX 3
  120. #define AU1550_DSCR_CMD0_DMA_REQ0 4
  121. #define AU1550_DSCR_CMD0_DMA_REQ1 5
  122. #define AU1550_DSCR_CMD0_DMA_REQ2 6
  123. #define AU1550_DSCR_CMD0_DMA_REQ3 7
  124. #define AU1550_DSCR_CMD0_USBDEV_RX0 8
  125. #define AU1550_DSCR_CMD0_USBDEV_TX0 9
  126. #define AU1550_DSCR_CMD0_USBDEV_TX1 10
  127. #define AU1550_DSCR_CMD0_USBDEV_TX2 11
  128. #define AU1550_DSCR_CMD0_USBDEV_RX3 12
  129. #define AU1550_DSCR_CMD0_USBDEV_RX4 13
  130. #define AU1550_DSCR_CMD0_PSC0_TX 14
  131. #define AU1550_DSCR_CMD0_PSC0_RX 15
  132. #define AU1550_DSCR_CMD0_PSC1_TX 16
  133. #define AU1550_DSCR_CMD0_PSC1_RX 17
  134. #define AU1550_DSCR_CMD0_PSC2_TX 18
  135. #define AU1550_DSCR_CMD0_PSC2_RX 19
  136. #define AU1550_DSCR_CMD0_PSC3_TX 20
  137. #define AU1550_DSCR_CMD0_PSC3_RX 21
  138. #define AU1550_DSCR_CMD0_PCI_WRITE 22
  139. #define AU1550_DSCR_CMD0_NAND_FLASH 23
  140. #define AU1550_DSCR_CMD0_MAC0_RX 24
  141. #define AU1550_DSCR_CMD0_MAC0_TX 25
  142. #define AU1550_DSCR_CMD0_MAC1_RX 26
  143. #define AU1550_DSCR_CMD0_MAC1_TX 27
  144. #define AU1200_DSCR_CMD0_UART0_TX 0
  145. #define AU1200_DSCR_CMD0_UART0_RX 1
  146. #define AU1200_DSCR_CMD0_UART1_TX 2
  147. #define AU1200_DSCR_CMD0_UART1_RX 3
  148. #define AU1200_DSCR_CMD0_DMA_REQ0 4
  149. #define AU1200_DSCR_CMD0_DMA_REQ1 5
  150. #define AU1200_DSCR_CMD0_MAE_BE 6
  151. #define AU1200_DSCR_CMD0_MAE_FE 7
  152. #define AU1200_DSCR_CMD0_SDMS_TX0 8
  153. #define AU1200_DSCR_CMD0_SDMS_RX0 9
  154. #define AU1200_DSCR_CMD0_SDMS_TX1 10
  155. #define AU1200_DSCR_CMD0_SDMS_RX1 11
  156. #define AU1200_DSCR_CMD0_AES_TX 13
  157. #define AU1200_DSCR_CMD0_AES_RX 12
  158. #define AU1200_DSCR_CMD0_PSC0_TX 14
  159. #define AU1200_DSCR_CMD0_PSC0_RX 15
  160. #define AU1200_DSCR_CMD0_PSC1_TX 16
  161. #define AU1200_DSCR_CMD0_PSC1_RX 17
  162. #define AU1200_DSCR_CMD0_CIM_RXA 18
  163. #define AU1200_DSCR_CMD0_CIM_RXB 19
  164. #define AU1200_DSCR_CMD0_CIM_RXC 20
  165. #define AU1200_DSCR_CMD0_MAE_BOTH 21
  166. #define AU1200_DSCR_CMD0_LCD 22
  167. #define AU1200_DSCR_CMD0_NAND_FLASH 23
  168. #define AU1200_DSCR_CMD0_PSC0_SYNC 24
  169. #define AU1200_DSCR_CMD0_PSC1_SYNC 25
  170. #define AU1200_DSCR_CMD0_CIM_SYNC 26
  171. #define AU1300_DSCR_CMD0_UART0_TX 0
  172. #define AU1300_DSCR_CMD0_UART0_RX 1
  173. #define AU1300_DSCR_CMD0_UART1_TX 2
  174. #define AU1300_DSCR_CMD0_UART1_RX 3
  175. #define AU1300_DSCR_CMD0_UART2_TX 4
  176. #define AU1300_DSCR_CMD0_UART2_RX 5
  177. #define AU1300_DSCR_CMD0_UART3_TX 6
  178. #define AU1300_DSCR_CMD0_UART3_RX 7
  179. #define AU1300_DSCR_CMD0_SDMS_TX0 8
  180. #define AU1300_DSCR_CMD0_SDMS_RX0 9
  181. #define AU1300_DSCR_CMD0_SDMS_TX1 10
  182. #define AU1300_DSCR_CMD0_SDMS_RX1 11
  183. #define AU1300_DSCR_CMD0_AES_TX 12
  184. #define AU1300_DSCR_CMD0_AES_RX 13
  185. #define AU1300_DSCR_CMD0_PSC0_TX 14
  186. #define AU1300_DSCR_CMD0_PSC0_RX 15
  187. #define AU1300_DSCR_CMD0_PSC1_TX 16
  188. #define AU1300_DSCR_CMD0_PSC1_RX 17
  189. #define AU1300_DSCR_CMD0_PSC2_TX 18
  190. #define AU1300_DSCR_CMD0_PSC2_RX 19
  191. #define AU1300_DSCR_CMD0_PSC3_TX 20
  192. #define AU1300_DSCR_CMD0_PSC3_RX 21
  193. #define AU1300_DSCR_CMD0_LCD 22
  194. #define AU1300_DSCR_CMD0_NAND_FLASH 23
  195. #define AU1300_DSCR_CMD0_SDMS_TX2 24
  196. #define AU1300_DSCR_CMD0_SDMS_RX2 25
  197. #define AU1300_DSCR_CMD0_CIM_SYNC 26
  198. #define AU1300_DSCR_CMD0_UDMA 27
  199. #define AU1300_DSCR_CMD0_DMA_REQ0 28
  200. #define AU1300_DSCR_CMD0_DMA_REQ1 29
  201. #define DSCR_CMD0_THROTTLE 30
  202. #define DSCR_CMD0_ALWAYS 31
  203. #define DSCR_NDEV_IDS 32
  204. /* This macro is used to find/create custom device types */
  205. #define DSCR_DEV2CUSTOM_ID(x, d) (((((x) & 0xFFFF) << 8) | 0x32000000) | \
  206. ((d) & 0xFF))
  207. #define DSCR_CUSTOM2DEV_ID(x) ((x) & 0xFF)
  208. #define DSCR_CMD0_SID(x) (((x) & 0x1f) << 25)
  209. #define DSCR_CMD0_DID(x) (((x) & 0x1f) << 20)
  210. /* Source/Destination transfer width. */
  211. #define DSCR_CMD0_BYTE 0
  212. #define DSCR_CMD0_HALFWORD 1
  213. #define DSCR_CMD0_WORD 2
  214. #define DSCR_CMD0_SW(x) (((x) & 0x3) << 18)
  215. #define DSCR_CMD0_DW(x) (((x) & 0x3) << 16)
  216. /* DDMA Descriptor Type. */
  217. #define DSCR_CMD0_STANDARD 0
  218. #define DSCR_CMD0_LITERAL 1
  219. #define DSCR_CMD0_CMP_BRANCH 2
  220. #define DSCR_CMD0_DT(x) (((x) & 0x3) << 13)
  221. /* Status Instruction. */
  222. #define DSCR_CMD0_ST_NOCHANGE 0 /* Don't change */
  223. #define DSCR_CMD0_ST_CURRENT 1 /* Write current status */
  224. #define DSCR_CMD0_ST_CMD0 2 /* Write cmd0 with V cleared */
  225. #define DSCR_CMD0_ST_BYTECNT 3 /* Write remaining byte count */
  226. #define DSCR_CMD0_ST(x) (((x) & 0x3) << 0)
  227. /* Descriptor Command 1. */
  228. #define DSCR_CMD1_SUPTR_MASK (0xf << 28) /* upper 4 bits of src addr */
  229. #define DSCR_CMD1_DUPTR_MASK (0xf << 24) /* upper 4 bits of dest addr */
  230. #define DSCR_CMD1_FL_MASK (0x3 << 22) /* Flag bits */
  231. #define DSCR_CMD1_BC_MASK (0x3fffff) /* Byte count */
  232. /* Flag description. */
  233. #define DSCR_CMD1_FL_MEM_STRIDE0 0
  234. #define DSCR_CMD1_FL_MEM_STRIDE1 1
  235. #define DSCR_CMD1_FL_MEM_STRIDE2 2
  236. #define DSCR_CMD1_FL(x) (((x) & 0x3) << 22)
  237. /* Source1, 1-dimensional stride. */
  238. #define DSCR_SRC1_STS_MASK (3 << 30) /* Src xfer size */
  239. #define DSCR_SRC1_SAM_MASK (3 << 28) /* Src xfer movement */
  240. #define DSCR_SRC1_SB_MASK (0x3fff << 14) /* Block size */
  241. #define DSCR_SRC1_SB(x) (((x) & 0x3fff) << 14)
  242. #define DSCR_SRC1_SS_MASK (0x3fff << 0) /* Stride */
  243. #define DSCR_SRC1_SS(x) (((x) & 0x3fff) << 0)
  244. /* Dest1, 1-dimensional stride. */
  245. #define DSCR_DEST1_DTS_MASK (3 << 30) /* Dest xfer size */
  246. #define DSCR_DEST1_DAM_MASK (3 << 28) /* Dest xfer movement */
  247. #define DSCR_DEST1_DB_MASK (0x3fff << 14) /* Block size */
  248. #define DSCR_DEST1_DB(x) (((x) & 0x3fff) << 14)
  249. #define DSCR_DEST1_DS_MASK (0x3fff << 0) /* Stride */
  250. #define DSCR_DEST1_DS(x) (((x) & 0x3fff) << 0)
  251. #define DSCR_xTS_SIZE1 0
  252. #define DSCR_xTS_SIZE2 1
  253. #define DSCR_xTS_SIZE4 2
  254. #define DSCR_xTS_SIZE8 3
  255. #define DSCR_SRC1_STS(x) (((x) & 3) << 30)
  256. #define DSCR_DEST1_DTS(x) (((x) & 3) << 30)
  257. #define DSCR_xAM_INCREMENT 0
  258. #define DSCR_xAM_DECREMENT 1
  259. #define DSCR_xAM_STATIC 2
  260. #define DSCR_xAM_BURST 3
  261. #define DSCR_SRC1_SAM(x) (((x) & 3) << 28)
  262. #define DSCR_DEST1_DAM(x) (((x) & 3) << 28)
  263. /* The next descriptor pointer. */
  264. #define DSCR_NXTPTR_MASK (0x07ffffff)
  265. #define DSCR_NXTPTR(x) ((x) >> 5)
  266. #define DSCR_GET_NXTPTR(x) ((x) << 5)
  267. #define DSCR_NXTPTR_MS (1 << 27)
  268. /* The number of DBDMA channels. */
  269. #define NUM_DBDMA_CHANS 16
  270. /*
  271. * DDMA API definitions
  272. * FIXME: may not fit to this header file
  273. */
  274. typedef struct dbdma_device_table {
  275. u32 dev_id;
  276. u32 dev_flags;
  277. u32 dev_tsize;
  278. u32 dev_devwidth;
  279. u32 dev_physaddr; /* If FIFO */
  280. u32 dev_intlevel;
  281. u32 dev_intpolarity;
  282. } dbdev_tab_t;
  283. typedef struct dbdma_chan_config {
  284. spinlock_t lock;
  285. u32 chan_flags;
  286. u32 chan_index;
  287. dbdev_tab_t *chan_src;
  288. dbdev_tab_t *chan_dest;
  289. au1x_dma_chan_t *chan_ptr;
  290. au1x_ddma_desc_t *chan_desc_base;
  291. u32 cdb_membase; /* kmalloc base of above */
  292. au1x_ddma_desc_t *get_ptr, *put_ptr, *cur_ptr;
  293. void *chan_callparam;
  294. void (*chan_callback)(int, void *);
  295. } chan_tab_t;
  296. #define DEV_FLAGS_INUSE (1 << 0)
  297. #define DEV_FLAGS_ANYUSE (1 << 1)
  298. #define DEV_FLAGS_OUT (1 << 2)
  299. #define DEV_FLAGS_IN (1 << 3)
  300. #define DEV_FLAGS_BURSTABLE (1 << 4)
  301. #define DEV_FLAGS_SYNC (1 << 5)
  302. /* end DDMA API definitions */
  303. /*
  304. * External functions for drivers to use.
  305. * Use this to allocate a DBDMA channel. The device IDs are one of
  306. * the DSCR_CMD0 devices IDs, which is usually redefined to a more
  307. * meaningful name. The 'callback' is called during DMA completion
  308. * interrupt.
  309. */
  310. extern u32 au1xxx_dbdma_chan_alloc(u32 srcid, u32 destid,
  311. void (*callback)(int, void *),
  312. void *callparam);
  313. #define DBDMA_MEM_CHAN DSCR_CMD0_ALWAYS
  314. /* Set the device width of an in/out FIFO. */
  315. u32 au1xxx_dbdma_set_devwidth(u32 chanid, int bits);
  316. /* Allocate a ring of descriptors for DBDMA. */
  317. u32 au1xxx_dbdma_ring_alloc(u32 chanid, int entries);
  318. /* Put buffers on source/destination descriptors. */
  319. u32 au1xxx_dbdma_put_source(u32 chanid, dma_addr_t buf, int nbytes, u32 flags);
  320. u32 au1xxx_dbdma_put_dest(u32 chanid, dma_addr_t buf, int nbytes, u32 flags);
  321. /* Get a buffer from the destination descriptor. */
  322. u32 au1xxx_dbdma_get_dest(u32 chanid, void **buf, int *nbytes);
  323. void au1xxx_dbdma_stop(u32 chanid);
  324. void au1xxx_dbdma_start(u32 chanid);
  325. void au1xxx_dbdma_reset(u32 chanid);
  326. u32 au1xxx_get_dma_residue(u32 chanid);
  327. void au1xxx_dbdma_chan_free(u32 chanid);
  328. void au1xxx_dbdma_dump(u32 chanid);
  329. u32 au1xxx_dbdma_put_dscr(u32 chanid, au1x_ddma_desc_t *dscr);
  330. u32 au1xxx_ddma_add_device(dbdev_tab_t *dev);
  331. extern void au1xxx_ddma_del_device(u32 devid);
  332. void *au1xxx_ddma_get_nextptr_virt(au1x_ddma_desc_t *dp);
  333. /*
  334. * Flags for the put_source/put_dest functions.
  335. */
  336. #define DDMA_FLAGS_IE (1 << 0)
  337. #define DDMA_FLAGS_NOIE (1 << 1)
  338. #endif /* _LANGUAGE_ASSEMBLY */
  339. #endif /* _AU1000_DBDMA_H_ */