vg_lite_hal.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /****************************************************************************
  2. *
  3. * The MIT License (MIT)
  4. *
  5. * Copyright (c) 2014 - 2022 Vivante Corporation
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. *
  25. *****************************************************************************
  26. *
  27. * The GPL License (GPL)
  28. *
  29. * Copyright (C) 2014 - 2022 Vivante Corporation
  30. *
  31. * This program is free software; you can redistribute it and/or
  32. * modify it under the terms of the GNU General Public License
  33. * as published by the Free Software Foundation; either version 2
  34. * of the License, or (at your option) any later version.
  35. *
  36. * This program is distributed in the hope that it will be useful,
  37. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  38. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  39. * GNU General Public License for more details.
  40. *
  41. * You should have received a copy of the GNU General Public License
  42. * along with this program; if not, write to the Free Software Foundation,
  43. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  44. *
  45. *****************************************************************************
  46. *
  47. * Note: This software is released under dual MIT and GPL licenses. A
  48. * recipient may use this file under the terms of either the MIT license or
  49. * GPL License. If you wish to use only one license not the other, you can
  50. * indicate your decision by deleting one of the above license notices in your
  51. * version of this file.
  52. *
  53. *****************************************************************************/
  54. #ifndef _vg_lite_hal_h_
  55. #define _vg_lite_hal_h_
  56. #define VGLITE_MEM_ALIGNMENT 128
  57. #define VGLITE_EVENT_FRAME_END 2
  58. #ifdef __cplusplus
  59. extern "C" {
  60. #endif
  61. /*!
  62. @brief Wait a number of milliseconds.
  63. @discussion
  64. The VGLite hardware requires some waiting when changing clock frequencies or issuing a reset. This is the wrapper function
  65. for the delay function.
  66. @param milliseconds
  67. The number of milliseconds to wait.
  68. */
  69. void vg_lite_hal_delay(uint32_t milliseconds);
  70. /*!
  71. @brief Initialize the hardware.
  72. @discussion
  73. The VGLite kernel knows how to program its own hardware, but in any SOC there might be additional control required for
  74. turning on the power or initializing the clocks. This function gets called by the VGLite kernel before the VGLite graphics
  75. hardware gets initialized by the VGLite kernel itself and allows for SOC power management control.
  76. The implementer should make sure that on exit of this function the power and clock to the VGLite graphics hardware is
  77. turned on and stable.
  78. */
  79. void vg_lite_hal_initialize(void);
  80. /*!
  81. @brief Uninitialize the hardware.
  82. @discussion
  83. The VGLite kernel knows how to program its own hardware, but in any SOC there might be additional control required for
  84. turning off the power or uninitializing the clocks. This function gets called by the VGLite kernel after the VGLite
  85. graphics hardware gets uninitialized by the VGLite kernel itself and allows for SOC power management control.
  86. On exit of this function it is okay to have the power and/or clock to the VGLite graphics hardware turned off.
  87. */
  88. void vg_lite_hal_deinitialize(void);
  89. /*!
  90. @brief Allocate contiguous video memory.
  91. @discussion
  92. Any memory the VGLite graphics hardware will see should be allocated as contiguous memory. Any allocated memory will be
  93. addressed through an opaque handle, usually a pointer to an opaque structure. The porting layer can put any information it
  94. needs inside this structure.
  95. @param size
  96. The number of bytes to allocate.
  97. @param pool
  98. select the reserved memory pool
  99. @param logical
  100. A pointer to a variable that will receive the logical address of the allocated memory for the CPU.
  101. @param gpu
  102. A pointer to a variable that will receive the physical address of the allocated memory for the VGLite graphics hardware.
  103. @result
  104. A pointer to an opaque structure that will be used as the memory handle. NULL should be returned if there is not
  105. enough memory.
  106. */
  107. vg_lite_error_t vg_lite_hal_allocate_contiguous(unsigned long size, vg_lite_vidmem_pool_t pool, void **logical, void **klogical, uint32_t *physical, void **node);
  108. /*!
  109. @brief Free contiguous video memory.
  110. @discussion
  111. Free the memory allocated by {@link vg_lite_hal_allocate_contiguous}. After this function returns, the associated memory
  112. handle is no longer a valid handle.
  113. @param memory_handle
  114. A pointer to an opaque structure returned by {@link vg_lite_hal_allocate_contiguous}.
  115. */
  116. void vg_lite_hal_free_contiguous(void * memory_handle);
  117. /*!
  118. @brief remove unfree node when continuously allocate buffer without free buffer.
  119. @discussion
  120. Free the node allocated by {@link kmalloc}. After this function returns, the associated memory
  121. handle is no longer a valid handle.
  122. */
  123. void vg_lite_hal_free_os_heap(void);
  124. /*!
  125. @brief Map contiguous logical or physical memory into the VGLite graphics hardware space.
  126. @discussion
  127. Any memory, like a frame buffer or some pre-allocated image or path data, needs to be mapped into the VGLite graphics
  128. hardware address space and wrapped by a memory handle. This allows the VGLite graphics hardware access that memory
  129. directly.
  130. Either a logical or a physical address should be passed in to map.
  131. @param size
  132. The number of bytes to map.
  133. @param logical
  134. The logical address of the memory region to map or NULL if the logical address is not known.
  135. @param physical
  136. The physical address of the memory region to map if logical is NULL.
  137. @param gpu
  138. A pointer to a variable that will receive the VGLite graphics hardware addressable address of the mapped region.
  139. @result
  140. A pointer to an opaque structure that will be used as the memory handle. NULL should be returned if there is
  141. not enough system resources to map the region.
  142. */
  143. void * vg_lite_hal_map(uint32_t flags, uint32_t bytes, void *logical, uint32_t physical, int32_t dma_buf_fd, uint32_t *gpu);
  144. /*!
  145. @brief Unmap a previously mapped region.
  146. @discussion
  147. If a mapped region by {@link vg_lite_hal_map} is no longer needed, it should be unmapped to free up any allocated system
  148. resources used when mapping the region.
  149. @param memory_handle
  150. A pointer to an opaque structure returned by {@link vg_lite_hal_map}.
  151. */
  152. void vg_lite_hal_unmap(void *memory_handle);
  153. /*!
  154. @brief Execute a memory barrier.
  155. @discussion
  156. Some systems require a a memory barrier to make sure all store operations in the CPU have been handled. This is the wrapper
  157. function for a memory barrier.
  158. */
  159. void vg_lite_hal_barrier(void);
  160. /*!
  161. @brief Read data from a register from the VGLite graphics hardware.
  162. @discussion
  163. In order to communicate with the VGLite graphics hardware, the kernel needs to read and write to some hardware registers.
  164. In each SOC those registers could be allocated at a different space in the physical memory map.
  165. @param address
  166. The relative address of the VGLite graphics hardware register to read from.
  167. @result
  168. The 32-bit value returned from reading the register.
  169. */
  170. uint32_t vg_lite_hal_peek(uint32_t address);
  171. /*!
  172. @brief Write data to a register from the VGLite graphics hardware.
  173. @discussion
  174. In order to communicate with the VGLite graphics hardware, the kernel needs to read and write to some hardware registers.
  175. In each SOC those registers could be allocated at a different space in the physical memory map.
  176. @param address
  177. The relative address of the VGLite graphics hardware register to write to.
  178. @param data
  179. The data to write to the VGLite graphics hardware register.
  180. */
  181. void vg_lite_hal_poke(uint32_t address, uint32_t data);
  182. /*!
  183. @brief query the remaining allocate contiguous video memory.
  184. @param data
  185. The data to get the remaining allocate contiguous video memory bytes.
  186. */
  187. vg_lite_error_t vg_lite_hal_query_mem(vg_lite_kernel_mem_t *mem);
  188. /*!
  189. @brief Map contiguous physical memory into the user space.
  190. @param node
  191. This node have 3 attributes, bytes means the number of bytes to map.
  192. physical means the physical address of the memory region to map.logical means
  193. the return logical address of the memory region after map.
  194. */
  195. vg_lite_error_t vg_lite_hal_map_memory(vg_lite_kernel_map_memory_t *node);
  196. /*!
  197. @brief Unmap a previously mapped region.
  198. @param node
  199. This node have 2 attributes, bytes means the number of bytes to unmap.logical means
  200. the logical address of the memory region to unmap.
  201. */
  202. vg_lite_error_t vg_lite_hal_unmap_memory(vg_lite_kernel_unmap_memory_t *node);
  203. /*!
  204. @brief Wait until an interrupt from the VGLite graphics hardware has been received.
  205. @discussion
  206. Currently, the VGLite API is synchronous. This means that after each call it will wait until the VGLite graphics hardware
  207. has completed. The VGLite graphics hardware will send an interrupt when it is finished, and this function will wait until
  208. that interrupt has been received by the operating system.
  209. A timeout value is specified in order if the kernel wants to wait for a specific number of milliseconds fir the interrupt to
  210. occur. If the interrupt does not occur in the specified timeout, a timeout error will be returned.
  211. @param timeout
  212. The number of milliseconds to wait for the interrupt before returning a timeout error. If timeout = 0xFFFFFFFF
  213. then {@link vg_lite_hal_wait_interrupt} will wait forever for the interrupt.
  214. @param mask
  215. Irq event mask to wait for.
  216. @result
  217. A boolean value indicating whether the interrupt was received (1) or not (0).
  218. */
  219. int32_t vg_lite_hal_wait_interrupt(uint32_t timeout, uint32_t mask, uint32_t *value);
  220. /*!
  221. @brief After call vg_lite_hal_map(), flush cpu cache according the direction
  222. spicified by parameter cache_op.
  223. */
  224. vg_lite_error_t vg_lite_hal_operation_cache(void *handle, vg_lite_cache_op_t cache_op);
  225. /*!
  226. @brief export memory to dma buf, and get the dma buf fd
  227. */
  228. vg_lite_error_t vg_lite_hal_memory_export(int32_t *fd);
  229. /*!
  230. @brief print message
  231. */
  232. void vg_lite_hal_print(char *format, ...);
  233. /*!
  234. @brief trace message
  235. */
  236. void vg_lite_hal_trace(char *format, ...);
  237. /*!
  238. @brief error number to string
  239. */
  240. const char* vg_lite_hal_Status2Name(vg_lite_error_t status);
  241. /*!
  242. @brief allocate virtual memory from os
  243. */
  244. vg_lite_error_t vg_lite_hal_allocate(uint32_t size, void **memory);
  245. /*!
  246. @brief free virtual memory
  247. */
  248. vg_lite_error_t vg_lite_hal_free(void *memory);
  249. /*!
  250. @brief set gpu execute state
  251. */
  252. void vg_lite_set_gpu_execute_state(vg_lite_gpu_execute_state_t state);
  253. /*!
  254. @brief set gpu clock state
  255. */
  256. void vg_lite_set_gpu_clock_state(int enabled);
  257. #ifdef __cplusplus
  258. }
  259. #endif
  260. #endif /* _vg_lite_hal_h_ */