2023-07-11 17:09:05

by Sui Jingfeng

[permalink] [raw]
Subject: [PATCH v3 0/9] 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/120548/

v2:
* Add a simple implemment for drm/i915 and drm/ast
* Pick up all tags (Mario)
v3:
* Fix a mistake for drm/i915 implement
* Fix patch can not be applied problem because of drm/amdgpu merged
other people's patch.

Sui Jingfeng (9):
video/aperture: Add a helper to detect if an aperture contains
firmware FB
video/aperture: Add a helper for determining if an unmoved aperture
contain FB
PCI/VGA: Switch to aperture_contain_firmware_fb_nonreloc()
PCI/VGA: Improve the default VGA device selection
drm/amdgpu: Implement the is_primary_gpu callback of
vga_client_register()
drm/radeon: Add an implement for the is_primary_gpu function callback
drm/i915: Add an implement for the is_primary_gpu hook
drm/ast: Register as a vga client to vgaarb by calling
vga_client_register()
drm/loongson: Add an implement for the is_primary_gpu function
callback

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 | 31 ++++++++-
drivers/gpu/drm/loongson/lsdc_drv.c | 10 ++-
drivers/gpu/drm/nouveau/nouveau_vga.c | 2 +-
drivers/gpu/drm/radeon/radeon_device.c | 12 +++-
drivers/pci/vgaarb.c | 74 ++++++++++++++++------
drivers/vfio/pci/vfio_pci_core.c | 2 +-
drivers/video/aperture.c | 65 +++++++++++++++++++
include/drm/drm_aperture.h | 2 +
include/linux/aperture.h | 14 ++++
include/linux/vgaarb.h | 8 ++-
13 files changed, 247 insertions(+), 30 deletions(-)

--
2.25.1



2023-07-11 17:34:34

by Sui Jingfeng

[permalink] [raw]
Subject: [PATCH v3 9/9] drm/loongson: Add an implement for the is_primary_gpu function callback

From: Sui Jingfeng <[email protected]>

Signed-off-by: Sui Jingfeng <[email protected]>
---
drivers/gpu/drm/loongson/lsdc_drv.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/loongson/lsdc_drv.c b/drivers/gpu/drm/loongson/lsdc_drv.c
index d10a28c2c494..92ef07d6a534 100644
--- a/drivers/gpu/drm/loongson/lsdc_drv.c
+++ b/drivers/gpu/drm/loongson/lsdc_drv.c
@@ -257,6 +257,14 @@ static unsigned int lsdc_vga_set_decode(struct pci_dev *pdev, bool state)
return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
}

+static bool lsdc_is_primary_gpu(struct pci_dev *pdev)
+{
+ struct drm_device *ddev = pci_get_drvdata(pdev);
+ struct lsdc_device *ldev = to_lsdc(ddev);
+
+ return drm_aperture_contain_firmware_fb(ldev->vram_base, ldev->vram_size);
+}
+
static int lsdc_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
{
const struct lsdc_desc *descp;
@@ -289,7 +297,7 @@ static int lsdc_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)

pci_set_drvdata(pdev, ddev);

- vga_client_register(pdev, lsdc_vga_set_decode, NULL);
+ vga_client_register(pdev, lsdc_vga_set_decode, lsdc_is_primary_gpu);

drm_kms_helper_poll_init(ddev);

--
2.25.1


2023-07-19 19:36:55

by Bjorn Helgaas

[permalink] [raw]
Subject: Re: [PATCH v3 0/9] PCI/VGA: Improve the default VGA device selection

[+cc linux-pci]

On Wed, Jul 12, 2023 at 12:43:01AM +0800, Sui Jingfeng wrote:
> 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.

I skimmed all these patches, but the only one that seems to mention an
actual problem being solved, i.e., something that doesn't work for an
end user, is "drm/ast: Register as a vga client ..." Maybe
"drm/loongson: Add an implement for ..." also solves a problem, but it
lacks a commit log, so I don't know what the problem is.

In the future, can you please cc: linux-pci with the entire series?
In this posting, only the patches that touched drivers/pci/vgaarb.c
went to linux-pci, but those aren't enough to make sense of the series
as a whole.

> video/aperture: Add a helper to detect if an aperture contains
> firmware FB
> video/aperture: Add a helper for determining if an unmoved aperture
> contain FB
> PCI/VGA: Switch to aperture_contain_firmware_fb_nonreloc()

Since this subject includes the function name (which is nice!), it
would also be helpful if the "Add a helper ..." subject included the
same function name.

> PCI/VGA: Improve the default VGA device selection

If you can make this subject any more specific, that would be useful.
There's more to say about that patch, so I'll respond there.

> drm/amdgpu: Implement the is_primary_gpu callback of
> vga_client_register()
> drm/radeon: Add an implement for the is_primary_gpu function callback
> drm/i915: Add an implement for the is_primary_gpu hook
> drm/ast: Register as a vga client to vgaarb by calling
> vga_client_register()
> drm/loongson: Add an implement for the is_primary_gpu function
> callback

There's unnecessary variation in the subject lines (and the commit
logs) of these patches. If they all do the same thing but in
different drivers, it's useful if the patches all *look* the same.

You might be able to write these subjects as
"Implement .is_primary_gpu() callback" for brevity.

Bjorn

2023-07-20 09:48:55

by Sui Jingfeng

[permalink] [raw]
Subject: Re: [PATCH v3 0/9] PCI/VGA: Improve the default VGA device selection

Hi,

On 2023/7/20 03:32, Bjorn Helgaas wrote:
>> drm/amdgpu: Implement the is_primary_gpu callback of
>> vga_client_register()
>> drm/radeon: Add an implement for the is_primary_gpu function callback
>> drm/i915: Add an implement for the is_primary_gpu hook
>> drm/ast: Register as a vga client to vgaarb by calling
>> vga_client_register()
>> drm/loongson: Add an implement for the is_primary_gpu function
>> callback
> There's unnecessary variation in the subject lines (and the commit
> logs) of these patches. If they all do the same thing but in
> different drivers, it's useful if the patches all*look* the same.
>
> You might be able to write these subjects as
> "Implement .is_primary_gpu() callback" for brevity.


This is a very good suggestion, I will adopt this.

Thanks, really.


2023-07-24 13:13:42

by Sui Jingfeng

[permalink] [raw]
Subject: Re: [PATCH v3 0/9] PCI/VGA: Improve the default VGA device selection

Hi,


On 2023/7/20 03:32, Bjorn Helgaas wrote:
> "drm/loongson: Add an implement for ..." also solves a problem, but it
> lacks a commit log, so I don't know what the problem is.


I have already telling you one yeas ago.

I want remove the pci_fixup_vgadev() function in arch/loongarch/pci/pci.c

I was the original author of this workaround at our downstream kernel.

While the time is not mature until this patch set be merged.

I don't want mention this, as you asked this question.

So, I think I have to explain.


-static void pci_fixup_vgadev(struct pci_dev *pdev)
-{
-       struct pci_dev *devp = NULL;
-
-       while ((devp = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, devp))) {
-               if (devp->vendor != PCI_VENDOR_ID_LOONGSON) {
-                       vga_set_default_device(devp);
-                       dev_info(&pdev->dev,
-                               "Overriding boot device as %X:%X\n",
-                               devp->vendor, devp->device);
-               }
-       }
-}
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LOONGSON,
PCI_DEVICE_ID_LOONGSON_DC1, pci_fixup_vgadev);
-DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LOONGSON,
PCI_DEVICE_ID_LOONGSON_DC2, pci_fixup_vgadev);


2023-07-25 22:03:56

by Bjorn Helgaas

[permalink] [raw]
Subject: Re: [PATCH v3 0/9] PCI/VGA: Improve the default VGA device selection

On Mon, Jul 24, 2023 at 08:47:48PM +0800, suijingfeng wrote:
> On 2023/7/20 03:32, Bjorn Helgaas wrote:
> > "drm/loongson: Add an implement for ..." also solves a problem, but it
> > lacks a commit log, so I don't know what the problem is.
>
> I have already telling you one yeas ago.

The patch itself must be self-contained, including a commit log that
justifies the change. You may have told me a year ago, but that
doesn't help somebody looking at these changes next year.

Bjorn