2 * Xilinx AXI DMA Engine support
4 * Copyright (C) 2010 Xilinx, Inc. All rights reserved.
6 * This is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
13 #ifndef __XILINX_DMA_APF_H
14 #define __XILINX_DMA_APF_H
17 #include <linux/ioctl.h>
20 #include <linux/interrupt.h>
23 #include <linux/dma-mapping.h>
27 #include "xlnk-sysdef.h"
29 #define XDMA_IOC_MAGIC 'X'
30 #define XDMA_IOCRESET _IO(XDMA_IOC_MAGIC, 0)
31 #define XDMA_IOCREQUEST _IOWR(XDMA_IOC_MAGIC, 1, unsigned long)
32 #define XDMA_IOCRELEASE _IOWR(XDMA_IOC_MAGIC, 2, unsigned long)
33 #define XDMA_IOCSUBMIT _IOWR(XDMA_IOC_MAGIC, 3, unsigned long)
34 #define XDMA_IOCWAIT _IOWR(XDMA_IOC_MAGIC, 4, unsigned long)
35 #define XDMA_IOCGETCONFIG _IOWR(XDMA_IOC_MAGIC, 5, unsigned long)
36 #define XDMA_IOCSETCONFIG _IOWR(XDMA_IOC_MAGIC, 6, unsigned long)
37 #define XDMA_IOC_MAXNR 6
39 /* Specific hardware configuration-related constants
41 #define XDMA_RESET_LOOP 1000000
42 #define XDMA_HALT_LOOP 1000000
43 #define XDMA_NO_CHANGE 0xFFFF
45 /* General register bits definitions
47 #define XDMA_CR_RESET_MASK 0x00000004 /* Reset DMA engine */
48 #define XDMA_CR_RUNSTOP_MASK 0x00000001 /* Start/stop DMA engine */
50 #define XDMA_SR_HALTED_MASK 0x00000001 /* DMA channel halted */
51 #define XDMA_SR_IDLE_MASK 0x00000002 /* DMA channel idle */
53 #define XDMA_SR_ERR_INTERNAL_MASK 0x00000010/* Datamover internal err */
54 #define XDMA_SR_ERR_SLAVE_MASK 0x00000020 /* Datamover slave err */
55 #define XDMA_SR_ERR_DECODE_MASK 0x00000040 /* Datamover decode err */
56 #define XDMA_SR_ERR_SG_INT_MASK 0x00000100 /* SG internal err */
57 #define XDMA_SR_ERR_SG_SLV_MASK 0x00000200 /* SG slave err */
58 #define XDMA_SR_ERR_SG_DEC_MASK 0x00000400 /* SG decode err */
59 #define XDMA_SR_ERR_ALL_MASK 0x00000770 /* All errors */
61 #define XDMA_XR_IRQ_IOC_MASK 0x00001000 /* Completion interrupt */
62 #define XDMA_XR_IRQ_DELAY_MASK 0x00002000 /* Delay interrupt */
63 #define XDMA_XR_IRQ_ERROR_MASK 0x00004000 /* Error interrupt */
64 #define XDMA_XR_IRQ_ALL_MASK 0x00007000 /* All interrupts */
66 #define XDMA_XR_DELAY_MASK 0xFF000000 /* Delay timeout counter */
67 #define XDMA_XR_COALESCE_MASK 0x00FF0000 /* Coalesce counter */
69 #define XDMA_DELAY_SHIFT 24
70 #define XDMA_COALESCE_SHIFT 16
72 #define XDMA_DELAY_MAX 0xFF /**< Maximum delay counter value */
73 #define XDMA_COALESCE_MAX 0xFF /**< Maximum coalescing counter value */
75 /* BD definitions for Axi DMA
77 #define XDMA_BD_STS_ACTUAL_LEN_MASK 0x007FFFFF
78 #define XDMA_BD_STS_COMPL_MASK 0x80000000
79 #define XDMA_BD_STS_ERR_MASK 0x70000000
80 #define XDMA_BD_STS_ALL_MASK 0xF0000000
82 /* DMA BD special bits definitions
84 #define XDMA_BD_SOP 0x08000000 /* Start of packet bit */
85 #define XDMA_BD_EOP 0x04000000 /* End of packet bit */
87 /* BD Software Flag definitions for Axi DMA
89 #define XDMA_BD_SF_POLL_MODE_MASK 0x00000002
90 #define XDMA_BD_SF_SW_DONE_MASK 0x00000001
93 #define XDMA_MAX_BD_CNT 16384
94 #define XDMA_MAX_CHANS_PER_DEVICE 2
95 #define XDMA_MAX_TRANS_LEN 0x7FF000
96 #define XDMA_MAX_APPWORDS 5
97 #define XDMA_BD_CLEANUP_THRESHOLD ((XDMA_MAX_BD_CNT * 8) / 10)
99 #define XDMA_FLAGS_WAIT_COMPLETE 1
100 #define XDMA_FLAGS_TRYWAIT 2
102 /* Platform data definition until ARM supports device tree */
103 struct xdma_channel_config {
105 unsigned int include_dre;
106 unsigned int datawidth;
107 unsigned int max_burst_len;
109 unsigned int poll_mode;
110 unsigned int lite_mode;
113 struct xdma_device_config {
116 unsigned int include_sg;
117 unsigned int sg_include_stscntrl_strm; /* dma only */
118 unsigned int channel_count;
119 struct xdma_channel_config *channel_config;
122 struct xdma_desc_hw {
123 xlnk_intptr_type next_desc; /* 0x00 */
124 #if XLNK_SYS_BIT_WIDTH == 32
127 xlnk_intptr_type src_addr; /* 0x08 */
128 #if XLNK_SYS_BIT_WIDTH == 32
131 u32 addr_vsize; /* 0x10 */
132 u32 hsize; /* 0x14 */
133 u32 control; /* 0x18 */
134 u32 status; /* 0x1c */
135 u32 app[5]; /* 0x20 */
136 xlnk_intptr_type dmahead;
137 #if XLNK_SYS_BIT_WIDTH == 32
140 u32 sw_flag; /* 0x3C */
143 /* shared by all Xilinx DMA engines */
145 u32 cr; /* 0x00 Control Register */
146 u32 sr; /* 0x04 Status Register */
147 u32 cdr; /* 0x08 Current Descriptor Register */
149 u32 tdr; /* 0x10 Tail Descriptor Register */
151 u32 src; /* 0x18 Source Address Register (cdma) */
153 u32 dst; /* 0x20 Destination Address Register (cdma) */
155 u32 btt_ref; /* 0x28 Bytes To Transfer (cdma) or
158 u32 version; /* 0x2c version (vdma) */
161 /* Per DMA specific operations should be embedded in the channel structure */
164 struct xdma_regs __iomem *regs;
165 struct device *dev; /* The dma device */
166 struct xdma_desc_hw *bds[XDMA_MAX_BD_CNT];
167 dma_addr_t bd_phys_addr;
171 unsigned int bd_used; /* # of BDs passed to hw chan */
172 enum dma_data_direction direction; /* Transfer direction */
173 int id; /* Channel ID */
174 int irq; /* Channel IRQ */
175 int poll_mode; /* Poll mode turned on? */
176 spinlock_t lock; /* Descriptor operation lock */
177 struct tasklet_struct tasklet; /* Cleanup work after irq */
178 struct tasklet_struct dma_err_tasklet; /* Cleanup work after irq */
179 int max_len; /* Maximum len per transfer */
180 int err; /* Channel has errors */
187 struct list_head node;
188 struct xdma_chan *chan[XDMA_MAX_CHANS_PER_DEVICE];
193 xlnk_intptr_type userbuf;
195 unsigned int dmaflag;
196 enum dma_data_direction dmadir;
197 struct scatterlist *sglist;
199 struct scatterlist *pagelist;
200 unsigned int pagecnt;
201 struct completion cmp;
202 struct xdma_chan *chan;
203 unsigned int nappwords_o;
204 u32 appwords_o[XDMA_MAX_APPWORDS];
205 unsigned int userflag;
207 struct xlnk_dmabuf_reg *dmabuf;
210 struct xdma_chan *xdma_request_channel(char *name);
211 void xdma_release_channel(struct xdma_chan *chan);
212 void xdma_release_all_channels(void);
213 int xdma_submit(struct xdma_chan *chan,
214 xlnk_intptr_type userbuf,
217 unsigned int nappwords_i,
219 unsigned int nappwords_o,
220 unsigned int user_flags,
221 struct xdma_head **dmaheadpp,
222 struct xlnk_dmabuf_reg *dp);
223 int xdma_wait(struct xdma_head *dmahead,
224 unsigned int user_flags,
225 unsigned int *operating_flags);
226 int xdma_getconfig(struct xdma_chan *chan,
227 unsigned char *irq_thresh,
228 unsigned char *irq_delay);
229 int xdma_setconfig(struct xdma_chan *chan,
230 unsigned char irq_thresh,
231 unsigned char irq_delay);
232 unsigned int xlate_irq(unsigned int hwirq);