[Intel-gfx] [PATCH 11/22] drm/atomic: Convert private_objs to drm_dynarray
ville.syrjala at linux.intel.com
ville.syrjala at linux.intel.com
Thu Jul 6 20:24:31 UTC 2017
From: Ville Syrjälä <ville.syrjala at linux.intel.com>
state->private_objs grows dynamically, so switch it over to use
the new drm_dynarray helper.
Cc: Dhinakaran Pandiyan <dhinakaran.pandiyan at intel.com>
Signed-off-by: Ville Syrjälä <ville.syrjala at linux.intel.com>
---
drivers/gpu/drm/drm_atomic.c | 64 ++++++++++++++++++++-----------------
drivers/gpu/drm/drm_atomic_helper.c | 2 +-
include/drm/drm_atomic.h | 15 ++++++---
3 files changed, 46 insertions(+), 35 deletions(-)
diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index a61e396b11a8..5eb14c73c0fb 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -57,7 +57,7 @@ void drm_atomic_state_default_release(struct drm_atomic_state *state)
drm_dynarray_fini(&state->connectors);
kfree(state->crtcs);
kfree(state->planes);
- kfree(state->private_objs);
+ drm_dynarray_fini(&state->private_objs);
}
EXPORT_SYMBOL(drm_atomic_state_default_release);
@@ -90,6 +90,8 @@ drm_atomic_state_init(struct drm_device *dev, struct drm_atomic_state *state)
drm_dynarray_init(&state->connectors,
sizeof(struct __drm_connectors_state));
+ drm_dynarray_init(&state->private_objs,
+ sizeof(struct __drm_private_objs_state));
state->dev = dev;
@@ -193,12 +195,14 @@ void drm_atomic_state_default_clear(struct drm_atomic_state *state)
}
for (i = 0; i < state->num_private_objs; i++) {
- void *obj_state = state->private_objs[i].obj_state;
-
- state->private_objs[i].funcs->destroy_state(obj_state);
- state->private_objs[i].obj = NULL;
- state->private_objs[i].obj_state = NULL;
- state->private_objs[i].funcs = NULL;
+ struct __drm_private_objs_state *p =
+ __drm_atomic_state_private_obj(state, i);
+ void *obj_state = p->obj_state;
+
+ p->funcs->destroy_state(obj_state);
+ p->obj = NULL;
+ p->obj_state = NULL;
+ p->funcs = NULL;
}
state->num_private_objs = 0;
@@ -1014,36 +1018,36 @@ void *
drm_atomic_get_private_obj_state(struct drm_atomic_state *state, void *obj,
const struct drm_private_state_funcs *funcs)
{
- int index, num_objs, i;
- size_t size;
- struct __drm_private_objs_state *arr;
-
- for (i = 0; i < state->num_private_objs; i++)
- if (obj == state->private_objs[i].obj)
- return state->private_objs[i].obj_state;
-
- num_objs = state->num_private_objs + 1;
- size = sizeof(*state->private_objs) * num_objs;
- arr = krealloc(state->private_objs, size, GFP_KERNEL);
- if (!arr)
- return ERR_PTR(-ENOMEM);
+ struct __drm_private_objs_state *p;
+ int index = state->num_private_objs;
+ int ret, i;
+
+ for (i = 0; i < state->num_private_objs; i++) {
+ p = __drm_atomic_state_private_obj(state, i);
+
+ if (obj == p->obj)
+ return p->obj_state;
+ }
- state->private_objs = arr;
- index = state->num_private_objs;
- memset(&state->private_objs[index], 0, sizeof(*state->private_objs));
+ ret = drm_dynarray_reserve(&state->private_objs, index);
+ if (ret)
+ return ERR_PTR(ret);
- state->private_objs[index].obj_state = funcs->duplicate_state(state, obj);
- if (!state->private_objs[index].obj_state)
+ p = __drm_atomic_state_private_obj(state, index);
+
+ p->obj_state = funcs->duplicate_state(state, obj);
+ if (!p->obj_state)
return ERR_PTR(-ENOMEM);
- state->private_objs[index].obj = obj;
- state->private_objs[index].funcs = funcs;
- state->num_private_objs = num_objs;
+ p->obj = obj;
+ p->funcs = funcs;
+
+ state->num_private_objs = index + 1;
DRM_DEBUG_ATOMIC("Added new private object state %p to %p\n",
- state->private_objs[index].obj_state, state);
+ p->obj_state, state);
- return state->private_objs[index].obj_state;
+ return p->obj_state;
}
EXPORT_SYMBOL(drm_atomic_get_private_obj_state);
diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c
index 2d747ac35ecf..77b57cdf0460 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -2331,7 +2331,7 @@ void drm_atomic_helper_swap_state(struct drm_atomic_state *state,
}
__for_each_private_obj(state, obj, obj_state, i, funcs)
- funcs->swap_state(obj, &state->private_objs[i].obj_state);
+ funcs->swap_state(obj, &__drm_atomic_state_private_obj(state, i)->obj_state);
}
EXPORT_SYMBOL(drm_atomic_helper_swap_state);
diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h
index 44316ce45fbb..809e8b4c3719 100644
--- a/include/drm/drm_atomic.h
+++ b/include/drm/drm_atomic.h
@@ -229,7 +229,7 @@ struct drm_atomic_state {
int num_connector;
struct drm_dynarray connectors; /* struct __drm_connectors_state [] */;
int num_private_objs;
- struct __drm_private_objs_state *private_objs;
+ struct drm_dynarray private_objs; /* struct __drm_private_objs_state [] */;
struct drm_modeset_acquire_ctx *acquire_ctx;
@@ -249,6 +249,13 @@ __drm_atomic_state_connector(const struct drm_atomic_state *state,
return drm_dynarray_elem(&state->connectors, index);
}
+static inline struct __drm_private_objs_state *
+__drm_atomic_state_private_obj(const struct drm_atomic_state *state,
+ unsigned int index)
+{
+ return drm_dynarray_elem(&state->private_objs, index);
+}
+
void __drm_crtc_commit_free(struct kref *kref);
/**
@@ -832,9 +839,9 @@ void drm_state_dump(struct drm_device *dev, struct drm_printer *p);
#define __for_each_private_obj(__state, obj, obj_state, __i, __funcs) \
for ((__i) = 0; \
(__i) < (__state)->num_private_objs && \
- ((obj) = (__state)->private_objs[__i].obj, \
- (__funcs) = (__state)->private_objs[__i].funcs, \
- (obj_state) = (__state)->private_objs[__i].obj_state, \
+ ((obj) = __drm_atomic_state_private_obj(__state, __i)->obj, \
+ (__funcs) = __drm_atomic_state_private_obj(__state, __i)->funcs, \
+ (obj_state) = __drm_atomic_state_private_obj(__state, __i)->obj_state, \
1); \
(__i)++) \
--
2.13.0
More information about the Intel-gfx
mailing list