drm/tyr: GPU reset infrastructure
Subsystems (4)
Onur Özkan
reviewerv8 cover drm/tyr: GPU reset infrastructure
Add support for scheduling GPU resets on a dedicated workqueue. Track the reset state to avoid queueing another reset while one is already pending or in progress.
Use an SRCU based gate with mutex-protected reader admission to block hardware accesses while reset work runs and wait for current users before resetting.
Stop new reset requests during teardown and drain any queued or running reset work before releasing the device resources.
This is the initial reset infrastructure only. It is not wired to a reset source yet as those will follow in separate work.
This version is based on drm-rust-next commitcc0e99fad239 ("gpu: nova-core: add support for GPU timer block. (v7)"), with v3 of "workqueue: OwnedQueue and ScopedWork" [1].
Changes since v7:
- Rebase against drm-rust-next and workqueue v3.
- Add a TODO to consider embedding HwGate in platform data.
V7: https://lore.kernel.org/all/[email protected]/
---
Onur Özkan (3):
drm/tyr: clear stale IRQ state before soft reset drm/tyr: add GPU reset infrastructure drm/tyr: put iomem behind the hardware gate
drivers/gpu/drm/tyr/driver.rs | 63 ++++---- drivers/gpu/drm/tyr/fw.rs | 16 +- drivers/gpu/drm/tyr/mmu.rs | 6 +- drivers/gpu/drm/tyr/mmu/address_space.rs | 87 ++++++----- drivers/gpu/drm/tyr/reset.rs | 244 +++++++++++++++++++++++++++++++ drivers/gpu/drm/tyr/reset/hw_gate.rs | 106 ++++++++++++++ drivers/gpu/drm/tyr/tyr.rs | 1 + 7 files changed, 441 insertions(+), 82 deletions(-)
---
base-commit: cc0e99fad2392ac479e2594b88fd947a2f2d9c33
change-id: 20260813-tyr-reset-impl-93e951f996b4
prerequisite-change-id: 20261012-rust-workqueue-658cd0fbe770:v3
prerequisite-patch-id: f5e24f7b3717f2ab0445b5395c7f12b554861d78
prerequisite-patch-id: 0bf6ae4abcef7090d0e48921d6ec627a59dc6a7a
prerequisite-patch-id: e19d2e11fc6c6fc121d65c8502bfa557e1dfc5ec
prerequisite-patch-id: 89eb57a43e71850c447ea7cb7051fb36066ca329
Onur Özkan
reviewerPATCH v8 1/3 drm/tyr: clear stale IRQ state before soft reset
Previous reset may leave the reset completed IRQ set which can make the poll return too early.
Clear the IRQ first so the driver waits for the current reset to complete.
--- drivers/gpu/drm/tyr/driver.rs | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpu/drm/tyr/driver.rs +3 -0
@@ -87,6 +87,9 @@ pub(crate) struct TyrDrmRegistrationData<'drm> { }fn issue_soft_reset (dev: &Device , iomem: &IoMem <'_>) ->Result { +// Clear any stale reset IRQ state before issuing a new soft reset. + iomem.write_reg (GPU_IRQ_CLEAR ::zeroed ().with_reset_completed (true )); + iomem.write_reg (GPU_COMMAND ::reset (ResetMode ::SoftReset )); poll::read_poll_timeout(
Signature · 1 line
2.51.2
[email protected]
AI reviewRe: [PATCH v8 1/3] drm/tyr: clear stale IRQ state before soft reset
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] drm/tyr: missing Fixes: trailer for issue_soft_reset() stale IRQ fix --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] drm/tyr: missing Fixes: trailer for issue_soft_reset() stale IRQ fix
--
commit e053765c9b79d29e4e4daed59084849814476fe4
Author: Onur Özkan <[email protected]>
Quoted 11 lines
drm/tyr: clear stale IRQ state before soft reset
Previous reset may leave the reset completed IRQ set which can make the poll return too early.
Clear the IRQ first so the driver waits for the current reset to complete.
Reviewed-by Daniel Almeida <[email protected]>Reviewed-by Boris Brezillon <[email protected]>Signed-off-by Onur Özkan <[email protected]>
[Severity: Low]
This looks like a bug fix for issue_soft_reset() polling. Should this include a Fixes: tag, such as:
or:
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH v8 1/3] drm/tyr: clear stale IRQ state before soft reset
In reply to Onur ÖzkanQuoted 9 lines · Onur Özkan
Previous reset may leave the reset completed IRQ set which can make the poll return too early.
Clear the IRQ first so the driver waits for the current reset to complete.
Reviewed-by Daniel Almeida <[email protected]>Reviewed-by Boris Brezillon <[email protected]>Signed-off-by Onur Özkan <[email protected]>
Do you want me to merge this now, without waiting for the other patches?
Daniel Almeida
maintainerRe: [PATCH v8 1/3] drm/tyr: clear stale IRQ state before soft reset
Quoted 11 lines · Alice Ryhl
Quoted 6 lines · Onur Özkan
Previous reset may leave the reset completed IRQ set which can make the poll return too early.
Clear the IRQ first so the driver waits for the current reset to complete.
Quoted 7 lines
Quoted 3 lines
Reviewed-by Daniel Almeida <[email protected]>Reviewed-by Boris Brezillon <[email protected]>Signed-off-by Onur Özkan <[email protected]>Do you want me to merge this now, without waiting for the other patches?
Reviewed-by Alice Ryhl <[email protected]>
If Onur is fine with this, I think we should merge what we can.
— Daniel
Onur Özkan
reviewerRe: [PATCH v8 1/3] drm/tyr: clear stale IRQ state before soft reset
Quoted 15 lines · On Wed, 18 Nov 2026 10:07:49 -0300 Daniel Almeida…
Quoted 15 lines · Alice Ryhl
Quoted 9 lines · Onur Özkan
Previous reset may leave the reset completed IRQ set which can make the poll return too early.
Clear the IRQ first so the driver waits for the current reset to complete.
Reviewed-by Daniel Almeida <[email protected]>Reviewed-by Boris Brezillon <[email protected]>Signed-off-by Onur Özkan <[email protected]>
Quoted 5 lines
Quoted 3 lines
Do you want me to merge this now, without waiting for the other patches?
Reviewed-by Alice Ryhl <[email protected]>If Onur is fine with this, I think we should merge what we can.
Sure, I am fine with that.
Thanks
Quoted 2 lines
— Daniel
Re: [PATCH v8 1/3] drm/tyr: clear stale IRQ state before soft reset
In reply to Onur ÖzkanQuoted 9 lines · Onur Özkan
Previous reset may leave the reset completed IRQ set which can make the poll return too early.
Clear the IRQ first so the driver waits for the current reset to complete.
Reviewed-by Daniel Almeida <[email protected]>Reviewed-by Boris Brezillon <[email protected]>Signed-off-by Onur Özkan <[email protected]>
Applied to drm-rust-next. Thanks!
I added this tag when applying:
Alice
Onur Özkan
reviewerPATCH v8 2/3 drm/tyr: add GPU reset infrastructure
In reply to Onur ÖzkanAdd support for scheduling GPU resets on a dedicated workqueue. Track the reset state to avoid queueing another reset while one is already pending or in progress.
Use an SRCU based gate with mutex-protected reader admission to block hardware accesses while reset work runs and wait for current users before resetting.
Stop new reset requests during teardown and drain any queued or running reset work before releasing the device resources.
This is the initial reset infrastructure only. It is not wired to a reset source yet as those will follow in separate work.
--- drivers/gpu/drm/tyr/driver.rs | 43 ++---- drivers/gpu/drm/tyr/reset.rs | 251 +++++++++++++++++++++++++++++++++++ drivers/gpu/drm/tyr/reset/hw_gate.rs | 80 +++++++++++ drivers/gpu/drm/tyr/tyr.rs | 1 + 4 files changed, 346 insertions(+), 29 deletions(-)
drivers/gpu/drm/tyr/driver.rs +14 -29
@@ -8,7 +8,6 @@ device::{ Bound, Core, -Device , DeviceContext, // }, dma::{
@@ -17,13 +16,9 @@ }, drm, drm::ioctl, - io::{ - poll, - Io, // - }, new_mutex, of, - platform, + platform, // prelude::*, regulator, regulator::Regulator,
@@ -32,17 +27,16 @@ Arc, Mutex, // }, - time, // };use crate ::{ file::TyrDrmFileData , fw::Firmware , gem::Bo , - gpu, gpu::GpuInfo , mmu::Mmu , - regs::gpu_control::*,// + regs::gpu_control::*, + reset,// };pub (crate )type IoMem <'a> = kernel::io::mem::IoMem <'a,SZ_2M >;
@@ -70,6 +64,12 @@ pub(crate) struct TyrDrmRegistrationData<'drm> {/// Parent platform device. pub(crate) pdev: &'drm platform::Device<Bound>, +// `ResetHandle::drop()` drains queued/running works and this must happen +// before clocks/regulators are dropped. So keep this field before them to +// ensure the correct drop order. +#[pin] + pub(crate) reset: reset::ResetHandle<'drm>, +/// Firmware sections. pub(crate) fw: Firmware<'drm>,
@@ -86,23 +86,6 @@ pub(crate) struct TyrDrmRegistrationData<'drm> { pub(crate) gpu_info: GpuInfo, } -fn issue_soft_reset (dev: &Device , iomem: &IoMem <'_>) ->Result { -// Clear any stale reset IRQ state before issuing a new soft reset. - iomem.write_reg (GPU_IRQ_CLEAR ::zeroed ().with_reset_completed (true )); - - iomem.write_reg (GPU_COMMAND ::reset (ResetMode ::SoftReset )); - - poll::read_poll_timeout ( - ||Ok (iomem.read (GPU_IRQ_RAWSTAT )), - |status| status.reset_completed (), - time::Delta ::from_millis (1 ), - time::Delta ::from_millis (100 ), - ) - .inspect_err (|_|dev_err! (dev,"GPU reset failed." ))?; - -Ok (()) -} - kernel::of_device_table!(OF_TABLE , <TyrPlatformDriver as platform::Driver >::IdInfo ,
@@ -137,8 +120,7 @@ fn probe<'bound>(let iomem =Arc ::new (request.iomap_sized ::<SZ_2M >()?,GFP_KERNEL )?; -issue_soft_reset (pdev.as_ref (), &iomem)?; - gpu::l2_power_on (pdev.as_ref (), &iomem)?; + reset::run_reset (pdev.as_ref (), &iomem)?;let gpu_info =GpuInfo ::new (&iomem); gpu_info.log (pdev.as_ref ());
@@ -171,8 +153,11 @@ fn probe<'bound>( _reg <- unsafe { drm::Registration::new( pdev.as_ref(), unreg_dev, - pin_init!(TyrDrmRegistrationData { + try_pin_init!(TyrDrmRegistrationData { pdev, + // SAFETY: The registration is owned by platform driver data, + // so reset work is drained before borrowed data expires. + reset <- reset::ResetHandle::new(pdev, iomem.as_arc_borrow())?, fw: firmware, clks <- new_mutex!(Clocks { core: core_clk,
drivers/gpu/drm/tyr/reset.rs new file +251 -0
251 lines not on this page · raw message
drivers/gpu/drm/tyr/reset/hw_gate.rs new file +80 -0
80 lines not on this page · raw message
drivers/gpu/drm/tyr/tyr.rs +1 -0
@@ -14,6 +14,7 @@mod gpu;mod mmu;mod regs; +mod reset;mod slot;mod vm;
Signature · 1 line
2.51.2
[email protected]
AI reviewRe: [PATCH v8 2/3] drm/tyr: add GPU reset infrastructure
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] drm/tyr: prepared clocks leaked on error in TyrPlatformDriver::probe() - [Low] drm/tyr: overly…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] drm/tyr: prepared clocks leaked on error in TyrPlatformDriver::probe()
- [Low] drm/tyr: overly restrictive &'reset self lifetime in ResetHandle::schedule()
--
commit 2f1b0845121531379549eca9ca27fd1ffc58562f
Author: Onur Özkan <[email protected]>
drm/tyr: add GPU reset infrastructure
This commit adds GPU reset infrastructure using a dedicated ordered workqueue and an SRCU-based hardware access gate, and drains pending or running reset work on teardown.
Quoted 4 lines
drivers/gpu/drm/tyr/driver.rs +0
-0
[ ... ]
drivers/gpu/drm/tyr/driver.rs fn probe<'bound>( · line 163
Quoted 13 lines
drivers/gpu/drm/tyr/driver.rs +4
-1@@ -171,8 +153,11 @@ fn probe<'bound>( _reg <- unsafe { drm::Registration::new( pdev.as_ref(), unreg_dev, - pin_init!(TyrDrmRegistrationData { + try_pin_init!(TyrDrmRegistrationData { pdev, + // SAFETY: The registration is owned by platform driver data, + // so reset work is drained before borrowed data expires. + reset <- reset::ResetHandle::new(pdev, iomem.as_arc_borrow())?, fw: firmware, clks <- new_mutex!(Clocks { core: core_clk,
[Severity: Medium]
Does this leak the prepared and enabled clocks if ResetHandle::new() or its PinInit initializer fails?
Drop for Clk and OptionalClk only calls clk_put(), while disable_unprepare() is only called in Clocks::drop():
drivers/gpu/drm/tyr/driver.rs:Clocks::drop() {
fn drop(&mut self) {
self.core.disable_unprepare();
self.stacks.disable_unprepare();
self.coregroup.disable_unprepare();
}
}Because TyrDrmRegistrationData now initializes reset via try_pin_init! before constructing Clocks, a failure in Queue::build() or HwGate::new() (as well as earlier error paths after prepare_enable() in probe()) drops core_clk, stacks_clk, and coregroup_clk without disabling or unpreparing them, leaving the hardware clocks enabled and triggering a warning in clk_put(). Wrapping the clocks in Clocks immediately after prepare_enable() would ensure they are cleaned up on all error paths.
Quoted 5 lines
drivers/gpu/drm/tyr/reset.rs new file +0
-0
[ ... ]
Quoted 5 lines
drivers/gpu/drm/tyr/reset.rs new file +5
-0+pub (crate )struct ResetHandle <'reset> { +#[pin] + controller:ScopedWork <Controller <'reset>>, + wq:OwnedQueue , +}
[ ... ]
Quoted 5 lines
drivers/gpu/drm/tyr/reset.rs new file +5
-0+/// Schedules a GPU reset on the dedicated workqueue. +/// +/// If a reset is already pending or in progress the call is a no-op. +#[expect(dead_code)] +pub (crate )fn schedule (&'reset self) {
drivers/gpu/drm/tyr/reset.rs line 205
Quoted 10 lines
drivers/gpu/drm/tyr/reset.rs new file +10
-0+// TODO: Similar to `panthor_device_schedule_reset()` in Panthor, add a +// power management check once Tyr supports it. + +if self + .controller + .try_transition (ResetState ::Idle ,ResetState ::Pending ) + { +let _ = self.wq.enqueue_scoped (&self.controller); + } + }
[Severity: Low]
Can ResetHandle::schedule() take &self instead of &'reset self?
ScopedWork wraps its payload in Opaque (UnsafeCell), making ResetHandle<'reset> invariant over 'reset, where 'reset is the device binding lifetime in TyrDrmRegistrationData<'drm>. Requiring &'reset self prevents callers holding a normal short-lived borrow of TyrDrmRegistrationData or ResetHandle from calling schedule(), and neither try_transition() nor enqueue_scoped() needs the reference to live for 'reset.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Onur Özkan
reviewerRe: [PATCH v8 2/3] drm/tyr: add GPU reset infrastructure
Quoted 53 lines · On Fri, 13 Nov 2026 14:47:34 +0000 [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] drm/tyr: prepared clocks leaked on error inTyrPlatformDriver::probe()
- [Low] drm/tyr: overly restrictive &'reset self lifetime inResetHandle::schedule()
--commit
2f1b0845121531379549eca9ca27fd1ffc58562f
Author: Onur Özkan <[email protected]>drm/tyr: add GPU reset infrastructure
This commit adds GPU reset infrastructure using a dedicated ordered workqueue and an SRCU-based hardware access gate, and drains pending or running reset work on teardown.
Quoted 4 lines
drivers/gpu/drm/tyr/driver.rs +0
-0[ ... ]
drivers/gpu/drm/tyr/driver.rs fn probe<'bound>( · line 163
Quoted 13 lines
drivers/gpu/drm/tyr/driver.rs +4
-1@@ -171,8 +153,11 @@ fn probe<'bound>( _reg <- unsafe { drm::Registration::new( pdev.as_ref(), unreg_dev, - pin_init!(TyrDrmRegistrationData { + try_pin_init!(TyrDrmRegistrationData { pdev, + // SAFETY: The registration is owned by platform driver data, + // so reset work is drained before borrowed data expires. + reset <- reset::ResetHandle::new(pdev, iomem.as_arc_borrow())?, fw: firmware, clks <- new_mutex!(Clocks { core: core_clk,[Severity: Medium]
Does this leak the prepared and enabled clocks ifResetHandle::new()or its PinInit initializer fails?Drop for Clk and OptionalClk only calls
clk_put(), whiledisable_unprepare()is only called inClocks::drop():drivers/gpu/drm/tyr/driver.rs:Clocks::drop() { fn drop(&mut self) { self.core.disable_unprepare(); self.stacks.disable_unprepare(); self.coregroup.disable_unprepare(); } }
Quoted 7 lines
Because TyrDrmRegistrationData now initializes reset via
try_pin_init! before constructing Clocks, a failure inQueue::build()orHwGate::new()(as well as earlier error paths afterprepare_enable()inprobe()) dropscore_clk,stacks_clk, andcoregroup_clkwithout disabling or unpreparing them, leaving the hardware clocks enabled and triggering a warning inclk_put(). Wrapping the clocks in Clocks immediately afterprepare_enable()would ensure they are cleaned up on all error paths.
I can fix this by guarding each enabled clock with ScopeGuard but IIUC this will no longer be necessary once Daniel's Clk series [1] is applied. If we plan to land this soon I can still do it. Otherwise, it's pointless.
@Daniel thoughts ?
[1]: https://lore.kernel.org/rust-for-linux/[email protected]
Quoted 42 lines
Quoted 6 lines
drivers/gpu/drm/tyr/reset.rs new file +0
-0[ ... ]
Quoted 5 lines
drivers/gpu/drm/tyr/reset.rs new file +5
-0+pub (crate )struct ResetHandle <'reset> { +#[pin] + controller:ScopedWork <Controller <'reset>>, + wq:OwnedQueue , +}[ ... ]
Quoted 5 lines
drivers/gpu/drm/tyr/reset.rs new file +5
-0+/// Schedules a GPU reset on the dedicated workqueue. +/// +/// If a reset is already pending or in progress the call is a no-op. +#[expect(dead_code)] +pub (crate )fn schedule (&'reset self) {drivers/gpu/drm/tyr/reset.rs line 205
Quoted 10 lines
drivers/gpu/drm/tyr/reset.rs new file +10
-0+// TODO: Similar to `panthor_device_schedule_reset()` in Panthor, add a +// power management check once Tyr supports it. + +if self + .controller + .try_transition (ResetState ::Idle ,ResetState ::Pending ) + { +let _ = self.wq.enqueue_scoped (&self.controller); + } + }[Severity: Low]
CanResetHandle::schedule()take &self instead of &'reset self?ScopedWork wraps its payload in Opaque (UnsafeCell), making ResetHandle<'reset> invariant over 'reset, where 'reset is the device binding lifetime in TyrDrmRegistrationData<'drm>. Requiring &'reset self prevents callers holding a normal short-lived borrow of TyrDrmRegistrationData or ResetHandle from calling
schedule(), and neithertry_transition()norenqueue_scoped()needs the reference to live for 'reset.Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
kernel test robot
build botRe: [PATCH v8 2/3] drm/tyr: add GPU reset infrastructure
In reply to Onur Özkankernel test robot noticed the following build errors:
Hi Onur,
kernel test robot noticed the following build errors:
[auto build test ERROR on drm-misc/drm-misc-next]
[also build test ERROR on daeinki-drm-exynos/exynos-drm-next drm/drm-next drm-i915/for-linux-next drm-i915/for-linux-next-fixes drm-tip/drm-tip linus/master v7.4-rc2 next-20261113] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Onur-zkan/drm-tyr-add-GPU-reset-infrastructure/20261113-173227 base: https://gitlab.freedesktop.org/drm/misc/kernel.git drm-misc-next patch link: https://lore.kernel.org/r/20261113-tyr-reset-impl-v8-2-2ee298ac9808%40onurozkan.dev patch subject: [PATCH v8 2/3] drm/tyr: add GPU reset infrastructure config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20261116/[email protected]/config) compiler: clang version 22.1.8 (https://github.com/llvm/llvm-project ca7933e47d3a3451d81e72ac174dcb5aa28b59d1) rustc: rustc 1.96.0 (ac68faa20 2026-05-25) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261116/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> error[E0432]: unresolved imports `kernel::workqueue::OwnedQueue`, `kernel::workqueue::ScopedWork`, `kernel::workqueue::ScopedWorkItem` --> drivers/gpu/drm/tyr/reset.rs:49:9 | 49 | OwnedQueue, | ^^^^^^^^^^ no `OwnedQueue` in `workqueue` 50 | Queue, 51 | ScopedWork,
| ^^^^^^^^^^ no ScopedWork in workqueue
52 | ScopedWorkItem, //
| ^^^^^^^^^^^^^^ no ScopedWorkItem in workqueue
--
>> error[E0433]: cannot find `new_scoped_work` in `kernel`
--> drivers/gpu/drm/tyr/reset.rs:185:25
|
185 | kernel::new_scoped_work!("tyr::reset", Controller::new(pdev, iomem))
| ^^^^^^^^^^^^^^^ could not find new_scoped_work in kernel
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Alice Ryhl
maintainerRe: [PATCH v8 2/3] drm/tyr: add GPU reset infrastructure
In reply to Onur ÖzkanQuoted 23 lines · Onur Özkan
drivers/gpu/drm/tyr/reset.rs new file +23
-0+/// Processes one scheduled reset request. +/// +/// If the pending reset cannot be claimed, the worker returns immediately. +/// +/// It first claims [`ResetState::Pending`], then waits for earlier hardware +/// accesses to complete before issuing the reset and returning the worker +/// state to [`ResetState::Idle`]. +/// +/// Panthor reference: +/// - drivers/gpu/drm/panthor/panthor_device.c::panthor_device_reset_work() +fn reset_work (&self) { +if !self.try_transition (ResetState ::Pending ,ResetState ::InProgress ) { +return ; + } + +dev_dbg! (self.pdev,"Starting GPU reset.\n" ); + +// Wait for current hardware accesses to finish before resetting. +let reset_guard = self.hw.close (); +let reset_result =run_reset (self.pdev.as_ref (), &self.iomem); +drop (reset_guard); + +if let Err (e) = reset_result {
drivers/gpu/drm/tyr/reset.rs line 154
Quoted 10 lines
drivers/gpu/drm/tyr/reset.rs new file +10
-0+dev_err! (self.pdev,"GPU reset failed: {:?}\n" , e); + +// TODO: Unplug the GPU. +// There is no API for unplugging the GPU and this is unreachable +// for now since there are no hardware users for reset API. + }else { +dev_dbg! (self.pdev,"GPU reset completed.\n" ); + } + +let _ = self.try_transition (ResetState ::InProgress ,ResetState ::Idle );
I'm pretty sure this needs to happen before drop(reset_guard).
Quoted 9 lines
drivers/gpu/drm/tyr/reset.rs new file +9
-0+/// Creates [`ResetHandle`]. +/// +/// # Safety +/// +/// The returned handle must not be leaked or otherwise prevented from +/// running [`Drop`], since it owns work that may borrow from `'reset`. +pub (crate )unsafe fn new ( + pdev: &'reset platform::Device <Bound >, + iomem: ArcBorrow<'_, IoMem<'reset>>,
drivers/gpu/drm/tyr/reset.rs line 188
Quoted 10 lines
drivers/gpu/drm/tyr/reset.rs new file +10
-0+ ) -> Result<impl PinInit<Self, Error>> { +let iomem = iomem.into (); + +Ok (try_pin_init! (Self { +// SAFETY: The caller guarantees the handle is dropped. + controller <-unsafe { + kernel::new_scoped_work!("tyr::reset" ,Controller ::new (pdev, iomem)) + }, + wq:Queue ::new_ordered ().build (c"tyr-reset-wq" )?, + }))
The Result is not needed. This can simplify to:
) -> impl PinInit<Self, Error> {
let iomem = iomem.into();
try_pin_init!(Self {
// SAFETY: The caller guarantees the handle is dropped.
controller <- unsafe {
kernel::new_scoped_work!("tyr::reset", Controller::new(pdev, iomem))
},
wq: Queue::new_ordered().build(c"tyr-reset-wq")?,
})Quoted 6 lines
drivers/gpu/drm/tyr/reset.rs new file +6
-0+ } + +/// Schedules a GPU reset on the dedicated workqueue. +/// +/// If a reset is already pending or in progress the call is a no-op. +#[expect(dead_code)]
drivers/gpu/drm/tyr/reset.rs line 204
Quoted 10 lines
drivers/gpu/drm/tyr/reset.rs new file +10
-0+pub (crate )fn schedule (&'reset self) { +// TODO: Similar to `panthor_device_schedule_reset()` in Panthor, add a +// power management check once Tyr supports it. + +if self + .controller + .try_transition (ResetState ::Idle ,ResetState ::Pending ) + { +let _ = self.wq.enqueue_scoped (&self.controller); + }
Because this type is invariant over 'reset, it's impossible to call a method that takes &'reset self.
I think you can just change this to &self.
Alice
Onur Özkan
reviewerPATCH v8 3/3 drm/tyr: put iomem behind the hardware gate
In reply to Onur ÖzkanMove iomem mapping into HwGate and pass Arc<HwGate> to components that access hardware. Callers obtain HwAccessGuard before accessing the iomem so the reset worker waits for ongoing accesses.
Acquire the gate once per address-space operation and pass the guarded iomem reference to its helpers. This prevents nested gate acquisition from deadlocking with reset and keeps each operation protected throughout. Clone the gate Arc before acquiring the guard so mutating helpers can retain their mutable self receivers.
--- drivers/gpu/drm/tyr/driver.rs | 27 ++++++---- drivers/gpu/drm/tyr/fw.rs | 16 +++--- drivers/gpu/drm/tyr/mmu.rs | 6 +-- drivers/gpu/drm/tyr/mmu/address_space.rs | 87 ++++++++++++++++++-------------- drivers/gpu/drm/tyr/reset.rs | 33 +++++------- drivers/gpu/drm/tyr/reset/hw_gate.rs | 44 ++++++++++++---- 6 files changed, 126 insertions(+), 87 deletions(-)
drivers/gpu/drm/tyr/driver.rs +16 -11
@@ -79,9 +79,6 @@ pub(crate) struct TyrDrmRegistrationData<'drm> {#[pin] regulators: Mutex<Regulators>, -/// GPU MMIO register mapping. - pub(crate) iomem: Arc<IoMem<'drm>>, -/// GPU information read from hardware during probe. pub(crate) gpu_info: GpuInfo, }
@@ -118,12 +115,21 @@ fn probe<'bound>(let request = pdev.io_request_by_index (0 ).ok_or (ENODEV )?; -let iomem =Arc ::new (request.iomap_sized ::<SZ_2M >()?,GFP_KERNEL )?; +// TODO: Consider embedding HwGate in platform data and using self referential +// pin-init instead of Arc. +let hw =Arc ::pin_init ( + reset::HwGate ::new (request.iomap_sized ::<SZ_2M >()?), +GFP_KERNEL , + )?; - reset::run_reset (pdev.as_ref (), &iomem)?; + reset::run_reset (pdev.as_ref (), &hw)?; -let gpu_info =GpuInfo ::new (&iomem); - gpu_info.log (pdev.as_ref ()); +let gpu_info = { +let hw_guard = hw.access (); +let gpu_info =GpuInfo ::new (hw_guard.iomem ()); + gpu_info.log (pdev.as_ref ()); + gpu_info + };let pa_bits =MMU_FEATURES ::from_raw (gpu_info.mmu_features) .pa_bits ()
@@ -135,11 +141,11 @@ fn probe<'bound>(let unreg_dev = drm::UnregisteredDevice ::<TyrDrmDriver >::new (pdev,Ok (()))?; -let mmu =Mmu ::new (pdev.as_ref (), iomem.as_arc_borrow (), &gpu_info)?; +let mmu =Mmu ::new (pdev.as_ref (), hw.clone (), &gpu_info)?;let firmware =Firmware ::new ( pdev.as_ref (), - iomem.clone (), + hw.clone (), &unreg_dev, mmu.as_arc_borrow (), &gpu_info,
@@ -157,7 +163,7 @@ fn probe<'bound>( pdev,// SAFETY: The registration is owned by platform driver data, // so reset work is drained before borrowed data expires. - reset <- reset::ResetHandle::new(pdev, iomem.as_arc_borrow())?, + reset <- reset::ResetHandle::new(pdev, hw.clone())?, fw: firmware, clks <-new_mutex! (Clocks { core: core_clk,
@@ -168,7 +174,6 @@ fn probe<'bound>( _mali: mali_regulator, _sram: sram_regulator, }), - iomem, gpu_info, }), )},
drivers/gpu/drm/tyr/fw.rs +9 -7
@@ -38,7 +38,6 @@use crate ::{ driver::{ -IoMem ,TyrDrmDevice ,// }, fw::parser::{
@@ -66,6 +65,7 @@ JOB_IRQ_RAWSTAT, // }, // }, + reset::HwGate, vm::Vm, // };
@@ -144,8 +144,8 @@ struct Section<'drm> {/// Loaded firmware with sections mapped into MCU VM. pub (crate )struct Firmware <'drm> { -/// Iomem need to access registers. - iomem:Arc <IoMem <'drm>>, +/// Shared gate that coordinates hardware access with GPU reset. + hw:Arc <HwGate <'drm>>,/// MCU VM. vm:Arc <Vm <'drm>>,
@@ -214,7 +214,7 @@ fn load(/// Load firmware and map sections into MCU VM. pub (crate )fn new ( dev: &'drmDevice <Bound >, - iomem:Arc <IoMem <'drm>>, + hw:Arc <HwGate <'drm>>, ddev: &TyrDrmDevice , mmu:ArcBorrow <'_,Mmu <'drm>>, gpu_info: &GpuInfo,
@@ -253,7 +253,7 @@ pub(crate) fn new( }Ok (Firmware { - iomem, + hw, vm: vm.clone (), sections, })
@@ -267,7 +267,8 @@ pub(crate) fn new( }pub (crate )fn boot (&self) ->Result { -let io = &self.iomem; +let hw_guard = self.hw.access (); +let io = hw_guard.iomem ();// Discard any stale global interrupt. io.write_reg (JOB_IRQ_CLEAR ::zeroed ().with_glb (true ));
@@ -297,7 +298,8 @@ pub(crate) fn boot(&self) -> Result { } fn stop(&self) -> Result { - let io = &self.iomem; + let hw_guard = self.hw.access(); + let io = hw_guard.iomem(); io.write_reg(MCU_CONTROL::zeroed().with_req(McuControlMode::Disable)); if let Err(e) = poll::read_poll_timeout(
drivers/gpu/drm/tyr/mmu.rs +3 -3
@@ -28,7 +28,6 @@ };use crate ::{ - driver::IoMem , gpu::GpuInfo , mmu::address_space::{AddressSpaceManager ,
@@ -38,6 +37,7 @@ gpu_control::AS_PRESENT, MAX_AS, // }, + reset::HwGate, slot::SlotManager, // };
@@ -57,13 +57,13 @@ impl<'drm> Mmu<'drm> { /// Create an MMU component for this device. pub(crate) fn new( dev: &'drm Device<Bound>, - iomem: ArcBorrow<'_, IoMem<'drm>>, + hw: Arc<HwGate<'drm>>, gpu_info: &GpuInfo, ) -> Result<Arc<Mmu<'drm>>> { let present = AS_PRESENT::from_raw(gpu_info.as_present).present().get(); let slot_count = present.count_ones().try_into()?; - let address_space_manager = AddressSpaceManager::new(dev, iomem.into(), present)?; + let address_space_manager = AddressSpaceManager::new(dev, hw, present)?; let as_slot_manager = SlotManager::new(address_space_manager, slot_count).inspect_err(|e| { dev_err!(
drivers/gpu/drm/tyr/mmu/address_space.rs +50 -37
223 lines not on this page · raw message
drivers/gpu/drm/tyr/reset.rs +13 -20
@@ -21,7 +21,7 @@mod hw_gate; -use hw_gate::HwGate ; +pub (crate )use hw_gate::HwGate ;use kernel::{ device::{
@@ -41,8 +41,7 @@ Full, Release, // }, - Arc, - ArcBorrow, // + Arc, // }, time, workqueue::{
@@ -84,13 +83,10 @@ unsafe impl AtomicType for ResetState {struct Controller <'ctrl> {/// Parent platform device. pdev: &'ctrl platform::Device <Bound >, -/// Mapped register space needed for reset operations. - iomem:Arc <IoMem <'ctrl>>,/// State shared by reset schedulers and the worker. state:Atomic <ResetState >, -/// Drains reset-sensitive hardware accesses before a reset. -#[pin] - hw:HwGate , +/// Shared gate that coordinates hardware access with GPU reset. + hw:Arc <HwGate <'ctrl>>, }impl <'ctrl>ScopedWorkItem for Controller <'ctrl> {
@@ -103,13 +99,12 @@ impl<'ctrl> Controller<'ctrl> {/// Creates a reset controller. fn new ( pdev: &'ctrl platform::Device <Bound >, - iomem:Arc <IoMem <'ctrl>>, + hw:Arc <HwGate <'ctrl>>, ) ->impl PinInit <Self ,Error > {try_pin_init! (Self { pdev, - iomem, state:Atomic ::new (ResetState ::Idle ), - hw <-HwGate ::new (), + hw, }) }
@@ -136,10 +131,7 @@ fn reset_work(&self) {dev_dbg! (self.pdev,"Starting GPU reset.\n" ); -// Wait for current hardware accesses to finish before resetting. -let reset_guard = self.hw.close (); -let reset_result =run_reset (self.pdev.as_ref (), &self.iomem); -drop (reset_guard); +let reset_result =run_reset (self.pdev.as_ref (), &self.hw);if let Err (e) = reset_result {dev_err! (self.pdev,"GPU reset failed: {:?}\n" , e);
@@ -175,14 +167,12 @@ impl<'reset> ResetHandle<'reset> {/// running [`Drop`], since it owns work that may borrow from `'reset`. pub (crate )unsafe fn new ( pdev: &'reset platform::Device <Bound >, - iomem:ArcBorrow <'_,IoMem <'reset>>, + hw:Arc <HwGate <'reset>>, ) ->Result <impl PinInit <Self ,Error >> { -let iomem = iomem.into (); -Ok (try_pin_init! (Self {// SAFETY: The caller guarantees the handle is dropped. controller <-unsafe { - kernel::new_scoped_work!("tyr::reset" ,Controller ::new (pdev, iomem)) + kernel::new_scoped_work!("tyr::reset" ,Controller ::new (pdev, hw)) }, wq:Queue ::new_ordered ().build (c"tyr-reset-wq" )?, }))
@@ -244,7 +234,10 @@ fn issue_soft_reset(dev: &Device<Bound>, io: &IoMem<'_>) -> Result {/// - Trigger a GPU soft reset. /// - Wait for the reset-complete IRQ status. /// - Power L2 back on. -pub (super )fn run_reset (dev: &Device <Bound >, iomem: &IoMem <'_>) ->Result { +pub (super )fn run_reset (dev: &Device <Bound >, hw: &HwGate <'_>) ->Result { +let hw_guard = hw.close (); +let iomem = hw_guard.iomem (); +issue_soft_reset (dev, iomem)?; gpu::l2_power_on (dev, iomem)?;Ok (())
drivers/gpu/drm/tyr/reset/hw_gate.rs +35 -9
93 lines not on this page · raw message
Signature · 1 line
2.51.2