IDS_RS: A no_std PCI Device Identification Library
A no_std-compatible PCI device identification library designed specifically for operating systems and low-level system software. This crate parses the PCI IDs database at compile time, enabling efficient runtime lookups without heap allocation or file I/O.
Features
- 🚀 no_std compatible: Perfect for kernel-space and embedded environments
- ⚡ Compile-time parsing: Database is parsed during build, not runtime
- 🔍 Comprehensive coverage: Supports vendors, devices, subsystems, and device classes
- 🎯 Zero-cost abstractions: Efficient static data structures with no runtime overhead
- 🛡️ Type-safe queries: Strongly typed IDs prevent common mistakes
- 🔧 Advanced querying: Flexible query builder for complex lookups
- 📦 Auto-updating: Includes scripts to update the PCI IDs database
Quick Start
Add this to your Cargo.toml:
[]
= "0.1"
Basic Usage
use ;
// Get the compiled database
let db = get;
// Look up a vendor (Intel)
let vendor_id = new;
if let Some = db.find_vendor
// Look up a specific device
let device_id = new;
if let Some = db.find_device
// Get a complete device description
let description = db.describe_device;
println!;
Advanced Querying
use ;
let db = get;
// Find all Intel network devices
let intel_network_devices = db.query
.vendor_name_contains
.class_name_contains
.execute;
for device_match in intel_network_devices
// Search for specific device types
let ethernet_devices = db.search_devices;
let wireless_classes = db.search_classes;
Device Class Lookups
use ;
let db = get;
// Look up device class information
let class_id = new; // Serial bus controller
let subclass_id = new; // USB controller
let prog_if_id = new; // XHCI
if let Some = db.find_prog_interface
Database Updates
The crate includes scripts to download and update the PCI IDs database:
PowerShell (Windows)
.\update_pci_ids.ps1
Bash (Linux/macOS)
These scripts will:
- Download the latest PCI IDs database from https://pci-ids.ucw.cz/
- Validate the download
- Show database statistics
- Only download if the local file is older than 7 days (use
-Forceto override)
After updating the database, rebuild your project to incorporate the new data:
Architecture
Modular Design
The crate is organized into focused modules:
types: Type-safe wrappers for PCI identifiersvendors: Vendor definitions and utilitiesdevices: Device and subsystem definitionsclasses: Device class, subclass, and programming interface definitionsdatabase: Main database interface and lookupsquery: Advanced query builder and search functionalityparser: PCI IDs format parser (build-time only)error: Error types and handling
Compile-Time Database Generation
The PCI IDs database is parsed at compile time using a build script. This approach provides:
- Zero runtime cost: No parsing overhead during program execution
- Static memory usage: All data is embedded in the binary
- Type safety: All IDs are validated at compile time
- Efficient lookups: Binary search on sorted arrays
Memory Layout
The generated database uses efficient memory layouts:
- Vendors are sorted by ID for binary search
- Device classes are sorted by ID for binary search
- Devices within vendors use linear search (typically small arrays)
- All strings are static
&'static strreferences
no_std Compatibility
This crate is fully compatible with no_std environments:
use ;
The only requirement is the heapless crate for some string operations in type conversion methods.
API Reference
Core Types
VendorId,DeviceId: Type-safe PCI vendor and device identifiersSubvendorId,SubdeviceId: Type-safe subsystem identifiersDeviceClassId,SubClassId,ProgInterfaceId: Type-safe class identifiers
Main Structures
PciDatabase: Main database interfaceVendor: PCI vendor informationDevice: PCI device informationSubsystem: PCI subsystem informationDeviceClass: PCI device class information
Query Interface
QueryBuilder: Flexible query builder for complex searchesDeviceMatch: Device search resultClassMatch: Class search result
Performance
The library is designed for maximum performance in system-level code:
- Lookup time: O(log n) for vendors and classes, O(n) for devices (n typically < 100)
- Memory usage: ~500KB-2MB depending on database size (static data)
- Binary size impact: Moderate increase due to embedded database
- Runtime allocations: None (all data is static)
Use Cases
This library is ideal for:
- Operating system kernels: Device driver loading and hardware identification
- System monitoring tools: Hardware inventory and device enumeration
- Embedded systems: Hardware discovery in resource-constrained environments
- Hypervisors: Virtual device management and PCI passthrough
- Boot loaders: Early hardware detection and initialization
Database Statistics
The current PCI IDs database contains approximately:
- 2,500+ vendors
- 25,000+ devices
- 5,000+ subsystems
- 20+ device classes
- 100+ subclasses
- 200+ programming interfaces
Contributing
Contributions are welcome! Please:
- Run the update scripts to get the latest database
- Add tests for new functionality
- Ensure
no_stdcompatibility - Follow the existing code style
- Update documentation as needed
License
MIT