Skip to content

Commit e979b80

Browse files
Improve pci abstractions; support MMIO PCI access for aarch64 (#1019)
* Support PCI on aarch64 via MMIO access mechanisms. * Redesign the PCI addressing code to be very clear and use more types. Currently some checks are done at runtime with assertions, but these could easily be moved to compile time by introducing traits about register sizes that can be implemented by each `RegisterSpan` within the `PciRegister` type. * Note: PCI currently uses Port I/O on x86 and MMIO on aarch64 to read/write, but x86_64 may also use MMIO-based access in the future, because Port I/O is the legacy method to access the PCI configuration space. * The `device_manager` now initializes and scans the PCI bus on both the aarch64 and x86_64 platforms. * Scanning the PCI bus for the first time also maps the memory behind the configuration space. Co-authored-by: Kevin Boos <[email protected]>
1 parent 3035738 commit e979b80

File tree

8 files changed

+434
-144
lines changed

8 files changed

+434
-144
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,9 @@ else ifeq ($(ARCH),aarch64)
933933
QEMU_FLAGS += -machine virt,gic-version=3
934934
QEMU_FLAGS += -device ramfb
935935
QEMU_FLAGS += -cpu cortex-a72
936+
QEMU_FLAGS += -usb
937+
QEMU_FLAGS += -device usb-ehci,id=ehci
938+
QEMU_FLAGS += -device usb-kbd
936939
else
937940
QEMU_FLAGS += -cpu Broadwell
938941
endif

kernel/arm_boards/src/boards/qemu_virt.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use super::{
44
InterruptControllerConfig::GicV3, GicV3InterruptControllerConfig,
5-
BoardConfig, mpidr::DefinedMpidrValue,
5+
BoardConfig, mpidr::DefinedMpidrValue, PciEcamConfig,
66
};
77
use memory_structs::PhysicalAddress;
88

@@ -38,4 +38,11 @@ pub const BOARD_CONFIG: BoardConfig = BoardConfig {
3838
pl011_base_addresses: [ PhysicalAddress::new_canonical(0x09000000) ],
3939
pl011_rx_spi: 33,
4040
cpu_local_timer_ppi: 30,
41+
42+
// obtained via internal qemu debugging
43+
// todo: will this always be correct?
44+
pci_ecam: PciEcamConfig {
45+
base_address: PhysicalAddress::new_canonical(0x4010000000),
46+
size_bytes: 0x10000000,
47+
}
4148
};

kernel/arm_boards/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ pub struct GicV3InterruptControllerConfig {
1919
pub redistributor_base_addresses: [PhysicalAddress; NUM_CPUS],
2020
}
2121

22+
#[derive(Debug, Copy, Clone)]
23+
pub struct PciEcamConfig {
24+
pub base_address: PhysicalAddress,
25+
pub size_bytes: usize,
26+
}
27+
2228
#[derive(Debug, Copy, Clone)]
2329
pub enum InterruptControllerConfig {
2430
GicV3(GicV3InterruptControllerConfig),
@@ -46,6 +52,8 @@ pub struct BoardConfig {
4652
//
4753
// aarch64 manuals define the default timer IRQ number to be 30.
4854
pub cpu_local_timer_ppi: u8,
55+
56+
pub pci_ecam: PciEcamConfig,
4957
}
5058

5159
// by default & on x86_64, the default.rs file is used

kernel/device_manager/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ event_types = { path = "../event_types" }
1212
serial_port = { path = "../serial_port" }
1313
console = { path = "../console" }
1414
logger = { path = "../logger" }
15+
pci = { path = "../pci" }
1516
derive_more = "0.99.0"
1617
mpmc = "0.1.6"
1718
log = "0.4.8"
@@ -20,7 +21,6 @@ log = "0.4.8"
2021
memory = { path = "../memory" }
2122
e1000 = { path = "../e1000" }
2223
acpi = { path = "../acpi" }
23-
pci = { path = "../pci" }
2424
ps2 = { path = "../ps2" }
2525
keyboard = { path = "../keyboard" }
2626
mouse = { path = "../mouse" }

kernel/device_manager/src/lib.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
extern crate alloc;
55

6-
use log::info;
6+
use log::{info, debug};
77

88
#[cfg(target_arch = "x86_64")]
99
use {
10-
log::{error, debug, warn},
10+
log::{error, warn},
1111
mpmc::Queue,
1212
event_types::Event,
1313
memory::MemoryManagementInfo,
@@ -86,19 +86,20 @@ pub fn init(
8686
mouse::init(ps2_controller.mouse_ref(), mouse_producer)?;
8787
}
8888

89-
// No PCI support on aarch64 at the moment
90-
#[cfg(target_arch = "x86_64")] {
9189
// Initialize/scan the PCI bus to discover PCI devices
92-
for dev in pci::pci_device_iter() {
93-
debug!("Found pci device: {:X?}", dev);
90+
for dev in pci::pci_device_iter()? {
91+
debug!("Found PCI device: {:X?}", dev);
9492
}
9593

94+
// No NIC support on aarch64 at the moment
95+
#[cfg(target_arch = "x86_64")] {
96+
9697
// store all the initialized ixgbe NICs here to be added to the network interface list
9798
let mut ixgbe_devs = Vec::new();
9899

99100
// Iterate over all PCI devices and initialize the drivers for the devices we support.
100101

101-
for dev in pci::pci_device_iter() {
102+
for dev in pci::pci_device_iter()? {
102103
// Currently we skip Bridge devices, since we have no use for them yet.
103104
if dev.class == 0x06 {
104105
continue;

kernel/pci/Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
authors = ["Kevin Boos <[email protected]>"]
33
name = "pci"
4-
description = "Basic PCI support for Theseus, x86 only."
4+
description = "Basic PCI support for Theseus."
55
version = "0.1.0"
66
edition = "2021"
77

@@ -12,10 +12,15 @@ log = "0.4.8"
1212
volatile = "0.2.4"
1313
zerocopy = "0.5.0"
1414

15-
port_io = { path = "../../libs/port_io" }
1615
memory = { path = "../memory" }
1716
cpu = { path = "../cpu" }
1817
interrupts = { path = "../interrupts" }
1918

19+
[target.'cfg(target_arch = "x86_64")'.dependencies]
20+
port_io = { path = "../../libs/port_io" }
21+
22+
[target.'cfg(target_arch = "aarch64")'.dependencies]
23+
arm_boards = { path = "../arm_boards" }
24+
2025
[lib]
2126
crate-type = ["rlib"]

0 commit comments

Comments
 (0)