Repository navigation
refactor(aarch64): decode PSCI calls into an enum - #446
mango-duck wants to merge 1 commit into
Conversation
5f23c0c to
fb29178
Compare
|
Thanks for the PR. The refactor itself looks well thoughout. One thing I'd like to raise: the PR description looks like it was generated with AI assistance, and the line breaks are off. I'm not against using AI to help draft descriptions, but the PR description is one of our main channels of communication — for reviewers now, and for anyone reading the history later. So it deserves the same care as the code: please re-read it and fix the wrapping, and make sure the wording actually reflects what the diff does. |
Decode the function ID into a PsciCall enum variant that carries its arguments, then dispatch on the variant exhaustively, so a missing arm breaks the build. Argument layout is now visible in the type. SYSTEM_RESET/SYSTEM_OFF move into standalone functions.
fb29178 to
a98d4be
Compare
|
Thanks for catching that. I’ve rewritten the description and re-wrapped the lines — the wording now matches what the diff actually does. |
|
Thanks for following up on #441! Looking at the two-step We can make this much leaner and safer at the same time:
Rough sketch: use smccc::{error::SUCCESS, psci::{self, *}};
struct ZoneCpuId(usize);
impl TryFrom<u64> for ZoneCpuId {
type Error = psci::Error;
fn try_from(mpidr: u64) -> Result<Self, Self::Error> {
if mpidr & !MPIDR_MASK != 0 {
return Err(Error::InvalidParameters);
}
let cpu = try_mpidr_to_cpuid(mpidr).ok_or(Error::InvalidParameters)?;
this_zone().read().cpu_set().contains_cpu(cpu)
.then_some(Self(cpu))
.ok_or(Error::InvalidParameters)
}
}
struct AffinityLevel(LowestAffinityLevel);
impl TryFrom<u64> for AffinityLevel {
type Error = psci::Error;
fn try_from(raw: u64) -> Result<Self, Self::Error> {
(raw == 0).then_some(Self(LowestAffinityLevel::All)).ok_or(Error::InvalidParameters)
}
}
fn psci_emulate_cpu_on(cpu: ZoneCpuId, entry: GuestPhysAddr, _ctx: u64) -> Result<u64, psci::Error> { ... }
fn psci_affinity_info(cpu: ZoneCpuId, _level: AffinityLevel) -> Result<u64, psci::Error> { ... }
fn handle_psci_smc(func_id: u32, arg0: u64, arg1: u64, arg2: u64) -> Result<u64, psci::Error> {
// check or conversion?
match func_id {
PSCI_VERSION => Ok(u32::from(Version { major: 1, minor: 1 }) as u64),
PSCI_CPU_SUSPEND_32 | PSCI_CPU_SUSPEND_64 => psci_cpu_suspend(arg0 as u32, arg1 as _, arg2),
PSCI_CPU_OFF => todo!(),
PSCI_CPU_ON_32 | PSCI_CPU_ON_64 => psci_emulate_cpu_on(arg0.try_into()?, arg1 as _, arg2),
PSCI_AFFINITY_INFO_32 | PSCI_AFFINITY_INFO_64 => {
psci_affinity_info(arg0.try_into()?, arg1.try_into()?)
}
PSCI_MIGRATE_INFO_TYPE => Ok(MigrateType::MigrationNotRequired as u64),
PSCI_FEATURES => psci_emulate_features_info(arg0 as u32),
PSCI_SYSTEM_RESET => psci_system_reset(),
PSCI_SYSTEM_OFF => psci_system_off(),
_ => Err(Error::NotSupported),
}
} |
Summary
Split the PSCI path into a decode step and an execution step. The incoming function ID is decoded into an enum value, one variant per supported call, with the call's arguments carried along; execution then dispatches on the variant.
The argument layout is now visible in the type, not inferred from register reads. Execution has to handle every variant, so a missing arm breaks the build.
Motivation
Follow-up to the review in #441, which suggested an enum-based decoder so that missed PSCI calls become compile errors. The old PSCI code had two problems:
Verification
Passed:
Risks and Limitations