linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Herrmann <dh.herrmann@googlemail.com>
To: linux-serial@vger.kernel.org
Cc: Florian Tobias Schandinat <FlorianSchandinat@gmx.de>,
	linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	David Herrmann <dh.herrmann@googlemail.com>
Subject: [PATCH 03/10] fblog: register framebuffer objects
Date: Sat, 16 Jun 2012 22:04:19 +0000	[thread overview]
Message-ID: <1339884266-9201-4-git-send-email-dh.herrmann@googlemail.com> (raw)
In-Reply-To: <1339884266-9201-1-git-send-email-dh.herrmann@googlemail.com>

We register each available framebuffer in the system with the fblog driver
so we always know all active devices. We directly open the fb-driver,
initialize the buffer and load a font so we are ready for drawing
operations. If a device cannot be opened, we mark it as dead and ignore it
in all other functions.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
---
 drivers/video/console/fblog.c |  108 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 108 insertions(+)

diff --git a/drivers/video/console/fblog.c b/drivers/video/console/fblog.c
index 1504ba9..8038dcc 100644
--- a/drivers/video/console/fblog.c
+++ b/drivers/video/console/fblog.c
@@ -39,6 +39,14 @@
 #include <linux/font.h>
 #include <linux/module.h>
 
+#define FBLOG_STR(x) x, sizeof(x) - 1
+
+enum fblog_flags {
+	FBLOG_KILLED,
+	FBLOG_SUSPENDED,
+	FBLOG_BLANKED,
+};
+
 /**
  * struct fblog_buf: Console text buffer
  *
@@ -61,6 +69,30 @@ struct fblog_buf {
 	size_t pos_y;
 };
 
+/**
+ * struct fblog_fb: Framebuffer object
+ *
+ * For each framebuffer we register this object. It contains all data we need to
+ * display the console log on it. The index of a framebuffer in registered_fb[]
+ * is the same as in fblog_fbs[]. So the following must always be true if the
+ * pointers are non-NULL:
+ *     registered_fb[idx] = fblog_fbs[idx]->info
+ *     fblog_fbs[idx]->info->node = idx
+ *
+ * flags: Framebuffer flags (see fblog_flags)
+ * info: Pointer to the associated framebuffer device
+ * font: Currently used font
+ * buf: Console text buffer
+ */
+struct fblog_fb {
+	unsigned long flags;
+	struct fb_info *info;
+	const struct font_desc *font;
+	struct fblog_buf buf;
+};
+
+static struct fblog_fb *fblog_fbs[FB_MAX];
+
 static void fblog_buf_resize(struct fblog_buf *buf, size_t width,
 			     size_t height)
 {
@@ -165,6 +197,82 @@ static void fblog_buf_write(struct fblog_buf *buf, const char *str, size_t len)
 	}
 }
 
+static struct fblog_fb *fblog_info2fb(struct fb_info *info)
+{
+	if (!info || info->node < 0 || info->node >= FB_MAX ||
+	    !registered_fb[info->node])
+		return NULL;
+
+	return fblog_fbs[info->node];
+}
+
+static void fblog_register(struct fb_info *info)
+{
+	struct fblog_fb *fb;
+	struct fb_var_screeninfo var;
+	const struct fb_videomode *mode;
+	unsigned int width, height;
+
+	if (!info || info->node < 0 || info->node >= FB_MAX)
+		return;
+	if (!registered_fb[info->node] || fblog_fbs[info->node])
+		return;
+
+	fb = kzalloc(sizeof(*fb), GFP_KERNEL);
+	if (!fb)
+		return;
+
+	fblog_fbs[info->node] = fb;
+	fb->info = info;
+	fblog_buf_init(&fb->buf);
+	fblog_buf_write(&fb->buf, FBLOG_STR("Framebuffer log initialized\n"));
+
+	if (!try_module_get(info->fbops->owner))
+		goto out_killed;
+	if (info->fbops->fb_open && info->fbops->fb_open(info, 0))
+		goto out_unref;
+
+	var = info->var;
+	mode = fb_find_best_mode(&var, &info->modelist);
+	var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
+	fb_set_var(info, &var);
+
+	fb->font = get_default_font(info->var.xres, info->var.yres,
+				    info->pixmap.blit_x,
+				    info->pixmap.blit_y);
+	if (fb->font) {
+		width = info->var.xres / fb->font->width;
+		height = info->var.yres / fb->font->height;
+		fblog_buf_resize(&fb->buf, width, height);
+	}
+
+	return;
+
+out_unref:
+	module_put(info->fbops->owner);
+out_killed:
+	set_bit(FBLOG_KILLED, &fb->flags);
+}
+
+static void fblog_unregister(struct fblog_fb *fb)
+{
+	struct fb_info *info;
+
+	if (!fb)
+		return;
+
+	info = fb->info;
+	if (!test_bit(FBLOG_KILLED, &fb->flags)) {
+		if (info->fbops->fb_release)
+			info->fbops->fb_release(info, 0);
+		module_put(info->fbops->owner);
+	}
+
+	fblog_buf_deinit(&fb->buf);
+	fblog_fbs[info->node] = NULL;
+	kfree(fb);
+}
+
 static int __init fblog_init(void)
 {
 	return 0;
-- 
1.7.10.4


  parent reply	other threads:[~2012-06-16 22:04 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-16 22:04 [RFC 00/10] fblog: framebuffer kernel log driver David Herrmann
2012-06-16 22:04 ` [PATCH 01/10] fblog: new framebuffer kernel log dummy driver David Herrmann
2012-06-16 22:04 ` [PATCH 02/10] fblog: implement buffer management David Herrmann
2012-06-16 22:04 ` David Herrmann [this message]
2012-06-16 22:04 ` [PATCH 04/10] fblog: implement fblog_redraw() David Herrmann
2012-06-16 22:35   ` Alan Cox
2012-06-18 18:36     ` David Herrmann
2012-06-16 22:04 ` [PATCH 05/10] fblog: add framebuffer helpers David Herrmann
2012-06-16 22:33   ` Bruno Prémont
2012-06-18 18:50     ` David Herrmann
2012-06-16 22:04 ` [PATCH 06/10] fblog: allow enabling/disabling fblog on runtime David Herrmann
2012-06-16 22:04 ` [PATCH 07/10] fblog: forward kernel log messages to all framebuffers David Herrmann
2012-06-16 22:04 ` [PATCH 08/10] fblog: react on framebuffer events David Herrmann
2012-06-16 22:04 ` [PATCH 09/10] fblog: register all handlers on module-init David Herrmann
2012-06-16 22:04 ` [PATCH 10/10] fblog: add "activate" module parameter David Herrmann
2012-06-18 19:06 ` [RFC 00/10] fblog: framebuffer kernel log driver David Herrmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1339884266-9201-4-git-send-email-dh.herrmann@googlemail.com \
    --to=dh.herrmann@googlemail.com \
    --cc=FlorianSchandinat@gmx.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).