1 // SPDX-License-Identifier: GPL-2.0
3 * (C) COPYRIGHT 2018 ARM Limited. All rights reserved.
4 * Author: James.Qian.Wang <james.qian.wang@arm.com>
7 #include "komeda_dev.h"
8 #include "komeda_kms.h"
11 komeda_component_state_reset(struct komeda_component_state
*st
)
13 st
->binding_user
= NULL
;
14 st
->affected_inputs
= st
->active_inputs
;
15 st
->active_inputs
= 0;
16 st
->changed_active_inputs
= 0;
19 static struct drm_private_state
*
20 komeda_layer_atomic_duplicate_state(struct drm_private_obj
*obj
)
22 struct komeda_layer_state
*st
;
24 st
= kmemdup(obj
->state
, sizeof(*st
), GFP_KERNEL
);
28 komeda_component_state_reset(&st
->base
);
29 __drm_atomic_helper_private_obj_duplicate_state(obj
, &st
->base
.obj
);
35 komeda_layer_atomic_destroy_state(struct drm_private_obj
*obj
,
36 struct drm_private_state
*state
)
38 struct komeda_layer_state
*st
= to_layer_st(priv_to_comp_st(state
));
43 static const struct drm_private_state_funcs komeda_layer_obj_funcs
= {
44 .atomic_duplicate_state
= komeda_layer_atomic_duplicate_state
,
45 .atomic_destroy_state
= komeda_layer_atomic_destroy_state
,
48 static int komeda_layer_obj_add(struct komeda_kms_dev
*kms
,
49 struct komeda_layer
*layer
)
51 struct komeda_layer_state
*st
;
53 st
= kzalloc(sizeof(*st
), GFP_KERNEL
);
57 st
->base
.component
= &layer
->base
;
58 drm_atomic_private_obj_init(&kms
->base
, &layer
->base
.obj
, &st
->base
.obj
,
59 &komeda_layer_obj_funcs
);
63 static struct drm_private_state
*
64 komeda_scaler_atomic_duplicate_state(struct drm_private_obj
*obj
)
66 struct komeda_scaler_state
*st
;
68 st
= kmemdup(obj
->state
, sizeof(*st
), GFP_KERNEL
);
72 komeda_component_state_reset(&st
->base
);
73 __drm_atomic_helper_private_obj_duplicate_state(obj
, &st
->base
.obj
);
79 komeda_scaler_atomic_destroy_state(struct drm_private_obj
*obj
,
80 struct drm_private_state
*state
)
82 kfree(to_scaler_st(priv_to_comp_st(state
)));
85 static const struct drm_private_state_funcs komeda_scaler_obj_funcs
= {
86 .atomic_duplicate_state
= komeda_scaler_atomic_duplicate_state
,
87 .atomic_destroy_state
= komeda_scaler_atomic_destroy_state
,
90 static int komeda_scaler_obj_add(struct komeda_kms_dev
*kms
,
91 struct komeda_scaler
*scaler
)
93 struct komeda_scaler_state
*st
;
95 st
= kzalloc(sizeof(*st
), GFP_KERNEL
);
99 st
->base
.component
= &scaler
->base
;
100 drm_atomic_private_obj_init(&kms
->base
,
101 &scaler
->base
.obj
, &st
->base
.obj
,
102 &komeda_scaler_obj_funcs
);
106 static struct drm_private_state
*
107 komeda_compiz_atomic_duplicate_state(struct drm_private_obj
*obj
)
109 struct komeda_compiz_state
*st
;
111 st
= kmemdup(obj
->state
, sizeof(*st
), GFP_KERNEL
);
115 komeda_component_state_reset(&st
->base
);
116 __drm_atomic_helper_private_obj_duplicate_state(obj
, &st
->base
.obj
);
118 return &st
->base
.obj
;
122 komeda_compiz_atomic_destroy_state(struct drm_private_obj
*obj
,
123 struct drm_private_state
*state
)
125 kfree(to_compiz_st(priv_to_comp_st(state
)));
128 static const struct drm_private_state_funcs komeda_compiz_obj_funcs
= {
129 .atomic_duplicate_state
= komeda_compiz_atomic_duplicate_state
,
130 .atomic_destroy_state
= komeda_compiz_atomic_destroy_state
,
133 static int komeda_compiz_obj_add(struct komeda_kms_dev
*kms
,
134 struct komeda_compiz
*compiz
)
136 struct komeda_compiz_state
*st
;
138 st
= kzalloc(sizeof(*st
), GFP_KERNEL
);
142 st
->base
.component
= &compiz
->base
;
143 drm_atomic_private_obj_init(&kms
->base
, &compiz
->base
.obj
, &st
->base
.obj
,
144 &komeda_compiz_obj_funcs
);
149 static struct drm_private_state
*
150 komeda_splitter_atomic_duplicate_state(struct drm_private_obj
*obj
)
152 struct komeda_splitter_state
*st
;
154 st
= kmemdup(obj
->state
, sizeof(*st
), GFP_KERNEL
);
158 komeda_component_state_reset(&st
->base
);
159 __drm_atomic_helper_private_obj_duplicate_state(obj
, &st
->base
.obj
);
161 return &st
->base
.obj
;
165 komeda_splitter_atomic_destroy_state(struct drm_private_obj
*obj
,
166 struct drm_private_state
*state
)
168 kfree(to_splitter_st(priv_to_comp_st(state
)));
171 static const struct drm_private_state_funcs komeda_splitter_obj_funcs
= {
172 .atomic_duplicate_state
= komeda_splitter_atomic_duplicate_state
,
173 .atomic_destroy_state
= komeda_splitter_atomic_destroy_state
,
176 static int komeda_splitter_obj_add(struct komeda_kms_dev
*kms
,
177 struct komeda_splitter
*splitter
)
179 struct komeda_splitter_state
*st
;
181 st
= kzalloc(sizeof(*st
), GFP_KERNEL
);
185 st
->base
.component
= &splitter
->base
;
186 drm_atomic_private_obj_init(&kms
->base
,
187 &splitter
->base
.obj
, &st
->base
.obj
,
188 &komeda_splitter_obj_funcs
);
193 static struct drm_private_state
*
194 komeda_merger_atomic_duplicate_state(struct drm_private_obj
*obj
)
196 struct komeda_merger_state
*st
;
198 st
= kmemdup(obj
->state
, sizeof(*st
), GFP_KERNEL
);
202 komeda_component_state_reset(&st
->base
);
203 __drm_atomic_helper_private_obj_duplicate_state(obj
, &st
->base
.obj
);
205 return &st
->base
.obj
;
208 static void komeda_merger_atomic_destroy_state(struct drm_private_obj
*obj
,
209 struct drm_private_state
*state
)
211 kfree(to_merger_st(priv_to_comp_st(state
)));
214 static const struct drm_private_state_funcs komeda_merger_obj_funcs
= {
215 .atomic_duplicate_state
= komeda_merger_atomic_duplicate_state
,
216 .atomic_destroy_state
= komeda_merger_atomic_destroy_state
,
219 static int komeda_merger_obj_add(struct komeda_kms_dev
*kms
,
220 struct komeda_merger
*merger
)
222 struct komeda_merger_state
*st
;
224 st
= kzalloc(sizeof(*st
), GFP_KERNEL
);
228 st
->base
.component
= &merger
->base
;
229 drm_atomic_private_obj_init(&kms
->base
,
230 &merger
->base
.obj
, &st
->base
.obj
,
231 &komeda_merger_obj_funcs
);
236 static struct drm_private_state
*
237 komeda_improc_atomic_duplicate_state(struct drm_private_obj
*obj
)
239 struct komeda_improc_state
*st
;
241 st
= kmemdup(obj
->state
, sizeof(*st
), GFP_KERNEL
);
245 komeda_component_state_reset(&st
->base
);
246 __drm_atomic_helper_private_obj_duplicate_state(obj
, &st
->base
.obj
);
248 return &st
->base
.obj
;
252 komeda_improc_atomic_destroy_state(struct drm_private_obj
*obj
,
253 struct drm_private_state
*state
)
255 kfree(to_improc_st(priv_to_comp_st(state
)));
258 static const struct drm_private_state_funcs komeda_improc_obj_funcs
= {
259 .atomic_duplicate_state
= komeda_improc_atomic_duplicate_state
,
260 .atomic_destroy_state
= komeda_improc_atomic_destroy_state
,
263 static int komeda_improc_obj_add(struct komeda_kms_dev
*kms
,
264 struct komeda_improc
*improc
)
266 struct komeda_improc_state
*st
;
268 st
= kzalloc(sizeof(*st
), GFP_KERNEL
);
272 st
->base
.component
= &improc
->base
;
273 drm_atomic_private_obj_init(&kms
->base
, &improc
->base
.obj
, &st
->base
.obj
,
274 &komeda_improc_obj_funcs
);
279 static struct drm_private_state
*
280 komeda_timing_ctrlr_atomic_duplicate_state(struct drm_private_obj
*obj
)
282 struct komeda_timing_ctrlr_state
*st
;
284 st
= kmemdup(obj
->state
, sizeof(*st
), GFP_KERNEL
);
288 komeda_component_state_reset(&st
->base
);
289 __drm_atomic_helper_private_obj_duplicate_state(obj
, &st
->base
.obj
);
291 return &st
->base
.obj
;
295 komeda_timing_ctrlr_atomic_destroy_state(struct drm_private_obj
*obj
,
296 struct drm_private_state
*state
)
298 kfree(to_ctrlr_st(priv_to_comp_st(state
)));
301 static const struct drm_private_state_funcs komeda_timing_ctrlr_obj_funcs
= {
302 .atomic_duplicate_state
= komeda_timing_ctrlr_atomic_duplicate_state
,
303 .atomic_destroy_state
= komeda_timing_ctrlr_atomic_destroy_state
,
306 static int komeda_timing_ctrlr_obj_add(struct komeda_kms_dev
*kms
,
307 struct komeda_timing_ctrlr
*ctrlr
)
309 struct komeda_compiz_state
*st
;
311 st
= kzalloc(sizeof(*st
), GFP_KERNEL
);
315 st
->base
.component
= &ctrlr
->base
;
316 drm_atomic_private_obj_init(&kms
->base
, &ctrlr
->base
.obj
, &st
->base
.obj
,
317 &komeda_timing_ctrlr_obj_funcs
);
322 static struct drm_private_state
*
323 komeda_pipeline_atomic_duplicate_state(struct drm_private_obj
*obj
)
325 struct komeda_pipeline_state
*st
;
327 st
= kmemdup(obj
->state
, sizeof(*st
), GFP_KERNEL
);
331 st
->active_comps
= 0;
333 __drm_atomic_helper_private_obj_duplicate_state(obj
, &st
->obj
);
339 komeda_pipeline_atomic_destroy_state(struct drm_private_obj
*obj
,
340 struct drm_private_state
*state
)
342 kfree(priv_to_pipe_st(state
));
345 static const struct drm_private_state_funcs komeda_pipeline_obj_funcs
= {
346 .atomic_duplicate_state
= komeda_pipeline_atomic_duplicate_state
,
347 .atomic_destroy_state
= komeda_pipeline_atomic_destroy_state
,
350 static int komeda_pipeline_obj_add(struct komeda_kms_dev
*kms
,
351 struct komeda_pipeline
*pipe
)
353 struct komeda_pipeline_state
*st
;
355 st
= kzalloc(sizeof(*st
), GFP_KERNEL
);
360 drm_atomic_private_obj_init(&kms
->base
, &pipe
->obj
, &st
->obj
,
361 &komeda_pipeline_obj_funcs
);
366 int komeda_kms_add_private_objs(struct komeda_kms_dev
*kms
,
367 struct komeda_dev
*mdev
)
369 struct komeda_pipeline
*pipe
;
372 for (i
= 0; i
< mdev
->n_pipelines
; i
++) {
373 pipe
= mdev
->pipelines
[i
];
375 err
= komeda_pipeline_obj_add(kms
, pipe
);
379 for (j
= 0; j
< pipe
->n_layers
; j
++) {
380 err
= komeda_layer_obj_add(kms
, pipe
->layers
[j
]);
385 if (pipe
->wb_layer
) {
386 err
= komeda_layer_obj_add(kms
, pipe
->wb_layer
);
391 for (j
= 0; j
< pipe
->n_scalers
; j
++) {
392 err
= komeda_scaler_obj_add(kms
, pipe
->scalers
[j
]);
397 err
= komeda_compiz_obj_add(kms
, pipe
->compiz
);
401 if (pipe
->splitter
) {
402 err
= komeda_splitter_obj_add(kms
, pipe
->splitter
);
408 err
= komeda_merger_obj_add(kms
, pipe
->merger
);
413 err
= komeda_improc_obj_add(kms
, pipe
->improc
);
417 err
= komeda_timing_ctrlr_obj_add(kms
, pipe
->ctrlr
);
425 void komeda_kms_cleanup_private_objs(struct komeda_kms_dev
*kms
)
427 struct drm_mode_config
*config
= &kms
->base
.mode_config
;
428 struct drm_private_obj
*obj
, *next
;
430 list_for_each_entry_safe(obj
, next
, &config
->privobj_list
, head
)
431 drm_atomic_private_obj_fini(obj
);