* [PATCH v2 0/2] drm/vc4: hdmi: Replace drm_detect_hdmi_monitor() with drm_display_info.is_hdmi
@ 2022-04-15 15:47 José Expósito
2022-04-15 15:47 ` [PATCH v2 1/2] drm/vc4: hdmi: Replace drm_detect_hdmi_monitor() with is_hdmi José Expósito
2022-04-15 15:47 ` [PATCH v2 2/2] drm/vc4: hdmi: Remove vc4_hdmi_encoder.hdmi_monitor José Expósito
0 siblings, 2 replies; 4+ messages in thread
From: José Expósito @ 2022-04-15 15:47 UTC (permalink / raw)
To: emma
Cc: mripard, laurent.pinchart, airlied, daniel, p.zabel, dri-devel,
linux-kernel, José Expósito
Hi everyone,
These patches replace the calls to drm_detect_hdmi_monitor() with the
more efficient drm_display_info.is_hdmi in the VC4 driver.
As I mentioned in v1, vc4_hdmi_encoder.hdmi_monitor (removed by this
series) is used by some code not present in the mainline kernel but
present in the Raspberry Pi tree [1].
Let me know if you want me to open a PR in the Raspberry Pi kernel
project applying this series and fixing this issue.
Thanks,
José Expósito
[1] https://github.com/raspberrypi/linux/blob/rpi-5.15.y/drivers/gpu/drm/vc4/vc4_firmware_kms.c#L1410
v1: https://lore.kernel.org/dri-devel/20220406165514.6106-1-jose.exposito89@gmail.com/
v2: Add the ftrace command used in the first patch
Remove vc4_hdmi_encoder.hdmi_monitor
(Thanks to Maxime for suggesting these changes)
José Expósito (2):
drm/vc4: hdmi: Replace drm_detect_hdmi_monitor() with is_hdmi
drm/vc4: hdmi: Remove vc4_hdmi_encoder.hdmi_monitor
drivers/gpu/drm/vc4/vc4_hdmi.c | 17 ++++++-----------
drivers/gpu/drm/vc4/vc4_hdmi.h | 1 -
2 files changed, 6 insertions(+), 12 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v2 1/2] drm/vc4: hdmi: Replace drm_detect_hdmi_monitor() with is_hdmi 2022-04-15 15:47 [PATCH v2 0/2] drm/vc4: hdmi: Replace drm_detect_hdmi_monitor() with drm_display_info.is_hdmi José Expósito @ 2022-04-15 15:47 ` José Expósito 2022-04-15 15:47 ` [PATCH v2 2/2] drm/vc4: hdmi: Remove vc4_hdmi_encoder.hdmi_monitor José Expósito 1 sibling, 0 replies; 4+ messages in thread From: José Expósito @ 2022-04-15 15:47 UTC (permalink / raw) To: emma Cc: mripard, laurent.pinchart, airlied, daniel, p.zabel, dri-devel, linux-kernel, José Expósito Once EDID is parsed, the monitor HDMI support information is cached in drm_display_info.is_hdmi by drm_parse_hdmi_vsdb_video(). This driver calls drm_detect_hdmi_monitor() to receive the same information and stores its own cached value, which is less efficient. Avoid calling drm_detect_hdmi_monitor() and use drm_display_info.is_hdmi instead. drm_detect_hdmi_monitor() is called in vc4_hdmi_connector_detect() and vc4_hdmi_connector_get_modes(). In both cases it is safe to rely on drm_display_info.is_hdmi as shown by ftrace: $ sudo trace-cmd record -p function_graph -l "vc4_hdmi_*" -l "drm_*" vc4_hdmi_connector_detect: vc4_hdmi_connector_detect() { drm_get_edid() { drm_connector_update_edid_property() { drm_add_display_info() { drm_reset_display_info(); drm_for_each_detailed_block.part.0(); drm_parse_cea_ext() { drm_find_cea_extension(); drm_parse_hdmi_vsdb_video(); /* drm_display_info.is_hdmi is cached here */ } } } } /* drm_display_info.is_hdmi is used here */ } vc4_hdmi_connector_get_modes: vc4_hdmi_connector_get_modes() { drm_get_edid() { drm_connector_update_edid_property() { drm_add_display_info() { drm_reset_display_info(); drm_for_each_detailed_block.part.0(); drm_parse_cea_ext() { drm_find_cea_extension(); drm_parse_hdmi_vsdb_video(); /* drm_display_info.is_hdmi is cached here */ } } } } /* drm_display_info.is_hdmi is used here */ drm_connector_update_edid_property(); } Signed-off-by: José Expósito <jose.exposito89@gmail.com> --- drivers/gpu/drm/vc4/vc4_hdmi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c index 6c58b0fd13fb..ecdb1ffc2023 100644 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c @@ -216,7 +216,7 @@ vc4_hdmi_connector_detect(struct drm_connector *connector, bool force) if (edid) { cec_s_phys_addr_from_edid(vc4_hdmi->cec_adap, edid); - vc4_hdmi->encoder.hdmi_monitor = drm_detect_hdmi_monitor(edid); + vc4_hdmi->encoder.hdmi_monitor = connector->display_info.is_hdmi; kfree(edid); } } @@ -255,7 +255,7 @@ static int vc4_hdmi_connector_get_modes(struct drm_connector *connector) goto out; } - vc4_encoder->hdmi_monitor = drm_detect_hdmi_monitor(edid); + vc4_encoder->hdmi_monitor = connector->display_info.is_hdmi; drm_connector_update_edid_property(connector, edid); ret = drm_add_edid_modes(connector, edid); -- 2.25.1 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 2/2] drm/vc4: hdmi: Remove vc4_hdmi_encoder.hdmi_monitor 2022-04-15 15:47 [PATCH v2 0/2] drm/vc4: hdmi: Replace drm_detect_hdmi_monitor() with drm_display_info.is_hdmi José Expósito 2022-04-15 15:47 ` [PATCH v2 1/2] drm/vc4: hdmi: Replace drm_detect_hdmi_monitor() with is_hdmi José Expósito @ 2022-04-15 15:47 ` José Expósito 2022-04-19 12:41 ` Maxime Ripard 1 sibling, 1 reply; 4+ messages in thread From: José Expósito @ 2022-04-15 15:47 UTC (permalink / raw) To: emma Cc: mripard, laurent.pinchart, airlied, daniel, p.zabel, dri-devel, linux-kernel, José Expósito The vc4_hdmi_encoder.hdmi_monitor field was used to cache the value returned by drm_detect_hdmi_monitor() in order to avoid calling it multiple times. Now that drm_detect_hdmi_monitor() has been replaced with drm_display_info.is_hdmi, there is no need to cache it in the driver encoder struct. Remove vc4_hdmi_encoder.hdmi_monitor and use drm_display_info.is_hdmi instead. Signed-off-by: José Expósito <jose.exposito89@gmail.com> --- drivers/gpu/drm/vc4/vc4_hdmi.c | 17 ++++++----------- drivers/gpu/drm/vc4/vc4_hdmi.h | 1 - 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c index ecdb1ffc2023..9c73a211ae80 100644 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c @@ -107,9 +107,9 @@ static bool vc4_hdmi_mode_needs_scrambling(const struct drm_display_mode *mode) static bool vc4_hdmi_is_full_range_rgb(struct vc4_hdmi *vc4_hdmi, const struct drm_display_mode *mode) { - struct vc4_hdmi_encoder *vc4_encoder = &vc4_hdmi->encoder; + struct drm_display_info *display = &vc4_hdmi->connector.display_info; - return !vc4_encoder->hdmi_monitor || + return !display->is_hdmi || drm_default_rgb_quant_range(mode) == HDMI_QUANTIZATION_RANGE_FULL; } @@ -216,7 +216,6 @@ vc4_hdmi_connector_detect(struct drm_connector *connector, bool force) if (edid) { cec_s_phys_addr_from_edid(vc4_hdmi->cec_adap, edid); - vc4_hdmi->encoder.hdmi_monitor = connector->display_info.is_hdmi; kfree(edid); } } @@ -242,7 +241,6 @@ static void vc4_hdmi_connector_destroy(struct drm_connector *connector) static int vc4_hdmi_connector_get_modes(struct drm_connector *connector) { struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector); - struct vc4_hdmi_encoder *vc4_encoder = &vc4_hdmi->encoder; int ret = 0; struct edid *edid; @@ -255,8 +253,6 @@ static int vc4_hdmi_connector_get_modes(struct drm_connector *connector) goto out; } - vc4_encoder->hdmi_monitor = connector->display_info.is_hdmi; - drm_connector_update_edid_property(connector, edid); ret = drm_add_edid_modes(connector, edid); kfree(edid); @@ -578,13 +574,12 @@ static void vc4_hdmi_set_infoframes(struct drm_encoder *encoder) static bool vc4_hdmi_supports_scrambling(struct drm_encoder *encoder, struct drm_display_mode *mode) { - struct vc4_hdmi_encoder *vc4_encoder = to_vc4_hdmi_encoder(encoder); struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder); struct drm_display_info *display = &vc4_hdmi->connector.display_info; lockdep_assert_held(&vc4_hdmi->mutex); - if (!vc4_encoder->hdmi_monitor) + if (!display->is_hdmi) return false; if (!display->hdmi.scdc.supported || @@ -1147,7 +1142,7 @@ static void vc4_hdmi_encoder_post_crtc_enable(struct drm_encoder *encoder, { struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder); struct drm_display_mode *mode = &vc4_hdmi->saved_adjusted_mode; - struct vc4_hdmi_encoder *vc4_encoder = to_vc4_hdmi_encoder(encoder); + struct drm_display_info *display = &vc4_hdmi->connector.display_info; bool hsync_pos = mode->flags & DRM_MODE_FLAG_PHSYNC; bool vsync_pos = mode->flags & DRM_MODE_FLAG_PVSYNC; unsigned long flags; @@ -1168,7 +1163,7 @@ static void vc4_hdmi_encoder_post_crtc_enable(struct drm_encoder *encoder, HDMI_WRITE(HDMI_VID_CTL, HDMI_READ(HDMI_VID_CTL) & ~VC4_HD_VID_CTL_BLANKPIX); - if (vc4_encoder->hdmi_monitor) { + if (display->is_hdmi) { HDMI_WRITE(HDMI_SCHEDULER_CONTROL, HDMI_READ(HDMI_SCHEDULER_CONTROL) | VC4_HDMI_SCHEDULER_CONTROL_MODE_HDMI); @@ -1195,7 +1190,7 @@ static void vc4_hdmi_encoder_post_crtc_enable(struct drm_encoder *encoder, "!VC4_HDMI_SCHEDULER_CONTROL_HDMI_ACTIVE\n"); } - if (vc4_encoder->hdmi_monitor) { + if (display->is_hdmi) { spin_lock_irqsave(&vc4_hdmi->hw_lock, flags); WARN_ON(!(HDMI_READ(HDMI_SCHEDULER_CONTROL) & diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.h b/drivers/gpu/drm/vc4/vc4_hdmi.h index 1076faeab616..44977002445f 100644 --- a/drivers/gpu/drm/vc4/vc4_hdmi.h +++ b/drivers/gpu/drm/vc4/vc4_hdmi.h @@ -11,7 +11,6 @@ /* VC4 HDMI encoder KMS struct */ struct vc4_hdmi_encoder { struct vc4_encoder base; - bool hdmi_monitor; }; static inline struct vc4_hdmi_encoder * -- 2.25.1 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 2/2] drm/vc4: hdmi: Remove vc4_hdmi_encoder.hdmi_monitor 2022-04-15 15:47 ` [PATCH v2 2/2] drm/vc4: hdmi: Remove vc4_hdmi_encoder.hdmi_monitor José Expósito @ 2022-04-19 12:41 ` Maxime Ripard 0 siblings, 0 replies; 4+ messages in thread From: Maxime Ripard @ 2022-04-19 12:41 UTC (permalink / raw) To: José Expósito Cc: emma, laurent.pinchart, airlied, daniel, p.zabel, dri-devel, linux-kernel [-- Attachment #1: Type: text/plain, Size: 4881 bytes --] Hi, On Fri, Apr 15, 2022 at 05:47:45PM +0200, José Expósito wrote: > The vc4_hdmi_encoder.hdmi_monitor field was used to cache the value > returned by drm_detect_hdmi_monitor() in order to avoid calling it > multiple times. > > Now that drm_detect_hdmi_monitor() has been replaced with > drm_display_info.is_hdmi, there is no need to cache it in the driver > encoder struct. > > Remove vc4_hdmi_encoder.hdmi_monitor and use drm_display_info.is_hdmi > instead. > > Signed-off-by: José Expósito <jose.exposito89@gmail.com> > --- > drivers/gpu/drm/vc4/vc4_hdmi.c | 17 ++++++----------- > drivers/gpu/drm/vc4/vc4_hdmi.h | 1 - > 2 files changed, 6 insertions(+), 12 deletions(-) > > diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c > index ecdb1ffc2023..9c73a211ae80 100644 > --- a/drivers/gpu/drm/vc4/vc4_hdmi.c > +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c > @@ -107,9 +107,9 @@ static bool vc4_hdmi_mode_needs_scrambling(const struct drm_display_mode *mode) > static bool vc4_hdmi_is_full_range_rgb(struct vc4_hdmi *vc4_hdmi, > const struct drm_display_mode *mode) > { > - struct vc4_hdmi_encoder *vc4_encoder = &vc4_hdmi->encoder; > + struct drm_display_info *display = &vc4_hdmi->connector.display_info; > > - return !vc4_encoder->hdmi_monitor || > + return !display->is_hdmi || > drm_default_rgb_quant_range(mode) == HDMI_QUANTIZATION_RANGE_FULL; > } > > @@ -216,7 +216,6 @@ vc4_hdmi_connector_detect(struct drm_connector *connector, bool force) > > if (edid) { > cec_s_phys_addr_from_edid(vc4_hdmi->cec_adap, edid); > - vc4_hdmi->encoder.hdmi_monitor = connector->display_info.is_hdmi; I think the first patch could be squashed into this one > kfree(edid); > } > } > @@ -242,7 +241,6 @@ static void vc4_hdmi_connector_destroy(struct drm_connector *connector) > static int vc4_hdmi_connector_get_modes(struct drm_connector *connector) > { > struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector); > - struct vc4_hdmi_encoder *vc4_encoder = &vc4_hdmi->encoder; > int ret = 0; > struct edid *edid; > > @@ -255,8 +253,6 @@ static int vc4_hdmi_connector_get_modes(struct drm_connector *connector) > goto out; > } > > - vc4_encoder->hdmi_monitor = connector->display_info.is_hdmi; > - > drm_connector_update_edid_property(connector, edid); > ret = drm_add_edid_modes(connector, edid); > kfree(edid); > @@ -578,13 +574,12 @@ static void vc4_hdmi_set_infoframes(struct drm_encoder *encoder) > static bool vc4_hdmi_supports_scrambling(struct drm_encoder *encoder, > struct drm_display_mode *mode) > { > - struct vc4_hdmi_encoder *vc4_encoder = to_vc4_hdmi_encoder(encoder); > struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder); > struct drm_display_info *display = &vc4_hdmi->connector.display_info; > > lockdep_assert_held(&vc4_hdmi->mutex); > > - if (!vc4_encoder->hdmi_monitor) > + if (!display->is_hdmi) > return false; > > if (!display->hdmi.scdc.supported || > @@ -1147,7 +1142,7 @@ static void vc4_hdmi_encoder_post_crtc_enable(struct drm_encoder *encoder, > { > struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder); > struct drm_display_mode *mode = &vc4_hdmi->saved_adjusted_mode; > - struct vc4_hdmi_encoder *vc4_encoder = to_vc4_hdmi_encoder(encoder); > + struct drm_display_info *display = &vc4_hdmi->connector.display_info; > bool hsync_pos = mode->flags & DRM_MODE_FLAG_PHSYNC; > bool vsync_pos = mode->flags & DRM_MODE_FLAG_PVSYNC; > unsigned long flags; > @@ -1168,7 +1163,7 @@ static void vc4_hdmi_encoder_post_crtc_enable(struct drm_encoder *encoder, > HDMI_WRITE(HDMI_VID_CTL, > HDMI_READ(HDMI_VID_CTL) & ~VC4_HD_VID_CTL_BLANKPIX); > > - if (vc4_encoder->hdmi_monitor) { > + if (display->is_hdmi) { > HDMI_WRITE(HDMI_SCHEDULER_CONTROL, > HDMI_READ(HDMI_SCHEDULER_CONTROL) | > VC4_HDMI_SCHEDULER_CONTROL_MODE_HDMI); > @@ -1195,7 +1190,7 @@ static void vc4_hdmi_encoder_post_crtc_enable(struct drm_encoder *encoder, > "!VC4_HDMI_SCHEDULER_CONTROL_HDMI_ACTIVE\n"); > } > > - if (vc4_encoder->hdmi_monitor) { > + if (display->is_hdmi) { > spin_lock_irqsave(&vc4_hdmi->hw_lock, flags); > > WARN_ON(!(HDMI_READ(HDMI_SCHEDULER_CONTROL) & > diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.h b/drivers/gpu/drm/vc4/vc4_hdmi.h > index 1076faeab616..44977002445f 100644 > --- a/drivers/gpu/drm/vc4/vc4_hdmi.h > +++ b/drivers/gpu/drm/vc4/vc4_hdmi.h > @@ -11,7 +11,6 @@ > /* VC4 HDMI encoder KMS struct */ > struct vc4_hdmi_encoder { > struct vc4_encoder base; > - bool hdmi_monitor; > }; And vc4_hdmi_encoder doesn't hold anything anymore now, so it can be removed as well. Doing it in a subsequent patch would probably be the most readable. Thanks! Maxime [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 228 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-04-19 12:42 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-04-15 15:47 [PATCH v2 0/2] drm/vc4: hdmi: Replace drm_detect_hdmi_monitor() with drm_display_info.is_hdmi José Expósito 2022-04-15 15:47 ` [PATCH v2 1/2] drm/vc4: hdmi: Replace drm_detect_hdmi_monitor() with is_hdmi José Expósito 2022-04-15 15:47 ` [PATCH v2 2/2] drm/vc4: hdmi: Remove vc4_hdmi_encoder.hdmi_monitor José Expósito 2022-04-19 12:41 ` Maxime Ripard
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®