1 From cbb97ae4af35277a5478383045a86438f2e97c71 Mon Sep 17 00:00:00 2001
2 From: David Herrmann <dh.herrmann@googlemail.com>
3 Date: Sat, 16 Jun 2012 22:56:55 +0200
4 Subject: [PATCH 03/10] fblog: register framebuffer objects
6 We register each available framebuffer in the system with the fblog driver
7 so we always know all active devices. We directly open the fb-driver,
8 initialize the buffer and load a font so we are ready for drawing
9 operations. If a device cannot be opened, we mark it as dead and ignore it
10 in all other functions.
12 Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
14 drivers/video/console/fblog.c | 108 +++++++++++++++++++++++++++++++++++++++++
15 1 file changed, 108 insertions(+)
17 diff --git a/drivers/video/console/fblog.c b/drivers/video/console/fblog.c
18 index 1504ba9..8038dcc 100644
19 --- a/drivers/video/console/fblog.c
20 +++ b/drivers/video/console/fblog.c
22 #include <linux/font.h>
23 #include <linux/module.h>
25 +#define FBLOG_STR(x) x, sizeof(x) - 1
34 * struct fblog_buf: Console text buffer
36 @@ -61,6 +69,30 @@ struct fblog_buf {
41 + * struct fblog_fb: Framebuffer object
43 + * For each framebuffer we register this object. It contains all data we need to
44 + * display the console log on it. The index of a framebuffer in registered_fb[]
45 + * is the same as in fblog_fbs[]. So the following must always be true if the
46 + * pointers are non-NULL:
47 + * registered_fb[idx] == fblog_fbs[idx]->info
48 + * fblog_fbs[idx]->info->node == idx
50 + * flags: Framebuffer flags (see fblog_flags)
51 + * info: Pointer to the associated framebuffer device
52 + * font: Currently used font
53 + * buf: Console text buffer
56 + unsigned long flags;
57 + struct fb_info *info;
58 + const struct font_desc *font;
59 + struct fblog_buf buf;
62 +static struct fblog_fb *fblog_fbs[FB_MAX];
64 static void fblog_buf_resize(struct fblog_buf *buf, size_t width,
67 @@ -165,6 +197,82 @@ static void fblog_buf_write(struct fblog_buf *buf, const char *str, size_t len)
71 +static struct fblog_fb *fblog_info2fb(struct fb_info *info)
73 + if (!info || info->node < 0 || info->node >= FB_MAX ||
74 + !registered_fb[info->node])
77 + return fblog_fbs[info->node];
80 +static void fblog_register(struct fb_info *info)
82 + struct fblog_fb *fb;
83 + struct fb_var_screeninfo var;
84 + const struct fb_videomode *mode;
85 + unsigned int width, height;
87 + if (!info || info->node < 0 || info->node >= FB_MAX)
89 + if (!registered_fb[info->node] || fblog_fbs[info->node])
92 + fb = kzalloc(sizeof(*fb), GFP_KERNEL);
96 + fblog_fbs[info->node] = fb;
98 + fblog_buf_init(&fb->buf);
99 + fblog_buf_write(&fb->buf, FBLOG_STR("Framebuffer log initialized\n"));
101 + if (!try_module_get(info->fbops->owner))
103 + if (info->fbops->fb_open && info->fbops->fb_open(info, 0))
107 + mode = fb_find_best_mode(&var, &info->modelist);
108 + var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
109 + fb_set_var(info, &var);
111 + fb->font = get_default_font(info->var.xres, info->var.yres,
112 + info->pixmap.blit_x,
113 + info->pixmap.blit_y);
115 + width = info->var.xres / fb->font->width;
116 + height = info->var.yres / fb->font->height;
117 + fblog_buf_resize(&fb->buf, width, height);
123 + module_put(info->fbops->owner);
125 + set_bit(FBLOG_KILLED, &fb->flags);
128 +static void fblog_unregister(struct fblog_fb *fb)
130 + struct fb_info *info;
136 + if (!test_bit(FBLOG_KILLED, &fb->flags)) {
137 + if (info->fbops->fb_release)
138 + info->fbops->fb_release(info, 0);
139 + module_put(info->fbops->owner);
142 + fblog_buf_deinit(&fb->buf);
143 + fblog_fbs[info->node] = NULL;
147 static int __init fblog_init(void)