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