refactor(soc-data): define the Apple MPIDR and L2 cache decode once
This commit is contained in:
1 parent
d686fc7219
commit
bc050eec2b
12 files changed
+71
-59
No files matched your search
@@ -158,6 +158,21 @@ impl Caches {
|
||||
pub fn ccsidr(&self, csselr: u64) -> u64 {
|
||||
u64::from(self.ccsidr[(csselr & SELECTION) as usize])
|
||||
}
|
||||
|
||||
/// The geometry `selection`'s CCSIDR_EL1 reports, as `do_cacheid`
|
||||
/// decodes it: line 16 << LineSize, NumSets + 1 sets and
|
||||
/// Associativity + 1 ways.
|
||||
pub fn cache(&self, selection: CacheSelection) -> Cache {
|
||||
let value = self.ccsidr[selection as usize];
|
||||
let line = 16 << (value & 7);
|
||||
let ways = (value >> ASSOCIATIVITY & (MAX_WAYS - 1)) + 1;
|
||||
let sets = (value >> NUM_SETS & (MAX_SETS - 1)) + 1;
|
||||
Cache {
|
||||
bytes: sets * ways * line,
|
||||
ways,
|
||||
line,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -194,6 +209,12 @@ mod tests {
|
||||
assert_eq!(decode(caches.ccsidr(0)), (128, 128, 8));
|
||||
assert_eq!(decode(caches.ccsidr(1)), (128, 256, 6));
|
||||
assert_eq!(decode(caches.ccsidr(2)), (128, 8192, 16));
|
||||
assert_eq!(caches.cache(CacheSelection::L1Data), cache(128 << 10, 8));
|
||||
assert_eq!(
|
||||
caches.cache(CacheSelection::L1Instruction),
|
||||
cache(192 << 10, 6)
|
||||
);
|
||||
assert_eq!(caches.cache(CacheSelection::L2Unified), cache(16 << 20, 16));
|
||||
// TnD is outside the selection; absent caches read 0.
|
||||
assert_eq!(caches.ccsidr(0x10), caches.ccsidr(0));
|
||||
assert_eq!(caches.ccsidr(3), 0);
|
||||
|
||||
@@ -40,6 +40,7 @@ use alloc::{collections::BTreeMap, format, string::String, vec::Vec};
|
||||
use stela_contracts::refuse;
|
||||
use {stela_contracts::adt::Node, stela_contracts::identity::Identity};
|
||||
|
||||
pub mod mpidr;
|
||||
pub mod t6000_pmgr;
|
||||
|
||||
mod apertures;
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
//! The MPIDR_EL1 identity of an Apple PE, the same on every SoC. XNU
|
||||
//! xnu-12377.121.6 apple_arm64_regs.h:102–107 defines MPIDR_CORETYPE at
|
||||
//! bits 18:16 (E=0, P=1, M=4); Aff1 and Aff0 are the DeviceTree `reg`'s
|
||||
//! physical cluster and core, so core type never creates another cluster.
|
||||
|
||||
/// The `reg` bits MPIDR_EL1 carries: Aff1 and Aff0.
|
||||
pub const CLUSTER_CORE: u32 = 0xffff;
|
||||
pub const CORETYPE_MASK: u8 = 7;
|
||||
pub const CORETYPE_SHIFT: u32 = 16;
|
||||
const RES1: u64 = 1 << 31;
|
||||
|
||||
/// The MPIDR_EL1 of core type `coretype` at `reg`, or `None` for an
|
||||
/// out-of-field core type or undeclared `reg` bits.
|
||||
pub const fn compose(coretype: u8, reg: u32) -> Option<u64> {
|
||||
if coretype & !CORETYPE_MASK != 0 || reg & !CLUSTER_CORE != 0 {
|
||||
return None;
|
||||
}
|
||||
Some(RES1 | (coretype as u64) << CORETYPE_SHIFT | reg as u64)
|
||||
}
|
||||
|
||||
/// MPIDR_EL1's core type.
|
||||
pub const fn coretype(mpidr: u64) -> u8 {
|
||||
(mpidr >> CORETYPE_SHIFT) as u8 & CORETYPE_MASK
|
||||
}
|
||||
@@ -80,8 +80,6 @@ const PERF_DOMAIN_BYTES: usize = 28;
|
||||
const DEVICE_BYTES: usize = 48;
|
||||
const DOMAIN_LIMIT: usize = 48;
|
||||
const VIRTUAL: u8 = 1 << 4;
|
||||
const PHYSICAL_AFFINITY: u64 = 0xffff;
|
||||
const CORETYPE_SHIFT: u32 = 16;
|
||||
|
||||
type Error = CpuAssociationError;
|
||||
|
||||
@@ -223,10 +221,8 @@ fn topology(
|
||||
}
|
||||
let kind = required(node, "cluster-type")?;
|
||||
let expected_kind = if complex == 0 { b"E\0" } else { b"P\0" };
|
||||
let expected_aff2 = complex as u64;
|
||||
if kind != expected_kind
|
||||
|| identity.mpidr & PHYSICAL_AFFINITY != u64::from(reg)
|
||||
|| identity.mpidr != (0x8000_0000 | expected_aff2 << CORETYPE_SHIFT | u64::from(reg))
|
||||
|| crate::board::mpidr::compose(complex as u8, reg) != Some(identity.mpidr)
|
||||
{
|
||||
return Err(Error::Topology(
|
||||
"CPU profile differs from original affinity",
|
||||
|
||||
@@ -12,7 +12,6 @@ const T6000_KERNEL_MAX_CLUSTERS: usize = 6;
|
||||
const T6000_KERNEL_MAX_PHYSICAL_CLUSTER: u32 = 10;
|
||||
const AFFINITY_PART_MASK: u32 = 0xff;
|
||||
const CLUSTER_SHIFT: u32 = 8;
|
||||
const MPIDR_RES1: u64 = 1 << 31;
|
||||
const ENABLE_CORE_SELECTOR: u32 = 0x436f_7265;
|
||||
|
||||
pub(super) const EVIDENCE: &str = "26A434 mac13j SHA256 5109fca5209bdbb89cec29e3241cc42a90418cb737d65e31962b059b9879af90; mode1 complex2b16e08/core2b190e4/skip2b19918, enable2b2dcb0; cpu/t6000-core-membership-r1 source receipt";
|
||||
@@ -59,7 +58,7 @@ pub(super) fn resolve(
|
||||
for (pe, (node, identity)) in nodes.iter().zip(processors).enumerate() {
|
||||
let reg = word(required(node, "reg")?)?;
|
||||
let aff1 = (reg >> CLUSTER_SHIFT) as usize;
|
||||
if u64::from(reg) & !PHYSICAL_AFFINITY != 0
|
||||
if reg & !crate::board::mpidr::CLUSTER_CORE != 0
|
||||
|| reg >> CLUSTER_SHIFT > T6000_KERNEL_MAX_PHYSICAL_CLUSTER
|
||||
{
|
||||
return Err(Error::Topology("T6000 physical affinity"));
|
||||
@@ -96,7 +95,7 @@ pub(super) fn resolve(
|
||||
|| word(required(node, "die-id")?)? != 0
|
||||
|| word(required(node, "die-cluster-id")?)? as usize != aff1
|
||||
|| word(required(node, "cluster-core-id")?)? != reg & AFFINITY_PART_MASK
|
||||
|| identity.mpidr != (MPIDR_RES1 | (aff2 << CORETYPE_SHIFT) | u64::from(reg))
|
||||
|| crate::board::mpidr::compose(aff2, reg) != Some(identity.mpidr)
|
||||
{
|
||||
return Err(Error::Topology("T6000 source/profile coordinate mismatch"));
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ impl Fixture {
|
||||
]);
|
||||
identities.push(Identity {
|
||||
midr: 0, // MPIDR membership alone is under test.
|
||||
mpidr: 0x8000_0000 | (complex as u64) << CORETYPE_SHIFT | u64::from(reg),
|
||||
mpidr: crate::board::mpidr::compose(complex as u8, reg).unwrap(),
|
||||
clock: None,
|
||||
caches: None,
|
||||
});
|
||||
@@ -449,7 +449,7 @@ fn adt_and_live_profile_affinities_must_agree_for_every_pe() {
|
||||
for mutation in 0..7 {
|
||||
let mut f = Fixture::new();
|
||||
match mutation {
|
||||
0 => f.identities[7].mpidr ^= 1 << CORETYPE_SHIFT,
|
||||
0 => f.identities[7].mpidr ^= 1 << crate::board::mpidr::CORETYPE_SHIFT,
|
||||
1 => f.identities[7].mpidr ^= 1 << 8,
|
||||
2 => {
|
||||
f.identities.pop();
|
||||
|
||||
@@ -98,15 +98,7 @@ impl CoreType {
|
||||
/// creates another physical cluster. Returns `None` for an unknown
|
||||
/// mapping, out-of-field core type or undeclared `reg` bits.
|
||||
pub fn mpidr(&self, reg: u32) -> Option<u64> {
|
||||
// XNU xnu-12377.121.6 apple_arm64_regs.h:102–107 defines
|
||||
// MPIDR_CORETYPE at bits 18:16, E=0, P=1, M=4.
|
||||
const CORETYPE_MASK: u8 = 7;
|
||||
const CORETYPE_SHIFT: u32 = 16;
|
||||
let aff2 = self.mpidr_aff2?;
|
||||
if aff2 & !CORETYPE_MASK != 0 || reg & !MPIDR_CLUSTER_CORE != 0 {
|
||||
return None;
|
||||
}
|
||||
Some(0x8000_0000 | u64::from(aff2) << CORETYPE_SHIFT | u64::from(reg))
|
||||
super::mpidr::compose(self.mpidr_aff2?, reg)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -417,9 +409,6 @@ pub struct Processor {
|
||||
/// (its template's `reg` 0x1000 to 0x1205; XNU's T6050
|
||||
/// `MAX_CPU_CLUSTER_PHY_ID` is 18). Each chip's kernel limits bound the
|
||||
/// cluster numbers further. A `reg` beyond Aff1 and Aff0 refuses.
|
||||
/// The `reg` bits a `/cpus` node may set: Aff1 and Aff0.
|
||||
const MPIDR_CLUSTER_CORE: u32 = 0xffff;
|
||||
|
||||
pub fn cpus(chip_id: u32, soc_name: &str, processors: &[Processor]) -> Result<Cpus> {
|
||||
let rows: Vec<&Soc> = SOCS.iter().filter(|soc| soc.chip_id == chip_id).collect();
|
||||
if rows.is_empty() {
|
||||
@@ -463,7 +452,7 @@ pub fn cpus(chip_id: u32, soc_name: &str, processors: &[Processor]) -> Result<Cp
|
||||
)
|
||||
})?;
|
||||
let core = core.expect("a part requires a core descriptor");
|
||||
if processor.reg & !MPIDR_CLUSTER_CORE != 0 {
|
||||
if processor.reg & !super::mpidr::CLUSTER_CORE != 0 {
|
||||
return Err(refuse!(
|
||||
"{name} cpu reg {reg:#x} has no public MPIDR mapping",
|
||||
name = soc.name,
|
||||
|
||||
@@ -249,13 +249,13 @@ mod tests {
|
||||
// core type. The M affinity must not split this shared P/M L2.
|
||||
for (pe, mpidr) in processors.iter().zip(&mpidrs) {
|
||||
assert_eq!(
|
||||
(*mpidr >> 16) & 7,
|
||||
u64::from(match pe.cluster_type {
|
||||
b'E' => 0u8,
|
||||
crate::board::mpidr::coretype(*mpidr),
|
||||
match pe.cluster_type {
|
||||
b'E' => 0,
|
||||
b'P' => 1,
|
||||
b'M' => 4,
|
||||
_ => unreachable!(),
|
||||
})
|
||||
}
|
||||
);
|
||||
assert_eq!((*mpidr >> 8) & 0xf, u64::from(pe.reg >> 8));
|
||||
assert_eq!(*mpidr & 0xff, u64::from(pe.reg & 0xff));
|
||||
|
||||
@@ -8,16 +8,13 @@ pub use source::{BspSource, SourceIdentity};
|
||||
use crate::pmgr::coverage::DomainId;
|
||||
use alloc::{collections::BTreeSet, sync::Arc, vec::Vec};
|
||||
use {
|
||||
stela_contracts::Chip, stela_contracts::caches::Cache, stela_contracts::caches::Caches,
|
||||
stela_contracts::identity::Identity,
|
||||
stela_contracts::Chip, stela_contracts::caches::Cache, stela_contracts::caches::CacheSelection,
|
||||
stela_contracts::caches::Caches, stela_contracts::identity::Identity,
|
||||
};
|
||||
|
||||
const AFFINITY_MASK: u32 = 0xffff;
|
||||
const AFFINITY_PART_MASK: u32 = 0xff;
|
||||
const CLUSTER_SHIFT: u32 = 8;
|
||||
const CORETYPE_SHIFT: u32 = 16;
|
||||
const CORETYPE_MASK: u8 = 7;
|
||||
const MPIDR_RES1: u64 = 1 << 31;
|
||||
|
||||
macro_rules! ids {
|
||||
($($id:ident),* $(,)?) => {$(
|
||||
@@ -540,7 +537,7 @@ impl<'a> Plan<'a> {
|
||||
if kind.cluster_type == 0
|
||||
|| kind.midr == 0
|
||||
|| kind.midr > u64::from(u32::MAX)
|
||||
|| kind.aff2 > CORETYPE_MASK
|
||||
|| kind.aff2 > crate::board::mpidr::CORETYPE_MASK
|
||||
|| kind.clock == Some(0)
|
||||
{
|
||||
return Err(conflict(id, ResourceKind::CoreKind));
|
||||
@@ -603,9 +600,8 @@ impl<'a> Plan<'a> {
|
||||
cluster_type: kind.cluster_type,
|
||||
identity: Identity {
|
||||
midr: kind.midr,
|
||||
mpidr: MPIDR_RES1
|
||||
| u64::from(kind.aff2) << CORETYPE_SHIFT
|
||||
| u64::from(slot.reg),
|
||||
mpidr: crate::board::mpidr::compose(kind.aff2, slot.reg)
|
||||
.ok_or_else(|| conflict(id, ResourceKind::CoreKind))?,
|
||||
clock: kind.clock,
|
||||
caches: Some(caches),
|
||||
},
|
||||
|
||||
@@ -406,15 +406,10 @@ impl<'a> BspSource<'a> {
|
||||
let identity = cpus.processors[0];
|
||||
let (instruction, data) = board::level1_caches(chip, b'E')
|
||||
.ok_or(refuse!("assigned source E cache geometry is unqualified"))?;
|
||||
let encoded = identity
|
||||
let geometry = identity
|
||||
.caches
|
||||
.ok_or(refuse!("assigned source lacks complete cache identity"))?
|
||||
.ccsidr(2);
|
||||
let geometry = Cache {
|
||||
line: 16 << (encoded & 7),
|
||||
ways: ((encoded >> 3) & 0x3ff) as u32 + 1,
|
||||
bytes: word(node, "l2-cache-size")?,
|
||||
};
|
||||
.cache(CacheSelection::L2Unified);
|
||||
let slot = GuestSlotId(0);
|
||||
let cluster = ClusterId(0);
|
||||
let cache = CacheId(0);
|
||||
|
||||
@@ -136,15 +136,10 @@ impl<'a> BspSource<'a> {
|
||||
let acc = region(node, "acc-impl-reg")?;
|
||||
let cpm = region(node, "cpm-impl-reg")?;
|
||||
let cpu_impl = region(node, "cpu-impl-reg")?;
|
||||
let encoded = identities.processors[pe]
|
||||
let cache = identities.processors[pe]
|
||||
.caches
|
||||
.ok_or(refuse!("assigned T6000 cache identity is incomplete"))?
|
||||
.ccsidr(2);
|
||||
let cache = Cache {
|
||||
line: 16 << (encoded & 7),
|
||||
ways: ((encoded >> 3) & 0x3ff) as u32 + 1,
|
||||
bytes: word(node, "l2-cache-size")?,
|
||||
};
|
||||
.cache(CacheSelection::L2Unified);
|
||||
let cluster = (cpu.reg >> CLUSTER_SHIFT) as usize;
|
||||
if geometry.len() == cluster {
|
||||
geometry.push((pe, acc, cpm, cpu_impl.bytes, cache));
|
||||
@@ -227,7 +222,7 @@ impl<'a> BspSource<'a> {
|
||||
id: kind_id,
|
||||
cluster_type: cpu.cluster_type,
|
||||
midr: identity.midr,
|
||||
aff2: (identity.mpidr >> CORETYPE_SHIFT & u64::from(CORETYPE_MASK)) as u8,
|
||||
aff2: crate::board::mpidr::coretype(identity.mpidr),
|
||||
clock: identity.clock,
|
||||
instruction,
|
||||
data,
|
||||
|
||||
@@ -274,10 +274,10 @@ impl<'a> BspSource<'a> {
|
||||
let kind = processors[pe].cluster_type;
|
||||
let (instruction, data) = board::level1_caches(profile.soc, kind)
|
||||
.ok_or(refuse!("assigned T8112 L1 geometry is unqualified"))?;
|
||||
let encoded = identity
|
||||
let unified = identity
|
||||
.caches
|
||||
.ok_or(refuse!("assigned T8112 cache identity is incomplete"))?
|
||||
.ccsidr(2);
|
||||
.cache(CacheSelection::L2Unified);
|
||||
let slot = GuestSlotId(0);
|
||||
let cluster = ClusterId(0);
|
||||
let cache = CacheId(0);
|
||||
@@ -305,7 +305,7 @@ impl<'a> BspSource<'a> {
|
||||
id: KindId(0),
|
||||
cluster_type: kind,
|
||||
midr: identity.midr,
|
||||
aff2: (identity.mpidr >> 16 & 7) as u8,
|
||||
aff2: crate::board::mpidr::coretype(identity.mpidr),
|
||||
clock: identity.clock,
|
||||
instruction,
|
||||
data,
|
||||
@@ -335,11 +335,7 @@ impl<'a> BspSource<'a> {
|
||||
caches: vec![SharedCache {
|
||||
id: cache,
|
||||
cluster,
|
||||
geometry: Cache {
|
||||
line: 16 << (encoded & 7),
|
||||
ways: ((encoded >> 3) & 0x3ff) as u32 + 1,
|
||||
bytes: word(node, "l2-cache-size")?,
|
||||
},
|
||||
geometry: unified,
|
||||
}],
|
||||
interrupts: vec![InterruptTarget {
|
||||
id: InterruptId(0),
|
||||
|
||||
Reference in new issue
Block a user