Skip to content

Commit 892deb4

Browse files
vskvortsalexdeucher
authored andcommitted
drm/amdgpu: Separate vf2pf work item init from virt data exchange
We want to be able to call virt data exchange conditionally after gmc sw init to reserve bad pages as early as possible. Since this is a conditional call, we will need to call it again unconditionally later in the init sequence. Refactor the data exchange function so it can be called multiple times without re-initializing the work item. v2: Cleaned up the code. Kept the original call to init_exchange_data() inside early init to initialize the work item, afterwards call exchange_data() when needed. Signed-off-by: Victor Skvortsov <[email protected]> Reviewed By: Shaoyun.liu <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent d999bc8 commit 892deb4

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2317,6 +2317,10 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev)
23172317

23182318
/* need to do gmc hw init early so we can allocate gpu mem */
23192319
if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC) {
2320+
/* Try to reserve bad pages early */
2321+
if (amdgpu_sriov_vf(adev))
2322+
amdgpu_virt_exchange_data(adev);
2323+
23202324
r = amdgpu_device_vram_scratch_init(adev);
23212325
if (r) {
23222326
DRM_ERROR("amdgpu_vram_scratch_init failed %d\n", r);
@@ -2348,7 +2352,7 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev)
23482352
}
23492353

23502354
if (amdgpu_sriov_vf(adev))
2351-
amdgpu_virt_init_data_exchange(adev);
2355+
amdgpu_virt_exchange_data(adev);
23522356

23532357
r = amdgpu_ib_pool_init(adev);
23542358
if (r) {

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -622,17 +622,35 @@ void amdgpu_virt_fini_data_exchange(struct amdgpu_device *adev)
622622

623623
void amdgpu_virt_init_data_exchange(struct amdgpu_device *adev)
624624
{
625-
uint64_t bp_block_offset = 0;
626-
uint32_t bp_block_size = 0;
627-
struct amd_sriov_msg_pf2vf_info *pf2vf_v2 = NULL;
628-
629625
adev->virt.fw_reserve.p_pf2vf = NULL;
630626
adev->virt.fw_reserve.p_vf2pf = NULL;
631627
adev->virt.vf2pf_update_interval_ms = 0;
632628

633-
if (adev->mman.fw_vram_usage_va != NULL) {
629+
if (adev->bios != NULL) {
634630
adev->virt.vf2pf_update_interval_ms = 2000;
635631

632+
adev->virt.fw_reserve.p_pf2vf =
633+
(struct amd_sriov_msg_pf2vf_info_header *)
634+
(adev->bios + (AMD_SRIOV_MSG_PF2VF_OFFSET_KB << 10));
635+
636+
amdgpu_virt_read_pf2vf_data(adev);
637+
}
638+
639+
if (adev->virt.vf2pf_update_interval_ms != 0) {
640+
INIT_DELAYED_WORK(&adev->virt.vf2pf_work, amdgpu_virt_update_vf2pf_work_item);
641+
schedule_delayed_work(&(adev->virt.vf2pf_work), msecs_to_jiffies(adev->virt.vf2pf_update_interval_ms));
642+
}
643+
}
644+
645+
646+
void amdgpu_virt_exchange_data(struct amdgpu_device *adev)
647+
{
648+
uint64_t bp_block_offset = 0;
649+
uint32_t bp_block_size = 0;
650+
struct amd_sriov_msg_pf2vf_info *pf2vf_v2 = NULL;
651+
652+
if (adev->mman.fw_vram_usage_va != NULL) {
653+
636654
adev->virt.fw_reserve.p_pf2vf =
637655
(struct amd_sriov_msg_pf2vf_info_header *)
638656
(adev->mman.fw_vram_usage_va + (AMD_SRIOV_MSG_PF2VF_OFFSET_KB << 10));
@@ -663,16 +681,10 @@ void amdgpu_virt_init_data_exchange(struct amdgpu_device *adev)
663681
(adev->bios + (AMD_SRIOV_MSG_PF2VF_OFFSET_KB << 10));
664682

665683
amdgpu_virt_read_pf2vf_data(adev);
666-
667-
return;
668-
}
669-
670-
if (adev->virt.vf2pf_update_interval_ms != 0) {
671-
INIT_DELAYED_WORK(&adev->virt.vf2pf_work, amdgpu_virt_update_vf2pf_work_item);
672-
schedule_delayed_work(&(adev->virt.vf2pf_work), adev->virt.vf2pf_update_interval_ms);
673684
}
674685
}
675686

687+
676688
void amdgpu_detect_virtualization(struct amdgpu_device *adev)
677689
{
678690
uint32_t reg;

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ int amdgpu_virt_alloc_mm_table(struct amdgpu_device *adev);
308308
void amdgpu_virt_free_mm_table(struct amdgpu_device *adev);
309309
void amdgpu_virt_release_ras_err_handler_data(struct amdgpu_device *adev);
310310
void amdgpu_virt_init_data_exchange(struct amdgpu_device *adev);
311+
void amdgpu_virt_exchange_data(struct amdgpu_device *adev);
311312
void amdgpu_virt_fini_data_exchange(struct amdgpu_device *adev);
312313
void amdgpu_detect_virtualization(struct amdgpu_device *adev);
313314

0 commit comments

Comments
 (0)