From: Maxime Ripard <maxime@cerno.tech>
To: David Airlie <airlied@linux.ie>, Daniel Vetter <daniel@ffwll.ch>,
Thomas Zimmermann <tzimmermann@suse.de>,
Maxime Ripard <mripard@kernel.org>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Emma Anholt <emma@anholt.net>
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
Stefan Wahren <stefan.wahren@i2se.com>,
Marc Kleine-Budde <mkl@pengutronix.de>,
Maxime Ripard <maxime@cerno.tech>
Subject: [PATCH 2/2] drm/vc4: hdmi: Check the HSM rate at runtime_resume
Date: Thu, 29 Sep 2022 11:21:18 +0200 [thread overview]
Message-ID: <20220929-rpi-pi3-unplugged-fixes-v1-2-cd22e962296c@cerno.tech> (raw)
In-Reply-To: <20220929-rpi-pi3-unplugged-fixes-v1-0-cd22e962296c@cerno.tech>
If our HSM clock has not been properly initialized, any register access
will silently lock up the system.
Let's check that this can't happen by adding a check for the rate before
any register access, and error out otherwise.
Link: https://lore.kernel.org/dri-devel/20220922145448.w3xfywkn5ecak2et@pengutronix.de/
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
---
drivers/gpu/drm/vc4/vc4_hdmi.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c
index 2e28fe16ed5e..eb3aaaca2b80 100644
--- a/drivers/gpu/drm/vc4/vc4_hdmi.c
+++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
@@ -2889,6 +2889,7 @@ static int vc4_hdmi_runtime_resume(struct device *dev)
struct vc4_hdmi *vc4_hdmi = dev_get_drvdata(dev);
unsigned long __maybe_unused flags;
u32 __maybe_unused value;
+ unsigned long rate;
int ret;
/*
@@ -2904,6 +2905,21 @@ static int vc4_hdmi_runtime_resume(struct device *dev)
if (ret)
return ret;
+ /*
+ * Whenever the RaspberryPi boots without an HDMI monitor
+ * plugged in, the firmware won't have initialized the HSM clock
+ * rate and it will be reported as 0.
+ *
+ * If we try to access a register of the controller in such a
+ * case, it will lead to a silent CPU stall. Let's make sure we
+ * prevent such a case.
+ */
+ rate = clk_get_rate(vc4_hdmi->hsm_clock);
+ if (!rate) {
+ ret = -EINVAL;
+ goto err_disable_clk;
+ }
+
if (vc4_hdmi->variant->reset)
vc4_hdmi->variant->reset(vc4_hdmi);
@@ -2925,6 +2941,10 @@ static int vc4_hdmi_runtime_resume(struct device *dev)
#endif
return 0;
+
+err_disable_clk:
+ clk_disable_unprepare(vc4_hdmi->hsm_clock);
+ return ret;
}
static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
--
b4 0.10.1
next prev parent reply other threads:[~2022-09-29 9:34 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-29 9:21 [PATCH 0/2] drm/vc4: hdmi: Fixes for the RaspberryPi 0-3 stalls Maxime Ripard
2022-09-29 9:21 ` [PATCH 1/2] drm/vc4: hdmi: Enforce the minimum rate at runtime_resume Maxime Ripard
2022-10-13 9:37 ` Javier Martinez Canillas
2022-10-13 12:11 ` (subset) " Maxime Ripard
2022-11-11 21:08 ` Stefan Wahren
2022-11-14 0:48 ` Stefan Wahren
2022-11-14 13:06 ` Maxime Ripard
2022-09-29 9:21 ` Maxime Ripard [this message]
2022-10-13 9:43 ` [PATCH 2/2] drm/vc4: hdmi: Check the HSM " Javier Martinez Canillas
2022-10-13 12:11 ` (subset) " Maxime Ripard
2022-10-10 8:50 ` [PATCH 0/2] drm/vc4: hdmi: Fixes for the RaspberryPi 0-3 stalls Maxime Ripard
2022-10-10 16:38 ` Stefan Wahren
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220929-rpi-pi3-unplugged-fixes-v1-2-cd22e962296c@cerno.tech \
--to=maxime@cerno.tech \
--cc=airlied@linux.ie \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=emma@anholt.net \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mkl@pengutronix.de \
--cc=mripard@kernel.org \
--cc=stefan.wahren@i2se.com \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).