|
PatchworkOS
2ca1c69
A non-POSIX operating system.
|
I/O port operations and reservations. More...
I/O port operations and reservations.
The CPU can communicate with certain hardware through I/O ports, these ports are accessed using special opcodes.
To avoid conflicts between different subsystems or drivers trying to use the same I/O ports, we provide a simple reservation mechanism. Before a range of I/O ports is used, it should be reserved using io_reserve(). Once the ports are no longer needed, they should be released using io_release().
There is no strict enforcement of I/O port reservations at the hardware level, so we have no choice but to hope that everyone is on their best behaviour.
Macros | |
| #define | IO_PORT_MAX UINT16_MAX |
| Maximum I/O port number. | |
Typedefs | |
| typedef uint16_t | port_t |
| I/O port type. | |
Functions | |
| uint64_t | io_reserve (port_t *out, port_t minBase, port_t maxBase, uint64_t alignment, uint64_t length, const char *owner) |
| Find and reserve a range of I/O ports if available. | |
| void | io_release (port_t base, uint64_t length) |
| Release a previously reserved range of I/O ports. | |
| static void | io_out8 (port_t port, uint8_t val) |
| Write an 8-bit value to an I/O port. | |
| static uint8_t | io_in8 (port_t port) |
| Read an 8-bit value from an I/O port. | |
| static void | io_out16 (port_t port, uint16_t val) |
| Write a 16-bit value to an I/O port. | |
| static uint16_t | io_in16 (port_t port) |
| Read a 16-bit value from an I/O port. | |
| static uint32_t | io_in32 (port_t port) |
| Write a 32-bit value to an I/O port. | |
| static void | io_out32 (port_t port, uint32_t val) |
| Read a 32-bit value from an I/O port. | |
| #define IO_PORT_MAX UINT16_MAX |
| uint64_t io_reserve | ( | port_t * | out, |
| port_t | minBase, | ||
| port_t | maxBase, | ||
| uint64_t | alignment, | ||
| uint64_t | length, | ||
| const char * | owner | ||
| ) |
Find and reserve a range of I/O ports if available.
minBase and maxBase do NOT specify the exact range to reserve, but rather the minimum and maximum values for the starting port of the range to reserve. For example, the minimum range would be [minBase, minBase + length) and the maximum range would be [maxBase, maxBase + length).| out | Output pointer for the first reserved port. |
| minBase | The minimum base I/O port address. |
| maxBase | The maximum base I/O port address. |
| alignment | The alignment of the I/O ports to reserve. |
| length | The amount of contiguous I/O ports to reserve. |
| owner | A string identifying the owner of the reservation, for debugging purposes, can be NULL. |
0. On failure, ERR and errno is set to:EINVAL: Invalid parameters.EOVERFLOW: The requested range overflows.ENOSPC: No suitable range of I/O ports available. Definition at line 15 of file io.c.