1 From 0c7fb448e0e0e47c2b3be64e438208682c6a5e61 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Mon, 9 Oct 2023 16:32:45 +0100
4 Subject: [PATCH] fbdev: Allow client to request a particular /dev/fbN node
6 Add a flag custom_fb_num to denote that the client has
7 requested a specific fbdev node number via node.
9 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
11 drivers/video/fbdev/core/fbmem.c | 24 +++++++++++++++++-------
12 include/linux/fb.h | 2 ++
13 2 files changed, 19 insertions(+), 7 deletions(-)
15 --- a/drivers/video/fbdev/core/fbmem.c
16 +++ b/drivers/video/fbdev/core/fbmem.c
17 @@ -52,6 +52,7 @@ static DEFINE_MUTEX(registration_lock);
19 struct fb_info *registered_fb[FB_MAX] __read_mostly;
20 int num_registered_fb __read_mostly;
21 +int min_dynamic_fb __read_mostly;
22 #define for_each_registered_fb(i) \
23 for (i = 0; i < FB_MAX; i++) \
24 if (!registered_fb[i]) {} else
25 @@ -1579,19 +1580,22 @@ static int do_register_framebuffer(struc
29 - for (i = 0 ; i < FB_MAX; i++)
30 - if (!registered_fb[i])
33 + if (!fb_info->custom_fb_num || fb_info->node >= FB_MAX || registered_fb[fb_info->node]) {
34 + for (i = min_dynamic_fb ; i < FB_MAX; i++)
35 + if (!registered_fb[i])
39 refcount_set(&fb_info->count, 1);
40 mutex_init(&fb_info->lock);
41 mutex_init(&fb_info->mm_lock);
43 fb_info->dev = device_create(fb_class, fb_info->device,
44 - MKDEV(FB_MAJOR, i), NULL, "fb%d", i);
45 + MKDEV(FB_MAJOR, fb_info->node), NULL, "fb%d", fb_info->node);
46 if (IS_ERR(fb_info->dev)) {
48 - printk(KERN_WARNING "Unable to create device for framebuffer %d; errno = %ld\n", i, PTR_ERR(fb_info->dev));
49 + printk(KERN_WARNING "Unable to create device for framebuffer %d; errno = %ld\n",
50 + fb_info->node, PTR_ERR(fb_info->dev));
53 fb_init_device(fb_info);
54 @@ -1624,7 +1628,7 @@ static int do_register_framebuffer(struc
56 fb_var_to_videomode(&mode, &fb_info->var);
57 fb_add_videomode(&mode, &fb_info->modelist);
58 - registered_fb[i] = fb_info;
59 + registered_fb[fb_info->node] = fb_info;
61 #ifdef CONFIG_GUMSTIX_AM200EPD
63 @@ -1719,6 +1723,12 @@ static int fb_aperture_acquire_for_platf
67 +void fb_set_lowest_dynamic_fb(int min_fb_dev)
69 + min_dynamic_fb = min_fb_dev;
71 +EXPORT_SYMBOL(fb_set_lowest_dynamic_fb);
74 * register_framebuffer - registers a frame buffer device
75 * @fb_info: frame buffer info structure
76 --- a/include/linux/fb.h
77 +++ b/include/linux/fb.h
78 @@ -512,6 +512,7 @@ struct fb_info {
81 bool skip_vt_switch; /* no VT switch on suspend/resume required */
82 + bool custom_fb_num; /* Use value in node as the preferred node number */
85 static inline struct apertures_struct *alloc_apertures(unsigned int max_num) {
86 @@ -614,6 +615,7 @@ extern ssize_t fb_sys_write(struct fb_in
87 size_t count, loff_t *ppos);
89 /* drivers/video/fbmem.c */
90 +extern void fb_set_lowest_dynamic_fb(int min_fb_dev);
91 extern int register_framebuffer(struct fb_info *fb_info);
92 extern void unregister_framebuffer(struct fb_info *fb_info);
93 extern int fb_prepare_logo(struct fb_info *fb_info, int rotate);