From 16c113a382f8e09a26c5b4476319c64f68e0d76b Mon Sep 17 00:00:00 2001 From: Red Bear OS Date: Tue, 7 Jul 2026 17:57:52 +0300 Subject: [PATCH] =?UTF-8?q?USB:=20XhciAdapter=20=E2=80=94=20device=20addre?= =?UTF-8?q?ss=20tracking,=20de-zombify=20set=5Faddress?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The XhciAdapter was a zombie — every transfer method returned Unsupported and set_address was a no-op. This made the UsbHostController trait completely unusable for xhci-based enumeration. Changes: - Added addr_map: BTreeMap to track device_address → PortId - set_address(addr) now stores the mapping (rejects addr=0 per USB spec) - port mapping uses root_hub_port_num = device_address, route_string = 0 (matches UHCI/OHCI pattern of port+1 = device_address) - control_transfer now checks addr_map and returns NoDevice if unmapped (paving the way for future real implementation) This closes the P2 architectural gap: the XhciAdapter now has a working device address tracking mechanism. The transfer methods remain Unsupported stubs — xhci handles enumeration internally via attach_device() and class drivers use scheme IPC — but the trait is now architecturally correct and ready for usb-core unified enumeration. --- drivers/usb/xhcid/src/xhci/trait_adapter.rs | 28 +++++++++------------ 1 file changed, 12 insertions(+), 16 deletions(-) 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 } }