vc4_drm.h revision 00a23bda
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
2400a23bdaSmrg#ifndef _VC4_DRM_H_
2500a23bdaSmrg#define _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
4300a23bdaSmrg#define DRM_VC4_LABEL_BO                          0x0a
4400a23bdaSmrg#define DRM_VC4_GEM_MADVISE                       0x0b
453f012e29Smrg
463f012e29Smrg#define DRM_IOCTL_VC4_SUBMIT_CL           DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_SUBMIT_CL, struct drm_vc4_submit_cl)
473f012e29Smrg#define DRM_IOCTL_VC4_WAIT_SEQNO          DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_WAIT_SEQNO, struct drm_vc4_wait_seqno)
483f012e29Smrg#define DRM_IOCTL_VC4_WAIT_BO             DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_WAIT_BO, struct drm_vc4_wait_bo)
493f012e29Smrg#define DRM_IOCTL_VC4_CREATE_BO           DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_CREATE_BO, struct drm_vc4_create_bo)
503f012e29Smrg#define DRM_IOCTL_VC4_MMAP_BO             DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_MMAP_BO, struct drm_vc4_mmap_bo)
513f012e29Smrg#define DRM_IOCTL_VC4_CREATE_SHADER_BO    DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_CREATE_SHADER_BO, struct drm_vc4_create_shader_bo)
523f012e29Smrg#define DRM_IOCTL_VC4_GET_HANG_STATE      DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_GET_HANG_STATE, struct drm_vc4_get_hang_state)
533f012e29Smrg#define DRM_IOCTL_VC4_GET_PARAM           DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_GET_PARAM, struct drm_vc4_get_param)
54d8807b2fSmrg#define DRM_IOCTL_VC4_SET_TILING          DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_SET_TILING, struct drm_vc4_set_tiling)
55d8807b2fSmrg#define DRM_IOCTL_VC4_GET_TILING          DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_GET_TILING, struct drm_vc4_get_tiling)
5600a23bdaSmrg#define DRM_IOCTL_VC4_LABEL_BO            DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_LABEL_BO, struct drm_vc4_label_bo)
5700a23bdaSmrg#define DRM_IOCTL_VC4_GEM_MADVISE         DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_GEM_MADVISE, struct drm_vc4_gem_madvise)
583f012e29Smrg
593f012e29Smrgstruct drm_vc4_submit_rcl_surface {
603f012e29Smrg	__u32 hindex; /* Handle index, or ~0 if not present. */
613f012e29Smrg	__u32 offset; /* Offset to start of buffer. */
623f012e29Smrg	/*
633f012e29Smrg	 * Bits for either render config (color_write) or load/store packet.
643f012e29Smrg	 * Bits should all be 0 for MSAA load/stores.
653f012e29Smrg	 */
663f012e29Smrg	__u16 bits;
673f012e29Smrg
683f012e29Smrg#define VC4_SUBMIT_RCL_SURFACE_READ_IS_FULL_RES		(1 << 0)
693f012e29Smrg	__u16 flags;
703f012e29Smrg};
713f012e29Smrg
723f012e29Smrg/**
733f012e29Smrg * struct drm_vc4_submit_cl - ioctl argument for submitting commands to the 3D
743f012e29Smrg * engine.
753f012e29Smrg *
763f012e29Smrg * Drivers typically use GPU BOs to store batchbuffers / command lists and
773f012e29Smrg * their associated state.  However, because the VC4 lacks an MMU, we have to
783f012e29Smrg * do validation of memory accesses by the GPU commands.  If we were to store
793f012e29Smrg * our commands in BOs, we'd need to do uncached readback from them to do the
803f012e29Smrg * validation process, which is too expensive.  Instead, userspace accumulates
813f012e29Smrg * commands and associated state in plain memory, then the kernel copies the
823f012e29Smrg * data to its own address space, and then validates and stores it in a GPU
833f012e29Smrg * BO.
843f012e29Smrg */
853f012e29Smrgstruct drm_vc4_submit_cl {
863f012e29Smrg	/* Pointer to the binner command list.
873f012e29Smrg	 *
883f012e29Smrg	 * This is the first set of commands executed, which runs the
893f012e29Smrg	 * coordinate shader to determine where primitives land on the screen,
903f012e29Smrg	 * then writes out the state updates and draw calls necessary per tile
913f012e29Smrg	 * to the tile allocation BO.
923f012e29Smrg	 */
933f012e29Smrg	__u64 bin_cl;
943f012e29Smrg
953f012e29Smrg	/* Pointer to the shader records.
963f012e29Smrg	 *
973f012e29Smrg	 * Shader records are the structures read by the hardware that contain
983f012e29Smrg	 * pointers to uniforms, shaders, and vertex attributes.  The
993f012e29Smrg	 * reference to the shader record has enough information to determine
1003f012e29Smrg	 * how many pointers are necessary (fixed number for shaders/uniforms,
1013f012e29Smrg	 * and an attribute count), so those BO indices into bo_handles are
1023f012e29Smrg	 * just stored as __u32s before each shader record passed in.
1033f012e29Smrg	 */
1043f012e29Smrg	__u64 shader_rec;
1053f012e29Smrg
1063f012e29Smrg	/* Pointer to uniform data and texture handles for the textures
1073f012e29Smrg	 * referenced by the shader.
1083f012e29Smrg	 *
1093f012e29Smrg	 * For each shader state record, there is a set of uniform data in the
1103f012e29Smrg	 * order referenced by the record (FS, VS, then CS).  Each set of
1113f012e29Smrg	 * uniform data has a __u32 index into bo_handles per texture
1123f012e29Smrg	 * sample operation, in the order the QPU_W_TMUn_S writes appear in
1133f012e29Smrg	 * the program.  Following the texture BO handle indices is the actual
1143f012e29Smrg	 * uniform data.
1153f012e29Smrg	 *
1163f012e29Smrg	 * The individual uniform state blocks don't have sizes passed in,
1173f012e29Smrg	 * because the kernel has to determine the sizes anyway during shader
1183f012e29Smrg	 * code validation.
1193f012e29Smrg	 */
1203f012e29Smrg	__u64 uniforms;
1213f012e29Smrg	__u64 bo_handles;
1223f012e29Smrg
1233f012e29Smrg	/* Size in bytes of the binner command list. */
1243f012e29Smrg	__u32 bin_cl_size;
1253f012e29Smrg	/* Size in bytes of the set of shader records. */
1263f012e29Smrg	__u32 shader_rec_size;
1273f012e29Smrg	/* Number of shader records.
1283f012e29Smrg	 *
1293f012e29Smrg	 * This could just be computed from the contents of shader_records and
1303f012e29Smrg	 * the address bits of references to them from the bin CL, but it
1313f012e29Smrg	 * keeps the kernel from having to resize some allocations it makes.
1323f012e29Smrg	 */
1333f012e29Smrg	__u32 shader_rec_count;
1343f012e29Smrg	/* Size in bytes of the uniform state. */
1353f012e29Smrg	__u32 uniforms_size;
1363f012e29Smrg
1373f012e29Smrg	/* Number of BO handles passed in (size is that times 4). */
1383f012e29Smrg	__u32 bo_handle_count;
1393f012e29Smrg
1403f012e29Smrg	/* RCL setup: */
1413f012e29Smrg	__u16 width;
1423f012e29Smrg	__u16 height;
1433f012e29Smrg	__u8 min_x_tile;
1443f012e29Smrg	__u8 min_y_tile;
1453f012e29Smrg	__u8 max_x_tile;
1463f012e29Smrg	__u8 max_y_tile;
1473f012e29Smrg	struct drm_vc4_submit_rcl_surface color_read;
1483f012e29Smrg	struct drm_vc4_submit_rcl_surface color_write;
1493f012e29Smrg	struct drm_vc4_submit_rcl_surface zs_read;
1503f012e29Smrg	struct drm_vc4_submit_rcl_surface zs_write;
1513f012e29Smrg	struct drm_vc4_submit_rcl_surface msaa_color_write;
1523f012e29Smrg	struct drm_vc4_submit_rcl_surface msaa_zs_write;
1533f012e29Smrg	__u32 clear_color[2];
1543f012e29Smrg	__u32 clear_z;
1553f012e29Smrg	__u8 clear_s;
1563f012e29Smrg
1573f012e29Smrg	__u32 pad:24;
1583f012e29Smrg
1593f012e29Smrg#define VC4_SUBMIT_CL_USE_CLEAR_COLOR			(1 << 0)
16000a23bdaSmrg/* By default, the kernel gets to choose the order that the tiles are
16100a23bdaSmrg * rendered in.  If this is set, then the tiles will be rendered in a
16200a23bdaSmrg * raster order, with the right-to-left vs left-to-right and
16300a23bdaSmrg * top-to-bottom vs bottom-to-top dictated by
16400a23bdaSmrg * VC4_SUBMIT_CL_RCL_ORDER_INCREASING_*.  This allows overlapping
16500a23bdaSmrg * blits to be implemented using the 3D engine.
16600a23bdaSmrg */
16700a23bdaSmrg#define VC4_SUBMIT_CL_FIXED_RCL_ORDER			(1 << 1)
16800a23bdaSmrg#define VC4_SUBMIT_CL_RCL_ORDER_INCREASING_X		(1 << 2)
16900a23bdaSmrg#define VC4_SUBMIT_CL_RCL_ORDER_INCREASING_Y		(1 << 3)
1703f012e29Smrg	__u32 flags;
1713f012e29Smrg
1723f012e29Smrg	/* Returned value of the seqno of this render job (for the
1733f012e29Smrg	 * wait ioctl).
1743f012e29Smrg	 */
1753f012e29Smrg	__u64 seqno;
1763f012e29Smrg};
1773f012e29Smrg
1783f012e29Smrg/**
1793f012e29Smrg * struct drm_vc4_wait_seqno - ioctl argument for waiting for
1803f012e29Smrg * DRM_VC4_SUBMIT_CL completion using its returned seqno.
1813f012e29Smrg *
1823f012e29Smrg * timeout_ns is the timeout in nanoseconds, where "0" means "don't
1833f012e29Smrg * block, just return the status."
1843f012e29Smrg */
1853f012e29Smrgstruct drm_vc4_wait_seqno {
1863f012e29Smrg	__u64 seqno;
1873f012e29Smrg	__u64 timeout_ns;
1883f012e29Smrg};
1893f012e29Smrg
1903f012e29Smrg/**
1913f012e29Smrg * struct drm_vc4_wait_bo - ioctl argument for waiting for
1923f012e29Smrg * completion of the last DRM_VC4_SUBMIT_CL on a BO.
1933f012e29Smrg *
1943f012e29Smrg * This is useful for cases where multiple processes might be
1953f012e29Smrg * rendering to a BO and you want to wait for all rendering to be
1963f012e29Smrg * completed.
1973f012e29Smrg */
1983f012e29Smrgstruct drm_vc4_wait_bo {
1993f012e29Smrg	__u32 handle;
2003f012e29Smrg	__u32 pad;
2013f012e29Smrg	__u64 timeout_ns;
2023f012e29Smrg};
2033f012e29Smrg
2043f012e29Smrg/**
2053f012e29Smrg * struct drm_vc4_create_bo - ioctl argument for creating VC4 BOs.
2063f012e29Smrg *
2073f012e29Smrg * There are currently no values for the flags argument, but it may be
2083f012e29Smrg * used in a future extension.
2093f012e29Smrg */
2103f012e29Smrgstruct drm_vc4_create_bo {
2113f012e29Smrg	__u32 size;
2123f012e29Smrg	__u32 flags;
2133f012e29Smrg	/** Returned GEM handle for the BO. */
2143f012e29Smrg	__u32 handle;
2153f012e29Smrg	__u32 pad;
2163f012e29Smrg};
2173f012e29Smrg
2183f012e29Smrg/**
2193f012e29Smrg * struct drm_vc4_mmap_bo - ioctl argument for mapping VC4 BOs.
2203f012e29Smrg *
2213f012e29Smrg * This doesn't actually perform an mmap.  Instead, it returns the
2223f012e29Smrg * offset you need to use in an mmap on the DRM device node.  This
2233f012e29Smrg * means that tools like valgrind end up knowing about the mapped
2243f012e29Smrg * memory.
2253f012e29Smrg *
2263f012e29Smrg * There are currently no values for the flags argument, but it may be
2273f012e29Smrg * used in a future extension.
2283f012e29Smrg */
2293f012e29Smrgstruct drm_vc4_mmap_bo {
2303f012e29Smrg	/** Handle for the object being mapped. */
2313f012e29Smrg	__u32 handle;
2323f012e29Smrg	__u32 flags;
2333f012e29Smrg	/** offset into the drm node to use for subsequent mmap call. */
2343f012e29Smrg	__u64 offset;
2353f012e29Smrg};
2363f012e29Smrg
2373f012e29Smrg/**
2383f012e29Smrg * struct drm_vc4_create_shader_bo - ioctl argument for creating VC4
2393f012e29Smrg * shader BOs.
2403f012e29Smrg *
2413f012e29Smrg * Since allowing a shader to be overwritten while it's also being
2423f012e29Smrg * executed from would allow privlege escalation, shaders must be
2433f012e29Smrg * created using this ioctl, and they can't be mmapped later.
2443f012e29Smrg */
2453f012e29Smrgstruct drm_vc4_create_shader_bo {
2463f012e29Smrg	/* Size of the data argument. */
2473f012e29Smrg	__u32 size;
2483f012e29Smrg	/* Flags, currently must be 0. */
2493f012e29Smrg	__u32 flags;
2503f012e29Smrg
2513f012e29Smrg	/* Pointer to the data. */
2523f012e29Smrg	__u64 data;
2533f012e29Smrg
2543f012e29Smrg	/** Returned GEM handle for the BO. */
2553f012e29Smrg	__u32 handle;
2563f012e29Smrg	/* Pad, must be 0. */
2573f012e29Smrg	__u32 pad;
2583f012e29Smrg};
2593f012e29Smrg
2603f012e29Smrgstruct drm_vc4_get_hang_state_bo {
2613f012e29Smrg	__u32 handle;
2623f012e29Smrg	__u32 paddr;
2633f012e29Smrg	__u32 size;
2643f012e29Smrg	__u32 pad;
2653f012e29Smrg};
2663f012e29Smrg
2673f012e29Smrg/**
2683f012e29Smrg * struct drm_vc4_hang_state - ioctl argument for collecting state
2693f012e29Smrg * from a GPU hang for analysis.
2703f012e29Smrg*/
2713f012e29Smrgstruct drm_vc4_get_hang_state {
2723f012e29Smrg	/** Pointer to array of struct drm_vc4_get_hang_state_bo. */
2733f012e29Smrg	__u64 bo;
2743f012e29Smrg	/**
2753f012e29Smrg	 * On input, the size of the bo array.  Output is the number
2763f012e29Smrg	 * of bos to be returned.
2773f012e29Smrg	 */
2783f012e29Smrg	__u32 bo_count;
2793f012e29Smrg
2803f012e29Smrg	__u32 start_bin, start_render;
2813f012e29Smrg
2823f012e29Smrg	__u32 ct0ca, ct0ea;
2833f012e29Smrg	__u32 ct1ca, ct1ea;
2843f012e29Smrg	__u32 ct0cs, ct1cs;
2853f012e29Smrg	__u32 ct0ra0, ct1ra0;
2863f012e29Smrg
2873f012e29Smrg	__u32 bpca, bpcs;
2883f012e29Smrg	__u32 bpoa, bpos;
2893f012e29Smrg
2903f012e29Smrg	__u32 vpmbase;
2913f012e29Smrg
2923f012e29Smrg	__u32 dbge;
2933f012e29Smrg	__u32 fdbgo;
2943f012e29Smrg	__u32 fdbgb;
2953f012e29Smrg	__u32 fdbgr;
2963f012e29Smrg	__u32 fdbgs;
2973f012e29Smrg	__u32 errstat;
2983f012e29Smrg
2993f012e29Smrg	/* Pad that we may save more registers into in the future. */
3003f012e29Smrg	__u32 pad[16];
3013f012e29Smrg};
3023f012e29Smrg
3033f012e29Smrg#define DRM_VC4_PARAM_V3D_IDENT0		0
3043f012e29Smrg#define DRM_VC4_PARAM_V3D_IDENT1		1
3053f012e29Smrg#define DRM_VC4_PARAM_V3D_IDENT2		2
3063f012e29Smrg#define DRM_VC4_PARAM_SUPPORTS_BRANCHES		3
307037b3c26Smrg#define DRM_VC4_PARAM_SUPPORTS_ETC1		4
308037b3c26Smrg#define DRM_VC4_PARAM_SUPPORTS_THREADED_FS	5
30900a23bdaSmrg#define DRM_VC4_PARAM_SUPPORTS_FIXED_RCL_ORDER	6
31000a23bdaSmrg#define DRM_VC4_PARAM_SUPPORTS_MADVISE		7
3113f012e29Smrg
3123f012e29Smrgstruct drm_vc4_get_param {
3133f012e29Smrg	__u32 param;
3143f012e29Smrg	__u32 pad;
3153f012e29Smrg	__u64 value;
3163f012e29Smrg};
3173f012e29Smrg
318d8807b2fSmrgstruct drm_vc4_get_tiling {
319d8807b2fSmrg	__u32 handle;
320d8807b2fSmrg	__u32 flags;
321d8807b2fSmrg	__u64 modifier;
322d8807b2fSmrg};
323d8807b2fSmrg
324d8807b2fSmrgstruct drm_vc4_set_tiling {
325d8807b2fSmrg	__u32 handle;
326d8807b2fSmrg	__u32 flags;
327d8807b2fSmrg	__u64 modifier;
328d8807b2fSmrg};
329d8807b2fSmrg
33000a23bdaSmrg/**
33100a23bdaSmrg * struct drm_vc4_label_bo - Attach a name to a BO for debug purposes.
33200a23bdaSmrg */
33300a23bdaSmrgstruct drm_vc4_label_bo {
33400a23bdaSmrg	__u32 handle;
33500a23bdaSmrg	__u32 len;
33600a23bdaSmrg	__u64 name;
33700a23bdaSmrg};
33800a23bdaSmrg
33900a23bdaSmrg/*
34000a23bdaSmrg * States prefixed with '__' are internal states and cannot be passed to the
34100a23bdaSmrg * DRM_IOCTL_VC4_GEM_MADVISE ioctl.
34200a23bdaSmrg */
34300a23bdaSmrg#define VC4_MADV_WILLNEED			0
34400a23bdaSmrg#define VC4_MADV_DONTNEED			1
34500a23bdaSmrg#define __VC4_MADV_PURGED			2
34600a23bdaSmrg#define __VC4_MADV_NOTSUPP			3
34700a23bdaSmrg
34800a23bdaSmrgstruct drm_vc4_gem_madvise {
34900a23bdaSmrg	__u32 handle;
35000a23bdaSmrg	__u32 madv;
35100a23bdaSmrg	__u32 retained;
35200a23bdaSmrg	__u32 pad;
35300a23bdaSmrg};
35400a23bdaSmrg
3553f012e29Smrg#if defined(__cplusplus)
3563f012e29Smrg}
3573f012e29Smrg#endif
3583f012e29Smrg
35900a23bdaSmrg#endif /* _VC4_DRM_H_ */
360