PatchworkOS  2ca1c69
A non-POSIX operating system.
Loading...
Searching...
No Matches
Port I/O

I/O port operations and reservations. More...

Collaboration diagram for Port I/O:

Detailed Description

I/O port operations and reservations.

The CPU can communicate with certain hardware through I/O ports, these ports are accessed using special opcodes.

Reserving I/O Ports

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.
 

Macro Definition Documentation

◆ IO_PORT_MAX

#define IO_PORT_MAX   UINT16_MAX

Maximum I/O port number.

Definition at line 32 of file io.h.

Typedef Documentation

◆ port_t

typedef uint16_t port_t

I/O port type.

Definition at line 27 of file io.h.

Function Documentation

◆ io_reserve()

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.

Note
The 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).
Todo:
Find a way to store the owner of each reservation that does not use way to much memory, and isent super slow.
Parameters
outOutput pointer for the first reserved port.
minBaseThe minimum base I/O port address.
maxBaseThe maximum base I/O port address.
alignmentThe alignment of the I/O ports to reserve.
lengthThe amount of contiguous I/O ports to reserve.
ownerA string identifying the owner of the reservation, for debugging purposes, can be NULL.
Returns
On success, 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ io_release()

void io_release ( port_t  base,
uint64_t  length 
)

Release a previously reserved range of I/O ports.

Parameters
baseThe base I/O port address of the reserved range.
lengthThe amount of contiguous I/O ports to release.

Definition at line 43 of file io.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ io_out8()

static void io_out8 ( port_t  port,
uint8_t  val 
)
inlinestatic

Write an 8-bit value to an I/O port.

Parameters
portThe I/O port to write to.
valThe value to write.

Definition at line 71 of file io.h.

Here is the caller graph for this function:

◆ io_in8()

static uint8_t io_in8 ( port_t  port)
inlinestatic

Read an 8-bit value from an I/O port.

Parameters
portThe I/O port to read from.
Returns
The value read from the port.

Definition at line 82 of file io.h.

Here is the caller graph for this function:

◆ io_out16()

static void io_out16 ( port_t  port,
uint16_t  val 
)
inlinestatic

Write a 16-bit value to an I/O port.

Parameters
portThe I/O port to write to.
valThe value to write.

Definition at line 95 of file io.h.

Here is the caller graph for this function:

◆ io_in16()

static uint16_t io_in16 ( port_t  port)
inlinestatic

Read a 16-bit value from an I/O port.

Parameters
portThe I/O port to read from.
Returns
The value read from the port.

Definition at line 106 of file io.h.

Here is the caller graph for this function:

◆ io_in32()

static uint32_t io_in32 ( port_t  port)
inlinestatic

Write a 32-bit value to an I/O port.

Parameters
portThe I/O port to write to.
valThe value to write.

Definition at line 119 of file io.h.

Here is the caller graph for this function:

◆ io_out32()

static void io_out32 ( port_t  port,
uint32_t  val 
)
inlinestatic

Read a 32-bit value from an I/O port.

Parameters
portThe I/O port to read from.
Returns
The value read from the port.

Definition at line 132 of file io.h.

Here is the caller graph for this function: