Skip to content

Commit

Permalink
Appropriately define GICD_BASE and GICR_BASE for gicv3
Browse files Browse the repository at this point in the history
  • Loading branch information
elliott10 committed Oct 21, 2024
1 parent 187ca9d commit 74c68a4
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 33 deletions.
30 changes: 14 additions & 16 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions crates/arm_gic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "arm_gic"
version = "0.1.0"
edition = "2021"
authors = ["Yuekai Jia <[email protected]>"]
authors = ["Yuekai Jia <[email protected]>", "Luoyuan Xiao <[email protected]>"]
description = "ARM Generic Interrupt Controller (GIC) register definitions and basic operations"
license = "GPL-3.0-or-later OR Apache-2.0"
homepage = "https://github.com/rcore-os/arceos"
Expand All @@ -17,4 +17,4 @@ cfg-if = "1.0"
log = "0.4"

[features]
hyper = []
hyper = []
26 changes: 13 additions & 13 deletions crates/arm_gic/src/gic_v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1129,18 +1129,19 @@ impl GicState {
}
}} // cfg_if!

// ? Todo
#[linkage = "weak"]
#[export_name = "PLATFORM_GICD_BASE"]
pub static PLATFORM_GICD_BASE: usize = 0xffff000008000000;
extern "C" {
#[link_name = "PLATFORM_GICD_BASE"]
pub static GICD_BASE: usize;

#[linkage = "weak"]
#[export_name = "PLATFORM_GICR_BASE"]
pub static PLATFORM_GICR_BASE: usize = 0xffff0000080a0000;
#[link_name = "PLATFORM_GICR_BASE"]
pub static GICR_BASE: usize;
}

lazy_static::lazy_static! {
// SAFETY: GICD & GICR are GICv3 mmio device regions
pub static GICD: DeviceRef<GicDistributor> = DeviceRef::new(PLATFORM_GICD_BASE as *const GicDistributor);
pub static GICR: DeviceRef<GicRedistributor> = DeviceRef::new(PLATFORM_GICR_BASE as *const GicRedistributor);
pub static ref GICD: DeviceRef<'static, GicDistributor> = DeviceRef::new(unsafe{ GICD_BASE as *const GicDistributor });
pub static ref GICR: DeviceRef<'static, GicRedistributor> = DeviceRef::new(unsafe { GICR_BASE as *const GicRedistributor });
}

pub static GICC: GicCpuInterface = GicCpuInterface;
#[cfg(feature = "hyper")]
Expand All @@ -1157,8 +1158,8 @@ impl<T> DeviceRef<'_, T> {
/// # Safety
/// - `ptr` must be aligned, non-null, and dereferencable as `T`.
/// - `*ptr` must be valid for the program duration.
pub const fn new<'a>(ptr: *const T) -> DeviceRef<'a, T> {
//info!("DeviceRef new @ {:#x}", ptr as usize);
pub fn new<'a>(ptr: *const T) -> DeviceRef<'a, T> {
info!("DeviceRef new @ {:#x}", ptr as usize);

// SAFETY: `ptr` is non-null as promised by the caller.
DeviceRef {
Expand Down Expand Up @@ -1209,8 +1210,7 @@ pub fn gic_max_spi() -> usize {
}

pub fn gic_glb_init() {
// Initialize gic glb
info!("Init gic v3, GICD@{:#x}, GICR@{:#x}", PLATFORM_GICD_BASE, PLATFORM_GICR_BASE);
info!("gic_glb_init gic v3, GICD@{:#x}, GICR@{:#x}", unsafe{ GICD_BASE }, unsafe{ GICR_BASE });

#[cfg(feature = "hyper")]
set_gic_lrs(gich_lrs_num());
Expand Down
4 changes: 2 additions & 2 deletions modules/axhal/src/platform/aarch64_common/gic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ use arm_gic::gic_v3::{GICD, gicc_get_current_irq, gicc_clear_current_irq, gic_gl

#[cfg(feature = "gicv3")]
#[export_name = "PLATFORM_GICD_BASE"]
pub static PLATFORM_GICD_BASE: usize = axconfig::PHYS_VIRT_OFFSET + axconfig::GICD_PADDR;
pub static GICD_BASE: usize = axconfig::PHYS_VIRT_OFFSET + axconfig::GICD_PADDR;
#[cfg(feature = "gicv3")]
#[export_name = "PLATFORM_GICR_BASE"]
pub static PLATFORM_GICR_BASE: usize = axconfig::PHYS_VIRT_OFFSET + axconfig::GICR_PADDR;
pub static GICR_BASE: usize = axconfig::PHYS_VIRT_OFFSET + axconfig::GICR_PADDR;

/// Enables or disables the given IRQ.
pub fn set_enable(irq_num: usize, enabled: bool) {
Expand Down

0 comments on commit 74c68a4

Please sign in to comment.