diff --git a/Cargo.lock b/Cargo.lock index 9fcbd662d8..ee2c267881 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2900,6 +2900,7 @@ dependencies = [ "bitflags 2.11.0", "chashmap", "common", + "config", "crossbeam-channel", "daemon", "futures", diff --git a/Makefile b/Makefile index dff36a0265..88a494f3be 100644 --- a/Makefile +++ b/Makefile @@ -82,7 +82,6 @@ base: install-base: base $(SYSROOT)/bin/redoxfs @mkdir -pv "$(DESTDIR)/usr/bin" "$(DESTDIR)/usr/lib/drivers" - @mkdir -pv "$(DESTDIR)/usr/lib/init.d/" "$(DESTDIR)/usr/lib/pcid.d" # Distribute binaries @for bin in $(BASE_BINS); do \ cp -v "$(TARGET_DIR)/$$bin" "$(DESTDIR)/usr/bin"; \ @@ -91,11 +90,13 @@ install-base: base $(SYSROOT)/bin/redoxfs cp -v "$(TARGET_DIR)/$$bin" "$(DESTDIR)/usr/lib/drivers"; \ done # Copy configurations + @mkdir -pv "$(DESTDIR)/usr/lib/init.d/" "$(DESTDIR)/usr/lib/pcid.d/" "$(DESTDIR)/usr/lib/xhcid.d/" @cp -v "$(SRC_DIR)/init.d"/* "$(DESTDIR)/usr/lib/init.d/" @find "$(SRC_DIR)/drivers" -maxdepth 3 -type f -name 'config.toml' | while read -r conf; do \ driver=$$(basename "$$(dirname "$$conf")"); \ cp -v "$$conf" "$(DESTDIR)/usr/lib/pcid.d/$$driver.toml"; \ done + @cp -v "$(SRC_DIR)/drivers/usb/xhcid/drivers.toml" "$(DESTDIR)/usr/lib/xhcid.d/" rm -rf "$(BUILD_DIR)/initfs" # Distribute initfs binaries diff --git a/drivers/usb/xhcid/Cargo.toml b/drivers/usb/xhcid/Cargo.toml index ca767fd257..6353ea5d69 100644 --- a/drivers/usb/xhcid/Cargo.toml +++ b/drivers/usb/xhcid/Cargo.toml @@ -30,6 +30,7 @@ smallvec = { workspace = true, features = ["serde"] } thiserror.workspace = true toml.workspace = true +config = { path = "../../../config" } common = { path = "../../common" } daemon = { path = "../../../daemon" } pcid = { path = "../../pcid" } diff --git a/drivers/usb/xhcid/src/xhci/mod.rs b/drivers/usb/xhcid/src/xhci/mod.rs index f214367639..73d9d90b2a 100644 --- a/drivers/usb/xhcid/src/xhci/mod.rs +++ b/drivers/usb/xhcid/src/xhci/mod.rs @@ -11,7 +11,7 @@ //! documents are specified in the crate-level documentation. use std::collections::BTreeMap; use std::convert::TryFrom; -use std::fs::File; +use std::fs::{self, File}; use std::sync::atomic::AtomicUsize; use std::sync::{Arc, Mutex}; @@ -63,6 +63,8 @@ use self::scheme::EndpIfState; pub use crate::driver_interface::PortId; use crate::driver_interface::*; +use crate::xhci::device_enumerator::{DeviceEnumerationRequest, DeviceEnumerator}; +use crate::xhci::port::PortFlags; /// Specifies the configurable interrupt mechanism used by the xhci subsystem for registering /// device state change notifications. @@ -280,6 +282,7 @@ pub struct Xhci { // used for the extended capabilities, and so far none of them are mutated, and thus no lock. base: *const u8, + drivers_config: DriversConfig, handles: CHashMap, next_handle: AtomicUsize, port_states: CHashMap>, @@ -445,6 +448,25 @@ impl Xhci { let (device_enumerator_sender, device_enumerator_receiver) = crossbeam_channel::unbounded(); + let mut drivers_config = DriversConfig { drivers: vec![] }; + for file in config::config("xhcid").expect("xhcid: Failed to read driver configs") { + let config = match fs::read(&file) { + Ok(config) => config, + Err(err) => { + println!("xhcid: Failed to read config {}: {err}", file.display()); + continue; + } + }; + let config = match toml::from_slice::(&config) { + Ok(config) => config, + Err(err) => { + println!("xhcid: Failed to parse config {}: {err}", file.display()); + continue; + } + }; + drivers_config.drivers.extend(config.drivers); + } + let mut xhci = Self { base: address as *const u8, @@ -460,6 +482,7 @@ impl Xhci { cmd: Mutex::new(cmd), primary_event_ring: Mutex::new(EventRing::new::(cap.ac64())?), + drivers_config, handles: CHashMap::new(), next_handle: AtomicUsize::new(0), port_states: CHashMap::new(), @@ -1243,7 +1266,6 @@ impl Xhci { })?; trace!("Got config and device descriptors on port {}", port); - let drivers_usercfg: &DriversConfig = &DRIVERS_CONFIG; for ifdesc in config_desc.interface_descs.iter() { //TODO: support alternate settings @@ -1264,7 +1286,7 @@ impl Xhci { continue; } - if let Some(driver) = drivers_usercfg.drivers.iter().find(|driver| { + if let Some(driver) = self.drivers_config.drivers.iter().find(|driver| { driver.class == ifdesc.class && driver .subclass() @@ -1474,16 +1496,3 @@ impl DriverConfig { struct DriversConfig { drivers: Vec, } - -use crate::xhci::device_enumerator::{DeviceEnumerationRequest, DeviceEnumerator}; -use crate::xhci::port::PortFlags; -use lazy_static::lazy_static; - -lazy_static! { - static ref DRIVERS_CONFIG: DriversConfig = { - // TODO: Load this at runtime. - const TOML: &'static [u8] = include_bytes!("../../drivers.toml"); - - toml::from_slice::(TOML).expect("Failed to parse internally embedded config file") - }; -}