vg_lite_kernel.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. /****************************************************************************
  2. *
  3. * The MIT License (MIT)
  4. *
  5. * Copyright (c) 2014 - 2020 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. #ifndef _vg_lite_kernel_h_
  27. #define _vg_lite_kernel_h_
  28. #include "vg_lite_os.h"
  29. /* Interrupt IDs from GPU. */
  30. #define EVENT_UNEXPECTED_MESH 0x80000000
  31. #define EVENT_CMD_BAD_WRITE 0x40000000
  32. #define EVENT_ERROR_RECOVER 0x20000000
  33. #define EVENT_CMD_SWITCH 0x10000000
  34. #define EVENT_MCU_BAD_WRITE 0x08000000
  35. #define EVENT_END 0
  36. #define MAX_CONTIGUOUS_SIZE 0x02000000
  37. #define VG_LITE_INFINITE 0xFFFFFFFF
  38. #define VG_LITE_MAX_WAIT_TIME 0x130000
  39. #define CMDBUF_COUNT 2
  40. #define VG_LITE_ALIGN(number, alignment) \
  41. (((number) + ((alignment) - 1)) & ~((alignment) - 1))
  42. /* Available function optimization levels */
  43. #if (defined(__ICCARM__))
  44. #define VG_LITE_ATTR_OPTIMIZE_LOW _Pragma("optimize=none")
  45. #define VG_LITE_ATTR_OPTIMIZE_MEDIUM _Pragma("optimize=medium")
  46. #define VG_LITE_ATTR_OPTIMIZE_HIGH _Pragma("optimize=high")
  47. #else /* ARMGCC */
  48. #define VG_LITE_ATTR_OPTIMIZE_LOW __attribute__((optimize(1)))
  49. #define VG_LITE_ATTR_OPTIMIZE_MEDIUM __attribute__((optimize(2)))
  50. #define VG_LITE_ATTR_OPTIMIZE_HIGH __attribute__((optimize(3)))
  51. #endif /* defined(__ICCARM__) */
  52. /* Allow develpers to force a function optimization level */
  53. #define VG_LITE_OPTIMIZE(level) VG_LITE_ATTR_OPTIMIZE_##level
  54. #define VG_LITE_KERNEL_IS_GPU_IDLE() \
  55. ((vg_lite_hal_peek(VG_LITE_HW_IDLE) & VG_LITE_HW_IDLE_STATE) == VG_LITE_HW_IDLE_STATE)
  56. /* Hardware chip Ids */
  57. #define GPU_CHIP_ID_GCNanoliteV 0x255
  58. #define GPU_CHIP_ID_GC355 0x355
  59. #ifdef __cplusplus
  60. extern "C" {
  61. #endif
  62. #ifndef VG_LITE_ERROR
  63. #define VG_LITE_ERROR 1
  64. /*!
  65. @abstract Error codes that the vg_lite functions can return.
  66. @discussion
  67. All API functions return a status code. On success, <code>VG_LITE_SUCCESS</code> will be returned when a function is
  68. successful. This value is set to zero, so if any function returns a non-zero value, an error has occured.
  69. */
  70. typedef enum vg_lite_error
  71. {
  72. VG_LITE_SUCCESS = 0, /*! Success. */
  73. VG_LITE_INVALID_ARGUMENT, /*! An invalid argument was specified. */
  74. VG_LITE_OUT_OF_MEMORY, /*! Out of memory. */
  75. VG_LITE_NO_CONTEXT, /*! No context or an unintialized context specified. */
  76. VG_LITE_TIMEOUT, /*! A timeout has occured during a wait. */
  77. VG_LITE_OUT_OF_RESOURCES, /*! Out of system resources. */
  78. VG_LITE_GENERIC_IO, /*! Cannot communicate with the kernel driver. */
  79. VG_LITE_NOT_SUPPORT, /*! Function call not supported. */
  80. VG_LITE_MULTI_THREAD_FAIL, /*! Multi-thread/tasks fail. */
  81. VG_LITE_ALREADY_EXISTS, /*! Object already exists */
  82. VG_LITE_NOT_ALIGNED, /*! Data alignment error */
  83. }
  84. vg_lite_error_t;
  85. #endif
  86. #if !defined(VG_DRIVER_SINGLE_THREAD)
  87. typedef enum vg_lite_buffer_signal
  88. {
  89. VG_LITE_IDLE = 0, /*! Buffer available. */
  90. VG_LITE_HW_FINISHED, /*! HW has completed command buffer. */
  91. VG_LITE_IN_QUEUE, /*! Buffer has been send to queue. */
  92. }
  93. vg_lite_buffer_signal_t;
  94. #endif /* not defined(VG_DRIVER_SINGLE_THREAD) */
  95. typedef enum vg_lite_kernel_counter
  96. {
  97. /* Dont't touch the counter. */
  98. VG_LITE_NONE,
  99. /* Turn the counter on. */
  100. VG_LITE_ON,
  101. /* Turn the counter off. */
  102. VG_LITE_OFF,
  103. /* Query the counter and reset its values. */
  104. VG_LITE_QUERY,
  105. }
  106. vg_lite_kernel_counter_t;
  107. typedef enum vg_lite_kernel_command
  108. {
  109. /* Initialize the GPU. */
  110. VG_LITE_INITIALIZE,
  111. /* Terminate the GPU. */
  112. VG_LITE_TERMINATE,
  113. /* Allocate memory. */
  114. VG_LITE_ALLOCATE,
  115. /* Free memory. */
  116. VG_LITE_FREE,
  117. /* Submit a command buffer to the GPU. */
  118. VG_LITE_SUBMIT,
  119. /* Wait for the GPU to be completed. */
  120. VG_LITE_WAIT,
  121. /* Reset the GPU. */
  122. VG_LITE_RESET,
  123. /* Debug commands. */
  124. VG_LITE_DEBUG,
  125. /* Map memory. */
  126. VG_LITE_MAP,
  127. /* Unmap memory. */
  128. VG_LITE_UNMAP,
  129. /* Check info. */
  130. VG_LITE_CHECK,
  131. /* Query mem. */
  132. VG_LITE_QUERY_MEM,
  133. #if !defined(VG_DRIVER_SINGLE_THREAD)
  134. /* Mutex lock. */
  135. VG_LITE_LOCK,
  136. /* Mutex unlock. */
  137. VG_LITE_UNLOCK,
  138. /* query context switch. */
  139. VG_LITE_QUERY_CONTEXT_SWITCH,
  140. #endif /* not defined(VG_DRIVER_SINGLE_THREAD) */
  141. }
  142. vg_lite_kernel_command_t;
  143. struct vg_lite_kernel_context {
  144. /* Command buffer. */
  145. void * command_buffer[CMDBUF_COUNT];
  146. void * command_buffer_logical[CMDBUF_COUNT];
  147. uint32_t command_buffer_physical[CMDBUF_COUNT];
  148. #if !defined(VG_DRIVER_SINGLE_THREAD)
  149. vg_lite_os_async_event_t async_event[CMDBUF_COUNT];
  150. #endif /* not defined(VG_DRIVER_SINGLE_THREAD) */
  151. /* Tessellation buffer. */
  152. void * tessellation_buffer;
  153. void * tessellation_buffer_logical;
  154. uint32_t tessellation_buffer_physical;
  155. #if !defined(VG_DRIVER_SINGLE_THREAD)
  156. /* context buffer. */
  157. void * context_buffer[CMDBUF_COUNT];
  158. void * context_buffer_logical[CMDBUF_COUNT];
  159. uint32_t context_buffer_physical[CMDBUF_COUNT];
  160. #endif /* not defined(VG_DRIVER_SINGLE_THREAD) */
  161. };
  162. /* Context structure. */
  163. typedef struct vg_lite_kernel_context vg_lite_kernel_context_t;
  164. typedef struct capabilities
  165. {
  166. uint32_t tiled : 2;
  167. uint32_t l2_cache : 1;
  168. }
  169. capabilities_t;
  170. typedef union vg_lite_capabilities
  171. {
  172. capabilities_t cap;
  173. uint32_t data;
  174. }
  175. vg_lite_capabilities_t;
  176. typedef struct vg_lite_kernel_initialize
  177. {
  178. /* Command buffer size. */
  179. uint32_t command_buffer_size;
  180. #if !defined(VG_DRIVER_SINGLE_THREAD)
  181. /* Context buffer size. */
  182. uint32_t context_buffer_size;
  183. #endif /* not defined(VG_DRIVER_SINGLE_THREAD) */
  184. /* Tessellation buffer width. */
  185. int32_t tessellation_width;
  186. /* Tessellation buffer height. */
  187. int32_t tessellation_height;
  188. /* OUTPUT */
  189. /* Context pointer. */
  190. vg_lite_kernel_context_t * context;
  191. /* Capabilities. */
  192. vg_lite_capabilities_t capabilities;
  193. /* Allocated command buffer. */
  194. void * command_buffer[CMDBUF_COUNT];
  195. /* GPU address for command buffer. */
  196. uint32_t command_buffer_gpu[CMDBUF_COUNT];
  197. #if !defined(VG_DRIVER_SINGLE_THREAD)
  198. /* Allocated context buffer. */
  199. void * context_buffer[CMDBUF_COUNT];
  200. /* GPU address for context buffer. */
  201. uint32_t context_buffer_gpu[CMDBUF_COUNT];
  202. #endif /* not defined(VG_DRIVER_SINGLE_THREAD) */
  203. /* GPU addresses for tesselation buffers. */
  204. uint32_t tessellation_buffer_gpu[3];
  205. /* Logic addresses for tessellation buffers: used by SW Tessellator. */
  206. uint8_t *tessellation_buffer_logic[3];
  207. /* Size of each level of the tesselation buffer. */
  208. uint32_t tessellation_buffer_size[3];
  209. /* Stride of the tessellation buffer. */
  210. uint32_t tessellation_stride;
  211. /* Width and height of tessellation buffer. */
  212. uint32_t tessellation_width_height;
  213. /* Tessellation config: shift. */
  214. uint32_t tessellation_shift;
  215. }
  216. vg_lite_kernel_initialize_t;
  217. typedef struct vg_lite_kernel_terminate
  218. {
  219. /* Context to terminate. */
  220. vg_lite_kernel_context_t * context;
  221. }
  222. vg_lite_kernel_terminate_t;
  223. typedef struct vg_lite_kernel_allocate
  224. {
  225. /* Number of bytes to allocate. */
  226. uint32_t bytes;
  227. /* Flag to indicate whether the allocated memory is contiguous or not. */
  228. int32_t contiguous;
  229. /* OUTPUT */
  230. /* Memory handle. */
  231. void * memory_handle;
  232. /* Allocated memory. */
  233. void * memory;
  234. /* GPU address of allocated memory. */
  235. uint32_t memory_gpu;
  236. }
  237. vg_lite_kernel_allocate_t;
  238. typedef struct vg_lite_kernel_free
  239. {
  240. /* Memory handle to free. */
  241. void * memory_handle;
  242. }
  243. vg_lite_kernel_free_t;
  244. typedef struct vg_lite_kernel_submit
  245. {
  246. /* Context to submit to. */
  247. vg_lite_kernel_context_t * context;
  248. /* Pointer to command buffer. */
  249. void * commands;
  250. /* Number of bytes in command buffer. */
  251. uint32_t command_size;
  252. /* Command Buffer ID. */
  253. uint32_t command_id;
  254. }
  255. vg_lite_kernel_submit_t;
  256. typedef struct vg_lite_kernel_wait
  257. {
  258. /* Context to wait for. */
  259. vg_lite_kernel_context_t * context;
  260. /* Timeout in milliseconds. */
  261. uint32_t timeout_ms;
  262. #if defined(VG_DRIVER_SINGLE_THREAD)
  263. /* The event to wait. */
  264. uint32_t event_mask;
  265. /* The event(s) got after waiting. */
  266. uint32_t event_got;
  267. #else
  268. /* Command Buffer ID. */
  269. uint32_t command_id;
  270. #endif /* VG_DRIVER_SINGLE_THREAD */
  271. }
  272. vg_lite_kernel_wait_t;
  273. typedef struct vg_lite_kernel_reset
  274. {
  275. /* Context to reset. */
  276. vg_lite_kernel_context_t * context;
  277. }
  278. vg_lite_kernel_reset_t;
  279. typedef struct vg_lite_kernel_debug
  280. {
  281. /* Context to debug. */
  282. vg_lite_kernel_context_t * context;
  283. /* Bandwidth counter enabler. */
  284. vg_lite_kernel_counter_t bandwidth_counter;
  285. /* Pixel counter enabler. */
  286. vg_lite_kernel_counter_t pixel_counters;
  287. /* OUTPUT */
  288. /* Bandwidth counters:
  289. * [0] - burst of 8.
  290. * [1] - burst of 16.
  291. * [2] - burst of 32.
  292. * [3] - burst of 64.
  293. */
  294. uint32_t bandwidth[4];
  295. /* Pixel counters:.
  296. * [0] - Number of tessellated pixels.
  297. * [1] - Number of imaged pixels.
  298. * [2] - Number of rendered pixels.
  299. */
  300. uint32_t pixels[3];
  301. }
  302. vg_lite_kernel_debug_t;
  303. typedef struct vg_lite_kernel_map
  304. {
  305. /* Number of bytes to map. */
  306. uint32_t bytes;
  307. /* Logical memory address or NULL. */
  308. void * logical;
  309. /* Physical memory address or 0. */
  310. uint32_t physical;
  311. /* OUTPUT */
  312. /* Memory handle for mapped memory. */
  313. void * memory_handle;
  314. /* GPU address of mapped memory. */
  315. uint32_t memory_gpu;
  316. }
  317. vg_lite_kernel_map_t;
  318. typedef struct vg_lite_kernel_unmap
  319. {
  320. /* Memory handle to unmap. */
  321. void * memory_handle;
  322. }
  323. vg_lite_kernel_unmap_t;
  324. typedef struct vg_lite_kernel_info
  325. {
  326. /* Register's address. */
  327. uint32_t addr;
  328. /* Check register info. */
  329. uint32_t reg;
  330. }
  331. vg_lite_kernel_info_t;
  332. typedef struct vg_lite_kernel_mem
  333. {
  334. uint32_t bytes;
  335. }
  336. vg_lite_kernel_mem_t;
  337. #if !defined(VG_DRIVER_SINGLE_THREAD)
  338. typedef struct vg_lite_kernel_context_switch
  339. {
  340. uint8_t isContextSwitched;
  341. uint32_t context;
  342. }
  343. vg_lite_kernel_context_switch_t;
  344. #endif /* not defined(VG_DRIVER_SINGLE_THREAD) */
  345. vg_lite_error_t vg_lite_kernel(vg_lite_kernel_command_t command, void * data);
  346. #ifdef __cplusplus
  347. }
  348. #endif
  349. #endif /* _vg_lite_kernel_h_ */