2023-07-02 18:49:34

by Sui Jingfeng

[permalink] [raw]
Subject: [PATCH v2 0/6] PCI/VGA: Improve the default VGA device selection

From: Sui Jingfeng <[email protected]>

Currently, the default VGA device selection is not perfect. Potential
problems are:

1) This function is a no-op on non-x86 architectures.
2) It does not take the PCI Bar may get relocated into consideration.
3) It is not effective for the PCI device without a dedicated VRAM Bar.
4) It is device-agnostic, thus it has to waste the effort to iterate all
of the PCI Bar to find the VRAM aperture.
5) It has invented lots of methods to determine which one is the default
boot device on a multiple video card coexistence system. But this is
still a policy because it doesn't give the user a choice to override.

With the observation that device drivers or video aperture helpers may
have better knowledge about which PCI bar contains the firmware FB,

This patch tries to solve the above problems by introducing a function
callback to the vga_client_register() function interface. DRM device
drivers for the PCI device need to register the is_boot_device() function
callback during the driver loading time. Once the driver binds the device
successfully, VRAARB will call back to the driver. This gives the device
drivers a chance to provide accurate boot device identification. Which in
turn unlock the abitration service to non-x86 architectures. A device
driver can also pass a NULL pointer to keep the original behavior.

This series is applied on the drm-tip branch (with a cleanup patch set[1]
applied beforehand)

[1] https://patchwork.freedesktop.org/series/120053/

v2:
* Add a simple implemment for drm/i915 and drm/ast
* Pick up all tags (Mario)

Sui Jingfeng (6):
video/aperture: Add a helper to detect if an aperture contains
firmware FB
PCI/VGA: Improve the default VGA device selection
drm/amdgpu: Implement the is_boot_device callback function
drm/radeon: Implement the is_boot_device callback function
drm/i915: Implement the is_boot_device callback function
drm/ast: Register as a vga client to vgaarb by calling
vga_client_register()

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 12 +++++++-
drivers/gpu/drm/ast/ast_drv.c | 29 ++++++++++++++++++++
drivers/gpu/drm/drm_aperture.c | 16 +++++++++++
drivers/gpu/drm/i915/display/intel_vga.c | 32 ++++++++++++++++++++--
drivers/gpu/drm/nouveau/nouveau_vga.c | 2 +-
drivers/gpu/drm/radeon/radeon_device.c | 12 +++++++-
drivers/pci/vgaarb.c | 21 +++++++++++++-
drivers/vfio/pci/vfio_pci_core.c | 2 +-
drivers/video/aperture.c | 29 ++++++++++++++++++++
include/drm/drm_aperture.h | 2 ++
include/linux/aperture.h | 7 +++++
include/linux/vgaarb.h | 8 ++++--
12 files changed, 162 insertions(+), 10 deletions(-)

--
2.25.1



2023-07-02 18:49:55

by Sui Jingfeng

[permalink] [raw]
Subject: [PATCH v2 5/6] drm/i915: Implement the is_boot_device callback function

From: Sui Jingfeng <[email protected]>

This patch add a function to identify if a device is the default boot
selected by the firmware, it require the GPU has firmware framebuffer
driver support (such as efifb). If a specific hardware doesn't have
firmware framebuffer support, then the introduced function will just
return false. But even in this case, it still do no harms.

Cc: Jani Nikula <[email protected]>
Cc: Joonas Lahtinen <[email protected]>
Cc: Rodrigo Vivi <[email protected]>
Cc: Tvrtko Ursulin <[email protected]>
Cc: David Airlie <[email protected]>
Cc: Daniel Vetter <[email protected]>
Cc: "Ville Syrjälä" <[email protected]>
Cc: Lyude Paul <[email protected]>
Signed-off-by: Sui Jingfeng <[email protected]>
---
drivers/gpu/drm/i915/display/intel_vga.c | 31 +++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/display/intel_vga.c b/drivers/gpu/drm/i915/display/intel_vga.c
index 98d7d4dffe9f..7a0ba677c932 100644
--- a/drivers/gpu/drm/i915/display/intel_vga.c
+++ b/drivers/gpu/drm/i915/display/intel_vga.c
@@ -6,6 +6,8 @@
#include <linux/pci.h>
#include <linux/vgaarb.h>

+#include <drm/drm_aperture.h>
+
#include <video/vga.h>

#include "soc/intel_gmch.h"
@@ -113,6 +115,32 @@ intel_vga_set_decode(struct pci_dev *pdev, bool enable_decode)
return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
}

+static bool intel_vga_is_default_boot_device(struct pci_dev *pdev)
+{
+ struct drm_i915_private *i915 = pdev_to_i915(pdev);
+ struct drm_device *drm = &i915->drm;
+ struct i915_gem_mm *mm = &i915->mm;
+ struct intel_memory_region *mr;
+ unsigned int i;
+ bool ret;
+
+ for (i = 0; i < ARRAY_SIZE(mm->regions); i++) {
+ mr = mm->regions[i];
+ if (mr) {
+ ret = drm_aperture_contain_firmware_fb(mr->io_start,
+ mr->io_size);
+
+ if (ret) {
+ drm_dbg(drm, "%s contains firmware fb\n",
+ mr->name);
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
int intel_vga_register(struct drm_i915_private *i915)
{
struct pci_dev *pdev = to_pci_dev(i915->drm.dev);
@@ -126,7 +154,8 @@ int intel_vga_register(struct drm_i915_private *i915)
* then we do not take part in VGA arbitration and the
* vga_client_register() fails with -ENODEV.
*/
- ret = vga_client_register(pdev, intel_vga_set_decode, NULL);
+ ret = vga_client_register(pdev, intel_vga_set_decode,
+ intel_vga_is_default_boot_device);
if (ret && ret != -ENODEV)
return ret;

--
2.25.1