1 /*********************************************************************
3 * Copyright (C) 2004 Motorola, Inc.
4 * MOTOROLA, INC. All Rights Reserved.
5 * Copyright 2009 Freescale Semiconductor, Inc.
6 * Shrek Wu b16972@freescale.com
8 * You are hereby granted a copyright license to use
9 * the SOFTWARE so long as this entire notice is
10 * retained without alteration in any modified and/or redistributed
11 * versions, and that such modified versions are clearly identified
12 * as such. No licenses are granted by implication, estoppel or
13 * otherwise under any patents or trademarks of Motorola, Inc. This
14 * software is provided on an "AS IS" basis and without warranty.
16 * To the maximum extent permitted by applicable law, MOTOROLA
17 * DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED, INCLUDING
18 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
19 * PURPOSE AND ANY WARRANTY AGAINST INFRINGEMENT WITH REGARD TO THE
20 * SOFTWARE (INCLUDING ANY MODIFIED VERSIONS THEREOF) AND ANY
21 * ACCOMPANYING WRITTEN MATERIALS.
23 * To the maximum extent permitted by applicable law, IN NO EVENT
24 * SHALL MOTOROLA BE LIABLE FOR ANY DAMAGES WHATSOEVER (INCLUDING
25 * WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS
26 * INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY
27 * LOSS) ARISING OF THE USE OR INABILITY TO USE THE SOFTWARE.
29 * Motorola assumes no responsibility for the maintenance and support
31 ********************************************************************/
35 * Purpose: Main header file for multi-channel DMA API.
44 #include <asm/types.h>
47 * Turn Execution Unit tasks ON (#define) or OFF (#undef)
52 * Number of DMA channels
57 * Total number of variants
60 #define NUMOFVARIANTS 6
62 #define NUMOFVARIANTS 4
66 * Define sizes of the various tables
68 #define TASK_TABLE_SIZE (NCHANNELS*32)
69 #define VAR_TAB_SIZE (128)
70 #define CONTEXT_SAVE_SIZE (128)
71 #define FUNCDESC_TAB_SIZE (256)
74 #define FUNCDESC_TAB_NUM 16
76 #define FUNCDESC_TAB_NUM 1
83 * Portability typedefs
90 typedef unsigned int u32;
96 typedef unsigned short u16;
102 typedef unsigned char u8;
106 * These structures represent the internal registers of the
110 u32 taskbar
; /* task table base address register */
115 u16 ptdControl
; /* ptd control */
116 u32 intPending
; /* interrupt pending register */
117 u32 intMask
; /* interrupt mask register */
118 u16 taskControl
[16]; /* task control registers */
119 u8 priority
[32]; /* priority registers */
120 u32 initiatorMux
; /* initiator mux control */
121 u32 taskSize0
; /* task size control register 0. */
122 u32 taskSize1
; /* task size control register 1. */
123 u32 dma_rsvd1
; /* reserved */
124 u32 dma_rsvd2
; /* reserved */
125 u32 debugComp1
; /* debug comparator 1 */
126 u32 debugComp2
; /* debug comparator 2 */
127 u32 debugControl
; /* debug control */
128 u32 debugStatus
; /* debug status */
129 u32 ptdDebug
; /* priority task decode debug */
130 u32 dma_rsvd3
[31]; /* reserved */
132 typedef volatile struct dmaRegs_s dmaRegs
;
137 * PTD contrl reg bits
139 #define PTD_CTL_TSK_PRI 0x8000
140 #define PTD_CTL_COMM_PREFETCH 0x0001
143 * Task Control reg bits and field masks
145 #define TASK_CTL_EN 0x8000
146 #define TASK_CTL_VALID 0x4000
147 #define TASK_CTL_ALWAYS 0x2000
148 #define TASK_CTL_INIT_MASK 0x1f00
149 #define TASK_CTL_ASTRT 0x0080
150 #define TASK_CTL_HIPRITSKEN 0x0040
151 #define TASK_CTL_HLDINITNUM 0x0020
152 #define TASK_CTL_ASTSKNUM_MASK 0x000f
155 * Priority reg bits and field masks
157 #define PRIORITY_HLD 0x80
158 #define PRIORITY_PRI_MASK 0x07
161 * Debug Control reg bits and field masks
163 #define DBG_CTL_BLOCK_TASKS_MASK 0xffff0000
164 #define DBG_CTL_AUTO_ARM 0x00008000
165 #define DBG_CTL_BREAK 0x00004000
166 #define DBG_CTL_COMP1_TYP_MASK 0x00003800
167 #define DBG_CTL_COMP2_TYP_MASK 0x00000070
168 #define DBG_CTL_EXT_BREAK 0x00000004
169 #define DBG_CTL_INT_BREAK 0x00000002
172 * PTD Debug reg selector addresses
173 * This reg must be written with a value to show the contents of
174 * one of the desired internal register.
176 #define PTD_DBG_REQ 0x00 /* shows the state of 31 initiators */
177 #define PTD_DBG_TSK_VLD_INIT 0x01 /* shows which 16 tasks are valid and
178 have initiators asserted */
182 * General return values
186 #define MCD_TABLE_UNALIGNED -2
187 #define MCD_CHANNEL_INVALID -3
190 * MCD_initDma input flags
192 #define MCD_RELOC_TASKS 0x00000001
193 #define MCD_NO_RELOC_TASKS 0x00000000
194 #define MCD_COMM_PREFETCH_EN 0x00000002
195 /* Commbus Prefetching - MCF547x/548x ONLY */
198 * MCD_dmaStatus Status Values for each channel
200 #define MCD_NO_DMA 1 /* No DMA has been requested since reset */
201 #define MCD_IDLE 2 /* DMA active, but the initiator is currently inactive */
202 #define MCD_RUNNING 3 /* DMA active, and the initiator is currently active */
203 #define MCD_PAUSED 4 /* DMA active but it is currently paused */
205 /* the most recent DMA has been killed with MCD_killTask() */
206 #define MCD_DONE 6 /* the most recent DMA has completed. */
210 * MCD_startDma parameter defines
214 * Constants for the funcDesc parameter
217 #define MCD_NO_BYTE_SWAP 0x00045670 /* to disable byte swapping. */
218 #define MCD_BYTE_REVERSE 0x00076540
219 /* to reverse the bytes of each u32 of the DMAed data. */
220 #define MCD_U16_REVERSE 0x00067450 /* to reverse the 16-bit halves of
221 each 32-bit data value being DMAed.*/
222 #define MCD_U16_BYTE_REVERSE 0x00054760 /* to reverse the byte halves of each
223 16-bit half of each 32-bit data value DMAed */
224 #define MCD_NO_BIT_REV 0x00000000
225 /* do not reverse the bits of each byte DMAed. */
226 #define MCD_BIT_REV 0x00088880 /* reverse the bits of each byte DMAed */
228 #define MCD_CRC16 0xc0100000 /* to perform CRC-16 on DMAed data. */
229 #define MCD_CRCCCITT 0xc0200000 /* to perform CRC-CCITT on DMAed data. */
230 #define MCD_CRC32 0xc0300000 /* to perform CRC-32 on DMAed data. */
231 #define MCD_CSUMINET 0xc0400000
232 /* to perform internet checksums on DMAed data.*/
233 #define MCD_NO_CSUM 0xa0000000 /* to perform no checksumming. */
235 #define MCD_FUNC_NOEU1 (MCD_NO_BYTE_SWAP | MCD_NO_BIT_REV | MCD_NO_CSUM)
236 #define MCD_FUNC_NOEU2 (MCD_NO_BYTE_SWAP | MCD_NO_CSUM)
239 * Constants for the flags parameter
241 #define MCD_TT_FLAGS_RL 0x00000001 /* Read line */
242 #define MCD_TT_FLAGS_CW 0x00000002 /* Combine Writes */
243 #define MCD_TT_FLAGS_SP 0x00000004
244 /* Speculative prefetch(XLB) MCF547x/548x ONLY */
245 #define MCD_TT_FLAGS_MASK 0x000000ff
246 #define MCD_TT_FLAGS_DEF (MCD_TT_FLAGS_RL | MCD_TT_FLAGS_CW)
248 #define MCD_SINGLE_DMA 0x00000100 /* Unchained DMA */
249 #define MCD_CHAIN_DMA /* TBD */
250 #define MCD_EU_DMA /* TBD */
251 #define MCD_FECTX_DMA 0x00001000 /* FEC TX ring DMA */
252 #define MCD_FECRX_DMA 0x00002000 /* FEC RX ring DMA */
255 /* these flags are valid for MCD_startDma and the chained buffer descriptors */
256 #define MCD_BUF_READY 0x80000000
257 /* indicates that this buffer is now under the DMA's control */
258 #define MCD_WRAP 0x20000000
259 /* to tell the FEC Dmas to wrap to the first BD */
260 #define MCD_INTERRUPT 0x10000000
261 /* to generate an interrupt after completion of the DMA. */
262 #define MCD_END_FRAME 0x08000000
263 /* tell the DMA to end the frame when transferring
264 last byte of data in buffer */
265 #define MCD_CRC_RESTART 0x40000000 /* to empty out the accumulated checksum
266 prior to performing the DMA. */
268 /* Defines for the FEC buffer descriptor control/status word*/
269 #define MCD_FEC_BUF_READY 0x8000
270 #define MCD_FEC_WRAP 0x2000
271 #define MCD_FEC_INTERRUPT 0x1000
272 #define MCD_FEC_END_FRAME 0x0800
276 * Defines for general intuitiveness
283 * Three different cases for destination and source.
291 /* Task Table Entry struct*/
293 u32 TDTstart
; /* task descriptor table start */
294 u32 TDTend
; /* task descriptor table end */
295 u32 varTab
; /* variable table start */
296 u32 FDTandFlags
; /* function descriptor table start and flags */
297 volatile u32 descAddrAndStatus
;
298 volatile u32 modifiedVarTab
;
299 u32 contextSaveSpace
; /* context save space start */
304 /* Chained buffer descriptor */
305 typedef volatile struct MCD_bufDesc_struct MCD_bufDesc
;
306 struct MCD_bufDesc_struct
{
307 u32 flags
; /* flags describing the DMA */
309 /* checksum from checksumming performed since last checksum reset */
310 s8
*srcAddr
; /* the address to move data from */
311 s8
*destAddr
; /* the address to move data to */
312 s8
*lastDestAddr
; /* the last address written to */
314 /* the number of bytes to transfer independent of the transfer size */
315 MCD_bufDesc
*next
; /* next buffer descriptor in chain */
317 /* private information about this descriptor; DMA does not affect it */
320 /* Progress Query struct */
321 typedef volatile struct MCD_XferProg_struct
{
323 /* the most-recent or last, post-increment source address */
325 /* the most-recent or last, post-increment destination address */
327 /* the amount of data transferred for the current buffer */
328 MCD_bufDesc
*currBufDesc
;
329 /* pointer to the current buffer descriptor being DMAed */
333 /* FEC buffer descriptor */
334 typedef volatile struct MCD_bufDescFec_struct
{
341 /*************************************************************************/
343 * API function Prototypes - see MCD_dmaApi.c for further notes
347 * MCD_startDma starts a particular kind of DMA .
350 int channel
, /* the channel on which to run the DMA */
352 /* the address to move data from, or buffer-descriptor address */
353 s16 srcIncr
, /* the amount to increment the source address per transfer */
354 s8
*destAddr
, /* the address to move data to */
356 /* the amount to increment the destination address per transfer */
358 /* the number of bytes to transfer independent of the transfer size */
359 u32 xferSize
, /* the number bytes in of each data movement (1, 2, or 4) */
360 u32 initiator
, /* what device initiates the DMA */
361 int priority
, /* priority of the DMA */
362 u32 flags
, /* flags describing the DMA */
364 /* a description of byte swapping, bit swapping, and CRC actions */
368 * MCD_initDma() initializes the DMA API by setting up a pointer to the DMA
369 * registers, relocating and creating the appropriate task structures, and
370 * setting up some global settings
372 int MCD_initDma(dmaRegs
*sDmaBarAddr
, void *taskTableDest
, u32 flags
);
375 * MCD_dmaStatus() returns the status of the DMA on the requested channel.
377 int MCD_dmaStatus(int channel
);
380 * MCD_XferProgrQuery() returns progress of DMA on requested channel
382 int MCD_XferProgrQuery(int channel
, MCD_XferProg
*progRep
);
385 * MCD_killDma() halts the DMA on the requested channel, without any
386 * intention of resuming the DMA.
388 int MCD_killDma(int channel
);
391 * MCD_continDma() continues a DMA which as stopped due to encountering an
392 * unready buffer descriptor.
394 int MCD_continDma(int channel
);
397 * MCD_pauseDma() pauses the DMA on the given channel ( if any DMA is
398 * running on that channel).
400 int MCD_pauseDma(int channel
);
403 * MCD_resumeDma() resumes the DMA on a given channel (if any DMA is
404 * running on that channel).
406 int MCD_resumeDma(int channel
);
409 * MCD_csumQuery provides the checksum/CRC after performing a non-chained DMA
411 int MCD_csumQuery(int channel
, u32
*csum
);
414 * MCD_getCodeSize provides the packed size required by the microcoded task
417 int MCD_getCodeSize(void);
420 * MCD_getVersion provides a pointer to a version string and returns a
423 int MCD_getVersion(char **longVersion
);
425 /* macro for setting a location in the variable table */
426 #define MCD_SET_VAR(taskTab, idx, value) ((u32 *)(taskTab)->varTab)[idx] = value
427 /* Note that MCD_SET_VAR() is invoked many times in firing up a DMA function,
428 so I'm avoiding surrounding it with "do {} while(0)" */
430 #endif /* DEFINESONLY */
432 #endif /* _MCD_API_H */