feat(agx): admit the M1 GPUs whose G13 kexts and firmware share the modeled interface

This commit is contained in:
Tyler Smith committed 2026-10-20 16:11:20 +00:00
1 parent ca20b2ae37
commit 59f72e95cd
8 files changed
+308 -112

No files matched your search

+57
View File
@@ -33,6 +33,14 @@
//! (the same DeviceTree notes they "must be filled in by the bootloader"), so
//! both tables state voltage 0, as `dvfs` does for the CPU clusters, rather
//! than an invented one. A SoC without public operating points refuses.
//!
//! T8103 and T600x take the same tables: the 26A434 `AGXG13X`
//! `AGXAccelerator::start` aligns instruction for instruction with G14G's
//! over the property reads above (only object offsets and string addresses
//! differ). One table serves every cluster: Inferred, as the Asahi tables
//! repeat each state's voltage per cluster, and the kext accepts 1..=16
//! tables; iBoot for a multi-cluster board (j314/j316) would confirm the
//! count it writes.
use crate::apple_device_tree::DeviceTree;
use alloc::vec::Vec;
use anyhow::{Result, bail};
@@ -52,9 +60,36 @@ const T8112_HZ: [u32; 9] = [
1_398_000_000,
];
/// T8103's GPU operating points in Hz (Asahi `t8103.dtsi` `gpu_opp`, the
/// same pinned commit).
const T8103_HZ: [u32; 7] = [
0,
396_000_000,
528_000_000,
720_000_000,
924_000_000,
1_128_000_000,
1_278_000_000,
];
/// The M1 Pro, Max and Ultra GPU operating points in Hz (Asahi
/// `t600x-common.dtsi` `gpu_opp`, the same pinned commit), shared by every
/// cluster.
const T600X_HZ: [u32; 7] = [
0,
388_800_000,
486_000_000,
648_000_000,
777_600_000,
972_000_000,
1_296_000_000,
];
/// The GPU's operating points, lowest first, on the SoC with `chip_id`.
fn operating_points(chip_id: u32) -> Option<&'static [u32]> {
match chip_id {
0x8103 => Some(&T8103_HZ),
0x6000..=0x6002 => Some(&T600X_HZ),
0x8112 => Some(&T8112_HZ),
_ => None,
}
@@ -164,6 +199,28 @@ mod tests {
assert_eq!(publish(&mut tree, 0x8112).unwrap(), None);
}
#[test]
fn the_m1_gpus_take_their_seven_operating_points() {
for (chip_id, top) in [
(0x8103, 1_278_000_000),
(0x6000, 1_296_000_000),
(0x6001, 1_296_000_000),
(0x6002, 1_296_000_000),
] {
let mut tree = shipped();
let tables = publish(&mut tree, chip_id).unwrap().unwrap();
assert_eq!(
tables,
Tables {
states: 7,
tables: 1
}
);
let table = tree.property(SGX, "perf-states").unwrap().value.clone();
assert_eq!((u32_at(&table, 12), u32_at(&table, 13)), (top, 0));
}
}
#[test]
fn without_operating_points_or_a_visible_sgx_node() {
assert!(publish(&mut shipped(), 0x8122).is_err());
+4 -3
View File
@@ -1000,7 +1000,8 @@ impl AppleDevices {
placement: &super::soc::GfxController,
observe: bool,
) -> Result<(), String> {
let coprocessor = GfxCoprocessor::with_observe(observe).map_err(String::from)?;
let coprocessor =
GfxCoprocessor::with_observe(placement.gpu.family, observe).map_err(String::from)?;
let wrapper = Asc::booted(
Box::new(coprocessor),
AscLines::from_interrupts(placement.interrupts.map(|n| AicInput::new(0, n))),
@@ -2710,7 +2711,7 @@ mod tests {
const SGX: u64 = 0x2_0400_0000;
const RAM: u64 = 0x8_0000_0000;
let placement = GfxController {
gpu: generation::by_compatible("gpu,t8112").unwrap(),
gpu: generation::by_chip(0x8112).unwrap(),
wrapper: (WRAPPER, 0x6c000),
interrupts: [0x2c6, 0x2c5, 0x2c8, 0x2c7],
sgx: vec![(SGX, 0x400_0000, 0)],
@@ -2755,7 +2756,7 @@ mod tests {
table::encode_pte(RAM + 0x1_0000, &flags),
);
// The kext's root: magic, the +0x28 words and its object pointers.
ram.put_u64(RAM + 0x1_0000, firmware::INITDATA_MAGIC);
ram.put_u64(RAM + 0x1_0000, generation::MAGIC_G13_G14G);
ram.put_u64(RAM + 0x1_0028, 1 << 32);
for field in [0x08, 0x18, 0x20, 0xa8, 0xb0, 0xb8, 0xc0] {
ram.put_u64(RAM + 0x1_0000 + field, va + 0x1000);
+22 -13
View File
@@ -2243,10 +2243,10 @@ fn pmp_controller(
pub const GFX_MAPPER: &str = "iommu-mapper,gfx";
/// Whether `compatible` names an `sgx` GPU whose whole interface is modeled
/// (`agx::generation`, every SoC 26A434 supports; only admitted ones stay
/// visible).
/// on every SoC that carries it (`agx::generation`, every SoC 26A434
/// supports; only admitted ones stay visible).
pub fn admitted_gpu(compatible: &str) -> bool {
agx::generation::by_compatible(compatible).is_some_and(|gpu| gpu.admitted().is_ok())
agx::generation::compatible_admitted(compatible)
}
/// The AGX GPU's DT placement: the `gfx-asc` wrapper (`reg[0]`) and its four
@@ -2295,21 +2295,25 @@ fn sgx_banks(block: (u64, u64), info: (u64, u64)) -> Result<Vec<(u64, u64, u64)>
fn gfx_controller(
io: &Node<'_>,
translate: &dyn Fn(u64) -> Option<u64>,
chip_id: u32,
) -> Result<Option<GfxController>, String> {
let asc = io
.child("gfx-asc")
.filter(|n| n.compatible(ASC) && n.property("role") == Some(b"GFX\0".as_slice()));
let sgx = io.child("sgx").and_then(|n| {
// Several SoCs share one `sgx` compatible; the chip names the GPU.
let sgx = io.child("sgx").filter(|n| {
agx::generation::GPUS
.iter()
.find(|gpu| n.compatible(gpu.compatible))
.map(|gpu| (n, gpu))
.any(|gpu| n.compatible(gpu.compatible))
});
let (asc, (sgx, gpu)) = match (asc, sgx) {
let (asc, sgx) = match (asc, sgx) {
(None, None) => return Ok(None),
(Some(asc), Some(sgx)) => (asc, sgx),
_ => return Err("the GFX coprocessor and the sgx GPU must be visible together".into()),
};
let gpu = agx::generation::by_chip(chip_id)
.filter(|gpu| sgx.compatible(gpu.compatible))
.ok_or_else(|| format!("sgx is not the GPU of ApChipID {chip_id:#x}"))?;
gpu.admitted()
.map_err(|reason| format!("{} is not modeled: {reason}", gpu.compatible))?;
let nub = asc
@@ -4479,7 +4483,7 @@ pub fn board(tree: &[u8]) -> Result<Board, String> {
let ans = ans_controller(&io, &translate, iboot_security)?;
let smc = smc_controller(&root, &io, &translate)?;
let pmp = pmp_controller(&io, &translate)?;
let gfx = gfx_controller(&io, &translate)?;
let gfx = gfx_controller(&io, &translate, chip_id)?;
let sep = sep_device(&root, &io, &translate, &darts)?;
let usbs = usb_controllers(&io, &translate, &darts)?;
let power_states = power_states(&io, &translate, chip_id)?;
@@ -5092,10 +5096,12 @@ mod tests {
model_children(ASC, gfx_role).len(),
usize::from(GPU_ADMITTED)
);
assert_eq!(models("gpu,t8112", |_| None), GPU_ADMITTED);
for gpu in ["gpu,t8112", "gpu,t8103", "gpu,t6000"] {
assert_eq!(models(gpu, |_| None), GPU_ADMITTED);
}
// A GPU whose family the firmware model does not implement stays
// hidden.
assert!(!models("gpu,t8103", |_| None));
assert!(!models("gpu,t6020", |_| None));
assert!(!models("gpu,t6041", |_| None));
assert_eq!(models(GFX_MAPPER, |_| None), GPU_ADMITTED);
assert!(!models(ASC, |key| (key == "role").then_some(b"GFX2\0".as_slice())));
@@ -5160,16 +5166,17 @@ mod tests {
encode(&[("name", &z("device-tree"))], &[io])
};
let translate = |offset| Some(0x2_0000_0000 + offset);
let placed = |asc: bool, sgx: bool| {
let placed_on = |asc: bool, sgx: bool, chip_id: u32| {
let bytes = tree(asc, sgx);
let root = Node::root(&bytes).unwrap();
let io = root.child("arm-io").unwrap();
gfx_controller(&io, &translate)
gfx_controller(&io, &translate, chip_id)
};
let placed = |asc: bool, sgx: bool| placed_on(asc, sgx, 0x8112);
assert_eq!(
placed(true, true).unwrap(),
Some(GfxController {
gpu: agx::generation::by_compatible("gpu,t8112").unwrap(),
gpu: agx::generation::by_chip(0x8112).unwrap(),
wrapper: (0x2_0640_0000, 0x6c000),
interrupts: [0x2c6, 0x2c5, 0x2c8, 0x2c7],
sgx: vec![(0x2_0400_0000, 0x400_0000, 0)],
@@ -5180,6 +5187,8 @@ mod tests {
assert_eq!(placed(false, false).unwrap(), None);
assert!(placed(true, false).is_err());
assert!(placed(false, true).is_err());
// The `sgx` must be the board chip's own GPU.
assert!(placed_on(true, true, 0x8103).is_err());
}
/// The census `sgx` layouts: T8112's `reg[1]` inside `reg[0]`, the
@@ -106,7 +106,7 @@ pub fn post(memory: &mut dyn Shared, root: &Root, event: Event) -> Result<(), &'
#[cfg(test)]
pub(crate) mod tests {
use super::*;
use crate::platform::apple::agx::initdata::tests::{BASE, RINGS, ROOT, kext_root};
use crate::platform::apple::agx::initdata::tests::{BASE, MAGIC, RINGS, ROOT, kext_root};
use crate::platform::apple::agx::ring::tests::Flat;
pub(crate) const EVENT_STATE: u64 = BASE + 0x14000;
@@ -154,7 +154,7 @@ pub(crate) mod tests {
let mut memory = Flat::new(BASE, 0x20000);
kext_root(&mut memory);
event_ring(&mut memory);
let root = Root::read(&mut memory, ROOT).unwrap();
let root = Root::read(&mut memory, ROOT, MAGIC).unwrap();
memory.put_u32(EVENT_STATE + READ, 0);
memory.put_u32(EVENT_STATE + WRITE, 0xfe);
post(&mut memory, &root, Event::Flag(1)).unwrap();
@@ -48,6 +48,7 @@ use super::super::asc::{Firmware, Message as Mail};
use super::super::rtkit::{Endpoint, RtKit};
use super::channel;
use super::event;
use super::generation::Family;
use super::initdata::{self, Root};
use super::observe::{self, Journal};
use super::ring::{self, Kind, Shared};
@@ -87,8 +88,6 @@ const DOORBELL_FWCTL: u64 = 4;
/// The firmware-control doorbell's low byte that names the device-control
/// ring (index 4, kind 1).
const FWCTL_DEVICE_CONTROL: u64 = 0x11;
/// The initdata root's first word.
pub const INITDATA_MAGIC: u64 = initdata::MAGIC;
/// The device-control power-transition notice (`AGXAccelerator::
/// powerStateDidChangeTo`/`WillChangeTo` 0x1af8508/0x1af861c).
const DEVICE_CONTROL_POWER: u32 = 0x28;
@@ -204,8 +203,10 @@ enum Job {
}
/// The GFX firmware protocol state shared by its two endpoints.
#[derive(Debug, Default)]
#[derive(Debug)]
pub struct State {
/// The AGX family whose kext and firmware fix the interface.
family: &'static Family,
/// The firmware VA of the initdata root, once the kext sends it, as the
/// 44-bit field of the message.
pub initdata_va: Option<u64>,
@@ -232,11 +233,22 @@ pub struct State {
}
impl State {
/// A fresh protocol state, observing work commands when `observe`.
fn new(observe: bool) -> Self {
/// A fresh protocol state for `family`'s interface, observing work
/// commands when `observe`.
fn new(family: &'static Family, observe: bool) -> Self {
State {
family,
initdata_va: None,
initdata_checked: false,
root: None,
work: Vec::new(),
fwctl: 0,
power: Vec::new(),
device_control: BTreeMap::new(),
commands: 0,
events: 0,
jobs: VecDeque::new(),
observe: observe.then(Journal::default),
..Self::default()
}
}
@@ -302,7 +314,11 @@ impl State {
/// Read the root, then run the queued doorbells in order.
fn dma(&mut self, memory: &mut dyn Shared, outbox: &mut Vec<Mail>) -> Result<(), &'static str> {
if let Some(va) = self.initdata_va.filter(|_| !self.initdata_checked) {
let root = Root::read(memory, uat::canonical_firmware_va(va))?;
let magic = self
.family
.initdata_magic
.ok_or("the GPU family's initdata root magic is not recovered")?;
let root = Root::read(memory, uat::canonical_firmware_va(va), magic)?;
self.root = Some(root);
self.initdata_checked = true;
}
@@ -431,6 +447,12 @@ impl State {
)),
}
}
if command.kind == channel::Kind::DashboardSignal && !self.family.dashboard_signals
{
return Err(
"GFX dashboard signal command: this GPU family's firmware has no dashboard-signal handler",
);
}
for event in signal::execute(memory, &command)? {
event::post(memory, root, event)?;
outbox.push(Mail {
@@ -690,13 +712,10 @@ fn device_control_entry(entry: &[u8]) -> Result<Command, &'static str> {
pub struct Protocol(Rc<RefCell<State>>);
impl Protocol {
pub fn new() -> Self {
Protocol::with_observe(false)
}
/// A protocol whose firmware records work commands (`--agx-observe`).
pub fn with_observe(observe: bool) -> Self {
Protocol(Rc::new(RefCell::new(State::new(observe))))
/// The protocol of `family`'s firmware, recording work commands when
/// `observe` (`--agx-observe`).
pub fn with_observe(family: &'static Family, observe: bool) -> Self {
Protocol(Rc::new(RefCell::new(State::new(family, observe))))
}
pub fn with<R>(&self, f: impl FnOnce(&State) -> R) -> R {
@@ -709,12 +728,6 @@ impl Protocol {
}
}
impl Default for Protocol {
fn default() -> Self {
Protocol::new()
}
}
/// The GFX coprocessor: RTKit with the GFX endpoints and the firmware's DMA.
pub struct Coprocessor {
rtkit: RtKit,
@@ -722,16 +735,11 @@ pub struct Coprocessor {
}
impl Coprocessor {
/// A GFX coprocessor whose RTKit manages its power ordinarily
/// (`power-managed`).
pub fn new() -> Result<Self, &'static str> {
Self::with_observe(false)
}
/// A GFX coprocessor that records each work command (`--agx-observe`)
/// `family`'s GFX coprocessor, whose RTKit manages its power ordinarily
/// (`power-managed`), recording each work command (`--agx-observe`)
/// when `observe`, still refusing it by name.
pub fn with_observe(observe: bool) -> Result<Self, &'static str> {
let (endpoints, protocol) = endpoints(observe);
pub fn with_observe(family: &'static Family, observe: bool) -> Result<Self, &'static str> {
let (endpoints, protocol) = endpoints(family, observe);
let rtkit = RtKit::new(endpoints, super::super::rtkit::Management::Ordinary)?;
Ok(Self { rtkit, protocol })
}
@@ -786,8 +794,8 @@ impl Endpoint for Doorbell {
/// The GFX coprocessor's application endpoints and a handle to their shared
/// state. Pass the endpoints to [`super::super::rtkit::RtKit::new`].
pub fn endpoints(observe: bool) -> (Vec<NumberedEndpoint>, Protocol) {
let protocol = Protocol::with_observe(observe);
pub fn endpoints(family: &'static Family, observe: bool) -> (Vec<NumberedEndpoint>, Protocol) {
let protocol = Protocol::with_observe(family, observe);
let endpoints: Vec<NumberedEndpoint> = alloc::vec![
(
MESSAGE_ENDPOINT,
@@ -801,6 +809,7 @@ pub fn endpoints(observe: bool) -> (Vec<NumberedEndpoint>, Protocol) {
#[cfg(test)]
mod tests {
use super::*;
use crate::platform::apple::agx::generation::{G13G, G14G, MAGIC_G13_G14G};
use crate::platform::apple::agx::initdata::tests::{BASE, RINGS, ROOT, kext_root};
use crate::platform::apple::agx::ring::tests::Flat;
use crate::platform::apple::agx::ring::{READ, WRITE};
@@ -819,6 +828,15 @@ mod tests {
/// A checked root whose device-control ring holds `entries`.
fn with_device_control(entries: &[[u8; 0x40]]) -> (State, Flat) {
with_device_control_on(&G14G, entries).unwrap()
}
/// `family`'s firmware, having read the root, with `entries` on its
/// device-control ring.
fn with_device_control_on(
family: &'static Family,
entries: &[[u8; 0x40]],
) -> Result<(State, Flat), &'static str> {
let mut memory = Flat::new(BASE, 0x20000);
kext_root(&mut memory);
memory.put_descriptor(RINGS + 0x1a0, CONTROL_STATE, CONTROL_ENTRIES);
@@ -826,12 +844,12 @@ mod tests {
memory.put(CONTROL_ENTRIES + n as u64 * 0x40, entry);
}
memory.put_u32(CONTROL_STATE + WRITE, entries.len() as u32);
let mut state = State::default();
let mut state = State::new(family, false);
state
.init((MSG_INIT << TYPE_SHIFT) | (ROOT & INIT_VA_BITS))
.unwrap();
state.dma(&mut memory, &mut Vec::new()).unwrap();
(state, memory)
state.dma(&mut memory, &mut Vec::new())?;
Ok((state, memory))
}
fn power(word: u32) -> [u8; 0x40] {
@@ -843,16 +861,16 @@ mod tests {
#[test]
fn the_message_endpoint_captures_the_initdata_pointer_once() {
let mut state = State::default();
let mut state = State::new(&G14G, false);
let va = 0x4_1234_5000;
assert!(state.init((MSG_INIT << TYPE_SHIFT) | va).is_ok());
assert_eq!(state.initdata_va, Some(va));
// A second initdata, or any other message type, is refused.
assert!(state.init((MSG_INIT << TYPE_SHIFT) | va).is_err());
let mut fresh = State::default();
let mut fresh = State::new(&G14G, false);
assert!(fresh.init(0x42 << TYPE_SHIFT).is_err());
// A VA above 44 bits is truncated to the field the kext sends.
let mut wide = State::default();
let mut wide = State::new(&G14G, false);
wide.init((MSG_INIT << TYPE_SHIFT) | INIT_VA_BITS | (1 << 44))
.unwrap();
assert_eq!(wide.initdata_va, Some(INIT_VA_BITS));
@@ -860,7 +878,7 @@ mod tests {
#[test]
fn doorbells_take_the_kexts_forms_and_queue_firmware_work() {
let (endpoints, protocol) = endpoints(false);
let (endpoints, protocol) = endpoints(&G14G, false);
let mut by_number = endpoints
.into_iter()
.collect::<alloc::collections::BTreeMap<_, _>>();
@@ -881,7 +899,7 @@ mod tests {
#[test]
fn malformed_or_unmodeled_doorbells_refuse_explicitly() {
let mut state = State::default();
let mut state = State::new(&G14G, false);
// Missing the 0x80 flag.
assert!(state.doorbell(DOORBELL_WORK << TYPE_SHIFT).is_err());
// An unmodeled type.
@@ -1267,6 +1285,34 @@ mod tests {
idle.0.dma(&mut idle.1, &mut Vec::new()).unwrap();
}
#[test]
fn each_family_reads_its_own_root_and_g13_refuses_dashboard_signals() {
use crate::platform::apple::agx::generation::{G14X, G16X};
// The kext root carries the G13G/G13X/G14G magic.
assert_eq!(
with_device_control_on(&G14X, &[]).err(),
Some("GFX initdata root lacks its magic")
);
assert_eq!(
with_device_control_on(&G16X, &[]).err(),
Some("the GPU family's initdata root magic is not recovered")
);
let (mut state, mut memory) = with_device_control_on(&G13G, &[]).unwrap();
assert!(state.root.is_some());
let (channel_state, command) = (BASE + 0xd000, BASE + 0x10000);
let (ring_state, _) = one_3d_entry(&mut memory, channel_state, command);
memory.put_u32(command, 0xc);
state.doorbell(work(1, 0)).unwrap();
assert_eq!(
state.dma(&mut memory, &mut Vec::new()),
Err(
"GFX dashboard signal command: this GPU family's firmware has no dashboard-signal handler"
)
);
assert_eq!(memory.read_u32(ring_state + READ), Ok(0));
assert_eq!(memory.read_u32(channel_state + 0x1000), Ok(0));
}
#[test]
fn a_shared_event_signal_completes_and_posts_its_events() {
use crate::platform::apple::agx::event::Event;
@@ -1324,7 +1370,7 @@ mod tests {
let mut memory = Flat::new(BASE, 0x20000);
kext_root(&mut memory);
memory.put_descriptor(RINGS + 0x1a0, CONTROL_STATE, CONTROL_ENTRIES);
let mut state = State::new(true);
let mut state = State::new(&G14G, true);
state
.init((MSG_INIT << TYPE_SHIFT) | (ROOT & INIT_VA_BITS))
.unwrap();
@@ -1360,14 +1406,14 @@ mod tests {
// Draining twice yields nothing the second time.
assert!(state.observations().is_empty());
// Off by default: no records without observe.
let mut quiet = State::default();
let mut quiet = State::new(&G14G, false);
assert!(quiet.observations().is_empty());
}
#[test]
fn the_root_must_be_the_kexts_before_any_doorbell_runs() {
let mut memory = Flat::new(BASE, 0x20000);
let mut state = State::default();
let mut state = State::new(&G14G, false);
state
.init((MSG_INIT << TYPE_SHIFT) | (ROOT & INIT_VA_BITS))
.unwrap();
@@ -1376,7 +1422,7 @@ mod tests {
Err("GFX initdata root lacks its magic")
);
assert!(state.dma_pending());
let mut early = State::default();
let mut early = State::new(&G14G, false);
early
.doorbell(doorbell_payload(DOORBELL_FWCTL, 0x11))
.unwrap();
@@ -1420,7 +1466,7 @@ mod tests {
let mut table = Uat::default();
table.configure(base).unwrap();
let mut latch = InterruptLatch::new();
let mut state = State::default();
let mut state = State::new(&G14G, false);
state
.init((MSG_INIT << TYPE_SHIFT) | (va & INIT_VA_BITS))
.unwrap();
@@ -1450,7 +1496,7 @@ mod tests {
/// Write a kext-shaped root at physical `at` whose objects follow `va`.
pub(crate) fn put_root(ram: &mut crate::platform::dma::tests::Ram, at: u64, va: u64) {
ram.put_u64(at, INITDATA_MAGIC);
ram.put_u64(at, MAGIC_G13_G14G);
ram.put_u64(at + 0x28, 1 << 32);
for (n, field) in [0x08, 0x18, 0x20, 0xa8, 0xb0, 0xb8, 0xc0]
.into_iter()
@@ -17,9 +17,13 @@
//!
//! A family is admitted ([`Gpu::admitted`]) only when every layout the GFX
//! firmware model and the `sgx` model use has been checked against that
//! family's own kext and firmware. Today that is G14G alone; every other
//! family is named here with the facts recovered so far and stays hidden
//! by the loader, its refusal naming what is missing.
//! family's own kext and firmware. Today that is G14G and the two G13
//! families, whose kexts write the same initdata, rings and channels
//! (aligned function by function) and whose firmware runs the same device-
//! control and signal handlers except the dashboard signal it lacks
//! ([`Family::dashboard_signals`]). Every other family is named here with
//! the facts recovered so far and stays hidden by the loader, its refusal
//! naming what is missing.
use super::sgx::Identity;
@@ -121,6 +125,11 @@ pub struct Family {
/// writes (`AGXArmFirmware::initFirmwareData`); `None` when the kext
/// builds it otherwise and the census has not recovered it.
pub initdata_magic: Option<u64>,
/// Whether the family's GFX firmware runs dashboard-signal records
/// (stream record 0xf, the kext's `submitDashboardSignalCommand`). The
/// G13 kexts have no such sender and the G13G/G13X firmware no handler
/// (no trace 0x126, no record jump table entry); G14G has both.
pub dashboard_signals: bool,
pub interface: Interface,
}
@@ -149,7 +158,8 @@ pub const G13G: Family = Family {
core_masks: &G13_G14G_CORE_MASKS,
mmu: g13_mmu(26),
initdata_magic: Some(MAGIC_G13_G14G),
interface: Interface::Unrecovered(NOT_CHECKED),
dashboard_signals: false,
interface: Interface::Modeled,
};
pub const G13X: Family = Family {
name: "G13X",
@@ -159,7 +169,8 @@ pub const G13X: Family = Family {
core_masks: &G13_G14G_CORE_MASKS,
mmu: g13_mmu(28),
initdata_magic: Some(MAGIC_G13_G14G),
interface: Interface::Unrecovered(NOT_CHECKED),
dashboard_signals: false,
interface: Interface::Modeled,
};
pub const G14G: Family = Family {
name: "G14G",
@@ -169,6 +180,7 @@ pub const G14G: Family = Family {
core_masks: &G13_G14G_CORE_MASKS,
mmu: g14_mmu(26),
initdata_magic: Some(MAGIC_G13_G14G),
dashboard_signals: true,
interface: Interface::Modeled,
};
pub const G14X: Family = Family {
@@ -179,6 +191,7 @@ pub const G14X: Family = Family {
core_masks: &G14X_CORE_MASKS,
mmu: g14_mmu(28),
initdata_magic: Some(0x0c8a_636f_0494_04b8),
dashboard_signals: true,
interface: Interface::Unrecovered(NOT_CHECKED),
};
pub const G15G: Family = Family {
@@ -189,6 +202,7 @@ pub const G15G: Family = Family {
core_masks: &G14X_CORE_MASKS,
mmu: g14_mmu(28),
initdata_magic: Some(0x0c8a_636f_0394_04b8),
dashboard_signals: true,
interface: Interface::Unrecovered(NOT_CHECKED),
};
pub const G15S: Family = Family {
@@ -199,6 +213,7 @@ pub const G15S: Family = Family {
core_masks: &G14X_CORE_MASKS,
mmu: g14_mmu(28),
initdata_magic: Some(0x0c8a_636f_0394_04b8),
dashboard_signals: true,
interface: Interface::Unrecovered(NOT_CHECKED),
};
pub const G15C: Family = Family {
@@ -209,6 +224,7 @@ pub const G15C: Family = Family {
core_masks: &G14X_CORE_MASKS,
mmu: g14_mmu(28),
initdata_magic: Some(0x0c8a_636f_0496_04b8),
dashboard_signals: true,
interface: Interface::Unrecovered(NOT_CHECKED),
};
pub const G16G: Family = Family {
@@ -219,6 +235,7 @@ pub const G16G: Family = Family {
core_masks: &G14X_CORE_MASKS,
mmu: g14_mmu(28),
initdata_magic: Some(0x0c8a_636f_0392_04b8),
dashboard_signals: true,
interface: Interface::Unrecovered(NOT_CHECKED),
};
pub const G16X: Family = Family {
@@ -229,6 +246,7 @@ pub const G16X: Family = Family {
core_masks: &G14X_CORE_MASKS,
mmu: g14_mmu(28),
initdata_magic: None,
dashboard_signals: true,
interface: Interface::Unrecovered(NOT_CHECKED),
};
pub const G17G: Family = Family {
@@ -239,6 +257,7 @@ pub const G17G: Family = Family {
core_masks: &G14X_CORE_MASKS,
mmu: g14_mmu(28),
initdata_magic: None,
dashboard_signals: true,
interface: Interface::Unrecovered(NOT_CHECKED),
};
pub const G17X: Family = Family {
@@ -249,6 +268,7 @@ pub const G17X: Family = Family {
core_masks: &G14X_CORE_MASKS,
mmu: g14_mmu(28),
initdata_magic: None,
dashboard_signals: true,
interface: Interface::Unrecovered(NOT_CHECKED),
};
pub const G17P: Family = Family {
@@ -259,6 +279,7 @@ pub const G17P: Family = Family {
core_masks: &G14X_CORE_MASKS,
mmu: g14_mmu(28),
initdata_magic: None,
dashboard_signals: true,
interface: Interface::Unrecovered(NOT_CHECKED),
};
pub const G18G: Family = Family {
@@ -269,6 +290,7 @@ pub const G18G: Family = Family {
core_masks: &G14X_CORE_MASKS,
mmu: g14_mmu(28),
initdata_magic: None,
dashboard_signals: true,
interface: Interface::Unrecovered(NOT_CHECKED),
};
@@ -286,6 +308,33 @@ pub const T8112: Identity = Identity {
core_mask: [0x3ff, 0, 0],
};
/// The M1 GPUs (G13, generation 4). Counts are per cluster, as
/// `AGXAcceleratorG13::readChipInfo` reads them (it multiplies each by the
/// cluster count in 0xd0401c bits 19:12), and Public: Asahi `hw/t8103.rs`
/// and `hw/t600x.rs` (8 cores, 8 fragment units and 4 GPs per cluster;
/// 1, 2, 4 and 8 clusters) and `regs.rs` (variant G = 2, S = 3, C and D =
/// 4). The kext reads one core-mask word for variant G and both for S, C
/// and D, and on those accepts 2, 4 or 8 clusters (16, 32 or 64 cores).
/// Revision: Inferred. No public source states it; the kext accepts A0, B0,
/// B1 and C0 (bits 15:12 and 11:8), and each SoC's newest GFX firmware image
/// is the one a shipping part runs (`armfw_g13g` b100, `armfw_g13x` c000).
const fn g13(variant: u8, revision: u8, clusters: u8, core_mask: [u32; 3]) -> Identity {
Identity {
generation: 4,
variant,
revision,
clusters,
cores: 8,
frags: 8,
gps: 4,
core_mask,
}
}
pub const T8103: Identity = g13(2, 0x11, 1, [0xff, 0, 0]);
pub const T6000: Identity = g13(3, 0x20, 2, [0xffff, 0, 0]);
pub const T6001: Identity = g13(4, 0x20, 4, [u32::MAX, 0, 0]);
pub const T6002: Identity = g13(4, 0x20, 8, [u32::MAX, u32::MAX, 0]);
const fn gpu(
compatible: &'static str,
chip_id: u16,
@@ -301,19 +350,28 @@ const fn gpu(
}
}
const fn known(
compatible: &'static str,
chip_id: u16,
family: &'static Family,
firmware: &'static str,
identity: Identity,
) -> Gpu {
Gpu {
identity: Some(identity),
..gpu(compatible, chip_id, family, firmware)
}
}
/// Every `sgx` of the 26A434 board DeviceTrees, by ApChipID.
pub const GPUS: [Gpu; 20] = [
gpu("gpu,t8103", 0x8103, &G13G, "armfw_g13g"),
gpu("gpu,t6000", 0x6000, &G13X, "armfw_g13x"),
gpu("gpu,t6001", 0x6001, &G13X, "armfw_g13x"),
gpu("gpu,t6002", 0x6002, &G13X, "armfw_g13x"),
Gpu {
compatible: "gpu,t8112",
chip_id: 0x8112,
family: &G14G,
firmware: "armfw_g14g",
identity: Some(T8112),
},
known("gpu,t8103", 0x8103, &G13G, "armfw_g13g", T8103),
// M1 Pro, Max and Ultra boards all name `gpu,t6000`; the chip is the
// board's `/chosen` `chip-id`.
known("gpu,t6000", 0x6000, &G13X, "armfw_g13x", T6000),
known("gpu,t6000", 0x6001, &G13X, "armfw_g13x", T6001),
known("gpu,t6000", 0x6002, &G13X, "armfw_g13x", T6002),
known("gpu,t8112", 0x8112, &G14G, "armfw_g14g", T8112),
gpu("gpu,t6020", 0x6020, &G14X, "armfw_g14s"),
gpu("gpu,t6021", 0x6021, &G14X, "armfw_g14c"),
gpu("gpu,t6022", 0x6022, &G14X, "armfw_g14d"),
@@ -331,9 +389,17 @@ pub const GPUS: [Gpu; 20] = [
gpu("gpu,t8152", 0x8152, &G18G, "armfw_g18g"),
];
/// The GPU whose `sgx` carries `compatible`.
pub fn by_compatible(compatible: &str) -> Option<&'static Gpu> {
GPUS.iter().find(|gpu| gpu.compatible == compatible)
/// The GPU of the SoC with ApChipID `chip_id`.
pub fn by_chip(chip_id: u32) -> Option<&'static Gpu> {
GPUS.iter().find(|gpu| u32::from(gpu.chip_id) == chip_id)
}
/// Whether every SoC whose `sgx` carries `compatible` is admitted, so the
/// node can stay visible on any board that names it (several SoCs share
/// one; the chip is then the board's `chip-id`).
pub fn compatible_admitted(compatible: &str) -> bool {
let mut gpus = GPUS.iter().filter(|gpu| gpu.compatible == compatible);
gpus.clone().next().is_some() && gpus.all(|gpu| gpu.admitted().is_ok())
}
impl Gpu {
@@ -358,35 +424,51 @@ mod tests {
use super::*;
#[test]
fn every_census_gpu_is_named_once_and_only_t8112_is_admitted() {
fn every_census_gpu_is_named_once_and_m1_and_m2_are_admitted() {
for (index, gpu) in GPUS.iter().enumerate() {
assert!(gpu.compatible.starts_with("gpu,t"));
assert_eq!(
gpu.compatible[5..],
alloc::format!("{:x}", gpu.chip_id),
"{} names its own chip",
gpu.compatible
);
assert!(
GPUS[..index]
.iter()
.all(|other| other.chip_id != gpu.chip_id)
);
assert_eq!(by_chip(gpu.chip_id.into()), Some(gpu));
assert!(gpu.firmware.starts_with("armfw_g"));
assert!(gpu.family.kext.ends_with(gpu.family.name));
}
let admitted: alloc::vec::Vec<_> = GPUS
.iter()
.filter(|gpu| gpu.admitted().is_ok())
.map(|gpu| gpu.compatible)
.map(|gpu| gpu.chip_id)
.collect();
assert_eq!(admitted, ["gpu,t8112"]);
assert_eq!(by_compatible("gpu,t8112").unwrap().admitted(), Ok(T8112));
assert_eq!(
by_compatible("gpu,t8103").unwrap().admitted(),
Err(NOT_CHECKED)
);
assert!(by_compatible("gpu,t9999").is_none());
assert_eq!(admitted, [0x8103, 0x6000, 0x6001, 0x6002, 0x8112]);
assert_eq!(by_chip(0x8112).unwrap().admitted(), Ok(T8112));
assert_eq!(by_chip(0x6020).unwrap().admitted(), Err(NOT_CHECKED));
assert!(by_chip(0x9999).is_none());
// M1 Pro, Max and Ultra share one compatible, admitted as a whole.
assert!(compatible_admitted("gpu,t6000"));
assert!(compatible_admitted("gpu,t8112"));
assert!(!compatible_admitted("gpu,t6020"));
assert!(!compatible_admitted("gpu,t9999"));
}
#[test]
fn g13_identities_are_ones_its_kext_accepts() {
for gpu in GPUS.iter().filter(|gpu| gpu.family.generations == [4]) {
let id = gpu.admitted().unwrap();
// `readChipInfo`: variants 0, 2, 3, 4; revisions A0, B0, B1, C0.
assert!([2, 3, 4].contains(&id.variant));
assert!([0x00, 0x10, 0x11, 0x20].contains(&id.revision));
let cores = u32::from(id.cores) * u32::from(id.clusters);
let enabled: u32 = id.core_mask.iter().map(|word| word.count_ones()).sum();
assert_eq!(enabled, cores);
if id.variant == 2 {
assert_eq!(id.core_mask[1..], [0, 0]);
} else {
assert!([2, 4, 8].contains(&id.clusters));
}
assert!(!gpu.family.dashboard_signals);
}
}
#[test]
@@ -7,7 +7,8 @@
//! Known (`AGXG14G`, kernel file offsets):
//! - The root is one page (`AGXArmFirmware::allocFirmwareData` 0x1b5bdc0).
//! `AGXArmFirmware::initFirmwareData` (0x1b5b35c..0x1b5b4f0) writes
//! [`MAGIC`] at +0x00, the firmware VA of the page at
//! the family's magic at +0x00 ([`super::generation::Family::
//! initdata_magic`]), the firmware VA of the page at
//! `AGXArmFirmware+0x1660` at +0x08, the 64-bit firmware VAs cached at
//! `AGXFirmware+0x830`, +0x358, +0x848, +0x928, +0x930 and +0x368 at +0x18,
//! +0x20, +0xa8, +0xb0, +0xb8 and +0xc0, the words 0 and 1 at +0x28 and
@@ -36,8 +37,6 @@
use super::firmware::Pipe;
use super::ring::{self, Descriptor, Shared};
/// The root's first word.
pub const MAGIC: u64 = 0x0c8a_6342_8392_04c8;
/// Bytes of the root the kext writes (through +0xc0's pointer).
pub const ROOT_BYTES: usize = 0xc8;
/// The words at +0x28 and +0x2c.
@@ -81,11 +80,12 @@ pub struct Root {
}
impl Root {
/// Parse the root's bytes, refusing a root that is not the kext's.
pub fn parse(bytes: &[u8; ROOT_BYTES]) -> Result<Self, &'static str> {
/// Parse the root's bytes, refusing a root that is not the kext's: its
/// first word must be the family's `magic`.
pub fn parse(bytes: &[u8; ROOT_BYTES], magic: u64) -> Result<Self, &'static str> {
let u64_at = |at: usize| u64::from_le_bytes(bytes[at..at + 8].try_into().unwrap());
let u32_at = |at: usize| u32::from_le_bytes(bytes[at..at + 4].try_into().unwrap());
if u64_at(0) != MAGIC {
if u64_at(0) != magic {
return Err("GFX initdata root lacks its magic");
}
if (u32_at(0x28), u32_at(0x2c)) != ROOT_CONSTANTS {
@@ -116,11 +116,11 @@ impl Root {
Ok(root)
}
/// Read the root at `va`.
pub fn read(memory: &mut dyn Shared, va: u64) -> Result<Self, &'static str> {
/// Read the root at `va`, whose first word must be `magic`.
pub fn read(memory: &mut dyn Shared, va: u64, magic: u64) -> Result<Self, &'static str> {
let mut bytes = [0; ROOT_BYTES];
memory.read(va, &mut bytes)?;
Self::parse(&bytes)
Self::parse(&bytes, magic)
}
/// The device-control ring.
@@ -159,6 +159,7 @@ impl Root {
#[cfg(test)]
pub(crate) mod tests {
use super::*;
pub(crate) use crate::platform::apple::agx::generation::MAGIC_G13_G14G as MAGIC;
use crate::platform::apple::agx::ring::tests::Flat;
pub(crate) const BASE: u64 = 0xffff_ffa0_0000_0000;
@@ -183,7 +184,7 @@ pub(crate) mod tests {
fn the_root_names_its_objects_by_the_kext_fields() {
let mut memory = Flat::new(BASE, 0x10000);
kext_root(&mut memory);
let root = Root::read(&mut memory, ROOT).unwrap();
let root = Root::read(&mut memory, ROOT, MAGIC).unwrap();
assert_eq!(root.rings, RINGS);
assert_eq!(root.page_1660, BASE + 0x2000);
assert_eq!(root.object_358, BASE + 0x3000);
@@ -196,14 +197,14 @@ pub(crate) mod tests {
let mut memory = Flat::new(BASE, 0x10000);
kext_root(&mut memory);
memory.put_u64(ROOT + 0x28, 0);
assert!(Root::read(&mut memory, ROOT).is_err());
assert!(Root::read(&mut memory, ROOT, MAGIC).is_err());
kext_root(&mut memory);
memory.put_u64(ROOT + 0xb0, 0);
assert!(Root::read(&mut memory, ROOT).is_err());
assert!(Root::read(&mut memory, ROOT, MAGIC).is_err());
kext_root(&mut memory);
memory.put_u64(ROOT, 0);
assert_eq!(
Root::read(&mut memory, ROOT),
Root::read(&mut memory, ROOT, MAGIC),
Err("GFX initdata root lacks its magic")
);
}
@@ -212,7 +213,7 @@ pub(crate) mod tests {
fn the_ring_directory_places_work_device_control_and_events() {
let mut memory = Flat::new(BASE, 0x10000);
kext_root(&mut memory);
let root = Root::read(&mut memory, ROOT).unwrap();
let root = Root::read(&mut memory, ROOT, MAGIC).unwrap();
// 3D, submission index 2.
memory.put_descriptor(RINGS + 0x20 + 2 * 0x60 + 0x20, BASE + 0x8000, BASE + 0x9000);
memory.put_descriptor(RINGS + 0x1a0, BASE + 0x8100, BASE + 0xa000);
@@ -361,7 +361,7 @@ mod tests {
const CORE_MASK_1: u64 = 0xd0_1514;
fn t8112() -> &'static Gpu {
generation::by_compatible("gpu,t8112").unwrap()
generation::by_chip(0x8112).unwrap()
}
fn read(sgx: &mut Sgx, offset: u64) -> Result<u64, MmioError> {