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