vg_lite_hal.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /****************************************************************************
  2. *
  3. * Copyright 2012 - 2020 Vivante Corporation, Santa Clara, California.
  4. * All Rights Reserved.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining
  7. * a copy of this software and associated documentation files (the
  8. * 'Software'), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sub license, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject
  12. * to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice (including the
  15. * next paragraph) shall be included in all copies or substantial
  16. * portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
  19. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  21. * IN NO EVENT SHALL VIVANTE AND/OR ITS SUPPLIERS BE LIABLE FOR ANY
  22. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  23. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  24. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. *****************************************************************************/
  27. #ifndef _vg_lite_hal_h_
  28. #define _vg_lite_hal_h_
  29. #include "vg_lite_platform.h"
  30. #define VGLITE_MEM_ALIGNMENT 128
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. /*!
  35. @brief Wait a number of milliseconds.
  36. @discussion
  37. The VGLite hardware requires some waiting when changing clock frequencies or issuing a reset. This is the wrapper function
  38. for the delay function.
  39. @param milliseconds
  40. The number of milliseconds to wait.
  41. */
  42. void vg_lite_hal_delay(uint32_t milliseconds);
  43. /*!
  44. @brief Initialize the hardware.
  45. @discussion
  46. The VGLite kernel knows how to program its own hardware, but in any SOC there might be additional control required for
  47. turning on the power or initializing the clocks. This function gets called by the VGLite kernel before the VGLite graphics
  48. hardware gets initialized by the VGLite kernel itself and allows for SOC power management control.
  49. The implementer should make sure that on exit of this function the power and clock to the VGLite graphics hardware is
  50. turned on and stable.
  51. */
  52. void vg_lite_hal_initialize(void);
  53. /*!
  54. @brief Uninitialize the hardware.
  55. @discussion
  56. The VGLite kernel knows how to program its own hardware, but in any SOC there might be additional control required for
  57. turning off the power or uninitializing the clocks. This function gets called by the VGLite kernel after the VGLite
  58. graphics hardware gets uninitialized by the VGLite kernel itself and allows for SOC power management control.
  59. On exit of this function it is okay to have the power and/or clock to the VGLite graphics hardware turned off.
  60. */
  61. void vg_lite_hal_deinitialize(void);
  62. /*!
  63. @brief Allocate contiguous video memory.
  64. @discussion
  65. Any memory the VGLite graphics hardware will see should be allocated as contiguous memory. Any allocated memory will be
  66. addressed through an opaque handle, usually a pointer to an opaque structure. The porting layer can put any information it
  67. needs inside this structure.
  68. @param size
  69. The number of bytes to allocate.
  70. @param logical
  71. A pointer to a variable that will receive the logical address of the allocated memory for the CPU.
  72. @param gpu
  73. A pointer to a variable that will receive the physical address of the allocated memory for the VGLite graphics hardware.
  74. @result
  75. A pointer to an opaque structure that will be used as the memory handle. <code>NULL</code> should be returned if there is not
  76. enough memory.
  77. */
  78. vg_lite_error_t vg_lite_hal_allocate_contiguous(unsigned long size, void ** logical, uint32_t * physical,void ** node);
  79. /*!
  80. @brief Free contiguous video memory.
  81. @discussion
  82. Free the memory allocated by {@link vg_lite_hal_allocate_contiguous}. After this function returns, the associated memory
  83. handle is no longer a valid handle.
  84. @param memory_handle
  85. A pointer to an opaque structure returned by {@link vg_lite_hal_allocate_contiguous}.
  86. */
  87. void vg_lite_hal_free_contiguous(void * memory_handle);
  88. /*!
  89. @brief remove unfree node when continuously allocate buffer without free buffer.
  90. @discussion
  91. Free the node allocated by {@link kmalloc}. After this function returns, the associated memory
  92. handle is no longer a valid handle.
  93. */
  94. void vg_lite_hal_free_os_heap(void);
  95. /*!
  96. @brief Map contiguous logical or physical memory into the VGLite graphics hardware space.
  97. @discussion
  98. Any memory, like a frame buffer or some pre-allocated image or path data, needs to be mapped into the VGLite graphics
  99. hardware address space and wrapped by a memory handle. This allows the VGLite graphics hardware access that memory
  100. directly.
  101. Either a logical or a physical address should be passed in to map.
  102. @param size
  103. The number of bytes to map.
  104. @param logical
  105. The logical address of the memory region to map or <code>NULL</code> if the logical address is not known.
  106. @param physical
  107. The physical address of the memory region to map if <code>logical</code> is <code>NULL</code>.
  108. @param gpu
  109. A pointer to a variable that will receive the VGLite graphics hardware addressable address of the mapped region.
  110. @result
  111. A pointer to an opaque structure that will be used as the memory handle. <code>NULL</code> should be returned if there is
  112. not enough system resources to map the region.
  113. */
  114. void * vg_lite_hal_map(unsigned long size, void * logical, uint32_t physical, uint32_t * gpu);
  115. /*!
  116. @brief Unmap a previously mapped region.
  117. @discussion
  118. If a mapped region by {@link vg_lite_hal_map} is no longer needed, it should be unmapped to free up any allocated system
  119. resources used when mapping the region.
  120. @param memory_handle
  121. A pointer to an opaque structure returned by {@link vg_lite_hal_map}.
  122. */
  123. void vg_lite_hal_unmap(void * memory_handle);
  124. /*!
  125. @brief Execute a memory barrier.
  126. @discussion
  127. Some systems require a a memory barrier to make sure all store operations in the CPU have been handled. This is the wrapper
  128. function for a memory barrier.
  129. */
  130. void vg_lite_hal_barrier(void);
  131. /*!
  132. @brief Read data from a register from the VGLite graphics hardware.
  133. @discussion
  134. In order to communicate with the VGLite graphics hardware, the kernel needs to read and write to some hardware registers.
  135. In each SOC those registers could be allocated at a different space in the physical memory map.
  136. @param address
  137. The relative address of the VGLite graphics hardware register to read from.
  138. @result
  139. The 32-bit value returned from reading the register.
  140. */
  141. uint32_t vg_lite_hal_peek(uint32_t address);
  142. /*!
  143. @brief Write data to a register from the VGLite graphics hardware.
  144. @discussion
  145. In order to communicate with the VGLite graphics hardware, the kernel needs to read and write to some hardware registers.
  146. In each SOC those registers could be allocated at a different space in the physical memory map.
  147. @param address
  148. The relative address of the VGLite graphics hardware register to write to.
  149. @param data
  150. The data to write to the VGLite graphics hardware register.
  151. */
  152. void vg_lite_hal_poke(uint32_t address, uint32_t data);
  153. /*!
  154. @brief query the remaining allocate contiguous video memory.
  155. @param data
  156. The data to get the remaining allocate contiguous video memory bytes.
  157. */
  158. vg_lite_error_t vg_lite_hal_query_mem(vg_lite_kernel_mem_t *mem);
  159. /*!
  160. @brief Map contiguous physical memory into the user space.
  161. @param node
  162. This node have 3 attributes, bytes means the number of bytes to map.
  163. physical means the physical address of the memory region to map.logical means
  164. the return logical address of the memory region after map.
  165. */
  166. vg_lite_error_t vg_lite_hal_map_memory(vg_lite_kernel_map_memory_t *node);
  167. /*!
  168. @brief Unmap a previously mapped region.
  169. @param node
  170. This node have 2 attributes, bytes means the number of bytes to unmap.logical means
  171. the logical address of the memory region to unmap.
  172. */
  173. vg_lite_error_t vg_lite_hal_unmap_memory(vg_lite_kernel_unmap_memory_t *node);
  174. /*!
  175. @brief Wait until an interrupt from the VGLite graphics hardware has been received.
  176. @discussion
  177. Currently, the VGLite API is synchronous. This means that after each call it will wait until the VGLite graphics hardware
  178. has completed. The VGLite graphics hardware will send an interrupt when it is finished, and this function will wait until
  179. that interrupt has been received by the operating system.
  180. A timeout value is specified in order if the kernel wants to wait for a specific number of milliseconds fir the interrupt to
  181. occur. If the interrupt does not occur in the specified timeout, a timeout error will be returned.
  182. @param timeout
  183. The number of milliseconds to wait for the interrupt before returning a timeout error. If <code>timeout = 0xFFFFFFFF</code>
  184. then {@link vg_lite_hal_wait_interrupt} will wait forever for the interrupt.
  185. @param mask
  186. Irq event mask to wait for.
  187. @result
  188. A boolean value indicating whether the interrupt was received (1) or not (0).
  189. */
  190. int32_t vg_lite_hal_wait_interrupt(uint32_t timeout, uint32_t mask, uint32_t * value);
  191. #ifdef __cplusplus
  192. }
  193. #endif
  194. #endif /* _vg_lite_hal_h_ */