feat(firmware): pin every firmware file amdgpu's built units name, selected per GPU by its family or, for a GPU amdgpu identifies by IP discovery, as every IP-versioned file
This commit is contained in:
1 parent
da33fa2c23
commit
1497252317
11 files changed
+4721
-531
No files matched your search
@@ -117,10 +117,11 @@ static NOUVEAU: Before = Before {
|
||||
},
|
||||
};
|
||||
|
||||
/// amdgpu: the files are those its IP blocks ask for on the PCI device ID's
|
||||
/// GPU, as pinned. The driver reads which blocks the device has from the
|
||||
/// device's own discovery table and loads every engine's firmware itself,
|
||||
/// so nothing boots by itself after the reset and nothing waits here.
|
||||
/// amdgpu: the files are those it may ask for on the PCI device ID's GPU,
|
||||
/// as pinned: its family's for a device its table names, every file named
|
||||
/// after an IP version for one it identifies by the device's own IP
|
||||
/// discovery table. The driver loads every engine's firmware itself, so
|
||||
/// nothing boots by itself after the reset and nothing waits here.
|
||||
static AMDGPU: Before = Before {
|
||||
admits: |adapter, catalog| {
|
||||
on_usb(
|
||||
@@ -302,14 +303,11 @@ fn video_bios_table(
|
||||
image
|
||||
}
|
||||
|
||||
/// The files amdgpu asks for on the AMD GPU with PCI device ID `device`.
|
||||
/// The files amdgpu may ask for on the AMD GPU with PCI device ID `device`.
|
||||
fn amdgpu_files(device: u16) -> Result<Inventory, ServiceError> {
|
||||
let mut inventory = Inventory::default();
|
||||
stela_loader::host_firmware::recipes::require_amdgpu(&mut inventory, device).map_err(|_| {
|
||||
ServiceError::Refused(
|
||||
"Stela pins amdgpu's firmware only for Ryzen 7000 and 9000 desktop graphics, \
|
||||
not for this GPU",
|
||||
)
|
||||
ServiceError::Refused("amdgpu leaves this GPU to an older driver and loads no files for it")
|
||||
})?;
|
||||
Ok(inventory)
|
||||
}
|
||||
@@ -458,15 +456,20 @@ fn select_firmware(
|
||||
let stored: &'static Catalog = unsafe { &*Arc::into_raw(catalog.clone()) };
|
||||
let mut bindings = Vec::new();
|
||||
let mut missing = Vec::new();
|
||||
// A driver that chooses among many files by what the device reports
|
||||
// (amdgpu by IP discovery) gets one line for them, not one each.
|
||||
let summarized = plan.selections().len() > SUMMARIZED;
|
||||
for selection in plan.selections() {
|
||||
let request = &selection.request;
|
||||
let found = find(stored, selection);
|
||||
if let Ok(image) = found {
|
||||
output::arguments(format_args!(
|
||||
"GPU {name}: firmware {} of {} bytes\n",
|
||||
request.name,
|
||||
image.bytes().len()
|
||||
));
|
||||
if !summarized {
|
||||
output::arguments(format_args!(
|
||||
"GPU {name}: firmware {} of {} bytes\n",
|
||||
request.name,
|
||||
image.bytes().len()
|
||||
));
|
||||
}
|
||||
bindings.push((image, request));
|
||||
}
|
||||
match found {
|
||||
@@ -505,6 +508,17 @@ fn select_firmware(
|
||||
if !missing.is_empty() {
|
||||
return Err(lacks(name, &missing, names.len()));
|
||||
}
|
||||
if summarized {
|
||||
output::arguments(format_args!(
|
||||
"GPU {name}: {} firmware files of {} bytes, of which its driver loads those the \
|
||||
device names\n",
|
||||
bindings.len(),
|
||||
bindings
|
||||
.iter()
|
||||
.map(|(image, _)| image.bytes().len())
|
||||
.sum::<usize>()
|
||||
));
|
||||
}
|
||||
names.extend(read.iter().map(|(_, name)| String::from(*name)));
|
||||
// Each file under the exact name and target the driver asks for.
|
||||
let catalog = Catalog::rebind_all(
|
||||
@@ -636,6 +650,9 @@ fn wait_for_firmware_boot(
|
||||
}
|
||||
}
|
||||
|
||||
/// More firmware files than this for one GPU are logged as one line.
|
||||
const SUMMARIZED: usize = 16;
|
||||
|
||||
/// Why a GPU was refused when the USB lacks any of its chip's firmware files.
|
||||
pub(super) const NO_FIRMWARE: &str = "no pinned firmware for the observed GPU chipset was loaded";
|
||||
/// Why a GPU was refused when the USB holds its chip's files and reading
|
||||
|
||||
@@ -22,6 +22,9 @@ use uefi::{
|
||||
proto::media::{file::Directory, fs::SimpleFileSystem},
|
||||
};
|
||||
|
||||
/// More files than this for one device are logged as one line.
|
||||
const SUMMARIZED: usize = 16;
|
||||
|
||||
/// The files read from the bundle, in the order of their regions.
|
||||
pub struct Bundled {
|
||||
bundle: Bundle<'static>,
|
||||
@@ -168,6 +171,17 @@ fn load_from(
|
||||
bundle: parsed,
|
||||
record: Region::default(),
|
||||
};
|
||||
// A device that may ask for many files (an AMD GPU amdgpu identifies by
|
||||
// IP discovery) gets one line for the files read, not one each.
|
||||
let many = |why: &str| {
|
||||
selection
|
||||
.wanted
|
||||
.iter()
|
||||
.filter(|(_, wanted)| wanted == why)
|
||||
.count()
|
||||
> SUMMARIZED
|
||||
};
|
||||
let mut summaries: Vec<(&str, usize, usize)> = Vec::new();
|
||||
let mut lacking = 0;
|
||||
let mut failed: Vec<&str> = Vec::new();
|
||||
for (artifact, why) in &selection.wanted {
|
||||
@@ -193,10 +207,17 @@ fn load_from(
|
||||
};
|
||||
match read {
|
||||
Ok(region) => {
|
||||
output::arguments(format_args!(
|
||||
"HOST FIRMWARE BUNDLE USE {} bytes={} for {why}\n",
|
||||
object.member, object.length
|
||||
));
|
||||
if !many(why) {
|
||||
output::arguments(format_args!(
|
||||
"HOST FIRMWARE BUNDLE USE {} bytes={} for {why}\n",
|
||||
object.member, object.length
|
||||
));
|
||||
} else if let Some(summary) = summaries.iter_mut().find(|(seen, ..)| seen == why) {
|
||||
summary.1 += 1;
|
||||
summary.2 += object.length;
|
||||
} else {
|
||||
summaries.push((why, 1, object.length));
|
||||
}
|
||||
bundled.selected.push(index);
|
||||
bundled.regions.push(region);
|
||||
}
|
||||
@@ -210,6 +231,11 @@ fn load_from(
|
||||
}
|
||||
}
|
||||
}
|
||||
for (why, files, bytes) in summaries {
|
||||
output::arguments(format_args!(
|
||||
"HOST FIRMWARE BUNDLE USE {files} files bytes={bytes} for {why}\n"
|
||||
));
|
||||
}
|
||||
let record = {
|
||||
let bundled = &bundled;
|
||||
bundle::held_record(&bundled.bundle, |sha256| {
|
||||
|
||||
@@ -1039,7 +1039,7 @@ mod tests {
|
||||
assert!(parsed.missing().is_empty());
|
||||
// A stick for an image with the AMD port also holds its firmware.
|
||||
let (objects, summary) = if cfg!(feature = "amdgpu-port") {
|
||||
(121, "for every supported device (184.9 MiB)")
|
||||
(648, "for every supported device (260.0 MiB)")
|
||||
} else {
|
||||
(88, "for every supported device (177.0 MiB)")
|
||||
};
|
||||
@@ -1068,7 +1068,7 @@ mod tests {
|
||||
);
|
||||
assert!(!left.contains(&"regulatory.db"));
|
||||
// Files the volume already holds count as room.
|
||||
let (_, left) = bundle_plan(Some(MARGIN), 260 * MIB);
|
||||
let (_, left) = bundle_plan(Some(MARGIN), 280 * MIB);
|
||||
assert!(left.is_empty());
|
||||
}
|
||||
|
||||
@@ -1330,7 +1330,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
status,
|
||||
if cfg!(feature = "amdgpu-port") {
|
||||
"the firmware on the stick is incomplete: 3 of 121 files are there"
|
||||
"the firmware on the stick is incomplete: 3 of 648 files are there"
|
||||
} else {
|
||||
"the firmware on the stick is incomplete: 3 of 88 files are there"
|
||||
}
|
||||
@@ -1356,7 +1356,7 @@ mod tests {
|
||||
.unwrap();
|
||||
let status = bundle_status(dir.path()).unwrap_err();
|
||||
let lacks = if cfg!(feature = "amdgpu-port") {
|
||||
"lacks 120 of 121 files"
|
||||
"lacks 647 of 648 files"
|
||||
} else {
|
||||
"lacks 87 of 88 files"
|
||||
};
|
||||
|
||||
@@ -5683,7 +5683,7 @@ fn a_usb_made_without_an_nvidia_gpu_needs_no_firmware_step() {
|
||||
}
|
||||
assert_eq!(lines[0], lines[1]);
|
||||
let size = if cfg!(feature = "amdgpu-port") {
|
||||
"184.9 MiB"
|
||||
"260.0 MiB"
|
||||
} else {
|
||||
"177.0 MiB"
|
||||
};
|
||||
|
||||
@@ -92,8 +92,13 @@ impl MountLimits {
|
||||
|
||||
pub const MANIFEST_PATH: &str = "EFI/stela/firmware/manifest.json";
|
||||
pub const DIRECTORY: &str = "EFI/stela/firmware";
|
||||
pub const MAX_MANIFEST_BYTES: usize = 128 * 1024;
|
||||
pub const MAX_IMAGES: usize = 64;
|
||||
/// Room for the complete bundle's manifest, whose amdgpu files alone are
|
||||
/// near 700.
|
||||
pub const MAX_MANIFEST_BYTES: usize = 1024 * 1024;
|
||||
/// Room for the files a GPU amdgpu identifies by IP discovery may ask for
|
||||
/// (every file named after an IP version, about 220), beside a second
|
||||
/// GPU's and the network's.
|
||||
pub const MAX_IMAGES: usize = 512;
|
||||
pub const MAX_IMAGE_BYTES: usize = 64 * 1024 * 1024;
|
||||
/// Room for a GSP-RM image per GPU family, beside every other driver's firmware.
|
||||
pub const MAX_TOTAL_BYTES: usize = 256 * 1024 * 1024;
|
||||
@@ -182,7 +187,7 @@ fn fail(message: &str) -> Error {
|
||||
impl<'a> Manifest<'a> {
|
||||
pub fn parse(bytes: &'a [u8]) -> Result<Self, Error> {
|
||||
if bytes.len() > MAX_MANIFEST_BYTES {
|
||||
return Err(fail("host firmware manifest exceeds 128 KiB"));
|
||||
return Err(fail("host firmware manifest exceeds 1 MiB"));
|
||||
}
|
||||
let manifest: Self = serde_json::from_slice(bytes)
|
||||
.map_err(|e| Error(format!("host firmware manifest: {e}")))?;
|
||||
|
||||
@@ -22,7 +22,7 @@ pub const DIRECTORY: &str = "stela/firmware";
|
||||
/// The bundle's manifest on its volume.
|
||||
pub const MANIFEST: &str = "stela/firmware/bundle.json";
|
||||
/// At most this many files and as many notices.
|
||||
pub const MAX_OBJECTS: usize = 256;
|
||||
pub const MAX_OBJECTS: usize = 1024;
|
||||
/// The target a bundle file has in the boot's catalog, under the name
|
||||
/// [`name`] gives its digest. Only [`BundleProvider`] asks for it.
|
||||
pub const TARGET: driver::Target<'static> = driver::Target {
|
||||
@@ -254,7 +254,7 @@ pub fn complete() -> Vec<(&'static Artifact, &'static Artifact)> {
|
||||
impl<'a> Bundle<'a> {
|
||||
pub fn parse(bytes: &'a [u8]) -> Result<Self, Error> {
|
||||
if bytes.len() > MAX_MANIFEST_BYTES {
|
||||
return Err(fail("host firmware bundle manifest exceeds 128 KiB"));
|
||||
return Err(fail("host firmware bundle manifest exceeds 1 MiB"));
|
||||
}
|
||||
let bundle: Self = serde_json::from_slice(bytes)
|
||||
.map_err(|e| Error(format!("host firmware bundle manifest: {e}")))?;
|
||||
@@ -631,11 +631,11 @@ pub fn select_for(functions: &[Pci], ports: Ports) -> Selection {
|
||||
if !ports.amd {
|
||||
continue;
|
||||
}
|
||||
// The files amdgpu may ask this device for; a device it leaves
|
||||
// to an older driver has none.
|
||||
if recipes::require_amdgpu(&mut inventory, function.device).is_ok() {
|
||||
selection.plan(&inventory, &why);
|
||||
driven.push(function.vendor);
|
||||
} else if !selection.unknown.contains(&why) {
|
||||
selection.unknown.push(why.clone());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
use super::*;
|
||||
|
||||
/// amdgpu's recipes whose bytes another holds, and the bundle's files and
|
||||
/// bytes with the AMD port: 648 files, 260.0 MiB.
|
||||
const AMD_SHARED: usize = 128;
|
||||
const AMD_TOTAL: (usize, usize) = (648, 272_649_034);
|
||||
use stela_driver_core::firmware::{Provenance, Resource, Target};
|
||||
|
||||
#[test]
|
||||
@@ -20,12 +25,12 @@ fn the_complete_bundle_holds_every_recipe_once_by_content() {
|
||||
let (count, bytes) = size();
|
||||
assert_eq!(count, objects.len());
|
||||
// The RTL8168H and RTL8168M share a file, as the RTL9151A and RTL9151AS
|
||||
// do, and, with the AMD port, amdgpu's `mec` and `mec2` of Raphael and
|
||||
// of Navi 21.
|
||||
// do, and, with the AMD port, amdgpu's files that hold another's bytes
|
||||
// (`mec2` and `mec` of most families, a revision's files that did not
|
||||
// change).
|
||||
if Ports::BUILT == Ports::ALL {
|
||||
assert_eq!(count + 4, recipes().count());
|
||||
// The recipes' recorded lengths: 121 files, 184.9 MiB.
|
||||
assert_eq!((count, bytes), (121, 193_887_456), "{count} {bytes}");
|
||||
assert_eq!(count + AMD_SHARED, recipes().count());
|
||||
assert_eq!((count, bytes), AMD_TOTAL, "{count} {bytes}");
|
||||
}
|
||||
if Ports::BUILT == Ports::NONE {
|
||||
assert_eq!(count + 2, recipes().count());
|
||||
@@ -177,70 +182,96 @@ fn a_boot_selects_exactly_the_files_its_pci_functions_need() {
|
||||
]);
|
||||
expected.sort_unstable();
|
||||
assert_eq!(members(&ax210), expected);
|
||||
// With the AMD port: Ryzen 9000 graphics, the files amdgpu asks for on it, its HDMI audio
|
||||
// function needs none, and an AMD display chip without pinned files
|
||||
// (Navi 10) is named once.
|
||||
// With the AMD port. Ryzen 9000 graphics, which amdgpu identifies by IP
|
||||
// discovery: every file named after an IP version; its HDMI audio
|
||||
// function needs none; a Navi 10 card, which amdgpu's table names: its
|
||||
// family's files; and a Radeon HD 5000 card, which amdgpu leaves to
|
||||
// radeon: none.
|
||||
let ryzen = select_for(
|
||||
&[
|
||||
pci(0x1002, 0x13c0, 0x03),
|
||||
pci(0x1002, 0x1640, 0x04),
|
||||
pci(0x1002, 0x731f, 0x03),
|
||||
pci(0x1002, 0x6898, 0x03),
|
||||
],
|
||||
Ports::ALL,
|
||||
);
|
||||
// The files amdgpu asks for on a GPU of the PCI device ID `device`.
|
||||
let family = |device: u16| {
|
||||
let mut inventory = Inventory::default();
|
||||
recipes::require_amdgpu(&mut inventory, device).unwrap();
|
||||
let mut names: Vec<&str> = inventory
|
||||
.requests()
|
||||
.iter()
|
||||
.map(|request| {
|
||||
recipes::AMDGPU
|
||||
.iter()
|
||||
.find(|recipe| recipe.image.member == request.name)
|
||||
.unwrap()
|
||||
.image
|
||||
.member
|
||||
})
|
||||
.collect();
|
||||
names.sort_unstable();
|
||||
names
|
||||
};
|
||||
let raphael = family(0x13c0);
|
||||
let mut expected: Vec<&str> = USB.to_vec();
|
||||
expected.extend(raphael.iter().copied());
|
||||
expected.sort_unstable();
|
||||
// `mec2` is `mec`'s bytes, which the bundle holds once.
|
||||
let amd: Vec<&Artifact> = recipes::AmdGpu::Discovered
|
||||
.files()
|
||||
.chain(recipes::AmdGpu::of(0x731f).files())
|
||||
.map(|recipe| &recipe.image)
|
||||
.collect();
|
||||
let found = members(&ryzen);
|
||||
assert!(found.iter().all(|member| expected.contains(member)));
|
||||
assert_eq!(found.len(), USB.len() + raphael.len() - 1);
|
||||
assert_eq!(ryzen.unknown, ["pci 1002:731f"]);
|
||||
// An RX 9070 (Navi 48) and its audio function: amdgpu's files for Navi
|
||||
// 48 and nothing for the audio function.
|
||||
let navi48 = select_for(
|
||||
&[pci(0x1002, 0x7550, 0x03), pci(0x1002, 0xab40, 0x04)],
|
||||
Ports::ALL,
|
||||
);
|
||||
let mut expected: Vec<&str> = USB.to_vec();
|
||||
expected.extend(family(0x7550));
|
||||
expected.sort_unstable();
|
||||
assert_eq!(members(&navi48), expected);
|
||||
assert!(navi48.unknown.is_empty());
|
||||
// An RX 6800 XT (Navi 21): its files, `mec2` held once as `mec`'s bytes.
|
||||
let navi21 = select_for(
|
||||
&[pci(0x1002, 0x73bf, 0x03), pci(0x1002, 0xab28, 0x04)],
|
||||
Ports::ALL,
|
||||
);
|
||||
let found = members(&navi21);
|
||||
let files = family(0x73bf);
|
||||
assert!(
|
||||
found
|
||||
.iter()
|
||||
.all(|member| USB.contains(member) || files.contains(member))
|
||||
);
|
||||
assert_eq!(found.len(), USB.len() + files.len() - 1);
|
||||
assert!(navi21.unknown.is_empty());
|
||||
for member in ["amdgpu/gc_10_3_6_pfp.bin", "amdgpu/navi10_pfp.bin"] {
|
||||
assert!(found.contains(&member), "{member}");
|
||||
}
|
||||
assert!(found.iter().all(
|
||||
|member| USB.contains(member) || amd.iter().any(|artifact| artifact.member == *member)
|
||||
));
|
||||
// Files of the same bytes are read once.
|
||||
let mut digests: Vec<&str> = amd.iter().map(|artifact| artifact.sha256).collect();
|
||||
digests.sort_unstable();
|
||||
digests.dedup();
|
||||
assert_eq!(found.len(), USB.len() + digests.len());
|
||||
assert!(ryzen.unknown.is_empty());
|
||||
// The files amdgpu loaded on an RX 9070 XT (Navi 48) and an RX 6800 XT
|
||||
// (Navi 21) under Stela, display core included, are among theirs.
|
||||
for (device, loaded) in [
|
||||
(
|
||||
0x7550,
|
||||
&[
|
||||
"gc_12_0_1_imu",
|
||||
"gc_12_0_1_me",
|
||||
"gc_12_0_1_mec",
|
||||
"gc_12_0_1_pfp",
|
||||
"gc_12_0_1_rlc",
|
||||
"gc_12_0_1_uni_mes",
|
||||
"psp_14_0_3_sos",
|
||||
"psp_14_0_3_ta",
|
||||
"sdma_7_0_1",
|
||||
"smu_14_0_3",
|
||||
"vcn_5_0_0",
|
||||
"dcn_4_0_1_dmcub",
|
||||
],
|
||||
),
|
||||
(
|
||||
0x73bf,
|
||||
&[
|
||||
"sienna_cichlid_ce",
|
||||
"sienna_cichlid_me",
|
||||
"sienna_cichlid_mec",
|
||||
"sienna_cichlid_mec2",
|
||||
"sienna_cichlid_pfp",
|
||||
"sienna_cichlid_rlc",
|
||||
"sienna_cichlid_sdma",
|
||||
"sienna_cichlid_smc",
|
||||
"sienna_cichlid_sos",
|
||||
"sienna_cichlid_ta",
|
||||
"sienna_cichlid_vcn",
|
||||
"sienna_cichlid_dmcub",
|
||||
],
|
||||
),
|
||||
] {
|
||||
let card = select_for(&[pci(0x1002, device, 0x03)], Ports::ALL);
|
||||
let found = members(&card);
|
||||
for file in loaded {
|
||||
let member = format!("amdgpu/{file}.bin");
|
||||
let held = recipes::AMDGPU
|
||||
.iter()
|
||||
.find(|recipe| recipe.image.member == member)
|
||||
.unwrap_or_else(|| panic!("{member}"));
|
||||
// `mec2` may be read as `mec`'s bytes.
|
||||
assert!(
|
||||
found
|
||||
.iter()
|
||||
.any(|name| recipes::AMDGPU.iter().any(|recipe| {
|
||||
recipe.image.member == *name && recipe.image.sha256 == held.image.sha256
|
||||
})),
|
||||
"{device:04x} {member}"
|
||||
);
|
||||
}
|
||||
assert!(card.unknown.is_empty());
|
||||
}
|
||||
// An NVIDIA display chip no recipe covers is named once.
|
||||
let old = select(&[pci(0x10de, 0x1b80, 0x03), pci(0x10de, 0x1b80, 0x03)]);
|
||||
assert_eq!(old.unknown, ["pci 10de:1b80"]);
|
||||
|
||||
@@ -1102,345 +1102,11 @@ pub const GSP: &[Recipe] = &[
|
||||
),
|
||||
];
|
||||
|
||||
const AMDGPU_LICENSE: Artifact = Artifact {
|
||||
source: LINUX_FIRMWARE,
|
||||
revision: GSP_REVISION,
|
||||
member: "LICENSES/LICENSE.amdgpu",
|
||||
length: 2938,
|
||||
sha256: "572872598565dc3513470de971a32bf9db301f47afeef3636345eadae33b2eee",
|
||||
mod amdgpu;
|
||||
pub use amdgpu::{
|
||||
AMDGPU, AmdGpu, UNPUBLISHED as AMDGPU_UNPUBLISHED, amd_gpu_family, require_amdgpu,
|
||||
};
|
||||
|
||||
/// A file of linux-firmware's `amdgpu` directory, under its notice, at the
|
||||
/// revision the GSP-RM files are pinned at.
|
||||
const fn amdgpu(member: &'static str, length: usize, sha256: &'static str) -> Recipe {
|
||||
Recipe {
|
||||
image: Artifact {
|
||||
source: LINUX_FIRMWARE,
|
||||
revision: GSP_REVISION,
|
||||
member,
|
||||
length,
|
||||
sha256,
|
||||
},
|
||||
license: &AMDGPU_LICENSE,
|
||||
consumer: Consumer::Amdgpu,
|
||||
}
|
||||
}
|
||||
|
||||
/// What amdgpu loads on the GPUs with pinned files, named as the driver
|
||||
/// names them: the graphics core's microcode (`gfx_v10_0.c`), the security
|
||||
/// processor's table of contents and trusted applications (`psp_v13_0.c`),
|
||||
/// the DMA engine's (`sdma_v5_2.c`), the display microcontroller's
|
||||
/// (`amdgpu_dm.c`) and the video decoder's (`amdgpu_vcn.c`).
|
||||
pub const AMDGPU: &[Recipe] = &[
|
||||
amdgpu(
|
||||
"amdgpu/gc_10_3_6_ce.bin",
|
||||
263296,
|
||||
"ed5fe8488d16ecc0923ff34afe8aa67177d5e1f3242e1de48ef1643b263ba33b",
|
||||
),
|
||||
amdgpu(
|
||||
"amdgpu/gc_10_3_6_pfp.bin",
|
||||
263424,
|
||||
"042f5d2d223aac6a62b500a47d0d0bf33984200110da0ffca4fe5df9a96571c0",
|
||||
),
|
||||
amdgpu(
|
||||
"amdgpu/gc_10_3_6_me.bin",
|
||||
263424,
|
||||
"776d2299bc4f3abffd4a7999f5a21a4e38aced8b6b4c199a83610dbabf08176d",
|
||||
),
|
||||
amdgpu(
|
||||
"amdgpu/gc_10_3_6_mec.bin",
|
||||
268592,
|
||||
"7003c4a77537e9edaf67064104cd9371fac38a84f71f948349140b28d3c210e8",
|
||||
),
|
||||
// The same bytes as `mec`, under the second name the driver asks for.
|
||||
amdgpu(
|
||||
"amdgpu/gc_10_3_6_mec2.bin",
|
||||
268592,
|
||||
"7003c4a77537e9edaf67064104cd9371fac38a84f71f948349140b28d3c210e8",
|
||||
),
|
||||
amdgpu(
|
||||
"amdgpu/gc_10_3_6_rlc.bin",
|
||||
177104,
|
||||
"acfbac75c0dcfbfe40e222640ef17eb3dc8d206d30bc3863f275f2dd1cb132a5",
|
||||
),
|
||||
amdgpu(
|
||||
"amdgpu/psp_13_0_5_toc.bin",
|
||||
1792,
|
||||
"2dfcc2b4d6b7f072a471da3852164560ae709bb563626997c41ef1ef17588bbe",
|
||||
),
|
||||
amdgpu(
|
||||
"amdgpu/psp_13_0_5_ta.bin",
|
||||
246784,
|
||||
"0b7fc5a0bea6e3559df9791a57ae5a648ec6246679f8f8a6bc27defb2aa7a75e",
|
||||
),
|
||||
amdgpu(
|
||||
"amdgpu/sdma_5_2_6.bin",
|
||||
34048,
|
||||
"3a163db00eb7e4752be8adbd61cf7dd8f08d924e59a6f798ced7dfcd89f340ed",
|
||||
),
|
||||
amdgpu(
|
||||
"amdgpu/dcn_3_1_5_dmcub.bin",
|
||||
239648,
|
||||
"035015964e5a33514201b50f43cc0643550cbee811be20da9f5e31ef6f405d76",
|
||||
),
|
||||
amdgpu(
|
||||
"amdgpu/vcn_3_1_2.bin",
|
||||
575056,
|
||||
"31176d1a359aad08d462895eb02184b5d36c8d7570afc380ec889a9c7ffe8cb4",
|
||||
),
|
||||
// Navi 48: GC 12.0.1, PSP and SMU 14.0.3, SDMA 7.0.1 and VCN 5.0.0, the
|
||||
// same bytes as at linux-firmware 20261019. MES runs one image for both its pipes
|
||||
// (`amdgpu_uni_mes`, on by default) and the PSP loads the rest, so GC's
|
||||
// table of contents for RLC's backdoor load is not asked for.
|
||||
amdgpu(
|
||||
"amdgpu/gc_12_0_1_imu.bin",
|
||||
132352,
|
||||
"b3b301fb636efc77b63ce4d2ced0f90c851d03c19681852faa45598e6f5773fd",
|
||||
),
|
||||
amdgpu(
|
||||
"amdgpu/gc_12_0_1_me.bin",
|
||||
267600,
|
||||
"fd5eb0f205a3bb7ec41f42e83a54bdc69151706b02bbee073fa775b8270e4bec",
|
||||
),
|
||||
amdgpu(
|
||||
"amdgpu/gc_12_0_1_mec.bin",
|
||||
259584,
|
||||
"83fe5e7bffe639ec9771219cde5c9809689168f769b147c86dfd5a1ca991c1a2",
|
||||
),
|
||||
amdgpu(
|
||||
"amdgpu/gc_12_0_1_pfp.bin",
|
||||
159616,
|
||||
"490bcd26a62e389b3f58acf5c087d324d2324b3188797ff6a36b7a6cdf1ca9ff",
|
||||
),
|
||||
amdgpu(
|
||||
"amdgpu/gc_12_0_1_rlc.bin",
|
||||
150848,
|
||||
"6ba4459532246a5c415d3cb33c9b1248294e48f67b827e2accb292a8d1a5c0ec",
|
||||
),
|
||||
amdgpu(
|
||||
"amdgpu/gc_12_0_1_uni_mes.bin",
|
||||
299408,
|
||||
"309d60ad4a0210f8a68e27cae88beddb22b5ae900d70848b1e8ca0eac9d1decd",
|
||||
),
|
||||
amdgpu(
|
||||
"amdgpu/psp_14_0_3_sos.bin",
|
||||
435632,
|
||||
"28469a0857c813c54a0492423cdf0b0caf757428400036377e19c47e5af62478",
|
||||
),
|
||||
amdgpu(
|
||||
"amdgpu/psp_14_0_3_ta.bin",
|
||||
291372,
|
||||
"fff8b0b56f21bf1d34c8d1fcf6cc903c2dbb5ef88eb06157c9f08baf95124883",
|
||||
),
|
||||
amdgpu(
|
||||
"amdgpu/sdma_7_0_1.bin",
|
||||
47104,
|
||||
"73c29e1c1714ebc95d2221ba56e187910902891593010653bf9518937e414a59",
|
||||
),
|
||||
amdgpu(
|
||||
"amdgpu/smu_14_0_3.bin",
|
||||
333236,
|
||||
"7624724231b0986b59f59705e7c854c482193f6b3b591ebdda58cb62af81c010",
|
||||
),
|
||||
amdgpu(
|
||||
"amdgpu/vcn_5_0_0.bin",
|
||||
440400,
|
||||
"9a0ab35bf157c835cbbc4a207ba819ea0111e2a65fe7f8c20910ffff3122f903",
|
||||
),
|
||||
// DCN 4.0.1's DMCUB, which the display core asks for (`amdgpu_dm.c`).
|
||||
amdgpu(
|
||||
"amdgpu/dcn_4_0_1_dmcub.bin",
|
||||
368288,
|
||||
"74b567655ac89bfe03389b660e973dc3c067aebd464c6389a071662cfbe6237f",
|
||||
),
|
||||
// Navi 21 (Sienna Cichlid): amdgpu names these files after the chip,
|
||||
// not its IP versions. MEC2 is byte for byte MEC.
|
||||
amdgpu(
|
||||
"amdgpu/sienna_cichlid_ce.bin",
|
||||
263296,
|
||||
"156769265ed26c8cb14902a13e14871732245daeffb793bdf394c1bd3de76f00",
|
||||
),
|
||||
amdgpu(
|
||||
"amdgpu/sienna_cichlid_me.bin",
|
||||
263424,
|
||||
"fbdf0e27e1c232e5b0a69f52efd5692a1803ec2a0d77201ea678dc8bc6407116",
|
||||
),
|
||||
amdgpu(
|
||||
"amdgpu/sienna_cichlid_mec.bin",
|
||||
268160,
|
||||
"ce7442ce45828e5726bb7b05d1fba7f228dd184f5c0a9daf6647a025540d7d39",
|
||||
),
|
||||
amdgpu(
|
||||
"amdgpu/sienna_cichlid_mec2.bin",
|
||||
268160,
|
||||
"ce7442ce45828e5726bb7b05d1fba7f228dd184f5c0a9daf6647a025540d7d39",
|
||||
),
|
||||
amdgpu(
|
||||
"amdgpu/sienna_cichlid_pfp.bin",
|
||||
263424,
|
||||
"fa904ab1609ab090d90edc0d11132fc9821a05800466b04a193c62d5a5c2d5ae",
|
||||
),
|
||||
amdgpu(
|
||||
"amdgpu/sienna_cichlid_rlc.bin",
|
||||
132960,
|
||||
"19d19bce396b6dc725acb87cdf419e6151a1b2961ff43d6e026e17ecf20c83d0",
|
||||
),
|
||||
amdgpu(
|
||||
"amdgpu/sienna_cichlid_sdma.bin",
|
||||
34048,
|
||||
"1aad9d95e1205d4a0c8da01670aa9fc6f77010ac04a321d8c644f581ada6c7ce",
|
||||
),
|
||||
amdgpu(
|
||||
"amdgpu/sienna_cichlid_smc.bin",
|
||||
247396,
|
||||
"0eb99764288f764fd853d6973693ffa52419cc7ba62074aee85df4a3e8d0286d",
|
||||
),
|
||||
amdgpu(
|
||||
"amdgpu/sienna_cichlid_sos.bin",
|
||||
227456,
|
||||
"67706b9e1545bf68850bf9cea97660af5972574ecb0ca30041174efbb59fac37",
|
||||
),
|
||||
amdgpu(
|
||||
"amdgpu/sienna_cichlid_ta.bin",
|
||||
386816,
|
||||
"dc28d6a9abc3e3a1e9e8c4f787fc179a3e02bd1d5d6a72f178f88b1ad5e61569",
|
||||
),
|
||||
amdgpu(
|
||||
"amdgpu/sienna_cichlid_vcn.bin",
|
||||
582800,
|
||||
"2f3cbd54cc9fad35665c06079f61e175dae3dca34d971bfeb73e4ab3efd7bf65",
|
||||
),
|
||||
// DCN 3.0's DMCUB, which the display core asks for (`amdgpu_dm.c`).
|
||||
amdgpu(
|
||||
"amdgpu/sienna_cichlid_dmcub.bin",
|
||||
114164,
|
||||
"286458c7911172734dd514631dcfba9690c2242f24f9be72afd6b56c0341974a",
|
||||
),
|
||||
];
|
||||
|
||||
/// A GPU family's name, PCI device IDs and files.
|
||||
type AmdgpuFamily = (&'static str, &'static [u16], &'static [&'static str]);
|
||||
|
||||
/// The AMD GPUs that have pinned files. amdgpu names its files after the
|
||||
/// versions of the IP blocks the device's own discovery table reports, which
|
||||
/// only the device can say; the pairing of a PCI device ID with them here is
|
||||
/// what the driver's version tables give these GPUs (for Raphael: graphics
|
||||
/// core 10.3.6, security processor 13.0.5, DMA engine 5.2.6, display 3.1.5,
|
||||
/// video 3.1.2). The driver asks for the video decoder's file in the same
|
||||
/// start as the rest and fails without it, so it is required too.
|
||||
const AMDGPU_FAMILIES: &[AmdgpuFamily] = &[
|
||||
(
|
||||
"Ryzen 7000 or 9000 desktop graphics (Raphael, Granite Ridge)",
|
||||
&[0x164e, 0x13c0],
|
||||
&[
|
||||
"amdgpu/gc_10_3_6_ce.bin",
|
||||
"amdgpu/gc_10_3_6_pfp.bin",
|
||||
"amdgpu/gc_10_3_6_me.bin",
|
||||
"amdgpu/gc_10_3_6_mec.bin",
|
||||
"amdgpu/gc_10_3_6_mec2.bin",
|
||||
"amdgpu/gc_10_3_6_rlc.bin",
|
||||
"amdgpu/psp_13_0_5_toc.bin",
|
||||
"amdgpu/psp_13_0_5_ta.bin",
|
||||
"amdgpu/sdma_5_2_6.bin",
|
||||
"amdgpu/dcn_3_1_5_dmcub.bin",
|
||||
"amdgpu/vcn_3_1_2.bin",
|
||||
],
|
||||
),
|
||||
(
|
||||
"Radeon RX 9070 or 9070 XT (Navi 48)",
|
||||
// 1002:7550, the board checked on hardware. 1002:7551 rev C8 boards
|
||||
// would also need the kicker images.
|
||||
&[0x7550],
|
||||
&[
|
||||
"amdgpu/gc_12_0_1_imu.bin",
|
||||
"amdgpu/gc_12_0_1_me.bin",
|
||||
"amdgpu/gc_12_0_1_mec.bin",
|
||||
"amdgpu/gc_12_0_1_pfp.bin",
|
||||
"amdgpu/gc_12_0_1_rlc.bin",
|
||||
"amdgpu/gc_12_0_1_uni_mes.bin",
|
||||
"amdgpu/psp_14_0_3_sos.bin",
|
||||
"amdgpu/psp_14_0_3_ta.bin",
|
||||
"amdgpu/sdma_7_0_1.bin",
|
||||
"amdgpu/smu_14_0_3.bin",
|
||||
"amdgpu/vcn_5_0_0.bin",
|
||||
"amdgpu/dcn_4_0_1_dmcub.bin",
|
||||
],
|
||||
),
|
||||
(
|
||||
"Radeon RX 6800, 6800 XT, 6900 XT or 6950 XT (Navi 21)",
|
||||
// amdgpu's ID table lists these under CHIP_SIENNA_CICHLID; 1002:73bf is
|
||||
// the RX 6800 XT checked on hardware.
|
||||
&[
|
||||
0x73a0, 0x73a1, 0x73a2, 0x73a3, 0x73a4, 0x73a5, 0x73a6, 0x73a7, 0x73a8, 0x73a9, 0x73aa,
|
||||
0x73ab, 0x73ac, 0x73ad, 0x73ae, 0x73af, 0x73bf,
|
||||
],
|
||||
&[
|
||||
"amdgpu/sienna_cichlid_ce.bin",
|
||||
"amdgpu/sienna_cichlid_me.bin",
|
||||
"amdgpu/sienna_cichlid_mec.bin",
|
||||
"amdgpu/sienna_cichlid_mec2.bin",
|
||||
"amdgpu/sienna_cichlid_pfp.bin",
|
||||
"amdgpu/sienna_cichlid_rlc.bin",
|
||||
"amdgpu/sienna_cichlid_sdma.bin",
|
||||
"amdgpu/sienna_cichlid_smc.bin",
|
||||
"amdgpu/sienna_cichlid_sos.bin",
|
||||
"amdgpu/sienna_cichlid_ta.bin",
|
||||
"amdgpu/sienna_cichlid_vcn.bin",
|
||||
"amdgpu/sienna_cichlid_dmcub.bin",
|
||||
],
|
||||
),
|
||||
];
|
||||
|
||||
/// The binding amdgpu's files take: Linux's names, as for nouveau's.
|
||||
const AMDGPU_TARGET: Target<'static> = Target {
|
||||
driver: "amdgpu",
|
||||
hardware: "amd",
|
||||
revision: "linux-firmware",
|
||||
board: None,
|
||||
};
|
||||
|
||||
/// amdgpu's request for a file, by the name the driver gives it.
|
||||
fn select_amdgpu(request: &Request) -> Option<&'static Recipe> {
|
||||
if request.target.hardware != AMDGPU_TARGET.hardware
|
||||
|| request.target.revision != AMDGPU_TARGET.revision
|
||||
{
|
||||
return None;
|
||||
}
|
||||
AMDGPU
|
||||
.iter()
|
||||
.find(|recipe| recipe.image.member == request.name)
|
||||
}
|
||||
|
||||
/// The family of an AMD GPU with PCI device ID `device`, as people know it,
|
||||
/// when its files are pinned.
|
||||
pub fn amd_gpu_family(device: u16) -> Option<&'static str> {
|
||||
AMDGPU_FAMILIES
|
||||
.iter()
|
||||
.find(|(_, devices, _)| devices.contains(&device))
|
||||
.map(|(name, ..)| *name)
|
||||
}
|
||||
|
||||
/// Requires the files amdgpu asks for on the AMD GPU with PCI device ID
|
||||
/// `device`.
|
||||
pub fn require_amdgpu(inventory: &mut Inventory, device: u16) -> Result<(), Error> {
|
||||
let (_, _, files) = AMDGPU_FAMILIES
|
||||
.iter()
|
||||
.find(|(_, devices, _)| devices.contains(&device))
|
||||
.ok_or_else(|| {
|
||||
Error(format!(
|
||||
"{device:04x} is no GPU amdgpu has pinned files for"
|
||||
))
|
||||
})?;
|
||||
for name in *files {
|
||||
inventory.observe(Requirement {
|
||||
name,
|
||||
target: AMDGPU_TARGET,
|
||||
minimum_bytes: 1,
|
||||
})?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The Intel GPU files and their notices: linux-firmware 20261019, whose
|
||||
/// GuC releases are at or above what the pinned xe asks of each platform.
|
||||
pub const XE_REVISION: &str = "a2dcb924f0897368b0b4f305cbf9808cdda90ce0";
|
||||
@@ -2377,7 +2043,7 @@ pub fn recipe(request: &Request) -> Option<&'static Recipe> {
|
||||
"realtek-wifi" => select_realtek_wifi(request),
|
||||
"nouveau" => select_gsp(request),
|
||||
"xe" => select_xe(request),
|
||||
"amdgpu" => select_amdgpu(request),
|
||||
"amdgpu" => amdgpu::select(request),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -2638,108 +2304,6 @@ mod tests {
|
||||
assert!(REALTEK_USB_LICENSE.verify(b"changed license").is_err());
|
||||
}
|
||||
|
||||
fn amdgpu_member(name: &str, hardware: &str) -> Option<&'static Recipe> {
|
||||
let request = serde_json::json!({"schema":1,"complete":true,"requirements":[{
|
||||
"name":name,"target":{"driver":"amdgpu","hardware":hardware,
|
||||
"revision":"linux-firmware","board":null},"minimum_bytes":1}]});
|
||||
let inventory = Inventory::parse(&serde_json::to_vec(&request).unwrap()).unwrap();
|
||||
Plan::select(&inventory)
|
||||
.ok()
|
||||
.map(|plan| plan.selections[0].recipe)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_amd_gpu_requires_the_files_amdgpu_names_for_its_ip_blocks() {
|
||||
// Raphael and Granite Ridge integrated graphics load the same files.
|
||||
for device in [0x164e, 0x13c0] {
|
||||
let mut inventory = Inventory::default();
|
||||
require_amdgpu(&mut inventory, device).unwrap();
|
||||
let names = inventory
|
||||
.requests()
|
||||
.iter()
|
||||
.map(|request| request.name.clone())
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(names.len(), 11);
|
||||
assert_eq!(names[0], "amdgpu/gc_10_3_6_ce.bin");
|
||||
assert!(names.contains(&"amdgpu/psp_13_0_5_toc.bin".into()));
|
||||
assert!(names.contains(&"amdgpu/dcn_3_1_5_dmcub.bin".into()));
|
||||
assert!(names.contains(&"amdgpu/vcn_3_1_2.bin".into()));
|
||||
assert!(amd_gpu_family(device).unwrap().contains("Granite Ridge"));
|
||||
}
|
||||
// A discrete GPU (Navi 10) has no pinned files yet.
|
||||
assert_eq!(amd_gpu_family(0x731f), None);
|
||||
assert!(require_amdgpu(&mut Inventory::default(), 0x731f).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn navi48_requires_every_file_amdgpu_asks_for_and_nothing_else() {
|
||||
assert_eq!(
|
||||
amd_gpu_family(0x7550),
|
||||
Some("Radeon RX 9070 or 9070 XT (Navi 48)")
|
||||
);
|
||||
assert_eq!(amd_gpu_family(0x7590), None);
|
||||
let mut inventory = Inventory::default();
|
||||
require_amdgpu(&mut inventory, 0x7550).unwrap();
|
||||
let plan = Plan::select(&inventory).unwrap();
|
||||
assert_eq!(plan.selections().len(), 12);
|
||||
for selection in plan.selections() {
|
||||
assert_eq!(selection.request.name, selection.recipe.image.member);
|
||||
assert!(
|
||||
selection.request.name.contains("_12_0_1")
|
||||
|| selection.request.name.contains("_14_0_3")
|
||||
|| selection.request.name.contains("_7_0_1")
|
||||
|| selection.request.name.contains("_5_0_0")
|
||||
|| selection.request.name.contains("_4_0_1")
|
||||
);
|
||||
assert_eq!(selection.request.target.driver, "amdgpu");
|
||||
assert!(selection.recipe.image.url().contains(GSP_REVISION));
|
||||
assert_eq!(selection.recipe.license.member, "LICENSES/LICENSE.amdgpu");
|
||||
}
|
||||
// One shared notice beside the twelve images.
|
||||
assert_eq!(plan.artifacts().len(), 13);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn amdgpu_files_are_pinned_once_under_the_amdgpu_notice() {
|
||||
let mut devices = Vec::new();
|
||||
for (family, ids, files) in AMDGPU_FAMILIES {
|
||||
for device in *ids {
|
||||
assert!(!devices.contains(device), "{family} {device:04x}");
|
||||
devices.push(*device);
|
||||
}
|
||||
for file in *files {
|
||||
assert!(amdgpu_member(file, "amd").is_some(), "{family} {file}");
|
||||
}
|
||||
}
|
||||
for (index, recipe) in AMDGPU.iter().enumerate() {
|
||||
let member = recipe.image.member;
|
||||
assert!(member.starts_with("amdgpu/"), "{member}");
|
||||
assert!(
|
||||
AMDGPU[..index]
|
||||
.iter()
|
||||
.all(|other| other.image.member != member),
|
||||
"{member}"
|
||||
);
|
||||
assert!(
|
||||
AMDGPU_FAMILIES
|
||||
.iter()
|
||||
.any(|(_, _, files)| files.contains(&member)),
|
||||
"{member} has no family"
|
||||
);
|
||||
assert_eq!(recipe.license.member, "LICENSES/LICENSE.amdgpu");
|
||||
assert_eq!(recipe.image.revision, GSP_REVISION);
|
||||
assert_eq!(recipe.image.sha256.len(), 64);
|
||||
}
|
||||
assert_eq!(
|
||||
amdgpu_member("amdgpu/gc_10_3_6_ce.bin", "nvidia").map(|_| ()),
|
||||
None
|
||||
);
|
||||
assert_eq!(
|
||||
amdgpu_member("amdgpu/gc_11_0_0_pfp.bin", "amd").map(|_| ()),
|
||||
None
|
||||
);
|
||||
}
|
||||
|
||||
fn xe_files(device: u16) -> Vec<alloc::string::String> {
|
||||
let mut inventory = Inventory::default();
|
||||
require_xe(&mut inventory, device).unwrap();
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,454 @@
|
||||
use super::*;
|
||||
use crate::host_firmware::{MAX_IMAGES, MAX_TOTAL_BYTES, recipes::Plan};
|
||||
use alloc::{string::String, vec::Vec};
|
||||
use std::{
|
||||
collections::{BTreeMap, BTreeSet},
|
||||
fs,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
fn names(gpu: AmdGpu) -> Vec<&'static str> {
|
||||
gpu.files().map(|recipe| recipe.image.member).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn files_are_pinned_once_in_name_order_under_the_amdgpu_notice() {
|
||||
assert!(
|
||||
AMDGPU
|
||||
.windows(2)
|
||||
.all(|pair| pair[0].image.member < pair[1].image.member)
|
||||
);
|
||||
for recipe in AMDGPU {
|
||||
let member = recipe.image.member;
|
||||
assert!(
|
||||
member.starts_with("amdgpu/") && member.ends_with(".bin"),
|
||||
"{member}"
|
||||
);
|
||||
assert_eq!(recipe.license.member, "LICENSES/LICENSE.amdgpu");
|
||||
assert_eq!(recipe.image.revision, GSP_REVISION);
|
||||
assert_eq!(recipe.image.source, LINUX_FIRMWARE);
|
||||
assert!(
|
||||
recipe.image.sha256.len() == 64
|
||||
&& recipe.image.sha256.bytes().all(|b| b.is_ascii_hexdigit()),
|
||||
"{member}"
|
||||
);
|
||||
assert!(!UNPUBLISHED.contains(&member), "{member}");
|
||||
}
|
||||
assert!(UNPUBLISHED.windows(2).all(|pair| pair[0] < pair[1]));
|
||||
// A request is answered by its exact name and amdgpu's target only.
|
||||
let request = |name: &str, hardware: &str| {
|
||||
let json = serde_json::json!({"schema":1,"complete":true,"requirements":[{
|
||||
"name":name,"target":{"driver":"amdgpu","hardware":hardware,
|
||||
"revision":"linux-firmware","board":null},"minimum_bytes":1}]});
|
||||
let inventory = Inventory::parse(&serde_json::to_vec(&json).unwrap()).unwrap();
|
||||
Plan::select(&inventory)
|
||||
.ok()
|
||||
.map(|plan| plan.selections()[0].recipe.image.length)
|
||||
};
|
||||
assert_eq!(request("amdgpu/gc_10_3_6_ce.bin", "amd"), Some(263296));
|
||||
assert_eq!(
|
||||
request("amdgpu/polaris10_mc.bin", "amd").map(|_| ()),
|
||||
Some(())
|
||||
);
|
||||
assert_eq!(request("amdgpu/gc_10_3_6_ce.bin", "nvidia"), None);
|
||||
assert_eq!(request("amdgpu/gc_11_5_4_pfp.bin", "amd"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_file_is_one_some_device_may_load() {
|
||||
let gpus = DEVICES
|
||||
.iter()
|
||||
.map(|(device, _)| AmdGpu::of(*device))
|
||||
.chain([AmdGpu::Discovered])
|
||||
.collect::<Vec<_>>();
|
||||
for recipe in AMDGPU {
|
||||
let member = recipe.image.member;
|
||||
assert!(
|
||||
gpus.iter().any(|gpu| gpu.may_load(member)),
|
||||
"{member} is no device's"
|
||||
);
|
||||
}
|
||||
// Each of a family's names matches one of its files, pinned or not
|
||||
// published (Cyan Skillfish's first revision has only an unpublished
|
||||
// `gpu_info`).
|
||||
for (chip, stems) in CHIPS {
|
||||
for stem in *stems {
|
||||
assert!(
|
||||
AMDGPU
|
||||
.iter()
|
||||
.map(|recipe| recipe.image.member)
|
||||
.chain(UNPUBLISHED.iter().copied())
|
||||
.any(|member| named(&member[7..], stem)),
|
||||
"{chip} {stem}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tables_are_sorted_and_every_family_has_its_names() {
|
||||
assert!(DEVICES.windows(2).all(|pair| pair[0].0 < pair[1].0));
|
||||
assert!(LEFT_TO_RADEON.windows(2).all(|pair| pair[0] < pair[1]));
|
||||
for (device, chip) in DEVICES.iter().chain(QUIRKS) {
|
||||
assert!(
|
||||
CHIPS.iter().any(|(known, _)| known == chip),
|
||||
"{device:04x} {chip}"
|
||||
);
|
||||
assert!(
|
||||
LEFT_TO_RADEON.binary_search(device).is_err(),
|
||||
"{device:04x}"
|
||||
);
|
||||
}
|
||||
for (device, _) in QUIRKS {
|
||||
assert!(DEVICES.iter().any(|(id, _)| id == device), "{device:04x}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_device_gets_the_files_amdgpu_may_ask_it_for() {
|
||||
// The 9800X3D's and the 7000 series' graphics, matched by class: their
|
||||
// IP blocks' files (graphics 10.3.6, PSP 13.0.5, SDMA 5.2.6, DCN 3.1.5,
|
||||
// VCN 3.1.2) are among every versioned file, beside Van Gogh's, which
|
||||
// only discovery reaches; no family's own files are.
|
||||
for device in [0x13c0, 0x164e] {
|
||||
let gpu = AmdGpu::of(device);
|
||||
assert_eq!(gpu, AmdGpu::Discovered);
|
||||
assert_eq!(gpu.family(), None);
|
||||
let files = names(gpu);
|
||||
for member in [
|
||||
"amdgpu/gc_10_3_6_ce.bin",
|
||||
"amdgpu/gc_10_3_6_pfp.bin",
|
||||
"amdgpu/gc_10_3_6_me.bin",
|
||||
"amdgpu/gc_10_3_6_mec.bin",
|
||||
"amdgpu/gc_10_3_6_mec2.bin",
|
||||
"amdgpu/gc_10_3_6_rlc.bin",
|
||||
"amdgpu/psp_13_0_5_toc.bin",
|
||||
"amdgpu/psp_13_0_5_ta.bin",
|
||||
"amdgpu/sdma_5_2_6.bin",
|
||||
"amdgpu/dcn_3_1_5_dmcub.bin",
|
||||
"amdgpu/vcn_3_1_2.bin",
|
||||
"amdgpu/dcn_3_5_dmcub.bin",
|
||||
"amdgpu/umsch_mm_4_0_0.bin",
|
||||
"amdgpu/vangogh_pfp.bin",
|
||||
] {
|
||||
assert!(files.contains(&member), "{member}");
|
||||
}
|
||||
assert!(
|
||||
!files
|
||||
.iter()
|
||||
.any(|member| member.starts_with("amdgpu/polaris"))
|
||||
);
|
||||
assert!(!files.contains(&"amdgpu/vce_1_0_0.bin"));
|
||||
assert!(!files.contains(&"amdgpu/banks_k_2_smc.bin"));
|
||||
}
|
||||
// Polaris 10 by ID; the ID quirks may make Polaris 11 a Polaris 10.
|
||||
let polaris = names(AmdGpu::of(0x67df));
|
||||
assert!(!polaris.is_empty() && polaris.iter().all(|m| m.starts_with("amdgpu/polaris10_")));
|
||||
assert!(polaris.contains(&"amdgpu/polaris10_k_mc.bin"));
|
||||
let quirked = names(AmdGpu::of(0x67ff));
|
||||
assert!(quirked.contains(&"amdgpu/polaris11_mc.bin"));
|
||||
assert!(quirked.contains(&"amdgpu/polaris10_mc.bin"));
|
||||
// Tahiti: its files, the 0x58 memory's and the video encoder's.
|
||||
let tahiti = names(AmdGpu::of(0x6798));
|
||||
for member in [
|
||||
"amdgpu/tahiti_mc.bin",
|
||||
"amdgpu/si58_mc.bin",
|
||||
"amdgpu/vce_1_0_0.bin",
|
||||
] {
|
||||
assert!(tahiti.contains(&member), "{member}");
|
||||
}
|
||||
assert!(!tahiti.contains(&"amdgpu/banks_k_2_smc.bin"));
|
||||
assert!(names(AmdGpu::of(0x6660)).contains(&"amdgpu/banks_k_2_smc.bin"));
|
||||
// Raven by ID loads Raven 2's and Picasso's by revision, not Renoir's.
|
||||
let raven = names(AmdGpu::of(0x15dd));
|
||||
for member in [
|
||||
"amdgpu/raven_pfp.bin",
|
||||
"amdgpu/raven2_pfp.bin",
|
||||
"amdgpu/picasso_pfp.bin",
|
||||
] {
|
||||
assert!(raven.contains(&member), "{member}");
|
||||
}
|
||||
assert!(!raven.iter().any(|m| m.starts_with("amdgpu/renoir")));
|
||||
// Navi 21 (Sienna Cichlid) by ID.
|
||||
let navi21 = names(AmdGpu::of(0x73bf));
|
||||
assert!(navi21.contains(&"amdgpu/sienna_cichlid_smc.bin"));
|
||||
assert!(
|
||||
navi21
|
||||
.iter()
|
||||
.all(|m| m.starts_with("amdgpu/sienna_cichlid_"))
|
||||
);
|
||||
// A device amdgpu leaves to radeon loads none of its files.
|
||||
let radeon = AmdGpu::of(LEFT_TO_RADEON[0]);
|
||||
assert_eq!(radeon, AmdGpu::LeftToRadeon);
|
||||
assert_eq!(radeon.files().count(), 0);
|
||||
assert!(require_amdgpu(&mut Inventory::default(), LEFT_TO_RADEON[0]).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_largest_set_fits_one_boots_firmware() {
|
||||
let mut largest = (0, 0);
|
||||
for gpu in DEVICES
|
||||
.iter()
|
||||
.map(|(device, _)| AmdGpu::of(*device))
|
||||
.chain([AmdGpu::Discovered])
|
||||
{
|
||||
let mut inventory = Inventory::default();
|
||||
let device = match gpu {
|
||||
AmdGpu::Named(..) => {
|
||||
DEVICES
|
||||
.iter()
|
||||
.find(|(device, _)| AmdGpu::of(*device) == gpu)
|
||||
.unwrap()
|
||||
.0
|
||||
}
|
||||
_ => 0x13c0,
|
||||
};
|
||||
require_amdgpu(&mut inventory, device).unwrap();
|
||||
let plan = Plan::select(&inventory).unwrap();
|
||||
let bytes: usize = plan
|
||||
.selections()
|
||||
.iter()
|
||||
.map(|s| s.recipe.image.length)
|
||||
.sum();
|
||||
largest = largest.max((plan.selections().len(), bytes));
|
||||
}
|
||||
// The discovered set: about 220 files, 49 MiB, which leaves room for a
|
||||
// second GPU's and the network's files in one boot's budget.
|
||||
assert!(largest.0 <= MAX_IMAGES / 2, "{largest:?}");
|
||||
assert!(largest.1 <= MAX_TOTAL_BYTES / 4, "{largest:?}");
|
||||
}
|
||||
|
||||
// The rest compares the tables with the driver's sources, when the
|
||||
// checkout holds them (`cargo xtask gpu fetch`).
|
||||
|
||||
fn amd() -> Option<PathBuf> {
|
||||
let root =
|
||||
Path::new(env!("CARGO_MANIFEST_DIR")).join("../../third_party/linux/drivers/gpu/drm/amd");
|
||||
if root.join("amdgpu/amdgpu_drv.c").is_file() {
|
||||
Some(root)
|
||||
} else {
|
||||
std::eprintln!(
|
||||
"{} is not checked out: amdgpu's tables not compared",
|
||||
root.display()
|
||||
);
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn between<'a>(text: &'a str, start: &str, end: &str) -> &'a str {
|
||||
text.split_once(start)
|
||||
.and_then(|(_, rest)| rest.split_once(end))
|
||||
.unwrap_or_else(|| panic!("no {start:?} closed by {end:?}"))
|
||||
.0
|
||||
}
|
||||
|
||||
fn hex(word: &str) -> u16 {
|
||||
u16::from_str_radix(word.trim().trim_start_matches("0x"), 16).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_device_tables_are_amdgpus() {
|
||||
let Some(amd) = amd() else { return };
|
||||
let driver = fs::read_to_string(amd.join("amdgpu/amdgpu_drv.c")).unwrap();
|
||||
let mut listed = BTreeMap::new();
|
||||
for line in between(&driver, "struct pci_device_id pciidlist[] = {", "{0, 0, 0}").lines() {
|
||||
let line = line.trim();
|
||||
let Some(rest) = line.strip_prefix("{0x1002, ") else {
|
||||
continue;
|
||||
};
|
||||
let device = hex(rest.split(',').next().unwrap());
|
||||
let chip = rest.split("CHIP_").nth(1).unwrap();
|
||||
let chip = chip
|
||||
.split(|c: char| !(c.is_ascii_alphanumeric() || c == '_'))
|
||||
.next()
|
||||
.unwrap();
|
||||
assert!(
|
||||
listed.insert(device, String::from(chip)).is_none(),
|
||||
"{device:04x}"
|
||||
);
|
||||
}
|
||||
let ours: BTreeMap<u16, String> = DEVICES
|
||||
.iter()
|
||||
.map(|(device, chip)| (*device, String::from(*chip)))
|
||||
.collect();
|
||||
assert_eq!(ours, listed, "amdgpu's pciidlist changed");
|
||||
let radeon: BTreeSet<u16> = between(&driver, "amdgpu_unsupported_pciidlist[] = {", "};")
|
||||
.split(|c: char| c == ',' || c.is_whitespace())
|
||||
.filter(|word| word.starts_with("0x"))
|
||||
.map(hex)
|
||||
.collect();
|
||||
assert_eq!(
|
||||
LEFT_TO_RADEON.iter().copied().collect::<BTreeSet<_>>(),
|
||||
radeon
|
||||
);
|
||||
let quirks: BTreeSet<(u16, String)> = between(&driver, "asic_type_quirks[] = {", "};")
|
||||
.lines()
|
||||
.filter_map(|line| line.trim().strip_prefix('{'))
|
||||
.map(|line| {
|
||||
let fields: Vec<&str> = line.split(',').map(str::trim).collect();
|
||||
(
|
||||
hex(fields[0]),
|
||||
String::from(fields[2].trim_start_matches("CHIP_").trim_end_matches('}')),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
let ours: BTreeSet<(u16, String)> = QUIRKS
|
||||
.iter()
|
||||
.map(|(device, chip)| (*device, String::from(*chip)))
|
||||
.collect();
|
||||
assert_eq!(ours, quirks, "amdgpu's revision quirks changed");
|
||||
// Every family of `enum amd_asic_type` but the discovery marker, in order.
|
||||
let types = fs::read_to_string(amd.join("../../../../include/drm/amd_asic_type.h")).unwrap();
|
||||
let families: Vec<String> = between(&types, "enum amd_asic_type {", "};")
|
||||
.lines()
|
||||
.filter_map(|line| line.trim().strip_prefix("CHIP_"))
|
||||
.map(|rest| String::from(rest.split([' ', ',', '\t']).next().unwrap()))
|
||||
.filter(|name| name != "IP_DISCOVERY" && name != "LAST")
|
||||
.collect();
|
||||
let ours: Vec<String> = CHIPS.iter().map(|(chip, _)| String::from(*chip)).collect();
|
||||
assert_eq!(ours, families, "amd_asic_type changed");
|
||||
}
|
||||
|
||||
/// Sources of amdgpu that declare files but that Stela's Kconfig profile
|
||||
/// does not build, with the symbol that would build them.
|
||||
const NOT_BUILT: [(&str, &str); 1] = [("amdgpu/isp_v4_1_1.c", "CONFIG_DRM_AMD_ISP")];
|
||||
|
||||
/// Every file with `extension` under `directory`.
|
||||
fn sources_of(directory: &Path, extension: &str) -> Vec<PathBuf> {
|
||||
let mut found = Vec::new();
|
||||
let mut pending = alloc::vec![directory.to_path_buf()];
|
||||
while let Some(directory) = pending.pop() {
|
||||
for entry in fs::read_dir(directory).unwrap() {
|
||||
let path = entry.unwrap().path();
|
||||
if path.is_dir() {
|
||||
pending.push(path);
|
||||
} else if path.extension().is_some_and(|known| known == extension) {
|
||||
found.push(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
found
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_file_amdgpus_built_units_declare_is_pinned_or_unpublished() {
|
||||
let Some(amd) = amd() else { return };
|
||||
let autoconf = fs::read_to_string(
|
||||
Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("../stela-linux/src/compat/generated/autoconf.h"),
|
||||
)
|
||||
.unwrap();
|
||||
for (_, symbol) in NOT_BUILT {
|
||||
assert!(
|
||||
!autoconf.contains(&format!("#define {symbol} ")),
|
||||
"{symbol} is built now"
|
||||
);
|
||||
}
|
||||
let files = sources_of(&amd, "c");
|
||||
// A source's own definitions first (amdgpu_uvd.c and amdgpu_vce.c both
|
||||
// define FIRMWARE_BONAIRE), then those of the headers.
|
||||
let mut shared = BTreeMap::new();
|
||||
let mut declared = Vec::new();
|
||||
for path in &files {
|
||||
let text = fs::read_to_string(path).unwrap();
|
||||
let mut defines = BTreeMap::new();
|
||||
for line in text.lines() {
|
||||
let mut words = line.split_whitespace();
|
||||
if words.next() == Some("#define")
|
||||
&& let (Some(name), Some(value)) = (words.next(), words.next())
|
||||
&& value.starts_with('"')
|
||||
{
|
||||
defines.insert(String::from(name), String::from(value.trim_matches('"')));
|
||||
}
|
||||
}
|
||||
let relative = path
|
||||
.strip_prefix(&amd)
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.replace('\\', "/");
|
||||
if NOT_BUILT.iter().any(|(source, _)| *source == relative) {
|
||||
continue;
|
||||
}
|
||||
for argument in text.split("MODULE_FIRMWARE(").skip(1) {
|
||||
let argument = String::from(argument.split(')').next().unwrap().trim());
|
||||
let local = defines.get(&argument).cloned();
|
||||
declared.push((argument, local));
|
||||
}
|
||||
shared.extend(defines);
|
||||
}
|
||||
let mut headers = Vec::new();
|
||||
for path in sources_of(&amd, "h") {
|
||||
let text = fs::read_to_string(path).unwrap();
|
||||
headers.push(text);
|
||||
}
|
||||
let mut names = BTreeSet::new();
|
||||
for (argument, local) in declared {
|
||||
let name = match (argument.strip_prefix('"'), local) {
|
||||
(Some(literal), _) => String::from(literal.trim_end_matches('"')),
|
||||
(None, Some(local)) => local,
|
||||
(None, None) => shared
|
||||
.get(&argument)
|
||||
.cloned()
|
||||
.or_else(|| {
|
||||
headers.iter().find_map(|text| {
|
||||
text.lines().find_map(|line| {
|
||||
let mut words = line.split_whitespace();
|
||||
(words.next() == Some("#define") && words.next() == Some(&argument))
|
||||
.then(|| words.next())
|
||||
.flatten()
|
||||
.map(|value| String::from(value.trim_matches('"')))
|
||||
})
|
||||
})
|
||||
})
|
||||
.unwrap_or_else(|| panic!("{argument} is defined nowhere")),
|
||||
};
|
||||
names.insert(name);
|
||||
}
|
||||
let ours: BTreeSet<String> = AMDGPU
|
||||
.iter()
|
||||
.map(|recipe| String::from(recipe.image.member))
|
||||
.chain(UNPUBLISHED.iter().map(|name| String::from(*name)))
|
||||
.collect();
|
||||
let missing: Vec<_> = names.difference(&ours).collect();
|
||||
let extra: Vec<_> = ours.difference(&names).collect();
|
||||
assert!(
|
||||
missing.is_empty() && extra.is_empty(),
|
||||
"amdgpu declares {missing:?} that have no recipe, and no longer {extra:?}"
|
||||
);
|
||||
// Every declared file is one some device of the table may load.
|
||||
for name in &names {
|
||||
let loaded = DEVICES
|
||||
.iter()
|
||||
.map(|(device, _)| AmdGpu::of(*device))
|
||||
.chain([AmdGpu::Discovered])
|
||||
.any(|gpu| gpu.may_load(name));
|
||||
assert!(
|
||||
loaded || name.ends_with("/ip_discovery.bin"),
|
||||
"{name} is no device's"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_legacy_name_is_a_familys() {
|
||||
let Some(amd) = amd() else { return };
|
||||
let ucode = fs::read_to_string(amd.join("amdgpu/amdgpu_ucode.c")).unwrap();
|
||||
let naming = between(
|
||||
&ucode,
|
||||
"static const char *amdgpu_ucode_legacy_naming(",
|
||||
"\n}\n",
|
||||
);
|
||||
for literal in naming.split("return \"").skip(1) {
|
||||
let name = literal.split('"').next().unwrap();
|
||||
let covered = CHIPS.iter().any(|(_, stems)| {
|
||||
stems.iter().any(|stem| {
|
||||
name == *stem || name.strip_prefix(stem).is_some_and(|r| r.starts_with('_'))
|
||||
})
|
||||
});
|
||||
assert!(
|
||||
covered,
|
||||
"amdgpu_ucode_legacy_naming's {name:?} is no family's"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -150,7 +150,7 @@ impl Inventory {
|
||||
|
||||
pub fn parse(bytes: &[u8]) -> Result<Self, Error> {
|
||||
if bytes.len() > MAX_MANIFEST_BYTES {
|
||||
return Err(fail("host firmware requirement inventory exceeds 128 KiB"));
|
||||
return Err(fail("host firmware requirement inventory exceeds 1 MiB"));
|
||||
}
|
||||
let inventory: Self = serde_json::from_slice(bytes)
|
||||
.map_err(|e| Error(alloc::format!("host firmware requirements: {e}")))?;
|
||||
|
||||
Reference in new issue
Block a user