Added few more stubs so that control reaches to DestroyDevice().
[mesa.git] / src / intel / dev / gen_device_info.c
1 /*
2 * Copyright © 2013 Intel Corporation
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
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include <assert.h>
25 #include <stdbool.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <unistd.h>
30 #include "gen_device_info.h"
31 #include "compiler/shader_enums.h"
32 #include "intel/common/gen_gem.h"
33 #include "util/bitscan.h"
34 #include "util/macros.h"
35
36 #include "drm-uapi/i915_drm.h"
37
38 static const struct {
39 const char *name;
40 int pci_id;
41 } name_map[] = {
42 { "brw", 0x2a02 },
43 { "g4x", 0x2a42 },
44 { "ilk", 0x0042 },
45 { "snb", 0x0126 },
46 { "ivb", 0x016a },
47 { "hsw", 0x0d2e },
48 { "byt", 0x0f33 },
49 { "bdw", 0x162e },
50 { "chv", 0x22B3 },
51 { "skl", 0x1912 },
52 { "bxt", 0x5A85 },
53 { "kbl", 0x5912 },
54 { "aml", 0x591C },
55 { "glk", 0x3185 },
56 { "cfl", 0x3E9B },
57 { "whl", 0x3EA1 },
58 { "cml", 0x9b41 },
59 { "cnl", 0x5a52 },
60 { "icl", 0x8a52 },
61 { "ehl", 0x4500 },
62 { "jsl", 0x4E71 },
63 { "tgl", 0x9a49 },
64 { "rkl", 0x4c8a },
65 { "dg1", 0x4905 },
66 };
67
68 /**
69 * Get the PCI ID for the device name.
70 *
71 * Returns -1 if the device is not known.
72 */
73 int
74 gen_device_name_to_pci_device_id(const char *name)
75 {
76 for (unsigned i = 0; i < ARRAY_SIZE(name_map); i++) {
77 if (!strcmp(name_map[i].name, name))
78 return name_map[i].pci_id;
79 }
80
81 return -1;
82 }
83
84 static const struct gen_device_info gen_device_info_i965 = {
85 .gen = 4,
86 .has_negative_rhw_bug = true,
87 .num_slices = 1,
88 .num_subslices = { 1, },
89 .num_eu_per_subslice = 8,
90 .num_thread_per_eu = 4,
91 .max_vs_threads = 16,
92 .max_gs_threads = 2,
93 .max_wm_threads = 8 * 4,
94 .urb = {
95 .size = 256,
96 },
97 .timestamp_frequency = 12500000,
98 .simulator_id = -1,
99 };
100
101 static const struct gen_device_info gen_device_info_g4x = {
102 .gen = 4,
103 .has_pln = true,
104 .has_compr4 = true,
105 .has_surface_tile_offset = true,
106 .is_g4x = true,
107 .num_slices = 1,
108 .num_subslices = { 1, },
109 .num_eu_per_subslice = 10,
110 .num_thread_per_eu = 5,
111 .max_vs_threads = 32,
112 .max_gs_threads = 2,
113 .max_wm_threads = 10 * 5,
114 .urb = {
115 .size = 384,
116 },
117 .timestamp_frequency = 12500000,
118 .simulator_id = -1,
119 };
120
121 static const struct gen_device_info gen_device_info_ilk = {
122 .gen = 5,
123 .has_pln = true,
124 .has_compr4 = true,
125 .has_surface_tile_offset = true,
126 .num_slices = 1,
127 .num_subslices = { 1, },
128 .num_eu_per_subslice = 12,
129 .num_thread_per_eu = 6,
130 .max_vs_threads = 72,
131 .max_gs_threads = 32,
132 .max_wm_threads = 12 * 6,
133 .urb = {
134 .size = 1024,
135 },
136 .timestamp_frequency = 12500000,
137 .simulator_id = -1,
138 };
139
140 static const struct gen_device_info gen_device_info_snb_gt1 = {
141 .gen = 6,
142 .gt = 1,
143 .has_hiz_and_separate_stencil = true,
144 .has_llc = true,
145 .has_pln = true,
146 .has_surface_tile_offset = true,
147 .needs_unlit_centroid_workaround = true,
148 .num_slices = 1,
149 .num_subslices = { 1, },
150 .num_eu_per_subslice = 6,
151 .num_thread_per_eu = 6, /* Not confirmed */
152 .max_vs_threads = 24,
153 .max_gs_threads = 21, /* conservative; 24 if rendering disabled. */
154 .max_wm_threads = 40,
155 .urb = {
156 .size = 32,
157 .min_entries = {
158 [MESA_SHADER_VERTEX] = 24,
159 },
160 .max_entries = {
161 [MESA_SHADER_VERTEX] = 256,
162 [MESA_SHADER_GEOMETRY] = 256,
163 },
164 },
165 .timestamp_frequency = 12500000,
166 .simulator_id = -1,
167 };
168
169 static const struct gen_device_info gen_device_info_snb_gt2 = {
170 .gen = 6,
171 .gt = 2,
172 .has_hiz_and_separate_stencil = true,
173 .has_llc = true,
174 .has_pln = true,
175 .has_surface_tile_offset = true,
176 .needs_unlit_centroid_workaround = true,
177 .num_slices = 1,
178 .num_subslices = { 1, },
179 .num_eu_per_subslice = 12,
180 .num_thread_per_eu = 6, /* Not confirmed */
181 .max_vs_threads = 60,
182 .max_gs_threads = 60,
183 .max_wm_threads = 80,
184 .urb = {
185 .size = 64,
186 .min_entries = {
187 [MESA_SHADER_VERTEX] = 24,
188 },
189 .max_entries = {
190 [MESA_SHADER_VERTEX] = 256,
191 [MESA_SHADER_GEOMETRY] = 256,
192 },
193 },
194 .timestamp_frequency = 12500000,
195 .simulator_id = -1,
196 };
197
198 #define GEN7_FEATURES \
199 .gen = 7, \
200 .has_hiz_and_separate_stencil = true, \
201 .must_use_separate_stencil = true, \
202 .has_llc = true, \
203 .has_pln = true, \
204 .has_64bit_float = true, \
205 .has_surface_tile_offset = true, \
206 .timestamp_frequency = 12500000
207
208 static const struct gen_device_info gen_device_info_ivb_gt1 = {
209 GEN7_FEATURES, .is_ivybridge = true, .gt = 1,
210 .num_slices = 1,
211 .num_subslices = { 1, },
212 .num_eu_per_subslice = 6,
213 .num_thread_per_eu = 6,
214 .l3_banks = 2,
215 .max_vs_threads = 36,
216 .max_tcs_threads = 36,
217 .max_tes_threads = 36,
218 .max_gs_threads = 36,
219 .max_wm_threads = 48,
220 .max_cs_threads = 36,
221 .urb = {
222 .min_entries = {
223 [MESA_SHADER_VERTEX] = 32,
224 [MESA_SHADER_TESS_EVAL] = 10,
225 },
226 .max_entries = {
227 [MESA_SHADER_VERTEX] = 512,
228 [MESA_SHADER_TESS_CTRL] = 32,
229 [MESA_SHADER_TESS_EVAL] = 288,
230 [MESA_SHADER_GEOMETRY] = 192,
231 },
232 },
233 .simulator_id = 7,
234 };
235
236 static const struct gen_device_info gen_device_info_ivb_gt2 = {
237 GEN7_FEATURES, .is_ivybridge = true, .gt = 2,
238 .num_slices = 1,
239 .num_subslices = { 1, },
240 .num_eu_per_subslice = 12,
241 .num_thread_per_eu = 8, /* Not sure why this isn't a multiple of
242 * @max_wm_threads ... */
243 .l3_banks = 4,
244 .max_vs_threads = 128,
245 .max_tcs_threads = 128,
246 .max_tes_threads = 128,
247 .max_gs_threads = 128,
248 .max_wm_threads = 172,
249 .max_cs_threads = 64,
250 .urb = {
251 .min_entries = {
252 [MESA_SHADER_VERTEX] = 32,
253 [MESA_SHADER_TESS_EVAL] = 10,
254 },
255 .max_entries = {
256 [MESA_SHADER_VERTEX] = 704,
257 [MESA_SHADER_TESS_CTRL] = 64,
258 [MESA_SHADER_TESS_EVAL] = 448,
259 [MESA_SHADER_GEOMETRY] = 320,
260 },
261 },
262 .simulator_id = 7,
263 };
264
265 static const struct gen_device_info gen_device_info_byt = {
266 GEN7_FEATURES, .is_baytrail = true, .gt = 1,
267 .num_slices = 1,
268 .num_subslices = { 1, },
269 .num_eu_per_subslice = 4,
270 .num_thread_per_eu = 8,
271 .l3_banks = 1,
272 .has_llc = false,
273 .max_vs_threads = 36,
274 .max_tcs_threads = 36,
275 .max_tes_threads = 36,
276 .max_gs_threads = 36,
277 .max_wm_threads = 48,
278 .max_cs_threads = 32,
279 .urb = {
280 .min_entries = {
281 [MESA_SHADER_VERTEX] = 32,
282 [MESA_SHADER_TESS_EVAL] = 10,
283 },
284 .max_entries = {
285 [MESA_SHADER_VERTEX] = 512,
286 [MESA_SHADER_TESS_CTRL] = 32,
287 [MESA_SHADER_TESS_EVAL] = 288,
288 [MESA_SHADER_GEOMETRY] = 192,
289 },
290 },
291 .simulator_id = 10,
292 };
293
294 #define HSW_FEATURES \
295 GEN7_FEATURES, \
296 .is_haswell = true, \
297 .supports_simd16_3src = true, \
298 .has_resource_streamer = true
299
300 static const struct gen_device_info gen_device_info_hsw_gt1 = {
301 HSW_FEATURES, .gt = 1,
302 .num_slices = 1,
303 .num_subslices = { 1, },
304 .num_eu_per_subslice = 10,
305 .num_thread_per_eu = 7,
306 .l3_banks = 2,
307 .max_vs_threads = 70,
308 .max_tcs_threads = 70,
309 .max_tes_threads = 70,
310 .max_gs_threads = 70,
311 .max_wm_threads = 102,
312 .max_cs_threads = 70,
313 .urb = {
314 .min_entries = {
315 [MESA_SHADER_VERTEX] = 32,
316 [MESA_SHADER_TESS_EVAL] = 10,
317 },
318 .max_entries = {
319 [MESA_SHADER_VERTEX] = 640,
320 [MESA_SHADER_TESS_CTRL] = 64,
321 [MESA_SHADER_TESS_EVAL] = 384,
322 [MESA_SHADER_GEOMETRY] = 256,
323 },
324 },
325 .simulator_id = 9,
326 };
327
328 static const struct gen_device_info gen_device_info_hsw_gt2 = {
329 HSW_FEATURES, .gt = 2,
330 .num_slices = 1,
331 .num_subslices = { 2, },
332 .num_eu_per_subslice = 10,
333 .num_thread_per_eu = 7,
334 .l3_banks = 4,
335 .max_vs_threads = 280,
336 .max_tcs_threads = 256,
337 .max_tes_threads = 280,
338 .max_gs_threads = 256,
339 .max_wm_threads = 204,
340 .max_cs_threads = 70,
341 .urb = {
342 .min_entries = {
343 [MESA_SHADER_VERTEX] = 64,
344 [MESA_SHADER_TESS_EVAL] = 10,
345 },
346 .max_entries = {
347 [MESA_SHADER_VERTEX] = 1664,
348 [MESA_SHADER_TESS_CTRL] = 128,
349 [MESA_SHADER_TESS_EVAL] = 960,
350 [MESA_SHADER_GEOMETRY] = 640,
351 },
352 },
353 .simulator_id = 9,
354 };
355
356 static const struct gen_device_info gen_device_info_hsw_gt3 = {
357 HSW_FEATURES, .gt = 3,
358 .num_slices = 2,
359 .num_subslices = { 2, },
360 .num_eu_per_subslice = 10,
361 .num_thread_per_eu = 7,
362 .l3_banks = 8,
363 .max_vs_threads = 280,
364 .max_tcs_threads = 256,
365 .max_tes_threads = 280,
366 .max_gs_threads = 256,
367 .max_wm_threads = 408,
368 .max_cs_threads = 70,
369 .urb = {
370 .min_entries = {
371 [MESA_SHADER_VERTEX] = 64,
372 [MESA_SHADER_TESS_EVAL] = 10,
373 },
374 .max_entries = {
375 [MESA_SHADER_VERTEX] = 1664,
376 [MESA_SHADER_TESS_CTRL] = 128,
377 [MESA_SHADER_TESS_EVAL] = 960,
378 [MESA_SHADER_GEOMETRY] = 640,
379 },
380 },
381 .simulator_id = 9,
382 };
383
384 /* It's unclear how well supported sampling from the hiz buffer is on GEN8,
385 * so keep things conservative for now and set has_sample_with_hiz = false.
386 */
387 #define GEN8_FEATURES \
388 .gen = 8, \
389 .has_hiz_and_separate_stencil = true, \
390 .has_resource_streamer = true, \
391 .must_use_separate_stencil = true, \
392 .has_llc = true, \
393 .has_sample_with_hiz = false, \
394 .has_pln = true, \
395 .has_integer_dword_mul = true, \
396 .has_64bit_float = true, \
397 .has_64bit_int = true, \
398 .supports_simd16_3src = true, \
399 .has_surface_tile_offset = true, \
400 .num_thread_per_eu = 7, \
401 .max_vs_threads = 504, \
402 .max_tcs_threads = 504, \
403 .max_tes_threads = 504, \
404 .max_gs_threads = 504, \
405 .max_wm_threads = 384, \
406 .timestamp_frequency = 12500000
407
408 static const struct gen_device_info gen_device_info_bdw_gt1 = {
409 GEN8_FEATURES, .gt = 1,
410 .is_broadwell = true,
411 .num_slices = 1,
412 .num_subslices = { 2, },
413 .num_eu_per_subslice = 6,
414 .l3_banks = 2,
415 .max_cs_threads = 42,
416 .urb = {
417 .min_entries = {
418 [MESA_SHADER_VERTEX] = 64,
419 [MESA_SHADER_TESS_EVAL] = 34,
420 },
421 .max_entries = {
422 [MESA_SHADER_VERTEX] = 2560,
423 [MESA_SHADER_TESS_CTRL] = 504,
424 [MESA_SHADER_TESS_EVAL] = 1536,
425 /* Reduced from 960, seems to be similar to the bug on Gen9 GT1. */
426 [MESA_SHADER_GEOMETRY] = 690,
427 },
428 },
429 .simulator_id = 11,
430 };
431
432 static const struct gen_device_info gen_device_info_bdw_gt2 = {
433 GEN8_FEATURES, .gt = 2,
434 .is_broadwell = true,
435 .num_slices = 1,
436 .num_subslices = { 3, },
437 .num_eu_per_subslice = 8,
438 .l3_banks = 4,
439 .max_cs_threads = 56,
440 .urb = {
441 .min_entries = {
442 [MESA_SHADER_VERTEX] = 64,
443 [MESA_SHADER_TESS_EVAL] = 34,
444 },
445 .max_entries = {
446 [MESA_SHADER_VERTEX] = 2560,
447 [MESA_SHADER_TESS_CTRL] = 504,
448 [MESA_SHADER_TESS_EVAL] = 1536,
449 [MESA_SHADER_GEOMETRY] = 960,
450 },
451 },
452 .simulator_id = 11,
453 };
454
455 static const struct gen_device_info gen_device_info_bdw_gt3 = {
456 GEN8_FEATURES, .gt = 3,
457 .is_broadwell = true,
458 .num_slices = 2,
459 .num_subslices = { 3, 3, },
460 .num_eu_per_subslice = 8,
461 .l3_banks = 8,
462 .max_cs_threads = 56,
463 .urb = {
464 .min_entries = {
465 [MESA_SHADER_VERTEX] = 64,
466 [MESA_SHADER_TESS_EVAL] = 34,
467 },
468 .max_entries = {
469 [MESA_SHADER_VERTEX] = 2560,
470 [MESA_SHADER_TESS_CTRL] = 504,
471 [MESA_SHADER_TESS_EVAL] = 1536,
472 [MESA_SHADER_GEOMETRY] = 960,
473 },
474 },
475 .simulator_id = 11,
476 };
477
478 static const struct gen_device_info gen_device_info_chv = {
479 GEN8_FEATURES, .is_cherryview = 1, .gt = 1,
480 .has_llc = false,
481 .has_integer_dword_mul = false,
482 .num_slices = 1,
483 .num_subslices = { 2, },
484 .num_eu_per_subslice = 8,
485 .l3_banks = 2,
486 .max_vs_threads = 80,
487 .max_tcs_threads = 80,
488 .max_tes_threads = 80,
489 .max_gs_threads = 80,
490 .max_wm_threads = 128,
491 .max_cs_threads = 6 * 7,
492 .urb = {
493 .min_entries = {
494 [MESA_SHADER_VERTEX] = 34,
495 [MESA_SHADER_TESS_EVAL] = 34,
496 },
497 .max_entries = {
498 [MESA_SHADER_VERTEX] = 640,
499 [MESA_SHADER_TESS_CTRL] = 80,
500 [MESA_SHADER_TESS_EVAL] = 384,
501 [MESA_SHADER_GEOMETRY] = 256,
502 },
503 },
504 .simulator_id = 13,
505 };
506
507 #define GEN9_HW_INFO \
508 .gen = 9, \
509 .max_vs_threads = 336, \
510 .max_gs_threads = 336, \
511 .max_tcs_threads = 336, \
512 .max_tes_threads = 336, \
513 .max_cs_threads = 56, \
514 .timestamp_frequency = 12000000, \
515 .urb = { \
516 .min_entries = { \
517 [MESA_SHADER_VERTEX] = 64, \
518 [MESA_SHADER_TESS_EVAL] = 34, \
519 }, \
520 .max_entries = { \
521 [MESA_SHADER_VERTEX] = 1856, \
522 [MESA_SHADER_TESS_CTRL] = 672, \
523 [MESA_SHADER_TESS_EVAL] = 1120, \
524 [MESA_SHADER_GEOMETRY] = 640, \
525 }, \
526 }
527
528 #define GEN9_LP_FEATURES \
529 GEN8_FEATURES, \
530 GEN9_HW_INFO, \
531 .has_integer_dword_mul = false, \
532 .gt = 1, \
533 .has_llc = false, \
534 .has_sample_with_hiz = true, \
535 .num_slices = 1, \
536 .num_thread_per_eu = 6, \
537 .max_vs_threads = 112, \
538 .max_tcs_threads = 112, \
539 .max_tes_threads = 112, \
540 .max_gs_threads = 112, \
541 .max_cs_threads = 6 * 6, \
542 .timestamp_frequency = 19200000, \
543 .urb = { \
544 .min_entries = { \
545 [MESA_SHADER_VERTEX] = 34, \
546 [MESA_SHADER_TESS_EVAL] = 34, \
547 }, \
548 .max_entries = { \
549 [MESA_SHADER_VERTEX] = 704, \
550 [MESA_SHADER_TESS_CTRL] = 256, \
551 [MESA_SHADER_TESS_EVAL] = 416, \
552 [MESA_SHADER_GEOMETRY] = 256, \
553 }, \
554 }
555
556 #define GEN9_LP_FEATURES_3X6 \
557 GEN9_LP_FEATURES, \
558 .num_subslices = { 3, }, \
559 .num_eu_per_subslice = 6
560
561 #define GEN9_LP_FEATURES_2X6 \
562 GEN9_LP_FEATURES, \
563 .num_subslices = { 2, }, \
564 .num_eu_per_subslice = 6, \
565 .max_vs_threads = 56, \
566 .max_tcs_threads = 56, \
567 .max_tes_threads = 56, \
568 .max_gs_threads = 56, \
569 .max_cs_threads = 6 * 6, \
570 .urb = { \
571 .min_entries = { \
572 [MESA_SHADER_VERTEX] = 34, \
573 [MESA_SHADER_TESS_EVAL] = 34, \
574 }, \
575 .max_entries = { \
576 [MESA_SHADER_VERTEX] = 352, \
577 [MESA_SHADER_TESS_CTRL] = 128, \
578 [MESA_SHADER_TESS_EVAL] = 208, \
579 [MESA_SHADER_GEOMETRY] = 128, \
580 }, \
581 }
582
583 #define GEN9_FEATURES \
584 GEN8_FEATURES, \
585 GEN9_HW_INFO, \
586 .has_sample_with_hiz = true
587
588 static const struct gen_device_info gen_device_info_skl_gt1 = {
589 GEN9_FEATURES, .gt = 1,
590 .is_skylake = true,
591 .num_slices = 1,
592 .num_subslices = { 2, },
593 .num_eu_per_subslice = 6,
594 .l3_banks = 2,
595 /* GT1 seems to have a bug in the top of the pipe (VF/VS?) fixed functions
596 * leading to some vertices to go missing if we use too much URB.
597 */
598 .urb.max_entries[MESA_SHADER_VERTEX] = 928,
599 .simulator_id = 12,
600 };
601
602 static const struct gen_device_info gen_device_info_skl_gt2 = {
603 GEN9_FEATURES, .gt = 2,
604 .is_skylake = true,
605 .num_slices = 1,
606 .num_subslices = { 3, },
607 .num_eu_per_subslice = 8,
608 .l3_banks = 4,
609 .simulator_id = 12,
610 };
611
612 static const struct gen_device_info gen_device_info_skl_gt3 = {
613 GEN9_FEATURES, .gt = 3,
614 .is_skylake = true,
615 .num_slices = 2,
616 .num_subslices = { 3, 3, },
617 .num_eu_per_subslice = 8,
618 .l3_banks = 8,
619 .simulator_id = 12,
620 };
621
622 static const struct gen_device_info gen_device_info_skl_gt4 = {
623 GEN9_FEATURES, .gt = 4,
624 .is_skylake = true,
625 .num_slices = 3,
626 .num_subslices = { 3, 3, 3, },
627 .num_eu_per_subslice = 8,
628 .l3_banks = 12,
629 /* From the "L3 Allocation and Programming" documentation:
630 *
631 * "URB is limited to 1008KB due to programming restrictions. This is not a
632 * restriction of the L3 implementation, but of the FF and other clients.
633 * Therefore, in a GT4 implementation it is possible for the programmed
634 * allocation of the L3 data array to provide 3*384KB=1152KB for URB, but
635 * only 1008KB of this will be used."
636 */
637 .simulator_id = 12,
638 };
639
640 static const struct gen_device_info gen_device_info_bxt = {
641 GEN9_LP_FEATURES_3X6,
642 .is_broxton = true,
643 .l3_banks = 2,
644 .simulator_id = 14,
645 };
646
647 static const struct gen_device_info gen_device_info_bxt_2x6 = {
648 GEN9_LP_FEATURES_2X6,
649 .is_broxton = true,
650 .l3_banks = 1,
651 .simulator_id = 14,
652 };
653 /*
654 * Note: for all KBL SKUs, the PRM says SKL for GS entries, not SKL+.
655 * There's no KBL entry. Using the default SKL (GEN9) GS entries value.
656 */
657
658 static const struct gen_device_info gen_device_info_kbl_gt1 = {
659 GEN9_FEATURES,
660 .is_kabylake = true,
661 .gt = 1,
662
663 .max_cs_threads = 7 * 6,
664 .num_slices = 1,
665 .num_subslices = { 2, },
666 .num_eu_per_subslice = 6,
667 .l3_banks = 2,
668 /* GT1 seems to have a bug in the top of the pipe (VF/VS?) fixed functions
669 * leading to some vertices to go missing if we use too much URB.
670 */
671 .urb.max_entries[MESA_SHADER_VERTEX] = 928,
672 .simulator_id = 16,
673 };
674
675 static const struct gen_device_info gen_device_info_kbl_gt1_5 = {
676 GEN9_FEATURES,
677 .is_kabylake = true,
678 .gt = 1,
679
680 .max_cs_threads = 7 * 6,
681 .num_slices = 1,
682 .num_subslices = { 3, },
683 .num_eu_per_subslice = 6,
684 .l3_banks = 4,
685 .simulator_id = 16,
686 };
687
688 static const struct gen_device_info gen_device_info_kbl_gt2 = {
689 GEN9_FEATURES,
690 .is_kabylake = true,
691 .gt = 2,
692
693 .num_slices = 1,
694 .num_subslices = { 3, },
695 .num_eu_per_subslice = 8,
696 .l3_banks = 4,
697 .simulator_id = 16,
698 };
699
700 static const struct gen_device_info gen_device_info_kbl_gt3 = {
701 GEN9_FEATURES,
702 .is_kabylake = true,
703 .gt = 3,
704
705 .num_slices = 2,
706 .num_subslices = { 3, 3, },
707 .num_eu_per_subslice = 8,
708 .l3_banks = 8,
709 .simulator_id = 16,
710 };
711
712 static const struct gen_device_info gen_device_info_kbl_gt4 = {
713 GEN9_FEATURES,
714 .is_kabylake = true,
715 .gt = 4,
716
717 /*
718 * From the "L3 Allocation and Programming" documentation:
719 *
720 * "URB is limited to 1008KB due to programming restrictions. This
721 * is not a restriction of the L3 implementation, but of the FF and
722 * other clients. Therefore, in a GT4 implementation it is
723 * possible for the programmed allocation of the L3 data array to
724 * provide 3*384KB=1152KB for URB, but only 1008KB of this
725 * will be used."
726 */
727 .num_slices = 3,
728 .num_subslices = { 3, 3, 3, },
729 .num_eu_per_subslice = 8,
730 .l3_banks = 12,
731 .simulator_id = 16,
732 };
733
734 static const struct gen_device_info gen_device_info_glk = {
735 GEN9_LP_FEATURES_3X6,
736 .is_geminilake = true,
737 .l3_banks = 2,
738 .simulator_id = 17,
739 };
740
741 static const struct gen_device_info gen_device_info_glk_2x6 = {
742 GEN9_LP_FEATURES_2X6,
743 .is_geminilake = true,
744 .l3_banks = 2,
745 .simulator_id = 17,
746 };
747
748 static const struct gen_device_info gen_device_info_cfl_gt1 = {
749 GEN9_FEATURES,
750 .is_coffeelake = true,
751 .gt = 1,
752
753 .num_slices = 1,
754 .num_subslices = { 2, },
755 .num_eu_per_subslice = 6,
756 .l3_banks = 2,
757 /* GT1 seems to have a bug in the top of the pipe (VF/VS?) fixed functions
758 * leading to some vertices to go missing if we use too much URB.
759 */
760 .urb.max_entries[MESA_SHADER_VERTEX] = 928,
761 .simulator_id = 24,
762 };
763 static const struct gen_device_info gen_device_info_cfl_gt2 = {
764 GEN9_FEATURES,
765 .is_coffeelake = true,
766 .gt = 2,
767
768 .num_slices = 1,
769 .num_subslices = { 3, },
770 .num_eu_per_subslice = 8,
771 .l3_banks = 4,
772 .simulator_id = 24,
773 };
774
775 static const struct gen_device_info gen_device_info_cfl_gt3 = {
776 GEN9_FEATURES,
777 .is_coffeelake = true,
778 .gt = 3,
779
780 .num_slices = 2,
781 .num_subslices = { 3, 3, },
782 .num_eu_per_subslice = 8,
783 .l3_banks = 8,
784 .simulator_id = 24,
785 };
786
787 #define GEN10_HW_INFO \
788 .gen = 10, \
789 .num_thread_per_eu = 7, \
790 .max_vs_threads = 728, \
791 .max_gs_threads = 432, \
792 .max_tcs_threads = 432, \
793 .max_tes_threads = 624, \
794 .max_cs_threads = 56, \
795 .timestamp_frequency = 19200000, \
796 .urb = { \
797 .min_entries = { \
798 [MESA_SHADER_VERTEX] = 64, \
799 [MESA_SHADER_TESS_EVAL] = 34, \
800 }, \
801 .max_entries = { \
802 [MESA_SHADER_VERTEX] = 3936, \
803 [MESA_SHADER_TESS_CTRL] = 896, \
804 [MESA_SHADER_TESS_EVAL] = 2064, \
805 [MESA_SHADER_GEOMETRY] = 832, \
806 }, \
807 }
808
809 #define subslices(args...) { args, }
810
811 #define GEN10_FEATURES(_gt, _slices, _subslices, _l3) \
812 GEN8_FEATURES, \
813 GEN10_HW_INFO, \
814 .has_sample_with_hiz = true, \
815 .gt = _gt, \
816 .num_slices = _slices, \
817 .num_subslices = _subslices, \
818 .num_eu_per_subslice = 8, \
819 .l3_banks = _l3
820
821 static const struct gen_device_info gen_device_info_cnl_gt0_5 = {
822 /* GT0.5 */
823 GEN10_FEATURES(1, 1, subslices(2), 2),
824 .is_cannonlake = true,
825 .simulator_id = 15,
826 };
827
828 static const struct gen_device_info gen_device_info_cnl_gt1 = {
829 /* GT1 */
830 GEN10_FEATURES(1, 1, subslices(3), 3),
831 .is_cannonlake = true,
832 .simulator_id = 15,
833 };
834
835 static const struct gen_device_info gen_device_info_cnl_gt1_5 = {
836 /* GT 1.5 */
837 GEN10_FEATURES(1, 2, subslices(2, 2), 6),
838 .is_cannonlake = true,
839 .simulator_id = 15,
840 };
841
842 static const struct gen_device_info gen_device_info_cnl_gt2 = {
843 /* GT2 */
844 GEN10_FEATURES(2, 2, subslices(3, 2), 6),
845 .is_cannonlake = true,
846 .simulator_id = 15,
847 };
848
849 #define GEN11_HW_INFO \
850 .gen = 11, \
851 .has_pln = false, \
852 .max_vs_threads = 364, \
853 .max_gs_threads = 224, \
854 .max_tcs_threads = 224, \
855 .max_tes_threads = 364, \
856 .max_cs_threads = 56
857
858 #define GEN11_FEATURES(_gt, _slices, _subslices, _l3) \
859 GEN8_FEATURES, \
860 GEN11_HW_INFO, \
861 .has_64bit_float = false, \
862 .has_64bit_int = false, \
863 .has_integer_dword_mul = false, \
864 .has_sample_with_hiz = false, \
865 .gt = _gt, .num_slices = _slices, .l3_banks = _l3, \
866 .num_subslices = _subslices, \
867 .num_eu_per_subslice = 8
868
869 #define GEN11_URB_MIN_MAX_ENTRIES \
870 .min_entries = { \
871 [MESA_SHADER_VERTEX] = 64, \
872 [MESA_SHADER_TESS_EVAL] = 34, \
873 }, \
874 .max_entries = { \
875 [MESA_SHADER_VERTEX] = 2384, \
876 [MESA_SHADER_TESS_CTRL] = 1032, \
877 [MESA_SHADER_TESS_EVAL] = 2384, \
878 [MESA_SHADER_GEOMETRY] = 1032, \
879 }
880
881 static const struct gen_device_info gen_device_info_icl_gt2 = {
882 GEN11_FEATURES(2, 1, subslices(8), 8),
883 .urb = {
884 GEN11_URB_MIN_MAX_ENTRIES,
885 },
886 .simulator_id = 19,
887 };
888
889 static const struct gen_device_info gen_device_info_icl_gt1_5 = {
890 GEN11_FEATURES(1, 1, subslices(6), 6),
891 .urb = {
892 GEN11_URB_MIN_MAX_ENTRIES,
893 },
894 .simulator_id = 19,
895 };
896
897 static const struct gen_device_info gen_device_info_icl_gt1 = {
898 GEN11_FEATURES(1, 1, subslices(4), 6),
899 .urb = {
900 GEN11_URB_MIN_MAX_ENTRIES,
901 },
902 .simulator_id = 19,
903 };
904
905 static const struct gen_device_info gen_device_info_icl_gt0_5 = {
906 GEN11_FEATURES(1, 1, subslices(1), 6),
907 .urb = {
908 GEN11_URB_MIN_MAX_ENTRIES,
909 },
910 .simulator_id = 19,
911 };
912
913 #define GEN11_LP_FEATURES \
914 .is_elkhartlake = true, \
915 .urb = { \
916 GEN11_URB_MIN_MAX_ENTRIES, \
917 }, \
918 .disable_ccs_repack = true, \
919 .simulator_id = 28
920
921 static const struct gen_device_info gen_device_info_ehl_4x8 = {
922 GEN11_FEATURES(1, 1, subslices(4), 4),
923 GEN11_LP_FEATURES,
924 };
925
926 static const struct gen_device_info gen_device_info_ehl_4x6 = {
927 GEN11_FEATURES(1, 1, subslices(4), 4),
928 GEN11_LP_FEATURES,
929 .num_eu_per_subslice = 6,
930 };
931
932 static const struct gen_device_info gen_device_info_ehl_4x5 = {
933 GEN11_FEATURES(1, 1, subslices(4), 4),
934 GEN11_LP_FEATURES,
935 .num_eu_per_subslice = 5,
936 };
937
938 static const struct gen_device_info gen_device_info_ehl_4x4 = {
939 GEN11_FEATURES(1, 1, subslices(4), 4),
940 GEN11_LP_FEATURES,
941 .num_eu_per_subslice = 4,
942 };
943
944 static const struct gen_device_info gen_device_info_ehl_2x8 = {
945 GEN11_FEATURES(1, 1, subslices(2), 4),
946 GEN11_LP_FEATURES,
947 };
948
949 static const struct gen_device_info gen_device_info_ehl_2x4 = {
950 GEN11_FEATURES(1, 1, subslices(2), 4),
951 GEN11_LP_FEATURES,
952 .num_eu_per_subslice =4,
953 };
954
955 #define GEN12_URB_MIN_MAX_ENTRIES \
956 .min_entries = { \
957 [MESA_SHADER_VERTEX] = 64, \
958 [MESA_SHADER_TESS_EVAL] = 34, \
959 }, \
960 .max_entries = { \
961 [MESA_SHADER_VERTEX] = 3576, \
962 [MESA_SHADER_TESS_CTRL] = 1548, \
963 [MESA_SHADER_TESS_EVAL] = 3576, \
964 [MESA_SHADER_GEOMETRY] = 1548, \
965 }
966
967 #define GEN12_HW_INFO \
968 .gen = 12, \
969 .has_pln = false, \
970 .has_sample_with_hiz = false, \
971 .has_aux_map = true, \
972 .max_vs_threads = 546, \
973 .max_gs_threads = 336, \
974 .max_tcs_threads = 336, \
975 .max_tes_threads = 546, \
976 .max_cs_threads = 112, /* threads per DSS */ \
977 .urb = { \
978 GEN12_URB_MIN_MAX_ENTRIES, \
979 }
980
981 #define GEN12_FEATURES(_gt, _slices, _l3) \
982 GEN8_FEATURES, \
983 GEN12_HW_INFO, \
984 .has_64bit_float = false, \
985 .has_64bit_int = false, \
986 .has_integer_dword_mul = false, \
987 .gt = _gt, .num_slices = _slices, .l3_banks = _l3, \
988 .simulator_id = 22, \
989 .num_eu_per_subslice = 16
990
991 #define dual_subslices(args...) { args, }
992
993 #define GEN12_GT05_FEATURES \
994 GEN12_FEATURES(1, 1, 4), \
995 .num_subslices = dual_subslices(1)
996
997 #define GEN12_GT_FEATURES(_gt) \
998 GEN12_FEATURES(_gt, 1, _gt == 1 ? 4 : 8), \
999 .num_subslices = dual_subslices(_gt == 1 ? 2 : 6)
1000
1001 static const struct gen_device_info gen_device_info_tgl_gt1 = {
1002 GEN12_GT_FEATURES(1),
1003 };
1004
1005 static const struct gen_device_info gen_device_info_tgl_gt2 = {
1006 GEN12_GT_FEATURES(2),
1007 };
1008
1009 static const struct gen_device_info gen_device_info_rkl_gt05 = {
1010 GEN12_GT05_FEATURES,
1011 };
1012
1013 static const struct gen_device_info gen_device_info_rkl_gt1 = {
1014 GEN12_GT_FEATURES(1),
1015 };
1016
1017 #define GEN12_DG1_FEATURES \
1018 GEN12_GT_FEATURES(2), \
1019 .is_dg1 = true, \
1020 .has_llc = false, \
1021 .urb.size = 768, \
1022 .simulator_id = 30
1023
1024 UNUSED static const struct gen_device_info gen_device_info_dg1 = {
1025 GEN12_DG1_FEATURES,
1026 };
1027
1028 static void
1029 gen_device_info_set_eu_mask(struct gen_device_info *devinfo,
1030 unsigned slice,
1031 unsigned subslice,
1032 unsigned eu_mask)
1033 {
1034 unsigned subslice_offset = slice * devinfo->eu_slice_stride +
1035 subslice * devinfo->eu_subslice_stride;
1036
1037 for (unsigned b_eu = 0; b_eu < devinfo->eu_subslice_stride; b_eu++) {
1038 devinfo->eu_masks[subslice_offset + b_eu] =
1039 (((1U << devinfo->num_eu_per_subslice) - 1) >> (b_eu * 8)) & 0xff;
1040 }
1041 }
1042
1043 /* Generate slice/subslice/eu masks from number of
1044 * slices/subslices/eu_per_subslices in the per generation/gt gen_device_info
1045 * structure.
1046 *
1047 * These can be overridden with values reported by the kernel either from
1048 * getparam SLICE_MASK/SUBSLICE_MASK values or from the kernel version 4.17+
1049 * through the i915 query uapi.
1050 */
1051 static void
1052 fill_masks(struct gen_device_info *devinfo)
1053 {
1054 devinfo->slice_masks = (1U << devinfo->num_slices) - 1;
1055
1056 /* Subslice masks */
1057 unsigned max_subslices = 0;
1058 for (int s = 0; s < devinfo->num_slices; s++)
1059 max_subslices = MAX2(devinfo->num_subslices[s], max_subslices);
1060 devinfo->subslice_slice_stride = DIV_ROUND_UP(max_subslices, 8);
1061
1062 for (int s = 0; s < devinfo->num_slices; s++) {
1063 devinfo->subslice_masks[s * devinfo->subslice_slice_stride] =
1064 (1U << devinfo->num_subslices[s]) - 1;
1065 }
1066
1067 /* EU masks */
1068 devinfo->eu_subslice_stride = DIV_ROUND_UP(devinfo->num_eu_per_subslice, 8);
1069 devinfo->eu_slice_stride = max_subslices * devinfo->eu_subslice_stride;
1070
1071 for (int s = 0; s < devinfo->num_slices; s++) {
1072 for (int ss = 0; ss < devinfo->num_subslices[s]; ss++) {
1073 gen_device_info_set_eu_mask(devinfo, s, ss,
1074 (1U << devinfo->num_eu_per_subslice) - 1);
1075 }
1076 }
1077 }
1078
1079 static void
1080 reset_masks(struct gen_device_info *devinfo)
1081 {
1082 devinfo->subslice_slice_stride = 0;
1083 devinfo->eu_subslice_stride = 0;
1084 devinfo->eu_slice_stride = 0;
1085
1086 devinfo->num_slices = 0;
1087 devinfo->num_eu_per_subslice = 0;
1088 memset(devinfo->num_subslices, 0, sizeof(devinfo->num_subslices));
1089
1090 memset(&devinfo->slice_masks, 0, sizeof(devinfo->slice_masks));
1091 memset(devinfo->subslice_masks, 0, sizeof(devinfo->subslice_masks));
1092 memset(devinfo->eu_masks, 0, sizeof(devinfo->eu_masks));
1093 memset(devinfo->ppipe_subslices, 0, sizeof(devinfo->ppipe_subslices));
1094 }
1095
1096 static void
1097 update_from_topology(struct gen_device_info *devinfo,
1098 const struct drm_i915_query_topology_info *topology)
1099 {
1100 reset_masks(devinfo);
1101
1102 devinfo->subslice_slice_stride = topology->subslice_stride;
1103
1104 devinfo->eu_subslice_stride = DIV_ROUND_UP(topology->max_eus_per_subslice, 8);
1105 devinfo->eu_slice_stride = topology->max_subslices * devinfo->eu_subslice_stride;
1106
1107 assert(sizeof(devinfo->slice_masks) >= DIV_ROUND_UP(topology->max_slices, 8));
1108 memcpy(&devinfo->slice_masks, topology->data, DIV_ROUND_UP(topology->max_slices, 8));
1109 devinfo->num_slices = __builtin_popcount(devinfo->slice_masks);
1110
1111 uint32_t subslice_mask_len =
1112 topology->max_slices * topology->subslice_stride;
1113 assert(sizeof(devinfo->subslice_masks) >= subslice_mask_len);
1114 memcpy(devinfo->subslice_masks, &topology->data[topology->subslice_offset],
1115 subslice_mask_len);
1116
1117 uint32_t n_subslices = 0;
1118 for (int s = 0; s < topology->max_slices; s++) {
1119 if ((devinfo->slice_masks & (1 << s)) == 0)
1120 continue;
1121
1122 for (int b = 0; b < devinfo->subslice_slice_stride; b++) {
1123 devinfo->num_subslices[s] +=
1124 __builtin_popcount(devinfo->subslice_masks[s * devinfo->subslice_slice_stride + b]);
1125 }
1126 n_subslices += devinfo->num_subslices[s];
1127 }
1128 assert(n_subslices > 0);
1129
1130 if (devinfo->gen == 11) {
1131 /* On ICL we only have one slice */
1132 assert(devinfo->slice_masks == 1);
1133
1134 /* Count the number of subslices on each pixel pipe. Assume that
1135 * subslices 0-3 are on pixel pipe 0, and 4-7 are on pixel pipe 1.
1136 */
1137 unsigned subslices = devinfo->subslice_masks[0];
1138 unsigned ss = 0;
1139 while (subslices > 0) {
1140 if (subslices & 1)
1141 devinfo->ppipe_subslices[ss >= 4 ? 1 : 0] += 1;
1142 subslices >>= 1;
1143 ss++;
1144 }
1145 }
1146
1147 if (devinfo->gen == 12 && devinfo->num_slices == 1) {
1148 if (n_subslices >= 6) {
1149 assert(n_subslices == 6);
1150 devinfo->l3_banks = 8;
1151 } else if (n_subslices > 2) {
1152 devinfo->l3_banks = 6;
1153 } else {
1154 devinfo->l3_banks = 4;
1155 }
1156 }
1157
1158 uint32_t eu_mask_len =
1159 topology->eu_stride * topology->max_subslices * topology->max_slices;
1160 assert(sizeof(devinfo->eu_masks) >= eu_mask_len);
1161 memcpy(devinfo->eu_masks, &topology->data[topology->eu_offset], eu_mask_len);
1162
1163 uint32_t n_eus = 0;
1164 for (int b = 0; b < eu_mask_len; b++)
1165 n_eus += __builtin_popcount(devinfo->eu_masks[b]);
1166
1167 devinfo->num_eu_per_subslice = DIV_ROUND_UP(n_eus, n_subslices);
1168 }
1169
1170 static bool
1171 update_from_masks(struct gen_device_info *devinfo, uint32_t slice_mask,
1172 uint32_t subslice_mask, uint32_t n_eus)
1173 {
1174 struct drm_i915_query_topology_info *topology;
1175
1176 assert((slice_mask & 0xff) == slice_mask);
1177
1178 size_t data_length = 100;
1179
1180 topology = calloc(1, sizeof(*topology) + data_length);
1181 if (!topology)
1182 return false;
1183
1184 topology->max_slices = util_last_bit(slice_mask);
1185 topology->max_subslices = util_last_bit(subslice_mask);
1186
1187 topology->subslice_offset = DIV_ROUND_UP(topology->max_slices, 8);
1188 topology->subslice_stride = DIV_ROUND_UP(topology->max_subslices, 8);
1189
1190 uint32_t n_subslices = __builtin_popcount(slice_mask) *
1191 __builtin_popcount(subslice_mask);
1192 uint32_t num_eu_per_subslice = DIV_ROUND_UP(n_eus, n_subslices);
1193 uint32_t eu_mask = (1U << num_eu_per_subslice) - 1;
1194
1195 topology->eu_offset = topology->subslice_offset +
1196 DIV_ROUND_UP(topology->max_subslices, 8);
1197 topology->eu_stride = DIV_ROUND_UP(num_eu_per_subslice, 8);
1198
1199 /* Set slice mask in topology */
1200 for (int b = 0; b < topology->subslice_offset; b++)
1201 topology->data[b] = (slice_mask >> (b * 8)) & 0xff;
1202
1203 for (int s = 0; s < topology->max_slices; s++) {
1204
1205 /* Set subslice mask in topology */
1206 for (int b = 0; b < topology->subslice_stride; b++) {
1207 int subslice_offset = topology->subslice_offset +
1208 s * topology->subslice_stride + b;
1209
1210 topology->data[subslice_offset] = (subslice_mask >> (b * 8)) & 0xff;
1211 }
1212
1213 /* Set eu mask in topology */
1214 for (int ss = 0; ss < topology->max_subslices; ss++) {
1215 for (int b = 0; b < topology->eu_stride; b++) {
1216 int eu_offset = topology->eu_offset +
1217 (s * topology->max_subslices + ss) * topology->eu_stride + b;
1218
1219 topology->data[eu_offset] = (eu_mask >> (b * 8)) & 0xff;
1220 }
1221 }
1222 }
1223
1224 update_from_topology(devinfo, topology);
1225 free(topology);
1226
1227 return true;
1228 }
1229
1230 static bool
1231 getparam(int fd, uint32_t param, int *value)
1232 {
1233 int tmp;
1234
1235 struct drm_i915_getparam gp = {
1236 .param = param,
1237 .value = &tmp,
1238 };
1239
1240 int ret = gen_ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);
1241 if (ret != 0)
1242 return false;
1243
1244 *value = tmp;
1245 return true;
1246 }
1247
1248 bool
1249 gen_get_device_info_from_pci_id(int pci_id,
1250 struct gen_device_info *devinfo)
1251 {
1252 switch (pci_id) {
1253 #undef CHIPSET
1254 #define CHIPSET(id, family, fam_str, name) \
1255 case id: *devinfo = gen_device_info_##family; break;
1256 #include "pci_ids/i965_pci_ids.h"
1257 #include "pci_ids/iris_pci_ids.h"
1258 default:
1259 fprintf(stderr, "Driver does not support the 0x%x PCI ID.\n", pci_id);
1260 return false;
1261 }
1262
1263 fill_masks(devinfo);
1264
1265 /* From the Skylake PRM, 3DSTATE_PS::Scratch Space Base Pointer:
1266 *
1267 * "Scratch Space per slice is computed based on 4 sub-slices. SW must
1268 * allocate scratch space enough so that each slice has 4 slices allowed."
1269 *
1270 * The equivalent internal documentation says that this programming note
1271 * applies to all Gen9+ platforms.
1272 *
1273 * The hardware typically calculates the scratch space pointer by taking
1274 * the base address, and adding per-thread-scratch-space * thread ID.
1275 * Extra padding can be necessary depending how the thread IDs are
1276 * calculated for a particular shader stage.
1277 */
1278
1279 switch(devinfo->gen) {
1280 case 9:
1281 case 10:
1282 devinfo->max_wm_threads = 64 /* threads-per-PSD */
1283 * devinfo->num_slices
1284 * 4; /* effective subslices per slice */
1285 break;
1286 case 11:
1287 case 12:
1288 devinfo->max_wm_threads = 128 /* threads-per-PSD */
1289 * devinfo->num_slices
1290 * 8; /* subslices per slice */
1291 break;
1292 default:
1293 assert(devinfo->gen < 9);
1294 break;
1295 }
1296
1297 assert(devinfo->num_slices <= ARRAY_SIZE(devinfo->num_subslices));
1298
1299 devinfo->chipset_id = pci_id;
1300 return true;
1301 }
1302
1303 const char *
1304 gen_get_device_name(int devid)
1305 {
1306 switch (devid) {
1307 #undef CHIPSET
1308 #define CHIPSET(id, family, fam_str, name) case id: return name " (" fam_str ")"; break;
1309 #include "pci_ids/i965_pci_ids.h"
1310 #include "pci_ids/iris_pci_ids.h"
1311 default:
1312 return NULL;
1313 }
1314 }
1315
1316 /**
1317 * for gen8/gen9, SLICE_MASK/SUBSLICE_MASK can be used to compute the topology
1318 * (kernel 4.13+)
1319 */
1320 static bool
1321 getparam_topology(struct gen_device_info *devinfo, int fd)
1322 {
1323 int slice_mask = 0;
1324 if (!getparam(fd, I915_PARAM_SLICE_MASK, &slice_mask))
1325 return false;
1326
1327 int n_eus;
1328 if (!getparam(fd, I915_PARAM_EU_TOTAL, &n_eus))
1329 return false;
1330
1331 int subslice_mask = 0;
1332 if (!getparam(fd, I915_PARAM_SUBSLICE_MASK, &subslice_mask))
1333 return false;
1334
1335 return update_from_masks(devinfo, slice_mask, subslice_mask, n_eus);
1336 }
1337
1338 /**
1339 * preferred API for updating the topology in devinfo (kernel 4.17+)
1340 */
1341 static bool
1342 query_topology(struct gen_device_info *devinfo, int fd)
1343 {
1344 struct drm_i915_query_item item = {
1345 .query_id = DRM_I915_QUERY_TOPOLOGY_INFO,
1346 };
1347 struct drm_i915_query query = {
1348 .num_items = 1,
1349 .items_ptr = (uintptr_t) &item,
1350 };
1351
1352 if (gen_ioctl(fd, DRM_IOCTL_I915_QUERY, &query))
1353 return false;
1354
1355 if (item.length < 0)
1356 return false;
1357
1358 struct drm_i915_query_topology_info *topo_info =
1359 (struct drm_i915_query_topology_info *) calloc(1, item.length);
1360 item.data_ptr = (uintptr_t) topo_info;
1361
1362 if (gen_ioctl(fd, DRM_IOCTL_I915_QUERY, &query) ||
1363 item.length <= 0)
1364 return false;
1365
1366 update_from_topology(devinfo, topo_info);
1367
1368 free(topo_info);
1369
1370 return true;
1371
1372 }
1373
1374 int
1375 gen_get_aperture_size(int fd, uint64_t *size)
1376 {
1377 struct drm_i915_gem_get_aperture aperture = { 0 };
1378
1379 int ret = gen_ioctl(fd, DRM_IOCTL_I915_GEM_GET_APERTURE, &aperture);
1380 if (ret == 0 && size)
1381 *size = aperture.aper_size;
1382
1383 return ret;
1384 }
1385
1386 static bool
1387 gen_has_get_tiling(int fd)
1388 {
1389 int ret;
1390
1391 struct drm_i915_gem_create gem_create = {
1392 .size = 4096,
1393 };
1394
1395 if (gen_ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &gem_create)) {
1396 unreachable("Failed to create GEM BO");
1397 return false;
1398 }
1399
1400 struct drm_i915_gem_get_tiling get_tiling = {
1401 .handle = gem_create.handle,
1402 };
1403 ret = gen_ioctl(fd, DRM_IOCTL_I915_GEM_SET_TILING, &get_tiling);
1404
1405 struct drm_gem_close close = {
1406 .handle = gem_create.handle,
1407 };
1408 gen_ioctl(fd, DRM_IOCTL_GEM_CLOSE, &close);
1409
1410 return ret == 0;
1411 }
1412
1413 bool
1414 gen_get_device_info_from_fd(int fd, struct gen_device_info *devinfo)
1415 {
1416 int devid = 0;
1417
1418 const char *devid_override = getenv("INTEL_DEVID_OVERRIDE");
1419 if (devid_override && strlen(devid_override) > 0) {
1420 if (geteuid() == getuid()) {
1421 devid = gen_device_name_to_pci_device_id(devid_override);
1422 /* Fallback to PCI ID. */
1423 if (devid <= 0)
1424 devid = strtol(devid_override, NULL, 0);
1425 if (devid <= 0) {
1426 fprintf(stderr, "Invalid INTEL_DEVID_OVERRIDE=\"%s\". "
1427 "Use a valid numeric PCI ID or one of the supported "
1428 "platform names: %s", devid_override, name_map[0].name);
1429 for (unsigned i = 1; i < ARRAY_SIZE(name_map); i++)
1430 fprintf(stderr, ", %s", name_map[i].name);
1431 fprintf(stderr, "\n");
1432 return false;
1433 }
1434 } else {
1435 fprintf(stderr, "Ignoring INTEL_DEVID_OVERRIDE=\"%s\" because "
1436 "real and effective user ID don't match.\n", devid_override);
1437 }
1438 }
1439
1440 if (devid > 0) {
1441 if (!gen_get_device_info_from_pci_id(devid, devinfo))
1442 return false;
1443 devinfo->no_hw = true;
1444 } else {
1445 /* query the device id */
1446 if (!getparam(fd, I915_PARAM_CHIPSET_ID, &devid))
1447 return false;
1448 if (!gen_get_device_info_from_pci_id(devid, devinfo))
1449 return false;
1450 devinfo->no_hw = false;
1451 }
1452
1453 /* remaining initializion queries the kernel for device info */
1454 if (devinfo->no_hw)
1455 return true;
1456
1457 int timestamp_frequency;
1458 if (getparam(fd, I915_PARAM_CS_TIMESTAMP_FREQUENCY,
1459 &timestamp_frequency))
1460 devinfo->timestamp_frequency = timestamp_frequency;
1461 else if (devinfo->gen >= 10)
1462 /* gen10 and later requires the timestamp_frequency to be updated */
1463 return false;
1464
1465 if (!getparam(fd, I915_PARAM_REVISION, &devinfo->revision))
1466 devinfo->revision = 0;
1467
1468 if (!query_topology(devinfo, fd)) {
1469 if (devinfo->gen >= 10) {
1470 /* topology uAPI required for CNL+ (kernel 4.17+) */
1471 return false;
1472 }
1473
1474 /* else use the kernel 4.13+ api for gen8+. For older kernels, topology
1475 * will be wrong, affecting GPU metrics. In this case, fail silently.
1476 */
1477 getparam_topology(devinfo, fd);
1478 }
1479
1480 gen_get_aperture_size(fd, &devinfo->aperture_bytes);
1481 devinfo->has_tiling_uapi = gen_has_get_tiling(fd);
1482
1483 return true;
1484 }