2 * Copyright (C) 2004-2007 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
10 /* Turn Execution Unit tasks ON (#define) or OFF (#undef) */
13 /* Number of DMA channels */
16 /* Total number of variants */
18 #define NUMOFVARIANTS 6
20 #define NUMOFVARIANTS 4
23 /* Define sizes of the various tables */
24 #define TASK_TABLE_SIZE (NCHANNELS*32)
25 #define VAR_TAB_SIZE (128)
26 #define CONTEXT_SAVE_SIZE (128)
27 #define FUNCDESC_TAB_SIZE (256)
30 #define FUNCDESC_TAB_NUM 16
32 #define FUNCDESC_TAB_NUM 1
37 /* Portability typedefs */
45 typedef unsigned int u32;
51 typedef unsigned short u16;
57 typedef unsigned char u8;
62 * These structures represent the internal registers of the
66 u32 taskbar; /* task table base address */
71 u16 ptdControl; /* ptd control */
72 u32 intPending; /* interrupt pending */
73 u32 intMask; /* interrupt mask */
74 u16 taskControl[16]; /* task control */
75 u8 priority[32]; /* priority */
76 u32 initiatorMux; /* initiator mux control */
77 u32 taskSize0; /* task size control 0. */
78 u32 taskSize1; /* task size control 1. */
79 u32 dma_rsvd1; /* reserved */
80 u32 dma_rsvd2; /* reserved */
81 u32 debugComp1; /* debug comparator 1 */
82 u32 debugComp2; /* debug comparator 2 */
83 u32 debugControl; /* debug control */
84 u32 debugStatus; /* debug status */
85 u32 ptdDebug; /* priority task decode debug */
86 u32 dma_rsvd3[31]; /* reserved */
88 typedef volatile struct dmaRegs_s dmaRegs;
92 /* PTD contrl reg bits */
93 #define PTD_CTL_TSK_PRI 0x8000
94 #define PTD_CTL_COMM_PREFETCH 0x0001
96 /* Task Control reg bits and field masks */
97 #define TASK_CTL_EN 0x8000
98 #define TASK_CTL_VALID 0x4000
99 #define TASK_CTL_ALWAYS 0x2000
100 #define TASK_CTL_INIT_MASK 0x1f00
101 #define TASK_CTL_ASTRT 0x0080
102 #define TASK_CTL_HIPRITSKEN 0x0040
103 #define TASK_CTL_HLDINITNUM 0x0020
104 #define TASK_CTL_ASTSKNUM_MASK 0x000f
106 /* Priority reg bits and field masks */
107 #define PRIORITY_HLD 0x80
108 #define PRIORITY_PRI_MASK 0x07
110 /* Debug Control reg bits and field masks */
111 #define DBG_CTL_BLOCK_TASKS_MASK 0xffff0000
112 #define DBG_CTL_AUTO_ARM 0x00008000
113 #define DBG_CTL_BREAK 0x00004000
114 #define DBG_CTL_COMP1_TYP_MASK 0x00003800
115 #define DBG_CTL_COMP2_TYP_MASK 0x00000070
116 #define DBG_CTL_EXT_BREAK 0x00000004
117 #define DBG_CTL_INT_BREAK 0x00000002
120 * PTD Debug reg selector addresses
121 * This reg must be written with a value to show the contents of
122 * one of the desired internal register.
124 #define PTD_DBG_REQ 0x00 /* shows the state of 31 initiators */
125 #define PTD_DBG_TSK_VLD_INIT 0x01 /* shows which 16 tasks are valid and
126 have initiators asserted */
128 /* General return values */
131 #define MCD_TABLE_UNALIGNED -2
132 #define MCD_CHANNEL_INVALID -3
134 /* MCD_initDma input flags */
135 #define MCD_RELOC_TASKS 0x00000001
136 #define MCD_NO_RELOC_TASKS 0x00000000
137 #define MCD_COMM_PREFETCH_EN 0x00000002 /* MCF547x/548x ONLY */
140 * MCD_dmaStatus Status Values for each channel:
141 * MCD_NO_DMA - No DMA has been requested since reset
142 * MCD_IDLE - DMA active, but the initiator is currently inactive
143 * MCD_RUNNING - DMA active, and the initiator is currently active
144 * MCD_PAUSED - DMA active but it is currently paused
145 * MCD_HALTED - the most recent DMA has been killed with MCD_killTask()
146 * MCD_DONE - the most recent DMA has completed
150 #define MCD_RUNNING 3
155 /* MCD_startDma parameter defines */
157 /* Constants for the funcDesc parameter */
159 * MCD_NO_BYTE_SWAP - to disable byte swapping
160 * MCD_BYTE_REVERSE - to reverse the bytes of each u32 of the DMAed data
161 * MCD_U16_REVERSE - to reverse the 16-bit halves of each 32-bit data
163 * MCD_U16_BYTE_REVERSE - to reverse the byte halves of each 16-bit half of
164 * each 32-bit data value DMAed
165 * MCD_NO_BIT_REV - do not reverse the bits of each byte DMAed
166 * MCD_BIT_REV - reverse the bits of each byte DMAed
167 * MCD_CRC16 - to perform CRC-16 on DMAed data
168 * MCD_CRCCCITT - to perform CRC-CCITT on DMAed data
169 * MCD_CRC32 - to perform CRC-32 on DMAed data
170 * MCD_CSUMINET - to perform internet checksums on DMAed data
171 * MCD_NO_CSUM - to perform no checksumming
173 #define MCD_NO_BYTE_SWAP 0x00045670
174 #define MCD_BYTE_REVERSE 0x00076540
175 #define MCD_U16_REVERSE 0x00067450
176 #define MCD_U16_BYTE_REVERSE 0x00054760
177 #define MCD_NO_BIT_REV 0x00000000
178 #define MCD_BIT_REV 0x00088880
180 #define MCD_CRC16 0xc0100000
181 #define MCD_CRCCCITT 0xc0200000
182 #define MCD_CRC32 0xc0300000
183 #define MCD_CSUMINET 0xc0400000
184 #define MCD_NO_CSUM 0xa0000000
186 #define MCD_FUNC_NOEU1 (MCD_NO_BYTE_SWAP | MCD_NO_BIT_REV | \
188 #define MCD_FUNC_NOEU2 (MCD_NO_BYTE_SWAP | MCD_NO_CSUM)
190 /* Constants for the flags parameter */
191 #define MCD_TT_FLAGS_RL 0x00000001 /* Read line */
192 #define MCD_TT_FLAGS_CW 0x00000002 /* Combine Writes */
193 #define MCD_TT_FLAGS_SP 0x00000004 /* MCF547x/548x ONLY */
194 #define MCD_TT_FLAGS_MASK 0x000000ff
195 #define MCD_TT_FLAGS_DEF (MCD_TT_FLAGS_RL | MCD_TT_FLAGS_CW)
197 #define MCD_SINGLE_DMA 0x00000100 /* Unchained DMA */
198 #define MCD_CHAIN_DMA /* TBD */
199 #define MCD_EU_DMA /* TBD */
200 #define MCD_FECTX_DMA 0x00001000 /* FEC TX ring DMA */
201 #define MCD_FECRX_DMA 0x00002000 /* FEC RX ring DMA */
203 /* these flags are valid for MCD_startDma and the chained buffer descriptors */
205 * MCD_BUF_READY - indicates that this buf is now under the DMA's ctrl
206 * MCD_WRAP - to tell the FEC Dmas to wrap to the first BD
207 * MCD_INTERRUPT - to generate an interrupt after completion of the DMA
208 * MCD_END_FRAME - tell the DMA to end the frame when transferring
209 * last byte of data in buffer
210 * MCD_CRC_RESTART - to empty out the accumulated checksum prior to
213 #define MCD_BUF_READY 0x80000000
214 #define MCD_WRAP 0x20000000
215 #define MCD_INTERRUPT 0x10000000
216 #define MCD_END_FRAME 0x08000000
217 #define MCD_CRC_RESTART 0x40000000
219 /* Defines for the FEC buffer descriptor control/status word*/
220 #define MCD_FEC_BUF_READY 0x8000
221 #define MCD_FEC_WRAP 0x2000
222 #define MCD_FEC_INTERRUPT 0x1000
223 #define MCD_FEC_END_FRAME 0x0800
225 /* Defines for general intuitiveness */
230 /* Three different cases for destination and source. */
237 /* Task Table Entry struct*/
239 u32 TDTstart; /* task descriptor table start */
240 u32 TDTend; /* task descriptor table end */
241 u32 varTab; /* variable table start */
242 u32 FDTandFlags; /* function descriptor table start & flags */
243 volatile u32 descAddrAndStatus;
244 volatile u32 modifiedVarTab;
245 u32 contextSaveSpace; /* context save space start */
249 /* Chained buffer descriptor:
250 * flags - flags describing the DMA
251 * csumResult - checksum performed since last checksum reset
252 * srcAddr - the address to move data from
253 * destAddr - the address to move data to
254 * lastDestAddr - the last address written to
255 * dmaSize - the no of bytes to xfer independent of the xfer sz
256 * next - next buffer descriptor in chain
257 * info - private info about this descriptor; DMA does not affect it
259 typedef volatile struct MCD_bufDesc_struct MCD_bufDesc;
260 struct MCD_bufDesc_struct {
271 /* Progress Query struct:
272 * lastSrcAddr - the most-recent or last, post-increment source address
273 * lastDestAddr - the most-recent or last, post-increment destination address
274 * dmaSize - the amount of data transferred for the current buffer
275 * currBufDesc - pointer to the current buffer descriptor being DMAed
278 typedef volatile struct MCD_XferProg_struct {
282 MCD_bufDesc *currBufDesc;
285 /* FEC buffer descriptor */
286 typedef volatile struct MCD_bufDescFec_struct {
292 /*************************************************************************/
293 /* API function Prototypes - see MCD_dmaApi.c for further notes */
295 /* MCD_startDma starts a particular kind of DMA:
296 * srcAddr - the channel on which to run the DMA
297 * srcIncr - the address to move data from, or buffer-descriptor address
298 * destAddr - the amount to increment the source address per transfer
299 * destIncr - the address to move data to
300 * dmaSize - the amount to increment the destination address per transfer
301 * xferSize - the number bytes in of each data movement (1, 2, or 4)
302 * initiator - what device initiates the DMA
303 * priority - priority of the DMA
304 * flags - flags describing the DMA
305 * funcDesc - description of byte swapping, bit swapping, and CRC actions
307 int MCD_startDma(int channel, s8 * srcAddr, s16 srcIncr, s8 * destAddr,
308 s16 destIncr, u32 dmaSize, u32 xferSize, u32 initiator,
309 int priority, u32 flags, u32 funcDesc);
312 * MCD_initDma() initializes the DMA API by setting up a pointer to the DMA
313 * registers, relocating and creating the appropriate task structures, and
314 * setting up some global settings
316 int MCD_initDma(dmaRegs * sDmaBarAddr, void *taskTableDest, u32 flags);
318 /* MCD_dmaStatus() returns the status of the DMA on the requested channel. */
319 int MCD_dmaStatus(int channel);
321 /* MCD_XferProgrQuery() returns progress of DMA on requested channel */
322 int MCD_XferProgrQuery(int channel, MCD_XferProg * progRep);
325 * MCD_killDma() halts the DMA on the requested channel, without any
326 * intention of resuming the DMA.
328 int MCD_killDma(int channel);
331 * MCD_continDma() continues a DMA which as stopped due to encountering an
332 * unready buffer descriptor.
334 int MCD_continDma(int channel);
337 * MCD_pauseDma() pauses the DMA on the given channel ( if any DMA is
338 * running on that channel).
340 int MCD_pauseDma(int channel);
343 * MCD_resumeDma() resumes the DMA on a given channel (if any DMA is
344 * running on that channel).
346 int MCD_resumeDma(int channel);
348 /* MCD_csumQuery provides the checksum/CRC after performing a non-chained DMA */
349 int MCD_csumQuery(int channel, u32 * csum);
352 * MCD_getCodeSize provides the packed size required by the microcoded task
355 int MCD_getCodeSize(void);
358 * MCD_getVersion provides a pointer to a version string and returns a
361 int MCD_getVersion(char **longVersion);
363 /* macro for setting a location in the variable table */
364 #define MCD_SET_VAR(taskTab,idx,value) ((u32 *)(taskTab)->varTab)[idx] = value
365 /* Note that MCD_SET_VAR() is invoked many times in firing up a DMA function,
366 so I'm avoiding surrounding it with "do {} while(0)" */
368 #endif /* DEFINESONLY */
370 #endif /* _MCD_API_H */