Skip to contentSkip to conversation

WIP: fbconsole: not so dirty font selection via param_enum

RFC In review Antony Pavlov 2 participants 4 messages Jul 14, 2015 – Jul 15, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC v2 1/1 WIP: fbconsole: not so dirty font selection via param_enum

Alas I can't find any tab-complition for param_enum, so addition 'fonts' command is introduced.

Usage example:
==============

barebox@barebox sandbox:/ fonts
VGA8x16
MINI4x6
barebox@barebox sandbox:/ fbconsole0.font=MINI4x6 barebox@barebox sandbox:/ fbconsole0.active=o
fb0: framebuffer console 160x80 activated barebox@barebox sandbox:/ fbconsole0.font=VGA8x16

---
 drivers/video/fbconsole.c | 60 +++++++++++++++++++++++++++++++++++++++--------
 include/linux/font.h      | 11 ++++++---
 lib/fonts/fonts.c         | 39 ++++++++++++++++--------------
 3 files changed, 80 insertions(+), 30 deletions(-)
drivers/video/fbconsole.c +50 -10
index 36fd138..7df89ab 100644
@@ -20,6 +20,10 @@ struct fbc_priv {
 	struct fb_info *fb;
 
 	struct screen *sc;
+
+	struct param_d *par_font;
+	int par_font_val;
+
 /* FIXME */
 #define VIDEO_FONT_CHARS 256
 	struct image *chars[VIDEO_FONT_CHARS];
@@ -47,6 +51,16 @@ static int fbc_tstc(struct console_device *cdev)
 	return 0;
 }
 
+static void cls(struct fbc_priv *priv)
+{
+	void *buf = gui_screen_render_buffer(priv->sc);
+
+	memset(buf, 0, priv->fb->line_length * priv->fb->yres);
+
+	priv->x = 0;
+	priv->y = 0;
+}
+
 static void drawchar(struct fbc_priv *priv, int x, int y, char c)
 {
 	void *buf;
@@ -173,12 +187,7 @@ static void fbc_parse_csi(struct fbc_priv *priv)
 	}
 
 	if (*end == 'J' && a == 2 && b == -1) {
-		void *buf = gui_screen_render_buffer(priv->sc);
-
-		memset(buf, 0, priv->fb->line_length * priv->fb->yres);
-
-		priv->x = 0;
-		priv->y = 0;
+		cls(priv);
 		video_invertchar(priv, priv->x, priv->y);
 	}
 
@@ -263,14 +272,13 @@ static void fbc_putc(struct console_device *cdev, char c)
 	}
 }
 
-static int fbc_set_active(struct console_device *cdev, unsigned flags)
+/* FIXME: name */
+static int setup_font(struct fbc_priv *priv)
 {
-	struct fbc_priv *priv = container_of(cdev,
-					struct fbc_priv, cdev);
 	struct fb_info *fb = priv->fb;
 	const struct font_desc *font;
 
-	font = find_font("MINI4x6");
+	font = find_font_enum(priv->par_font_val);
 	if (!font) {
 		return -ENOENT;
 	}
@@ -282,6 +290,20 @@ static int fbc_set_active(struct console_device *cdev, unsigned flags)
 	priv->rows = fb->yres / priv->font_height - 1;
 	priv->cols = fb->xres / priv->font_width - 1;
 
+	return 0;
+}
+
+static int fbc_set_active(struct console_device *cdev, unsigned flags)
+{
+	struct fbc_priv *priv = container_of(cdev,
+					struct fbc_priv, cdev);
+	struct fb_info *fb = priv->fb;
+	int ret;
+
+	ret = setup_font(priv);
+	if (ret)
+		return ret;
+
 	priv->sc = fb_create_screen(fb, 0);
 	if (IS_ERR(priv->sc))
 		return PTR_ERR(priv->sc);
@@ -296,6 +318,19 @@ static int fbc_set_active(struct console_device *cdev, unsigned flags)
 	return 0;
 }
 
+static int set_font(struct param_d *p, void *vpriv)
+{
+	struct fbc_priv *priv = vpriv;
+	struct console_device *cdev = &priv->cdev;
+
+	if (cdev->f_active & (CONSOLE_STDOUT | CONSOLE_STDERR)) {
+		cls(priv);
+		setup_font(priv);
+	}
+
+	return 0;
+}
+
 int register_fbconsole(struct fb_info *fb)
 {
 	struct fbc_priv *priv;
@@ -325,6 +360,11 @@ int register_fbconsole(struct fb_info *fb)
 		return ret;
 	}
 
+	priv->par_font_val = 0;
+	priv->par_font = add_param_font(&cdev->class_dev,
+			set_font, NULL,
+			&priv->par_font_val, priv);
+
 	pr_info("registered as %s%d\n", cdev->class_dev.name, cdev->class_dev.id);
 
 	return 0;
include/linux/font.h +8 -3
index 24d6355..17693a0 100644
@@ -11,6 +11,8 @@
 #ifndef _VIDEO_FONT_H
 #define _VIDEO_FONT_H
 
+#include <param.h>
+
 struct font_desc {
 	const char *name;
 	int width, height;
@@ -20,10 +22,13 @@ struct font_desc {
 extern const struct font_desc	font_vga_8x16,
 			font_mini_4x6;
 
-/* Find a font with a specific name */
-extern const struct font_desc *find_font(const char *name);
-
 /* Max. length for the name of a predefined font */
 #define MAX_FONT_NAME	32
 
+extern const struct font_desc *find_font_enum(int n);
+extern struct param_d *add_param_font(struct device_d *dev,
+		int (*set)(struct param_d *p, void *priv),
+		int (*get)(struct param_d *p, void *priv),
+		int *value, void *priv);
+
 #endif /* _VIDEO_FONT_H */
lib/fonts/fonts.c +22 -17
index dbd1813..234885b 100644
@@ -37,30 +37,35 @@ static const struct font_desc *fonts[] = {
 #error No fonts configured.
 #endif
 
+static char *font_names;
 
-/**
- *	find_font - find a font
- *	@name: string name of a font
- *
- *	Find a specified font with string name @name.
- *
- *	Returns %NULL if no font found, or a pointer to the
- *	specified font.
- *
- */
-const struct font_desc *find_font(const char *name)
+const struct font_desc *find_font_enum(int n)
+{
+	if (n > num_fonts)
+		return NULL;
+
+	return fonts[n];
+}
+
+struct param_d *add_param_font(struct device_d *dev,
+		int (*set)(struct param_d *p, void *priv),
+		int (*get)(struct param_d *p, void *priv),
+		int *value, void *priv)
 {
 	unsigned int i;
 
-	for (i = 0; i < num_fonts; i++)
-		if (!strncmp(fonts[i]->name, name, MAX_FONT_NAME))
-			  return fonts[i];
+	if (!font_names) {
+		font_names = xmalloc(sizeof(char *) * num_fonts);
 
-	return NULL;
+		for (i = 0; i < num_fonts; i++)
+			((const char **)font_names)[i] = fonts[i]->name;
+	}
+
+	return dev_add_param_enum(dev, "font",
+			set, get, value,
+			(const char **)font_names, num_fonts, priv);
 }
 
-EXPORT_SYMBOL(find_font);
-
 MODULE_AUTHOR("James Simmons <[email protected]>");
 MODULE_DESCRIPTION("Console Fonts");
 MODULE_LICENSE("GPL");
Signature · 7 lines
2.1.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

Hi Antony,

Quoted 38 lines · Antony Pavlov

Alas I can't find any tab-complition for param_enum, so addition 'fonts' command is introduced.

Usage example:
==============

barebox@barebox sandbox:/ fonts
VGA8x16
MINI4x6
barebox@barebox sandbox:/ fbconsole0.font=MINI4x6 barebox@barebox sandbox:/ fbconsole0.active=o
fb0: framebuffer console 160x80 activated barebox@barebox sandbox:/ fbconsole0.font=VGA8x16

---
 drivers/video/fbconsole.c | 60 +++++++++++++++++++++++++++++++++++++++--------
 include/linux/font.h      | 11 ++++++---
 lib/fonts/fonts.c         | 39 ++++++++++++++++--------------
 3 files changed, 80 insertions(+), 30 deletions(-)
drivers/video/fbconsole.c +4 -0
index 36fd138..7df89ab 100644
@@ -20,6 +20,10 @@ struct fbc_priv {
 	struct fb_info *fb;
 
 	struct screen *sc;
+
+	struct param_d *par_font;
+	int par_font_val;
+
 /* FIXME */
 #define VIDEO_FONT_CHARS 256
 	struct image *chars[VIDEO_FONT_CHARS];
@@ -47,6 +51,16 @@ static int fbc_tstc(struct console_device *cdev)
 	return 0;

drivers/video/fbconsole.c static int fbc_tstc(struct console_device *cdev) · line 61

Quoted 10 lines
drivers/video/fbconsole.c +8 -0
 }
 
+static void cls(struct fbc_priv *priv)
+{
+	void *buf = gui_screen_render_buffer(priv->sc);
+
+	memset(buf, 0, priv->fb->line_length * priv->fb->yres);
+
+	priv->x = 0;
+	priv->y = 0;

I found out this is not entirely correct. Clearing the screen (\e[2J) and putting the cursor top left (\e[;H) are two different things.

I integrated the changes from this patch, but changed cls() not to put the cursor in home position.

Also I integrated some other changes:

- Fix fbc_set_active, no longer lose memory when called multiple times
- Add 7x14 font
- properly export get_pixel
- Add fb_enable/fb_disable function so that we do not have to call into the fb_info ops directly
- Make splash screen work again, was broken by "graphics_utils: Let fb_open allocate the screen"

Checkout the result on -next.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw
Quoted 68 lines · On Wed, 15 Jul 2015 07:45:32 +0200 Sascha Hauer <[email protected]> wrote:

Hi Antony,

Quoted 38 lines · Antony Pavlov

Alas I can't find any tab-complition for param_enum, so addition 'fonts' command is introduced.

Usage example:
==============

barebox@barebox sandbox:/ fonts
VGA8x16
MINI4x6
barebox@barebox sandbox:/ fbconsole0.font=MINI4x6 barebox@barebox sandbox:/ fbconsole0.active=o
fb0: framebuffer console 160x80 activated barebox@barebox sandbox:/ fbconsole0.font=VGA8x16

---
 drivers/video/fbconsole.c | 60 +++++++++++++++++++++++++++++++++++++++--------
 include/linux/font.h      | 11 ++++++---
 lib/fonts/fonts.c         | 39 ++++++++++++++++--------------
 3 files changed, 80 insertions(+), 30 deletions(-)
drivers/video/fbconsole.c +4 -0
index 36fd138..7df89ab 100644
@@ -20,6 +20,10 @@ struct fbc_priv {
 	struct fb_info *fb;
 
 	struct screen *sc;
+
+	struct param_d *par_font;
+	int par_font_val;
+
 /* FIXME */
 #define VIDEO_FONT_CHARS 256
 	struct image *chars[VIDEO_FONT_CHARS];
@@ -47,6 +51,16 @@ static int fbc_tstc(struct console_device *cdev)
 	return 0;

drivers/video/fbconsole.c static int fbc_tstc(struct console_device *cdev) · line 61

Quoted 10 lines
drivers/video/fbconsole.c +8 -0
 }
 
+static void cls(struct fbc_priv *priv)
+{
+	void *buf = gui_screen_render_buffer(priv->sc);
+
+	memset(buf, 0, priv->fb->line_length * priv->fb->yres);
+
+	priv->x = 0;
+	priv->y = 0;

I found out this is not entirely correct. Clearing the screen (\e[2J) and putting the cursor top left (\e[;H) are two different things.

I integrated the changes from this patch, but changed cls() not to put the cursor in home position.

Also I integrated some other changes:

- Fix fbc_set_active, no longer lose memory when called multiple times
- Add 7x14 font
- properly export get_pixel
- Add fb_enable/fb_disable function so that we do not have to call into the fb_info ops directly
- Make splash screen work again, was broken by "graphics_utils: Let fb_open allocate the screen"

Quoted 1 line

Checkout the result on -next.

So my fbconsole TODO list contain only one position:

- add Documentation.

Have you any fbconsole TODOs?

--
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#3 lore raw
Quoted 71 lines · Antony Pavlov
Quoted 68 lines · On Wed, 15 Jul 2015 07:45:32 +0200 Sascha Hauer <[email protected]> wrote:

Hi Antony,

Quoted 38 lines · Antony Pavlov

Alas I can't find any tab-complition for param_enum, so addition 'fonts' command is introduced.

Usage example:
==============

barebox@barebox sandbox:/ fonts
VGA8x16
MINI4x6
barebox@barebox sandbox:/ fbconsole0.font=MINI4x6 barebox@barebox sandbox:/ fbconsole0.active=o
fb0: framebuffer console 160x80 activated barebox@barebox sandbox:/ fbconsole0.font=VGA8x16

---
 drivers/video/fbconsole.c | 60 +++++++++++++++++++++++++++++++++++++++--------
 include/linux/font.h      | 11 ++++++---
 lib/fonts/fonts.c         | 39 ++++++++++++++++--------------
 3 files changed, 80 insertions(+), 30 deletions(-)
drivers/video/fbconsole.c +4 -0
index 36fd138..7df89ab 100644
@@ -20,6 +20,10 @@ struct fbc_priv {
 	struct fb_info *fb;
 
 	struct screen *sc;
+
+	struct param_d *par_font;
+	int par_font_val;
+
 /* FIXME */
 #define VIDEO_FONT_CHARS 256
 	struct image *chars[VIDEO_FONT_CHARS];
@@ -47,6 +51,16 @@ static int fbc_tstc(struct console_device *cdev)
 	return 0;

drivers/video/fbconsole.c static int fbc_tstc(struct console_device *cdev) · line 61

Quoted 10 lines
drivers/video/fbconsole.c +8 -0
 }
 
+static void cls(struct fbc_priv *priv)
+{
+	void *buf = gui_screen_render_buffer(priv->sc);
+
+	memset(buf, 0, priv->fb->line_length * priv->fb->yres);
+
+	priv->x = 0;
+	priv->y = 0;

I found out this is not entirely correct. Clearing the screen (\e[2J) and putting the cursor top left (\e[;H) are two different things.

I integrated the changes from this patch, but changed cls() not to put the cursor in home position.

Also I integrated some other changes:

- Fix fbc_set_active, no longer lose memory when called multiple times
- Add 7x14 font
- properly export get_pixel
- Add fb_enable/fb_disable function so that we do not have to call into the fb_info ops directly
- Make splash screen work again, was broken by "graphics_utils: Let fb_open allocate the screen"

Quoted 7 lines
Quoted 1 line

Checkout the result on -next.

So my fbconsole TODO list contain only one position:

- add Documentation.

Have you any fbconsole TODOs?

One that should be fixed before merging into master:

- protect against u8 csi[20] overflows

Some items that can be done later, shouldn't prevent us from merging:

- support remaining colors
- implement dma_alloc_writecombine for faster scrolling
- implement more ANSI sequences (until edit works properly)

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox