Skip to contentSkip to conversation

drm: add plane iterator macros

RFC In review Rob Clark 3 participants 3 messages Nov 21, 2014

Subsystems (2)
lore
Share & tools
lore

Rob Clark

author
#0 lore raw

RFC 1/1 drm: add plane iterator macros

Inspired in part by some cute iterator macros I noticed in i915. I currently have these in drm/msm, but seems like they should be useful for others. Quite possibly other iterators would be useful to add for other drivers.

---
NOTE: to actually merge this, depending on the order this is merged vs drm/msm/mdp5 atomic support, these would have to be removed from msm_kms.h.

 include/drm/drm_crtc.h | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
include/drm/drm_crtc.h +28 -0
index bc1cc3c..5ea46ec 100644
@@ -773,6 +773,34 @@ struct drm_plane {
 	struct drm_plane_state *state;
 };
 
+/* iterate over the planes *currently* attached to a crtc, useful
+ * to apply current state to hw:
+ */
+#define for_each_plane_on_crtc(_crtc, _plane) \
+	list_for_each_entry((_plane), &(_crtc)->dev->mode_config.plane_list, head) \
+		if ((_plane)->state->crtc == (_crtc))
+
+static inline bool
+__plane_will_be_attached_to_crtc(struct drm_atomic_state *state,
+		struct drm_plane *plane, struct drm_crtc *crtc)
+{
+	int idx = drm_plane_index(plane);
+
+	/* if plane is modified in incoming state, use the new state: */
+	if (state->plane_states[idx])
+		return state->plane_states[idx]->crtc == crtc;
+
+	/* otherwise, current state: */
+	return plane->state->crtc == crtc;
+}
+
+/* iterate over the planes that *will be* attached to a crtc,
+ * useful for ->atomic_check() operations:
+ */
+#define for_each_pending_plane_on_crtc(_state, _crtc, _plane) \
+	list_for_each_entry((_plane), &(_crtc)->dev->mode_config.plane_list, head) \
+		if (__plane_will_be_attached_to_crtc((_state), (_plane), (_crtc)))
+
 /**
  * struct drm_bridge_funcs - drm_bridge control functions
  * @mode_fixup: Try to fixup (or reject entirely) proposed mode for this bridge
Signature · 6 lines
1.9.3

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw
Quoted 6 lines · Rob Clark

Inspired in part by some cute iterator macros I noticed in i915. I currently have these in drm/msm, but seems like they should be useful for others. Quite possibly other iterators would be useful to add for other drivers.

Since they are both atomic specific perhaps better to put them into drm_atomic.h? And kerneldoc please ;-)

With that fixed this is Reviewed-by: Daniel Vetter <[email protected]>

Quoted 50 lines

---
NOTE: to actually merge this, depending on the order this is merged vs drm/msm/mdp5 atomic support, these would have to be removed from msm_kms.h.

 include/drm/drm_crtc.h | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
include/drm/drm_crtc.h +28 -0
index bc1cc3c..5ea46ec 100644
@@ -773,6 +773,34 @@ struct drm_plane {
 	struct drm_plane_state *state;
 };
 
+/* iterate over the planes *currently* attached to a crtc, useful
+ * to apply current state to hw:
+ */
+#define for_each_plane_on_crtc(_crtc, _plane) \
+	list_for_each_entry((_plane), &(_crtc)->dev->mode_config.plane_list, head) \
+		if ((_plane)->state->crtc == (_crtc))
+
+static inline bool
+__plane_will_be_attached_to_crtc(struct drm_atomic_state *state,
+		struct drm_plane *plane, struct drm_crtc *crtc)
+{
+	int idx = drm_plane_index(plane);
+
+	/* if plane is modified in incoming state, use the new state: */
+	if (state->plane_states[idx])
+		return state->plane_states[idx]->crtc == crtc;
+
+	/* otherwise, current state: */
+	return plane->state->crtc == crtc;
+}
+
+/* iterate over the planes that *will be* attached to a crtc,
+ * useful for ->atomic_check() operations:
+ */
+#define for_each_pending_plane_on_crtc(_state, _crtc, _plane) \
+	list_for_each_entry((_plane), &(_crtc)->dev->mode_config.plane_list, head) \
+		if (__plane_will_be_attached_to_crtc((_state), (_plane), (_crtc)))
+
 /**
  * struct drm_bridge_funcs - drm_bridge control functions
  * @mode_fixup: Try to fixup (or reject entirely) proposed mode for this bridge
Signature · 1 line
1.9.3
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 1/1
#2 lore raw
In reply to Rob Clark
Quoted 19 lines · Rob Clark

Inspired in part by some cute iterator macros I noticed in i915. I currently have these in drm/msm, but seems like they should be useful for others. Quite possibly other iterators would be useful to add for other drivers.

---
NOTE: to actually merge this, depending on the order this is merged vs drm/msm/mdp5 atomic support, these would have to be removed from msm_kms.h.

 include/drm/drm_crtc.h | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
include/drm/drm_crtc.h +0 -0
index bc1cc3c..5ea46ec 100644

include/drm/drm_crtc.h struct drm_plane { · line 781

Quoted 9 lines
include/drm/drm_crtc.h +6 -0
@@ -773,6 +773,34 @@ struct drm_plane {
 	struct drm_plane_state *state;
 };
 
+/* iterate over the planes *currently* attached to a crtc, useful
+ * to apply current state to hw:
+ */
+#define for_each_plane_on_crtc(_crtc, _plane) \
+	list_for_each_entry((_plane), &(_crtc)->dev->mode_config.plane_list, head) \
+		if ((_plane)->state->crtc == (_crtc))

Perhaps throw in a drm_ prefix (for this and the below iterator). Or maybe rename to something like:

drm_crtc_for_each_plane()

to make the argument list more intuitive?

include/drm/drm_crtc.h struct drm_plane { · line 795

Quoted 13 lines
include/drm/drm_crtc.h +13 -0
+static inline bool
+__plane_will_be_attached_to_crtc(struct drm_atomic_state *state,
+		struct drm_plane *plane, struct drm_crtc *crtc)
+{
+	int idx = drm_plane_index(plane);
+
+	/* if plane is modified in incoming state, use the new state: */
+	if (state->plane_states[idx])
+		return state->plane_states[idx]->crtc == crtc;
+
+	/* otherwise, current state: */
+	return plane->state->crtc == crtc;
+}

Maybe drm_crtc_plane_pending(crtc, state, plane) for somewhat more cohesive naming?

include/drm/drm_crtc.h struct drm_plane { · line 802

Quoted 7 lines
include/drm/drm_crtc.h +7 -0
+
+/* iterate over the planes that *will be* attached to a crtc,
+ * useful for ->atomic_check() operations:
+ */
+#define for_each_pending_plane_on_crtc(_state, _crtc, _plane) \
+	list_for_each_entry((_plane), &(_crtc)->dev->mode_config.plane_list, head) \
+		if (__plane_will_be_attached_to_crtc((_state), (_plane), (_crtc)))

Similarily as for the above, perhaps:

drm_crtc_for_each_pending_plane(_crtc, _state, _plane)

might be more intuitive.

Irrespective of the bike-shedding and with Daniel's comments addressed, this is:

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel