/* SPDX-License-Identifier: MIT */1/*2* Copyright © 2014-2018 Broadcom3* Copyright © 2019 Collabora ltd.4*/5#ifndef _PANFROST_DRM_H_6#define _PANFROST_DRM_H_78#include "drm.h"910#if defined(__cplusplus)11extern "C" {12#endif1314#define DRM_PANFROST_SUBMIT 0x0015#define DRM_PANFROST_WAIT_BO 0x0116#define DRM_PANFROST_CREATE_BO 0x0217#define DRM_PANFROST_MMAP_BO 0x0318#define DRM_PANFROST_GET_PARAM 0x0419#define DRM_PANFROST_GET_BO_OFFSET 0x0520#define DRM_PANFROST_PERFCNT_ENABLE 0x0621#define DRM_PANFROST_PERFCNT_DUMP 0x0722#define DRM_PANFROST_MADVISE 0x0823#define DRM_PANFROST_SET_LABEL_BO 0x0924#define DRM_PANFROST_JM_CTX_CREATE 0x0a25#define DRM_PANFROST_JM_CTX_DESTROY 0x0b2627#define DRM_IOCTL_PANFROST_SUBMIT DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_SUBMIT, struct drm_panfrost_submit)28#define DRM_IOCTL_PANFROST_WAIT_BO DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_WAIT_BO, struct drm_panfrost_wait_bo)29#define DRM_IOCTL_PANFROST_CREATE_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_CREATE_BO, struct drm_panfrost_create_bo)30#define DRM_IOCTL_PANFROST_MMAP_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_MMAP_BO, struct drm_panfrost_mmap_bo)31#define DRM_IOCTL_PANFROST_GET_PARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_GET_PARAM, struct drm_panfrost_get_param)32#define DRM_IOCTL_PANFROST_GET_BO_OFFSET DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_GET_BO_OFFSET, struct drm_panfrost_get_bo_offset)33#define DRM_IOCTL_PANFROST_MADVISE DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_MADVISE, struct drm_panfrost_madvise)34#define DRM_IOCTL_PANFROST_SET_LABEL_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_SET_LABEL_BO, struct drm_panfrost_set_label_bo)35#define DRM_IOCTL_PANFROST_JM_CTX_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_JM_CTX_CREATE, struct drm_panfrost_jm_ctx_create)36#define DRM_IOCTL_PANFROST_JM_CTX_DESTROY DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_JM_CTX_DESTROY, struct drm_panfrost_jm_ctx_destroy)3738/*39* Unstable ioctl(s): only exposed when the unsafe unstable_ioctls module40* param is set to true.41* All these ioctl(s) are subject to deprecation, so please don't rely on42* them for anything but debugging purpose.43*/44#define DRM_IOCTL_PANFROST_PERFCNT_ENABLE DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_PERFCNT_ENABLE, struct drm_panfrost_perfcnt_enable)45#define DRM_IOCTL_PANFROST_PERFCNT_DUMP DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_PERFCNT_DUMP, struct drm_panfrost_perfcnt_dump)4647#define PANFROST_JD_REQ_FS (1 << 0)48#define PANFROST_JD_REQ_CYCLE_COUNT (1 << 1)49/**50* struct drm_panfrost_submit - ioctl argument for submitting commands to the 3D51* engine.52*53* This asks the kernel to have the GPU execute a render command list.54*/55struct drm_panfrost_submit {56/**57* @jc: Address to GPU mapping of job descriptor58*/59__u64 jc;60/**61* @in_syncs: An optional array of sync objects to wait on62* before starting this job.63*/64__u64 in_syncs;65/**66* @in_sync_count: Number of sync objects to wait on before67* starting this job.68*/69__u32 in_sync_count;70/**71* @out_sync: An optional sync object to place the completion fence in.72*/73__u32 out_sync;74/**75* @bo_handles: Pointer to a u32 array of the BOs that are76* referenced by the job.77*/78__u64 bo_handles;79/**80* @bo_handle_count: Number of BO handles passed in (size is81* that times 4).82*/83__u32 bo_handle_count;84/**85* @requirements: A combination of PANFROST_JD_REQ_*86*/87__u32 requirements;88/**89* @jm_ctx_handle: JM context handle. Zero if you want to use the90* default context.91*/92__u32 jm_ctx_handle;93/**94* @pad: Padding field. Must be zero.95*/96__u32 pad;97};9899/**100* struct drm_panfrost_wait_bo - ioctl argument for waiting for101* completion of the last DRM_PANFROST_SUBMIT on a BO.102*103* This is useful for cases where multiple processes might be104* rendering to a BO and you want to wait for all rendering to be105* completed.106*/107struct drm_panfrost_wait_bo {108/**109* @handle: Handle for the object to wait for.110*/111__u32 handle;112/**113* @pad: Padding, must be zero-filled.114*/115__u32 pad;116/**117* @timeout_ns: absolute number of nanoseconds to wait.118*/119__s64 timeout_ns;120};121122/* Valid flags to pass to drm_panfrost_create_bo */123#define PANFROST_BO_NOEXEC 1124#define PANFROST_BO_HEAP 2125126/**127* struct drm_panfrost_create_bo - ioctl argument for creating Panfrost BOs.128*129* The flags argument is a bit mask of PANFROST_BO_* flags.130*/131struct drm_panfrost_create_bo {132/**133* @size: size of shmem/BO area to create (bytes)134*/135__u32 size;136/**137* @flags: see PANFROST_BO_* flags138*/139__u32 flags;140/**141* @handle: Returned GEM handle for the BO.142*/143__u32 handle;144/**145* @pad: Padding, must be zero-filled.146*/147__u32 pad;148/**149* @offset: Returned offset for the BO in the GPU address space.150* This offset is private to the DRM fd and is valid for the151* lifetime of the GEM handle.152*153* This offset value will always be nonzero, since various HW154* units treat 0 specially.155*/156__u64 offset;157};158159/**160* struct drm_panfrost_mmap_bo - ioctl argument for mapping Panfrost BOs.161*162* This doesn't actually perform an mmap. Instead, it returns the163* offset you need to use in an mmap on the DRM device node. This164* means that tools like valgrind end up knowing about the mapped165* memory.166*167* There are currently no values for the flags argument, but it may be168* used in a future extension.169*/170struct drm_panfrost_mmap_bo {171/**172* @handle: Handle for the object being mapped.173*/174__u32 handle;175/**176* @flags: currently not used (should be zero)177*/178__u32 flags;179/**180* @offset: offset into the drm node to use for subsequent mmap call.181*/182__u64 offset;183};184185enum drm_panfrost_param {186DRM_PANFROST_PARAM_GPU_PROD_ID,187DRM_PANFROST_PARAM_GPU_REVISION,188DRM_PANFROST_PARAM_SHADER_PRESENT,189DRM_PANFROST_PARAM_TILER_PRESENT,190DRM_PANFROST_PARAM_L2_PRESENT,191DRM_PANFROST_PARAM_STACK_PRESENT,192DRM_PANFROST_PARAM_AS_PRESENT,193DRM_PANFROST_PARAM_JS_PRESENT,194DRM_PANFROST_PARAM_L2_FEATURES,195DRM_PANFROST_PARAM_CORE_FEATURES,196DRM_PANFROST_PARAM_TILER_FEATURES,197DRM_PANFROST_PARAM_MEM_FEATURES,198DRM_PANFROST_PARAM_MMU_FEATURES,199DRM_PANFROST_PARAM_THREAD_FEATURES,200DRM_PANFROST_PARAM_MAX_THREADS,201DRM_PANFROST_PARAM_THREAD_MAX_WORKGROUP_SZ,202DRM_PANFROST_PARAM_THREAD_MAX_BARRIER_SZ,203DRM_PANFROST_PARAM_COHERENCY_FEATURES,204DRM_PANFROST_PARAM_TEXTURE_FEATURES0,205DRM_PANFROST_PARAM_TEXTURE_FEATURES1,206DRM_PANFROST_PARAM_TEXTURE_FEATURES2,207DRM_PANFROST_PARAM_TEXTURE_FEATURES3,208DRM_PANFROST_PARAM_JS_FEATURES0,209DRM_PANFROST_PARAM_JS_FEATURES1,210DRM_PANFROST_PARAM_JS_FEATURES2,211DRM_PANFROST_PARAM_JS_FEATURES3,212DRM_PANFROST_PARAM_JS_FEATURES4,213DRM_PANFROST_PARAM_JS_FEATURES5,214DRM_PANFROST_PARAM_JS_FEATURES6,215DRM_PANFROST_PARAM_JS_FEATURES7,216DRM_PANFROST_PARAM_JS_FEATURES8,217DRM_PANFROST_PARAM_JS_FEATURES9,218DRM_PANFROST_PARAM_JS_FEATURES10,219DRM_PANFROST_PARAM_JS_FEATURES11,220DRM_PANFROST_PARAM_JS_FEATURES12,221DRM_PANFROST_PARAM_JS_FEATURES13,222DRM_PANFROST_PARAM_JS_FEATURES14,223DRM_PANFROST_PARAM_JS_FEATURES15,224DRM_PANFROST_PARAM_NR_CORE_GROUPS,225DRM_PANFROST_PARAM_THREAD_TLS_ALLOC,226DRM_PANFROST_PARAM_AFBC_FEATURES,227DRM_PANFROST_PARAM_SYSTEM_TIMESTAMP,228DRM_PANFROST_PARAM_SYSTEM_TIMESTAMP_FREQUENCY,229DRM_PANFROST_PARAM_ALLOWED_JM_CTX_PRIORITIES,230};231232struct drm_panfrost_get_param {233__u32 param;234__u32 pad;235__u64 value;236};237238/*239* Returns the offset for the BO in the GPU address space for this DRM fd.240* This is the same value returned by drm_panfrost_create_bo, if that was called241* from this DRM fd.242*/243struct drm_panfrost_get_bo_offset {244__u32 handle;245__u32 pad;246__u64 offset;247};248249struct drm_panfrost_perfcnt_enable {250__u32 enable;251/*252* On bifrost we have 2 sets of counters, this parameter defines the253* one to track.254*/255__u32 counterset;256};257258struct drm_panfrost_perfcnt_dump {259__u64 buf_ptr;260};261262/* madvise provides a way to tell the kernel in case a buffers contents263* can be discarded under memory pressure, which is useful for userspace264* bo cache where we want to optimistically hold on to buffer allocate265* and potential mmap, but allow the pages to be discarded under memory266* pressure.267*268* Typical usage would involve madvise(DONTNEED) when buffer enters BO269* cache, and madvise(WILLNEED) if trying to recycle buffer from BO cache.270* In the WILLNEED case, 'retained' indicates to userspace whether the271* backing pages still exist.272*/273#define PANFROST_MADV_WILLNEED 0 /* backing pages are needed, status returned in 'retained' */274#define PANFROST_MADV_DONTNEED 1 /* backing pages not needed */275276struct drm_panfrost_madvise {277__u32 handle; /* in, GEM handle */278__u32 madv; /* in, PANFROST_MADV_x */279__u32 retained; /* out, whether backing store still exists */280};281282/**283* struct drm_panfrost_set_label_bo - ioctl argument for labelling Panfrost BOs.284*/285struct drm_panfrost_set_label_bo {286/**287* @handle: Handle of the buffer object to label.288*/289__u32 handle;290/**291* @pad: Must be zero.292*/293__u32 pad;294/**295* @label: User pointer to a NUL-terminated string296*297* Length cannot be greater than 4096.298* NULL is permitted and means clear the label.299*/300__u64 label;301};302303/* Definitions for coredump decoding in user space */304#define PANFROSTDUMP_MAJOR 1305#define PANFROSTDUMP_MINOR 0306307#define PANFROSTDUMP_MAGIC 0x464E4150 /* PANF */308309#define PANFROSTDUMP_BUF_REG 0310#define PANFROSTDUMP_BUF_BOMAP (PANFROSTDUMP_BUF_REG + 1)311#define PANFROSTDUMP_BUF_BO (PANFROSTDUMP_BUF_BOMAP + 1)312#define PANFROSTDUMP_BUF_TRAILER (PANFROSTDUMP_BUF_BO + 1)313314/*315* This structure is the native endianness of the dumping machine, tools can316* detect the endianness by looking at the value in 'magic'.317*/318struct panfrost_dump_object_header {319__u32 magic;320__u32 type;321__u32 file_size;322__u32 file_offset;323324union {325struct {326__u64 jc;327__u32 gpu_id;328__u32 major;329__u32 minor;330__u64 nbos;331} reghdr;332333struct {334__u32 valid;335__u64 iova;336__u32 data[2];337} bomap;338339/*340* Force same size in case we want to expand the header341* with new fields and also keep it 512-byte aligned342*/343344__u32 sizer[496];345};346};347348/* Registers object, an array of these */349struct panfrost_dump_registers {350__u32 reg;351__u32 value;352};353354enum drm_panfrost_jm_ctx_priority {355/**356* @PANFROST_JM_CTX_PRIORITY_LOW: Low priority context.357*/358PANFROST_JM_CTX_PRIORITY_LOW = 0,359360/**361* @PANFROST_JM_CTX_PRIORITY_MEDIUM: Medium priority context.362*/363PANFROST_JM_CTX_PRIORITY_MEDIUM,364365/**366* @PANFROST_JM_CTX_PRIORITY_HIGH: High priority context.367*368* Requires CAP_SYS_NICE or DRM_MASTER.369*/370PANFROST_JM_CTX_PRIORITY_HIGH,371};372373struct drm_panfrost_jm_ctx_create {374/**375* @handle: Handle of the created JM context376*/377__u32 handle;378/**379* @priority: Context priority (see enum drm_panfrost_jm_ctx_priority).380*/381__u32 priority;382};383384struct drm_panfrost_jm_ctx_destroy {385/**386* @handle: Handle of the JM context to destroy.387*388* Must be a valid context handle returned by DRM_IOCTL_PANTHOR_JM_CTX_CREATE.389*/390__u32 handle;391/**392* @pad: Padding field, must be zero.393*/394__u32 pad;395};396397#if defined(__cplusplus)398}399#endif400401#endif /* _PANFROST_DRM_H_ */402403404