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
15 changes: 15 additions & 0 deletions drivers/gpu/drm/asahi/fwid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,21 @@ mod tests {
assert!(measured(builds, 0x13c000, &[[0x5c8df, 0x5c9c2]], [0; 32]).is_none());
}

#[cfg(CONFIG_DRM_ASAHI_G16)]
#[test]
fn j773g_accepts_its_loaded_image() {
let builds = crate::g16::hw::t8132::CONFIG.firmware;
let digest = [
0x91, 0x54, 0xc7, 0xf8, 0x4b, 0xce, 0x32, 0x15, 0x1e, 0x8a, 0x97, 0x41, 0x7d, 0x6a,
0x20, 0x7a, 0x9e, 0xaf, 0x03, 0x54, 0xb4, 0xb8, 0xd6, 0xf0, 0x2a, 0xf5, 0x29, 0x95,
0x40, 0xd3, 0xe8, 0x5a,
];
let found = measured(builds, 0x13c000, &[[0x5c8df, 0x5c9c2]], digest).unwrap();
assert_eq!(found.name, "Apple GFX 25G83 (normalized loaded image, J773g)");
assert_eq!(found.boot_filled, &[(0x224, 4), (0x5c917, 8)]);
assert!(measured(builds, 0x138000, &[[0x5c8df, 0x5c9c2]], digest).is_none());
}

#[test]
fn t6050_admits_only_its_pinned_image() {
for cfg in [
Expand Down
24 changes: 15 additions & 9 deletions drivers/gpu/drm/asahi/g16/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,39 @@

//! 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 (J713, J604) or eleven (J773g) firmware rows selected from 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.
/// Differently shaped tables, inconsistent voltage pairs and layouts with a row count other
/// than the one qualified for this board 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| {
let rows = super::boot::glue::perf_rows();
let (performance, layout) = data::select_named(&adt.performance, Some(rows)).map_err(|error| {
dev_err!(
dev,
"M4 original ADT performance layout rejected: {:?}\n",
"M4 original ADT performance layout rejected for {} firmware rows: {:?}\n",
rows,
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
43 changes: 30 additions & 13 deletions drivers/gpu/drm/asahi/g16/board/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,47 @@

//! 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.
pub(crate) const LAYOUTS: [Layout; 2] = [
/// frequency and both voltages, so the J713 shape cannot be mistaken for the others. J604 and
/// J773g have the same shape and differ only in their row count, which the board selects.
pub(crate) const LAYOUTS: [Layout; 3] = [
// J713: four common low states followed by six equal-voltage pairs.
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],
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.
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],
rows: 10,
main: [0, 1, 2, 3, 6, 8, 10, 12, 14, 15, 0],
auxiliary: [0, 1, 2, 3, 5, 7, 9, 11, 13, 15, 0],
},
// J773g (Mac mini, M4): the J604 shape, with every state kept in eleven rows.
Layout {
name: "J773g",
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 All @@ -41,18 +52,23 @@ use super::super::fw::initdata::{Performance, PERF_STATES};
pub(crate) fn select(
source: &super::super::adt::perf::Source,
) -> core::result::Result<Performance, super::super::adt::perf::Error> {
select_named(source).map(|(performance, _)| performance)
select_named(source, None).map(|(performance, _)| performance)
}

/// As [`select`], with the name of the layout that matched.
/// As [`select`], with the name of the layout that matched. With `rows`, only the layouts with
/// that row count, the one qualified for the board, are tried.
pub(crate) fn select_named(
source: &super::super::adt::perf::Source,
rows: Option<usize>,
) -> core::result::Result<(Performance, &'static str), super::super::adt::perf::Error> {
use super::super::adt::perf::Error;
if source.count != SOURCE_STATES {
return Err(Error::Shape);
}
for layout in LAYOUTS.iter() {
if rows.is_some_and(|rows| rows != layout.rows) {
continue;
}
match select_layout(source, layout) {
Err(Error::Shape) => continue,
Err(error) => return Err(error),
Expand All @@ -68,12 +84,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
17 changes: 14 additions & 3 deletions drivers/gpu/drm/asahi/g16/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub(crate) mod glue {
extern "C" {
fn asahi_g16_board() -> bool;
fn asahi_g16_display_prepare(dev: *mut core::ffi::c_void) -> core::ffi::c_int;
fn asahi_g16_perf_rows() -> core::ffi::c_uint;
fn asahi_g16_hold_power(dev: *mut core::ffi::c_void) -> core::ffi::c_int;
fn asahi_g16_ram_disjoint(start: u64, size: u64) -> bool;
fn asahi_g16_ioremap_wc(start: u64, size: usize) -> *mut core::ffi::c_void;
Expand All @@ -60,7 +61,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 All @@ -72,6 +73,12 @@ pub(crate) mod glue {
kernel::error::to_result(unsafe { asahi_g16_display_prepare(dev.as_raw().cast()) })
}

/// The firmware DVFS row count qualified for this board, or zero.
pub(crate) fn perf_rows() -> usize {
// SAFETY: Reads the machine compatible strings only.
unsafe { asahi_g16_perf_rows() as usize }
}

/// Holds the GFX power domain for the retained session.
pub(crate) fn hold_power(dev: &device::Device) -> Result {
// SAFETY: `dev` is a valid device; runtime-PM accounting on it has no other requirement.
Expand Down Expand Up @@ -408,7 +415,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 @@ -729,7 +736,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 @@ -778,6 +785,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
14 changes: 12 additions & 2 deletions drivers/gpu/drm/asahi/g16/glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include <linux/soc/apple/pmp-telemetry.h>
#include <linux/thermal.h>

#include "glue.h"

bool asahi_g16_board(void);
int asahi_g16_display_prepare(struct device *dev);
int asahi_g16_hold_power(struct device *dev);
Expand Down Expand Up @@ -200,10 +202,18 @@ 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_retained_board();
}

/* Preserve the existing ten-row table except for the qualified J773g layout. */
unsigned int asahi_g16_perf_rows(void)
{
if (!apple_pmp_t8132_retained_board())
return 0;
return of_machine_is_compatible("apple,j773g") ? 11 : 10;
}

/*
Expand Down
7 changes: 7 additions & 0 deletions drivers/gpu/drm/asahi/g16/glue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-only OR MIT */
#ifndef _ASAHI_G16_GLUE_H
#define _ASAHI_G16_GLUE_H

unsigned int asahi_g16_perf_rows(void);

#endif /* _ASAHI_G16_GLUE_H */
17 changes: 16 additions & 1 deletion drivers/gpu/drm/asahi/g16/hw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub(crate) struct HwId {

pub(crate) use crate::fwid::FirmwareBuild;

/// The J713/T8132 configuration. Hardware admission also checks the exact TEXT image.
/// The J713/J773g T8132 configuration. Hardware admission also checks the exact TEXT image.
pub(crate) mod t8132 {
use super::super::Config;
use super::{FirmwareBuild, HwId};
Expand Down Expand Up @@ -79,6 +79,21 @@ pub(crate) mod t8132 {
0xc8, 0x29, 0x86, 0x8b, 0xc9, 0xcf,
],
},
FirmwareBuild {
// The 25G83 image as loaded by iBoot on a J773g (Mac mini). iBoot rewrites
// the header word at 0x224 and the 8-byte DILS payload at 0x5c917 on every
// boot there; they are zeroed before hashing.
name: "Apple GFX 25G83 (normalized loaded image, J773g)",
text_size: 0x60000,
data_size: 0x13c000,
entropy: &[[0x5c8df, 0x5c9c2]],
boot_filled: &[(0x224, 4), (0x5c917, 8)],
text_sha256: [
0x91, 0x54, 0xc7, 0xf8, 0x4b, 0xce, 0x32, 0x15, 0x1e, 0x8a, 0x97, 0x41, 0x7d,
0x6a, 0x20, 0x7a, 0x9e, 0xaf, 0x03, 0x54, 0xb4, 0xb8, 0xd6, 0xf0, 0x2a, 0xf5,
0x29, 0x95, 0x40, 0xd3, 0xe8, 0x5a,
],
},
],
};
}
Expand Down
Loading
Loading