1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
3 * Copyright (C) 2022-2024, Advanced Micro Devices, Inc.
6 #ifndef _UAPI_AMDXDNA_ACCEL_H_
7 #define _UAPI_AMDXDNA_ACCEL_H_
9 #include <linux/stddef.h>
12 #if defined(__cplusplus)
16 #define AMDXDNA_INVALID_CMD_HANDLE (~0UL)
17 #define AMDXDNA_INVALID_ADDR (~0UL)
18 #define AMDXDNA_INVALID_CTX_HANDLE 0
19 #define AMDXDNA_INVALID_BO_HANDLE 0
20 #define AMDXDNA_INVALID_FENCE_HANDLE 0
22 enum amdxdna_device_type {
23 AMDXDNA_DEV_TYPE_UNKNOWN = -1,
27 enum amdxdna_drm_ioctl_id {
28 DRM_AMDXDNA_CREATE_HWCTX,
29 DRM_AMDXDNA_DESTROY_HWCTX,
30 DRM_AMDXDNA_CONFIG_HWCTX,
31 DRM_AMDXDNA_CREATE_BO,
32 DRM_AMDXDNA_GET_BO_INFO,
36 DRM_AMDXDNA_SET_STATE,
40 * struct qos_info - QoS information for driver.
41 * @gops: Giga operations per second.
42 * @fps: Frames per second.
43 * @dma_bandwidth: DMA bandwidtha.
44 * @latency: Frame response latency.
45 * @frame_exec_time: Frame execution time.
46 * @priority: Request priority.
48 * User program can provide QoS hints to driver.
50 struct amdxdna_qos_info {
55 __u32 frame_exec_time;
60 * struct amdxdna_drm_create_hwctx - Create hardware context.
63 * @qos_p: Address of QoS info.
64 * @umq_bo: BO handle for user mode queue(UMQ).
65 * @log_buf_bo: BO handle for log buffer.
66 * @max_opc: Maximum operations per cycle.
67 * @num_tiles: Number of AIE tiles.
68 * @mem_size: Size of AIE tile memory.
69 * @umq_doorbell: Returned offset of doorbell associated with UMQ.
70 * @handle: Returned hardware context handle.
71 * @syncobj_handle: Returned syncobj handle for command completion.
73 struct amdxdna_drm_create_hwctx {
88 * struct amdxdna_drm_destroy_hwctx - Destroy hardware context.
89 * @handle: Hardware context handle.
92 struct amdxdna_drm_destroy_hwctx {
98 * struct amdxdna_cu_config - configuration for one CU
99 * @cu_bo: CU configuration buffer bo handle.
100 * @cu_func: Function of a CU.
103 struct amdxdna_cu_config {
110 * struct amdxdna_hwctx_param_config_cu - configuration for CUs in hardware context
111 * @num_cus: Number of CUs to configure.
113 * @cu_configs: Array of CU configurations of struct amdxdna_cu_config.
115 struct amdxdna_hwctx_param_config_cu {
118 struct amdxdna_cu_config cu_configs[] __counted_by(num_cus);
121 enum amdxdna_drm_config_hwctx_param {
122 DRM_AMDXDNA_HWCTX_CONFIG_CU,
123 DRM_AMDXDNA_HWCTX_ASSIGN_DBG_BUF,
124 DRM_AMDXDNA_HWCTX_REMOVE_DBG_BUF,
128 * struct amdxdna_drm_config_hwctx - Configure hardware context.
129 * @handle: hardware context handle.
130 * @param_type: Value in enum amdxdna_drm_config_hwctx_param. Specifies the
131 * structure passed in via param_val.
132 * @param_val: A structure specified by the param_type struct member.
133 * @param_val_size: Size of the parameter buffer pointed to by the param_val.
134 * If param_val is not a pointer, driver can ignore this.
137 * Note: if the param_val is a pointer pointing to a buffer, the maximum size
138 * of the buffer is 4KiB(PAGE_SIZE).
140 struct amdxdna_drm_config_hwctx {
144 __u32 param_val_size;
148 enum amdxdna_bo_type {
149 AMDXDNA_BO_INVALID = 0,
157 * struct amdxdna_drm_create_bo - Create a buffer object.
158 * @flags: Buffer flags. MBZ.
159 * @vaddr: User VA of buffer if applied. MBZ.
160 * @size: Size in bytes.
161 * @type: Buffer type.
162 * @handle: Returned DRM buffer object handle.
164 struct amdxdna_drm_create_bo {
173 * struct amdxdna_drm_get_bo_info - Get buffer object information.
176 * @handle: DRM buffer object handle.
178 * @map_offset: Returned DRM fake offset for mmap().
179 * @vaddr: Returned user VA of buffer. 0 in case user needs mmap().
180 * @xdna_addr: Returned XDNA device virtual address.
182 struct amdxdna_drm_get_bo_info {
193 * struct amdxdna_drm_sync_bo - Sync buffer object.
194 * @handle: Buffer object handle.
195 * @direction: Direction of sync, can be from device or to device.
196 * @offset: Offset in the buffer to sync.
197 * @size: Size in bytes.
199 struct amdxdna_drm_sync_bo {
201 #define SYNC_DIRECT_TO_DEVICE 0U
202 #define SYNC_DIRECT_FROM_DEVICE 1U
208 enum amdxdna_cmd_type {
209 AMDXDNA_CMD_SUBMIT_EXEC_BUF = 0,
210 AMDXDNA_CMD_SUBMIT_DEPENDENCY,
211 AMDXDNA_CMD_SUBMIT_SIGNAL,
215 * struct amdxdna_drm_exec_cmd - Execute command.
218 * @hwctx: Hardware context handle.
219 * @type: One of command type in enum amdxdna_cmd_type.
220 * @cmd_handles: Array of command handles or the command handle itself
221 * in case of just one.
222 * @args: Array of arguments for all command handles.
223 * @cmd_count: Number of command handles in the cmd_handles array.
224 * @arg_count: Number of arguments in the args array.
225 * @seq: Returned sequence number for this command.
227 struct amdxdna_drm_exec_cmd {
240 * struct amdxdna_drm_query_aie_status - Query the status of the AIE hardware
241 * @buffer: The user space buffer that will return the AIE status.
242 * @buffer_size: The size of the user space buffer.
243 * @cols_filled: A bitmap of AIE columns whose data has been returned in the buffer.
245 struct amdxdna_drm_query_aie_status {
246 __u64 buffer; /* out */
247 __u32 buffer_size; /* in */
248 __u32 cols_filled; /* out */
252 * struct amdxdna_drm_query_aie_version - Query the version of the AIE hardware
253 * @major: The major version number.
254 * @minor: The minor version number.
256 struct amdxdna_drm_query_aie_version {
257 __u32 major; /* out */
258 __u32 minor; /* out */
262 * struct amdxdna_drm_query_aie_tile_metadata - Query the metadata of AIE tile (core, mem, shim)
263 * @row_count: The number of rows.
264 * @row_start: The starting row number.
265 * @dma_channel_count: The number of dma channels.
266 * @lock_count: The number of locks.
267 * @event_reg_count: The number of events.
268 * @pad: Structure padding.
270 struct amdxdna_drm_query_aie_tile_metadata {
273 __u16 dma_channel_count;
275 __u16 event_reg_count;
280 * struct amdxdna_drm_query_aie_metadata - Query the metadata of the AIE hardware
281 * @col_size: The size of a column in bytes.
282 * @cols: The total number of columns.
283 * @rows: The total number of rows.
284 * @version: The version of the AIE hardware.
285 * @core: The metadata for all core tiles.
286 * @mem: The metadata for all mem tiles.
287 * @shim: The metadata for all shim tiles.
289 struct amdxdna_drm_query_aie_metadata {
293 struct amdxdna_drm_query_aie_version version;
294 struct amdxdna_drm_query_aie_tile_metadata core;
295 struct amdxdna_drm_query_aie_tile_metadata mem;
296 struct amdxdna_drm_query_aie_tile_metadata shim;
300 * struct amdxdna_drm_query_clock - Metadata for a clock
301 * @name: The clock name.
302 * @freq_mhz: The clock frequency.
303 * @pad: Structure padding.
305 struct amdxdna_drm_query_clock {
312 * struct amdxdna_drm_query_clock_metadata - Query metadata for clocks
313 * @mp_npu_clock: The metadata for MP-NPU clock.
314 * @h_clock: The metadata for H clock.
316 struct amdxdna_drm_query_clock_metadata {
317 struct amdxdna_drm_query_clock mp_npu_clock;
318 struct amdxdna_drm_query_clock h_clock;
321 enum amdxdna_sensor_type {
322 AMDXDNA_SENSOR_TYPE_POWER
326 * struct amdxdna_drm_query_sensor - The data for single sensor.
327 * @label: The name for a sensor.
328 * @input: The current value of the sensor.
329 * @max: The maximum value possible for the sensor.
330 * @average: The average value of the sensor.
331 * @highest: The highest recorded sensor value for this driver load for the sensor.
332 * @status: The sensor status.
333 * @units: The sensor units.
334 * @unitm: Translates value member variables into the correct unit via (pow(10, unitm) * value).
335 * @type: The sensor type from enum amdxdna_sensor_type.
336 * @pad: Structure padding.
338 struct amdxdna_drm_query_sensor {
352 * struct amdxdna_drm_query_hwctx - The data for single context.
353 * @context_id: The ID for this context.
354 * @start_col: The starting column for the partition assigned to this context.
355 * @num_col: The number of columns in the partition assigned to this context.
356 * @pad: Structure padding.
357 * @pid: The Process ID of the process that created this context.
358 * @command_submissions: The number of commands submitted to this context.
359 * @command_completions: The number of commands completed by this context.
360 * @migrations: The number of times this context has been moved to a different partition.
361 * @preemptions: The number of times this context has been preempted by another context in the
363 * @errors: The errors for this context.
365 struct amdxdna_drm_query_hwctx {
371 __u64 command_submissions;
372 __u64 command_completions;
378 enum amdxdna_power_mode_type {
379 POWER_MODE_DEFAULT, /* Fallback to calculated DPM */
380 POWER_MODE_LOW, /* Set frequency to lowest DPM */
381 POWER_MODE_MEDIUM, /* Set frequency to medium DPM */
382 POWER_MODE_HIGH, /* Set frequency to highest DPM */
383 POWER_MODE_TURBO, /* Maximum power */
387 * struct amdxdna_drm_get_power_mode - Get the configured power mode
388 * @power_mode: The mode type from enum amdxdna_power_mode_type
389 * @pad: Structure padding.
391 struct amdxdna_drm_get_power_mode {
397 * struct amdxdna_drm_query_firmware_version - Query the firmware version
398 * @major: The major version number
399 * @minor: The minor version number
400 * @patch: The patch level version number
401 * @build: The build ID
403 struct amdxdna_drm_query_firmware_version {
404 __u32 major; /* out */
405 __u32 minor; /* out */
406 __u32 patch; /* out */
407 __u32 build; /* out */
410 enum amdxdna_drm_get_param {
411 DRM_AMDXDNA_QUERY_AIE_STATUS,
412 DRM_AMDXDNA_QUERY_AIE_METADATA,
413 DRM_AMDXDNA_QUERY_AIE_VERSION,
414 DRM_AMDXDNA_QUERY_CLOCK_METADATA,
415 DRM_AMDXDNA_QUERY_SENSORS,
416 DRM_AMDXDNA_QUERY_HW_CONTEXTS,
417 DRM_AMDXDNA_QUERY_FIRMWARE_VERSION = 8,
418 DRM_AMDXDNA_GET_POWER_MODE,
422 * struct amdxdna_drm_get_info - Get some information from the AIE hardware.
423 * @param: Value in enum amdxdna_drm_get_param. Specifies the structure passed in the buffer.
424 * @buffer_size: Size of the input buffer. Size needed/written by the kernel.
425 * @buffer: A structure specified by the param struct member.
427 struct amdxdna_drm_get_info {
428 __u32 param; /* in */
429 __u32 buffer_size; /* in/out */
430 __u64 buffer; /* in/out */
433 enum amdxdna_drm_set_param {
434 DRM_AMDXDNA_SET_POWER_MODE,
435 DRM_AMDXDNA_WRITE_AIE_MEM,
436 DRM_AMDXDNA_WRITE_AIE_REG,
440 * struct amdxdna_drm_set_state - Set the state of the AIE hardware.
441 * @param: Value in enum amdxdna_drm_set_param.
442 * @buffer_size: Size of the input param.
443 * @buffer: Pointer to the input param.
445 struct amdxdna_drm_set_state {
446 __u32 param; /* in */
447 __u32 buffer_size; /* in */
448 __u64 buffer; /* in */
452 * struct amdxdna_drm_set_power_mode - Set the power mode of the AIE hardware
453 * @power_mode: The sensor type from enum amdxdna_power_mode_type
456 struct amdxdna_drm_set_power_mode {
461 #define DRM_IOCTL_AMDXDNA_CREATE_HWCTX \
462 DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_CREATE_HWCTX, \
463 struct amdxdna_drm_create_hwctx)
465 #define DRM_IOCTL_AMDXDNA_DESTROY_HWCTX \
466 DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_DESTROY_HWCTX, \
467 struct amdxdna_drm_destroy_hwctx)
469 #define DRM_IOCTL_AMDXDNA_CONFIG_HWCTX \
470 DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_CONFIG_HWCTX, \
471 struct amdxdna_drm_config_hwctx)
473 #define DRM_IOCTL_AMDXDNA_CREATE_BO \
474 DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_CREATE_BO, \
475 struct amdxdna_drm_create_bo)
477 #define DRM_IOCTL_AMDXDNA_GET_BO_INFO \
478 DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_GET_BO_INFO, \
479 struct amdxdna_drm_get_bo_info)
481 #define DRM_IOCTL_AMDXDNA_SYNC_BO \
482 DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_SYNC_BO, \
483 struct amdxdna_drm_sync_bo)
485 #define DRM_IOCTL_AMDXDNA_EXEC_CMD \
486 DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_EXEC_CMD, \
487 struct amdxdna_drm_exec_cmd)
489 #define DRM_IOCTL_AMDXDNA_GET_INFO \
490 DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_GET_INFO, \
491 struct amdxdna_drm_get_info)
493 #define DRM_IOCTL_AMDXDNA_SET_STATE \
494 DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_SET_STATE, \
495 struct amdxdna_drm_set_state)
497 #if defined(__cplusplus)
501 #endif /* _UAPI_AMDXDNA_ACCEL_H_ */