etnaviv_drm.h revision 7cdc0497
17cdc0497Smrg/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2037b3c26Smrg/* 3037b3c26Smrg * Copyright (C) 2015 Etnaviv Project 4037b3c26Smrg * 5037b3c26Smrg * This program is free software; you can redistribute it and/or modify it 6037b3c26Smrg * under the terms of the GNU General Public License version 2 as published by 7037b3c26Smrg * the Free Software Foundation. 8037b3c26Smrg * 9037b3c26Smrg * This program is distributed in the hope that it will be useful, but WITHOUT 10037b3c26Smrg * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11037b3c26Smrg * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12037b3c26Smrg * more details. 13037b3c26Smrg * 14037b3c26Smrg * You should have received a copy of the GNU General Public License along with 15037b3c26Smrg * this program. If not, see <http://www.gnu.org/licenses/>. 16037b3c26Smrg */ 17037b3c26Smrg 18037b3c26Smrg#ifndef __ETNAVIV_DRM_H__ 19037b3c26Smrg#define __ETNAVIV_DRM_H__ 20037b3c26Smrg 21037b3c26Smrg#include "drm.h" 22037b3c26Smrg 23037b3c26Smrg#if defined(__cplusplus) 24037b3c26Smrgextern "C" { 25037b3c26Smrg#endif 26037b3c26Smrg 27037b3c26Smrg/* Please note that modifications to all structs defined here are 28037b3c26Smrg * subject to backwards-compatibility constraints: 29037b3c26Smrg * 1) Do not use pointers, use __u64 instead for 32 bit / 64 bit 30037b3c26Smrg * user/kernel compatibility 31037b3c26Smrg * 2) Keep fields aligned to their size 32037b3c26Smrg * 3) Because of how drm_ioctl() works, we can add new fields at 33037b3c26Smrg * the end of an ioctl if some care is taken: drm_ioctl() will 34037b3c26Smrg * zero out the new fields at the tail of the ioctl, so a zero 35037b3c26Smrg * value should have a backwards compatible meaning. And for 36037b3c26Smrg * output params, userspace won't see the newly added output 37037b3c26Smrg * fields.. so that has to be somehow ok. 38037b3c26Smrg */ 39037b3c26Smrg 40037b3c26Smrg/* timeouts are specified in clock-monotonic absolute times (to simplify 41037b3c26Smrg * restarting interrupted ioctls). The following struct is logically the 42037b3c26Smrg * same as 'struct timespec' but 32/64b ABI safe. 43037b3c26Smrg */ 44037b3c26Smrgstruct drm_etnaviv_timespec { 45037b3c26Smrg __s64 tv_sec; /* seconds */ 46037b3c26Smrg __s64 tv_nsec; /* nanoseconds */ 47037b3c26Smrg}; 48037b3c26Smrg 49037b3c26Smrg#define ETNAVIV_PARAM_GPU_MODEL 0x01 50037b3c26Smrg#define ETNAVIV_PARAM_GPU_REVISION 0x02 51037b3c26Smrg#define ETNAVIV_PARAM_GPU_FEATURES_0 0x03 52037b3c26Smrg#define ETNAVIV_PARAM_GPU_FEATURES_1 0x04 53037b3c26Smrg#define ETNAVIV_PARAM_GPU_FEATURES_2 0x05 54037b3c26Smrg#define ETNAVIV_PARAM_GPU_FEATURES_3 0x06 55037b3c26Smrg#define ETNAVIV_PARAM_GPU_FEATURES_4 0x07 56037b3c26Smrg#define ETNAVIV_PARAM_GPU_FEATURES_5 0x08 57037b3c26Smrg#define ETNAVIV_PARAM_GPU_FEATURES_6 0x09 587cdc0497Smrg#define ETNAVIV_PARAM_GPU_FEATURES_7 0x0a 597cdc0497Smrg#define ETNAVIV_PARAM_GPU_FEATURES_8 0x0b 607cdc0497Smrg#define ETNAVIV_PARAM_GPU_FEATURES_9 0x0c 617cdc0497Smrg#define ETNAVIV_PARAM_GPU_FEATURES_10 0x0d 627cdc0497Smrg#define ETNAVIV_PARAM_GPU_FEATURES_11 0x0e 637cdc0497Smrg#define ETNAVIV_PARAM_GPU_FEATURES_12 0x0f 64037b3c26Smrg 65037b3c26Smrg#define ETNAVIV_PARAM_GPU_STREAM_COUNT 0x10 66037b3c26Smrg#define ETNAVIV_PARAM_GPU_REGISTER_MAX 0x11 67037b3c26Smrg#define ETNAVIV_PARAM_GPU_THREAD_COUNT 0x12 68037b3c26Smrg#define ETNAVIV_PARAM_GPU_VERTEX_CACHE_SIZE 0x13 69037b3c26Smrg#define ETNAVIV_PARAM_GPU_SHADER_CORE_COUNT 0x14 70037b3c26Smrg#define ETNAVIV_PARAM_GPU_PIXEL_PIPES 0x15 71037b3c26Smrg#define ETNAVIV_PARAM_GPU_VERTEX_OUTPUT_BUFFER_SIZE 0x16 72037b3c26Smrg#define ETNAVIV_PARAM_GPU_BUFFER_SIZE 0x17 73037b3c26Smrg#define ETNAVIV_PARAM_GPU_INSTRUCTION_COUNT 0x18 74037b3c26Smrg#define ETNAVIV_PARAM_GPU_NUM_CONSTANTS 0x19 75037b3c26Smrg#define ETNAVIV_PARAM_GPU_NUM_VARYINGS 0x1a 76037b3c26Smrg 77037b3c26Smrg#define ETNA_MAX_PIPES 4 78037b3c26Smrg 79037b3c26Smrgstruct drm_etnaviv_param { 80037b3c26Smrg __u32 pipe; /* in */ 81037b3c26Smrg __u32 param; /* in, ETNAVIV_PARAM_x */ 82037b3c26Smrg __u64 value; /* out (get_param) or in (set_param) */ 83037b3c26Smrg}; 84037b3c26Smrg 85037b3c26Smrg/* 86037b3c26Smrg * GEM buffers: 87037b3c26Smrg */ 88037b3c26Smrg 89037b3c26Smrg#define ETNA_BO_CACHE_MASK 0x000f0000 90037b3c26Smrg/* cache modes */ 91037b3c26Smrg#define ETNA_BO_CACHED 0x00010000 92037b3c26Smrg#define ETNA_BO_WC 0x00020000 93037b3c26Smrg#define ETNA_BO_UNCACHED 0x00040000 94037b3c26Smrg/* map flags */ 95037b3c26Smrg#define ETNA_BO_FORCE_MMU 0x00100000 96037b3c26Smrg 97037b3c26Smrgstruct drm_etnaviv_gem_new { 98037b3c26Smrg __u64 size; /* in */ 99037b3c26Smrg __u32 flags; /* in, mask of ETNA_BO_x */ 100037b3c26Smrg __u32 handle; /* out */ 101037b3c26Smrg}; 102037b3c26Smrg 103037b3c26Smrgstruct drm_etnaviv_gem_info { 104037b3c26Smrg __u32 handle; /* in */ 105037b3c26Smrg __u32 pad; 106037b3c26Smrg __u64 offset; /* out, offset to pass to mmap() */ 107037b3c26Smrg}; 108037b3c26Smrg 109037b3c26Smrg#define ETNA_PREP_READ 0x01 110037b3c26Smrg#define ETNA_PREP_WRITE 0x02 111037b3c26Smrg#define ETNA_PREP_NOSYNC 0x04 112037b3c26Smrg 113037b3c26Smrgstruct drm_etnaviv_gem_cpu_prep { 114037b3c26Smrg __u32 handle; /* in */ 115037b3c26Smrg __u32 op; /* in, mask of ETNA_PREP_x */ 116037b3c26Smrg struct drm_etnaviv_timespec timeout; /* in */ 117037b3c26Smrg}; 118037b3c26Smrg 119037b3c26Smrgstruct drm_etnaviv_gem_cpu_fini { 120037b3c26Smrg __u32 handle; /* in */ 121037b3c26Smrg __u32 flags; /* in, placeholder for now, no defined values */ 122037b3c26Smrg}; 123037b3c26Smrg 124037b3c26Smrg/* 125037b3c26Smrg * Cmdstream Submission: 126037b3c26Smrg */ 127037b3c26Smrg 128037b3c26Smrg/* The value written into the cmdstream is logically: 129037b3c26Smrg * relocbuf->gpuaddr + reloc_offset 130037b3c26Smrg * 131037b3c26Smrg * NOTE that reloc's must be sorted by order of increasing submit_offset, 132037b3c26Smrg * otherwise EINVAL. 133037b3c26Smrg */ 134037b3c26Smrgstruct drm_etnaviv_gem_submit_reloc { 135037b3c26Smrg __u32 submit_offset; /* in, offset from submit_bo */ 136037b3c26Smrg __u32 reloc_idx; /* in, index of reloc_bo buffer */ 137037b3c26Smrg __u64 reloc_offset; /* in, offset from start of reloc_bo */ 138037b3c26Smrg __u32 flags; /* in, placeholder for now, no defined values */ 139037b3c26Smrg}; 140037b3c26Smrg 141037b3c26Smrg/* Each buffer referenced elsewhere in the cmdstream submit (ie. the 142037b3c26Smrg * cmdstream buffer(s) themselves or reloc entries) has one (and only 143037b3c26Smrg * one) entry in the submit->bos[] table. 144037b3c26Smrg * 145037b3c26Smrg * As a optimization, the current buffer (gpu virtual address) can be 146037b3c26Smrg * passed back through the 'presumed' field. If on a subsequent reloc, 147037b3c26Smrg * userspace passes back a 'presumed' address that is still valid, 148037b3c26Smrg * then patching the cmdstream for this entry is skipped. This can 149037b3c26Smrg * avoid kernel needing to map/access the cmdstream bo in the common 150037b3c26Smrg * case. 151037b3c26Smrg */ 152037b3c26Smrg#define ETNA_SUBMIT_BO_READ 0x0001 153037b3c26Smrg#define ETNA_SUBMIT_BO_WRITE 0x0002 154037b3c26Smrgstruct drm_etnaviv_gem_submit_bo { 155037b3c26Smrg __u32 flags; /* in, mask of ETNA_SUBMIT_BO_x */ 156037b3c26Smrg __u32 handle; /* in, GEM handle */ 157037b3c26Smrg __u64 presumed; /* in/out, presumed buffer address */ 158037b3c26Smrg}; 159037b3c26Smrg 16000a23bdaSmrg/* performance monitor request (pmr) */ 16100a23bdaSmrg#define ETNA_PM_PROCESS_PRE 0x0001 16200a23bdaSmrg#define ETNA_PM_PROCESS_POST 0x0002 16300a23bdaSmrgstruct drm_etnaviv_gem_submit_pmr { 16400a23bdaSmrg __u32 flags; /* in, when to process request (ETNA_PM_PROCESS_x) */ 16500a23bdaSmrg __u8 domain; /* in, pm domain */ 16600a23bdaSmrg __u8 pad; 16700a23bdaSmrg __u16 signal; /* in, pm signal */ 16800a23bdaSmrg __u32 sequence; /* in, sequence number */ 16900a23bdaSmrg __u32 read_offset; /* in, offset from read_bo */ 17000a23bdaSmrg __u32 read_idx; /* in, index of read_bo buffer */ 17100a23bdaSmrg}; 17200a23bdaSmrg 173037b3c26Smrg/* Each cmdstream submit consists of a table of buffers involved, and 174037b3c26Smrg * one or more cmdstream buffers. This allows for conditional execution 175037b3c26Smrg * (context-restore), and IB buffers needed for per tile/bin draw cmds. 176037b3c26Smrg */ 177d8807b2fSmrg#define ETNA_SUBMIT_NO_IMPLICIT 0x0001 178d8807b2fSmrg#define ETNA_SUBMIT_FENCE_FD_IN 0x0002 179d8807b2fSmrg#define ETNA_SUBMIT_FENCE_FD_OUT 0x0004 180d8807b2fSmrg#define ETNA_SUBMIT_FLAGS (ETNA_SUBMIT_NO_IMPLICIT | \ 181d8807b2fSmrg ETNA_SUBMIT_FENCE_FD_IN | \ 182d8807b2fSmrg ETNA_SUBMIT_FENCE_FD_OUT) 183037b3c26Smrg#define ETNA_PIPE_3D 0x00 184037b3c26Smrg#define ETNA_PIPE_2D 0x01 185037b3c26Smrg#define ETNA_PIPE_VG 0x02 186037b3c26Smrgstruct drm_etnaviv_gem_submit { 187037b3c26Smrg __u32 fence; /* out */ 188037b3c26Smrg __u32 pipe; /* in */ 189037b3c26Smrg __u32 exec_state; /* in, initial execution state (ETNA_PIPE_x) */ 190037b3c26Smrg __u32 nr_bos; /* in, number of submit_bo's */ 191037b3c26Smrg __u32 nr_relocs; /* in, number of submit_reloc's */ 192037b3c26Smrg __u32 stream_size; /* in, cmdstream size */ 193037b3c26Smrg __u64 bos; /* in, ptr to array of submit_bo's */ 194037b3c26Smrg __u64 relocs; /* in, ptr to array of submit_reloc's */ 195037b3c26Smrg __u64 stream; /* in, ptr to cmdstream */ 196d8807b2fSmrg __u32 flags; /* in, mask of ETNA_SUBMIT_x */ 197d8807b2fSmrg __s32 fence_fd; /* in/out, fence fd (see ETNA_SUBMIT_FENCE_FD_x) */ 19800a23bdaSmrg __u64 pmrs; /* in, ptr to array of submit_pmr's */ 19900a23bdaSmrg __u32 nr_pmrs; /* in, number of submit_pmr's */ 20000a23bdaSmrg __u32 pad; 201037b3c26Smrg}; 202037b3c26Smrg 203037b3c26Smrg/* The normal way to synchronize with the GPU is just to CPU_PREP on 204037b3c26Smrg * a buffer if you need to access it from the CPU (other cmdstream 205037b3c26Smrg * submission from same or other contexts, PAGE_FLIP ioctl, etc, all 206037b3c26Smrg * handle the required synchronization under the hood). This ioctl 207037b3c26Smrg * mainly just exists as a way to implement the gallium pipe_fence 208037b3c26Smrg * APIs without requiring a dummy bo to synchronize on. 209037b3c26Smrg */ 210037b3c26Smrg#define ETNA_WAIT_NONBLOCK 0x01 211037b3c26Smrgstruct drm_etnaviv_wait_fence { 212037b3c26Smrg __u32 pipe; /* in */ 213037b3c26Smrg __u32 fence; /* in */ 214037b3c26Smrg __u32 flags; /* in, mask of ETNA_WAIT_x */ 215037b3c26Smrg __u32 pad; 216037b3c26Smrg struct drm_etnaviv_timespec timeout; /* in */ 217037b3c26Smrg}; 218037b3c26Smrg 219037b3c26Smrg#define ETNA_USERPTR_READ 0x01 220037b3c26Smrg#define ETNA_USERPTR_WRITE 0x02 221037b3c26Smrgstruct drm_etnaviv_gem_userptr { 222037b3c26Smrg __u64 user_ptr; /* in, page aligned user pointer */ 223037b3c26Smrg __u64 user_size; /* in, page aligned user size */ 224037b3c26Smrg __u32 flags; /* in, flags */ 225037b3c26Smrg __u32 handle; /* out, non-zero handle */ 226037b3c26Smrg}; 227037b3c26Smrg 228037b3c26Smrgstruct drm_etnaviv_gem_wait { 229037b3c26Smrg __u32 pipe; /* in */ 230037b3c26Smrg __u32 handle; /* in, bo to be waited for */ 231037b3c26Smrg __u32 flags; /* in, mask of ETNA_WAIT_x */ 232037b3c26Smrg __u32 pad; 233037b3c26Smrg struct drm_etnaviv_timespec timeout; /* in */ 234037b3c26Smrg}; 235037b3c26Smrg 23600a23bdaSmrg/* 23700a23bdaSmrg * Performance Monitor (PM): 23800a23bdaSmrg */ 23900a23bdaSmrg 24000a23bdaSmrgstruct drm_etnaviv_pm_domain { 24100a23bdaSmrg __u32 pipe; /* in */ 24200a23bdaSmrg __u8 iter; /* in/out, select pm domain at index iter */ 24300a23bdaSmrg __u8 id; /* out, id of domain */ 24400a23bdaSmrg __u16 nr_signals; /* out, how many signals does this domain provide */ 24500a23bdaSmrg char name[64]; /* out, name of domain */ 24600a23bdaSmrg}; 24700a23bdaSmrg 24800a23bdaSmrgstruct drm_etnaviv_pm_signal { 24900a23bdaSmrg __u32 pipe; /* in */ 25000a23bdaSmrg __u8 domain; /* in, pm domain index */ 25100a23bdaSmrg __u8 pad; 25200a23bdaSmrg __u16 iter; /* in/out, select pm source at index iter */ 25300a23bdaSmrg __u16 id; /* out, id of signal */ 25400a23bdaSmrg char name[64]; /* out, name of domain */ 25500a23bdaSmrg}; 25600a23bdaSmrg 257037b3c26Smrg#define DRM_ETNAVIV_GET_PARAM 0x00 258037b3c26Smrg/* placeholder: 259037b3c26Smrg#define DRM_ETNAVIV_SET_PARAM 0x01 260037b3c26Smrg */ 261037b3c26Smrg#define DRM_ETNAVIV_GEM_NEW 0x02 262037b3c26Smrg#define DRM_ETNAVIV_GEM_INFO 0x03 263037b3c26Smrg#define DRM_ETNAVIV_GEM_CPU_PREP 0x04 264037b3c26Smrg#define DRM_ETNAVIV_GEM_CPU_FINI 0x05 265037b3c26Smrg#define DRM_ETNAVIV_GEM_SUBMIT 0x06 266037b3c26Smrg#define DRM_ETNAVIV_WAIT_FENCE 0x07 267037b3c26Smrg#define DRM_ETNAVIV_GEM_USERPTR 0x08 268037b3c26Smrg#define DRM_ETNAVIV_GEM_WAIT 0x09 26900a23bdaSmrg#define DRM_ETNAVIV_PM_QUERY_DOM 0x0a 27000a23bdaSmrg#define DRM_ETNAVIV_PM_QUERY_SIG 0x0b 27100a23bdaSmrg#define DRM_ETNAVIV_NUM_IOCTLS 0x0c 272037b3c26Smrg 273037b3c26Smrg#define DRM_IOCTL_ETNAVIV_GET_PARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_GET_PARAM, struct drm_etnaviv_param) 274037b3c26Smrg#define DRM_IOCTL_ETNAVIV_GEM_NEW DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_NEW, struct drm_etnaviv_gem_new) 275037b3c26Smrg#define DRM_IOCTL_ETNAVIV_GEM_INFO DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_INFO, struct drm_etnaviv_gem_info) 276037b3c26Smrg#define DRM_IOCTL_ETNAVIV_GEM_CPU_PREP DRM_IOW(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_CPU_PREP, struct drm_etnaviv_gem_cpu_prep) 277037b3c26Smrg#define DRM_IOCTL_ETNAVIV_GEM_CPU_FINI DRM_IOW(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_CPU_FINI, struct drm_etnaviv_gem_cpu_fini) 278037b3c26Smrg#define DRM_IOCTL_ETNAVIV_GEM_SUBMIT DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_SUBMIT, struct drm_etnaviv_gem_submit) 279037b3c26Smrg#define DRM_IOCTL_ETNAVIV_WAIT_FENCE DRM_IOW(DRM_COMMAND_BASE + DRM_ETNAVIV_WAIT_FENCE, struct drm_etnaviv_wait_fence) 280037b3c26Smrg#define DRM_IOCTL_ETNAVIV_GEM_USERPTR DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_USERPTR, struct drm_etnaviv_gem_userptr) 281037b3c26Smrg#define DRM_IOCTL_ETNAVIV_GEM_WAIT DRM_IOW(DRM_COMMAND_BASE + DRM_ETNAVIV_GEM_WAIT, struct drm_etnaviv_gem_wait) 28200a23bdaSmrg#define DRM_IOCTL_ETNAVIV_PM_QUERY_DOM DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_PM_QUERY_DOM, struct drm_etnaviv_pm_domain) 28300a23bdaSmrg#define DRM_IOCTL_ETNAVIV_PM_QUERY_SIG DRM_IOWR(DRM_COMMAND_BASE + DRM_ETNAVIV_PM_QUERY_SIG, struct drm_etnaviv_pm_signal) 284037b3c26Smrg 285037b3c26Smrg#if defined(__cplusplus) 286037b3c26Smrg} 287037b3c26Smrg#endif 288037b3c26Smrg 289037b3c26Smrg#endif /* __ETNAVIV_DRM_H__ */ 290