etnaviv_drm.h revision d8807b2f
1037b3c26Smrg/* 2037b3c26Smrg * Copyright (C) 2015 Etnaviv Project 3037b3c26Smrg * 4037b3c26Smrg * This program is free software; you can redistribute it and/or modify it 5037b3c26Smrg * under the terms of the GNU General Public License version 2 as published by 6037b3c26Smrg * the Free Software Foundation. 7037b3c26Smrg * 8037b3c26Smrg * This program is distributed in the hope that it will be useful, but WITHOUT 9037b3c26Smrg * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10037b3c26Smrg * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11037b3c26Smrg * more details. 12037b3c26Smrg * 13037b3c26Smrg * You should have received a copy of the GNU General Public License along with 14037b3c26Smrg * this program. If not, see <http://www.gnu.org/licenses/>. 15037b3c26Smrg */ 16037b3c26Smrg 17037b3c26Smrg#ifndef __ETNAVIV_DRM_H__ 18037b3c26Smrg#define __ETNAVIV_DRM_H__ 19037b3c26Smrg 20037b3c26Smrg#include "drm.h" 21037b3c26Smrg 22037b3c26Smrg#if defined(__cplusplus) 23037b3c26Smrgextern "C" { 24037b3c26Smrg#endif 25037b3c26Smrg 26037b3c26Smrg/* Please note that modifications to all structs defined here are 27037b3c26Smrg * subject to backwards-compatibility constraints: 28037b3c26Smrg * 1) Do not use pointers, use __u64 instead for 32 bit / 64 bit 29037b3c26Smrg * user/kernel compatibility 30037b3c26Smrg * 2) Keep fields aligned to their size 31037b3c26Smrg * 3) Because of how drm_ioctl() works, we can add new fields at 32037b3c26Smrg * the end of an ioctl if some care is taken: drm_ioctl() will 33037b3c26Smrg * zero out the new fields at the tail of the ioctl, so a zero 34037b3c26Smrg * value should have a backwards compatible meaning. And for 35037b3c26Smrg * output params, userspace won't see the newly added output 36037b3c26Smrg * fields.. so that has to be somehow ok. 37037b3c26Smrg */ 38037b3c26Smrg 39037b3c26Smrg/* timeouts are specified in clock-monotonic absolute times (to simplify 40037b3c26Smrg * restarting interrupted ioctls). The following struct is logically the 41037b3c26Smrg * same as 'struct timespec' but 32/64b ABI safe. 42037b3c26Smrg */ 43037b3c26Smrgstruct drm_etnaviv_timespec { 44037b3c26Smrg __s64 tv_sec; /* seconds */ 45037b3c26Smrg __s64 tv_nsec; /* nanoseconds */ 46037b3c26Smrg}; 47037b3c26Smrg 48037b3c26Smrg#define ETNAVIV_PARAM_GPU_MODEL 0x01 49037b3c26Smrg#define ETNAVIV_PARAM_GPU_REVISION 0x02 50037b3c26Smrg#define ETNAVIV_PARAM_GPU_FEATURES_0 0x03 51037b3c26Smrg#define ETNAVIV_PARAM_GPU_FEATURES_1 0x04 52037b3c26Smrg#define ETNAVIV_PARAM_GPU_FEATURES_2 0x05 53037b3c26Smrg#define ETNAVIV_PARAM_GPU_FEATURES_3 0x06 54037b3c26Smrg#define ETNAVIV_PARAM_GPU_FEATURES_4 0x07 55037b3c26Smrg#define ETNAVIV_PARAM_GPU_FEATURES_5 0x08 56037b3c26Smrg#define ETNAVIV_PARAM_GPU_FEATURES_6 0x09 57037b3c26Smrg 58037b3c26Smrg#define ETNAVIV_PARAM_GPU_STREAM_COUNT 0x10 59037b3c26Smrg#define ETNAVIV_PARAM_GPU_REGISTER_MAX 0x11 60037b3c26Smrg#define ETNAVIV_PARAM_GPU_THREAD_COUNT 0x12 61037b3c26Smrg#define ETNAVIV_PARAM_GPU_VERTEX_CACHE_SIZE 0x13 62037b3c26Smrg#define ETNAVIV_PARAM_GPU_SHADER_CORE_COUNT 0x14 63037b3c26Smrg#define ETNAVIV_PARAM_GPU_PIXEL_PIPES 0x15 64037b3c26Smrg#define ETNAVIV_PARAM_GPU_VERTEX_OUTPUT_BUFFER_SIZE 0x16 65037b3c26Smrg#define ETNAVIV_PARAM_GPU_BUFFER_SIZE 0x17 66037b3c26Smrg#define ETNAVIV_PARAM_GPU_INSTRUCTION_COUNT 0x18 67037b3c26Smrg#define ETNAVIV_PARAM_GPU_NUM_CONSTANTS 0x19 68037b3c26Smrg#define ETNAVIV_PARAM_GPU_NUM_VARYINGS 0x1a 69037b3c26Smrg 70037b3c26Smrg#define ETNA_MAX_PIPES 4 71037b3c26Smrg 72037b3c26Smrgstruct drm_etnaviv_param { 73037b3c26Smrg __u32 pipe; /* in */ 74037b3c26Smrg __u32 param; /* in, ETNAVIV_PARAM_x */ 75037b3c26Smrg __u64 value; /* out (get_param) or in (set_param) */ 76037b3c26Smrg}; 77037b3c26Smrg 78037b3c26Smrg/* 79037b3c26Smrg * GEM buffers: 80037b3c26Smrg */ 81037b3c26Smrg 82037b3c26Smrg#define ETNA_BO_CACHE_MASK 0x000f0000 83037b3c26Smrg/* cache modes */ 84037b3c26Smrg#define ETNA_BO_CACHED 0x00010000 85037b3c26Smrg#define ETNA_BO_WC 0x00020000 86037b3c26Smrg#define ETNA_BO_UNCACHED 0x00040000 87037b3c26Smrg/* map flags */ 88037b3c26Smrg#define ETNA_BO_FORCE_MMU 0x00100000 89037b3c26Smrg 90037b3c26Smrgstruct drm_etnaviv_gem_new { 91037b3c26Smrg __u64 size; /* in */ 92037b3c26Smrg __u32 flags; /* in, mask of ETNA_BO_x */ 93037b3c26Smrg __u32 handle; /* out */ 94037b3c26Smrg}; 95037b3c26Smrg 96037b3c26Smrgstruct drm_etnaviv_gem_info { 97037b3c26Smrg __u32 handle; /* in */ 98037b3c26Smrg __u32 pad; 99037b3c26Smrg __u64 offset; /* out, offset to pass to mmap() */ 100037b3c26Smrg}; 101037b3c26Smrg 102037b3c26Smrg#define ETNA_PREP_READ 0x01 103037b3c26Smrg#define ETNA_PREP_WRITE 0x02 104037b3c26Smrg#define ETNA_PREP_NOSYNC 0x04 105037b3c26Smrg 106037b3c26Smrgstruct drm_etnaviv_gem_cpu_prep { 107037b3c26Smrg __u32 handle; /* in */ 108037b3c26Smrg __u32 op; /* in, mask of ETNA_PREP_x */ 109037b3c26Smrg struct drm_etnaviv_timespec timeout; /* in */ 110037b3c26Smrg}; 111037b3c26Smrg 112037b3c26Smrgstruct drm_etnaviv_gem_cpu_fini { 113037b3c26Smrg __u32 handle; /* in */ 114037b3c26Smrg __u32 flags; /* in, placeholder for now, no defined values */ 115037b3c26Smrg}; 116037b3c26Smrg 117037b3c26Smrg/* 118037b3c26Smrg * Cmdstream Submission: 119037b3c26Smrg */ 120037b3c26Smrg 121037b3c26Smrg/* The value written into the cmdstream is logically: 122037b3c26Smrg * relocbuf->gpuaddr + reloc_offset 123037b3c26Smrg * 124037b3c26Smrg * NOTE that reloc's must be sorted by order of increasing submit_offset, 125037b3c26Smrg * otherwise EINVAL. 126037b3c26Smrg */ 127037b3c26Smrgstruct drm_etnaviv_gem_submit_reloc { 128037b3c26Smrg __u32 submit_offset; /* in, offset from submit_bo */ 129037b3c26Smrg __u32 reloc_idx; /* in, index of reloc_bo buffer */ 130037b3c26Smrg __u64 reloc_offset; /* in, offset from start of reloc_bo */ 131037b3c26Smrg __u32 flags; /* in, placeholder for now, no defined values */ 132037b3c26Smrg}; 133037b3c26Smrg 134037b3c26Smrg/* Each buffer referenced elsewhere in the cmdstream submit (ie. the 135037b3c26Smrg * cmdstream buffer(s) themselves or reloc entries) has one (and only 136037b3c26Smrg * one) entry in the submit->bos[] table. 137037b3c26Smrg * 138037b3c26Smrg * As a optimization, the current buffer (gpu virtual address) can be 139037b3c26Smrg * passed back through the 'presumed' field. If on a subsequent reloc, 140037b3c26Smrg * userspace passes back a 'presumed' address that is still valid, 141037b3c26Smrg * then patching the cmdstream for this entry is skipped. This can 142037b3c26Smrg * avoid kernel needing to map/access the cmdstream bo in the common 143037b3c26Smrg * case. 144037b3c26Smrg */ 145037b3c26Smrg#define ETNA_SUBMIT_BO_READ 0x0001 146037b3c26Smrg#define ETNA_SUBMIT_BO_WRITE 0x0002 147037b3c26Smrgstruct drm_etnaviv_gem_submit_bo { 148037b3c26Smrg __u32 flags; /* in, mask of ETNA_SUBMIT_BO_x */ 149037b3c26Smrg __u32 handle; /* in, GEM handle */ 150037b3c26Smrg __u64 presumed; /* in/out, presumed buffer address */ 151037b3c26Smrg}; 152037b3c26Smrg 153037b3c26Smrg/* Each cmdstream submit consists of a table of buffers involved, and 154037b3c26Smrg * one or more cmdstream buffers. This allows for conditional execution 155037b3c26Smrg * (context-restore), and IB buffers needed for per tile/bin draw cmds. 156037b3c26Smrg */ 157d8807b2fSmrg#define ETNA_SUBMIT_NO_IMPLICIT 0x0001 158d8807b2fSmrg#define ETNA_SUBMIT_FENCE_FD_IN 0x0002 159d8807b2fSmrg#define ETNA_SUBMIT_FENCE_FD_OUT 0x0004 160d8807b2fSmrg#define ETNA_SUBMIT_FLAGS (ETNA_SUBMIT_NO_IMPLICIT | \ 161d8807b2fSmrg ETNA_SUBMIT_FENCE_FD_IN | \ 162d8807b2fSmrg ETNA_SUBMIT_FENCE_FD_OUT) 163037b3c26Smrg#define ETNA_PIPE_3D 0x00 164037b3c26Smrg#define ETNA_PIPE_2D 0x01 165037b3c26Smrg#define ETNA_PIPE_VG 0x02 166037b3c26Smrgstruct drm_etnaviv_gem_submit { 167037b3c26Smrg __u32 fence; /* out */ 168037b3c26Smrg __u32 pipe; /* in */ 169037b3c26Smrg __u32 exec_state; /* in, initial execution state (ETNA_PIPE_x) */ 170037b3c26Smrg __u32 nr_bos; /* in, number of submit_bo's */ 171037b3c26Smrg __u32 nr_relocs; /* in, number of submit_reloc's */ 172037b3c26Smrg __u32 stream_size; /* in, cmdstream size */ 173037b3c26Smrg __u64 bos; /* in, ptr to array of submit_bo's */ 174037b3c26Smrg __u64 relocs; /* in, ptr to array of submit_reloc's */ 175037b3c26Smrg __u64 stream; /* in, ptr to cmdstream */ 176d8807b2fSmrg __u32 flags; /* in, mask of ETNA_SUBMIT_x */ 177d8807b2fSmrg __s32 fence_fd; /* in/out, fence fd (see ETNA_SUBMIT_FENCE_FD_x) */ 178037b3c26Smrg}; 179037b3c26Smrg 180037b3c26Smrg/* The normal way to synchronize with the GPU is just to CPU_PREP on 181037b3c26Smrg * a buffer if you need to access it from the CPU (other cmdstream 182037b3c26Smrg * submission from same or other contexts, PAGE_FLIP ioctl, etc, all 183037b3c26Smrg * handle the required synchronization under the hood). This ioctl 184037b3c26Smrg * mainly just exists as a way to implement the gallium pipe_fence 185037b3c26Smrg * APIs without requiring a dummy bo to synchronize on. 186037b3c26Smrg */ 187037b3c26Smrg#define ETNA_WAIT_NONBLOCK 0x01 188037b3c26Smrgstruct drm_etnaviv_wait_fence { 189037b3c26Smrg __u32 pipe; /* in */ 190037b3c26Smrg __u32 fence; /* in */ 191037b3c26Smrg __u32 flags; /* in, mask of ETNA_WAIT_x */ 192037b3c26Smrg __u32 pad; 193037b3c26Smrg struct drm_etnaviv_timespec timeout; /* in */ 194037b3c26Smrg}; 195037b3c26Smrg 196037b3c26Smrg#define ETNA_USERPTR_READ 0x01 197037b3c26Smrg#define ETNA_USERPTR_WRITE 0x02 198037b3c26Smrgstruct drm_etnaviv_gem_userptr { 199037b3c26Smrg __u64 user_ptr; /* in, page aligned user pointer */ 200037b3c26Smrg __u64 user_size; /* in, page aligned user size */ 201037b3c26Smrg __u32 flags; /* in, flags */ 202037b3c26Smrg __u32 handle; /* out, non-zero handle */ 203037b3c26Smrg}; 204037b3c26Smrg 205037b3c26Smrgstruct drm_etnaviv_gem_wait { 206037b3c26Smrg __u32 pipe; /* in */ 207037b3c26Smrg __u32 handle; /* in, bo to be waited for */ 208037b3c26Smrg __u32 flags; /* in, mask of ETNA_WAIT_x */ 209037b3c26Smrg __u32 pad; 210037b3c26Smrg struct drm_etnaviv_timespec timeout; /* in */ 211037b3c26Smrg}; 212037b3c26Smrg 213037b3c26Smrg#define DRM_ETNAVIV_GET_PARAM 0x00 214037b3c26Smrg/* placeholder: 215037b3c26Smrg#define DRM_ETNAVIV_SET_PARAM 0x01 216037b3c26Smrg */ 217037b3c26Smrg#define DRM_ETNAVIV_GEM_NEW 0x02 218037b3c26Smrg#define DRM_ETNAVIV_GEM_INFO 0x03 219037b3c26Smrg#define DRM_ETNAVIV_GEM_CPU_PREP 0x04 220037b3c26Smrg#define DRM_ETNAVIV_GEM_CPU_FINI 0x05 221037b3c26Smrg#define DRM_ETNAVIV_GEM_SUBMIT 0x06 222037b3c26Smrg#define DRM_ETNAVIV_WAIT_FENCE 0x07 223037b3c26Smrg#define DRM_ETNAVIV_GEM_USERPTR 0x08 224037b3c26Smrg#define DRM_ETNAVIV_GEM_WAIT 0x09 225037b3c26Smrg#define DRM_ETNAVIV_NUM_IOCTLS 0x0a 226037b3c26Smrg 227037b3c26Smrg#define DRM_IOCTL_ETNAVIV_GET_PARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_GET_PARAM, struct drm_etnaviv_param) 228037b3c26Smrg#define DRM_IOCTL_ETNAVIV_GEM_NEW DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_NEW, struct drm_etnaviv_gem_new) 229037b3c26Smrg#define DRM_IOCTL_ETNAVIV_GEM_INFO DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_INFO, struct drm_etnaviv_gem_info) 230037b3c26Smrg#define DRM_IOCTL_ETNAVIV_GEM_CPU_PREP DRM_IOW(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_CPU_PREP, struct drm_etnaviv_gem_cpu_prep) 231037b3c26Smrg#define DRM_IOCTL_ETNAVIV_GEM_CPU_FINI DRM_IOW(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_CPU_FINI, struct drm_etnaviv_gem_cpu_fini) 232037b3c26Smrg#define DRM_IOCTL_ETNAVIV_GEM_SUBMIT DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_SUBMIT, struct drm_etnaviv_gem_submit) 233037b3c26Smrg#define DRM_IOCTL_ETNAVIV_WAIT_FENCE DRM_IOW(DRM_COMMAND_BASE + DRM_ETNAVIV_WAIT_FENCE, struct drm_etnaviv_wait_fence) 234037b3c26Smrg#define DRM_IOCTL_ETNAVIV_GEM_USERPTR DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_USERPTR, struct drm_etnaviv_gem_userptr) 235037b3c26Smrg#define DRM_IOCTL_ETNAVIV_GEM_WAIT DRM_IOW(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_WAIT, struct drm_etnaviv_gem_wait) 236037b3c26Smrg 237037b3c26Smrg#if defined(__cplusplus) 238037b3c26Smrg} 239037b3c26Smrg#endif 240037b3c26Smrg 241037b3c26Smrg#endif /* __ETNAVIV_DRM_H__ */ 242