OSDN Git Service

drm/amdgpu: Unmap MMIO mappings when device is not unplugged
authorLeslie Shi <Yuliang.Shi@amd.com>
Wed, 5 Jan 2022 02:57:20 +0000 (10:57 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 11 Jan 2022 20:44:26 +0000 (15:44 -0500)
Patch: 3efb17ae7e92 ("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>
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c

index 500a9e6..ef10981 100644 (file)
@@ -3833,6 +3833,7 @@ failed:
 
 static void amdgpu_device_unmap_mmio(struct amdgpu_device *adev)
 {
+
        /* Clear all CPU mappings pointing to this device */
        unmap_mapping_range(adev->ddev.anon_inode->i_mapping, 0, 0, 1);
 
@@ -3913,6 +3914,8 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)
 
 void amdgpu_device_fini_sw(struct amdgpu_device *adev)
 {
+       int idx;
+
        amdgpu_fence_driver_sw_fini(adev);
        amdgpu_device_ip_fini(adev);
        release_firmware(adev->firmware.gpu_info_fw);
@@ -3937,6 +3940,14 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev)
        if ((adev->pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA)
                vga_client_unregister(adev->pdev);
 
+       if (drm_dev_enter(adev_to_drm(adev), &idx)) {
+
+               iounmap(adev->rmmio);
+               adev->rmmio = NULL;
+               amdgpu_device_doorbell_fini(adev);
+               drm_dev_exit(idx);
+       }
+
        if (IS_ENABLED(CONFIG_PERF_EVENTS))
                amdgpu_pmu_fini(adev);
        if (adev->mman.discovery_bin)
index 3a7b56e..5661b82 100644 (file)
@@ -33,6 +33,7 @@
 #include <linux/slab.h>
 #include <linux/dma-buf.h>
 
+#include <drm/drm_drv.h>
 #include <drm/amdgpu_drm.h>
 #include <drm/drm_cache.h>
 #include "amdgpu.h"
@@ -1061,7 +1062,18 @@ int amdgpu_bo_init(struct amdgpu_device *adev)
  */
 void amdgpu_bo_fini(struct amdgpu_device *adev)
 {
+       int idx;
+
        amdgpu_ttm_fini(adev);
+
+       if (drm_dev_enter(adev_to_drm(adev), &idx)) {
+
+               if (!adev->gmc.xgmi.connected_to_cpu) {
+                       arch_phys_wc_del(adev->gmc.vram_mtrr);
+                       arch_io_free_memtype_wc(adev->gmc.aper_base, adev->gmc.aper_size);
+               }
+               drm_dev_exit(idx);
+       }
 }
 
 /**
index fb0d8bf..5c3f240 100644 (file)
@@ -43,6 +43,7 @@
 #include <linux/sizes.h>
 #include <linux/module.h>
 
+#include <drm/drm_drv.h>
 #include <drm/ttm/ttm_bo_api.h>
 #include <drm/ttm/ttm_bo_driver.h>
 #include <drm/ttm/ttm_placement.h>
@@ -1804,6 +1805,7 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
  */
 void amdgpu_ttm_fini(struct amdgpu_device *adev)
 {
+       int idx;
        if (!adev->mman.initialized)
                return;
 
@@ -1818,6 +1820,15 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)
                                      NULL, NULL);
        amdgpu_ttm_fw_reserve_vram_fini(adev);
 
+       if (drm_dev_enter(adev_to_drm(adev), &idx)) {
+
+               if (adev->mman.aper_base_kaddr)
+                       iounmap(adev->mman.aper_base_kaddr);
+               adev->mman.aper_base_kaddr = NULL;
+
+               drm_dev_exit(idx);
+       }
+
        amdgpu_vram_mgr_fini(adev);
        amdgpu_gtt_mgr_fini(adev);
        amdgpu_preempt_mgr_fini(adev);