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
705705
706706 /* Structure of attributes is hardware-dependent */
707707
708−static u8 build_attr(struct vc_data *vc, u8 _color, u8 _intensity, u8 _blink,
709− u8 _underline, u8 _reverse, u8 _italic)
708+static u8 build_attr(struct vc_data *vc, u8 _color,
709+ enum vc_intensity _intensity, u8 _blink, u8 _underline,
710+ u8 _reverse, u8 _italic)
710711 {
711712 if (vc->vc_sw->con_build_attr)
712713 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
734735 a = (a & 0xF0) | vc->vc_itcolor;
735736 else if (_underline)
736737 a = (a & 0xf0) | vc->vc_ulcolor;
737− else if (_intensity == 0)
738+ else if (_intensity == VCI_HALF_BRIGHT)
738739 a = (a & 0xf0) | vc->vc_halfcolor;
739740 if (_reverse)
740741 a = ((a) & 0x88) | ((((a) >> 4) | ((a) << 4)) & 0x77);
741742 if (_blink)
742743 a ^= 0x80;
743− if (_intensity == 2)
744+ if (_intensity == VCI_BOLD)
744745 a ^= 0x08;
745746 if (vc->vc_hi_font_mask == 0x100)
746747 a <<= 1;
@@ -753,8 +754,9 @@ static void update_attr(struct vc_data *vc) · 6 unmodified lines
753754 vc->vc_attr = build_attr(vc, vc->state.color, vc->state.intensity,
754755 vc->state.blink, vc->state.underline,
755756 vc->state.reverse ^ vc->vc_decscnm, vc->state.italic);
756− vc->vc_video_erase_char = ' ' | (build_attr(vc, vc->state.color, 1,
757− vc->state.blink, 0, vc->vc_decscnm, 0) << 8);
757+ vc->vc_video_erase_char = ' ' | (build_attr(vc, vc->state.color,
758+ VCI_NORMAL, vc->state.blink, 0, vc->vc_decscnm,
759+ 0) << 8);
758760 }
759761
760762 /* 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
16111613
16121614 static void default_attr(struct vc_data *vc)
16131615 {
1614− vc->state.intensity = 1;
1616+ vc->state.intensity = VCI_NORMAL;
16151617 vc->state.italic = 0;
16161618 vc->state.underline = 0;
16171619 vc->state.reverse = 0;
@@ -1652,11 +1654,11 @@ static void rgb_foreground(struct vc_data *vc, const struct rgb *c) · 34 unmodified lines
16521654
16531655 if (hue == 7 && max <= 0x55) {
16541656 hue = 0;
1655− vc->state.intensity = 2;
1657+ vc->state.intensity = VCI_BOLD;
16561658 } else if (max > 0xaa)
1657− vc->state.intensity = 2;
1659+ vc->state.intensity = VCI_BOLD;
16581660 else
1659− vc->state.intensity = 1;
1661+ vc->state.intensity = VCI_NORMAL;
16601662
16611663 vc->state.color = (vc->state.color & 0xf0) | hue;
16621664 }
@@ -1715,10 +1717,10 @@ static void csi_m(struct vc_data *vc) · 52 unmodified lines
17151717 default_attr(vc);
17161718 break;
17171719 case 1:
1718− vc->state.intensity = 2;
1720+ vc->state.intensity = VCI_BOLD;
17191721 break;
17201722 case 2:
1721− vc->state.intensity = 0;
1723+ vc->state.intensity = VCI_HALF_BRIGHT;
17221724 break;
17231725 case 3:
17241726 vc->state.italic = 1;
@@ -1764,7 +1766,7 @@ static void csi_m(struct vc_data *vc) · 39 unmodified lines
17641766 vc->vc_toggle_meta = 1;
17651767 break;
17661768 case 22:
1767− vc->state.intensity = 1;
1769+ vc->state.intensity = VCI_NORMAL;
17681770 break;
17691771 case 23:
17701772 vc->state.italic = 0;
@@ -1795,7 +1797,7 @@ static void csi_m(struct vc_data *vc) · 24 unmodified lines
17951797 default:
17961798 if (vc->vc_par[i] >= 90 && vc->vc_par[i] <= 107) {
17971799 if (vc->vc_par[i] < 100)
1798− vc->state.intensity = 2;
1800+ vc->state.intensity = VCI_BOLD;
17991801 vc->vc_par[i] -= 60;
18001802 }
18011803 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
19341936 case 2: /* set color for half intensity mode */
19351937 if (vc->vc_can_do_color && vc->vc_par[1] < 16) {
19361938 vc->vc_halfcolor = color_table[vc->vc_par[1]];
1937− if (vc->state.intensity == 0)
1939+ if (vc->state.intensity == VCI_HALF_BRIGHT)
19381940 update_attr(vc);
19391941 }
19401942 break;
drivers/usb/misc/sisusbvga/sisusb_con.c+3−3
@@ -302,14 +302,14 @@ sisusbcon_deinit(struct vc_data *c) · 301 unmodified lines
302302
303303 /* interface routine */
304304 static u8
305−sisusbcon_build_attr(struct vc_data *c, u8 color, u8 intensity,
305+sisusbcon_build_attr(struct vc_data *c, u8 color, enum vc_intensity intensity,
306306 u8 blink, u8 underline, u8 reverse, u8 unused)
307307 {
308308 u8 attr = color;
309309
310310 if (underline)
311311 attr = (attr & 0xf0) | c->vc_ulcolor;
312− else if (intensity == 0)
312+ else if (intensity == VCI_HALF_BRIGHT)
313313 attr = (attr & 0xf0) | c->vc_halfcolor;
314314
315315 if (reverse)
@@ -320,7 +320,7 @@ sisusbcon_build_attr(struct vc_data *c, u8 color, u8 intensity, · 4 unmodified lines
320320 if (blink)
321321 attr ^= 0x80;
322322
323− if (intensity == 2)
323+ if (intensity == VCI_BOLD)
324324 attr ^= 0x08;
325325
326326 return attr;
drivers/video/console/mdacon.c+3−2
@@ -394,7 +394,8 @@ static inline u16 mda_convert_attr(u16 ch) · 393 unmodified lines
394394 (ch & 0x00ff) | attr;
395395 }
396396
397−static u8 mdacon_build_attr(struct vc_data *c, u8 color, u8 intensity,
397+static u8 mdacon_build_attr(struct vc_data *c, u8 color,
398+ enum vc_intensity intensity,
398399 u8 blink, u8 underline, u8 reverse, u8 italic)
399400 {
400401 /* 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
405406 * Bit 7 : blink
406407 */
407408
408− return (intensity & 3) |
409+ return (intensity & VCI_MASK) |
409410 ((underline & 1) << 2) |
410411 ((reverse & 1) << 3) |
411412 (!!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
288288 return ret;
289289 }
290290
291−static u8 sticon_build_attr(struct vc_data *conp, u8 color, u8 intens,
291+static u8 sticon_build_attr(struct vc_data *conp, u8 color,
292+ enum vc_intensity intens,
292293 u8 blink, u8 underline, u8 reverse, u8 italic)
293294 {
294295 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
629629 con_set_default_unimap(c);
630630 }
631631
632−static u8 vgacon_build_attr(struct vc_data *c, u8 color, u8 intensity,
632+static u8 vgacon_build_attr(struct vc_data *c, u8 color,
633+ enum vc_intensity intensity,
633634 u8 blink, u8 underline, u8 reverse, u8 italic)
634635 {
635636 u8 attr = color;
@@ -639,7 +640,7 @@ static u8 vgacon_build_attr(struct vc_data *c, u8 color, u8 intensity, · 3 unmodified lines
639640 attr = (attr & 0xF0) | c->vc_itcolor;
640641 else if (underline)
641642 attr = (attr & 0xf0) | c->vc_ulcolor;
642− else if (intensity == 0)
643+ else if (intensity == VCI_HALF_BRIGHT)
643644 attr = (attr & 0xf0) | c->vc_halfcolor;
644645 }
645646 if (reverse)
@@ -648,14 +649,14 @@ static u8 vgacon_build_attr(struct vc_data *c, u8 color, u8 intensity, · 2 unmodified lines
648649 0x77);
649650 if (blink)
650651 attr ^= 0x80;
651− if (intensity == 2)
652+ if (intensity == VCI_BOLD)
652653 attr ^= 0x08;
653654 if (!vga_can_do_color) {
654655 if (italic)
655656 attr = (attr & 0xF8) | 0x02;
656657 else if (underline)
657658 attr = (attr & 0xf8) | 0x01;
658− else if (intensity == 0)
659+ else if (intensity == VCI_HALF_BRIGHT)
659660 attr = (attr & 0xf0) | 0x08;
660661 }
661662 return attr;
include/linux/console.h+4−1
@@ -35,6 +35,8 @@ enum con_scroll { · 34 unmodified lines
3535 SM_DOWN,
3636 };
3737
38+enum vc_intensity;
39+
3840 /**
3941 * struct consw - callbacks for consoles
4042 *
@@ -74,7 +76,8 @@ struct consw { · 33 unmodified lines
7476 void (*con_scrolldelta)(struct vc_data *vc, int lines);
7577 int (*con_set_origin)(struct vc_data *vc);
7678 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,
7881 u8 blink, u8 underline, u8 reverse, u8 italic);
7982 void (*con_invert_region)(struct vc_data *vc, u16 *p, int count);
8083 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
2222
2323 #define NPAR 16
2424
25+enum vc_intensity {
26+ VCI_HALF_BRIGHT,
27+ VCI_NORMAL,
28+ VCI_BOLD,
29+ VCI_MASK = 0x3,
30+};
31+
2532 /**
2633 * struct vc_state -- state of a VC
2734 * @x: cursor's x-position
@@ -30,7 +37,7 @@ struct uni_screen; · 2 unmodified lines
3037 * @G0_charset: what's G0 slot set to (like GRAF_MAP, LAT1_MAP)
3138 * @G1_charset: what's G1 slot set to (like GRAF_MAP, LAT1_MAP)
3239 * @charset: what character set to use (0=G0 or 1=G1)
33− * @intensity: 0=half-bright, 1=normal, 2=bold
40+ * @intensity: see enum vc_intensity for values
3441 * @reverse: reversed foreground/background colors
3542 *
3643 * These members are defined separately from struct vc_data as we save &
@@ -46,7 +53,7 @@ struct vc_state { · 9 unmodified lines
4653 unsigned int charset : 1;
4754
4855 /* attribute flags */
49− unsigned int intensity : 2;
56+ enum vc_intensity intensity;
5057 unsigned int italic : 1;
5158 unsigned int underline : 1;
5259 unsigned int blink : 1;