[PATCH] drm: add func to better detect wether swiotlb is needed

2019-02-20 Thread Michael D Labriola
This commit fixes DRM failures on Xen PV systems that were introduced in
v4.17 by the following commits:

82626363 drm: add func to get max iomem address v2
fd5fd480 drm/amdgpu: only enable swiotlb alloc when need v2
1bc3d3cc drm/radeon: only enable swiotlb path when need v2

The introduction of ->need_swiotlb to the ttm_dma_populate() conditionals
in the radeon and amdgpu device drivers causes Gnome to immediately crash
on Xen PV systems, returning the user to the login screen.  The following
kernel errors get logged:

[   28.554259] radeon_dp_aux_transfer_native: 200 callbacks suppressed
[   31.219821] radeon :01:00.0: swiotlb buffer is full (sz: 2097152 bytes)
[   31.220030] [drm:radeon_gem_object_create [radeon]] *ERROR* Failed to 
allocate GEM object (16384000, 2, 4096, -14)
[   31.226109] radeon :01:00.0: swiotlb buffer is full (sz: 2097152 bytes)
[   31.226300] [drm:radeon_gem_object_create [radeon]] *ERROR* Failed to 
allocate GEM object (16384000, 2, 4096, -14)
[   31.300734] gnome-shell[1935]: segfault at 88 ip 7f39151cd904 sp 
7ffc97611ad8 error 4 in libmutter-cogl.so[7f3915178000+aa000]
[   31.300745] Code: 5f c3 0f 1f 40 00 48 8b 47 78 48 8b 40 40 ff e0 66 0f 1f 
44 00 00 48 8b 47 78 48 8b 40 48 ff e0 66 0f 1f 44 00 00 48 8b 47 78 <48> 8b 80 
88 00 00 00 ff e0 0f 1f 00 48 8b 47 78 48 8b 40 68 ff e0
[   38.193302] radeon_dp_aux_transfer_native: 116 callbacks suppressed
[   40.009317] radeon :01:00.0: swiotlb buffer is full (sz: 2097152 bytes)
[   40.009488] [drm:radeon_gem_object_create [radeon]] *ERROR* Failed to 
allocate GEM object (16384000, 2, 4096, -14)
[   40.015114] radeon :01:00.0: swiotlb buffer is full (sz: 2097152 bytes)
[   40.015297] [drm:radeon_gem_object_create [radeon]] *ERROR* Failed to 
allocate GEM object (16384000, 2, 4096, -14)
[   40.028302] gnome-shell[2431]: segfault at 2dadf40 ip 02dadf40 sp 
7ffcd24ea5f8 error 15
[   40.028306] Code: 20 6e 31 00 00 00 00 00 00 00 00 37 e3 3d 2d 7f 00 00 80 
f4 e6 3d 2d 7f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 <00> 00 00 
00 00 00 00 00 c1 00 00 00 00 00 00 00 80 e1 d2 03 00 00

This commit renames drm_get_max_iomem() to drm_need_swiotlb(), adds a
xen_pv_domain() check to it, and moves the bit shifting comparison that
always follows its usage into the function (simplifying the drm driver
code).

Signed-off-by: Michael D Labriola 
---
 drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c  |  2 +-
 drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c  |  2 +-
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c  |  2 +-
 drivers/gpu/drm/drm_memory.c   | 19 ---
 drivers/gpu/drm/radeon/radeon_device.c |  2 +-
 include/drm/drm_cache.h|  2 +-
 6 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c 
b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
index 910c4ce..6bc0266 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
@@ -1029,7 +1029,7 @@ static int gmc_v7_0_sw_init(void *handle)
pci_set_consistent_dma_mask(adev->pdev, DMA_BIT_MASK(32));
pr_warn("amdgpu: No coherent DMA available\n");
}
-   adev->need_swiotlb = drm_get_max_iomem() > ((u64)1 << dma_bits);
+   adev->need_swiotlb = drm_need_swiotlb(dma_bits);
 
r = gmc_v7_0_init_microcode(adev);
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 747c068..8638adf 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
@@ -1155,7 +1155,7 @@ static int gmc_v8_0_sw_init(void *handle)
pci_set_consistent_dma_mask(adev->pdev, DMA_BIT_MASK(32));
pr_warn("amdgpu: No coherent DMA available\n");
}
-   adev->need_swiotlb = drm_get_max_iomem() > ((u64)1 << dma_bits);
+   adev->need_swiotlb = drm_need_swiotlb(dma_bits);
 
r = gmc_v8_0_init_microcode(adev);
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 f35d7a5..4f67093 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
@@ -989,7 +989,7 @@ static int gmc_v9_0_sw_init(void *handle)
pci_set_consistent_dma_mask(adev->pdev, DMA_BIT_MASK(32));
printk(KERN_WARNING "amdgpu: No coherent DMA available.\n");
}
-   adev->need_swiotlb = drm_get_max_iomem() > ((u64)1 << dma_bits);
+   adev->need_swiotlb = drm_need_swiotlb(dma_bits);
 
if (adev->asic_type == CHIP_VEGA20) {
r = gfxhub_v1_1_get_xgmi_info(adev);
diff --git a/drivers/gpu/drm/drm_memory.c b/drivers/gpu/drm/drm_memory.c
index d69e4fc..6af59a6 100644
--- a/drivers/gpu/drm/drm_memory.c
+++ b/drivers/gpu/drm/drm_memory.c
@@ -35,6 +35,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include

gma500: invalid frequency for monitor

2012-02-04 Thread Michael D Labriola
I've got a VersaLogic Ocelot (Atom Z530, Menlow) and I've been test
driving the new GMA500 driver w/out much luck.  I tried the old
staging driver a few times, and just compiled and tested a checkout
from Linus' tree (d12566).  I've got the gma500 driver compiled as a
module, with the optional parts disabled.  Here's what I'm seeing.

My system boots up, loads drm, loads gma500_gfx, and then my monitor's
OSD says "Out of Frequency".  Pretty much the same behavior with the
old psb_gfx module and the new gma500_gfx module.

My system is configured with a LVDS-VGA adapter board, which is
plugged into the VGA port on a 1680x1050 LCD.  The BIOS for the Ocelot
is configured for a 1280x1024 LVDS panel, which seems like a
resolution my monitor should be able to handle.  I've attached
relevant kernel log with drm.debug set to 999.

I think my setup is correct, because the vesa frambuffer seems to work
correctly.  All is well unless I load the gma500_gfx driver and let it
set the mode.

I'd love to help nail this down, let me know if you want me to try
anything.

[  102.969863] [drm] Initialized drm 1.1.0 20060810
[  110.192778] [drm:drm_pci_init], 
[  110.192863] [drm:drm_get_pci_dev], 
[  110.192930] gma500 :00:02.0: setting latency timer to 64
[  110.193545] [drm:drm_get_minor], 
[  110.193863] [drm:drm_get_minor], new minor assigned 64
[  110.193887] [drm:drm_get_minor], 
[  110.194753] [drm:drm_get_minor], new minor assigned 0
[  110.197942] ioremap error for 0x7f7f8000-0x7f7fb000, requested 0x10, got 0x0
[  110.206418] [drm:drm_mode_debug_printmodeline], Modeline 0:"1280x1024" 0 
108000 1280 1328 1440 1688 1024 1025 1028 1072 0x8 0x0
[  110.207738] Stolen memory information
[  110.207757]base in RAM: 0x7f80
[  110.207771]size: 8060K, calculated by (GTT RAM base) - (Stolen 
base), seems wrong
[  110.207789]   the correct size should be: 8M(dvmt mode=3)
[  110.216955] Set up 2015 stolen pages starting at 0x7f80, GTT offset 0K
[  110.217662] [drm] SGX core id = 0x0113
[  110.217682] [drm] SGX core rev major = 0x01, minor = 0x02
[  110.217701] [drm] SGX core rev maintenance = 0x01, designer = 0x00
[  110.223579] input: Video Bus as 
/devices/LNXSYSTM:00/device:00/PNP0A03:00/LNXVIDEO:00/input/input6
[  110.223800] ACPI: Video Device [GFX0] (multi-head: yes  rom: no  post: no)
[  110.223940] [drm] Supports vblank timestamp caching Rev 1 (10.10.2010).
[  110.223958] [drm] No driver support for vblank timestamp query.
[  110.223980] [drm:drm_irq_install], irq=16
[  110.257714] [drm:drm_sysfs_connector_add], adding "LVDS-1" to sysfs
[  110.257932] [drm:drm_sysfs_hotplug_event], generating hotplug event
[  110.269604] [drm:psb_intel_sdvo_read_byte], i2c transfer returned -6
[  110.269633] [drm:psb_intel_sdvo_init], No SDVO device found on SDVOB
[  110.561304] [drm:drm_helper_probe_single_connector_modes], 
[CONNECTOR:7:LVDS-1]
[  110.586242] [drm:drm_helper_probe_single_connector_modes], 
[CONNECTOR:7:LVDS-1] probed modes :
[  110.586274] [drm:drm_mode_debug_printmodeline], Modeline 10:"1280x1024" 40 
71500 1280 1328 1440 1688 1024 1025 1028 1072 0x8 0x0
[  110.586314] [drm:drm_setup_crtcs], 
[  110.586335] [drm:drm_enable_connectors], connector 7 enabled? yes
[  110.586357] [drm:drm_target_preferred], looking for cmdline mode on 
connector 7
[  110.586380] [drm:drm_target_preferred], looking for preferred mode on 
connector 7
[  110.586402] [drm:drm_target_preferred], found mode 1280x1024
[  110.586423] [drm:drm_setup_crtcs], picking CRTCs for 2048x2048 config
[  110.586450] [drm:drm_setup_crtcs], desired mode 1280x1024 set on crtc 4
[  110.586513] gma500 :00:02.0: allocated 1280x1024 fb
[  110.586819] fbcon: psbfb (fb0) is primary device
[  110.596288] [drm:drm_crtc_helper_set_config], 
[  110.596306] [drm:drm_crtc_helper_set_config], [CRTC:3] [NOFB]
[  110.637408] [drm:drm_crtc_helper_set_config], 
[  110.637427] [drm:drm_crtc_helper_set_config], [CRTC:4] [FB:12] #connectors=1 
(x y) (0 0)
[  110.637467] [drm:drm_crtc_helper_set_config], crtc has no fb, full mode set
[  110.637484] [drm:drm_crtc_helper_set_config], modes are different, full mode 
set
[  110.637500] [drm:drm_mode_debug_printmodeline], Modeline 0:"" 0 0 0 0 0 0 0 
0 0 0 0x0 0x0
[  110.637529] [drm:drm_mode_debug_printmodeline], Modeline 11:"1280x1024" 40 
71500 1280 1328 1440 1688 1024 1025 1028 1072 0x8 0x0
[  110.637564] [drm:drm_crtc_helper_set_config], encoder changed, full mode 
switch
[  110.637580] [drm:drm_crtc_helper_set_config], crtc changed, full mode switch
[  110.637599] [drm:drm_crtc_helper_set_config], [CONNECTOR:7:LVDS-1] to 
[CRTC:4]
[  110.637618] [drm:drm_crtc_helper_set_config], attempting to set mode from 
userspace
[  110.637634] [drm:drm_mode_debug_printmodeline], Modeline 11:"1280x1024" 40 
71500 1280 1328 1440 1688 1024 1025 1028 1072 0x8 0x0
[  110.637678] [drm:drm_crtc_helper_set_mode], [CRTC:4]
[  110.658501] [drm:drm_mode_debug_printmodeline], Modeline 11:"1280x1024" 40 
71500 1280 13

gma500: invalid frequency for monitor

2012-02-03 Thread Michael D Labriola
I've got a VersaLogic Ocelot (Atom Z530, Menlow) and I've been test
driving the new GMA500 driver w/out much luck.  I tried the old
staging driver a few times, and just compiled and tested a checkout
from Linus' tree (d12566).  I've got the gma500 driver compiled as a
module, with the optional parts disabled.  Here's what I'm seeing.

My system boots up, loads drm, loads gma500_gfx, and then my monitor's
OSD says "Out of Frequency".  Pretty much the same behavior with the
old psb_gfx module and the new gma500_gfx module.

My system is configured with a LVDS-VGA adapter board, which is
plugged into the VGA port on a 1680x1050 LCD.  The BIOS for the Ocelot
is configured for a 1280x1024 LVDS panel, which seems like a
resolution my monitor should be able to handle.  I've attached
relevant kernel log with drm.debug set to 999.

I think my setup is correct, because the vesa frambuffer seems to work
correctly.  All is well unless I load the gma500_gfx driver and let it
set the mode.

I'd love to help nail this down, let me know if you want me to try
anything.

[  102.969863] [drm] Initialized drm 1.1.0 20060810
[  110.192778] [drm:drm_pci_init], 
[  110.192863] [drm:drm_get_pci_dev], 
[  110.192930] gma500 :00:02.0: setting latency timer to 64
[  110.193545] [drm:drm_get_minor], 
[  110.193863] [drm:drm_get_minor], new minor assigned 64
[  110.193887] [drm:drm_get_minor], 
[  110.194753] [drm:drm_get_minor], new minor assigned 0
[  110.197942] ioremap error for 0x7f7f8000-0x7f7fb000, requested 0x10, got 0x0
[  110.206418] [drm:drm_mode_debug_printmodeline], Modeline 0:"1280x1024" 0 
108000 1280 1328 1440 1688 1024 1025 1028 1072 0x8 0x0
[  110.207738] Stolen memory information
[  110.207757]base in RAM: 0x7f80
[  110.207771]size: 8060K, calculated by (GTT RAM base) - (Stolen 
base), seems wrong
[  110.207789]   the correct size should be: 8M(dvmt mode=3)
[  110.216955] Set up 2015 stolen pages starting at 0x7f80, GTT offset 0K
[  110.217662] [drm] SGX core id = 0x0113
[  110.217682] [drm] SGX core rev major = 0x01, minor = 0x02
[  110.217701] [drm] SGX core rev maintenance = 0x01, designer = 0x00
[  110.223579] input: Video Bus as 
/devices/LNXSYSTM:00/device:00/PNP0A03:00/LNXVIDEO:00/input/input6
[  110.223800] ACPI: Video Device [GFX0] (multi-head: yes  rom: no  post: no)
[  110.223940] [drm] Supports vblank timestamp caching Rev 1 (10.10.2010).
[  110.223958] [drm] No driver support for vblank timestamp query.
[  110.223980] [drm:drm_irq_install], irq=16
[  110.257714] [drm:drm_sysfs_connector_add], adding "LVDS-1" to sysfs
[  110.257932] [drm:drm_sysfs_hotplug_event], generating hotplug event
[  110.269604] [drm:psb_intel_sdvo_read_byte], i2c transfer returned -6
[  110.269633] [drm:psb_intel_sdvo_init], No SDVO device found on SDVOB
[  110.561304] [drm:drm_helper_probe_single_connector_modes], 
[CONNECTOR:7:LVDS-1]
[  110.586242] [drm:drm_helper_probe_single_connector_modes], 
[CONNECTOR:7:LVDS-1] probed modes :
[  110.586274] [drm:drm_mode_debug_printmodeline], Modeline 10:"1280x1024" 40 
71500 1280 1328 1440 1688 1024 1025 1028 1072 0x8 0x0
[  110.586314] [drm:drm_setup_crtcs], 
[  110.586335] [drm:drm_enable_connectors], connector 7 enabled? yes
[  110.586357] [drm:drm_target_preferred], looking for cmdline mode on 
connector 7
[  110.586380] [drm:drm_target_preferred], looking for preferred mode on 
connector 7
[  110.586402] [drm:drm_target_preferred], found mode 1280x1024
[  110.586423] [drm:drm_setup_crtcs], picking CRTCs for 2048x2048 config
[  110.586450] [drm:drm_setup_crtcs], desired mode 1280x1024 set on crtc 4
[  110.586513] gma500 :00:02.0: allocated 1280x1024 fb
[  110.586819] fbcon: psbfb (fb0) is primary device
[  110.596288] [drm:drm_crtc_helper_set_config], 
[  110.596306] [drm:drm_crtc_helper_set_config], [CRTC:3] [NOFB]
[  110.637408] [drm:drm_crtc_helper_set_config], 
[  110.637427] [drm:drm_crtc_helper_set_config], [CRTC:4] [FB:12] #connectors=1 
(x y) (0 0)
[  110.637467] [drm:drm_crtc_helper_set_config], crtc has no fb, full mode set
[  110.637484] [drm:drm_crtc_helper_set_config], modes are different, full mode 
set
[  110.637500] [drm:drm_mode_debug_printmodeline], Modeline 0:"" 0 0 0 0 0 0 0 
0 0 0 0x0 0x0
[  110.637529] [drm:drm_mode_debug_printmodeline], Modeline 11:"1280x1024" 40 
71500 1280 1328 1440 1688 1024 1025 1028 1072 0x8 0x0
[  110.637564] [drm:drm_crtc_helper_set_config], encoder changed, full mode 
switch
[  110.637580] [drm:drm_crtc_helper_set_config], crtc changed, full mode switch
[  110.637599] [drm:drm_crtc_helper_set_config], [CONNECTOR:7:LVDS-1] to 
[CRTC:4]
[  110.637618] [drm:drm_crtc_helper_set_config], attempting to set mode from 
userspace
[  110.637634] [drm:drm_mode_debug_printmodeline], Modeline 11:"1280x1024" 40 
71500 1280 1328 1440 1688 1024 1025 1028 1072 0x8 0x0
[  110.637678] [drm:drm_crtc_helper_set_mode], [CRTC:4]
[  110.658501] [drm:drm_mode_debug_printmodeline], Modeline 11:"1280x1024" 40 
71500 1280 13

[PATCH RFC] drm: add func to better detect wether swiotlb is needed

2019-02-18 Thread Michael D Labriola via dri-devel
This commit fixes DRM failures on Xen PV systems that were introduced in
v4.17 by the following commits:

82626363 drm: add func to get max iomem address v2
fd5fd480 drm/amdgpu: only enable swiotlb alloc when need v2
1bc3d3cc drm/radeon: only enable swiotlb path when need v2

The introduction of ->need_swiotlb to the ttm_dma_populate() conditionals
in the radeon and amdgpu device drivers causes Gnome to immediately crash
on Xen PV systems, returning the user to the login screen.  The following
kernel errors get logged:

[   28.554259] radeon_dp_aux_transfer_native: 200 callbacks suppressed
[   31.219821] radeon :01:00.0: swiotlb buffer is full (sz: 2097152 bytes)
[   31.220030] [drm:radeon_gem_object_create [radeon]] *ERROR* Failed to 
allocate GEM object (16384000, 2, 4096, -14)
[   31.226109] radeon :01:00.0: swiotlb buffer is full (sz: 2097152 bytes)
[   31.226300] [drm:radeon_gem_object_create [radeon]] *ERROR* Failed to 
allocate GEM object (16384000, 2, 4096, -14)
[   31.300734] gnome-shell[1935]: segfault at 88 ip 7f39151cd904 sp 
7ffc97611ad8 error 4 in libmutter-cogl.so[7f3915178000+aa000]
[   31.300745] Code: 5f c3 0f 1f 40 00 48 8b 47 78 48 8b 40 40 ff e0 66 0f 1f 
44 00 00 48 8b 47 78 48 8b 40 48 ff e0 66 0f 1f 44 00 00 48 8b 47 78 <48> 8b 80 
88 00 00 00 ff e0 0f 1f 00 48 8b 47 78 48 8b 40 68 ff e0
[   38.193302] radeon_dp_aux_transfer_native: 116 callbacks suppressed
[   40.009317] radeon :01:00.0: swiotlb buffer is full (sz: 2097152 bytes)
[   40.009488] [drm:radeon_gem_object_create [radeon]] *ERROR* Failed to 
allocate GEM object (16384000, 2, 4096, -14)
[   40.015114] radeon :01:00.0: swiotlb buffer is full (sz: 2097152 bytes)
[   40.015297] [drm:radeon_gem_object_create [radeon]] *ERROR* Failed to 
allocate GEM object (16384000, 2, 4096, -14)
[   40.028302] gnome-shell[2431]: segfault at 2dadf40 ip 02dadf40 sp 
7ffcd24ea5f8 error 15
[   40.028306] Code: 20 6e 31 00 00 00 00 00 00 00 00 37 e3 3d 2d 7f 00 00 80 
f4 e6 3d 2d 7f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 <00> 00 00 
00 00 00 00 00 c1 00 00 00 00 00 00 00 80 e1 d2 03 00 00

This commit renames drm_get_max_iomem() to drm_need_swiotlb(), adds a
xen_pv_domain() check to it, and moves the bit shifting comparison that
always follows its usage into the function (simplifying the drm driver
code).
---
 drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c  |  2 +-
 drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c  |  2 +-
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c  |  2 +-
 drivers/gpu/drm/drm_memory.c   | 19 ---
 drivers/gpu/drm/radeon/radeon_device.c |  2 +-
 include/drm/drm_cache.h|  2 +-
 6 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c 
b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
index 910c4ce..6bc0266 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
@@ -1029,7 +1029,7 @@ static int gmc_v7_0_sw_init(void *handle)
pci_set_consistent_dma_mask(adev->pdev, DMA_BIT_MASK(32));
pr_warn("amdgpu: No coherent DMA available\n");
}
-   adev->need_swiotlb = drm_get_max_iomem() > ((u64)1 << dma_bits);
+   adev->need_swiotlb = drm_need_swiotlb(dma_bits);
 
r = gmc_v7_0_init_microcode(adev);
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 747c068..8638adf 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
@@ -1155,7 +1155,7 @@ static int gmc_v8_0_sw_init(void *handle)
pci_set_consistent_dma_mask(adev->pdev, DMA_BIT_MASK(32));
pr_warn("amdgpu: No coherent DMA available\n");
}
-   adev->need_swiotlb = drm_get_max_iomem() > ((u64)1 << dma_bits);
+   adev->need_swiotlb = drm_need_swiotlb(dma_bits);
 
r = gmc_v8_0_init_microcode(adev);
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 f35d7a5..4f67093 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
@@ -989,7 +989,7 @@ static int gmc_v9_0_sw_init(void *handle)
pci_set_consistent_dma_mask(adev->pdev, DMA_BIT_MASK(32));
printk(KERN_WARNING "amdgpu: No coherent DMA available.\n");
}
-   adev->need_swiotlb = drm_get_max_iomem() > ((u64)1 << dma_bits);
+   adev->need_swiotlb = drm_need_swiotlb(dma_bits);
 
if (adev->asic_type == CHIP_VEGA20) {
r = gfxhub_v1_1_get_xgmi_info(adev);
diff --git a/drivers/gpu/drm/drm_memory.c b/drivers/gpu/drm/drm_memory.c
index d69e4fc..6af59a6 100644
--- a/drivers/gpu/drm/drm_memory.c
+++ b/drivers/gpu/drm/drm_memory.c
@@ -35,6 +35,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include "drm_legacy.h"
 
@@ -150,15 +151,27 @@ void drm_legacy_ioremapfree(struct drm_local_map *map, 
struct drm_device *dev)
 }
 EXPORT_SYMBOL(d