1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright (C) 2014-2015 Etnaviv Project 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20bf215546Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21bf215546Sopenharmony_ci * SOFTWARE. 22bf215546Sopenharmony_ci * 23bf215546Sopenharmony_ci * Authors: 24bf215546Sopenharmony_ci * Christian Gmeiner <christian.gmeiner@gmail.com> 25bf215546Sopenharmony_ci */ 26bf215546Sopenharmony_ci 27bf215546Sopenharmony_ci#ifndef ETNAVIV_DRMIF_H_ 28bf215546Sopenharmony_ci#define ETNAVIV_DRMIF_H_ 29bf215546Sopenharmony_ci 30bf215546Sopenharmony_ci#include <xf86drm.h> 31bf215546Sopenharmony_ci#include <stdbool.h> 32bf215546Sopenharmony_ci#include <stdint.h> 33bf215546Sopenharmony_ci 34bf215546Sopenharmony_cistruct etna_bo; 35bf215546Sopenharmony_cistruct etna_pipe; 36bf215546Sopenharmony_cistruct etna_gpu; 37bf215546Sopenharmony_cistruct etna_device; 38bf215546Sopenharmony_cistruct etna_cmd_stream; 39bf215546Sopenharmony_cistruct etna_perfmon; 40bf215546Sopenharmony_cistruct etna_perfmon_domain; 41bf215546Sopenharmony_cistruct etna_perfmon_signal; 42bf215546Sopenharmony_ci 43bf215546Sopenharmony_cienum etna_pipe_id { 44bf215546Sopenharmony_ci ETNA_PIPE_3D = 0, 45bf215546Sopenharmony_ci ETNA_PIPE_2D = 1, 46bf215546Sopenharmony_ci ETNA_PIPE_VG = 2, 47bf215546Sopenharmony_ci ETNA_PIPE_MAX 48bf215546Sopenharmony_ci}; 49bf215546Sopenharmony_ci 50bf215546Sopenharmony_cienum etna_param_id { 51bf215546Sopenharmony_ci ETNA_GPU_MODEL = 0x1, 52bf215546Sopenharmony_ci ETNA_GPU_REVISION = 0x2, 53bf215546Sopenharmony_ci ETNA_GPU_FEATURES_0 = 0x3, 54bf215546Sopenharmony_ci ETNA_GPU_FEATURES_1 = 0x4, 55bf215546Sopenharmony_ci ETNA_GPU_FEATURES_2 = 0x5, 56bf215546Sopenharmony_ci ETNA_GPU_FEATURES_3 = 0x6, 57bf215546Sopenharmony_ci ETNA_GPU_FEATURES_4 = 0x7, 58bf215546Sopenharmony_ci ETNA_GPU_FEATURES_5 = 0x8, 59bf215546Sopenharmony_ci ETNA_GPU_FEATURES_6 = 0x9, 60bf215546Sopenharmony_ci ETNA_GPU_FEATURES_7 = 0xa, 61bf215546Sopenharmony_ci ETNA_GPU_FEATURES_8 = 0xb, 62bf215546Sopenharmony_ci ETNA_GPU_FEATURES_9 = 0xc, 63bf215546Sopenharmony_ci ETNA_GPU_FEATURES_10 = 0xd, 64bf215546Sopenharmony_ci ETNA_GPU_FEATURES_11 = 0xe, 65bf215546Sopenharmony_ci ETNA_GPU_FEATURES_12 = 0xf, 66bf215546Sopenharmony_ci 67bf215546Sopenharmony_ci ETNA_GPU_STREAM_COUNT = 0x10, 68bf215546Sopenharmony_ci ETNA_GPU_REGISTER_MAX = 0x11, 69bf215546Sopenharmony_ci ETNA_GPU_THREAD_COUNT = 0x12, 70bf215546Sopenharmony_ci ETNA_GPU_VERTEX_CACHE_SIZE = 0x13, 71bf215546Sopenharmony_ci ETNA_GPU_SHADER_CORE_COUNT = 0x14, 72bf215546Sopenharmony_ci ETNA_GPU_PIXEL_PIPES = 0x15, 73bf215546Sopenharmony_ci ETNA_GPU_VERTEX_OUTPUT_BUFFER_SIZE = 0x16, 74bf215546Sopenharmony_ci ETNA_GPU_BUFFER_SIZE = 0x17, 75bf215546Sopenharmony_ci ETNA_GPU_INSTRUCTION_COUNT = 0x18, 76bf215546Sopenharmony_ci ETNA_GPU_NUM_CONSTANTS = 0x19, 77bf215546Sopenharmony_ci ETNA_GPU_NUM_VARYINGS = 0x1a 78bf215546Sopenharmony_ci}; 79bf215546Sopenharmony_ci 80bf215546Sopenharmony_ci/* bo flags: */ 81bf215546Sopenharmony_ci#define DRM_ETNA_GEM_CACHE_CACHED 0x00010000 82bf215546Sopenharmony_ci#define DRM_ETNA_GEM_CACHE_WC 0x00020000 83bf215546Sopenharmony_ci#define DRM_ETNA_GEM_CACHE_UNCACHED 0x00040000 84bf215546Sopenharmony_ci#define DRM_ETNA_GEM_CACHE_MASK 0x000f0000 85bf215546Sopenharmony_ci/* map flags */ 86bf215546Sopenharmony_ci#define DRM_ETNA_GEM_FORCE_MMU 0x00100000 87bf215546Sopenharmony_ci 88bf215546Sopenharmony_ci/* bo access flags: (keep aligned to ETNA_PREP_x) */ 89bf215546Sopenharmony_ci#define DRM_ETNA_PREP_READ 0x01 90bf215546Sopenharmony_ci#define DRM_ETNA_PREP_WRITE 0x02 91bf215546Sopenharmony_ci#define DRM_ETNA_PREP_NOSYNC 0x04 92bf215546Sopenharmony_ci 93bf215546Sopenharmony_ci/* device functions: 94bf215546Sopenharmony_ci */ 95bf215546Sopenharmony_ci 96bf215546Sopenharmony_ci#define ETNA_DRM_VERSION(major, minor) ((major) << 16 | (minor)) 97bf215546Sopenharmony_ci 98bf215546Sopenharmony_cistruct etna_device *etna_device_new(int fd); 99bf215546Sopenharmony_cistruct etna_device *etna_device_new_dup(int fd); 100bf215546Sopenharmony_cistruct etna_device *etna_device_ref(struct etna_device *dev); 101bf215546Sopenharmony_civoid etna_device_del(struct etna_device *dev); 102bf215546Sopenharmony_ciint etna_device_fd(struct etna_device *dev); 103bf215546Sopenharmony_cibool etnaviv_device_softpin_capable(struct etna_device *dev); 104bf215546Sopenharmony_ciuint32_t etnaviv_device_version(struct etna_device *dev); 105bf215546Sopenharmony_ci 106bf215546Sopenharmony_ci/* gpu functions: 107bf215546Sopenharmony_ci */ 108bf215546Sopenharmony_ci 109bf215546Sopenharmony_cistruct etna_gpu *etna_gpu_new(struct etna_device *dev, unsigned int core); 110bf215546Sopenharmony_civoid etna_gpu_del(struct etna_gpu *gpu); 111bf215546Sopenharmony_ciint etna_gpu_get_param(struct etna_gpu *gpu, enum etna_param_id param, 112bf215546Sopenharmony_ci uint64_t *value); 113bf215546Sopenharmony_ci 114bf215546Sopenharmony_ci 115bf215546Sopenharmony_ci/* pipe functions: 116bf215546Sopenharmony_ci */ 117bf215546Sopenharmony_ci 118bf215546Sopenharmony_cistruct etna_pipe *etna_pipe_new(struct etna_gpu *gpu, enum etna_pipe_id id); 119bf215546Sopenharmony_civoid etna_pipe_del(struct etna_pipe *pipe); 120bf215546Sopenharmony_ciint etna_pipe_wait_ns(struct etna_pipe *pipe, uint32_t timestamp, uint64_t ns); 121bf215546Sopenharmony_ci 122bf215546Sopenharmony_ci 123bf215546Sopenharmony_ci/* buffer-object functions: 124bf215546Sopenharmony_ci */ 125bf215546Sopenharmony_ci 126bf215546Sopenharmony_cistruct etna_bo *etna_bo_new(struct etna_device *dev, 127bf215546Sopenharmony_ci uint32_t size, uint32_t flags); 128bf215546Sopenharmony_cistruct etna_bo *etna_bo_from_name(struct etna_device *dev, uint32_t name); 129bf215546Sopenharmony_cistruct etna_bo *etna_bo_from_dmabuf(struct etna_device *dev, int fd); 130bf215546Sopenharmony_cistruct etna_bo *etna_bo_ref(struct etna_bo *bo); 131bf215546Sopenharmony_civoid etna_bo_del(struct etna_bo *bo); 132bf215546Sopenharmony_ciint etna_bo_get_name(struct etna_bo *bo, uint32_t *name); 133bf215546Sopenharmony_ciuint32_t etna_bo_handle(struct etna_bo *bo); 134bf215546Sopenharmony_ciint etna_bo_dmabuf(struct etna_bo *bo); 135bf215546Sopenharmony_ciuint32_t etna_bo_size(struct etna_bo *bo); 136bf215546Sopenharmony_ciuint32_t etna_bo_gpu_va(struct etna_bo *bo); 137bf215546Sopenharmony_civoid * etna_bo_map(struct etna_bo *bo); 138bf215546Sopenharmony_ciint etna_bo_cpu_prep(struct etna_bo *bo, uint32_t op); 139bf215546Sopenharmony_civoid etna_bo_cpu_fini(struct etna_bo *bo); 140bf215546Sopenharmony_ciint etna_bo_is_idle(struct etna_bo *bo); 141bf215546Sopenharmony_ci 142bf215546Sopenharmony_ci 143bf215546Sopenharmony_ci/* cmd stream functions: 144bf215546Sopenharmony_ci */ 145bf215546Sopenharmony_ci 146bf215546Sopenharmony_cistruct etna_cmd_stream { 147bf215546Sopenharmony_ci uint32_t *buffer; 148bf215546Sopenharmony_ci uint32_t offset; /* in 32-bit words */ 149bf215546Sopenharmony_ci uint32_t size; /* in 32-bit words */ 150bf215546Sopenharmony_ci}; 151bf215546Sopenharmony_ci 152bf215546Sopenharmony_cistruct etna_cmd_stream *etna_cmd_stream_new(struct etna_pipe *pipe, uint32_t size, 153bf215546Sopenharmony_ci void (*reset_notify)(struct etna_cmd_stream *stream, void *priv), 154bf215546Sopenharmony_ci void *priv); 155bf215546Sopenharmony_civoid etna_cmd_stream_del(struct etna_cmd_stream *stream); 156bf215546Sopenharmony_ciuint32_t etna_cmd_stream_timestamp(struct etna_cmd_stream *stream); 157bf215546Sopenharmony_civoid etna_cmd_stream_flush(struct etna_cmd_stream *stream, int in_fence_fd, 158bf215546Sopenharmony_ci int *out_fence_fd, bool is_noop); 159bf215546Sopenharmony_civoid etna_cmd_stream_force_flush(struct etna_cmd_stream *stream); 160bf215546Sopenharmony_ci 161bf215546Sopenharmony_cistatic inline uint32_t etna_cmd_stream_avail(struct etna_cmd_stream *stream) 162bf215546Sopenharmony_ci{ 163bf215546Sopenharmony_ci static const uint32_t END_CLEARANCE = 2; /* LINK op code */ 164bf215546Sopenharmony_ci 165bf215546Sopenharmony_ci return stream->size - stream->offset - END_CLEARANCE; 166bf215546Sopenharmony_ci} 167bf215546Sopenharmony_ci 168bf215546Sopenharmony_civoid etna_cmd_stream_realloc(struct etna_cmd_stream *stream, size_t n); 169bf215546Sopenharmony_ci 170bf215546Sopenharmony_cistatic inline void etna_cmd_stream_reserve(struct etna_cmd_stream *stream, size_t n) 171bf215546Sopenharmony_ci{ 172bf215546Sopenharmony_ci if (etna_cmd_stream_avail(stream) < n) 173bf215546Sopenharmony_ci etna_cmd_stream_realloc(stream, n); 174bf215546Sopenharmony_ci} 175bf215546Sopenharmony_ci 176bf215546Sopenharmony_cistatic inline void etna_cmd_stream_emit(struct etna_cmd_stream *stream, uint32_t data) 177bf215546Sopenharmony_ci{ 178bf215546Sopenharmony_ci stream->buffer[stream->offset++] = data; 179bf215546Sopenharmony_ci} 180bf215546Sopenharmony_ci 181bf215546Sopenharmony_cistatic inline uint32_t etna_cmd_stream_get(struct etna_cmd_stream *stream, uint32_t offset) 182bf215546Sopenharmony_ci{ 183bf215546Sopenharmony_ci return stream->buffer[offset]; 184bf215546Sopenharmony_ci} 185bf215546Sopenharmony_ci 186bf215546Sopenharmony_cistatic inline void etna_cmd_stream_set(struct etna_cmd_stream *stream, uint32_t offset, 187bf215546Sopenharmony_ci uint32_t data) 188bf215546Sopenharmony_ci{ 189bf215546Sopenharmony_ci stream->buffer[offset] = data; 190bf215546Sopenharmony_ci} 191bf215546Sopenharmony_ci 192bf215546Sopenharmony_cistatic inline uint32_t etna_cmd_stream_offset(struct etna_cmd_stream *stream) 193bf215546Sopenharmony_ci{ 194bf215546Sopenharmony_ci return stream->offset; 195bf215546Sopenharmony_ci} 196bf215546Sopenharmony_ci 197bf215546Sopenharmony_cistruct etna_reloc { 198bf215546Sopenharmony_ci struct etna_bo *bo; 199bf215546Sopenharmony_ci#define ETNA_RELOC_READ 0x0001 200bf215546Sopenharmony_ci#define ETNA_RELOC_WRITE 0x0002 201bf215546Sopenharmony_ci uint32_t flags; 202bf215546Sopenharmony_ci uint32_t offset; 203bf215546Sopenharmony_ci}; 204bf215546Sopenharmony_ci 205bf215546Sopenharmony_civoid etna_cmd_stream_reloc(struct etna_cmd_stream *stream, const struct etna_reloc *r); 206bf215546Sopenharmony_civoid etna_cmd_stream_ref_bo(struct etna_cmd_stream *stream, 207bf215546Sopenharmony_ci struct etna_bo *bo, uint32_t flags); 208bf215546Sopenharmony_ci 209bf215546Sopenharmony_ci/* performance monitoring functions: 210bf215546Sopenharmony_ci */ 211bf215546Sopenharmony_ci 212bf215546Sopenharmony_cistruct etna_perfmon *etna_perfmon_create(struct etna_pipe *pipe); 213bf215546Sopenharmony_civoid etna_perfmon_del(struct etna_perfmon *perfmon); 214bf215546Sopenharmony_cistruct etna_perfmon_domain *etna_perfmon_get_dom_by_name(struct etna_perfmon *pm, const char *name); 215bf215546Sopenharmony_cistruct etna_perfmon_signal *etna_perfmon_get_sig_by_name(struct etna_perfmon_domain *dom, const char *name); 216bf215546Sopenharmony_ci 217bf215546Sopenharmony_cistruct etna_perf { 218bf215546Sopenharmony_ci#define ETNA_PM_PROCESS_PRE 0x0001 219bf215546Sopenharmony_ci#define ETNA_PM_PROCESS_POST 0x0002 220bf215546Sopenharmony_ci uint32_t flags; 221bf215546Sopenharmony_ci uint32_t sequence; 222bf215546Sopenharmony_ci struct etna_perfmon_signal *signal; 223bf215546Sopenharmony_ci struct etna_bo *bo; 224bf215546Sopenharmony_ci uint32_t offset; 225bf215546Sopenharmony_ci}; 226bf215546Sopenharmony_ci 227bf215546Sopenharmony_civoid etna_cmd_stream_perf(struct etna_cmd_stream *stream, const struct etna_perf *p); 228bf215546Sopenharmony_ci 229bf215546Sopenharmony_ci#endif /* ETNAVIV_DRMIF_H_ */ 230