Skip to content

Commit b06c6e7

Browse files
committed
smp
1 parent 40876c3 commit b06c6e7

File tree

9 files changed

+194
-215
lines changed

9 files changed

+194
-215
lines changed

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

platforms/axplat-aarch64-dyn/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ smp = ["axplat/smp"]
1515

1616
[dependencies]
1717
aarch64-cpu = "10"
18+
aarch64-cpu-ext = "0.1"
1819
any-uart = "0.2.11"
1920
axconfig-macros = "0.2"
2021
axcpu = {workspace = true}

platforms/axplat-aarch64-dyn/src/cache.rs

Lines changed: 0 additions & 159 deletions
This file was deleted.
Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
1-
use core::ops::Deref;
2-
31
use pie_boot::boot_info;
4-
pub use rdrive::probe_all;
5-
use rdrive::{
6-
Platform, init, probe_pre_kernel,
7-
register::{DriverRegister, DriverRegisterSlice},
8-
register_append,
9-
};
2+
use rdrive::{Platform, init, probe_pre_kernel};
103

114
pub fn setup() {
125
let fdt = boot_info().fdt.expect("FDT must be present");
@@ -15,22 +8,3 @@ pub fn setup() {
158

169
probe_pre_kernel().unwrap();
1710
}
18-
19-
fn driver_registers() -> impl Deref<Target = [DriverRegister]> {
20-
unsafe extern "C" {
21-
fn __sdriver_register();
22-
fn __edriver_register();
23-
}
24-
25-
unsafe {
26-
let len = __edriver_register as usize - __sdriver_register as usize;
27-
28-
if len == 0 {
29-
return DriverRegisterSlice::empty();
30-
}
31-
32-
let data = core::slice::from_raw_parts(__sdriver_register as _, len);
33-
34-
DriverRegisterSlice::from_raw(data)
35-
}
36-
}

platforms/axplat-aarch64-dyn/src/init.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
use aarch64_cpu_ext::cache::{CacheOp, dcache_all};
12
use axplat::init::InitIf;
23

3-
use crate::{cache, console, driver};
4+
use crate::{console, driver};
45

56
struct InitIfImpl;
67

@@ -30,7 +31,7 @@ impl InitIf for InitIfImpl {
3031
/// * Exception & interrupt handlers are set up.
3132
/// * Early console is initialized.
3233
/// * Current monotonic time and wall time can be obtained.
33-
fn init_early(cpu_id: usize, arg: usize) {
34+
fn init_early(_cpu_id: usize, _arg: usize) {
3435
axcpu::init::init_trap();
3536
crate::mem::setup();
3637
console::setup_early();
@@ -40,7 +41,7 @@ impl InitIf for InitIfImpl {
4041
///
4142
/// See [`init_early`] for details.
4243
#[cfg(feature = "smp")]
43-
fn init_early_secondary(cpu_id: usize) {
44+
fn init_early_secondary(_cpu_id: usize) {
4445
axcpu::init::init_trap();
4546
}
4647

@@ -68,8 +69,10 @@ impl InitIf for InitIfImpl {
6869
/// * Interrupt controller is initialized (if applicable).
6970
/// * Timer interrupts are enabled (if applicable).
7071
/// * Other platform devices are initialized.
71-
fn init_later(cpu_id: usize, arg: usize) {
72-
unsafe { cache::dcache_all(cache::DcacheOp::CleanAndInvalidate) };
72+
fn init_later(_cpu_id: usize, _arg: usize) {
73+
dcache_all(CacheOp::CleanAndInvalidate);
74+
#[cfg(feature = "smp")]
75+
crate::smp::init();
7376
driver::setup();
7477
#[cfg(feature = "irq")]
7578
{
@@ -83,8 +86,8 @@ impl InitIf for InitIfImpl {
8386
///
8487
/// See [`init_later`] for details.
8588
#[cfg(feature = "smp")]
86-
fn init_later_secondary(cpu_id: usize) {
87-
unsafe { cache::dcache_all(cache::DcacheOp::CleanAndInvalidate) };
89+
fn init_later_secondary(_cpu_id: usize) {
90+
dcache_all(CacheOp::CleanAndInvalidate);
8891
#[cfg(feature = "irq")]
8992
{
9093
crate::irq::init_current_cpu();

platforms/axplat-aarch64-dyn/src/irq.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub(crate) fn init_current_cpu() {
8585
let mut cpu_if = intc.lock().unwrap().cpu_local().unwrap();
8686
cpu_if.open().unwrap();
8787
cpu_if.set_eoi_mode(true);
88-
CPU_IF.init_once(cpu_if);
88+
CPU_IF.call_once(move || cpu_if);
8989
debug!("GIC initialized for current CPU");
9090
}
9191

@@ -97,11 +97,7 @@ fn current_cpu() -> usize {
9797
MPIDR_EL1.get() as usize & 0xffffff
9898
}
9999

100-
pub(crate) fn set_enable(
101-
irq_raw: usize,
102-
trigger: Option<Trigger>,
103-
enabled: bool,
104-
) {
100+
pub(crate) fn set_enable(irq_raw: usize, trigger: Option<Trigger>, enabled: bool) {
105101
debug!(
106102
"IRQ({:#x}) set enable: {}, {}",
107103
irq_raw,
@@ -131,7 +127,7 @@ pub(crate) fn set_enable(
131127
if !is_irq_private(irq_raw) {
132128
// For private IRQs, we need to acknowledge the interrupt
133129
// controller.
134-
intc.set_target_cpu(irq, current_cpu().into());
130+
intc.set_target_cpu(irq, current_cpu().into()).unwrap();
135131
}
136132

137133
if let Some(t) = trigger {

platforms/axplat-aarch64-dyn/src/lib.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
extern crate axplat;
66
extern crate alloc;
77

8+
use core::ptr::NonNull;
9+
10+
use axplat::mem::phys_to_virt;
11+
use fdt_parser::Fdt;
812
use pie_boot::BootInfo;
913

1014
mod console;
@@ -14,8 +18,9 @@ mod init;
1418
mod irq;
1519
mod mem;
1620
mod power;
21+
#[cfg(feature = "smp")]
22+
mod smp;
1723
mod time;
18-
mod cache;
1924

2025
pub mod config {
2126
axconfig_macros::include_configs!(path_env = "AX_CONFIG_PATH", fallback = "axconfig.toml");
@@ -25,3 +30,12 @@ pub mod config {
2530
fn main(args: &BootInfo) -> ! {
2631
axplat::call_main(0, args.fdt.map(|p| p.as_ptr() as usize).unwrap_or_default());
2732
}
33+
34+
fn fdt() -> Fdt<'static> {
35+
let paddr = pie_boot::boot_info()
36+
.fdt
37+
.expect("FDT is not available, please check the bootloader configuration");
38+
let addr = phys_to_virt((paddr.as_ptr() as usize).into());
39+
40+
Fdt::from_ptr(NonNull::new(addr.as_mut_ptr()).unwrap()).expect("Failed to parse FDT")
41+
}

platforms/axplat-aarch64-dyn/src/power.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,18 @@ impl PowerIf for PowerImpl {
2020
/// Where `cpu_id` is the logical CPU ID (0, 1, ..., N-1, N is the number of
2121
/// CPU cores on the platform).
2222
#[cfg(feature = "smp")]
23-
fn cpu_boot(cpu_id: usize, stack_top_paddr: usize) {
24-
todo!()
23+
fn cpu_boot(cpu_idx: usize, stack_top_paddr: usize) {
24+
use aarch64_cpu_ext::cache::{CacheOp, dcache_all};
25+
use log::info;
26+
27+
let cpu_id = crate::smp::cpu_idx_to_id(cpu_idx);
28+
let entry = crate::smp::secondary_entry_phys_addr();
29+
info!(
30+
"booting CPU {cpu_id} with entry {:#x} and stack top {:#x}",
31+
entry, stack_top_paddr
32+
);
33+
dcache_all(CacheOp::CleanAndInvalidate);
34+
cpu_on(cpu_id as _, entry.as_usize() as _, stack_top_paddr as _).unwrap();
2535
}
2636

2737
/// Shutdown the whole system.
@@ -82,15 +92,11 @@ fn probe(fdt: FdtInfo<'_>, _dev: PlatformDevice) -> Result<(), OnProbeError> {
8292
Ok(())
8393
}
8494

85-
// fn cpu_on(
86-
// cpu_id: CpuId,
87-
// entry: usize,
88-
// stack_top: PhysAddr,
89-
// ) -> Result<(), alloc::boxed::Box<dyn Error>> {
90-
// let method = *METHOD;
91-
// match method {
92-
// Method::Smc => psci::cpu_on::<Smc>(cpu_id.raw() as _, entry as _, stack_top.raw() as _)?,
93-
// Method::Hvc => psci::cpu_on::<Hvc>(cpu_id.raw() as _, entry as _, stack_top.raw() as _)?,
94-
// };
95-
// Ok(())
96-
// }
95+
fn cpu_on(cpu_id: u64, entry: u64, stack_top: u64) -> Result<(), alloc::boxed::Box<dyn Error>> {
96+
let method = METHOD.wait();
97+
match method {
98+
Method::Smc => psci::cpu_on::<Smc>(cpu_id, entry, stack_top)?,
99+
Method::Hvc => psci::cpu_on::<Hvc>(cpu_id, entry, stack_top)?,
100+
};
101+
Ok(())
102+
}

0 commit comments

Comments
 (0)