From 4ed6db69a82d47a304c70e29eb4ba563d9f33395 Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Wed, 16 Jul 2025 14:01:14 +0100 Subject: [PATCH 1/5] Fix example in doc comment. --- CHANGELOG.md | 6 ++++++ src/lib.rs | 21 +++++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index babe0e5..d751fb1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Bugfixes + +- Fixed example in crate documentation. + ## 0.5.0 ### Breaking changes diff --git a/src/lib.rs b/src/lib.rs index fe68281..f7dfaf0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,27 +11,31 @@ //! //! Using a GICv3 on a single-core aarch64 system: //! -//! ``` +//! ```no_run //! use arm_gic::{ -//! gicv3::{GicV3, SgiTarget}, -//! irq_enable, IntId, +//! IntId, +//! gicv3::{ +//! GicV3, SgiTarget, SgiTargetGroup, +//! registers::{Gicd, GicrSgi}, +//! }, +//! irq_enable, //! }; //! //! // Base addresses of the GICv3 distributor and redistributor. -//! const GICD_BASE_ADDRESS: *mut u64 = 0x800_0000 as _; -//! const GICR_BASE_ADDRESS: *mut u64 = 0x80A_0000 as _; +//! const GICD_BASE_ADDRESS: *mut Gicd = 0x800_0000 as _; +//! const GICR_BASE_ADDRESS: *mut GicrSgi = 0x80A_0000 as _; //! //! // Initialise the GIC. -//! let mut gic = unsafe { GicV3::new(GICD_BASE_ADDRESS, GICR_BASE_ADDRESS, 1, 0x20000) }; +//! let mut gic = unsafe { GicV3::new(GICD_BASE_ADDRESS, GICR_BASE_ADDRESS, 1, false) }; //! gic.setup(0); //! //! // Configure an SGI and then send it to ourself. //! let sgi_intid = IntId::sgi(3); -//! SingleCoreGicV3::set_priority_mask(0xff); +//! GicV3::set_priority_mask(0xff); //! gic.set_interrupt_priority(sgi_intid, Some(0), 0x80); //! gic.enable_interrupt(sgi_intid, Some(0), true); //! irq_enable(); -//! SingleCoreGicV3::send_sgi( +//! GicV3::send_sgi( //! sgi_intid, //! SgiTarget::List { //! affinity3: 0, @@ -39,6 +43,7 @@ //! affinity1: 0, //! target_list: 0b1, //! }, +//! SgiTargetGroup::CurrentGroup1, //! ); //! ``` From 679defdd597d25d81c65ec2b8f49ade6ebac6dc7 Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Wed, 16 Jul 2025 14:02:27 +0100 Subject: [PATCH 2/5] Provide fakes for irq_disable, irq_enable and wfi too. --- CHANGELOG.md | 4 ++++ src/lib.rs | 10 ++++++---- src/sysreg/fake.rs | 17 +++++++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d751fb1..7a302cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ - Fixed example in crate documentation. +### Improvements + +- Added fakes for `irq_disable`, `irq_enable` and `wfi`. + ## 0.5.0 ### Breaking changes diff --git a/src/lib.rs b/src/lib.rs index f7dfaf0..6495a8c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -58,8 +58,10 @@ mod sysreg; #[cfg(feature = "fakes")] pub use sysreg::fake as sysreg_fake; +#[cfg(feature = "fakes")] +pub use sysreg::fake::{irq_disable, irq_enable, wfi}; -#[cfg(target_arch = "aarch64")] +#[cfg(all(target_arch = "aarch64", not(feature = "fakes")))] use core::arch::asm; use core::fmt::{Debug, Formatter, Result}; @@ -241,7 +243,7 @@ impl From for u32 { } /// Disables debug, SError, IRQ and FIQ exceptions. -#[cfg(target_arch = "aarch64")] +#[cfg(all(target_arch = "aarch64", not(feature = "fakes")))] pub fn irq_disable() { // SAFETY: Writing to this system register doesn't access memory in any way. unsafe { @@ -250,7 +252,7 @@ pub fn irq_disable() { } /// Enables debug, SError, IRQ and FIQ exceptions. -#[cfg(target_arch = "aarch64")] +#[cfg(all(target_arch = "aarch64", not(feature = "fakes")))] pub fn irq_enable() { // SAFETY: Writing to this system register doesn't access memory in any way. unsafe { @@ -259,7 +261,7 @@ pub fn irq_enable() { } /// Waits for an interrupt. -#[cfg(target_arch = "aarch64")] +#[cfg(all(target_arch = "aarch64", not(feature = "fakes")))] pub fn wfi() { // SAFETY: This doesn't access memory in any way. unsafe { diff --git a/src/sysreg/fake.rs b/src/sysreg/fake.rs index 34d6d58..40b5622 100644 --- a/src/sysreg/fake.rs +++ b/src/sysreg/fake.rs @@ -26,6 +26,7 @@ pub struct SystemRegisters { pub icc_sgi0r_el1: u64, pub icc_sgi1r_el1: u64, pub icc_sre_el1: u32, + pub daif: u64, } impl SystemRegisters { @@ -45,6 +46,7 @@ impl SystemRegisters { icc_sgi0r_el1: 0, icc_sgi1r_el1: 0, icc_sre_el1: 0, + daif: 0, } } } @@ -77,3 +79,18 @@ macro_rules! write_sysreg64 { } }; } + +/// Disables debug, SError, IRQ and FIQ exceptions. +pub fn irq_disable() { + SYSREGS.lock().unwrap().daif = 0b11_1100_0000; +} + +/// Enables debug, SError, IRQ and FIQ exceptions. +pub fn irq_enable() { + SYSREGS.lock().unwrap().daif = 0; +} + +/// Waits for an interrupt. +pub fn wfi() { + // No-op, just return immediately. +} From f44bd6292b50c12ca12c550f32fc0f4796c0bb3c Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Wed, 16 Jul 2025 14:07:26 +0100 Subject: [PATCH 3/5] Test documentation in CI, with fakes. --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 76eb319..04d92ed 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -39,7 +39,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Test on host - run: cargo test --target=x86_64-unknown-linux-gnu --lib + run: cargo test --target=x86_64-unknown-linux-gnu --features=fakes format: runs-on: ubuntu-latest From 3db8751f545ffce7186e1f1aba0af580ff1b8e7e Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Thu, 17 Jul 2025 15:54:50 +0100 Subject: [PATCH 4/5] Stop setting target in cargo config.toml. This requires CI to choose an explicit target matching the host, which we don't want. --- .cargo/config.toml | 2 -- .github/workflows/rust.yml | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) delete mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml deleted file mode 100644 index 724feba..0000000 --- a/.cargo/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -[build] -target = "aarch64-unknown-none" diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 04d92ed..cd4803b 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -21,7 +21,7 @@ jobs: - armv7a-none-eabi steps: - uses: actions/checkout@v4 - - name: Install aarch64 toolchain + - name: Install ${{ matrix.target }} toolchain uses: actions-rs/toolchain@v1 with: toolchain: stable @@ -39,7 +39,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Test on host - run: cargo test --target=x86_64-unknown-linux-gnu --features=fakes + run: cargo test --features=fakes format: runs-on: ubuntu-latest From d1c4e19bae66b073bc82945ec40a7b641e8e37cf Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Thu, 17 Jul 2025 15:55:01 +0100 Subject: [PATCH 5/5] Run clippy for fakes too. --- .github/workflows/rust.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index cd4803b..07e7f96 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -35,11 +35,18 @@ jobs: args: --target ${{ matrix.target }} test: + permissions: + checks: write runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Test on host run: cargo test --features=fakes + - name: Run clippy + uses: actions-rs/clippy-check@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + args: --features=fakes format: runs-on: ubuntu-latest