f1f9e8a51f9fbdea891de8c0ff7d3d96f8f063bd
[mesa.git] / src / etnaviv / drm-shim / etnaviv_noop.c
1 /*
2 * Copyright (c) 2019 Etnaviv Project
3 * Copyright (c) 2019 Zodiac Inflight Innovations
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sub license,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
14 * of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Christian Gmeiner <christian.gmeiner@gmail.com>
26 */
27
28 #include <stdio.h>
29 #include <sys/ioctl.h>
30 #include "drm-uapi/etnaviv_drm.h"
31 #include "drm-shim/drm_shim.h"
32 #include "util/u_debug.h"
33
34 struct etna_shim_gpu
35 {
36 const char *name;
37 const uint64_t *reg_map;
38 };
39
40 static const struct etna_shim_gpu gpus[] = {
41 {
42 .name = "GC2000",
43 .reg_map = (const uint64_t[]){
44 [ETNAVIV_PARAM_GPU_MODEL] = 0x2000,
45 [ETNAVIV_PARAM_GPU_REVISION] = 0x5108,
46 [ETNAVIV_PARAM_GPU_FEATURES_0] = 0xe0296cad,
47 [ETNAVIV_PARAM_GPU_FEATURES_1] = 0xc9799eff,
48 [ETNAVIV_PARAM_GPU_FEATURES_2] = 0x2efbf2d9,
49 [ETNAVIV_PARAM_GPU_FEATURES_3] = 0x0,
50 [ETNAVIV_PARAM_GPU_FEATURES_4] = 0x0,
51 [ETNAVIV_PARAM_GPU_FEATURES_5] = 0x0,
52 [ETNAVIV_PARAM_GPU_FEATURES_6] = 0x0,
53 [ETNAVIV_PARAM_GPU_FEATURES_7] = 0x0,
54 [ETNAVIV_PARAM_GPU_STREAM_COUNT] = 0x8,
55 [ETNAVIV_PARAM_GPU_REGISTER_MAX] = 0x40,
56 [ETNAVIV_PARAM_GPU_THREAD_COUNT] = 0x400,
57 [ETNAVIV_PARAM_GPU_VERTEX_CACHE_SIZE] = 0x10,
58 [ETNAVIV_PARAM_GPU_SHADER_CORE_COUNT] = 0x4,
59 [ETNAVIV_PARAM_GPU_PIXEL_PIPES] = 0x2,
60 [ETNAVIV_PARAM_GPU_VERTEX_OUTPUT_BUFFER_SIZE] = 0x200,
61 [ETNAVIV_PARAM_GPU_BUFFER_SIZE] = 0x0,
62 [ETNAVIV_PARAM_GPU_INSTRUCTION_COUNT] = 0x200,
63 [ETNAVIV_PARAM_GPU_NUM_CONSTANTS] = 0xa8,
64 [ETNAVIV_PARAM_GPU_NUM_VARYINGS] = 0xb,
65 [ETNAVIV_PARAM_SOFTPIN_START_ADDR] = ~0ULL,
66 }
67 },
68 {
69 .name = "GC3000",
70 .reg_map = (const uint64_t[]){
71 [ETNAVIV_PARAM_GPU_MODEL] = 0x3000,
72 [ETNAVIV_PARAM_GPU_REVISION] = 0x5450,
73 [ETNAVIV_PARAM_GPU_FEATURES_0] = 0xe0287cad,
74 [ETNAVIV_PARAM_GPU_FEATURES_1] = 0xc9799efb,
75 [ETNAVIV_PARAM_GPU_FEATURES_2] = 0xfefbfadb,
76 [ETNAVIV_PARAM_GPU_FEATURES_3] = 0xeb9d4bbf,
77 [ETNAVIV_PARAM_GPU_FEATURES_4] = 0xedffdced,
78 [ETNAVIV_PARAM_GPU_FEATURES_5] = 0x930d2f47,
79 [ETNAVIV_PARAM_GPU_FEATURES_6] = 0x10000133,
80 [ETNAVIV_PARAM_GPU_FEATURES_7] = 0x0,
81 [ETNAVIV_PARAM_GPU_STREAM_COUNT] = 0x10,
82 [ETNAVIV_PARAM_GPU_REGISTER_MAX] = 0x40,
83 [ETNAVIV_PARAM_GPU_THREAD_COUNT] = 0x400,
84 [ETNAVIV_PARAM_GPU_VERTEX_CACHE_SIZE] = 0x10,
85 [ETNAVIV_PARAM_GPU_SHADER_CORE_COUNT] = 0x4,
86 [ETNAVIV_PARAM_GPU_PIXEL_PIPES] = 0x2,
87 [ETNAVIV_PARAM_GPU_VERTEX_OUTPUT_BUFFER_SIZE] = 0x400,
88 [ETNAVIV_PARAM_GPU_BUFFER_SIZE] = 0x0,
89 [ETNAVIV_PARAM_GPU_INSTRUCTION_COUNT] = 0x100,
90 [ETNAVIV_PARAM_GPU_NUM_CONSTANTS] = 0x140,
91 [ETNAVIV_PARAM_GPU_NUM_VARYINGS] = 0x10,
92 [ETNAVIV_PARAM_SOFTPIN_START_ADDR] = ~0ULL,
93 }
94 },
95 {
96 .name = "GC7000L",
97 .reg_map = (const uint64_t[]){
98 [ETNAVIV_PARAM_GPU_MODEL] = 0x7000,
99 [ETNAVIV_PARAM_GPU_REVISION] = 0x6214,
100 [ETNAVIV_PARAM_GPU_FEATURES_0] = 0xe0287cad,
101 [ETNAVIV_PARAM_GPU_FEATURES_1] = 0xc1799eff,
102 [ETNAVIV_PARAM_GPU_FEATURES_2] = 0xfefbfad9,
103 [ETNAVIV_PARAM_GPU_FEATURES_3] = 0xeb9d4fbf,
104 [ETNAVIV_PARAM_GPU_FEATURES_4] = 0xedfffced,
105 [ETNAVIV_PARAM_GPU_FEATURES_5] = 0xdb0dafc7,
106 [ETNAVIV_PARAM_GPU_FEATURES_6] = 0xbb5ac333,
107 [ETNAVIV_PARAM_GPU_FEATURES_7] = 0xfc8ee200,
108 [ETNAVIV_PARAM_GPU_STREAM_COUNT] = 0x10,
109 [ETNAVIV_PARAM_GPU_REGISTER_MAX] = 0x40,
110 [ETNAVIV_PARAM_GPU_THREAD_COUNT] = 0x400,
111 [ETNAVIV_PARAM_GPU_VERTEX_CACHE_SIZE] = 0x10,
112 [ETNAVIV_PARAM_GPU_SHADER_CORE_COUNT] = 0x4,
113 [ETNAVIV_PARAM_GPU_PIXEL_PIPES] = 0x2,
114 [ETNAVIV_PARAM_GPU_VERTEX_OUTPUT_BUFFER_SIZE] = 0x400,
115 [ETNAVIV_PARAM_GPU_BUFFER_SIZE] = 0x0,
116 [ETNAVIV_PARAM_GPU_INSTRUCTION_COUNT] = 0x200,
117 [ETNAVIV_PARAM_GPU_NUM_CONSTANTS] = 0x140,
118 [ETNAVIV_PARAM_GPU_NUM_VARYINGS] = 0x10,
119 [ETNAVIV_PARAM_SOFTPIN_START_ADDR] = 0x00400000,
120 }
121 }
122 };
123
124 static const struct etna_shim_gpu *shim_gpu;
125
126 static int
127 etnaviv_ioctl_noop(int fd, unsigned long request, void *arg)
128 {
129 return 0;
130 }
131
132 static int
133 etnaviv_ioctl_gem_new(int fd, unsigned long request, void *arg)
134 {
135 struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);
136 struct drm_etnaviv_gem_new *create = arg;
137 struct shim_bo *bo = calloc(1, sizeof(*bo));
138
139 drm_shim_bo_init(bo, create->size);
140 create->handle = drm_shim_bo_get_handle(shim_fd, bo);
141 drm_shim_bo_put(bo);
142
143 return 0;
144 }
145
146 static int
147 etnaviv_ioctl_gem_info(int fd, unsigned long request, void *arg)
148 {
149 struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);
150 struct drm_etnaviv_gem_info *args = arg;
151 struct shim_bo *bo = drm_shim_bo_lookup(shim_fd, args->handle);
152
153 args->offset = drm_shim_bo_get_mmap_offset(shim_fd, bo);
154 drm_shim_bo_put(bo);
155
156 return 0;
157 }
158
159 static int
160 etnaviv_ioctl_get_param(int fd, unsigned long request, void *arg)
161 {
162 struct drm_etnaviv_param *gp = arg;
163
164 if (gp->param > ETNAVIV_PARAM_SOFTPIN_START_ADDR) {
165 fprintf(stderr, "Unknown DRM_IOCTL_ETNAVIV_GET_PARAM %d\n", gp->param);
166 return -1;
167 }
168
169 gp->value = shim_gpu->reg_map[gp->param];
170
171 return 0;
172 }
173
174 static ioctl_fn_t driver_ioctls[] = {
175 [DRM_ETNAVIV_GET_PARAM] = etnaviv_ioctl_get_param,
176 [DRM_ETNAVIV_GEM_NEW] = etnaviv_ioctl_gem_new,
177 [DRM_ETNAVIV_GEM_INFO] = etnaviv_ioctl_gem_info,
178 [DRM_ETNAVIV_GEM_CPU_PREP] = etnaviv_ioctl_noop,
179 [DRM_ETNAVIV_GEM_CPU_FINI] = etnaviv_ioctl_noop,
180 [DRM_ETNAVIV_GEM_SUBMIT] = etnaviv_ioctl_noop,
181 [DRM_ETNAVIV_WAIT_FENCE] = etnaviv_ioctl_noop,
182 [DRM_ETNAVIV_GEM_USERPTR] = etnaviv_ioctl_noop,
183 [DRM_ETNAVIV_GEM_WAIT] = etnaviv_ioctl_noop,
184 [DRM_ETNAVIV_PM_QUERY_DOM] = etnaviv_ioctl_noop,
185 [DRM_ETNAVIV_PM_QUERY_SIG] = etnaviv_ioctl_noop,
186 };
187
188 void
189 drm_shim_driver_init(void)
190 {
191 shim_device.driver_name = "etnaviv";
192 shim_device.driver_ioctls = driver_ioctls;
193 shim_device.driver_ioctl_count = ARRAY_SIZE(driver_ioctls);
194
195 /* etnaviv uses the DRM version to expose features, instead of getparam. */
196 shim_device.version_major = 1;
197 shim_device.version_minor = 1;
198 shim_device.version_patchlevel = 0;
199
200 drm_shim_override_file("DRIVER=etnaviv\n"
201 "MODALIAS=platform:etnaviv\n",
202 "/sys/dev/char/%d:%d/device/uevent",
203 DRM_MAJOR, render_node_minor);
204
205 /* decide what GPU to emulate */
206 const char *gpu = debug_get_option("ETNA_SHIM_GPU", "GC2000");
207
208 for (unsigned i = 0; i < ARRAY_SIZE(gpus); i++) {
209 if (strncasecmp(gpu, gpus[i].name, strlen(gpus[i].name)) == 0) {
210 shim_gpu = &gpus[i];
211 break;
212 }
213 }
214
215 /* NOTE: keep keep default value and fallback index in sync */
216 if (!shim_gpu)
217 shim_gpu = &gpus[0];
218
219 fprintf(stderr, "Using %s as shim gpu\n", shim_gpu->name);
220 }