drm/komeda: Initialize komeda component as drm private object
authorjames qian wang (Arm Technology China) <james.qian.wang@arm.com>
Tue, 22 Jan 2019 11:06:01 +0000 (11:06 +0000)
committerLiviu Dudau <Liviu.Dudau@arm.com>
Mon, 29 Apr 2019 11:35:56 +0000 (12:35 +0100)
Initialize koemda_layer, komeda_compiz, komeda_improc and
komeda_timing_ctrlr as drm private object, then track komeda private
component state by drm_atomic_state.

v2:
- Update code after Applied commit:
  b962a12050a3 ("drm/atomic: integrate modeset lock with private objects")

Signed-off-by: James Qian Wang (Arm Technology China) <james.qian.wang@arm.com>
Signed-off-by: Liviu Dudau <liviu.dudau@arm.com>
drivers/gpu/drm/arm/display/komeda/komeda_kms.c
drivers/gpu/drm/arm/display/komeda/komeda_kms.h
drivers/gpu/drm/arm/display/komeda/komeda_private_obj.c

index b214edbfbbc6774e5ed60f1baa2c49b01b4e5dd1..55b103ae3e2f1d879d21fcec6018545fbc8cfa7b 100644 (file)
@@ -184,6 +184,7 @@ uninstall_irq:
        drm_irq_uninstall(drm);
 cleanup_mode_config:
        drm_mode_config_cleanup(drm);
+       komeda_kms_cleanup_private_objs(kms);
 free_kms:
        kfree(kms);
        return ERR_PTR(err);
@@ -198,7 +199,7 @@ void komeda_kms_detach(struct komeda_kms_dev *kms)
        drm_dev_unregister(drm);
        drm_irq_uninstall(drm);
        component_unbind_all(mdev->dev, drm);
-       komeda_kms_cleanup_private_objs(mdev);
+       komeda_kms_cleanup_private_objs(kms);
        drm_mode_config_cleanup(drm);
        drm->dev_private = NULL;
        drm_dev_put(drm);
index 15ac8b85506ce475c25db5b92744ff9a8acee3e5..beb94ff110d74d556957f7ac22b11639d9bc57dc 100644 (file)
@@ -108,7 +108,7 @@ int komeda_kms_add_crtcs(struct komeda_kms_dev *kms, struct komeda_dev *mdev);
 int komeda_kms_add_planes(struct komeda_kms_dev *kms, struct komeda_dev *mdev);
 int komeda_kms_add_private_objs(struct komeda_kms_dev *kms,
                                struct komeda_dev *mdev);
-void komeda_kms_cleanup_private_objs(struct komeda_dev *mdev);
+void komeda_kms_cleanup_private_objs(struct komeda_kms_dev *kms);
 
 void komeda_crtc_handle_event(struct komeda_crtc   *kcrtc,
                              struct komeda_events *evts);
index f1c9e3fefa86b4f8722d201475c1961603690836..a54878cbd6e4f54d6a64fc5b345b24d2b7b79d92 100644 (file)
@@ -7,6 +7,188 @@
 #include "komeda_dev.h"
 #include "komeda_kms.h"
 
+static void
+komeda_component_state_reset(struct komeda_component_state *st)
+{
+       st->binding_user = NULL;
+       st->affected_inputs = st->active_inputs;
+       st->active_inputs = 0;
+       st->changed_active_inputs = 0;
+}
+
+static struct drm_private_state *
+komeda_layer_atomic_duplicate_state(struct drm_private_obj *obj)
+{
+       struct komeda_layer_state *st;
+
+       st = kmemdup(obj->state, sizeof(*st), GFP_KERNEL);
+       if (!st)
+               return NULL;
+
+       komeda_component_state_reset(&st->base);
+       __drm_atomic_helper_private_obj_duplicate_state(obj, &st->base.obj);
+
+       return &st->base.obj;
+}
+
+static void
+komeda_layer_atomic_destroy_state(struct drm_private_obj *obj,
+                                 struct drm_private_state *state)
+{
+       struct komeda_layer_state *st = to_layer_st(priv_to_comp_st(state));
+
+       kfree(st);
+}
+
+static const struct drm_private_state_funcs komeda_layer_obj_funcs = {
+       .atomic_duplicate_state = komeda_layer_atomic_duplicate_state,
+       .atomic_destroy_state   = komeda_layer_atomic_destroy_state,
+};
+
+static int komeda_layer_obj_add(struct komeda_kms_dev *kms,
+                               struct komeda_layer *layer)
+{
+       struct komeda_layer_state *st;
+
+       st = kzalloc(sizeof(*st), GFP_KERNEL);
+       if (!st)
+               return -ENOMEM;
+
+       st->base.component = &layer->base;
+       drm_atomic_private_obj_init(&kms->base, &layer->base.obj, &st->base.obj,
+                                   &komeda_layer_obj_funcs);
+       return 0;
+}
+
+static struct drm_private_state *
+komeda_compiz_atomic_duplicate_state(struct drm_private_obj *obj)
+{
+       struct komeda_compiz_state *st;
+
+       st = kmemdup(obj->state, sizeof(*st), GFP_KERNEL);
+       if (!st)
+               return NULL;
+
+       komeda_component_state_reset(&st->base);
+       __drm_atomic_helper_private_obj_duplicate_state(obj, &st->base.obj);
+
+       return &st->base.obj;
+}
+
+static void
+komeda_compiz_atomic_destroy_state(struct drm_private_obj *obj,
+                                  struct drm_private_state *state)
+{
+       kfree(to_compiz_st(priv_to_comp_st(state)));
+}
+
+static const struct drm_private_state_funcs komeda_compiz_obj_funcs = {
+       .atomic_duplicate_state = komeda_compiz_atomic_duplicate_state,
+       .atomic_destroy_state   = komeda_compiz_atomic_destroy_state,
+};
+
+static int komeda_compiz_obj_add(struct komeda_kms_dev *kms,
+                                struct komeda_compiz *compiz)
+{
+       struct komeda_compiz_state *st;
+
+       st = kzalloc(sizeof(*st), GFP_KERNEL);
+       if (!st)
+               return -ENOMEM;
+
+       st->base.component = &compiz->base;
+       drm_atomic_private_obj_init(&kms->base, &compiz->base.obj, &st->base.obj,
+                                   &komeda_compiz_obj_funcs);
+
+       return 0;
+}
+
+static struct drm_private_state *
+komeda_improc_atomic_duplicate_state(struct drm_private_obj *obj)
+{
+       struct komeda_improc_state *st;
+
+       st = kmemdup(obj->state, sizeof(*st), GFP_KERNEL);
+       if (!st)
+               return NULL;
+
+       komeda_component_state_reset(&st->base);
+       __drm_atomic_helper_private_obj_duplicate_state(obj, &st->base.obj);
+
+       return &st->base.obj;
+}
+
+static void
+komeda_improc_atomic_destroy_state(struct drm_private_obj *obj,
+                                  struct drm_private_state *state)
+{
+       kfree(to_improc_st(priv_to_comp_st(state)));
+}
+
+static const struct drm_private_state_funcs komeda_improc_obj_funcs = {
+       .atomic_duplicate_state = komeda_improc_atomic_duplicate_state,
+       .atomic_destroy_state   = komeda_improc_atomic_destroy_state,
+};
+
+static int komeda_improc_obj_add(struct komeda_kms_dev *kms,
+                                struct komeda_improc *improc)
+{
+       struct komeda_improc_state *st;
+
+       st = kzalloc(sizeof(*st), GFP_KERNEL);
+       if (!st)
+               return -ENOMEM;
+
+       st->base.component = &improc->base;
+       drm_atomic_private_obj_init(&kms->base, &improc->base.obj, &st->base.obj,
+                                   &komeda_improc_obj_funcs);
+
+       return 0;
+}
+
+static struct drm_private_state *
+komeda_timing_ctrlr_atomic_duplicate_state(struct drm_private_obj *obj)
+{
+       struct komeda_timing_ctrlr_state *st;
+
+       st = kmemdup(obj->state, sizeof(*st), GFP_KERNEL);
+       if (!st)
+               return NULL;
+
+       komeda_component_state_reset(&st->base);
+       __drm_atomic_helper_private_obj_duplicate_state(obj, &st->base.obj);
+
+       return &st->base.obj;
+}
+
+static void
+komeda_timing_ctrlr_atomic_destroy_state(struct drm_private_obj *obj,
+                                        struct drm_private_state *state)
+{
+       kfree(to_ctrlr_st(priv_to_comp_st(state)));
+}
+
+static const struct drm_private_state_funcs komeda_timing_ctrlr_obj_funcs = {
+       .atomic_duplicate_state = komeda_timing_ctrlr_atomic_duplicate_state,
+       .atomic_destroy_state   = komeda_timing_ctrlr_atomic_destroy_state,
+};
+
+static int komeda_timing_ctrlr_obj_add(struct komeda_kms_dev *kms,
+                                      struct komeda_timing_ctrlr *ctrlr)
+{
+       struct komeda_compiz_state *st;
+
+       st = kzalloc(sizeof(*st), GFP_KERNEL);
+       if (!st)
+               return -ENOMEM;
+
+       st->base.component = &ctrlr->base;
+       drm_atomic_private_obj_init(&kms->base, &ctrlr->base.obj, &st->base.obj,
+                                   &komeda_timing_ctrlr_obj_funcs);
+
+       return 0;
+}
+
 static struct drm_private_state *
 komeda_pipeline_atomic_duplicate_state(struct drm_private_obj *obj)
 {
@@ -55,7 +237,7 @@ int komeda_kms_add_private_objs(struct komeda_kms_dev *kms,
                                struct komeda_dev *mdev)
 {
        struct komeda_pipeline *pipe;
-       int i, err;
+       int i, j, err;
 
        for (i = 0; i < mdev->n_pipelines; i++) {
                pipe = mdev->pipelines[i];
@@ -64,25 +246,33 @@ int komeda_kms_add_private_objs(struct komeda_kms_dev *kms,
                if (err)
                        return err;
 
-               /* Add component */
+               for (j = 0; j < pipe->n_layers; j++) {
+                       err = komeda_layer_obj_add(kms, pipe->layers[j]);
+                       if (err)
+                               return err;
+               }
+
+               err = komeda_compiz_obj_add(kms, pipe->compiz);
+               if (err)
+                       return err;
+
+               err = komeda_improc_obj_add(kms, pipe->improc);
+               if (err)
+                       return err;
+
+               err = komeda_timing_ctrlr_obj_add(kms, pipe->ctrlr);
+               if (err)
+                       return err;
        }
 
        return 0;
 }
 
-void komeda_kms_cleanup_private_objs(struct komeda_dev *mdev)
+void komeda_kms_cleanup_private_objs(struct komeda_kms_dev *kms)
 {
-       struct komeda_pipeline *pipe;
-       struct komeda_component *c;
-       int i, id;
+       struct drm_mode_config *config = &kms->base.mode_config;
+       struct drm_private_obj *obj, *next;
 
-       for (i = 0; i < mdev->n_pipelines; i++) {
-               pipe = mdev->pipelines[i];
-               dp_for_each_set_bit(id, pipe->avail_comps) {
-                       c = komeda_pipeline_get_component(pipe, id);
-
-                       drm_atomic_private_obj_fini(&c->obj);
-               }
-               drm_atomic_private_obj_fini(&pipe->obj);
-       }
+       list_for_each_entry_safe(obj, next, &config->privobj_list, head)
+               drm_atomic_private_obj_fini(obj);
 }