Skip to content

Commit 62d5f9f

Browse files
yuliashi-amdalexdeucher
authored andcommitted
drm/amdgpu: Unmap MMIO mappings when device is not unplugged
Patch: 3efb17a ("drm/amdgpu: Call amdgpu_device_unmap_mmio() if device is unplugged to prevent crash in GPU initialization failure") makes call to amdgpu_device_unmap_mmio() conditioned on device unplugged. This patch unmaps MMIO mappings even when device is not unplugged. v2: Add condition of drm_dev_enter() to deleted unmaps in patch "drm/amdgpu: Unmap all MMIO mappings" Signed-off-by: Leslie Shi <Yuliang.Shi@amd.com> Reviewed-by: Andrey Grodzovsky <andrey.grodzovsky@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent 6638391 commit 62d5f9f

3 files changed

Lines changed: 34 additions & 0 deletions

File tree

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3833,6 +3833,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
38333833

38343834
static void amdgpu_device_unmap_mmio(struct amdgpu_device *adev)
38353835
{
3836+
38363837
/* Clear all CPU mappings pointing to this device */
38373838
unmap_mapping_range(adev->ddev.anon_inode->i_mapping, 0, 0, 1);
38383839

@@ -3913,6 +3914,8 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)
39133914

39143915
void amdgpu_device_fini_sw(struct amdgpu_device *adev)
39153916
{
3917+
int idx;
3918+
39163919
amdgpu_fence_driver_sw_fini(adev);
39173920
amdgpu_device_ip_fini(adev);
39183921
release_firmware(adev->firmware.gpu_info_fw);
@@ -3937,6 +3940,14 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev)
39373940
if ((adev->pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA)
39383941
vga_client_unregister(adev->pdev);
39393942

3943+
if (drm_dev_enter(adev_to_drm(adev), &idx)) {
3944+
3945+
iounmap(adev->rmmio);
3946+
adev->rmmio = NULL;
3947+
amdgpu_device_doorbell_fini(adev);
3948+
drm_dev_exit(idx);
3949+
}
3950+
39403951
if (IS_ENABLED(CONFIG_PERF_EVENTS))
39413952
amdgpu_pmu_fini(adev);
39423953
if (adev->mman.discovery_bin)

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <linux/slab.h>
3434
#include <linux/dma-buf.h>
3535

36+
#include <drm/drm_drv.h>
3637
#include <drm/amdgpu_drm.h>
3738
#include <drm/drm_cache.h>
3839
#include "amdgpu.h"
@@ -1061,7 +1062,18 @@ int amdgpu_bo_init(struct amdgpu_device *adev)
10611062
*/
10621063
void amdgpu_bo_fini(struct amdgpu_device *adev)
10631064
{
1065+
int idx;
1066+
10641067
amdgpu_ttm_fini(adev);
1068+
1069+
if (drm_dev_enter(adev_to_drm(adev), &idx)) {
1070+
1071+
if (!adev->gmc.xgmi.connected_to_cpu) {
1072+
arch_phys_wc_del(adev->gmc.vram_mtrr);
1073+
arch_io_free_memtype_wc(adev->gmc.aper_base, adev->gmc.aper_size);
1074+
}
1075+
drm_dev_exit(idx);
1076+
}
10651077
}
10661078

10671079
/**

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <linux/sizes.h>
4444
#include <linux/module.h>
4545

46+
#include <drm/drm_drv.h>
4647
#include <drm/ttm/ttm_bo_api.h>
4748
#include <drm/ttm/ttm_bo_driver.h>
4849
#include <drm/ttm/ttm_placement.h>
@@ -1804,6 +1805,7 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
18041805
*/
18051806
void amdgpu_ttm_fini(struct amdgpu_device *adev)
18061807
{
1808+
int idx;
18071809
if (!adev->mman.initialized)
18081810
return;
18091811

@@ -1818,6 +1820,15 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)
18181820
NULL, NULL);
18191821
amdgpu_ttm_fw_reserve_vram_fini(adev);
18201822

1823+
if (drm_dev_enter(adev_to_drm(adev), &idx)) {
1824+
1825+
if (adev->mman.aper_base_kaddr)
1826+
iounmap(adev->mman.aper_base_kaddr);
1827+
adev->mman.aper_base_kaddr = NULL;
1828+
1829+
drm_dev_exit(idx);
1830+
}
1831+
18211832
amdgpu_vram_mgr_fini(adev);
18221833
amdgpu_gtt_mgr_fini(adev);
18231834
amdgpu_preempt_mgr_fini(adev);

0 commit comments

Comments
 (0)