x86_64/structures/port.rs
1//! Traits for accessing I/O ports.
2
3/// A helper trait that implements the read port operation.
4///
5/// On x86, I/O ports operate on either `u8` (via `inb`/`outb`), `u16` (via `inw`/`outw`),
6/// or `u32` (via `inl`/`outl`). Therefore this trait is implemented for exactly these types.
7pub trait PortRead {
8 /// Reads a `Self` value from the given port.
9 ///
10 /// ## Safety
11 ///
12 /// This function is unsafe because the I/O port could have side effects that violate memory
13 /// safety.
14 unsafe fn read_from_port(port: u16) -> Self;
15}
16
17/// A helper trait that implements the write port operation.
18///
19/// On x86, I/O ports operate on either `u8` (via `inb`/`outb`), `u16` (via `inw`/`outw`),
20/// or `u32` (via `inl`/`outl`). Therefore this trait is implemented for exactly these types.
21pub trait PortWrite {
22 /// Writes a `Self` value to the given port.
23 ///
24 /// ## Safety
25 ///
26 /// This function is unsafe because the I/O port could have side effects that violate memory
27 /// safety.
28 unsafe fn write_to_port(port: u16, value: Self);
29}