History

vt: introduce enum vc_intensity for intensity

Introduce names (en enum) for 0, 1, and 2 constants. We now have VCI_HALF_BRIGHT, VCI_NORMAL, and VCI_BOLD instead. Apart from the cleanup, 1) the enum allows for better type checking, and 2) this saves some code. No more fiddling with bits is needed in assembly now. (OTOH, the structure is larger.)

Jiri Slaby committed 6 years ago

Commit b84ae3d1 parent 28bc24f7 files · +43 −28Browse files

Unified · Split

7 files
  1. drivers/tty/vt/vt.c +17 −15
  2. drivers/usb/misc/sisusbvga/sisusb_con.c +3 −3
  3. drivers/video/console/mdacon.c +3 −2
  4. drivers/video/console/sticon.c +2 −1
  5. drivers/video/console/vgacon.c +5 −4
  6. include/linux/console.h +4 −1
  7. include/linux/console_struct.h +9 −2
drivers/tty/vt/vt.c+17−15
@@ -705,8 +705,9 @@ void update_region(struct vc_data *vc, unsigned long start, int count) · 704 unmodified lines
705 705
706/* Structure of attributes is hardware-dependent */706/* Structure of attributes is hardware-dependent */
707 707
708static u8 build_attr(struct vc_data *vc, u8 _color, u8 _intensity, u8 _blink,708static u8 build_attr(struct vc_data *vc, u8 _color,
709 u8 _underline, u8 _reverse, u8 _italic)709 enum vc_intensity _intensity, u8 _blink, u8 _underline,
710 u8 _reverse, u8 _italic)
710{711{
711 if (vc->vc_sw->con_build_attr)712 if (vc->vc_sw->con_build_attr)
712 return vc->vc_sw->con_build_attr(vc, _color, _intensity,713 return vc->vc_sw->con_build_attr(vc, _color, _intensity,
@@ -734,13 +735,13 @@ static u8 build_attr(struct vc_data *vc, u8 _color, u8 _intensity, u8 _blink, · 21 unmodified lines
734 a = (a & 0xF0) | vc->vc_itcolor;735 a = (a & 0xF0) | vc->vc_itcolor;
735 else if (_underline)736 else if (_underline)
736 a = (a & 0xf0) | vc->vc_ulcolor;737 a = (a & 0xf0) | vc->vc_ulcolor;
737 else if (_intensity == 0)738 else if (_intensity == VCI_HALF_BRIGHT)
738 a = (a & 0xf0) | vc->vc_halfcolor;739 a = (a & 0xf0) | vc->vc_halfcolor;
739 if (_reverse)740 if (_reverse)
740 a = ((a) & 0x88) | ((((a) >> 4) | ((a) << 4)) & 0x77);741 a = ((a) & 0x88) | ((((a) >> 4) | ((a) << 4)) & 0x77);
741 if (_blink)742 if (_blink)
742 a ^= 0x80;743 a ^= 0x80;
743 if (_intensity == 2)744 if (_intensity == VCI_BOLD)
744 a ^= 0x08;745 a ^= 0x08;
745 if (vc->vc_hi_font_mask == 0x100)746 if (vc->vc_hi_font_mask == 0x100)
746 a <<= 1;747 a <<= 1;
@@ -753,8 +754,9 @@ static void update_attr(struct vc_data *vc) · 6 unmodified lines
753 vc->vc_attr = build_attr(vc, vc->state.color, vc->state.intensity,754 vc->vc_attr = build_attr(vc, vc->state.color, vc->state.intensity,
754 vc->state.blink, vc->state.underline,755 vc->state.blink, vc->state.underline,
755 vc->state.reverse ^ vc->vc_decscnm, vc->state.italic);756 vc->state.reverse ^ vc->vc_decscnm, vc->state.italic);
756 vc->vc_video_erase_char = ' ' | (build_attr(vc, vc->state.color, 1,757 vc->vc_video_erase_char = ' ' | (build_attr(vc, vc->state.color,
757 vc->state.blink, 0, vc->vc_decscnm, 0) << 8);758 VCI_NORMAL, vc->state.blink, 0, vc->vc_decscnm,
759 0) << 8);
758}760}
759 761
760/* Note: inverting the screen twice should revert to the original state */762/* Note: inverting the screen twice should revert to the original state */
@@ -1611,7 +1613,7 @@ static void csi_X(struct vc_data *vc, int vpar) /* erase the following vpar posi · 850 unmodified lines
1611 1613
1612static void default_attr(struct vc_data *vc)1614static void default_attr(struct vc_data *vc)
1613{1615{
1614 vc->state.intensity = 1;1616 vc->state.intensity = VCI_NORMAL;
1615 vc->state.italic = 0;1617 vc->state.italic = 0;
1616 vc->state.underline = 0;1618 vc->state.underline = 0;
1617 vc->state.reverse = 0;1619 vc->state.reverse = 0;
@@ -1652,11 +1654,11 @@ static void rgb_foreground(struct vc_data *vc, const struct rgb *c) · 34 unmodified lines
1652 1654
1653 if (hue == 7 && max <= 0x55) {1655 if (hue == 7 && max <= 0x55) {
1654 hue = 0;1656 hue = 0;
1655 vc->state.intensity = 2;1657 vc->state.intensity = VCI_BOLD;
1656 } else if (max > 0xaa)1658 } else if (max > 0xaa)
1657 vc->state.intensity = 2;1659 vc->state.intensity = VCI_BOLD;
1658 else1660 else
1659 vc->state.intensity = 1;1661 vc->state.intensity = VCI_NORMAL;
1660 1662
1661 vc->state.color = (vc->state.color & 0xf0) | hue;1663 vc->state.color = (vc->state.color & 0xf0) | hue;
1662}1664}
@@ -1715,10 +1717,10 @@ static void csi_m(struct vc_data *vc) · 52 unmodified lines
1715 default_attr(vc);1717 default_attr(vc);
1716 break;1718 break;
1717 case 1:1719 case 1:
1718 vc->state.intensity = 2;1720 vc->state.intensity = VCI_BOLD;
1719 break;1721 break;
1720 case 2:1722 case 2:
1721 vc->state.intensity = 0;1723 vc->state.intensity = VCI_HALF_BRIGHT;
1722 break;1724 break;
1723 case 3:1725 case 3:
1724 vc->state.italic = 1;1726 vc->state.italic = 1;
@@ -1764,7 +1766,7 @@ static void csi_m(struct vc_data *vc) · 39 unmodified lines
1764 vc->vc_toggle_meta = 1;1766 vc->vc_toggle_meta = 1;
1765 break;1767 break;
1766 case 22:1768 case 22:
1767 vc->state.intensity = 1;1769 vc->state.intensity = VCI_NORMAL;
1768 break;1770 break;
1769 case 23:1771 case 23:
1770 vc->state.italic = 0;1772 vc->state.italic = 0;
@@ -1795,7 +1797,7 @@ static void csi_m(struct vc_data *vc) · 24 unmodified lines
1795 default:1797 default:
1796 if (vc->vc_par[i] >= 90 && vc->vc_par[i] <= 107) {1798 if (vc->vc_par[i] >= 90 && vc->vc_par[i] <= 107) {
1797 if (vc->vc_par[i] < 100)1799 if (vc->vc_par[i] < 100)
1798 vc->state.intensity = 2;1800 vc->state.intensity = VCI_BOLD;
1799 vc->vc_par[i] -= 60;1801 vc->vc_par[i] -= 60;
1800 }1802 }
1801 if (vc->vc_par[i] >= 30 && vc->vc_par[i] <= 37)1803 if (vc->vc_par[i] >= 30 && vc->vc_par[i] <= 37)
@@ -1934,7 +1936,7 @@ static void setterm_command(struct vc_data *vc) · 132 unmodified lines
1934 case 2: /* set color for half intensity mode */1936 case 2: /* set color for half intensity mode */
1935 if (vc->vc_can_do_color && vc->vc_par[1] < 16) {1937 if (vc->vc_can_do_color && vc->vc_par[1] < 16) {
1936 vc->vc_halfcolor = color_table[vc->vc_par[1]];1938 vc->vc_halfcolor = color_table[vc->vc_par[1]];
1937 if (vc->state.intensity == 0)1939 if (vc->state.intensity == VCI_HALF_BRIGHT)
1938 update_attr(vc);1940 update_attr(vc);
1939 }1941 }
1940 break;1942 break;
drivers/usb/misc/sisusbvga/sisusb_con.c+3−3
@@ -302,14 +302,14 @@ sisusbcon_deinit(struct vc_data *c) · 301 unmodified lines
302 302
303/* interface routine */303/* interface routine */
304static u8304static u8
305sisusbcon_build_attr(struct vc_data *c, u8 color, u8 intensity,305sisusbcon_build_attr(struct vc_data *c, u8 color, enum vc_intensity intensity,
306 u8 blink, u8 underline, u8 reverse, u8 unused)306 u8 blink, u8 underline, u8 reverse, u8 unused)
307{307{
308 u8 attr = color;308 u8 attr = color;
309 309
310 if (underline)310 if (underline)
311 attr = (attr & 0xf0) | c->vc_ulcolor;311 attr = (attr & 0xf0) | c->vc_ulcolor;
312 else if (intensity == 0)312 else if (intensity == VCI_HALF_BRIGHT)
313 attr = (attr & 0xf0) | c->vc_halfcolor;313 attr = (attr & 0xf0) | c->vc_halfcolor;
314 314
315 if (reverse)315 if (reverse)
@@ -320,7 +320,7 @@ sisusbcon_build_attr(struct vc_data *c, u8 color, u8 intensity, · 4 unmodified lines
320 if (blink)320 if (blink)
321 attr ^= 0x80;321 attr ^= 0x80;
322 322
323 if (intensity == 2)323 if (intensity == VCI_BOLD)
324 attr ^= 0x08;324 attr ^= 0x08;
325 325
326 return attr;326 return attr;
drivers/video/console/mdacon.c+3−2
@@ -394,7 +394,8 @@ static inline u16 mda_convert_attr(u16 ch) · 393 unmodified lines
394 (ch & 0x00ff) | attr;394 (ch & 0x00ff) | attr;
395}395}
396 396
397static u8 mdacon_build_attr(struct vc_data *c, u8 color, u8 intensity, 397static u8 mdacon_build_attr(struct vc_data *c, u8 color,
398 enum vc_intensity intensity,
398 u8 blink, u8 underline, u8 reverse, u8 italic)399 u8 blink, u8 underline, u8 reverse, u8 italic)
399{400{
400 /* The attribute is just a bit vector:401 /* The attribute is just a bit vector:
@@ -405,7 +406,7 @@ static u8 mdacon_build_attr(struct vc_data *c, u8 color, u8 intensity, · 4 unmodified lines
405 * Bit 7 : blink406 * Bit 7 : blink
406 */407 */
407 408
408 return (intensity & 3) |409 return (intensity & VCI_MASK) |
409 ((underline & 1) << 2) |410 ((underline & 1) << 2) |
410 ((reverse & 1) << 3) |411 ((reverse & 1) << 3) |
411 (!!italic << 4) |412 (!!italic << 4) |
drivers/video/console/sticon.c+2−1
@@ -288,7 +288,8 @@ static unsigned long sticon_getxy(struct vc_data *conp, unsigned long pos, · 287 unmodified lines
288 return ret;288 return ret;
289}289}
290 290
291static u8 sticon_build_attr(struct vc_data *conp, u8 color, u8 intens,291static u8 sticon_build_attr(struct vc_data *conp, u8 color,
292 enum vc_intensity intens,
292 u8 blink, u8 underline, u8 reverse, u8 italic)293 u8 blink, u8 underline, u8 reverse, u8 italic)
293{294{
294 u8 attr = ((color & 0x70) >> 1) | ((color & 7));295 u8 attr = ((color & 0x70) >> 1) | ((color & 7));
drivers/video/console/vgacon.c+5−4
@@ -629,7 +629,8 @@ static void vgacon_deinit(struct vc_data *c) · 628 unmodified lines
629 con_set_default_unimap(c);629 con_set_default_unimap(c);
630}630}
631 631
632static u8 vgacon_build_attr(struct vc_data *c, u8 color, u8 intensity,632static u8 vgacon_build_attr(struct vc_data *c, u8 color,
633 enum vc_intensity intensity,
633 u8 blink, u8 underline, u8 reverse, u8 italic)634 u8 blink, u8 underline, u8 reverse, u8 italic)
634{635{
635 u8 attr = color;636 u8 attr = color;
@@ -639,7 +640,7 @@ static u8 vgacon_build_attr(struct vc_data *c, u8 color, u8 intensity, · 3 unmodified lines
639 attr = (attr & 0xF0) | c->vc_itcolor;640 attr = (attr & 0xF0) | c->vc_itcolor;
640 else if (underline)641 else if (underline)
641 attr = (attr & 0xf0) | c->vc_ulcolor;642 attr = (attr & 0xf0) | c->vc_ulcolor;
642 else if (intensity == 0)643 else if (intensity == VCI_HALF_BRIGHT)
643 attr = (attr & 0xf0) | c->vc_halfcolor;644 attr = (attr & 0xf0) | c->vc_halfcolor;
644 }645 }
645 if (reverse)646 if (reverse)
@@ -648,14 +649,14 @@ static u8 vgacon_build_attr(struct vc_data *c, u8 color, u8 intensity, · 2 unmodified lines
648 0x77);649 0x77);
649 if (blink)650 if (blink)
650 attr ^= 0x80;651 attr ^= 0x80;
651 if (intensity == 2)652 if (intensity == VCI_BOLD)
652 attr ^= 0x08;653 attr ^= 0x08;
653 if (!vga_can_do_color) {654 if (!vga_can_do_color) {
654 if (italic)655 if (italic)
655 attr = (attr & 0xF8) | 0x02;656 attr = (attr & 0xF8) | 0x02;
656 else if (underline)657 else if (underline)
657 attr = (attr & 0xf8) | 0x01;658 attr = (attr & 0xf8) | 0x01;
658 else if (intensity == 0)659 else if (intensity == VCI_HALF_BRIGHT)
659 attr = (attr & 0xf0) | 0x08;660 attr = (attr & 0xf0) | 0x08;
660 }661 }
661 return attr;662 return attr;
include/linux/console.h+4−1
@@ -35,6 +35,8 @@ enum con_scroll { · 34 unmodified lines
35 SM_DOWN,35 SM_DOWN,
36};36};
37 37
38enum vc_intensity;
39
38/**40/**
39 * struct consw - callbacks for consoles41 * struct consw - callbacks for consoles
40 *42 *
@@ -74,7 +76,8 @@ struct consw { · 33 unmodified lines
74 void (*con_scrolldelta)(struct vc_data *vc, int lines);76 void (*con_scrolldelta)(struct vc_data *vc, int lines);
75 int (*con_set_origin)(struct vc_data *vc);77 int (*con_set_origin)(struct vc_data *vc);
76 void (*con_save_screen)(struct vc_data *vc);78 void (*con_save_screen)(struct vc_data *vc);
77 u8 (*con_build_attr)(struct vc_data *vc, u8 color, u8 intensity,79 u8 (*con_build_attr)(struct vc_data *vc, u8 color,
80 enum vc_intensity intensity,
78 u8 blink, u8 underline, u8 reverse, u8 italic);81 u8 blink, u8 underline, u8 reverse, u8 italic);
79 void (*con_invert_region)(struct vc_data *vc, u16 *p, int count);82 void (*con_invert_region)(struct vc_data *vc, u16 *p, int count);
80 u16 *(*con_screen_pos)(struct vc_data *vc, int offset);83 u16 *(*con_screen_pos)(struct vc_data *vc, int offset);
include/linux/console_struct.h+9−2
@@ -22,6 +22,13 @@ struct uni_screen; · 21 unmodified lines
22 22
23#define NPAR 1623#define NPAR 16
24 24
25enum vc_intensity {
26 VCI_HALF_BRIGHT,
27 VCI_NORMAL,
28 VCI_BOLD,
29 VCI_MASK = 0x3,
30};
31
25/**32/**
26 * struct vc_state -- state of a VC33 * struct vc_state -- state of a VC
27 * @x: cursor's x-position34 * @x: cursor's x-position
@@ -30,7 +37,7 @@ struct uni_screen; · 2 unmodified lines
30 * @G0_charset: what's G0 slot set to (like GRAF_MAP, LAT1_MAP)37 * @G0_charset: what's G0 slot set to (like GRAF_MAP, LAT1_MAP)
31 * @G1_charset: what's G1 slot set to (like GRAF_MAP, LAT1_MAP)38 * @G1_charset: what's G1 slot set to (like GRAF_MAP, LAT1_MAP)
32 * @charset: what character set to use (0=G0 or 1=G1)39 * @charset: what character set to use (0=G0 or 1=G1)
33 * @intensity: 0=half-bright, 1=normal, 2=bold40 * @intensity: see enum vc_intensity for values
34 * @reverse: reversed foreground/background colors41 * @reverse: reversed foreground/background colors
35 *42 *
36 * These members are defined separately from struct vc_data as we save &43 * These members are defined separately from struct vc_data as we save &
@@ -46,7 +53,7 @@ struct vc_state { · 9 unmodified lines
46 unsigned int charset : 1;53 unsigned int charset : 1;
47 54
48 /* attribute flags */55 /* attribute flags */
49 unsigned int intensity : 2;56 enum vc_intensity intensity;
50 unsigned int italic : 1;57 unsigned int italic : 1;
51 unsigned int underline : 1;58 unsigned int underline : 1;
52 unsigned int blink : 1;59 unsigned int blink : 1;