Skip to content

Commit bde376e

Browse files
firmware: sysfb: Add sysfb_disable() helper function
This can be used by subsystems to unregister a platform device registered by sysfb and also to disable future platform device registration in sysfb. Suggested-by: Daniel Vetter <daniel.vetter@ffwll.ch> Signed-off-by: Javier Martinez Canillas <javierm@redhat.com> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Link: https://patchwork.freedesktop.org/patch/msgid/20220607182338.344270-3-javierm@redhat.com
1 parent 9e12104 commit bde376e

File tree

3 files changed

+66
-6
lines changed

3 files changed

+66
-6
lines changed

Documentation/driver-api/firmware/other_interfaces.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ EDD Interfaces
1313
.. kernel-doc:: drivers/firmware/edd.c
1414
:internal:
1515

16+
Generic System Framebuffers Interface
17+
-------------------------------------
18+
19+
.. kernel-doc:: drivers/firmware/sysfb.c
20+
:export:
21+
1622
Intel Stratix10 SoC Service Layer
1723
---------------------------------
1824
Some features of the Intel Stratix10 SoC require a level of privilege

drivers/firmware/sysfb.c

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,59 @@
3434
#include <linux/screen_info.h>
3535
#include <linux/sysfb.h>
3636

37+
static struct platform_device *pd;
38+
static DEFINE_MUTEX(disable_lock);
39+
static bool disabled;
40+
41+
static bool sysfb_unregister(void)
42+
{
43+
if (IS_ERR_OR_NULL(pd))
44+
return false;
45+
46+
platform_device_unregister(pd);
47+
pd = NULL;
48+
49+
return true;
50+
}
51+
52+
/**
53+
* sysfb_disable() - disable the Generic System Framebuffers support
54+
*
55+
* This disables the registration of system framebuffer devices that match the
56+
* generic drivers that make use of the system framebuffer set up by firmware.
57+
*
58+
* It also unregisters a device if this was already registered by sysfb_init().
59+
*
60+
* Context: The function can sleep. A @disable_lock mutex is acquired to serialize
61+
* against sysfb_init(), that registers a system framebuffer device.
62+
*/
63+
void sysfb_disable(void)
64+
{
65+
mutex_lock(&disable_lock);
66+
sysfb_unregister();
67+
disabled = true;
68+
mutex_unlock(&disable_lock);
69+
}
70+
EXPORT_SYMBOL_GPL(sysfb_disable);
71+
3772
static __init int sysfb_init(void)
3873
{
3974
struct screen_info *si = &screen_info;
4075
struct simplefb_platform_data mode;
41-
struct platform_device *pd;
4276
const char *name;
4377
bool compatible;
44-
int ret;
78+
int ret = 0;
79+
80+
mutex_lock(&disable_lock);
81+
if (disabled)
82+
goto unlock_mutex;
4583

4684
/* try to create a simple-framebuffer device */
4785
compatible = sysfb_parse_mode(si, &mode);
4886
if (compatible) {
4987
pd = sysfb_create_simplefb(si, &mode);
5088
if (!IS_ERR(pd))
51-
return 0;
89+
goto unlock_mutex;
5290
}
5391

5492
/* if the FB is incompatible, create a legacy framebuffer device */
@@ -60,8 +98,10 @@ static __init int sysfb_init(void)
6098
name = "platform-framebuffer";
6199

62100
pd = platform_device_alloc(name, 0);
63-
if (!pd)
64-
return -ENOMEM;
101+
if (!pd) {
102+
ret = -ENOMEM;
103+
goto unlock_mutex;
104+
}
65105

66106
sysfb_apply_efi_quirks(pd);
67107

@@ -73,9 +113,11 @@ static __init int sysfb_init(void)
73113
if (ret)
74114
goto err;
75115

76-
return 0;
116+
goto unlock_mutex;
77117
err:
78118
platform_device_put(pd);
119+
unlock_mutex:
120+
mutex_unlock(&disable_lock);
79121
return ret;
80122
}
81123

include/linux/sysfb.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ struct efifb_dmi_info {
5555
int flags;
5656
};
5757

58+
#ifdef CONFIG_SYSFB
59+
60+
void sysfb_disable(void);
61+
62+
#else /* CONFIG_SYSFB */
63+
64+
static inline void sysfb_disable(void)
65+
{
66+
}
67+
68+
#endif /* CONFIG_SYSFB */
69+
5870
#ifdef CONFIG_EFI
5971

6072
extern struct efifb_dmi_info efifb_dmi_list[];

0 commit comments

Comments
 (0)