| Crates.io | polished_pci |
| lib.rs | polished_pci |
| version | 0.2.2 |
| created_at | 2025-06-12 20:11:43.25617+00 |
| updated_at | 2025-06-13 03:20:25.666675+00 |
| description | Low-level routines for initializing and managing PCI devices on x86 systems. |
| homepage | |
| repository | https://codeberg.org/ofluffydev/polished |
| max_upload_size | |
| id | 1710317 |
| size | 49,366 |
polished_pci)This crate provides low-level routines for accessing and enumerating PCI devices on x86 systems. It is designed for use in operating system kernels or bootloaders written in Rust, where direct hardware access is required. polished_pci is a core component of the Polished OS project, enabling device discovery and initialization for modern and legacy hardware.
The polished_pci library offers safe(ish) Rust abstractions over the raw I/O port operations needed to:
serial_logging crateAll hardware access is performed in unsafe blocks, as is required for direct port I/O on x86 hardware.
For current features and todo items, see the TODO.md file.
serial_logging crate (or a no-op logger if disabled).no_std environments such as kernels and bootloaders.If using as part of a workspace (as in Polished OS), add to your Cargo.toml:
[dependencies]
polished_pci = { path = "../pci" }
Or, if using features:
[features]
default = ["polished_serial_logging"]
polished_serial_logging = ["dep:polished_serial_logging"]
[dependencies]
polished_serial_logging = { path = "../serial_logging", optional = true }
Call the pci_enumeration_demo() function early in your kernel or bootloader initialization sequence, after setting up basic memory and logging:
polished_pci::pci_enumeration_demo();
This will:
All functions that perform hardware access are marked unsafe internally. The public API (pci_enumeration_demo) is safe to call, but must only be used in a context where direct hardware access is permitted (i.e., kernel mode, not in userland or standard OS processes).
// In your kernel's main.rs or initialization code:
extern crate polished_pci;
fn main() {
// ...other early setup...
polished_pci::pci_enumeration_demo();
// ...continue kernel boot...
}
For detailed API documentation, integration examples, and usage notes, see the crate-level documentation (e.g., run cargo doc --open or view the docs.rs page if published). The documentation includes:
core::arch::asm!) for inl and outl operations to access PCI configuration space.serial_logging crate to log device information, or a no-op logger if the feature is disabled.#![no_std] and the alloc crate for string formatting.The PCI (Peripheral Component Interconnect) bus is a standard for connecting peripheral devices to a computer's processor and memory. Device enumeration is the process of scanning the bus to discover all connected devices and their capabilities. Here’s how it works in the context of OS development:
polished_pci is a foundational crate for Polished OS, enabling the kernel to:
PCI enumeration is a critical step in modern OS initialization, as it allows the kernel to discover and initialize all hardware required for boot and runtime operation.
This crate is licensed under the zlib License. See the root LICENSE file for details.
For questions or contributions, see the main Polished OS repository.