diff --git a/drivers/gpu/drm/asahi/fwid.rs b/drivers/gpu/drm/asahi/fwid.rs index df20d3c406626..5d5039dee0399 100644 --- a/drivers/gpu/drm/asahi/fwid.rs +++ b/drivers/gpu/drm/asahi/fwid.rs @@ -591,6 +591,36 @@ mod tests { } } + #[test] + fn t8140_identifies_current_and_26b123_graphs() { + use crate::g17::fw::m5::initdata::RootProfile; + let crate::g17::fw::variant::Firmware::Identified(builds) = + crate::hw::t8140::CONFIG.firmware + else { + panic!("T8140 must identify its loaded firmware"); + }; + assert_eq!(builds.len(), 2); + assert_eq!(builds[0].os_version, [27, 2, 0]); + assert_eq!(builds[1].os_version, [26, 6, 2]); + t6050_admits_only(builds); + + let [b123, g83] = [&builds[0].images[0], &builds[1].images[0]]; + assert_eq!((b123.text_size, b123.data_size), (0x9c000, 0x188000)); + assert_eq!((g83.text_size, g83.data_size), (0x98000, 0x260000)); + assert_ne!(b123.text_sha256, g83.text_sha256); + + assert!(builds[1].config.is_none()); + let config = builds[0].config.expect("26B123 needs its own graph"); + assert_eq!( + config + .m5 + .expect("26B123 needs a common-graph board") + .graph + .profile, + RootProfile::J873G18G26B123 + ); + } + #[test] fn t8142_identifies_each_build() { use crate::g17::fw::m5::initdata::RootProfile; diff --git a/drivers/gpu/drm/asahi/g17/fw/m5/initdata.rs b/drivers/gpu/drm/asahi/g17/fw/m5/initdata.rs index fa59271630930..84519cabea175 100644 --- a/drivers/gpu/drm/asahi/g17/fw/m5/initdata.rs +++ b/drivers/gpu/drm/asahi/g17/fw/m5/initdata.rs @@ -2319,11 +2319,14 @@ pub(crate) fn encode_common26_bundle_policy( /// Encode a common 26A428 region C from the board's 25G76 one: the fields from +0x38 on move up /// by four, plus the fields 26A428 added. Unlike [`encode_common26_region_c`] it keeps the /// board's own tunables (standby timer, minimum confidence, state counts). -pub(crate) fn encode_common26_board_region_c(out: &mut [u8]) -> Result<(), InitdataError> { +pub(crate) fn encode_common26_board_region_c( + board: &Board, + out: &mut [u8], +) -> Result<(), InitdataError> { if out.len() != REGION_C_SIZE { return Err(InitdataError::BufferSize); } - encode_region_c_for_profile(RootProfile::J813G17G25G76, out)?; + encode_region_c_for_profile(board.region_c_source, out)?; let shifted = ABI_ALLOCATION_SIZES_25G76[ALLOC_REGION_C]; if out[shifted..].iter().any(|byte| *byte != 0) { return Err(InitdataError::BufferSize); @@ -2346,8 +2349,8 @@ const fn hw_offset(board: &Board, offset: usize) -> usize { } } -/// What the M5 graph's HW data and power policy depend on per board. Every board is a T6050 -/// running the same firmware build; [`crate::g17::Config::m5`] names the board's. +/// What a packed G17 graph's HW data and power policy depend on per board. +/// [`crate::g17::Config::m5`] names the board selected by the identified build. pub(crate) struct Board { /// The chip ID the HW data names. chip_id: u32, @@ -2408,6 +2411,13 @@ pub(crate) struct Board { /// Whether explicit waits on other kicks take the completion class /// ([`Board::completion_inputs`]). completion_inputs: bool, + /// Whether queues and register programs use the single-cluster G17 forms shared by J700 + /// and J813 rather than the multi-cluster M5 Pro forms. + j813_forms: bool, + /// The 25G76-era region C layout the board's tunables come from, which + /// [`encode_common26_board_region_c`] moves to the common 26A428 layout: the board's own + /// firmware generation, not its chip ID. + region_c_source: RootProfile, } /// M5 Pro: two clusters of ten cores. @@ -2437,6 +2447,8 @@ pub(crate) const J714: Board = Board { fan_curve_start_mc: 84_000, g17d_forms: false, completion_inputs: true, + j813_forms: false, + region_c_source: RootProfile::J813G17G25G76, }; /// M5 Max: four clusters of ten cores. @@ -2468,6 +2480,8 @@ pub(crate) const J716C: Board = Board { fan_curve_start_mc: 84_000, g17d_forms: false, completion_inputs: false, + j813_forms: false, + region_c_source: RootProfile::J813G17G25G76, }; /// J775D's performance controllers run from P3. @@ -2509,6 +2523,110 @@ pub(crate) const J775D: Board = Board { fan_curve_start_mc: 97_000, g17d_forms: true, completion_inputs: false, + j813_forms: false, + region_c_source: RootProfile::J813G17G25G76, +}; + +/// A18 Pro (J700) on the common 26B123 graph. The performance rows are the eleven states the +/// existing J700 table A selects from the device tree; unused rows stay zero. +const J700_GPU_PERF_STATES: [M5PerfState; 14] = one_table([ + (0, 125, 765), (338, 605, 765), (492, 630, 765), (618, 650, 765), + (796, 695, 765), (928, 745, 765), (1056, 800, 800), (1170, 845, 845), + (1278, 885, 885), (1338, 905, 905), (1470, 975, 975), + (1470, 975, 975), (1470, 975, 975), (1470, 975, 975), +]); + +/// Relative performance of the J700 table-A rows, in percent. +const J700_GPU_RELATIVE_POWER: [u32; 14] = + [0, 15, 22, 29, 42, 56, 74, 86, 90, 92, 100, 0, 0, 0]; + +/// Relative performance of the J700 table-B rows, in percent. +const J700_GPU_RELATIVE_FREQUENCY: [u32; 16] = + [0, 0, 13, 24, 40, 52, 63, 73, 83, 88, 100, 0, 0, 0, 0, 0]; + +const J700_GPU_BASE: u64 = 0x4_8000_0000; + +/// J700's existing register windows expressed in the packed common-graph form. +const J700_REGISTER_WINDOWS: [M5RegisterWindowSpec; 18] = { + const G: u64 = J700_GPU_BASE; + [ + jw(0, &[0x3_0101_4000], 0x4000, 0, 2), + jw(3, &[0x2_2010_4000], 0x18000, 0, 2), + jw(9, &[0x3_003d_0000], 0x1000, 0, 2), + jw(10, &[0x3_003c_0000], 0x2000, 0, 0), + jw(12, &[0x4_0165_c000], 0x4000, 0, 2), + jw(14, &[0x3_0028_0000], 0x8000, 0, 0), + jw(17, &[G], 0x21400, 0, 2), + jw(22, &[G + 0x100_0000], 0x8000, 0, 2), + jw(26, &[G + 0xd0_4000], 0x8000, 0xd0_4000, 2), + jw(27, &[G + 0xd0_d000], 0x1000, 0xd0_d000, 2), + jw(28, &[G + 0xd5_8000], 0x8000, 0xd5_8000, 2), + jw(29, &[G + 0xd1_0000], 0x4000, 0xd1_0000, 2), + jw(31, &[G + 0xd4_0000], 0x4000, 0xd4_0000, 2), + jw(32, &[G + 0xd6_0000], 0x4000, 0xd6_0000, 2), + jw(35, &[G + 0xe0_0000], 0x4000, 0xe0_0000, 2), + jw(39, &[G + 0xe0_8000], 0x8000, 0, 2), + jw(40, &[G + 0xe1_c000], 0x4000, 0xe1_c000, 2), + jw(41, &[G + 0xe1_f800], 0x4000, 0, 0), + ] +}; + +/// Register-map slots reserved by the J700 graph but not backed by a window. +const J700_RESERVED_REGISTER_SLOTS: [usize; 17] = + [2, 5, 6, 7, 8, 30, 33, 34, 37, 38, 42, 43, 46, 47, 48, 49, 52]; + +const fn j700_register_slot_flags() -> [u32; COMMON26_HW_REGISTER_MAP_SLOTS] { + let mut flags = [0; COMMON26_HW_REGISTER_MAP_SLOTS]; + let mut index = 0; + while index < J700_REGISTER_WINDOWS.len() { + let window = J700_REGISTER_WINDOWS[index]; + flags[window.slot] = window.flag; + index += 1; + } + index = 0; + while index < J700_RESERVED_REGISTER_SLOTS.len() { + flags[J700_RESERVED_REGISTER_SLOTS[index]] = 2; + index += 1; + } + flags +} + +const J700_HW_REGISTER_SLOT_FLAGS: [u32; COMMON26_HW_REGISTER_MAP_SLOTS] = + j700_register_slot_flags(); + +/// The common graph requires an AON row even when the board has no separate AON tuning table. +const J700_AON_RECORDS: [[u32; 3]; 1] = [[0; 3]]; + +/// J700 on macOS 27.2 (26B123): one cluster with six cores on the common 27.2 graph. +pub(crate) const J700_26B123: Board = Board { + chip_id: 0x8140, + graph: &COMMON26B123_GRAPH, + hw_data_insert: false, + clusters: 1, + gpu_cores: 6, + core_revision: (0x1e, 4), + perf_state_count: 10, + perf_states: &J700_GPU_PERF_STATES, + perf_tables: 1, + aux_perf_states: None, + relative_frequency: J700_GPU_RELATIVE_FREQUENCY, + relative_power: Some(&J700_GPU_RELATIVE_POWER), + aon_records: &J700_AON_RECORDS, + register_windows: &J700_REGISTER_WINDOWS, + register_slot_flags: Some(&J700_HW_REGISTER_SLOT_FLAGS), + min_parameter_buffer: (super::target::min_parameter_buffer_pages(1) << 15) as u32, + render_pool: (0x10_0000, 1 << 31), + calibration: None, + controller_defaults: None, + idle_standby_us: None, + mcc_mask: Some(1), + topology_words: None, + hw_words: &[], + fan_curve_start_mc: 84_000, + g17d_forms: false, + completion_inputs: false, + j813_forms: true, + region_c_source: RootProfile::J700G17P, }; /// M5 (T8142, MacBook Air J813): one cluster of ten core slots, eight enabled. Values from the @@ -2548,6 +2666,8 @@ pub(crate) const J813: Board = Board { fan_curve_start_mc: 84_000, g17d_forms: false, completion_inputs: false, + j813_forms: true, + region_c_source: RootProfile::J813G17G25G76, }; /// The J813 on its macOS 27.2 (26B123) firmware: the same board on the common 26B123 graph. @@ -2926,10 +3046,10 @@ impl Board { self.completion_inputs } - /// Whether this is the J813, whose register programs macOS 27.0 writes in the common 26A428 - /// forms rather than the M5 Pro's (read out of its own kicks under aura). + /// Whether the board uses the single-cluster common-G17 register-program and queue forms + /// rather than the M5 Pro's multi-cluster forms. pub(crate) const fn j813_forms(&self) -> bool { - self.chip_id == 0x8142 + self.j813_forms } /// The board's `index`th register window. @@ -3657,3 +3777,45 @@ pub(crate) fn encode_m5_policy_controller_defaults_j775d(out: &mut [u8]) -> Resu } Ok(()) } + +use kernel::prelude::kunit_tests; + +#[kunit_tests(asahi_g17_fw272_layout)] +mod fw272_tests { + use super::*; + + #[test] + fn j700_26b123_uses_the_common_layout_delta() { + assert_eq!(J700_26B123.graph.profile, RootProfile::J873G18G26B123); + assert_eq!(J700_26B123.graph.profile.version_word(), 0x0c8b_6339_83a0_04c0); + assert_eq!( + COMMON26B123_LAYOUTS.policy_size, + COMMON26_LAYOUTS.policy_size + 0x60 + ); + assert_eq!( + COMMON26B123_LAYOUTS.status_config_size, + COMMON26_LAYOUTS.status_config_size + 8 + ); + assert_eq!( + COMMON26B123_SHARED_LAYOUT.block_68, + COMMON26_SHARED_LAYOUT.block_68 + 0x80 + ); + assert_eq!(COMMON26B123_SHARED_LAYOUT.total, COMMON26_SHARED_LAYOUT.total); + assert_eq!(COMMON26B123_PRIVATE_LAYOUT.total, COMMON26_PRIVATE_LAYOUT.total); + } + + #[test] + fn j700_26b123_region_c_keeps_board_values() { + let mut region = [0u8; REGION_C_SIZE]; + encode_common26_board_region_c(&J700_26B123, &mut region).unwrap(); + let word = |offset| { + u32::from_le_bytes(region[offset..offset + 4].try_into().unwrap()) + }; + // The common graph inserts its enable word at +0x38; the J700 maximum-power input therefore + // moves from +0x84 to +0x88. The 27.2-only controller word is at +0x2f28 in policy, + // not Region C, so this board value stays 9550 mW. + assert_eq!(word(0x38), 1); + assert_eq!(word(0x88), 9550); + assert_eq!(word(0x7c8), 2000); + } +} diff --git a/drivers/gpu/drm/asahi/g17/fw/variant.rs b/drivers/gpu/drm/asahi/g17/fw/variant.rs index 7c3ee790dc941..1dcd7d0225365 100644 --- a/drivers/gpu/drm/asahi/g17/fw/variant.rs +++ b/drivers/gpu/drm/asahi/g17/fw/variant.rs @@ -216,6 +216,19 @@ pub(crate) const V26A428_M5: Variant = Variant { ..V26A428 }; +/// The common G17 interface shipped for J700 in macOS 27.2 (26B123). +/// +/// Its queue and command protocol is the common two-role protocol. The exact InitData graph is +/// selected by the build's [`crate::g17::Config`], so the current J700 build remains on +/// [`V26A428`] and its existing graph. +pub(crate) const V26B123: Variant = Variant { + m5_commands: true, + traversal_exclusion: false, + render_ray_query: false, + registration_power_hold: false, + ..V26A428 +}; + pub(crate) const V25F84: Variant = Variant { qid_floor: 0, registration: QueueRegistration::Mailbox, @@ -227,6 +240,7 @@ pub(crate) const V25F84: Variant = Variant { const _: () = { assert!(super::queue::PointerBlock::valid_layout(&V26A428.pointers)); + assert!(super::queue::PointerBlock::valid_layout(&V26B123.pointers)); assert!(super::queue::PointerBlock::valid_layout(&V25G83.pointers)); assert!(super::queue::PointerBlock::valid_layout(&V25F84.pointers)); }; diff --git a/drivers/gpu/drm/asahi/g17/initdata/m5.rs b/drivers/gpu/drm/asahi/g17/initdata/m5.rs index 7b641965cdc70..5bd2f3a6b9510 100644 --- a/drivers/gpu/drm/asahi/g17/initdata/m5.rs +++ b/drivers/gpu/drm/asahi/g17/initdata/m5.rs @@ -202,7 +202,7 @@ impl InitData { m::encode_common26_aon_ptd(board, &mut self.object_mut(aon)?.bytes_mut()[..m::M5_AON_PTD_SIZE]) .map_err(|_| EINVAL)?; if common26 { - m::encode_common26_board_region_c( + m::encode_common26_board_region_c(board, &mut self.object_mut(self.region_c)?.bytes_mut()[..m::REGION_C_SIZE]) .map_err(|_| EINVAL)?; m::encode_common26_private_cluster(board.graph.profile, PRIVATE, FWCTL, diff --git a/drivers/gpu/drm/asahi/hw/t8140.rs b/drivers/gpu/drm/asahi/hw/t8140.rs index 0165140565567..d4651d50d47f2 100644 --- a/drivers/gpu/drm/asahi/hw/t8140.rs +++ b/drivers/gpu/drm/asahi/hw/t8140.rs @@ -10,8 +10,14 @@ use crate::g17::{ }; use crate::hw::{GpuGen, GpuVariant}; -/// Static configuration of the T8140 GPU. +/// Static configuration of the T8140 GPU. The exact loaded firmware selects the graph below. pub(crate) const CONFIG: Config = Config { + firmware: crate::g17::fw::variant::Firmware::Identified(&BUILDS), + ..BASE +}; + +/// The J700 hardware before a firmware build has been selected. +const BASE: Config = Config { chip_id: CHIP_ID, identity: Identity { family: 0xa, @@ -58,6 +64,8 @@ pub(crate) const CONFIG: Config = Config { adopt_root_entries: true, fabric_bridge: true, sleep_restart: true, + // Replaced by CONFIG. Keeping the old graph here makes every field of the 25G83 + // configuration explicit and gives the 26B123 override a non-recursive base. firmware: crate::g17::fw::variant::Firmware::Fixed(&crate::g17::fw::variant::V26A428), // The layouts the A18 Pro has always run with. core_layout: crate::g17::CoreLayout { @@ -69,6 +77,88 @@ pub(crate) const CONFIG: Config = Config { }, }; +/// J700 on the common macOS 27.2 graph. Only the exactly identified 26B123 image selects it; +/// the current 25G83 image continues to use [`BASE`] unchanged. +const CONFIG_26B123: Config = Config { + profile: crate::g17::FirmwareProfile::M5PublishedRoots, + pm_metrics: None, + windows: &[], + reserved_slots: &[], + perf: None, + opps: 0, + region_c: None, + m5: Some(&crate::g17::fw::m5::initdata::J700_26B123), + firmware: crate::g17::fw::variant::Firmware::Identified(&[BUILD_26B123]), + ..BASE +}; + +/// Exact J700 builds, newest first. iBoot loads the primary and secondary b100 TEXT segments +/// back to back. The digest excludes each role's load fields, boot arguments and entropy records, +/// the same normalization used by the M5 build table. +const BUILDS: [crate::g17::fw::variant::Build; 2] = [ + crate::g17::fw::variant::Build { + config: Some(&CONFIG_26B123), + ..BUILD_26B123 + }, + BUILD_25G83, +]; + +const BUILD_25G83: crate::g17::fw::variant::Build = crate::g17::fw::variant::Build { + os_version: [26, 6, 2], + name: "26.6.2 (25G83), G17P", + images: &[crate::fwid::FirmwareBuild { + name: "25G83 for T8140 G17P, primary then secondary", + text_size: 0x98000, + data_size: 0x260000, + entropy: &[[0x46251, 0x46334], [0x91bd9, 0x91cbc]], + boot_filled: &[ + (0x224, 4), + (0x23c, 8), + (0x45b11, 0x740), + (0x46251, 0x231), + (0x4c224, 4), + (0x4c23c, 8), + (0x91499, 0x740), + (0x91bd9, 0x231), + ], + text_sha256: [ + 0xc8, 0x8c, 0x3f, 0x28, 0x72, 0xd5, 0xfc, 0x12, 0x35, 0x5f, 0x42, 0x14, 0x86, 0xd0, + 0xdb, 0x9d, 0xe0, 0x88, 0x87, 0x65, 0xab, 0xe9, 0x62, 0x0d, 0x28, 0x87, 0x17, 0x9f, + 0x67, 0x98, 0x92, 0x06, + ], + }], + variant: &crate::g17::fw::variant::V26A428, + config: None, +}; + +const BUILD_26B123: crate::g17::fw::variant::Build = crate::g17::fw::variant::Build { + os_version: [27, 2, 0], + name: "27.2 (26B123), G17P", + images: &[crate::fwid::FirmwareBuild { + name: "26B123 for T8140 G17P, primary then secondary", + text_size: 0x9c000, + data_size: 0x188000, + entropy: &[[0x4629c, 0x4637f], [0x95bcc, 0x95caf]], + boot_filled: &[ + (0x224, 4), + (0x23c, 8), + (0x45b5c, 0x740), + (0x4629c, 0x231), + (0x4c224, 4), + (0x4c23c, 8), + (0x9548c, 0x740), + (0x95bcc, 0x231), + ], + text_sha256: [ + 0xfd, 0xec, 0xca, 0x8b, 0x92, 0x35, 0x8d, 0x89, 0x13, 0x6f, 0x69, 0xda, 0x5e, 0x90, + 0xe5, 0xbd, 0xe5, 0x0a, 0x64, 0x78, 0xf6, 0x47, 0x45, 0x6c, 0x79, 0xac, 0x47, 0x84, + 0x68, 0x5a, 0x36, 0xe1, + ], + }], + variant: &crate::g17::fw::variant::V26B123, + config: None, +}; + use crate::g17::fw::initdata::{PerfConfig, RegisterWindow, PERF_STATES}; /// Chip identifier written to the hardware data.