xref: /openbmc/linux/drivers/gpu/drm/arm/display/komeda/komeda_private_obj.c (revision 023e41632e065d49bcbe31b3c4b336217f96a271)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * (C) COPYRIGHT 2018 ARM Limited. All rights reserved.
4  * Author: James.Qian.Wang <james.qian.wang@arm.com>
5  *
6  */
7 #include "komeda_dev.h"
8 #include "komeda_kms.h"
9 
10 static struct drm_private_state *
11 komeda_pipeline_atomic_duplicate_state(struct drm_private_obj *obj)
12 {
13 	struct komeda_pipeline_state *st;
14 
15 	st = kmemdup(obj->state, sizeof(*st), GFP_KERNEL);
16 	if (!st)
17 		return NULL;
18 
19 	st->active_comps = 0;
20 
21 	__drm_atomic_helper_private_obj_duplicate_state(obj, &st->obj);
22 
23 	return &st->obj;
24 }
25 
26 static void
27 komeda_pipeline_atomic_destroy_state(struct drm_private_obj *obj,
28 				     struct drm_private_state *state)
29 {
30 	kfree(priv_to_pipe_st(state));
31 }
32 
33 static const struct drm_private_state_funcs komeda_pipeline_obj_funcs = {
34 	.atomic_duplicate_state	= komeda_pipeline_atomic_duplicate_state,
35 	.atomic_destroy_state	= komeda_pipeline_atomic_destroy_state,
36 };
37 
38 static int komeda_pipeline_obj_add(struct komeda_kms_dev *kms,
39 				   struct komeda_pipeline *pipe)
40 {
41 	struct komeda_pipeline_state *st;
42 
43 	st = kzalloc(sizeof(*st), GFP_KERNEL);
44 	if (!st)
45 		return -ENOMEM;
46 
47 	st->pipe = pipe;
48 	drm_atomic_private_obj_init(&kms->base, &pipe->obj, &st->obj,
49 				    &komeda_pipeline_obj_funcs);
50 
51 	return 0;
52 }
53 
54 int komeda_kms_add_private_objs(struct komeda_kms_dev *kms,
55 				struct komeda_dev *mdev)
56 {
57 	struct komeda_pipeline *pipe;
58 	int i, err;
59 
60 	for (i = 0; i < mdev->n_pipelines; i++) {
61 		pipe = mdev->pipelines[i];
62 
63 		err = komeda_pipeline_obj_add(kms, pipe);
64 		if (err)
65 			return err;
66 
67 		/* Add component */
68 	}
69 
70 	return 0;
71 }
72 
73 void komeda_kms_cleanup_private_objs(struct komeda_dev *mdev)
74 {
75 	struct komeda_pipeline *pipe;
76 	struct komeda_component *c;
77 	int i, id;
78 
79 	for (i = 0; i < mdev->n_pipelines; i++) {
80 		pipe = mdev->pipelines[i];
81 		dp_for_each_set_bit(id, pipe->avail_comps) {
82 			c = komeda_pipeline_get_component(pipe, id);
83 
84 			drm_atomic_private_obj_fini(&c->obj);
85 		}
86 		drm_atomic_private_obj_fini(&pipe->obj);
87 	}
88 }
89