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