AquilaOS documentation
How it works, and its code
Toggle main menu visibility
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
15
static
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
28
static
inline
uint8_t
io_in8
(
struct
ioaddr
*io,
uintptr_t
off)
29
{
30
return
*(
volatile
uint8_t
*)
io_reg
(io, off);
31
}
32
33
static
inline
uint16_t
io_in16
(
struct
ioaddr
*io,
uintptr_t
off)
34
{
35
return
*(
volatile
uint16_t
*)
io_reg
(io, off);
36
}
37
38
static
inline
uint32_t
io_in32
(
struct
ioaddr
*io,
uintptr_t
off)
39
{
40
return
*(
volatile
uint32_t
*)
io_reg
(io, off);
41
}
42
44
static
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
49
static
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
54
static
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
60
static
inline
uint32_t
mmio_read32
(
uintptr_t
addr)
61
{
62
return
*(
volatile
uint32_t
*) addr;
63
}
64
65
static
inline
void
mmio_write32
(
uintptr_t
addr,
uint32_t
val)
66
{
67
*(
volatile
uint32_t
*) addr = val;
68
}
69
70
#endif
/* ! _AARCH64_IO_H */
mmio_read32
static uint32_t mmio_read32(uintptr_t addr)
Reads, or writes, a 32-bit register at a kernel address.
Definition
io.h:60
io_reg
static uintptr_t io_reg(struct ioaddr *io, uintptr_t off)
Returns the kernel address of register off.
Definition
io.h:15
io_out16
static void io_out16(struct ioaddr *io, uintptr_t off, uint16_t val)
Definition
io.h:49
io_in32
static uint32_t io_in32(struct ioaddr *io, uintptr_t off)
Definition
io.h:38
io_in16
static uint16_t io_in16(struct ioaddr *io, uintptr_t off)
Definition
io.h:33
io_out32
static void io_out32(struct ioaddr *io, uintptr_t off, uint32_t val)
Definition
io.h:54
io_in8
static uint8_t io_in8(struct ioaddr *io, uintptr_t off)
Reads an 8-, 16- or 32-bit register.
Definition
io.h:28
io_out8
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
mmio_write32
static void mmio_write32(uintptr_t addr, uint32_t val)
Definition
io.h:65
IOADDR_MMIO16
#define IOADDR_MMIO16
Definition
io.h:91
IOADDR_MMIO32
#define IOADDR_MMIO32
Definition
io.h:92
uintptr_t
__SIZE_TYPE__ uintptr_t
Definition
stddef.h:12
uint32_t
unsigned int uint32_t
Definition
stddef.h:22
uint8_t
unsigned char uint8_t
Definition
stddef.h:20
uint16_t
unsigned short int uint16_t
Definition
stddef.h:21
ioaddr
Where a device's registers are.
Definition
io.h:95
ioaddr::addr
uintptr_t addr
Definition
io.h:97
ioaddr::type
char type
Definition
io.h:96
kernel
arch
aarch64
include
cpu
io.h
Generated by
1.18.0