Skip to content

Commit 27599aa

Browse files
committed
fbdev: Hot-unplug firmware fb devices on forced removal
Hot-unplug all firmware-framebuffer devices as part of removing them via remove_conflicting_framebuffers() et al. Releases all memory regions to be acquired by native drivers. Firmware, such as EFI, install a framebuffer while posting the computer. After removing the firmware-framebuffer device from fbdev, a native driver takes over the hardware and the firmware framebuffer becomes invalid. Firmware-framebuffer drivers, specifically simplefb, don't release their device from Linux' device hierarchy. It still owns the firmware framebuffer and blocks the native drivers from loading. This has been observed in the vmwgfx driver. [1] Initiating a device removal (i.e., hot unplug) as part of remove_conflicting_framebuffers() removes the underlying device and returns the memory range to the system. [1] https://lore.kernel.org/dri-devel/[email protected]/ v2: * rename variable 'dev' to 'device' (Javier) Signed-off-by: Thomas Zimmermann <[email protected]> Reported-by: Zack Rusin <[email protected]> Reviewed-by: Javier Martinez Canillas <[email protected]> Reviewed-by: Zack Rusin <[email protected]> Reviewed-by: Hans de Goede <[email protected]> CC: [email protected] # v5.11+ Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 31b0488 commit 27599aa

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

drivers/video/fbdev/core/fbmem.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <linux/init.h>
2626
#include <linux/linux_logo.h>
2727
#include <linux/proc_fs.h>
28+
#include <linux/platform_device.h>
2829
#include <linux/seq_file.h>
2930
#include <linux/console.h>
3031
#include <linux/kmod.h>
@@ -1557,18 +1558,36 @@ static void do_remove_conflicting_framebuffers(struct apertures_struct *a,
15571558
/* check all firmware fbs and kick off if the base addr overlaps */
15581559
for_each_registered_fb(i) {
15591560
struct apertures_struct *gen_aper;
1561+
struct device *device;
15601562

15611563
if (!(registered_fb[i]->flags & FBINFO_MISC_FIRMWARE))
15621564
continue;
15631565

15641566
gen_aper = registered_fb[i]->apertures;
1567+
device = registered_fb[i]->device;
15651568
if (fb_do_apertures_overlap(gen_aper, a) ||
15661569
(primary && gen_aper && gen_aper->count &&
15671570
gen_aper->ranges[0].base == VGA_FB_PHYS)) {
15681571

15691572
printk(KERN_INFO "fb%d: switching to %s from %s\n",
15701573
i, name, registered_fb[i]->fix.id);
1571-
do_unregister_framebuffer(registered_fb[i]);
1574+
1575+
/*
1576+
* If we kick-out a firmware driver, we also want to remove
1577+
* the underlying platform device, such as simple-framebuffer,
1578+
* VESA, EFI, etc. A native driver will then be able to
1579+
* allocate the memory range.
1580+
*
1581+
* If it's not a platform device, at least print a warning. A
1582+
* fix would add code to remove the device from the system.
1583+
*/
1584+
if (dev_is_platform(device)) {
1585+
registered_fb[i]->forced_out = true;
1586+
platform_device_unregister(to_platform_device(device));
1587+
} else {
1588+
pr_warn("fb%d: cannot remove device\n", i);
1589+
do_unregister_framebuffer(registered_fb[i]);
1590+
}
15721591
}
15731592
}
15741593
}
@@ -1851,9 +1870,13 @@ EXPORT_SYMBOL(register_framebuffer);
18511870
void
18521871
unregister_framebuffer(struct fb_info *fb_info)
18531872
{
1854-
mutex_lock(&registration_lock);
1873+
bool forced_out = fb_info->forced_out;
1874+
1875+
if (!forced_out)
1876+
mutex_lock(&registration_lock);
18551877
do_unregister_framebuffer(fb_info);
1856-
mutex_unlock(&registration_lock);
1878+
if (!forced_out)
1879+
mutex_unlock(&registration_lock);
18571880
}
18581881
EXPORT_SYMBOL(unregister_framebuffer);
18591882

include/linux/fb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ struct fb_info {
502502
} *apertures;
503503

504504
bool skip_vt_switch; /* no VT switch on suspend/resume required */
505+
bool forced_out; /* set when being removed by another driver */
505506
};
506507

507508
static inline struct apertures_struct *alloc_apertures(unsigned int max_num) {

0 commit comments

Comments
 (0)