Skip to main content

ostd/io/
mod.rs

1// SPDX-License-Identifier: MPL-2.0
2
3//! Device I/O access and corresponding allocator.
4//!
5//! This module allows device drivers to access the device I/O they need
6//! through _allocators_. There are two types of device I/O:
7//!  - `IoMem` for memory I/O (MMIO).
8//!  - `IoPort` for port I/O (PIO).
9
10pub(crate) mod io_mem;
11
12pub use self::io_mem::IoMem;
13#[cfg_attr(
14    any(target_arch = "loongarch64", target_arch = "aarch64"),
15    expect(unused_imports)
16)]
17pub(crate) use self::io_mem::{IoMemAllocatorBuilder, Sensitive};
18
19cfg_select! {
20    target_arch = "x86_64" => {
21        mod io_port;
22
23        pub use self::io_port::IoPort;
24        pub(crate) use self::io_port::{reserve_io_port_range, sensitive_io_port, RawIoPortRange};
25    }
26    _ => {},
27}
28
29/// Initializes the static allocator based on builder.
30///
31/// # Safety
32///
33/// User must ensure that:
34///
35/// 1. All the memory that belong to the system device have been removed
36///    by calling the `remove` function.
37///
38/// 2. All the port I/O regions belonging to the system device are defined
39///    using the macros `sensitive_io_port` and `reserve_io_port_range`.
40///
41/// 3. `MAX_IO_PORT` defined in `crate::arch::io` is guaranteed not to
42///    exceed the maximum value specified by architecture.
43pub(crate) unsafe fn init(io_mem_builder: IoMemAllocatorBuilder) {
44    // SAFETY: The safety is upheld by the caller.
45    unsafe { io_mem::init(io_mem_builder) };
46
47    // SAFETY: The safety is upheld by the caller.
48    #[cfg(target_arch = "x86_64")]
49    unsafe {
50        io_port::init()
51    };
52}