diff --git a/drivers/gpu/drm/asahi/fwid.rs b/drivers/gpu/drm/asahi/fwid.rs index df20d3c406626..d75543b703780 100644 --- a/drivers/gpu/drm/asahi/fwid.rs +++ b/drivers/gpu/drm/asahi/fwid.rs @@ -545,6 +545,34 @@ mod tests { assert!(measured(builds, 0x13c000, &[[0x5c8df, 0x5c9c2]], [0; 32]).is_none()); } + #[cfg(CONFIG_DRM_ASAHI_G16)] + #[test] + fn t8132_25g83_b000_zeroes_what_iboot_fills() { + let builds = crate::g16::hw::t8132::CONFIG.firmware; + let filled = crate::g16::hw::t8132::BOOT_FILLED_25G83_B000; + let build = builds.iter().find(|b| b.boot_filled == filled).unwrap(); + let [gkts, ecap] = build.entropy[0]; + // The header's per-boot word and DATA address, then one value per parameter record: + // each follows its 8-byte tag and length, back to back from the GKTS record. + assert_eq!(filled[..2], [(0x224, 4), (0x23c, 8)]); + let mut next = gkts; + for &(off, len) in &filled[2..filled.len() - 4] { + assert_eq!(off, next + 8); + next = off + len; + } + assert_eq!(next, 0x5c8df + 0x231); + assert!(filled.contains(&(gkts + 8, 8))); + assert!(filled.contains(&(ecap + 8, 8))); + // Then each tunable table's count byte and body, 0x350 bytes from its header. + for (i, table) in [next, next + 0x350].into_iter().enumerate() { + let at = filled.len() - 4 + 2 * i; + assert_eq!(filled[at..at + 2], [(table + 3, 1), (table + 4, 0x34c)]); + } + let found = measured(builds, 0x13c000, &[[gkts, ecap]], build.text_sha256).unwrap(); + assert!(core::ptr::eq(found, build)); + assert!(measured(builds, 0x138000, &[[gkts, ecap]], build.text_sha256).is_none()); + } + #[test] fn t6050_admits_only_its_pinned_image() { for cfg in [ diff --git a/drivers/gpu/drm/asahi/g16/board.rs b/drivers/gpu/drm/asahi/g16/board.rs index 9d005164e6de8..b14e303dc26ff 100644 --- a/drivers/gpu/drm/asahi/g16/board.rs +++ b/drivers/gpu/drm/asahi/g16/board.rs @@ -2,33 +2,32 @@ //! M4 board admission for the qualified firmware graph. //! -//! M4 uses ten firmware rows selected from sixteen source states, including off, and sixteen -//! voltage lanes. The source values belong to this machine's preserved original ADT. +//! M4 uses ten or eleven firmware rows, by the shape of the sixteen source +//! states, including off, and sixteen voltage lanes. The source values belong to this +//! machine's preserved original ADT. pub(crate) mod data; use super::adt::GpuAdt; -use super::fw::initdata::{Performance, PERF_STATES}; +use super::fw::initdata::Performance; use kernel::{device, prelude::*}; /// Admit the qualified table layout while preserving every machine-specific source value. /// Differently shaped tables and inconsistent voltage pairs fail before publication. pub(crate) fn qualify(dev: &device::Device, adt: &GpuAdt) -> Result { let (performance, layout) = data::select_named(&adt.performance).map_err(|error| { - dev_err!( - dev, - "M4 original ADT performance layout rejected: {:?}\n", - error - ); + dev_err!(dev, "M4 original ADT performance layout rejected: {:?}\n", error); EINVAL })?; dev_info!( dev, - "M4 ADT DVFS: 16 source states -> 10 firmware rows ({} layout), top {} MHz\n", + "M4 ADT DVFS: {} source states -> {} firmware rows ({} layout), top {} MHz\n", + adt.performance.count, + performance.count, layout, - performance.frequency[PERF_STATES - 1] + performance.frequency[performance.count - 1] ); - for i in 0..PERF_STATES { + for i in 0..performance.count { dev_info!( dev, "M4 ADT DVFS S{}: main={} MHz auxiliary={} MHz core={} mV SRAM={} mV\n", diff --git a/drivers/gpu/drm/asahi/g16/board/data.rs b/drivers/gpu/drm/asahi/g16/board/data.rs index 6d18386727a7f..7bfc081252765 100644 --- a/drivers/gpu/drm/asahi/g16/board/data.rs +++ b/drivers/gpu/drm/asahi/g16/board/data.rs @@ -2,36 +2,40 @@ //! Qualified selections of the original ADT's sixteen performance states for 25G83. //! -//! The firmware takes ten rows, each a main and an auxiliary frequency at one voltage. Every -//! qualified layout maps the sixteen ADT states onto those rows by index; the values are always -//! this machine's own, never frequencies or voltages copied from a reference machine. +//! The firmware takes ten or eleven rows, each a main and an auxiliary frequency at one voltage. +//! Every qualified layout maps the sixteen ADT states onto those rows by index; the values are +//! always this machine's own, never frequencies or voltages copied from a reference machine. pub(crate) const SOURCE_STATES: usize = 16; -/// One qualified mapping of the ADT states onto the firmware rows. +/// One qualified mapping of the ADT states onto the first `rows` firmware rows. pub(crate) struct Layout { pub(crate) name: &'static str, + pub(crate) rows: usize, pub(crate) main: [usize; PERF_STATES], pub(crate) auxiliary: [usize; PERF_STATES], } /// Tried in order; a layout matches only when each row's two states share frequency, SRAM -/// frequency and both voltages, so the shapes below cannot be mistaken for each other. +/// frequency and both voltages, so the two shapes cannot be mistaken for each other. The row +/// count follows from the shape of the machine's own ADT states; no board is asked. pub(crate) const LAYOUTS: [Layout; 2] = [ - // J713: four common low states followed by six equal-voltage pairs. + // Four common low states followed by six equal-voltage pairs (the J713's ADT): ten rows. Layout { - name: "J713", - main: [0, 1, 2, 3, 5, 7, 9, 11, 13, 15], - auxiliary: [0, 1, 2, 3, 4, 6, 8, 10, 12, 14], + name: "4+6 pairs", + rows: 10, + main: [0, 1, 2, 3, 5, 7, 9, 11, 13, 15, 0], + auxiliary: [0, 1, 2, 3, 4, 6, 8, 10, 12, 14, 0], }, - // J604 (MacBook Pro 14-inch, M4): five low states, five equal-voltage pairs (5/6 to - // 13/14) and a single top state 15. Eleven distinct rows do not fit in ten, so the fifth - // low state (4) is left out; the four lowest states, every pair and the top state keep - // their own ADT values. + // Five low states, five equal-voltage pairs (5/6 to 13/14) and a single top state 15 (the + // J604's and the J773g's ADT): eleven distinct rows, every state kept. The firmware takes + // eleven rows; this was run on a J773g. An earlier ten-row selection for this shape left + // the fifth low state out only because ten rows were thought to be the limit. Layout { - name: "J604", - main: [0, 1, 2, 3, 6, 8, 10, 12, 14, 15], - auxiliary: [0, 1, 2, 3, 5, 7, 9, 11, 13, 15], + name: "5+5 pairs+top", + rows: 11, + main: [0, 1, 2, 3, 4, 6, 8, 10, 12, 14, 15], + auxiliary: [0, 1, 2, 3, 4, 5, 7, 9, 11, 13, 15], }, ]; @@ -68,12 +72,13 @@ fn select_layout( ) -> core::result::Result { use super::super::adt::perf::Error; let mut performance = Performance { + count: layout.rows, frequency: [0; PERF_STATES], auxiliary: [0; PERF_STATES], voltage: [0; PERF_STATES], sram: [0; PERF_STATES], }; - for i in 0..PERF_STATES { + for i in 0..layout.rows { let (main, aux) = (layout.main[i], layout.auxiliary[i]); if source.frequency_mhz[main] != source.sram_frequency_mhz[main] || source.frequency_mhz[aux] != source.sram_frequency_mhz[aux] diff --git a/drivers/gpu/drm/asahi/g16/boot.rs b/drivers/gpu/drm/asahi/g16/boot.rs index f7f2cb25c56ea..467ecf6d92e44 100644 --- a/drivers/gpu/drm/asahi/g16/boot.rs +++ b/drivers/gpu/drm/asahi/g16/boot.rs @@ -60,7 +60,7 @@ pub(crate) mod glue { ) -> core::ffi::c_int; } - /// A qualified J713/T8132 board. + /// A qualified T8132 board (J713, J773g). pub(crate) fn board() -> bool { // SAFETY: Reads the machine compatible strings only. unsafe { asahi_g16_board() } @@ -409,7 +409,7 @@ impl Session { self.shared.check()?; if !self.rtkit.running() || self.regs.asc_control()? & regs::ASC_RUN == 0 - || self.regs.pstate()? > 9 + || self.regs.pstate()? > self.regs.top() { return Err(EIO); } @@ -730,7 +730,7 @@ pub(crate) fn start( "M4 G16G: {} cores enabled\n", id.core_masks[0].count_ones() ); - if regs.pstate()? > 9 { + if regs.pstate()? > regs.top() { return Err(eproto()); } // Cold only: ASC RUN clear and an all-zero TTBAT before ownership. @@ -779,6 +779,10 @@ pub(crate) fn start( events.reserve()?; // Every host object and every context-0 alias is prepared before RUN is set. built = Some(initdata::build(&d, &session.adt, &mut objects)?); + if let Some((init, _, _)) = built.as_ref() { + // The running firmware may report any state of the board's table, up to S10 on J773g. + session.regs.set_table(init.rows); + } objects.window.lock().bootstrap(&d, &session.uat)?; uat::tlbi_all(); if session.regs.asc_control()? & regs::ASC_RUN != 0 { diff --git a/drivers/gpu/drm/asahi/g16/fw/initdata.rs b/drivers/gpu/drm/asahi/g16/fw/initdata.rs index 9acbb4ac763a5..0083f5cad939e 100644 --- a/drivers/gpu/drm/asahi/g16/fw/initdata.rs +++ b/drivers/gpu/drm/asahi/g16/fw/initdata.rs @@ -324,12 +324,15 @@ pub(crate) fn loader_encode(slot: usize, va: u64, record: &mut [u8]) -> Result<( put64(out, 0x20, u64::from(e.mode)) } -pub(crate) const PERF_STATES: usize = 10; +/// Capacity for the largest qualified table: J713 has ten rows, J773g eleven. +pub(crate) const PERF_STATES: usize = 11; /// Machine-specific values selected from the original ADT before firmware publication. /// Frequencies are exact MHz, voltages are millivolts. No reference-bin defaults exist. +/// Only the first `count` rows are used; the rest are zero. #[derive(Clone, Debug, PartialEq, Eq)] pub(crate) struct Performance { + pub(crate) count: usize, pub(crate) frequency: [u32; PERF_STATES], pub(crate) auxiliary: [u32; PERF_STATES], pub(crate) voltage: [u32; PERF_STATES], @@ -338,7 +341,19 @@ pub(crate) struct Performance { impl Performance { pub(crate) fn valid(&self) -> bool { - for i in 0..PERF_STATES { + if !(2..=PERF_STATES).contains(&self.count) { + return false; + } + for i in self.count..PERF_STATES { + if self.frequency[i] != 0 + || self.auxiliary[i] != 0 + || self.voltage[i] != 0 + || self.sram[i] != 0 + { + return false; + } + } + for i in 0..self.count { if self.frequency[i] > 3000 || self.auxiliary[i] > self.frequency[i] || ((i == 0) != (self.frequency[i] == 0)) @@ -445,8 +460,8 @@ pub(crate) fn encode( input: &Input, ceiling: u32, ) -> Result<(), ()> { - if !(1..=9).contains(&ceiling) - || !input.performance.valid() + if !input.performance.valid() + || !(1..input.performance.count as u32).contains(&ceiling) || !object_va(input.scratch, 0x8000) || !bootstrap_alias(input.lower_uma) || !bootstrap_alias(input.lower_parameter) @@ -542,7 +557,7 @@ pub(crate) fn encode( (0xed0, 24000), (0xed4, 1), (0xed8, 8), - (0xfc0, 10), + (0xfc0, input.performance.count as u32), (0x259c, 1), (0x2544, 4), (0x2548, 6), diff --git a/drivers/gpu/drm/asahi/g16/glue.c b/drivers/gpu/drm/asahi/g16/glue.c index 368b56149acc7..c8b64ec601b90 100644 --- a/drivers/gpu/drm/asahi/g16/glue.c +++ b/drivers/gpu/drm/asahi/g16/glue.c @@ -200,10 +200,10 @@ int asahi_g16_tvm_enable(struct device *dev) return ret; } -/* Whether this is a qualified J713/T8132 board. */ +/* Whether this T8132 board's retained PMP carries the GPU's AGX vote. */ bool asahi_g16_board(void) { - return apple_pmp_j713_board(); + return apple_pmp_t8132_g16_board(); } /* diff --git a/drivers/gpu/drm/asahi/g16/hw.rs b/drivers/gpu/drm/asahi/g16/hw.rs index 353199dea75a1..447d73279e812 100644 --- a/drivers/gpu/drm/asahi/g16/hw.rs +++ b/drivers/gpu/drm/asahi/g16/hw.rs @@ -79,8 +79,78 @@ pub(crate) mod t8132 { 0xc8, 0x29, 0x86, 0x8b, 0xc9, 0xcf, ], }, + FirmwareBuild { + // Build b000 (G16G B0) of armfw_g16g.im4p in 25G83, as iBoot loads it on any + // machine: the boot-filled ranges below are zeroed, which gives the digest of + // the shipped image with the same ranges zeroed. + name: "Apple GFX 25G83 (build b000, iBoot-filled ranges zeroed)", + text_size: 0x60000, + data_size: 0x13c000, + entropy: &[[0x5c8df, 0x5c9c2]], + boot_filled: BOOT_FILLED_25G83_B000, + text_sha256: [ + 0xb9, 0xea, 0x7e, 0x6b, 0x2a, 0xca, 0x70, 0xa2, 0x75, 0xa0, 0xb0, 0x68, 0xee, + 0x79, 0x1e, 0xd5, 0x05, 0x27, 0xe8, 0xdb, 0x76, 0x19, 0x64, 0xd2, 0x73, 0x3f, + 0xa4, 0x07, 0xa6, 0xf2, 0x22, 0x6c, + ], + }, ], }; + + /// What iBoot writes into the 25G83 build b000 TEXT it loads, in TEXT order: + /// - the header word at 0x224, which changes from boot to boot, and the DATA address at 0x23c; + /// - the value of each of the 39 boot parameter records the header at 0x22c places from + /// 0x5c8df to 0x5cb10 (a tag, a 32-bit length and the value: carveout addresses below the + /// top of DRAM, a per-boot slide, the entropy); + /// - the entry count and the 0x34c-byte body of the two tunable tables at 0x5cb10 and 0x5ce60 + /// (headers 01/03 03 2a), which the shipped image leaves empty. + pub(crate) const BOOT_FILLED_25G83_B000: &[(u32, u32)] = &[ + (0x224, 4), + (0x23c, 8), + (0x5c8e7, 8), + (0x5c8f7, 8), + (0x5c907, 8), + (0x5c917, 8), + (0x5c927, 8), + (0x5c937, 8), + (0x5c947, 8), + (0x5c957, 4), + (0x5c963, 1), + (0x5c96c, 8), + (0x5c97c, 8), + (0x5c98c, 4), + (0x5c998, 8), + (0x5c9a8, 1), + (0x5c9b1, 1), + (0x5c9ba, 8), + (0x5c9ca, 8), + (0x5c9da, 8), + (0x5c9ea, 8), + (0x5c9fa, 8), + (0x5ca0a, 8), + (0x5ca1a, 8), + (0x5ca2a, 8), + (0x5ca3a, 8), + (0x5ca4a, 8), + (0x5ca5a, 8), + (0x5ca6a, 8), + (0x5ca7a, 4), + (0x5ca86, 8), + (0x5ca96, 4), + (0x5caa2, 4), + (0x5caae, 8), + (0x5cabe, 8), + (0x5cace, 1), + (0x5cad7, 8), + (0x5cae7, 8), + (0x5caf7, 4), + (0x5cb03, 1), + (0x5cb0c, 4), + (0x5cb13, 1), + (0x5cb14, 0x34c), + (0x5ce63, 1), + (0x5ce64, 0x34c), + ]; } /// User VA range reported as `vm_start..vm_end`: 42 bits with the final two pages excluded. diff --git a/drivers/gpu/drm/asahi/g16/initdata.rs b/drivers/gpu/drm/asahi/g16/initdata.rs index ecdde0579133a..f022689ad0878 100644 --- a/drivers/gpu/drm/asahi/g16/initdata.rs +++ b/drivers/gpu/drm/asahi/g16/initdata.rs @@ -38,6 +38,8 @@ pub(crate) struct InitData { #[allow(dead_code)] pub(crate) parameter: Arc, root: Arc, + /// Rows of the board's firmware performance table, including off. + pub(crate) rows: u32, loader: [u8; wire::LOADER_BYTES], /// The complete inventory, including firmware-only log and retention data. _graph: KVec>, @@ -83,7 +85,10 @@ pub(crate) fn build( objects: &mut Objects, ) -> Result<(InitData, Channels, u32)> { let performance = board::qualify(dev, adt)?; - let max_khz = performance.frequency[wire::PERF_STATES - 1] * 1000; + // The top row: S9 on J713, S10 on J773g. + let ceiling = performance.count as u32 - 1; + let rows = performance.count as u32; + let max_khz = performance.frequency[ceiling as usize] * 1000; let mut graph = KVec::with_capacity(wire::OBJECT_COUNT, GFP_KERNEL)?; for (i, size) in wire::OBJECT_SIZE.iter().copied().enumerate() { let lower = match i { @@ -184,11 +189,11 @@ pub(crate) fn build( } let array: &mut [&mut [u8]; wire::OBJECT_COUNT] = (&mut slices[..]).try_into().map_err(|_| EINVAL)?; - wire::encode(array, &input, 9).map_err(|()| EINVAL)?; + wire::encode(array, &input, ceiling).map_err(|()| EINVAL)?; } let mut loader = [0u8; wire::LOADER_BYTES]; loader.copy_from_slice(&images[id::MAIN][0x640..0x640 + wire::LOADER_BYTES]); - // Host startup policy: Main and PowerPerformance contain S9, but the + // Host startup policy: Main and PowerPerformance contain the top row, but the // published selectors remain S1 until the thermal owner admits a raise. for at in globals::PSTATE_SELECTORS { images[id::GLOBALS][at..at + 4].copy_from_slice(&100u32.to_le_bytes()); @@ -197,7 +202,11 @@ pub(crate) fn build( graph[i].write(0, &images[i])?; } - dev_info!(dev, "M4 initdata: 31 objects, 12 submit channel pairs, 42 loader records, S1 startup (S9 tables)\n"); + dev_info!( + dev, + "M4 initdata: 31 objects, 12 submit channel pairs, 42 loader records, S1 startup (S{} tables)\n", + ceiling + ); Ok(( InitData { globals: Some(graph[id::GLOBALS].clone()), @@ -213,6 +222,7 @@ pub(crate) fn build( uma: graph[id::UMA].clone(), parameter: graph[id::PARAMETER].clone(), root: graph[id::ROOT].clone(), + rows, loader, _graph: graph, }, diff --git a/drivers/gpu/drm/asahi/g16/mod.rs b/drivers/gpu/drm/asahi/g16/mod.rs index f161b218a0d06..8287d6fd140f1 100644 --- a/drivers/gpu/drm/asahi/g16/mod.rs +++ b/drivers/gpu/drm/asahi/g16/mod.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only OR MIT -//! G16 GPU support (T8132, M4: J713; the qualified 25G83 firmware). +//! G16 GPU support (T8132, M4: J713 and J773g; the qualified 25G83 firmware). //! //! G16 firmware is *classic*: one ring per engine (TA, FS, compute) and ordering expressed by //! in-ring barrier records that wait on another queue's stamp, unlike the G17 kick-ring/QID @@ -456,7 +456,7 @@ impl Firmware { dev: &AsahiDrmDevice, booted: boot::Booted, shared: &Arc, - power: power::Power, + mut power: power::Power, ) -> Result> { let boot::Booted { session, @@ -470,6 +470,7 @@ impl Firmware { dev.as_ref(), "G16: firmware at READY, starting the backend\n" ); + power.set_table(init.rows); let orphan = |session: boot::Session, objects: object::Objects, channels: channel::Channels, diff --git a/drivers/gpu/drm/asahi/g16/power.rs b/drivers/gpu/drm/asahi/g16/power.rs index 5e3346e3cf1e2..ae07876b3b45b 100644 --- a/drivers/gpu/drm/asahi/g16/power.rs +++ b/drivers/gpu/drm/asahi/g16/power.rs @@ -24,7 +24,7 @@ use super::fw::initdata::globals; use super::recovery::now_ns; use super::regs::wmb; use super::Firmware; -use policy::{COOLING_MAX, PSTATE_MAX}; +use policy::{COOLING_MAX, TOP_DEFAULT}; static_assert!(globals::PSTATE_SELECTORS[0] == 0x88); static_assert!(globals::PSTATE_SELECTORS[1] == 0x8c); @@ -155,6 +155,8 @@ pub(crate) struct Power { cooling: Cooling, sample: Sample, last_sample_ns: Option, + /// The board's top state: S9 on the ten-row tables, S10 on the J773g table. + pub(crate) top: u32, pub(crate) configured: u32, pub(crate) user: u32, pub(crate) effective: u32, @@ -170,7 +172,7 @@ pub(crate) struct Power { } impl Power { - /// The Main image initializes all nine active states. Initdata publishes + /// The Main image initializes every active state of the board's table. Initdata publishes /// startup S1 before INIT; this object starts with that same effective state. pub(crate) fn new(dev: &device::Device) -> Result { Ok(Self { @@ -185,8 +187,9 @@ impl Power { backstop: COOLING_MAX, }, last_sample_ns: None, - configured: PSTATE_MAX, - user: PSTATE_MAX, + top: TOP_DEFAULT, + configured: TOP_DEFAULT, + user: TOP_DEFAULT, effective: 1, temperature_mc: 0, governor: COOLING_MAX, @@ -200,6 +203,17 @@ impl Power { }) } + /// Adopts the board's firmware table, `rows` rows including off, before the first + /// governed publication: its top row is the governor's top state and configured + /// ceiling. The J773g table has eleven rows, so its top state is S10. + pub(crate) fn set_table(&mut self, rows: u32) { + let top = policy::top_of(rows); + self.top = top; + self.configured = top; + self.user = top; + self.utilization.top = top; + } + /// Reports a change of work in flight to the CLPC: the memory and fabric /// floor follows it, not the GFX power state. pub(crate) fn report_work(&mut self, in_flight: bool) { @@ -221,7 +235,7 @@ impl Power { self.budget = self.sample.budget; } let level = self.governor.max(self.budget).max(self.sample.backstop); - let ceiling = PSTATE_MAX - level.min(COOLING_MAX); + let ceiling = policy::cooling_ceiling(self.top, level); let limit = policy::limit(self.configured, ceiling, self.user); let decision = ( limit, diff --git a/drivers/gpu/drm/asahi/g16/power/policy.rs b/drivers/gpu/drm/asahi/g16/power/policy.rs index 0d127b8a5f817..9b7021178b177 100644 --- a/drivers/gpu/drm/asahi/g16/power/policy.rs +++ b/drivers/gpu/drm/asahi/g16/power/policy.rs @@ -6,7 +6,11 @@ //! Temperature decoding and regulation belong to the PMP provider and the //! shared C cooling policy. This module defines no temperature thresholds. -pub(crate) const PSTATE_MAX: u32 = 9; +/// Highest selector any M4 table can have: S9 on the ten-row tables, S10 on the +/// eleven-row ones (J604, J773g). The board's own top state (`top`) bounds every request. +pub(crate) const PSTATE_MAX: u32 = 10; +/// Top state of the ten-row tables, used until the board's table is known. +pub(crate) const TOP_DEFAULT: u32 = 9; pub(crate) const COOLING_MAX: u32 = 8; pub(crate) const SAMPLE_NS: u64 = 5_000_000; /// Utilization window of the governor. @@ -21,11 +25,26 @@ pub(crate) fn read_due(last: Option, now: u64) -> bool { } /// Zero is not an unlimited selector in the firmware. Every published state -/// is 1..=9, bounded by the initialized Main table and the user ceiling. +/// is 1..=top, bounded by the initialized Main table and the user ceiling. pub(crate) fn limit(configured: u32, ceiling: u32, user: u32) -> u32 { ceiling.min(PSTATE_MAX).min(configured).min(user).max(1) } +/// The board's top state, from its firmware table's row count (row 0 is off). +pub(crate) fn top_of(rows: u32) -> u32 { + rows.saturating_sub(1).clamp(FLOOR, PSTATE_MAX) +} + +/// The cooling ceiling for a cooling `level` (0..=COOLING_MAX) under the board's `top` +/// state: one state per level below the top, and S1 at full cooling on every table. +pub(crate) fn cooling_ceiling(top: u32, level: u32) -> u32 { + if level >= COOLING_MAX { + 1 + } else { + top.saturating_sub(level).max(1) + } +} + /// Percentage of `window` ns the GPU was busy for. pub(crate) fn utilization(busy: u64, window: u64) -> u32 { if window == 0 { @@ -53,9 +72,10 @@ pub(crate) fn smooth(average: u32, util: u32, window: u64) -> u32 { /// The state to request from the `current` published one: up on the last /// window's utilization `util`, to the top state under heavy load, and down /// on the smoothed `average`, to the floor when idle. -pub(crate) fn demand(current: u32, util: u32, average: u32) -> u32 { +pub(crate) fn demand(current: u32, util: u32, average: u32, top: u32) -> u32 { + let top = top.clamp(FLOOR, PSTATE_MAX); let next = if util >= 70 { - PSTATE_MAX + top } else if util >= 40 { current.saturating_add(1) } else if average < 10 { @@ -65,7 +85,7 @@ pub(crate) fn demand(current: u32, util: u32, average: u32) -> u32 { } else { current }; - next.clamp(FLOOR, PSTATE_MAX) + next.clamp(FLOOR, top) } /// Busy-time accounting over the governor's windows. The engine reports each @@ -74,6 +94,8 @@ pub(crate) struct Governor { /// The requested state and the smoothed utilization. pub(crate) demand: u32, pub(crate) average: u32, + /// The board's top state. + pub(crate) top: u32, window_ns: u64, busy_since: Option, busy_ns: u64, @@ -84,6 +106,7 @@ impl Governor { Self { demand: FLOOR, average: 0, + top: TOP_DEFAULT, window_ns: 0, busy_since: None, busy_ns: 0, @@ -123,7 +146,7 @@ impl Governor { } let util = utilization(self.busy_ns, window); self.average = smooth(self.average, util, window); - self.demand = demand(self.demand.min(limit), util, self.average); + self.demand = demand(self.demand.min(limit), util, self.average, self.top); self.window_ns = now; self.busy_ns = 0; } @@ -135,6 +158,9 @@ impl Governor { mod tests { use super::*; + /// The ten-row tables' top state; the J773g cases name theirs. + const TOP: u32 = TOP_DEFAULT; + #[test] fn provider_sampling_is_independent_of_completion_polling() { assert!(read_due(None, 0)); @@ -146,7 +172,7 @@ mod tests { #[test] fn initialized_selectors_and_user_caps_bound_every_request() { - assert_eq!(COOLING_MAX, PSTATE_MAX - 1); + assert_eq!(COOLING_MAX, TOP_DEFAULT - 1); for configured in [0, 1, 7, 9, 10, u32::MAX] { for ceiling in [0, 1, 5, 9, 10, u32::MAX] { for user in [0, 1, 3, 9, 10, u32::MAX] { @@ -180,7 +206,7 @@ mod tests { assert_eq!(smooth(u32::MAX, u32::MAX, w), 100); let mut average = 100; let mut windows = 0; - while demand(PSTATE_MAX, 0, average) != FLOOR { + while demand(TOP, 0, average, TOP) != FLOOR { average = smooth(average, 0, w); windows += 1; } @@ -189,23 +215,23 @@ mod tests { #[test] fn demand_rises_fast_and_falls_on_the_average() { - assert_eq!(demand(FLOOR, 100, 0), PSTATE_MAX); - assert_eq!(demand(FLOOR, 70, 0), PSTATE_MAX); - assert_eq!(demand(4, 50, 0), 5); - assert_eq!(demand(PSTATE_MAX, 50, 0), PSTATE_MAX); + assert_eq!(demand(FLOOR, 100, 0, TOP), TOP); + assert_eq!(demand(FLOOR, 70, 0, TOP), TOP); + assert_eq!(demand(4, 50, 0, TOP), 5); + assert_eq!(demand(TOP, 50, 0, TOP), TOP); // A short dip under a busy average holds the state. - assert_eq!(demand(PSTATE_MAX, 5, 80), PSTATE_MAX); - assert_eq!(demand(6, 30, 30), 6); - assert_eq!(demand(6, 20, 20), 5); - assert_eq!(demand(PSTATE_MAX, 0, 5), FLOOR); + assert_eq!(demand(TOP, 5, 80, TOP), TOP); + assert_eq!(demand(6, 30, 30, TOP), 6); + assert_eq!(demand(6, 20, 20, TOP), 5); + assert_eq!(demand(TOP, 0, 5, TOP), FLOOR); // A light 60 fps load near 25% busy settles on the floor. - assert_eq!(demand(FLOOR, 25, 24), FLOOR); - assert_eq!(demand(1, 30, 30), FLOOR); - for current in [0, 1, FLOOR, 7, PSTATE_MAX, u32::MAX] { + assert_eq!(demand(FLOOR, 25, 24, TOP), FLOOR); + assert_eq!(demand(1, 30, 30, TOP), FLOOR); + for current in [0, 1, FLOOR, 7, TOP, u32::MAX] { for util in [0, 20, 50, 70, 100, u32::MAX] { for average in [0, 9, 20, 30, 100, u32::MAX] { - let next = demand(current, util, average); - assert!((FLOOR..=PSTATE_MAX).contains(&next)); + let next = demand(current, util, average, TOP); + assert!((FLOOR..=TOP).contains(&next)); } } } @@ -216,7 +242,7 @@ mod tests { /// A governor whose first window closed idle at `T`. fn started() -> Governor { let mut governor = Governor::new(); - assert_eq!(governor.govern(T, PSTATE_MAX, false), FLOOR); + assert_eq!(governor.govern(T, TOP, false), FLOOR); assert_eq!(governor.average, 0); governor } @@ -232,10 +258,10 @@ mod tests { // A drain without a publication adds nothing. g.idle(T + 9_000_000); // A service before the window is due changes nothing. - assert_eq!(g.govern(T + w - 1, PSTATE_MAX, false), FLOOR); + assert_eq!(g.govern(T + w - 1, TOP, false), FLOOR); assert_eq!(g.average, 0); // 5 ms of 20 ms: 25%, a quarter of it in the average. - assert_eq!(g.govern(T + w, PSTATE_MAX, false), FLOOR); + assert_eq!(g.govern(T + w, TOP, false), FLOOR); assert_eq!(g.average, 6); } @@ -246,13 +272,13 @@ mod tests { g.busy(T); assert!(!g.decaying()); // Busy through the window: all of it counts, and the load gets the top state. - assert_eq!(g.govern(T + w, PSTATE_MAX, true), PSTATE_MAX); + assert_eq!(g.govern(T + w, TOP, true), TOP); assert_eq!(g.average, 25); // Busy above the floor: the engine's own polls govern it, not the idle re-arm. assert!(!g.decaying()); // The span carries on from the window's end, not from its publication. g.idle(T + w + w / 2); - assert_eq!(g.govern(T + 2 * w, PSTATE_MAX, false), PSTATE_MAX); + assert_eq!(g.govern(T + 2 * w, TOP, false), TOP); assert_eq!(g.average, (3 * 25 + 50) / 4); } @@ -263,15 +289,15 @@ mod tests { g.busy(T); // Recovery dropped the flights and reported no drain: the next service, // finding none outstanding, ends the span there. - assert_eq!(g.govern(T + w / 2, PSTATE_MAX, false), FLOOR); + assert_eq!(g.govern(T + w / 2, TOP, false), FLOOR); assert!(!g.decaying()); - assert_eq!(g.govern(T + w, PSTATE_MAX, false), FLOOR + 1); + assert_eq!(g.govern(T + w, TOP, false), FLOOR + 1); assert_eq!(g.average, 50 / 4); // Idle above the floor: the poll keeps coming back. assert!(g.decaying()); // A late drain report counts nothing more. g.idle(T + w + 1); - assert_eq!(g.govern(T + 2 * w, PSTATE_MAX, false), FLOOR); + assert_eq!(g.govern(T + 2 * w, TOP, false), FLOOR); assert!(!g.decaying()); } @@ -281,7 +307,7 @@ mod tests { let mut g = started(); g.busy(T); for n in 1..=8 { - assert_eq!(g.govern(T + n * w, PSTATE_MAX, true), PSTATE_MAX); + assert_eq!(g.govern(T + n * w, TOP, true), TOP); } let mut now = T + 8 * w; g.idle(now); @@ -289,21 +315,21 @@ mod tests { let mut passes = 0; while g.decaying() { now += w; - g.govern(now, PSTATE_MAX, false); + g.govern(now, TOP, false); passes += 1; assert!(passes <= 10); } assert_eq!(g.demand, FLOOR); assert!(passes > 1); // At the floor nothing re-arms, and a later service holds it there. - assert_eq!(g.govern(now + 10 * w, PSTATE_MAX, false), FLOOR); + assert_eq!(g.govern(now + 10 * w, TOP, false), FLOOR); assert!(!g.decaying()); // A long sleep between passes restarts the average and drops at once. let mut g = started(); g.busy(T); - assert_eq!(g.govern(T + w, PSTATE_MAX, true), PSTATE_MAX); + assert_eq!(g.govern(T + w, TOP, true), TOP); g.idle(T + w); - assert_eq!(g.govern(T + 6 * w, PSTATE_MAX, false), FLOOR); + assert_eq!(g.govern(T + 6 * w, TOP, false), FLOOR); assert!(!g.decaying()); } @@ -318,7 +344,7 @@ mod tests { assert_eq!(g.govern(T + 2 * w, 1, true), 1); assert_eq!(g.govern(T + 2 * w + 1, 2, true), 2); // Released, the load's request applies at once. - assert_eq!(g.govern(T + 2 * w + 2, PSTATE_MAX, true), PSTATE_MAX); + assert_eq!(g.govern(T + 2 * w + 2, TOP, true), TOP); // Idle under a ceiling below the floor: one window gives it all back. g.idle(T + 3 * w); assert!(g.decaying()); @@ -326,4 +352,39 @@ mod tests { assert_eq!(g.demand, FLOOR); assert!(!g.decaying()); } + + #[test] + fn the_board_table_sets_the_top_state() { + // Ten rows (J713): top S9. Eleven rows (J604, J773g): top S10 (1578 MHz on the Mac mini). + assert_eq!(top_of(10), 9); + assert_eq!(top_of(11), 10); + assert_eq!(top_of(12), PSTATE_MAX); + assert_eq!(top_of(0), FLOOR); + for top in [9, 10] { + assert_eq!(demand(FLOOR, 100, 0, top), top); + assert_eq!(demand(top, 50, 80, top), top); + assert_eq!(demand(top, 0, 5, top), FLOOR); + let mut g = Governor::new(); + g.top = top; + assert_eq!(g.govern(T, top, false), FLOOR); + g.busy(T); + assert_eq!(g.govern(T + WINDOW_NS, top, true), top); + // A ceiling still bounds the request. + assert_eq!(g.govern(T + 2 * WINDOW_NS, top - 1, true), top - 1); + } + } + + #[test] + fn cooling_keeps_one_state_per_level_and_s1_at_full_cooling() { + // Ten-row tables: unchanged, 9 - level, S1 at level 8. + for level in 0..=COOLING_MAX { + assert_eq!(cooling_ceiling(9, level), 9 - level); + } + // Eleven rows: S10..S3 for levels 0..7, S1 at full cooling. + assert_eq!(cooling_ceiling(10, 0), 10); + assert_eq!(cooling_ceiling(10, 7), 3); + assert_eq!(cooling_ceiling(10, COOLING_MAX), 1); + assert_eq!(cooling_ceiling(10, u32::MAX), 1); + assert_eq!(limit(10, cooling_ceiling(10, 0), 10), 10); + } } diff --git a/drivers/gpu/drm/asahi/g16/regs.rs b/drivers/gpu/drm/asahi/g16/regs.rs index e264e319c2a64..56e034ec89a5a 100644 --- a/drivers/gpu/drm/asahi/g16/regs.rs +++ b/drivers/gpu/drm/asahi/g16/regs.rs @@ -21,6 +21,8 @@ use kernel::{ prelude::*, }; +use core::sync::atomic::{AtomicU32, Ordering}; + use crate::regs::G16Resources; /// Write memory barrier (`wmb()`): `dsb st`. @@ -179,6 +181,9 @@ pub(crate) struct Regs { status: Mapping, /// Host-owned generation register page (SGX +0xd60000). generation: Mapping, + /// Highest firmware performance state the board's table holds: S9 until the table is + /// known (the ten-row tables), S10 on the eleven-row ones. + top: AtomicU32, } impl Regs { @@ -198,6 +203,7 @@ impl Regs { asc: window(c_str!("asc"), 0)?, status: window(c_str!("sgx"), SGX_STATUS as u64)?, generation: window(c_str!("sgx"), 0xd60000)?, + top: AtomicU32::new(9), res, }) } @@ -216,10 +222,22 @@ impl Regs { }) } - /// Actual cold or running firmware pstate (zero is valid while stopped). + /// Adopts the board's firmware performance table, `rows` rows including off. + pub(crate) fn set_table(&self, rows: u32) { + let top = rows.saturating_sub(1).clamp(1, super::fw::initdata::PERF_STATES as u32 - 1); + self.top.store(top, Ordering::Relaxed); + } + + /// Highest performance state the firmware may run in. + pub(crate) fn top(&self) -> u32 { + self.top.load(Ordering::Relaxed) + } + + /// Actual cold or running firmware pstate (zero is valid while stopped). A state above the + /// board table's top row is a protocol error. pub(crate) fn pstate(&self) -> Result { let state = self.res.sgx_read32_at(SGX_CORE + 0x1000)? & 0xf; - if state > 9 { + if state > self.top() { Err(super::boot::eproto()) } else { Ok(state) diff --git a/drivers/pmdomain/apple/pmp-report.c b/drivers/pmdomain/apple/pmp-report.c index 09325b041dd55..1b6702b95ecbf 100644 --- a/drivers/pmdomain/apple/pmp-report.c +++ b/drivers/pmdomain/apple/pmp-report.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -699,7 +700,7 @@ int apple_pmp_report_wait_supplier_ready(struct device *supplier, unsigned int t struct platform_device *pdev; struct apple_pmp_report *rep; u64 status; - bool t8132 = apple_t8132_firmware_path() && + bool t8132 = apple_pmp_t8132_retained_board() && of_device_is_compatible(supplier->of_node, "apple,t8132-pmp-v2"); int ret; diff --git a/drivers/soc/apple/pmp-display.c b/drivers/soc/apple/pmp-display.c index b32e155ec09f0..5b196447446a2 100644 --- a/drivers/soc/apple/pmp-display.c +++ b/drivers/soc/apple/pmp-display.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only OR MIT -/* Retained J713 DISP/AGX votes through the existing Rust PMP owner. - * Exactly one untagged request is in flight; invalid replies fail the epoch. +/* Retained J713 DISP and J713/J773g AGX votes through the existing Rust PMP + * owner. Exactly one untagged request is in flight; invalid replies fail the + * epoch. */ #include #include @@ -214,6 +215,7 @@ struct apple_pmp_display { struct pmp_power_vote vote; struct device_link *link[PMP_POWER_COUNT]; bool agx_table_valid; + bool disp_table_valid; }; /* One qualified supplier; published once, never freed during its epoch. */ @@ -222,7 +224,7 @@ static DEFINE_MUTEX(pmp_display_registration); bool apple_pmp_display_retained_board(void) { - return apple_pmp_j713_board(); + return apple_pmp_t8132_retained_board(); } /* The qualified loader publishes the existing PMP through its alias. */ @@ -238,24 +240,26 @@ struct apple_pmp_display *apple_pmp_display_register(struct device *dev, struct device_node *node, *qualified; const void *table; int size; - bool match, j713 = apple_pmp_j713_board(); + bool match; - if (!j713 || !dev->of_node || + if (!apple_pmp_t8132_retained_board() || !dev->of_node || !of_device_is_compatible(dev->of_node, "apple,t8132-pmp-v2")) return NULL; node = pmp_bridge_node(); match = node == dev->of_node; of_node_put(node); - if (j713) { - qualified = of_find_node_by_path("/soc/pmp@380500000"); - match = match && qualified == dev->of_node; - of_node_put(qualified); - } - /* J713 has a qualified fixed table shape. */ + qualified = of_find_node_by_path("/soc/pmp@380500000"); + match = match && qualified == dev->of_node; + of_node_put(qualified); + /* + * The tree carries the record of the consumer its PMP serves: the DISP + * record, or with no display consumer the AGX record. Either will do. + */ table = of_get_property(dev->of_node, "apple,tunable-soc-device", &size); if (!match || !of_property_present(dev->of_node, "apple,tunable-soc-device") || - !cookie || !send || (j713 && !j713_disp_table(table, size))) + !cookie || !send || + (!j713_agx_table(table, size) && !j713_disp_table(table, size))) return NULL; mutex_lock(&pmp_display_registration); if (pmp_display) @@ -267,7 +271,8 @@ struct apple_pmp_display *apple_pmp_display_register(struct device *dev, p->driver = dev->driver; p->cookie = cookie; p->send = send; - p->agx_table_valid = !j713 || j713_agx_table(table, size); + p->agx_table_valid = j713_agx_table(table, size); + p->disp_table_valid = j713_disp_table(table, size); mutex_init(&p->request); spin_lock_init(&p->lock); init_completion(&p->reply); @@ -275,8 +280,8 @@ struct apple_pmp_display *apple_pmp_display_register(struct device *dev, __module_get(THIS_MODULE); pm_runtime_get_noresume(dev); smp_store_release(&pmp_display, p); - dev_info(dev, "%s PMP vote bridge ready; retained existing PMP owner\n", - j713 ? "J713" : "J514S"); + dev_info(dev, "T8132 PMP vote bridge ready (%s record); retained existing PMP owner\n", + !p->disp_table_valid ? "AGX" : p->agx_table_valid ? "AGX+DISP" : "DISP"); out: mutex_unlock(&pmp_display_registration); return p; @@ -312,6 +317,22 @@ bool apple_pmp_display_receive(struct apple_pmp_display *p, u8 endpoint, u64 wor return true; /* This is a reply; never send an ACK for it. */ } +/* + * The DISP vote is the internal panel's: its consumer is the main DCP of a + * machine with a panel. A main DCP that is not available, or that drives a + * connector instead (it has apple,connector-type, as on a machine without a + * panel), is no DISP consumer, whatever records the PMP's table carries. + */ +static bool pmp_disp_consumer(void) +{ + struct device_node *dcp = of_find_node_by_path("dcp"); + bool panel = dcp && of_device_is_available(dcp) && + !of_property_present(dcp, "apple,connector-type"); + + of_node_put(dcp); + return panel && apple_pmp_j713_board(); +} + static struct apple_pmp_display *pmp_power_consumer(struct device *consumer, enum pmp_power_kind kind) { @@ -319,7 +340,7 @@ static struct apple_pmp_display *pmp_power_consumer(struct device *consumer, struct device_node *pmp, *supplier; bool match; - if (apple_pmp_j713_board()) { + if (kind == PMP_POWER_AGX ? apple_pmp_t8132_g16_board() : pmp_disp_consumer()) { /* Both consumers must name the exact boot-profile node. */ if ((kind != PMP_POWER_AGX && kind != PMP_POWER_DISP) || !consumer->of_node || !of_device_is_compatible(consumer->of_node, @@ -341,6 +362,8 @@ static struct apple_pmp_display *pmp_power_consumer(struct device *consumer, of_node_put(supplier); if (!match || (p && !p->agx_table_valid)) return ERR_PTR(-ENODEV); + } else if (p && !p->disp_table_valid) { + return ERR_PTR(-ENODEV); } return p ? p : ERR_PTR(-EPROBE_DEFER); } @@ -380,7 +403,7 @@ static int pmp_power_prepare(struct device *consumer, enum pmp_power_kind kind) } /* Rust checks the actual drvdata type; no provider exists before full binding. */ p = apple_pmp_display_bound_owner(&pdev->dev); - if (!p || (kind == PMP_POWER_AGX && !p->agx_table_valid)) { + if (!p || (kind == PMP_POWER_AGX ? !p->agx_table_valid : !p->disp_table_valid)) { device_link_del(link); ret = -ENODEV; goto out; @@ -520,7 +543,8 @@ EXPORT_SYMBOL_GPL(apple_pmp_j713_display_prepare); int apple_pmp_j713_gpu_prepare(struct device *consumer) { - return apple_pmp_j713_board() ? pmp_power_prepare(consumer, PMP_POWER_AGX) : -ENODEV; + return apple_pmp_t8132_g16_board() ? + pmp_power_prepare(consumer, PMP_POWER_AGX) : -ENODEV; } EXPORT_SYMBOL_GPL(apple_pmp_j713_gpu_prepare); @@ -538,7 +562,8 @@ EXPORT_SYMBOL_GPL(apple_pmp_j713_display_check_release); int apple_pmp_j713_gpu_check(struct device *consumer) { - return apple_pmp_j713_board() ? pmp_power_check(consumer, PMP_POWER_AGX, false) : -ENODEV; + return apple_pmp_t8132_g16_board() ? + pmp_power_check(consumer, PMP_POWER_AGX, false) : -ENODEV; } EXPORT_SYMBOL_GPL(apple_pmp_j713_gpu_check); @@ -556,6 +581,7 @@ EXPORT_SYMBOL_GPL(apple_pmp_j713_display_put); int apple_pmp_j713_gpu_get(struct device *consumer) { - return apple_pmp_j713_board() ? pmp_power_get(consumer, PMP_POWER_AGX) : -ENODEV; + return apple_pmp_t8132_g16_board() ? + pmp_power_get(consumer, PMP_POWER_AGX) : -ENODEV; } EXPORT_SYMBOL_GPL(apple_pmp_j713_gpu_get); diff --git a/drivers/soc/apple/pmp-telemetry.c b/drivers/soc/apple/pmp-telemetry.c index 788a5e3a4fac2..9e39f1e63b474 100644 --- a/drivers/soc/apple/pmp-telemetry.c +++ b/drivers/soc/apple/pmp-telemetry.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -19,7 +20,7 @@ bool apple_pmp_telemetry_retained_board(void) { - return apple_t8132_firmware_path() && of_machine_is_compatible("apple,t8132"); + return apple_pmp_t8132_retained_board(); } static LIST_HEAD(apple_pmp_telemetry_list); diff --git a/drivers/soc/apple/pmp.rs b/drivers/soc/apple/pmp.rs index a3c72483ee4be..e52b399c6b2e0 100644 --- a/drivers/soc/apple/pmp.rs +++ b/drivers/soc/apple/pmp.rs @@ -817,7 +817,7 @@ impl rtkit::Operations for PmpData { fn recv_message(data: ::Borrowed<'_>, _ep: u8, msg: u64) { let ret = data.recv_message(msg); if let Err(e) = ret { - // Only the retained J713 bridge latches a message it cannot + // Only the retained T8132 bridge latches a message it cannot // handle as fatal. Other boards log it and keep power commands. // SAFETY: read-only board identity check. if unsafe { bindings::apple_pmp_display_retained_board() } { @@ -857,7 +857,7 @@ struct PmpHwConfig { enum Ep7 { /// Never started. No, - /// Only on the retained J713 board. + /// Only on T8132 boards with a retained, qualified PMP session. RetainedBoard, /// On every board with this SoC. Always, @@ -942,7 +942,7 @@ impl platform::Driver for PmpDriver { type Data<'bound> = PmpDriver; fn suppress_bind_attrs() -> bool { - // Retained J713 power votes have no teardown path, and an unbound T8140 PMP still runs. + // Retained T8132 power votes have no teardown path, and an unbound T8140 PMP still runs. // SAFETY: read-only machine identity checks; other machines remain unchanged. unsafe { bindings::apple_pmp_keep_bound() } } @@ -988,7 +988,7 @@ impl platform::Driver for PmpDriver { } data.patch_bootargs(&pmp_mmio, &patches, cfg.check_bootargs_uuid)?; // EP7 is a startup dependency on every T6041 PMP, and on the - // retained J713 PMP among the T8132 boards. + // retained, qualified PMP session among the T8132 boards. let needs_coreanalytics = match cfg.coreanalytics { Ep7::No => false, Ep7::Always => true, diff --git a/include/linux/soc/apple/pmp-display.h b/include/linux/soc/apple/pmp-display.h index e65effb337aa8..23f45ae2259e8 100644 --- a/include/linux/soc/apple/pmp-display.h +++ b/include/linux/soc/apple/pmp-display.h @@ -12,6 +12,22 @@ static inline bool apple_pmp_j713_board(void) return apple_t8132_firmware_path() && of_machine_is_compatible("apple,t8132"); } +/* + * T8132: Linux retains the PMP firmware session the boot loader left + * running, on any OS firmware. + */ +static inline bool apple_pmp_t8132_retained_board(void) +{ + return of_machine_is_compatible("apple,t8132"); +} + +/* The G16 consumer of that session: only on the firmware it was run on. */ +static inline bool apple_pmp_t8132_g16_board(void) +{ + return apple_t8132_firmware_path() && + of_machine_is_compatible("apple,t8132"); +} + struct device; struct apple_pmp_display; @@ -30,12 +46,12 @@ void apple_pmp_display_fail(struct apple_pmp_display *display, int error); /* Internal: caller holds the bound supplier device lock. */ struct apple_pmp_display *apple_pmp_display_bound_owner(struct device *dev); -/* J713 votes share the existing PMP owner's untagged request stream. - * Prepare is probe-only; supplier links persist until reboot, and so do - * accepted votes, except that the DCP releases its DISP vote while it has - * powered the display domains down (put) and takes it again (get). Before - * that it asks, changing nothing, whether the vote can be released now and - * taken again later (check_release). +/* DISP (J713) and AGX (J713, J773g) votes share the existing PMP owner's + * untagged request stream. Prepare is probe-only; supplier links persist + * until reboot, and so do accepted votes, except that the J713 DCP releases + * its DISP vote while it has powered the display domains down (put) and + * takes it again (get). Before that it asks, changing nothing, whether the + * vote can be released now and taken again later (check_release). */ int apple_pmp_j713_display_prepare(struct device *consumer); int apple_pmp_j713_display_get(struct device *consumer); diff --git a/tools/asahi/pmp-disp-consumer-tests.py b/tools/asahi/pmp-disp-consumer-tests.py new file mode 100755 index 0000000000000..02af22fb452d8 --- /dev/null +++ b/tools/asahi/pmp-disp-consumer-tests.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only OR MIT +"""Host check of which device tree makes the main DCP a PMP DISP consumer. + +pmp_disp_consumer() of drivers/soc/apple/pmp-display.c is compiled against a +mocked "dcp" alias node. The DISP vote belongs to a machine with an internal +panel: an available main DCP without apple,connector-type. A main DCP that +drives a connector, one that is not available, a tree without the node and a +machine off the 26.6.2 firmware path are no consumers. With --mutations the +function is replaced by each constant and the test must then fail. +""" +import argparse +from pathlib import Path +import subprocess +import tempfile + + +def definition(source, name): + start = source.index(name) + start = source.rfind('\n', 0, start) + 1 + brace = source.index('{', start) + depth = 1 + end = brace + 1 + while depth: + depth += (source[end] == '{') - (source[end] == '}') + end += 1 + return source[start:end] + + +UNIT = r''' +#include +#include +#include +#include +#include +struct device_node { bool available, connector; }; +static struct device_node *alias; +static bool firmware_path; +static int puts_; +static struct device_node *of_find_node_by_path(const char *path) { assert(!strcmp(path, "dcp")); return alias; } +static bool of_device_is_available(const struct device_node *n) { return n->available; } +static bool of_property_present(const struct device_node *n, const char *p) +{ assert(!strcmp(p, "apple,connector-type")); return n->connector; } +static void of_node_put(struct device_node *n) { if (n) puts_++; } +static bool apple_pmp_j713_board(void) { return firmware_path; } +FUNCTION +int main(void) +{ + struct device_node panel = { true, false }, fixed = { true, true }; + struct device_node off = { false, false }, off_fixed = { false, true }; + + firmware_path = true; + alias = &panel; assert(pmp_disp_consumer()); /* a machine with a panel */ + alias = &fixed; assert(!pmp_disp_consumer()); /* its main DCP drives a connector */ + alias = &off; assert(!pmp_disp_consumer()); /* main DCP not available */ + alias = &off_fixed; assert(!pmp_disp_consumer()); + alias = NULL; assert(!pmp_disp_consumer()); /* no main DCP described */ + assert(puts_ == 4); + firmware_path = false; + alias = &panel; assert(!pmp_disp_consumer()); /* not the firmware the vote was run on */ + puts("DISP consumer selection: 6 cases"); + return 0; +} +''' + + +def run(cc, text, directory, name): + c = Path(directory) / (name + '.c') + binary = Path(directory) / name + c.write_text(text) + subprocess.run([cc, '-std=gnu11', '-Wall', '-Wextra', '-Werror', '-Wno-unused-function', + '-Wno-unused-parameter', str(c), '-o', str(binary)], check=True) + return subprocess.run([str(binary)], capture_output=True, text=True).returncode + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--source', type=Path, default=Path(__file__).resolve().parents[2]) + parser.add_argument('--cc', default='cc') + parser.add_argument('--mutations', action='store_true') + args = parser.parse_args() + source = (args.source / 'drivers/soc/apple/pmp-display.c').read_text() + function = definition(source, 'static bool pmp_disp_consumer(void)') + with tempfile.TemporaryDirectory(prefix='pmp-disp-') as directory: + assert run(args.cc, UNIT.replace('FUNCTION', function), directory, 'base') == 0 + print('PASS DISP consumer selection follows the main DCP node') + if args.mutations: + for value in ('true', 'false'): + constant = 'static bool pmp_disp_consumer(void) { return %s; }' % value + assert run(args.cc, UNIT.replace('FUNCTION', constant), directory, value) != 0, value + print('PASS 2 constant mutants fail') + + +if __name__ == '__main__': + main() diff --git a/tools/asahi/run-host-tests.py b/tools/asahi/run-host-tests.py index 1af0e3c242fc4..35b86c5caa572 100755 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -251,6 +251,7 @@ def mutations(flag, names, base, expect=KILL): + [(out('--output') + ['--old-usb'], KILL), (out('--output') + ['--old-regulatory'], KILL)], 'pciec-policy-tests.py': [(out(), PASS)], 'pmgr-bus-tests.py': [([], PASS)], + 'pmp-disp-consumer-tests.py': [([], PASS)], 'sep-suspend-errors-tests.py': [(out(), PASS)] + mutations('--mutation', ('unsupported-as-success', 'read-as-deadline', 'no-capability-check', 'no-transport-check', 'lost-accept', 'nonphysical-wake', diff --git a/tools/asahi/t6030-pmp-graph-tests.c b/tools/asahi/t6030-pmp-graph-tests.c index 13f8260dd985d..f4098dfa75e3d 100644 --- a/tools/asahi/t6030-pmp-graph-tests.c +++ b/tools/asahi/t6030-pmp-graph-tests.c @@ -482,6 +482,13 @@ static inline bool apple_t8132_firmware_path(void) { return apple_t8132_air(); } + +/* Production: . */ +static inline bool apple_pmp_t8132_retained_board(void) +{ + return apple_t8132_firmware_path() && + of_machine_is_compatible("apple,t8132"); +} static bool of_property_read_bool(const struct device_node *n, const char *p) { if (!strcmp(p, "apple,always-on")) diff --git a/tools/asahi/t6030-pmp-supplier-tests.c b/tools/asahi/t6030-pmp-supplier-tests.c index 7c3a7020b5215..7d0f27f88de9d 100644 --- a/tools/asahi/t6030-pmp-supplier-tests.c +++ b/tools/asahi/t6030-pmp-supplier-tests.c @@ -181,6 +181,13 @@ static inline bool apple_t8132_firmware_path(void) { return apple_t8132_air(); } + +/* Production: . */ +static inline bool apple_pmp_t8132_retained_board(void) +{ + return apple_t8132_firmware_path() && + of_machine_is_compatible("apple,t8132"); +} static struct device_node *of_find_compatible_node(struct device_node *from, const char *type, const char *compat) diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/check-initdata-bounds.rs b/tools/testing/selftests/drivers/gpu/asahi-m4/check-initdata-bounds.rs index 29b51ee5cefaf..72eae3a009585 100644 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/check-initdata-bounds.rs +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/check-initdata-bounds.rs @@ -6,12 +6,13 @@ const HOST: u64 = wire::HOST_START; fn emit(out:&mut Vec, value:Result)->Option { out.push(u8::from(value.is_err()));value.ok() } fn input()->wire::Input { wire::Input { - // Independently pinned qualified C/J713 bin for this immutable byte fixture. + // J713 frequencies with synthetic voltage bins. performance: wire::Performance { - frequency: [0,338,618,796,928,1056,1170,1278,1338,1470], - auxiliary: [0,338,618,796,836,952,1053,1152,1204,1326], - voltage: [125,610,645,680,725,780,825,865,895,970], - sram: [780,780,780,780,780,780,825,865,895,970], + count: 10, + frequency: [0,338,618,796,928,1056,1170,1278,1338,1470,0], + auxiliary: [0,338,618,796,836,952,1053,1152,1204,1326,0], + voltage: [100,600,650,700,750,800,850,900,950,1000,0], + sram: [800,800,800,800,800,800,850,900,950,1000,0], }, va: core::array::from_fn(|i|HOST+0x100000+i as u64*0x100000), channel_state:core::array::from_fn(|i|HOST+0x4000000+i as u64*0x10000), diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/check-initdata.rs b/tools/testing/selftests/drivers/gpu/asahi-m4/check-initdata.rs index 97d526fbf504f..98419052d41ad 100644 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/check-initdata.rs +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/check-initdata.rs @@ -7,12 +7,13 @@ fn input(variant: u64) -> initdata::Input { let start = 0xfffffc2000000000u64; let shift = variant * 0x100000000; let mut input = initdata::Input { - // Independently pinned qualified C/J713 bin for this immutable byte fixture. + // J713 frequencies with synthetic voltage bins. performance: initdata::Performance { - frequency: [0,338,618,796,928,1056,1170,1278,1338,1470], - auxiliary: [0,338,618,796,836,952,1053,1152,1204,1326], - voltage: [125,610,645,680,725,780,825,865,895,970], - sram: [780,780,780,780,780,780,825,865,895,970], + count: 10, + frequency: [0,338,618,796,928,1056,1170,1278,1338,1470,0], + auxiliary: [0,338,618,796,836,952,1053,1152,1204,1326,0], + voltage: [100,600,650,700,750,800,850,900,950,1000,0], + sram: [800,800,800,800,800,800,850,900,950,1000,0], }, va: core::array::from_fn(|i| start + shift + 0x100000 + i as u64 * 0x100000), channel_state: core::array::from_fn(|i| start + shift + 0x4000000 + i as u64 * 0x10000), @@ -41,12 +42,22 @@ fn main() { let mut slices: [&mut [u8]; initdata::OBJECT_COUNT] = buffers.each_mut().map(|buffer| buffer.as_mut_slice()); initdata::encode(&mut slices, &input(variant as u64), ceiling).expect("valid C fixture rejected"); let got: Vec<_> = buffers.into_iter().flatten().collect(); - let expected = std::fs::read(directory.join(format!("initdata-{variant}.bin"))).unwrap(); + let mut expected = + std::fs::read(directory.join(format!("initdata-{variant}.bin"))).unwrap(); + // Substitute synthetic voltages in the immutable C golden before comparison. + let main: usize = initdata::OBJECT_SIZE[..initdata::id::MAIN].iter().sum(); + let perf = input(variant as u64).performance; + for i in 0..=ceiling as usize { for lane in 0..16 { + for (offset, value) in [(0x1008, perf.voltage[i]), (0x1408, perf.sram[i])] { + let at = main + offset + (i * 16 + lane) * 4; + expected[at..at+4].copy_from_slice(&value.to_le_bytes()); + } + }} if let Some(offset) = got.iter().zip(&expected).position(|(a, b)| a != b) { panic!("initdata variant {variant} differs at {offset:#x}: C={:#x}, Rust={:#x}", expected[offset], got[offset]); } assert_eq!(got.len(), expected.len()); bytes_checked += got.len(); } - println!("3 initdata fixtures / {bytes_checked} output bytes match qualified C exactly"); + println!("3 initdata fixtures / {bytes_checked} bytes match C with synthetic voltages"); } diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/fixtures/m4-perf-source-j773g.json b/tools/testing/selftests/drivers/gpu/asahi-m4/fixtures/m4-perf-source-j773g.json new file mode 100644 index 0000000000000..c7102de386272 --- /dev/null +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/fixtures/m4-perf-source-j773g.json @@ -0,0 +1,16 @@ +{ + "provenance": { + "source": "Mac mini (J773g, Mac16,10) ADT read from the running machine on the macOS 27.2 (26B123) stub; the GPU performance-state properties match the 26.6.2 ADT byte for byte", + "source_sha256": "e0487b2be078c7e8e098ab4432b92b0c3d99ebf852ba8e29fa35fc983468f3b8", + "source_bytes": 475136, + "extraction": "Exact property values from /arm-io/sgx. Names and unrelated nodes omitted. No serial identifiers or full ADT included." + }, + "properties_hex": { + "compatible": "6770752c743831333200", + "perf-state-count": "10000000", + "perf-state-table-count": "01000000", + "gpu-num-perf-states": "0f000000", + "perf-states": "000000007d000000807825146202000080eed5248002000000ff712f9e02000000285037cb020000005ebe38020300000048f13e020300004081c33e2f03000080c8bc452f0300000020aa446603000080bb2c4c660300000095c347840300008042c04f840300008027094fca030000806b9e57ca030000805e0e5e15040000", + "perf-states-sram": "000000000c030000807825140c03000080eed5240c03000000ff712f0c030000002850370c030000005ebe380c0300000048f13e0c0300004081c33e2f03000080c8bc452f0300000020aa446603000080bb2c4c660300000095c347840300008042c04f840300008027094fca030000806b9e57ca030000805e0e5e15040000" + } +} diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/test-perf.py b/tools/testing/selftests/drivers/gpu/asahi-m4/test-perf.py index 36574512d4298..3cf885743de60 100755 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-perf.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-perf.py @@ -26,6 +26,14 @@ def node(props, children=()): # Minimal synthetic envelope around exact measured properties, with no unrelated machine data. image = node({'name': b'device-tree\0'}, [node({'name': b'arm-io\0'}, [node({'name': b'sgx\0', **properties})])]) blob = out / 'measured-perf.adt' +# The Mac mini's own properties (five low states, five pairs, a top state), in the same envelope. +j773g_fixture = HERE / 'fixtures/m4-perf-source-j773g.json' +if sha(j773g_fixture) != '3248fe413aa6bd9206baf2f41e2eaa8154452a2ba0eda65131382e04dccbedd7': + raise RuntimeError('J773g original ADT performance fixture changed') +j773g_properties = {name: bytes.fromhex(value) + for name, value in json.loads(j773g_fixture.read_text())['properties_hex'].items()} +j773g_blob = out / 'measured-perf-j773g.adt' +j773g_blob.write_bytes(node({'name': b'device-tree\0'}, [node({'name': b'arm-io\0'}, [node({'name': b'sgx\0', **j773g_properties})])])) blob.write_bytes(image) backend = root / 'drivers/gpu/drm/asahi/g16' source = r''' @@ -37,6 +45,7 @@ def node(props, children=()): } use backend::{adt::perf, board::data, fw::initdata as wire}; const MEASURED: &[u8] = include_bytes!("@FIXTURE@"); +const MEASURED_J773G: &[u8] = include_bytes!("@FIXTURE_J773G@"); fn put32(out: &mut [u8], at: usize, value: u32) { out[at..at+4].copy_from_slice(&value.to_le_bytes()); } fn property_offset(data: &[u8], name: &[u8]) -> usize { data.windows(32).position(|value| value.starts_with(name) && value[name.len()..].iter().all(|&x| x==0)).unwrap() @@ -66,11 +75,74 @@ def node(props, children=()): fn get32(bytes: &[u8], at: usize) -> u32 { u32::from_le_bytes(bytes[at..at+4].try_into().unwrap()) } #[test] fn measured_original_adt_produces_qualified_tables() { let s=source(); assert_eq!(s.count,16); - let p=tables(); - assert_eq!(p.frequency,[0,338,618,796,928,1056,1170,1278,1338,1470]); - assert_eq!(p.auxiliary,[0,338,618,796,836,952,1053,1152,1204,1326]); - assert_eq!(p.voltage,[125,610,645,680,725,780,825,865,895,970]); - assert_eq!(p.sram,[780,780,780,780,780,780,825,865,895,970]); + // Keep the original frequency layout but use synthetic voltage bins. + let mut s=s; + s.core_mv[..16].copy_from_slice(&[100,600,650,700,750,750,800,800,850,850,900,900,950,950,1000,1000]); + s.sram_mv[..16].copy_from_slice(&[800,800,800,800,800,800,800,800,850,850,900,900,950,950,1000,1000]); + let p=data::select(&s).unwrap(); assert_eq!(p.count,10); + assert_eq!(p.frequency,[0,338,618,796,928,1056,1170,1278,1338,1470,0]); + assert_eq!(p.auxiliary,[0,338,618,796,836,952,1053,1152,1204,1326,0]); + assert_eq!(p.voltage,[100,600,650,700,750,800,850,900,950,1000,0]); + assert_eq!(p.sram,[800,800,800,800,800,800,850,900,950,1000,0]); + assert_eq!(get32(&encode(p).unwrap()[wire::id::MAIN],0xfc0),10); +} +// J773g frequency layout with synthetic voltage bins, both with eleven groups. +fn j773g(core: [u32; 16], sram: [u32; 16]) -> perf::Source { + let mhz=[0,338,618,796,928,952,1056,1053,1170,1152,1278,1204,1338,1326,1470,1578]; + let mut s=source(); s.count=16; + s.frequency_mhz=[0;perf::MAX_STATES]; s.sram_frequency_mhz=[0;perf::MAX_STATES]; + s.core_mv=[0;perf::MAX_STATES]; s.sram_mv=[0;perf::MAX_STATES]; + s.frequency_mhz[..16].copy_from_slice(&mhz); s.sram_frequency_mhz[..16].copy_from_slice(&mhz); + s.core_mv[..16].copy_from_slice(&core); s.sram_mv[..16].copy_from_slice(&sram); + s +} +#[test] fn j773g_synthetic_bins_produce_eleven_rows_and_encode_all_of_them() { + for (core,sram,voltage,row_sram) in [ + ([100,600,620,660,700,750,750,800,800,850,850,900,900,950,950,1000], + [740,740,740,740,740,750,750,800,800,850,850,900,900,950,950,1000], + [100,600,620,660,700,750,800,850,900,950,1000], + [740,740,740,740,740,750,800,850,900,950,1000]), + ([100,590,630,650,690,730,730,790,790,840,840,890,890,940,940,990], + [760,760,760,760,760,760,760,790,790,840,840,890,890,940,940,990], + [100,590,630,650,690,730,790,840,890,940,990], + [760,760,760,760,760,760,790,840,890,940,990]), + ] { + let (p,name)=data::select_named(&j773g(core,sram)).unwrap(); + assert_eq!(name,"5+5 pairs+top"); assert_eq!(p.count,11); + assert_eq!(p.frequency,[0,338,618,796,928,1056,1170,1278,1338,1470,1578]); + assert_eq!(p.auxiliary,[0,338,618,796,928,952,1053,1152,1204,1326,1578]); + assert_eq!(p.voltage,voltage); assert_eq!(p.sram,row_sram); + let mut buffers=wire::OBJECT_SIZE.map(|size|vec![0xa5;size]); + wire::encode(&mut buffers.each_mut().map(|b|b.as_mut_slice()),&input(p.clone()),10).unwrap(); + let main=&buffers[wire::id::MAIN]; + assert_eq!(get32(main,0xfc0),11); assert_eq!(get32(main,0xfc4),10); + for i in 0..11 { + assert_eq!(get32(main,0xfc8+i*4),p.frequency[i]); + assert_eq!(get32(main,0x1808+i*4),p.auxiliary[i]); + assert_eq!(get32(main,0x1008+i*16*4),p.voltage[i]); + assert_eq!(get32(main,0x1408+(i*16+15)*4),p.sram[i]); + } + } +} +#[test] fn the_row_count_bounds_the_encoded_ceiling() { + let j713=tables(); let j773g=data::select_named(&j773g( + [100,600,620,660,700,750,750,800,800,850,850,900,900,950,950,1000], + [740,740,740,740,740,750,750,800,800,850,850,900,900,950,950,1000])).unwrap().0; + for (p,good,bad) in [(j713,[1,9],[0,10]),(j773g,[1,10],[0,11])] { + for ceiling in good { + let mut buffers=wire::OBJECT_SIZE.map(|size|vec![0xa5;size]); + assert!(wire::encode(&mut buffers.each_mut().map(|b|b.as_mut_slice()),&input(p.clone()),ceiling).is_ok()); + assert_eq!(get32(&buffers[wire::id::MAIN],0xfc0),p.count as u32); + } + for ceiling in bad { + let mut buffers=wire::OBJECT_SIZE.map(|size|vec![0xa5;size]); + assert!(wire::encode(&mut buffers.each_mut().map(|b|b.as_mut_slice()),&input(p.clone()),ceiling).is_err()); + assert!(buffers.iter().all(|buffer|buffer.iter().all(|&byte|byte==0xa5))); + } + } + // Rows past the count must stay zero, and the count must match the rows. + let mut p=tables(); p.frequency[10]=1500; assert!(!p.valid()); + let mut p=tables(); p.count=11; assert!(!p.valid()); } #[test] fn different_real_bin_values_reach_all_firmware_lanes() { let mut raw=MEASURED.to_vec(); @@ -134,11 +206,28 @@ def node(props, children=()): let mut s=source();s.frequency_mhz[4]=s.frequency_mhz[5]+1;s.sram_frequency_mhz[4]=s.frequency_mhz[4];assert!(data::select(&s).is_err()); let mut s=source();s.frequency_mhz[7]=s.frequency_mhz[5];s.sram_frequency_mhz[7]=s.frequency_mhz[7];assert!(data::select(&s).is_err()); let mut s=source();s.core_mv[14]=600;s.core_mv[15]=600;assert!(data::select(&s).is_err()); + // Three states at one voltage, and split pairs, match no layout. + let mut s=source();s.core_mv[6]=s.core_mv[5];s.sram_mv[6]=s.sram_mv[5];assert!(data::select(&s).is_err()); + let mut s=source();s.core_mv[4]-=1;s.core_mv[6]-=1;assert!(data::select(&s).is_err()); } -#[test] fn j604_shape_selects_its_own_layout_and_the_j713_keeps_its_own() { - assert_eq!(data::select_named(&source()).unwrap().1,"J713"); - // J604 shape: five low states, equal-voltage pairs 5/6 to 13/14, a single top state 15. - // Rows 0-3 and 5-15 are the J604's selected values; state 4 (left out) is synthetic. +#[test] fn measured_adts_give_ten_rows_on_the_j713_and_eleven_on_the_j773g() { + // The two machines' own, unmodified ADT states: the count is derived from each. + let (p,name)=data::select_named(&perf::parse(MEASURED).unwrap()).unwrap(); + assert_eq!((p.count,name),(10,"4+6 pairs")); + let s=perf::parse(MEASURED_J773G).unwrap(); assert_eq!(s.count,16); + let (p,name)=data::select_named(&s).unwrap(); + assert_eq!((p.count,name),(11,"5+5 pairs+top")); + assert_eq!(p.frequency,[0,338,618,796,928,1056,1170,1278,1338,1470,1578]); + assert_eq!(p.auxiliary,[0,338,618,796,928,952,1053,1152,1204,1326,1578]); + assert_eq!(p.voltage,[125,610,640,670,715,770,815,870,900,970,1045]); + assert!(encode(p).is_ok()); +} +#[test] fn the_row_count_follows_from_the_shape_of_the_adt_states() { + // Four low states and six pairs (the J713's own values): ten rows. + let (p,name)=data::select_named(&source()).unwrap(); + assert_eq!(name,"4+6 pairs"); assert_eq!(p.count,10); + // Five low states, pairs 5/6 to 13/14 and a single top state 15 (the J604's selected + // values; its state 4 is synthetic here): eleven rows, every state kept. let mhz=[0,338,618,796,928,952,1056,1053,1170,1152,1278,1204,1338,1326,1470,1578]; let mv=[125,625,640,680,725,780,780,825,825,865,865,895,895,970,970,1045]; let mut s=source(); @@ -147,13 +236,19 @@ def node(props, children=()): s.core_mv[i]=mv[i];s.sram_mv[i]=mv[i].max(780); } let (p,name)=data::select_named(&s).unwrap(); - assert_eq!(name,"J604"); - assert_eq!(p.frequency,[0,338,618,796,1056,1170,1278,1338,1470,1578]); - assert_eq!(p.auxiliary,[0,338,618,796,952,1053,1152,1204,1326,1578]); - assert_eq!(p.voltage,[125,625,640,680,780,825,865,895,970,1045]); - assert_eq!(p.sram,[780,780,780,780,780,825,865,895,970,1045]); - assert!(encode(p).is_ok()); - // A J604 shape with one unequal pair matches neither layout. + assert_eq!(name,"5+5 pairs+top"); assert_eq!(p.count,11); + assert_eq!(p.frequency,[0,338,618,796,928,1056,1170,1278,1338,1470,1578]); + assert_eq!(p.auxiliary,[0,338,618,796,928,952,1053,1152,1204,1326,1578]); + assert_eq!(p.voltage,[125,625,640,680,725,780,825,865,895,970,1045]); + assert!(encode(p.clone()).is_ok()); + // The same shape with the J773g's frequencies gives eleven rows too; no board is asked. + let (q,name)=data::select_named(&j773g(mv,mv.map(|v: u32| v.max(780)))).unwrap(); + assert_eq!(name,"5+5 pairs+top"); assert_eq!(q.count,11); + // The count is derived, not fixed: each shape keeps its own, and neither fits the other. + assert_ne!(data::select(&source()).unwrap().count,p.count); + assert_eq!(data::LAYOUTS.len(),2); + assert!(data::LAYOUTS.iter().any(|l| l.rows==10) && data::LAYOUTS.iter().any(|l| l.rows==11)); + // This shape with one unequal pair matches no layout. let mut bad=s;bad.core_mv[9]+=1;bad.sram_mv[9]+=1; assert_eq!(data::select(&bad),Err(perf::Error::Shape)); } @@ -167,7 +262,8 @@ def node(props, children=()): } ''' for marker, value in {'PARSER': backend / 'adt/perf.rs', 'ENCODER': backend / 'fw/initdata.rs', - 'SELECT': backend / 'board/data.rs', 'FIXTURE': blob}.items(): + 'SELECT': backend / 'board/data.rs', 'FIXTURE_J773G': j773g_blob, + 'FIXTURE': blob}.items(): source = source.replace('@' + marker + '@', str(value)) path = out / 'perf.rs' path.write_text(source) @@ -177,7 +273,7 @@ def node(props, children=()): print(run.stdout, end='') print(run.stderr, end='') run.check_returncode() -report = {'passed': True, 'test_groups': 8, 'hardware_validated': False, +report = {'passed': True, 'test_groups': 10, 'hardware_validated': False, 'fixture_sha256': sha(fixture), 'original_adt_sha256': metadata['provenance']['source_sha256'], 'production_sha256': {str(p.relative_to(root)): sha(p) for p in [backend / 'adt.rs', backend / 'adt/perf.rs', backend / 'board.rs', backend / 'board/data.rs', backend / 'initdata.rs', backend / 'fw/initdata.rs']}}