aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Deucher <alexdeucher@gmail.com>2018-04-06 15:54:09 -0400
committerAlex Deucher <alexander.deucher@amd.com>2018-05-15 14:43:16 -0400
commitebdef28ebbcf767d9fa687acb1d02d97d834c628 (patch)
tree08dad09318f1921187c4329b910f3a8a3197b4cb
parentf8bc903707ae87342b97528037e27bf190051c11 (diff)
drm/amdgpu/gmc: steal the appropriate amount of vram for fw hand-over (v3)
Steal 9 MB for vga emulation and fb if vga is enabled, otherwise, steal enough to cover the current display size as set by the vbios. If no memory is used (e.g., secondary or headless card), skip stolen memory reserve. v2: skip reservation if vram is limited, address Christian's comments v3: squash in fix from Harry Reviewed-and-Tested-by: Andrey Grodzovsky <andrey.grodzovsky@amd.com> (v2) Signed-off-by: Alex Deucher <alexdeucher@gmail.com>
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c14
-rw-r--r--drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c23
-rw-r--r--drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c23
-rw-r--r--drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c23
-rw-r--r--drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c53
5 files changed, 118 insertions, 18 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index ab73300e6c7f..2be04acf4efb 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -1441,12 +1441,14 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
1441 return r; 1441 return r;
1442 } 1442 }
1443 1443
1444 r = amdgpu_bo_create_kernel(adev, adev->gmc.stolen_size, PAGE_SIZE, 1444 if (adev->gmc.stolen_size) {
1445 AMDGPU_GEM_DOMAIN_VRAM, 1445 r = amdgpu_bo_create_kernel(adev, adev->gmc.stolen_size, PAGE_SIZE,
1446 &adev->stolen_vga_memory, 1446 AMDGPU_GEM_DOMAIN_VRAM,
1447 NULL, NULL); 1447 &adev->stolen_vga_memory,
1448 if (r) 1448 NULL, NULL);
1449 return r; 1449 if (r)
1450 return r;
1451 }
1450 DRM_INFO("amdgpu: %uM of VRAM memory ready\n", 1452 DRM_INFO("amdgpu: %uM of VRAM memory ready\n",
1451 (unsigned) (adev->gmc.real_vram_size / (1024 * 1024))); 1453 (unsigned) (adev->gmc.real_vram_size / (1024 * 1024)));
1452 1454
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
index 5617cf62c566..24e1ea36b454 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
@@ -825,6 +825,25 @@ static int gmc_v6_0_late_init(void *handle)
825 return 0; 825 return 0;
826} 826}
827 827
828static unsigned gmc_v6_0_get_vbios_fb_size(struct amdgpu_device *adev)
829{
830 u32 d1vga_control = RREG32(mmD1VGA_CONTROL);
831 unsigned size;
832
833 if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL, D1VGA_MODE_ENABLE)) {
834 size = 9 * 1024 * 1024; /* reserve 8MB for vga emulator and 1 MB for FB */
835 } else {
836 u32 viewport = RREG32(mmVIEWPORT_SIZE);
837 size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_HEIGHT) *
838 REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_WIDTH) *
839 4);
840 }
841 /* return 0 if the pre-OS buffer uses up most of vram */
842 if ((adev->gmc.real_vram_size - size) < (8 * 1024 * 1024))
843 return 0;
844 return size;
845}
846
828static int gmc_v6_0_sw_init(void *handle) 847static int gmc_v6_0_sw_init(void *handle)
829{ 848{
830 int r; 849 int r;
@@ -851,8 +870,6 @@ static int gmc_v6_0_sw_init(void *handle)
851 870
852 adev->gmc.mc_mask = 0xffffffffffULL; 871 adev->gmc.mc_mask = 0xffffffffffULL;
853 872
854 adev->gmc.stolen_size = 256 * 1024;
855
856 adev->need_dma32 = false; 873 adev->need_dma32 = false;
857 dma_bits = adev->need_dma32 ? 32 : 40; 874 dma_bits = adev->need_dma32 ? 32 : 40;
858 r = pci_set_dma_mask(adev->pdev, DMA_BIT_MASK(dma_bits)); 875 r = pci_set_dma_mask(adev->pdev, DMA_BIT_MASK(dma_bits));
@@ -878,6 +895,8 @@ static int gmc_v6_0_sw_init(void *handle)
878 if (r) 895 if (r)
879 return r; 896 return r;
880 897
898 adev->gmc.stolen_size = gmc_v6_0_get_vbios_fb_size(adev);
899
881 r = amdgpu_bo_init(adev); 900 r = amdgpu_bo_init(adev);
882 if (r) 901 if (r)
883 return r; 902 return r;
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
index 80054f36e487..93861f9c7773 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
@@ -964,6 +964,25 @@ static int gmc_v7_0_late_init(void *handle)
964 return 0; 964 return 0;
965} 965}
966 966
967static unsigned gmc_v7_0_get_vbios_fb_size(struct amdgpu_device *adev)
968{
969 u32 d1vga_control = RREG32(mmD1VGA_CONTROL);
970 unsigned size;
971
972 if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL, D1VGA_MODE_ENABLE)) {
973 size = 9 * 1024 * 1024; /* reserve 8MB for vga emulator and 1 MB for FB */
974 } else {
975 u32 viewport = RREG32(mmVIEWPORT_SIZE);
976 size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_HEIGHT) *
977 REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_WIDTH) *
978 4);
979 }
980 /* return 0 if the pre-OS buffer uses up most of vram */
981 if ((adev->gmc.real_vram_size - size) < (8 * 1024 * 1024))
982 return 0;
983 return size;
984}
985
967static int gmc_v7_0_sw_init(void *handle) 986static int gmc_v7_0_sw_init(void *handle)
968{ 987{
969 int r; 988 int r;
@@ -998,8 +1017,6 @@ static int gmc_v7_0_sw_init(void *handle)
998 */ 1017 */
999 adev->gmc.mc_mask = 0xffffffffffULL; /* 40 bit MC */ 1018 adev->gmc.mc_mask = 0xffffffffffULL; /* 40 bit MC */
1000 1019
1001 adev->gmc.stolen_size = 256 * 1024;
1002
1003 /* set DMA mask + need_dma32 flags. 1020 /* set DMA mask + need_dma32 flags.
1004 * PCIE - can handle 40-bits. 1021 * PCIE - can handle 40-bits.
1005 * IGP - can handle 40-bits 1022 * IGP - can handle 40-bits
@@ -1030,6 +1047,8 @@ static int gmc_v7_0_sw_init(void *handle)
1030 if (r) 1047 if (r)
1031 return r; 1048 return r;
1032 1049
1050 adev->gmc.stolen_size = gmc_v7_0_get_vbios_fb_size(adev);
1051
1033 /* Memory manager */ 1052 /* Memory manager */
1034 r = amdgpu_bo_init(adev); 1053 r = amdgpu_bo_init(adev);
1035 if (r) 1054 if (r)
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
index d71d4cb68f9c..fbd8f56c70f3 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
@@ -1055,6 +1055,25 @@ static int gmc_v8_0_late_init(void *handle)
1055 return 0; 1055 return 0;
1056} 1056}
1057 1057
1058static unsigned gmc_v8_0_get_vbios_fb_size(struct amdgpu_device *adev)
1059{
1060 u32 d1vga_control = RREG32(mmD1VGA_CONTROL);
1061 unsigned size;
1062
1063 if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL, D1VGA_MODE_ENABLE)) {
1064 size = 9 * 1024 * 1024; /* reserve 8MB for vga emulator and 1 MB for FB */
1065 } else {
1066 u32 viewport = RREG32(mmVIEWPORT_SIZE);
1067 size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_HEIGHT) *
1068 REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_WIDTH) *
1069 4);
1070 }
1071 /* return 0 if the pre-OS buffer uses up most of vram */
1072 if ((adev->gmc.real_vram_size - size) < (8 * 1024 * 1024))
1073 return 0;
1074 return size;
1075}
1076
1058#define mmMC_SEQ_MISC0_FIJI 0xA71 1077#define mmMC_SEQ_MISC0_FIJI 0xA71
1059 1078
1060static int gmc_v8_0_sw_init(void *handle) 1079static int gmc_v8_0_sw_init(void *handle)
@@ -1096,8 +1115,6 @@ static int gmc_v8_0_sw_init(void *handle)
1096 */ 1115 */
1097 adev->gmc.mc_mask = 0xffffffffffULL; /* 40 bit MC */ 1116 adev->gmc.mc_mask = 0xffffffffffULL; /* 40 bit MC */
1098 1117
1099 adev->gmc.stolen_size = 256 * 1024;
1100
1101 /* set DMA mask + need_dma32 flags. 1118 /* set DMA mask + need_dma32 flags.
1102 * PCIE - can handle 40-bits. 1119 * PCIE - can handle 40-bits.
1103 * IGP - can handle 40-bits 1120 * IGP - can handle 40-bits
@@ -1128,6 +1145,8 @@ static int gmc_v8_0_sw_init(void *handle)
1128 if (r) 1145 if (r)
1129 return r; 1146 return r;
1130 1147
1148 adev->gmc.stolen_size = gmc_v8_0_get_vbios_fb_size(adev);
1149
1131 /* Memory manager */ 1150 /* Memory manager */
1132 r = amdgpu_bo_init(adev); 1151 r = amdgpu_bo_init(adev);
1133 if (r) 1152 if (r)
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
index aeaed7fe9ced..3071f51d6ca6 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
@@ -57,6 +57,14 @@
57#define DF_CS_AON0_DramBaseAddress0__IntLvAddrSel_MASK 0x00000700L 57#define DF_CS_AON0_DramBaseAddress0__IntLvAddrSel_MASK 0x00000700L
58#define DF_CS_AON0_DramBaseAddress0__DramBaseAddr_MASK 0xFFFFF000L 58#define DF_CS_AON0_DramBaseAddress0__DramBaseAddr_MASK 0xFFFFF000L
59 59
60/* add these here since we already include dce12 headers and these are for DCN */
61#define mmHUBP0_DCSURF_PRI_VIEWPORT_DIMENSION 0x055d
62#define mmHUBP0_DCSURF_PRI_VIEWPORT_DIMENSION_BASE_IDX 2
63#define HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION__PRI_VIEWPORT_WIDTH__SHIFT 0x0
64#define HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION__PRI_VIEWPORT_HEIGHT__SHIFT 0x10
65#define HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION__PRI_VIEWPORT_WIDTH_MASK 0x00003FFFL
66#define HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION__PRI_VIEWPORT_HEIGHT_MASK 0x3FFF0000L
67
60/* XXX Move this macro to VEGA10 header file, which is like vid.h for VI.*/ 68/* XXX Move this macro to VEGA10 header file, which is like vid.h for VI.*/
61#define AMDGPU_NUM_OF_VMIDS 8 69#define AMDGPU_NUM_OF_VMIDS 8
62 70
@@ -791,6 +799,43 @@ static int gmc_v9_0_gart_init(struct amdgpu_device *adev)
791 return amdgpu_gart_table_vram_alloc(adev); 799 return amdgpu_gart_table_vram_alloc(adev);
792} 800}
793 801
802static unsigned gmc_v9_0_get_vbios_fb_size(struct amdgpu_device *adev)
803{
804#if 0
805 u32 d1vga_control = RREG32_SOC15(DCE, 0, mmD1VGA_CONTROL);
806#endif
807 unsigned size;
808
809 if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL, D1VGA_MODE_ENABLE)) {
810 size = 9 * 1024 * 1024; /* reserve 8MB for vga emulator and 1 MB for FB */
811 } else {
812 u32 viewport;
813
814 switch (adev->asic_type) {
815 case CHIP_RAVEN:
816 viewport = RREG32_SOC15(DCE, 0, mmHUBP0_DCSURF_PRI_VIEWPORT_DIMENSION);
817 size = (REG_GET_FIELD(viewport,
818 HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION, PRI_VIEWPORT_HEIGHT) *
819 REG_GET_FIELD(viewport,
820 HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION, PRI_VIEWPORT_WIDTH) *
821 4);
822 break;
823 case CHIP_VEGA10:
824 case CHIP_VEGA12:
825 default:
826 viewport = RREG32_SOC15(DCE, 0, mmSCL0_VIEWPORT_SIZE);
827 size = (REG_GET_FIELD(viewport, SCL0_VIEWPORT_SIZE, VIEWPORT_HEIGHT) *
828 REG_GET_FIELD(viewport, SCL0_VIEWPORT_SIZE, VIEWPORT_WIDTH) *
829 4);
830 break;
831 }
832 }
833 /* return 0 if the pre-OS buffer uses up most of vram */
834 if ((adev->gmc.real_vram_size - size) < (8 * 1024 * 1024))
835 return 0;
836 return size;
837}
838
794static int gmc_v9_0_sw_init(void *handle) 839static int gmc_v9_0_sw_init(void *handle)
795{ 840{
796 int r; 841 int r;
@@ -842,12 +887,6 @@ static int gmc_v9_0_sw_init(void *handle)
842 */ 887 */
843 adev->gmc.mc_mask = 0xffffffffffffULL; /* 48 bit MC */ 888 adev->gmc.mc_mask = 0xffffffffffffULL; /* 48 bit MC */
844 889
845 /*
846 * It needs to reserve 8M stolen memory for vega10
847 * TODO: Figure out how to avoid that...
848 */
849 adev->gmc.stolen_size = 8 * 1024 * 1024;
850
851 /* set DMA mask + need_dma32 flags. 890 /* set DMA mask + need_dma32 flags.
852 * PCIE - can handle 44-bits. 891 * PCIE - can handle 44-bits.
853 * IGP - can handle 44-bits 892 * IGP - can handle 44-bits
@@ -872,6 +911,8 @@ static int gmc_v9_0_sw_init(void *handle)
872 if (r) 911 if (r)
873 return r; 912 return r;
874 913
914 adev->gmc.stolen_size = gmc_v9_0_get_vbios_fb_size(adev);
915
875 /* Memory manager */ 916 /* Memory manager */
876 r = amdgpu_bo_init(adev); 917 r = amdgpu_bo_init(adev);
877 if (r) 918 if (r)