/* 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 0x092425#define DRM_IOCTL_PANFROST_SUBMIT DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_SUBMIT, struct drm_panfrost_submit)26#define DRM_IOCTL_PANFROST_WAIT_BO DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_WAIT_BO, struct drm_panfrost_wait_bo)27#define DRM_IOCTL_PANFROST_CREATE_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_CREATE_BO, struct drm_panfrost_create_bo)28#define DRM_IOCTL_PANFROST_MMAP_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_MMAP_BO, struct drm_panfrost_mmap_bo)29#define DRM_IOCTL_PANFROST_GET_PARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_GET_PARAM, struct drm_panfrost_get_param)30#define DRM_IOCTL_PANFROST_GET_BO_OFFSET DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_GET_BO_OFFSET, struct drm_panfrost_get_bo_offset)31#define DRM_IOCTL_PANFROST_MADVISE DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_MADVISE, struct drm_panfrost_madvise)32#define DRM_IOCTL_PANFROST_SET_LABEL_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_SET_LABEL_BO, struct drm_panfrost_set_label_bo)3334/*35* Unstable ioctl(s): only exposed when the unsafe unstable_ioctls module36* param is set to true.37* All these ioctl(s) are subject to deprecation, so please don't rely on38* them for anything but debugging purpose.39*/40#define DRM_IOCTL_PANFROST_PERFCNT_ENABLE DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_PERFCNT_ENABLE, struct drm_panfrost_perfcnt_enable)41#define DRM_IOCTL_PANFROST_PERFCNT_DUMP DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_PERFCNT_DUMP, struct drm_panfrost_perfcnt_dump)4243#define PANFROST_JD_REQ_FS (1 << 0)44#define PANFROST_JD_REQ_CYCLE_COUNT (1 << 1)45/**46* struct drm_panfrost_submit - ioctl argument for submitting commands to the 3D47* engine.48*49* This asks the kernel to have the GPU execute a render command list.50*/51struct drm_panfrost_submit {5253/** Address to GPU mapping of job descriptor */54__u64 jc;5556/** An optional array of sync objects to wait on before starting this job. */57__u64 in_syncs;5859/** Number of sync objects to wait on before starting this job. */60__u32 in_sync_count;6162/** An optional sync object to place the completion fence in. */63__u32 out_sync;6465/** Pointer to a u32 array of the BOs that are referenced by the job. */66__u64 bo_handles;6768/** Number of BO handles passed in (size is that times 4). */69__u32 bo_handle_count;7071/** A combination of PANFROST_JD_REQ_* */72__u32 requirements;73};7475/**76* struct drm_panfrost_wait_bo - ioctl argument for waiting for77* completion of the last DRM_PANFROST_SUBMIT on a BO.78*79* This is useful for cases where multiple processes might be80* rendering to a BO and you want to wait for all rendering to be81* completed.82*/83struct drm_panfrost_wait_bo {84__u32 handle;85__u32 pad;86__s64 timeout_ns; /* absolute */87};8889/* Valid flags to pass to drm_panfrost_create_bo */90#define PANFROST_BO_NOEXEC 191#define PANFROST_BO_HEAP 29293/**94* struct drm_panfrost_create_bo - ioctl argument for creating Panfrost BOs.95*96* The flags argument is a bit mask of PANFROST_BO_* flags.97*/98struct drm_panfrost_create_bo {99__u32 size;100__u32 flags;101/** Returned GEM handle for the BO. */102__u32 handle;103/* Pad, must be zero-filled. */104__u32 pad;105/**106* Returned offset for the BO in the GPU address space. This offset107* is private to the DRM fd and is valid for the lifetime of the GEM108* handle.109*110* This offset value will always be nonzero, since various HW111* units treat 0 specially.112*/113__u64 offset;114};115116/**117* struct drm_panfrost_mmap_bo - ioctl argument for mapping Panfrost BOs.118*119* This doesn't actually perform an mmap. Instead, it returns the120* offset you need to use in an mmap on the DRM device node. This121* means that tools like valgrind end up knowing about the mapped122* memory.123*124* There are currently no values for the flags argument, but it may be125* used in a future extension.126*/127struct drm_panfrost_mmap_bo {128/** Handle for the object being mapped. */129__u32 handle;130__u32 flags;131/** offset into the drm node to use for subsequent mmap call. */132__u64 offset;133};134135enum drm_panfrost_param {136DRM_PANFROST_PARAM_GPU_PROD_ID,137DRM_PANFROST_PARAM_GPU_REVISION,138DRM_PANFROST_PARAM_SHADER_PRESENT,139DRM_PANFROST_PARAM_TILER_PRESENT,140DRM_PANFROST_PARAM_L2_PRESENT,141DRM_PANFROST_PARAM_STACK_PRESENT,142DRM_PANFROST_PARAM_AS_PRESENT,143DRM_PANFROST_PARAM_JS_PRESENT,144DRM_PANFROST_PARAM_L2_FEATURES,145DRM_PANFROST_PARAM_CORE_FEATURES,146DRM_PANFROST_PARAM_TILER_FEATURES,147DRM_PANFROST_PARAM_MEM_FEATURES,148DRM_PANFROST_PARAM_MMU_FEATURES,149DRM_PANFROST_PARAM_THREAD_FEATURES,150DRM_PANFROST_PARAM_MAX_THREADS,151DRM_PANFROST_PARAM_THREAD_MAX_WORKGROUP_SZ,152DRM_PANFROST_PARAM_THREAD_MAX_BARRIER_SZ,153DRM_PANFROST_PARAM_COHERENCY_FEATURES,154DRM_PANFROST_PARAM_TEXTURE_FEATURES0,155DRM_PANFROST_PARAM_TEXTURE_FEATURES1,156DRM_PANFROST_PARAM_TEXTURE_FEATURES2,157DRM_PANFROST_PARAM_TEXTURE_FEATURES3,158DRM_PANFROST_PARAM_JS_FEATURES0,159DRM_PANFROST_PARAM_JS_FEATURES1,160DRM_PANFROST_PARAM_JS_FEATURES2,161DRM_PANFROST_PARAM_JS_FEATURES3,162DRM_PANFROST_PARAM_JS_FEATURES4,163DRM_PANFROST_PARAM_JS_FEATURES5,164DRM_PANFROST_PARAM_JS_FEATURES6,165DRM_PANFROST_PARAM_JS_FEATURES7,166DRM_PANFROST_PARAM_JS_FEATURES8,167DRM_PANFROST_PARAM_JS_FEATURES9,168DRM_PANFROST_PARAM_JS_FEATURES10,169DRM_PANFROST_PARAM_JS_FEATURES11,170DRM_PANFROST_PARAM_JS_FEATURES12,171DRM_PANFROST_PARAM_JS_FEATURES13,172DRM_PANFROST_PARAM_JS_FEATURES14,173DRM_PANFROST_PARAM_JS_FEATURES15,174DRM_PANFROST_PARAM_NR_CORE_GROUPS,175DRM_PANFROST_PARAM_THREAD_TLS_ALLOC,176DRM_PANFROST_PARAM_AFBC_FEATURES,177DRM_PANFROST_PARAM_SYSTEM_TIMESTAMP,178DRM_PANFROST_PARAM_SYSTEM_TIMESTAMP_FREQUENCY,179};180181struct drm_panfrost_get_param {182__u32 param;183__u32 pad;184__u64 value;185};186187/**188* Returns the offset for the BO in the GPU address space for this DRM fd.189* This is the same value returned by drm_panfrost_create_bo, if that was called190* from this DRM fd.191*/192struct drm_panfrost_get_bo_offset {193__u32 handle;194__u32 pad;195__u64 offset;196};197198struct drm_panfrost_perfcnt_enable {199__u32 enable;200/*201* On bifrost we have 2 sets of counters, this parameter defines the202* one to track.203*/204__u32 counterset;205};206207struct drm_panfrost_perfcnt_dump {208__u64 buf_ptr;209};210211/* madvise provides a way to tell the kernel in case a buffers contents212* can be discarded under memory pressure, which is useful for userspace213* bo cache where we want to optimistically hold on to buffer allocate214* and potential mmap, but allow the pages to be discarded under memory215* pressure.216*217* Typical usage would involve madvise(DONTNEED) when buffer enters BO218* cache, and madvise(WILLNEED) if trying to recycle buffer from BO cache.219* In the WILLNEED case, 'retained' indicates to userspace whether the220* backing pages still exist.221*/222#define PANFROST_MADV_WILLNEED 0 /* backing pages are needed, status returned in 'retained' */223#define PANFROST_MADV_DONTNEED 1 /* backing pages not needed */224225struct drm_panfrost_madvise {226__u32 handle; /* in, GEM handle */227__u32 madv; /* in, PANFROST_MADV_x */228__u32 retained; /* out, whether backing store still exists */229};230231/**232* struct drm_panfrost_set_label_bo - ioctl argument for labelling Panfrost BOs.233*/234struct drm_panfrost_set_label_bo {235/** @handle: Handle of the buffer object to label. */236__u32 handle;237238/** @pad: MBZ. */239__u32 pad;240241/**242* @label: User pointer to a NUL-terminated string243*244* Length cannot be greater than 4096.245* NULL is permitted and means clear the label.246*/247__u64 label;248};249250/* Definitions for coredump decoding in user space */251#define PANFROSTDUMP_MAJOR 1252#define PANFROSTDUMP_MINOR 0253254#define PANFROSTDUMP_MAGIC 0x464E4150 /* PANF */255256#define PANFROSTDUMP_BUF_REG 0257#define PANFROSTDUMP_BUF_BOMAP (PANFROSTDUMP_BUF_REG + 1)258#define PANFROSTDUMP_BUF_BO (PANFROSTDUMP_BUF_BOMAP + 1)259#define PANFROSTDUMP_BUF_TRAILER (PANFROSTDUMP_BUF_BO + 1)260261/*262* This structure is the native endianness of the dumping machine, tools can263* detect the endianness by looking at the value in 'magic'.264*/265struct panfrost_dump_object_header {266__u32 magic;267__u32 type;268__u32 file_size;269__u32 file_offset;270271union {272struct {273__u64 jc;274__u32 gpu_id;275__u32 major;276__u32 minor;277__u64 nbos;278} reghdr;279280struct {281__u32 valid;282__u64 iova;283__u32 data[2];284} bomap;285286/*287* Force same size in case we want to expand the header288* with new fields and also keep it 512-byte aligned289*/290291__u32 sizer[496];292};293};294295/* Registers object, an array of these */296struct panfrost_dump_registers {297__u32 reg;298__u32 value;299};300301#if defined(__cplusplus)302}303#endif304305#endif /* _PANFROST_DRM_H_ */306307308