Debian Codegraph @

src/etnaviv/drm/etnaviv_gpu.c

raw
1 /*
2 * Copyright (C) 2015 Etnaviv Project
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *
23 * Authors:
24 * Christian Gmeiner <[email protected]>
25 */
26
27 #include "etnaviv_priv.h"
28 #include "etnaviv_drmif.h"
29
30 #include "hwdb/etna_hwdb.h"
31
32 #include "hw/common.xml.h"
33
34 /* Enum with indices for each of the feature words */
35 enum viv_features_word {
36 viv_chipFeatures = 0,
37 viv_chipMinorFeatures0 = 1,
38 viv_chipMinorFeatures1 = 2,
39 viv_chipMinorFeatures2 = 3,
40 viv_chipMinorFeatures3 = 4,
41 viv_chipMinorFeatures4 = 5,
42 viv_chipMinorFeatures5 = 6,
43 viv_chipMinorFeatures6 = 7,
44 viv_chipMinorFeatures7 = 8,
45 viv_chipMinorFeatures8 = 9,
46 viv_chipMinorFeatures9 = 10,
47 viv_chipMinorFeatures10 = 11,
48 viv_chipMinorFeatures11 = 12,
49 viv_chipMinorFeatures12 = 13,
50 VIV_FEATURES_WORD_COUNT /* Must be last */
51 };
52
53 #define VIV_FEATURE(word, feature) \
54 ((features[viv_ ## word] & (word ## _ ## feature)) != 0)
55
56 #define ETNA_FEATURE(word, feature) \
57 if (VIV_FEATURE(word, feature)) \
58 etna_core_enable_feature(&gpu->info, ETNA_FEATURE_## feature)
59
60 static void
61 query_features_from_kernel(struct etna_gpu *gpu)
62 {
63 uint32_t features[VIV_FEATURES_WORD_COUNT];
64
65 STATIC_ASSERT(ETNA_GPU_FEATURES_0 == 0x3);
66 STATIC_ASSERT(ETNA_GPU_FEATURES_1 == 0x4);
67 STATIC_ASSERT(ETNA_GPU_FEATURES_2 == 0x5);
68 STATIC_ASSERT(ETNA_GPU_FEATURES_3 == 0x6);
69 STATIC_ASSERT(ETNA_GPU_FEATURES_4 == 0x7);
70 STATIC_ASSERT(ETNA_GPU_FEATURES_5 == 0x8);
71 STATIC_ASSERT(ETNA_GPU_FEATURES_6 == 0x9);
72 STATIC_ASSERT(ETNA_GPU_FEATURES_7 == 0xa);
73 STATIC_ASSERT(ETNA_GPU_FEATURES_8 == 0xb);
74 STATIC_ASSERT(ETNA_GPU_FEATURES_9 == 0xc);
75 STATIC_ASSERT(ETNA_GPU_FEATURES_10 == 0xd);
76 STATIC_ASSERT(ETNA_GPU_FEATURES_11 == 0xe);
77 STATIC_ASSERT(ETNA_GPU_FEATURES_12 == 0xf);
78
79 for (unsigned i = ETNA_GPU_FEATURES_0; i <= ETNA_GPU_FEATURES_12; i++) {
80 uint64_t val = 0;
81
82 etna_gpu_get_param(gpu, i, &val);
83 features[i - ETNA_GPU_FEATURES_0] = val;
84 }
85
86 etna_core_enable_feature(&gpu->info, ETNA_FEATURE_CORE_GPU);
87
88 ETNA_FEATURE(chipFeatures, FAST_CLEAR);
89 ETNA_FEATURE(chipFeatures, PIPE_3D);
90 ETNA_FEATURE(chipFeatures, 32_BIT_INDICES);
91 ETNA_FEATURE(chipFeatures, MSAA);
92 ETNA_FEATURE(chipFeatures, DXT_TEXTURE_COMPRESSION);
93 ETNA_FEATURE(chipFeatures, ETC1_TEXTURE_COMPRESSION);
94 ETNA_FEATURE(chipFeatures, NO_EARLY_Z);
95 ETNA_FEATURE(chipFeatures, YUV420_TILER);
96
97 ETNA_FEATURE(chipMinorFeatures0, MC20);
98 ETNA_FEATURE(chipMinorFeatures0, RENDERTARGET_8K);
99 ETNA_FEATURE(chipMinorFeatures0, TEXTURE_8K);
100 ETNA_FEATURE(chipMinorFeatures0, HAS_SIGN_FLOOR_CEIL);
101 ETNA_FEATURE(chipMinorFeatures0, HAS_SQRT_TRIG);
102 ETNA_FEATURE(chipMinorFeatures0, 2BITPERTILE);
103 ETNA_FEATURE(chipMinorFeatures0, SUPER_TILED);
104
105 ETNA_FEATURE(chipMinorFeatures1, AUTO_DISABLE);
106 ETNA_FEATURE(chipMinorFeatures1, TEXTURE_HALIGN);
107 ETNA_FEATURE(chipMinorFeatures1, MMU_VERSION);
108 ETNA_FEATURE(chipMinorFeatures1, HALF_FLOAT);
109 ETNA_FEATURE(chipMinorFeatures1, WIDE_LINE);
110 ETNA_FEATURE(chipMinorFeatures1, HALTI0);
111 ETNA_FEATURE(chipMinorFeatures1, NON_POWER_OF_TWO);
112 ETNA_FEATURE(chipMinorFeatures1, LINEAR_TEXTURE_SUPPORT);
113
114 ETNA_FEATURE(chipMinorFeatures2, LINEAR_PE);
115 ETNA_FEATURE(chipMinorFeatures2, SUPERTILED_TEXTURE);
116 ETNA_FEATURE(chipMinorFeatures2, LOGIC_OP);
117 ETNA_FEATURE(chipMinorFeatures2, HALTI1);
118 ETNA_FEATURE(chipMinorFeatures2, SEAMLESS_CUBE_MAP);
119 ETNA_FEATURE(chipMinorFeatures2, LINE_LOOP);
120 ETNA_FEATURE(chipMinorFeatures2, TEXTURE_TILED_READ);
121 ETNA_FEATURE(chipMinorFeatures2, BUG_FIXES8);
122
123 ETNA_FEATURE(chipMinorFeatures3, PE_DITHER_FIX);
124 ETNA_FEATURE(chipMinorFeatures3, INSTRUCTION_CACHE);
125 ETNA_FEATURE(chipMinorFeatures3, HAS_FAST_TRANSCENDENTALS);
126
127 ETNA_FEATURE(chipMinorFeatures4, SMALL_MSAA);
128 ETNA_FEATURE(chipMinorFeatures4, BUG_FIXES18);
129 ETNA_FEATURE(chipMinorFeatures4, TEXTURE_ASTC);
130 ETNA_FEATURE(chipMinorFeatures4, SINGLE_BUFFER);
131 ETNA_FEATURE(chipMinorFeatures4, HALTI2);
132
133 ETNA_FEATURE(chipMinorFeatures5, BLT_ENGINE);
134 ETNA_FEATURE(chipMinorFeatures5, HALTI3);
135 ETNA_FEATURE(chipMinorFeatures5, HALTI4);
136 ETNA_FEATURE(chipMinorFeatures5, HALTI5);
137 ETNA_FEATURE(chipMinorFeatures5, RA_WRITE_DEPTH);
138
139 ETNA_FEATURE(chipMinorFeatures6, CACHE128B256BPERLINE);
140 ETNA_FEATURE(chipMinorFeatures6, NEW_GPIPE);
141 ETNA_FEATURE(chipMinorFeatures6, NO_ASTC);
142 ETNA_FEATURE(chipMinorFeatures6, V4_COMPRESSION);
143
144 ETNA_FEATURE(chipMinorFeatures7, BLT_64BPP_MASKED_CLEAR_FIX);
145 ETNA_FEATURE(chipMinorFeatures7, RS_NEW_BASEADDR);
146 ETNA_FEATURE(chipMinorFeatures7, PE_NO_ALPHA_TEST);
147
148 ETNA_FEATURE(chipMinorFeatures8, SH_NO_ONECONST_LIMIT);
149
150 ETNA_FEATURE(chipMinorFeatures10, DEC400);
151 ETNA_FEATURE(chipMinorFeatures10, WIDELINE_TRIANGLE_EMU);
152 }
153
154 static void
155 query_limits_from_kernel(struct etna_gpu *gpu)
156 {
157 struct etna_core_info *info = &gpu->info;
158 uint64_t val;
159
160 assert(etna_core_has_feature(info, ETNA_FEATURE_CORE_GPU));
161
162 etna_gpu_get_param(gpu, ETNA_GPU_INSTRUCTION_COUNT, &val);
163 info->gpu.max_instructions = val;
164
165 etna_gpu_get_param(gpu, ETNA_GPU_VERTEX_OUTPUT_BUFFER_SIZE, &val);
166 info->gpu.vertex_output_buffer_size = val;
167
168 etna_gpu_get_param(gpu, ETNA_GPU_VERTEX_CACHE_SIZE, &val);
169 info->gpu.vertex_cache_size = val;
170
171 etna_gpu_get_param(gpu, ETNA_GPU_SHADER_CORE_COUNT, &val);
172 info->gpu.shader_core_count = val;
173
174 etna_gpu_get_param(gpu, ETNA_GPU_STREAM_COUNT, &val);
175 info->gpu.stream_count = val;
176
177 etna_gpu_get_param(gpu, ETNA_GPU_REGISTER_MAX, &val);
178 info->gpu.max_registers = val;
179
180 etna_gpu_get_param(gpu, ETNA_GPU_PIXEL_PIPES, &val);
181 info->gpu.pixel_pipes = val;
182
183 etna_gpu_get_param(gpu, ETNA_GPU_NUM_CONSTANTS, &val);
184 info->gpu.num_constants = val;
185
186 etna_gpu_get_param(gpu, ETNA_GPU_NUM_VARYINGS, &val);
187 info->gpu.max_varyings = val;
188 }
189
190 static uint64_t get_param(struct etna_device *dev, uint32_t core, uint32_t param)
191 {
192 struct drm_etnaviv_param req = {
193 .pipe = core,
194 .param = param,
195 };
196 int ret;
197
198 ret = drmCommandWriteRead(dev->fd, DRM_ETNAVIV_GET_PARAM, &req, sizeof(req));
199 if (ret) {
200 if (ret != -ENXIO)
201 ERROR_MSG("get-param (%x) failed! %d (%s)", param, ret,
202 strerror(errno));
203 return 0;
204 }
205
206 return req.value;
207 }
208
209 static void determine_halti(struct etna_gpu *gpu)
210 {
211 struct etna_core_info *info = &gpu->info;
212
213 /* Figure out gross GPU architecture. See rnndb/common.xml for a specific
214 * description of the differences. */
215 if (etna_core_has_feature(info, ETNA_FEATURE_HALTI5))
216 info->halti = 5; /* New GC7000/GC8x00 */
217 else if (etna_core_has_feature(info, ETNA_FEATURE_HALTI4))
218 info->halti = 4; /* Old GC7000/GC7400 */
219 else if (etna_core_has_feature(info, ETNA_FEATURE_HALTI3))
220 info->halti = 3; /* None? */
221 else if (etna_core_has_feature(info, ETNA_FEATURE_HALTI2))
222 info->halti = 2; /* GC2500/GC3000/GC5000/GC6400 */
223 else if (etna_core_has_feature(info, ETNA_FEATURE_HALTI1))
224 info->halti = 1; /* GC900/GC4000/GC7000UL */
225 else if (etna_core_has_feature(info, ETNA_FEATURE_HALTI0))
226 info->halti = 0; /* GC880/GC2000/GC7000TM */
227 else
228 info->halti = -1; /* GC7000nanolite / pre-GC2000 except GC880 */
229 }
230
231 struct etna_gpu *etna_gpu_new(struct etna_device *dev, unsigned int core)
232 {
233 struct etna_gpu *gpu;
234 bool core_info_okay = false;
235
236 gpu = calloc(1, sizeof(*gpu));
237 if (!gpu) {
238 ERROR_MSG("allocation failed");
239 goto fail;
240 }
241
242 gpu->dev = dev;
243 gpu->core = core;
244
245 gpu->info.model = get_param(dev, core, ETNAVIV_PARAM_GPU_MODEL);
246 if (!gpu->info.model)
247 goto fail;
248
249 gpu->info.revision = get_param(dev, core, ETNAVIV_PARAM_GPU_REVISION);
250
251 DEBUG_MSG(" GPU model: 0x%x (rev %x)", gpu->info.model, gpu->info.revision);
252
253 if (dev->drm_version >= ETNA_DRM_VERSION(1, 4)) {
254 gpu->info.product_id = get_param(dev, core, ETNAVIV_PARAM_GPU_PRODUCT_ID);
255 gpu->info.customer_id = get_param(dev, core, ETNAVIV_PARAM_GPU_CUSTOMER_ID);
256 gpu->info.eco_id = get_param(dev, core, ETNAVIV_PARAM_GPU_ECO_ID);
257
258 core_info_okay = etna_query_feature_db(&gpu->info);
259 DEBUG_MSG(" Found entry in hwdb: %u\n", core_info_okay);
260 }
261
262 if (!core_info_okay) {
263 query_features_from_kernel(gpu);
264 query_limits_from_kernel(gpu);
265
266 /* GC3000 with the instruction cache feature has a incorrect instruction
267 * limit encoded in HW (HWDB has the correct number). Fix this up so
268 * other parts of the stack don't have to worry about this.
269 */
270 if (etna_core_has_feature(&gpu->info, ETNA_FEATURE_INSTRUCTION_CACHE) &&
271 gpu->info.gpu.max_instructions < 512)
272 gpu->info.gpu.max_instructions = 512;
273 }
274
275 determine_halti(gpu);
276
277 return gpu;
278 fail:
279 if (gpu)
280 etna_gpu_del(gpu);
281
282 return NULL;
283 }
284
285 void etna_gpu_del(struct etna_gpu *gpu)
286 {
287 free(gpu);
288 }
289
290 int etna_gpu_get_param(struct etna_gpu *gpu, enum etna_param_id param,
291 uint64_t *value)
292 {
293 struct etna_device *dev = gpu->dev;
294 unsigned int core = gpu->core;
295
296 switch(param) {
297 case ETNA_GPU_MODEL:
298 *value = gpu->info.model;
299 return 0;
300 case ETNA_GPU_REVISION:
301 *value = gpu->info.revision;
302 return 0;
303 case ETNA_GPU_FEATURES_0:
304 *value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_0);
305 return 0;
306 case ETNA_GPU_FEATURES_1:
307 *value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_1);
308 return 0;
309 case ETNA_GPU_FEATURES_2:
310 *value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_2);
311 return 0;
312 case ETNA_GPU_FEATURES_3:
313 *value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_3);
314 return 0;
315 case ETNA_GPU_FEATURES_4:
316 *value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_4);
317 return 0;
318 case ETNA_GPU_FEATURES_5:
319 *value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_5);
320 return 0;
321 case ETNA_GPU_FEATURES_6:
322 *value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_6);
323 return 0;
324 case ETNA_GPU_FEATURES_7:
325 *value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_7);
326 return 0;
327 case ETNA_GPU_FEATURES_8:
328 *value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_8);
329 return 0;
330 case ETNA_GPU_FEATURES_9:
331 *value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_9);
332 return 0;
333 case ETNA_GPU_FEATURES_10:
334 *value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_10);
335 return 0;
336 case ETNA_GPU_FEATURES_11:
337 *value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_11);
338 return 0;
339 case ETNA_GPU_FEATURES_12:
340 *value = get_param(dev, core, ETNAVIV_PARAM_GPU_FEATURES_12);
341 return 0;
342 case ETNA_GPU_STREAM_COUNT:
343 *value = get_param(dev, core, ETNA_GPU_STREAM_COUNT);
344 return 0;
345 case ETNA_GPU_REGISTER_MAX:
346 *value = get_param(dev, core, ETNA_GPU_REGISTER_MAX);
347 return 0;
348 case ETNA_GPU_THREAD_COUNT:
349 *value = get_param(dev, core, ETNA_GPU_THREAD_COUNT);
350 return 0;
351 case ETNA_GPU_VERTEX_CACHE_SIZE:
352 *value = get_param(dev, core, ETNA_GPU_VERTEX_CACHE_SIZE);
353 return 0;
354 case ETNA_GPU_SHADER_CORE_COUNT:
355 *value = get_param(dev, core, ETNA_GPU_SHADER_CORE_COUNT);
356 return 0;
357 case ETNA_GPU_PIXEL_PIPES:
358 *value = get_param(dev, core, ETNA_GPU_PIXEL_PIPES);
359 return 0;
360 case ETNA_GPU_VERTEX_OUTPUT_BUFFER_SIZE:
361 *value = get_param(dev, core, ETNA_GPU_VERTEX_OUTPUT_BUFFER_SIZE);
362 return 0;
363 case ETNA_GPU_BUFFER_SIZE:
364 *value = get_param(dev, core, ETNA_GPU_BUFFER_SIZE);
365 return 0;
366 case ETNA_GPU_INSTRUCTION_COUNT:
367 *value = get_param(dev, core, ETNA_GPU_INSTRUCTION_COUNT);
368 return 0;
369 case ETNA_GPU_NUM_CONSTANTS:
370 *value = get_param(dev, core, ETNA_GPU_NUM_CONSTANTS);
371 return 0;
372 case ETNA_GPU_NUM_VARYINGS:
373 *value = get_param(dev, core, ETNA_GPU_NUM_VARYINGS);
374 return 0;
375 case ETNA_SOFTPIN_START_ADDR:
376 *value = get_param(dev, core, ETNA_SOFTPIN_START_ADDR);
377 return 0;
378 case ETNA_GPU_PRODUCT_ID:
379 *value = gpu->info.product_id;
380 return 0;
381 case ETNA_GPU_CUSTOMER_ID:
382 *value = gpu->info.customer_id;
383 return 0;
384 case ETNA_GPU_ECO_ID:
385 *value = gpu->info.eco_id;
386 return 0;
387
388 default:
389 ERROR_MSG("invalid param id: %d", param);
390 return -1;
391 }
392
393 return 0;
394 }
395
396 struct etna_core_info *etna_gpu_get_core_info(struct etna_gpu *gpu)
397 {
398 return &gpu->info;
399 }