From e1512e9ad06e1a13f1c43591a1900421d1d1e7e2 Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Sat, 14 Nov 2026 15:48:03 -0800 Subject: [PATCH] drm/asahi: g18: Make the GPU driver load again when G18 is built (one __param section, not two) Since #1939 turned the G18 backend on in the shared defaults (CONFIG_DRM_ASAHI_G18=y), aurora.ko no longer loads, so no Apple GPU probes, on any generation: sysfs: cannot create duplicate filename '/module/aurora/sections/__param' ... mod_sysfs_setup+0x408/0x6d4 ... load_module+0x1bd4/0x2200 The module has two sections named __param. The 22 diagnostic parameters of g18/compat declare their kernel_param entries by hand with a plain used attribute, which is #[used(linker)] on ELF: their section gets SHF_GNU_RETAIN, so the module link keeps it apart from the module's other __param input sections, whose entries (kernel::module!'s, g18_param!'s) are #[used(compiler)]. The import of the backend brought these entries; with G18 off they are not built and the module has one __param section, so the mistake stayed hidden until #1939 exposed it by turning G18 on. Declare every hand-written __param entry of the backend through one macro, g18_kernel_param!, which emits it the way rust/macros/module.rs does: #[used(compiler)], and a raw address of __this_module instead of a reference to the mutable extern static. g18_param!, the application compute knobs, the two render policy parameters and the 22 compat parameters now go through it; their names, permissions, operations and arguments are unchanged. Built with G18, aurora.ko has one __param section again, and the 23 "creating a shared reference to mutable static" warnings of these entries are gone. Only code built with CONFIG_DRM_ASAHI_G18 changes. Without it none of this is built; with it every board gets a GPU driver that loads, and the G18 boards (T8152) keep the same parameters. Fixes: b2e300ad24ad ("drm/asahi: g18: import the G18G (T8152) backend") Signed-off-by: Jeff Queisser --- drivers/gpu/drm/asahi/g18/compat/dep_stats.rs | 22 +-- .../gpu/drm/asahi/g18/compat/dvfs_parity.rs | 22 +-- drivers/gpu/drm/asahi/g18/compat/e2e.rs | 22 +-- drivers/gpu/drm/asahi/g18/compat/gem_stats.rs | 22 +-- drivers/gpu/drm/asahi/g18/compat/host_path.rs | 102 ++++------- drivers/gpu/drm/asahi/g18/compat/mem_path.rs | 22 +-- .../gpu/drm/asahi/g18/compat/queue_slots.rs | 22 +-- .../asahi/g18/compat/recovery_isolation.rs | 22 +-- .../gpu/drm/asahi/g18/compat/recovery_path.rs | 22 +-- .../gpu/drm/asahi/g18/compat/stackwatch.rs | 22 +-- .../gpu/drm/asahi/g18/compat/timing_buffer.rs | 162 ++++++------------ .../asahi/g18/initdata/application_compute.rs | 26 +-- drivers/gpu/drm/asahi/g18/params.rs | 69 +++++--- .../gpu/drm/asahi/g18/uapi/render_policy.rs | 47 ++--- 14 files changed, 232 insertions(+), 372 deletions(-) diff --git a/drivers/gpu/drm/asahi/g18/compat/dep_stats.rs b/drivers/gpu/drm/asahi/g18/compat/dep_stats.rs index 9eef0d51ccdc7..11300f19aa8c0 100644 --- a/drivers/gpu/drm/asahi/g18/compat/dep_stats.rs +++ b/drivers/gpu/drm/asahi/g18/compat/dep_stats.rs @@ -11,7 +11,7 @@ //! #46,#1), which the resolver used to refuse as unmodeled bits. use core::fmt::Write; use core::sync::atomic::{AtomicI64, AtomicU64, Ordering}; -use kernel::{bindings, module_param::KernelParam}; +use kernel::bindings; use crate::g18::fw::submission::SubmissionError; @@ -89,16 +89,10 @@ unsafe extern "C" fn stats_set(_: *const core::ffi::c_char, _: *const bindings:: static STATS_OPS: bindings::kernel_param_ops = bindings::kernel_param_ops { flags: 0, set: Some(stats_set), get: Some(stats_get), free: None, }; -#[link_section = "__param"] -#[used] -static STATS_PARAM: KernelParam = KernelParam::new(bindings::kernel_param { - name: kernel::str::as_char_ptr_in_const_context(if cfg!(MODULE) { - c"g17p_render_dep_stats" - } else { c"aurora.g17p_render_dep_stats" }), - #[cfg(MODULE)] - mod_: unsafe { core::ptr::from_ref(&bindings::__this_module).cast_mut() }, - #[cfg(not(MODULE))] - mod_: core::ptr::null_mut(), - ops: core::ptr::from_ref(&STATS_OPS), perm: 0o400, level: -1, flags: 0, - __bindgen_anon_1: bindings::kernel_param__bindgen_ty_1 { arg: core::ptr::null_mut() }, -}); +crate::g18::params::g18_kernel_param!( + STATS_PARAM, + "g17p_render_dep_stats", + ops: core::ptr::from_ref(&STATS_OPS), + perm: 0o400, + arg: core::ptr::null_mut(), +); diff --git a/drivers/gpu/drm/asahi/g18/compat/dvfs_parity.rs b/drivers/gpu/drm/asahi/g18/compat/dvfs_parity.rs index 3ec61a902813d..55542cf1e8941 100644 --- a/drivers/gpu/drm/asahi/g18/compat/dvfs_parity.rs +++ b/drivers/gpu/drm/asahi/g18/compat/dvfs_parity.rs @@ -10,7 +10,7 @@ //! A change takes effect at the next submission or completion service. use core::fmt::{self, Write}; use core::sync::atomic::{AtomicU32, AtomicU64, Ordering}; -use kernel::{bindings, module_param::KernelParam}; +use kernel::bindings; use crate::g18::compat::g17p::{self as policy, Config}; @@ -110,16 +110,10 @@ unsafe extern "C" fn parity_get(buf: *mut core::ffi::c_char, static PARITY_OPS: bindings::kernel_param_ops = bindings::kernel_param_ops { flags: 0, set: Some(parity_set), get: Some(parity_get), free: None, }; -#[link_section = "__param"] -#[used] -static PARITY_PARAM: KernelParam = KernelParam::new(bindings::kernel_param { - name: kernel::str::as_char_ptr_in_const_context(if cfg!(MODULE) { - c"g17p_dvfs_parity" - } else { c"aurora.g17p_dvfs_parity" }), - #[cfg(MODULE)] - mod_: unsafe { core::ptr::from_ref(&bindings::__this_module).cast_mut() }, - #[cfg(not(MODULE))] - mod_: core::ptr::null_mut(), - ops: core::ptr::from_ref(&PARITY_OPS), perm: 0o600, level: -1, flags: 0, - __bindgen_anon_1: bindings::kernel_param__bindgen_ty_1 { arg: core::ptr::null_mut() }, -}); +crate::g18::params::g18_kernel_param!( + PARITY_PARAM, + "g17p_dvfs_parity", + ops: core::ptr::from_ref(&PARITY_OPS), + perm: 0o600, + arg: core::ptr::null_mut(), +); diff --git a/drivers/gpu/drm/asahi/g18/compat/e2e.rs b/drivers/gpu/drm/asahi/g18/compat/e2e.rs index 173d2571ee38d..d189df3eca289 100644 --- a/drivers/gpu/drm/asahi/g18/compat/e2e.rs +++ b/drivers/gpu/drm/asahi/g18/compat/e2e.rs @@ -25,7 +25,7 @@ //! Reading returns up to 24 records from the cursor and advances it. use core::fmt::{self, Write}; use core::sync::atomic::{AtomicPtr, AtomicU32, AtomicU64, AtomicUsize, Ordering}; -use kernel::{bindings, module_param::KernelParam}; +use kernel::bindings; pub(crate) const OPT_BASE: u32 = 1 << 0; pub(crate) const OPT_MAILBOX: u32 = 1 << 1; @@ -357,16 +357,10 @@ unsafe extern "C" fn e2e_get(buf: *mut core::ffi::c_char, _: *const bindings::ke static E2E_OPS: bindings::kernel_param_ops = bindings::kernel_param_ops { flags: 0, set: Some(e2e_set), get: Some(e2e_get), free: None, }; -#[link_section = "__param"] -#[used] -static E2E_PARAM: KernelParam = KernelParam::new(bindings::kernel_param { - name: kernel::str::as_char_ptr_in_const_context(if cfg!(MODULE) { - c"g17p_e2e" - } else { c"aurora.g17p_e2e" }), - #[cfg(MODULE)] - mod_: unsafe { core::ptr::from_ref(&bindings::__this_module).cast_mut() }, - #[cfg(not(MODULE))] - mod_: core::ptr::null_mut(), - ops: core::ptr::from_ref(&E2E_OPS), perm: 0o600, level: -1, flags: 0, - __bindgen_anon_1: bindings::kernel_param__bindgen_ty_1 { arg: core::ptr::null_mut() }, -}); +crate::g18::params::g18_kernel_param!( + E2E_PARAM, + "g17p_e2e", + ops: core::ptr::from_ref(&E2E_OPS), + perm: 0o600, + arg: core::ptr::null_mut(), +); diff --git a/drivers/gpu/drm/asahi/g18/compat/gem_stats.rs b/drivers/gpu/drm/asahi/g18/compat/gem_stats.rs index 8f81b2d02a575..95bef4e04c19c 100644 --- a/drivers/gpu/drm/asahi/g18/compat/gem_stats.rs +++ b/drivers/gpu/drm/asahi/g18/compat/gem_stats.rs @@ -10,7 +10,7 @@ //! `*_created` / `*_freed` totals show allocation churn. use core::fmt::Write; use core::sync::atomic::{AtomicU64, Ordering}; -use kernel::{bindings, module_param::KernelParam}; +use kernel::bindings; static USER_OBJECTS: AtomicU64 = AtomicU64::new(0); static USER_BYTES: AtomicU64 = AtomicU64::new(0); @@ -76,16 +76,10 @@ unsafe extern "C" fn stats_set(_: *const core::ffi::c_char, _: *const bindings:: static STATS_OPS: bindings::kernel_param_ops = bindings::kernel_param_ops { flags: 0, set: Some(stats_set), get: Some(stats_get), free: None, }; -#[link_section = "__param"] -#[used] -static STATS_PARAM: KernelParam = KernelParam::new(bindings::kernel_param { - name: kernel::str::as_char_ptr_in_const_context(if cfg!(MODULE) { - c"gem_stats" - } else { c"aurora.gem_stats" }), - #[cfg(MODULE)] - mod_: unsafe { core::ptr::from_ref(&bindings::__this_module).cast_mut() }, - #[cfg(not(MODULE))] - mod_: core::ptr::null_mut(), - ops: core::ptr::from_ref(&STATS_OPS), perm: 0o400, level: -1, flags: 0, - __bindgen_anon_1: bindings::kernel_param__bindgen_ty_1 { arg: core::ptr::null_mut() }, -}); +crate::g18::params::g18_kernel_param!( + STATS_PARAM, + "gem_stats", + ops: core::ptr::from_ref(&STATS_OPS), + perm: 0o400, + arg: core::ptr::null_mut(), +); diff --git a/drivers/gpu/drm/asahi/g18/compat/host_path.rs b/drivers/gpu/drm/asahi/g18/compat/host_path.rs index 2403560feae6c..6a747109bec77 100644 --- a/drivers/gpu/drm/asahi/g18/compat/host_path.rs +++ b/drivers/gpu/drm/asahi/g18/compat/host_path.rs @@ -114,7 +114,7 @@ //! each policy at `g17p_feed_perf_pct` percent of that policy's maximum. use core::fmt::{self, Write}; use core::sync::atomic::{AtomicBool, AtomicPtr, AtomicU32, AtomicU64, Ordering}; -use kernel::{bindings, module_param::KernelParam}; +use kernel::bindings; pub(crate) const EARLY_PUBLISH: u32 = 1 << 0; pub(crate) const FEED_PERF: u32 = 1 << 1; @@ -713,68 +713,38 @@ static PCT_P_OPS: bindings::kernel_param_ops = bindings::kernel_param_ops { static PCT_E_OPS: bindings::kernel_param_ops = bindings::kernel_param_ops { flags: 0, set: Some(pct_e_set), get: Some(pct_e_get), free: None, }; -#[link_section = "__param"] -#[used] -static MASK_PARAM: KernelParam = KernelParam::new(bindings::kernel_param { - name: kernel::str::as_char_ptr_in_const_context(if cfg!(MODULE) { - c"g17p_host_path" - } else { c"aurora.g17p_host_path" }), - #[cfg(MODULE)] - mod_: unsafe { core::ptr::from_ref(&bindings::__this_module).cast_mut() }, - #[cfg(not(MODULE))] - mod_: core::ptr::null_mut(), - ops: core::ptr::from_ref(&MASK_OPS), perm: 0o600, level: -1, flags: 0, - __bindgen_anon_1: bindings::kernel_param__bindgen_ty_1 { arg: core::ptr::null_mut() }, -}); -#[link_section = "__param"] -#[used] -static PCT_PARAM: KernelParam = KernelParam::new(bindings::kernel_param { - name: kernel::str::as_char_ptr_in_const_context(if cfg!(MODULE) { - c"g17p_feed_perf_pct" - } else { c"aurora.g17p_feed_perf_pct" }), - #[cfg(MODULE)] - mod_: unsafe { core::ptr::from_ref(&bindings::__this_module).cast_mut() }, - #[cfg(not(MODULE))] - mod_: core::ptr::null_mut(), - ops: core::ptr::from_ref(&PCT_OPS), perm: 0o600, level: -1, flags: 0, - __bindgen_anon_1: bindings::kernel_param__bindgen_ty_1 { arg: core::ptr::null_mut() }, -}); -#[link_section = "__param"] -#[used] -static DEPTH_PARAM: KernelParam = KernelParam::new(bindings::kernel_param { - name: kernel::str::as_char_ptr_in_const_context(if cfg!(MODULE) { - c"g17p_early_depth" - } else { c"aurora.g17p_early_depth" }), - #[cfg(MODULE)] - mod_: unsafe { core::ptr::from_ref(&bindings::__this_module).cast_mut() }, - #[cfg(not(MODULE))] - mod_: core::ptr::null_mut(), - ops: core::ptr::from_ref(&DEPTH_OPS), perm: 0o600, level: -1, flags: 0, - __bindgen_anon_1: bindings::kernel_param__bindgen_ty_1 { arg: core::ptr::null_mut() }, -}); -#[link_section = "__param"] -#[used] -static PCT_P_PARAM: KernelParam = KernelParam::new(bindings::kernel_param { - name: kernel::str::as_char_ptr_in_const_context(if cfg!(MODULE) { - c"g17p_feed_perf_pct_p" - } else { c"aurora.g17p_feed_perf_pct_p" }), - #[cfg(MODULE)] - mod_: unsafe { core::ptr::from_ref(&bindings::__this_module).cast_mut() }, - #[cfg(not(MODULE))] - mod_: core::ptr::null_mut(), - ops: core::ptr::from_ref(&PCT_P_OPS), perm: 0o600, level: -1, flags: 0, - __bindgen_anon_1: bindings::kernel_param__bindgen_ty_1 { arg: core::ptr::null_mut() }, -}); -#[link_section = "__param"] -#[used] -static PCT_E_PARAM: KernelParam = KernelParam::new(bindings::kernel_param { - name: kernel::str::as_char_ptr_in_const_context(if cfg!(MODULE) { - c"g17p_feed_perf_pct_e" - } else { c"aurora.g17p_feed_perf_pct_e" }), - #[cfg(MODULE)] - mod_: unsafe { core::ptr::from_ref(&bindings::__this_module).cast_mut() }, - #[cfg(not(MODULE))] - mod_: core::ptr::null_mut(), - ops: core::ptr::from_ref(&PCT_E_OPS), perm: 0o600, level: -1, flags: 0, - __bindgen_anon_1: bindings::kernel_param__bindgen_ty_1 { arg: core::ptr::null_mut() }, -}); +crate::g18::params::g18_kernel_param!( + MASK_PARAM, + "g17p_host_path", + ops: core::ptr::from_ref(&MASK_OPS), + perm: 0o600, + arg: core::ptr::null_mut(), +); +crate::g18::params::g18_kernel_param!( + PCT_PARAM, + "g17p_feed_perf_pct", + ops: core::ptr::from_ref(&PCT_OPS), + perm: 0o600, + arg: core::ptr::null_mut(), +); +crate::g18::params::g18_kernel_param!( + DEPTH_PARAM, + "g17p_early_depth", + ops: core::ptr::from_ref(&DEPTH_OPS), + perm: 0o600, + arg: core::ptr::null_mut(), +); +crate::g18::params::g18_kernel_param!( + PCT_P_PARAM, + "g17p_feed_perf_pct_p", + ops: core::ptr::from_ref(&PCT_P_OPS), + perm: 0o600, + arg: core::ptr::null_mut(), +); +crate::g18::params::g18_kernel_param!( + PCT_E_PARAM, + "g17p_feed_perf_pct_e", + ops: core::ptr::from_ref(&PCT_E_OPS), + perm: 0o600, + arg: core::ptr::null_mut(), +); diff --git a/drivers/gpu/drm/asahi/g18/compat/mem_path.rs b/drivers/gpu/drm/asahi/g18/compat/mem_path.rs index e658033088d7c..f7fa58411cfe0 100644 --- a/drivers/gpu/drm/asahi/g18/compat/mem_path.rs +++ b/drivers/gpu/drm/asahi/g18/compat/mem_path.rs @@ -35,7 +35,7 @@ //! Boot-only `g17p_gem_huge` (asahi.rs) is reported here too. use core::fmt::{self, Write}; use core::sync::atomic::{AtomicU32, AtomicU64, Ordering}; -use kernel::{bindings, module_param::KernelParam}; +use kernel::bindings; pub(crate) const ASYNC_CLOSED_DRAIN: u32 = 1 << 0; pub(crate) const MEM_STATS: u32 = 1 << 1; @@ -221,16 +221,10 @@ unsafe extern "C" fn mask_get(buf: *mut core::ffi::c_char, _: *const bindings::k static MASK_OPS: bindings::kernel_param_ops = bindings::kernel_param_ops { flags: 0, set: Some(mask_set), get: Some(mask_get), free: None, }; -#[link_section = "__param"] -#[used] -static MASK_PARAM: KernelParam = KernelParam::new(bindings::kernel_param { - name: kernel::str::as_char_ptr_in_const_context(if cfg!(MODULE) { - c"g17p_mem_path" - } else { c"aurora.g17p_mem_path" }), - #[cfg(MODULE)] - mod_: unsafe { core::ptr::from_ref(&bindings::__this_module).cast_mut() }, - #[cfg(not(MODULE))] - mod_: core::ptr::null_mut(), - ops: core::ptr::from_ref(&MASK_OPS), perm: 0o600, level: -1, flags: 0, - __bindgen_anon_1: bindings::kernel_param__bindgen_ty_1 { arg: core::ptr::null_mut() }, -}); +crate::g18::params::g18_kernel_param!( + MASK_PARAM, + "g17p_mem_path", + ops: core::ptr::from_ref(&MASK_OPS), + perm: 0o600, + arg: core::ptr::null_mut(), +); diff --git a/drivers/gpu/drm/asahi/g18/compat/queue_slots.rs b/drivers/gpu/drm/asahi/g18/compat/queue_slots.rs index 0de236b4ab872..ee4f0c6396279 100644 --- a/drivers/gpu/drm/asahi/g18/compat/queue_slots.rs +++ b/drivers/gpu/drm/asahi/g18/compat/queue_slots.rs @@ -16,7 +16,7 @@ //! or submit says which pool ran out. use core::fmt::Write; use core::sync::atomic::{AtomicU32, AtomicU64, Ordering}; -use kernel::{bindings, module_param::KernelParam, prelude::*}; +use kernel::{bindings, prelude::*}; use crate::g18::compat::g17p::{self as g17_channel, QID_COUNT}; @@ -173,16 +173,10 @@ unsafe extern "C" fn slots_set(_: *const core::ffi::c_char, _: *const bindings:: static SLOTS_OPS: bindings::kernel_param_ops = bindings::kernel_param_ops { flags: 0, set: Some(slots_set), get: Some(slots_get), free: None, }; -#[link_section = "__param"] -#[used] -static SLOTS_PARAM: KernelParam = KernelParam::new(bindings::kernel_param { - name: kernel::str::as_char_ptr_in_const_context(if cfg!(MODULE) { - c"g17p_queue_slots" - } else { c"aurora.g17p_queue_slots" }), - #[cfg(MODULE)] - mod_: unsafe { core::ptr::from_ref(&bindings::__this_module).cast_mut() }, - #[cfg(not(MODULE))] - mod_: core::ptr::null_mut(), - ops: core::ptr::from_ref(&SLOTS_OPS), perm: 0o400, level: -1, flags: 0, - __bindgen_anon_1: bindings::kernel_param__bindgen_ty_1 { arg: core::ptr::null_mut() }, -}); +crate::g18::params::g18_kernel_param!( + SLOTS_PARAM, + "g17p_queue_slots", + ops: core::ptr::from_ref(&SLOTS_OPS), + perm: 0o400, + arg: core::ptr::null_mut(), +); diff --git a/drivers/gpu/drm/asahi/g18/compat/recovery_isolation.rs b/drivers/gpu/drm/asahi/g18/compat/recovery_isolation.rs index 22d7995b6a000..eec0738e53f13 100644 --- a/drivers/gpu/drm/asahi/g18/compat/recovery_isolation.rs +++ b/drivers/gpu/drm/asahi/g18/compat/recovery_isolation.rs @@ -165,7 +165,7 @@ use core::fmt::{self, Write}; use core::sync::atomic::{AtomicU32, AtomicU64, Ordering}; #[cfg(not(test))] -use kernel::{bindings, module_param::KernelParam}; +use kernel::bindings; pub(crate) const INNOCENT: u32 = 1 << 0; pub(crate) const ADMISSION_WAIT: u32 = 1 << 1; @@ -629,16 +629,10 @@ static MASK_OPS: bindings::kernel_param_ops = bindings::kernel_param_ops { flags: 0, set: Some(mask_set), get: Some(mask_get), free: None, }; #[cfg(not(test))] -#[link_section = "__param"] -#[used] -static MASK_PARAM: KernelParam = KernelParam::new(bindings::kernel_param { - name: kernel::str::as_char_ptr_in_const_context(if cfg!(MODULE) { - c"g17p_recovery_isolation" - } else { c"aurora.g17p_recovery_isolation" }), - #[cfg(MODULE)] - mod_: unsafe { core::ptr::from_ref(&bindings::__this_module).cast_mut() }, - #[cfg(not(MODULE))] - mod_: core::ptr::null_mut(), - ops: core::ptr::from_ref(&MASK_OPS), perm: 0o600, level: -1, flags: 0, - __bindgen_anon_1: bindings::kernel_param__bindgen_ty_1 { arg: core::ptr::null_mut() }, -}); +crate::g18::params::g18_kernel_param!( + MASK_PARAM, + "g17p_recovery_isolation", + ops: core::ptr::from_ref(&MASK_OPS), + perm: 0o600, + arg: core::ptr::null_mut(), +); diff --git a/drivers/gpu/drm/asahi/g18/compat/recovery_path.rs b/drivers/gpu/drm/asahi/g18/compat/recovery_path.rs index f35cf67d91715..56c8e7c0f062d 100644 --- a/drivers/gpu/drm/asahi/g18/compat/recovery_path.rs +++ b/drivers/gpu/drm/asahi/g18/compat/recovery_path.rs @@ -58,7 +58,7 @@ //! logged (rate-limited) and counted, independent of the mask. use core::fmt::{self, Write}; use core::sync::atomic::{AtomicU32, AtomicU64, Ordering}; -use kernel::{bindings, module_param::KernelParam}; +use kernel::bindings; pub(crate) const RECLAIM_DRAINED: u32 = 1 << 0; pub(crate) const CONTROL_TRACE: u32 = 1 << 1; @@ -384,16 +384,10 @@ unsafe extern "C" fn mask_get(buf: *mut core::ffi::c_char, _: *const bindings::k static MASK_OPS: bindings::kernel_param_ops = bindings::kernel_param_ops { flags: 0, set: Some(mask_set), get: Some(mask_get), free: None, }; -#[link_section = "__param"] -#[used] -static MASK_PARAM: KernelParam = KernelParam::new(bindings::kernel_param { - name: kernel::str::as_char_ptr_in_const_context(if cfg!(MODULE) { - c"g17p_recovery_path" - } else { c"aurora.g17p_recovery_path" }), - #[cfg(MODULE)] - mod_: unsafe { core::ptr::from_ref(&bindings::__this_module).cast_mut() }, - #[cfg(not(MODULE))] - mod_: core::ptr::null_mut(), - ops: core::ptr::from_ref(&MASK_OPS), perm: 0o600, level: -1, flags: 0, - __bindgen_anon_1: bindings::kernel_param__bindgen_ty_1 { arg: core::ptr::null_mut() }, -}); +crate::g18::params::g18_kernel_param!( + MASK_PARAM, + "g17p_recovery_path", + ops: core::ptr::from_ref(&MASK_OPS), + perm: 0o600, + arg: core::ptr::null_mut(), +); diff --git a/drivers/gpu/drm/asahi/g18/compat/stackwatch.rs b/drivers/gpu/drm/asahi/g18/compat/stackwatch.rs index 2c74f17ef7dda..62ad1da8a86d7 100644 --- a/drivers/gpu/drm/asahi/g18/compat/stackwatch.rs +++ b/drivers/gpu/drm/asahi/g18/compat/stackwatch.rs @@ -12,7 +12,7 @@ //! 16K pages, VMAP_STACK). Never a default. use core::fmt::Write; use core::sync::atomic::{AtomicU32, AtomicU64, AtomicUsize, Ordering}; -use kernel::{bindings, module_param::KernelParam}; +use kernel::bindings; const THREAD_SIZE: usize = 1 << 15; const GUARD: usize = 256; @@ -135,16 +135,10 @@ unsafe extern "C" fn sw_get(buf: *mut core::ffi::c_char, _: *const bindings::ker static SW_OPS: bindings::kernel_param_ops = bindings::kernel_param_ops { flags: 0, set: Some(sw_set), get: Some(sw_get), free: None, }; -#[link_section = "__param"] -#[used] -static SW_PARAM: KernelParam = KernelParam::new(bindings::kernel_param { - name: kernel::str::as_char_ptr_in_const_context(if cfg!(MODULE) { - c"g17p_stack_watch" - } else { c"aurora.g17p_stack_watch" }), - #[cfg(MODULE)] - mod_: unsafe { core::ptr::from_ref(&bindings::__this_module).cast_mut() }, - #[cfg(not(MODULE))] - mod_: core::ptr::null_mut(), - ops: core::ptr::from_ref(&SW_OPS), perm: 0o600, level: -1, flags: 0, - __bindgen_anon_1: bindings::kernel_param__bindgen_ty_1 { arg: core::ptr::null_mut() }, -}); +crate::g18::params::g18_kernel_param!( + SW_PARAM, + "g17p_stack_watch", + ops: core::ptr::from_ref(&SW_OPS), + perm: 0o600, + arg: core::ptr::null_mut(), +); diff --git a/drivers/gpu/drm/asahi/g18/compat/timing_buffer.rs b/drivers/gpu/drm/asahi/g18/compat/timing_buffer.rs index 611465fa139b3..98a6c23df9670 100644 --- a/drivers/gpu/drm/asahi/g18/compat/timing_buffer.rs +++ b/drivers/gpu/drm/asahi/g18/compat/timing_buffer.rs @@ -3,7 +3,7 @@ //! Atomic words avoid unsafe shared payload access; ready publishes each slot. use core::sync::atomic::{AtomicU32, AtomicU64, AtomicUsize, Ordering}; use core::fmt::{self, Write}; -use kernel::{bindings, module_param::KernelParam}; +use kernel::bindings; pub(crate) const WORDS: usize = 24; const CAPACITY: usize = 16384; @@ -174,19 +174,13 @@ unsafe extern "C" fn set(value: *const core::ffi::c_char, _: *const bindings::ke static OPS: bindings::kernel_param_ops = bindings::kernel_param_ops { flags: 0, set: Some(set), get: Some(get), free: None, }; -#[link_section = "__param"] -#[used] -static PARAM: KernelParam = KernelParam::new(bindings::kernel_param { - name: kernel::str::as_char_ptr_in_const_context(if cfg!(MODULE) { - c"g17p_timing_buffer" - } else { c"aurora.g17p_timing_buffer" }), - #[cfg(MODULE)] - mod_: unsafe { core::ptr::from_ref(&bindings::__this_module).cast_mut() }, - #[cfg(not(MODULE))] - mod_: core::ptr::null_mut(), - ops: core::ptr::from_ref(&OPS), perm: 0o600, level: -1, flags: 0, - __bindgen_anon_1: bindings::kernel_param__bindgen_ty_1 { arg: core::ptr::null_mut() }, -}); +crate::g18::params::g18_kernel_param!( + PARAM, + "g17p_timing_buffer", + ops: core::ptr::from_ref(&OPS), + perm: 0o600, + arg: core::ptr::null_mut(), +); // One explicit post-window snapshot. No live ring reads occur in record(). // 0 unused, 1 requested, 2 copying, 3 complete, 4 failed; no reset until unload. @@ -287,19 +281,13 @@ unsafe extern "C" fn completion_get(buf: *mut core::ffi::c_char, static COMPLETION_OPS: bindings::kernel_param_ops = bindings::kernel_param_ops { flags: 0, set: Some(completion_set), get: Some(completion_get), free: None, }; -#[link_section = "__param"] -#[used] -static COMPLETION_PARAM: KernelParam = KernelParam::new(bindings::kernel_param { - name: kernel::str::as_char_ptr_in_const_context(if cfg!(MODULE) { - c"g17p_completion_buffer" - } else { c"aurora.g17p_completion_buffer" }), - #[cfg(MODULE)] - mod_: unsafe { core::ptr::from_ref(&bindings::__this_module).cast_mut() }, - #[cfg(not(MODULE))] - mod_: core::ptr::null_mut(), - ops: core::ptr::from_ref(&COMPLETION_OPS), perm: 0o600, level: -1, flags: 0, - __bindgen_anon_1: bindings::kernel_param__bindgen_ty_1 { arg: core::ptr::null_mut() }, -}); +crate::g18::params::g18_kernel_param!( + COMPLETION_PARAM, + "g17p_completion_buffer", + ops: core::ptr::from_ref(&COMPLETION_OPS), + perm: 0o600, + arg: core::ptr::null_mut(), +); /// Armed-only host observation gate; no additional device reads. Kind7 words: /// slot, front ordinal (MAX if unavailable), reason (1borrowed,2restaged,3UMA, @@ -467,19 +455,13 @@ unsafe extern "C" fn peek_get(buf: *mut core::ffi::c_char, static PEEK_OPS: bindings::kernel_param_ops = bindings::kernel_param_ops { flags: 0, set: Some(peek_set), get: Some(peek_get), free: None, }; -#[link_section = "__param"] -#[used] -static PEEK_PARAM: KernelParam = KernelParam::new(bindings::kernel_param { - name: kernel::str::as_char_ptr_in_const_context(if cfg!(MODULE) { - c"g17p_fw_peek" - } else { c"aurora.g17p_fw_peek" }), - #[cfg(MODULE)] - mod_: unsafe { core::ptr::from_ref(&bindings::__this_module).cast_mut() }, - #[cfg(not(MODULE))] - mod_: core::ptr::null_mut(), - ops: core::ptr::from_ref(&PEEK_OPS), perm: 0o600, level: -1, flags: 0, - __bindgen_anon_1: bindings::kernel_param__bindgen_ty_1 { arg: core::ptr::null_mut() }, -}); +crate::g18::params::g18_kernel_param!( + PEEK_PARAM, + "g17p_fw_peek", + ops: core::ptr::from_ref(&PEEK_OPS), + perm: 0o600, + arg: core::ptr::null_mut(), +); /// Root-only `g17p_grid_peek`: write a byte offset (hex, 8-aligned) into the /// last `DIAG_GRID_SNAPSHOT` copy; reading returns up to 64 qwords from it. static GRID_OFFSET: AtomicUsize = AtomicUsize::new(0); @@ -522,19 +504,13 @@ unsafe extern "C" fn grid_get(buf: *mut core::ffi::c_char, static GRID_OPS: bindings::kernel_param_ops = bindings::kernel_param_ops { flags: 0, set: Some(grid_set), get: Some(grid_get), free: None, }; -#[link_section = "__param"] -#[used] -static GRID_PARAM: KernelParam = KernelParam::new(bindings::kernel_param { - name: kernel::str::as_char_ptr_in_const_context(if cfg!(MODULE) { - c"g17p_grid_peek" - } else { c"aurora.g17p_grid_peek" }), - #[cfg(MODULE)] - mod_: unsafe { core::ptr::from_ref(&bindings::__this_module).cast_mut() }, - #[cfg(not(MODULE))] - mod_: core::ptr::null_mut(), - ops: core::ptr::from_ref(&GRID_OPS), perm: 0o600, level: -1, flags: 0, - __bindgen_anon_1: bindings::kernel_param__bindgen_ty_1 { arg: core::ptr::null_mut() }, -}); +crate::g18::params::g18_kernel_param!( + GRID_PARAM, + "g17p_grid_peek", + ops: core::ptr::from_ref(&GRID_OPS), + perm: 0o600, + arg: core::ptr::null_mut(), +); /// Root-only `g17p_gpc_sample`: writing N (1..=400000) samples the always-on /// GPC performance state (sgx+0xe01000 & 0xf, J700 physical 0x4_80e0_1000) /// N times, sleeping ~20 us between reads; reading prints the histogram of @@ -591,35 +567,23 @@ unsafe extern "C" fn gpc_get(buf: *mut core::ffi::c_char, static GPC_OPS: bindings::kernel_param_ops = bindings::kernel_param_ops { flags: 0, set: Some(gpc_set), get: Some(gpc_get), free: None, }; -#[link_section = "__param"] -#[used] -static GPC_PARAM: KernelParam = KernelParam::new(bindings::kernel_param { - name: kernel::str::as_char_ptr_in_const_context(if cfg!(MODULE) { - c"g17p_gpc_sample" - } else { c"aurora.g17p_gpc_sample" }), - #[cfg(MODULE)] - mod_: unsafe { core::ptr::from_ref(&bindings::__this_module).cast_mut() }, - #[cfg(not(MODULE))] - mod_: core::ptr::null_mut(), - ops: core::ptr::from_ref(&GPC_OPS), perm: 0o600, level: -1, flags: 0, - __bindgen_anon_1: bindings::kernel_param__bindgen_ty_1 { arg: core::ptr::null_mut() }, -}); +crate::g18::params::g18_kernel_param!( + GPC_PARAM, + "g17p_gpc_sample", + ops: core::ptr::from_ref(&GPC_OPS), + perm: 0o600, + arg: core::ptr::null_mut(), +); static DIAG_OPS: bindings::kernel_param_ops = bindings::kernel_param_ops { flags: 0, set: Some(diag_set), get: Some(diag_get), free: None, }; -#[link_section = "__param"] -#[used] -static DIAG_PARAM: KernelParam = KernelParam::new(bindings::kernel_param { - name: kernel::str::as_char_ptr_in_const_context(if cfg!(MODULE) { - c"g17p_diag_knobs" - } else { c"aurora.g17p_diag_knobs" }), - #[cfg(MODULE)] - mod_: unsafe { core::ptr::from_ref(&bindings::__this_module).cast_mut() }, - #[cfg(not(MODULE))] - mod_: core::ptr::null_mut(), - ops: core::ptr::from_ref(&DIAG_OPS), perm: 0o600, level: -1, flags: 0, - __bindgen_anon_1: bindings::kernel_param__bindgen_ty_1 { arg: core::ptr::null_mut() }, -}); +crate::g18::params::g18_kernel_param!( + DIAG_PARAM, + "g17p_diag_knobs", + ops: core::ptr::from_ref(&DIAG_OPS), + perm: 0o600, + arg: core::ptr::null_mut(), +); /// Opt-in `g17p_diag_knobs` bit10: one-shot log of host<->firmware traffic. /// Each entry is [counter | kind << 56, a, b, c]; the log stops at capacity /// until `g17p_msglog` is written "reset". Logging only; changes no behaviour. @@ -726,19 +690,13 @@ unsafe extern "C" fn msglog_get(buf: *mut core::ffi::c_char, static MSGLOG_OPS: bindings::kernel_param_ops = bindings::kernel_param_ops { flags: 0, set: Some(msglog_set), get: Some(msglog_get), free: None, }; -#[link_section = "__param"] -#[used] -static MSGLOG_PARAM: KernelParam = KernelParam::new(bindings::kernel_param { - name: kernel::str::as_char_ptr_in_const_context(if cfg!(MODULE) { - c"g17p_msglog" - } else { c"aurora.g17p_msglog" }), - #[cfg(MODULE)] - mod_: unsafe { core::ptr::from_ref(&bindings::__this_module).cast_mut() }, - #[cfg(not(MODULE))] - mod_: core::ptr::null_mut(), - ops: core::ptr::from_ref(&MSGLOG_OPS), perm: 0o600, level: -1, flags: 0, - __bindgen_anon_1: bindings::kernel_param__bindgen_ty_1 { arg: core::ptr::null_mut() }, -}); +crate::g18::params::g18_kernel_param!( + MSGLOG_PARAM, + "g17p_msglog", + ops: core::ptr::from_ref(&MSGLOG_OPS), + perm: 0o600, + arg: core::ptr::null_mut(), +); /// Opt-in bit14: request a work-ring scan before eligible render preparation. pub(crate) const DIAG_EARLY_RENDER_DOORBELL: u32 = 1 << 14; @@ -914,16 +872,10 @@ unsafe extern "C" fn pstate_get(buf: *mut core::ffi::c_char, static PSTATE_OPS: bindings::kernel_param_ops = bindings::kernel_param_ops { flags: 0, set: Some(pstate_set), get: Some(pstate_get), free: None, }; -#[link_section = "__param"] -#[used] -static PSTATE_PARAM: KernelParam = KernelParam::new(bindings::kernel_param { - name: kernel::str::as_char_ptr_in_const_context(if cfg!(MODULE) { - c"g17p_stats_pstate" - } else { c"aurora.g17p_stats_pstate" }), - #[cfg(MODULE)] - mod_: unsafe { core::ptr::from_ref(&bindings::__this_module).cast_mut() }, - #[cfg(not(MODULE))] - mod_: core::ptr::null_mut(), - ops: core::ptr::from_ref(&PSTATE_OPS), perm: 0o600, level: -1, flags: 0, - __bindgen_anon_1: bindings::kernel_param__bindgen_ty_1 { arg: core::ptr::null_mut() }, -}); +crate::g18::params::g18_kernel_param!( + PSTATE_PARAM, + "g17p_stats_pstate", + ops: core::ptr::from_ref(&PSTATE_OPS), + perm: 0o600, + arg: core::ptr::null_mut(), +); diff --git a/drivers/gpu/drm/asahi/g18/initdata/application_compute.rs b/drivers/gpu/drm/asahi/g18/initdata/application_compute.rs index 7dba393568828..549324f688467 100644 --- a/drivers/gpu/drm/asahi/g18/initdata/application_compute.rs +++ b/drivers/gpu/drm/asahi/g18/initdata/application_compute.rs @@ -14,30 +14,18 @@ use core::sync::atomic::Ordering; macro_rules! app_knob { ($module:ident, $name:literal, $default:expr, $description:literal) => { mod $module { - use kernel::{bindings, module_param::KernelParam}; + use kernel::bindings; pub(super) static VALUE: core::sync::atomic::AtomicU32 = core::sync::atomic::AtomicU32::new($default); - #[link_section = "__param"] - #[used(compiler)] - static PARAM: KernelParam = KernelParam::new(bindings::kernel_param { - name: kernel::str::as_char_ptr_in_const_context(if cfg!(MODULE) { - kernel::c_str!($name) - } else { kernel::c_str!(concat!("aurora.", $name)) }), - // Module lifetime and parameter serialization are managed by the - // kernel, identically to the kernel::module! registration. A raw - // address avoids a reference to the mutable extern static. - #[cfg(MODULE)] - mod_: &raw mut bindings::__this_module, - #[cfg(not(MODULE))] - mod_: core::ptr::null_mut(), + crate::g18::params::g18_kernel_param!( + PARAM, + $name, // SAFETY: exported vmlinux ops; they access `arg` as an unsigned // int under the parameter lock, which AtomicU32 represents exactly. ops: unsafe { core::ptr::from_ref(&bindings::param_ops_uint) }, - perm: 0o644, level: -1, flags: 0, - __bindgen_anon_1: bindings::kernel_param__bindgen_ty_1 { - arg: core::ptr::from_ref(&VALUE).cast_mut().cast(), - }, - }); + perm: 0o644, + arg: core::ptr::from_ref(&VALUE).cast_mut().cast(), + ); const TYPE: &[u8] = concat!("parmtype=", $name, ":uint\0").as_bytes(); #[link_section = ".modinfo"] #[used(compiler)] diff --git a/drivers/gpu/drm/asahi/g18/params.rs b/drivers/gpu/drm/asahi/g18/params.rs index 555c9959ead2f..cacf51eb917d7 100644 --- a/drivers/gpu/drm/asahi/g18/params.rs +++ b/drivers/gpu/drm/asahi/g18/params.rs @@ -23,35 +23,56 @@ const fn modinfo(bytes: &[u8]) -> [u8; N] { out } +/// One `__param` entry of this backend, emitted as `kernel::module!` emits its own: every +/// hand-written parameter of the G18 backend is declared through this macro. +/// +/// The entry must be `#[used(compiler)]`, as in rust/macros/module.rs. A plain `#[used]` is +/// `#[used(linker)]` on ELF targets: its section gets SHF_GNU_RETAIN, the module link keeps it +/// apart from the module's other `__param` input sections, and the module loader then refuses +/// the whole module ("cannot create duplicate filename '/module/aurora/sections/__param'"), so no +/// GPU of any generation probes. +/// +/// `$name` is the parameter's name as a string; built in, it gets the `aurora.` prefix. +macro_rules! g18_kernel_param { + ($static:ident, $name:expr, ops: $ops:expr, perm: $perm:expr, arg: $arg:expr $(,)?) => { + #[link_section = "__param"] + #[used(compiler)] + static $static: kernel::module_param::KernelParam = + kernel::module_param::KernelParam::new(kernel::bindings::kernel_param { + name: kernel::str::as_char_ptr_in_const_context(if cfg!(MODULE) { + kernel::c_str!($name) + } else { + kernel::c_str!(concat!("aurora.", $name)) + }), + // `__this_module` is constructed by the kernel at load time and is not + // freed until the module is unloaded. A raw address avoids a reference to + // the mutable extern static. + #[cfg(MODULE)] + mod_: &raw mut kernel::bindings::__this_module, + #[cfg(not(MODULE))] + mod_: core::ptr::null_mut(), + ops: $ops, + perm: $perm, + level: -1, + flags: 0, + __bindgen_anon_1: kernel::bindings::kernel_param__bindgen_ty_1 { arg: $arg }, + }); + }; +} +pub(crate) use g18_kernel_param; + macro_rules! g18_param { ($name:ident: $ty:ident = $default:expr, $ops:ident, $description:literal) => { pub(crate) static $name: ModuleParamAccess<$ty> = ModuleParamAccess::new($default); const _: () = { - #[link_section = "__param"] - #[used(compiler)] - static PARAM: kernel::module_param::KernelParam = - kernel::module_param::KernelParam::new(kernel::bindings::kernel_param { - name: kernel::str::as_char_ptr_in_const_context(if cfg!(MODULE) { - kernel::c_str!(stringify!($name)) - } else { - kernel::c_str!(concat!("aurora.", stringify!($name))) - }), - // `__this_module` is constructed by the kernel at load time and is not - // freed until the module is unloaded. A raw address avoids a reference to - // the mutable extern static. - #[cfg(MODULE)] - mod_: &raw mut kernel::bindings::__this_module, - #[cfg(not(MODULE))] - mod_: core::ptr::null_mut(), - ops: core::ptr::from_ref(&$ops), - perm: 0, // Will not appear in sysfs - level: -1, - flags: 0, - __bindgen_anon_1: kernel::bindings::kernel_param__bindgen_ty_1 { - arg: $name.as_void_ptr(), - }, - }); + g18_kernel_param!( + PARAM, + stringify!($name), + ops: core::ptr::from_ref(&$ops), + perm: 0, // Will not appear in sysfs + arg: $name.as_void_ptr(), + ); #[cfg(MODULE)] const TYPE: &[u8] = diff --git a/drivers/gpu/drm/asahi/g18/uapi/render_policy.rs b/drivers/gpu/drm/asahi/g18/uapi/render_policy.rs index 84170ed8be79c..c10b4098fca9f 100644 --- a/drivers/gpu/drm/asahi/g18/uapi/render_policy.rs +++ b/drivers/gpu/drm/asahi/g18/uapi/render_policy.rs @@ -64,23 +64,15 @@ pub(crate) fn resource_pairs() -> [[u64; 2]; 2] { // force-kind-1 flag. Invalid selectors fail target_plan before publication. #[cfg(CONFIG_RUST)] mod parameter { - use kernel::{bindings, module_param::{KernelParam, ModuleParamAccess, PARAM_OPS_U32}}; + use kernel::module_param::{ModuleParamAccess, PARAM_OPS_U32}; pub(super) static VALUE: ModuleParamAccess = ModuleParamAccess::new(1); - #[link_section = "__param"] - #[used(compiler)] - static PARAM: KernelParam = KernelParam::new(bindings::kernel_param { - name: kernel::str::as_char_ptr_in_const_context(if cfg!(MODULE) { - c"g18_render_target_kind" - } else { c"aurora.g18_render_target_kind" }), - // SAFETY: module lifetime and parameter serialization are managed by - // the kernel, identically to the kernel::module! registration. - #[cfg(MODULE)] - mod_: unsafe { core::ptr::from_ref(&bindings::__this_module).cast_mut() }, - #[cfg(not(MODULE))] - mod_: core::ptr::null_mut(), - ops: core::ptr::from_ref(&PARAM_OPS_U32), perm: 0, level: -1, flags: 0, - __bindgen_anon_1: bindings::kernel_param__bindgen_ty_1 { arg: VALUE.as_void_ptr() }, - }); + crate::g18::params::g18_kernel_param!( + PARAM, + "g18_render_target_kind", + ops: core::ptr::from_ref(&PARAM_OPS_U32), + perm: 0, + arg: VALUE.as_void_ptr(), + ); #[link_section = ".modinfo"] #[used(compiler)] static TYPE: [u8; b"parmtype=g18_render_target_kind:uint\0".len()] = *b"parmtype=g18_render_target_kind:uint\0"; @@ -101,27 +93,18 @@ pub(crate) static HOST_TARGET_KIND: core::sync::atomic::AtomicU32 = core::sync:: // knobs), read at every 4x render. #[cfg(CONFIG_RUST)] mod msaa4_fragment { - use kernel::{bindings, module_param::KernelParam}; + use kernel::bindings; pub(super) static VALUE: core::sync::atomic::AtomicU32 = core::sync::atomic::AtomicU32::new(0xd_0009); - #[link_section = "__param"] - #[used(compiler)] - static PARAM: KernelParam = KernelParam::new(bindings::kernel_param { - name: kernel::str::as_char_ptr_in_const_context(if cfg!(MODULE) { - c"g18_msaa4_fragment_word" - } else { c"aurora.g18_msaa4_fragment_word" }), - #[cfg(MODULE)] - mod_: &raw mut bindings::__this_module, - #[cfg(not(MODULE))] - mod_: core::ptr::null_mut(), + crate::g18::params::g18_kernel_param!( + PARAM, + "g18_msaa4_fragment_word", // SAFETY: exported vmlinux ops; they access `arg` as an unsigned int // under the parameter lock, which AtomicU32 represents exactly. ops: unsafe { core::ptr::from_ref(&bindings::param_ops_uint) }, - perm: 0o644, level: -1, flags: 0, - __bindgen_anon_1: bindings::kernel_param__bindgen_ty_1 { - arg: core::ptr::from_ref(&VALUE).cast_mut().cast(), - }, - }); + perm: 0o644, + arg: core::ptr::from_ref(&VALUE).cast_mut().cast(), + ); #[link_section = ".modinfo"] #[used(compiler)] static TYPE: [u8; b"parmtype=g18_msaa4_fragment_word:uint\0".len()] =