haiku/headers
PulkoMandy a38c3c0384 serial/tty: fix handling of custom baudrates
Fixes the code I introduced in hrev50114 for custom serial port
baudrates. The idea there was based on FreeBSD implementation, but I
missed a key detail: speed_t in BeOS (and Haiku) is only an 8 bit value.
Note that BeOS does not have c_ispeed and c_ospeed fields, instead they
are named c_ixxxxx and c_oxxxxx with a comment in termios.h saying that
they are not used. So the renaming and moving of these fields isn't a problem.

This means the previous code worked only for speed between 20 and 255
baud, quite the opposite of what I wanted to do, which is to enable
access to fast baudrates.

This new implementation exploits the fact that tcflag_t is 32 bit, but
we never actually use more than 16 bits. Therefore, the high bits of
each value were unused, and can be reclaimed to store the speed,
by changing tcflag_t to 16 bits. The speed is then inserted as two 16
bit values that can be combined as a 32 bit one. The flag bits are not
moved (on little endian systems), and the extra values are guaranteed to
be set to 0 by any previous code that was compiled with 32 bit tcflag_t.

Support for different speeds for input and output is now also possible
(POSIX specifies separate functions for setting the input and output
speeds, which is useful for some old terminals and modems, where it was
useful to have a high baudrate for data to display on the screen, but
things typed on the keyboard aren't quite as fast). If desired, we could
now properly implement this in our serial drivers, but it isn't done
here yet.

Additional changes:
- speed_t is now a 32bit type, allowing to pass large values to
  cfset(i,o)speed
- fix some places where a baudrate enum value was incorrectly put in the
  c_ispeed and c_ospeed fields, this is not how they were meant to be
  used (it meant the default was to use a speed of 0, that means "hangup"
  the line, which I think no serial driver really implemented).
- do not put baudrate enumeration values in c_iflag and c_oflag, they
  are meant to be used in c_cflag only, and conflict with other bits.
  Separate speeds for input and output can be done by setting the
  c_cflag value to CBAUD (indicating custom baudrates) and then setting
  the values in c_ispeed and c_ospeed.

Fixes #18483

Change-Id: If63a24b5ced5edf6d051d921197db194def0c614
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7068
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk>
2024-12-14 12:29:05 +00:00
..
build kernel/util: Introduce BumpAllocator. 2024-09-06 19:15:42 +00:00
compatibility libroot: move memmem for POSIX.1/2024 2024-11-04 17:55:40 +00:00
config HaikuConfig: Don't define __HAIKU_BEOS_COMPATIBLE_TYPES in kernel mode. 2024-09-24 12:10:35 -04:00
cpp userlandfs: use std::bitset for FSCapabilities 2023-07-10 06:27:18 +00:00
glibc Make public glibc header printf.h usable. 2013-07-17 18:07:56 +02:00
libs udis86: remove 2024-07-17 19:11:50 +00:00
os input: Adjust input_pointing_device_subtype enumeration and usages. 2024-12-11 19:11:45 +00:00
posix serial/tty: fix handling of custom baudrates 2024-12-14 12:29:05 +00:00
private kernel/listeners: Use an rw_spinlock for the gWaitObjectListenerLock. 2024-12-13 17:17:43 -05:00
tools cppunit: Enable CPPUNIT_HAVE_SSTREAM for the non-legacy GCC. 2022-03-29 19:09:38 -04:00