-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for starting cores with PSCI #169
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1e4537a
Register secondary cores
PandaZ3D 71ddd31
Add machine specific boot module
PandaZ3D d564a78
Add PSCI support to turn on cores
PandaZ3D b583fb5
Only call `init_secondary` for secondary cores
PandaZ3D e68643c
Make `Mutex` only call scheduler if there is a current thread
PandaZ3D 16b6a82
Make cores spin and wait
PandaZ3D 2208089
Cleanup test code and unnecessary logs
PandaZ3D d7eba7c
Add PSCI documentation
PandaZ3D File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/// The method of starting a CPU on ARM devices is machine specific | ||
/// and usually implemented by the firmware. | ||
|
||
mod psci; | ||
|
||
use core::str::FromStr; | ||
|
||
use arm64::registers::{PAR_EL1, Readable}; | ||
|
||
use twizzler_abi::upcall::MemoryAccessKind; | ||
|
||
use crate::memory::{VirtAddr, PhysAddr}; | ||
|
||
/// Possible boot protocols used to start a CPU. | ||
#[derive(Debug, Default, Copy, Clone, PartialEq)] | ||
pub enum BootMethod { | ||
Psci, | ||
SpinTable, | ||
#[default] | ||
Unknown, | ||
} | ||
|
||
impl BootMethod { | ||
fn as_str(&self) -> &'static str { | ||
match self { | ||
Self::Psci => "psci", | ||
Self::SpinTable => "spintable", | ||
Self::Unknown => "unknown", | ||
} | ||
} | ||
} | ||
|
||
impl FromStr for BootMethod { | ||
type Err = (); | ||
|
||
// Required method | ||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
match s { | ||
"psci" => Ok(BootMethod::Psci), | ||
"spin-table" => Ok(BootMethod::SpinTable), | ||
_ => Err(()) | ||
} | ||
} | ||
} | ||
|
||
/// The arguments needed to start a CPU. | ||
#[derive(Debug, Default, Copy, Clone)] | ||
pub struct BootArgs { | ||
/// System-wide ID of this CPU core | ||
cpu: u32, | ||
/// TCB base use for TLS data | ||
tcb_base: u64, | ||
/// The stack of this kernel thread | ||
kernel_stack: u64, | ||
/// The entry point of this CPU core | ||
entry: u64, | ||
// system register state used to start core | ||
mair: u64, | ||
ttbr1: u64, | ||
ttbr0: u64, | ||
tcr: u64, | ||
sctlr: u64, | ||
spsr: u64, | ||
cpacr: u64, | ||
} | ||
|
||
/// Start up a CPU. | ||
/// # Safety | ||
/// The tcb_base and kernel stack must both be valid memory regions for each thing. | ||
pub unsafe fn poke_cpu(cpu: u32, tcb_base: VirtAddr, kernel_stack: *mut u8) { | ||
let core = unsafe { | ||
crate::processor::get_processor_mut(cpu) | ||
}; | ||
|
||
match core.arch.boot { | ||
BootMethod::Psci => psci::boot_core(core, tcb_base, kernel_stack), | ||
_ => unimplemented!("boot method: {}", core.arch.boot.as_str()) | ||
} | ||
} | ||
|
||
// Translate a virtual to a physical address if it is mapped in with the desired access rights | ||
fn translate(va: VirtAddr, access: MemoryAccessKind) -> Option<PhysAddr> { | ||
if !va.is_kernel() { | ||
unimplemented!("address is in user memory: {:?}", va) | ||
} | ||
unsafe { | ||
// AT <operation>, <Xt> | ||
// <operation>: <stage><level><r/w> | ||
// - S1,E1,R/W (stage 1, EL1, R or Write) | ||
// <Xt>: address | ||
match access { | ||
MemoryAccessKind::Read => core::arch::asm!( | ||
"AT S1E1R, {}", | ||
in(reg) va.raw(), | ||
options(nostack, nomem), | ||
), | ||
// given the way address translation works | ||
// writeable implies readable ... | ||
MemoryAccessKind::Write => core::arch::asm!( | ||
"AT S1E1W, {}", | ||
in(reg) va.raw(), | ||
options(nostack, nomem), | ||
), | ||
_ => unimplemented!("translation for {:?}", access) | ||
} | ||
} | ||
// PAR_EL1 holds result of AT instruction | ||
// - FST: fault status info | ||
// - PA: output address | ||
if PAR_EL1.matches_all(PAR_EL1::F::TranslationSuccessfull) { | ||
let pa = unsafe { | ||
// PAR_EL1.PA returns bits 47:12 | ||
let base_phys = PAR_EL1.read(PAR_EL1::PA) << 12; | ||
// the lower 12 bit offset resides in the VA | ||
let block_offset = va.raw() & 0xFFF; | ||
PhysAddr::new_unchecked(base_phys | block_offset) | ||
}; | ||
return Some(pa) | ||
} | ||
None | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the todo!() was removed is this still a TODO?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so.
wfe
puts the core in some low power state (standby), but PSCI gives more control to put the core in different power level states (e.g., retention).