cc'ing PCI devs

Am 17.04.25 um 09:27 schrieb Thomas Zimmermann:
Apply bridge window offsets to screen_info framebuffers during
relocation. Fixes invalid access to I/O memory.

Resources behind a PCI bridge can be located at a certain offset
in the kernel's I/O range. The framebuffer memory range stored in
screen_info refers to the offset as seen during boot (essentialy 0).
During boot up, the kernel may assign a different memory offset to
the bridge device and thereby relocating the framebuffer address of
the PCI graphics device as seen by the kernel. The information in
screen_info must be updated as well.

The helper pcibios_bus_to_resource() performs the relocation of
the screen_info resource. The result now matches the I/O-memory
resource of the PCI graphics device. As before, we store away the
information necessary to update the information in screen_info.

Commit 78aa89d1dfba ("firmware/sysfb: Update screen_info for relocated
EFI framebuffers") added the code for updating screen_info. It is
based on similar functionality that pre-existed in efifb. But efifb
did not handle bridges correctly, so the problem presumably exists
only on newer systems.

Signed-off-by: Thomas Zimmermann <[email protected]>
Reported-by: Tested-by: "Ivan T. Ivanov" <[email protected]>
Closes: https://bugzilla.suse.com/show_bug.cgi?id=1240696
Tested-by: Tested-by: "Ivan T. Ivanov" <[email protected]>
Fixes: 78aa89d1dfba ("firmware/sysfb: Update screen_info for relocated EFI 
framebuffers")
Cc: [email protected]
Cc: <[email protected]> # v6.9+
---
  drivers/video/screen_info_pci.c | 17 ++++++++++++++---
  1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/video/screen_info_pci.c b/drivers/video/screen_info_pci.c
index 6c5833517141..c46c75dc3fae 100644
--- a/drivers/video/screen_info_pci.c
+++ b/drivers/video/screen_info_pci.c
@@ -8,7 +8,7 @@
  static struct pci_dev *screen_info_lfb_pdev;
  static size_t screen_info_lfb_bar;
  static resource_size_t screen_info_lfb_offset;
-static struct resource screen_info_lfb_res = DEFINE_RES_MEM(0, 0);
+static struct pci_bus_region screen_info_lfb_region;
static bool __screen_info_relocation_is_valid(const struct screen_info *si, struct resource *pr)
  {
@@ -31,7 +31,7 @@ void screen_info_apply_fixups(void)
        if (screen_info_lfb_pdev) {
                struct resource *pr = 
&screen_info_lfb_pdev->resource[screen_info_lfb_bar];
- if (pr->start != screen_info_lfb_res.start) {
+               if (pr->start != screen_info_lfb_region.start) {
                        if (__screen_info_relocation_is_valid(si, pr)) {
                                /*
                                 * Only update base if we have an actual
@@ -69,10 +69,21 @@ static void screen_info_fixup_lfb(struct pci_dev *pdev)
for (i = 0; i < numres; ++i) {
                struct resource *r = &res[i];
+               struct pci_bus_region bus_region = {
+                       .start = r->start,
+                       .end = r->end,
+               };
                const struct resource *pr;
if (!(r->flags & IORESOURCE_MEM))
                        continue;
+
+               /*
+                * Translate the address to resource if the framebuffer
+                * is behind a PCI bridge.
+                */
+               pcibios_bus_to_resource(pdev->bus, r, &bus_region);
+
                pr = pci_find_resource(pdev, r);
                if (!pr)
                        continue;
@@ -85,7 +96,7 @@ static void screen_info_fixup_lfb(struct pci_dev *pdev)
                screen_info_lfb_pdev = pdev;
                screen_info_lfb_bar = pr - pdev->resource;
                screen_info_lfb_offset = r->start - pr->start;
-               memcpy(&screen_info_lfb_res, r, sizeof(screen_info_lfb_res));
+               memcpy(&screen_info_lfb_region, &bus_region, 
sizeof(screen_info_lfb_region));
        }
  }
  DECLARE_PCI_FIXUP_CLASS_HEADER(PCI_ANY_ID, PCI_ANY_ID, 
PCI_BASE_CLASS_DISPLAY, 16,

--
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)

Reply via email to