-
-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructure init of PCI legacy interrupts (INTx); add
lspci
app (#1081
) * INTX interrupt handler registration for PCI devices is now done lazily on both architectures. * On aarch64, the interrupt numbers are known statically. * On x86_64, we expect that the driver or module using the PCI device knows which interrupt number to use. Technically this information can be discovered through ACPI AML, but we do not yet support that because it is tedious and difficult. * Clarify PCI interrupt information functions, e.g., MSI/MSI-x support, etc. Co-authored-by: Kevin Boos <1139460+kevinaboos@users.noreply.github.com>
- Loading branch information
1 parent
e06c84a
commit ac5712c
Showing
8 changed files
with
249 additions
and
75 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "lspci" | ||
version = "0.1.0" | ||
description = "An application which lists currently connected PCI devices." | ||
authors = ["Nathan Royer <nathan.royer.pro@gmail.com>"] | ||
edition = "2021" | ||
|
||
[dependencies] | ||
getopts = "0.2.21" | ||
pci = { path = "../../kernel/pci" } | ||
memory = { path = "../../kernel/memory" } | ||
app_io = { path = "../../kernel/app_io" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
//! This application lists currently connected PCI devices. | ||
|
||
#![no_std] | ||
|
||
extern crate alloc; | ||
#[macro_use] extern crate app_io; | ||
extern crate getopts; | ||
|
||
use alloc::vec::Vec; | ||
use alloc::string::String; | ||
use getopts::Options; | ||
use pci::pci_device_iter; | ||
use memory::PhysicalAddress; | ||
|
||
pub fn main(args: Vec<String>) -> isize { | ||
let mut opts = Options::new(); | ||
opts.optflag("h", "help", "print this help menu"); | ||
|
||
let matches = match opts.parse(args) { | ||
Ok(m) => m, | ||
Err(_f) => { | ||
println!("{}", _f); | ||
print_usage(opts); | ||
return -1; | ||
} | ||
}; | ||
|
||
if matches.opt_present("h") { | ||
print_usage(opts); | ||
return 0; | ||
} | ||
|
||
if let Err(msg) = list_pci_devices() { | ||
println!("Error: {}", msg); | ||
} | ||
|
||
0 | ||
} | ||
|
||
fn list_pci_devices() -> Result<(), &'static str> { | ||
for dev in pci_device_iter()? { | ||
println!("{} -- {:04x}:{:04x}", dev.location, dev.vendor_id, dev.device_id); | ||
println!("- class, subclass, prog_if: {:x}, {:x}, {:x}", dev.class, dev.subclass, dev.prog_if); | ||
|
||
for bar_idx in 0..6 { | ||
let base = dev.determine_mem_base(bar_idx)?; | ||
if base != PhysicalAddress::zero() { | ||
let size = dev.determine_mem_size(bar_idx); | ||
println!("- BAR {}: base = 0x{:x}, size = 0x{:x}", bar_idx, base, size); | ||
} | ||
} | ||
|
||
let support = dev.modern_interrupt_support(); | ||
let supports = |b| match b { | ||
true => "supported", | ||
false => "not supported", | ||
}; | ||
|
||
println!("- MSI interrupts: {}", supports(support.msi)); | ||
println!("- MSI-X interrupts: {}", supports(support.msix)); | ||
println!("- INTx enabled: {}", dev.pci_intx_enabled()); | ||
println!("- INTx status: {}", dev.pci_get_intx_status(false)); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
|
||
fn print_usage(opts: Options) { | ||
println!("{}", opts.usage(USAGE)); | ||
} | ||
|
||
|
||
const USAGE: &str = "Usage: lspci | ||
An application which lists currently connected PCI devices."; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.