treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / gpu / drm / arm / display / komeda / komeda_private_obj.c
blob914400c4af73824e52dda76425a73a74e681a146
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>
6 */
7 #include "komeda_dev.h"
8 #include "komeda_kms.h"
10 static void
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);
25 if (!st)
26 return NULL;
28 komeda_component_state_reset(&st->base);
29 __drm_atomic_helper_private_obj_duplicate_state(obj, &st->base.obj);
31 return &st->base.obj;
34 static void
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));
40 kfree(st);
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);
54 if (!st)
55 return -ENOMEM;
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);
60 return 0;
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);
69 if (!st)
70 return NULL;
72 komeda_component_state_reset(&st->base);
73 __drm_atomic_helper_private_obj_duplicate_state(obj, &st->base.obj);
75 return &st->base.obj;
78 static void
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);
96 if (!st)
97 return -ENOMEM;
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);
103 return 0;
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);
112 if (!st)
113 return NULL;
115 komeda_component_state_reset(&st->base);
116 __drm_atomic_helper_private_obj_duplicate_state(obj, &st->base.obj);
118 return &st->base.obj;
121 static void
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);
139 if (!st)
140 return -ENOMEM;
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);
146 return 0;
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);
155 if (!st)
156 return NULL;
158 komeda_component_state_reset(&st->base);
159 __drm_atomic_helper_private_obj_duplicate_state(obj, &st->base.obj);
161 return &st->base.obj;
164 static void
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);
182 if (!st)
183 return -ENOMEM;
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);
190 return 0;
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);
199 if (!st)
200 return NULL;
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);
225 if (!st)
226 return -ENOMEM;
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);
233 return 0;
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);
242 if (!st)
243 return NULL;
245 komeda_component_state_reset(&st->base);
246 __drm_atomic_helper_private_obj_duplicate_state(obj, &st->base.obj);
248 return &st->base.obj;
251 static void
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);
269 if (!st)
270 return -ENOMEM;
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);
276 return 0;
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);
285 if (!st)
286 return NULL;
288 komeda_component_state_reset(&st->base);
289 __drm_atomic_helper_private_obj_duplicate_state(obj, &st->base.obj);
291 return &st->base.obj;
294 static void
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);
312 if (!st)
313 return -ENOMEM;
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);
319 return 0;
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);
328 if (!st)
329 return NULL;
331 st->active_comps = 0;
333 __drm_atomic_helper_private_obj_duplicate_state(obj, &st->obj);
335 return &st->obj;
338 static void
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);
356 if (!st)
357 return -ENOMEM;
359 st->pipe = pipe;
360 drm_atomic_private_obj_init(&kms->base, &pipe->obj, &st->obj,
361 &komeda_pipeline_obj_funcs);
363 return 0;
366 int komeda_kms_add_private_objs(struct komeda_kms_dev *kms,
367 struct komeda_dev *mdev)
369 struct komeda_pipeline *pipe;
370 int i, j, err;
372 for (i = 0; i < mdev->n_pipelines; i++) {
373 pipe = mdev->pipelines[i];
375 err = komeda_pipeline_obj_add(kms, pipe);
376 if (err)
377 return err;
379 for (j = 0; j < pipe->n_layers; j++) {
380 err = komeda_layer_obj_add(kms, pipe->layers[j]);
381 if (err)
382 return err;
385 if (pipe->wb_layer) {
386 err = komeda_layer_obj_add(kms, pipe->wb_layer);
387 if (err)
388 return err;
391 for (j = 0; j < pipe->n_scalers; j++) {
392 err = komeda_scaler_obj_add(kms, pipe->scalers[j]);
393 if (err)
394 return err;
397 err = komeda_compiz_obj_add(kms, pipe->compiz);
398 if (err)
399 return err;
401 if (pipe->splitter) {
402 err = komeda_splitter_obj_add(kms, pipe->splitter);
403 if (err)
404 return err;
407 if (pipe->merger) {
408 err = komeda_merger_obj_add(kms, pipe->merger);
409 if (err)
410 return err;
413 err = komeda_improc_obj_add(kms, pipe->improc);
414 if (err)
415 return err;
417 err = komeda_timing_ctrlr_obj_add(kms, pipe->ctrlr);
418 if (err)
419 return err;
422 return 0;
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);