41 size_t n =
MIN(size,
sizeof(buf));
43 for (
size_t i = 0; i < n; ++i)
61 size_t len = ringbuf_available(u->
out);
64 for (
size_t i = 0; i < len; ++i) {
66 ringbuf_read(u->
out, 1, &c);
85 size_t s = ringbuf_write(u->
out, size, buf);
96 while (ringbuf_read(u->
in, 1, &c))
112 return ringbuf_write(u->
in, size, buf);
122#ifndef CONFIG_DEV_CONSOLE
128 if (minor < 64 || minor - 64 >=
UART_MAX)
151 return ringbuf_read_iobuf(u->
in, io->
resid, io);
168 if (u->
tty->
tios.c_lflag & TOSTOP) {
284 for (
int i = 0; i < 192; ++i) {
298 printk(
"uart: registered uart %d: %s\n",
id, u->
name);
316 .can_write = __vfs_can_always,
static int uart_file_eof(struct file *file)
Returns whether a read that found no data is at the end of the file (the terminal says,...
int uart_file_open(struct file *file)
Opens a UART's device, setting the UART up the first time.
ssize_t uart_slave_write(struct tty *tty, size_t size, void *buf)
Takes the terminal's input, after its line editing, for the readers of the UART's device.
ssize_t uart_master_write(struct tty *tty, size_t size, void *buf)
Takes the terminal's output, and sends it to the UART at once: the UART drivers don't use a "transmit...
void uart_transmit_handler(struct uart *u, size_t size)
Sends characters that the terminal output to its UART.
static void uart_input_flush(struct tty *tty)
Drops the input waiting to be read (tcflush()).
static int uart_setup(struct uart *u, struct vnode *vnode)
Sets a UART up the first time it is opened: its rings, its terminal, and the UART itself.
ssize_t uart_read(struct devid *dd, off_t offset, struct iobuf *io)
Reads a UART's terminal.
static uint64_t uart_read_timeout(struct file *file)
Returns how long a read may wait for data, from the terminal's mode (VTIME), or 0 for no limit.
static struct uart * devices[192]
static int uart_can_read(struct file *file, size_t size)
Returns whether a read wouldn't have to wait.
static struct uart * uart_get(devid_t minor)
Returns the UART of a minor (they start at 64), or NULL if there's none.
int uart_register(int id, struct uart *u)
Registers a UART, as /dev/ttyS<id>.
int uart_ioctl(struct devid *dd, int request, void *argp)
Handles a UART terminal's ioctl()s, which are the terminal's.
void uart_receive_handler(struct uart *u, size_t size)
Takes characters a UART received, and gives them to its terminal.
ssize_t uart_write(struct devid *dd, off_t offset, struct iobuf *io)
Writes to a UART's terminal.
ssize_t tty_slave_write(struct tty *tty, size_t size, void *_buf)
Takes what programs write to the terminal, and sends it to the device through output processing (OPOS...
int tty_ioctl(struct tty *tty, int request, void *argp)
Handles a terminal's ioctl()s: its modes (TCGETS, TCSETS, ...), flushing, its session and foreground ...
ssize_t tty_write_iobuf(struct tty *tty, struct iobuf *io, ttyio write)
Writes to a terminal from an iobuf (user memory), to either side: a piece at a time through a kernel ...
int tty_new(struct proc *proc, size_t buf_size, ttyio master, ttyio slave, void *p, struct tty **ref)
Makes a new terminal, with the default modes (canonical, echo, signals, ICRNL, IXON,...
ssize_t tty_master_write(struct tty *tty, size_t size, void *buf)
Takes input from the terminal's device (the keyboard, a UART, or a pseudo-terminal's master),...
int tty_can_read(struct tty *tty, size_t buffered)
Says whether the terminal is readable, for select() and poll(): there is input, or an end-of-file.
int tty_eof(struct tty *tty)
Says whether a read that found nothing to return should return 0 at once: at an end-of-file (VEOF at ...
int tty_background(struct tty *tty, int sig)
Stops a background process that reads the terminal, writes it or changes it: if the current process i...
uint64_t tty_read_timeout(struct tty *tty)
Says how long a read waits for input: VTIME tenths of a second with VMIN 0 in non-canonical mode,...
void tty_open(struct tty *tty, struct file *file)
Handles a terminal device being opened: it becomes the controlling terminal of a session leader that ...
int posix_file_ioctl(struct file *file, int request, void *argp)
Passes an ioctl() request on to the file's vnode (a device's, or its filesystem's).
ssize_t posix_file_read(struct file *file, struct iobuf *io)
Reads from an open file at its offset, and moves the offset past what was read.
ssize_t posix_file_write(struct file *file, struct iobuf *io)
Writes to an open file at its offset, and moves the offset past what was written.
int printk(const char *fmt,...)
Writes a kernel message, to the message buffer and the consoles.
unsigned long long int uint64_t
A device driver: its operations, any of which may be NULL.
Which device: its kind (S_IFCHR or S_IFBLK) and numbers.
An open file (POSIX's "open file description", fs/file.c).
A terminal, and its line discipline's state.
void * p
the device's own data
struct vnode * vnode
the device's vnode, which /dev/tty opens in its place
void(*) input_flush(struct tty *tty)
discards the input that readers haven't read yet
ssize_t(*) transmit(struct uart *u, char c)
void(*) init(struct uart *u)
char(*) receive(struct uart *u)
A file in memory (a vnode): what its inode says, and the kernel's own state.
size_t ref
how many references there are to it
void waitq_wakeup(struct waitq *waitq)
Wakes up every thread sleeping on a wait queue, and every thread polling it.