mali_dma.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * This confidential and proprietary software may be used only as
  3. * authorised by a licensing agreement from ARM Limited
  4. * (C) COPYRIGHT 2012-2013 ARM Limited
  5. * ALL RIGHTS RESERVED
  6. * The entire notice above must be reproduced on all authorised
  7. * copies and copies may only be made to the extent permitted
  8. * by a licensing agreement from ARM Limited.
  9. */
  10. #ifndef __MALI_DMA_H__
  11. #define __MALI_DMA_H__
  12. #include "mali_osk.h"
  13. #include "mali_osk_mali.h"
  14. #include "mali_hw_core.h"
  15. #define MALI_DMA_CMD_BUF_SIZE 1024
  16. typedef struct mali_dma_cmd_buf {
  17. u32 *virt_addr; /**< CPU address of command buffer */
  18. u32 phys_addr; /**< Physical address of command buffer */
  19. u32 size; /**< Number of prepared words in command buffer */
  20. } mali_dma_cmd_buf;
  21. /** @brief Create a new DMA unit
  22. *
  23. * This is called from entry point of the driver in order to create and
  24. * intialize the DMA resource
  25. *
  26. * @param resource it will be a pointer to a DMA resource
  27. * @return DMA object on success, NULL on failure
  28. */
  29. struct mali_dma_core *mali_dma_create(_mali_osk_resource_t *resource);
  30. /** @brief Delete DMA unit
  31. *
  32. * This is called on entry point of driver if the driver initialization fails
  33. * after initialization of the DMA unit. It is also called on the exit of the
  34. * driver to delete the DMA resource
  35. *
  36. * @param dma Pointer to DMA unit object
  37. */
  38. void mali_dma_delete(struct mali_dma_core *dma);
  39. /** @brief Retrieves the MALI DMA core object (if there is)
  40. *
  41. * @return The Mali DMA object otherwise NULL
  42. */
  43. struct mali_dma_core *mali_dma_get_global_dma_core(void);
  44. /**
  45. * @brief Run a command buffer on the DMA unit
  46. *
  47. * @param dma Pointer to the DMA unit to use
  48. * @param buf Pointer to the command buffer to use
  49. * @return _MALI_OSK_ERR_OK if the buffer was started successfully,
  50. * _MALI_OSK_ERR_BUSY if the DMA unit is busy.
  51. */
  52. _mali_osk_errcode_t mali_dma_start(struct mali_dma_core* dma, mali_dma_cmd_buf *buf);
  53. /**
  54. * @brief Create a DMA command
  55. *
  56. * @param core Mali core
  57. * @param reg offset to register of core
  58. * @param n number of registers to write
  59. */
  60. MALI_STATIC_INLINE u32 mali_dma_command_write(struct mali_hw_core *core, u32 reg, u32 n)
  61. {
  62. u32 core_offset = core->phys_offset;
  63. MALI_DEBUG_ASSERT(reg < 0x2000);
  64. MALI_DEBUG_ASSERT(n < 0x800);
  65. MALI_DEBUG_ASSERT(core_offset < 0x30000);
  66. MALI_DEBUG_ASSERT(0 == ((core_offset + reg) & ~0x7FFFF));
  67. return (n << 20) | (core_offset + reg);
  68. }
  69. /**
  70. * @brief Add a array write to DMA command buffer
  71. *
  72. * @param buf DMA command buffer to fill in
  73. * @param core Core to do DMA to
  74. * @param reg Register on core to start writing to
  75. * @param data Pointer to data to write
  76. * @param count Number of 4 byte words to write
  77. */
  78. MALI_STATIC_INLINE void mali_dma_write_array(mali_dma_cmd_buf *buf, struct mali_hw_core *core,
  79. u32 reg, u32 *data, u32 count)
  80. {
  81. MALI_DEBUG_ASSERT((buf->size + 1 + count ) < MALI_DMA_CMD_BUF_SIZE / 4);
  82. buf->virt_addr[buf->size++] = mali_dma_command_write(core, reg, count);
  83. _mali_osk_memcpy(buf->virt_addr + buf->size, data, count * sizeof(*buf->virt_addr));
  84. buf->size += count;
  85. }
  86. /**
  87. * @brief Add a conditional array write to DMA command buffer
  88. *
  89. * @param buf DMA command buffer to fill in
  90. * @param core Core to do DMA to
  91. * @param reg Register on core to start writing to
  92. * @param data Pointer to data to write
  93. * @param count Number of 4 byte words to write
  94. * @param ref Pointer to referance data that can be skipped if equal
  95. */
  96. MALI_STATIC_INLINE void mali_dma_write_array_conditional(mali_dma_cmd_buf *buf, struct mali_hw_core *core,
  97. u32 reg, u32 *data, u32 count, const u32 *ref)
  98. {
  99. /* Do conditional array writes are not yet implemented, fallback to a
  100. * normal array write. */
  101. mali_dma_write_array(buf, core, reg, data, count);
  102. }
  103. /**
  104. * @brief Add a conditional register write to the DMA command buffer
  105. *
  106. * If the data matches the reference the command will be skipped.
  107. *
  108. * @param buf DMA command buffer to fill in
  109. * @param core Core to do DMA to
  110. * @param reg Register on core to start writing to
  111. * @param data Pointer to data to write
  112. * @param ref Pointer to referance data that can be skipped if equal
  113. */
  114. MALI_STATIC_INLINE void mali_dma_write_conditional(mali_dma_cmd_buf *buf, struct mali_hw_core *core,
  115. u32 reg, u32 data, const u32 ref)
  116. {
  117. /* Skip write if reference value is equal to data. */
  118. if (data == ref) return;
  119. buf->virt_addr[buf->size++] = mali_dma_command_write(core, reg, 1);
  120. buf->virt_addr[buf->size++] = data;
  121. MALI_DEBUG_ASSERT(buf->size < MALI_DMA_CMD_BUF_SIZE / 4);
  122. }
  123. /**
  124. * @brief Add a register write to the DMA command buffer
  125. *
  126. * @param buf DMA command buffer to fill in
  127. * @param core Core to do DMA to
  128. * @param reg Register on core to start writing to
  129. * @param data Pointer to data to write
  130. */
  131. MALI_STATIC_INLINE void mali_dma_write(mali_dma_cmd_buf *buf, struct mali_hw_core *core,
  132. u32 reg, u32 data)
  133. {
  134. buf->virt_addr[buf->size++] = mali_dma_command_write(core, reg, 1);
  135. buf->virt_addr[buf->size++] = data;
  136. MALI_DEBUG_ASSERT(buf->size < MALI_DMA_CMD_BUF_SIZE / 4);
  137. }
  138. /**
  139. * @brief Prepare DMA command buffer for use
  140. *
  141. * This function allocates the DMA buffer itself.
  142. *
  143. * @param buf The mali_dma_cmd_buf to prepare
  144. * @return _MALI_OSK_ERR_OK if the \a buf is ready to use
  145. */
  146. _mali_osk_errcode_t mali_dma_get_cmd_buf(mali_dma_cmd_buf *buf);
  147. /**
  148. * @brief Check if a DMA command buffer is ready for use
  149. *
  150. * @param buf The mali_dma_cmd_buf to check
  151. * @return MALI_TRUE if buffer is usable, MALI_FALSE otherwise
  152. */
  153. MALI_STATIC_INLINE mali_bool mali_dma_cmd_buf_is_valid(mali_dma_cmd_buf *buf)
  154. {
  155. return NULL != buf->virt_addr;
  156. }
  157. /**
  158. * @brief Return a DMA command buffer
  159. *
  160. * @param buf Pointer to DMA command buffer to return
  161. */
  162. void mali_dma_put_cmd_buf(mali_dma_cmd_buf *buf);
  163. #endif /* __MALI_DMA_H__ */