Path: blob/21.2-virgl/src/etnaviv/drm/etnaviv_drmif.h
4565 views
/*1* Copyright (C) 2014-2015 Etnaviv Project2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20* SOFTWARE.21*22* Authors:23* Christian Gmeiner <[email protected]>24*/2526#ifndef ETNAVIV_DRMIF_H_27#define ETNAVIV_DRMIF_H_2829#include <xf86drm.h>30#include <stdbool.h>31#include <stdint.h>3233struct etna_bo;34struct etna_pipe;35struct etna_gpu;36struct etna_device;37struct etna_cmd_stream;38struct etna_perfmon;39struct etna_perfmon_domain;40struct etna_perfmon_signal;4142enum etna_pipe_id {43ETNA_PIPE_3D = 0,44ETNA_PIPE_2D = 1,45ETNA_PIPE_VG = 2,46ETNA_PIPE_MAX47};4849enum etna_param_id {50ETNA_GPU_MODEL = 0x1,51ETNA_GPU_REVISION = 0x2,52ETNA_GPU_FEATURES_0 = 0x3,53ETNA_GPU_FEATURES_1 = 0x4,54ETNA_GPU_FEATURES_2 = 0x5,55ETNA_GPU_FEATURES_3 = 0x6,56ETNA_GPU_FEATURES_4 = 0x7,57ETNA_GPU_FEATURES_5 = 0x8,58ETNA_GPU_FEATURES_6 = 0x9,59ETNA_GPU_FEATURES_7 = 0xa,60ETNA_GPU_FEATURES_8 = 0xb,6162ETNA_GPU_STREAM_COUNT = 0x10,63ETNA_GPU_REGISTER_MAX = 0x11,64ETNA_GPU_THREAD_COUNT = 0x12,65ETNA_GPU_VERTEX_CACHE_SIZE = 0x13,66ETNA_GPU_SHADER_CORE_COUNT = 0x14,67ETNA_GPU_PIXEL_PIPES = 0x15,68ETNA_GPU_VERTEX_OUTPUT_BUFFER_SIZE = 0x16,69ETNA_GPU_BUFFER_SIZE = 0x17,70ETNA_GPU_INSTRUCTION_COUNT = 0x18,71ETNA_GPU_NUM_CONSTANTS = 0x19,72ETNA_GPU_NUM_VARYINGS = 0x1a73};7475/* bo flags: */76#define DRM_ETNA_GEM_CACHE_CACHED 0x0001000077#define DRM_ETNA_GEM_CACHE_WC 0x0002000078#define DRM_ETNA_GEM_CACHE_UNCACHED 0x0004000079#define DRM_ETNA_GEM_CACHE_MASK 0x000f000080/* map flags */81#define DRM_ETNA_GEM_FORCE_MMU 0x001000008283/* bo access flags: (keep aligned to ETNA_PREP_x) */84#define DRM_ETNA_PREP_READ 0x0185#define DRM_ETNA_PREP_WRITE 0x0286#define DRM_ETNA_PREP_NOSYNC 0x048788/* device functions:89*/9091struct etna_device *etna_device_new(int fd);92struct etna_device *etna_device_new_dup(int fd);93struct etna_device *etna_device_ref(struct etna_device *dev);94void etna_device_del(struct etna_device *dev);95int etna_device_fd(struct etna_device *dev);96bool etnaviv_device_softpin_capable(struct etna_device *dev);9798/* gpu functions:99*/100101struct etna_gpu *etna_gpu_new(struct etna_device *dev, unsigned int core);102void etna_gpu_del(struct etna_gpu *gpu);103int etna_gpu_get_param(struct etna_gpu *gpu, enum etna_param_id param,104uint64_t *value);105106107/* pipe functions:108*/109110struct etna_pipe *etna_pipe_new(struct etna_gpu *gpu, enum etna_pipe_id id);111void etna_pipe_del(struct etna_pipe *pipe);112int etna_pipe_wait_ns(struct etna_pipe *pipe, uint32_t timestamp, uint64_t ns);113114115/* buffer-object functions:116*/117118struct etna_bo *etna_bo_new(struct etna_device *dev,119uint32_t size, uint32_t flags);120struct etna_bo *etna_bo_from_name(struct etna_device *dev, uint32_t name);121struct etna_bo *etna_bo_from_dmabuf(struct etna_device *dev, int fd);122struct etna_bo *etna_bo_ref(struct etna_bo *bo);123void etna_bo_del(struct etna_bo *bo);124int etna_bo_get_name(struct etna_bo *bo, uint32_t *name);125uint32_t etna_bo_handle(struct etna_bo *bo);126int etna_bo_dmabuf(struct etna_bo *bo);127uint32_t etna_bo_size(struct etna_bo *bo);128uint32_t etna_bo_gpu_va(struct etna_bo *bo);129void * etna_bo_map(struct etna_bo *bo);130int etna_bo_cpu_prep(struct etna_bo *bo, uint32_t op);131void etna_bo_cpu_fini(struct etna_bo *bo);132133134/* cmd stream functions:135*/136137struct etna_cmd_stream {138uint32_t *buffer;139uint32_t offset; /* in 32-bit words */140uint32_t size; /* in 32-bit words */141};142143struct etna_cmd_stream *etna_cmd_stream_new(struct etna_pipe *pipe, uint32_t size,144void (*reset_notify)(struct etna_cmd_stream *stream, void *priv),145void *priv);146void etna_cmd_stream_del(struct etna_cmd_stream *stream);147uint32_t etna_cmd_stream_timestamp(struct etna_cmd_stream *stream);148void etna_cmd_stream_flush(struct etna_cmd_stream *stream, int in_fence_fd,149int *out_fence_fd);150void etna_cmd_stream_force_flush(struct etna_cmd_stream *stream);151152static inline uint32_t etna_cmd_stream_avail(struct etna_cmd_stream *stream)153{154static const uint32_t END_CLEARANCE = 2; /* LINK op code */155156return stream->size - stream->offset - END_CLEARANCE;157}158159void etna_cmd_stream_realloc(struct etna_cmd_stream *stream, size_t n);160161static inline void etna_cmd_stream_reserve(struct etna_cmd_stream *stream, size_t n)162{163if (etna_cmd_stream_avail(stream) < n)164etna_cmd_stream_realloc(stream, n);165}166167static inline void etna_cmd_stream_emit(struct etna_cmd_stream *stream, uint32_t data)168{169stream->buffer[stream->offset++] = data;170}171172static inline uint32_t etna_cmd_stream_get(struct etna_cmd_stream *stream, uint32_t offset)173{174return stream->buffer[offset];175}176177static inline void etna_cmd_stream_set(struct etna_cmd_stream *stream, uint32_t offset,178uint32_t data)179{180stream->buffer[offset] = data;181}182183static inline uint32_t etna_cmd_stream_offset(struct etna_cmd_stream *stream)184{185return stream->offset;186}187188struct etna_reloc {189struct etna_bo *bo;190#define ETNA_RELOC_READ 0x0001191#define ETNA_RELOC_WRITE 0x0002192uint32_t flags;193uint32_t offset;194};195196void etna_cmd_stream_reloc(struct etna_cmd_stream *stream, const struct etna_reloc *r);197void etna_cmd_stream_ref_bo(struct etna_cmd_stream *stream,198struct etna_bo *bo, uint32_t flags);199200/* performance monitoring functions:201*/202203struct etna_perfmon *etna_perfmon_create(struct etna_pipe *pipe);204void etna_perfmon_del(struct etna_perfmon *perfmon);205struct etna_perfmon_domain *etna_perfmon_get_dom_by_name(struct etna_perfmon *pm, const char *name);206struct etna_perfmon_signal *etna_perfmon_get_sig_by_name(struct etna_perfmon_domain *dom, const char *name);207208struct etna_perf {209#define ETNA_PM_PROCESS_PRE 0x0001210#define ETNA_PM_PROCESS_POST 0x0002211uint32_t flags;212uint32_t sequence;213struct etna_perfmon_signal *signal;214struct etna_bo *bo;215uint32_t offset;216};217218void etna_cmd_stream_perf(struct etna_cmd_stream *stream, const struct etna_perf *p);219220#endif /* ETNAVIV_DRMIF_H_ */221222223