drm/amdgpu: move keep stolen memory check into gmc core
authorAlex Deucher <alexander.deucher@amd.com>
Tue, 28 Jul 2020 21:55:30 +0000 (17:55 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 4 Aug 2020 21:29:28 +0000 (17:29 -0400)
Rather than leaving this as a gmc v9 specific hack.

Reviewed-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c

index ddb64be..0cf18f0 100644 (file)
@@ -215,6 +215,7 @@ struct amdgpu_gmc {
        bool                    prt_warning;
        uint64_t                stolen_vga_size;
        struct amdgpu_bo        *stolen_vga_memory;
+       bool                    keep_stolen_vga_memory;
        uint32_t                sdpif_register;
        /* apertures */
        u64                     shared_aperture_start;
index 3978112..fd61769 100644 (file)
@@ -2042,8 +2042,10 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
 void amdgpu_ttm_late_init(struct amdgpu_device *adev)
 {
        void *stolen_vga_buf;
+
        /* return the VGA stolen memory (if any) back to VRAM */
-       amdgpu_bo_free_kernel(&adev->gmc.stolen_vga_memory, NULL, &stolen_vga_buf);
+       if (!adev->gmc.keep_stolen_vga_memory)
+               amdgpu_bo_free_kernel(&adev->gmc.stolen_vga_memory, NULL, &stolen_vga_buf);
 }
 
 /**
@@ -2051,10 +2053,15 @@ void amdgpu_ttm_late_init(struct amdgpu_device *adev)
  */
 void amdgpu_ttm_fini(struct amdgpu_device *adev)
 {
+       void *stolen_vga_buf;
+
        if (!adev->mman.initialized)
                return;
 
        amdgpu_ttm_training_reserve_vram_fini(adev);
+       /* return the stolen vga memory back to VRAM */
+       if (adev->gmc.keep_stolen_vga_memory)
+               amdgpu_bo_free_kernel(&adev->gmc.stolen_vga_memory, NULL, &stolen_vga_buf);
        /* return the IP Discovery TMR memory back to VRAM */
        amdgpu_bo_free_kernel(&adev->discovery_memory, NULL, NULL);
        amdgpu_ttm_fw_reserve_vram_fini(adev);
index b66c606..c5d2e43 100644 (file)
@@ -932,8 +932,7 @@ static int gmc_v9_0_late_init(void *handle)
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
        int r;
 
-       if (!gmc_v9_0_keep_stolen_memory(adev))
-               amdgpu_bo_late_init(adev);
+       amdgpu_bo_late_init(adev);
 
        r = amdgpu_gmc_allocate_vm_inv_eng(adev);
        if (r)
@@ -1076,7 +1075,7 @@ static unsigned gmc_v9_0_get_vbios_fb_size(struct amdgpu_device *adev)
         * TODO Remove once GART corruption is resolved
         * Check related code in gmc_v9_0_sw_fini
         * */
-       if (gmc_v9_0_keep_stolen_memory(adev))
+       if (adev->gmc.keep_stolen_vga_memory)
                return AMDGPU_VBIOS_VGA_ALLOCATION;
 
        d1vga_control = RREG32_SOC15(DCE, 0, mmD1VGA_CONTROL);
@@ -1243,6 +1242,7 @@ static int gmc_v9_0_sw_init(void *handle)
        if (r)
                return r;
 
+       adev->gmc.keep_stolen_vga_memory = gmc_v9_0_keep_stolen_memory(adev);
        adev->gmc.stolen_vga_size = gmc_v9_0_get_vbios_fb_size(adev);
 
        /* Memory manager */
@@ -1275,15 +1275,10 @@ static int gmc_v9_0_sw_init(void *handle)
 static int gmc_v9_0_sw_fini(void *handle)
 {
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
-       void *stolen_vga_buf;
 
        amdgpu_gmc_ras_fini(adev);
        amdgpu_gem_force_release(adev);
        amdgpu_vm_manager_fini(adev);
-
-       if (gmc_v9_0_keep_stolen_memory(adev))
-               amdgpu_bo_free_kernel(&adev->gmc.stolen_vga_memory, NULL, &stolen_vga_buf);
-
        amdgpu_gart_table_vram_free(adev);
        amdgpu_bo_fini(adev);
        amdgpu_gart_fini(adev);