mirror of
https://github.com/torvalds/linux.git
synced 2024-11-25 13:41:51 +00:00
60aebc9559
Consider a configuration like this:
1, efifb (or simpledrm) is built-in;
2, a native display driver (such as radeon) is also built-in.
As Javier said, this is not a common configuration (the native display
driver is usually built as a module), but it can happen and cause some
trouble.
In this case, since efifb, radeon and sysfb are all in device_initcall()
level, the order in practise is like this:
efifb registered at first, but no "efi-framebuffer" device yet. radeon
registered later, and /dev/fb0 created. sysfb_init() comes at last, it
registers "efi-framebuffer" and then causes an error message "efifb: a
framebuffer is already registered". Make sysfb_init() to be subsys_
initcall_sync() can avoid this. And Javier Martinez Canillas is trying
to make a more general solution in commit 873eb3b118
("fbdev: Disable
sysfb device registration when removing conflicting FBs").
However, this patch still makes sense because it can make the screen
display as early as possible (We cannot move to subsys_initcall, since
sysfb_init() should be executed after PCI enumeration).
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220704011704.1418055-1-chenhuacai@loongson.cn
132 lines
3.5 KiB
C
132 lines
3.5 KiB
C
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
/*
|
|
* Generic System Framebuffers
|
|
* Copyright (c) 2012-2013 David Herrmann <dh.herrmann@gmail.com>
|
|
*/
|
|
|
|
/*
|
|
* Simple-Framebuffer support
|
|
* Create a platform-device for any available boot framebuffer. The
|
|
* simple-framebuffer platform device is already available on DT systems, so
|
|
* this module parses the global "screen_info" object and creates a suitable
|
|
* platform device compatible with the "simple-framebuffer" DT object. If
|
|
* the framebuffer is incompatible, we instead create a legacy
|
|
* "vesa-framebuffer", "efi-framebuffer" or "platform-framebuffer" device and
|
|
* pass the screen_info as platform_data. This allows legacy drivers
|
|
* to pick these devices up without messing with simple-framebuffer drivers.
|
|
* The global "screen_info" is still valid at all times.
|
|
*
|
|
* If CONFIG_SYSFB_SIMPLEFB is not selected, never register "simple-framebuffer"
|
|
* platform devices, but only use legacy framebuffer devices for
|
|
* backwards compatibility.
|
|
*
|
|
* TODO: We set the dev_id field of all platform-devices to 0. This allows
|
|
* other OF/DT parsers to create such devices, too. However, they must
|
|
* start at offset 1 for this to work.
|
|
*/
|
|
|
|
#include <linux/err.h>
|
|
#include <linux/init.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/platform_data/simplefb.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/screen_info.h>
|
|
#include <linux/sysfb.h>
|
|
|
|
static struct platform_device *pd;
|
|
static DEFINE_MUTEX(disable_lock);
|
|
static bool disabled;
|
|
|
|
static bool sysfb_unregister(void)
|
|
{
|
|
if (IS_ERR_OR_NULL(pd))
|
|
return false;
|
|
|
|
platform_device_unregister(pd);
|
|
pd = NULL;
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* sysfb_disable() - disable the Generic System Framebuffers support
|
|
*
|
|
* This disables the registration of system framebuffer devices that match the
|
|
* generic drivers that make use of the system framebuffer set up by firmware.
|
|
*
|
|
* It also unregisters a device if this was already registered by sysfb_init().
|
|
*
|
|
* Context: The function can sleep. A @disable_lock mutex is acquired to serialize
|
|
* against sysfb_init(), that registers a system framebuffer device.
|
|
*/
|
|
void sysfb_disable(void)
|
|
{
|
|
mutex_lock(&disable_lock);
|
|
sysfb_unregister();
|
|
disabled = true;
|
|
mutex_unlock(&disable_lock);
|
|
}
|
|
EXPORT_SYMBOL_GPL(sysfb_disable);
|
|
|
|
static __init int sysfb_init(void)
|
|
{
|
|
struct screen_info *si = &screen_info;
|
|
struct simplefb_platform_data mode;
|
|
const char *name;
|
|
bool compatible;
|
|
int ret = 0;
|
|
|
|
mutex_lock(&disable_lock);
|
|
if (disabled)
|
|
goto unlock_mutex;
|
|
|
|
sysfb_apply_efi_quirks();
|
|
|
|
/* try to create a simple-framebuffer device */
|
|
compatible = sysfb_parse_mode(si, &mode);
|
|
if (compatible) {
|
|
pd = sysfb_create_simplefb(si, &mode);
|
|
if (!IS_ERR(pd))
|
|
goto unlock_mutex;
|
|
}
|
|
|
|
/* if the FB is incompatible, create a legacy framebuffer device */
|
|
if (si->orig_video_isVGA == VIDEO_TYPE_EFI)
|
|
name = "efi-framebuffer";
|
|
else if (si->orig_video_isVGA == VIDEO_TYPE_VLFB)
|
|
name = "vesa-framebuffer";
|
|
else if (si->orig_video_isVGA == VIDEO_TYPE_VGAC)
|
|
name = "vga-framebuffer";
|
|
else if (si->orig_video_isVGA == VIDEO_TYPE_EGAC)
|
|
name = "ega-framebuffer";
|
|
else
|
|
name = "platform-framebuffer";
|
|
|
|
pd = platform_device_alloc(name, 0);
|
|
if (!pd) {
|
|
ret = -ENOMEM;
|
|
goto unlock_mutex;
|
|
}
|
|
|
|
sysfb_set_efifb_fwnode(pd);
|
|
|
|
ret = platform_device_add_data(pd, si, sizeof(*si));
|
|
if (ret)
|
|
goto err;
|
|
|
|
ret = platform_device_add(pd);
|
|
if (ret)
|
|
goto err;
|
|
|
|
goto unlock_mutex;
|
|
err:
|
|
platform_device_put(pd);
|
|
unlock_mutex:
|
|
mutex_unlock(&disable_lock);
|
|
return ret;
|
|
}
|
|
|
|
/* must execute after PCI subsystem for EFI quirks */
|
|
subsys_initcall_sync(sysfb_init);
|