| Crates.io | usb-oxide |
| lib.rs | usb-oxide |
| version | 0.1.1 |
| created_at | 2026-01-18 14:17:10.305862+00 |
| updated_at | 2026-01-20 02:30:51.991797+00 |
| description | Bare-metal lightweight USB/xHCI driver |
| homepage | |
| repository | |
| max_upload_size | |
| id | 2052410 |
| size | 133,845 |
Bare-metal lightweight xHCI/USB stack for OS development.
Implement the Dma trait to provide DMA allocation and MMIO mapping:
impl Dma for MyDma {
unsafe fn alloc(&self, size: usize, align: usize) -> usize { /* physically contiguous */ }
unsafe fn free(&self, addr: usize, size: usize, align: usize) { }
unsafe fn map_mmio(&self, phys: usize, size: usize) -> usize { }
unsafe fn unmap_mmio(&self, virt: usize, size: usize) { }
fn virt_to_phys(&self, va: usize) -> usize { }
fn page_size(&self) -> usize { /* typically 4096 */ }
}
Then initialise from PCI:
let ctrl = Arc::new(XhciCtrl::new(pci_bar0_addr, MyDma)?);
for port in 0..ctrl.max_ports() {
if ctrl.port_connected(port) {
let dev = UsbDevice::new(ctrl.clone(), port)?;
// enumerate, configure, use class drivers...
}
}
The alloc function receives alignment requirements per allocation:
| Structure | Align |
|---|---|
| TRB rings | 16 B |
| Slot/Endpoint contexts | 32 B |
| Device/Input contexts, DCBAA | 64 B |
| Scratchpad buffers | Page |