forked from theseus-os/Theseus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/bit-set' into update-epoch-sched…
…uler Signed-off-by: Klimenty Tsoutsman <klim@tsoutsman.com>
- Loading branch information
Showing
13 changed files
with
260 additions
and
84 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
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
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.