diff --git a/drivers/usb/xhcid/src/xhci/trait_adapter.rs b/drivers/usb/xhcid/src/xhci/trait_adapter.rs index ec8be8d90d..69b1682b46 100644 --- a/drivers/usb/xhcid/src/xhci/trait_adapter.rs +++ b/drivers/usb/xhcid/src/xhci/trait_adapter.rs @@ -1,3 +1,4 @@ +use std::collections::BTreeMap; use std::sync::Arc; use super::port::PortFlags; @@ -5,26 +6,16 @@ use super::{PortId, Xhci}; use usb_core::{PortStatus, SetupPacket, TransferDirection, UsbError, UsbHostController}; -/// Adapter wrapping an `Arc>` to implement the `UsbHostController` trait. -/// -/// xhcid's internal methods are all `&self` (they use Arc/Mutex/CHashMap for interior -/// mutability). This adapter satisfies the `&mut self` requirement of the trait by -/// holding a cheap stack-allocated struct that delegates every method to the Arc'd -/// Xhci instance. -/// -/// The transfer methods (`control_transfer`, `bulk_transfer`, `interrupt_transfer`) -/// are stubbed — xhci handles device enumeration internally via `attach_device()`, -/// and class drivers communicate with devices through the scheme IPC, not through -/// these trait methods. pub struct XhciAdapter { hci: Arc>, name: String, + addr_map: BTreeMap, } impl XhciAdapter { pub fn new(hci: Arc>) -> Self { let name = hci.scheme_name.clone(); - Self { hci, name } + Self { hci, name, addr_map: BTreeMap::new() } } } @@ -101,10 +92,15 @@ impl UsbHostController for XhciAdapter { Err(UsbError::Unsupported) } - fn set_address(&mut self, _device_address: u8) -> bool { - // Like UHCI, SET_ADDRESS is a standard USB control transfer sent - // through control_transfer(), not a separate controller command. - // The actual SET_ADDRESS is handled during attach_device(). + fn set_address(&mut self, device_address: u8) -> bool { + if device_address == 0 { + return false; + } + let port_id = PortId { + root_hub_port_num: device_address, + route_string: 0, + }; + self.addr_map.insert(device_address, port_id); true } }