Skip to content

Conversation

@WhatAmISupposedToPutHere
Copy link
Contributor

Instead of doing gpu initialization partially in m1n1 and partially in kernel, build all the blobs in m1n1 and put them in the device tree to be picked up by the kernel. Most of the code here is copied and pasted kernel code, with some fixups

@WhatAmISupposedToPutHere WhatAmISupposedToPutHere force-pushed the bootloader-cal-blobs branch 3 times, most recently from 339d779 to e90dd1d Compare May 12, 2025 09:08
@svenpeter42
Copy link
Member

svenpeter42 commented May 13, 2025

I vaguely remember that bsd has some issues(?) with building rust code. we should check if this would create additional pain for them and then potentially allow building without rust (which means no gpu support then ofc).

@svenpeter42
Copy link
Member

looks like this also breaks the CI because https://src.fedoraproject.org/rpms/m1n1/raw/main/f/m1n1-rust-deps.patch doesn't apply anymore. no idea where that file comes from though or why we need it.

@davide125 @Conan-Kudo

@davide125
Copy link
Member

It's here: https://src.fedoraproject.org/rpms/m1n1/blob/rawhide/f/m1n1-rust-deps.patch . We need it because in Fedora we build against the system packages, not the vendored ones.

@svenpeter42
Copy link
Member

<kettenis> regarding m1n1 and rust on OpenBSD; yes that is a huge problem since you can't easily build your own standard library for a cross compiler

let's not break m1n1 stage2 builds for all openbsd users. so we either need to convert this all to C (ugh...) or allow builds without rust and gpu support and make sure we don't shot ourselves in the foot with that

Copy link
Member

@svenpeter42 svenpeter42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lina's sign-off is missing, my other comment is optional and can be ignored. I also didn't really review the rust code because it's been copied from the kernel and we know that it works

@WhatAmISupposedToPutHere
Copy link
Contributor Author

Lina's sign-off is missing, my other comment is optional and can be ignored. I also didn't really review the rust code because it's been copied from the kernel and we know that it works

It is not a 1 to 1 copy, but i have a special kernel build that compares the kernel blob with m1n1 one, and those matched on t6000

svenpeter42
svenpeter42 previously approved these changes May 13, 2025
@svenpeter42
Copy link
Member

Let's see if jannau wants to review all this magic since he's more familiar with both rust and the gpu driver but I'm fine with merging it

Copy link
Member

@jannau jannau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First review of the C code

src/kboot_gpu.c Outdated
int32_t rust_gpu_initdata_size(uint32_t compat_maj, uint32_t compat_min, size_t *data_a,
size_t *data_b, size_t *globals);

int32_t rust_fill_gpu_initdata(size_t perf_state_table_count, size_t perf_state_count,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use a struct for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can, i just find structs to be a bit inconvenient to keep in sync with rust/c

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but keeping 22 function arguments in sync is convenient? I find the the function argument variant harder to validate and would assume it's more likely to attract bugs. We could use bindgen.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, they are both terrible tbh. i'll look into bindgen

src/kboot_gpu.c Outdated
size_t n_perf_states_afr, const struct aux_perf_state *pstates_afr,
uint32_t is_j180, uint32_t base_pstate, uint64_t uat_ttb_base,
uint32_t num_cores, uint32_t compat_maj, uint32_t compat_min,
uint32_t gpu_rev_id, void *data_a, void *data_b, void *globals);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd feel more comfortable if we pass the size data_a, data_b and globals as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The caller is supposed to allocate exactly as much as rust_gpu_initdata_size asked for, so not sure what value that adds?

@WhatAmISupposedToPutHere WhatAmISupposedToPutHere force-pushed the bootloader-cal-blobs branch 2 times, most recently from 3d6d5de to b131656 Compare May 15, 2025 22:05
@WhatAmISupposedToPutHere WhatAmISupposedToPutHere force-pushed the bootloader-cal-blobs branch 3 times, most recently from 881a53b to 55c9824 Compare May 31, 2025 15:26
@WhatAmISupposedToPutHere WhatAmISupposedToPutHere force-pushed the bootloader-cal-blobs branch 2 times, most recently from c2ae886 to e0ccac2 Compare June 13, 2025 20:48
@svenpeter42 svenpeter42 dismissed their stale review August 3, 2025 09:04

jannau's going to take care of this one since he actually knows both the gpu driver and rust

jannau added a commit to jannau/m1n1 that referenced this pull request Aug 13, 2025
Booting with Linux 6.17-rc1 device trees fails due to missing
"operating-points-v2" properties. Check for the downstream only
"apple,agx-t*" compatible strings and disable the gpu node if those are
not found.
This serves as temporary fix until
AsahiLinux#466 is merged.

Signed-off-by: Janne Grunau <j@jannau.net>
svenpeter42 pushed a commit that referenced this pull request Aug 14, 2025
Booting with Linux 6.17-rc1 device trees fails due to missing
"operating-points-v2" properties. Check for the downstream only
"apple,agx-t*" compatible strings and disable the gpu node if those are
not found.
This serves as temporary fix until
#466 is merged.

Signed-off-by: Janne Grunau <j@jannau.net>
@WhatAmISupposedToPutHere WhatAmISupposedToPutHere force-pushed the bootloader-cal-blobs branch 2 times, most recently from aeb9983 to 46e70a4 Compare August 22, 2025 19:25
jannau added a commit to jannau/m1n1 that referenced this pull request Sep 21, 2025
Booting with Linux 6.17-rc1 device trees fails due to missing
"operating-points-v2" properties. Check for the downstream only
"apple,agx-t*" compatible strings and disable the gpu node if those are
not found.
This serves as temporary fix until
AsahiLinux#466 is merged.

Signed-off-by: Janne Grunau <j@jannau.net>
Copy link
Member

@jannau jannau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With fixes from https://github.com/jannau/m1n1/commits/bootloader-cal-blobs/ GPU initdata matches on j274, j375c, j375d, j473, j474s, j493 and j180d. I've pushed verification changes to asahi-wip. Missing devices to verify are M1 Pro/Max laptops and M2 Max (laptop and studio).

The branch contains fixes for some of the review comments and depends on #499. Feel free to cherry-pick and squash.

Besides the review comments I'd like to have the code in kboot_gpu.c split into 3 parts:

  • common
  • downstream compatibles
  • upstream compatibles

but that can happen after this PR is merged

@WhatAmISupposedToPutHere
Copy link
Contributor Author

m1 pro is verified on my side

from_path_trace inserts an extra root node, which when
roundripped via C resutls in a None entry, but breaks
using it directly from rust. Replace it with a None

Signed-off-by: Sasha Finkelstein <fnkl.kernel@gmail.com>
Instead of doing gpu initialization partially in m1n1 and partially in
kernel, build all the blobs in m1n1 and put them in the device tree to be
picked up by the kernel. Most of the code here is copied and pasted kernel
code, with some fixups

Signed-off-by: Asahi Lina <lina@asahilina.net>
Co-authored-by: Sasha Finkelstein <fnkl.kernel@gmail.com>
Signed-off-by: Sasha Finkelstein <fnkl.kernel@gmail.com>
Signed-off-by: Sasha Finkelstein <fnkl.kernel@gmail.com>
The reserved-memory nodes have a page size aligned size.

Signed-off-by: Janne Grunau <j@jannau.net>
This mirrors the DT in the downstream AsahiLinux kernel. j274 misses the
"gpu-perf-base-pstate" property in the ADT. j474s uses 1 which is
unusual for non-battery powered devices.
Using the same values as the downstream DT simplifies comparing Linux
and m1n1 initialized GPU initdata.

Signed-off-by: Janne Grunau <j@jannau.net>
Based on the downstream Linux DT. Values are in the ADT so they could be
read from there but that would be a larger refactoring.

Signed-off-by: Janne Grunau <j@jannau.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants