/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */1/*2* Copyright (C) 2022-2024, Advanced Micro Devices, Inc.3*/45#ifndef _UAPI_AMDXDNA_ACCEL_H_6#define _UAPI_AMDXDNA_ACCEL_H_78#include <linux/stddef.h>9#include "drm.h"1011#if defined(__cplusplus)12extern "C" {13#endif1415#define AMDXDNA_INVALID_CMD_HANDLE (~0UL)16#define AMDXDNA_INVALID_ADDR (~0UL)17#define AMDXDNA_INVALID_CTX_HANDLE 018#define AMDXDNA_INVALID_BO_HANDLE 019#define AMDXDNA_INVALID_FENCE_HANDLE 02021enum amdxdna_device_type {22AMDXDNA_DEV_TYPE_UNKNOWN = -1,23AMDXDNA_DEV_TYPE_KMQ,24};2526enum amdxdna_drm_ioctl_id {27DRM_AMDXDNA_CREATE_HWCTX,28DRM_AMDXDNA_DESTROY_HWCTX,29DRM_AMDXDNA_CONFIG_HWCTX,30DRM_AMDXDNA_CREATE_BO,31DRM_AMDXDNA_GET_BO_INFO,32DRM_AMDXDNA_SYNC_BO,33DRM_AMDXDNA_EXEC_CMD,34DRM_AMDXDNA_GET_INFO,35DRM_AMDXDNA_SET_STATE,36DRM_AMDXDNA_GET_ARRAY = 10,37};3839/**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.47*48* User program can provide QoS hints to driver.49*/50struct amdxdna_qos_info {51__u32 gops;52__u32 fps;53__u32 dma_bandwidth;54__u32 latency;55__u32 frame_exec_time;56__u32 priority;57};5859/**60* struct amdxdna_drm_create_hwctx - Create hardware context.61* @ext: MBZ.62* @ext_flags: MBZ.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.72*/73struct amdxdna_drm_create_hwctx {74__u64 ext;75__u64 ext_flags;76__u64 qos_p;77__u32 umq_bo;78__u32 log_buf_bo;79__u32 max_opc;80__u32 num_tiles;81__u32 mem_size;82__u32 umq_doorbell;83__u32 handle;84__u32 syncobj_handle;85};8687/**88* struct amdxdna_drm_destroy_hwctx - Destroy hardware context.89* @handle: Hardware context handle.90* @pad: MBZ.91*/92struct amdxdna_drm_destroy_hwctx {93__u32 handle;94__u32 pad;95};9697/**98* struct amdxdna_cu_config - configuration for one CU99* @cu_bo: CU configuration buffer bo handle.100* @cu_func: Function of a CU.101* @pad: MBZ.102*/103struct amdxdna_cu_config {104__u32 cu_bo;105__u8 cu_func;106__u8 pad[3];107};108109/**110* struct amdxdna_hwctx_param_config_cu - configuration for CUs in hardware context111* @num_cus: Number of CUs to configure.112* @pad: MBZ.113* @cu_configs: Array of CU configurations of struct amdxdna_cu_config.114*/115struct amdxdna_hwctx_param_config_cu {116__u16 num_cus;117__u16 pad[3];118struct amdxdna_cu_config cu_configs[] __counted_by(num_cus);119};120121enum amdxdna_drm_config_hwctx_param {122DRM_AMDXDNA_HWCTX_CONFIG_CU,123DRM_AMDXDNA_HWCTX_ASSIGN_DBG_BUF,124DRM_AMDXDNA_HWCTX_REMOVE_DBG_BUF,125};126127/**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 the131* 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.135* @pad: MBZ.136*137* Note: if the param_val is a pointer pointing to a buffer, the maximum size138* of the buffer is 4KiB(PAGE_SIZE).139*/140struct amdxdna_drm_config_hwctx {141__u32 handle;142__u32 param_type;143__u64 param_val;144__u32 param_val_size;145__u32 pad;146};147148enum amdxdna_bo_type {149AMDXDNA_BO_INVALID = 0,150AMDXDNA_BO_SHMEM,151AMDXDNA_BO_DEV_HEAP,152AMDXDNA_BO_DEV,153AMDXDNA_BO_CMD,154};155156/**157* struct amdxdna_drm_va_entry158* @vaddr: Virtual address.159* @len: Size of entry.160*/161struct amdxdna_drm_va_entry {162__u64 vaddr;163__u64 len;164};165166/**167* struct amdxdna_drm_va_tbl168* @dmabuf_fd: The fd of dmabuf.169* @num_entries: Number of va entries.170* @va_entries: Array of va entries.171*172* The input can be either a dmabuf fd or a virtual address entry table.173* When dmabuf_fd is used, num_entries must be zero.174*/175struct amdxdna_drm_va_tbl {176__s32 dmabuf_fd;177__u32 num_entries;178struct amdxdna_drm_va_entry va_entries[];179};180181/**182* struct amdxdna_drm_create_bo - Create a buffer object.183* @flags: Buffer flags. MBZ.184* @vaddr: User VA of buffer if applied. MBZ.185* @size: Size in bytes.186* @type: Buffer type.187* @handle: Returned DRM buffer object handle.188*/189struct amdxdna_drm_create_bo {190__u64 flags;191__u64 vaddr;192__u64 size;193__u32 type;194__u32 handle;195};196197/**198* struct amdxdna_drm_get_bo_info - Get buffer object information.199* @ext: MBZ.200* @ext_flags: MBZ.201* @handle: DRM buffer object handle.202* @pad: MBZ.203* @map_offset: Returned DRM fake offset for mmap().204* @vaddr: Returned user VA of buffer. 0 in case user needs mmap().205* @xdna_addr: Returned XDNA device virtual address.206*/207struct amdxdna_drm_get_bo_info {208__u64 ext;209__u64 ext_flags;210__u32 handle;211__u32 pad;212__u64 map_offset;213__u64 vaddr;214__u64 xdna_addr;215};216217/**218* struct amdxdna_drm_sync_bo - Sync buffer object.219* @handle: Buffer object handle.220* @direction: Direction of sync, can be from device or to device.221* @offset: Offset in the buffer to sync.222* @size: Size in bytes.223*/224struct amdxdna_drm_sync_bo {225__u32 handle;226#define SYNC_DIRECT_TO_DEVICE 0U227#define SYNC_DIRECT_FROM_DEVICE 1U228__u32 direction;229__u64 offset;230__u64 size;231};232233enum amdxdna_cmd_type {234AMDXDNA_CMD_SUBMIT_EXEC_BUF = 0,235AMDXDNA_CMD_SUBMIT_DEPENDENCY,236AMDXDNA_CMD_SUBMIT_SIGNAL,237};238239/**240* struct amdxdna_drm_exec_cmd - Execute command.241* @ext: MBZ.242* @ext_flags: MBZ.243* @hwctx: Hardware context handle.244* @type: One of command type in enum amdxdna_cmd_type.245* @cmd_handles: Array of command handles or the command handle itself246* in case of just one.247* @args: Array of arguments for all command handles.248* @cmd_count: Number of command handles in the cmd_handles array.249* @arg_count: Number of arguments in the args array.250* @seq: Returned sequence number for this command.251*/252struct amdxdna_drm_exec_cmd {253__u64 ext;254__u64 ext_flags;255__u32 hwctx;256__u32 type;257__u64 cmd_handles;258__u64 args;259__u32 cmd_count;260__u32 arg_count;261__u64 seq;262};263264/**265* struct amdxdna_drm_query_aie_status - Query the status of the AIE hardware266* @buffer: The user space buffer that will return the AIE status.267* @buffer_size: The size of the user space buffer.268* @cols_filled: A bitmap of AIE columns whose data has been returned in the buffer.269*/270struct amdxdna_drm_query_aie_status {271__u64 buffer; /* out */272__u32 buffer_size; /* in */273__u32 cols_filled; /* out */274};275276/**277* struct amdxdna_drm_query_aie_version - Query the version of the AIE hardware278* @major: The major version number.279* @minor: The minor version number.280*/281struct amdxdna_drm_query_aie_version {282__u32 major; /* out */283__u32 minor; /* out */284};285286/**287* struct amdxdna_drm_query_aie_tile_metadata - Query the metadata of AIE tile (core, mem, shim)288* @row_count: The number of rows.289* @row_start: The starting row number.290* @dma_channel_count: The number of dma channels.291* @lock_count: The number of locks.292* @event_reg_count: The number of events.293* @pad: Structure padding.294*/295struct amdxdna_drm_query_aie_tile_metadata {296__u16 row_count;297__u16 row_start;298__u16 dma_channel_count;299__u16 lock_count;300__u16 event_reg_count;301__u16 pad[3];302};303304/**305* struct amdxdna_drm_query_aie_metadata - Query the metadata of the AIE hardware306* @col_size: The size of a column in bytes.307* @cols: The total number of columns.308* @rows: The total number of rows.309* @version: The version of the AIE hardware.310* @core: The metadata for all core tiles.311* @mem: The metadata for all mem tiles.312* @shim: The metadata for all shim tiles.313*/314struct amdxdna_drm_query_aie_metadata {315__u32 col_size;316__u16 cols;317__u16 rows;318struct amdxdna_drm_query_aie_version version;319struct amdxdna_drm_query_aie_tile_metadata core;320struct amdxdna_drm_query_aie_tile_metadata mem;321struct amdxdna_drm_query_aie_tile_metadata shim;322};323324/**325* struct amdxdna_drm_query_clock - Metadata for a clock326* @name: The clock name.327* @freq_mhz: The clock frequency.328* @pad: Structure padding.329*/330struct amdxdna_drm_query_clock {331__u8 name[16];332__u32 freq_mhz;333__u32 pad;334};335336/**337* struct amdxdna_drm_query_clock_metadata - Query metadata for clocks338* @mp_npu_clock: The metadata for MP-NPU clock.339* @h_clock: The metadata for H clock.340*/341struct amdxdna_drm_query_clock_metadata {342struct amdxdna_drm_query_clock mp_npu_clock;343struct amdxdna_drm_query_clock h_clock;344};345346enum amdxdna_sensor_type {347AMDXDNA_SENSOR_TYPE_POWER348};349350/**351* struct amdxdna_drm_query_sensor - The data for single sensor.352* @label: The name for a sensor.353* @input: The current value of the sensor.354* @max: The maximum value possible for the sensor.355* @average: The average value of the sensor.356* @highest: The highest recorded sensor value for this driver load for the sensor.357* @status: The sensor status.358* @units: The sensor units.359* @unitm: Translates value member variables into the correct unit via (pow(10, unitm) * value).360* @type: The sensor type from enum amdxdna_sensor_type.361* @pad: Structure padding.362*/363struct amdxdna_drm_query_sensor {364__u8 label[64];365__u32 input;366__u32 max;367__u32 average;368__u32 highest;369__u8 status[64];370__u8 units[16];371__s8 unitm;372__u8 type;373__u8 pad[6];374};375376/**377* struct amdxdna_drm_query_hwctx - The data for single context.378* @context_id: The ID for this context.379* @start_col: The starting column for the partition assigned to this context.380* @num_col: The number of columns in the partition assigned to this context.381* @pad: Structure padding.382* @pid: The Process ID of the process that created this context.383* @command_submissions: The number of commands submitted to this context.384* @command_completions: The number of commands completed by this context.385* @migrations: The number of times this context has been moved to a different partition.386* @preemptions: The number of times this context has been preempted by another context in the387* same partition.388* @errors: The errors for this context.389*/390struct amdxdna_drm_query_hwctx {391__u32 context_id;392__u32 start_col;393__u32 num_col;394__u32 pad;395__s64 pid;396__u64 command_submissions;397__u64 command_completions;398__u64 migrations;399__u64 preemptions;400__u64 errors;401};402403enum amdxdna_power_mode_type {404POWER_MODE_DEFAULT, /* Fallback to calculated DPM */405POWER_MODE_LOW, /* Set frequency to lowest DPM */406POWER_MODE_MEDIUM, /* Set frequency to medium DPM */407POWER_MODE_HIGH, /* Set frequency to highest DPM */408POWER_MODE_TURBO, /* Maximum power */409};410411/**412* struct amdxdna_drm_get_power_mode - Get the configured power mode413* @power_mode: The mode type from enum amdxdna_power_mode_type414* @pad: Structure padding.415*/416struct amdxdna_drm_get_power_mode {417__u8 power_mode;418__u8 pad[7];419};420421/**422* struct amdxdna_drm_query_firmware_version - Query the firmware version423* @major: The major version number424* @minor: The minor version number425* @patch: The patch level version number426* @build: The build ID427*/428struct amdxdna_drm_query_firmware_version {429__u32 major; /* out */430__u32 minor; /* out */431__u32 patch; /* out */432__u32 build; /* out */433};434435enum amdxdna_drm_get_param {436DRM_AMDXDNA_QUERY_AIE_STATUS,437DRM_AMDXDNA_QUERY_AIE_METADATA,438DRM_AMDXDNA_QUERY_AIE_VERSION,439DRM_AMDXDNA_QUERY_CLOCK_METADATA,440DRM_AMDXDNA_QUERY_SENSORS,441DRM_AMDXDNA_QUERY_HW_CONTEXTS,442DRM_AMDXDNA_QUERY_FIRMWARE_VERSION = 8,443DRM_AMDXDNA_GET_POWER_MODE,444DRM_AMDXDNA_QUERY_TELEMETRY,445DRM_AMDXDNA_GET_FORCE_PREEMPT_STATE,446DRM_AMDXDNA_QUERY_RESOURCE_INFO,447DRM_AMDXDNA_GET_FRAME_BOUNDARY_PREEMPT_STATE,448};449450/**451* struct amdxdna_drm_get_resource_info - Get resource information452*/453struct amdxdna_drm_get_resource_info {454/** @npu_clk_max: max H-Clocks */455__u64 npu_clk_max;456/** @npu_tops_max: max TOPs */457__u64 npu_tops_max;458/** @npu_task_max: max number of tasks */459__u64 npu_task_max;460/** @npu_tops_curr: current TOPs */461__u64 npu_tops_curr;462/** @npu_task_curr: current number of tasks */463__u64 npu_task_curr;464};465466/**467* struct amdxdna_drm_attribute_state - State of an attribute468*/469struct amdxdna_drm_attribute_state {470/** @state: enabled or disabled */471__u8 state;472/** @pad: MBZ */473__u8 pad[7];474};475476/**477* struct amdxdna_drm_query_telemetry_header - Telemetry data header478*/479struct amdxdna_drm_query_telemetry_header {480/** @major: Firmware telemetry interface major version number */481__u32 major;482/** @minor: Firmware telemetry interface minor version number */483__u32 minor;484/** @type: Telemetry query type */485__u32 type;486/** @map_num_elements: Total number of elements in the map table */487__u32 map_num_elements;488/** @map: Element map */489__u32 map[];490};491492/**493* struct amdxdna_drm_get_info - Get some information from the AIE hardware.494* @param: Value in enum amdxdna_drm_get_param. Specifies the structure passed in the buffer.495* @buffer_size: Size of the input buffer. Size needed/written by the kernel.496* @buffer: A structure specified by the param struct member.497*/498struct amdxdna_drm_get_info {499__u32 param; /* in */500__u32 buffer_size; /* in/out */501__u64 buffer; /* in/out */502};503504#define AMDXDNA_HWCTX_STATE_IDLE 0505#define AMDXDNA_HWCTX_STATE_ACTIVE 1506507/**508* struct amdxdna_drm_hwctx_entry - The hardware context array entry509*/510struct amdxdna_drm_hwctx_entry {511/** @context_id: Context ID. */512__u32 context_id;513/** @start_col: Start AIE array column assigned to context. */514__u32 start_col;515/** @num_col: Number of AIE array columns assigned to context. */516__u32 num_col;517/** @hwctx_id: The real hardware context id. */518__u32 hwctx_id;519/** @pid: ID of process which created this context. */520__s64 pid;521/** @command_submissions: Number of commands submitted. */522__u64 command_submissions;523/** @command_completions: Number of commands completed. */524__u64 command_completions;525/** @migrations: Number of times been migrated. */526__u64 migrations;527/** @preemptions: Number of times been preempted. */528__u64 preemptions;529/** @errors: Number of errors happened. */530__u64 errors;531/** @priority: Context priority. */532__u64 priority;533/** @heap_usage: Usage of device heap buffer. */534__u64 heap_usage;535/** @suspensions: Number of times been suspended. */536__u64 suspensions;537/**538* @state: Context state.539* %AMDXDNA_HWCTX_STATE_IDLE540* %AMDXDNA_HWCTX_STATE_ACTIVE541*/542__u32 state;543/** @pasid: PASID been bound. */544__u32 pasid;545/** @gops: Giga operations per second. */546__u32 gops;547/** @fps: Frames per second. */548__u32 fps;549/** @dma_bandwidth: DMA bandwidth. */550__u32 dma_bandwidth;551/** @latency: Frame response latency. */552__u32 latency;553/** @frame_exec_time: Frame execution time. */554__u32 frame_exec_time;555/** @txn_op_idx: Index of last control code executed. */556__u32 txn_op_idx;557/** @ctx_pc: Program counter. */558__u32 ctx_pc;559/** @fatal_error_type: Fatal error type if context crashes. */560__u32 fatal_error_type;561/** @fatal_error_exception_type: Firmware exception type. */562__u32 fatal_error_exception_type;563/** @fatal_error_exception_pc: Firmware exception program counter. */564__u32 fatal_error_exception_pc;565/** @fatal_error_app_module: Exception module name. */566__u32 fatal_error_app_module;567/** @pad: Structure pad. */568__u32 pad;569};570571/**572* struct amdxdna_async_error - XDNA async error structure573*/574struct amdxdna_async_error {575/** @err_code: Error code. */576__u64 err_code;577/** @ts_us: Timestamp. */578__u64 ts_us;579/** @ex_err_code: Extra error code */580__u64 ex_err_code;581};582583#define DRM_AMDXDNA_HW_CONTEXT_ALL 0584#define DRM_AMDXDNA_HW_LAST_ASYNC_ERR 2585586/**587* struct amdxdna_drm_get_array - Get information array.588*/589struct amdxdna_drm_get_array {590/**591* @param:592*593* Supported params:594*595* %DRM_AMDXDNA_HW_CONTEXT_ALL:596* Returns all created hardware contexts.597*/598__u32 param;599/**600* @element_size:601*602* Specifies maximum element size and returns the actual element size.603*/604__u32 element_size;605/**606* @num_element:607*608* Specifies maximum number of elements and returns the actual number609* of elements.610*/611__u32 num_element; /* in/out */612/** @pad: MBZ */613__u32 pad;614/**615* @buffer:616*617* Specifies the match conditions and returns the matched information618* array.619*/620__u64 buffer;621};622623enum amdxdna_drm_set_param {624DRM_AMDXDNA_SET_POWER_MODE,625DRM_AMDXDNA_WRITE_AIE_MEM,626DRM_AMDXDNA_WRITE_AIE_REG,627DRM_AMDXDNA_SET_FORCE_PREEMPT,628DRM_AMDXDNA_SET_FRAME_BOUNDARY_PREEMPT,629};630631/**632* struct amdxdna_drm_set_state - Set the state of the AIE hardware.633* @param: Value in enum amdxdna_drm_set_param.634* @buffer_size: Size of the input param.635* @buffer: Pointer to the input param.636*/637struct amdxdna_drm_set_state {638__u32 param; /* in */639__u32 buffer_size; /* in */640__u64 buffer; /* in */641};642643/**644* struct amdxdna_drm_set_power_mode - Set the power mode of the AIE hardware645* @power_mode: The sensor type from enum amdxdna_power_mode_type646* @pad: MBZ.647*/648struct amdxdna_drm_set_power_mode {649__u8 power_mode;650__u8 pad[7];651};652653#define DRM_IOCTL_AMDXDNA_CREATE_HWCTX \654DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_CREATE_HWCTX, \655struct amdxdna_drm_create_hwctx)656657#define DRM_IOCTL_AMDXDNA_DESTROY_HWCTX \658DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_DESTROY_HWCTX, \659struct amdxdna_drm_destroy_hwctx)660661#define DRM_IOCTL_AMDXDNA_CONFIG_HWCTX \662DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_CONFIG_HWCTX, \663struct amdxdna_drm_config_hwctx)664665#define DRM_IOCTL_AMDXDNA_CREATE_BO \666DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_CREATE_BO, \667struct amdxdna_drm_create_bo)668669#define DRM_IOCTL_AMDXDNA_GET_BO_INFO \670DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_GET_BO_INFO, \671struct amdxdna_drm_get_bo_info)672673#define DRM_IOCTL_AMDXDNA_SYNC_BO \674DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_SYNC_BO, \675struct amdxdna_drm_sync_bo)676677#define DRM_IOCTL_AMDXDNA_EXEC_CMD \678DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_EXEC_CMD, \679struct amdxdna_drm_exec_cmd)680681#define DRM_IOCTL_AMDXDNA_GET_INFO \682DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_GET_INFO, \683struct amdxdna_drm_get_info)684685#define DRM_IOCTL_AMDXDNA_SET_STATE \686DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_SET_STATE, \687struct amdxdna_drm_set_state)688689#define DRM_IOCTL_AMDXDNA_GET_ARRAY \690DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_GET_ARRAY, \691struct amdxdna_drm_get_array)692693#if defined(__cplusplus)694} /* extern c end */695#endif696697#endif /* _UAPI_AMDXDNA_ACCEL_H_ */698699700