AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
8250.c File Reference

The driver for the 8250 UART and its successors, such as the 16550 with its FIFOs: the PC's serial ports, /dev/ttyS0 and up. More...

#include <core/system.h>
#include <core/module.h>
#include <dev/tty.h>
#include <dev/uart.h>
#include <dev/irq.h>
#include <dev/platform.h>
#include <cpu/io.h>
#include <mm/mm.h>

Go to the source code of this file.

Data Structures

struct  uart_8250
 One UART: the terminal layer's struct uart (first, so that a pointer to one is a pointer to the other), and its registers. More...

Macros

#define UART_IER   1
#define UART_FCR   2
#define UART_LCR   3
#define UART_MCR   4
#define UART_LSR   5
#define UART_SCR   7
#define UART_DLL   0
#define UART_DLH   1
#define UART_LCR_DLAB   0x80
#define UART_8250_MAX   4
#define IO(u)

Functions

static int serial_empty (struct ioaddr *io)
 Returns whether the transmitter can take a character.
static int serial_received (struct ioaddr *io)
 Returns whether a received character is waiting.
static char uart_8250_receive (struct uart *u)
 Takes one received character.
static ssize_t uart_8250_transmit (struct uart *u, char c)
 Sends one character, once the transmitter can take it.
static void uart_8250_irq (void *arg)
 Handles a UART's interrupt: every received character goes to the terminal, or is dropped if no one has opened it.
static void uart_8250_comm_init (struct uart *u)
 Sets a UART up when it is first opened: 38400 baud, 8 bits, no parity, one stop bit, the FIFOs, and the receive interrupt.
static int uart_8250_present (struct ioaddr *io)
 Returns whether a UART is really there: its scratch register keeps what is written to it, where no device would read back all ones.
static int uart_8250_attach (const struct platform_device *pd, int id)
 Attaches to one of the platform's 8250s, if it is there, as /dev/ttyS<id>.
static int uart_8250_init (void)
 Attaches to the platform's 8250s that are there, as /dev/ttyS0 and up, in the platform's order.

Detailed Description

The driver for the 8250 UART and its successors, such as the 16550 with its FIFOs: the PC's serial ports, /dev/ttyS0 and up.

The driver attaches to each 8250 the platform lists (dev/platform.h) that is really there, in the platform's order. Output is written one character at a time, waiting until the transmitter is empty. Input comes with the UART's interrupt, which drains the receive FIFO into the terminal. The registers may be ports or memory (struct ioaddr).

Definition in file 8250.c.

Macro Definition Documentation

◆ IO

#define IO ( u)
Value:
(&((struct uart_8250 *) (u))->io)
One UART: the terminal layer's struct uart (first, so that a pointer to one is a pointer to the other...
Definition 8250.c:38

Definition at line 44 of file 8250.c.

Referenced by uart_8250_comm_init(), uart_8250_irq(), uart_8250_receive(), and uart_8250_transmit().

◆ UART_8250_MAX

#define UART_8250_MAX   4

Definition at line 34 of file 8250.c.

Referenced by uart_8250_init().

◆ UART_DLH

#define UART_DLH   1

Definition at line 31 of file 8250.c.

◆ UART_DLL

#define UART_DLL   0

Definition at line 30 of file 8250.c.

◆ UART_FCR

#define UART_FCR   2

Definition at line 25 of file 8250.c.

◆ UART_IER

#define UART_IER   1

Definition at line 24 of file 8250.c.

◆ UART_LCR

#define UART_LCR   3

Definition at line 26 of file 8250.c.

◆ UART_LCR_DLAB

#define UART_LCR_DLAB   0x80

Definition at line 32 of file 8250.c.

◆ UART_LSR

#define UART_LSR   5

Definition at line 28 of file 8250.c.

Referenced by serial_empty(), and serial_received().

◆ UART_MCR

#define UART_MCR   4

Definition at line 27 of file 8250.c.

◆ UART_SCR

#define UART_SCR   7

Definition at line 29 of file 8250.c.

Referenced by uart_8250_present().

Function Documentation

◆ serial_empty()

int serial_empty ( struct ioaddr * io)
static

Returns whether the transmitter can take a character.

Definition at line 47 of file 8250.c.

References io_in8(), serial_empty(), and UART_LSR.

Referenced by serial_empty(), uart_8250_comm_init(), uart_8250_irq(), and uart_8250_transmit().

◆ serial_received()

int serial_received ( struct ioaddr * io)
static

Returns whether a received character is waiting.

Definition at line 53 of file 8250.c.

References io_in8(), serial_received(), and UART_LSR.

Referenced by serial_received(), and uart_8250_irq().

◆ uart_8250_attach()

int uart_8250_attach ( const struct platform_device * pd,
int id )
static

◆ uart_8250_comm_init()

void uart_8250_comm_init ( struct uart * u)
static

Sets a UART up when it is first opened: 38400 baud, 8 bits, no parity, one stop bit, the FIFOs, and the receive interrupt.

Definition at line 99 of file 8250.c.

References IO, io_in8(), io_out8(), serial_empty(), uart_8250_comm_init(), UART_DLH, UART_DLL, UART_FCR, UART_IER, UART_LCR, UART_LCR_DLAB, and UART_MCR.

Referenced by uart_8250_attach(), and uart_8250_comm_init().

◆ uart_8250_init()

int uart_8250_init ( void )
static

Attaches to the platform's 8250s that are there, as /dev/ttyS0 and up, in the platform's order.

Definition at line 175 of file 8250.c.

References platform_device_get(), uart_8250_attach(), uart_8250_init(), and UART_8250_MAX.

Referenced by uart_8250_init().

◆ uart_8250_irq()

void uart_8250_irq ( void * arg)
static

Handles a UART's interrupt: every received character goes to the terminal, or is dropped if no one has opened it.

Definition at line 77 of file 8250.c.

References IO, serial_empty(), serial_received(), uart::tty, uart_8250_irq(), uart_8250_receive(), uart_receive_handler(), and uart_transmit_handler().

Referenced by uart_8250_attach(), and uart_8250_irq().

◆ uart_8250_present()

int uart_8250_present ( struct ioaddr * io)
static

Returns whether a UART is really there: its scratch register keeps what is written to it, where no device would read back all ones.

Definition at line 126 of file 8250.c.

References io_in8(), io_out8(), uart_8250_present(), and UART_SCR.

Referenced by uart_8250_attach(), and uart_8250_present().

◆ uart_8250_receive()

char uart_8250_receive ( struct uart * u)
static

Takes one received character.

Definition at line 59 of file 8250.c.

References IO, io_in8(), and uart_8250_receive().

Referenced by uart_8250_attach(), uart_8250_irq(), and uart_8250_receive().

◆ uart_8250_transmit()

ssize_t uart_8250_transmit ( struct uart * u,
char c )
static

Sends one character, once the transmitter can take it.

Definition at line 65 of file 8250.c.

References IO, io_out8(), serial_empty(), and uart_8250_transmit().

Referenced by uart_8250_attach(), and uart_8250_transmit().