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
23 changes: 23 additions & 0 deletions drivers/gpu/drm/asahi/fwid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,29 @@ mod tests {
}
}

#[test]
fn m5_pro_builds_name_their_layouts() {
use crate::g17::fw::variant::{Firmware, M5Layouts};
let Firmware::Identified(builds) = crate::hw::t6050::CONFIG.firmware else {
panic!("the M5 Pro must identify its loaded firmware");
};
for (i, build) in builds.iter().enumerate() {
// 27.2 (26B123) moved the InitData layouts; 27.3 beta 1 (26C5035r) also moved
// the HW data.
let layouts = if build.os_version >= [27, 3, 0] {
M5Layouts::V26C5035
} else if build.os_version >= [27, 2, 0] {
M5Layouts::V26B123
} else {
M5Layouts::V26A428
};
assert_eq!(build.variant.m5_layouts, Some(layouts));
for other in &builds[i + 1..] {
assert_ne!(build.images[0].text_sha256, other.images[0].text_sha256);
}
}
}

fn t6050_admits_only(builds: &[crate::g17::fw::variant::Build]) {
for image in builds.iter().flat_map(|build| build.images) {
// Both roles' records, inside TEXT.
Expand Down
876 changes: 819 additions & 57 deletions drivers/gpu/drm/asahi/g17/fw/m5/initdata.rs

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions drivers/gpu/drm/asahi/g17/fw/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ pub(crate) enum InitGraph {
V25G83,
}

/// The InitData layouts of an M5 firmware build ([`super::m5::initdata`]). The 27.2 and later
/// layouts are not yet confirmed from captured InitData. Observed so far: the 27.3 beta 1
/// firmware (26C5035r) on a J716s acknowledged the primary and secondary InitData built with the
/// `V26C5035` layouts and ran without a coprocessor fault; the 27.2 firmware has not run.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub(crate) enum M5Layouts {
/// The 26A428 graph: version word 0x0c8e_0339_8728_04c0 and its allocation sizes.
V26A428,
/// The 27.2 (26B123) graph: version word 0x0c8e_4339_8728_04c0, a larger power policy
/// (0x12728) and status config (0x790), the 26A428 HW data.
V26B123,
/// The 27.3 beta 1 (26C5035r) graph: 26B123's, the same version word included, with a HW
/// data word inserted at 0x2720. Only the firmware's identity tells it from 26B123.
V26C5035,
}

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub(crate) enum QueueRegistration {
Firmware,
Expand Down Expand Up @@ -94,6 +110,8 @@ pub(crate) struct Variant {
/// work. The bare-metal M5 firmware powers the cores for work by its own policy: under a
/// hold, the M5 Ultra's core-power witness reads unpowered until the hold is released.
pub(crate) registration_power_hold: bool,
/// The InitData layouts the M5 graph must build for this firmware; `None` off M5.
pub(crate) m5_layouts: Option<M5Layouts>,
/// A context takes its render pool identity when it is created, not at its first render,
/// so that identities held by render graphs kept until the firmware stops refuse new
/// contexts with an error instead of failing a context's first render. Set for the A18
Expand Down Expand Up @@ -159,6 +177,7 @@ pub(crate) const V26A428: Variant = Variant {
split_firmware_area: false,
m5_commands: false,
registration_power_hold: true,
m5_layouts: None,
render_id_at_create: true,
objects_after_release: true,
};
Expand Down Expand Up @@ -199,6 +218,7 @@ pub(crate) const V25G83: Variant = Variant {
split_firmware_area: false,
m5_commands: false,
registration_power_hold: true,
m5_layouts: None,
render_id_at_create: false,
objects_after_release: false,
};
Expand All @@ -211,11 +231,25 @@ pub(crate) const V26A428_M5: Variant = Variant {
traversal_exclusion: false,
render_ray_query: false,
registration_power_hold: false,
m5_layouts: Some(M5Layouts::V26A428),
render_id_at_create: false,
objects_after_release: false,
..V26A428
};

/// The 27.2 M5 firmware (26B123): the 26A428 M5 protocol with the 26B123 InitData layouts.
pub(crate) const V26B123_M5: Variant = Variant {
m5_layouts: Some(M5Layouts::V26B123),
..V26A428_M5
};

/// The 27.3 beta 1 M5 firmware (26C5035r): the 26A428 M5 protocol with the 26C5035r InitData
/// layouts.
pub(crate) const V26C5035_M5: Variant = Variant {
m5_layouts: Some(M5Layouts::V26C5035),
..V26A428_M5
};

pub(crate) const V25F84: Variant = Variant {
qid_floor: 0,
registration: QueueRegistration::Mailbox,
Expand Down
6 changes: 6 additions & 0 deletions drivers/gpu/drm/asahi/g17/initdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ pub(super) struct InitData {
m5: bool,
/// The M5 firmware build's layout, where [`Self::m5`].
graph: &'static super::fw::m5::initdata::Graph,
/// Power-policy layout of the M5 firmware build.
m5_policy: &'static crate::g17::fw::m5::initdata::M5PolicyMap,
/// Status-config layout of the M5 firmware build.
m5_status_config: &'static crate::g17::fw::m5::initdata::M5StatusConfigMap,
outer_credits: Option<Arc<outer_credit::Credits>>,
// Live publication uses interior writes under the device mutex. This owner is Send but not
// Sync, so safe host code cannot issue those writes concurrently through shared references.
Expand Down Expand Up @@ -292,6 +296,8 @@ impl InitData {
Self {
m5: false,
graph: &super::fw::m5::initdata::M5_GRAPH,
m5_policy: &crate::g17::fw::m5::initdata::M5_26A428_POLICY,
m5_status_config: &crate::g17::fw::m5::initdata::M5_26A428_STATUS_CONFIG,
outer_credits: None,
_single_publisher: core::marker::PhantomData,
aliases: KVec::new(),
Expand Down
88 changes: 67 additions & 21 deletions drivers/gpu/drm/asahi/g17/initdata/m5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,16 @@ impl InitData {
ring(0), ring(1), ring(2), ring(3), page(canonical.start)]
}

/// Diagnostic-only read of an aligned word within the existing policy allocation.
/// Selects the power-policy layout of the M5 firmware build `build_m5` encodes for.
pub(in crate::g17) fn set_m5_policy_layouts(
&mut self,
layouts: crate::g17::fw::variant::M5Layouts,
) {
self.m5_policy = m::m5_policy(layouts);
}

/// Diagnostic-only read of an aligned word within the existing policy allocation, at the
/// firmware build's own offset.
/// Callers hold the device state mutex, retaining this mapping for the entire sample.
pub(crate) fn m5_policy_telemetry_word(&self, offset: usize) -> Result<u32> {
if !self.m5 || offset & 3 != 0
Expand All @@ -70,18 +79,27 @@ impl InitData {
// 26A428 one (0x6d0 bytes) has no such table.
if self.graph.is_common26() { return Ok(()); }
let private = self.object(self.cluster)?;
let base = m::M5_PRIVATE_LAYOUT.status_config;
let base = self.graph.private.status_config;
let field = |offset| {
self.m5_status_config
.relocate(offset)
.map(|at| base + at)
.ok_or(EINVAL)
};
let history = field(m::M5_STATUS_CONFIG_HISTORY)?;
let generation_at = field(m::M5_STATUS_CONFIG_HISTORY_GENERATION)?;
let slots = field(m::M5_STATUS_CONFIG_HISTORY_SLOTS)?;
for _ in 0..64 {
let generation = private.word(base + 0x74c)?.load(Ordering::Acquire);
let generation = private.word(generation_at)?.load(Ordering::Acquire);
if generation & 1 != 0 { core::hint::spin_loop(); continue; }
// The firmware moves the generation around every change of the geometry: while it
// reads as it did, the geometry read under it stands, without four more loads.
let (period, count) = match self.history_geometry.get() {
Some((seen, period, count)) if seen == generation => (period, count),
_ => {
let config = private.read_words::<4>(base + 0x73c)?;
let config = private.read_words::<4>(history)?;
fence(Ordering::Acquire);
if generation != private.word(base + 0x74c)?.load(Ordering::Acquire) {
if generation != private.word(generation_at)?.load(Ordering::Acquire) {
core::hint::spin_loop(); continue;
}
let period = u64::from(config[0]) | u64::from(config[1]) << 32;
Expand All @@ -96,7 +114,7 @@ impl InitData {
// One slot per 25000 ticks of the period.
let index = (ticks % period) / 25_000;
if index >= count { return Err(ERANGE); }
let byte = private.pointer(base + 0x750 + index as usize, 1)?;
let byte = private.pointer(slots + index as usize, 1)?;
// SAFETY: retained, bounds-checked WC byte, written as a single byte
// after reading the even, stable generation, as the firmware expects.
unsafe {
Expand Down Expand Up @@ -130,13 +148,25 @@ impl InitData {
}
}

pub(crate) fn build_m5(&mut self, dev: &AsahiDrmDevice, uat: &mmu::Uat,
id: &crate::regs::G17Id, board: &m::Board) -> Result {
/// Builds the M5 graph in the InitData layouts the loaded firmware build (`variant`) names.
pub(crate) fn build_m5(
&mut self,
dev: &AsahiDrmDevice,
uat: &mmu::Uat,
id: &crate::regs::G17Id,
board: &m::Board,
variant: &crate::g17::fw::Variant,
) -> Result {
use mmu::{PROT_FW_SHARED_RW as RW, PROT_FW_SHARED_RO as RO,
PROT_GPU_SHARED_RW as GPU};
self.m5 = true;
self.graph = board.graph;
let layouts = variant.m5_layouts.ok_or(EINVAL)?;
let common26 = board.graph.is_common26();
self.graph = if common26 { board.graph } else { m::m5_graph(layouts) };
let profile = self.graph.profile;
let layout = profile.m5_layout().unwrap_or(&m::M5_LAYOUT_26A428);
self.m5_status_config = profile.m5_status_config();
self.set_m5_policy_layouts(layouts);
self.m5 = true;
// TA, fragment and compute share the compute work ring per priority; every
// preparation's claim on it is counted from the first publication on.
self.outer_credits = Some(super::outer_credit::Credits::new()?);
Expand All @@ -146,8 +176,8 @@ impl InitData {
KernelObject::new(dev, uat.kernel_vm(), Placement::At(address), size,
mmu::PROT_FW_PRIV_RW, CpuMap::WriteBack)
};
let private = board.graph.private;
let shared = board.graph.shared;
let private = self.graph.private;
let shared = self.graph.shared;
self.cluster = self.add(fixed(PRIVATE, private.total, RW)?)?;
self.region_c = self.add(fixed(REGION_C, mmu::UAT_PGSZ, RO)?)?;
self.roots = self.add(fixed(ROOTS, 0xc000, RO)?)?;
Expand All @@ -173,7 +203,7 @@ impl InitData {
Placement::In(uat.kernel_dynamic_range(), mmu::UAT_PGSZ as u64),
mmu::UAT_PGSZ, mmu::PROT_FW_SHARED_RW, CpuMap::WriteCombined)?)?;
}
let views = board.graph.profile.region_view_low_addrs();
let views = profile.region_view_low_addrs();
self.alias(self.pb, uat.kernel_lower_vm(), views[0], GPU)?;
self.alias(self.page_pool, uat.kernel_lower_vm(), views[1], GPU)?;
let (low, high) = if common26 {
Expand Down Expand Up @@ -210,7 +240,7 @@ impl InitData {
.map_err(|_| EINVAL)?;
} else {
m::encode_m5_region_c(self.object_mut(self.region_c)?.bytes_mut()).map_err(|_| EINVAL)?;
m::encode_m5_private_cluster(PRIVATE, FWCTL,
m::encode_m5_private_cluster_for_profile(profile, PRIVATE, FWCTL,
&mut self.object_mut(self.cluster)?.bytes_mut()[..private.total]).map_err(|_| EINVAL)?;
}
let windows = board.register_windows();
Expand All @@ -236,15 +266,15 @@ impl InitData {
let views = m::PrimaryRegionViews {
sentinel_high: BASE + 0xc07e_0000, alias_high: [PB, UMA],
};
m::encode_m5_hw_data(board, completions, QOS, windows,
m::encode_m5_hw_data_for_layout(layout, board, completions, QOS, windows,
&mut self.object_mut(self.bundle)?.bytes_mut()[..m::M5_HW_DATA_SIZE]).map_err(|_| EINVAL)?;
m::set_m5_kick_shared(board,
m::set_m5_kick_shared_for_layout(layout, board,
&mut self.object_mut(self.bundle)?.bytes_mut()[..m::M5_HW_DATA_SIZE], KICK_SHARED)
.map_err(|_| EINVAL)?;
let masked_cores: u32 = id.core_masks.iter().map(|mask| mask.count_ones()).sum();
let enabled_cores = if masked_cores != 0 { masked_cores }
else { id.num_clusters.checked_mul(id.num_cores).ok_or(EOVERFLOW)? };
m::set_m5_enabled_cores(board,
m::set_m5_enabled_cores_for_layout(layout, board,
&mut self.object_mut(self.bundle)?.bytes_mut()[..m::M5_HW_DATA_SIZE], enabled_cores)
.map_err(|_| EINVAL)?;
let bindings = m::M5PolicyBindings {
Expand All @@ -253,15 +283,32 @@ impl InitData {
if common26 {
m::encode_common26_bundle_policy(board, bindings, self.object_mut(self.bundle)?.bytes_mut())
} else {
m::encode_m5_bundle_policy(bindings, self.object_mut(self.bundle)?.bytes_mut())
m::encode_m5_bundle_policy_for_layout(layout, bindings, self.object_mut(self.bundle)?.bytes_mut())
}.map_err(|_| EINVAL)?;
if let Some(defaults) = board.controller_defaults {
let controller_defaults = board.controller_defaults;
if let Some(defaults) = controller_defaults {
defaults(self.object_mut(self.bundle)?.bytes_mut()).map_err(|_| EINVAL)?;
let maximum = self.object(self.bundle)?.word(shared.policy + m::M5_POLICY_MAXIMUM_POWER)?
.load(Ordering::Relaxed);
m::set_m5_region_maximum_power(self.object_mut(self.region_c)?.bytes_mut(), maximum)
.map_err(|_| EINVAL)?;
}
// The policy encoders write the 26A428 layout; a build with another one gets it laid out
// in place, within its own allocation.
if !common26 {
let policy = self.m5_policy;
let policy_end = shared.policy.checked_add(policy.size).ok_or(EINVAL)?;
if policy_end > shared.block_68 {
return Err(EINVAL);
}
m::relayout_m5_policy(
policy,
board,
controller_defaults.is_some(),
&mut self.object_mut(self.bundle)?.bytes_mut()[shared.policy..policy_end],
)
.map_err(|_| EINVAL)?;
}
if let Some(microseconds) = board.idle_standby_us {
m::set_m5_region_idle_standby(self.object_mut(self.region_c)?.bytes_mut(), microseconds)
.map_err(|_| EINVAL)?;
Expand All @@ -276,9 +323,8 @@ impl InitData {
[PRIVATE + private.status_config as u64, PRIVATE + private.secondary_extra_1 as u64]
},
};
let profile = board.graph.profile;
let channels = m::derive_channel_table_for_profile(profile, role,
PRIVATE + board.graph.state_grids[index] as u64,
PRIVATE + self.graph.state_grids[index] as u64,
instance.status_a, instance.main_config, BUNDLE);
let offset = shared.main_config[index];
m::encode_main_config_for_profile(profile, role, &addresses, &instance,
Expand Down
12 changes: 11 additions & 1 deletion drivers/gpu/drm/asahi/g17/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1648,6 +1648,16 @@ impl Gpu {
}
let m5 = cfg.profile.is_m5();
if m5 {
// The M5 graph builds the InitData layouts the firmware build names. A build that
// names none is refused here, before anything is written to the GPU.
if variant.m5_layouts.is_none() {
dev_err!(
dev.as_ref(),
"No M5 InitData layouts for this GPU firmware build ({:?})\n",
variant.m5_layouts
);
return Err(ENODEV);
}
let board = cfg.m5.ok_or(EINVAL)?;
J813_FORMS.store(board.j813_forms(), core::sync::atomic::Ordering::Relaxed);
// Hold the J813's GFX power domain for the session, as the G15 and G16 paths do
Expand Down Expand Up @@ -2142,7 +2152,7 @@ impl Gpu {
.inspect_err(at("root adoption"))?;
session
.init
.build_m5(dev, &session.uat, id, board)
.build_m5(dev, &session.uat, id, board, shared.variant)
.inspect_err(at("M5 graph"))?;
session
.init
Expand Down
Loading
Loading