Skip to content

Commit 4e75459

Browse files
committed
firmware/sysfb: Create firmware device only for enabled PCI devices
Test if the firmware framebuffer's parent PCI device, if any, has been enabled. If not, the firmware framebuffer is most likely not working. Hence, do not create a device for the firmware framebuffer on disabled PCI devices. So far, efifb tracked the status of the PCI parent device internally and did not bind if it was disabled. This patch implements the functionality for all PCI-based firmware framebuffers. v3: * make commit message more precise (Sui) v2: * rework sysfb_pci_dev_is_enabled() (Javier) Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de> Reviewed-by: Javier Martinez Canillas <javierm@redhat.com> Link: https://patchwork.freedesktop.org/patch/msgid/20240212090736.11464-6-tzimmermann@suse.de
1 parent 9040d02 commit 4e75459

1 file changed

Lines changed: 30 additions & 2 deletions

File tree

drivers/firmware/sysfb.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,41 @@ void sysfb_disable(void)
7070
}
7171
EXPORT_SYMBOL_GPL(sysfb_disable);
7272

73+
#if defined(CONFIG_PCI)
74+
static __init bool sysfb_pci_dev_is_enabled(struct pci_dev *pdev)
75+
{
76+
/*
77+
* TODO: Try to integrate this code into the PCI subsystem
78+
*/
79+
int ret;
80+
u16 command;
81+
82+
ret = pci_read_config_word(pdev, PCI_COMMAND, &command);
83+
if (ret != PCIBIOS_SUCCESSFUL)
84+
return false;
85+
if (!(command & PCI_COMMAND_MEMORY))
86+
return false;
87+
return true;
88+
}
89+
#else
90+
static __init bool sysfb_pci_dev_is_enabled(struct pci_dev *pdev)
91+
{
92+
return false;
93+
}
94+
#endif
95+
7396
static __init struct device *sysfb_parent_dev(const struct screen_info *si)
7497
{
7598
struct pci_dev *pdev;
7699

77100
pdev = screen_info_pci_dev(si);
78-
if (IS_ERR(pdev))
101+
if (IS_ERR(pdev)) {
79102
return ERR_CAST(pdev);
80-
else if (pdev)
103+
} else if (pdev) {
104+
if (!sysfb_pci_dev_is_enabled(pdev))
105+
return ERR_PTR(-ENODEV);
81106
return &pdev->dev;
107+
}
82108

83109
return NULL;
84110
}
@@ -99,6 +125,8 @@ static __init int sysfb_init(void)
99125
sysfb_apply_efi_quirks();
100126

101127
parent = sysfb_parent_dev(si);
128+
if (IS_ERR(parent))
129+
goto unlock_mutex;
102130

103131
/* try to create a simple-framebuffer device */
104132
compatible = sysfb_parse_mode(si, &mode);

0 commit comments

Comments
 (0)