Skip to contentSkip to conversation

termbits.h: Further improvements

PATCH In review Ilpo Järvinen 2 participants 6 messages May 9, 2022

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

cover termbits.h: Further improvements

Again, I prefer Greg to take these through his tty tree.

Changes done by this serie:

1) Create termbits-common.h for the most obvious termbits.h intersection.
2) Reformat some lines that remain in termbits.h files.
3) Don't include posix_types.h unnecessarily.

Please do check I got the uapi include things done correctly! That is, that including using asm-generic/termbits-common.h path is the preferred approach for a header file that is not supposed to be overridden by the arch specific header files and that mandatory-y is not required for termbits-common.h.

Unfortunately I couldn't move also tcflag_t into termbits-common.h due to the way it is being defined for sparc. However, by the looks of how the type for tcflag_t is being chosen there, having just unsigned int might work also for sparc?

Ilpo Järvinen (3):
termbits.h: create termbits-common.h for identical bits termbits.h: Align lines & format
termbits.h: Remove posix_types.h include

 arch/alpha/include/uapi/asm/termbits.h     | 182 ++++++-----------
 arch/mips/include/uapi/asm/termbits.h      | 209 ++++++++-----------
 arch/parisc/include/uapi/asm/termbits.h    | 131 ++++--------
 arch/powerpc/include/uapi/asm/termbits.h   | 152 +++++---------
 arch/sparc/include/uapi/asm/termbits.h     | 223 ++++++++-------------
 include/uapi/asm-generic/termbits-common.h |  65 ++++++
 include/uapi/asm-generic/termbits.h        | 129 ++++--------
 7 files changed, 418 insertions(+), 673 deletions(-)
 create mode 100644 include/uapi/asm-generic/termbits-common.h
Signature · 1 line
2.30.2
#1 lore raw

PATCH 1/3 termbits.h: create termbits-common.h for identical bits

Some defines are the same across all archs. Move the most obvious intersection to termbits-common.h.

---
 arch/alpha/include/uapi/asm/termbits.h     | 52 +----------------
 arch/mips/include/uapi/asm/termbits.h      | 53 +-----------------
 arch/parisc/include/uapi/asm/termbits.h    | 54 +-----------------
 arch/powerpc/include/uapi/asm/termbits.h   | 52 +----------------
 arch/sparc/include/uapi/asm/termbits.h     | 53 +-----------------
 include/uapi/asm-generic/termbits-common.h | 65 ++++++++++++++++++++++
 include/uapi/asm-generic/termbits.h        | 53 +-----------------
 7 files changed, 76 insertions(+), 306 deletions(-)
 create mode 100644 include/uapi/asm-generic/termbits-common.h
arch/alpha/include/uapi/asm/termbits.h +2 -50
index 30dc7ff777b8..3c7a9afc4333 100644
@@ -4,8 +4,8 @@
 
 #include <linux/posix_types.h>
 
-typedef unsigned char	cc_t;
-typedef unsigned int	speed_t;
+#include <asm-generic/termbits-common.h>
+
 typedef unsigned int	tcflag_t;
 
 /*
@@ -72,33 +72,17 @@ struct ktermios {
 #define VTIME 17
 
 /* c_iflag bits */
-#define IGNBRK	0x00001
-#define BRKINT	0x00002
-#define IGNPAR	0x00004
-#define PARMRK	0x00008
-#define INPCK	0x00010
-#define ISTRIP	0x00020
-#define INLCR	0x00040
-#define IGNCR	0x00080
-#define ICRNL	0x00100
 #define IXON	0x00200
 #define IXOFF	0x00400
-#define IXANY	0x00800
 #define IUCLC	0x01000
 #define IMAXBEL	0x02000
 #define IUTF8	0x04000
 
 /* c_oflag bits */
-#define OPOST	0x00001
 #define ONLCR	0x00002
 #define OLCUC	0x00004
 
-#define OCRNL	0x00008
-#define ONOCR	0x00010
-#define ONLRET	0x00020
 
-#define OFILL	0x000040
-#define OFDEL	0x000080
 #define NLDLY	0x000300
 #define   NL0	0x000000
 #define   NL1	0x000100
@@ -131,24 +115,6 @@ struct ktermios {
 
 /* c_cflag bit meaning */
 #define CBAUD		0x0000001f
-#define  B0		0x00000000	/* hang up */
-#define  B50		0x00000001
-#define  B75		0x00000002
-#define  B110		0x00000003
-#define  B134		0x00000004
-#define  B150		0x00000005
-#define  B200		0x00000006
-#define  B300		0x00000007
-#define  B600		0x00000008
-#define  B1200		0x00000009
-#define  B1800		0x0000000a
-#define  B2400		0x0000000b
-#define  B4800		0x0000000c
-#define  B9600		0x0000000d
-#define  B19200		0x0000000e
-#define  B38400		0x0000000f
-#define EXTA B19200
-#define EXTB B38400
 #define CBAUDEX		0x00000000
 #define  B57600		0x00000010
 #define  B115200	0x00000011
@@ -180,11 +146,8 @@ struct ktermios {
 #define HUPCL		0x00004000
 
 #define CLOCAL		0x00008000
-#define CMSPAR		0x40000000	/* mark or space (stick) parity */
-#define CRTSCTS		0x80000000	/* flow control */
 
 #define CIBAUD		0x1f0000
-#define IBSHIFT	16
 
 /* c_lflag bits */
 #define ISIG	0x00000080
@@ -204,17 +167,6 @@ struct ktermios {
 #define IEXTEN	0x00000400
 #define EXTPROC	0x10000000
 
-/* Values for the ACTION argument to `tcflow'.  */
-#define	TCOOFF		0
-#define	TCOON		1
-#define	TCIOFF		2
-#define	TCION		3
-
-/* Values for the QUEUE_SELECTOR argument to `tcflush'.  */
-#define	TCIFLUSH	0
-#define	TCOFLUSH	1
-#define	TCIOFLUSH	2
-
 /* Values for the OPTIONAL_ACTIONS argument to `tcsetattr'.  */
 #define	TCSANOW		0
 #define	TCSADRAIN	1
arch/mips/include/uapi/asm/termbits.h +2 -51

92 lines not on this page · raw message

arch/parisc/include/uapi/asm/termbits.h +2 -52

93 lines not on this page · raw message

arch/powerpc/include/uapi/asm/termbits.h +2 -50

99 lines not on this page · raw message

arch/sparc/include/uapi/asm/termbits.h +1 -52

92 lines not on this page · raw message

include/uapi/asm-generic/termbits-common.h new file +65 -0

65 lines not on this page · raw message

include/uapi/asm-generic/termbits.h +2 -51

92 lines not on this page · raw message

Signature · 1 line
2.30.2
maintainer
#2 lore raw

Re: [PATCH 1/3] termbits.h: create termbits-common.h for identical bits

Hello Ilpo,

Quoted 2 lines · Ilpo Järvinen

Some defines are the same across all archs. Move the most obvious intersection to termbits-common.h.

I like your cleanup patches, but in this specific one, does it makes sense to split up together-belonging constants, e.g.

Quoted 13 lines
arch/parisc/include/uapi/asm/termbits.h +0 -5
index 6017ee08f099..7f74a822b7ea 100644
@@ -61,31 +61,15 @@ struct ktermios {
 
 
 /* c_iflag bits */
-#define IGNBRK	0x00001
-#define BRKINT	0x00002
-#define IGNPAR	0x00004
-#define PARMRK	0x00008
-#define INPCK	0x00010

arch/parisc/include/uapi/asm/termbits.h struct ktermios { · line 68

Quoted 10 lines
arch/parisc/include/uapi/asm/termbits.h +0 -5
-#define ISTRIP	0x00020
-#define INLCR	0x00040
-#define IGNCR	0x00080
-#define ICRNL	0x00100
 #define IUCLC	0x00200
 #define IXON	0x00400
-#define IXANY	0x00800
 #define IXOFF	0x01000
 #define IMAXBEL	0x04000
 #define IUTF8	0x08000

In the hunk above you leave IUCLC, IXON, IXOFF... because they seem unique to parisc. The other defines are then taken from generic header.
Although this is correct, it leaves single values alone, which make it hard to verify because you don't see the full list of values in one place.

Quoted 12 lines
arch/parisc/include/uapi/asm/termbits.h +0 -8
@@ -112,24 +96,6 @@ struct ktermios {
 
 /* c_cflag bit meaning */
 #define CBAUD		0x0000100f
-#define  B0		0x00000000	/* hang up */
-#define  B50		0x00000001
-#define  B75		0x00000002
-#define  B110		0x00000003
-#define  B134		0x00000004
-#define  B150		0x00000005
-#define  B200		0x00000006
-#define  B300		0x00000007

arch/parisc/include/uapi/asm/termbits.h struct ktermios { · line 132

Quoted 10 lines
arch/parisc/include/uapi/asm/termbits.h +0 -10
-#define  B600		0x00000008
-#define  B1200		0x00000009
-#define  B1800		0x0000000a
-#define  B2400		0x0000000b
-#define  B4800		0x0000000c
-#define  B9600		0x0000000d
-#define  B19200		0x0000000e
-#define  B38400		0x0000000f
-#define EXTA B19200
-#define EXTB B38400

Here all baud values are dropped and will be taken from generic header, which is good.

That said, I think it's good to move away the second hunk, but maybe we should keep the first as is?

It's just a thought. Either way, I'm fine your patch if that's the way which is decided to go for all platforms.

Helge

#3 lore raw

Re: [PATCH 1/3] termbits.h: create termbits-common.h for identical bits

Quoted 29 lines · Helge Deller

Hello Ilpo,

Quoted 2 lines · Ilpo Järvinen

Some defines are the same across all archs. Move the most obvious intersection to termbits-common.h.

I like your cleanup patches, but in this specific one, does it makes sense to split up together-belonging constants, e.g.

Quoted 20 lines
arch/parisc/include/uapi/asm/termbits.h +0 -10
index 6017ee08f099..7f74a822b7ea 100644
@@ -61,31 +61,15 @@ struct ktermios {
 
 
 /* c_iflag bits */
-#define IGNBRK	0x00001
-#define BRKINT	0x00002
-#define IGNPAR	0x00004
-#define PARMRK	0x00008
-#define INPCK	0x00010
-#define ISTRIP	0x00020
-#define INLCR	0x00040
-#define IGNCR	0x00080
-#define ICRNL	0x00100
 #define IUCLC	0x00200
 #define IXON	0x00400
-#define IXANY	0x00800
Quoted 8 lines

arch/parisc/include/uapi/asm/termbits.h struct ktermios { · line 68

Quoted 3 lines
arch/parisc/include/uapi/asm/termbits.h +0 -0
 #define IXOFF	0x01000
 #define IMAXBEL	0x04000
 #define IUTF8	0x08000

In the hunk above you leave IUCLC, IXON, IXOFF... because they seem unique to parisc. The other defines are then taken from generic header.
Although this is correct, it leaves single values alone, which make it hard to verify because you don't see the full list of values in one place.

While I too am fine either way, I don't think these are as strongly grouped as you seem to imply. There's no big advantage in having as much as possible within the same file. If somebody is looking for the meaning of these, these headers are no match when compared e.g. with stty manpage.

For c_iflag, the break, parity and cr related "groups" within c_iflag are moving completely to common header.

IXANY is probably only one close to borderline whether it kind of belongs to the same group as IXON/IXOFF (which both by chance both remained on the same side in the split). I don't think it does strongly enough to warrant keeping them next to each other but I'm open what opinions others have on it.

The rest in c_iflag don't seem to be strongly tied/grouped to the other defines within c_iflag. They're just bits that appear next/close to each other but are not tied by any significant meaning-based connection.

C_oflag is more messy. I exercised grouping based judgement with c_oflag where only the defines with all bits as zero would have moved to the common header breaking the groups very badly. That is, only CR0 would have moved and CR1-3 remained in arch headers, etc. which made no sense to do. One could argue, that since ONLCR (and perhaps CRDLY) are not moving, no other cr related defines should move either.

Quoted 26 lines
Quoted 12 lines
arch/parisc/include/uapi/asm/termbits.h +0 -8
@@ -112,24 +96,6 @@ struct ktermios {
 
 /* c_cflag bit meaning */
 #define CBAUD		0x0000100f
-#define  B0		0x00000000	/* hang up */
-#define  B50		0x00000001
-#define  B75		0x00000002
-#define  B110		0x00000003
-#define  B134		0x00000004
-#define  B150		0x00000005
-#define  B200		0x00000006
-#define  B300		0x00000007

arch/parisc/include/uapi/asm/termbits.h struct ktermios { · line 132

Quoted 10 lines
arch/parisc/include/uapi/asm/termbits.h +0 -10
-#define  B600		0x00000008
-#define  B1200		0x00000009
-#define  B1800		0x0000000a
-#define  B2400		0x0000000b
-#define  B4800		0x0000000c
-#define  B9600		0x0000000d
-#define  B19200		0x0000000e
-#define  B38400		0x0000000f
-#define EXTA B19200
-#define EXTB B38400

Here all baud values are dropped and will be taken from generic header, which is good.

Quoted 5 lines

That said, I think it's good to move away the second hunk, but maybe we should keep the first as is?

It's just a thought. Either way, I'm fine your patch if that's the way which is decided to go for all platforms.

Yes, lets wait and see what the others think.

Thanks for taking a look!

Signature · 1 line
 i.
#4 lore raw

PATCH 2/3 termbits.h: Align lines & format

In reply to Ilpo Järvinen

- Align c_cc defines.
- Remove extra newlines.
- Realign & adjust number of leading zeros.
- Reorder c_cflag defines to ascending order
- Make comment ending shorted (=remove period and one extra space from the comments in mips).

---
 arch/alpha/include/uapi/asm/termbits.h   | 130 +++++++++---------
 arch/mips/include/uapi/asm/termbits.h    | 156 ++++++++++-----------
 arch/parisc/include/uapi/asm/termbits.h  |  77 +++++------
 arch/powerpc/include/uapi/asm/termbits.h | 100 +++++++-------
 arch/sparc/include/uapi/asm/termbits.h   | 168 +++++++++++------------
 include/uapi/asm-generic/termbits.h      |  76 +++++-----
 6 files changed, 346 insertions(+), 361 deletions(-)
arch/alpha/include/uapi/asm/termbits.h +62 -68
index 3c7a9afc4333..735e9ffe2795 100644
@@ -53,60 +53,58 @@ struct ktermios {
 };
 
 /* c_cc characters */
-#define VEOF 0
-#define VEOL 1
-#define VEOL2 2
-#define VERASE 3
-#define VWERASE 4
-#define VKILL 5
-#define VREPRINT 6
-#define VSWTC 7
-#define VINTR 8
-#define VQUIT 9
-#define VSUSP 10
-#define VSTART 12
-#define VSTOP 13
-#define VLNEXT 14
-#define VDISCARD 15
-#define VMIN 16
-#define VTIME 17
+#define VEOF		 0
+#define VEOL		 1
+#define VEOL2		 2
+#define VERASE		 3
+#define VWERASE		 4
+#define VKILL		 5
+#define VREPRINT	 6
+#define VSWTC		 7
+#define VINTR		 8
+#define VQUIT		 9
+#define VSUSP		10
+#define VSTART		12
+#define VSTOP		13
+#define VLNEXT		14
+#define VDISCARD	15
+#define VMIN		16
+#define VTIME		17
 
 /* c_iflag bits */
-#define IXON	0x00200
-#define IXOFF	0x00400
-#define IUCLC	0x01000
-#define IMAXBEL	0x02000
-#define IUTF8	0x04000
+#define IXON	0x0200
+#define IXOFF	0x0400
+#define IUCLC	0x1000
+#define IMAXBEL	0x2000
+#define IUTF8	0x4000
 
 /* c_oflag bits */
 #define ONLCR	0x00002
 #define OLCUC	0x00004
-
-
-#define NLDLY	0x000300
-#define   NL0	0x000000
-#define   NL1	0x000100
-#define   NL2	0x000200
-#define   NL3	0x000300
-#define TABDLY	0x000c00
-#define   TAB0	0x000000
-#define   TAB1	0x000400
-#define   TAB2	0x000800
-#define   TAB3	0x000c00
-#define CRDLY	0x003000
-#define   CR0	0x000000
-#define   CR1	0x001000
-#define   CR2	0x002000
-#define   CR3	0x003000
-#define FFDLY	0x004000
-#define   FF0	0x000000
-#define   FF1	0x004000
-#define BSDLY	0x008000
-#define   BS0	0x000000
-#define   BS1	0x008000
-#define VTDLY	0x010000
-#define   VT0	0x000000
-#define   VT1	0x010000
+#define NLDLY	0x00300
+#define   NL0	0x00000
+#define   NL1	0x00100
+#define   NL2	0x00200
+#define   NL3	0x00300
+#define TABDLY	0x00c00
+#define   TAB0	0x00000
+#define   TAB1	0x00400
+#define   TAB2	0x00800
+#define   TAB3	0x00c00
+#define CRDLY	0x03000
+#define   CR0	0x00000
+#define   CR1	0x01000
+#define   CR2	0x02000
+#define   CR3	0x03000
+#define FFDLY	0x04000
+#define   FF0	0x00000
+#define   FF1	0x04000
+#define BSDLY	0x08000
+#define   BS0	0x00000
+#define   BS1	0x08000
+#define VTDLY	0x10000
+#define   VT0	0x00000
+#define   VT1	0x10000
 /*
  * Should be equivalent to TAB3, see description of TAB3 in
  * POSIX.1-2008, Ch. 11.2.3 "Output Modes"
@@ -116,38 +114,34 @@ struct ktermios {
 /* c_cflag bit meaning */
 #define CBAUD		0x0000001f
 #define CBAUDEX		0x00000000
-#define  B57600		0x00000010
-#define  B115200	0x00000011
-#define  B230400	0x00000012
-#define  B460800	0x00000013
-#define  B500000	0x00000014
-#define  B576000	0x00000015
-#define  B921600	0x00000016
-#define B1000000	0x00000017
-#define B1152000	0x00000018
-#define B1500000	0x00000019
-#define B2000000	0x0000001a
-#define B2500000	0x0000001b
-#define B3000000	0x0000001c
-#define B3500000	0x0000001d
-#define B4000000	0x0000001e
 #define BOTHER		0x0000001f
-
+#define     B57600	0x00000010
+#define    B115200	0x00000011
+#define    B230400	0x00000012
+#define    B460800	0x00000013
+#define    B500000	0x00000014
+#define    B576000	0x00000015
+#define    B921600	0x00000016
+#define   B1000000	0x00000017
+#define   B1152000	0x00000018
+#define   B1500000	0x00000019
+#define   B2000000	0x0000001a
+#define   B2500000	0x0000001b
+#define   B3000000	0x0000001c
+#define   B3500000	0x0000001d
+#define   B4000000	0x0000001e
 #define CSIZE		0x00000300
 #define   CS5		0x00000000
 #define   CS6		0x00000100
 #define   CS7		0x00000200
 #define   CS8		0x00000300
-
 #define CSTOPB		0x00000400
 #define CREAD		0x00000800
 #define PARENB		0x00001000
 #define PARODD		0x00002000
 #define HUPCL		0x00004000
-
 #define CLOCAL		0x00008000
-
-#define CIBAUD		0x1f0000
+#define CIBAUD		0x001f0000
 
 /* c_lflag bits */
 #define ISIG	0x00000080
arch/mips/include/uapi/asm/termbits.h +78 -78

207 lines not on this page · raw message

arch/parisc/include/uapi/asm/termbits.h +38 -39

91 lines not on this page · raw message

arch/powerpc/include/uapi/asm/termbits.h +47 -53

125 lines not on this page · raw message

arch/sparc/include/uapi/asm/termbits.h +83 -85

211 lines not on this page · raw message

include/uapi/asm-generic/termbits.h +38 -38

90 lines not on this page · raw message

Signature · 1 line
2.30.2
#5 lore raw

PATCH 3/3 termbits.h: Remove posix_types.h include

In reply to Ilpo Järvinen

Nothing in termbits seems to require anything from linux/posix_types.h.

---
 arch/alpha/include/uapi/asm/termbits.h  | 2 --
 arch/mips/include/uapi/asm/termbits.h   | 2 --
 arch/parisc/include/uapi/asm/termbits.h | 2 --
 arch/sparc/include/uapi/asm/termbits.h  | 2 --
 include/uapi/asm-generic/termbits.h     | 2 --
 5 files changed, 10 deletions(-)
arch/alpha/include/uapi/asm/termbits.h +0 -2
index 735e9ffe2795..f1290b22072b 100644
@@ -2,8 +2,6 @@
 #ifndef _ALPHA_TERMBITS_H
 #define _ALPHA_TERMBITS_H
 
-#include <linux/posix_types.h>
-
 #include <asm-generic/termbits-common.h>
 
 typedef unsigned int	tcflag_t;
arch/mips/include/uapi/asm/termbits.h +0 -2
index 8fa3e79d4f94..1eb60903d6f0 100644
@@ -11,8 +11,6 @@
 #ifndef _ASM_TERMBITS_H
 #define _ASM_TERMBITS_H
 
-#include <linux/posix_types.h>
-
 #include <asm-generic/termbits-common.h>
 
 typedef unsigned int	tcflag_t;
arch/parisc/include/uapi/asm/termbits.h +0 -2
index d72c5ebf3a3a..3a8938d26fb4 100644
@@ -2,8 +2,6 @@
 #ifndef __ARCH_PARISC_TERMBITS_H__
 #define __ARCH_PARISC_TERMBITS_H__
 
-#include <linux/posix_types.h>
-
 #include <asm-generic/termbits-common.h>
 
 typedef unsigned int	tcflag_t;
arch/sparc/include/uapi/asm/termbits.h +0 -2
index cfcc4e07ce51..4321322701fc 100644
@@ -2,8 +2,6 @@
 #ifndef _UAPI_SPARC_TERMBITS_H
 #define _UAPI_SPARC_TERMBITS_H
 
-#include <linux/posix_types.h>
-
 #include <asm-generic/termbits-common.h>
 
 #if defined(__sparc__) && defined(__arch64__)
include/uapi/asm-generic/termbits.h +0 -2
index c92179563289..890ef29053e2 100644
@@ -2,8 +2,6 @@
 #ifndef __ASM_GENERIC_TERMBITS_H
 #define __ASM_GENERIC_TERMBITS_H
 
-#include <linux/posix_types.h>
-
 #include <asm-generic/termbits-common.h>
 
 typedef unsigned int	tcflag_t;
Signature · 1 line
2.30.2