From: James Simmons Here is the newest patch. The patch fixes 3 problems. The first problem is set_con2fb did not test to see if we where mapping to a invalid VC. Now we do. The part of this patch which is the bulk of it aimed at combining putcs_aligned and putcs_unaligned. Even at non 8 bit multiple wide fonts we often ended up having aligned data. So I used aligned data as often as possible. This is a nice performance boost. The final improvement was to change struct pixmap. Data is now transfered whole scanlines instead of byte by byte. This was really needed to enhance speed on drawing fonts. I also moved struct pixmap inside of __KERNEL__ to prevent userland versions of this file from defining this. Userland doesn't really need it and it breaks userland apps because it is mixed with internal kernel data defines. Please give it a try. drivers/video/console/fbcon.c | 221 ++++++++++++++++-------------------------- drivers/video/console/fbcon.h | 2 drivers/video/fbmem.c | 5 drivers/video/logo/logo.c | 0 include/linux/fb.h | 31 +++-- include/linux/linux_logo.h | 4 6 files changed, 106 insertions(+), 157 deletions(-) diff -puN drivers/video/console/fbcon.c~fbdev-updates drivers/video/console/fbcon.c --- 25-power4/drivers/video/console/fbcon.c~fbdev-updates 2003-05-08 14:00:08.000000000 -0700 +++ 25-power4-akpm/drivers/video/console/fbcon.c 2003-05-08 14:00:08.000000000 -0700 @@ -294,104 +294,16 @@ __setup("fbcon=", fb_console_setup); * Maps a virtual console @unit to a frame buffer device * @newidx. */ -void set_con2fb_map(int unit, int newidx) +int set_con2fb_map(int unit, int newidx) { struct vc_data *vc = vc_cons[unit].d; + if (!vc) + return -ENODEV; con2fb_map[unit] = newidx; fbcon_is_default = (vc->vc_sw == &fb_con) ? 1 : 0; take_over_console(&fb_con, unit, unit, fbcon_is_default); -} - -/* - * drawing helpers - */ -static void putcs_unaligned(struct vc_data *vc, struct fb_info *info, - struct fb_image *image, int count, - const unsigned short *s) -{ - unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff; - unsigned int width = (vc->vc_font.width + 7) >> 3; - unsigned int cellsize = vc->vc_font.height * width; - unsigned int maxcnt = info->pixmap.size/cellsize; - unsigned int shift_low = 0, mod = vc->vc_font.width % 8; - unsigned int shift_high = 8, size, pitch, cnt, k; - unsigned int buf_align = info->pixmap.buf_align - 1; - unsigned int scan_align = info->pixmap.scan_align - 1; - unsigned int idx = vc->vc_font.width >> 3; - u8 mask, *src, *dst, *dst0; - - while (count) { - if (count > maxcnt) - cnt = k = maxcnt; - else - cnt = k = count; - - image->width = vc->vc_font.width * cnt; - pitch = ((image->width + 7) >> 3) + scan_align; - pitch &= ~scan_align; - size = pitch * vc->vc_font.height + buf_align; - size &= ~buf_align; - dst0 = info->pixmap.addr + fb_get_buffer_offset(info, size); - image->data = dst0; - while (k--) { - src = vc->vc_font.data + (scr_readw(s++) & charmask)* - cellsize; - dst = dst0; - mask = (u8) (0xfff << shift_high); - move_buf_unaligned(info, dst, src, pitch, image->height, - mask, shift_high, shift_low, mod, idx); - shift_low += mod; - dst0 += (shift_low >= 8) ? width : width - 1; - shift_low &= 7; - shift_high = 8 - shift_low; - } - info->fbops->fb_imageblit(info, image); - image->dx += cnt * vc->vc_font.width; - count -= cnt; - atomic_dec(&info->pixmap.count); - smp_mb__after_atomic_dec(); - } -} - -static void putcs_aligned(struct vc_data *vc, struct fb_info *info, - struct fb_image *image, int count, - const unsigned short *s) -{ - unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff; - unsigned int width = vc->vc_font.width >> 3; - unsigned int cellsize = vc->vc_font.height * width; - unsigned int maxcnt = info->pixmap.size/cellsize; - unsigned int scan_align = info->pixmap.scan_align - 1; - unsigned int buf_align = info->pixmap.buf_align - 1; - unsigned int pitch, cnt, size, k; - u8 *src, *dst, *dst0; - - while (count) { - if (count > maxcnt) - cnt = k = maxcnt; - else - cnt = k = count; - - pitch = width * cnt + scan_align; - pitch &= ~scan_align; - size = pitch * vc->vc_font.height + buf_align; - size &= ~buf_align; - image->width = vc->vc_font.width * cnt; - dst0 = info->pixmap.addr + fb_get_buffer_offset(info, size); - image->data = dst0; - while (k--) { - src = vc->vc_font.data + (scr_readw(s++)&charmask)*cellsize; - dst = dst0; - move_buf_aligned(info, dst, src, pitch, width, image->height); - dst0 += width; - } - info->fbops->fb_imageblit(info, image); - image->dx += cnt * vc->vc_font.width; - count -= cnt; - atomic_dec(&info->pixmap.count); - smp_mb__after_atomic_dec(); - } + return 0; } /* @@ -428,62 +340,69 @@ void accel_clear(struct vc_data *vc, str info->fbops->fb_fillrect(info, ®ion); } -static void accel_putc(struct vc_data *vc, struct fb_info *info, - int c, int ypos, int xpos) +void accel_putcs(struct vc_data *vc, struct fb_info *info, + const unsigned short *s, int count, int yy, int xx) { unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff; unsigned int width = (vc->vc_font.width + 7) >> 3; + unsigned int cellsize = vc->vc_font.height * width; + unsigned int maxcnt = info->pixmap.size/cellsize; unsigned int scan_align = info->pixmap.scan_align - 1; unsigned int buf_align = info->pixmap.buf_align - 1; + unsigned int shift_low = 0, mod = vc->vc_font.width % 8; + unsigned int shift_high = 8, pitch, cnt, size, k; int bgshift = (vc->vc_hi_font_mask) ? 13 : 12; int fgshift = (vc->vc_hi_font_mask) ? 9 : 8; - unsigned int size, pitch; + unsigned int idx = vc->vc_font.width >> 3; + u8 *src, *dst, *dst0, mask; struct fb_image image; - u8 *src, *dst; + u16 c = scr_readw(s); - image.dx = xpos * vc->vc_font.width; - image.dy = ypos * vc->vc_font.height; - image.width = vc->vc_font.width; - image.height = vc->vc_font.height; image.fg_color = attr_fgcol(fgshift, c); image.bg_color = attr_bgcol(bgshift, c); + image.dx = xx * vc->vc_font.width; + image.dy = yy * vc->vc_font.height; + image.height = vc->vc_font.height; image.depth = 1; - pitch = width + scan_align; + while (count) { + if (count > maxcnt) + cnt = k = maxcnt; + else + cnt = k = count; + + image.width = vc->vc_font.width * cnt; + pitch = ((image.width + 7) >> 3) + scan_align; pitch &= ~scan_align; - size = pitch * vc->vc_font.height; - size += buf_align; + size = pitch * vc->vc_font.height + buf_align; size &= ~buf_align; - dst = info->pixmap.addr + fb_get_buffer_offset(info, size); - image.data = dst; - src = vc->vc_font.data + (c & charmask) * vc->vc_font.height * width; - - move_buf_aligned(info, dst, src, pitch, width, image.height); + dst0 = info->pixmap.addr + fb_get_buffer_offset(info, size); + image.data = dst0; + while (k--) { + src = vc->vc_font.data + (scr_readw(s++) & charmask)*cellsize; + dst = dst0; + if (mod) { + mask = (u8) (0xfff << shift_high); + move_buf_unaligned(info, dst, src, pitch, + image.height, mask, shift_high, + shift_low, mod, idx); + shift_low += mod; + dst0 += (shift_low >= 8) ? width : width - 1; + shift_low &= 7; + shift_high = 8 - shift_low; + } else { + move_buf_aligned(info, dst, src, pitch, idx, + image.height); + dst0 += width; + } + } info->fbops->fb_imageblit(info, &image); + image.dx += cnt * vc->vc_font.width; + count -= cnt; atomic_dec(&info->pixmap.count); smp_mb__after_atomic_dec(); } - -void accel_putcs(struct vc_data *vc, struct fb_info *info, - const unsigned short *s, int count, int yy, int xx) -{ - int bgshift = (vc->vc_hi_font_mask) ? 13 : 12; - int fgshift = (vc->vc_hi_font_mask) ? 9 : 8; - struct fb_image image; - u16 c = scr_readw(s); - - image.fg_color = attr_fgcol(fgshift, c); - image.bg_color = attr_bgcol(bgshift, c); - image.dx = xx * vc->vc_font.width; - image.dy = yy * vc->vc_font.height; - image.height = vc->vc_font.height; - image.depth = 1; - - if (!(vc->vc_font.width & 7)) - putcs_aligned(vc, info, &image, count, s); - else - putcs_unaligned(vc, info, &image, count, s); } void accel_clear_margins(struct vc_data *vc, struct fb_info *info, @@ -724,15 +643,13 @@ static __inline__ void updatescrollmode( static void fbcon_set_display(struct vc_data *vc, int init, int logo) { struct fb_info *info = registered_fb[(int) con2fb_map[vc->vc_num]]; + int nr_rows, nr_cols, old_rows, old_cols, i, charcnt = 256; struct display *p = &fb_display[vc->vc_num]; - int nr_rows, nr_cols; - int old_rows, old_cols; unsigned short *save = NULL, *r, *q; - int i, charcnt = 256; struct font_desc *font; if (vc->vc_num != fg_console || (info->flags & FBINFO_FLAG_MODULE) || - info->fix.type == FB_TYPE_TEXT) + (info->fix.type == FB_TYPE_TEXT)) logo = 0; info->var.xoffset = info->var.yoffset = p->yscroll = 0; /* reset wrap/pan */ @@ -956,11 +873,19 @@ static void fbcon_clear(struct vc_data * accel_clear(vc, info, real_y(p, sy), sx, height, width); } - static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos) { struct fb_info *info = registered_fb[(int) con2fb_map[vc->vc_num]]; + unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff; + unsigned int scan_align = info->pixmap.scan_align - 1; + unsigned int buf_align = info->pixmap.buf_align - 1; + unsigned int width = (vc->vc_font.width + 7) >> 3; + int bgshift = (vc->vc_hi_font_mask) ? 13 : 12; + int fgshift = (vc->vc_hi_font_mask) ? 9 : 8; struct display *p = &fb_display[vc->vc_num]; + unsigned int size, pitch; + struct fb_image image; + u8 *src, *dst; if (!info->fbops->fb_blank && console_blanked) return; @@ -968,7 +893,30 @@ static void fbcon_putc(struct vc_data *v if (vt_cons[vc->vc_num]->vc_mode != KD_TEXT) return; - accel_putc(vc, info, c, real_y(p, ypos), xpos); + image.dx = xpos * vc->vc_font.width; + image.dy = real_y(p, ypos) * vc->vc_font.height; + image.width = vc->vc_font.width; + image.height = vc->vc_font.height; + image.fg_color = attr_fgcol(fgshift, c); + image.bg_color = attr_bgcol(bgshift, c); + image.depth = 1; + + src = vc->vc_font.data + (c & charmask) * vc->vc_font.height * width; + + pitch = width + scan_align; + pitch &= ~scan_align; + size = pitch * vc->vc_font.height; + size += buf_align; + size &= ~buf_align; + + dst = info->pixmap.addr + fb_get_buffer_offset(info, size); + image.data = dst; + + move_buf_aligned(info, dst, src, pitch, width, image.height); + + info->fbops->fb_imageblit(info, &image); + atomic_dec(&info->pixmap.count); + smp_mb__after_atomic_dec(); } static void fbcon_putcs(struct vc_data *vc, const unsigned short *s, @@ -1047,6 +995,11 @@ static void fbcon_cursor(struct vc_data cursor.set |= FB_CUR_SETSIZE; } + if (info->cursor.hot.x || info->cursor.hot.y) { + cursor.hot.x = cursor.hot.y = 0; + cursor.set |= FB_CUR_SETHOT; + } + if ((cursor.set & FB_CUR_SETSIZE) || ((vc->vc_cursor_type & 0x0f) != p->cursor_shape)) { char *mask = kmalloc(w*vc->vc_font.height, GFP_ATOMIC); int cur_height, size, i = 0; diff -puN drivers/video/console/fbcon.h~fbdev-updates drivers/video/console/fbcon.h --- 25-power4/drivers/video/console/fbcon.h~fbdev-updates 2003-05-08 14:00:08.000000000 -0700 +++ 25-power4-akpm/drivers/video/console/fbcon.h 2003-05-08 14:00:08.000000000 -0700 @@ -38,7 +38,7 @@ struct display { /* drivers/video/console/fbcon.c */ extern char con2fb_map[MAX_NR_CONSOLES]; -extern void set_con2fb_map(int unit, int newidx); +extern int set_con2fb_map(int unit, int newidx); /* * Attribute Decoding diff -puN drivers/video/fbmem.c~fbdev-updates drivers/video/fbmem.c --- 25-power4/drivers/video/fbmem.c~fbdev-updates 2003-05-08 14:00:08.000000000 -0700 +++ 25-power4-akpm/drivers/video/fbmem.c 2003-05-08 14:00:08.000000000 -0700 @@ -25,7 +25,6 @@ #include #include #include -#include #include #ifdef CONFIG_KMOD #include @@ -656,7 +655,7 @@ int fb_prepare_logo(struct fb_info *info } /* Return if no suitable logo was found */ - fb_logo.logo = fb_find_logo(info->var.bits_per_pixel); + fb_logo.logo = find_logo(info->var.bits_per_pixel); if (!fb_logo.logo || fb_logo.logo->height > info->var.yres) { fb_logo.logo = NULL; @@ -726,8 +725,6 @@ int fb_show_logo(struct fb_info *info) x <= info->var.xres-fb_logo.logo->width; x += (fb_logo.logo->width + 8)) { image.dx = x; info->fbops->fb_imageblit(info, &image); - //atomic_dec(&info->pixmap.count); - //smp_mb__after_atomic_dec(); } if (palette != NULL) diff -puN drivers/video/logo/logo.c~fbdev-updates drivers/video/logo/logo.c diff -puN include/linux/fb.h~fbdev-updates include/linux/fb.h --- 25-power4/include/linux/fb.h~fbdev-updates 2003-05-08 14:00:08.000000000 -0700 +++ 25-power4-akpm/include/linux/fb.h 2003-05-08 14:00:08.000000000 -0700 @@ -2,7 +2,6 @@ #define _LINUX_FB_H #include -#include #include #include @@ -326,28 +325,31 @@ struct fb_cursor { struct fb_image image; /* Cursor image */ }; +#ifdef __KERNEL__ + +#include +#include +#include +#include + #define FB_PIXMAP_DEFAULT 1 /* used internally by fbcon */ #define FB_PIXMAP_SYSTEM 2 /* memory is in system RAM */ #define FB_PIXMAP_IO 4 /* memory is iomapped */ #define FB_PIXMAP_SYNC 256 /* set if GPU can DMA */ struct fb_pixmap { - __u8 *addr; /* pointer to memory */ - __u32 size; /* size of buffer in bytes */ - __u32 offset; /* current offset to buffer */ - __u32 buf_align; /* byte alignment of each bitmap */ - __u32 scan_align; /* alignment per scanline */ - __u32 flags; /* see FB_PIXMAP_* */ + u8 *addr; /* pointer to memory */ + u32 size; /* size of buffer in bytes */ + u32 offset; /* current offset to buffer */ + u32 buf_align; /* byte alignment of each bitmap */ + u32 scan_align; /* alignment per scanline */ + u32 flags; /* see FB_PIXMAP_* */ + spinlock_t lock; /* spinlock */ + atomic_t count; /* access methods */ void (*outbuf)(u8 *dst, u8 *addr, unsigned int size); u8 (*inbuf) (u8 *addr); - spinlock_t lock; /* spinlock */ - atomic_t count; }; -#ifdef __KERNEL__ - -#include -#include struct fb_info; struct vm_area_struct; @@ -398,7 +400,6 @@ struct fb_ops { struct fb_info { int node; int flags; - int open; /* Has this been open already ? */ #define FBINFO_FLAG_MODULE 1 /* Low-level driver is a module */ struct fb_var_screeninfo var; /* Current var */ struct fb_fix_screeninfo fix; /* Current fix */ @@ -410,8 +411,8 @@ struct fb_info { struct fb_ops *fbops; char *screen_base; /* Virtual address */ struct vc_data *display_fg; /* Console visible on this display */ - int currcon; /* Current VC. */ void *pseudo_palette; /* Fake palette of 16 colors */ + int currcon; /* Current VC. */ /* From here on everything is device dependent */ void *par; }; diff -puN include/linux/linux_logo.h~fbdev-updates include/linux/linux_logo.h --- 25-power4/include/linux/linux_logo.h~fbdev-updates 2003-05-08 14:00:08.000000000 -0700 +++ 25-power4-akpm/include/linux/linux_logo.h 2003-05-08 14:00:08.000000000 -0700 @@ -16,13 +16,11 @@ #include - #define LINUX_LOGO_MONO 1 /* monochrome black/white */ #define LINUX_LOGO_VGA16 2 /* 16 colors VGA text palette */ #define LINUX_LOGO_CLUT224 3 /* 224 colors */ #define LINUX_LOGO_GRAY256 4 /* 256 levels grayscale */ - struct linux_logo { int type; /* one of LINUX_LOGO_* */ unsigned int width; @@ -32,6 +30,6 @@ struct linux_logo { const unsigned char *data; }; -extern const struct linux_logo *fb_find_logo(int depth); +extern const struct linux_logo *find_logo(int depth); #endif /* _LINUX_LINUX_LOGO_H */ _