-
Notifications
You must be signed in to change notification settings - Fork 0
Drivers
David de Rosier edited this page Jan 31, 2025
·
5 revisions
| Category | Device | Status | Ticket |
|---|---|---|---|
| filesystem | TARFS | read-only | 54 |
| PLIC | generic PLIC | max 31 IRQs | |
| RTC | Goldfish | no alarms, read-only | 8 |
| UART | NS16550A | no output IRQ | 18 |
| UART | SiFive | no IRQs |
By convention each driver is represented as at least 8-byte structure, where initial 4 bytes act as driver's ID (but actually it's a base address), and the second 4-bytes is a pointer to a config function.
Below there is an example of 16-byte structure representing UART device:
struct hal_uart {
u32 base_addr;
u32 (*config)(u32 base_addr, u32 mask, u32 flags);
u32 (*putc)(u32 base_addr, char c);
byte (*getc)(u32 base_addr);
}Getting ad setting device's configuration is achieved by a function of the following signatur:
u32 config(u32 base_addr, u32 mask, u32 config);The config flags can be specific per device, but by convention bit 0 should indicate
whether the device is enabled (1) or disabled (0). The above allows common interface for
handling any device config. I.e. system function #6 (SYSFN_GET_DEV_CFG) returns a configuration
of any device passed to it as a parameter, i.e.
li a0, DEV_UART_0 # const representing device ID in device manager
call device_get # function returns device's structure address
lw a0, (a0) # load first word from the structure (base_addr)
li a5, SYSFN_GET_DEV_CFG # system function #6
ecall # execute system function and fetch the config