/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note1*2* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.3* Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved.4*/56#ifndef QAIC_ACCEL_H_7#define QAIC_ACCEL_H_89#include "drm.h"1011#if defined(__cplusplus)12extern "C" {13#endif1415/* The length(4K) includes len and count fields of qaic_manage_msg */16#define QAIC_MANAGE_MAX_MSG_LENGTH SZ_4K1718/* semaphore flags */19#define QAIC_SEM_INSYNCFENCE 220#define QAIC_SEM_OUTSYNCFENCE 12122/* Semaphore commands */23#define QAIC_SEM_NOP 024#define QAIC_SEM_INIT 125#define QAIC_SEM_INC 226#define QAIC_SEM_DEC 327#define QAIC_SEM_WAIT_EQUAL 428#define QAIC_SEM_WAIT_GT_EQ 5 /* Greater than or equal */29#define QAIC_SEM_WAIT_GT_0 6 /* Greater than 0 */3031#define QAIC_TRANS_UNDEFINED 032#define QAIC_TRANS_PASSTHROUGH_FROM_USR 133#define QAIC_TRANS_PASSTHROUGH_TO_USR 234#define QAIC_TRANS_PASSTHROUGH_FROM_DEV 335#define QAIC_TRANS_PASSTHROUGH_TO_DEV 436#define QAIC_TRANS_DMA_XFER_FROM_USR 537#define QAIC_TRANS_DMA_XFER_TO_DEV 638#define QAIC_TRANS_ACTIVATE_FROM_USR 739#define QAIC_TRANS_ACTIVATE_FROM_DEV 840#define QAIC_TRANS_ACTIVATE_TO_DEV 941#define QAIC_TRANS_DEACTIVATE_FROM_USR 1042#define QAIC_TRANS_DEACTIVATE_FROM_DEV 1143#define QAIC_TRANS_STATUS_FROM_USR 1244#define QAIC_TRANS_STATUS_TO_USR 1345#define QAIC_TRANS_STATUS_FROM_DEV 1446#define QAIC_TRANS_STATUS_TO_DEV 1547#define QAIC_TRANS_TERMINATE_FROM_DEV 1648#define QAIC_TRANS_TERMINATE_TO_DEV 1749#define QAIC_TRANS_DMA_XFER_CONT 1850#define QAIC_TRANS_VALIDATE_PARTITION_FROM_DEV 1951#define QAIC_TRANS_VALIDATE_PARTITION_TO_DEV 205253/**54* struct qaic_manage_trans_hdr - Header for a transaction in a manage message.55* @type: In. Identifies this transaction. See QAIC_TRANS_* defines.56* @len: In. Length of this transaction, including this header.57*/58struct qaic_manage_trans_hdr {59__u32 type;60__u32 len;61};6263/**64* struct qaic_manage_trans_passthrough - Defines a passthrough transaction.65* @hdr: In. Header to identify this transaction.66* @data: In. Payload of this transaction. Opaque to the driver. Userspace must67* encode in little endian and align/pad to 64-bit.68*/69struct qaic_manage_trans_passthrough {70struct qaic_manage_trans_hdr hdr;71__u8 data[];72};7374/**75* struct qaic_manage_trans_dma_xfer - Defines a DMA transfer transaction.76* @hdr: In. Header to identify this transaction.77* @tag: In. Identified this transfer in other transactions. Opaque to the78* driver.79* @pad: Structure padding.80* @addr: In. Address of the data to DMA to the device.81* @size: In. Length of the data to DMA to the device.82*/83struct qaic_manage_trans_dma_xfer {84struct qaic_manage_trans_hdr hdr;85__u32 tag;86__u32 pad;87__u64 addr;88__u64 size;89};9091/**92* struct qaic_manage_trans_activate_to_dev - Defines an activate request.93* @hdr: In. Header to identify this transaction.94* @queue_size: In. Number of elements for DBC request and response queues.95* @eventfd: Unused.96* @options: In. Device specific options for this activate.97* @pad: Structure padding. Must be 0.98*/99struct qaic_manage_trans_activate_to_dev {100struct qaic_manage_trans_hdr hdr;101__u32 queue_size;102__u32 eventfd;103__u32 options;104__u32 pad;105};106107/**108* struct qaic_manage_trans_activate_from_dev - Defines an activate response.109* @hdr: Out. Header to identify this transaction.110* @status: Out. Return code of the request from the device.111* @dbc_id: Out. Id of the assigned DBC for successful request.112* @options: Out. Device specific options for this activate.113*/114struct qaic_manage_trans_activate_from_dev {115struct qaic_manage_trans_hdr hdr;116__u32 status;117__u32 dbc_id;118__u64 options;119};120121/**122* struct qaic_manage_trans_deactivate - Defines a deactivate request.123* @hdr: In. Header to identify this transaction.124* @dbc_id: In. Id of assigned DBC.125* @pad: Structure padding. Must be 0.126*/127struct qaic_manage_trans_deactivate {128struct qaic_manage_trans_hdr hdr;129__u32 dbc_id;130__u32 pad;131};132133/**134* struct qaic_manage_trans_status_to_dev - Defines a status request.135* @hdr: In. Header to identify this transaction.136*/137struct qaic_manage_trans_status_to_dev {138struct qaic_manage_trans_hdr hdr;139};140141/**142* struct qaic_manage_trans_status_from_dev - Defines a status response.143* @hdr: Out. Header to identify this transaction.144* @major: Out. NNC protocol version major number.145* @minor: Out. NNC protocol version minor number.146* @status: Out. Return code from device.147* @status_flags: Out. Flags from device. Bit 0 indicates if CRCs are required.148*/149struct qaic_manage_trans_status_from_dev {150struct qaic_manage_trans_hdr hdr;151__u16 major;152__u16 minor;153__u32 status;154__u64 status_flags;155};156157/**158* struct qaic_manage_msg - Defines a message to the device.159* @len: In. Length of all the transactions contained within this message.160* @count: In. Number of transactions in this message.161* @data: In. Address to an array where the transactions can be found.162*/163struct qaic_manage_msg {164__u32 len;165__u32 count;166__u64 data;167};168169/**170* struct qaic_create_bo - Defines a request to create a buffer object.171* @size: In. Size of the buffer in bytes.172* @handle: Out. GEM handle for the BO.173* @pad: Structure padding. Must be 0.174*/175struct qaic_create_bo {176__u64 size;177__u32 handle;178__u32 pad;179};180181/**182* struct qaic_mmap_bo - Defines a request to prepare a BO for mmap().183* @handle: In. Handle of the GEM BO to prepare for mmap().184* @pad: Structure padding. Must be 0.185* @offset: Out. Offset value to provide to mmap().186*/187struct qaic_mmap_bo {188__u32 handle;189__u32 pad;190__u64 offset;191};192193/**194* struct qaic_sem - Defines a semaphore command for a BO slice.195* @val: In. Only lower 12 bits are valid.196* @index: In. Only lower 5 bits are valid.197* @presync: In. 1 if presync operation, 0 if postsync.198* @cmd: In. One of QAIC_SEM_*.199* @flags: In. Bitfield. See QAIC_SEM_INSYNCFENCE and QAIC_SEM_OUTSYNCFENCE200* @pad: Structure padding. Must be 0.201*/202struct qaic_sem {203__u16 val;204__u8 index;205__u8 presync;206__u8 cmd;207__u8 flags;208__u16 pad;209};210211/**212* struct qaic_attach_slice_entry - Defines a single BO slice.213* @size: In. Size of this slice in bytes.214* @sem0: In. Semaphore command 0. Must be 0 is not valid.215* @sem1: In. Semaphore command 1. Must be 0 is not valid.216* @sem2: In. Semaphore command 2. Must be 0 is not valid.217* @sem3: In. Semaphore command 3. Must be 0 is not valid.218* @dev_addr: In. Device address this slice pushes to or pulls from.219* @db_addr: In. Address of the doorbell to ring.220* @db_data: In. Data to write to the doorbell.221* @db_len: In. Size of the doorbell data in bits - 32, 16, or 8. 0 is for222* inactive doorbells.223* @offset: In. Start of this slice as an offset from the start of the BO.224*/225struct qaic_attach_slice_entry {226__u64 size;227struct qaic_sem sem0;228struct qaic_sem sem1;229struct qaic_sem sem2;230struct qaic_sem sem3;231__u64 dev_addr;232__u64 db_addr;233__u32 db_data;234__u32 db_len;235__u64 offset;236};237238/**239* struct qaic_attach_slice_hdr - Defines metadata for a set of BO slices.240* @count: In. Number of slices for this BO.241* @dbc_id: In. Associate the sliced BO with this DBC.242* @handle: In. GEM handle of the BO to slice.243* @dir: In. Direction of data flow. 1 = DMA_TO_DEVICE, 2 = DMA_FROM_DEVICE244* @size: Deprecated. This value is ignored and size of @handle is used instead.245*/246struct qaic_attach_slice_hdr {247__u32 count;248__u32 dbc_id;249__u32 handle;250__u32 dir;251__u64 size;252};253254/**255* struct qaic_attach_slice - Defines a set of BO slices.256* @hdr: In. Metadata of the set of slices.257* @data: In. Pointer to an array containing the slice definitions.258*/259struct qaic_attach_slice {260struct qaic_attach_slice_hdr hdr;261__u64 data;262};263264/**265* struct qaic_execute_entry - Defines a BO to submit to the device.266* @handle: In. GEM handle of the BO to commit to the device.267* @dir: In. Direction of data. 1 = to device, 2 = from device.268*/269struct qaic_execute_entry {270__u32 handle;271__u32 dir;272};273274/**275* struct qaic_partial_execute_entry - Defines a BO to resize and submit.276* @handle: In. GEM handle of the BO to commit to the device.277* @dir: In. Direction of data. 1 = to device, 2 = from device.278* @resize: In. New size of the BO. Must be <= the original BO size.279* @resize as 0 would be interpreted as no DMA transfer is280* involved.281*/282struct qaic_partial_execute_entry {283__u32 handle;284__u32 dir;285__u64 resize;286};287288/**289* struct qaic_execute_hdr - Defines metadata for BO submission.290* @count: In. Number of BOs to submit.291* @dbc_id: In. DBC to submit the BOs on.292*/293struct qaic_execute_hdr {294__u32 count;295__u32 dbc_id;296};297298/**299* struct qaic_execute - Defines a list of BOs to submit to the device.300* @hdr: In. BO list metadata.301* @data: In. Pointer to an array of BOs to submit.302*/303struct qaic_execute {304struct qaic_execute_hdr hdr;305__u64 data;306};307308/**309* struct qaic_wait - Defines a blocking wait for BO execution.310* @handle: In. GEM handle of the BO to wait on.311* @timeout: In. Maximum time in ms to wait for the BO.312* @dbc_id: In. DBC the BO is submitted to.313* @pad: Structure padding. Must be 0.314*/315struct qaic_wait {316__u32 handle;317__u32 timeout;318__u32 dbc_id;319__u32 pad;320};321322/**323* struct qaic_perf_stats_hdr - Defines metadata for getting BO perf info.324* @count: In. Number of BOs requested.325* @pad: Structure padding. Must be 0.326* @dbc_id: In. DBC the BO are associated with.327*/328struct qaic_perf_stats_hdr {329__u16 count;330__u16 pad;331__u32 dbc_id;332};333334/**335* struct qaic_perf_stats - Defines a request for getting BO perf info.336* @hdr: In. Request metadata337* @data: In. Pointer to array of stats structures that will receive the data.338*/339struct qaic_perf_stats {340struct qaic_perf_stats_hdr hdr;341__u64 data;342};343344/**345* struct qaic_perf_stats_entry - Defines a BO perf info.346* @handle: In. GEM handle of the BO to get perf stats for.347* @queue_level_before: Out. Number of elements in the queue before this BO348* was submitted.349* @num_queue_element: Out. Number of elements added to the queue to submit350* this BO.351* @submit_latency_us: Out. Time taken by the driver to submit this BO.352* @device_latency_us: Out. Time taken by the device to execute this BO.353* @pad: Structure padding. Must be 0.354*/355struct qaic_perf_stats_entry {356__u32 handle;357__u32 queue_level_before;358__u32 num_queue_element;359__u32 submit_latency_us;360__u32 device_latency_us;361__u32 pad;362};363364/**365* struct qaic_detach_slice - Detaches slicing configuration from BO.366* @handle: In. GEM handle of the BO to detach slicing configuration.367* @pad: Structure padding. Must be 0.368*/369struct qaic_detach_slice {370__u32 handle;371__u32 pad;372};373374#define DRM_QAIC_MANAGE 0x00375#define DRM_QAIC_CREATE_BO 0x01376#define DRM_QAIC_MMAP_BO 0x02377#define DRM_QAIC_ATTACH_SLICE_BO 0x03378#define DRM_QAIC_EXECUTE_BO 0x04379#define DRM_QAIC_PARTIAL_EXECUTE_BO 0x05380#define DRM_QAIC_WAIT_BO 0x06381#define DRM_QAIC_PERF_STATS_BO 0x07382#define DRM_QAIC_DETACH_SLICE_BO 0x08383384#define DRM_IOCTL_QAIC_MANAGE DRM_IOWR(DRM_COMMAND_BASE + DRM_QAIC_MANAGE, struct qaic_manage_msg)385#define DRM_IOCTL_QAIC_CREATE_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_QAIC_CREATE_BO, struct qaic_create_bo)386#define DRM_IOCTL_QAIC_MMAP_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_QAIC_MMAP_BO, struct qaic_mmap_bo)387#define DRM_IOCTL_QAIC_ATTACH_SLICE_BO DRM_IOW(DRM_COMMAND_BASE + DRM_QAIC_ATTACH_SLICE_BO, struct qaic_attach_slice)388#define DRM_IOCTL_QAIC_EXECUTE_BO DRM_IOW(DRM_COMMAND_BASE + DRM_QAIC_EXECUTE_BO, struct qaic_execute)389#define DRM_IOCTL_QAIC_PARTIAL_EXECUTE_BO DRM_IOW(DRM_COMMAND_BASE + DRM_QAIC_PARTIAL_EXECUTE_BO, struct qaic_execute)390#define DRM_IOCTL_QAIC_WAIT_BO DRM_IOW(DRM_COMMAND_BASE + DRM_QAIC_WAIT_BO, struct qaic_wait)391#define DRM_IOCTL_QAIC_PERF_STATS_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_QAIC_PERF_STATS_BO, struct qaic_perf_stats)392#define DRM_IOCTL_QAIC_DETACH_SLICE_BO DRM_IOW(DRM_COMMAND_BASE + DRM_QAIC_DETACH_SLICE_BO, struct qaic_detach_slice)393394#if defined(__cplusplus)395}396#endif397398#endif /* QAIC_ACCEL_H_ */399400401