All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Slaby <jslaby@suse.cz>
To: gregkh@linuxfoundation.org
Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
	Jiri Slaby <jslaby@suse.cz>
Subject: [PATCH 02/38] vt: introduce enum vc_intensity for intensity
Date: Mon, 15 Jun 2020 09:48:34 +0200	[thread overview]
Message-ID: <20200615074910.19267-2-jslaby@suse.cz> (raw)
In-Reply-To: <20200615074910.19267-1-jslaby@suse.cz>

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.)

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/tty/vt/vt.c                     | 32 +++++++++++++------------
 drivers/usb/misc/sisusbvga/sisusb_con.c |  6 ++---
 drivers/video/console/mdacon.c          |  5 ++--
 drivers/video/console/sticon.c          |  3 ++-
 drivers/video/console/vgacon.c          |  9 +++----
 include/linux/console.h                 |  5 +++-
 include/linux/console_struct.h          | 11 +++++++--
 7 files changed, 43 insertions(+), 28 deletions(-)

diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index 76f52935e0c8..71bf483e5640 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -705,8 +705,9 @@ void update_region(struct vc_data *vc, unsigned long start, int count)
 
 /* Structure of attributes is hardware-dependent */
 
-static u8 build_attr(struct vc_data *vc, u8 _color, u8 _intensity, u8 _blink,
-    u8 _underline, u8 _reverse, u8 _italic)
+static u8 build_attr(struct vc_data *vc, u8 _color,
+		enum vc_intensity _intensity, u8 _blink, u8 _underline,
+		u8 _reverse, u8 _italic)
 {
 	if (vc->vc_sw->con_build_attr)
 		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,
 		a = (a & 0xF0) | vc->vc_itcolor;
 	else if (_underline)
 		a = (a & 0xf0) | vc->vc_ulcolor;
-	else if (_intensity == 0)
+	else if (_intensity == VCI_HALF_BRIGHT)
 		a = (a & 0xf0) | vc->vc_halfcolor;
 	if (_reverse)
 		a = ((a) & 0x88) | ((((a) >> 4) | ((a) << 4)) & 0x77);
 	if (_blink)
 		a ^= 0x80;
-	if (_intensity == 2)
+	if (_intensity == VCI_BOLD)
 		a ^= 0x08;
 	if (vc->vc_hi_font_mask == 0x100)
 		a <<= 1;
@@ -753,8 +754,9 @@ static void update_attr(struct vc_data *vc)
 	vc->vc_attr = build_attr(vc, vc->state.color, vc->state.intensity,
 	              vc->state.blink, vc->state.underline,
 	              vc->state.reverse ^ vc->vc_decscnm, vc->state.italic);
-	vc->vc_video_erase_char = ' ' | (build_attr(vc, vc->state.color, 1,
-				vc->state.blink, 0, vc->vc_decscnm, 0) << 8);
+	vc->vc_video_erase_char = ' ' | (build_attr(vc, vc->state.color,
+				VCI_NORMAL, vc->state.blink, 0, vc->vc_decscnm,
+				0) << 8);
 }
 
 /* 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
 
 static void default_attr(struct vc_data *vc)
 {
-	vc->state.intensity = 1;
+	vc->state.intensity = VCI_NORMAL;
 	vc->state.italic = 0;
 	vc->state.underline = 0;
 	vc->state.reverse = 0;
@@ -1652,11 +1654,11 @@ static void rgb_foreground(struct vc_data *vc, const struct rgb *c)
 
 	if (hue == 7 && max <= 0x55) {
 		hue = 0;
-		vc->state.intensity = 2;
+		vc->state.intensity = VCI_BOLD;
 	} else if (max > 0xaa)
-		vc->state.intensity = 2;
+		vc->state.intensity = VCI_BOLD;
 	else
-		vc->state.intensity = 1;
+		vc->state.intensity = VCI_NORMAL;
 
 	vc->state.color = (vc->state.color & 0xf0) | hue;
 }
@@ -1715,10 +1717,10 @@ static void csi_m(struct vc_data *vc)
 			default_attr(vc);
 			break;
 		case 1:
-			vc->state.intensity = 2;
+			vc->state.intensity = VCI_BOLD;
 			break;
 		case 2:
-			vc->state.intensity = 0;
+			vc->state.intensity = VCI_HALF_BRIGHT;
 			break;
 		case 3:
 			vc->state.italic = 1;
@@ -1764,7 +1766,7 @@ static void csi_m(struct vc_data *vc)
 			vc->vc_toggle_meta = 1;
 			break;
 		case 22:
-			vc->state.intensity = 1;
+			vc->state.intensity = VCI_NORMAL;
 			break;
 		case 23:
 			vc->state.italic = 0;
@@ -1795,7 +1797,7 @@ static void csi_m(struct vc_data *vc)
 		default:
 			if (vc->vc_par[i] >= 90 && vc->vc_par[i] <= 107) {
 				if (vc->vc_par[i] < 100)
-					vc->state.intensity = 2;
+					vc->state.intensity = VCI_BOLD;
 				vc->vc_par[i] -= 60;
 			}
 			if (vc->vc_par[i] >= 30 && vc->vc_par[i] <= 37)
@@ -1934,7 +1936,7 @@ static void setterm_command(struct vc_data *vc)
 	case 2:	/* set color for half intensity mode */
 		if (vc->vc_can_do_color && vc->vc_par[1] < 16) {
 			vc->vc_halfcolor = color_table[vc->vc_par[1]];
-			if (vc->state.intensity == 0)
+			if (vc->state.intensity == VCI_HALF_BRIGHT)
 				update_attr(vc);
 		}
 		break;
diff --git a/drivers/usb/misc/sisusbvga/sisusb_con.c b/drivers/usb/misc/sisusbvga/sisusb_con.c
index cd0155310fea..c59fe641b8b5 100644
--- a/drivers/usb/misc/sisusbvga/sisusb_con.c
+++ b/drivers/usb/misc/sisusbvga/sisusb_con.c
@@ -302,14 +302,14 @@ sisusbcon_deinit(struct vc_data *c)
 
 /* interface routine */
 static u8
-sisusbcon_build_attr(struct vc_data *c, u8 color, u8 intensity,
+sisusbcon_build_attr(struct vc_data *c, u8 color, enum vc_intensity intensity,
 			    u8 blink, u8 underline, u8 reverse, u8 unused)
 {
 	u8 attr = color;
 
 	if (underline)
 		attr = (attr & 0xf0) | c->vc_ulcolor;
-	else if (intensity == 0)
+	else if (intensity == VCI_HALF_BRIGHT)
 		attr = (attr & 0xf0) | c->vc_halfcolor;
 
 	if (reverse)
@@ -320,7 +320,7 @@ sisusbcon_build_attr(struct vc_data *c, u8 color, u8 intensity,
 	if (blink)
 		attr ^= 0x80;
 
-	if (intensity == 2)
+	if (intensity == VCI_BOLD)
 		attr ^= 0x08;
 
 	return attr;
diff --git a/drivers/video/console/mdacon.c b/drivers/video/console/mdacon.c
index d64c5ce84125..e3da664df16c 100644
--- a/drivers/video/console/mdacon.c
+++ b/drivers/video/console/mdacon.c
@@ -394,7 +394,8 @@ static inline u16 mda_convert_attr(u16 ch)
 		(ch & 0x00ff) | attr;
 }
 
-static u8 mdacon_build_attr(struct vc_data *c, u8 color, u8 intensity, 
+static u8 mdacon_build_attr(struct vc_data *c, u8 color,
+			    enum vc_intensity intensity,
 			    u8 blink, u8 underline, u8 reverse, u8 italic)
 {
 	/* The attribute is just a bit vector:
@@ -405,7 +406,7 @@ static u8 mdacon_build_attr(struct vc_data *c, u8 color, u8 intensity,
 	 *	Bit 7    : blink
 	 */
 
-	return (intensity & 3) |
+	return (intensity & VCI_MASK) |
 		((underline & 1) << 2) |
 		((reverse   & 1) << 3) |
 		(!!italic << 4) |
diff --git a/drivers/video/console/sticon.c b/drivers/video/console/sticon.c
index 90083eb80515..a847067abbe5 100644
--- a/drivers/video/console/sticon.c
+++ b/drivers/video/console/sticon.c
@@ -288,7 +288,8 @@ static unsigned long sticon_getxy(struct vc_data *conp, unsigned long pos,
     return ret;
 }
 
-static u8 sticon_build_attr(struct vc_data *conp, u8 color, u8 intens,
+static u8 sticon_build_attr(struct vc_data *conp, u8 color,
+			    enum vc_intensity intens,
 			    u8 blink, u8 underline, u8 reverse, u8 italic)
 {
     u8 attr = ((color & 0x70) >> 1) | ((color & 7));
diff --git a/drivers/video/console/vgacon.c b/drivers/video/console/vgacon.c
index d073fa167e87..d0b26e2318d3 100644
--- a/drivers/video/console/vgacon.c
+++ b/drivers/video/console/vgacon.c
@@ -629,7 +629,8 @@ static void vgacon_deinit(struct vc_data *c)
 	con_set_default_unimap(c);
 }
 
-static u8 vgacon_build_attr(struct vc_data *c, u8 color, u8 intensity,
+static u8 vgacon_build_attr(struct vc_data *c, u8 color,
+			    enum vc_intensity intensity,
 			    u8 blink, u8 underline, u8 reverse, u8 italic)
 {
 	u8 attr = color;
@@ -639,7 +640,7 @@ static u8 vgacon_build_attr(struct vc_data *c, u8 color, u8 intensity,
 			attr = (attr & 0xF0) | c->vc_itcolor;
 		else if (underline)
 			attr = (attr & 0xf0) | c->vc_ulcolor;
-		else if (intensity == 0)
+		else if (intensity == VCI_HALF_BRIGHT)
 			attr = (attr & 0xf0) | c->vc_halfcolor;
 	}
 	if (reverse)
@@ -648,14 +649,14 @@ static u8 vgacon_build_attr(struct vc_data *c, u8 color, u8 intensity,
 				       0x77);
 	if (blink)
 		attr ^= 0x80;
-	if (intensity == 2)
+	if (intensity == VCI_BOLD)
 		attr ^= 0x08;
 	if (!vga_can_do_color) {
 		if (italic)
 			attr = (attr & 0xF8) | 0x02;
 		else if (underline)
 			attr = (attr & 0xf8) | 0x01;
-		else if (intensity == 0)
+		else if (intensity == VCI_HALF_BRIGHT)
 			attr = (attr & 0xf0) | 0x08;
 	}
 	return attr;
diff --git a/include/linux/console.h b/include/linux/console.h
index 75dd20650fbe..10c04779ae49 100644
--- a/include/linux/console.h
+++ b/include/linux/console.h
@@ -35,6 +35,8 @@ enum con_scroll {
 	SM_DOWN,
 };
 
+enum vc_intensity;
+
 /**
  * struct consw - callbacks for consoles
  *
@@ -74,7 +76,8 @@ struct consw {
 	void	(*con_scrolldelta)(struct vc_data *vc, int lines);
 	int	(*con_set_origin)(struct vc_data *vc);
 	void	(*con_save_screen)(struct vc_data *vc);
-	u8	(*con_build_attr)(struct vc_data *vc, u8 color, u8 intensity,
+	u8	(*con_build_attr)(struct vc_data *vc, u8 color,
+			enum vc_intensity intensity,
 			u8 blink, u8 underline, u8 reverse, u8 italic);
 	void	(*con_invert_region)(struct vc_data *vc, u16 *p, int count);
 	u16    *(*con_screen_pos)(struct vc_data *vc, int offset);
diff --git a/include/linux/console_struct.h b/include/linux/console_struct.h
index 162f4337c767..e901d98790bf 100644
--- a/include/linux/console_struct.h
+++ b/include/linux/console_struct.h
@@ -22,6 +22,13 @@ struct uni_screen;
 
 #define NPAR 16
 
+enum vc_intensity {
+	VCI_HALF_BRIGHT,
+	VCI_NORMAL,
+	VCI_BOLD,
+	VCI_MASK = 0x3,
+};
+
 /**
  * struct vc_state -- state of a VC
  * @x: cursor's x-position
@@ -30,7 +37,7 @@ struct uni_screen;
  * @G0_charset: what's G0 slot set to (like GRAF_MAP, LAT1_MAP)
  * @G1_charset: what's G1 slot set to (like GRAF_MAP, LAT1_MAP)
  * @charset: what character set to use (0=G0 or 1=G1)
- * @intensity: 0=half-bright, 1=normal, 2=bold
+ * @intensity: see enum vc_intensity for values
  * @reverse: reversed foreground/background colors
  *
  * These members are defined separately from struct vc_data as we save &
@@ -46,7 +53,7 @@ struct vc_state {
 	unsigned int	charset		: 1;
 
 	/* attribute flags */
-	unsigned int	intensity	: 2;
+	enum vc_intensity intensity;
 	unsigned int	italic		: 1;
 	unsigned int	underline	: 1;
 	unsigned int	blink		: 1;
-- 
2.27.0


  reply	other threads:[~2020-06-15  7:49 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-15  7:48 [PATCH 01/38] vc: separate state Jiri Slaby
2020-06-15  7:48 ` Jiri Slaby [this message]
2020-06-15  7:48 ` [PATCH 03/38] vc: switch state to bool Jiri Slaby
2020-06-15  7:48 ` [PATCH 04/38] vt: deduplicate setGx code Jiri Slaby
2020-06-15  7:48 ` [PATCH 05/38] vt: switch G0/1_charset to an array Jiri Slaby
2020-06-15  7:48 ` [PATCH 06/38] vt: convert vc_tab_stop to bitmap Jiri Slaby
2020-06-15  7:48 ` [PATCH 07/38] vt: remove 25 years stale comment Jiri Slaby
2020-06-15  7:48 ` [PATCH 08/38] vt: use tty_insert_flip_string in respond_string Jiri Slaby
2020-06-15  7:48 ` [PATCH 09/38] vt: get rid of VT10.ID macros Jiri Slaby
2020-06-15  7:48 ` [PATCH 10/38] vt: move vc_translate to vt.c and rename it Jiri Slaby
2020-06-15  7:48 ` [PATCH 11/38] vt: use modern types in do_con_write Jiri Slaby
2020-06-15  7:48 ` [PATCH 12/38] vt: separate unicode handling into vc_translate_unicode Jiri Slaby
2020-06-15  7:48 ` [PATCH 13/38] vt: rearrange vc_translate_unicode Jiri Slaby
2020-06-15  7:48 ` [PATCH 14/38] vt: extract attribute inversion to vc_invert_attr Jiri Slaby
2020-06-15  7:48 ` [PATCH 15/38] vt: move rescan_last_byte label earlier Jiri Slaby
2020-06-15  7:48 ` [PATCH 16/38] vc: move translation out of do_con_write Jiri Slaby
2020-06-15  7:48 ` [PATCH 17/38] vc: introduce struct vc_draw_region Jiri Slaby
2020-06-15  7:48 ` [PATCH 18/38] vc: extract detecting control characters from do_con_write Jiri Slaby
2020-06-15  7:48 ` [PATCH 19/38] vc: move normal char processing " Jiri Slaby
2020-06-15  7:48 ` [PATCH 20/38] vc: simplify condition in vc_con_write_normal Jiri Slaby
2020-06-15  7:48 ` [PATCH 21/38] vt: simplify vc_attr handling " Jiri Slaby
2020-06-15  7:48 ` [PATCH 22/38] vt: make tc write more obvious " Jiri Slaby
2020-06-15  7:48 ` [PATCH 23/38] vt: synchronize types and use min in csi_X Jiri Slaby
2020-06-15  7:48 ` [PATCH 24/38] vt: whitespace and paren cleanup in add_softcursor Jiri Slaby
2020-06-15  7:48 ` [PATCH 25/38] vt: redefine world of cursor macros Jiri Slaby
2020-06-15  7:48   ` Jiri Slaby
2020-06-15  7:48   ` Jiri Slaby
2020-06-15  7:48 ` [PATCH 26/38] vt: use newly defined CUR_* macros Jiri Slaby
2020-06-15  7:48   ` Jiri Slaby
2020-06-15  7:48   ` Jiri Slaby
2020-06-15 20:31   ` Helge Deller
2020-06-15 20:31     ` Helge Deller
2020-06-15 20:31     ` Helge Deller
2020-06-15  7:48 ` [PATCH 27/38] vt: remove superfluous parens in invert_screen and build_attr Jiri Slaby
2020-06-15  7:49 ` [PATCH 28/38] vt: simplify noncolor attributes in build_attr Jiri Slaby
2020-06-15  7:49 ` [PATCH 29/38] vt_ioctl: eliminate ret & breaks in vt_ioctl Jiri Slaby
2020-06-15  7:49 ` [PATCH 30/38] vt_ioctl: eliminate use of uival and ucval Jiri Slaby
2020-06-15  7:49 ` [PATCH 31/38] vt_ioctl: move K* ioctls to a separate function Jiri Slaby
2020-06-15  7:49 ` [PATCH 32/38] vt_ioctl: move io " Jiri Slaby
2020-06-15  7:49 ` [PATCH 33/38] vt_ioctl: move vt_setactivate out of vt_ioctl Jiri Slaby
2020-06-15  7:49 ` [PATCH 34/38] vt_ioctl: move vt_reldisp " Jiri Slaby
2020-06-15  7:49 ` [PATCH 35/38] vt_ioctl: move vt_resizex " Jiri Slaby
2020-06-15  7:49 ` [PATCH 36/38] vt_ioctl: move vt_io_fontreset out of vt_io_ioctl Jiri Slaby
2020-06-15  7:49 ` [PATCH 37/38] vt_ioctl: move vt_kdsetmode out of vt_k_ioctl Jiri Slaby
2020-06-15  7:49 ` [PATCH 38/38] vt_ioctl: move perm checks level up Jiri Slaby

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200615074910.19267-2-jslaby@suse.cz \
    --to=jslaby@suse.cz \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.