/* 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,36};3738/**39* struct qos_info - QoS information for driver.40* @gops: Giga operations per second.41* @fps: Frames per second.42* @dma_bandwidth: DMA bandwidtha.43* @latency: Frame response latency.44* @frame_exec_time: Frame execution time.45* @priority: Request priority.46*47* User program can provide QoS hints to driver.48*/49struct amdxdna_qos_info {50__u32 gops;51__u32 fps;52__u32 dma_bandwidth;53__u32 latency;54__u32 frame_exec_time;55__u32 priority;56};5758/**59* struct amdxdna_drm_create_hwctx - Create hardware context.60* @ext: MBZ.61* @ext_flags: MBZ.62* @qos_p: Address of QoS info.63* @umq_bo: BO handle for user mode queue(UMQ).64* @log_buf_bo: BO handle for log buffer.65* @max_opc: Maximum operations per cycle.66* @num_tiles: Number of AIE tiles.67* @mem_size: Size of AIE tile memory.68* @umq_doorbell: Returned offset of doorbell associated with UMQ.69* @handle: Returned hardware context handle.70* @syncobj_handle: Returned syncobj handle for command completion.71*/72struct amdxdna_drm_create_hwctx {73__u64 ext;74__u64 ext_flags;75__u64 qos_p;76__u32 umq_bo;77__u32 log_buf_bo;78__u32 max_opc;79__u32 num_tiles;80__u32 mem_size;81__u32 umq_doorbell;82__u32 handle;83__u32 syncobj_handle;84};8586/**87* struct amdxdna_drm_destroy_hwctx - Destroy hardware context.88* @handle: Hardware context handle.89* @pad: MBZ.90*/91struct amdxdna_drm_destroy_hwctx {92__u32 handle;93__u32 pad;94};9596/**97* struct amdxdna_cu_config - configuration for one CU98* @cu_bo: CU configuration buffer bo handle.99* @cu_func: Function of a CU.100* @pad: MBZ.101*/102struct amdxdna_cu_config {103__u32 cu_bo;104__u8 cu_func;105__u8 pad[3];106};107108/**109* struct amdxdna_hwctx_param_config_cu - configuration for CUs in hardware context110* @num_cus: Number of CUs to configure.111* @pad: MBZ.112* @cu_configs: Array of CU configurations of struct amdxdna_cu_config.113*/114struct amdxdna_hwctx_param_config_cu {115__u16 num_cus;116__u16 pad[3];117struct amdxdna_cu_config cu_configs[] __counted_by(num_cus);118};119120enum amdxdna_drm_config_hwctx_param {121DRM_AMDXDNA_HWCTX_CONFIG_CU,122DRM_AMDXDNA_HWCTX_ASSIGN_DBG_BUF,123DRM_AMDXDNA_HWCTX_REMOVE_DBG_BUF,124};125126/**127* struct amdxdna_drm_config_hwctx - Configure hardware context.128* @handle: hardware context handle.129* @param_type: Value in enum amdxdna_drm_config_hwctx_param. Specifies the130* structure passed in via param_val.131* @param_val: A structure specified by the param_type struct member.132* @param_val_size: Size of the parameter buffer pointed to by the param_val.133* If param_val is not a pointer, driver can ignore this.134* @pad: MBZ.135*136* Note: if the param_val is a pointer pointing to a buffer, the maximum size137* of the buffer is 4KiB(PAGE_SIZE).138*/139struct amdxdna_drm_config_hwctx {140__u32 handle;141__u32 param_type;142__u64 param_val;143__u32 param_val_size;144__u32 pad;145};146147enum amdxdna_bo_type {148AMDXDNA_BO_INVALID = 0,149AMDXDNA_BO_SHMEM,150AMDXDNA_BO_DEV_HEAP,151AMDXDNA_BO_DEV,152AMDXDNA_BO_CMD,153};154155/**156* struct amdxdna_drm_create_bo - Create a buffer object.157* @flags: Buffer flags. MBZ.158* @vaddr: User VA of buffer if applied. MBZ.159* @size: Size in bytes.160* @type: Buffer type.161* @handle: Returned DRM buffer object handle.162*/163struct amdxdna_drm_create_bo {164__u64 flags;165__u64 vaddr;166__u64 size;167__u32 type;168__u32 handle;169};170171/**172* struct amdxdna_drm_get_bo_info - Get buffer object information.173* @ext: MBZ.174* @ext_flags: MBZ.175* @handle: DRM buffer object handle.176* @pad: MBZ.177* @map_offset: Returned DRM fake offset for mmap().178* @vaddr: Returned user VA of buffer. 0 in case user needs mmap().179* @xdna_addr: Returned XDNA device virtual address.180*/181struct amdxdna_drm_get_bo_info {182__u64 ext;183__u64 ext_flags;184__u32 handle;185__u32 pad;186__u64 map_offset;187__u64 vaddr;188__u64 xdna_addr;189};190191/**192* struct amdxdna_drm_sync_bo - Sync buffer object.193* @handle: Buffer object handle.194* @direction: Direction of sync, can be from device or to device.195* @offset: Offset in the buffer to sync.196* @size: Size in bytes.197*/198struct amdxdna_drm_sync_bo {199__u32 handle;200#define SYNC_DIRECT_TO_DEVICE 0U201#define SYNC_DIRECT_FROM_DEVICE 1U202__u32 direction;203__u64 offset;204__u64 size;205};206207enum amdxdna_cmd_type {208AMDXDNA_CMD_SUBMIT_EXEC_BUF = 0,209AMDXDNA_CMD_SUBMIT_DEPENDENCY,210AMDXDNA_CMD_SUBMIT_SIGNAL,211};212213/**214* struct amdxdna_drm_exec_cmd - Execute command.215* @ext: MBZ.216* @ext_flags: MBZ.217* @hwctx: Hardware context handle.218* @type: One of command type in enum amdxdna_cmd_type.219* @cmd_handles: Array of command handles or the command handle itself220* in case of just one.221* @args: Array of arguments for all command handles.222* @cmd_count: Number of command handles in the cmd_handles array.223* @arg_count: Number of arguments in the args array.224* @seq: Returned sequence number for this command.225*/226struct amdxdna_drm_exec_cmd {227__u64 ext;228__u64 ext_flags;229__u32 hwctx;230__u32 type;231__u64 cmd_handles;232__u64 args;233__u32 cmd_count;234__u32 arg_count;235__u64 seq;236};237238/**239* struct amdxdna_drm_query_aie_status - Query the status of the AIE hardware240* @buffer: The user space buffer that will return the AIE status.241* @buffer_size: The size of the user space buffer.242* @cols_filled: A bitmap of AIE columns whose data has been returned in the buffer.243*/244struct amdxdna_drm_query_aie_status {245__u64 buffer; /* out */246__u32 buffer_size; /* in */247__u32 cols_filled; /* out */248};249250/**251* struct amdxdna_drm_query_aie_version - Query the version of the AIE hardware252* @major: The major version number.253* @minor: The minor version number.254*/255struct amdxdna_drm_query_aie_version {256__u32 major; /* out */257__u32 minor; /* out */258};259260/**261* struct amdxdna_drm_query_aie_tile_metadata - Query the metadata of AIE tile (core, mem, shim)262* @row_count: The number of rows.263* @row_start: The starting row number.264* @dma_channel_count: The number of dma channels.265* @lock_count: The number of locks.266* @event_reg_count: The number of events.267* @pad: Structure padding.268*/269struct amdxdna_drm_query_aie_tile_metadata {270__u16 row_count;271__u16 row_start;272__u16 dma_channel_count;273__u16 lock_count;274__u16 event_reg_count;275__u16 pad[3];276};277278/**279* struct amdxdna_drm_query_aie_metadata - Query the metadata of the AIE hardware280* @col_size: The size of a column in bytes.281* @cols: The total number of columns.282* @rows: The total number of rows.283* @version: The version of the AIE hardware.284* @core: The metadata for all core tiles.285* @mem: The metadata for all mem tiles.286* @shim: The metadata for all shim tiles.287*/288struct amdxdna_drm_query_aie_metadata {289__u32 col_size;290__u16 cols;291__u16 rows;292struct amdxdna_drm_query_aie_version version;293struct amdxdna_drm_query_aie_tile_metadata core;294struct amdxdna_drm_query_aie_tile_metadata mem;295struct amdxdna_drm_query_aie_tile_metadata shim;296};297298/**299* struct amdxdna_drm_query_clock - Metadata for a clock300* @name: The clock name.301* @freq_mhz: The clock frequency.302* @pad: Structure padding.303*/304struct amdxdna_drm_query_clock {305__u8 name[16];306__u32 freq_mhz;307__u32 pad;308};309310/**311* struct amdxdna_drm_query_clock_metadata - Query metadata for clocks312* @mp_npu_clock: The metadata for MP-NPU clock.313* @h_clock: The metadata for H clock.314*/315struct amdxdna_drm_query_clock_metadata {316struct amdxdna_drm_query_clock mp_npu_clock;317struct amdxdna_drm_query_clock h_clock;318};319320enum amdxdna_sensor_type {321AMDXDNA_SENSOR_TYPE_POWER322};323324/**325* struct amdxdna_drm_query_sensor - The data for single sensor.326* @label: The name for a sensor.327* @input: The current value of the sensor.328* @max: The maximum value possible for the sensor.329* @average: The average value of the sensor.330* @highest: The highest recorded sensor value for this driver load for the sensor.331* @status: The sensor status.332* @units: The sensor units.333* @unitm: Translates value member variables into the correct unit via (pow(10, unitm) * value).334* @type: The sensor type from enum amdxdna_sensor_type.335* @pad: Structure padding.336*/337struct amdxdna_drm_query_sensor {338__u8 label[64];339__u32 input;340__u32 max;341__u32 average;342__u32 highest;343__u8 status[64];344__u8 units[16];345__s8 unitm;346__u8 type;347__u8 pad[6];348};349350/**351* struct amdxdna_drm_query_hwctx - The data for single context.352* @context_id: The ID for this context.353* @start_col: The starting column for the partition assigned to this context.354* @num_col: The number of columns in the partition assigned to this context.355* @pad: Structure padding.356* @pid: The Process ID of the process that created this context.357* @command_submissions: The number of commands submitted to this context.358* @command_completions: The number of commands completed by this context.359* @migrations: The number of times this context has been moved to a different partition.360* @preemptions: The number of times this context has been preempted by another context in the361* same partition.362* @errors: The errors for this context.363*/364struct amdxdna_drm_query_hwctx {365__u32 context_id;366__u32 start_col;367__u32 num_col;368__u32 pad;369__s64 pid;370__u64 command_submissions;371__u64 command_completions;372__u64 migrations;373__u64 preemptions;374__u64 errors;375};376377enum amdxdna_power_mode_type {378POWER_MODE_DEFAULT, /* Fallback to calculated DPM */379POWER_MODE_LOW, /* Set frequency to lowest DPM */380POWER_MODE_MEDIUM, /* Set frequency to medium DPM */381POWER_MODE_HIGH, /* Set frequency to highest DPM */382POWER_MODE_TURBO, /* Maximum power */383};384385/**386* struct amdxdna_drm_get_power_mode - Get the configured power mode387* @power_mode: The mode type from enum amdxdna_power_mode_type388* @pad: Structure padding.389*/390struct amdxdna_drm_get_power_mode {391__u8 power_mode;392__u8 pad[7];393};394395/**396* struct amdxdna_drm_query_firmware_version - Query the firmware version397* @major: The major version number398* @minor: The minor version number399* @patch: The patch level version number400* @build: The build ID401*/402struct amdxdna_drm_query_firmware_version {403__u32 major; /* out */404__u32 minor; /* out */405__u32 patch; /* out */406__u32 build; /* out */407};408409enum amdxdna_drm_get_param {410DRM_AMDXDNA_QUERY_AIE_STATUS,411DRM_AMDXDNA_QUERY_AIE_METADATA,412DRM_AMDXDNA_QUERY_AIE_VERSION,413DRM_AMDXDNA_QUERY_CLOCK_METADATA,414DRM_AMDXDNA_QUERY_SENSORS,415DRM_AMDXDNA_QUERY_HW_CONTEXTS,416DRM_AMDXDNA_QUERY_FIRMWARE_VERSION = 8,417DRM_AMDXDNA_GET_POWER_MODE,418};419420/**421* struct amdxdna_drm_get_info - Get some information from the AIE hardware.422* @param: Value in enum amdxdna_drm_get_param. Specifies the structure passed in the buffer.423* @buffer_size: Size of the input buffer. Size needed/written by the kernel.424* @buffer: A structure specified by the param struct member.425*/426struct amdxdna_drm_get_info {427__u32 param; /* in */428__u32 buffer_size; /* in/out */429__u64 buffer; /* in/out */430};431432enum amdxdna_drm_set_param {433DRM_AMDXDNA_SET_POWER_MODE,434DRM_AMDXDNA_WRITE_AIE_MEM,435DRM_AMDXDNA_WRITE_AIE_REG,436};437438/**439* struct amdxdna_drm_set_state - Set the state of the AIE hardware.440* @param: Value in enum amdxdna_drm_set_param.441* @buffer_size: Size of the input param.442* @buffer: Pointer to the input param.443*/444struct amdxdna_drm_set_state {445__u32 param; /* in */446__u32 buffer_size; /* in */447__u64 buffer; /* in */448};449450/**451* struct amdxdna_drm_set_power_mode - Set the power mode of the AIE hardware452* @power_mode: The sensor type from enum amdxdna_power_mode_type453* @pad: MBZ.454*/455struct amdxdna_drm_set_power_mode {456__u8 power_mode;457__u8 pad[7];458};459460#define DRM_IOCTL_AMDXDNA_CREATE_HWCTX \461DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_CREATE_HWCTX, \462struct amdxdna_drm_create_hwctx)463464#define DRM_IOCTL_AMDXDNA_DESTROY_HWCTX \465DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_DESTROY_HWCTX, \466struct amdxdna_drm_destroy_hwctx)467468#define DRM_IOCTL_AMDXDNA_CONFIG_HWCTX \469DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_CONFIG_HWCTX, \470struct amdxdna_drm_config_hwctx)471472#define DRM_IOCTL_AMDXDNA_CREATE_BO \473DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_CREATE_BO, \474struct amdxdna_drm_create_bo)475476#define DRM_IOCTL_AMDXDNA_GET_BO_INFO \477DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_GET_BO_INFO, \478struct amdxdna_drm_get_bo_info)479480#define DRM_IOCTL_AMDXDNA_SYNC_BO \481DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_SYNC_BO, \482struct amdxdna_drm_sync_bo)483484#define DRM_IOCTL_AMDXDNA_EXEC_CMD \485DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_EXEC_CMD, \486struct amdxdna_drm_exec_cmd)487488#define DRM_IOCTL_AMDXDNA_GET_INFO \489DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_GET_INFO, \490struct amdxdna_drm_get_info)491492#define DRM_IOCTL_AMDXDNA_SET_STATE \493DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDXDNA_SET_STATE, \494struct amdxdna_drm_set_state)495496#if defined(__cplusplus)497} /* extern c end */498#endif499500#endif /* _UAPI_AMDXDNA_ACCEL_H_ */501502503