vc4_drm.h revision d8807b2f
13f012e29Smrg/* 23f012e29Smrg * Copyright © 2014-2015 Broadcom 33f012e29Smrg * 43f012e29Smrg * Permission is hereby granted, free of charge, to any person obtaining a 53f012e29Smrg * copy of this software and associated documentation files (the "Software"), 63f012e29Smrg * to deal in the Software without restriction, including without limitation 73f012e29Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 83f012e29Smrg * and/or sell copies of the Software, and to permit persons to whom the 93f012e29Smrg * Software is furnished to do so, subject to the following conditions: 103f012e29Smrg * 113f012e29Smrg * The above copyright notice and this permission notice (including the next 123f012e29Smrg * paragraph) shall be included in all copies or substantial portions of the 133f012e29Smrg * Software. 143f012e29Smrg * 153f012e29Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 163f012e29Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 173f012e29Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 183f012e29Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 193f012e29Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 203f012e29Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 213f012e29Smrg * IN THE SOFTWARE. 223f012e29Smrg */ 233f012e29Smrg 24d8807b2fSmrg#ifndef _UAPI_VC4_DRM_H_ 25d8807b2fSmrg#define _UAPI_VC4_DRM_H_ 263f012e29Smrg 273f012e29Smrg#include "drm.h" 283f012e29Smrg 293f012e29Smrg#if defined(__cplusplus) 303f012e29Smrgextern "C" { 313f012e29Smrg#endif 323f012e29Smrg 333f012e29Smrg#define DRM_VC4_SUBMIT_CL 0x00 343f012e29Smrg#define DRM_VC4_WAIT_SEQNO 0x01 353f012e29Smrg#define DRM_VC4_WAIT_BO 0x02 363f012e29Smrg#define DRM_VC4_CREATE_BO 0x03 373f012e29Smrg#define DRM_VC4_MMAP_BO 0x04 383f012e29Smrg#define DRM_VC4_CREATE_SHADER_BO 0x05 393f012e29Smrg#define DRM_VC4_GET_HANG_STATE 0x06 403f012e29Smrg#define DRM_VC4_GET_PARAM 0x07 41d8807b2fSmrg#define DRM_VC4_SET_TILING 0x08 42d8807b2fSmrg#define DRM_VC4_GET_TILING 0x09 433f012e29Smrg 443f012e29Smrg#define DRM_IOCTL_VC4_SUBMIT_CL DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_SUBMIT_CL, struct drm_vc4_submit_cl) 453f012e29Smrg#define DRM_IOCTL_VC4_WAIT_SEQNO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_WAIT_SEQNO, struct drm_vc4_wait_seqno) 463f012e29Smrg#define DRM_IOCTL_VC4_WAIT_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_WAIT_BO, struct drm_vc4_wait_bo) 473f012e29Smrg#define DRM_IOCTL_VC4_CREATE_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_CREATE_BO, struct drm_vc4_create_bo) 483f012e29Smrg#define DRM_IOCTL_VC4_MMAP_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_MMAP_BO, struct drm_vc4_mmap_bo) 493f012e29Smrg#define DRM_IOCTL_VC4_CREATE_SHADER_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_CREATE_SHADER_BO, struct drm_vc4_create_shader_bo) 503f012e29Smrg#define DRM_IOCTL_VC4_GET_HANG_STATE DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_GET_HANG_STATE, struct drm_vc4_get_hang_state) 513f012e29Smrg#define DRM_IOCTL_VC4_GET_PARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_GET_PARAM, struct drm_vc4_get_param) 52d8807b2fSmrg#define DRM_IOCTL_VC4_SET_TILING DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_SET_TILING, struct drm_vc4_set_tiling) 53d8807b2fSmrg#define DRM_IOCTL_VC4_GET_TILING DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_GET_TILING, struct drm_vc4_get_tiling) 543f012e29Smrg 553f012e29Smrgstruct drm_vc4_submit_rcl_surface { 563f012e29Smrg __u32 hindex; /* Handle index, or ~0 if not present. */ 573f012e29Smrg __u32 offset; /* Offset to start of buffer. */ 583f012e29Smrg /* 593f012e29Smrg * Bits for either render config (color_write) or load/store packet. 603f012e29Smrg * Bits should all be 0 for MSAA load/stores. 613f012e29Smrg */ 623f012e29Smrg __u16 bits; 633f012e29Smrg 643f012e29Smrg#define VC4_SUBMIT_RCL_SURFACE_READ_IS_FULL_RES (1 << 0) 653f012e29Smrg __u16 flags; 663f012e29Smrg}; 673f012e29Smrg 683f012e29Smrg/** 693f012e29Smrg * struct drm_vc4_submit_cl - ioctl argument for submitting commands to the 3D 703f012e29Smrg * engine. 713f012e29Smrg * 723f012e29Smrg * Drivers typically use GPU BOs to store batchbuffers / command lists and 733f012e29Smrg * their associated state. However, because the VC4 lacks an MMU, we have to 743f012e29Smrg * do validation of memory accesses by the GPU commands. If we were to store 753f012e29Smrg * our commands in BOs, we'd need to do uncached readback from them to do the 763f012e29Smrg * validation process, which is too expensive. Instead, userspace accumulates 773f012e29Smrg * commands and associated state in plain memory, then the kernel copies the 783f012e29Smrg * data to its own address space, and then validates and stores it in a GPU 793f012e29Smrg * BO. 803f012e29Smrg */ 813f012e29Smrgstruct drm_vc4_submit_cl { 823f012e29Smrg /* Pointer to the binner command list. 833f012e29Smrg * 843f012e29Smrg * This is the first set of commands executed, which runs the 853f012e29Smrg * coordinate shader to determine where primitives land on the screen, 863f012e29Smrg * then writes out the state updates and draw calls necessary per tile 873f012e29Smrg * to the tile allocation BO. 883f012e29Smrg */ 893f012e29Smrg __u64 bin_cl; 903f012e29Smrg 913f012e29Smrg /* Pointer to the shader records. 923f012e29Smrg * 933f012e29Smrg * Shader records are the structures read by the hardware that contain 943f012e29Smrg * pointers to uniforms, shaders, and vertex attributes. The 953f012e29Smrg * reference to the shader record has enough information to determine 963f012e29Smrg * how many pointers are necessary (fixed number for shaders/uniforms, 973f012e29Smrg * and an attribute count), so those BO indices into bo_handles are 983f012e29Smrg * just stored as __u32s before each shader record passed in. 993f012e29Smrg */ 1003f012e29Smrg __u64 shader_rec; 1013f012e29Smrg 1023f012e29Smrg /* Pointer to uniform data and texture handles for the textures 1033f012e29Smrg * referenced by the shader. 1043f012e29Smrg * 1053f012e29Smrg * For each shader state record, there is a set of uniform data in the 1063f012e29Smrg * order referenced by the record (FS, VS, then CS). Each set of 1073f012e29Smrg * uniform data has a __u32 index into bo_handles per texture 1083f012e29Smrg * sample operation, in the order the QPU_W_TMUn_S writes appear in 1093f012e29Smrg * the program. Following the texture BO handle indices is the actual 1103f012e29Smrg * uniform data. 1113f012e29Smrg * 1123f012e29Smrg * The individual uniform state blocks don't have sizes passed in, 1133f012e29Smrg * because the kernel has to determine the sizes anyway during shader 1143f012e29Smrg * code validation. 1153f012e29Smrg */ 1163f012e29Smrg __u64 uniforms; 1173f012e29Smrg __u64 bo_handles; 1183f012e29Smrg 1193f012e29Smrg /* Size in bytes of the binner command list. */ 1203f012e29Smrg __u32 bin_cl_size; 1213f012e29Smrg /* Size in bytes of the set of shader records. */ 1223f012e29Smrg __u32 shader_rec_size; 1233f012e29Smrg /* Number of shader records. 1243f012e29Smrg * 1253f012e29Smrg * This could just be computed from the contents of shader_records and 1263f012e29Smrg * the address bits of references to them from the bin CL, but it 1273f012e29Smrg * keeps the kernel from having to resize some allocations it makes. 1283f012e29Smrg */ 1293f012e29Smrg __u32 shader_rec_count; 1303f012e29Smrg /* Size in bytes of the uniform state. */ 1313f012e29Smrg __u32 uniforms_size; 1323f012e29Smrg 1333f012e29Smrg /* Number of BO handles passed in (size is that times 4). */ 1343f012e29Smrg __u32 bo_handle_count; 1353f012e29Smrg 1363f012e29Smrg /* RCL setup: */ 1373f012e29Smrg __u16 width; 1383f012e29Smrg __u16 height; 1393f012e29Smrg __u8 min_x_tile; 1403f012e29Smrg __u8 min_y_tile; 1413f012e29Smrg __u8 max_x_tile; 1423f012e29Smrg __u8 max_y_tile; 1433f012e29Smrg struct drm_vc4_submit_rcl_surface color_read; 1443f012e29Smrg struct drm_vc4_submit_rcl_surface color_write; 1453f012e29Smrg struct drm_vc4_submit_rcl_surface zs_read; 1463f012e29Smrg struct drm_vc4_submit_rcl_surface zs_write; 1473f012e29Smrg struct drm_vc4_submit_rcl_surface msaa_color_write; 1483f012e29Smrg struct drm_vc4_submit_rcl_surface msaa_zs_write; 1493f012e29Smrg __u32 clear_color[2]; 1503f012e29Smrg __u32 clear_z; 1513f012e29Smrg __u8 clear_s; 1523f012e29Smrg 1533f012e29Smrg __u32 pad:24; 1543f012e29Smrg 1553f012e29Smrg#define VC4_SUBMIT_CL_USE_CLEAR_COLOR (1 << 0) 1563f012e29Smrg __u32 flags; 1573f012e29Smrg 1583f012e29Smrg /* Returned value of the seqno of this render job (for the 1593f012e29Smrg * wait ioctl). 1603f012e29Smrg */ 1613f012e29Smrg __u64 seqno; 1623f012e29Smrg}; 1633f012e29Smrg 1643f012e29Smrg/** 1653f012e29Smrg * struct drm_vc4_wait_seqno - ioctl argument for waiting for 1663f012e29Smrg * DRM_VC4_SUBMIT_CL completion using its returned seqno. 1673f012e29Smrg * 1683f012e29Smrg * timeout_ns is the timeout in nanoseconds, where "0" means "don't 1693f012e29Smrg * block, just return the status." 1703f012e29Smrg */ 1713f012e29Smrgstruct drm_vc4_wait_seqno { 1723f012e29Smrg __u64 seqno; 1733f012e29Smrg __u64 timeout_ns; 1743f012e29Smrg}; 1753f012e29Smrg 1763f012e29Smrg/** 1773f012e29Smrg * struct drm_vc4_wait_bo - ioctl argument for waiting for 1783f012e29Smrg * completion of the last DRM_VC4_SUBMIT_CL on a BO. 1793f012e29Smrg * 1803f012e29Smrg * This is useful for cases where multiple processes might be 1813f012e29Smrg * rendering to a BO and you want to wait for all rendering to be 1823f012e29Smrg * completed. 1833f012e29Smrg */ 1843f012e29Smrgstruct drm_vc4_wait_bo { 1853f012e29Smrg __u32 handle; 1863f012e29Smrg __u32 pad; 1873f012e29Smrg __u64 timeout_ns; 1883f012e29Smrg}; 1893f012e29Smrg 1903f012e29Smrg/** 1913f012e29Smrg * struct drm_vc4_create_bo - ioctl argument for creating VC4 BOs. 1923f012e29Smrg * 1933f012e29Smrg * There are currently no values for the flags argument, but it may be 1943f012e29Smrg * used in a future extension. 1953f012e29Smrg */ 1963f012e29Smrgstruct drm_vc4_create_bo { 1973f012e29Smrg __u32 size; 1983f012e29Smrg __u32 flags; 1993f012e29Smrg /** Returned GEM handle for the BO. */ 2003f012e29Smrg __u32 handle; 2013f012e29Smrg __u32 pad; 2023f012e29Smrg}; 2033f012e29Smrg 2043f012e29Smrg/** 2053f012e29Smrg * struct drm_vc4_mmap_bo - ioctl argument for mapping VC4 BOs. 2063f012e29Smrg * 2073f012e29Smrg * This doesn't actually perform an mmap. Instead, it returns the 2083f012e29Smrg * offset you need to use in an mmap on the DRM device node. This 2093f012e29Smrg * means that tools like valgrind end up knowing about the mapped 2103f012e29Smrg * memory. 2113f012e29Smrg * 2123f012e29Smrg * There are currently no values for the flags argument, but it may be 2133f012e29Smrg * used in a future extension. 2143f012e29Smrg */ 2153f012e29Smrgstruct drm_vc4_mmap_bo { 2163f012e29Smrg /** Handle for the object being mapped. */ 2173f012e29Smrg __u32 handle; 2183f012e29Smrg __u32 flags; 2193f012e29Smrg /** offset into the drm node to use for subsequent mmap call. */ 2203f012e29Smrg __u64 offset; 2213f012e29Smrg}; 2223f012e29Smrg 2233f012e29Smrg/** 2243f012e29Smrg * struct drm_vc4_create_shader_bo - ioctl argument for creating VC4 2253f012e29Smrg * shader BOs. 2263f012e29Smrg * 2273f012e29Smrg * Since allowing a shader to be overwritten while it's also being 2283f012e29Smrg * executed from would allow privlege escalation, shaders must be 2293f012e29Smrg * created using this ioctl, and they can't be mmapped later. 2303f012e29Smrg */ 2313f012e29Smrgstruct drm_vc4_create_shader_bo { 2323f012e29Smrg /* Size of the data argument. */ 2333f012e29Smrg __u32 size; 2343f012e29Smrg /* Flags, currently must be 0. */ 2353f012e29Smrg __u32 flags; 2363f012e29Smrg 2373f012e29Smrg /* Pointer to the data. */ 2383f012e29Smrg __u64 data; 2393f012e29Smrg 2403f012e29Smrg /** Returned GEM handle for the BO. */ 2413f012e29Smrg __u32 handle; 2423f012e29Smrg /* Pad, must be 0. */ 2433f012e29Smrg __u32 pad; 2443f012e29Smrg}; 2453f012e29Smrg 2463f012e29Smrgstruct drm_vc4_get_hang_state_bo { 2473f012e29Smrg __u32 handle; 2483f012e29Smrg __u32 paddr; 2493f012e29Smrg __u32 size; 2503f012e29Smrg __u32 pad; 2513f012e29Smrg}; 2523f012e29Smrg 2533f012e29Smrg/** 2543f012e29Smrg * struct drm_vc4_hang_state - ioctl argument for collecting state 2553f012e29Smrg * from a GPU hang for analysis. 2563f012e29Smrg*/ 2573f012e29Smrgstruct drm_vc4_get_hang_state { 2583f012e29Smrg /** Pointer to array of struct drm_vc4_get_hang_state_bo. */ 2593f012e29Smrg __u64 bo; 2603f012e29Smrg /** 2613f012e29Smrg * On input, the size of the bo array. Output is the number 2623f012e29Smrg * of bos to be returned. 2633f012e29Smrg */ 2643f012e29Smrg __u32 bo_count; 2653f012e29Smrg 2663f012e29Smrg __u32 start_bin, start_render; 2673f012e29Smrg 2683f012e29Smrg __u32 ct0ca, ct0ea; 2693f012e29Smrg __u32 ct1ca, ct1ea; 2703f012e29Smrg __u32 ct0cs, ct1cs; 2713f012e29Smrg __u32 ct0ra0, ct1ra0; 2723f012e29Smrg 2733f012e29Smrg __u32 bpca, bpcs; 2743f012e29Smrg __u32 bpoa, bpos; 2753f012e29Smrg 2763f012e29Smrg __u32 vpmbase; 2773f012e29Smrg 2783f012e29Smrg __u32 dbge; 2793f012e29Smrg __u32 fdbgo; 2803f012e29Smrg __u32 fdbgb; 2813f012e29Smrg __u32 fdbgr; 2823f012e29Smrg __u32 fdbgs; 2833f012e29Smrg __u32 errstat; 2843f012e29Smrg 2853f012e29Smrg /* Pad that we may save more registers into in the future. */ 2863f012e29Smrg __u32 pad[16]; 2873f012e29Smrg}; 2883f012e29Smrg 2893f012e29Smrg#define DRM_VC4_PARAM_V3D_IDENT0 0 2903f012e29Smrg#define DRM_VC4_PARAM_V3D_IDENT1 1 2913f012e29Smrg#define DRM_VC4_PARAM_V3D_IDENT2 2 2923f012e29Smrg#define DRM_VC4_PARAM_SUPPORTS_BRANCHES 3 293037b3c26Smrg#define DRM_VC4_PARAM_SUPPORTS_ETC1 4 294037b3c26Smrg#define DRM_VC4_PARAM_SUPPORTS_THREADED_FS 5 2953f012e29Smrg 2963f012e29Smrgstruct drm_vc4_get_param { 2973f012e29Smrg __u32 param; 2983f012e29Smrg __u32 pad; 2993f012e29Smrg __u64 value; 3003f012e29Smrg}; 3013f012e29Smrg 302d8807b2fSmrgstruct drm_vc4_get_tiling { 303d8807b2fSmrg __u32 handle; 304d8807b2fSmrg __u32 flags; 305d8807b2fSmrg __u64 modifier; 306d8807b2fSmrg}; 307d8807b2fSmrg 308d8807b2fSmrgstruct drm_vc4_set_tiling { 309d8807b2fSmrg __u32 handle; 310d8807b2fSmrg __u32 flags; 311d8807b2fSmrg __u64 modifier; 312d8807b2fSmrg}; 313d8807b2fSmrg 3143f012e29Smrg#if defined(__cplusplus) 3153f012e29Smrg} 3163f012e29Smrg#endif 3173f012e29Smrg 318d8807b2fSmrg#endif /* _UAPI_VC4_DRM_H_ */ 319