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
25#include <linux/init.h>25#include <linux/init.h>
26#include <linux/linux_logo.h>26#include <linux/linux_logo.h>
27#include <linux/proc_fs.h>27#include <linux/proc_fs.h>
28#include <linux/platform_device.h>
28#include <linux/seq_file.h>29#include <linux/seq_file.h>
29#include <linux/console.h>30#include <linux/console.h>
30#include <linux/kmod.h>31#include <linux/kmod.h>
@@ -1557,18 +1558,36 @@ static void do_remove_conflicting_framebuffers(struct apertures_struct *a, · 1526 unmodified lines
1557 /* check all firmware fbs and kick off if the base addr overlaps */1558 /* check all firmware fbs and kick off if the base addr overlaps */
1558 for_each_registered_fb(i) {1559 for_each_registered_fb(i) {
1559 struct apertures_struct *gen_aper;1560 struct apertures_struct *gen_aper;
1561 struct device *device;
1560 1562
1561 if (!(registered_fb[i]->flags & FBINFO_MISC_FIRMWARE))1563 if (!(registered_fb[i]->flags & FBINFO_MISC_FIRMWARE))
1562 continue;1564 continue;
1563 1565
1564 gen_aper = registered_fb[i]->apertures;1566 gen_aper = registered_fb[i]->apertures;
1567 device = registered_fb[i]->device;
1565 if (fb_do_apertures_overlap(gen_aper, a) ||1568 if (fb_do_apertures_overlap(gen_aper, a) ||
1566 (primary && gen_aper && gen_aper->count &&1569 (primary && gen_aper && gen_aper->count &&
1567 gen_aper->ranges[0].base == VGA_FB_PHYS)) {1570 gen_aper->ranges[0].base == VGA_FB_PHYS)) {
1568 1571
1569 printk(KERN_INFO "fb%d: switching to %s from %s\n",1572 printk(KERN_INFO "fb%d: switching to %s from %s\n",
1570 i, name, registered_fb[i]->fix.id);1573 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 }
1572 }1591 }
1573 }1592 }
1574}1593}
@@ -1851,9 +1870,13 @@ EXPORT_SYMBOL(register_framebuffer); · 276 unmodified lines
1851void1870void
1852unregister_framebuffer(struct fb_info *fb_info)1871unregister_framebuffer(struct fb_info *fb_info)
1853{1872{
1854 mutex_lock(&registration_lock);1873 bool forced_out = fb_info->forced_out;
1874
1875 if (!forced_out)
1876 mutex_lock(&registration_lock);
1855 do_unregister_framebuffer(fb_info);1877 do_unregister_framebuffer(fb_info);
1856 mutex_unlock(&registration_lock);1878 if (!forced_out)
1879 mutex_unlock(&registration_lock);
1857}1880}
1858EXPORT_SYMBOL(unregister_framebuffer);1881EXPORT_SYMBOL(unregister_framebuffer);
1859 1882
include/linux/fb.h+1−0
@@ -502,6 +502,7 @@ struct fb_info { · 501 unmodified lines
502 } *apertures;502 } *apertures;
503 503
504 bool skip_vt_switch; /* no VT switch on suspend/resume required */504 bool skip_vt_switch; /* no VT switch on suspend/resume required */
505 bool forced_out; /* set when being removed by another driver */
505};506};
506 507
507static inline struct apertures_struct *alloc_apertures(unsigned int max_num) {508static 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