Skip to content
Closed
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
2 changes: 1 addition & 1 deletion README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ hvisor 是一个用 Rust 实现的 Type-1 裸机虚拟机监控器,采用分
| | imx-uart | `aarch64` | NXP i.MX8MP |
| | NS16550A | `loongarch64` | |
| | xuartps | `aarch64` | Xilinx Ultrascale+ MPSoC ZCU102 |
| **中断控制器** | GIC irq controller | `aarch64` | |
| **中断控制器** | GIC irq controller | `aarch64` | GICv2, GICv3 |
| | 7A2000 irq controller | `loongarch64` | |
| | PLIC | `riscv64` | |
| | AIA-APIC | `riscv64` | 仅支持 MSI 模式 |
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ hvisor is a Type-1 bare-metal virtual machine monitor implemented in Rust, featu
| | imx-uart | `aarch64` | NXP i.MX8MP |
| | NS16550A | `loongarch64` | |
| | xuartps | `aarch64` | Xilinx Ultrascale+ MPSoC ZCU102 |
| **Interrupt Controllers** | GIC irq controller | `aarch64` | |
| **Interrupt Controllers** | GIC irq controller | `aarch64` | GICv2, GICv3 |
| | 7A2000 irq controller | `loongarch64` | |
| | PLIC | `riscv64` | |
| | AIA-APIC | `riscv64` | Only supports MSI mode |
Expand Down
3 changes: 3 additions & 0 deletions src/arch/aarch64/cpu.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![allow(dead_code)]
#![allow(unused_imports)]

use crate::{
arch::{mm::new_s2_memory_set, sysreg::write_sysreg},
consts::{PAGE_SIZE, PER_CPU_ARRAY_PTR, PER_CPU_SIZE},
Expand Down
5 changes: 2 additions & 3 deletions src/arch/aarch64/entry.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use core::arch::global_asm;
#![allow(unused)]

use crate::consts::PER_CPU_SIZE;

//global_asm!(include_str!("boot_pt.S"));
use core::arch::global_asm;

#[naked]
#[no_mangle]
Expand Down
6 changes: 3 additions & 3 deletions src/arch/aarch64/mm.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use core::sync::atomic::AtomicU32;
#![allow(unused)]

use core::sync::atomic::AtomicU32;
use spin::RwLock;

use super::sysreg::read_sysreg;
use crate::{
arch::Stage2PageTable, consts::MAX_CPU_NUM, error::HvResult, memory::MemorySet, wait_for,
};

use super::sysreg::read_sysreg;

pub fn init_hv_page_table() -> HvResult {
todo!();
// let mut hv_pt: MemorySet<Stage1PageTable> = MemorySet::new(4);
Expand Down
2 changes: 2 additions & 0 deletions src/arch/aarch64/mmu.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(unused)]

use cfg_if::cfg_if;
use cortex_a::registers::{MAIR_EL1, SCTLR_EL2};
use tock_registers::interfaces::*;
Expand Down
2 changes: 2 additions & 0 deletions src/arch/aarch64/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(unused_imports)]

pub mod cpu;
pub mod entry;
pub mod iommu;
Expand Down
2 changes: 2 additions & 0 deletions src/arch/aarch64/sysreg.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(unused_imports)]

// Copyright 2023 The arm-gic Authors.
// This project is dual-licensed under Apache 2.0 and MIT terms.
// See LICENSE-APACHE and LICENSE-MIT for details.
Expand Down
4 changes: 3 additions & 1 deletion src/arch/aarch64/trap.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(unused)]

use aarch64_cpu::{asm::wfi, registers::*};
use core::arch::global_asm;

Expand Down Expand Up @@ -395,7 +397,7 @@ fn handle_arch_smc(
SMCccFnId::SMCCC_ARCH_FEATURES => !0,
_ => {
error!("unsupported ARM smc service");
return !0;
!0
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(unused)]

use alloc::vec::Vec;
use spin::Once;

Expand Down
4 changes: 2 additions & 2 deletions src/device/irqchip/gicv3/gicr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
// Copyright (c) 2020-2022 Andre Richter <[email protected]>

//! GICC Driver - GIC CPU interface.

use core::ptr;
#![allow(unused)]

use alloc::vec::Vec;
use core::ptr;
use spin::{mutex::Mutex, Once};

use crate::{
Expand Down
14 changes: 7 additions & 7 deletions src/device/irqchip/gicv3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,29 +76,29 @@
//! - 00..15 SGIs
//! - 16..31 PPIs
#![allow(dead_code)]
#![allow(unused_imports)]

pub mod gicd;
pub mod gicr;
pub mod gits;
pub mod vgic;

use alloc::collections::vec_deque::VecDeque;
use alloc::vec::Vec;
use core::arch::asm;
use core::ptr::write_volatile;
use core::sync::atomic::AtomicU64;

use alloc::collections::btree_map::BTreeMap;
use alloc::collections::vec_deque::VecDeque;
use alloc::vec::Vec;
use gicr::{init_lpi_prop, GICR_ISENABLER, GICR_SGI_BASE};
use gits::gits_init;
use spin::{Mutex, Once};

use self::gicd::{enable_gic_are_ns, GICD_ICACTIVER, GICD_ICENABLER};
use self::gicr::enable_ipi;

use crate::arch::aarch64::sysreg::{read_sysreg, smc_arg1, write_sysreg};
use crate::arch::cpu::this_cpu_id;
use crate::config::root_zone_config;
use crate::consts::MAX_CPU_NUM;

use crate::event::check_events;
use crate::hypercall::SGI_IPI_ID;
use crate::zone::Zone;
Expand Down Expand Up @@ -374,7 +374,7 @@ pub fn inject_irq(irq_id: usize, is_hardware: bool) -> bool {
.add_irq(irq_id, is_hardware)
.unwrap();
enable_maintenace_interrupt(true);
return false;
false
} else {
let mut val = irq_id as u64; //v intid
val |= 1 << 60; //group 1
Expand All @@ -385,7 +385,7 @@ pub fn inject_irq(irq_id: usize, is_hardware: bool) -> bool {
val |= (irq_id as u64) << 32; //pINTID
}
write_lr(free_ir as usize, val);
return true;
true
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/device/uart/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(unused_imports)]

#[cfg(all(feature = "platform_qemu", target_arch = "aarch64"))]
mod pl011;

Expand Down
2 changes: 2 additions & 0 deletions src/device/virtio_trampoline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub static VIRTIO_BRIDGE: Mutex<VirtioBridgeRegion> = Mutex::new(VirtioBridgeReg
const QUEUE_NOTIFY: usize = 0x50;
pub const MAX_REQ: u32 = 32;
pub const MAX_DEVS: usize = 4; // Attention: The max virtio-dev number for vm is 4.
#[allow(unused)]
pub const MAX_CPUS: usize = 4;
pub const IRQ_WAKEUP_VIRTIO_DEVICE: usize = 32 + 0x20;

Expand Down Expand Up @@ -75,6 +76,7 @@ pub fn mmio_virtio_handler(mmio: &mut MMIOAccess, base: usize) -> HvResult {
if need_interrupt == 0 {
// when virtio backend finish the req, it will add 1 to cfg_flag.
while cfg_flags[cpu_id] == old_cfg_flag {
// TODO: fix the clippy: this may lead to an infinite or to a never running loop
// fence(Ordering::Acquire);
count += 1;
if count > 1000000 {
Expand Down
6 changes: 4 additions & 2 deletions src/event.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#![allow(unused)]

use crate::{
arch::ipi::arch_send_event,
device::{
irqchip::{self, inject_irq},
irqchip::inject_irq,
virtio_trampoline::{handle_virtio_irq, IRQ_WAKEUP_VIRTIO_DEVICE},
},
percpu::this_cpu_data,
Expand Down Expand Up @@ -113,7 +115,7 @@ pub fn check_events() -> bool {
}
#[cfg(target_arch = "loongarch64")]
Some(IPI_EVENT_CLEAR_INJECT_IRQ) => {
irqchip::ls7a2000::clear_hwi_injected_irq();
crate::device::irqchip::ls7a2000::clear_hwi_injected_irq();
true
}
_ => false,
Expand Down
5 changes: 3 additions & 2 deletions src/hypercall/mod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#![allow(dead_code)]
#![allow(unused_imports)]
use crate::arch::cpu::this_cpu_id;
use crate::config::HvZoneConfig;
use crate::consts::{INVALID_ADDRESS, MAX_CPU_NUM, PAGE_SIZE};
use crate::device::irqchip::inject_irq;
use crate::device::virtio_trampoline::{MAX_DEVS, MAX_REQ, VIRTIO_BRIDGE, VIRTIO_IRQS};
use crate::error::HvResult;
use crate::event::{send_event, IPI_EVENT_SHUTDOWN, IPI_EVENT_VIRTIO_INJECT_IRQ, IPI_EVENT_WAKEUP};
use crate::percpu::{get_cpu_data, this_zone, PerCpu};
use crate::zone::{
all_zones_info, find_zone, is_this_root_zone, remove_zone, this_zone_id, zone_create, ZoneInfo,
};

use crate::event::{send_event, IPI_EVENT_SHUTDOWN, IPI_EVENT_VIRTIO_INJECT_IRQ, IPI_EVENT_WAKEUP};
use core::convert::TryFrom;
use core::sync::atomic::{fence, Ordering};

Expand Down Expand Up @@ -79,6 +79,7 @@ impl<'a> HyperCall<'a> {
}
#[cfg(target_arch = "aarch64")]
HyperCallCode::HvIvcInfo => self.hv_ivc_info(arg0),
#[allow(unreachable_patterns)]
_ => {
warn!("hypercall id={} unsupported!", code as u64);
Ok(0)
Expand Down
8 changes: 3 additions & 5 deletions src/ivc.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use core::ptr::write_volatile;
#![allow(unused)]

use alloc::{
collections::{btree_map::BTreeMap, btree_set::BTreeSet},
vec::Vec,
};
use alloc::collections::btree_map::BTreeMap;
use core::ptr::write_volatile;
use spin::Mutex;

use crate::device::irqchip::set_ispender;
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ mod zone;
mod ivc;

mod pci;

#[cfg(test)]
mod tests;

#[cfg(target_arch = "aarch64")]
Expand Down
2 changes: 0 additions & 2 deletions src/memory/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#![allow(dead_code)]

use core::fmt::Debug;

use crate::consts::PAGE_SIZE;

pub type VirtAddr = usize;
Expand Down
1 change: 0 additions & 1 deletion src/memory/mapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ impl<VA: From<usize> + Into<usize> + Copy> MemoryRegion<VA> {
flags: MemFlags,
) -> Self {
let start_vaddr = start_vaddr.into();
let start_paddr = start_paddr;
// bug: vaddr > paddr?
let phys_virt_offset = start_vaddr.wrapping_sub(start_paddr);
Self::new(
Expand Down
7 changes: 3 additions & 4 deletions src/memory/mmio.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use core::ptr;

use crate::{error::HvResult, percpu::this_zone};

use super::GuestPhysAddr;
use crate::{error::HvResult, percpu::this_zone};
use core::ptr;

pub type MMIOHandler = fn(&mut MMIOAccess, usize) -> HvResult;

Expand Down Expand Up @@ -77,6 +75,7 @@ pub fn mmio_handle_access(mmio: &mut MMIOAccess) -> HvResult {
}
}

#[allow(unused)]
pub fn mmio_generic_handler(mmio: &mut MMIOAccess, base: usize) -> HvResult {
mmio_perform_access(base, mmio);
Ok(())
Expand Down
2 changes: 2 additions & 0 deletions src/memory/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(unused)]

pub mod addr;
pub mod frame;
pub mod heap;
Expand Down
4 changes: 4 additions & 0 deletions src/panic.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#![allow(unused_imports)]

#[cfg(test)]
use crate::tests::*;

use core::panic::PanicInfo;

#[panic_handler]
Expand Down
3 changes: 1 addition & 2 deletions src/pci/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ pub struct EndpointConfig {
impl EndpointConfig {
pub fn new(bdf: usize) -> Self {
let (bars, bdf) = { ([PciBar::default(); NUM_BAR_REGS_TYPE0], bdf) };
let r = EndpointConfig { bars, bdf };
r
EndpointConfig { bars, bdf }
}

pub fn bars_init(&mut self, bar_id: usize, origin_val: u32, val: u32) {
Expand Down
4 changes: 3 additions & 1 deletion src/pci/pci.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![allow(unused_imports)]

use alloc::vec::Vec;
use core::{ptr, usize};

use crate::config::{HvPciConfig, CONFIG_MAX_PCI_DEV};
Expand All @@ -12,7 +15,6 @@ use crate::{
memory::{mmio_perform_access, GuestPhysAddr, MemFlags, MemoryRegion},
zone::Zone,
};
use alloc::vec::Vec;

use super::bridge::BridgeConfig;
use super::endpoint::EndpointConfig;
Expand Down
5 changes: 1 addition & 4 deletions src/percpu.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
use alloc::sync::Arc;
use alloc::vec::Vec;
use spin::{Mutex, RwLock};

use crate::arch::cpu::{this_cpu_id, ArchCpu};
use crate::consts::{INVALID_ADDRESS, PER_CPU_ARRAY_PTR, PER_CPU_SIZE};
use crate::memory::addr::VirtAddr;
use crate::zone::Zone;
use crate::{arch, ENTERED_CPUS};
use crate::ENTERED_CPUS;
use core::fmt::Debug;
use core::sync::atomic::Ordering;

// global_asm!(include_str!("./arch/aarch64/page_table.S"),);

#[cfg(test)]
mod tests;

Expand Down
1 change: 1 addition & 0 deletions src/percpu/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::*;
use alloc::vec::Vec;

#[test_case]
fn test_cpuset() {
Expand Down
2 changes: 2 additions & 0 deletions src/platform/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(unused_assignments)]

use crate::{
config::{
HvConfigMemoryRegion, HvIvcConfig, HvPciConfig, HvZoneConfig, CONFIG_MAX_INTERRUPTS,
Expand Down
2 changes: 2 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(unused)]

/// this module is for unittests of hvisor
/// since this is a baremetal program
/// all unittests are performed when running hvisor on qemu
Expand Down