Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

lib/fonts: Store font data as font_data_t; update consoles

Store font data as pointer to font_data_t instead of unsigned char.
Update consoles.

Pointers to font data refer to the raw data. There is a hidden header
before the data that contains additional state. Document the existing
layout and semantics of font_data_t.

The data field in struct vc_font can be used by any console. Therefore
it still points to plain data without the additional header. Fbcon sets
its value from struct fbcon_display.fontdata. Hence, update the size
test in fbcon_resize() to use struct fbcon_display.fontdata instead of
struct vc_font.data.

v3:
- fix typos (Helge)
v2:
- 'Font lookup' -> 'Font description' in <linux/font.h>

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Signed-off-by: Helge Deller <deller@gmx.de>

authored by

Thomas Zimmermann and committed by
Helge Deller
04bd5abc 773ac24c

+84 -27
+9 -8
drivers/video/console/newport_con.c
··· 33 33 34 34 #define NEWPORT_LEN 0x10000 35 35 36 - #define FONT_DATA ((unsigned char *)font_vga_8x16.data) 36 + #define FONT_DATA font_vga_8x16.data 37 37 38 - static unsigned char *font_data[MAX_NR_CONSOLES]; 38 + static font_data_t *font_data[MAX_NR_CONSOLES]; 39 39 40 40 static struct newport_regs *npregs; 41 41 static unsigned long newport_addr; ··· 370 370 static void newport_putc(struct vc_data *vc, u16 charattr, unsigned int ypos, 371 371 unsigned int xpos) 372 372 { 373 - unsigned char *p; 373 + const unsigned char *p; 374 374 375 - p = &font_data[vc->vc_num][(charattr & 0xff) << 4]; 375 + p = &font_data_buf(font_data[vc->vc_num])[(charattr & 0xff) << 4]; 376 376 charattr = (charattr >> 8) & 0xff; 377 377 xpos <<= 3; 378 378 ypos <<= 4; ··· 400 400 unsigned int count, unsigned int ypos, 401 401 unsigned int xpos) 402 402 { 403 - unsigned char *p; 403 + const unsigned char *p; 404 404 unsigned int i; 405 405 u16 charattr; 406 406 ··· 424 424 NPORT_DMODE0_L32); 425 425 426 426 for (i = 0; i < count; i++, xpos += 8) { 427 - p = &font_data[vc->vc_num][(scr_readw(s++) & 0xff) << 4]; 427 + p = &font_data_buf(font_data[vc->vc_num])[(scr_readw(s++) & 0xff) << 4]; 428 428 429 429 newport_wait(npregs); 430 430 ··· 503 503 int h = op->height; 504 504 int size = h * op->charcount; 505 505 int i; 506 - unsigned char *new_data, *data = op->data, *p; 506 + font_data_t *new_data; 507 + unsigned char *data = op->data, *p; 507 508 508 509 /* ladis: when I grow up, there will be a day... and more sizes will 509 510 * be supported ;-) */ ··· 520 519 REFCOUNT(new_data) = 0; /* usage counter */ 521 520 FNTSUM(new_data) = 0; 522 521 523 - p = new_data; 522 + p = (unsigned char *)font_data_buf(new_data); 524 523 for (i = 0; i < op->charcount; i++) { 525 524 memcpy(p, data, h); 526 525 data += 32;
+27 -17
drivers/video/fbdev/core/fbcon.c
··· 1019 1019 info->pixmap.blit_y); 1020 1020 vc->vc_font.width = font->width; 1021 1021 vc->vc_font.height = font->height; 1022 - vc->vc_font.data = (void *)(p->fontdata = font->data); 1022 + vc->vc_font.data = font_data_buf(font->data); 1023 1023 vc->vc_font.charcount = font->charcount; 1024 + 1025 + p->fontdata = font->data; 1024 1026 } 1025 1027 1026 1028 cols = FBCON_SWAP(par->rotate, info->var.xres, info->var.yres); ··· 1080 1078 if (t->fontdata) { 1081 1079 struct vc_data *fvc = vc_cons[fg_console].d; 1082 1080 1083 - vc->vc_font.data = (void *)(p->fontdata = 1084 - fvc->vc_font.data); 1081 + vc->vc_font.data = fvc->vc_font.data; 1085 1082 vc->vc_font.width = fvc->vc_font.width; 1086 1083 vc->vc_font.height = fvc->vc_font.height; 1087 1084 vc->vc_font.charcount = fvc->vc_font.charcount; 1085 + 1086 + p->fontdata = t->fontdata; 1088 1087 p->userfont = t->userfont; 1089 1088 1090 1089 if (p->userfont) ··· 1100 1097 info->pixmap.blit_y); 1101 1098 vc->vc_font.width = font->width; 1102 1099 vc->vc_font.height = font->height; 1103 - vc->vc_font.data = (void *)(p->fontdata = font->data); 1100 + vc->vc_font.data = font_data_buf(font->data); 1104 1101 vc->vc_font.charcount = font->charcount; 1102 + 1103 + p->fontdata = font->data; 1105 1104 } 1106 1105 } 1107 1106 ··· 1414 1409 svc = *default_mode; 1415 1410 t = &fb_display[svc->vc_num]; 1416 1411 1417 - if (!vc->vc_font.data) { 1418 - vc->vc_font.data = (void *)(p->fontdata = t->fontdata); 1412 + if (!p->fontdata) { 1413 + vc->vc_font.data = font_data_buf(t->fontdata); 1419 1414 vc->vc_font.width = (*default_mode)->vc_font.width; 1420 1415 vc->vc_font.height = (*default_mode)->vc_font.height; 1421 1416 vc->vc_font.charcount = (*default_mode)->vc_font.charcount; 1417 + p->fontdata = t->fontdata; 1422 1418 p->userfont = t->userfont; 1423 1419 if (p->userfont) 1424 1420 REFCOUNT(p->fontdata)++; ··· 2053 2047 struct fb_var_screeninfo var = info->var; 2054 2048 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh; 2055 2049 2056 - if (p->userfont && FNTSIZE(vc->vc_font.data)) { 2050 + if (p->userfont && FNTSIZE(p->fontdata)) { 2057 2051 unsigned int size = vc_font_size(&vc->vc_font); 2058 2052 2059 2053 /* ··· 2063 2057 * charcount can change and cannot be used to determine the 2064 2058 * font data allocated size. 2065 2059 */ 2066 - if (!size || size > FNTSIZE(vc->vc_font.data)) 2060 + if (!size || size > FNTSIZE(p->fontdata)) 2067 2061 return -EINVAL; 2068 2062 } 2069 2063 ··· 2287 2281 2288 2282 static int fbcon_get_font(struct vc_data *vc, struct console_font *font, unsigned int vpitch) 2289 2283 { 2290 - const u8 *fontdata = vc->vc_font.data; 2284 + struct fbcon_display *p = &fb_display[vc->vc_num]; 2285 + font_data_t *fontdata = p->fontdata; 2291 2286 u8 *data = font->data; 2292 2287 int i, j; 2293 2288 ··· 2413 2406 } 2414 2407 2415 2408 static int fbcon_do_set_font(struct vc_data *vc, int w, int h, int charcount, 2416 - const u8 * data, int userfont) 2409 + font_data_t *data, int userfont) 2417 2410 { 2418 2411 struct fb_info *info = fbcon_info_from_console(vc->vc_num); 2419 2412 struct fbcon_par *par = info->fbcon_par; 2420 2413 struct fbcon_display *p = &fb_display[vc->vc_num]; 2421 2414 int resize, ret, old_userfont, old_width, old_height, old_charcount; 2415 + font_data_t *old_fontdata = p->fontdata; 2422 2416 const u8 *old_data = vc->vc_font.data; 2423 2417 2424 2418 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height); 2425 - vc->vc_font.data = (void *)(p->fontdata = data); 2419 + p->fontdata = data; 2420 + vc->vc_font.data = font_data_buf(p->fontdata); 2426 2421 old_userfont = p->userfont; 2427 2422 if ((p->userfont = userfont)) 2428 2423 REFCOUNT(data)++; ··· 2457 2448 update_screen(vc); 2458 2449 } 2459 2450 2460 - if (old_userfont && (--REFCOUNT(old_data) == 0)) 2461 - kfree(old_data - FONT_EXTRA_WORDS * sizeof(int)); 2451 + if (old_userfont && (--REFCOUNT(old_fontdata) == 0)) 2452 + kfree(old_fontdata - FONT_EXTRA_WORDS * sizeof(int)); 2462 2453 return 0; 2463 2454 2464 2455 err_out: 2465 - p->fontdata = old_data; 2456 + p->fontdata = old_fontdata; 2466 2457 vc->vc_font.data = old_data; 2467 2458 2468 2459 if (userfont) { ··· 2492 2483 int h = font->height; 2493 2484 int size, alloc_size; 2494 2485 int i, csum; 2495 - u8 *new_data, *data = font->data; 2486 + font_data_t *new_data; 2487 + u8 *data = font->data; 2496 2488 int pitch = PITCH(font->width); 2497 2489 2498 2490 /* Is there a reason why fbconsole couldn't handle any charcount >256? ··· 2532 2522 if (!new_data) 2533 2523 return -ENOMEM; 2534 2524 2535 - memset(new_data, 0, FONT_EXTRA_WORDS * sizeof(int)); 2525 + memset((u8 *)new_data, 0, FONT_EXTRA_WORDS * sizeof(int)); 2536 2526 2537 2527 new_data += FONT_EXTRA_WORDS * sizeof(int); 2538 2528 FNTSIZE(new_data) = size; 2539 2529 REFCOUNT(new_data) = 0; /* usage counter */ 2540 2530 for (i=0; i< charcount; i++) { 2541 - memcpy(new_data + i*h*pitch, data + i*vpitch*pitch, h*pitch); 2531 + memcpy((u8 *)new_data + i * h * pitch, data + i * vpitch * pitch, h * pitch); 2542 2532 } 2543 2533 2544 2534 /* Since linux has a nice crc32 function use it for counting font
+2 -1
drivers/video/fbdev/core/fbcon.h
··· 11 11 #ifndef _VIDEO_FBCON_H 12 12 #define _VIDEO_FBCON_H 13 13 14 + #include <linux/font.h> 14 15 #include <linux/types.h> 15 16 #include <linux/vt_buffer.h> 16 17 #include <linux/vt_kern.h> ··· 26 25 27 26 struct fbcon_display { 28 27 /* Filled in by the low-level console driver */ 29 - const u_char *fontdata; 28 + font_data_t *fontdata; 30 29 int userfont; /* != 0 if fontdata kmalloc()ed */ 31 30 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_LEGACY_ACCELERATION 32 31 u_short scrollmode; /* Scroll Method, use fb_scrollmode() */
+46 -1
include/linux/font.h
··· 13 13 14 14 #include <linux/types.h> 15 15 16 + /* 17 + * font_data_t and helpers 18 + */ 19 + 20 + /** 21 + * font_data_t - Raw font data 22 + * 23 + * Values of type font_data_t store a pointer to raw font data. The format 24 + * is monochrome. Each bit sets a pixel of a stored glyph. Font data does 25 + * not store geometry information for the individual glyphs. Users of the 26 + * font have to store glyph size, pitch and character count separately. 27 + * 28 + * Font data in font_data_t is not equivalent to raw u8. Each pointer stores 29 + * an additional hidden header before the font data. The layout is 30 + * 31 + * +------+-----------------------------+ 32 + * | -16 | CRC32 Checksum (optional) | 33 + * | -12 | <Unused> | 34 + * | -8 | Number of data bytes | 35 + * | -4 | Reference count | 36 + * +------+-----------------------------+ 37 + * | 0 | Data buffer | 38 + * | ... | | 39 + * +------+-----------------------------+ 40 + * 41 + * Use helpers to access font_data_t. Use font_data_buf() to get the stored data. 42 + */ 43 + typedef const unsigned char font_data_t; 44 + 45 + /** 46 + * font_data_buf() - Returns the font data as raw bytes 47 + * @fd: The font data 48 + * 49 + * Returns: 50 + * The raw font data. The provided buffer is read-only. 51 + */ 52 + static inline const unsigned char *font_data_buf(font_data_t *fd) 53 + { 54 + return (const unsigned char *)fd; 55 + } 56 + 57 + /* 58 + * Font description 59 + */ 60 + 16 61 struct font_desc { 17 62 int idx; 18 63 const char *name; 19 64 unsigned int width, height; 20 65 unsigned int charcount; 21 - const void *data; 66 + font_data_t *data; 22 67 int pref; 23 68 }; 24 69