[PATCH 09/22] drm/atomic: Convert state->connectors to drm_dynarray

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Ville Syrjälä <ville.syrjala@xxxxxxxxxxxxxxx>

state->connectors[] can grows dynamically, so we can switch over to
using the new drm_dynarray.

Signed-off-by: Ville Syrjälä <ville.syrjala@xxxxxxxxxxxxxxx>
---
 drivers/gpu/drm/drm_atomic.c        | 49 +++++++++++++++++++------------------
 drivers/gpu/drm/drm_atomic_helper.c |  4 +--
 include/drm/drm_atomic.h            | 42 ++++++++++++++++++-------------
 3 files changed, 52 insertions(+), 43 deletions(-)

diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index 09ca662fcd35..1663ec3626a1 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -28,6 +28,7 @@
 
 #include <drm/drmP.h>
 #include <drm/drm_atomic.h>
+#include <drm/drm_dynarray.h>
 #include <drm/drm_mode.h>
 #include <drm/drm_print.h>
 #include <linux/sync_file.h>
@@ -53,7 +54,7 @@ EXPORT_SYMBOL(__drm_crtc_commit_free);
  */
 void drm_atomic_state_default_release(struct drm_atomic_state *state)
 {
-	kfree(state->connectors);
+	drm_dynarray_fini(&state->connectors);
 	kfree(state->crtcs);
 	kfree(state->planes);
 	kfree(state->private_objs);
@@ -87,6 +88,9 @@ drm_atomic_state_init(struct drm_device *dev, struct drm_atomic_state *state)
 	if (!state->planes)
 		goto fail;
 
+	drm_dynarray_init(&state->connectors,
+			  sizeof(struct __drm_connectors_state));
+
 	state->dev = dev;
 
 	DRM_DEBUG_ATOMIC("Allocated atomic state %p\n", state);
@@ -142,15 +146,17 @@ void drm_atomic_state_default_clear(struct drm_atomic_state *state)
 	DRM_DEBUG_ATOMIC("Clearing atomic state %p\n", state);
 
 	for (i = 0; i < state->num_connector; i++) {
-		struct drm_connector *connector = state->connectors[i].ptr;
+		struct __drm_connectors_state *c =
+			__drm_atomic_state_connector(state, i);
+		struct drm_connector *connector = c->ptr;
 
 		if (!connector)
 			continue;
 
 		connector->funcs->atomic_destroy_state(connector,
-						       state->connectors[i].state);
-		state->connectors[i].ptr = NULL;
-		state->connectors[i].state = NULL;
+						       c->state);
+		c->ptr = NULL;
+		c->state = NULL;
 		drm_connector_put(connector);
 	}
 
@@ -1064,6 +1070,7 @@ drm_atomic_get_connector_state(struct drm_atomic_state *state,
 	int ret, index;
 	struct drm_mode_config *config = &connector->dev->mode_config;
 	struct drm_connector_state *connector_state;
+	struct __drm_connectors_state *c;
 
 	WARN_ON(!state->acquire_ctx);
 
@@ -1073,35 +1080,29 @@ drm_atomic_get_connector_state(struct drm_atomic_state *state,
 
 	index = drm_connector_index(connector);
 
-	if (index >= state->num_connector) {
-		struct __drm_connnectors_state *c;
-		int alloc = max(index + 1, config->num_connector);
-
-		c = krealloc(state->connectors, alloc * sizeof(*state->connectors), GFP_KERNEL);
-		if (!c)
-			return ERR_PTR(-ENOMEM);
-
-		state->connectors = c;
-		memset(&state->connectors[state->num_connector], 0,
-		       sizeof(*state->connectors) * (alloc - state->num_connector));
+	ret = drm_dynarray_reserve(&state->connectors,
+				   max(index, config->num_connector - 1));
+	if (ret)
+		return ERR_PTR(ret);
 
-		state->num_connector = alloc;
-	}
+	c = __drm_atomic_state_connector(state, index);
 
-	if (state->connectors[index].state)
-		return state->connectors[index].state;
+	if (c->state)
+		return c->state;
 
 	connector_state = connector->funcs->atomic_duplicate_state(connector);
 	if (!connector_state)
 		return ERR_PTR(-ENOMEM);
 
 	drm_connector_get(connector);
-	state->connectors[index].state = connector_state;
-	state->connectors[index].old_state = connector->state;
-	state->connectors[index].new_state = connector_state;
-	state->connectors[index].ptr = connector;
+	c->state = connector_state;
+	c->old_state = connector->state;
+	c->new_state = connector_state;
+	c->ptr = connector;
 	connector_state->state = state;
 
+	state->num_connector = state->connectors.num_elems;
+
 	DRM_DEBUG_ATOMIC("Added [CONNECTOR:%d:%s] %p state to %p\n",
 			 connector->base.id, connector->name,
 			 connector_state, state);
diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c
index 667ec97d4efb..2d747ac35ecf 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -2297,7 +2297,7 @@ void drm_atomic_helper_swap_state(struct drm_atomic_state *state,
 		old_conn_state->state = state;
 		new_conn_state->state = NULL;
 
-		state->connectors[i].state = old_conn_state;
+		__drm_atomic_state_connector(state, i)->state = old_conn_state;
 		connector->state = new_conn_state;
 	}
 
@@ -2871,7 +2871,7 @@ int drm_atomic_helper_commit_duplicated_state(struct drm_atomic_state *state,
 		state->crtcs[i].old_state = crtc->state;
 
 	for_each_new_connector_in_state(state, connector, new_conn_state, i)
-		state->connectors[i].old_state = connector->state;
+		__drm_atomic_state_connector(state, i)->old_state = connector->state;
 
 	return drm_atomic_commit(state);
 }
diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h
index dcc8e0cdb7ff..44316ce45fbb 100644
--- a/include/drm/drm_atomic.h
+++ b/include/drm/drm_atomic.h
@@ -29,6 +29,7 @@
 #define DRM_ATOMIC_H_
 
 #include <drm/drm_crtc.h>
+#include <drm/drm_dynarray.h>
 
 /**
  * struct drm_crtc_commit - track modeset commits on a CRTC
@@ -149,7 +150,7 @@ struct __drm_crtcs_state {
 	unsigned last_vblank_count;
 };
 
-struct __drm_connnectors_state {
+struct __drm_connectors_state {
 	struct drm_connector *ptr;
 	struct drm_connector_state *state, *old_state, *new_state;
 };
@@ -226,7 +227,7 @@ struct drm_atomic_state {
 	struct __drm_planes_state *planes;
 	struct __drm_crtcs_state *crtcs;
 	int num_connector;
-	struct __drm_connnectors_state *connectors;
+	struct drm_dynarray connectors; /* struct __drm_connectors_state [] */;
 	int num_private_objs;
 	struct __drm_private_objs_state *private_objs;
 
@@ -241,6 +242,13 @@ struct drm_atomic_state {
 	struct work_struct commit_work;
 };
 
+static inline struct __drm_connectors_state *
+__drm_atomic_state_connector(const struct drm_atomic_state *state,
+			     unsigned int index)
+{
+	return drm_dynarray_elem(&state->connectors, index);
+}
+
 void __drm_crtc_commit_free(struct kref *kref);
 
 /**
@@ -441,7 +449,7 @@ drm_atomic_get_existing_connector_state(struct drm_atomic_state *state,
 	if (index >= state->num_connector)
 		return NULL;
 
-	return state->connectors[index].state;
+	return __drm_atomic_state_connector(state, index)->state;
 }
 
 /**
@@ -461,7 +469,7 @@ drm_atomic_get_old_connector_state(struct drm_atomic_state *state,
 	if (index >= state->num_connector)
 		return NULL;
 
-	return state->connectors[index].old_state;
+	return __drm_atomic_state_connector(state, index)->old_state;
 }
 
 /**
@@ -481,7 +489,7 @@ drm_atomic_get_new_connector_state(struct drm_atomic_state *state,
 	if (index >= state->num_connector)
 		return NULL;
 
-	return state->connectors[index].new_state;
+	return __drm_atomic_state_connector(state, index)->new_state;
 }
 
 /**
@@ -573,9 +581,9 @@ void drm_state_dump(struct drm_device *dev, struct drm_printer *p);
  */
 #define for_each_connector_in_state(__state, connector, connector_state, __i) \
 	for ((__i) = 0;							\
-	     (__i) < (__state)->num_connector &&				\
-	     ((connector) = (__state)->connectors[__i].ptr,			\
-	     (connector_state) = (__state)->connectors[__i].state, 1); 	\
+	     (__i) < (__state)->num_connector &&			\
+		     ((connector) = __drm_atomic_state_connector(__state, __i)->ptr, \
+		      (connector_state) = __drm_atomic_state_connector(__state, __i)->state, 1); \
 	     (__i)++)							\
 		for_each_if (connector)
 
@@ -595,10 +603,10 @@ void drm_state_dump(struct drm_device *dev, struct drm_printer *p);
  */
 #define for_each_oldnew_connector_in_state(__state, connector, old_connector_state, new_connector_state, __i) \
 	for ((__i) = 0;								\
-	     (__i) < (__state)->num_connector &&				\
-	     ((connector) = (__state)->connectors[__i].ptr,			\
-	     (old_connector_state) = (__state)->connectors[__i].old_state,	\
-	     (new_connector_state) = (__state)->connectors[__i].new_state, 1); 	\
+	     (__i) < (__state)->num_connector &&			\
+		     ((connector) = __drm_atomic_state_connector(__state, __i)->ptr, \
+		      (old_connector_state) = __drm_atomic_state_connector(__state, __i)->old_state, \
+		      (new_connector_state) = __drm_atomic_state_connector(__state, __i)->new_state, 1); \
 	     (__i)++)							\
 		for_each_if (connector)
 
@@ -616,9 +624,9 @@ void drm_state_dump(struct drm_device *dev, struct drm_printer *p);
  */
 #define for_each_old_connector_in_state(__state, connector, old_connector_state, __i) \
 	for ((__i) = 0;								\
-	     (__i) < (__state)->num_connector &&				\
-	     ((connector) = (__state)->connectors[__i].ptr,			\
-	     (old_connector_state) = (__state)->connectors[__i].old_state, 1); 	\
+	     (__i) < (__state)->num_connector &&			\
+		     ((connector) = __drm_atomic_state_connector(__state, __i)->ptr, \
+		      (old_connector_state) = __drm_atomic_state_connector(__state, __i)->old_state, 1); \
 	     (__i)++)							\
 		for_each_if (connector)
 
@@ -637,8 +645,8 @@ void drm_state_dump(struct drm_device *dev, struct drm_printer *p);
 #define for_each_new_connector_in_state(__state, connector, new_connector_state, __i) \
 	for ((__i) = 0;								\
 	     (__i) < (__state)->num_connector &&				\
-	     ((connector) = (__state)->connectors[__i].ptr,			\
-	     (new_connector_state) = (__state)->connectors[__i].new_state, 1); 	\
+		     ((connector) = __drm_atomic_state_connector(__state, __i)->ptr, \
+		      (new_connector_state) = __drm_atomic_state_connector(__state, __i)->new_state, 1); \
 	     (__i)++)							\
 		for_each_if (connector)
 
-- 
2.13.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/intel-gfx




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]
  Powered by Linux