Skip to content

Commit d91b010

Browse files
author
Andrey Grodzovsky
committed
drm/amdgpu: Unmap all MMIO mappings
Access to those must be prevented post pci_remove v6: Drop BOs list, unampping VRAM BAR is enough. v8: Add condition of xgmi.connected_to_cpu to MTTR handling and remove MTTR handling from the old place. Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky@amd.com> Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Link: https://patchwork.freedesktop.org/patch/msgid/20210517193105.491461-1-andrey.grodzovsky@amd.com
1 parent a6937c9 commit d91b010

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3664,6 +3664,27 @@ int amdgpu_device_init(struct amdgpu_device *adev,
36643664
return r;
36653665
}
36663666

3667+
static void amdgpu_device_unmap_mmio(struct amdgpu_device *adev)
3668+
{
3669+
/* Clear all CPU mappings pointing to this device */
3670+
unmap_mapping_range(adev->ddev.anon_inode->i_mapping, 0, 0, 1);
3671+
3672+
/* Unmap all mapped bars - Doorbell, registers and VRAM */
3673+
amdgpu_device_doorbell_fini(adev);
3674+
3675+
iounmap(adev->rmmio);
3676+
adev->rmmio = NULL;
3677+
if (adev->mman.aper_base_kaddr)
3678+
iounmap(adev->mman.aper_base_kaddr);
3679+
adev->mman.aper_base_kaddr = NULL;
3680+
3681+
/* Memory manager related */
3682+
if (!adev->gmc.xgmi.connected_to_cpu) {
3683+
arch_phys_wc_del(adev->gmc.vram_mtrr);
3684+
arch_io_free_memtype_wc(adev->gmc.aper_base, adev->gmc.aper_size);
3685+
}
3686+
}
3687+
36673688
/**
36683689
* amdgpu_device_fini - tear down the driver
36693690
*
@@ -3710,6 +3731,8 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)
37103731
amdgpu_device_ip_fini_early(adev);
37113732

37123733
amdgpu_gart_dummy_page_fini(adev);
3734+
3735+
amdgpu_device_unmap_mmio(adev);
37133736
}
37143737

37153738
void amdgpu_device_fini_sw(struct amdgpu_device *adev)
@@ -3737,9 +3760,6 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev)
37373760
}
37383761
if ((adev->pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA)
37393762
vga_client_register(adev->pdev, NULL, NULL, NULL);
3740-
iounmap(adev->rmmio);
3741-
adev->rmmio = NULL;
3742-
amdgpu_device_doorbell_fini(adev);
37433763

37443764
if (IS_ENABLED(CONFIG_PERF_EVENTS))
37453765
amdgpu_pmu_fini(adev);

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,10 +1107,6 @@ int amdgpu_bo_init(struct amdgpu_device *adev)
11071107
void amdgpu_bo_fini(struct amdgpu_device *adev)
11081108
{
11091109
amdgpu_ttm_fini(adev);
1110-
if (!adev->gmc.xgmi.connected_to_cpu) {
1111-
arch_phys_wc_del(adev->gmc.vram_mtrr);
1112-
arch_io_free_memtype_wc(adev->gmc.aper_base, adev->gmc.aper_size);
1113-
}
11141110
}
11151111

11161112
/**

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,10 +1841,6 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)
18411841
amdgpu_bo_free_kernel(&adev->mman.discovery_memory, NULL, NULL);
18421842
amdgpu_ttm_fw_reserve_vram_fini(adev);
18431843

1844-
if (adev->mman.aper_base_kaddr)
1845-
iounmap(adev->mman.aper_base_kaddr);
1846-
adev->mman.aper_base_kaddr = NULL;
1847-
18481844
amdgpu_vram_mgr_fini(adev);
18491845
amdgpu_gtt_mgr_fini(adev);
18501846
ttm_range_man_fini(&adev->mman.bdev, AMDGPU_PL_GDS);

0 commit comments

Comments
 (0)