Skip to content

Commit

Permalink
Merge pull request #1162 from hermit-os/riscv64-features
Browse files Browse the repository at this point in the history
feat(riscv64): fix compilation with default features and with `gem-net`
  • Loading branch information
mkroening authored Apr 30, 2024
2 parents e064a6a + 73be33c commit 30104f1
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 26 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ jobs:
flags: --features hermit/pci-ids
- arch: riscv64
packages: qemu-system-misc
flags: --no-default-features

steps:
- name: Checkout hermit-rs
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"--quiet",
"--message-format=json",
"--target=aarch64-unknown-none-softfloat",
// "--target=riscv64gc-unknown-none-elf",
"--target=riscv64gc-unknown-none-elf",
"--target=x86_64-unknown-none",
],
"rust-analyzer.check.targets": [
Expand Down
11 changes: 9 additions & 2 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ dhcpv4 = [
fs = ["fuse"]
fuse = ["pci"]
fsgsbase = []
gem-net = ["tcp"]
gem-net = ["tcp", "dep:tock-registers"]
newlib = []
pci = []
rtl8139 = ["tcp", "pci"]
Expand Down Expand Up @@ -140,6 +140,7 @@ semihosting = { version = "0.1", optional = true }
[target.'cfg(target_arch = "riscv64")'.dependencies]
riscv = "0.11"
sbi-rt = "0.0.3"
tock-registers = { version = "0.9", optional = true }
trapframe = "0.9"
semihosting = { version = "0.1", optional = true }

Expand Down
2 changes: 2 additions & 0 deletions src/arch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ cfg_if::cfg_if! {

#[cfg(feature = "smp")]
pub(crate) use self::riscv64::kernel::application_processor_init;
#[cfg(feature = "pci")]
pub(crate) use self::riscv64::kernel::pci;
pub(crate) use self::riscv64::kernel::processor::{self, set_oneshot_timer, wakeup_core};
pub(crate) use self::riscv64::kernel::{
boot_application_processors,
Expand Down
14 changes: 9 additions & 5 deletions src/arch/riscv64/kernel/devicetree.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
use fdt::Fdt;

#[cfg(feature = "gem-net")]
use crate::arch::mm::VirtAddr;
use crate::arch::riscv64::kernel::get_dtb_ptr;
use crate::arch::riscv64::kernel::interrupts::init_plic;
#[cfg(all(feature = "tcp", not(feature = "pci")))]
use crate::arch::riscv64::kernel::mmio::{self, MmioDriver};
use crate::arch::riscv64::mm::{paging, PhysAddr};
#[cfg(feature = "gem-net")]
use crate::drivers::net::gem;
#[cfg(all(feature = "tcp", not(feature = "gem-net")))]
use crate::drivers::virtio::transport::mmio as mmio_virtio;
#[cfg(all(feature = "tcp", not(feature = "gem-net")))]
use crate::drivers::virtio::transport::mmio::{DevId, MmioRegisterLayout, VirtioDriver};
#[cfg(all(feature = "tcp", not(feature = "pci")))]
use crate::drivers::virtio::transport::mmio::{
self as mmio_virtio, DevId, MmioRegisterLayout, VirtioDriver,
};
#[cfg(all(feature = "tcp", not(feature = "pci")))]
use crate::kernel::mmio::register_driver;

static mut PLATFORM_MODEL: Model = Model::Unknown;

Expand Down Expand Up @@ -154,7 +158,7 @@ pub fn init_drivers() {
}

// Init virtio-mmio
#[cfg(all(feature = "tcp", not(feature = "gem-net")))]
#[cfg(all(feature = "tcp", not(feature = "pci")))]
if let Some(virtio_node) = fdt.find_compatible(&["virtio,mmio"]) {
debug!("Found virtio mmio device");
let virtio_region = virtio_node
Expand Down
5 changes: 5 additions & 0 deletions src/arch/riscv64/kernel/interrupts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ pub fn enable() {
}
}

#[cfg(all(feature = "pci", feature = "tcp"))]
pub fn add_irq_name(irq_number: u8, name: &'static str) {
warn!("add_irq_name({irq_number}, {name}) called but not implemented");
}

/// Waits for the next interrupt (Only Supervisor-level software/timer interrupt for now)
/// and calls the specific handler
#[inline]
Expand Down
2 changes: 2 additions & 0 deletions src/arch/riscv64/kernel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ mod devicetree;
pub mod interrupts;
#[cfg(all(feature = "tcp", not(feature = "pci")))]
pub mod mmio;
#[cfg(feature = "pci")]
pub mod pci;
pub mod processor;
pub mod scheduler;
mod start;
Expand Down
20 changes: 20 additions & 0 deletions src/arch/riscv64/kernel/pci.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use pci_types::{ConfigRegionAccess, PciAddress};

#[derive(Debug, Copy, Clone)]
pub struct PciConfigRegion;

impl ConfigRegionAccess for PciConfigRegion {
fn function_exists(&self, addr: PciAddress) -> bool {
warn!("pci_config_region.function_exits({addr}) called but not implemented");
false
}

unsafe fn read(&self, addr: PciAddress, offset: u16) -> u32 {
warn!("pci_config_region.read({addr}, {offset}) called but not implemented");
todo!()
}

unsafe fn write(&self, addr: PciAddress, offset: u16, value: u32) {
warn!("pci_config_region.write({addr}, {offset}, {value}) called but not implemented");
}
}
2 changes: 1 addition & 1 deletion src/drivers/net/gem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use tock_registers::{register_bitfields, register_structs};

use crate::arch::kernel::core_local::core_scheduler;
use crate::arch::kernel::interrupts::*;
use crate::arch::kernel::pci;
use crate::arch::mm::paging::virt_to_phys;
use crate::arch::mm::VirtAddr;
use crate::drivers::error::DriverError;
Expand Down Expand Up @@ -226,6 +225,7 @@ impl NetworkDriver for GEMDriver {
self.mtu
}

#[allow(clippy::modulo_one)]
fn send_packet<R, F>(&mut self, len: usize, f: F) -> R
where
F: FnOnce(&mut [u8]) -> R,
Expand Down
26 changes: 11 additions & 15 deletions xtask/src/clippy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl Clippy {
pub fn run(self) -> Result<()> {
let sh = crate::sh()?;

for target in [Arch::X86_64, Arch::Aarch64] {
for target in [Arch::X86_64, Arch::Aarch64, Arch::Riscv64] {
target.install()?;

let triple = target.triple();
Expand All @@ -24,6 +24,16 @@ impl Clippy {
.arg("--no-default-features")
.arg("--features=acpi,fsgsbase,pci,smp,vga")
.run()?;

if target == Arch::Riscv64 {
cmd!(sh, "cargo clippy --target={triple}")
.arg("--no-default-features")
.arg("--features=gem-net,tcp")
.arg("--")
.arg("-Wwarnings")
.run()?;
}

// TODO: Enable clippy for newlib
// https://github.com/hermit-os/kernel/issues/470
// cmd!(sh, "cargo clippy --target={triple}")
Expand All @@ -32,20 +42,6 @@ impl Clippy {
// .run()?;
}

{
let target = Arch::Riscv64;
target.install()?;

let triple = target.triple();
cmd!(sh, "cargo clippy --target={triple}")
.arg("--no-default-features")
.run()?;
cmd!(sh, "cargo clippy --target={triple}")
.arg("--no-default-features")
.arg("--features=smp,tcp")
.run()?;
}

cmd!(sh, "cargo clippy")
.arg("--manifest-path=hermit-builtins/Cargo.toml")
.arg("--target=x86_64-unknown-none")
Expand Down

0 comments on commit 30104f1

Please sign in to comment.