/*1* Copyright © 2014-2015 Broadcom2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223#ifndef _UAPI_VC4_DRM_H_24#define _UAPI_VC4_DRM_H_2526#include "drm.h"2728#if defined(__cplusplus)29extern "C" {30#endif3132#define DRM_VC4_SUBMIT_CL 0x0033#define DRM_VC4_WAIT_SEQNO 0x0134#define DRM_VC4_WAIT_BO 0x0235#define DRM_VC4_CREATE_BO 0x0336#define DRM_VC4_MMAP_BO 0x0437#define DRM_VC4_CREATE_SHADER_BO 0x0538#define DRM_VC4_GET_HANG_STATE 0x0639#define DRM_VC4_GET_PARAM 0x0740#define DRM_VC4_SET_TILING 0x0841#define DRM_VC4_GET_TILING 0x0942#define DRM_VC4_LABEL_BO 0x0a43#define DRM_VC4_GEM_MADVISE 0x0b44#define DRM_VC4_PERFMON_CREATE 0x0c45#define DRM_VC4_PERFMON_DESTROY 0x0d46#define DRM_VC4_PERFMON_GET_VALUES 0x0e4748#define DRM_IOCTL_VC4_SUBMIT_CL DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_SUBMIT_CL, struct drm_vc4_submit_cl)49#define DRM_IOCTL_VC4_WAIT_SEQNO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_WAIT_SEQNO, struct drm_vc4_wait_seqno)50#define DRM_IOCTL_VC4_WAIT_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_WAIT_BO, struct drm_vc4_wait_bo)51#define DRM_IOCTL_VC4_CREATE_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_CREATE_BO, struct drm_vc4_create_bo)52#define DRM_IOCTL_VC4_MMAP_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_MMAP_BO, struct drm_vc4_mmap_bo)53#define DRM_IOCTL_VC4_CREATE_SHADER_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_CREATE_SHADER_BO, struct drm_vc4_create_shader_bo)54#define DRM_IOCTL_VC4_GET_HANG_STATE DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_GET_HANG_STATE, struct drm_vc4_get_hang_state)55#define DRM_IOCTL_VC4_GET_PARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_GET_PARAM, struct drm_vc4_get_param)56#define DRM_IOCTL_VC4_SET_TILING DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_SET_TILING, struct drm_vc4_set_tiling)57#define DRM_IOCTL_VC4_GET_TILING DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_GET_TILING, struct drm_vc4_get_tiling)58#define DRM_IOCTL_VC4_LABEL_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_LABEL_BO, struct drm_vc4_label_bo)59#define DRM_IOCTL_VC4_GEM_MADVISE DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_GEM_MADVISE, struct drm_vc4_gem_madvise)60#define DRM_IOCTL_VC4_PERFMON_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_PERFMON_CREATE, struct drm_vc4_perfmon_create)61#define DRM_IOCTL_VC4_PERFMON_DESTROY DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_PERFMON_DESTROY, struct drm_vc4_perfmon_destroy)62#define DRM_IOCTL_VC4_PERFMON_GET_VALUES DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_PERFMON_GET_VALUES, struct drm_vc4_perfmon_get_values)6364struct drm_vc4_submit_rcl_surface {65__u32 hindex; /* Handle index, or ~0 if not present. */66__u32 offset; /* Offset to start of buffer. */67/*68* Bits for either render config (color_write) or load/store packet.69* Bits should all be 0 for MSAA load/stores.70*/71__u16 bits;7273#define VC4_SUBMIT_RCL_SURFACE_READ_IS_FULL_RES (1 << 0)74__u16 flags;75};7677/**78* struct drm_vc4_submit_cl - ioctl argument for submitting commands to the 3D79* engine.80*81* Drivers typically use GPU BOs to store batchbuffers / command lists and82* their associated state. However, because the VC4 lacks an MMU, we have to83* do validation of memory accesses by the GPU commands. If we were to store84* our commands in BOs, we'd need to do uncached readback from them to do the85* validation process, which is too expensive. Instead, userspace accumulates86* commands and associated state in plain memory, then the kernel copies the87* data to its own address space, and then validates and stores it in a GPU88* BO.89*/90struct drm_vc4_submit_cl {91/* Pointer to the binner command list.92*93* This is the first set of commands executed, which runs the94* coordinate shader to determine where primitives land on the screen,95* then writes out the state updates and draw calls necessary per tile96* to the tile allocation BO.97*/98__u64 bin_cl;99100/* Pointer to the shader records.101*102* Shader records are the structures read by the hardware that contain103* pointers to uniforms, shaders, and vertex attributes. The104* reference to the shader record has enough information to determine105* how many pointers are necessary (fixed number for shaders/uniforms,106* and an attribute count), so those BO indices into bo_handles are107* just stored as __u32s before each shader record passed in.108*/109__u64 shader_rec;110111/* Pointer to uniform data and texture handles for the textures112* referenced by the shader.113*114* For each shader state record, there is a set of uniform data in the115* order referenced by the record (FS, VS, then CS). Each set of116* uniform data has a __u32 index into bo_handles per texture117* sample operation, in the order the QPU_W_TMUn_S writes appear in118* the program. Following the texture BO handle indices is the actual119* uniform data.120*121* The individual uniform state blocks don't have sizes passed in,122* because the kernel has to determine the sizes anyway during shader123* code validation.124*/125__u64 uniforms;126__u64 bo_handles;127128/* Size in bytes of the binner command list. */129__u32 bin_cl_size;130/* Size in bytes of the set of shader records. */131__u32 shader_rec_size;132/* Number of shader records.133*134* This could just be computed from the contents of shader_records and135* the address bits of references to them from the bin CL, but it136* keeps the kernel from having to resize some allocations it makes.137*/138__u32 shader_rec_count;139/* Size in bytes of the uniform state. */140__u32 uniforms_size;141142/* Number of BO handles passed in (size is that times 4). */143__u32 bo_handle_count;144145/* RCL setup: */146__u16 width;147__u16 height;148__u8 min_x_tile;149__u8 min_y_tile;150__u8 max_x_tile;151__u8 max_y_tile;152struct drm_vc4_submit_rcl_surface color_read;153struct drm_vc4_submit_rcl_surface color_write;154struct drm_vc4_submit_rcl_surface zs_read;155struct drm_vc4_submit_rcl_surface zs_write;156struct drm_vc4_submit_rcl_surface msaa_color_write;157struct drm_vc4_submit_rcl_surface msaa_zs_write;158__u32 clear_color[2];159__u32 clear_z;160__u8 clear_s;161162__u32 pad:24;163164#define VC4_SUBMIT_CL_USE_CLEAR_COLOR (1 << 0)165/* By default, the kernel gets to choose the order that the tiles are166* rendered in. If this is set, then the tiles will be rendered in a167* raster order, with the right-to-left vs left-to-right and168* top-to-bottom vs bottom-to-top dictated by169* VC4_SUBMIT_CL_RCL_ORDER_INCREASING_*. This allows overlapping170* blits to be implemented using the 3D engine.171*/172#define VC4_SUBMIT_CL_FIXED_RCL_ORDER (1 << 1)173#define VC4_SUBMIT_CL_RCL_ORDER_INCREASING_X (1 << 2)174#define VC4_SUBMIT_CL_RCL_ORDER_INCREASING_Y (1 << 3)175__u32 flags;176177/* Returned value of the seqno of this render job (for the178* wait ioctl).179*/180__u64 seqno;181182/* ID of the perfmon to attach to this job. 0 means no perfmon. */183__u32 perfmonid;184185/* Syncobj handle to wait on. If set, processing of this render job186* will not start until the syncobj is signaled. 0 means ignore.187*/188__u32 in_sync;189190/* Syncobj handle to export fence to. If set, the fence in the syncobj191* will be replaced with a fence that signals upon completion of this192* render job. 0 means ignore.193*/194__u32 out_sync;195196__u32 pad2;197};198199/**200* struct drm_vc4_wait_seqno - ioctl argument for waiting for201* DRM_VC4_SUBMIT_CL completion using its returned seqno.202*203* timeout_ns is the timeout in nanoseconds, where "0" means "don't204* block, just return the status."205*/206struct drm_vc4_wait_seqno {207__u64 seqno;208__u64 timeout_ns;209};210211/**212* struct drm_vc4_wait_bo - ioctl argument for waiting for213* completion of the last DRM_VC4_SUBMIT_CL on a BO.214*215* This is useful for cases where multiple processes might be216* rendering to a BO and you want to wait for all rendering to be217* completed.218*/219struct drm_vc4_wait_bo {220__u32 handle;221__u32 pad;222__u64 timeout_ns;223};224225/**226* struct drm_vc4_create_bo - ioctl argument for creating VC4 BOs.227*228* There are currently no values for the flags argument, but it may be229* used in a future extension.230*/231struct drm_vc4_create_bo {232__u32 size;233__u32 flags;234/** Returned GEM handle for the BO. */235__u32 handle;236__u32 pad;237};238239/**240* struct drm_vc4_mmap_bo - ioctl argument for mapping VC4 BOs.241*242* This doesn't actually perform an mmap. Instead, it returns the243* offset you need to use in an mmap on the DRM device node. This244* means that tools like valgrind end up knowing about the mapped245* memory.246*247* There are currently no values for the flags argument, but it may be248* used in a future extension.249*/250struct drm_vc4_mmap_bo {251/** Handle for the object being mapped. */252__u32 handle;253__u32 flags;254/** offset into the drm node to use for subsequent mmap call. */255__u64 offset;256};257258/**259* struct drm_vc4_create_shader_bo - ioctl argument for creating VC4260* shader BOs.261*262* Since allowing a shader to be overwritten while it's also being263* executed from would allow privlege escalation, shaders must be264* created using this ioctl, and they can't be mmapped later.265*/266struct drm_vc4_create_shader_bo {267/* Size of the data argument. */268__u32 size;269/* Flags, currently must be 0. */270__u32 flags;271272/* Pointer to the data. */273__u64 data;274275/** Returned GEM handle for the BO. */276__u32 handle;277/* Pad, must be 0. */278__u32 pad;279};280281struct drm_vc4_get_hang_state_bo {282__u32 handle;283__u32 paddr;284__u32 size;285__u32 pad;286};287288/**289* struct drm_vc4_hang_state - ioctl argument for collecting state290* from a GPU hang for analysis.291*/292struct drm_vc4_get_hang_state {293/** Pointer to array of struct drm_vc4_get_hang_state_bo. */294__u64 bo;295/**296* On input, the size of the bo array. Output is the number297* of bos to be returned.298*/299__u32 bo_count;300301__u32 start_bin, start_render;302303__u32 ct0ca, ct0ea;304__u32 ct1ca, ct1ea;305__u32 ct0cs, ct1cs;306__u32 ct0ra0, ct1ra0;307308__u32 bpca, bpcs;309__u32 bpoa, bpos;310311__u32 vpmbase;312313__u32 dbge;314__u32 fdbgo;315__u32 fdbgb;316__u32 fdbgr;317__u32 fdbgs;318__u32 errstat;319320/* Pad that we may save more registers into in the future. */321__u32 pad[16];322};323324#define DRM_VC4_PARAM_V3D_IDENT0 0325#define DRM_VC4_PARAM_V3D_IDENT1 1326#define DRM_VC4_PARAM_V3D_IDENT2 2327#define DRM_VC4_PARAM_SUPPORTS_BRANCHES 3328#define DRM_VC4_PARAM_SUPPORTS_ETC1 4329#define DRM_VC4_PARAM_SUPPORTS_THREADED_FS 5330#define DRM_VC4_PARAM_SUPPORTS_FIXED_RCL_ORDER 6331#define DRM_VC4_PARAM_SUPPORTS_MADVISE 7332#define DRM_VC4_PARAM_SUPPORTS_PERFMON 8333334struct drm_vc4_get_param {335__u32 param;336__u32 pad;337__u64 value;338};339340struct drm_vc4_get_tiling {341__u32 handle;342__u32 flags;343__u64 modifier;344};345346struct drm_vc4_set_tiling {347__u32 handle;348__u32 flags;349__u64 modifier;350};351352/**353* struct drm_vc4_label_bo - Attach a name to a BO for debug purposes.354*/355struct drm_vc4_label_bo {356__u32 handle;357__u32 len;358__u64 name;359};360361/*362* States prefixed with '__' are internal states and cannot be passed to the363* DRM_IOCTL_VC4_GEM_MADVISE ioctl.364*/365#define VC4_MADV_WILLNEED 0366#define VC4_MADV_DONTNEED 1367#define __VC4_MADV_PURGED 2368#define __VC4_MADV_NOTSUPP 3369370struct drm_vc4_gem_madvise {371__u32 handle;372__u32 madv;373__u32 retained;374__u32 pad;375};376377enum {378VC4_PERFCNT_FEP_VALID_PRIMS_NO_RENDER,379VC4_PERFCNT_FEP_VALID_PRIMS_RENDER,380VC4_PERFCNT_FEP_CLIPPED_QUADS,381VC4_PERFCNT_FEP_VALID_QUADS,382VC4_PERFCNT_TLB_QUADS_NOT_PASSING_STENCIL,383VC4_PERFCNT_TLB_QUADS_NOT_PASSING_Z_AND_STENCIL,384VC4_PERFCNT_TLB_QUADS_PASSING_Z_AND_STENCIL,385VC4_PERFCNT_TLB_QUADS_ZERO_COVERAGE,386VC4_PERFCNT_TLB_QUADS_NON_ZERO_COVERAGE,387VC4_PERFCNT_TLB_QUADS_WRITTEN_TO_COLOR_BUF,388VC4_PERFCNT_PLB_PRIMS_OUTSIDE_VIEWPORT,389VC4_PERFCNT_PLB_PRIMS_NEED_CLIPPING,390VC4_PERFCNT_PSE_PRIMS_REVERSED,391VC4_PERFCNT_QPU_TOTAL_IDLE_CYCLES,392VC4_PERFCNT_QPU_TOTAL_CLK_CYCLES_VERTEX_COORD_SHADING,393VC4_PERFCNT_QPU_TOTAL_CLK_CYCLES_FRAGMENT_SHADING,394VC4_PERFCNT_QPU_TOTAL_CLK_CYCLES_EXEC_VALID_INST,395VC4_PERFCNT_QPU_TOTAL_CLK_CYCLES_WAITING_TMUS,396VC4_PERFCNT_QPU_TOTAL_CLK_CYCLES_WAITING_SCOREBOARD,397VC4_PERFCNT_QPU_TOTAL_CLK_CYCLES_WAITING_VARYINGS,398VC4_PERFCNT_QPU_TOTAL_INST_CACHE_HIT,399VC4_PERFCNT_QPU_TOTAL_INST_CACHE_MISS,400VC4_PERFCNT_QPU_TOTAL_UNIFORM_CACHE_HIT,401VC4_PERFCNT_QPU_TOTAL_UNIFORM_CACHE_MISS,402VC4_PERFCNT_TMU_TOTAL_TEXT_QUADS_PROCESSED,403VC4_PERFCNT_TMU_TOTAL_TEXT_CACHE_MISS,404VC4_PERFCNT_VPM_TOTAL_CLK_CYCLES_VDW_STALLED,405VC4_PERFCNT_VPM_TOTAL_CLK_CYCLES_VCD_STALLED,406VC4_PERFCNT_L2C_TOTAL_L2_CACHE_HIT,407VC4_PERFCNT_L2C_TOTAL_L2_CACHE_MISS,408VC4_PERFCNT_NUM_EVENTS,409};410411#define DRM_VC4_MAX_PERF_COUNTERS 16412413struct drm_vc4_perfmon_create {414__u32 id;415__u32 ncounters;416__u8 events[DRM_VC4_MAX_PERF_COUNTERS];417};418419struct drm_vc4_perfmon_destroy {420__u32 id;421};422423/*424* Returns the values of the performance counters tracked by this425* perfmon (as an array of ncounters u64 values).426*427* No implicit synchronization is performed, so the user has to428* guarantee that any jobs using this perfmon have already been429* completed (probably by blocking on the seqno returned by the430* last exec that used the perfmon).431*/432struct drm_vc4_perfmon_get_values {433__u32 id;434__u64 values_ptr;435};436437#if defined(__cplusplus)438}439#endif440441#endif /* _UAPI_VC4_DRM_H_ */442443444