Skip to content

Commit

Permalink
nusb fork with iokit host controller info for pci
Browse files Browse the repository at this point in the history
  • Loading branch information
tuna-f1sh committed Oct 16, 2024
1 parent 315bf67 commit 3f024cf
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 63 deletions.
88 changes: 44 additions & 44 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pci-ids = "0.2.5"
unicode-width = "0.2.0"

[patch.crates-io]
nusb = { git = "https://github.com/tuna-f1sh/nusb", branch = "win-hub-devices" }
nusb = { git = "https://github.com/tuna-f1sh/nusb", branch = "cyme" }

[dev-dependencies]
diff = "0.1"
Expand Down
30 changes: 12 additions & 18 deletions src/profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1094,10 +1094,17 @@ mod platform {
#[cfg(target_os = "macos")]
mod platform {
use super::*;
use std::sync::OnceLock;

/// Static SystemProfile for macOS lookup of PCI data
static SP_USB: OnceLock<Result<SystemProfile>> = OnceLock::new();
use ::nusb::HostControllerInfo;

impl From<&HostControllerInfo> for PciInfo {
fn from(pci_info: &HostControllerInfo) -> Self {
PciInfo {
vendor_id: pci_info.vendor_id(),
product_id: pci_info.device_id(),
revision: pci_info.revision_id(),
}
}
}

#[allow(unused_variables)]
pub(crate) fn pci_info_from_device(device: &Device) -> Option<PciInfo> {
Expand All @@ -1106,20 +1113,7 @@ mod platform {

#[cfg(feature = "nusb")]
pub(crate) fn pci_info_from_bus(bus_info: &::nusb::BusInfo) -> Option<PciInfo> {
// TODO would be better io-kit-sys and core-foundation-sys bindings directly
let sp_usb = SP_USB.get_or_init(macos::get_spusb).as_ref().ok()?;

sp_usb.buses.iter().find_map(|b| {
if b.host_controller == bus_info.class_name() {
Some(PciInfo {
vendor_id: b.pci_vendor?,
product_id: b.pci_device?,
revision: b.pci_revision?,
})
} else {
None
}
})
bus_info.host_controller_info().map(Into::into)
}

#[cfg(feature = "nusb")]
Expand Down

0 comments on commit 3f024cf

Please sign in to comment.