Skip to content

Commit ffc1e08

Browse files
sthibaulgregkh
authored andcommitted
VT: Add height parameter to con_font_get/set consw operations
The current con_font_get/set API currently hardcodes a 32-pixel-tall limitation, which only dates from the old VGA hardware which could not handle taller fonts than that. This change just adds a vpitch parameter to release this constraint. Drivers which do not support vpitch != 32 can just return EINVAL when it is not 32, font loading tools will revert to trying 32 and succeed. This change makes the fbcon driver consider vpitch appropriately, thus making it able to load large fonts. Signed-off-by: Samuel Thibault <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent e34a79d commit ffc1e08

File tree

6 files changed

+32
-36
lines changed

6 files changed

+32
-36
lines changed

drivers/tty/vt/vt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4552,7 +4552,7 @@ static int con_font_get(struct vc_data *vc, struct console_font_op *op)
45524552
if (vc->vc_mode != KD_TEXT)
45534553
rc = -EINVAL;
45544554
else if (vc->vc_sw->con_font_get)
4555-
rc = vc->vc_sw->con_font_get(vc, &font);
4555+
rc = vc->vc_sw->con_font_get(vc, &font, 32);
45564556
else
45574557
rc = -ENOSYS;
45584558
console_unlock();
@@ -4613,7 +4613,7 @@ static int con_font_set(struct vc_data *vc, struct console_font_op *op)
46134613
else if (vc->vc_sw->con_font_set) {
46144614
if (vc_is_sel(vc))
46154615
clear_selection();
4616-
rc = vc->vc_sw->con_font_set(vc, &font, op->flags);
4616+
rc = vc->vc_sw->con_font_set(vc, &font, 32, op->flags);
46174617
} else
46184618
rc = -ENOSYS;
46194619
console_unlock();

drivers/video/console/newport_con.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ static int newport_blank(struct vc_data *c, int blank, int mode_switch)
497497
return 1;
498498
}
499499

500-
static int newport_set_font(int unit, struct console_font *op)
500+
static int newport_set_font(int unit, struct console_font *op, unsigned int vpitch)
501501
{
502502
int w = op->width;
503503
int h = op->height;
@@ -507,7 +507,7 @@ static int newport_set_font(int unit, struct console_font *op)
507507

508508
/* ladis: when I grow up, there will be a day... and more sizes will
509509
* be supported ;-) */
510-
if ((w != 8) || (h != 16)
510+
if ((w != 8) || (h != 16) || (vpitch != 32)
511511
|| (op->charcount != 256 && op->charcount != 512))
512512
return -EINVAL;
513513

@@ -569,9 +569,10 @@ static int newport_font_default(struct vc_data *vc, struct console_font *op, cha
569569
return newport_set_def_font(vc->vc_num, op);
570570
}
571571

572-
static int newport_font_set(struct vc_data *vc, struct console_font *font, unsigned flags)
572+
static int newport_font_set(struct vc_data *vc, struct console_font *font,
573+
unsigned int vpitch, unsigned int flags)
573574
{
574-
return newport_set_font(vc->vc_num, font);
575+
return newport_set_font(vc->vc_num, font, vpitch);
575576
}
576577

577578
static bool newport_scroll(struct vc_data *vc, unsigned int t, unsigned int b,

drivers/video/console/sticon.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ static int sticon_set_def_font(int unit, struct console_font *op)
169169
return 0;
170170
}
171171

172-
static int sticon_set_font(struct vc_data *vc, struct console_font *op)
172+
static int sticon_set_font(struct vc_data *vc, struct console_font *op,
173+
unsigned int vpitch)
173174
{
174175
struct sti_struct *sti = sticon_sti;
175176
int vc_cols, vc_rows, vc_old_cols, vc_old_rows;
@@ -181,7 +182,7 @@ static int sticon_set_font(struct vc_data *vc, struct console_font *op)
181182
struct sti_cooked_font *cooked_font;
182183
unsigned char *data = op->data, *p;
183184

184-
if ((w < 6) || (h < 6) || (w > 32) || (h > 32)
185+
if ((w < 6) || (h < 6) || (w > 32) || (h > 32) || (vpitch != 32)
185186
|| (op->charcount != 256 && op->charcount != 512))
186187
return -EINVAL;
187188
pitch = ALIGN(w, 8) / 8;
@@ -267,9 +268,9 @@ static int sticon_font_default(struct vc_data *vc, struct console_font *op, char
267268
}
268269

269270
static int sticon_font_set(struct vc_data *vc, struct console_font *font,
270-
unsigned int flags)
271+
unsigned int vpitch, unsigned int flags)
271272
{
272-
return sticon_set_font(vc, font);
273+
return sticon_set_font(vc, font, vpitch);
273274
}
274275

275276
static void sticon_init(struct vc_data *c, int init)

drivers/video/console/vgacon.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,15 +1029,15 @@ static int vgacon_adjust_height(struct vc_data *vc, unsigned fontheight)
10291029
}
10301030

10311031
static int vgacon_font_set(struct vc_data *c, struct console_font *font,
1032-
unsigned int flags)
1032+
unsigned int vpitch, unsigned int flags)
10331033
{
10341034
unsigned charcount = font->charcount;
10351035
int rc;
10361036

10371037
if (vga_video_type < VIDEO_TYPE_EGAM)
10381038
return -EINVAL;
10391039

1040-
if (font->width != VGA_FONTWIDTH ||
1040+
if (font->width != VGA_FONTWIDTH || vpitch != 32 ||
10411041
(charcount != 256 && charcount != 512))
10421042
return -EINVAL;
10431043

@@ -1050,9 +1050,9 @@ static int vgacon_font_set(struct vc_data *c, struct console_font *font,
10501050
return rc;
10511051
}
10521052

1053-
static int vgacon_font_get(struct vc_data *c, struct console_font *font)
1053+
static int vgacon_font_get(struct vc_data *c, struct console_font *font, unsigned int vpitch)
10541054
{
1055-
if (vga_video_type < VIDEO_TYPE_EGAM)
1055+
if (vga_video_type < VIDEO_TYPE_EGAM || vpitch != 32)
10561056
return -EINVAL;
10571057

10581058
font->width = VGA_FONTWIDTH;

drivers/video/fbdev/core/fbcon.c

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2271,7 +2271,7 @@ static int fbcon_debug_leave(struct vc_data *vc)
22712271
return 0;
22722272
}
22732273

2274-
static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2274+
static int fbcon_get_font(struct vc_data *vc, struct console_font *font, unsigned int vpitch)
22752275
{
22762276
u8 *fontdata = vc->vc_font.data;
22772277
u8 *data = font->data;
@@ -2290,8 +2290,8 @@ static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
22902290

22912291
for (i = 0; i < font->charcount; i++) {
22922292
memcpy(data, fontdata, j);
2293-
memset(data + j, 0, 32 - j);
2294-
data += 32;
2293+
memset(data + j, 0, vpitch - j);
2294+
data += vpitch;
22952295
fontdata += j;
22962296
}
22972297
} else if (font->width <= 16) {
@@ -2301,8 +2301,8 @@ static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
23012301

23022302
for (i = 0; i < font->charcount; i++) {
23032303
memcpy(data, fontdata, j);
2304-
memset(data + j, 0, 64 - j);
2305-
data += 64;
2304+
memset(data + j, 0, 2*vpitch - j);
2305+
data += 2*vpitch;
23062306
fontdata += j;
23072307
}
23082308
} else if (font->width <= 24) {
@@ -2316,8 +2316,8 @@ static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
23162316
*data++ = fontdata[2];
23172317
fontdata += sizeof(u32);
23182318
}
2319-
memset(data, 0, 3 * (32 - j));
2320-
data += 3 * (32 - j);
2319+
memset(data, 0, 3 * (vpitch - j));
2320+
data += 3 * (vpitch - j);
23212321
}
23222322
} else {
23232323
j = vc->vc_font.height * 4;
@@ -2326,8 +2326,8 @@ static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
23262326

23272327
for (i = 0; i < font->charcount; i++) {
23282328
memcpy(data, fontdata, j);
2329-
memset(data + j, 0, 128 - j);
2330-
data += 128;
2329+
memset(data + j, 0, 4 * vpitch - j);
2330+
data += 4 * vpitch;
23312331
fontdata += j;
23322332
}
23332333
}
@@ -2462,19 +2462,12 @@ static int fbcon_do_set_font(struct vc_data *vc, int w, int h, int charcount,
24622462
}
24632463

24642464
/*
2465-
* User asked to set font; we are guaranteed that
2466-
* a) width and height are in range 1..32
2467-
* b) charcount does not exceed 512
2468-
* but lets not assume that, since someone might someday want to use larger
2469-
* fonts. And charcount of 512 is small for unicode support.
2470-
*
2471-
* However, user space gives the font in 32 rows , regardless of
2472-
* actual font height. So a new API is needed if support for larger fonts
2473-
* is ever implemented.
2465+
* User asked to set font; we are guaranteed that charcount does not exceed 512
2466+
* but lets not assume that, since charcount of 512 is small for unicode support.
24742467
*/
24752468

24762469
static int fbcon_set_font(struct vc_data *vc, struct console_font *font,
2477-
unsigned int flags)
2470+
unsigned int vpitch, unsigned int flags)
24782471
{
24792472
struct fb_info *info = fbcon_info_from_console(vc->vc_num);
24802473
unsigned charcount = font->charcount;
@@ -2517,7 +2510,7 @@ static int fbcon_set_font(struct vc_data *vc, struct console_font *font,
25172510
FNTSIZE(new_data) = size;
25182511
REFCOUNT(new_data) = 0; /* usage counter */
25192512
for (i=0; i< charcount; i++) {
2520-
memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2513+
memcpy(new_data + i*h*pitch, data + i*vpitch*pitch, h*pitch);
25212514
}
25222515

25232516
/* Since linux has a nice crc32 function use it for counting font

include/linux/console.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ struct consw {
5959
int (*con_switch)(struct vc_data *vc);
6060
int (*con_blank)(struct vc_data *vc, int blank, int mode_switch);
6161
int (*con_font_set)(struct vc_data *vc, struct console_font *font,
62-
unsigned int flags);
63-
int (*con_font_get)(struct vc_data *vc, struct console_font *font);
62+
unsigned int vpitch, unsigned int flags);
63+
int (*con_font_get)(struct vc_data *vc, struct console_font *font,
64+
unsigned int vpitch);
6465
int (*con_font_default)(struct vc_data *vc,
6566
struct console_font *font, char *name);
6667
int (*con_resize)(struct vc_data *vc, unsigned int width,

0 commit comments

Comments
 (0)