Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/amd/common/ac_gpu_info.c
7197 views
1
/*
2
* Copyright © 2017 Advanced Micro Devices, Inc.
3
*
4
* Permission is hereby granted, free of charge, to any person obtaining
5
* a copy of this software and associated documentation files (the
6
* "Software"), to deal in the Software without restriction, including
7
* without limitation the rights to use, copy, modify, merge, publish,
8
* distribute, sub license, and/or sell copies of the Software, and to
9
* permit persons to whom the Software is furnished to do so, subject to
10
* the following conditions:
11
*
12
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
14
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15
* NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS
16
* AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
18
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
19
* USE OR OTHER DEALINGS IN THE SOFTWARE.
20
*
21
* The above copyright notice and this permission notice (including the
22
* next paragraph) shall be included in all copies or substantial portions
23
* of the Software.
24
*/
25
26
#include "ac_gpu_info.h"
27
28
#include "addrlib/src/amdgpu_asic_addr.h"
29
#include "sid.h"
30
#include "util/macros.h"
31
#include "util/u_cpu_detect.h"
32
#include "util/u_math.h"
33
34
#include <stdio.h>
35
36
#ifdef _WIN32
37
#define DRM_CAP_ADDFB2_MODIFIERS 0x10
38
#define DRM_CAP_SYNCOBJ 0x13
39
#define DRM_CAP_SYNCOBJ_TIMELINE 0x14
40
#define AMDGPU_GEM_DOMAIN_GTT 0x2
41
#define AMDGPU_GEM_DOMAIN_VRAM 0x4
42
#define AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED (1 << 0)
43
#define AMDGPU_GEM_CREATE_ENCRYPTED (1 << 10)
44
#define AMDGPU_HW_IP_GFX 0
45
#define AMDGPU_HW_IP_COMPUTE 1
46
#define AMDGPU_HW_IP_DMA 2
47
#define AMDGPU_HW_IP_UVD 3
48
#define AMDGPU_HW_IP_VCE 4
49
#define AMDGPU_HW_IP_UVD_ENC 5
50
#define AMDGPU_HW_IP_VCN_DEC 6
51
#define AMDGPU_HW_IP_VCN_ENC 7
52
#define AMDGPU_HW_IP_VCN_JPEG 8
53
#define AMDGPU_IDS_FLAGS_FUSION 0x1
54
#define AMDGPU_IDS_FLAGS_PREEMPTION 0x2
55
#define AMDGPU_IDS_FLAGS_TMZ 0x4
56
#define AMDGPU_INFO_FW_VCE 0x1
57
#define AMDGPU_INFO_FW_UVD 0x2
58
#define AMDGPU_INFO_FW_GFX_ME 0x04
59
#define AMDGPU_INFO_FW_GFX_PFP 0x05
60
#define AMDGPU_INFO_FW_GFX_CE 0x06
61
#define AMDGPU_INFO_DEV_INFO 0x16
62
#define AMDGPU_INFO_MEMORY 0x19
63
#define AMDGPU_INFO_VIDEO_CAPS_DECODE 0
64
#define AMDGPU_INFO_VIDEO_CAPS_ENCODE 1
65
struct drm_amdgpu_heap_info {
66
uint64_t total_heap_size;
67
};
68
struct drm_amdgpu_memory_info {
69
struct drm_amdgpu_heap_info vram;
70
struct drm_amdgpu_heap_info cpu_accessible_vram;
71
struct drm_amdgpu_heap_info gtt;
72
};
73
struct drm_amdgpu_info_device {
74
uint32_t num_tcc_blocks;
75
uint32_t pa_sc_tile_steering_override;
76
uint64_t tcc_disabled_mask;
77
};
78
struct drm_amdgpu_info_hw_ip {
79
uint32_t ib_start_alignment;
80
uint32_t ib_size_alignment;
81
uint32_t available_rings;
82
};
83
typedef struct _drmPciBusInfo {
84
uint16_t domain;
85
uint8_t bus;
86
uint8_t dev;
87
uint8_t func;
88
} drmPciBusInfo, *drmPciBusInfoPtr;
89
typedef struct _drmDevice {
90
union {
91
drmPciBusInfoPtr pci;
92
} businfo;
93
} drmDevice, *drmDevicePtr;
94
enum amdgpu_sw_info {
95
amdgpu_sw_info_address32_hi = 0,
96
};
97
typedef struct amdgpu_device *amdgpu_device_handle;
98
typedef struct amdgpu_bo *amdgpu_bo_handle;
99
struct amdgpu_bo_alloc_request {
100
uint64_t alloc_size;
101
uint64_t phys_alignment;
102
uint32_t preferred_heap;
103
uint64_t flags;
104
};
105
struct amdgpu_gds_resource_info {
106
uint32_t gds_gfx_partition_size;
107
uint32_t gds_total_size;
108
};
109
struct amdgpu_buffer_size_alignments {
110
uint64_t size_local;
111
uint64_t size_remote;
112
};
113
struct amdgpu_heap_info {
114
uint64_t heap_size;
115
};
116
struct amdgpu_gpu_info {
117
uint32_t asic_id;
118
uint32_t chip_external_rev;
119
uint32_t family_id;
120
uint64_t ids_flags;
121
uint64_t max_engine_clk;
122
uint64_t max_memory_clk;
123
uint32_t num_shader_engines;
124
uint32_t num_shader_arrays_per_engine;
125
uint32_t rb_pipes;
126
uint32_t enabled_rb_pipes_mask;
127
uint32_t gpu_counter_freq;
128
uint32_t mc_arb_ramcfg;
129
uint32_t gb_addr_cfg;
130
uint32_t gb_tile_mode[32];
131
uint32_t gb_macro_tile_mode[16];
132
uint32_t cu_bitmap[4][4];
133
uint32_t vram_type;
134
uint32_t vram_bit_width;
135
uint32_t ce_ram_size;
136
uint32_t vce_harvest_config;
137
uint32_t pci_rev_id;
138
};
139
static int drmGetCap(int fd, uint64_t capability, uint64_t *value)
140
{
141
return -EINVAL;
142
}
143
static void drmFreeDevice(drmDevicePtr *device)
144
{
145
}
146
static int drmGetDevice2(int fd, uint32_t flags, drmDevicePtr *device)
147
{
148
return -ENODEV;
149
}
150
static int amdgpu_bo_alloc(amdgpu_device_handle dev,
151
struct amdgpu_bo_alloc_request *alloc_buffer,
152
amdgpu_bo_handle *buf_handle)
153
{
154
return -EINVAL;
155
}
156
static int amdgpu_bo_free(amdgpu_bo_handle buf_handle)
157
{
158
return -EINVAL;
159
}
160
static int amdgpu_query_buffer_size_alignment(amdgpu_device_handle dev,
161
struct amdgpu_buffer_size_alignments
162
*info)
163
{
164
return -EINVAL;
165
}
166
static int amdgpu_query_firmware_version(amdgpu_device_handle dev, unsigned fw_type,
167
unsigned ip_instance, unsigned index,
168
uint32_t *version, uint32_t *feature)
169
{
170
return -EINVAL;
171
}
172
static int amdgpu_query_hw_ip_info(amdgpu_device_handle dev, unsigned type,
173
unsigned ip_instance,
174
struct drm_amdgpu_info_hw_ip *info)
175
{
176
return -EINVAL;
177
}
178
static int amdgpu_query_heap_info(amdgpu_device_handle dev, uint32_t heap,
179
uint32_t flags, struct amdgpu_heap_info *info)
180
{
181
return -EINVAL;
182
}
183
static int amdgpu_query_gpu_info(amdgpu_device_handle dev,
184
struct amdgpu_gpu_info *info)
185
{
186
return -EINVAL;
187
}
188
static int amdgpu_query_info(amdgpu_device_handle dev, unsigned info_id,
189
unsigned size, void *value)
190
{
191
return -EINVAL;
192
}
193
static int amdgpu_query_sw_info(amdgpu_device_handle dev, enum amdgpu_sw_info info,
194
void *value)
195
{
196
return -EINVAL;
197
}
198
static int amdgpu_query_gds_info(amdgpu_device_handle dev,
199
struct amdgpu_gds_resource_info *gds_info)
200
{
201
return -EINVAL;
202
}
203
static int amdgpu_query_video_caps_info(amdgpu_device_handle dev, unsigned cap_type,
204
unsigned size, void *value)
205
{
206
return -EINVAL;
207
}
208
static const char *amdgpu_get_marketing_name(amdgpu_device_handle dev)
209
{
210
return NULL;
211
}
212
#else
213
#include "drm-uapi/amdgpu_drm.h"
214
#include <amdgpu.h>
215
#include <xf86drm.h>
216
#endif
217
218
#define CIK_TILE_MODE_COLOR_2D 14
219
220
#define CIK__GB_TILE_MODE__PIPE_CONFIG(x) (((x) >> 6) & 0x1f)
221
#define CIK__PIPE_CONFIG__ADDR_SURF_P2 0
222
#define CIK__PIPE_CONFIG__ADDR_SURF_P4_8x16 4
223
#define CIK__PIPE_CONFIG__ADDR_SURF_P4_16x16 5
224
#define CIK__PIPE_CONFIG__ADDR_SURF_P4_16x32 6
225
#define CIK__PIPE_CONFIG__ADDR_SURF_P4_32x32 7
226
#define CIK__PIPE_CONFIG__ADDR_SURF_P8_16x16_8x16 8
227
#define CIK__PIPE_CONFIG__ADDR_SURF_P8_16x32_8x16 9
228
#define CIK__PIPE_CONFIG__ADDR_SURF_P8_32x32_8x16 10
229
#define CIK__PIPE_CONFIG__ADDR_SURF_P8_16x32_16x16 11
230
#define CIK__PIPE_CONFIG__ADDR_SURF_P8_32x32_16x16 12
231
#define CIK__PIPE_CONFIG__ADDR_SURF_P8_32x32_16x32 13
232
#define CIK__PIPE_CONFIG__ADDR_SURF_P8_32x64_32x32 14
233
#define CIK__PIPE_CONFIG__ADDR_SURF_P16_32X32_8X16 16
234
#define CIK__PIPE_CONFIG__ADDR_SURF_P16_32X32_16X16 17
235
236
static unsigned cik_get_num_tile_pipes(struct amdgpu_gpu_info *info)
237
{
238
unsigned mode2d = info->gb_tile_mode[CIK_TILE_MODE_COLOR_2D];
239
240
switch (CIK__GB_TILE_MODE__PIPE_CONFIG(mode2d)) {
241
case CIK__PIPE_CONFIG__ADDR_SURF_P2:
242
return 2;
243
case CIK__PIPE_CONFIG__ADDR_SURF_P4_8x16:
244
case CIK__PIPE_CONFIG__ADDR_SURF_P4_16x16:
245
case CIK__PIPE_CONFIG__ADDR_SURF_P4_16x32:
246
case CIK__PIPE_CONFIG__ADDR_SURF_P4_32x32:
247
return 4;
248
case CIK__PIPE_CONFIG__ADDR_SURF_P8_16x16_8x16:
249
case CIK__PIPE_CONFIG__ADDR_SURF_P8_16x32_8x16:
250
case CIK__PIPE_CONFIG__ADDR_SURF_P8_32x32_8x16:
251
case CIK__PIPE_CONFIG__ADDR_SURF_P8_16x32_16x16:
252
case CIK__PIPE_CONFIG__ADDR_SURF_P8_32x32_16x16:
253
case CIK__PIPE_CONFIG__ADDR_SURF_P8_32x32_16x32:
254
case CIK__PIPE_CONFIG__ADDR_SURF_P8_32x64_32x32:
255
return 8;
256
case CIK__PIPE_CONFIG__ADDR_SURF_P16_32X32_8X16:
257
case CIK__PIPE_CONFIG__ADDR_SURF_P16_32X32_16X16:
258
return 16;
259
default:
260
fprintf(stderr, "Invalid GFX7 pipe configuration, assuming P2\n");
261
assert(!"this should never occur");
262
return 2;
263
}
264
}
265
266
static bool has_syncobj(int fd)
267
{
268
uint64_t value;
269
if (drmGetCap(fd, DRM_CAP_SYNCOBJ, &value))
270
return false;
271
return value ? true : false;
272
}
273
274
static bool has_timeline_syncobj(int fd)
275
{
276
uint64_t value;
277
if (drmGetCap(fd, DRM_CAP_SYNCOBJ_TIMELINE, &value))
278
return false;
279
return value ? true : false;
280
}
281
282
static bool has_modifiers(int fd)
283
{
284
uint64_t value;
285
if (drmGetCap(fd, DRM_CAP_ADDFB2_MODIFIERS, &value))
286
return false;
287
return value ? true : false;
288
}
289
290
static uint64_t fix_vram_size(uint64_t size)
291
{
292
/* The VRAM size is underreported, so we need to fix it, because
293
* it's used to compute the number of memory modules for harvesting.
294
*/
295
return align64(size, 256 * 1024 * 1024);
296
}
297
298
static bool
299
has_tmz_support(amdgpu_device_handle dev,
300
struct radeon_info *info,
301
struct amdgpu_gpu_info *amdinfo)
302
{
303
struct amdgpu_bo_alloc_request request = {0};
304
int r;
305
amdgpu_bo_handle bo;
306
307
if (amdinfo->ids_flags & AMDGPU_IDS_FLAGS_TMZ)
308
return true;
309
310
/* AMDGPU_IDS_FLAGS_TMZ is supported starting from drm_minor 40 */
311
if (info->drm_minor >= 40)
312
return false;
313
314
/* Find out ourselves if TMZ is enabled */
315
if (info->chip_class < GFX9)
316
return false;
317
318
if (info->drm_minor < 36)
319
return false;
320
321
request.alloc_size = 256;
322
request.phys_alignment = 1024;
323
request.preferred_heap = AMDGPU_GEM_DOMAIN_VRAM;
324
request.flags = AMDGPU_GEM_CREATE_ENCRYPTED;
325
r = amdgpu_bo_alloc(dev, &request, &bo);
326
if (r)
327
return false;
328
amdgpu_bo_free(bo);
329
return true;
330
}
331
332
333
bool ac_query_gpu_info(int fd, void *dev_p, struct radeon_info *info,
334
struct amdgpu_gpu_info *amdinfo)
335
{
336
struct drm_amdgpu_info_device device_info = {0};
337
struct amdgpu_buffer_size_alignments alignment_info = {0};
338
struct drm_amdgpu_info_hw_ip dma = {0}, compute = {0}, uvd = {0};
339
struct drm_amdgpu_info_hw_ip uvd_enc = {0}, vce = {0}, vcn_dec = {0}, vcn_jpeg = {0};
340
struct drm_amdgpu_info_hw_ip vcn_enc = {0}, gfx = {0};
341
struct amdgpu_gds_resource_info gds = {0};
342
uint32_t vce_version = 0, vce_feature = 0, uvd_version = 0, uvd_feature = 0;
343
int r, i, j;
344
amdgpu_device_handle dev = dev_p;
345
drmDevicePtr devinfo;
346
347
/* Get PCI info. */
348
r = drmGetDevice2(fd, 0, &devinfo);
349
if (r) {
350
fprintf(stderr, "amdgpu: drmGetDevice2 failed.\n");
351
return false;
352
}
353
info->pci_domain = devinfo->businfo.pci->domain;
354
info->pci_bus = devinfo->businfo.pci->bus;
355
info->pci_dev = devinfo->businfo.pci->dev;
356
info->pci_func = devinfo->businfo.pci->func;
357
drmFreeDevice(&devinfo);
358
359
assert(info->drm_major == 3);
360
info->is_amdgpu = true;
361
362
/* Query hardware and driver information. */
363
r = amdgpu_query_gpu_info(dev, amdinfo);
364
if (r) {
365
fprintf(stderr, "amdgpu: amdgpu_query_gpu_info failed.\n");
366
return false;
367
}
368
369
r = amdgpu_query_info(dev, AMDGPU_INFO_DEV_INFO, sizeof(device_info), &device_info);
370
if (r) {
371
fprintf(stderr, "amdgpu: amdgpu_query_info(dev_info) failed.\n");
372
return false;
373
}
374
375
r = amdgpu_query_buffer_size_alignment(dev, &alignment_info);
376
if (r) {
377
fprintf(stderr, "amdgpu: amdgpu_query_buffer_size_alignment failed.\n");
378
return false;
379
}
380
381
r = amdgpu_query_hw_ip_info(dev, AMDGPU_HW_IP_DMA, 0, &dma);
382
if (r) {
383
fprintf(stderr, "amdgpu: amdgpu_query_hw_ip_info(dma) failed.\n");
384
return false;
385
}
386
387
r = amdgpu_query_hw_ip_info(dev, AMDGPU_HW_IP_GFX, 0, &gfx);
388
if (r) {
389
fprintf(stderr, "amdgpu: amdgpu_query_hw_ip_info(gfx) failed.\n");
390
return false;
391
}
392
393
r = amdgpu_query_hw_ip_info(dev, AMDGPU_HW_IP_COMPUTE, 0, &compute);
394
if (r) {
395
fprintf(stderr, "amdgpu: amdgpu_query_hw_ip_info(compute) failed.\n");
396
return false;
397
}
398
399
r = amdgpu_query_hw_ip_info(dev, AMDGPU_HW_IP_UVD, 0, &uvd);
400
if (r) {
401
fprintf(stderr, "amdgpu: amdgpu_query_hw_ip_info(uvd) failed.\n");
402
return false;
403
}
404
405
if (info->drm_minor >= 17) {
406
r = amdgpu_query_hw_ip_info(dev, AMDGPU_HW_IP_UVD_ENC, 0, &uvd_enc);
407
if (r) {
408
fprintf(stderr, "amdgpu: amdgpu_query_hw_ip_info(uvd_enc) failed.\n");
409
return false;
410
}
411
}
412
413
if (info->drm_minor >= 17) {
414
r = amdgpu_query_hw_ip_info(dev, AMDGPU_HW_IP_VCN_DEC, 0, &vcn_dec);
415
if (r) {
416
fprintf(stderr, "amdgpu: amdgpu_query_hw_ip_info(vcn_dec) failed.\n");
417
return false;
418
}
419
}
420
421
if (info->drm_minor >= 17) {
422
r = amdgpu_query_hw_ip_info(dev, AMDGPU_HW_IP_VCN_ENC, 0, &vcn_enc);
423
if (r) {
424
fprintf(stderr, "amdgpu: amdgpu_query_hw_ip_info(vcn_enc) failed.\n");
425
return false;
426
}
427
}
428
429
if (info->drm_minor >= 27) {
430
r = amdgpu_query_hw_ip_info(dev, AMDGPU_HW_IP_VCN_JPEG, 0, &vcn_jpeg);
431
if (r) {
432
fprintf(stderr, "amdgpu: amdgpu_query_hw_ip_info(vcn_jpeg) failed.\n");
433
return false;
434
}
435
}
436
437
r = amdgpu_query_firmware_version(dev, AMDGPU_INFO_FW_GFX_ME, 0, 0, &info->me_fw_version,
438
&info->me_fw_feature);
439
if (r) {
440
fprintf(stderr, "amdgpu: amdgpu_query_firmware_version(me) failed.\n");
441
return false;
442
}
443
444
r = amdgpu_query_firmware_version(dev, AMDGPU_INFO_FW_GFX_PFP, 0, 0, &info->pfp_fw_version,
445
&info->pfp_fw_feature);
446
if (r) {
447
fprintf(stderr, "amdgpu: amdgpu_query_firmware_version(pfp) failed.\n");
448
return false;
449
}
450
451
r = amdgpu_query_firmware_version(dev, AMDGPU_INFO_FW_GFX_CE, 0, 0, &info->ce_fw_version,
452
&info->ce_fw_feature);
453
if (r) {
454
fprintf(stderr, "amdgpu: amdgpu_query_firmware_version(ce) failed.\n");
455
return false;
456
}
457
458
r = amdgpu_query_firmware_version(dev, AMDGPU_INFO_FW_UVD, 0, 0, &uvd_version, &uvd_feature);
459
if (r) {
460
fprintf(stderr, "amdgpu: amdgpu_query_firmware_version(uvd) failed.\n");
461
return false;
462
}
463
464
r = amdgpu_query_hw_ip_info(dev, AMDGPU_HW_IP_VCE, 0, &vce);
465
if (r) {
466
fprintf(stderr, "amdgpu: amdgpu_query_hw_ip_info(vce) failed.\n");
467
return false;
468
}
469
470
r = amdgpu_query_firmware_version(dev, AMDGPU_INFO_FW_VCE, 0, 0, &vce_version, &vce_feature);
471
if (r) {
472
fprintf(stderr, "amdgpu: amdgpu_query_firmware_version(vce) failed.\n");
473
return false;
474
}
475
476
r = amdgpu_query_sw_info(dev, amdgpu_sw_info_address32_hi, &info->address32_hi);
477
if (r) {
478
fprintf(stderr, "amdgpu: amdgpu_query_sw_info(address32_hi) failed.\n");
479
return false;
480
}
481
482
r = amdgpu_query_gds_info(dev, &gds);
483
if (r) {
484
fprintf(stderr, "amdgpu: amdgpu_query_gds_info failed.\n");
485
return false;
486
}
487
488
if (info->drm_minor >= 9) {
489
struct drm_amdgpu_memory_info meminfo = {0};
490
491
r = amdgpu_query_info(dev, AMDGPU_INFO_MEMORY, sizeof(meminfo), &meminfo);
492
if (r) {
493
fprintf(stderr, "amdgpu: amdgpu_query_info(memory) failed.\n");
494
return false;
495
}
496
497
/* Note: usable_heap_size values can be random and can't be relied on. */
498
info->gart_size = meminfo.gtt.total_heap_size;
499
info->vram_size = fix_vram_size(meminfo.vram.total_heap_size);
500
info->vram_vis_size = meminfo.cpu_accessible_vram.total_heap_size;
501
} else {
502
/* This is a deprecated interface, which reports usable sizes
503
* (total minus pinned), but the pinned size computation is
504
* buggy, so the values returned from these functions can be
505
* random.
506
*/
507
struct amdgpu_heap_info vram, vram_vis, gtt;
508
509
r = amdgpu_query_heap_info(dev, AMDGPU_GEM_DOMAIN_VRAM, 0, &vram);
510
if (r) {
511
fprintf(stderr, "amdgpu: amdgpu_query_heap_info(vram) failed.\n");
512
return false;
513
}
514
515
r = amdgpu_query_heap_info(dev, AMDGPU_GEM_DOMAIN_VRAM, AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED,
516
&vram_vis);
517
if (r) {
518
fprintf(stderr, "amdgpu: amdgpu_query_heap_info(vram_vis) failed.\n");
519
return false;
520
}
521
522
r = amdgpu_query_heap_info(dev, AMDGPU_GEM_DOMAIN_GTT, 0, &gtt);
523
if (r) {
524
fprintf(stderr, "amdgpu: amdgpu_query_heap_info(gtt) failed.\n");
525
return false;
526
}
527
528
info->gart_size = gtt.heap_size;
529
info->vram_size = fix_vram_size(vram.heap_size);
530
info->vram_vis_size = vram_vis.heap_size;
531
}
532
533
info->gart_size_kb = DIV_ROUND_UP(info->gart_size, 1024);
534
info->vram_size_kb = DIV_ROUND_UP(info->vram_size, 1024);
535
536
if (info->drm_minor >= 41) {
537
r = amdgpu_query_video_caps_info(dev, AMDGPU_INFO_VIDEO_CAPS_DECODE,
538
sizeof(info->dec_caps), &(info->dec_caps));
539
if (r) {
540
fprintf(stderr, "amdgpu: amdgpu_query_video_caps_info for decode failed.\n");
541
return r;
542
}
543
544
r = amdgpu_query_video_caps_info(dev, AMDGPU_INFO_VIDEO_CAPS_ENCODE,
545
sizeof(info->enc_caps), &(info->enc_caps));
546
if (r) {
547
fprintf(stderr, "amdgpu: amdgpu_query_video_caps_info for encode failed.\n");
548
return r;
549
}
550
}
551
552
/* Add some margin of error, though this shouldn't be needed in theory. */
553
info->all_vram_visible = info->vram_size * 0.9 < info->vram_vis_size;
554
555
util_cpu_detect();
556
info->smart_access_memory = info->all_vram_visible &&
557
info->chip_class >= GFX10_3 &&
558
util_get_cpu_caps()->family >= CPU_AMD_ZEN3 &&
559
util_get_cpu_caps()->family < CPU_AMD_LAST;
560
561
/* Set chip identification. */
562
info->pci_id = amdinfo->asic_id; /* TODO: is this correct? */
563
info->pci_rev_id = amdinfo->pci_rev_id;
564
info->vce_harvest_config = amdinfo->vce_harvest_config;
565
566
#define identify_chip2(asic, chipname) \
567
if (ASICREV_IS(amdinfo->chip_external_rev, asic)) { \
568
info->family = CHIP_##chipname; \
569
info->name = #chipname; \
570
}
571
#define identify_chip(chipname) identify_chip2(chipname, chipname)
572
573
switch (amdinfo->family_id) {
574
case FAMILY_SI:
575
identify_chip(TAHITI);
576
identify_chip(PITCAIRN);
577
identify_chip2(CAPEVERDE, VERDE);
578
identify_chip(OLAND);
579
identify_chip(HAINAN);
580
break;
581
case FAMILY_CI:
582
identify_chip(BONAIRE);
583
identify_chip(HAWAII);
584
break;
585
case FAMILY_KV:
586
identify_chip2(SPECTRE, KAVERI);
587
identify_chip2(SPOOKY, KAVERI);
588
identify_chip2(KALINDI, KABINI);
589
identify_chip2(GODAVARI, KABINI);
590
break;
591
case FAMILY_VI:
592
identify_chip(ICELAND);
593
identify_chip(TONGA);
594
identify_chip(FIJI);
595
identify_chip(POLARIS10);
596
identify_chip(POLARIS11);
597
identify_chip(POLARIS12);
598
identify_chip(VEGAM);
599
break;
600
case FAMILY_CZ:
601
identify_chip(CARRIZO);
602
identify_chip(STONEY);
603
break;
604
case FAMILY_AI:
605
identify_chip(VEGA10);
606
identify_chip(VEGA12);
607
identify_chip(VEGA20);
608
identify_chip(ARCTURUS);
609
identify_chip(ALDEBARAN);
610
break;
611
case FAMILY_RV:
612
identify_chip(RAVEN);
613
identify_chip(RAVEN2);
614
identify_chip(RENOIR);
615
break;
616
case FAMILY_NV:
617
identify_chip(NAVI10);
618
identify_chip(NAVI12);
619
identify_chip(NAVI14);
620
identify_chip(SIENNA_CICHLID);
621
identify_chip(NAVY_FLOUNDER);
622
identify_chip(DIMGREY_CAVEFISH);
623
identify_chip(BEIGE_GOBY);
624
break;
625
case FAMILY_VGH:
626
identify_chip(VANGOGH);
627
break;
628
case FAMILY_YC:
629
identify_chip(YELLOW_CARP);
630
break;
631
}
632
633
if (!info->name) {
634
fprintf(stderr, "amdgpu: unknown (family_id, chip_external_rev): (%u, %u)\n",
635
amdinfo->family_id, amdinfo->chip_external_rev);
636
return false;
637
}
638
639
if (info->family >= CHIP_SIENNA_CICHLID)
640
info->chip_class = GFX10_3;
641
else if (info->family >= CHIP_NAVI10)
642
info->chip_class = GFX10;
643
else if (info->family >= CHIP_VEGA10)
644
info->chip_class = GFX9;
645
else if (info->family >= CHIP_TONGA)
646
info->chip_class = GFX8;
647
else if (info->family >= CHIP_BONAIRE)
648
info->chip_class = GFX7;
649
else if (info->family >= CHIP_TAHITI)
650
info->chip_class = GFX6;
651
else {
652
fprintf(stderr, "amdgpu: Unknown family.\n");
653
return false;
654
}
655
656
info->family_id = amdinfo->family_id;
657
info->chip_external_rev = amdinfo->chip_external_rev;
658
info->marketing_name = amdgpu_get_marketing_name(dev);
659
info->is_pro_graphics = info->marketing_name && (strstr(info->marketing_name, "Pro") ||
660
strstr(info->marketing_name, "PRO") ||
661
strstr(info->marketing_name, "Frontier"));
662
663
/* Set which chips have dedicated VRAM. */
664
info->has_dedicated_vram = !(amdinfo->ids_flags & AMDGPU_IDS_FLAGS_FUSION);
665
666
/* The kernel can split large buffers in VRAM but not in GTT, so large
667
* allocations can fail or cause buffer movement failures in the kernel.
668
*/
669
if (info->has_dedicated_vram)
670
info->max_alloc_size = info->vram_size * 0.8;
671
else
672
info->max_alloc_size = info->gart_size * 0.7;
673
674
info->vram_type = amdinfo->vram_type;
675
info->vram_bit_width = amdinfo->vram_bit_width;
676
info->ce_ram_size = amdinfo->ce_ram_size;
677
678
/* Set which chips have uncached device memory. */
679
info->has_l2_uncached = info->chip_class >= GFX9;
680
681
/* Set hardware information. */
682
info->gds_size = gds.gds_total_size;
683
info->gds_gfx_partition_size = gds.gds_gfx_partition_size;
684
/* convert the shader/memory clocks from KHz to MHz */
685
info->max_shader_clock = amdinfo->max_engine_clk / 1000;
686
info->max_memory_clock = amdinfo->max_memory_clk / 1000;
687
info->max_tcc_blocks = device_info.num_tcc_blocks;
688
info->max_se = amdinfo->num_shader_engines;
689
info->max_sa_per_se = amdinfo->num_shader_arrays_per_engine;
690
info->uvd_fw_version = uvd.available_rings ? uvd_version : 0;
691
info->vce_fw_version = vce.available_rings ? vce_version : 0;
692
info->has_video_hw.uvd_decode = uvd.available_rings != 0;
693
info->has_video_hw.vcn_decode = vcn_dec.available_rings != 0;
694
info->has_video_hw.jpeg_decode = vcn_jpeg.available_rings != 0;
695
info->has_video_hw.vce_encode = vce.available_rings != 0;
696
info->has_video_hw.uvd_encode = uvd_enc.available_rings != 0;
697
info->has_video_hw.vcn_encode = vcn_enc.available_rings != 0;
698
info->has_userptr = true;
699
info->has_syncobj = has_syncobj(fd);
700
info->has_timeline_syncobj = has_timeline_syncobj(fd);
701
info->has_fence_to_handle = info->has_syncobj && info->drm_minor >= 21;
702
info->has_local_buffers = info->drm_minor >= 20;
703
info->kernel_flushes_hdp_before_ib = true;
704
info->htile_cmask_support_1d_tiling = true;
705
info->si_TA_CS_BC_BASE_ADDR_allowed = true;
706
info->has_bo_metadata = true;
707
info->has_gpu_reset_status_query = true;
708
info->has_eqaa_surface_allocator = true;
709
info->has_format_bc1_through_bc7 = true;
710
/* DRM 3.1.0 doesn't flush TC for GFX8 correctly. */
711
info->kernel_flushes_tc_l2_after_ib = info->chip_class != GFX8 || info->drm_minor >= 2;
712
info->has_indirect_compute_dispatch = true;
713
/* GFX6 doesn't support unaligned loads. */
714
info->has_unaligned_shader_loads = info->chip_class != GFX6;
715
/* Disable sparse mappings on GFX6 due to VM faults in CP DMA. Enable them once
716
* these faults are mitigated in software.
717
*/
718
info->has_sparse_vm_mappings = info->chip_class >= GFX7 && info->drm_minor >= 13;
719
info->has_2d_tiling = true;
720
info->has_read_registers_query = true;
721
info->has_scheduled_fence_dependency = info->drm_minor >= 28;
722
info->mid_command_buffer_preemption_enabled = amdinfo->ids_flags & AMDGPU_IDS_FLAGS_PREEMPTION;
723
info->has_tmz_support = has_tmz_support(dev, info, amdinfo);
724
info->kernel_has_modifiers = has_modifiers(fd);
725
info->has_graphics = gfx.available_rings > 0;
726
727
info->pa_sc_tile_steering_override = device_info.pa_sc_tile_steering_override;
728
info->max_render_backends = amdinfo->rb_pipes;
729
/* The value returned by the kernel driver was wrong. */
730
if (info->family == CHIP_KAVERI)
731
info->max_render_backends = 2;
732
733
/* Guess the number of enabled SEs because the kernel doesn't tell us. */
734
if (info->chip_class >= GFX10_3 && info->max_se > 1) {
735
unsigned num_rbs_per_se = info->max_render_backends / info->max_se;
736
info->num_se = util_bitcount(amdinfo->enabled_rb_pipes_mask) / num_rbs_per_se;
737
} else {
738
info->num_se = info->max_se;
739
}
740
741
info->clock_crystal_freq = amdinfo->gpu_counter_freq;
742
if (!info->clock_crystal_freq) {
743
fprintf(stderr, "amdgpu: clock crystal frequency is 0, timestamps will be wrong\n");
744
info->clock_crystal_freq = 1;
745
}
746
if (info->chip_class >= GFX10) {
747
info->tcc_cache_line_size = 128;
748
749
if (info->drm_minor >= 35) {
750
info->num_tcc_blocks = info->max_tcc_blocks - util_bitcount64(device_info.tcc_disabled_mask);
751
} else {
752
/* This is a hack, but it's all we can do without a kernel upgrade. */
753
info->num_tcc_blocks = info->vram_size / (512 * 1024 * 1024);
754
if (info->num_tcc_blocks > info->max_tcc_blocks)
755
info->num_tcc_blocks /= 2;
756
}
757
} else {
758
if (!info->has_graphics && info->family >= CHIP_ALDEBARAN)
759
info->tcc_cache_line_size = 128;
760
else
761
info->tcc_cache_line_size = 64;
762
763
info->num_tcc_blocks = info->max_tcc_blocks;
764
}
765
766
info->tcc_rb_non_coherent = !util_is_power_of_two_or_zero(info->num_tcc_blocks);
767
768
switch (info->family) {
769
case CHIP_TAHITI:
770
case CHIP_PITCAIRN:
771
case CHIP_OLAND:
772
case CHIP_HAWAII:
773
case CHIP_KABINI:
774
case CHIP_TONGA:
775
case CHIP_STONEY:
776
case CHIP_RAVEN2:
777
info->l2_cache_size = info->num_tcc_blocks * 64 * 1024;
778
break;
779
case CHIP_VERDE:
780
case CHIP_HAINAN:
781
case CHIP_BONAIRE:
782
case CHIP_KAVERI:
783
case CHIP_ICELAND:
784
case CHIP_CARRIZO:
785
case CHIP_FIJI:
786
case CHIP_POLARIS12:
787
case CHIP_VEGAM:
788
info->l2_cache_size = info->num_tcc_blocks * 128 * 1024;
789
break;
790
default:
791
info->l2_cache_size = info->num_tcc_blocks * 256 * 1024;
792
break;
793
}
794
795
info->l1_cache_size = 16384;
796
797
info->mc_arb_ramcfg = amdinfo->mc_arb_ramcfg;
798
info->gb_addr_config = amdinfo->gb_addr_cfg;
799
if (info->chip_class >= GFX9) {
800
info->num_tile_pipes = 1 << G_0098F8_NUM_PIPES(amdinfo->gb_addr_cfg);
801
info->pipe_interleave_bytes = 256 << G_0098F8_PIPE_INTERLEAVE_SIZE_GFX9(amdinfo->gb_addr_cfg);
802
} else {
803
info->num_tile_pipes = cik_get_num_tile_pipes(amdinfo);
804
info->pipe_interleave_bytes = 256 << G_0098F8_PIPE_INTERLEAVE_SIZE_GFX6(amdinfo->gb_addr_cfg);
805
}
806
info->r600_has_virtual_memory = true;
807
808
/* LDS is 64KB per CU (4 SIMDs), which is 16KB per SIMD (usage above
809
* 16KB makes some SIMDs unoccupied).
810
*
811
* LDS is 128KB in WGP mode and 64KB in CU mode. Assume the WGP mode is used.
812
*/
813
info->lds_size_per_workgroup = info->chip_class >= GFX10 ? 128 * 1024 : 64 * 1024;
814
/* lds_encode_granularity is the block size used for encoding registers.
815
* lds_alloc_granularity is what the hardware will align the LDS size to.
816
*/
817
info->lds_encode_granularity = info->chip_class >= GFX7 ? 128 * 4 : 64 * 4;
818
info->lds_alloc_granularity = info->chip_class >= GFX10_3 ? 256 * 4 : info->lds_encode_granularity;
819
820
assert(util_is_power_of_two_or_zero(dma.available_rings + 1));
821
assert(util_is_power_of_two_or_zero(compute.available_rings + 1));
822
823
info->num_rings[RING_GFX] = util_bitcount(gfx.available_rings);
824
info->num_rings[RING_COMPUTE] = util_bitcount(compute.available_rings);
825
info->num_rings[RING_DMA] = util_bitcount(dma.available_rings);
826
info->num_rings[RING_UVD] = util_bitcount(uvd.available_rings);
827
info->num_rings[RING_VCE] = util_bitcount(vce.available_rings);
828
info->num_rings[RING_UVD_ENC] = util_bitcount(uvd_enc.available_rings);
829
info->num_rings[RING_VCN_DEC] = util_bitcount(vcn_dec.available_rings);
830
info->num_rings[RING_VCN_ENC] = util_bitcount(vcn_enc.available_rings);
831
info->num_rings[RING_VCN_JPEG] = util_bitcount(vcn_jpeg.available_rings);
832
833
/* This is "align_mask" copied from the kernel, maximums of all IP versions. */
834
info->ib_pad_dw_mask[RING_GFX] = 0xff;
835
info->ib_pad_dw_mask[RING_COMPUTE] = 0xff;
836
info->ib_pad_dw_mask[RING_DMA] = 0xf;
837
info->ib_pad_dw_mask[RING_UVD] = 0xf;
838
info->ib_pad_dw_mask[RING_VCE] = 0x3f;
839
info->ib_pad_dw_mask[RING_UVD_ENC] = 0x3f;
840
info->ib_pad_dw_mask[RING_VCN_DEC] = 0xf;
841
info->ib_pad_dw_mask[RING_VCN_ENC] = 0x3f;
842
info->ib_pad_dw_mask[RING_VCN_JPEG] = 0xf;
843
844
/* The mere presence of CLEAR_STATE in the IB causes random GPU hangs
845
* on GFX6. Some CLEAR_STATE cause asic hang on radeon kernel, etc.
846
* SPI_VS_OUT_CONFIG. So only enable GFX7 CLEAR_STATE on amdgpu kernel.
847
*/
848
info->has_clear_state = info->chip_class >= GFX7;
849
850
info->has_distributed_tess =
851
info->chip_class >= GFX10 || (info->chip_class >= GFX8 && info->max_se >= 2);
852
853
info->has_dcc_constant_encode =
854
info->family == CHIP_RAVEN2 || info->family == CHIP_RENOIR || info->chip_class >= GFX10;
855
856
info->has_rbplus = info->family == CHIP_STONEY || info->chip_class >= GFX9;
857
858
/* Some chips have RB+ registers, but don't support RB+. Those must
859
* always disable it.
860
*/
861
info->rbplus_allowed =
862
info->has_rbplus &&
863
(info->family == CHIP_STONEY || info->family == CHIP_VEGA12 || info->family == CHIP_RAVEN ||
864
info->family == CHIP_RAVEN2 || info->family == CHIP_RENOIR || info->chip_class >= GFX10_3);
865
866
info->has_out_of_order_rast =
867
info->chip_class >= GFX8 && info->chip_class <= GFX9 && info->max_se >= 2;
868
869
/* Whether chips support double rate packed math instructions. */
870
info->has_packed_math_16bit = info->chip_class >= GFX9;
871
872
/* TODO: Figure out how to use LOAD_CONTEXT_REG on GFX6-GFX7. */
873
info->has_load_ctx_reg_pkt =
874
info->chip_class >= GFX9 || (info->chip_class >= GFX8 && info->me_fw_feature >= 41);
875
876
info->cpdma_prefetch_writes_memory = info->chip_class <= GFX8;
877
878
info->has_gfx9_scissor_bug = info->family == CHIP_VEGA10 || info->family == CHIP_RAVEN;
879
880
info->has_tc_compat_zrange_bug = info->chip_class >= GFX8 && info->chip_class <= GFX9;
881
882
info->has_msaa_sample_loc_bug =
883
(info->family >= CHIP_POLARIS10 && info->family <= CHIP_POLARIS12) ||
884
info->family == CHIP_VEGA10 || info->family == CHIP_RAVEN;
885
886
info->has_ls_vgpr_init_bug = info->family == CHIP_VEGA10 || info->family == CHIP_RAVEN;
887
888
/* Drawing from 0-sized index buffers causes hangs on gfx10. */
889
info->has_zero_index_buffer_bug = info->chip_class == GFX10;
890
891
/* Whether chips are affected by the image load/sample/gather hw bug when
892
* DCC is enabled (ie. WRITE_COMPRESS_ENABLE should be 0).
893
*/
894
info->has_image_load_dcc_bug = info->family == CHIP_DIMGREY_CAVEFISH ||
895
info->family == CHIP_VANGOGH ||
896
info->family == CHIP_YELLOW_CARP;
897
898
/* DB has a bug when ITERATE_256 is set to 1 that can cause a hang. The
899
* workaround is to set DECOMPRESS_ON_Z_PLANES to 2 for 4X MSAA D/S images.
900
*/
901
info->has_two_planes_iterate256_bug = info->chip_class == GFX10;
902
903
/* GE has a bug when a legacy GS draw follows an NGG draw and it requires
904
* a VGT_FLUSH to fix that.
905
*/
906
info->has_vgt_flush_ngg_legacy_bug = info->chip_class == GFX10 ||
907
info->family == CHIP_SIENNA_CICHLID;
908
909
/* HW bug workaround when CS threadgroups > 256 threads and async compute
910
* isn't used, i.e. only one compute job can run at a time. If async
911
* compute is possible, the threadgroup size must be limited to 256 threads
912
* on all queues to avoid the bug.
913
* Only GFX6 and certain GFX7 chips are affected.
914
*
915
* FIXME: RADV doesn't limit the number of threads for async compute.
916
*/
917
info->has_cs_regalloc_hang_bug = info->chip_class == GFX6 ||
918
info->family == CHIP_BONAIRE ||
919
info->family == CHIP_KABINI;
920
921
/* Support for GFX10.3 was added with F32_ME_FEATURE_VERSION_31 but the
922
* feature version wasn't bumped.
923
*/
924
info->has_32bit_predication = (info->chip_class >= GFX10 &&
925
info->me_fw_feature >= 32) ||
926
(info->chip_class == GFX9 &&
927
info->me_fw_feature >= 52);
928
929
/* Get the number of good compute units. */
930
info->num_good_compute_units = 0;
931
for (i = 0; i < info->max_se; i++) {
932
for (j = 0; j < info->max_sa_per_se; j++) {
933
/*
934
* The cu bitmap in amd gpu info structure is
935
* 4x4 size array, and it's usually suitable for Vega
936
* ASICs which has 4*2 SE/SH layout.
937
* But for Arcturus, SE/SH layout is changed to 8*1.
938
* To mostly reduce the impact, we make it compatible
939
* with current bitmap array as below:
940
* SE4,SH0 --> cu_bitmap[0][1]
941
* SE5,SH0 --> cu_bitmap[1][1]
942
* SE6,SH0 --> cu_bitmap[2][1]
943
* SE7,SH0 --> cu_bitmap[3][1]
944
*/
945
info->cu_mask[i % 4][j + i / 4] = amdinfo->cu_bitmap[i % 4][j + i / 4];
946
info->num_good_compute_units += util_bitcount(info->cu_mask[i][j]);
947
}
948
}
949
950
/* On GFX10, only whole WGPs (in units of 2 CUs) can be disabled,
951
* and max - min <= 2.
952
*/
953
unsigned cu_group = info->chip_class >= GFX10 ? 2 : 1;
954
info->max_good_cu_per_sa =
955
DIV_ROUND_UP(info->num_good_compute_units, (info->num_se * info->max_sa_per_se * cu_group)) *
956
cu_group;
957
info->min_good_cu_per_sa =
958
(info->num_good_compute_units / (info->num_se * info->max_sa_per_se * cu_group)) * cu_group;
959
960
memcpy(info->si_tile_mode_array, amdinfo->gb_tile_mode, sizeof(amdinfo->gb_tile_mode));
961
info->enabled_rb_mask = amdinfo->enabled_rb_pipes_mask;
962
963
memcpy(info->cik_macrotile_mode_array, amdinfo->gb_macro_tile_mode,
964
sizeof(amdinfo->gb_macro_tile_mode));
965
966
info->pte_fragment_size = alignment_info.size_local;
967
info->gart_page_size = alignment_info.size_remote;
968
969
if (info->chip_class == GFX6)
970
info->gfx_ib_pad_with_type2 = true;
971
972
unsigned ib_align = 0;
973
ib_align = MAX2(ib_align, gfx.ib_start_alignment);
974
ib_align = MAX2(ib_align, gfx.ib_size_alignment);
975
ib_align = MAX2(ib_align, compute.ib_start_alignment);
976
ib_align = MAX2(ib_align, compute.ib_size_alignment);
977
ib_align = MAX2(ib_align, dma.ib_start_alignment);
978
ib_align = MAX2(ib_align, dma.ib_size_alignment);
979
ib_align = MAX2(ib_align, uvd.ib_start_alignment);
980
ib_align = MAX2(ib_align, uvd.ib_size_alignment);
981
ib_align = MAX2(ib_align, uvd_enc.ib_start_alignment);
982
ib_align = MAX2(ib_align, uvd_enc.ib_size_alignment);
983
ib_align = MAX2(ib_align, vce.ib_start_alignment);
984
ib_align = MAX2(ib_align, vce.ib_size_alignment);
985
ib_align = MAX2(ib_align, vcn_dec.ib_start_alignment);
986
ib_align = MAX2(ib_align, vcn_dec.ib_size_alignment);
987
ib_align = MAX2(ib_align, vcn_enc.ib_start_alignment);
988
ib_align = MAX2(ib_align, vcn_enc.ib_size_alignment);
989
ib_align = MAX2(ib_align, vcn_jpeg.ib_start_alignment);
990
ib_align = MAX2(ib_align, vcn_jpeg.ib_size_alignment);
991
/* GFX10 and maybe GFX9 need this alignment for cache coherency. */
992
if (info->chip_class >= GFX9)
993
ib_align = MAX2(ib_align, info->tcc_cache_line_size);
994
/* The kernel pads gfx and compute IBs to 256 dwords since:
995
* 66f3b2d527154bd258a57c8815004b5964aa1cf5
996
* Do the same.
997
*/
998
ib_align = MAX2(ib_align, 1024);
999
info->ib_alignment = ib_align;
1000
1001
if ((info->drm_minor >= 31 && (info->family == CHIP_RAVEN || info->family == CHIP_RAVEN2 ||
1002
info->family == CHIP_RENOIR)) ||
1003
(info->drm_minor >= 34 && (info->family == CHIP_NAVI12 || info->family == CHIP_NAVI14)) ||
1004
info->chip_class >= GFX10_3) {
1005
if (info->max_render_backends == 1)
1006
info->use_display_dcc_unaligned = true;
1007
else
1008
info->use_display_dcc_with_retile_blit = true;
1009
}
1010
1011
info->has_gds_ordered_append = info->chip_class >= GFX7 && info->drm_minor >= 29;
1012
1013
if (info->chip_class >= GFX9 && info->has_graphics) {
1014
unsigned pc_lines = 0;
1015
1016
switch (info->family) {
1017
case CHIP_VEGA10:
1018
case CHIP_VEGA12:
1019
case CHIP_VEGA20:
1020
pc_lines = 2048;
1021
break;
1022
case CHIP_RAVEN:
1023
case CHIP_RAVEN2:
1024
case CHIP_RENOIR:
1025
case CHIP_NAVI10:
1026
case CHIP_NAVI12:
1027
case CHIP_SIENNA_CICHLID:
1028
case CHIP_NAVY_FLOUNDER:
1029
case CHIP_DIMGREY_CAVEFISH:
1030
pc_lines = 1024;
1031
break;
1032
case CHIP_NAVI14:
1033
case CHIP_BEIGE_GOBY:
1034
pc_lines = 512;
1035
break;
1036
case CHIP_VANGOGH:
1037
case CHIP_YELLOW_CARP:
1038
pc_lines = 256;
1039
break;
1040
default:
1041
assert(0);
1042
}
1043
1044
info->pc_lines = pc_lines;
1045
1046
if (info->chip_class >= GFX10) {
1047
info->pbb_max_alloc_count = pc_lines / 3;
1048
} else {
1049
info->pbb_max_alloc_count = MIN2(128, pc_lines / (4 * info->max_se));
1050
}
1051
}
1052
1053
if (info->chip_class >= GFX10_3)
1054
info->max_wave64_per_simd = 16;
1055
else if (info->chip_class == GFX10)
1056
info->max_wave64_per_simd = 20;
1057
else if (info->family >= CHIP_POLARIS10 && info->family <= CHIP_VEGAM)
1058
info->max_wave64_per_simd = 8;
1059
else
1060
info->max_wave64_per_simd = 10;
1061
1062
if (info->chip_class >= GFX10) {
1063
info->num_physical_sgprs_per_simd = 128 * info->max_wave64_per_simd;
1064
info->min_sgpr_alloc = 128;
1065
info->sgpr_alloc_granularity = 128;
1066
info->use_late_alloc = info->min_good_cu_per_sa > 2;
1067
} else if (info->chip_class >= GFX8) {
1068
info->num_physical_sgprs_per_simd = 800;
1069
info->min_sgpr_alloc = 16;
1070
info->sgpr_alloc_granularity = 16;
1071
info->use_late_alloc = true;
1072
} else {
1073
info->num_physical_sgprs_per_simd = 512;
1074
info->min_sgpr_alloc = 8;
1075
info->sgpr_alloc_granularity = 8;
1076
/* Potential hang on Kabini: */
1077
info->use_late_alloc = info->family != CHIP_KABINI;
1078
}
1079
1080
info->has_3d_cube_border_color_mipmap = info->has_graphics || info->family == CHIP_ARCTURUS;
1081
info->max_sgpr_alloc = info->family == CHIP_TONGA || info->family == CHIP_ICELAND ? 96 : 104;
1082
1083
if (!info->has_graphics && info->family >= CHIP_ALDEBARAN) {
1084
info->min_wave64_vgpr_alloc = 8;
1085
info->max_vgpr_alloc = 512;
1086
info->wave64_vgpr_alloc_granularity = 8;
1087
} else {
1088
info->min_wave64_vgpr_alloc = 4;
1089
info->max_vgpr_alloc = 256;
1090
info->wave64_vgpr_alloc_granularity = 4;
1091
}
1092
1093
info->num_physical_wave64_vgprs_per_simd = info->chip_class >= GFX10 ? 512 : 256;
1094
info->num_simd_per_compute_unit = info->chip_class >= GFX10 ? 2 : 4;
1095
1096
return true;
1097
}
1098
1099
void ac_compute_driver_uuid(char *uuid, size_t size)
1100
{
1101
char amd_uuid[] = "AMD-MESA-DRV";
1102
1103
assert(size >= sizeof(amd_uuid));
1104
1105
memset(uuid, 0, size);
1106
strncpy(uuid, amd_uuid, size);
1107
}
1108
1109
void ac_compute_device_uuid(struct radeon_info *info, char *uuid, size_t size)
1110
{
1111
uint32_t *uint_uuid = (uint32_t *)uuid;
1112
1113
assert(size >= sizeof(uint32_t) * 4);
1114
1115
/**
1116
* Use the device info directly instead of using a sha1. GL/VK UUIDs
1117
* are 16 byte vs 20 byte for sha1, and the truncation that would be
1118
* required would get rid of part of the little entropy we have.
1119
* */
1120
memset(uuid, 0, size);
1121
uint_uuid[0] = info->pci_domain;
1122
uint_uuid[1] = info->pci_bus;
1123
uint_uuid[2] = info->pci_dev;
1124
uint_uuid[3] = info->pci_func;
1125
}
1126
1127
void ac_print_gpu_info(struct radeon_info *info, FILE *f)
1128
{
1129
fprintf(f, "Device info:\n");
1130
fprintf(f, " pci (domain:bus:dev.func): %04x:%02x:%02x.%x\n", info->pci_domain, info->pci_bus,
1131
info->pci_dev, info->pci_func);
1132
1133
fprintf(f, " name = %s\n", info->name);
1134
fprintf(f, " marketing_name = %s\n", info->marketing_name);
1135
fprintf(f, " is_pro_graphics = %u\n", info->is_pro_graphics);
1136
fprintf(f, " pci_id = 0x%x\n", info->pci_id);
1137
fprintf(f, " pci_rev_id = 0x%x\n", info->pci_rev_id);
1138
fprintf(f, " family = %i\n", info->family);
1139
fprintf(f, " chip_class = %i\n", info->chip_class);
1140
fprintf(f, " family_id = %i\n", info->family_id);
1141
fprintf(f, " chip_external_rev = %i\n", info->chip_external_rev);
1142
fprintf(f, " clock_crystal_freq = %i\n", info->clock_crystal_freq);
1143
1144
fprintf(f, "Features:\n");
1145
fprintf(f, " has_graphics = %i\n", info->has_graphics);
1146
fprintf(f, " num_rings[RING_GFX] = %i\n", info->num_rings[RING_GFX]);
1147
fprintf(f, " num_rings[RING_DMA] = %i\n", info->num_rings[RING_DMA]);
1148
fprintf(f, " num_rings[RING_COMPUTE] = %u\n", info->num_rings[RING_COMPUTE]);
1149
fprintf(f, " num_rings[RING_UVD] = %i\n", info->num_rings[RING_UVD]);
1150
fprintf(f, " num_rings[RING_VCE] = %i\n", info->num_rings[RING_VCE]);
1151
fprintf(f, " num_rings[RING_UVD_ENC] = %i\n", info->num_rings[RING_UVD_ENC]);
1152
fprintf(f, " num_rings[RING_VCN_DEC] = %i\n", info->num_rings[RING_VCN_DEC]);
1153
fprintf(f, " num_rings[RING_VCN_ENC] = %i\n", info->num_rings[RING_VCN_ENC]);
1154
fprintf(f, " num_rings[RING_VCN_JPEG] = %i\n", info->num_rings[RING_VCN_JPEG]);
1155
fprintf(f, " has_clear_state = %u\n", info->has_clear_state);
1156
fprintf(f, " has_distributed_tess = %u\n", info->has_distributed_tess);
1157
fprintf(f, " has_dcc_constant_encode = %u\n", info->has_dcc_constant_encode);
1158
fprintf(f, " has_rbplus = %u\n", info->has_rbplus);
1159
fprintf(f, " rbplus_allowed = %u\n", info->rbplus_allowed);
1160
fprintf(f, " has_load_ctx_reg_pkt = %u\n", info->has_load_ctx_reg_pkt);
1161
fprintf(f, " has_out_of_order_rast = %u\n", info->has_out_of_order_rast);
1162
fprintf(f, " cpdma_prefetch_writes_memory = %u\n", info->cpdma_prefetch_writes_memory);
1163
fprintf(f, " has_gfx9_scissor_bug = %i\n", info->has_gfx9_scissor_bug);
1164
fprintf(f, " has_tc_compat_zrange_bug = %i\n", info->has_tc_compat_zrange_bug);
1165
fprintf(f, " has_msaa_sample_loc_bug = %i\n", info->has_msaa_sample_loc_bug);
1166
fprintf(f, " has_ls_vgpr_init_bug = %i\n", info->has_ls_vgpr_init_bug);
1167
fprintf(f, " has_32bit_predication = %i\n", info->has_32bit_predication);
1168
fprintf(f, " has_3d_cube_border_color_mipmap = %i\n", info->has_3d_cube_border_color_mipmap);
1169
1170
fprintf(f, "Display features:\n");
1171
fprintf(f, " use_display_dcc_unaligned = %u\n", info->use_display_dcc_unaligned);
1172
fprintf(f, " use_display_dcc_with_retile_blit = %u\n", info->use_display_dcc_with_retile_blit);
1173
1174
fprintf(f, "Memory info:\n");
1175
fprintf(f, " pte_fragment_size = %u\n", info->pte_fragment_size);
1176
fprintf(f, " gart_page_size = %u\n", info->gart_page_size);
1177
fprintf(f, " gart_size = %i MB\n", (int)DIV_ROUND_UP(info->gart_size, 1024 * 1024));
1178
fprintf(f, " vram_size = %i MB\n", (int)DIV_ROUND_UP(info->vram_size, 1024 * 1024));
1179
fprintf(f, " vram_vis_size = %i MB\n", (int)DIV_ROUND_UP(info->vram_vis_size, 1024 * 1024));
1180
fprintf(f, " vram_type = %i\n", info->vram_type);
1181
fprintf(f, " vram_bit_width = %i\n", info->vram_bit_width);
1182
fprintf(f, " gds_size = %u kB\n", info->gds_size / 1024);
1183
fprintf(f, " gds_gfx_partition_size = %u kB\n", info->gds_gfx_partition_size / 1024);
1184
fprintf(f, " max_alloc_size = %i MB\n", (int)DIV_ROUND_UP(info->max_alloc_size, 1024 * 1024));
1185
fprintf(f, " min_alloc_size = %u\n", info->min_alloc_size);
1186
fprintf(f, " address32_hi = %u\n", info->address32_hi);
1187
fprintf(f, " has_dedicated_vram = %u\n", info->has_dedicated_vram);
1188
fprintf(f, " all_vram_visible = %u\n", info->all_vram_visible);
1189
fprintf(f, " smart_access_memory = %u\n", info->smart_access_memory);
1190
fprintf(f, " max_tcc_blocks = %i\n", info->max_tcc_blocks);
1191
fprintf(f, " num_tcc_blocks = %i\n", info->num_tcc_blocks);
1192
fprintf(f, " tcc_cache_line_size = %u\n", info->tcc_cache_line_size);
1193
fprintf(f, " tcc_rb_non_coherent = %u\n", info->tcc_rb_non_coherent);
1194
fprintf(f, " pc_lines = %u\n", info->pc_lines);
1195
fprintf(f, " lds_size_per_workgroup = %u\n", info->lds_size_per_workgroup);
1196
fprintf(f, " lds_alloc_granularity = %i\n", info->lds_alloc_granularity);
1197
fprintf(f, " lds_encode_granularity = %i\n", info->lds_encode_granularity);
1198
fprintf(f, " max_memory_clock = %i\n", info->max_memory_clock);
1199
fprintf(f, " ce_ram_size = %i\n", info->ce_ram_size);
1200
fprintf(f, " l1_cache_size = %i\n", info->l1_cache_size);
1201
fprintf(f, " l2_cache_size = %i\n", info->l2_cache_size);
1202
1203
fprintf(f, "CP info:\n");
1204
fprintf(f, " gfx_ib_pad_with_type2 = %i\n", info->gfx_ib_pad_with_type2);
1205
fprintf(f, " ib_alignment = %u\n", info->ib_alignment);
1206
fprintf(f, " me_fw_version = %i\n", info->me_fw_version);
1207
fprintf(f, " me_fw_feature = %i\n", info->me_fw_feature);
1208
fprintf(f, " pfp_fw_version = %i\n", info->pfp_fw_version);
1209
fprintf(f, " pfp_fw_feature = %i\n", info->pfp_fw_feature);
1210
fprintf(f, " ce_fw_version = %i\n", info->ce_fw_version);
1211
fprintf(f, " ce_fw_feature = %i\n", info->ce_fw_feature);
1212
1213
fprintf(f, "Multimedia info:\n");
1214
fprintf(f, " uvd_decode = %u\n", info->has_video_hw.uvd_decode);
1215
fprintf(f, " vcn_decode = %u\n", info->has_video_hw.vcn_decode);
1216
fprintf(f, " jpeg_decode = %u\n", info->has_video_hw.jpeg_decode);
1217
fprintf(f, " vce_encode = %u\n", info->has_video_hw.vce_encode);
1218
fprintf(f, " uvd_encode = %u\n", info->has_video_hw.uvd_encode);
1219
fprintf(f, " vcn_encode = %u\n", info->has_video_hw.vcn_encode);
1220
fprintf(f, " uvd_fw_version = %u\n", info->uvd_fw_version);
1221
fprintf(f, " vce_fw_version = %u\n", info->vce_fw_version);
1222
fprintf(f, " vce_harvest_config = %i\n", info->vce_harvest_config);
1223
1224
fprintf(f, "Kernel & winsys capabilities:\n");
1225
fprintf(f, " drm = %i.%i.%i\n", info->drm_major, info->drm_minor, info->drm_patchlevel);
1226
fprintf(f, " has_userptr = %i\n", info->has_userptr);
1227
fprintf(f, " has_syncobj = %u\n", info->has_syncobj);
1228
fprintf(f, " has_timeline_syncobj = %u\n", info->has_timeline_syncobj);
1229
fprintf(f, " has_fence_to_handle = %u\n", info->has_fence_to_handle);
1230
fprintf(f, " has_local_buffers = %u\n", info->has_local_buffers);
1231
fprintf(f, " kernel_flushes_hdp_before_ib = %u\n", info->kernel_flushes_hdp_before_ib);
1232
fprintf(f, " htile_cmask_support_1d_tiling = %u\n", info->htile_cmask_support_1d_tiling);
1233
fprintf(f, " si_TA_CS_BC_BASE_ADDR_allowed = %u\n", info->si_TA_CS_BC_BASE_ADDR_allowed);
1234
fprintf(f, " has_bo_metadata = %u\n", info->has_bo_metadata);
1235
fprintf(f, " has_gpu_reset_status_query = %u\n", info->has_gpu_reset_status_query);
1236
fprintf(f, " has_eqaa_surface_allocator = %u\n", info->has_eqaa_surface_allocator);
1237
fprintf(f, " has_format_bc1_through_bc7 = %u\n", info->has_format_bc1_through_bc7);
1238
fprintf(f, " kernel_flushes_tc_l2_after_ib = %u\n", info->kernel_flushes_tc_l2_after_ib);
1239
fprintf(f, " has_indirect_compute_dispatch = %u\n", info->has_indirect_compute_dispatch);
1240
fprintf(f, " has_unaligned_shader_loads = %u\n", info->has_unaligned_shader_loads);
1241
fprintf(f, " has_sparse_vm_mappings = %u\n", info->has_sparse_vm_mappings);
1242
fprintf(f, " has_2d_tiling = %u\n", info->has_2d_tiling);
1243
fprintf(f, " has_read_registers_query = %u\n", info->has_read_registers_query);
1244
fprintf(f, " has_gds_ordered_append = %u\n", info->has_gds_ordered_append);
1245
fprintf(f, " has_scheduled_fence_dependency = %u\n", info->has_scheduled_fence_dependency);
1246
fprintf(f, " mid_command_buffer_preemption_enabled = %u\n",
1247
info->mid_command_buffer_preemption_enabled);
1248
fprintf(f, " has_tmz_support = %u\n", info->has_tmz_support);
1249
1250
fprintf(f, "Shader core info:\n");
1251
fprintf(f, " max_shader_clock = %i\n", info->max_shader_clock);
1252
fprintf(f, " num_good_compute_units = %i\n", info->num_good_compute_units);
1253
fprintf(f, " max_good_cu_per_sa = %i\n", info->max_good_cu_per_sa);
1254
fprintf(f, " min_good_cu_per_sa = %i\n", info->min_good_cu_per_sa);
1255
fprintf(f, " max_se = %i\n", info->max_se);
1256
fprintf(f, " num_se = %i\n", info->num_se);
1257
fprintf(f, " max_sa_per_se = %i\n", info->max_sa_per_se);
1258
fprintf(f, " max_wave64_per_simd = %i\n", info->max_wave64_per_simd);
1259
fprintf(f, " num_physical_sgprs_per_simd = %i\n", info->num_physical_sgprs_per_simd);
1260
fprintf(f, " num_physical_wave64_vgprs_per_simd = %i\n",
1261
info->num_physical_wave64_vgprs_per_simd);
1262
fprintf(f, " num_simd_per_compute_unit = %i\n", info->num_simd_per_compute_unit);
1263
fprintf(f, " min_sgpr_alloc = %i\n", info->min_sgpr_alloc);
1264
fprintf(f, " max_sgpr_alloc = %i\n", info->max_sgpr_alloc);
1265
fprintf(f, " sgpr_alloc_granularity = %i\n", info->sgpr_alloc_granularity);
1266
fprintf(f, " min_wave64_vgpr_alloc = %i\n", info->min_wave64_vgpr_alloc);
1267
fprintf(f, " max_vgpr_alloc = %i\n", info->max_vgpr_alloc);
1268
fprintf(f, " wave64_vgpr_alloc_granularity = %i\n", info->wave64_vgpr_alloc_granularity);
1269
fprintf(f, " use_late_alloc = %i\n", info->use_late_alloc);
1270
1271
fprintf(f, "Render backend info:\n");
1272
fprintf(f, " pa_sc_tile_steering_override = 0x%x\n", info->pa_sc_tile_steering_override);
1273
fprintf(f, " max_render_backends = %i\n", info->max_render_backends);
1274
fprintf(f, " num_tile_pipes = %i\n", info->num_tile_pipes);
1275
fprintf(f, " pipe_interleave_bytes = %i\n", info->pipe_interleave_bytes);
1276
fprintf(f, " enabled_rb_mask = 0x%x\n", info->enabled_rb_mask);
1277
fprintf(f, " max_alignment = %u\n", (unsigned)info->max_alignment);
1278
fprintf(f, " pbb_max_alloc_count = %u\n", info->pbb_max_alloc_count);
1279
1280
fprintf(f, "GB_ADDR_CONFIG: 0x%08x\n", info->gb_addr_config);
1281
if (info->chip_class >= GFX10) {
1282
fprintf(f, " num_pipes = %u\n", 1 << G_0098F8_NUM_PIPES(info->gb_addr_config));
1283
fprintf(f, " pipe_interleave_size = %u\n",
1284
256 << G_0098F8_PIPE_INTERLEAVE_SIZE_GFX9(info->gb_addr_config));
1285
fprintf(f, " max_compressed_frags = %u\n",
1286
1 << G_0098F8_MAX_COMPRESSED_FRAGS(info->gb_addr_config));
1287
if (info->chip_class >= GFX10_3)
1288
fprintf(f, " num_pkrs = %u\n", 1 << G_0098F8_NUM_PKRS(info->gb_addr_config));
1289
} else if (info->chip_class == GFX9) {
1290
fprintf(f, " num_pipes = %u\n", 1 << G_0098F8_NUM_PIPES(info->gb_addr_config));
1291
fprintf(f, " pipe_interleave_size = %u\n",
1292
256 << G_0098F8_PIPE_INTERLEAVE_SIZE_GFX9(info->gb_addr_config));
1293
fprintf(f, " max_compressed_frags = %u\n",
1294
1 << G_0098F8_MAX_COMPRESSED_FRAGS(info->gb_addr_config));
1295
fprintf(f, " bank_interleave_size = %u\n",
1296
1 << G_0098F8_BANK_INTERLEAVE_SIZE(info->gb_addr_config));
1297
fprintf(f, " num_banks = %u\n", 1 << G_0098F8_NUM_BANKS(info->gb_addr_config));
1298
fprintf(f, " shader_engine_tile_size = %u\n",
1299
16 << G_0098F8_SHADER_ENGINE_TILE_SIZE(info->gb_addr_config));
1300
fprintf(f, " num_shader_engines = %u\n",
1301
1 << G_0098F8_NUM_SHADER_ENGINES_GFX9(info->gb_addr_config));
1302
fprintf(f, " num_gpus = %u (raw)\n", G_0098F8_NUM_GPUS_GFX9(info->gb_addr_config));
1303
fprintf(f, " multi_gpu_tile_size = %u (raw)\n",
1304
G_0098F8_MULTI_GPU_TILE_SIZE(info->gb_addr_config));
1305
fprintf(f, " num_rb_per_se = %u\n", 1 << G_0098F8_NUM_RB_PER_SE(info->gb_addr_config));
1306
fprintf(f, " row_size = %u\n", 1024 << G_0098F8_ROW_SIZE(info->gb_addr_config));
1307
fprintf(f, " num_lower_pipes = %u (raw)\n", G_0098F8_NUM_LOWER_PIPES(info->gb_addr_config));
1308
fprintf(f, " se_enable = %u (raw)\n", G_0098F8_SE_ENABLE(info->gb_addr_config));
1309
} else {
1310
fprintf(f, " num_pipes = %u\n", 1 << G_0098F8_NUM_PIPES(info->gb_addr_config));
1311
fprintf(f, " pipe_interleave_size = %u\n",
1312
256 << G_0098F8_PIPE_INTERLEAVE_SIZE_GFX6(info->gb_addr_config));
1313
fprintf(f, " bank_interleave_size = %u\n",
1314
1 << G_0098F8_BANK_INTERLEAVE_SIZE(info->gb_addr_config));
1315
fprintf(f, " num_shader_engines = %u\n",
1316
1 << G_0098F8_NUM_SHADER_ENGINES_GFX6(info->gb_addr_config));
1317
fprintf(f, " shader_engine_tile_size = %u\n",
1318
16 << G_0098F8_SHADER_ENGINE_TILE_SIZE(info->gb_addr_config));
1319
fprintf(f, " num_gpus = %u (raw)\n", G_0098F8_NUM_GPUS_GFX6(info->gb_addr_config));
1320
fprintf(f, " multi_gpu_tile_size = %u (raw)\n",
1321
G_0098F8_MULTI_GPU_TILE_SIZE(info->gb_addr_config));
1322
fprintf(f, " row_size = %u\n", 1024 << G_0098F8_ROW_SIZE(info->gb_addr_config));
1323
fprintf(f, " num_lower_pipes = %u (raw)\n", G_0098F8_NUM_LOWER_PIPES(info->gb_addr_config));
1324
}
1325
}
1326
1327
int ac_get_gs_table_depth(enum chip_class chip_class, enum radeon_family family)
1328
{
1329
if (chip_class >= GFX9)
1330
return -1;
1331
1332
switch (family) {
1333
case CHIP_OLAND:
1334
case CHIP_HAINAN:
1335
case CHIP_KAVERI:
1336
case CHIP_KABINI:
1337
case CHIP_ICELAND:
1338
case CHIP_CARRIZO:
1339
case CHIP_STONEY:
1340
return 16;
1341
case CHIP_TAHITI:
1342
case CHIP_PITCAIRN:
1343
case CHIP_VERDE:
1344
case CHIP_BONAIRE:
1345
case CHIP_HAWAII:
1346
case CHIP_TONGA:
1347
case CHIP_FIJI:
1348
case CHIP_POLARIS10:
1349
case CHIP_POLARIS11:
1350
case CHIP_POLARIS12:
1351
case CHIP_VEGAM:
1352
return 32;
1353
default:
1354
unreachable("Unknown GPU");
1355
}
1356
}
1357
1358
void ac_get_raster_config(struct radeon_info *info, uint32_t *raster_config_p,
1359
uint32_t *raster_config_1_p, uint32_t *se_tile_repeat_p)
1360
{
1361
unsigned raster_config, raster_config_1, se_tile_repeat;
1362
1363
switch (info->family) {
1364
/* 1 SE / 1 RB */
1365
case CHIP_HAINAN:
1366
case CHIP_KABINI:
1367
case CHIP_STONEY:
1368
raster_config = 0x00000000;
1369
raster_config_1 = 0x00000000;
1370
break;
1371
/* 1 SE / 4 RBs */
1372
case CHIP_VERDE:
1373
raster_config = 0x0000124a;
1374
raster_config_1 = 0x00000000;
1375
break;
1376
/* 1 SE / 2 RBs (Oland is special) */
1377
case CHIP_OLAND:
1378
raster_config = 0x00000082;
1379
raster_config_1 = 0x00000000;
1380
break;
1381
/* 1 SE / 2 RBs */
1382
case CHIP_KAVERI:
1383
case CHIP_ICELAND:
1384
case CHIP_CARRIZO:
1385
raster_config = 0x00000002;
1386
raster_config_1 = 0x00000000;
1387
break;
1388
/* 2 SEs / 4 RBs */
1389
case CHIP_BONAIRE:
1390
case CHIP_POLARIS11:
1391
case CHIP_POLARIS12:
1392
raster_config = 0x16000012;
1393
raster_config_1 = 0x00000000;
1394
break;
1395
/* 2 SEs / 8 RBs */
1396
case CHIP_TAHITI:
1397
case CHIP_PITCAIRN:
1398
raster_config = 0x2a00126a;
1399
raster_config_1 = 0x00000000;
1400
break;
1401
/* 4 SEs / 8 RBs */
1402
case CHIP_TONGA:
1403
case CHIP_POLARIS10:
1404
raster_config = 0x16000012;
1405
raster_config_1 = 0x0000002a;
1406
break;
1407
/* 4 SEs / 16 RBs */
1408
case CHIP_HAWAII:
1409
case CHIP_FIJI:
1410
case CHIP_VEGAM:
1411
raster_config = 0x3a00161a;
1412
raster_config_1 = 0x0000002e;
1413
break;
1414
default:
1415
fprintf(stderr, "ac: Unknown GPU, using 0 for raster_config\n");
1416
raster_config = 0x00000000;
1417
raster_config_1 = 0x00000000;
1418
break;
1419
}
1420
1421
/* drm/radeon on Kaveri is buggy, so disable 1 RB to work around it.
1422
* This decreases performance by up to 50% when the RB is the bottleneck.
1423
*/
1424
if (info->family == CHIP_KAVERI && !info->is_amdgpu)
1425
raster_config = 0x00000000;
1426
1427
/* Fiji: Old kernels have incorrect tiling config. This decreases
1428
* RB performance by 25%. (it disables 1 RB in the second packer)
1429
*/
1430
if (info->family == CHIP_FIJI && info->cik_macrotile_mode_array[0] == 0x000000e8) {
1431
raster_config = 0x16000012;
1432
raster_config_1 = 0x0000002a;
1433
}
1434
1435
unsigned se_width = 8 << G_028350_SE_XSEL_GFX6(raster_config);
1436
unsigned se_height = 8 << G_028350_SE_YSEL_GFX6(raster_config);
1437
1438
/* I don't know how to calculate this, though this is probably a good guess. */
1439
se_tile_repeat = MAX2(se_width, se_height) * info->max_se;
1440
1441
*raster_config_p = raster_config;
1442
*raster_config_1_p = raster_config_1;
1443
if (se_tile_repeat_p)
1444
*se_tile_repeat_p = se_tile_repeat;
1445
}
1446
1447
void ac_get_harvested_configs(struct radeon_info *info, unsigned raster_config,
1448
unsigned *cik_raster_config_1_p, unsigned *raster_config_se)
1449
{
1450
unsigned sh_per_se = MAX2(info->max_sa_per_se, 1);
1451
unsigned num_se = MAX2(info->max_se, 1);
1452
unsigned rb_mask = info->enabled_rb_mask;
1453
unsigned num_rb = MIN2(info->max_render_backends, 16);
1454
unsigned rb_per_pkr = MIN2(num_rb / num_se / sh_per_se, 2);
1455
unsigned rb_per_se = num_rb / num_se;
1456
unsigned se_mask[4];
1457
unsigned se;
1458
1459
se_mask[0] = ((1 << rb_per_se) - 1) & rb_mask;
1460
se_mask[1] = (se_mask[0] << rb_per_se) & rb_mask;
1461
se_mask[2] = (se_mask[1] << rb_per_se) & rb_mask;
1462
se_mask[3] = (se_mask[2] << rb_per_se) & rb_mask;
1463
1464
assert(num_se == 1 || num_se == 2 || num_se == 4);
1465
assert(sh_per_se == 1 || sh_per_se == 2);
1466
assert(rb_per_pkr == 1 || rb_per_pkr == 2);
1467
1468
if (info->chip_class >= GFX7) {
1469
unsigned raster_config_1 = *cik_raster_config_1_p;
1470
if ((num_se > 2) && ((!se_mask[0] && !se_mask[1]) || (!se_mask[2] && !se_mask[3]))) {
1471
raster_config_1 &= C_028354_SE_PAIR_MAP;
1472
1473
if (!se_mask[0] && !se_mask[1]) {
1474
raster_config_1 |= S_028354_SE_PAIR_MAP(V_028354_RASTER_CONFIG_SE_PAIR_MAP_3);
1475
} else {
1476
raster_config_1 |= S_028354_SE_PAIR_MAP(V_028354_RASTER_CONFIG_SE_PAIR_MAP_0);
1477
}
1478
*cik_raster_config_1_p = raster_config_1;
1479
}
1480
}
1481
1482
for (se = 0; se < num_se; se++) {
1483
unsigned pkr0_mask = ((1 << rb_per_pkr) - 1) << (se * rb_per_se);
1484
unsigned pkr1_mask = pkr0_mask << rb_per_pkr;
1485
int idx = (se / 2) * 2;
1486
1487
raster_config_se[se] = raster_config;
1488
if ((num_se > 1) && (!se_mask[idx] || !se_mask[idx + 1])) {
1489
raster_config_se[se] &= C_028350_SE_MAP;
1490
1491
if (!se_mask[idx]) {
1492
raster_config_se[se] |= S_028350_SE_MAP(V_028350_RASTER_CONFIG_SE_MAP_3);
1493
} else {
1494
raster_config_se[se] |= S_028350_SE_MAP(V_028350_RASTER_CONFIG_SE_MAP_0);
1495
}
1496
}
1497
1498
pkr0_mask &= rb_mask;
1499
pkr1_mask &= rb_mask;
1500
if (rb_per_se > 2 && (!pkr0_mask || !pkr1_mask)) {
1501
raster_config_se[se] &= C_028350_PKR_MAP;
1502
1503
if (!pkr0_mask) {
1504
raster_config_se[se] |= S_028350_PKR_MAP(V_028350_RASTER_CONFIG_PKR_MAP_3);
1505
} else {
1506
raster_config_se[se] |= S_028350_PKR_MAP(V_028350_RASTER_CONFIG_PKR_MAP_0);
1507
}
1508
}
1509
1510
if (rb_per_se >= 2) {
1511
unsigned rb0_mask = 1 << (se * rb_per_se);
1512
unsigned rb1_mask = rb0_mask << 1;
1513
1514
rb0_mask &= rb_mask;
1515
rb1_mask &= rb_mask;
1516
if (!rb0_mask || !rb1_mask) {
1517
raster_config_se[se] &= C_028350_RB_MAP_PKR0;
1518
1519
if (!rb0_mask) {
1520
raster_config_se[se] |= S_028350_RB_MAP_PKR0(V_028350_RASTER_CONFIG_RB_MAP_3);
1521
} else {
1522
raster_config_se[se] |= S_028350_RB_MAP_PKR0(V_028350_RASTER_CONFIG_RB_MAP_0);
1523
}
1524
}
1525
1526
if (rb_per_se > 2) {
1527
rb0_mask = 1 << (se * rb_per_se + rb_per_pkr);
1528
rb1_mask = rb0_mask << 1;
1529
rb0_mask &= rb_mask;
1530
rb1_mask &= rb_mask;
1531
if (!rb0_mask || !rb1_mask) {
1532
raster_config_se[se] &= C_028350_RB_MAP_PKR1;
1533
1534
if (!rb0_mask) {
1535
raster_config_se[se] |= S_028350_RB_MAP_PKR1(V_028350_RASTER_CONFIG_RB_MAP_3);
1536
} else {
1537
raster_config_se[se] |= S_028350_RB_MAP_PKR1(V_028350_RASTER_CONFIG_RB_MAP_0);
1538
}
1539
}
1540
}
1541
}
1542
}
1543
}
1544
1545
unsigned ac_get_compute_resource_limits(struct radeon_info *info, unsigned waves_per_threadgroup,
1546
unsigned max_waves_per_sh, unsigned threadgroups_per_cu)
1547
{
1548
unsigned compute_resource_limits = S_00B854_SIMD_DEST_CNTL(waves_per_threadgroup % 4 == 0);
1549
1550
if (info->chip_class >= GFX7) {
1551
unsigned num_cu_per_se = info->num_good_compute_units / info->num_se;
1552
1553
/* Force even distribution on all SIMDs in CU if the workgroup
1554
* size is 64. This has shown some good improvements if # of CUs
1555
* per SE is not a multiple of 4.
1556
*/
1557
if (num_cu_per_se % 4 && waves_per_threadgroup == 1)
1558
compute_resource_limits |= S_00B854_FORCE_SIMD_DIST(1);
1559
1560
assert(threadgroups_per_cu >= 1 && threadgroups_per_cu <= 8);
1561
compute_resource_limits |=
1562
S_00B854_WAVES_PER_SH(max_waves_per_sh) | S_00B854_CU_GROUP_COUNT(threadgroups_per_cu - 1);
1563
} else {
1564
/* GFX6 */
1565
if (max_waves_per_sh) {
1566
unsigned limit_div16 = DIV_ROUND_UP(max_waves_per_sh, 16);
1567
compute_resource_limits |= S_00B854_WAVES_PER_SH_GFX6(limit_div16);
1568
}
1569
}
1570
return compute_resource_limits;
1571
}
1572
1573