diff --git a/crates/stela-boot-core/src/bundle/source.rs b/crates/stela-boot-core/src/bundle/source.rs index 0b10b0f455..265fb9a277 100644 --- a/crates/stela-boot-core/src/bundle/source.rs +++ b/crates/stela-boot-core/src/bundle/source.rs @@ -510,7 +510,7 @@ mod tests { let mut original = DeviceTree::parse(&tree(0, 0)).unwrap(); original.ensure_child("/", "counter-control").unwrap(); original - .set_property("/counter-control", "compatible", b"clpc,t8112\0".to_vec()) + .set_property("/counter-control", "compatible", b"clpc,t6000\0".to_vec()) .unwrap(); let original = original.serialize(); let mut prepared = DeviceTree::parse(&tree(0x6000, 8)).unwrap(); diff --git a/crates/stela-boot-core/src/bundle/source/clpc.rs b/crates/stela-boot-core/src/bundle/source/clpc.rs index e993d7f852..eb490488e1 100644 --- a/crates/stela-boot-core/src/bundle/source/clpc.rs +++ b/crates/stela-boot-core/src/bundle/source/clpc.rs @@ -1,17 +1,21 @@ -//! Positive evidence for hiding the unsupported original CLPC class. +//! Positive evidence for hiding an original CLPC class the machine does not +//! model. [`CLPC`] stays visible. use crate::Result; use alloc::{format, string::String, vec::Vec}; use stela_contracts::refuse; use stela_loader::apple_device_tree::{DeviceTree, Node}; +use stela_soc_data::board::CLPC; fn class(node: &Node) -> bool { node.properties .iter() .filter(|p| p.name() == "compatible") .any(|p| { - p.value - .split(|byte| *byte == 0) - .any(|token| token.starts_with(b"clpc,") && token.len() > b"clpc,".len()) + p.value.split(|byte| *byte == 0).any(|token| { + token.starts_with(b"clpc,") + && token.len() > b"clpc,".len() + && token != CLPC.as_bytes() + }) }) } @@ -95,7 +99,7 @@ mod tests { root: Node::named("device-tree").unwrap(), }; tree.ensure_child("/", "arbitrary").unwrap(); - tree.set_property("/arbitrary", "compatible", b"clpc,t8112\0".to_vec()) + tree.set_property("/arbitrary", "compatible", b"clpc,t6000\0".to_vec()) .unwrap(); tree } @@ -123,6 +127,19 @@ mod tests { assert!(validate_live(&prepared, &hidden).is_err()); } + #[test] + fn the_modeled_clpc_stays_visible_without_evidence() { + let mut original = tree(); + original + .set_property("/arbitrary", "compatible", b"clpc,t8112\0".to_vec()) + .unwrap(); + assert!( + verify(&original, &original, &[], 0x8112, 0x28) + .unwrap() + .is_empty() + ); + } + #[test] fn deleting_an_ordinary_kept_clpc_cannot_waive_its_absence_notice() { let original = tree(); diff --git a/crates/stela-loader/src/boot_bundle.rs b/crates/stela-loader/src/boot_bundle.rs index 0fef9cfa4e..75d306f4fb 100644 --- a/crates/stela-loader/src/boot_bundle.rs +++ b/crates/stela-loader/src/boot_bundle.rs @@ -55,7 +55,7 @@ use patches::*; /// The revision of the content [`prepare`] writes within its schema; a /// bundle of another revision is prepared again (`stela setup update stela`). -pub const REVISION: u32 = 32; +pub const REVISION: u32 = 33; /// m1n1 `_write_boot_args`: the physical aperture base XNU expects, offset /// by `phys_base` modulo 32 MiB. const VIRT_BASE: u64 = 0xfffffe0010000000; @@ -778,6 +778,7 @@ fn assemble(inputs: &Inputs, options: &Options, owned: Option) -> target: Some(inputs.target.clone()), options: options.clone(), boot_cpu: Some(shaped.boot_cpu), + processors: shaped.processors, sources: sources(inputs, ramdisk_source), files: files .iter() diff --git a/crates/stela-loader/src/boot_bundle/layout.rs b/crates/stela-loader/src/boot_bundle/layout.rs index 3413b6d852..7630591fb3 100644 --- a/crates/stela-loader/src/boot_bundle/layout.rs +++ b/crates/stela-loader/src/boot_bundle/layout.rs @@ -125,6 +125,8 @@ pub(super) struct Shaped { pub(super) tree: DeviceTree, pub(super) placeholders: Vec, pub(super) boot_cpu: BootCpu, + /// The PEs of the shaped `/cpus`. + pub(super) processors: usize, pub(super) security: Vec, pub(super) unresolved: Vec, pub(super) nvram_published: bool, @@ -158,6 +160,7 @@ impl Shaped { }); let placeholders = resolve_placeholders(&mut tree, options)?; let boot_cpu = select_boot_cpu(&tree, &original_tree, options.boot_cpu.as_deref())?; + let processors = tree.node("/cpus").map_or(0, |cpus| cpus.children.len()); let mut unresolved = shape_device_tree(&mut tree, &inputs.target, options, &boot_cpu)?; let (mut security, policy_unresolved) = boot_policy::apply( &mut tree, @@ -171,6 +174,7 @@ impl Shaped { tree, placeholders, boot_cpu, + processors, security, unresolved, nvram_published: false, @@ -312,6 +316,10 @@ impl Shaped { dvfs::Contents::OperatingPoints => format!( "/arm-io/pmgr {name}: {domain} operating points without calibrated voltages (0)" ), + dvfs::Contents::ChosenClocks => format!( + "/arm-io/pmgr {name}: {domain} clocks are chosen, not the chip's; \ + nothing runs at them" + ), dvfs::Contents::SingleState => { format!("/arm-io/pmgr {name}: {domain} has one state; its clock is not modeled") } diff --git a/crates/stela-loader/src/boot_bundle/tests.rs b/crates/stela-loader/src/boot_bundle/tests.rs index 97df892e0d..483e51fc0b 100644 --- a/crates/stela-loader/src/boot_bundle/tests.rs +++ b/crates/stela-loader/src/boot_bundle/tests.rs @@ -779,8 +779,8 @@ fn lays_out_sptm_regions_and_patch_slots() -> Result<()> { assert_eq!( (REVISION, prepared_digest(&bundle)?), ( - 32, - "b284eebb93b9c998316d910cf9af9dbe3b121bb9312c4497a5fd2dffba9f99e4".to_owned() + 33, + "2282554604131299f7c7f3c6587e671ac28afc7d77ff0728ead446e034bb3279".to_owned() ) ); let original = bundle diff --git a/crates/stela-loader/src/dvfs.rs b/crates/stela-loader/src/dvfs.rs index e26785a836..1a70bdc688 100644 --- a/crates/stela-loader/src/dvfs.rs +++ b/crates/stela-loader/src/dvfs.rs @@ -19,16 +19,21 @@ //! points (`machine::board::operating_points`); //! - any other domain's table whose first state has voltage 0 is a list of //! state numbers, `(0, 0), (1, 0), …`, and the domain has as many states as -//! the last number plus one. The IPSW DeviceTree ships `voltage-states0`, -//! `2` and `9` in this form; the driver asserts the list is not empty. +//! the last number plus one, each without a clock. The IPSW DeviceTree ships +//! `voltage-states0`, `2` and `9` in this form; the driver asserts the list +//! is not empty; +//! - one whose first state has a voltage is a run of `(clock in Hz, voltage)` +//! states of a domain of the plain type, byte 2 of 0. //! //! iBoot fills these tables from the chip itself: each state's voltage from //! its calibration fuses, and the non-CPU domains' clocks from their PLL //! registers. An emulated chip has neither. The CPU tables leave the voltage //! 0, which the driver uses only for its dynamic energy estimate (V² × f), so -//! the estimate states no energy rather than an invented one. Every other -//! domain gets one state, `(0, 0)`: the machine does not scale its clock, so -//! the domain has a single operating point. The optional `-sram` and +//! the estimate states no energy rather than an invented one. The ANE gets +//! `board::ANE_CLOCKS_MHZ`, chosen clocks that CLPC cannot start without, at +//! the least voltage that marks them as clocks. Every other domain gets one +//! state, `(0, 0)`: the machine does not scale its clock, so the domain has a +//! single operating point. The optional `-sram` and //! `-extra` tables are not published. A CPU cluster of a SoC without //! operating-point evidence keeps no table: inventing clocks would be a //! placeholder, so the bundle records the gap and the driver's own stop @@ -45,12 +50,18 @@ const PERF_DOMAINS: &str = "perf-domains"; const DOMAIN: usize = 28; /// The period unit: a state's period is this over its clock in Hz. const PERIOD_SCALE: u64 = 65_536 * 1_000_000_000; +/// The domain whose table holds [`board::ANE_CLOCKS_MHZ`]. +const ANE: &str = "ANE"; +/// The voltage of a state whose only use is to mark its table as clocks. +const LEAST_VOLTAGE: u32 = 1; /// What [`publish`] did for one domain without a table. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Contents { /// A CPU cluster's operating points. OperatingPoints, + /// Clocks chosen for a domain nothing runs at. + ChosenClocks, /// A single state, for a domain whose clock the machine does not scale. SingleState, /// Nothing: the SoC has no operating-point evidence for this cluster. @@ -112,6 +123,16 @@ fn cluster(domain: &str, chip_id: u32) -> Result>> { Ok(Some(value)) } +/// The ANE's table: [`board::ANE_CLOCKS_MHZ`] as Hz. +fn ane_clocks() -> Vec { + let mut value = Vec::with_capacity(board::ANE_CLOCKS_MHZ.len() * 8); + for mhz in board::ANE_CLOCKS_MHZ { + value.extend_from_slice(&(mhz * 1_000_000).to_le_bytes()); + value.extend_from_slice(&LEAST_VOLTAGE.to_le_bytes()); + } + value +} + /// Add the table of each `perf-domains` domain that lacks one. Returns the /// tables written; a tree without the domains gets none. pub fn publish(tree: &mut DeviceTree, chip_id: u32) -> Result> { @@ -145,6 +166,8 @@ pub fn publish(tree: &mut DeviceTree, chip_id: u32) -> Result> { Some(value) => (Contents::OperatingPoints, Some(value)), None => (Contents::Unpublished, None), } + } else if domain == ANE { + (Contents::ChosenClocks, Some(ane_clocks())) } else { (Contents::SingleState, Some([0u8; 8].to_vec())) }; @@ -214,7 +237,7 @@ mod tests { ); assert_eq!(written[2].domain, "ANE"); assert_eq!(written[0].contents, Contents::OperatingPoints); - assert_eq!(written[2].contents, Contents::SingleState); + assert_eq!(written[2].contents, Contents::ChosenClocks); // 600 MHz is period 109,226, which the driver reads back as 600 MHz. let e = &tree.property(PMGR, "voltage-states1").unwrap().value; assert_eq!(e.len(), 7 * 8); @@ -223,9 +246,11 @@ mod tests { let p = &tree.property(PMGR, "voltage-states5").unwrap().value; assert_eq!(p.len(), 17 * 8); assert_eq!(word(p, 32), 18_703); - // A domain whose clock the machine does not scale has one state. + // The ANE's clocks are in Hz, marked by a voltage. let ane = &tree.property(PMGR, "voltage-states8").unwrap().value; - assert_eq!(ane, &vec![0u8; 8]); + assert_eq!(ane.len(), 2 * 8); + assert_eq!((word(ane, 0), word(ane, 1)), (300_000_000, 1)); + assert_eq!((word(ane, 2), word(ane, 3)), (600_000_000, 1)); // The shipped table stays, and a second publish writes nothing. assert_eq!( tree.property(PMGR, "voltage-states0").unwrap().value.len(), @@ -274,7 +299,7 @@ mod tests { let written = publish(&mut m3, 0x8122).unwrap(); assert_eq!(written[0].contents, Contents::Unpublished); assert!(m3.property(PMGR, "voltage-states1").is_none()); - assert_eq!(written[2].contents, Contents::SingleState); + assert_eq!(written[2].contents, Contents::ChosenClocks); assert!(publish(&mut with_domains(None), 0x8122).unwrap().is_empty()); assert!(publish(&mut with_domains(Some(&[0; 27])), 0x8112).is_err()); } diff --git a/crates/stela-soc-data/src/board.rs b/crates/stela-soc-data/src/board.rs index 36f6effb59..f5c3cf3991 100644 --- a/crates/stela-soc-data/src/board.rs +++ b/crates/stela-soc-data/src/board.rs @@ -173,6 +173,17 @@ pub struct CounterBlock { pub const UART: &str = "uart-1,samsung"; /// The `compatible` of the watchdog the engine models (`platform::apple::wdt`). pub const WATCHDOG: &str = "wdt,s5l8960x"; +/// The `compatible` of the closed-loop performance controller whose kext, +/// `AppleT8112CLPC`, runs on the modeled PMGR, core counters and PTD. Its +/// perfcontrol callbacks are what place thread groups on the P-cores. +pub const CLPC: &str = "clpc,t8112"; + +/// The ANE domain's clocks in MHz, lowest first. iBoot reads them from the +/// chip's PLLs; these are chosen, and nothing runs at them. `CLPC::init` turns +/// each P state's ANE clock into a curve and needs two different clocks, the +/// lowest at 19 MHz or more for the curve to be positive; the curve is near 1 +/// at the highest. +pub const ANE_CLOCKS_MHZ: [u32; 2] = [300, 600]; /// The AIC versions the engine models (`platform::apple::aic1` and `aic`). const AICS: [&str; 3] = ["aic,1", "aic,2", "aic,3"]; /// The modern DART compatible; native legacy families are selected through diff --git a/crates/stela-soc-data/src/board/models.rs b/crates/stela-soc-data/src/board/models.rs index 2afb98ce4d..4037fd8bac 100644 --- a/crates/stela-soc-data/src/board/models.rs +++ b/crates/stela-soc-data/src/board/models.rs @@ -1,6 +1,6 @@ //! Compatible and role matching for the native models exposed in the DeviceTree. use super::{ - AES, AICS, ASC, BOOT_FIRMWARE, BUTTONS, DCP_EXPERT, DCPEXT_ROLE, DISPEXT, DISPEXT_T6000, + AES, AICS, ASC, BOOT_FIRMWARE, BUTTONS, CLPC, DCP_EXPERT, DCPEXT_ROLE, DISPEXT, DISPEXT_T6000, DOCK_PORT, GFX_MAPPER, GPIO, GPIO_S5L, GPIO_T6000, HPM, HPM_MANAGER, IOMMU_MAPPER, MCC, NOR, NVRAM, PMGR2_IMPLEMENTATION, PMU, RTBUDDY, SEP, SEP_NUB, SMC_PMU, SOCS, SPI, SPMI, SYSCFG, T6000_EXTERNAL_OUTPUT_ADMITTED, UART, WATCHDOG, admitted_gpu, atc_phy_compatible, @@ -225,6 +225,7 @@ pub fn models<'a>(name: &str, property: impl Fn(&str) -> Option<&'a [u8]>) -> bo PMU, BUTTONS, DISPEXT, + CLPC, ] .contains(&name) || i2c_compatible(name, property("compatible")) diff --git a/crates/stela-soc-data/src/cpm.rs b/crates/stela-soc-data/src/cpm.rs index 1f00b5306d..1f4b477ba2 100644 --- a/crates/stela-soc-data/src/cpm.rs +++ b/crates/stela-soc-data/src/cpm.rs @@ -1,20 +1,43 @@ //! CPM power-register placement, independently of kept controller state. //! T8112 `enableThrottler` uses the four common full-width controls and a -//! performance-cluster control. `restoreHW` uses the separate restore word. +//! performance-cluster control. `restoreHW` and CLPC's cluster samplers use +//! the counter block's enable word, and CLPC its two counter banks. use alloc::vec::Vec; pub const T8112_OFFSET: u64 = 0x40000; -pub const RESTORE: u64 = 0x40f8; +pub const COUNTER_ENABLE: u64 = 0x40f8; pub const THROTTLERS: [u64; 4] = [0x250, 0x270, 0x8400, 0x8408]; pub const P_THROTTLER: u64 = 0x8b30; +/// The cluster counter slots, each a count and then its event selector. +const CLUSTER_COUNTERS: u64 = 0x4000; +const CLUSTER_STRIDE: u64 = 0x10; +const CLUSTER_SLOTS: u64 = 8; +/// The uncore counters: both banks of a slot, and the control words. +const UNCORE_COUNTS: u64 = 0x4100; +const UNCORE_COUNT_STRIDE: u64 = 0x10; +const UNCORE_SHADOWS: u64 = 0x4248; +const UNCORE_SLOTS: u64 = 8; +const UNCORE_CONTROL: u64 = 0x4180; +const UNCORE_CONTROLS: u64 = 10; +const WORD: u64 = 8; + /// The complete described register offsets in their established iteration /// order. Describing a word does not perform or complete its operation. pub fn offsets(performance: bool) -> Vec { let mut offsets = THROTTLERS.to_vec(); - offsets.push(RESTORE); + offsets.push(COUNTER_ENABLE); if performance { offsets.push(P_THROTTLER); } + for slot in 0..CLUSTER_SLOTS { + let count = CLUSTER_COUNTERS + slot * CLUSTER_STRIDE; + offsets.extend([count, count + WORD]); + } + for slot in 0..UNCORE_SLOTS { + offsets.push(UNCORE_COUNTS + slot * UNCORE_COUNT_STRIDE); + offsets.push(UNCORE_SHADOWS + slot * WORD); + } + offsets.extend((0..UNCORE_CONTROLS).map(|word| UNCORE_CONTROL + word * WORD)); offsets } diff --git a/crates/stela-soc/src/cluster.rs b/crates/stela-soc/src/cluster.rs index 68fcfff8d0..3f2c91af43 100644 --- a/crates/stela-soc/src/cluster.rs +++ b/crates/stela-soc/src/cluster.rs @@ -15,10 +15,26 @@ //! every `0x40` bytes (m1n1 `cpufreq.c` reads its T8112 slots there). //! `AppleT8110PMGR::getDVMRMaxWeight` takes a state's DVMR weight type //! from word 1 bits 41:38, and the DPE power expressions take its -//! voltage code from word 0 bits 63:56. The boot firmware builds the -//! table from the die's calibration, which an emulated die does not -//! have: every word reads 0, the lowest voltage code and DVMR weight -//! type 0, until software writes it, and then holds what it wrote. +//! voltage code from word 0 bits 63:56. `AppleT8110PMGR::getFANEIndex` +//! (0xfffffe0009fa1954) reads a P-cluster state's three ANE frequency +//! indices from word 2 bits 33:29, 38:34 and 43:39, and an E-cluster +//! state has none. `ApplePMGR::_initPerfDomainInfo` publishes the ANE +//! domain's clocks as `ANEFrequencies`, and `CLPC::init` looks each index +//! up there (0xfffffe0009f4c048), failing on one past its end. Of a state's +//! clocks it keeps the first only when a `_dvmrWeightMapPacc` row up to the +//! state's weight type names the ANE: type 4 at the least, and type 15 is +//! the one `_getDVMRMinActiveState` skips as no limit. `initDriver` requires +//! a limited state among the first sixteen. CLPC keeps the states +//! whose first clock is not 0 and, finding none, indexes its table with -1; +//! it fails when the first clock falls under the range of a curve through +//! them, or when they are all one clock and the range is empty. The boot +//! firmware builds the table from the die's calibration, which an emulated +//! die does not have: every word reads 0, the lowest voltage code and DVMR +//! weight type 0, until software writes it, and then holds what it wrote. +//! Only the P cluster's states do not: an emulated die has no voltage droop +//! to limit them, so they read type 15 up to the sixteenth, and from there +//! type 10, the highest with a row of its own; their first ANE index rises +//! through `board::ANE_CLOCKS_MHZ`. There is no ANE behind them. //! //! ACC counters (`get/setCPUPerfCounter`, kernel file 0x2fa009c/0x2fa01c4, //! T8112 P override 0x2fa4c38/0x2fa4ad8) are paired full64 banks at +20400 @@ -85,6 +101,16 @@ const DVMR: core::ops::Range = 0x206a8..0x20700; /// The performance-state table and its slot size. pub const PSTATE_OFFSET: u64 = 0x78000; pub const PSTATE_BYTES: u64 = 0x40; +/// The state word that holds a state's DVMR weight type, its field, the type +/// of a state with no limit and of a limited one, and the first limited state. +const PSTATE_WEIGHT: u64 = 0x8; +const WEIGHT_TYPE_SHIFT: u32 = 38; +const WEIGHT_TYPE_UNLIMITED: u64 = 15; +const WEIGHT_TYPE_LIMITED: u64 = 10; +const FIRST_LIMITED_STATE: u64 = 15; +/// The state word that holds a P-cluster state's ANE indices. +const PSTATE_ANE: u64 = 0x10; +const ANE_INDEX_SHIFT: u32 = 29; /// One cluster's registers: the DVMR tables the boot firmware programmed, /// as `(offset, value)`, and `pstates` performance-state slots. @@ -122,6 +148,25 @@ impl Cluster { }) } + /// A P cluster's states: only the last have a DVMR limit, and each names + /// one of `clocks` ANE clocks, rising. + pub fn with_ane_states(mut self, clocks: usize) -> Self { + for state in 0..self.pstates { + let slot = PSTATE_OFFSET + state * PSTATE_BYTES; + let index = state * clocks as u64 / self.pstates; + let weight = if state < FIRST_LIMITED_STATE { + WEIGHT_TYPE_UNLIMITED + } else { + WEIGHT_TYPE_LIMITED + }; + self.registers + .set(slot + PSTATE_WEIGHT, weight << WEIGHT_TYPE_SHIFT); + self.registers + .set(slot + PSTATE_ANE, index << ANE_INDEX_SHIFT); + } + self + } + /// Extend only the DT-selected event counters and the hardware's state /// counter capacity. The P mapping table is separate from either bank. pub fn with_counters(mut self, capacity: usize, mapped: bool, events: &[u8]) -> Result { @@ -343,6 +388,23 @@ mod tests { ); } + #[test] + fn a_p_clusters_last_states_are_limited_and_all_name_rising_ane_clocks() { + let mut c = Cluster::new(&[], 17).unwrap().with_ane_states(2); + let mut latch = InterruptLatch::new(); + let mut a = Access::new(0, 0, &mut latch); + let word = |state: u64| PSTATE_OFFSET + state * PSTATE_BYTES + PSTATE_ANE; + let index = |value: u64| (value >> ANE_INDEX_SHIFT) & 0x1f; + let mut read = |state| index(c.read(word(state), Width::Double, &mut a).unwrap()); + let indices: Vec = (0..17).map(&mut read).collect(); + assert!(indices.is_sorted()); + assert_eq!((indices[0], indices[16]), (0, 1)); + let weight = |state: u64| PSTATE_OFFSET + state * PSTATE_BYTES + PSTATE_WEIGHT; + let mut read = |state| c.read(weight(state), Width::Double, &mut a).unwrap(); + assert_eq!((read(14) >> WEIGHT_TYPE_SHIFT) & 0xf, 15); + assert_eq!((read(15) >> WEIGHT_TYPE_SHIFT) & 0xf, 10); + } + #[test] fn the_dvmr_tables_hold_the_firmware_tunables_and_the_pstates_start_empty() { let mut latch = InterruptLatch::new(); diff --git a/crates/stela-soc/src/cpm.rs b/crates/stela-soc/src/cpm.rs index c4c8ff7dae..45451f6bff 100644 --- a/crates/stela-soc/src/cpm.rs +++ b/crates/stela-soc/src/cpm.rs @@ -5,16 +5,28 @@ //! No physical overload or thermal cause is modeled, so no active throttle //! or counter event is invented. Configuration keeps every written field. //! -//! `restoreHW` (0x2f9cb9c, stores 0x2f9ce74..0x2f9ced8) writes full64 1 -//! at +40f8. The restore request completes immediately against the already -//! configuration. Its completion is recorded; electrical effects and -//! command readback are not proved. Other values and reads of it refuse. +//! `restoreHW` (0x2f9cb9c, stores 0x2f9ce74..0x2f9ced8) and CLPC's +//! `ClusterPerfSampler::enableCluster` (0xfffffe0009f407a4) write full64 1 at +//! +40f8, the counter block's enable. Its completion is recorded; effects and +//! readback are not proved. Other values and reads of it refuse. +//! +//! `T8112CLPC::clusterPerfSamplerConfig` (0xfffffe0009f78be4) places eight +//! slots at +4000, 0x10 apart, each a count and at +8 its event selector; +//! `enableCluster` selects seven and `sample` reads them. And +//! `uncorePerfSamplerConfig` (0xfffffe0009f78c80) places the uncore counters: +//! eight pairs at +4100, 0x10 apart, and +4248, 8 apart, read by +//! `UncorePerfSampler::sampleCluster` (0xfffffe0009f41ca0), and ten control +//! words at +4180 that `enableCluster` (0xfffffe0009f41bf0) reads and writes, +//! its low byte of the first enabling the counters. These counters' events +//! are not documented and an emulated die has no event source, so like the +//! core counters ([`crate::core_counters`]) they hold what software writes, +//! 0 from reset (inference): no activity is invented, and CLPC sees none. use super::regfile::Held; use crate::Result; use alloc::vec::Vec; use stela_contracts::Refusal; use stela_contracts::refuse; -use stela_soc_data::cpm::RESTORE; +use stela_soc_data::cpm::COUNTER_ENABLE; #[cfg(test)] use stela_soc_data::cpm::{P_THROTTLER, THROTTLERS}; use { @@ -27,22 +39,22 @@ const NAME: &str = "cpm-power"; pub struct Cpm { performance: bool, values: Held, - restored: bool, + counting: bool, } impl Cpm { pub fn new(performance: bool) -> Self { Self { performance, values: Held::default(), - restored: false, + counting: false, } } pub fn offsets(&self) -> Vec { stela_soc_data::cpm::offsets(self.performance) } #[cfg(test)] - pub fn restored(&self) -> bool { - self.restored + pub fn counting(&self) -> bool { + self.counting } fn check(&self, o: u64, w: Width) -> Result<()> { if w != Width::Double || !self.offsets().contains(&o) { @@ -64,9 +76,9 @@ impl MmioDevice for Cpm { fn read(&mut self, o: u64, w: Width, _: &mut Access<'_>) -> Result { let fail = |r: Refusal| refuse(NAME, o, w, Direction::Read, r); self.check(o, w).map_err(fail)?; - if o == RESTORE { + if o == COUNTER_ENABLE { return Err(fail(refuse!( - "CPM restore command readback is not established" + "CPM counter enable readback is not established" ))); } Ok(self.values.get(o)) @@ -74,13 +86,13 @@ impl MmioDevice for Cpm { fn write(&mut self, o: u64, w: Width, v: u64, _: &mut Access<'_>) -> Result<(), MmioError> { let fail = |r: Refusal| refuse(NAME, o, w, Direction::Write, r); self.check(o, w).map_err(fail)?; - if o == RESTORE { + if o == COUNTER_ENABLE { if v != 1 { return Err(fail(refuse!( - "CPM restore accepts only the documented full64 command1" + "CPM counter enable accepts only the documented full64 1" ))); } - self.restored = true; + self.counting = true; } else { self.values.set(o, v); } @@ -92,30 +104,45 @@ mod tests { use super::*; use stela_contracts::interrupt::InterruptLatch; #[test] - fn throttlers_keep_configuration_and_restore_does_not_discard_it() { + fn registers_keep_configuration_and_the_counter_enable_does_not_discard_it() { let mut sink = InterruptLatch::new(); let mut a = Access::new(0, 0, &mut sink); for performance in [false, true] { let mut c = Cpm::new(performance); - assert!(!c.restored()); - for o in c.offsets().into_iter().filter(|&o| o != RESTORE) { + assert!(!c.counting()); + for o in c.offsets().into_iter().filter(|&o| o != COUNTER_ENABLE) { assert_eq!(c.read(o, Width::Double, &mut a), Ok(0)); c.write(o, Width::Double, 0x8000_1234_5678_0001, &mut a) .unwrap(); assert_eq!(c.read(o, Width::Double, &mut a), Ok(0x8000_1234_5678_0001)); } - c.write(RESTORE, Width::Double, 1, &mut a).unwrap(); - assert!(c.restored()); + c.write(COUNTER_ENABLE, Width::Double, 1, &mut a).unwrap(); + assert!(c.counting()); assert_eq!( c.read(THROTTLERS[0], Width::Double, &mut a), Ok(0x8000_1234_5678_0001) ); - assert!(c.read(RESTORE, Width::Double, &mut a).is_err()); - assert!(c.write(RESTORE, Width::Double, 2, &mut a).is_err()); + assert!(c.read(COUNTER_ENABLE, Width::Double, &mut a).is_err()); + assert!(c.write(COUNTER_ENABLE, Width::Double, 2, &mut a).is_err()); assert!(c.write(0x254, Width::Word, 0, &mut a).is_err()); if !performance { assert!(c.read(P_THROTTLER, Width::Double, &mut a).is_err()); } } } + + #[test] + fn clpcs_cluster_and_uncore_counters_are_placed_and_idle() { + let mut sink = InterruptLatch::new(); + let mut a = Access::new(0, 0, &mut sink); + let mut c = Cpm::new(false); + // The first of seven selectors, the last count and the uncore's + // first control word, its last, and a slot's two banks. + for o in [0x4008, 0x4060, 0x4180, 0x41c8, 0x4170, 0x4280] { + assert_eq!(c.read(o, Width::Double, &mut a), Ok(0)); + } + c.write(0x4008, Width::Double, 0x800f, &mut a).unwrap(); + assert_eq!(c.read(0x4008, Width::Double, &mut a), Ok(0x800f)); + assert!(c.read(0x4288, Width::Double, &mut a).is_err()); + } } diff --git a/crates/stela-soc/src/fuse.rs b/crates/stela-soc/src/fuse.rs index 108c1ef816..5259a52f03 100644 --- a/crates/stela-soc/src/fuse.rs +++ b/crates/stela-soc/src/fuse.rs @@ -23,6 +23,9 @@ //! ones. The registers' other bits are fields no reader of this kernel is //! known to take, so they read 0 as well, and every other register refuses. //! Fuses are read-only. +//! +//! `T8112CLPC::isRunningOnSilicon` (0xfffffe0009f78cf0) reads `0x80c` and +//! takes bits 31:28 of 0 for a real die, so 0 there is the silicon answer. use { stela_contracts::bus::Access, stela_contracts::bus::Direction, stela_contracts::bus::MmioDevice, stela_contracts::bus::MmioError, stela_contracts::bus::Width, @@ -32,7 +35,7 @@ use { const NAME: &str = "aon-fuse"; /// The calibration registers a model describes. -const DESCRIBED: [u64; 6] = [0x4b0, 0x4c4, 0x4cc, 0x4d8, 0x4dc, 0x4e0]; +const DESCRIBED: [u64; 7] = [0x4b0, 0x4c4, 0x4cc, 0x4d8, 0x4dc, 0x4e0, 0x80c]; /// The block's span. pub const FUSE_BYTES: u64 = 0x4000; diff --git a/crates/stela-soc/src/machine/power.rs b/crates/stela-soc/src/machine/power.rs index bcae03c44c..27fe8e4849 100644 --- a/crates/stela-soc/src/machine/power.rs +++ b/crates/stela-soc/src/machine/power.rs @@ -284,8 +284,12 @@ impl AppleDevices { mapped: bool, events: &[u8], ) -> Result<()> { - let model = Cluster::new(dvmr, pstates) + let mut model = Cluster::new(dvmr, pstates) .and_then(|c| c.with_counters(counter_capacity, mapped, events))?; + // Only the P cluster's counters are mapped; only it shares with the ANE. + if mapped { + model = model.with_ane_states(stela_soc_data::board::ANE_CLOCKS_MHZ.len()); + } let table = model.pstate_bytes(); let device = self.bus.add(Box::new(model)); for (offset, bytes) in [