drm: Introduce drm_crtc_index() and drm_crtc_mask()
Subsystems (3)
v3 cover drm: Introduce drm_crtc_index() and drm_crtc_mask()
This series is a continuation of a patch posted earlier by Russell. It addresses some comments from the initial posting as well as from some discussion on IRC.
Patch 2 moves the drm_encoder_crtc_ok() function from the CRTC helpers into the core so that patch 3 can reuse it to get rid of the duplicate implementation in the i915 driver.
Note that I have a pair of patches that rely on this to fix a bug in the Tegra driver that was exposed by the addition of the panel support, so I would like to take these two patches through the Tegra tree.
Thierry
Russell King (1):
drm: provide a helper for the encoder possible_crtcs mask
Thierry Reding (2):
drm: Move drm_encoder_crtc_ok() to core
drm/i915: Use drm_encoder_crtc_ok()
drivers/gpu/drm/drm_crtc.c | 23 +++++++++++++++++++++++ drivers/gpu/drm/drm_crtc_helper.c | 29 ----------------------------- drivers/gpu/drm/i915/intel_display.c | 26 ++------------------------ include/drm/drm_crtc.h | 26 ++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 53 deletions(-)
Signature · 1 line
1.8.4.2
PATCH v3 1/3 drm: provide a helper for the encoder possible_crtcs mask
From: Russell King <[email protected]>
The encoder possible_crtcs mask identifies which CRTCs can be bound to a particular encoder. Each bit from bit 0 defines an index in the list of CRTCs held in the DRM mode_config crtc_list. Rather than having drivers trying to track the position of their CRTCs in the list, expose the code which already exists for calculating the appropriate mask bit for a CRTC.
---
Changes in v3:
- move drm_crtc_mask() into include/drm/drm_crtc.h and make it static inline as suggested by Russell King
- BUG() instead of returning -1 if a CRTC isn't registered (David Herrmann)
- drop WARN(!crtc, "...") since code will oops anyway (Jani Nikula)
Changes in v2:
- further extract a new drm_crtc_index() function
- move to DRM core (drm_crtc.c)
drivers/gpu/drm/drm_crtc.c | 23 +++++++++++++++++++++++ drivers/gpu/drm/drm_crtc_helper.c | 18 +----------------- include/drm/drm_crtc.h | 13 +++++++++++++ 3 files changed, 37 insertions(+), 17 deletions(-)
drivers/gpu/drm/drm_crtc.c +23 -0
@@ -675,6 +675,29 @@ void drm_crtc_cleanup(struct drm_crtc *crtc)EXPORT_SYMBOL (drm_crtc_cleanup);/** +* drm_crtc_index - find the index of a registered CRTC +* @crtc: CRTC to find index for +* +* Given a registered CRTC, return the index of that CRTC within a DRM +* device's list of CRTCs. +*/ +unsigned int drm_crtc_index (struct drm_crtc *crtc) +{ +unsigned int index =0 ; +struct drm_crtc *tmp; + +list_for_each_entry (tmp, &crtc->dev->mode_config.crtc_list, head) { +if (tmp == crtc) +return index; + + index++; + } + +BUG (); +} +EXPORT_SYMBOL (drm_crtc_index); + +/** * drm_mode_probed_add - add a mode to a connector's probed mode list * @connector: connector the new mode * @mode: mode data
drivers/gpu/drm/drm_crtc_helper.c +1 -17
@@ -334,23 +334,7 @@ EXPORT_SYMBOL(drm_helper_disable_unused_functions);static bool drm_encoder_crtc_ok (struct drm_encoder *encoder,struct drm_crtc *crtc) { -struct drm_device *dev; -struct drm_crtc *tmp; -int crtc_mask =1 ; - -WARN (!crtc,"checking null crtc?\n" ); - - dev = crtc->dev; - -list_for_each_entry (tmp, &dev->mode_config.crtc_list, head) { -if (tmp == crtc) -break ; - crtc_mask <<=1 ; - } - -if (encoder->possible_crtcs & crtc_mask) -return true; -return false; +return !!(encoder->possible_crtcs &drm_crtc_mask (crtc)); }/*
include/drm/drm_crtc.h +13 -0
@@ -929,6 +929,19 @@ extern int drm_crtc_init(struct drm_device *dev,struct drm_crtc *crtc, const struct drm_crtc_funcs *funcs);extern void drm_crtc_cleanup (struct drm_crtc *crtc); +extern unsigned int drm_crtc_index (struct drm_crtc *crtc); + +/** +* drm_crtc_mask - find the mask of a registered CRTC +* @crtc: CRTC to find mask for +* +* Given a registered CRTC, return the mask bit of that CRTC for an +* encoder's possible_crtcs field. +*/ +static inline uint32_t drm_crtc_mask (struct drm_crtc *crtc) +{ +return 1 <<drm_crtc_index (crtc); +}extern void drm_connector_ida_init (void );extern void drm_connector_ida_destroy (void );
Signature · 1 line
1.8.4.2
PATCH v3 2/3 drm: Move drm_encoder_crtc_ok() to core
In reply to Thierry RedingUsing the new drm_crtc_mask() function, drm_encoder_crtc_ok() can now be written in a significantly shorter way, so it can be moved to a header file and be made static inline.
---
Changes in v3:
- new patch
drivers/gpu/drm/drm_crtc_helper.c | 13 ------------- include/drm/drm_crtc.h | 13 +++++++++++++ 2 files changed, 13 insertions(+), 13 deletions(-)
drivers/gpu/drm/drm_crtc_helper.c +0 -13
@@ -324,19 +324,6 @@ void drm_helper_disable_unused_functions(struct drm_device *dev) }EXPORT_SYMBOL (drm_helper_disable_unused_functions); -/** -* drm_encoder_crtc_ok - can a given crtc drive a given encoder? -* @encoder: encoder to test -* @crtc: crtc to test -* -* Return false if @encoder can't be driven by @crtc, true otherwise. -*/ -static bool drm_encoder_crtc_ok (struct drm_encoder *encoder, -struct drm_crtc *crtc) -{ -return !!(encoder->possible_crtcs &drm_crtc_mask (crtc)); -} -/* * Check the CRTC we're going to map each output to vs. its current * CRTC. If they don't match, we have to disable the output and the CRTC
include/drm/drm_crtc.h +13 -0
@@ -963,6 +963,19 @@ extern int drm_encoder_init(struct drm_device *dev,const struct drm_encoder_funcs *funcs, int encoder_type); +/** +* drm_encoder_crtc_ok - can a given crtc drive a given encoder? +* @encoder: encoder to test +* @crtc: crtc to test +* +* Return false if @encoder can't be driven by @crtc, true otherwise. +*/ +static inline bool drm_encoder_crtc_ok (struct drm_encoder *encoder, +struct drm_crtc *crtc) +{ +return !!(encoder->possible_crtcs &drm_crtc_mask (crtc)); +} + extern int drm_plane_init(struct drm_device *dev, struct drm_plane *plane, unsigned long possible_crtcs,
Signature · 1 line
1.8.4.2
PATCH v3 3/3 drm/i915: Use drm_encoder_crtc_ok()
In reply to Thierry RedingThe intel_encoder_crtc_ok() is a duplicate of the drm_encoder_crtc_ok() function that used to be only available in the DRM CRTC helpers. It has recently been moved to the core, so the duplicate can now be dropped.
---
Changes in v3:
- replace intel_encoder_crtc_ok() by drm_encoder_crtc_ok()
drivers/gpu/drm/i915/intel_display.c | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-)
drivers/gpu/drm/i915/intel_display.c +2 -24
@@ -8720,28 +8720,6 @@ static struct drm_crtc_helper_funcs intel_helper_funcs = { .load_lut = intel_crtc_load_lut, }; -static bool intel_encoder_crtc_ok (struct drm_encoder *encoder, -struct drm_crtc *crtc) -{ -struct drm_device *dev; -struct drm_crtc *tmp; -int crtc_mask =1 ; - -WARN (!crtc,"checking null crtc?\n" ); - - dev = crtc->dev; - -list_for_each_entry (tmp, &dev->mode_config.crtc_list, head) { -if (tmp == crtc) -break ; - crtc_mask <<=1 ; - } - -if (encoder->possible_crtcs & crtc_mask) -return true; -return false; -} -/** * intel_modeset_update_staged_output_state *
@@ -9923,8 +9901,8 @@ intel_modeset_stage_output_state(struct drm_device *dev, }/* Make sure the new CRTC will work with the encoder */ -if (!intel_encoder_crtc_ok (&connector->new_encoder->base, - new_crtc)) { +if (!drm_encoder_crtc_ok (&connector->new_encoder->base, + new_crtc)) {return -EINVAL ; } connector->encoder->new_crtc =to_intel_crtc (new_crtc);
Signature · 1 line
1.8.4.2
Re: [PATCH v3 3/3] drm/i915: Use drm_encoder_crtc_ok()
Quoted 6 lines · Thierry Reding
The
intel_encoder_crtc_ok()is a duplicate of thedrm_encoder_crtc_ok()function that used to be only available in the DRM CRTC helpers. It has recently been moved to the core, so the duplicate can now be dropped.Acked-by Daniel Vetter <[email protected]>Signed-off-by Thierry Reding <[email protected]>
Quoted 54 lines
---
Changes in v3:
- replaceintel_encoder_crtc_ok()bydrm_encoder_crtc_ok()drivers/gpu/drm/i915/intel_display.c | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-)drivers/gpu/drm/i915/intel_display.c +2
-24@@ -8720,28 +8720,6 @@ static struct drm_crtc_helper_funcs intel_helper_funcs = { .load_lut = intel_crtc_load_lut, }; -static bool intel_encoder_crtc_ok (struct drm_encoder *encoder, -struct drm_crtc *crtc) -{ -struct drm_device *dev; -struct drm_crtc *tmp; -int crtc_mask =1 ; - -WARN (!crtc,"checking null crtc?\n" ); - - dev = crtc->dev; - -list_for_each_entry (tmp, &dev->mode_config.crtc_list, head) { -if (tmp == crtc) -break ; - crtc_mask <<=1 ; - } - -if (encoder->possible_crtcs & crtc_mask) -return true; -return false; -} -/** * intel_modeset_update_staged_output_state * @@ -9923,8 +9901,8 @@ intel_modeset_stage_output_state(struct drm_device *dev, }/* Make sure the new CRTC will work with the encoder */ -if (!intel_encoder_crtc_ok (&connector->new_encoder->base, - new_crtc)) { +if (!drm_encoder_crtc_ok (&connector->new_encoder->base, + new_crtc)) {return -EINVAL ; } connector->encoder->new_crtc =to_intel_crtc (new_crtc);Signature · 1 line
1.8.4.2
Signature · 1 line
Jani Nikula, Intel Open Source Technology Center