Skip to content

Commit baac36e

Browse files
committed
[wip] add ipi for x86_64
1 parent 1631f66 commit baac36e

File tree

17 files changed

+102
-34
lines changed

17 files changed

+102
-34
lines changed

Cargo.lock

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/arceos_api/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,4 @@ axdriver = { workspace = true, optional = true }
4343
axfs = { workspace = true, optional = true }
4444
axnet = { workspace = true, optional = true }
4545
axdisplay = { workspace = true, optional = true }
46+
axipi = { workspace = true }

api/arceos_api/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ pub mod modules {
391391
pub use axlog;
392392
pub use axruntime;
393393
pub use axsync;
394+
pub use axipi;
394395

395396
#[cfg(feature = "alloc")]
396397
pub use axalloc;

api/axfeat/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fp_simd = ["axhal/fp_simd"]
2020

2121
# Interrupts
2222
irq = ["axhal/irq", "axruntime/irq", "axtask?/irq"]
23-
ipi = ["axruntime/ipi"]
23+
ipi = ["axhal/ipi", "axruntime/ipi"]
2424

2525
# Memory
2626
alloc = ["axalloc", "axruntime/alloc"]
@@ -58,7 +58,7 @@ driver-ixgbe = ["axdriver?/ixgbe"]
5858
driver-bcm2835-sdhci = ["axdriver?/bcm2835-sdhci"]
5959

6060
#Hypervisor support
61-
hv = ["axhal/hv"]
61+
hv = ["axhal/hv", "ipi"]
6262

6363
# Logging
6464
log-level-off = ["axlog/log-level-off"]

modules/axhal/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ repository = "https://github.com/arceos-org/arceos/tree/main/modules/axhal"
1010
documentation = "https://arceos-org.github.io/arceos/axhal/index.html"
1111

1212
[features]
13-
smp = ["dep:cpumask"]
13+
smp = []
1414
alloc = []
1515
fp_simd = []
1616
paging = ["axalloc", "page_table_multiarch"]
@@ -19,6 +19,7 @@ tls = ["alloc"]
1919
rtc = ["x86_rtc", "riscv_goldfish", "arm_pl031"]
2020
default = []
2121
hv = ["paging", "cortex-a", "percpu/arm-el2", "page_table_entry/arm-el2", "arm_gicv2/el2", "dep:crate_interface"]
22+
ipi = []
2223

2324
[dependencies]
2425
log = "=0.4.21"
@@ -56,7 +57,7 @@ riscv_goldfish = { version = "0.1", optional = true }
5657
[target.'cfg(target_arch = "aarch64")'.dependencies]
5758
aarch64-cpu = "9.4"
5859
tock-registers = "0.8"
59-
arm_gicv2 = { git = "https://github.com/arceos-hypervisor/arm_gicv2" }
60+
arm_gicv2 = { git = "https://github.com/arceos-hypervisor/arm_gicv2", branch = "sgi" }
6061
crate_interface = { version = "0.1.3", optional = true }
6162
arm_pl011 = "0.1"
6263
arm_pl031 = { version = "0.2", optional = true }

modules/axhal/src/irq.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ use handler_table::HandlerTable;
55
use crate::platform::irq::{dispatch_irq, MAX_IRQ_COUNT};
66
use crate::trap::{register_trap_handler, IRQ};
77

8-
pub use crate::platform::irq::{register_handler, set_enable, IPI_IRQ_NUM};
8+
pub use crate::platform::irq::{register_handler, set_enable};
9+
10+
#[cfg(feature = "ipi")]
11+
pub use crate::platform::irq::{send_sgi_all, send_sgi_one, IPI_IRQ_NUM};
912

1013
#[cfg(target_arch = "aarch64")]
1114
pub use crate::platform::irq::fetch_irq;

modules/axhal/src/platform/aarch64_common/gic.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,18 @@ pub fn set_enable(irq_num: usize, enabled: bool) {
4040
/// It also enables the IRQ if the registration succeeds. It returns `false` if
4141
/// the registration failed.
4242
pub fn register_handler(irq_num: usize, handler: IrqHandler) -> bool {
43-
trace!("register handler irq {}", irq_num);
43+
warn!("register handler irq {}", irq_num);
4444
crate::irq::register_handler_common(irq_num, handler)
4545
}
4646

47-
/// Sends Software Generated Interrupt (SGI)(s) (usually IPI) to the given CPUs.
48-
#[cfg(feature = "smp")]
49-
pub fn send_sgi(cpu_if: usize, irq_num: usize) {
50-
GICD.lock().send_sgi(cpu_if, irq_num);
47+
/// Sends Software Generated Interrupt (SGI)(s) (usually IPI) to the given dest CPU.
48+
pub fn send_sgi_one(dest_cpu_id: usize, irq_num: usize) {
49+
GICD.lock().send_sgi(dest_cpu_id, irq_num);
50+
}
51+
52+
/// Sends a broadcast IPI to all CPUs.
53+
pub fn send_sgi_all(irq_num: usize) {
54+
GICD.lock().send_sgi_all_except_self(irq_num);
5155
}
5256

5357
/// Fetches the IRQ number.

modules/axhal/src/platform/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ cfg_if::cfg_if! {
2626
mod aarch64_rk3588j;
2727
pub use self::aarch64_rk3588j::*;
2828
} else {
29-
// mod dummy;
30-
// pub use self::dummy::*;
31-
mod aarch64_qemu_virt;
32-
pub use self::aarch64_qemu_virt::*;
29+
mod dummy;
30+
pub use self::dummy::*;
31+
// mod aarch64_qemu_virt;
32+
// pub use self::aarch64_qemu_virt::*;
3333
}
3434
}

modules/axhal/src/platform/x86_pc/apic.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub(super) mod vectors {
1414
pub const APIC_TIMER_VECTOR: u8 = 0xf0;
1515
pub const APIC_SPURIOUS_VECTOR: u8 = 0xf1;
1616
pub const APIC_ERROR_VECTOR: u8 = 0xf2;
17+
pub const APIC_IPI_VECTOR: u8 = 0xf2;
1718
}
1819

1920
/// The maximum number of IRQs.
@@ -22,6 +23,9 @@ pub const MAX_IRQ_COUNT: usize = 256;
2223
/// The timer IRQ number.
2324
pub const TIMER_IRQ_NUM: usize = APIC_TIMER_VECTOR as usize;
2425

26+
/// The IPI IRQ number.
27+
pub const IPI_IRQ_NUM: usize = APIC_IPI_VECTOR as usize;
28+
2529
const IO_APIC_BASE: PhysAddr = pa!(0xFEC0_0000);
2630

2731
static mut LOCAL_APIC: Option<LocalApic> = None;
@@ -52,6 +56,21 @@ pub fn register_handler(vector: usize, handler: crate::irq::IrqHandler) -> bool
5256
crate::irq::register_handler_common(vector, handler)
5357
}
5458

59+
/// Sends Software Generated Interrupt (SGI)(s) (usually IPI) to the given dest CPU.
60+
pub fn send_sgi_one(dest_cpu_id: usize, irq_num: usize) {
61+
unsafe {
62+
local_apic().send_ipi(irq_num as _, dest_cpu_id as _);
63+
};
64+
}
65+
66+
/// Sends a broadcast IPI to all CPUs.
67+
pub fn send_sgi_all(irq_num: usize) {
68+
use x2apic::lapic::IpiAllShorthand;
69+
unsafe {
70+
local_apic().send_ipi_all(irq_num as _, IpiAllShorthand::AllExcludingSelf);
71+
};
72+
}
73+
5574
/// Dispatches the IRQ.
5675
///
5776
/// This function is called by the common interrupt handler. It looks

modules/axipi/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ percpu = { version = "0.1.5" }
2020
kspin = { version = "0.1" }
2121

2222
axhal = { workspace = true }
23+
axconfig = { workspace = true }

0 commit comments

Comments
 (0)