Skip to content

Commit 2f29b5c

Browse files
author
Thomas Zimmermann
committed
video: screen_info: Relocate framebuffers behind PCI bridges
Apply PCI host-bridge window offsets to screen_info framebuffers. Fixes invalid access to I/O memory. Resources behind a PCI host bridge can be relocated by a certain offset in the kernel's CPU address range used for I/O. The framebuffer memory range stored in screen_info refers to the CPU addresses as seen during boot (where the offset is 0). During boot up, firmware may assign a different memory offset to the PCI host bridge 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's framebuffer resource (given in PCI bus addresses). The result matches the I/O-memory resource of the PCI graphics device (given in CPU addresses). As before, we store away the information necessary to later update the information in screen_info itself. Commit 78aa89d ("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. Efifb uses a pointer to the PCI resource, while the newer code does a memcpy of the region. Hence efifb sees any updates to the PCI resource and avoids the issue. v3: - Only use struct pci_bus_region for PCI bus addresses (Bjorn) - Clarify address semantics in commit messages and comments (Bjorn) v2: - Fixed tags (Takashi, Ivan) - Updated information on efifb Signed-off-by: Thomas Zimmermann <[email protected]> Reviewed-by: Javier Martinez Canillas <[email protected]> Reported-by: "Ivan T. Ivanov" <[email protected]> Closes: https://bugzilla.suse.com/show_bug.cgi?id=1240696 Tested-by: "Ivan T. Ivanov" <[email protected]> Fixes: 78aa89d ("firmware/sysfb: Update screen_info for relocated EFI framebuffers") Cc: [email protected] Cc: <[email protected]> # v6.9+ Link: https://lore.kernel.org/r/[email protected]
1 parent 91274fd commit 2f29b5c

File tree

1 file changed

+50
-29
lines changed

1 file changed

+50
-29
lines changed

drivers/video/screen_info_pci.c

Lines changed: 50 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
static struct pci_dev *screen_info_lfb_pdev;
99
static size_t screen_info_lfb_bar;
10-
static resource_size_t screen_info_lfb_offset;
11-
static struct resource screen_info_lfb_res = DEFINE_RES_MEM(0, 0);
10+
static resource_size_t screen_info_lfb_res_start; // original start of resource
11+
static resource_size_t screen_info_lfb_offset; // framebuffer offset within resource
1212

1313
static bool __screen_info_relocation_is_valid(const struct screen_info *si, struct resource *pr)
1414
{
@@ -31,7 +31,7 @@ void screen_info_apply_fixups(void)
3131
if (screen_info_lfb_pdev) {
3232
struct resource *pr = &screen_info_lfb_pdev->resource[screen_info_lfb_bar];
3333

34-
if (pr->start != screen_info_lfb_res.start) {
34+
if (pr->start != screen_info_lfb_res_start) {
3535
if (__screen_info_relocation_is_valid(si, pr)) {
3636
/*
3737
* Only update base if we have an actual
@@ -47,46 +47,67 @@ void screen_info_apply_fixups(void)
4747
}
4848
}
4949

50+
static int __screen_info_lfb_pci_bus_region(const struct screen_info *si, unsigned int type,
51+
struct pci_bus_region *r)
52+
{
53+
u64 base, size;
54+
55+
base = __screen_info_lfb_base(si);
56+
if (!base)
57+
return -EINVAL;
58+
59+
size = __screen_info_lfb_size(si, type);
60+
if (!size)
61+
return -EINVAL;
62+
63+
r->start = base;
64+
r->end = base + size - 1;
65+
66+
return 0;
67+
}
68+
5069
static void screen_info_fixup_lfb(struct pci_dev *pdev)
5170
{
5271
unsigned int type;
53-
struct resource res[SCREEN_INFO_MAX_RESOURCES];
54-
size_t i, numres;
72+
struct pci_bus_region bus_region;
5573
int ret;
74+
struct resource r = {
75+
.flags = IORESOURCE_MEM,
76+
};
77+
const struct resource *pr;
5678
const struct screen_info *si = &screen_info;
5779

5880
if (screen_info_lfb_pdev)
5981
return; // already found
6082

6183
type = screen_info_video_type(si);
62-
if (type != VIDEO_TYPE_EFI)
63-
return; // only applies to EFI
84+
if (!__screen_info_has_lfb(type))
85+
return; // only applies to EFI; maybe VESA
6486

65-
ret = screen_info_resources(si, res, ARRAY_SIZE(res));
87+
ret = __screen_info_lfb_pci_bus_region(si, type, &bus_region);
6688
if (ret < 0)
6789
return;
68-
numres = ret;
6990

70-
for (i = 0; i < numres; ++i) {
71-
struct resource *r = &res[i];
72-
const struct resource *pr;
73-
74-
if (!(r->flags & IORESOURCE_MEM))
75-
continue;
76-
pr = pci_find_resource(pdev, r);
77-
if (!pr)
78-
continue;
79-
80-
/*
81-
* We've found a PCI device with the framebuffer
82-
* resource. Store away the parameters to track
83-
* relocation of the framebuffer aperture.
84-
*/
85-
screen_info_lfb_pdev = pdev;
86-
screen_info_lfb_bar = pr - pdev->resource;
87-
screen_info_lfb_offset = r->start - pr->start;
88-
memcpy(&screen_info_lfb_res, r, sizeof(screen_info_lfb_res));
89-
}
91+
/*
92+
* Translate the PCI bus address to resource. Account
93+
* for an offset if the framebuffer is behind a PCI host
94+
* bridge.
95+
*/
96+
pcibios_bus_to_resource(pdev->bus, &r, &bus_region);
97+
98+
pr = pci_find_resource(pdev, &r);
99+
if (!pr)
100+
return;
101+
102+
/*
103+
* We've found a PCI device with the framebuffer
104+
* resource. Store away the parameters to track
105+
* relocation of the framebuffer aperture.
106+
*/
107+
screen_info_lfb_pdev = pdev;
108+
screen_info_lfb_bar = pr - pdev->resource;
109+
screen_info_lfb_offset = r.start - pr->start;
110+
screen_info_lfb_res_start = bus_region.start;
90111
}
91112
DECLARE_PCI_FIXUP_CLASS_HEADER(PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY, 16,
92113
screen_info_fixup_lfb);

0 commit comments

Comments
 (0)