ethosu_accel.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /* SPDX-License-Identifier: MIT */
  2. /* Copyright (C) 2025 Arm, Ltd. */
  3. #ifndef _ETHOSU_DRM_H_
  4. #define _ETHOSU_DRM_H_
  5. #include "drm.h"
  6. #if defined(__cplusplus)
  7. extern "C" {
  8. #endif
  9. /**
  10. * DOC: IOCTL IDs
  11. *
  12. * enum drm_ethosu_ioctl_id - IOCTL IDs
  13. *
  14. * Place new ioctls at the end, don't re-order, don't replace or remove entries.
  15. *
  16. * These IDs are not meant to be used directly. Use the DRM_IOCTL_ETHOSU_xxx
  17. * definitions instead.
  18. */
  19. enum drm_ethosu_ioctl_id {
  20. /** @DRM_ETHOSU_DEV_QUERY: Query device information. */
  21. DRM_ETHOSU_DEV_QUERY = 0,
  22. /** @DRM_ETHOSU_BO_CREATE: Create a buffer object. */
  23. DRM_ETHOSU_BO_CREATE,
  24. /** @DRM_ETHOSU_BO_WAIT: Wait on a buffer object's fence. */
  25. DRM_ETHOSU_BO_WAIT,
  26. /**
  27. * @DRM_ETHOSU_BO_MMAP_OFFSET: Get the file offset to pass to
  28. * mmap to map a GEM object.
  29. */
  30. DRM_ETHOSU_BO_MMAP_OFFSET,
  31. /**
  32. * @DRM_ETHOSU_CMDSTREAM_BO_CREATE: Create a command stream buffer
  33. * object.
  34. */
  35. DRM_ETHOSU_CMDSTREAM_BO_CREATE,
  36. /** @DRM_ETHOSU_SUBMIT: Submit a job and BOs to run. */
  37. DRM_ETHOSU_SUBMIT,
  38. };
  39. /**
  40. * DOC: IOCTL arguments
  41. */
  42. /**
  43. * enum drm_ethosu_dev_query_type - Query type
  44. *
  45. * Place new types at the end, don't re-order, don't remove or replace.
  46. */
  47. enum drm_ethosu_dev_query_type {
  48. /** @DRM_ETHOSU_DEV_QUERY_NPU_INFO: Query NPU information. */
  49. DRM_ETHOSU_DEV_QUERY_NPU_INFO = 0,
  50. };
  51. /**
  52. * struct drm_ethosu_gpu_info - NPU information
  53. *
  54. * Structure grouping all queryable information relating to the NPU.
  55. */
  56. struct drm_ethosu_npu_info {
  57. /** @id : NPU ID. */
  58. __u32 id;
  59. #define DRM_ETHOSU_ARCH_MAJOR(x) ((x) >> 28)
  60. #define DRM_ETHOSU_ARCH_MINOR(x) (((x) >> 20) & 0xff)
  61. #define DRM_ETHOSU_ARCH_PATCH(x) (((x) >> 16) & 0xf)
  62. #define DRM_ETHOSU_PRODUCT_MAJOR(x) (((x) >> 12) & 0xf)
  63. #define DRM_ETHOSU_VERSION_MAJOR(x) (((x) >> 8) & 0xf)
  64. #define DRM_ETHOSU_VERSION_MINOR(x) (((x) >> 4) & 0xff)
  65. #define DRM_ETHOSU_VERSION_STATUS(x) ((x) & 0xf)
  66. /** @gpu_rev: GPU revision. */
  67. __u32 config;
  68. __u32 sram_size;
  69. };
  70. /**
  71. * struct drm_ethosu_dev_query - Arguments passed to DRM_ETHOSU_IOCTL_DEV_QUERY
  72. */
  73. struct drm_ethosu_dev_query {
  74. /** @type: the query type (see drm_ethosu_dev_query_type). */
  75. __u32 type;
  76. /**
  77. * @size: size of the type being queried.
  78. *
  79. * If pointer is NULL, size is updated by the driver to provide the
  80. * output structure size. If pointer is not NULL, the driver will
  81. * only copy min(size, actual_structure_size) bytes to the pointer,
  82. * and update the size accordingly. This allows us to extend query
  83. * types without breaking userspace.
  84. */
  85. __u32 size;
  86. /**
  87. * @pointer: user pointer to a query type struct.
  88. *
  89. * Pointer can be NULL, in which case, nothing is copied, but the
  90. * actual structure size is returned. If not NULL, it must point to
  91. * a location that's large enough to hold size bytes.
  92. */
  93. __u64 pointer;
  94. };
  95. /**
  96. * enum drm_ethosu_bo_flags - Buffer object flags, passed at creation time.
  97. */
  98. enum drm_ethosu_bo_flags {
  99. /**
  100. * @DRM_ETHOSU_BO_NO_MMAP: The buffer object will never be CPU-mapped
  101. * in userspace.
  102. */
  103. DRM_ETHOSU_BO_NO_MMAP = (1 << 0),
  104. };
  105. /**
  106. * struct drm_ethosu_bo_create - Arguments passed to DRM_IOCTL_ETHOSU_BO_CREATE.
  107. */
  108. struct drm_ethosu_bo_create {
  109. /**
  110. * @size: Requested size for the object
  111. *
  112. * The (page-aligned) allocated size for the object will be returned.
  113. */
  114. __u64 size;
  115. /**
  116. * @flags: Flags. Must be a combination of drm_ethosu_bo_flags flags.
  117. */
  118. __u32 flags;
  119. /**
  120. * @handle: Returned handle for the object.
  121. *
  122. * Object handles are nonzero.
  123. */
  124. __u32 handle;
  125. };
  126. /**
  127. * struct drm_ethosu_bo_mmap_offset - Arguments passed to DRM_IOCTL_ETHOSU_BO_MMAP_OFFSET.
  128. */
  129. struct drm_ethosu_bo_mmap_offset {
  130. /** @handle: Handle of the object we want an mmap offset for. */
  131. __u32 handle;
  132. /** @pad: MBZ. */
  133. __u32 pad;
  134. /** @offset: The fake offset to use for subsequent mmap calls. */
  135. __u64 offset;
  136. };
  137. /**
  138. * struct drm_ethosu_wait_bo - ioctl argument for waiting for
  139. * completion of the last DRM_ETHOSU_SUBMIT on a BO.
  140. *
  141. * This is useful for cases where multiple processes might be
  142. * rendering to a BO and you want to wait for all rendering to be
  143. * completed.
  144. */
  145. struct drm_ethosu_bo_wait {
  146. __u32 handle;
  147. __u32 pad;
  148. __s64 timeout_ns; /* absolute */
  149. };
  150. struct drm_ethosu_cmdstream_bo_create {
  151. /* Size of the data argument. */
  152. __u32 size;
  153. /* Flags, currently must be 0. */
  154. __u32 flags;
  155. /* Pointer to the data. */
  156. __u64 data;
  157. /** Returned GEM handle for the BO. */
  158. __u32 handle;
  159. /* Pad, must be 0. */
  160. __u32 pad;
  161. };
  162. /**
  163. * struct drm_ethosu_job - A job to be run on the NPU
  164. *
  165. * The kernel will schedule the execution of this job taking into account its
  166. * dependencies with other jobs. All tasks in the same job will be executed
  167. * sequentially on the same core, to benefit from memory residency in SRAM.
  168. */
  169. struct drm_ethosu_job {
  170. /** Input: BO handle for cmdstream. */
  171. __u32 cmd_bo;
  172. /** Input: Amount of SRAM to use. */
  173. __u32 sram_size;
  174. #define ETHOSU_MAX_REGIONS 8
  175. /** Input: Array of BO handles for each region. */
  176. __u32 region_bo_handles[ETHOSU_MAX_REGIONS];
  177. };
  178. /**
  179. * struct drm_ethosu_submit - ioctl argument for submitting commands to the NPU.
  180. *
  181. * The kernel will schedule the execution of these jobs in dependency order.
  182. */
  183. struct drm_ethosu_submit {
  184. /** Input: Pointer to an array of struct drm_ethosu_job. */
  185. __u64 jobs;
  186. /** Input: Number of jobs passed in. */
  187. __u32 job_count;
  188. /** Reserved, must be zero. */
  189. __u32 pad;
  190. };
  191. /**
  192. * DRM_IOCTL_ETHOSU() - Build a ethosu IOCTL number
  193. * @__access: Access type. Must be R, W or RW.
  194. * @__id: One of the DRM_ETHOSU_xxx id.
  195. * @__type: Suffix of the type being passed to the IOCTL.
  196. *
  197. * Don't use this macro directly, use the DRM_IOCTL_ETHOSU_xxx
  198. * values instead.
  199. *
  200. * Return: An IOCTL number to be passed to ioctl() from userspace.
  201. */
  202. #define DRM_IOCTL_ETHOSU(__access, __id, __type) \
  203. DRM_IO ## __access(DRM_COMMAND_BASE + DRM_ETHOSU_ ## __id, \
  204. struct drm_ethosu_ ## __type)
  205. enum {
  206. DRM_IOCTL_ETHOSU_DEV_QUERY =
  207. DRM_IOCTL_ETHOSU(WR, DEV_QUERY, dev_query),
  208. DRM_IOCTL_ETHOSU_BO_CREATE =
  209. DRM_IOCTL_ETHOSU(WR, BO_CREATE, bo_create),
  210. DRM_IOCTL_ETHOSU_BO_WAIT =
  211. DRM_IOCTL_ETHOSU(WR, BO_WAIT, bo_wait),
  212. DRM_IOCTL_ETHOSU_BO_MMAP_OFFSET =
  213. DRM_IOCTL_ETHOSU(WR, BO_MMAP_OFFSET, bo_mmap_offset),
  214. DRM_IOCTL_ETHOSU_CMDSTREAM_BO_CREATE =
  215. DRM_IOCTL_ETHOSU(WR, CMDSTREAM_BO_CREATE, cmdstream_bo_create),
  216. DRM_IOCTL_ETHOSU_SUBMIT =
  217. DRM_IOCTL_ETHOSU(WR, SUBMIT, submit),
  218. };
  219. #if defined(__cplusplus)
  220. }
  221. #endif
  222. #endif /* _ETHOSU_DRM_H_ */