drm/amdgpu/gmc: use PCI BARs for APUs in passthrough
Subsystems (2)
Alex Deucher
maintainerPATCH 1/1 drm/amdgpu/gmc: use PCI BARs for APUs in passthrough
If the GPU is passed through to a guest VM, use the PCI BAR for CPU FB access rather than the physical address of carve out. The physical address is not valid in a guest.
v2: Fix HDP handing as suggested by Michel
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c | 5 +++-- drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -2
@@ -5733,7 +5733,7 @@ void amdgpu_device_flush_hdp(struct amdgpu_device *adev, struct amdgpu_ring *ring) {#ifdef CONFIG_X86_64 -if (adev->flags &AMD_IS_APU ) +if ((adev->flags &AMD_IS_APU ) && !amdgpu_passthrough (adev))return ;#endif if (adev->gmc.xgmi.connected_to_cpu)
@@ -5749,7 +5749,7 @@ void amdgpu_device_invalidate_hdp(struct amdgpu_device *adev, struct amdgpu_ring *ring) {#ifdef CONFIG_X86_64 -if (adev->flags &AMD_IS_APU ) +if ((adev->flags &AMD_IS_APU ) && !amdgpu_passthrough (adev))return ;#endif if (adev->gmc.xgmi.connected_to_cpu)
drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c +1 -1
@@ -814,7 +814,7 @@ static int gmc_v10_0_mc_init(struct amdgpu_device *adev) adev->gmc.aper_size =pci_resource_len (adev->pdev,0 );#ifdef CONFIG_X86_64 -if (adev->flags &AMD_IS_APU ) { +if ((adev->flags &AMD_IS_APU ) && !amdgpu_passthrough (adev)) { adev->gmc.aper_base = adev->gfxhub.funcs->get_mc_fb_offset (adev); adev->gmc.aper_size = adev->gmc.real_vram_size; }
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +3 -2
@@ -381,8 +381,9 @@ static int gmc_v7_0_mc_init(struct amdgpu_device *adev) adev->gmc.aper_size =pci_resource_len (adev->pdev,0 );#ifdef CONFIG_X86_64 -if (adev->flags &AMD_IS_APU && - adev->gmc.real_vram_size > adev->gmc.aper_size) { +if ((adev->flags &AMD_IS_APU ) && + adev->gmc.real_vram_size > adev->gmc.aper_size && + !amdgpu_passthrough (adev)) { adev->gmc.aper_base = ((u64 )RREG32 (mmMC_VM_FB_OFFSET)) <<22 ; adev->gmc.aper_size = adev->gmc.real_vram_size; }
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +1 -1
@@ -581,7 +581,7 @@ static int gmc_v8_0_mc_init(struct amdgpu_device *adev) adev->gmc.aper_size =pci_resource_len (adev->pdev,0 );#ifdef CONFIG_X86_64 -if (adev->flags &AMD_IS_APU ) { +if ((adev->flags &AMD_IS_APU ) && !amdgpu_passthrough (adev)) { adev->gmc.aper_base = ((u64 )RREG32 (mmMC_VM_FB_OFFSET)) <<22 ; adev->gmc.aper_size = adev->gmc.real_vram_size; }
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -1
@@ -1456,7 +1456,7 @@ static int gmc_v9_0_mc_init(struct amdgpu_device *adev)*/ /* check whether both host-gpu and gpu-gpu xgmi links exist */ -if ((adev->flags &AMD_IS_APU ) || +if (((adev->flags &AMD_IS_APU ) && !amdgpu_passthrough (adev)) || (adev->gmc.xgmi.supported && adev->gmc.xgmi.connected_to_cpu)) { adev->gmc.aper_base =
Signature · 1 line
2.35.1
Am 15.03.22 um 19:13 schrieb Alex Deucher:
Quoted 7 lines
If the GPU is passed through to a guest VM, use the PCI BAR for CPU FB access rather than the physical address of carve out. The physical address is not valid in a guest.
v2: Fix HDP handing as suggested by Michel
Signed-off-by Alex Deucher <[email protected]>
Might be a good idea to have a function or macro to figure out if we should use the BAR or not on APUs.
Anyway patch is Reviewed-by: Christian König <[email protected]>.
Quoted 85 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c | 5 +++-- drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2
-2@@ -5733,7 +5733,7 @@ void amdgpu_device_flush_hdp(struct amdgpu_device *adev, struct amdgpu_ring *ring) {#ifdef CONFIG_X86_64 -if (adev->flags &AMD_IS_APU ) +if ((adev->flags &AMD_IS_APU ) && !amdgpu_passthrough (adev))return ;#endif if (adev->gmc.xgmi.connected_to_cpu)@@ -5749,7 +5749,7 @@ void amdgpu_device_invalidate_hdp(struct amdgpu_device *adev, struct amdgpu_ring *ring) {#ifdef CONFIG_X86_64 -if (adev->flags &AMD_IS_APU ) +if ((adev->flags &AMD_IS_APU ) && !amdgpu_passthrough (adev))return ;#endif if (adev->gmc.xgmi.connected_to_cpu)drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c +1
-1@@ -814,7 +814,7 @@ static int gmc_v10_0_mc_init(struct amdgpu_device *adev) adev->gmc.aper_size =pci_resource_len (adev->pdev,0 );#ifdef CONFIG_X86_64 -if (adev->flags &AMD_IS_APU ) { +if ((adev->flags &AMD_IS_APU ) && !amdgpu_passthrough (adev)) { adev->gmc.aper_base = adev->gfxhub.funcs->get_mc_fb_offset (adev); adev->gmc.aper_size = adev->gmc.real_vram_size; }drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +3
-2@@ -381,8 +381,9 @@ static int gmc_v7_0_mc_init(struct amdgpu_device *adev) adev->gmc.aper_size =pci_resource_len (adev->pdev,0 );#ifdef CONFIG_X86_64 -if (adev->flags &AMD_IS_APU && - adev->gmc.real_vram_size > adev->gmc.aper_size) { +if ((adev->flags &AMD_IS_APU ) && + adev->gmc.real_vram_size > adev->gmc.aper_size && + !amdgpu_passthrough (adev)) { adev->gmc.aper_base = ((u64 )RREG32 (mmMC_VM_FB_OFFSET)) <<22 ; adev->gmc.aper_size = adev->gmc.real_vram_size; }drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +1
-1@@ -581,7 +581,7 @@ static int gmc_v8_0_mc_init(struct amdgpu_device *adev) adev->gmc.aper_size =pci_resource_len (adev->pdev,0 );#ifdef CONFIG_X86_64 -if (adev->flags &AMD_IS_APU ) { +if ((adev->flags &AMD_IS_APU ) && !amdgpu_passthrough (adev)) { adev->gmc.aper_base = ((u64 )RREG32 (mmMC_VM_FB_OFFSET)) <<22 ; adev->gmc.aper_size = adev->gmc.real_vram_size; }drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1
-1@@ -1456,7 +1456,7 @@ static int gmc_v9_0_mc_init(struct amdgpu_device *adev)*/ /* check whether both host-gpu and gpu-gpu xgmi links exist */ -if ((adev->flags &AMD_IS_APU ) || +if (((adev->flags &AMD_IS_APU ) && !amdgpu_passthrough (adev)) || (adev->gmc.xgmi.supported && adev->gmc.xgmi.connected_to_cpu)) { adev->gmc.aper_base =
Michel Dänzer
Reviewed-byQuoted 5 lines · Christian König
Am 15.03.22 um 19:13 schrieb Alex Deucher:
Quoted 4 lines
If the GPU is passed through to a guest VM, use the PCI BAR for CPU FB access rather than the physical address of carve out. The physical address is not valid in a guest.
Quoted 7 lines
Quoted 3 lines
v2: Fix HDP handing as suggested by Michel
Signed-off-by Alex Deucher <[email protected]>Might be a good idea to have a function or macro to figure out if we should use the BAR or not on APUs.
Anyway patch is Reviewed-by: Christian König <[email protected]>.
And
Signature · 2 lines
Earthling Michel Dänzer | https://redhat.com Libre software enthusiast | Mesa and Xwayland developer