Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions drivers/gpu/drm/asahi/fwid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down
21 changes: 10 additions & 11 deletions drivers/gpu/drm/asahi/g16/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Performance> {
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",
Expand Down
39 changes: 22 additions & 17 deletions drivers/gpu/drm/asahi/g16/board/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
},
];

Expand Down Expand Up @@ -68,12 +72,13 @@ fn select_layout(
) -> core::result::Result<Performance, super::super::adt::perf::Error> {
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]
Expand Down
10 changes: 7 additions & 3 deletions drivers/gpu/drm/asahi/g16/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
25 changes: 20 additions & 5 deletions drivers/gpu/drm/asahi/g16/fw/initdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions drivers/gpu/drm/asahi/g16/glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/*
Expand Down
70 changes: 70 additions & 0 deletions drivers/gpu/drm/asahi/g16/hw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 14 additions & 4 deletions drivers/gpu/drm/asahi/g16/initdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ pub(crate) struct InitData {
#[allow(dead_code)]
pub(crate) parameter: Arc<FwObject>,
root: Arc<FwObject>,
/// 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<Arc<FwObject>>,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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());
Expand All @@ -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()),
Expand All @@ -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,
},
Expand Down
Loading
Loading