AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
io.h
Go to the documentation of this file.
1#ifndef _AARCH64_IO_H
2#define _AARCH64_IO_H
3
4#include_next <cpu/io.h>
5
6/*
7 * Reading and writing devices' registers. On aarch64 they are only ever
8 * memory-mapped (there are no I/O ports): register `off` is at
9 * `io->addr` (a kernel address, from arch_mmio_map()) plus `off`
10 * registers, which are a byte apart (IOADDR_MMIO8), two bytes
11 * (IOADDR_MMIO16), or four (IOADDR_MMIO32).
12 */
13
15static inline uintptr_t io_reg(struct ioaddr *io, uintptr_t off)
16{
17 switch (io->type) {
18 case IOADDR_MMIO16:
19 return io->addr + (off << 1);
20 case IOADDR_MMIO32:
21 return io->addr + (off << 2);
22 }
23
24 return io->addr + off;
25}
26
28static inline uint8_t io_in8(struct ioaddr *io, uintptr_t off)
29{
30 return *(volatile uint8_t *) io_reg(io, off);
31}
32
33static inline uint16_t io_in16(struct ioaddr *io, uintptr_t off)
34{
35 return *(volatile uint16_t *) io_reg(io, off);
36}
37
38static inline uint32_t io_in32(struct ioaddr *io, uintptr_t off)
39{
40 return *(volatile uint32_t *) io_reg(io, off);
41}
42
44static inline void io_out8(struct ioaddr *io, uintptr_t off, uint8_t val)
45{
46 *(volatile uint8_t *) io_reg(io, off) = val;
47}
48
49static inline void io_out16(struct ioaddr *io, uintptr_t off, uint16_t val)
50{
51 *(volatile uint16_t *) io_reg(io, off) = val;
52}
53
54static inline void io_out32(struct ioaddr *io, uintptr_t off, uint32_t val)
55{
56 *(volatile uint32_t *) io_reg(io, off) = val;
57}
58
60static inline uint32_t mmio_read32(uintptr_t addr)
61{
62 return *(volatile uint32_t *) addr;
63}
64
65static inline void mmio_write32(uintptr_t addr, uint32_t val)
66{
67 *(volatile uint32_t *) addr = val;
68}
69
70#endif /* ! _AARCH64_IO_H */
static uint32_t mmio_read32(uintptr_t addr)
Reads, or writes, a 32-bit register at a kernel address.
Definition io.h:60
static uintptr_t io_reg(struct ioaddr *io, uintptr_t off)
Returns the kernel address of register off.
Definition io.h:15
static void io_out16(struct ioaddr *io, uintptr_t off, uint16_t val)
Definition io.h:49
static uint32_t io_in32(struct ioaddr *io, uintptr_t off)
Definition io.h:38
static uint16_t io_in16(struct ioaddr *io, uintptr_t off)
Definition io.h:33
static void io_out32(struct ioaddr *io, uintptr_t off, uint32_t val)
Definition io.h:54
static uint8_t io_in8(struct ioaddr *io, uintptr_t off)
Reads an 8-, 16- or 32-bit register.
Definition io.h:28
static void io_out8(struct ioaddr *io, uintptr_t off, uint8_t val)
Writes an 8-, 16- or 32-bit register.
Definition io.h:44
static void mmio_write32(uintptr_t addr, uint32_t val)
Definition io.h:65
#define IOADDR_MMIO16
Definition io.h:91
#define IOADDR_MMIO32
Definition io.h:92
__SIZE_TYPE__ uintptr_t
Definition stddef.h:12
unsigned int uint32_t
Definition stddef.h:22
unsigned char uint8_t
Definition stddef.h:20
unsigned short int uint16_t
Definition stddef.h:21
Where a device's registers are.
Definition io.h:95
uintptr_t addr
Definition io.h:97
char type
Definition io.h:96