strat9_kernel/shell/commands/hw/
mod.rs1use crate::{shell::ShellError, shell_println};
3use alloc::string::String;
4
5fn pci_class_name(class: u8, subclass: u8) -> &'static str {
6 match (class, subclass) {
7 (0x01, 0x00) => "SCSI",
8 (0x01, 0x01) => "IDE",
9 (0x01, 0x06) => "SATA",
10 (0x01, 0x08) => "NVMe",
11 (0x01, _) => "Storage",
12 (0x02, 0x00) => "Ethernet",
13 (0x02, _) => "Network",
14 (0x03, 0x00) => "VGA",
15 (0x03, _) => "Display",
16 (0x04, _) => "Multimedia",
17 (0x05, _) => "Memory",
18 (0x06, 0x00) => "Host bridge",
19 (0x06, 0x01) => "ISA bridge",
20 (0x06, 0x04) => "PCI bridge",
21 (0x06, _) => "Bridge",
22 (0x07, _) => "Serial",
23 (0x08, _) => "System",
24 (0x0C, 0x03) => "USB",
25 (0x0C, _) => "Serial bus",
26 _ => "Other",
27 }
28}
29
30pub fn cmd_lspci(_args: &[String]) -> Result<(), ShellError> {
31 let devices = crate::arch::x86_64::pci::all_devices();
32 if devices.is_empty() {
33 shell_println!("(no PCI devices found)");
34 return Ok(());
35 }
36
37 shell_println!(
38 "{:<12} {:<11} {:<12} {}",
39 "Address",
40 "Vendor:Dev",
41 "Class",
42 "Type"
43 );
44 shell_println!("──────────────────────────────────────────────────────");
45 for dev in &devices {
46 let addr = dev.address;
47 shell_println!(
48 "{:02x}:{:02x}.{:<5} {:04x}:{:04x} {:02x}:{:02x} {}",
49 addr.bus,
50 addr.device,
51 addr.function,
52 dev.vendor_id,
53 dev.device_id,
54 dev.class_code,
55 dev.subclass,
56 pci_class_name(dev.class_code, dev.subclass)
57 );
58 }
59 shell_println!("{} device(s)", devices.len());
60 Ok(())
61}
62
63pub fn cmd_lsns(_args: &[String]) -> Result<(), ShellError> {
64 let bindings = crate::namespace::list_all_bindings();
65 if bindings.is_empty() {
66 shell_println!("(no IPC namespace bindings)");
67 return Ok(());
68 }
69
70 shell_println!("{:<8} {}", "Port", "Path");
71 shell_println!("────────────────────────────────────────");
72 for (path, port_id) in &bindings {
73 shell_println!("{:<8} {}", port_id, path);
74 }
75 shell_println!("{} binding(s)", bindings.len());
76 Ok(())
77}