drm/atomic: Make private objs proper objects

Make the atomic private object stuff less special by introducing proper
base classes for the object and its state. Drivers can embed these in
their own appropriate objects, after which these things will work
exactly like the plane/crtc/connector states during atomic operations.

v2: Reorder to not depend on drm_dynarray (Daniel)

Change-Id: I475f3c46440934b8d6f461935b6413624b7d34c7
Cc: Dhinakaran Pandiyan <dhinakaran.pandiyan@intel.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> #v1
Signed-off-by: Ville Syrj?l? <ville.syrjala@linux.intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20170712155102.26276-3-ville.syrjala@linux.intel.com
Signed-off-by: Ao Xu <ao.xu@amlogic.com>
This commit is contained in:
Ville Syrjälä
2017-07-12 18:51:02 +03:00
committed by Luke Go
parent 0fd3ffc68f
commit 0899d02319
4 changed files with 210 additions and 0 deletions

View File

@@ -61,6 +61,7 @@ void drm_atomic_state_default_release(struct drm_atomic_state *state)
kfree(state->connectors);
kfree(state->crtcs);
kfree(state->planes);
kfree(state->private_objs);
}
EXPORT_SYMBOL(drm_atomic_state_default_release);
@@ -186,6 +187,20 @@ void drm_atomic_state_default_clear(struct drm_atomic_state *state)
state->planes[i].ptr = NULL;
state->planes[i].state = NULL;
}
for (i = 0; i < state->num_private_objs; i++) {
struct drm_private_obj *obj = state->private_objs[i].ptr;
if (!obj)
continue;
obj->funcs->atomic_destroy_state(obj,
state->private_objs[i].state);
state->private_objs[i].ptr = NULL;
state->private_objs[i].state = NULL;
}
state->num_private_objs = 0;
}
EXPORT_SYMBOL(drm_atomic_state_default_clear);
@@ -926,6 +941,93 @@ static int drm_atomic_plane_check(struct drm_plane *plane,
return 0;
}
/**
* drm_atomic_private_obj_init - initialize private object
* @obj: private object
* @state: initial private object state
* @funcs: pointer to the struct of function pointers that identify the object
* type
*
* Initialize the private object, which can be embedded into any
* driver private object that needs its own atomic state.
*/
void
drm_atomic_private_obj_init(struct drm_private_obj *obj,
struct drm_private_state *state,
const struct drm_private_state_funcs *funcs)
{
memset(obj, 0, sizeof(*obj));
obj->state = state;
obj->funcs = funcs;
}
EXPORT_SYMBOL(drm_atomic_private_obj_init);
/**
* drm_atomic_private_obj_fini - finalize private object
* @obj: private object
*
* Finalize the private object.
*/
void
drm_atomic_private_obj_fini(struct drm_private_obj *obj)
{
obj->funcs->atomic_destroy_state(obj, obj->state);
}
EXPORT_SYMBOL(drm_atomic_private_obj_fini);
/**
* drm_atomic_get_private_obj_state - get private object state
* @state: global atomic state
* @obj: private object to get the state for
*
* This function returns the private object state for the given private object,
* allocating the state if needed. It does not grab any locks as the caller is
* expected to care of any required locking.
*
* RETURNS:
*
* Either the allocated state or the error code encoded into a pointer.
*/
struct drm_private_state *
drm_atomic_get_private_obj_state(struct drm_atomic_state *state,
struct drm_private_obj *obj)
{
int index, num_objs, i;
size_t size;
struct __drm_private_objs_state *arr;
struct drm_private_state *obj_state;
for (i = 0; i < state->num_private_objs; i++)
if (obj == state->private_objs[i].ptr)
return state->private_objs[i].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);
state->private_objs = arr;
index = state->num_private_objs;
memset(&state->private_objs[index], 0, sizeof(*state->private_objs));
obj_state = obj->funcs->atomic_duplicate_state(obj);
if (!obj_state)
return ERR_PTR(-ENOMEM);
state->private_objs[index].state = obj_state;
state->private_objs[index].ptr = obj;
state->num_private_objs = num_objs;
DRM_DEBUG_ATOMIC("Added new private object %p state %p to %p\n",
obj, obj_state, state);
return obj_state;
}
EXPORT_SYMBOL(drm_atomic_get_private_obj_state);
/**
* drm_atomic_get_connector_state - get connector state
* @state: global atomic state object

View File

@@ -2011,6 +2011,8 @@ void drm_atomic_helper_swap_state(struct drm_atomic_state *state,
struct drm_plane *plane;
struct drm_plane_state *plane_state;
struct drm_crtc_commit *commit;
struct drm_private_obj *obj;
struct drm_private_state *obj_state;
if (stall) {
for_each_crtc_in_state(state, crtc, crtc_state, i) {
@@ -2059,6 +2061,12 @@ void drm_atomic_helper_swap_state(struct drm_atomic_state *state,
swap(state->planes[i].state, plane->state);
plane->state->state = NULL;
}
for_each_private_obj(state, obj, obj_state, i) {
obj->state->state = state;
swap(state->private_objs[i].state, obj->state);
obj->state->state = NULL;
}
}
EXPORT_SYMBOL(drm_atomic_helper_swap_state);
@@ -3485,3 +3493,18 @@ backoff:
goto retry;
}
EXPORT_SYMBOL(drm_atomic_helper_legacy_gamma_set);
/**
* __drm_atomic_helper_private_duplicate_state - copy atomic private state
* @obj: CRTC object
* @state: new private object state
*
* Copies atomic state from a private objects's current state and resets inferred values.
* This is useful for drivers that subclass the private state.
*/
void __drm_atomic_helper_private_obj_duplicate_state(struct drm_private_obj *obj,
struct drm_private_state *state)
{
memcpy(state, obj->state, sizeof(*state));
}
EXPORT_SYMBOL(__drm_atomic_helper_private_obj_duplicate_state);

View File

@@ -152,6 +152,57 @@ struct __drm_connnectors_state {
struct drm_connector_state *state;
};
struct drm_private_obj;
struct drm_private_state;
/**
* struct drm_private_state_funcs - atomic state functions for private objects
*
* These hooks are used by atomic helpers to create, swap and destroy states of
* private objects. The structure itself is used as a vtable to identify the
* associated private object type. Each private object type that needs to be
* added to the atomic states is expected to have an implementation of these
* hooks and pass a pointer to it's drm_private_state_funcs struct to
* drm_atomic_get_private_obj_state().
*/
struct drm_private_state_funcs {
/**
* @atomic_duplicate_state:
*
* Duplicate the current state of the private object and return it. It
* is an error to call this before obj->state has been initialized.
*
* RETURNS:
*
* Duplicated atomic state or NULL when obj->state is not
* initialized or allocation failed.
*/
struct drm_private_state *(*atomic_duplicate_state)(struct drm_private_obj *obj);
/**
* @atomic_destroy_state:
*
* Frees the private object state created with @atomic_duplicate_state.
*/
void (*atomic_destroy_state)(struct drm_private_obj *obj,
struct drm_private_state *state);
};
struct drm_private_obj {
struct drm_private_state *state;
const struct drm_private_state_funcs *funcs;
};
struct drm_private_state {
struct drm_atomic_state *state;
};
struct __drm_private_objs_state {
struct drm_private_obj *ptr;
struct drm_private_state *state;
};
/**
* struct drm_atomic_state - the global state object for atomic updates
* @dev: parent DRM device
@@ -162,6 +213,8 @@ struct __drm_connnectors_state {
* @crtcs: pointer to array of CRTC pointers
* @num_connector: size of the @connectors and @connector_states arrays
* @connectors: pointer to array of structures with per-connector data
* @num_private_objs: size of the @private_objs array
* @private_objs: pointer to array of private object pointers
* @acquire_ctx: acquire context for this atomic modeset state update
*/
struct drm_atomic_state {
@@ -173,6 +226,8 @@ struct drm_atomic_state {
struct __drm_crtcs_state *crtcs;
int num_connector;
struct __drm_connnectors_state *connectors;
int num_private_objs;
struct __drm_private_objs_state *private_objs;
struct drm_modeset_acquire_ctx *acquire_ctx;
@@ -220,6 +275,15 @@ int drm_atomic_connector_set_property(struct drm_connector *connector,
struct drm_connector_state *state, struct drm_property *property,
uint64_t val);
void drm_atomic_private_obj_init(struct drm_private_obj *obj,
struct drm_private_state *state,
const struct drm_private_state_funcs *funcs);
void drm_atomic_private_obj_fini(struct drm_private_obj *obj);
struct drm_private_state * __must_check
drm_atomic_get_private_obj_state(struct drm_atomic_state *state,
struct drm_private_obj *obj);
/**
* drm_atomic_get_existing_crtc_state - get crtc state, if it exists
* @state: global atomic state object
@@ -362,6 +426,23 @@ int __must_check drm_atomic_nonblocking_commit(struct drm_atomic_state *state);
(__i)++) \
for_each_if (plane_state)
/**
* for_each_private_obj - iterate over a specify type of private object
* @__state: &struct drm_atomic_state pointer
* @obj: private object iteration cursor
* @obj_state: private object state iteration cursor
* @__i: int iteration cursor, for macro-internal use
*
* This macro iterates over all private objects in an atomic update.
*/
#define for_each_private_obj(__state, obj, obj_state, __i) \
for ((__i) = 0; \
(__i) < (__state)->num_private_objs && \
((obj) = (__state)->private_objs[__i].ptr, \
(obj_state) = (__state)->private_objs[__i].state, 1); \
(__i)++) \
for_each_if (obj)
/**
* drm_atomic_crtc_needs_modeset - compute combined modeset need
* @state: &drm_crtc_state for the CRTC

View File

@@ -33,6 +33,8 @@
#include <drm/drm_modeset_helper.h>
struct drm_atomic_state;
struct drm_private_obj;
struct drm_private_state;
int drm_atomic_helper_check_modeset(struct drm_device *dev,
struct drm_atomic_state *state);
@@ -166,6 +168,8 @@ void drm_atomic_helper_connector_destroy_state(struct drm_connector *connector,
int drm_atomic_helper_legacy_gamma_set(struct drm_crtc *crtc,
u16 *red, u16 *green, u16 *blue,
uint32_t size);
void __drm_atomic_helper_private_obj_duplicate_state(struct drm_private_obj *obj,
struct drm_private_state *state);
/**
* drm_atomic_crtc_for_each_plane - iterate over planes currently attached to CRTC