]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
drm/amdgpu: Free VGA stolen memory as soon as possible.
authorAndrey Grodzovsky <andrey.grodzovsky@amd.com>
Thu, 7 Mar 2019 06:51:46 +0000 (08:51 +0200)
committerStefan Bader <stefan.bader@canonical.com>
Mon, 1 Apr 2019 12:37:29 +0000 (14:37 +0200)
BugLink: https://launchpad.net/bugs/1818617
Reserved VRAM is used to avoid overriding pre OS FB.
Once our display stack takes over we don't need the reserved
VRAM anymore.

v2:
Remove comment, we know actually why we need to reserve the stolen VRAM.
Fix return type for amdgpu_ttm_late_init.
v3:
Return 0 in amdgpu_bo_late_init, rebase on changes to previous patch
v4: rebase
v5:
For GMC9 reserve always just 9M and keep the stolem memory around
until GART table curruption on S3 resume is resolved.

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
(backported from commit 6f752ec2c20c6a575da29d5b297980f376830e6b)
Signed-off-by: Timo Aaltonen <timo.aaltonen@canonical.com>
Acked-by: Khalid Elmously <khalid.elmously@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c

index 9f99cd19adfe1c988eb8a18dfdf83954473a66d9..857062abdc7f8cd8dee167a4e07e49b95dd2a21c 100644 (file)
@@ -790,6 +790,13 @@ int amdgpu_bo_init(struct amdgpu_device *adev)
        return amdgpu_ttm_init(adev);
 }
 
+int amdgpu_bo_late_init(struct amdgpu_device *adev)
+{
+       amdgpu_ttm_late_init(adev);
+
+       return 0;
+}
+
 void amdgpu_bo_fini(struct amdgpu_device *adev)
 {
        amdgpu_ttm_fini(adev);
index 428aae048f4b19bb2f31dbb168a9a12cb6ae5a2b..738b832d4ca35ba30c251820bc6db3308d632007 100644 (file)
@@ -230,6 +230,7 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,
 int amdgpu_bo_unpin(struct amdgpu_bo *bo);
 int amdgpu_bo_evict_vram(struct amdgpu_device *adev);
 int amdgpu_bo_init(struct amdgpu_device *adev);
+int amdgpu_bo_late_init(struct amdgpu_device *adev);
 void amdgpu_bo_fini(struct amdgpu_device *adev);
 int amdgpu_bo_fbdev_mmap(struct amdgpu_bo *bo,
                                struct vm_area_struct *vma);
index 8383529f429611fdce8604063edee2ddacc3622c..a2c5ac753c6ddb4d753b4e53a2c48d4344456219 100644 (file)
@@ -1410,6 +1410,11 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
        return 0;
 }
 
+void amdgpu_ttm_late_init(struct amdgpu_device *adev)
+{
+       amdgpu_bo_free_kernel(&adev->stolen_vga_memory, NULL, NULL);
+}
+
 void amdgpu_ttm_fini(struct amdgpu_device *adev)
 {
        int r;
@@ -1417,14 +1422,6 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)
        if (!adev->mman.initialized)
                return;
        amdgpu_ttm_debugfs_fini(adev);
-       if (adev->stolen_vga_memory) {
-               r = amdgpu_bo_reserve(adev->stolen_vga_memory, true);
-               if (r == 0) {
-                       amdgpu_bo_unpin(adev->stolen_vga_memory);
-                       amdgpu_bo_unreserve(adev->stolen_vga_memory);
-               }
-               amdgpu_bo_unref(&adev->stolen_vga_memory);
-       }
        ttm_bo_clean_mm(&adev->mman.bdev, TTM_PL_VRAM);
        ttm_bo_clean_mm(&adev->mman.bdev, TTM_PL_TT);
        if (adev->gds.mem.total_size)
index 402b08368ead0ca6c6ead6af9c7b240e5a2c4ee2..f3d7baa6511b9208fef2ee65f3fca00ae6637f2a 100644 (file)
@@ -74,6 +74,7 @@ u64 amdgpu_vram_mgr_bo_invisible_size(struct amdgpu_bo *bo);
 uint64_t amdgpu_vram_mgr_usage(struct ttm_mem_type_manager *man);
 uint64_t amdgpu_vram_mgr_vis_usage(struct ttm_mem_type_manager *man);
 
+void amdgpu_ttm_late_init(struct amdgpu_device *adev);
 int amdgpu_copy_buffer(struct amdgpu_ring *ring, uint64_t src_offset,
                       uint64_t dst_offset, uint32_t byte_count,
                       struct reservation_object *resv,
index 53c8c75545045caf0bd4d52efecd4674d6512b50..99cb3d727183a65605c3f72220ccda817881efb1 100644 (file)
@@ -803,6 +803,8 @@ static int gmc_v6_0_late_init(void *handle)
 {
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 
+       amdgpu_bo_late_init(adev);
+
        if (amdgpu_vm_fault_stop != AMDGPU_VM_FAULT_STOP_ALWAYS)
                return amdgpu_irq_get(adev, &adev->mc.vm_fault, 0);
        else
index e257ae9f873fea81858e1cd80e59f6bef88e3e26..f75f1eea13a1eef6025f4aa736732824638ca5ef 100644 (file)
@@ -938,6 +938,8 @@ static int gmc_v7_0_late_init(void *handle)
 {
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 
+       amdgpu_bo_late_init(adev);
+
        if (amdgpu_vm_fault_stop != AMDGPU_VM_FAULT_STOP_ALWAYS)
                return amdgpu_irq_get(adev, &adev->mc.vm_fault, 0);
        else
index dd30741964dbfb03a740e30b9dab3b0cf1cb28f8..d0ac1bd7ccf5cfa8437cdf52ee36c41713bb5f71 100644 (file)
@@ -1028,6 +1028,8 @@ static int gmc_v8_0_late_init(void *handle)
 {
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 
+       amdgpu_bo_late_init(adev);
+
        if (amdgpu_vm_fault_stop != AMDGPU_VM_FAULT_STOP_ALWAYS)
                return amdgpu_irq_get(adev, &adev->mc.vm_fault, 0);
        else
index 8a9b7e6850339bd725092c8206426220c945235a..1a6eef9b1b70bd0f59c63c0d426202e2cd20e568 100644 (file)
@@ -412,6 +412,11 @@ static int gmc_v9_0_late_init(void *handle)
        unsigned vm_inv_eng[AMDGPU_MAX_VMHUBS] = { 4, 4 };
        unsigned i;
 
+       /*
+        * TODO - Uncomment once GART corruption issue is fixed.
+        */
+       /* amdgpu_bo_late_init(adev); */
+
        for(i = 0; i < adev->num_rings; ++i) {
                struct amdgpu_ring *ring = adev->rings[i];
                unsigned vmhub = ring->funcs->vmhub;
@@ -561,6 +566,13 @@ static unsigned gmc_v9_0_get_vbios_fb_size(struct amdgpu_device *adev)
 #endif
        unsigned size;
 
+       /*
+        * TODO Remove once GART corruption is resolved
+        * Check related code in gmc_v9_0_sw_fini
+        * */
+       size = 9 * 1024 * 1024;
+
+#if 0
        if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL, D1VGA_MODE_ENABLE)) {
                size = 9 * 1024 * 1024; /* reserve 8MB for vga emulator and 1 MB for FB */
        } else {
@@ -588,6 +600,8 @@ static unsigned gmc_v9_0_get_vbios_fb_size(struct amdgpu_device *adev)
        /* return 0 if the pre-OS buffer uses up most of vram */
        if ((adev->mc.real_vram_size - size) < (8 * 1024 * 1024))
                return 0;
+
+#endif
        return size;
 }
 
@@ -723,6 +737,18 @@ static int gmc_v9_0_sw_fini(void *handle)
        amdgpu_vm_manager_fini(adev);
        gmc_v9_0_gart_fini(adev);
        amdgpu_gem_force_release(adev);
+
+       /*
+       * TODO:
+       * Currently there is a bug where some memory client outside
+       * of the driver writes to first 8M of VRAM on S3 resume,
+       * this overrides GART which by default gets placed in first 8M and
+       * causes VM_FAULTS once GTT is accessed.
+       * Keep the stolen memory reservation until the while this is not solved.
+       * Also check code in gmc_v9_0_get_vbios_fb_size and gmc_v9_0_late_init
+       */
+       amdgpu_bo_free_kernel(&adev->stolen_vga_memory, NULL, NULL);
+
        amdgpu_bo_fini(adev);
 
        return 0;