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(target_arch = "loongarch64", expect(unused_imports))]
14pub(crate) use self::io_mem::{IoMemAllocatorBuilder, Sensitive};
15
16cfg_select! {
17    target_arch = "x86_64" => {
18        mod io_port;
19
20        pub use self::io_port::IoPort;
21        pub(crate) use self::io_port::{reserve_io_port_range, sensitive_io_port, RawIoPortRange};
22    }
23    _ => {},
24}
25
26/// Initializes the static allocator based on builder.
27///
28/// # Safety
29///
30/// User must ensure that:
31///
32/// 1. All the memory that belong to the system device have been removed
33///    by calling the `remove` function.
34///
35/// 2. All the port I/O regions belonging to the system device are defined
36///    using the macros `sensitive_io_port` and `reserve_io_port_range`.
37///
38/// 3. `MAX_IO_PORT` defined in `crate::arch::io` is guaranteed not to
39///    exceed the maximum value specified by architecture.
40pub(crate) unsafe fn init(io_mem_builder: IoMemAllocatorBuilder) {
41    // SAFETY: The safety is upheld by the caller.
42    unsafe { io_mem::init(io_mem_builder) };
43
44    // SAFETY: The safety is upheld by the caller.
45    #[cfg(target_arch = "x86_64")]
46    unsafe {
47        io_port::init()
48    };
49}