1037b3c26Smrg/* 2037b3c26Smrg * Copyright (C) 2014-2015 Etnaviv Project 3037b3c26Smrg * 4037b3c26Smrg * Permission is hereby granted, free of charge, to any person obtaining a 5037b3c26Smrg * copy of this software and associated documentation files (the "Software"), 6037b3c26Smrg * to deal in the Software without restriction, including without limitation 7037b3c26Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8037b3c26Smrg * and/or sell copies of the Software, and to permit persons to whom the 9037b3c26Smrg * Software is furnished to do so, subject to the following conditions: 10037b3c26Smrg * 11037b3c26Smrg * The above copyright notice and this permission notice (including the next 12037b3c26Smrg * paragraph) shall be included in all copies or substantial portions of the 13037b3c26Smrg * Software. 14037b3c26Smrg * 15037b3c26Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16037b3c26Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17037b3c26Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18037b3c26Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19037b3c26Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20037b3c26Smrg * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21037b3c26Smrg * SOFTWARE. 22037b3c26Smrg * 23037b3c26Smrg * Authors: 24037b3c26Smrg * Christian Gmeiner <christian.gmeiner@gmail.com> 25037b3c26Smrg */ 26037b3c26Smrg 27037b3c26Smrg#ifndef ETNAVIV_DRMIF_H_ 28037b3c26Smrg#define ETNAVIV_DRMIF_H_ 29037b3c26Smrg 30037b3c26Smrg#include <xf86drm.h> 31037b3c26Smrg#include <stdint.h> 32037b3c26Smrg 33037b3c26Smrgstruct etna_bo; 34037b3c26Smrgstruct etna_pipe; 35037b3c26Smrgstruct etna_gpu; 36037b3c26Smrgstruct etna_device; 37037b3c26Smrgstruct etna_cmd_stream; 3800a23bdaSmrgstruct etna_perfmon; 3900a23bdaSmrgstruct etna_perfmon_domain; 4000a23bdaSmrgstruct etna_perfmon_signal; 41037b3c26Smrg 42037b3c26Smrgenum etna_pipe_id { 43037b3c26Smrg ETNA_PIPE_3D = 0, 44037b3c26Smrg ETNA_PIPE_2D = 1, 45037b3c26Smrg ETNA_PIPE_VG = 2, 46037b3c26Smrg ETNA_PIPE_MAX 47037b3c26Smrg}; 48037b3c26Smrg 49037b3c26Smrgenum etna_param_id { 50037b3c26Smrg ETNA_GPU_MODEL = 0x1, 51037b3c26Smrg ETNA_GPU_REVISION = 0x2, 52037b3c26Smrg ETNA_GPU_FEATURES_0 = 0x3, 53037b3c26Smrg ETNA_GPU_FEATURES_1 = 0x4, 54037b3c26Smrg ETNA_GPU_FEATURES_2 = 0x5, 55037b3c26Smrg ETNA_GPU_FEATURES_3 = 0x6, 56037b3c26Smrg ETNA_GPU_FEATURES_4 = 0x7, 57037b3c26Smrg ETNA_GPU_FEATURES_5 = 0x8, 58037b3c26Smrg ETNA_GPU_FEATURES_6 = 0x9, 59037b3c26Smrg 60037b3c26Smrg ETNA_GPU_STREAM_COUNT = 0x10, 61037b3c26Smrg ETNA_GPU_REGISTER_MAX = 0x11, 62037b3c26Smrg ETNA_GPU_THREAD_COUNT = 0x12, 63037b3c26Smrg ETNA_GPU_VERTEX_CACHE_SIZE = 0x13, 64037b3c26Smrg ETNA_GPU_SHADER_CORE_COUNT = 0x14, 65037b3c26Smrg ETNA_GPU_PIXEL_PIPES = 0x15, 66037b3c26Smrg ETNA_GPU_VERTEX_OUTPUT_BUFFER_SIZE = 0x16, 67037b3c26Smrg ETNA_GPU_BUFFER_SIZE = 0x17, 68037b3c26Smrg ETNA_GPU_INSTRUCTION_COUNT = 0x18, 69037b3c26Smrg ETNA_GPU_NUM_CONSTANTS = 0x19, 70037b3c26Smrg ETNA_GPU_NUM_VARYINGS = 0x1a 71037b3c26Smrg}; 72037b3c26Smrg 73037b3c26Smrg/* bo flags: */ 74037b3c26Smrg#define DRM_ETNA_GEM_CACHE_CACHED 0x00010000 75037b3c26Smrg#define DRM_ETNA_GEM_CACHE_WC 0x00020000 76037b3c26Smrg#define DRM_ETNA_GEM_CACHE_UNCACHED 0x00040000 77037b3c26Smrg#define DRM_ETNA_GEM_CACHE_MASK 0x000f0000 78037b3c26Smrg/* map flags */ 79037b3c26Smrg#define DRM_ETNA_GEM_FORCE_MMU 0x00100000 80037b3c26Smrg 81037b3c26Smrg/* bo access flags: (keep aligned to ETNA_PREP_x) */ 82037b3c26Smrg#define DRM_ETNA_PREP_READ 0x01 83037b3c26Smrg#define DRM_ETNA_PREP_WRITE 0x02 84037b3c26Smrg#define DRM_ETNA_PREP_NOSYNC 0x04 85037b3c26Smrg 86037b3c26Smrg/* device functions: 87037b3c26Smrg */ 88037b3c26Smrg 89037b3c26Smrgstruct etna_device *etna_device_new(int fd); 90037b3c26Smrgstruct etna_device *etna_device_new_dup(int fd); 91037b3c26Smrgstruct etna_device *etna_device_ref(struct etna_device *dev); 92037b3c26Smrgvoid etna_device_del(struct etna_device *dev); 93037b3c26Smrgint etna_device_fd(struct etna_device *dev); 94037b3c26Smrg 95037b3c26Smrg/* gpu functions: 96037b3c26Smrg */ 97037b3c26Smrg 98037b3c26Smrgstruct etna_gpu *etna_gpu_new(struct etna_device *dev, unsigned int core); 99037b3c26Smrgvoid etna_gpu_del(struct etna_gpu *gpu); 100037b3c26Smrgint etna_gpu_get_param(struct etna_gpu *gpu, enum etna_param_id param, 101037b3c26Smrg uint64_t *value); 102037b3c26Smrg 103037b3c26Smrg 104037b3c26Smrg/* pipe functions: 105037b3c26Smrg */ 106037b3c26Smrg 107037b3c26Smrgstruct etna_pipe *etna_pipe_new(struct etna_gpu *gpu, enum etna_pipe_id id); 108037b3c26Smrgvoid etna_pipe_del(struct etna_pipe *pipe); 109037b3c26Smrgint etna_pipe_wait(struct etna_pipe *pipe, uint32_t timestamp, uint32_t ms); 110037b3c26Smrgint etna_pipe_wait_ns(struct etna_pipe *pipe, uint32_t timestamp, uint64_t ns); 111037b3c26Smrg 112037b3c26Smrg 113037b3c26Smrg/* buffer-object functions: 114037b3c26Smrg */ 115037b3c26Smrg 116037b3c26Smrgstruct etna_bo *etna_bo_new(struct etna_device *dev, 117037b3c26Smrg uint32_t size, uint32_t flags); 118037b3c26Smrgstruct etna_bo *etna_bo_from_name(struct etna_device *dev, uint32_t name); 119037b3c26Smrgstruct etna_bo *etna_bo_from_dmabuf(struct etna_device *dev, int fd); 120037b3c26Smrgstruct etna_bo *etna_bo_ref(struct etna_bo *bo); 121037b3c26Smrgvoid etna_bo_del(struct etna_bo *bo); 122037b3c26Smrgint etna_bo_get_name(struct etna_bo *bo, uint32_t *name); 123037b3c26Smrguint32_t etna_bo_handle(struct etna_bo *bo); 124037b3c26Smrgint etna_bo_dmabuf(struct etna_bo *bo); 125037b3c26Smrguint32_t etna_bo_size(struct etna_bo *bo); 126037b3c26Smrgvoid * etna_bo_map(struct etna_bo *bo); 127037b3c26Smrgint etna_bo_cpu_prep(struct etna_bo *bo, uint32_t op); 128037b3c26Smrgvoid etna_bo_cpu_fini(struct etna_bo *bo); 129037b3c26Smrg 130037b3c26Smrg 131037b3c26Smrg/* cmd stream functions: 132037b3c26Smrg */ 133037b3c26Smrg 134037b3c26Smrgstruct etna_cmd_stream { 135037b3c26Smrg uint32_t *buffer; 136037b3c26Smrg uint32_t offset; /* in 32-bit words */ 137037b3c26Smrg uint32_t size; /* in 32-bit words */ 138037b3c26Smrg}; 139037b3c26Smrg 140037b3c26Smrgstruct etna_cmd_stream *etna_cmd_stream_new(struct etna_pipe *pipe, uint32_t size, 141037b3c26Smrg void (*reset_notify)(struct etna_cmd_stream *stream, void *priv), 142037b3c26Smrg void *priv); 143037b3c26Smrgvoid etna_cmd_stream_del(struct etna_cmd_stream *stream); 144037b3c26Smrguint32_t etna_cmd_stream_timestamp(struct etna_cmd_stream *stream); 145037b3c26Smrgvoid etna_cmd_stream_flush(struct etna_cmd_stream *stream); 146d8807b2fSmrgvoid etna_cmd_stream_flush2(struct etna_cmd_stream *stream, int in_fence_fd, 147d8807b2fSmrg int *out_fence_fd); 148037b3c26Smrgvoid etna_cmd_stream_finish(struct etna_cmd_stream *stream); 149037b3c26Smrg 150037b3c26Smrgstatic inline uint32_t etna_cmd_stream_avail(struct etna_cmd_stream *stream) 151037b3c26Smrg{ 152037b3c26Smrg static const uint32_t END_CLEARANCE = 2; /* LINK op code */ 153037b3c26Smrg 154037b3c26Smrg return stream->size - stream->offset - END_CLEARANCE; 155037b3c26Smrg} 156037b3c26Smrg 157037b3c26Smrgstatic inline void etna_cmd_stream_reserve(struct etna_cmd_stream *stream, size_t n) 158037b3c26Smrg{ 159037b3c26Smrg if (etna_cmd_stream_avail(stream) < n) 160037b3c26Smrg etna_cmd_stream_flush(stream); 161037b3c26Smrg} 162037b3c26Smrg 163037b3c26Smrgstatic inline void etna_cmd_stream_emit(struct etna_cmd_stream *stream, uint32_t data) 164037b3c26Smrg{ 165037b3c26Smrg stream->buffer[stream->offset++] = data; 166037b3c26Smrg} 167037b3c26Smrg 168037b3c26Smrgstatic inline uint32_t etna_cmd_stream_get(struct etna_cmd_stream *stream, uint32_t offset) 169037b3c26Smrg{ 170037b3c26Smrg return stream->buffer[offset]; 171037b3c26Smrg} 172037b3c26Smrg 173037b3c26Smrgstatic inline void etna_cmd_stream_set(struct etna_cmd_stream *stream, uint32_t offset, 174037b3c26Smrg uint32_t data) 175037b3c26Smrg{ 176037b3c26Smrg stream->buffer[offset] = data; 177037b3c26Smrg} 178037b3c26Smrg 179037b3c26Smrgstatic inline uint32_t etna_cmd_stream_offset(struct etna_cmd_stream *stream) 180037b3c26Smrg{ 181037b3c26Smrg return stream->offset; 182037b3c26Smrg} 183037b3c26Smrg 184037b3c26Smrgstruct etna_reloc { 185037b3c26Smrg struct etna_bo *bo; 186037b3c26Smrg#define ETNA_RELOC_READ 0x0001 187037b3c26Smrg#define ETNA_RELOC_WRITE 0x0002 188037b3c26Smrg uint32_t flags; 189037b3c26Smrg uint32_t offset; 190037b3c26Smrg}; 191037b3c26Smrg 192037b3c26Smrgvoid etna_cmd_stream_reloc(struct etna_cmd_stream *stream, const struct etna_reloc *r); 193037b3c26Smrg 19400a23bdaSmrg/* performance monitoring functions: 19500a23bdaSmrg */ 19600a23bdaSmrg 19700a23bdaSmrgstruct etna_perfmon *etna_perfmon_create(struct etna_pipe *pipe); 19800a23bdaSmrgvoid etna_perfmon_del(struct etna_perfmon *perfmon); 19900a23bdaSmrgstruct etna_perfmon_domain *etna_perfmon_get_dom_by_name(struct etna_perfmon *pm, const char *name); 20000a23bdaSmrgstruct etna_perfmon_signal *etna_perfmon_get_sig_by_name(struct etna_perfmon_domain *dom, const char *name); 20100a23bdaSmrg 20200a23bdaSmrgstruct etna_perf { 20300a23bdaSmrg#define ETNA_PM_PROCESS_PRE 0x0001 20400a23bdaSmrg#define ETNA_PM_PROCESS_POST 0x0002 20500a23bdaSmrg uint32_t flags; 20600a23bdaSmrg uint32_t sequence; 20700a23bdaSmrg struct etna_perfmon_signal *signal; 20800a23bdaSmrg struct etna_bo *bo; 20900a23bdaSmrg uint32_t offset; 21000a23bdaSmrg}; 21100a23bdaSmrg 21200a23bdaSmrgvoid etna_cmd_stream_perf(struct etna_cmd_stream *stream, const struct etna_perf *p); 21300a23bdaSmrg 214037b3c26Smrg#endif /* ETNAVIV_DRMIF_H_ */ 215