Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revise PCI support #745

Merged
merged 9 commits into from
May 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ jobs:
run: rustup show
- uses: Swatinem/rust-cache@v2
- name: Build dev profile
run: cargo build -Zbuild-std=std,panic_abort --package rusty_demo --target x86_64-unknown-hermit
run: cargo build -Zbuild-std=std,panic_abort --package rusty_demo --target x86_64-unknown-hermit --features pci-ids
- name: Download loader
uses: dsaltares/[email protected]
with:
Expand All @@ -157,7 +157,7 @@ jobs:
-object memory-backend-file,id=mem,size=1G,mem-path=/dev/shm,share=on -numa node,memdev=mem \
-initrd target/x86_64-unknown-hermit/debug/rusty_demo
- name: Build release profile
run: cargo build -Zbuild-std=std,panic_abort --package rusty_demo --target x86_64-unknown-hermit --release
run: cargo build -Zbuild-std=std,panic_abort --package rusty_demo --target x86_64-unknown-hermit --release --features pci-ids
- name: Test release profile
run: |
virtiofsd --socket-path=./vhostqemu --shared-dir ./img --announce-submounts --sandbox none --seccomp none --inode-file-handles=never &
Expand All @@ -169,6 +169,34 @@ jobs:
-device vhost-user-fs-pci,queue-size=1024,chardev=char0,tag=root \
-object memory-backend-file,id=mem,size=1G,mem-path=/dev/shm,share=on -numa node,memdev=mem \
-initrd target/x86_64-unknown-hermit/release/rusty_demo
- name: Build httpd with DHCP support (debug profile)
run:
cargo build -Zbuild-std=std,panic_abort --target x86_64-unknown-hermit --package httpd --features ci,dhcpv4
- name: Test httpd with DHCP support (debug profile)
run: |
qemu-system-x86_64 -smp 1 -cpu qemu64,apic,fsgsbase,rdtscp,xsave,xsaveopt,fxsr,rdrand \
-device isa-debug-exit,iobase=0xf4,iosize=0x04 -display none -m 128M -serial stdio \
-kernel rusty-loader-x86_64 \
-initrd target/x86_64-unknown-hermit/debug/httpd \
-netdev user,id=u1,hostfwd=tcp::9975-:9975,net=192.168.76.0/24,dhcpstart=192.168.76.9 \
-device rtl8139,netdev=u1 &
sleep 5
curl http://127.0.0.1:9975/help
sleep 1
- name: Build httpd with DHCP support (release profile)
run:
cargo build -Zbuild-std=std,panic_abort --target x86_64-unknown-hermit --package httpd --release --features ci,dhcpv4
- name: Test httpd with DHCP support (release profile)
run: |
qemu-system-x86_64 -smp 1 -cpu qemu64,apic,fsgsbase,rdtscp,xsave,xsaveopt,fxsr,rdrand \
-device isa-debug-exit,iobase=0xf4,iosize=0x04 -display none -m 128M -serial stdio \
-kernel rusty-loader-x86_64 \
-initrd target/x86_64-unknown-hermit/release/httpd \
-netdev user,id=u1,hostfwd=tcp::9975-:9975,net=192.168.76.0/24,dhcpstart=192.168.76.9 \
-device rtl8139,netdev=u1 &
sleep 5
curl http://127.0.0.1:9975/help
sleep 1
- name: Build minimal profile
run: cargo build -Zbuild-std=std,panic_abort --target x86_64-unknown-hermit --no-default-features --release --package hello_world
- name: Test minimal profile
Expand Down Expand Up @@ -216,15 +244,15 @@ jobs:
sudo apt-get install qemu-system-aarch64
- uses: Swatinem/rust-cache@v2
- name: Build dev profile
run: cargo build -Zbuild-std=std,panic_abort --target aarch64-unknown-hermit --package rusty_demo
run: cargo build -Zbuild-std=std,panic_abort --target aarch64-unknown-hermit --package rusty_demo --features pci-ids
- name: Test dev kernel
run: |
qemu-system-aarch64 -semihosting \
-kernel rusty-loader-aarch64 -machine virt,gic-version=max \
-m 512M -cpu max -smp 1 -display none -serial stdio -kernel rusty-loader-aarch64 \
-device guest-loader,addr=0x48000000,initrd=target/aarch64-unknown-hermit/debug/rusty_demo
- name: Build release profile
run: cargo build -Zbuild-std=std,panic_abort --target aarch64-unknown-hermit --package rusty_demo --release
run: cargo build -Zbuild-std=std,panic_abort --target aarch64-unknown-hermit --package rusty_demo --release --features pci-ids
- name: Test release kernel
run: |
qemu-system-aarch64 -semihosting \
Expand Down
33 changes: 21 additions & 12 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ num-traits = { version = "0.2", default-features = false }
num-derive = "0.3"
zerocopy = "0.6"
time = { version = "0.3", default-features = false }
pci_types = { git = "https://github.com/hermitcore/pci_types.git", branch = "hermit" }

[dependencies.smoltcp]
version = "0.9"
Expand Down
22 changes: 20 additions & 2 deletions src/arch/aarch64/kernel/core_local.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use alloc::boxed::Box;
use core::ptr;
use core::sync::atomic::Ordering;

use super::interrupts::{IrqStatistics, IRQ_COUNTERS};
use super::CPU_ONLINE;
use crate::scheduler::{CoreId, PerCoreScheduler};

#[no_mangle]
Expand All @@ -19,6 +23,13 @@ impl CoreLocal {
scheduler: CoreLocalVariable::new(0 as *mut PerCoreScheduler),
}
}

pub fn install() {
let core_id = CPU_ONLINE.load(Ordering::Relaxed);

let irq_statistics = &*Box::leak(Box::new(IrqStatistics::new()));
IRQ_COUNTERS.lock().insert(core_id, irq_statistics);
}
}

#[repr(C)]
Expand Down Expand Up @@ -72,6 +83,13 @@ pub fn set_core_scheduler(scheduler: *mut PerCoreScheduler) {
}
}

pub fn init() {
// TODO: Implement!
pub fn increment_irq_counter(irq_no: u8) {
unsafe {
let id = CORE_LOCAL.core_id.get();
if let Some(counter) = IRQ_COUNTERS.lock().get(&id) {
counter.inc(irq_no);
} else {
warn!("Unknown core {}, is core {} already registered?", id, id);
}
}
}
79 changes: 68 additions & 11 deletions src/arch/aarch64/kernel/interrupts.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
use alloc::collections::BTreeMap;
use alloc::vec::Vec;
use core::arch::asm;
use core::ptr;
use core::sync::atomic::{AtomicU64, Ordering};

use aarch64::regs::*;
use arm_gic::gicv3::{GicV3, IntId, SgiTarget};
use ahash::RandomState;
use arm_gic::gicv3::{GicV3, IntId};
use hashbrown::HashMap;
use hermit_dtb::Dtb;
use hermit_sync::{without_interrupts, InterruptTicketMutex, OnceCell};
use hermit_sync::{InterruptSpinMutex, InterruptTicketMutex, OnceCell};
use tock_registers::interfaces::Readable;

use crate::arch::aarch64::kernel::boot_info;
use crate::arch::aarch64::kernel::core_local::increment_irq_counter;
use crate::arch::aarch64::kernel::scheduler::State;
use crate::arch::aarch64::mm::paging::{
self, virt_to_phys, BasePageSize, PageSize, PageTableEntryFlags,
};
use crate::arch::aarch64::mm::{virtualmem, PhysAddr, VirtAddr};
use crate::arch::aarch64::mm::paging::{self, BasePageSize, PageSize, PageTableEntryFlags};
use crate::arch::aarch64::mm::{virtualmem, PhysAddr};
use crate::errno::EFAULT;
use crate::scheduler::CoreId;
use crate::{core_scheduler, sys_exit};
Expand Down Expand Up @@ -83,10 +85,10 @@ pub fn disable() {
}
}

pub fn irq_install_handler(irq_number: u32, handler: fn(state: &State)) {
pub fn irq_install_handler(irq_number: u8, handler: fn(state: &State)) {
debug!("Install handler for interrupt {}", irq_number);
unsafe {
INTERRUPT_HANDLERS[irq_number as usize] = Some(handler);
INTERRUPT_HANDLERS[irq_number as usize + 16] = Some(handler);
}
}

Expand All @@ -96,6 +98,7 @@ pub extern "C" fn do_fiq(state: &State) {
let vector: usize = u32::from(irqid).try_into().unwrap();

debug!("Receive fiq {}", vector);
increment_irq_counter(vector.try_into().unwrap());

if vector < MAX_HANDLERS {
unsafe {
Expand All @@ -122,6 +125,7 @@ pub extern "C" fn do_irq(state: &State) {
let vector: usize = u32::from(irqid).try_into().unwrap();

debug!("Receive interrupt {}", vector);
increment_irq_counter(vector.try_into().unwrap());

if vector < MAX_HANDLERS {
unsafe {
Expand Down Expand Up @@ -276,8 +280,9 @@ pub fn init() {
TIMER_INTERRUPT = irq;
}

info!("Timer interrupt: {}", irq);
irq_install_handler(irq + 16, timer_handler);
debug!("Timer interrupt: {}", irq);
irq_install_handler(irq.try_into().unwrap(), timer_handler);
add_irq_name(irq.try_into().unwrap(), "Timer");

// enable timer interrupt
let timer_irqid = IntId::ppi(irq);
Expand All @@ -291,3 +296,55 @@ pub fn init() {
GIC.set(gic).unwrap();
}
}

static IRQ_NAMES: InterruptTicketMutex<HashMap<u8, &'static str, RandomState>> =
InterruptTicketMutex::new(HashMap::with_hasher(RandomState::with_seeds(0, 0, 0, 0)));

pub fn add_irq_name(irq_number: u8, name: &'static str) {
debug!("Register name \"{}\" for interrupt {}", name, irq_number);
IRQ_NAMES.lock().insert(16 + irq_number, name);
}

fn get_irq_name(irq_number: u8) -> Option<&'static str> {
IRQ_NAMES.lock().get(&irq_number).copied()
}

pub static IRQ_COUNTERS: InterruptSpinMutex<BTreeMap<CoreId, &IrqStatistics>> =
InterruptSpinMutex::new(BTreeMap::new());

pub struct IrqStatistics {
pub counters: [AtomicU64; 256],
}

impl IrqStatistics {
pub const fn new() -> Self {
#[allow(clippy::declare_interior_mutable_const)]
const NEW_COUNTER: AtomicU64 = AtomicU64::new(0);
IrqStatistics {
counters: [NEW_COUNTER; 256],
}
}

pub fn inc(&self, pos: u8) {
self.counters[usize::from(pos)].fetch_add(1, Ordering::Relaxed);
}
}

pub fn print_statistics() {
info!("Number of interrupts");
for (core_id, irg_statistics) in IRQ_COUNTERS.lock().iter() {
for (i, counter) in irg_statistics.counters.iter().enumerate() {
let counter = counter.load(Ordering::Relaxed);
if counter > 0 {
match get_irq_name(i.try_into().unwrap()) {
Some(name) => {
info!("[{core_id}][{name}]: {counter}");
}
_ => {
info!("[{core_id}][{i}]: {counter}");
}
}
}
}
}
}
7 changes: 7 additions & 0 deletions src/arch/aarch64/kernel/mmio.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use hermit_sync::InterruptTicketMutex;

use crate::drivers::net::NetworkInterface;

pub fn get_network_driver() -> Option<&'static InterruptTicketMutex<dyn NetworkInterface>> {
None
}
Loading