History

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/20220117180359.18114-1-zack@kde.org/ v2: * rename variable 'dev' to 'device' (Javier)

Thomas Zimmermann committed 4 years ago

Commit 27599aa1 parent 31b04882 files · +27 −3Browse files

Unified · Split

2 files
  1. drivers/video/fbdev/core/fbmem.c +26 −3
  2. include/linux/fb.h +1 −0
drivers/video/fbdev/core/fbmem.c+26−3
@@ -25,6 +25,7 @@ · 24 unmodified lines
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, · 1526 unmodified lines
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); · 276 unmodified lines
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+1−0
@@ -502,6 +502,7 @@ struct fb_info { · 501 unmodified lines
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) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t