Commit 8633ef82 authored by Javier Martinez Canillas's avatar Javier Martinez Canillas Committed by Thomas Zimmermann

drivers/firmware: consolidate EFI framebuffer setup for all arches

The register_gop_device() function registers an "efi-framebuffer" platform
device to match against the efifb driver, to have an early framebuffer for
EFI platforms.

But there is already support to do exactly the same by the Generic System
Framebuffers (sysfb) driver. This used to be only for X86 but it has been
moved to drivers/firmware and could be reused by other architectures.

Also, besides supporting registering an "efi-framebuffer", this driver can
register a "simple-framebuffer" allowing to use the siple{fb,drm} drivers
on non-X86 EFI platforms. For example, on aarch64 these drivers can only
be used with DT and doesn't have code to register a "simple-frambuffer"
platform device when booting with EFI.

For these reasons, let's remove the register_gop_device() duplicated code
and instead move the platform specific logic that's there to sysfb driver.
Signed-off-by: default avatarJavier Martinez Canillas <javierm@redhat.com>
Acked-by: default avatarBorislav Petkov <bp@suse.de>
Acked-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20210625131359.1804394-1-javierm@redhat.com
parent d391c582
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#ifdef CONFIG_EFI #ifdef CONFIG_EFI
void efi_init(void); void efi_init(void);
extern void efifb_setup_from_dmi(struct screen_info *si, const char *opt);
int efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md); int efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md);
int efi_set_mapping_permissions(struct mm_struct *mm, efi_memory_desc_t *md); int efi_set_mapping_permissions(struct mm_struct *mm, efi_memory_desc_t *md);
...@@ -52,10 +53,6 @@ void efi_virtmap_unload(void); ...@@ -52,10 +53,6 @@ void efi_virtmap_unload(void);
struct screen_info *alloc_screen_info(void); struct screen_info *alloc_screen_info(void);
void free_screen_info(struct screen_info *si); void free_screen_info(struct screen_info *si);
static inline void efifb_setup_from_dmi(struct screen_info *si, const char *opt)
{
}
/* /*
* A reasonable upper bound for the uncompressed kernel size is 32 MBytes, * A reasonable upper bound for the uncompressed kernel size is 32 MBytes,
* so we will reserve that amount of memory. We have no easy way to tell what * so we will reserve that amount of memory. We have no easy way to tell what
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#ifdef CONFIG_EFI #ifdef CONFIG_EFI
extern void efi_init(void); extern void efi_init(void);
extern void efifb_setup_from_dmi(struct screen_info *si, const char *opt);
#else #else
#define efi_init() #define efi_init()
#endif #endif
...@@ -85,10 +86,6 @@ static inline void free_screen_info(struct screen_info *si) ...@@ -85,10 +86,6 @@ static inline void free_screen_info(struct screen_info *si)
{ {
} }
static inline void efifb_setup_from_dmi(struct screen_info *si, const char *opt)
{
}
#define EFI_ALLOC_ALIGN SZ_64K #define EFI_ALLOC_ALIGN SZ_64K
/* /*
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#ifdef CONFIG_EFI #ifdef CONFIG_EFI
extern void efi_init(void); extern void efi_init(void);
extern void efifb_setup_from_dmi(struct screen_info *si, const char *opt);
#else #else
#define efi_init() #define efi_init()
#endif #endif
...@@ -39,10 +40,6 @@ static inline void free_screen_info(struct screen_info *si) ...@@ -39,10 +40,6 @@ static inline void free_screen_info(struct screen_info *si)
{ {
} }
static inline void efifb_setup_from_dmi(struct screen_info *si, const char *opt)
{
}
void efi_virtmap_load(void); void efi_virtmap_load(void);
void efi_virtmap_unload(void); void efi_virtmap_unload(void);
......
...@@ -254,9 +254,9 @@ config QCOM_SCM_DOWNLOAD_MODE_DEFAULT ...@@ -254,9 +254,9 @@ config QCOM_SCM_DOWNLOAD_MODE_DEFAULT
config SYSFB config SYSFB
bool bool
default y default y
depends on X86 || COMPILE_TEST depends on X86 || ARM || ARM64 || RISCV || COMPILE_TEST
config X86_SYSFB config SYSFB_SIMPLEFB
bool "Mark VGA/VBE/EFI FB as generic system framebuffer" bool "Mark VGA/VBE/EFI FB as generic system framebuffer"
depends on SYSFB depends on SYSFB
help help
...@@ -264,10 +264,10 @@ config X86_SYSFB ...@@ -264,10 +264,10 @@ config X86_SYSFB
bootloader or kernel can show basic video-output during boot for bootloader or kernel can show basic video-output during boot for
user-guidance and debugging. Historically, x86 used the VESA BIOS user-guidance and debugging. Historically, x86 used the VESA BIOS
Extensions and EFI-framebuffers for this, which are mostly limited Extensions and EFI-framebuffers for this, which are mostly limited
to x86. to x86 BIOS or EFI systems.
This option, if enabled, marks VGA/VBE/EFI framebuffers as generic This option, if enabled, marks VGA/VBE/EFI framebuffers as generic
framebuffers so the new generic system-framebuffer drivers can be framebuffers so the new generic system-framebuffer drivers can be
used on x86. If the framebuffer is not compatible with the generic used instead. If the framebuffer is not compatible with the generic
modes, it is advertised as fallback platform framebuffer so legacy modes, it is advertised as fallback platform framebuffer so legacy
drivers like efifb, vesafb and uvesafb can pick it up. drivers like efifb, vesafb and uvesafb can pick it up.
If this option is not selected, all system framebuffers are always If this option is not selected, all system framebuffers are always
......
...@@ -19,7 +19,7 @@ obj-$(CONFIG_RASPBERRYPI_FIRMWARE) += raspberrypi.o ...@@ -19,7 +19,7 @@ obj-$(CONFIG_RASPBERRYPI_FIRMWARE) += raspberrypi.o
obj-$(CONFIG_FW_CFG_SYSFS) += qemu_fw_cfg.o obj-$(CONFIG_FW_CFG_SYSFS) += qemu_fw_cfg.o
obj-$(CONFIG_QCOM_SCM) += qcom_scm.o qcom_scm-smc.o qcom_scm-legacy.o obj-$(CONFIG_QCOM_SCM) += qcom_scm.o qcom_scm-smc.o qcom_scm-legacy.o
obj-$(CONFIG_SYSFB) += sysfb.o obj-$(CONFIG_SYSFB) += sysfb.o
obj-$(CONFIG_X86_SYSFB) += sysfb_simplefb.o obj-$(CONFIG_SYSFB_SIMPLEFB) += sysfb_simplefb.o
obj-$(CONFIG_TI_SCI_PROTOCOL) += ti_sci.o obj-$(CONFIG_TI_SCI_PROTOCOL) += ti_sci.o
obj-$(CONFIG_TRUSTED_FOUNDATIONS) += trusted_foundations.o obj-$(CONFIG_TRUSTED_FOUNDATIONS) += trusted_foundations.o
obj-$(CONFIG_TURRIS_MOX_RWTM) += turris-mox-rwtm.o obj-$(CONFIG_TURRIS_MOX_RWTM) += turris-mox-rwtm.o
......
...@@ -275,93 +275,3 @@ void __init efi_init(void) ...@@ -275,93 +275,3 @@ void __init efi_init(void)
} }
#endif #endif
} }
static bool efifb_overlaps_pci_range(const struct of_pci_range *range)
{
u64 fb_base = screen_info.lfb_base;
if (screen_info.capabilities & VIDEO_CAPABILITY_64BIT_BASE)
fb_base |= (u64)(unsigned long)screen_info.ext_lfb_base << 32;
return fb_base >= range->cpu_addr &&
fb_base < (range->cpu_addr + range->size);
}
static struct device_node *find_pci_overlap_node(void)
{
struct device_node *np;
for_each_node_by_type(np, "pci") {
struct of_pci_range_parser parser;
struct of_pci_range range;
int err;
err = of_pci_range_parser_init(&parser, np);
if (err) {
pr_warn("of_pci_range_parser_init() failed: %d\n", err);
continue;
}
for_each_of_pci_range(&parser, &range)
if (efifb_overlaps_pci_range(&range))
return np;
}
return NULL;
}
/*
* If the efifb framebuffer is backed by a PCI graphics controller, we have
* to ensure that this relation is expressed using a device link when
* running in DT mode, or the probe order may be reversed, resulting in a
* resource reservation conflict on the memory window that the efifb
* framebuffer steals from the PCIe host bridge.
*/
static int efifb_add_links(struct fwnode_handle *fwnode)
{
struct device_node *sup_np;
sup_np = find_pci_overlap_node();
/*
* If there's no PCI graphics controller backing the efifb, we are
* done here.
*/
if (!sup_np)
return 0;
fwnode_link_add(fwnode, of_fwnode_handle(sup_np));
of_node_put(sup_np);
return 0;
}
static const struct fwnode_operations efifb_fwnode_ops = {
.add_links = efifb_add_links,
};
static struct fwnode_handle efifb_fwnode;
static int __init register_gop_device(void)
{
struct platform_device *pd;
int err;
if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI)
return 0;
pd = platform_device_alloc("efi-framebuffer", 0);
if (!pd)
return -ENOMEM;
if (IS_ENABLED(CONFIG_PCI)) {
fwnode_init(&efifb_fwnode, &efifb_fwnode_ops);
pd->dev.fwnode = &efifb_fwnode;
}
err = platform_device_add_data(pd, &screen_info, sizeof(screen_info));
if (err)
return err;
return platform_device_add(pd);
}
subsys_initcall(register_gop_device);
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
/* /*
* Generic System Framebuffers on x86 * Generic System Framebuffers
* Copyright (c) 2012-2013 David Herrmann <dh.herrmann@gmail.com> * Copyright (c) 2012-2013 David Herrmann <dh.herrmann@gmail.com>
* *
* EFI Quirks Copyright (c) 2006 Edgar Hucek <gimli@dark-green.com> * EFI Quirks Copyright (c) 2006 Edgar Hucek <gimli@dark-green.com>
...@@ -19,7 +19,9 @@ ...@@ -19,7 +19,9 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/of_address.h>
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/platform_device.h>
#include <linux/screen_info.h> #include <linux/screen_info.h>
#include <linux/sysfb.h> #include <linux/sysfb.h>
#include <video/vga.h> #include <video/vga.h>
...@@ -267,7 +269,72 @@ static const struct dmi_system_id efifb_dmi_swap_width_height[] __initconst = { ...@@ -267,7 +269,72 @@ static const struct dmi_system_id efifb_dmi_swap_width_height[] __initconst = {
{}, {},
}; };
__init void sysfb_apply_efi_quirks(void) static bool efifb_overlaps_pci_range(const struct of_pci_range *range)
{
u64 fb_base = screen_info.lfb_base;
if (screen_info.capabilities & VIDEO_CAPABILITY_64BIT_BASE)
fb_base |= (u64)(unsigned long)screen_info.ext_lfb_base << 32;
return fb_base >= range->cpu_addr &&
fb_base < (range->cpu_addr + range->size);
}
static struct device_node *find_pci_overlap_node(void)
{
struct device_node *np;
for_each_node_by_type(np, "pci") {
struct of_pci_range_parser parser;
struct of_pci_range range;
int err;
err = of_pci_range_parser_init(&parser, np);
if (err) {
pr_warn("of_pci_range_parser_init() failed: %d\n", err);
continue;
}
for_each_of_pci_range(&parser, &range)
if (efifb_overlaps_pci_range(&range))
return np;
}
return NULL;
}
/*
* If the efifb framebuffer is backed by a PCI graphics controller, we have
* to ensure that this relation is expressed using a device link when
* running in DT mode, or the probe order may be reversed, resulting in a
* resource reservation conflict on the memory window that the efifb
* framebuffer steals from the PCIe host bridge.
*/
static int efifb_add_links(struct fwnode_handle *fwnode)
{
struct device_node *sup_np;
sup_np = find_pci_overlap_node();
/*
* If there's no PCI graphics controller backing the efifb, we are
* done here.
*/
if (!sup_np)
return 0;
fwnode_link_add(fwnode, of_fwnode_handle(sup_np));
of_node_put(sup_np);
return 0;
}
static const struct fwnode_operations efifb_fwnode_ops = {
.add_links = efifb_add_links,
};
static struct fwnode_handle efifb_fwnode;
__init void sysfb_apply_efi_quirks(struct platform_device *pd)
{ {
if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI || if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI ||
!(screen_info.capabilities & VIDEO_CAPABILITY_SKIP_QUIRKS)) !(screen_info.capabilities & VIDEO_CAPABILITY_SKIP_QUIRKS))
...@@ -281,4 +348,9 @@ __init void sysfb_apply_efi_quirks(void) ...@@ -281,4 +348,9 @@ __init void sysfb_apply_efi_quirks(void)
screen_info.lfb_height = temp; screen_info.lfb_height = temp;
screen_info.lfb_linelength = 4 * screen_info.lfb_width; screen_info.lfb_linelength = 4 * screen_info.lfb_width;
} }
if (screen_info.orig_video_isVGA == VIDEO_TYPE_EFI && IS_ENABLED(CONFIG_PCI)) {
fwnode_init(&efifb_fwnode, &efifb_fwnode_ops);
pd->dev.fwnode = &efifb_fwnode;
}
} }
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
/* /*
* Generic System Framebuffers on x86 * Generic System Framebuffers
* Copyright (c) 2012-2013 David Herrmann <dh.herrmann@gmail.com> * Copyright (c) 2012-2013 David Herrmann <dh.herrmann@gmail.com>
*/ */
/* /*
* Simple-Framebuffer support for x86 systems * Simple-Framebuffer support
* Create a platform-device for any available boot framebuffer. The * Create a platform-device for any available boot framebuffer. The
* simple-framebuffer platform device is already available on DT systems, so * simple-framebuffer platform device is already available on DT systems, so
* this module parses the global "screen_info" object and creates a suitable * this module parses the global "screen_info" object and creates a suitable
...@@ -16,12 +16,12 @@ ...@@ -16,12 +16,12 @@
* to pick these devices up without messing with simple-framebuffer drivers. * to pick these devices up without messing with simple-framebuffer drivers.
* The global "screen_info" is still valid at all times. * The global "screen_info" is still valid at all times.
* *
* If CONFIG_X86_SYSFB is not selected, we never register "simple-framebuffer" * If CONFIG_SYSFB_SIMPLEFB is not selected, never register "simple-framebuffer"
* platform devices, but only use legacy framebuffer devices for * platform devices, but only use legacy framebuffer devices for
* backwards compatibility. * backwards compatibility.
* *
* TODO: We set the dev_id field of all platform-devices to 0. This allows * TODO: We set the dev_id field of all platform-devices to 0. This allows
* other x86 OF/DT parsers to create such devices, too. However, they must * other OF/DT parsers to create such devices, too. However, they must
* start at offset 1 for this to work. * start at offset 1 for this to work.
*/ */
...@@ -43,12 +43,10 @@ static __init int sysfb_init(void) ...@@ -43,12 +43,10 @@ static __init int sysfb_init(void)
bool compatible; bool compatible;
int ret; int ret;
sysfb_apply_efi_quirks();
/* try to create a simple-framebuffer device */ /* try to create a simple-framebuffer device */
compatible = parse_mode(si, &mode); compatible = sysfb_parse_mode(si, &mode);
if (compatible) { if (compatible) {
ret = create_simplefb(si, &mode); ret = sysfb_create_simplefb(si, &mode);
if (!ret) if (!ret)
return 0; return 0;
} }
...@@ -61,9 +59,24 @@ static __init int sysfb_init(void) ...@@ -61,9 +59,24 @@ static __init int sysfb_init(void)
else else
name = "platform-framebuffer"; name = "platform-framebuffer";
pd = platform_device_register_resndata(NULL, name, 0, pd = platform_device_alloc(name, 0);
NULL, 0, si, sizeof(*si)); if (!pd)
return PTR_ERR_OR_ZERO(pd); return -ENOMEM;
sysfb_apply_efi_quirks(pd);
ret = platform_device_add_data(pd, si, sizeof(*si));
if (ret)
goto err;
ret = platform_device_add(pd);
if (ret)
goto err;
return 0;
err:
platform_device_put(pd);
return ret;
} }
/* must execute after PCI subsystem for EFI quirks */ /* must execute after PCI subsystem for EFI quirks */
......
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
/* /*
* Generic System Framebuffers on x86 * Generic System Framebuffers
* Copyright (c) 2012-2013 David Herrmann <dh.herrmann@gmail.com> * Copyright (c) 2012-2013 David Herrmann <dh.herrmann@gmail.com>
*/ */
...@@ -23,8 +23,8 @@ ...@@ -23,8 +23,8 @@
static const char simplefb_resname[] = "BOOTFB"; static const char simplefb_resname[] = "BOOTFB";
static const struct simplefb_format formats[] = SIMPLEFB_FORMATS; static const struct simplefb_format formats[] = SIMPLEFB_FORMATS;
/* try parsing x86 screen_info into a simple-framebuffer mode struct */ /* try parsing screen_info into a simple-framebuffer mode struct */
__init bool parse_mode(const struct screen_info *si, __init bool sysfb_parse_mode(const struct screen_info *si,
struct simplefb_platform_data *mode) struct simplefb_platform_data *mode)
{ {
const struct simplefb_format *f; const struct simplefb_format *f;
...@@ -57,13 +57,14 @@ __init bool parse_mode(const struct screen_info *si, ...@@ -57,13 +57,14 @@ __init bool parse_mode(const struct screen_info *si,
return false; return false;
} }
__init int create_simplefb(const struct screen_info *si, __init int sysfb_create_simplefb(const struct screen_info *si,
const struct simplefb_platform_data *mode) const struct simplefb_platform_data *mode)
{ {
struct platform_device *pd; struct platform_device *pd;
struct resource res; struct resource res;
u64 base, size; u64 base, size;
u32 length; u32 length;
int ret;
/* /*
* If the 64BIT_BASE capability is set, ext_lfb_base will contain the * If the 64BIT_BASE capability is set, ext_lfb_base will contain the
...@@ -105,7 +106,19 @@ __init int create_simplefb(const struct screen_info *si, ...@@ -105,7 +106,19 @@ __init int create_simplefb(const struct screen_info *si,
if (res.end <= res.start) if (res.end <= res.start)
return -EINVAL; return -EINVAL;
pd = platform_device_register_resndata(NULL, "simple-framebuffer", 0, pd = platform_device_alloc("simple-framebuffer", 0);
&res, 1, mode, sizeof(*mode)); if (!pd)
return PTR_ERR_OR_ZERO(pd); return -ENOMEM;
sysfb_apply_efi_quirks(pd);
ret = platform_device_add_resources(pd, &res, 1);
if (ret)
return ret;
ret = platform_device_add_data(pd, mode, sizeof(*mode));
if (ret)
return ret;
return platform_device_add(pd);
} }
...@@ -64,8 +64,8 @@ config DRM_SIMPLEDRM ...@@ -64,8 +64,8 @@ config DRM_SIMPLEDRM
buffer, size, and display format must be provided via device tree, buffer, size, and display format must be provided via device tree,
UEFI, VESA, etc. UEFI, VESA, etc.
On x86 and compatible, you should also select CONFIG_X86_SYSFB to On x86 BIOS or UEFI systems, you should also select SYSFB_SIMPLEFB
use UEFI and VESA framebuffers. to use UEFI and VESA framebuffers.
config TINYDRM_HX8357D config TINYDRM_HX8357D
tristate "DRM support for HX8357D display panels" tristate "DRM support for HX8357D display panels"
......
...@@ -58,37 +58,37 @@ struct efifb_dmi_info { ...@@ -58,37 +58,37 @@ struct efifb_dmi_info {
#ifdef CONFIG_EFI #ifdef CONFIG_EFI
extern struct efifb_dmi_info efifb_dmi_list[]; extern struct efifb_dmi_info efifb_dmi_list[];
void sysfb_apply_efi_quirks(void); void sysfb_apply_efi_quirks(struct platform_device *pd);
#else /* CONFIG_EFI */ #else /* CONFIG_EFI */
static inline void sysfb_apply_efi_quirks(void) static inline void sysfb_apply_efi_quirks(struct platform_device *pd)
{ {
} }
#endif /* CONFIG_EFI */ #endif /* CONFIG_EFI */
#ifdef CONFIG_X86_SYSFB #ifdef CONFIG_SYSFB_SIMPLEFB
bool parse_mode(const struct screen_info *si, bool sysfb_parse_mode(const struct screen_info *si,
struct simplefb_platform_data *mode); struct simplefb_platform_data *mode);
int create_simplefb(const struct screen_info *si, int sysfb_create_simplefb(const struct screen_info *si,
const struct simplefb_platform_data *mode); const struct simplefb_platform_data *mode);
#else /* CONFIG_X86_SYSFB */ #else /* CONFIG_SYSFB_SIMPLE */
static inline bool parse_mode(const struct screen_info *si, static inline bool sysfb_parse_mode(const struct screen_info *si,
struct simplefb_platform_data *mode) struct simplefb_platform_data *mode)
{ {
return false; return false;
} }
static inline int create_simplefb(const struct screen_info *si, static inline int sysfb_create_simplefb(const struct screen_info *si,
const struct simplefb_platform_data *mode) const struct simplefb_platform_data *mode)
{ {
return -EINVAL; return -EINVAL;
} }
#endif /* CONFIG_X86_SYSFB */ #endif /* CONFIG_SYSFB_SIMPLE */
#endif /* _LINUX_SYSFB_H */ #endif /* _LINUX_SYSFB_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment