rocket_accel.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /* SPDX-License-Identifier: MIT */
  2. /*
  3. * Copyright © 2024 Tomeu Vizoso
  4. */
  5. #ifndef __DRM_UAPI_ROCKET_ACCEL_H__
  6. #define __DRM_UAPI_ROCKET_ACCEL_H__
  7. #include "drm.h"
  8. #if defined(__cplusplus)
  9. extern "C" {
  10. #endif
  11. #define DRM_ROCKET_CREATE_BO 0x00
  12. #define DRM_ROCKET_SUBMIT 0x01
  13. #define DRM_ROCKET_PREP_BO 0x02
  14. #define DRM_ROCKET_FINI_BO 0x03
  15. #define DRM_IOCTL_ROCKET_CREATE_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_ROCKET_CREATE_BO, struct drm_rocket_create_bo)
  16. #define DRM_IOCTL_ROCKET_SUBMIT DRM_IOW(DRM_COMMAND_BASE + DRM_ROCKET_SUBMIT, struct drm_rocket_submit)
  17. #define DRM_IOCTL_ROCKET_PREP_BO DRM_IOW(DRM_COMMAND_BASE + DRM_ROCKET_PREP_BO, struct drm_rocket_prep_bo)
  18. #define DRM_IOCTL_ROCKET_FINI_BO DRM_IOW(DRM_COMMAND_BASE + DRM_ROCKET_FINI_BO, struct drm_rocket_fini_bo)
  19. /**
  20. * struct drm_rocket_create_bo - ioctl argument for creating Rocket BOs.
  21. *
  22. */
  23. struct drm_rocket_create_bo {
  24. /**
  25. * @size: Input: Size of the requested BO.
  26. */
  27. __u32 size;
  28. /**
  29. * @handle: Output: GEM handle for the BO.
  30. */
  31. __u32 handle;
  32. /**
  33. * @dma_address: Output: DMA address for the BO in the NPU address
  34. * space. This address is private to the DRM fd and is valid for
  35. * the lifetime of the GEM handle.
  36. */
  37. __u64 dma_address;
  38. /**
  39. * @offset: Output: Offset into the drm node to use for subsequent
  40. * mmap call.
  41. */
  42. __u64 offset;
  43. };
  44. /**
  45. * struct drm_rocket_prep_bo - ioctl argument for starting CPU ownership of the BO.
  46. *
  47. * Takes care of waiting for any NPU jobs that might still use the NPU and performs cache
  48. * synchronization.
  49. */
  50. struct drm_rocket_prep_bo {
  51. /**
  52. * @handle: Input: GEM handle of the buffer object.
  53. */
  54. __u32 handle;
  55. /**
  56. * @reserved: Reserved, must be zero.
  57. */
  58. __u32 reserved;
  59. /**
  60. * @timeout_ns: Input: Amount of time to wait for NPU jobs.
  61. */
  62. __s64 timeout_ns;
  63. };
  64. /**
  65. * struct drm_rocket_fini_bo - ioctl argument for finishing CPU ownership of the BO.
  66. *
  67. * Synchronize caches for NPU access.
  68. */
  69. struct drm_rocket_fini_bo {
  70. /**
  71. * @handle: Input: GEM handle of the buffer object.
  72. */
  73. __u32 handle;
  74. /**
  75. * @reserved: Reserved, must be zero.
  76. */
  77. __u32 reserved;
  78. };
  79. /**
  80. * struct drm_rocket_task - A task to be run on the NPU
  81. *
  82. * A task is the smallest unit of work that can be run on the NPU.
  83. */
  84. struct drm_rocket_task {
  85. /**
  86. * @regcmd: Input: DMA address to NPU mapping of register command buffer
  87. */
  88. __u32 regcmd;
  89. /**
  90. * @regcmd_count: Input: Number of commands in the register command
  91. * buffer
  92. */
  93. __u32 regcmd_count;
  94. };
  95. /**
  96. * struct drm_rocket_job - A job to be run on the NPU
  97. *
  98. * The kernel will schedule the execution of this job taking into account its
  99. * dependencies with other jobs. All tasks in the same job will be executed
  100. * sequentially on the same core, to benefit from memory residency in SRAM.
  101. */
  102. struct drm_rocket_job {
  103. /**
  104. * @tasks: Input: Pointer to an array of struct drm_rocket_task.
  105. */
  106. __u64 tasks;
  107. /**
  108. * @in_bo_handles: Input: Pointer to a u32 array of the BOs that
  109. * are read by the job.
  110. */
  111. __u64 in_bo_handles;
  112. /**
  113. * @out_bo_handles: Input: Pointer to a u32 array of the BOs that
  114. * are written to by the job.
  115. */
  116. __u64 out_bo_handles;
  117. /**
  118. * @task_count: Input: Number of tasks passed in.
  119. */
  120. __u32 task_count;
  121. /**
  122. * @task_struct_size: Input: Size in bytes of the structs in the
  123. * @tasks field.
  124. */
  125. __u32 task_struct_size;
  126. /**
  127. * @in_bo_handle_count: Input: Number of input BO handles passed in
  128. * (size is that times 4).
  129. */
  130. __u32 in_bo_handle_count;
  131. /**
  132. * @out_bo_handle_count: Input: Number of output BO handles passed in
  133. * (size is that times 4).
  134. */
  135. __u32 out_bo_handle_count;
  136. };
  137. /**
  138. * struct drm_rocket_submit - ioctl argument for submitting commands to the NPU.
  139. *
  140. * The kernel will schedule the execution of these jobs in dependency order.
  141. */
  142. struct drm_rocket_submit {
  143. /**
  144. * @jobs: Input: Pointer to an array of struct drm_rocket_job.
  145. */
  146. __u64 jobs;
  147. /**
  148. * @job_count: Input: Number of jobs passed in.
  149. */
  150. __u32 job_count;
  151. /**
  152. * @job_struct_size: Input: Size in bytes of the structs in the
  153. * @jobs field.
  154. */
  155. __u32 job_struct_size;
  156. /**
  157. * @reserved: Reserved, must be zero.
  158. */
  159. __u64 reserved;
  160. };
  161. #if defined(__cplusplus)
  162. }
  163. #endif
  164. #endif /* __DRM_UAPI_ROCKET_ACCEL_H__ */