xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
To: xen-devel@lists.xensource.com
Cc: tim@xen.org, Ian.Campbell@citrix.com,
	Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: [PATCH v3 4/8] xen/vesa: use the new fb_* functions
Date: Tue, 18 Dec 2012 18:46:37 +0000	[thread overview]
Message-ID: <1355856402-26614-4-git-send-email-stefano.stabellini@eu.citrix.com> (raw)
In-Reply-To: <alpine.DEB.2.02.1212181843200.17523@kaball.uk.xensource.com>

Make use of the framebuffer functions previously introduced.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
---
 xen/drivers/video/vesa.c |  179 +++++++---------------------------------------
 1 files changed, 26 insertions(+), 153 deletions(-)

diff --git a/xen/drivers/video/vesa.c b/xen/drivers/video/vesa.c
index aaf8b23..9f24d03 100644
--- a/xen/drivers/video/vesa.c
+++ b/xen/drivers/video/vesa.c
@@ -13,20 +13,15 @@
 #include <asm/io.h>
 #include <asm/page.h>
 #include "font.h"
+#include "fb.h"
 
 #define vlfb_info    vga_console_info.u.vesa_lfb
-#define text_columns (vlfb_info.width / font->width)
-#define text_rows    (vlfb_info.height / font->height)
 
-static void vesa_redraw_puts(const char *s);
-static void vesa_scroll_puts(const char *s);
+static void lfb_flush(void);
 
-static unsigned char *lfb, *lbuf, *text_buf;
-static unsigned int *__initdata line_len;
+static unsigned char *lfb;
 static const struct font_desc *font;
 static bool_t vga_compat;
-static unsigned int pixel_on;
-static unsigned int xpos, ypos;
 
 static unsigned int vram_total;
 integer_param("vesa-ram", vram_total);
@@ -87,29 +82,26 @@ void __init vesa_early_init(void)
 
 void __init vesa_init(void)
 {
-    if ( !font )
-        goto fail;
-
-    lbuf = xmalloc_bytes(vlfb_info.bytes_per_line);
-    if ( !lbuf )
-        goto fail;
+    struct fb_prop fbp;
 
-    text_buf = xzalloc_bytes(text_columns * text_rows);
-    if ( !text_buf )
-        goto fail;
+    if ( !font )
+        return;
 
-    line_len = xzalloc_array(unsigned int, text_columns);
-    if ( !line_len )
-        goto fail;
+    fbp.font = font;
+    fbp.bits_per_pixel = vlfb_info.bits_per_pixel;
+    fbp.bytes_per_line = vlfb_info.bytes_per_line;
+    fbp.width = vlfb_info.width;
+    fbp.height = vlfb_info.height;
+    fbp.flush = lfb_flush;
+    fbp.text_columns = vlfb_info.width / font->width;
+    fbp.text_rows = vlfb_info.height / font->height;
 
-    lfb = ioremap(vlfb_info.lfb_base, vram_remap);
+    fbp.lfb = lfb = ioremap(vlfb_info.lfb_base, vram_remap);
     if ( !lfb )
-        goto fail;
+        return;
 
     memset(lfb, 0, vram_remap);
 
-    video_puts = vesa_redraw_puts;
-
     printk(XENLOG_INFO "vesafb: framebuffer at %#x, mapped to 0x%p, "
            "using %uk, total %uk\n",
            vlfb_info.lfb_base, lfb,
@@ -131,7 +123,7 @@ void __init vesa_init(void)
     {
         /* Light grey in truecolor. */
         unsigned int grey = 0xaaaaaaaa;
-        pixel_on = 
+        fbp.pixel_on = 
             ((grey >> (32 - vlfb_info.  red_size)) << vlfb_info.  red_pos) |
             ((grey >> (32 - vlfb_info.green_size)) << vlfb_info.green_pos) |
             ((grey >> (32 - vlfb_info. blue_size)) << vlfb_info. blue_pos);
@@ -139,15 +131,14 @@ void __init vesa_init(void)
     else
     {
         /* White(ish) in default pseudocolor palette. */
-        pixel_on = 7;
+        fbp.pixel_on = 7;
     }
 
-    return;
-
- fail:
-    xfree(lbuf);
-    xfree(text_buf);
-    xfree(line_len);
+    if ( fb_init(fbp) < 0 )
+        return;
+    if ( fb_alloc() < 0 )
+        return;
+    video_puts = fb_redraw_puts;
 }
 
 #include <asm/mtrr.h>
@@ -192,8 +183,8 @@ void __init vesa_endboot(bool_t keep)
 {
     if ( keep )
     {
-        xpos = 0;
-        video_puts = vesa_scroll_puts;
+        video_puts = fb_scroll_puts;
+        fb_carriage_return();
     }
     else
     {
@@ -202,124 +193,6 @@ void __init vesa_endboot(bool_t keep)
             memset(lfb + i * vlfb_info.bytes_per_line, 0,
                    vlfb_info.width * bpp);
         lfb_flush();
+        fb_free();
     }
-
-    xfree(line_len);
-}
-
-/* Render one line of text to given linear framebuffer line. */
-static void vesa_show_line(
-    const unsigned char *text_line,
-    unsigned char *video_line,
-    unsigned int nr_chars,
-    unsigned int nr_cells)
-{
-    unsigned int i, j, b, bpp, pixel;
-
-    bpp = (vlfb_info.bits_per_pixel + 7) >> 3;
-
-    for ( i = 0; i < font->height; i++ )
-    {
-        unsigned char *ptr = lbuf;
-
-        for ( j = 0; j < nr_chars; j++ )
-        {
-            const unsigned char *bits = font->data;
-            bits += ((text_line[j] * font->height + i) *
-                     ((font->width + 7) >> 3));
-            for ( b = font->width; b--; )
-            {
-                pixel = (*bits & (1u<<b)) ? pixel_on : 0;
-                memcpy(ptr, &pixel, bpp);
-                ptr += bpp;
-            }
-        }
-
-        memset(ptr, 0, (vlfb_info.width - nr_chars * font->width) * bpp);
-        memcpy(video_line, lbuf, nr_cells * font->width * bpp);
-        video_line += vlfb_info.bytes_per_line;
-    }
-}
-
-/* Fast mode which redraws all modified parts of a 2D text buffer. */
-static void __init vesa_redraw_puts(const char *s)
-{
-    unsigned int i, min_redraw_y = ypos;
-    char c;
-
-    /* Paste characters into text buffer. */
-    while ( (c = *s++) != '\0' )
-    {
-        if ( (c == '\n') || (xpos >= text_columns) )
-        {
-            if ( ++ypos >= text_rows )
-            {
-                min_redraw_y = 0;
-                ypos = text_rows - 1;
-                memmove(text_buf, text_buf + text_columns,
-                        ypos * text_columns);
-                memset(text_buf + ypos * text_columns, 0, xpos);
-            }
-            xpos = 0;
-        }
-
-        if ( c != '\n' )
-            text_buf[xpos++ + ypos * text_columns] = c;
-    }
-
-    /* Render modified section of text buffer to VESA linear framebuffer. */
-    for ( i = min_redraw_y; i <= ypos; i++ )
-    {
-        const unsigned char *line = text_buf + i * text_columns;
-        unsigned int width;
-
-        for ( width = text_columns; width; --width )
-            if ( line[width - 1] )
-                 break;
-        vesa_show_line(line,
-                       lfb + i * font->height * vlfb_info.bytes_per_line,
-                       width, max(line_len[i], width));
-        line_len[i] = width;
-    }
-
-    lfb_flush();
-}
-
-/* Slower line-based scroll mode which interacts better with dom0. */
-static void vesa_scroll_puts(const char *s)
-{
-    unsigned int i;
-    char c;
-
-    while ( (c = *s++) != '\0' )
-    {
-        if ( (c == '\n') || (xpos >= text_columns) )
-        {
-            unsigned int bytes = (vlfb_info.width *
-                                  ((vlfb_info.bits_per_pixel + 7) >> 3));
-            unsigned char *src = lfb + font->height * vlfb_info.bytes_per_line;
-            unsigned char *dst = lfb;
-            
-            /* New line: scroll all previous rows up one line. */
-            for ( i = font->height; i < vlfb_info.height; i++ )
-            {
-                memcpy(dst, src, bytes);
-                src += vlfb_info.bytes_per_line;
-                dst += vlfb_info.bytes_per_line;
-            }
-
-            /* Render new line. */
-            vesa_show_line(
-                text_buf,
-                lfb + (text_rows-1) * font->height * vlfb_info.bytes_per_line,
-                xpos, text_columns);
-
-            xpos = 0;
-        }
-
-        if ( c != '\n' )
-            text_buf[xpos++] = c;
-    }
-
-    lfb_flush();
 }
-- 
1.7.2.5

  parent reply	other threads:[~2012-12-18 18:46 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-18 18:45 [PATCH v3 0/8] xen: ARM HDLCD video driver Stefano Stabellini
2012-12-18 18:46 ` [PATCH v3 1/8] xen/arm: introduce early_ioremap Stefano Stabellini
2012-12-19 11:52   ` Ian Campbell
2013-01-08 19:02     ` Stefano Stabellini
2012-12-18 18:46 ` [PATCH v3 2/8] xen: infrastructure to have cross-platform video drivers Stefano Stabellini
2012-12-18 18:46 ` [PATCH v3 3/8] xen: introduce a generic framebuffer driver Stefano Stabellini
2012-12-19  8:08   ` Jan Beulich
2012-12-19  8:13   ` Jan Beulich
2012-12-18 18:46 ` Stefano Stabellini [this message]
2012-12-19 12:29   ` [PATCH v3 4/8] xen/vesa: use the new fb_* functions Ian Campbell
2012-12-18 18:46 ` [PATCH v3 5/8] xen/arm: preserve DTB mappings Stefano Stabellini
2012-12-19 12:36   ` Ian Campbell
2013-01-08 18:33     ` Stefano Stabellini
2013-01-08 19:04       ` David Vrabel
2013-01-08 19:32         ` Stefano Stabellini
2012-12-18 18:46 ` [PATCH v3 6/8] xen/device_tree: introduce find_compatible_node Stefano Stabellini
2012-12-19 14:06   ` Ian Campbell
2012-12-18 18:46 ` [PATCH v3 7/8] xen/arm: introduce vexpress_syscfg Stefano Stabellini
2012-12-19 12:47   ` Ian Campbell
2013-01-08 17:16     ` Stefano Stabellini
2012-12-18 18:46 ` [PATCH v3 8/8] xen/arm: introduce a driver for the ARM HDLCD controller Stefano Stabellini
2012-12-19 12:58   ` Ian Campbell
2013-01-08 13:51     ` Stefano Stabellini

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=1355856402-26614-4-git-send-email-stefano.stabellini@eu.citrix.com \
    --to=stefano.stabellini@eu.citrix.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=tim@xen.org \
    --cc=xen-devel@lists.xensource.com \
    /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).