[PATCH v3 6/9] drm/radeon: Add an implement for the is_primary_gpu function callback

From: Sui Jingfeng
Date: Tue Jul 11 2023 - 12:44:22 EST


From: Sui Jingfeng <suijingfeng@xxxxxxxxxxx>

[why]

The vga_is_firmware_default() function defined in drivers/pci/vgaarb.c is
arch-dependent, it's no-op on non-x86 architectures. The arbitration is
not usabe on non-x86 platform.

[how]

The device that owns the firmware framebuffer should be the default boot
device. This patch adds an arch-independent function to implement this
rule. The vgaarb will call back to radeon_is_primary_gpu() when drm/radeon
is bound to a ATI gpu device successfully.

Cc: Alex Deucher <alexander.deucher@xxxxxxx>
Cc: Christian Konig <christian.koenig@xxxxxxx>
Cc: Pan Xinhui <Xinhui.Pan@xxxxxxx>
Cc: David Airlie <airlied@xxxxxxxxx>
Cc: Daniel Vetter <daniel@xxxxxxxx>
Signed-off-by: Sui Jingfeng <suijingfeng@xxxxxxxxxxx>
---
drivers/gpu/drm/radeon/radeon_device.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
index 71f2ff39d6a1..7db8dc5f79a9 100644
--- a/drivers/gpu/drm/radeon/radeon_device.c
+++ b/drivers/gpu/drm/radeon/radeon_device.c
@@ -34,6 +34,7 @@
#include <linux/vga_switcheroo.h>
#include <linux/vgaarb.h>

+#include <drm/drm_aperture.h>
#include <drm/drm_cache.h>
#include <drm/drm_crtc_helper.h>
#include <drm/drm_device.h>
@@ -1263,6 +1264,15 @@ static const struct vga_switcheroo_client_ops radeon_switcheroo_ops = {
.can_switch = radeon_switcheroo_can_switch,
};

+static bool radeon_vga_is_primary_gpu(struct pci_dev *pdev)
+{
+ struct drm_device *dev = pci_get_drvdata(pdev);
+ struct radeon_device *rdev = dev->dev_private;
+ struct radeon_mc *gmc = &rdev->mc;
+
+ return drm_aperture_contain_firmware_fb(gmc->aper_base, gmc->aper_size);
+}
+
/**
* radeon_device_init - initialize the driver
*
@@ -1425,7 +1435,7 @@ int radeon_device_init(struct radeon_device *rdev,
/* if we have > 1 VGA cards, then disable the radeon VGA resources */
/* this will fail for cards that aren't VGA class devices, just
* ignore it */
- vga_client_register(rdev->pdev, radeon_vga_set_decode, NULL);
+ vga_client_register(rdev->pdev, radeon_vga_set_decode, radeon_vga_is_primary_gpu);

if (rdev->flags & RADEON_IS_PX)
runtime = true;
--
2.25.1