vc4_drm.h revision 3f012e29
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
243f012e29Smrg#ifndef _VC4_DRM_H_
253f012e29Smrg#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
413f012e29Smrg
423f012e29Smrg#define DRM_IOCTL_VC4_SUBMIT_CL           DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_SUBMIT_CL, struct drm_vc4_submit_cl)
433f012e29Smrg#define DRM_IOCTL_VC4_WAIT_SEQNO          DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_WAIT_SEQNO, struct drm_vc4_wait_seqno)
443f012e29Smrg#define DRM_IOCTL_VC4_WAIT_BO             DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_WAIT_BO, struct drm_vc4_wait_bo)
453f012e29Smrg#define DRM_IOCTL_VC4_CREATE_BO           DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_CREATE_BO, struct drm_vc4_create_bo)
463f012e29Smrg#define DRM_IOCTL_VC4_MMAP_BO             DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_MMAP_BO, struct drm_vc4_mmap_bo)
473f012e29Smrg#define DRM_IOCTL_VC4_CREATE_SHADER_BO    DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_CREATE_SHADER_BO, struct drm_vc4_create_shader_bo)
483f012e29Smrg#define DRM_IOCTL_VC4_GET_HANG_STATE      DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_GET_HANG_STATE, struct drm_vc4_get_hang_state)
493f012e29Smrg#define DRM_IOCTL_VC4_GET_PARAM           DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_GET_PARAM, struct drm_vc4_get_param)
503f012e29Smrg
513f012e29Smrgstruct drm_vc4_submit_rcl_surface {
523f012e29Smrg	__u32 hindex; /* Handle index, or ~0 if not present. */
533f012e29Smrg	__u32 offset; /* Offset to start of buffer. */
543f012e29Smrg	/*
553f012e29Smrg	 * Bits for either render config (color_write) or load/store packet.
563f012e29Smrg	 * Bits should all be 0 for MSAA load/stores.
573f012e29Smrg	 */
583f012e29Smrg	__u16 bits;
593f012e29Smrg
603f012e29Smrg#define VC4_SUBMIT_RCL_SURFACE_READ_IS_FULL_RES		(1 << 0)
613f012e29Smrg	__u16 flags;
623f012e29Smrg};
633f012e29Smrg
643f012e29Smrg/**
653f012e29Smrg * struct drm_vc4_submit_cl - ioctl argument for submitting commands to the 3D
663f012e29Smrg * engine.
673f012e29Smrg *
683f012e29Smrg * Drivers typically use GPU BOs to store batchbuffers / command lists and
693f012e29Smrg * their associated state.  However, because the VC4 lacks an MMU, we have to
703f012e29Smrg * do validation of memory accesses by the GPU commands.  If we were to store
713f012e29Smrg * our commands in BOs, we'd need to do uncached readback from them to do the
723f012e29Smrg * validation process, which is too expensive.  Instead, userspace accumulates
733f012e29Smrg * commands and associated state in plain memory, then the kernel copies the
743f012e29Smrg * data to its own address space, and then validates and stores it in a GPU
753f012e29Smrg * BO.
763f012e29Smrg */
773f012e29Smrgstruct drm_vc4_submit_cl {
783f012e29Smrg	/* Pointer to the binner command list.
793f012e29Smrg	 *
803f012e29Smrg	 * This is the first set of commands executed, which runs the
813f012e29Smrg	 * coordinate shader to determine where primitives land on the screen,
823f012e29Smrg	 * then writes out the state updates and draw calls necessary per tile
833f012e29Smrg	 * to the tile allocation BO.
843f012e29Smrg	 */
853f012e29Smrg	__u64 bin_cl;
863f012e29Smrg
873f012e29Smrg	/* Pointer to the shader records.
883f012e29Smrg	 *
893f012e29Smrg	 * Shader records are the structures read by the hardware that contain
903f012e29Smrg	 * pointers to uniforms, shaders, and vertex attributes.  The
913f012e29Smrg	 * reference to the shader record has enough information to determine
923f012e29Smrg	 * how many pointers are necessary (fixed number for shaders/uniforms,
933f012e29Smrg	 * and an attribute count), so those BO indices into bo_handles are
943f012e29Smrg	 * just stored as __u32s before each shader record passed in.
953f012e29Smrg	 */
963f012e29Smrg	__u64 shader_rec;
973f012e29Smrg
983f012e29Smrg	/* Pointer to uniform data and texture handles for the textures
993f012e29Smrg	 * referenced by the shader.
1003f012e29Smrg	 *
1013f012e29Smrg	 * For each shader state record, there is a set of uniform data in the
1023f012e29Smrg	 * order referenced by the record (FS, VS, then CS).  Each set of
1033f012e29Smrg	 * uniform data has a __u32 index into bo_handles per texture
1043f012e29Smrg	 * sample operation, in the order the QPU_W_TMUn_S writes appear in
1053f012e29Smrg	 * the program.  Following the texture BO handle indices is the actual
1063f012e29Smrg	 * uniform data.
1073f012e29Smrg	 *
1083f012e29Smrg	 * The individual uniform state blocks don't have sizes passed in,
1093f012e29Smrg	 * because the kernel has to determine the sizes anyway during shader
1103f012e29Smrg	 * code validation.
1113f012e29Smrg	 */
1123f012e29Smrg	__u64 uniforms;
1133f012e29Smrg	__u64 bo_handles;
1143f012e29Smrg
1153f012e29Smrg	/* Size in bytes of the binner command list. */
1163f012e29Smrg	__u32 bin_cl_size;
1173f012e29Smrg	/* Size in bytes of the set of shader records. */
1183f012e29Smrg	__u32 shader_rec_size;
1193f012e29Smrg	/* Number of shader records.
1203f012e29Smrg	 *
1213f012e29Smrg	 * This could just be computed from the contents of shader_records and
1223f012e29Smrg	 * the address bits of references to them from the bin CL, but it
1233f012e29Smrg	 * keeps the kernel from having to resize some allocations it makes.
1243f012e29Smrg	 */
1253f012e29Smrg	__u32 shader_rec_count;
1263f012e29Smrg	/* Size in bytes of the uniform state. */
1273f012e29Smrg	__u32 uniforms_size;
1283f012e29Smrg
1293f012e29Smrg	/* Number of BO handles passed in (size is that times 4). */
1303f012e29Smrg	__u32 bo_handle_count;
1313f012e29Smrg
1323f012e29Smrg	/* RCL setup: */
1333f012e29Smrg	__u16 width;
1343f012e29Smrg	__u16 height;
1353f012e29Smrg	__u8 min_x_tile;
1363f012e29Smrg	__u8 min_y_tile;
1373f012e29Smrg	__u8 max_x_tile;
1383f012e29Smrg	__u8 max_y_tile;
1393f012e29Smrg	struct drm_vc4_submit_rcl_surface color_read;
1403f012e29Smrg	struct drm_vc4_submit_rcl_surface color_write;
1413f012e29Smrg	struct drm_vc4_submit_rcl_surface zs_read;
1423f012e29Smrg	struct drm_vc4_submit_rcl_surface zs_write;
1433f012e29Smrg	struct drm_vc4_submit_rcl_surface msaa_color_write;
1443f012e29Smrg	struct drm_vc4_submit_rcl_surface msaa_zs_write;
1453f012e29Smrg	__u32 clear_color[2];
1463f012e29Smrg	__u32 clear_z;
1473f012e29Smrg	__u8 clear_s;
1483f012e29Smrg
1493f012e29Smrg	__u32 pad:24;
1503f012e29Smrg
1513f012e29Smrg#define VC4_SUBMIT_CL_USE_CLEAR_COLOR			(1 << 0)
1523f012e29Smrg	__u32 flags;
1533f012e29Smrg
1543f012e29Smrg	/* Returned value of the seqno of this render job (for the
1553f012e29Smrg	 * wait ioctl).
1563f012e29Smrg	 */
1573f012e29Smrg	__u64 seqno;
1583f012e29Smrg};
1593f012e29Smrg
1603f012e29Smrg/**
1613f012e29Smrg * struct drm_vc4_wait_seqno - ioctl argument for waiting for
1623f012e29Smrg * DRM_VC4_SUBMIT_CL completion using its returned seqno.
1633f012e29Smrg *
1643f012e29Smrg * timeout_ns is the timeout in nanoseconds, where "0" means "don't
1653f012e29Smrg * block, just return the status."
1663f012e29Smrg */
1673f012e29Smrgstruct drm_vc4_wait_seqno {
1683f012e29Smrg	__u64 seqno;
1693f012e29Smrg	__u64 timeout_ns;
1703f012e29Smrg};
1713f012e29Smrg
1723f012e29Smrg/**
1733f012e29Smrg * struct drm_vc4_wait_bo - ioctl argument for waiting for
1743f012e29Smrg * completion of the last DRM_VC4_SUBMIT_CL on a BO.
1753f012e29Smrg *
1763f012e29Smrg * This is useful for cases where multiple processes might be
1773f012e29Smrg * rendering to a BO and you want to wait for all rendering to be
1783f012e29Smrg * completed.
1793f012e29Smrg */
1803f012e29Smrgstruct drm_vc4_wait_bo {
1813f012e29Smrg	__u32 handle;
1823f012e29Smrg	__u32 pad;
1833f012e29Smrg	__u64 timeout_ns;
1843f012e29Smrg};
1853f012e29Smrg
1863f012e29Smrg/**
1873f012e29Smrg * struct drm_vc4_create_bo - ioctl argument for creating VC4 BOs.
1883f012e29Smrg *
1893f012e29Smrg * There are currently no values for the flags argument, but it may be
1903f012e29Smrg * used in a future extension.
1913f012e29Smrg */
1923f012e29Smrgstruct drm_vc4_create_bo {
1933f012e29Smrg	__u32 size;
1943f012e29Smrg	__u32 flags;
1953f012e29Smrg	/** Returned GEM handle for the BO. */
1963f012e29Smrg	__u32 handle;
1973f012e29Smrg	__u32 pad;
1983f012e29Smrg};
1993f012e29Smrg
2003f012e29Smrg/**
2013f012e29Smrg * struct drm_vc4_mmap_bo - ioctl argument for mapping VC4 BOs.
2023f012e29Smrg *
2033f012e29Smrg * This doesn't actually perform an mmap.  Instead, it returns the
2043f012e29Smrg * offset you need to use in an mmap on the DRM device node.  This
2053f012e29Smrg * means that tools like valgrind end up knowing about the mapped
2063f012e29Smrg * memory.
2073f012e29Smrg *
2083f012e29Smrg * There are currently no values for the flags argument, but it may be
2093f012e29Smrg * used in a future extension.
2103f012e29Smrg */
2113f012e29Smrgstruct drm_vc4_mmap_bo {
2123f012e29Smrg	/** Handle for the object being mapped. */
2133f012e29Smrg	__u32 handle;
2143f012e29Smrg	__u32 flags;
2153f012e29Smrg	/** offset into the drm node to use for subsequent mmap call. */
2163f012e29Smrg	__u64 offset;
2173f012e29Smrg};
2183f012e29Smrg
2193f012e29Smrg/**
2203f012e29Smrg * struct drm_vc4_create_shader_bo - ioctl argument for creating VC4
2213f012e29Smrg * shader BOs.
2223f012e29Smrg *
2233f012e29Smrg * Since allowing a shader to be overwritten while it's also being
2243f012e29Smrg * executed from would allow privlege escalation, shaders must be
2253f012e29Smrg * created using this ioctl, and they can't be mmapped later.
2263f012e29Smrg */
2273f012e29Smrgstruct drm_vc4_create_shader_bo {
2283f012e29Smrg	/* Size of the data argument. */
2293f012e29Smrg	__u32 size;
2303f012e29Smrg	/* Flags, currently must be 0. */
2313f012e29Smrg	__u32 flags;
2323f012e29Smrg
2333f012e29Smrg	/* Pointer to the data. */
2343f012e29Smrg	__u64 data;
2353f012e29Smrg
2363f012e29Smrg	/** Returned GEM handle for the BO. */
2373f012e29Smrg	__u32 handle;
2383f012e29Smrg	/* Pad, must be 0. */
2393f012e29Smrg	__u32 pad;
2403f012e29Smrg};
2413f012e29Smrg
2423f012e29Smrgstruct drm_vc4_get_hang_state_bo {
2433f012e29Smrg	__u32 handle;
2443f012e29Smrg	__u32 paddr;
2453f012e29Smrg	__u32 size;
2463f012e29Smrg	__u32 pad;
2473f012e29Smrg};
2483f012e29Smrg
2493f012e29Smrg/**
2503f012e29Smrg * struct drm_vc4_hang_state - ioctl argument for collecting state
2513f012e29Smrg * from a GPU hang for analysis.
2523f012e29Smrg*/
2533f012e29Smrgstruct drm_vc4_get_hang_state {
2543f012e29Smrg	/** Pointer to array of struct drm_vc4_get_hang_state_bo. */
2553f012e29Smrg	__u64 bo;
2563f012e29Smrg	/**
2573f012e29Smrg	 * On input, the size of the bo array.  Output is the number
2583f012e29Smrg	 * of bos to be returned.
2593f012e29Smrg	 */
2603f012e29Smrg	__u32 bo_count;
2613f012e29Smrg
2623f012e29Smrg	__u32 start_bin, start_render;
2633f012e29Smrg
2643f012e29Smrg	__u32 ct0ca, ct0ea;
2653f012e29Smrg	__u32 ct1ca, ct1ea;
2663f012e29Smrg	__u32 ct0cs, ct1cs;
2673f012e29Smrg	__u32 ct0ra0, ct1ra0;
2683f012e29Smrg
2693f012e29Smrg	__u32 bpca, bpcs;
2703f012e29Smrg	__u32 bpoa, bpos;
2713f012e29Smrg
2723f012e29Smrg	__u32 vpmbase;
2733f012e29Smrg
2743f012e29Smrg	__u32 dbge;
2753f012e29Smrg	__u32 fdbgo;
2763f012e29Smrg	__u32 fdbgb;
2773f012e29Smrg	__u32 fdbgr;
2783f012e29Smrg	__u32 fdbgs;
2793f012e29Smrg	__u32 errstat;
2803f012e29Smrg
2813f012e29Smrg	/* Pad that we may save more registers into in the future. */
2823f012e29Smrg	__u32 pad[16];
2833f012e29Smrg};
2843f012e29Smrg
2853f012e29Smrg#define DRM_VC4_PARAM_V3D_IDENT0		0
2863f012e29Smrg#define DRM_VC4_PARAM_V3D_IDENT1		1
2873f012e29Smrg#define DRM_VC4_PARAM_V3D_IDENT2		2
2883f012e29Smrg#define DRM_VC4_PARAM_SUPPORTS_BRANCHES		3
2893f012e29Smrg
2903f012e29Smrgstruct drm_vc4_get_param {
2913f012e29Smrg	__u32 param;
2923f012e29Smrg	__u32 pad;
2933f012e29Smrg	__u64 value;
2943f012e29Smrg};
2953f012e29Smrg
2963f012e29Smrg#if defined(__cplusplus)
2973f012e29Smrg}
2983f012e29Smrg#endif
2993f012e29Smrg
3003f012e29Smrg#endif /* _VC4_DRM_H_ */
301