dmacHw_priv.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*****************************************************************************
  2. * Copyright 2004 - 2008 Broadcom Corporation. All rights reserved.
  3. *
  4. * Unless you and Broadcom execute a separate written software license
  5. * agreement governing use of this software, this software is licensed to you
  6. * under the terms of the GNU General Public License version 2, available at
  7. * http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  8. *
  9. * Notwithstanding the above, under no circumstances may you combine this
  10. * software in any way with any other Broadcom software provided under a
  11. * license other than the GPL, without Broadcom's express prior written
  12. * consent.
  13. *****************************************************************************/
  14. /****************************************************************************/
  15. /**
  16. * @file dmacHw_priv.h
  17. *
  18. * @brief Private Definitions for low level DMA driver
  19. *
  20. */
  21. /****************************************************************************/
  22. #ifndef _DMACHW_PRIV_H
  23. #define _DMACHW_PRIV_H
  24. #include <csp/stdint.h>
  25. /* Data type for DMA Link List Item */
  26. typedef struct {
  27. uint32_t sar; /* Source Adress Register.
  28. Address must be aligned to CTLx.SRC_TR_WIDTH. */
  29. uint32_t dar; /* Destination Address Register.
  30. Address must be aligned to CTLx.DST_TR_WIDTH. */
  31. uint32_t llpPhy; /* LLP contains the physical address of the next descriptor for block chaining using linked lists.
  32. Address MUST be aligned to a 32-bit boundary. */
  33. dmacHw_REG64_t ctl; /* Control Register. 64 bits */
  34. uint32_t sstat; /* Source Status Register */
  35. uint32_t dstat; /* Destination Status Register */
  36. uint32_t devCtl; /* Device specific control information */
  37. uint32_t llp; /* LLP contains the virtual address of the next descriptor for block chaining using linked lists. */
  38. } dmacHw_DESC_t;
  39. /*
  40. * Descriptor ring pointers
  41. */
  42. typedef struct {
  43. int num; /* Number of link items */
  44. dmacHw_DESC_t *pHead; /* Head of descriptor ring (for writing) */
  45. dmacHw_DESC_t *pTail; /* Tail of descriptor ring (for reading) */
  46. dmacHw_DESC_t *pProg; /* Descriptor to program the channel (for programming the channel register) */
  47. dmacHw_DESC_t *pEnd; /* End of current descriptor chain */
  48. dmacHw_DESC_t *pFree; /* Descriptor to free memory (freeing dynamic memory) */
  49. uint32_t virt2PhyOffset; /* Virtual to physical address offset for the descriptor ring */
  50. } dmacHw_DESC_RING_t;
  51. /*
  52. * DMA channel control block
  53. */
  54. typedef struct {
  55. uint32_t module; /* DMA controller module (0-1) */
  56. uint32_t channel; /* DMA channel (0-7) */
  57. volatile uint32_t varDataStarted; /* Flag indicating variable data channel is enabled */
  58. volatile uint32_t descUpdated; /* Flag to indicate descriptor update is complete */
  59. void *userData; /* Channel specifc user data */
  60. } dmacHw_CBLK_t;
  61. #define dmacHw_ASSERT(a) if (!(a)) while (1)
  62. #define dmacHw_MAX_CHANNEL_COUNT 16
  63. #define dmacHw_FREE_USER_MEMORY 0xFFFFFFFF
  64. #define dmacHw_DESC_FREE dmacHw_REG_CTL_DONE
  65. #define dmacHw_DESC_INIT ((dmacHw_DESC_t *) 0xFFFFFFFF)
  66. #define dmacHw_MAX_BLOCKSIZE 4064
  67. #define dmacHw_GET_DESC_RING(addr) (dmacHw_DESC_RING_t *)(addr)
  68. #define dmacHw_ADDRESS_MASK(byte) ((byte) - 1)
  69. #define dmacHw_NEXT_DESC(rp, dp) ((rp)->dp = (dmacHw_DESC_t *)(rp)->dp->llp)
  70. #define dmacHw_HANDLE_TO_CBLK(handle) ((dmacHw_CBLK_t *) (handle))
  71. #define dmacHw_CBLK_TO_HANDLE(cblkp) ((dmacHw_HANDLE_t) (cblkp))
  72. #define dmacHw_DST_IS_MEMORY(tt) (((tt) == dmacHw_TRANSFER_TYPE_PERIPHERAL_TO_MEM) || ((tt) == dmacHw_TRANSFER_TYPE_MEM_TO_MEM)) ? 1 : 0
  73. /****************************************************************************/
  74. /**
  75. * @brief Get next available transaction width
  76. *
  77. *
  78. * @return On sucess : Next avail able transaction width
  79. * On failure : dmacHw_TRANSACTION_WIDTH_8
  80. *
  81. * @note
  82. * None
  83. */
  84. /****************************************************************************/
  85. static inline dmacHw_TRANSACTION_WIDTH_e dmacHw_GetNextTrWidth(dmacHw_TRANSACTION_WIDTH_e tw /* [ IN ] Current transaction width */
  86. ) {
  87. if (tw & dmacHw_REG_CTL_SRC_TR_WIDTH_MASK) {
  88. return ((tw >> dmacHw_REG_CTL_SRC_TR_WIDTH_SHIFT) -
  89. 1) << dmacHw_REG_CTL_SRC_TR_WIDTH_SHIFT;
  90. } else if (tw & dmacHw_REG_CTL_DST_TR_WIDTH_MASK) {
  91. return ((tw >> dmacHw_REG_CTL_DST_TR_WIDTH_SHIFT) -
  92. 1) << dmacHw_REG_CTL_DST_TR_WIDTH_SHIFT;
  93. }
  94. /* Default return */
  95. return dmacHw_SRC_TRANSACTION_WIDTH_8;
  96. }
  97. /****************************************************************************/
  98. /**
  99. * @brief Get number of bytes per transaction
  100. *
  101. * @return Number of bytes per transaction
  102. *
  103. *
  104. * @note
  105. * None
  106. */
  107. /****************************************************************************/
  108. static inline int dmacHw_GetTrWidthInBytes(dmacHw_TRANSACTION_WIDTH_e tw /* [ IN ] Transaction width */
  109. ) {
  110. int width = 1;
  111. switch (tw) {
  112. case dmacHw_SRC_TRANSACTION_WIDTH_8:
  113. width = 1;
  114. break;
  115. case dmacHw_SRC_TRANSACTION_WIDTH_16:
  116. case dmacHw_DST_TRANSACTION_WIDTH_16:
  117. width = 2;
  118. break;
  119. case dmacHw_SRC_TRANSACTION_WIDTH_32:
  120. case dmacHw_DST_TRANSACTION_WIDTH_32:
  121. width = 4;
  122. break;
  123. case dmacHw_SRC_TRANSACTION_WIDTH_64:
  124. case dmacHw_DST_TRANSACTION_WIDTH_64:
  125. width = 8;
  126. break;
  127. default:
  128. dmacHw_ASSERT(0);
  129. }
  130. /* Default transaction width */
  131. return width;
  132. }
  133. #endif /* _DMACHW_PRIV_H */