* [PATCH] drm/tyr: replace fixed sleeps with read_poll_timeout
@ 2026-03-07 20:47 Artem Lytkin
2026-03-09 9:58 ` Alice Ryhl
0 siblings, 1 reply; 2+ messages in thread
From: Artem Lytkin @ 2026-03-07 20:47 UTC (permalink / raw)
To: dri-devel; +Cc: daniel.almeida, aliceryhl, dakr, airlied, simona
The Tyr driver uses fixed 100ms sleeps followed by manual register
checks in l2_power_on() and issue_soft_reset(). Both functions have
TODO comments noting that read_poll_timeout() was not yet available
in Rust.
read_poll_timeout() has since been implemented in the kernel (at
rust/kernel/io/poll.rs) and is actively used by other Rust drivers.
Replace the fixed sleeps with proper read_poll_timeout() calls:
- l2_power_on: 100us poll interval, 20ms timeout (matches the C
panthor driver)
- issue_soft_reset: 1ms poll interval, 100ms timeout (the C driver
uses interrupt-driven wait_event_timeout; polling is used here as
the Tyr driver does not yet have IRQ support)
This also changes the error code on timeout from EIO to ETIMEDOUT,
which better reflects the nature of the failure. No callers in the
driver inspect the specific error code.
Signed-off-by: Artem Lytkin <iprintercanon@gmail.com>
---
drivers/gpu/drm/tyr/driver.rs | 27 ++++++++++-----------------
drivers/gpu/drm/tyr/gpu.rs | 21 ++++++++++-----------
2 files changed, 20 insertions(+), 28 deletions(-)
diff --git a/drivers/gpu/drm/tyr/driver.rs b/drivers/gpu/drm/tyr/driver.rs
index 0389c558c036..f54f5f44e923 100644
--- a/drivers/gpu/drm/tyr/driver.rs
+++ b/drivers/gpu/drm/tyr/driver.rs
@@ -9,6 +9,7 @@
use kernel::devres::Devres;
use kernel::drm;
use kernel::drm::ioctl;
+use kernel::io::poll::read_poll_timeout;
use kernel::new_mutex;
use kernel::of;
use kernel::platform;
@@ -18,7 +19,7 @@
use kernel::sizes::SZ_2M;
use kernel::sync::Arc;
use kernel::sync::Mutex;
-use kernel::time;
+use kernel::time::Delta;
use kernel::types::ARef;
use crate::file::File;
@@ -68,22 +69,14 @@ unsafe impl Sync for TyrData {}
fn issue_soft_reset(dev: &Device<Bound>, iomem: &Devres<IoMem>) -> Result {
regs::GPU_CMD.write(dev, iomem, regs::GPU_CMD_SOFT_RESET)?;
- // TODO: We cannot poll, as there is no support in Rust currently, so we
- // sleep. Change this when read_poll_timeout() is implemented in Rust.
- kernel::time::delay::fsleep(time::Delta::from_millis(100));
-
- if regs::GPU_IRQ_RAWSTAT.read(dev, iomem)? & regs::GPU_IRQ_RAWSTAT_RESET_COMPLETED == 0 {
- dev_err!(dev, "GPU reset failed with errno\n");
- dev_err!(
- dev,
- "GPU_INT_RAWSTAT is {}\n",
- regs::GPU_IRQ_RAWSTAT.read(dev, iomem)?
- );
-
- return Err(EIO);
- }
-
- Ok(())
+ read_poll_timeout(
+ || regs::GPU_IRQ_RAWSTAT.read(dev, iomem),
+ |val| *val & regs::GPU_IRQ_RAWSTAT_RESET_COMPLETED != 0,
+ Delta::from_millis(1),
+ Delta::from_millis(100),
+ )
+ .map(|_| ())
+ .inspect_err(|_| dev_err!(dev, "soft reset timed out\n"))
}
kernel::of_device_table!(
diff --git a/drivers/gpu/drm/tyr/gpu.rs b/drivers/gpu/drm/tyr/gpu.rs
index 6c582910dd5d..76dfdef054f1 100644
--- a/drivers/gpu/drm/tyr/gpu.rs
+++ b/drivers/gpu/drm/tyr/gpu.rs
@@ -4,9 +4,10 @@
use kernel::device::Bound;
use kernel::device::Device;
use kernel::devres::Devres;
+use kernel::io::poll::read_poll_timeout;
use kernel::platform;
use kernel::prelude::*;
-use kernel::time;
+use kernel::time::Delta;
use kernel::transmute::AsBytes;
use crate::driver::IoMem;
@@ -206,14 +207,12 @@ fn from(value: u32) -> Self {
pub(crate) fn l2_power_on(dev: &Device<Bound>, iomem: &Devres<IoMem>) -> Result {
regs::L2_PWRON_LO.write(dev, iomem, 1)?;
- // TODO: We cannot poll, as there is no support in Rust currently, so we
- // sleep. Change this when read_poll_timeout() is implemented in Rust.
- kernel::time::delay::fsleep(time::Delta::from_millis(100));
-
- if regs::L2_READY_LO.read(dev, iomem)? != 1 {
- dev_err!(dev, "Failed to power on the GPU\n");
- return Err(EIO);
- }
-
- Ok(())
+ read_poll_timeout(
+ || regs::L2_READY_LO.read(dev, iomem),
+ |val| *val == 1,
+ Delta::from_micros(100),
+ Delta::from_millis(20),
+ )
+ .map(|_| ())
+ .inspect_err(|_| dev_err!(dev, "Failed to power on the GPU\n"))
}
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] drm/tyr: replace fixed sleeps with read_poll_timeout
2026-03-07 20:47 [PATCH] drm/tyr: replace fixed sleeps with read_poll_timeout Artem Lytkin
@ 2026-03-09 9:58 ` Alice Ryhl
0 siblings, 0 replies; 2+ messages in thread
From: Alice Ryhl @ 2026-03-09 9:58 UTC (permalink / raw)
To: Artem Lytkin
Cc: dri-devel, daniel.almeida, dakr, airlied, simona, rust-for-linux,
boris.brezillon
Cc'ing rust-for-linux list.
On Sat, Mar 07, 2026 at 11:47:08PM +0300, Artem Lytkin wrote:
> The Tyr driver uses fixed 100ms sleeps followed by manual register
> checks in l2_power_on() and issue_soft_reset(). Both functions have
> TODO comments noting that read_poll_timeout() was not yet available
> in Rust.
>
> read_poll_timeout() has since been implemented in the kernel (at
> rust/kernel/io/poll.rs) and is actively used by other Rust drivers.
>
> Replace the fixed sleeps with proper read_poll_timeout() calls:
> - l2_power_on: 100us poll interval, 20ms timeout (matches the C
> panthor driver)
> - issue_soft_reset: 1ms poll interval, 100ms timeout (the C driver
> uses interrupt-driven wait_event_timeout; polling is used here as
> the Tyr driver does not yet have IRQ support)
>
> This also changes the error code on timeout from EIO to ETIMEDOUT,
> which better reflects the nature of the failure. No callers in the
> driver inspect the specific error code.
>
> Signed-off-by: Artem Lytkin <iprintercanon@gmail.com>
I thought we already had a patch fixing these? Did it get lost
somewhere?
Alice
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-09 9:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-07 20:47 [PATCH] drm/tyr: replace fixed sleeps with read_poll_timeout Artem Lytkin
2026-03-09 9:58 ` Alice Ryhl
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.