Skip to content

Commit f1e582e

Browse files
committed
drm/amdgpu: implement harvesting support for UVD 7.2 (v3)
Properly handle cases where one or more instance of the IP block may be harvested. v2: make sure ip_num_rings is initialized amdgpu_queue_mgr.c v3: rebase on Christian's UVD changes, drop unused var Reviewed-by: James Zhu <James.Zhu@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent d04cc60 commit f1e582e

5 files changed

Lines changed: 89 additions & 12 deletions

File tree

‎drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
286286
struct drm_crtc *crtc;
287287
uint32_t ui32 = 0;
288288
uint64_t ui64 = 0;
289-
int i, found;
289+
int i, j, found;
290290
int ui32_size = sizeof(ui32);
291291

292292
if (!info->return_size || !info->return_pointer)
@@ -348,7 +348,11 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
348348
break;
349349
case AMDGPU_HW_IP_UVD:
350350
type = AMD_IP_BLOCK_TYPE_UVD;
351-
ring_mask |= adev->uvd.inst[0].ring.ready;
351+
for (i = 0; i < adev->uvd.num_uvd_inst; i++) {
352+
if (adev->uvd.harvest_config & (1 << i))
353+
continue;
354+
ring_mask |= adev->uvd.inst[i].ring.ready;
355+
}
352356
ib_start_alignment = 64;
353357
ib_size_alignment = 64;
354358
break;
@@ -361,9 +365,12 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
361365
break;
362366
case AMDGPU_HW_IP_UVD_ENC:
363367
type = AMD_IP_BLOCK_TYPE_UVD;
364-
for (i = 0; i < adev->uvd.num_enc_rings; i++)
365-
ring_mask |=
366-
adev->uvd.inst[0].ring_enc[i].ready << i;
368+
for (i = 0; i < adev->uvd.num_uvd_inst; i++) {
369+
if (adev->uvd.harvest_config & (1 << i))
370+
continue;
371+
for (j = 0; j < adev->uvd.num_enc_rings; j++)
372+
ring_mask |= adev->uvd.inst[i].ring_enc[j].ready << j;
373+
}
367374
ib_start_alignment = 64;
368375
ib_size_alignment = 64;
369376
break;

‎drivers/gpu/drm/amd/amdgpu/amdgpu_queue_mgr.c‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ int amdgpu_queue_mgr_map(struct amdgpu_device *adev,
214214
u32 hw_ip, u32 instance, u32 ring,
215215
struct amdgpu_ring **out_ring)
216216
{
217-
int r, ip_num_rings;
217+
int i, r, ip_num_rings = 0;
218218
struct amdgpu_queue_mapper *mapper = &mgr->mapper[hw_ip];
219219

220220
if (!adev || !mgr || !out_ring)
@@ -243,14 +243,21 @@ int amdgpu_queue_mgr_map(struct amdgpu_device *adev,
243243
ip_num_rings = adev->sdma.num_instances;
244244
break;
245245
case AMDGPU_HW_IP_UVD:
246-
ip_num_rings = adev->uvd.num_uvd_inst;
246+
for (i = 0; i < adev->uvd.num_uvd_inst; i++) {
247+
if (!(adev->uvd.harvest_config & (1 << i)))
248+
ip_num_rings++;
249+
}
247250
break;
248251
case AMDGPU_HW_IP_VCE:
249252
ip_num_rings = adev->vce.num_rings;
250253
break;
251254
case AMDGPU_HW_IP_UVD_ENC:
255+
for (i = 0; i < adev->uvd.num_uvd_inst; i++) {
256+
if (!(adev->uvd.harvest_config & (1 << i)))
257+
ip_num_rings++;
258+
}
252259
ip_num_rings =
253-
adev->uvd.num_enc_rings * adev->uvd.num_uvd_inst;
260+
adev->uvd.num_enc_rings * ip_num_rings;
254261
break;
255262
case AMDGPU_HW_IP_VCN_DEC:
256263
ip_num_rings = 1;

‎drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ int amdgpu_uvd_sw_init(struct amdgpu_device *adev)
255255
bo_size += AMDGPU_GPU_PAGE_ALIGN(le32_to_cpu(hdr->ucode_size_bytes) + 8);
256256

257257
for (j = 0; j < adev->uvd.num_uvd_inst; j++) {
258-
258+
if (adev->uvd.harvest_config & (1 << j))
259+
continue;
259260
r = amdgpu_bo_create_kernel(adev, bo_size, PAGE_SIZE,
260261
AMDGPU_GEM_DOMAIN_VRAM, &adev->uvd.inst[j].vcpu_bo,
261262
&adev->uvd.inst[j].gpu_addr, &adev->uvd.inst[j].cpu_addr);
@@ -308,6 +309,8 @@ int amdgpu_uvd_sw_fini(struct amdgpu_device *adev)
308309
drm_sched_entity_destroy(&adev->uvd.entity);
309310

310311
for (j = 0; j < adev->uvd.num_uvd_inst; ++j) {
312+
if (adev->uvd.harvest_config & (1 << j))
313+
continue;
311314
kfree(adev->uvd.inst[j].saved_bo);
312315

313316
amdgpu_bo_free_kernel(&adev->uvd.inst[j].vcpu_bo,
@@ -343,6 +346,8 @@ int amdgpu_uvd_suspend(struct amdgpu_device *adev)
343346
}
344347

345348
for (j = 0; j < adev->uvd.num_uvd_inst; ++j) {
349+
if (adev->uvd.harvest_config & (1 << j))
350+
continue;
346351
if (adev->uvd.inst[j].vcpu_bo == NULL)
347352
continue;
348353

@@ -365,6 +370,8 @@ int amdgpu_uvd_resume(struct amdgpu_device *adev)
365370
int i;
366371

367372
for (i = 0; i < adev->uvd.num_uvd_inst; i++) {
373+
if (adev->uvd.harvest_config & (1 << i))
374+
continue;
368375
if (adev->uvd.inst[i].vcpu_bo == NULL)
369376
return -EINVAL;
370377

@@ -1159,6 +1166,8 @@ static void amdgpu_uvd_idle_work_handler(struct work_struct *work)
11591166
unsigned fences = 0, i, j;
11601167

11611168
for (i = 0; i < adev->uvd.num_uvd_inst; ++i) {
1169+
if (adev->uvd.harvest_config & (1 << i))
1170+
continue;
11621171
fences += amdgpu_fence_count_emitted(&adev->uvd.inst[i].ring);
11631172
for (j = 0; j < adev->uvd.num_enc_rings; ++j) {
11641173
fences += amdgpu_fence_count_emitted(&adev->uvd.inst[i].ring_enc[j]);

‎drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ struct amdgpu_uvd_inst {
4848
uint32_t srbm_soft_reset;
4949
};
5050

51+
#define AMDGPU_UVD_HARVEST_UVD0 (1 << 0)
52+
#define AMDGPU_UVD_HARVEST_UVD1 (1 << 1)
53+
5154
struct amdgpu_uvd {
5255
const struct firmware *fw; /* UVD firmware */
5356
unsigned fw_version;
@@ -61,6 +64,7 @@ struct amdgpu_uvd {
6164
atomic_t handles[AMDGPU_MAX_UVD_HANDLES];
6265
struct drm_sched_entity entity;
6366
struct delayed_work idle_work;
67+
unsigned harvest_config;
6468
};
6569

6670
int amdgpu_uvd_sw_init(struct amdgpu_device *adev);

‎drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c‎

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141
#include "mmhub/mmhub_1_0_sh_mask.h"
4242
#include "ivsrcid/uvd/irqsrcs_uvd_7_0.h"
4343

44+
#define mmUVD_PG0_CC_UVD_HARVESTING 0x00c7
45+
#define mmUVD_PG0_CC_UVD_HARVESTING_BASE_IDX 1
46+
//UVD_PG0_CC_UVD_HARVESTING
47+
#define UVD_PG0_CC_UVD_HARVESTING__UVD_DISABLE__SHIFT 0x1
48+
#define UVD_PG0_CC_UVD_HARVESTING__UVD_DISABLE_MASK 0x00000002L
49+
4450
#define UVD7_MAX_HW_INSTANCES_VEGA20 2
4551

4652
static void uvd_v7_0_set_ring_funcs(struct amdgpu_device *adev);
@@ -370,10 +376,25 @@ static int uvd_v7_0_enc_ring_test_ib(struct amdgpu_ring *ring, long timeout)
370376
static int uvd_v7_0_early_init(void *handle)
371377
{
372378
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
373-
if (adev->asic_type == CHIP_VEGA20)
379+
380+
if (adev->asic_type == CHIP_VEGA20) {
381+
u32 harvest;
382+
int i;
383+
374384
adev->uvd.num_uvd_inst = UVD7_MAX_HW_INSTANCES_VEGA20;
375-
else
385+
for (i = 0; i < adev->uvd.num_uvd_inst; i++) {
386+
harvest = RREG32_SOC15(UVD, i, mmUVD_PG0_CC_UVD_HARVESTING);
387+
if (harvest & UVD_PG0_CC_UVD_HARVESTING__UVD_DISABLE_MASK) {
388+
adev->uvd.harvest_config |= 1 << i;
389+
}
390+
}
391+
if (adev->uvd.harvest_config == (AMDGPU_UVD_HARVEST_UVD0 |
392+
AMDGPU_UVD_HARVEST_UVD1))
393+
/* both instances are harvested, disable the block */
394+
return -ENOENT;
395+
} else {
376396
adev->uvd.num_uvd_inst = 1;
397+
}
377398

378399
if (amdgpu_sriov_vf(adev))
379400
adev->uvd.num_enc_rings = 1;
@@ -393,6 +414,8 @@ static int uvd_v7_0_sw_init(void *handle)
393414
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
394415

395416
for (j = 0; j < adev->uvd.num_uvd_inst; j++) {
417+
if (adev->uvd.harvest_config & (1 << j))
418+
continue;
396419
/* UVD TRAP */
397420
r = amdgpu_irq_add_id(adev, amdgpu_ih_clientid_uvds[j], UVD_7_0__SRCID__UVD_SYSTEM_MESSAGE_INTERRUPT, &adev->uvd.inst[j].irq);
398421
if (r)
@@ -425,6 +448,8 @@ static int uvd_v7_0_sw_init(void *handle)
425448
return r;
426449

427450
for (j = 0; j < adev->uvd.num_uvd_inst; j++) {
451+
if (adev->uvd.harvest_config & (1 << j))
452+
continue;
428453
if (!amdgpu_sriov_vf(adev)) {
429454
ring = &adev->uvd.inst[j].ring;
430455
sprintf(ring->name, "uvd<%d>", j);
@@ -472,6 +497,8 @@ static int uvd_v7_0_sw_fini(void *handle)
472497
return r;
473498

474499
for (j = 0; j < adev->uvd.num_uvd_inst; ++j) {
500+
if (adev->uvd.harvest_config & (1 << j))
501+
continue;
475502
for (i = 0; i < adev->uvd.num_enc_rings; ++i)
476503
amdgpu_ring_fini(&adev->uvd.inst[j].ring_enc[i]);
477504
}
@@ -500,6 +527,8 @@ static int uvd_v7_0_hw_init(void *handle)
500527
goto done;
501528

502529
for (j = 0; j < adev->uvd.num_uvd_inst; ++j) {
530+
if (adev->uvd.harvest_config & (1 << j))
531+
continue;
503532
ring = &adev->uvd.inst[j].ring;
504533

505534
if (!amdgpu_sriov_vf(adev)) {
@@ -579,8 +608,11 @@ static int uvd_v7_0_hw_fini(void *handle)
579608
DRM_DEBUG("For SRIOV client, shouldn't do anything.\n");
580609
}
581610

582-
for (i = 0; i < adev->uvd.num_uvd_inst; ++i)
611+
for (i = 0; i < adev->uvd.num_uvd_inst; ++i) {
612+
if (adev->uvd.harvest_config & (1 << i))
613+
continue;
583614
adev->uvd.inst[i].ring.ready = false;
615+
}
584616

585617
return 0;
586618
}
@@ -623,6 +655,8 @@ static void uvd_v7_0_mc_resume(struct amdgpu_device *adev)
623655
int i;
624656

625657
for (i = 0; i < adev->uvd.num_uvd_inst; ++i) {
658+
if (adev->uvd.harvest_config & (1 << i))
659+
continue;
626660
if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
627661
WREG32_SOC15(UVD, i, mmUVD_LMI_VCPU_CACHE_64BIT_BAR_LOW,
628662
lower_32_bits(adev->firmware.ucode[AMDGPU_UCODE_ID_UVD].mc_addr));
@@ -695,6 +729,8 @@ static int uvd_v7_0_mmsch_start(struct amdgpu_device *adev,
695729
WREG32_SOC15(VCE, 0, mmVCE_MMSCH_VF_MAILBOX_RESP, 0);
696730

697731
for (i = 0; i < adev->uvd.num_uvd_inst; ++i) {
732+
if (adev->uvd.harvest_config & (1 << i))
733+
continue;
698734
WDOORBELL32(adev->uvd.inst[i].ring_enc[0].doorbell_index, 0);
699735
adev->wb.wb[adev->uvd.inst[i].ring_enc[0].wptr_offs] = 0;
700736
adev->uvd.inst[i].ring_enc[0].wptr = 0;
@@ -751,6 +787,8 @@ static int uvd_v7_0_sriov_start(struct amdgpu_device *adev)
751787
init_table += header->uvd_table_offset;
752788

753789
for (i = 0; i < adev->uvd.num_uvd_inst; ++i) {
790+
if (adev->uvd.harvest_config & (1 << i))
791+
continue;
754792
ring = &adev->uvd.inst[i].ring;
755793
ring->wptr = 0;
756794
size = AMDGPU_GPU_PAGE_ALIGN(adev->uvd.fw->size + 4);
@@ -890,6 +928,8 @@ static int uvd_v7_0_start(struct amdgpu_device *adev)
890928
int i, j, k, r;
891929

892930
for (k = 0; k < adev->uvd.num_uvd_inst; ++k) {
931+
if (adev->uvd.harvest_config & (1 << k))
932+
continue;
893933
/* disable DPG */
894934
WREG32_P(SOC15_REG_OFFSET(UVD, k, mmUVD_POWER_STATUS), 0,
895935
~UVD_POWER_STATUS__UVD_PG_MODE_MASK);
@@ -902,6 +942,8 @@ static int uvd_v7_0_start(struct amdgpu_device *adev)
902942
uvd_v7_0_mc_resume(adev);
903943

904944
for (k = 0; k < adev->uvd.num_uvd_inst; ++k) {
945+
if (adev->uvd.harvest_config & (1 << k))
946+
continue;
905947
ring = &adev->uvd.inst[k].ring;
906948
/* disable clock gating */
907949
WREG32_P(SOC15_REG_OFFSET(UVD, k, mmUVD_CGC_CTRL), 0,
@@ -1069,6 +1111,8 @@ static void uvd_v7_0_stop(struct amdgpu_device *adev)
10691111
uint8_t i = 0;
10701112

10711113
for (i = 0; i < adev->uvd.num_uvd_inst; ++i) {
1114+
if (adev->uvd.harvest_config & (1 << i))
1115+
continue;
10721116
/* force RBC into idle state */
10731117
WREG32_SOC15(UVD, i, mmUVD_RBC_RB_CNTL, 0x11010101);
10741118

@@ -1785,6 +1829,8 @@ static void uvd_v7_0_set_ring_funcs(struct amdgpu_device *adev)
17851829
int i;
17861830

17871831
for (i = 0; i < adev->uvd.num_uvd_inst; i++) {
1832+
if (adev->uvd.harvest_config & (1 << i))
1833+
continue;
17881834
adev->uvd.inst[i].ring.funcs = &uvd_v7_0_ring_vm_funcs;
17891835
adev->uvd.inst[i].ring.me = i;
17901836
DRM_INFO("UVD(%d) is enabled in VM mode\n", i);
@@ -1796,6 +1842,8 @@ static void uvd_v7_0_set_enc_ring_funcs(struct amdgpu_device *adev)
17961842
int i, j;
17971843

17981844
for (j = 0; j < adev->uvd.num_uvd_inst; j++) {
1845+
if (adev->uvd.harvest_config & (1 << j))
1846+
continue;
17991847
for (i = 0; i < adev->uvd.num_enc_rings; ++i) {
18001848
adev->uvd.inst[j].ring_enc[i].funcs = &uvd_v7_0_enc_ring_vm_funcs;
18011849
adev->uvd.inst[j].ring_enc[i].me = j;
@@ -1815,6 +1863,8 @@ static void uvd_v7_0_set_irq_funcs(struct amdgpu_device *adev)
18151863
int i;
18161864

18171865
for (i = 0; i < adev->uvd.num_uvd_inst; i++) {
1866+
if (adev->uvd.harvest_config & (1 << i))
1867+
continue;
18181868
adev->uvd.inst[i].irq.num_types = adev->uvd.num_enc_rings + 1;
18191869
adev->uvd.inst[i].irq.funcs = &uvd_v7_0_irq_funcs;
18201870
}

0 commit comments

Comments
 (0)