Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:46

0001 /*
0002  * File:        MCD_dma.h
0003  * Purpose:     Main header file for multi-channel DMA API.
0004  *
0005  * Notes:
0006  */
0007 #ifndef _MCD_API_H
0008 #define _MCD_API_H
0009 
0010 /*
0011  * Turn Execution Unit tasks ON (#define) or OFF (#undef)
0012  */
0013 #define MCD_INCLUDE_EU
0014 
0015 /*
0016  * Number of DMA channels
0017  */
0018 #define NCHANNELS 16
0019 
0020 /*
0021  * Total number of variants
0022  */
0023 #ifdef MCD_INCLUDE_EU
0024 #define NUMOFVARIANTS   6
0025 #else
0026 #define NUMOFVARIANTS   4
0027 #endif
0028 
0029 /*
0030  * Define sizes of the various tables
0031  */
0032 #define TASK_TABLE_SIZE     (NCHANNELS*32)
0033 #define VAR_TAB_SIZE        (128)
0034 #define CONTEXT_SAVE_SIZE   (128)
0035 #define FUNCDESC_TAB_SIZE   (256)
0036 
0037 #ifdef MCD_INCLUDE_EU
0038 #define FUNCDESC_TAB_NUM    16
0039 #else
0040 #define FUNCDESC_TAB_NUM    1
0041 #endif
0042 
0043 
0044 #ifndef DEFINESONLY
0045 
0046 /*
0047  * Portability typedefs
0048  */
0049 typedef int s32;
0050 typedef unsigned int u32;
0051 typedef short s16;
0052 typedef unsigned short u16;
0053 typedef char s8;
0054 typedef unsigned char u8;
0055 
0056 /*
0057  * These structures represent the internal registers of the
0058  * multi-channel DMA
0059  */
0060 struct dmaRegs_s {
0061    u32 taskbar;         /* task table base address register */
0062    u32 currPtr;
0063    u32 endPtr;
0064    u32 varTablePtr;
0065    u16 dma_rsvd0;
0066    u16 ptdControl;      /* ptd control */
0067    u32 intPending;      /* interrupt pending register */
0068    u32 intMask;         /* interrupt mask register */
0069    u16 taskControl[16]; /* task control registers */
0070    u8  priority[32];    /* priority registers */
0071    u32 initiatorMux;    /* initiator mux control */
0072    u32 taskSize0;       /* task size control register 0. */
0073    u32 taskSize1;       /* task size control register 1. */
0074    u32 dma_rsvd1;       /* reserved */
0075    u32 dma_rsvd2;       /* reserved */
0076    u32 debugComp1;      /* debug comparator 1 */
0077    u32 debugComp2;      /* debug comparator 2 */
0078    u32 debugControl;    /* debug control */
0079    u32 debugStatus;     /* debug status */
0080    u32 ptdDebug;        /* priority task decode debug */
0081    u32 dma_rsvd3[31];   /* reserved */
0082 };
0083 typedef volatile struct dmaRegs_s dmaRegs;
0084 
0085 #endif
0086 
0087 /*
0088  * PTD contrl reg bits
0089  */
0090 #define PTD_CTL_TSK_PRI         0x8000
0091 #define PTD_CTL_COMM_PREFETCH   0x0001
0092 
0093 /*
0094  * Task Control reg bits and field masks
0095  */
0096 #define TASK_CTL_EN             0x8000
0097 #define TASK_CTL_VALID          0x4000
0098 #define TASK_CTL_ALWAYS         0x2000
0099 #define TASK_CTL_INIT_MASK      0x1f00
0100 #define TASK_CTL_ASTRT          0x0080
0101 #define TASK_CTL_HIPRITSKEN     0x0040
0102 #define TASK_CTL_HLDINITNUM     0x0020
0103 #define TASK_CTL_ASTSKNUM_MASK  0x000f
0104 
0105 /*
0106  * Priority reg bits and field masks
0107  */
0108 #define PRIORITY_HLD            0x80
0109 #define PRIORITY_PRI_MASK       0x07
0110 
0111 /*
0112  * Debug Control reg bits and field masks
0113  */
0114 #define DBG_CTL_BLOCK_TASKS_MASK    0xffff0000
0115 #define DBG_CTL_AUTO_ARM            0x00008000
0116 #define DBG_CTL_BREAK               0x00004000
0117 #define DBG_CTL_COMP1_TYP_MASK      0x00003800
0118 #define DBG_CTL_COMP2_TYP_MASK      0x00000070
0119 #define DBG_CTL_EXT_BREAK           0x00000004
0120 #define DBG_CTL_INT_BREAK           0x00000002
0121 
0122 /*
0123  * PTD Debug reg selector addresses
0124  * This reg must be written with a value to show the contents of
0125  * one of the desired internal register.
0126  */
0127 #define PTD_DBG_REQ             0x00 /* shows the state of 31 initiators */
0128 #define PTD_DBG_TSK_VLD_INIT    0x01 /* shows which 16 tasks are valid and
0129                                         have initiators asserted */
0130 
0131 
0132 /*
0133  * General return values
0134  */
0135 #define MCD_OK                   0
0136 #define MCD_ERROR               -1
0137 #define MCD_TABLE_UNALIGNED     -2
0138 #define MCD_CHANNEL_INVALID     -3
0139 
0140 /*
0141  * MCD_initDma input flags
0142  */
0143 #define MCD_RELOC_TASKS         0x00000001
0144 #define MCD_NO_RELOC_TASKS      0x00000000
0145 #define MCD_COMM_PREFETCH_EN    0x00000002  /* Commbus Prefetching - MCF547x/548x ONLY */
0146 
0147 /*
0148  * MCD_dmaStatus Status Values for each channel
0149  */
0150 #define MCD_NO_DMA  1 /* No DMA has been requested since reset */
0151 #define MCD_IDLE    2 /* DMA active, but the initiator is currently inactive */
0152 #define MCD_RUNNING 3 /* DMA active, and the initiator is currently active */
0153 #define MCD_PAUSED  4 /* DMA active but it is currently paused */
0154 #define MCD_HALTED  5 /* the most recent DMA has been killed with MCD_killTask() */
0155 #define MCD_DONE    6 /* the most recent DMA has completed. */
0156 
0157 
0158 /*
0159  * MCD_startDma parameter defines
0160  */
0161 
0162 /*
0163  * Constants for the funcDesc parameter
0164  */
0165 /* Byte swapping: */
0166 #define MCD_NO_BYTE_SWAP    0x00045670  /* to disable byte swapping. */
0167 #define MCD_BYTE_REVERSE    0x00076540  /* to reverse the bytes of each u32 of the DMAed data. */
0168 #define MCD_U16_REVERSE     0x00067450  /* to reverse the 16-bit halves of
0169                                            each 32-bit data value being DMAed.*/
0170 #define MCD_U16_BYTE_REVERSE    0x00054760 /* to reverse the byte halves of each
0171                                             16-bit half of each 32-bit data value DMAed */
0172 #define MCD_NO_BIT_REV  0x00000000  /* do not reverse the bits of each byte DMAed. */
0173 #define MCD_BIT_REV     0x00088880  /* reverse the bits of each byte DMAed */
0174 /* CRCing: */
0175 #define MCD_CRC16       0xc0100000  /* to perform CRC-16 on DMAed data. */
0176 #define MCD_CRCCCITT    0xc0200000  /* to perform CRC-CCITT on DMAed data. */
0177 #define MCD_CRC32       0xc0300000  /* to perform CRC-32 on DMAed data. */
0178 #define MCD_CSUMINET    0xc0400000  /* to perform internet checksums on DMAed data.*/
0179 #define MCD_NO_CSUM     0xa0000000  /* to perform no checksumming. */
0180 
0181 #define MCD_FUNC_NOEU1 (MCD_NO_BYTE_SWAP | MCD_NO_BIT_REV | MCD_NO_CSUM)
0182 #define MCD_FUNC_NOEU2 (MCD_NO_BYTE_SWAP | MCD_NO_CSUM)
0183 
0184 /*
0185  * Constants for the flags parameter
0186  */
0187 #define MCD_TT_FLAGS_RL   0x00000001 /* Read line */
0188 #define MCD_TT_FLAGS_CW   0x00000002 /* Combine Writes */
0189 #define MCD_TT_FLAGS_SP   0x00000004 /* Speculative prefetch(XLB) MCF547x/548x ONLY  */
0190 #define MCD_TT_FLAGS_MASK 0x000000ff
0191 #define MCD_TT_FLAGS_DEF  (MCD_TT_FLAGS_RL | MCD_TT_FLAGS_CW)
0192 
0193 #define MCD_SINGLE_DMA  0x00000100 /* Unchained DMA */
0194 #define MCD_CHAIN_DMA              /* TBD */
0195 #define MCD_EU_DMA                 /* TBD */
0196 #define MCD_FECTX_DMA   0x00001000 /* FEC TX ring DMA */
0197 #define MCD_FECRX_DMA   0x00002000 /* FEC RX ring DMA */
0198 
0199 
0200 /* these flags are valid for MCD_startDma and the chained buffer descriptors */
0201 #define MCD_BUF_READY   0x80000000 /* indicates that this buffer is now under the DMA's control */
0202 #define MCD_WRAP        0x20000000 /* to tell the FEC Dmas to wrap to the first BD */
0203 #define MCD_INTERRUPT   0x10000000 /* to generate an interrupt after completion of the DMA. */
0204 #define MCD_END_FRAME   0x08000000 /* tell the DMA to end the frame when transferring
0205                                       last byte of data in buffer */
0206 #define MCD_CRC_RESTART 0x40000000 /* to empty out the accumulated checksum
0207                                       prior to performing the DMA. */
0208 
0209 /* Defines for the FEC buffer descriptor control/status word*/
0210 #define MCD_FEC_BUF_READY   0x8000
0211 #define MCD_FEC_WRAP        0x2000
0212 #define MCD_FEC_INTERRUPT   0x1000
0213 #define MCD_FEC_END_FRAME   0x0800
0214 
0215 
0216 /*
0217  * Defines for general intuitiveness
0218  */
0219 
0220 #define MCD_TRUE  1
0221 #define MCD_FALSE 0
0222 
0223 /*
0224  * Three different cases for destination and source.
0225  */
0226 #define MINUS1          -1
0227 #define ZERO            0
0228 #define PLUS1           1
0229 
0230 #ifndef DEFINESONLY
0231 
0232 /* Task Table Entry struct*/
0233 typedef struct {
0234     u32 TDTstart;   /* task descriptor table start */
0235     u32 TDTend;     /* task descriptor table end */
0236     u32 varTab;     /* variable table start */
0237     u32 FDTandFlags;    /* function descriptor table start and flags */
0238     volatile u32 descAddrAndStatus;
0239     volatile u32 modifiedVarTab;
0240     u32 contextSaveSpace;   /* context save space start */
0241     u32 literalBases;
0242 } TaskTableEntry;
0243 
0244 
0245 /* Chained buffer descriptor */
0246 typedef volatile struct MCD_bufDesc_struct MCD_bufDesc;
0247 struct MCD_bufDesc_struct {
0248    u32 flags;         /* flags describing the DMA */
0249    u32 csumResult;    /* checksum from checksumming performed since last checksum reset */
0250    s8  *srcAddr;      /* the address to move data from */
0251    s8  *destAddr;     /* the address to move data to */
0252    s8  *lastDestAddr; /* the last address written to */
0253    u32 dmaSize;       /* the number of bytes to transfer independent of the transfer size */
0254    MCD_bufDesc *next; /* next buffer descriptor in chain */
0255    u32 info;          /* private information about this descriptor;  DMA does not affect it */
0256 };
0257 
0258 /* Progress Query struct */
0259 typedef volatile struct MCD_XferProg_struct {
0260    s8 *lastSrcAddr;         /* the most-recent or last, post-increment source address */
0261    s8 *lastDestAddr;        /* the most-recent or last, post-increment destination address */
0262    u32  dmaSize;            /* the amount of data transferred for the current buffer */
0263    MCD_bufDesc *currBufDesc;/* pointer to the current buffer descriptor being DMAed */
0264 } MCD_XferProg;
0265 
0266 
0267 /* FEC buffer descriptor */
0268 typedef volatile struct MCD_bufDescFec_struct {
0269     u16 statCtrl;
0270     u16 length;
0271     u32 dataPointer;
0272 } MCD_bufDescFec;
0273 
0274 
0275 /*************************************************************************/
0276 /*
0277  * API function Prototypes  - see MCD_dmaApi.c for further notes
0278  */
0279 
0280 /*
0281  * MCD_startDma starts a particular kind of DMA .
0282  */
0283 int MCD_startDma (
0284    int channel,   /* the channel on which to run the DMA */
0285    s8  *srcAddr,  /* the address to move data from, or buffer-descriptor address */
0286    s16 srcIncr,   /* the amount to increment the source address per transfer */
0287    s8  *destAddr, /* the address to move data to */
0288    s16 destIncr,  /* the amount to increment the destination address per transfer */
0289    u32 dmaSize,   /* the number of bytes to transfer independent of the transfer size */
0290    u32 xferSize,  /* the number bytes in of each data movement (1, 2, or 4) */
0291    u32 initiator, /* what device initiates the DMA */
0292    int priority,  /* priority of the DMA */
0293    u32 flags,     /* flags describing the DMA */
0294    u32 funcDesc   /* a description of byte swapping, bit swapping, and CRC actions */
0295 );
0296 
0297 /*
0298  * MCD_initDma() initializes the DMA API by setting up a pointer to the DMA
0299  * registers, relocating and creating the appropriate task structures, and
0300  * setting up some global settings
0301  */
0302 int MCD_initDma (dmaRegs *sDmaBarAddr, void *taskTableDest, u32 flags);
0303 
0304 /*
0305  * MCD_dmaStatus() returns the status of the DMA on the requested channel.
0306  */
0307 int MCD_dmaStatus (int channel);
0308 
0309 /*
0310  * MCD_XferProgrQuery() returns progress of DMA on requested channel
0311  */
0312 int MCD_XferProgrQuery (int channel, MCD_XferProg *progRep);
0313 
0314 /*
0315  * MCD_killDma() halts the DMA on the requested channel, without any
0316  * intention of resuming the DMA.
0317  */
0318 int MCD_killDma (int channel);
0319 
0320 /*
0321  * MCD_continDma() continues a DMA which as stopped due to encountering an
0322  * unready buffer descriptor.
0323  */
0324 int MCD_continDma (int channel);
0325 
0326 /*
0327  * MCD_pauseDma() pauses the DMA on the given channel ( if any DMA is
0328  * running on that channel).
0329  */
0330 int MCD_pauseDma (int channel);
0331 
0332 /*
0333  * MCD_resumeDma() resumes the DMA on a given channel (if any DMA is
0334  * running on that channel).
0335  */
0336 int MCD_resumeDma (int channel);
0337 
0338 /*
0339  * MCD_csumQuery provides the checksum/CRC after performing a non-chained DMA
0340  */
0341 int MCD_csumQuery (int channel, u32 *csum);
0342 
0343 /*
0344  * MCD_getCodeSize provides the packed size required by the microcoded task
0345  * and structures.
0346  */
0347 int MCD_getCodeSize(void);
0348 
0349 /*
0350  * MCD_getVersion provides a pointer to a version string and returns a
0351  * version number.
0352  */
0353 int MCD_getVersion(char **longVersion);
0354 
0355 /* macro for setting a location in the variable table */
0356 #define MCD_SET_VAR(taskTab,idx,value) ((u32 *)(taskTab)->varTab)[idx] = value
0357    /* Note that MCD_SET_VAR() is invoked many times in firing up a DMA function,
0358       so I'm avoiding surrounding it with "do {} while(0)" */
0359 
0360 #endif  /* DEFINESONLY */
0361 
0362 #endif /* _MCD_API_H */