Skip to contentSkip to conversation

drm: Introduce drm_crtc_index() and drm_crtc_mask()

PATCH Superseded Thierry Reding 4 participants 9 messages Jan 13, 2014

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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 makes use of the new functions to replace an open-coded version in the i915 driver, as suggested by David Herrmann. I've left David's Reviewed-by in place on patch 1 since it didn't change fundamentally.

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 (1):
drm/i915: Use drm_crtc_mask() helper

 drivers/gpu/drm/drm_crtc.c           | 38 ++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_crtc_helper.c    | 16 +++------------
 drivers/gpu/drm/i915/intel_display.c | 16 +--------------
 include/drm/drm_crtc.h               |  2 ++
 4 files changed, 44 insertions(+), 28 deletions(-)
Signature · 1 line
1.8.4.2
#1 lore raw

PATCH 1/2 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 v2:
- further extract a new drm_crtc_index() function
- move to DRM core (drm_crtc.c)

 drivers/gpu/drm/drm_crtc.c        | 38 ++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_crtc_helper.c | 16 +++-------------
 include/drm/drm_crtc.h            |  2 ++
 3 files changed, 43 insertions(+), 13 deletions(-)
drivers/gpu/drm/drm_crtc.c +38 -0
index 266a01d7f635..fdfa5a0e51d6 100644
@@ -675,6 +675,44 @@ 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. If the CRTC isn't registered, return -1.
+ */
+int drm_crtc_index(struct drm_crtc *crtc)
+{
+	struct drm_crtc *tmp;
+	int index = 0;
+
+	list_for_each_entry(tmp, &crtc->dev->mode_config.crtc_list, head) {
+		if (tmp == crtc)
+			return index;
+
+		index++;
+	}
+
+	return -1;
+}
+EXPORT_SYMBOL(drm_crtc_index);
+
+/**
+ * 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.
+ */
+uint32_t drm_crtc_mask(struct drm_crtc *crtc)
+{
+	int i = drm_crtc_index(crtc);
+
+	return i < 0 ? 0 : 1 << i;
+}
+EXPORT_SYMBOL(drm_crtc_mask);
+
+/**
  * 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 +3 -13
index 01361aba033b..95b32098badf 100644
@@ -334,23 +334,13 @@ 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;
+	uint32_t crtc_mask;
 
 	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;
-	}
+	crtc_mask = drm_crtc_mask(crtc);
 
-	if (encoder->possible_crtcs & crtc_mask)
-		return true;
-	return false;
+	return !!(encoder->possible_crtcs & crtc_mask);
 }
 
 /*
include/drm/drm_crtc.h +2 -0
index f32c5cd51f41..a61fb73fdcb5 100644
@@ -929,6 +929,8 @@ 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 int drm_crtc_index(struct drm_crtc *crtc);
+extern uint32_t drm_crtc_mask(struct drm_crtc *crtc);
 
 extern void drm_connector_ida_init(void);
 extern void drm_connector_ida_destroy(void);
Signature · 1 line
1.8.4.2
#8 lore raw

PATCH 2/2 drm/i915: Use drm_crtc_mask() helper

In reply to Thierry Reding

Replace an open-coded occurrence by a call to the new drm_crtc_mask() helper.

---
 drivers/gpu/drm/i915/intel_display.c | 16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)
drivers/gpu/drm/i915/intel_display.c +1 -15
index e77d4b8856a7..807feab38ea6 100644
@@ -8723,21 +8723,7 @@ static struct drm_crtc_helper_funcs intel_helper_funcs = {
 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)
+	if (encoder->possible_crtcs & drm_crtc_mask(crtc))
 		return true;
 	return false;
 }
Signature · 1 line
1.8.4.2
#2 lore raw

Re: [PATCH 1/2] drm: provide a helper for the encoder possible_crtcs mask

In reply to Thierry Reding

Hi

Quoted 40 lines · Thierry Reding

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 v2:
- further extract a new drm_crtc_index() function
- move to DRM core (drm_crtc.c)

 drivers/gpu/drm/drm_crtc.c        | 38 ++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_crtc_helper.c | 16 +++-------------
 include/drm/drm_crtc.h            |  2 ++
 3 files changed, 43 insertions(+), 13 deletions(-)
drivers/gpu/drm/drm_crtc.c +9 -0
index 266a01d7f635..fdfa5a0e51d6 100644
@@ -675,6 +675,44 @@ 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. If the CRTC isn't registered, return -1.
+ */
+int drm_crtc_index(struct drm_crtc *crtc)
+{
+       struct drm_crtc *tmp;

drivers/gpu/drm/drm_crtc.c void drm_crtc_cleanup(struct drm_crtc *crtc) · line 696

Quoted 10 lines
drivers/gpu/drm/drm_crtc.c +10 -0
+       int index = 0;
+
+       list_for_each_entry(tmp, &crtc->dev->mode_config.crtc_list, head) {
+               if (tmp == crtc)
+                       return index;
+
+               index++;
+       }
+
+       return -1;

Does that -1 ever make sense? We don't support mode-object-hotplugging so all "drm_crtc" objects are known at initialization time. I'd rather put a BUG() here than a silent -1. This also makes drm_crtc_mask() redundant.

Anyhow, still r-b by me.

Thanks
David

Quoted 69 lines
drivers/gpu/drm/drm_crtc.c +19 -0
+}
+EXPORT_SYMBOL(drm_crtc_index);
+
+/**
+ * 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.
+ */
+uint32_t drm_crtc_mask(struct drm_crtc *crtc)
+{
+       int i = drm_crtc_index(crtc);
+
+       return i < 0 ? 0 : 1 << i;
+}
+EXPORT_SYMBOL(drm_crtc_mask);
+
+/**
  * 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 +3 -13
index 01361aba033b..95b32098badf 100644
@@ -334,23 +334,13 @@ 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;
+       uint32_t crtc_mask;
 
        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;
-       }
+       crtc_mask = drm_crtc_mask(crtc);
 
-       if (encoder->possible_crtcs & crtc_mask)
-               return true;
-       return false;
+       return !!(encoder->possible_crtcs & crtc_mask);
 }
 
 /*
include/drm/drm_crtc.h +2 -1
index f32c5cd51f41..a61fb73fdcb5 100644
@@ -929,6 +929,8 @@ 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 int drm_crtc_index(struct drm_crtc *crtc);
+extern uint32_t drm_crtc_mask(struct drm_crtc *crtc);
 
 extern void drm_connector_ida_init(void);
 extern void drm_connector_ida_destroy(void);
--

1.8.4.2

#3 lore raw

Re: [PATCH 1/2] drm: provide a helper for the encoder possible_crtcs mask

Quoted 4 lines · David Herrmann

Does that -1 ever make sense? We don't support mode-object-hotplugging so all "drm_crtc" objects are known at initialization time. I'd rather put a BUG() here than a silent -1. This also makes drm_crtc_mask() redundant.

I disagree with that last statement. drm_crtc_mask() is still useful for converting to the mask, rather than having that open coded all over the place. It probably makes more sense for drm_crtc_mask() to become a helper in a header file though.

Signature · 3 lines
FTTC broadband for 0.8mile line: 5.8Mbps down 500kbps up.  Estimation
in database were 13.1 to 19Mbit for a good line, about 7.5+ for a bad.
Estimate before purchase was "up to 13.2Mbit".
maintainer Reviewed-by on v1 1/2
#7 lore raw

Re: [PATCH 1/2] drm: provide a helper for the encoder possible_crtcs mask

In reply to Thierry Reding
Quoted 40 lines · Thierry Reding

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 v2:
- further extract a new drm_crtc_index() function
- move to DRM core (drm_crtc.c)

 drivers/gpu/drm/drm_crtc.c        | 38 ++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_crtc_helper.c | 16 +++-------------
 include/drm/drm_crtc.h            |  2 ++
 3 files changed, 43 insertions(+), 13 deletions(-)
drivers/gpu/drm/drm_crtc.c +9 -0
index 266a01d7f635..fdfa5a0e51d6 100644
@@ -675,6 +675,44 @@ 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. If the CRTC isn't registered, return -1.
+ */
+int drm_crtc_index(struct drm_crtc *crtc)
+{
+	struct drm_crtc *tmp;

drivers/gpu/drm/drm_crtc.c void drm_crtc_cleanup(struct drm_crtc *crtc) · line 696

Quoted 10 lines
drivers/gpu/drm/drm_crtc.c +10 -0
+	int index = 0;
+
+	list_for_each_entry(tmp, &crtc->dev->mode_config.crtc_list, head) {
+		if (tmp == crtc)
+			return index;
+
+		index++;
+	}
+
+	return -1;

I share David's opinion of using BUG() here.

Quoted 27 lines
drivers/gpu/drm/drm_crtc.c +19 -0
+}
+EXPORT_SYMBOL(drm_crtc_index);
+
+/**
+ * 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.
+ */
+uint32_t drm_crtc_mask(struct drm_crtc *crtc)
+{
+	int i = drm_crtc_index(crtc);
+
+	return i < 0 ? 0 : 1 << i;
+}
+EXPORT_SYMBOL(drm_crtc_mask);
+
+/**
  * 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 +0 -0
index 01361aba033b..95b32098badf 100644

drivers/gpu/drm/drm_crtc_helper.c EXPORT_SYMBOL(drm_helper_disable_unused_functions); · line 339

Quoted 9 lines
drivers/gpu/drm/drm_crtc_helper.c +1 -3
@@ -334,23 +334,13 @@ 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;
+	uint32_t crtc_mask;
 
 	WARN(!crtc, "checking null crtc?\n");

You could drop this while at it, the code will neatly oops a moment later anyway if crtc == NULL.

Otherwise, both patches are

Quoted 37 lines
drivers/gpu/drm/drm_crtc_helper.c +2 -10
-	dev = crtc->dev;
-
-	list_for_each_entry(tmp, &dev->mode_config.crtc_list, head) {
-		if (tmp == crtc)
-			break;
-		crtc_mask <<= 1;
-	}
+	crtc_mask = drm_crtc_mask(crtc);
 
-	if (encoder->possible_crtcs & crtc_mask)
-		return true;
-	return false;
+	return !!(encoder->possible_crtcs & crtc_mask);
 }
 
 /*
include/drm/drm_crtc.h +2 -0
index f32c5cd51f41..a61fb73fdcb5 100644
@@ -929,6 +929,8 @@ 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 int drm_crtc_index(struct drm_crtc *crtc);
+extern uint32_t drm_crtc_mask(struct drm_crtc *crtc);
 
 extern void drm_connector_ida_init(void);
 extern void drm_connector_ida_destroy(void);
Signature · 6 lines
1.8.4.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 1 line
Jani Nikula, Intel Open Source Technology Center
#4 lore raw

Re: [PATCH 1/2] drm: provide a helper for the encoder possible_crtcs mask

In reply to Russell King - ARM Linux

Hi Russel

Quoted 10 lines · Russell King - ARM Linux
Quoted 4 lines · David Herrmann

Does that -1 ever make sense? We don't support mode-object-hotplugging so all "drm_crtc" objects are known at initialization time. I'd rather put a BUG() here than a silent -1. This also makes drm_crtc_mask() redundant.

I disagree with that last statement. drm_crtc_mask() is still useful for converting to the mask, rather than having that open coded all over the place. It probably makes more sense for drm_crtc_mask() to become a helper in a header file though.

Thierry renamed your helper to drm_crtc_index() and added drm_crtc_mask(). If we remove the -1, drm_crtc_mask() is redundant as it just calls drm_crtc_index(). So I cannot follow what you mean by "open coded all over the place". I guess you were talking about drm_crtc_index()?

Thanks
David

#5 lore raw

Re: [PATCH 1/2] drm: provide a helper for the encoder possible_crtcs mask

Quoted 15 lines · David Herrmann

Hi Russel

Quoted 10 lines · Russell King - ARM Linux
Quoted 4 lines · David Herrmann

Does that -1 ever make sense? We don't support mode-object-hotplugging so all "drm_crtc" objects are known at initialization time. I'd rather put a BUG() here than a silent -1. This also makes drm_crtc_mask() redundant.

I disagree with that last statement. drm_crtc_mask() is still useful for converting to the mask, rather than having that open coded all over the place. It probably makes more sense for drm_crtc_mask() to become a helper in a header file though.

Quoted 5 lines

Thierry renamed your helper to drm_crtc_index() and added drm_crtc_mask(). If we remove the -1, drm_crtc_mask() is redundant as it just calls drm_crtc_index(). So I cannot follow what you mean by "open coded all over the place". I guess you were talking about drm_crtc_index()?

+uint32_t drm_crtc_mask(struct drm_crtc *crtc)
+{
+ int i = drm_crtc_index(crtc);
+
+ return i < 0 ? 0 : 1 << i;
+}
+EXPORT_SYMBOL(drm_crtc_mask);

When drm_crtc_index() no longer returns negative numbers, this becomes:

+uint32_t drm_crtc_mask(struct drm_crtc *crtc)
+{
+ return 1 << drm_crtc_index(crtc);
+}
+EXPORT_SYMBOL(drm_crtc_mask);

Notice the conversion from an index returned by drm_crtc_index() to a bitmask.

Signature · 3 lines
FTTC broadband for 0.8mile line: 5.8Mbps down 500kbps up.  Estimation
in database were 13.1 to 19Mbit for a good line, about 7.5+ for a bad.
Estimate before purchase was "up to 13.2Mbit".
#6 lore raw

Re: [PATCH 1/2] drm: provide a helper for the encoder possible_crtcs mask

Hi

Quoted 38 lines · Russell King - ARM Linux
Quoted 20 lines · David Herrmann

Hi Russel

Quoted 10 lines · Russell King - ARM Linux
Quoted 4 lines · David Herrmann

Does that -1 ever make sense? We don't support mode-object-hotplugging so all "drm_crtc" objects are known at initialization time. I'd rather put a BUG() here than a silent -1. This also makes drm_crtc_mask() redundant.

I disagree with that last statement. drm_crtc_mask() is still useful for converting to the mask, rather than having that open coded all over the place. It probably makes more sense for drm_crtc_mask() to become a helper in a header file though.

Thierry renamed your helper to drm_crtc_index() and added drm_crtc_mask(). If we remove the -1, drm_crtc_mask() is redundant as it just calls drm_crtc_index(). So I cannot follow what you mean by "open coded all over the place". I guess you were talking about drm_crtc_index()?

drivers/gpu/drm/drm_crtc.c +7 -0
+uint32_t drm_crtc_mask(struct drm_crtc *crtc)
+{
+       int i = drm_crtc_index(crtc);
+
+       return i < 0 ? 0 : 1 << i;
+}
+EXPORT_SYMBOL(drm_crtc_mask);

When drm_crtc_index() no longer returns negative numbers, this becomes:

drivers/gpu/drm/drm_crtc.c +5 -0
+uint32_t drm_crtc_mask(struct drm_crtc *crtc)
+{
+       return 1 << drm_crtc_index(crtc);
+}
+EXPORT_SYMBOL(drm_crtc_mask);
Quoted 2 lines

Notice the conversion from an index returned by drm_crtc_index() to a bitmask.

Oops, missed that, sorry for the noise.