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