1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include <drm/drm_atomic.h>
28#include <drm/drm_atomic_state_helper.h>
29#include <drm/drm_bridge.h>
30#include <drm/drm_connector.h>
31#include <drm/drm_crtc.h>
32#include <drm/drm_device.h>
33#include <drm/drm_plane.h>
34#include <drm/drm_print.h>
35#include <drm/drm_vblank.h>
36#include <drm/drm_writeback.h>
37
38#include <linux/slab.h>
39#include <linux/dma-fence.h>
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70void
71__drm_atomic_helper_crtc_state_reset(struct drm_crtc_state *crtc_state,
72 struct drm_crtc *crtc)
73{
74 crtc_state->crtc = crtc;
75}
76EXPORT_SYMBOL(__drm_atomic_helper_crtc_state_reset);
77
78
79
80
81
82
83
84
85
86
87
88
89
90void
91__drm_atomic_helper_crtc_reset(struct drm_crtc *crtc,
92 struct drm_crtc_state *crtc_state)
93{
94 if (crtc_state)
95 __drm_atomic_helper_crtc_state_reset(crtc_state, crtc);
96
97 if (drm_dev_has_vblank(crtc->dev))
98 drm_crtc_vblank_reset(crtc);
99
100 crtc->state = crtc_state;
101}
102EXPORT_SYMBOL(__drm_atomic_helper_crtc_reset);
103
104
105
106
107
108
109
110
111void drm_atomic_helper_crtc_reset(struct drm_crtc *crtc)
112{
113 struct drm_crtc_state *crtc_state =
114 kzalloc(sizeof(*crtc->state), GFP_KERNEL);
115
116 if (crtc->state)
117 crtc->funcs->atomic_destroy_state(crtc, crtc->state);
118
119 __drm_atomic_helper_crtc_reset(crtc, crtc_state);
120}
121EXPORT_SYMBOL(drm_atomic_helper_crtc_reset);
122
123
124
125
126
127
128
129
130
131void __drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc,
132 struct drm_crtc_state *state)
133{
134 memcpy(state, crtc->state, sizeof(*state));
135
136 if (state->mode_blob)
137 drm_property_blob_get(state->mode_blob);
138 if (state->degamma_lut)
139 drm_property_blob_get(state->degamma_lut);
140 if (state->ctm)
141 drm_property_blob_get(state->ctm);
142 if (state->gamma_lut)
143 drm_property_blob_get(state->gamma_lut);
144 state->mode_changed = false;
145 state->active_changed = false;
146 state->planes_changed = false;
147 state->connectors_changed = false;
148 state->color_mgmt_changed = false;
149 state->zpos_changed = false;
150 state->commit = NULL;
151 state->event = NULL;
152 state->async_flip = false;
153
154
155 state->active = drm_atomic_crtc_effectively_active(state);
156 state->self_refresh_active = false;
157}
158EXPORT_SYMBOL(__drm_atomic_helper_crtc_duplicate_state);
159
160
161
162
163
164
165
166
167struct drm_crtc_state *
168drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc)
169{
170 struct drm_crtc_state *state;
171
172 if (WARN_ON(!crtc->state))
173 return NULL;
174
175 state = kmalloc(sizeof(*state), GFP_KERNEL);
176 if (state)
177 __drm_atomic_helper_crtc_duplicate_state(crtc, state);
178
179 return state;
180}
181EXPORT_SYMBOL(drm_atomic_helper_crtc_duplicate_state);
182
183
184
185
186
187
188
189
190
191void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc_state *state)
192{
193 if (state->commit) {
194
195
196
197
198
199
200
201
202
203 if (state->event && state->commit->abort_completion)
204 drm_crtc_commit_put(state->commit);
205
206 kfree(state->commit->event);
207 state->commit->event = NULL;
208
209 drm_crtc_commit_put(state->commit);
210 }
211
212 drm_property_blob_put(state->mode_blob);
213 drm_property_blob_put(state->degamma_lut);
214 drm_property_blob_put(state->ctm);
215 drm_property_blob_put(state->gamma_lut);
216}
217EXPORT_SYMBOL(__drm_atomic_helper_crtc_destroy_state);
218
219
220
221
222
223
224
225
226
227void drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc,
228 struct drm_crtc_state *state)
229{
230 __drm_atomic_helper_crtc_destroy_state(state);
231 kfree(state);
232}
233EXPORT_SYMBOL(drm_atomic_helper_crtc_destroy_state);
234
235
236
237
238
239
240
241
242
243void __drm_atomic_helper_plane_state_reset(struct drm_plane_state *plane_state,
244 struct drm_plane *plane)
245{
246 u64 val;
247
248 plane_state->plane = plane;
249 plane_state->rotation = DRM_MODE_ROTATE_0;
250
251 plane_state->alpha = DRM_BLEND_ALPHA_OPAQUE;
252 plane_state->pixel_blend_mode = DRM_MODE_BLEND_PREMULTI;
253
254 if (plane->color_encoding_property) {
255 if (!drm_object_property_get_default_value(&plane->base,
256 plane->color_encoding_property,
257 &val))
258 plane_state->color_encoding = val;
259 }
260
261 if (plane->color_range_property) {
262 if (!drm_object_property_get_default_value(&plane->base,
263 plane->color_range_property,
264 &val))
265 plane_state->color_range = val;
266 }
267
268 if (plane->zpos_property) {
269 if (!drm_object_property_get_default_value(&plane->base,
270 plane->zpos_property,
271 &val)) {
272 plane_state->zpos = val;
273 plane_state->normalized_zpos = val;
274 }
275 }
276}
277EXPORT_SYMBOL(__drm_atomic_helper_plane_state_reset);
278
279
280
281
282
283
284
285
286
287
288
289
290
291void __drm_atomic_helper_plane_reset(struct drm_plane *plane,
292 struct drm_plane_state *plane_state)
293{
294 if (plane_state)
295 __drm_atomic_helper_plane_state_reset(plane_state, plane);
296
297 plane->state = plane_state;
298}
299EXPORT_SYMBOL(__drm_atomic_helper_plane_reset);
300
301
302
303
304
305
306
307
308void drm_atomic_helper_plane_reset(struct drm_plane *plane)
309{
310 if (plane->state)
311 __drm_atomic_helper_plane_destroy_state(plane->state);
312
313 kfree(plane->state);
314 plane->state = kzalloc(sizeof(*plane->state), GFP_KERNEL);
315 if (plane->state)
316 __drm_atomic_helper_plane_reset(plane, plane->state);
317}
318EXPORT_SYMBOL(drm_atomic_helper_plane_reset);
319
320
321
322
323
324
325
326
327
328void __drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane,
329 struct drm_plane_state *state)
330{
331 memcpy(state, plane->state, sizeof(*state));
332
333 if (state->fb)
334 drm_framebuffer_get(state->fb);
335
336 state->fence = NULL;
337 state->commit = NULL;
338 state->fb_damage_clips = NULL;
339}
340EXPORT_SYMBOL(__drm_atomic_helper_plane_duplicate_state);
341
342
343
344
345
346
347
348
349struct drm_plane_state *
350drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane)
351{
352 struct drm_plane_state *state;
353
354 if (WARN_ON(!plane->state))
355 return NULL;
356
357 state = kmalloc(sizeof(*state), GFP_KERNEL);
358 if (state)
359 __drm_atomic_helper_plane_duplicate_state(plane, state);
360
361 return state;
362}
363EXPORT_SYMBOL(drm_atomic_helper_plane_duplicate_state);
364
365
366
367
368
369
370
371
372
373void __drm_atomic_helper_plane_destroy_state(struct drm_plane_state *state)
374{
375 if (state->fb)
376 drm_framebuffer_put(state->fb);
377
378 if (state->fence)
379 dma_fence_put(state->fence);
380
381 if (state->commit)
382 drm_crtc_commit_put(state->commit);
383
384 drm_property_blob_put(state->fb_damage_clips);
385}
386EXPORT_SYMBOL(__drm_atomic_helper_plane_destroy_state);
387
388
389
390
391
392
393
394
395
396void drm_atomic_helper_plane_destroy_state(struct drm_plane *plane,
397 struct drm_plane_state *state)
398{
399 __drm_atomic_helper_plane_destroy_state(state);
400 kfree(state);
401}
402EXPORT_SYMBOL(drm_atomic_helper_plane_destroy_state);
403
404
405
406
407
408
409
410
411
412void
413__drm_atomic_helper_connector_state_reset(struct drm_connector_state *conn_state,
414 struct drm_connector *connector)
415{
416 conn_state->connector = connector;
417}
418EXPORT_SYMBOL(__drm_atomic_helper_connector_state_reset);
419
420
421
422
423
424
425
426
427
428
429
430
431
432void
433__drm_atomic_helper_connector_reset(struct drm_connector *connector,
434 struct drm_connector_state *conn_state)
435{
436 if (conn_state)
437 __drm_atomic_helper_connector_state_reset(conn_state, connector);
438
439 connector->state = conn_state;
440}
441EXPORT_SYMBOL(__drm_atomic_helper_connector_reset);
442
443
444
445
446
447
448
449
450
451void drm_atomic_helper_connector_reset(struct drm_connector *connector)
452{
453 struct drm_connector_state *conn_state =
454 kzalloc(sizeof(*conn_state), GFP_KERNEL);
455
456 if (connector->state)
457 __drm_atomic_helper_connector_destroy_state(connector->state);
458
459 kfree(connector->state);
460 __drm_atomic_helper_connector_reset(connector, conn_state);
461}
462EXPORT_SYMBOL(drm_atomic_helper_connector_reset);
463
464
465
466
467
468
469
470void drm_atomic_helper_connector_tv_reset(struct drm_connector *connector)
471{
472 struct drm_cmdline_mode *cmdline = &connector->cmdline_mode;
473 struct drm_connector_state *state = connector->state;
474
475 state->tv.margins.left = cmdline->tv_margins.left;
476 state->tv.margins.right = cmdline->tv_margins.right;
477 state->tv.margins.top = cmdline->tv_margins.top;
478 state->tv.margins.bottom = cmdline->tv_margins.bottom;
479}
480EXPORT_SYMBOL(drm_atomic_helper_connector_tv_reset);
481
482
483
484
485
486
487
488
489
490void
491__drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector,
492 struct drm_connector_state *state)
493{
494 memcpy(state, connector->state, sizeof(*state));
495 if (state->crtc)
496 drm_connector_get(connector);
497 state->commit = NULL;
498
499 if (state->hdr_output_metadata)
500 drm_property_blob_get(state->hdr_output_metadata);
501
502
503 state->writeback_job = NULL;
504}
505EXPORT_SYMBOL(__drm_atomic_helper_connector_duplicate_state);
506
507
508
509
510
511
512
513
514struct drm_connector_state *
515drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector)
516{
517 struct drm_connector_state *state;
518
519 if (WARN_ON(!connector->state))
520 return NULL;
521
522 state = kmalloc(sizeof(*state), GFP_KERNEL);
523 if (state)
524 __drm_atomic_helper_connector_duplicate_state(connector, state);
525
526 return state;
527}
528EXPORT_SYMBOL(drm_atomic_helper_connector_duplicate_state);
529
530
531
532
533
534
535
536
537
538void
539__drm_atomic_helper_connector_destroy_state(struct drm_connector_state *state)
540{
541 if (state->crtc)
542 drm_connector_put(state->connector);
543
544 if (state->commit)
545 drm_crtc_commit_put(state->commit);
546
547 if (state->writeback_job)
548 drm_writeback_cleanup_job(state->writeback_job);
549
550 drm_property_blob_put(state->hdr_output_metadata);
551}
552EXPORT_SYMBOL(__drm_atomic_helper_connector_destroy_state);
553
554
555
556
557
558
559
560
561
562void drm_atomic_helper_connector_destroy_state(struct drm_connector *connector,
563 struct drm_connector_state *state)
564{
565 __drm_atomic_helper_connector_destroy_state(state);
566 kfree(state);
567}
568EXPORT_SYMBOL(drm_atomic_helper_connector_destroy_state);
569
570
571
572
573
574
575
576
577
578void __drm_atomic_helper_private_obj_duplicate_state(struct drm_private_obj *obj,
579 struct drm_private_state *state)
580{
581 memcpy(state, obj->state, sizeof(*state));
582}
583EXPORT_SYMBOL(__drm_atomic_helper_private_obj_duplicate_state);
584
585
586
587
588
589
590
591
592
593void __drm_atomic_helper_bridge_duplicate_state(struct drm_bridge *bridge,
594 struct drm_bridge_state *state)
595{
596 __drm_atomic_helper_private_obj_duplicate_state(&bridge->base,
597 &state->base);
598 state->bridge = bridge;
599}
600EXPORT_SYMBOL(__drm_atomic_helper_bridge_duplicate_state);
601
602
603
604
605
606
607
608
609
610
611struct drm_bridge_state *
612drm_atomic_helper_bridge_duplicate_state(struct drm_bridge *bridge)
613{
614 struct drm_bridge_state *new;
615
616 if (WARN_ON(!bridge->base.state))
617 return NULL;
618
619 new = kzalloc(sizeof(*new), GFP_KERNEL);
620 if (new)
621 __drm_atomic_helper_bridge_duplicate_state(bridge, new);
622
623 return new;
624}
625EXPORT_SYMBOL(drm_atomic_helper_bridge_duplicate_state);
626
627
628
629
630
631
632
633
634
635
636
637
638void drm_atomic_helper_bridge_destroy_state(struct drm_bridge *bridge,
639 struct drm_bridge_state *state)
640{
641 kfree(state);
642}
643EXPORT_SYMBOL(drm_atomic_helper_bridge_destroy_state);
644
645
646
647
648
649
650
651
652
653
654
655void __drm_atomic_helper_bridge_reset(struct drm_bridge *bridge,
656 struct drm_bridge_state *state)
657{
658 memset(state, 0, sizeof(*state));
659 state->bridge = bridge;
660}
661EXPORT_SYMBOL(__drm_atomic_helper_bridge_reset);
662
663
664
665
666
667
668
669
670
671
672struct drm_bridge_state *
673drm_atomic_helper_bridge_reset(struct drm_bridge *bridge)
674{
675 struct drm_bridge_state *bridge_state;
676
677 bridge_state = kzalloc(sizeof(*bridge_state), GFP_KERNEL);
678 if (!bridge_state)
679 return ERR_PTR(-ENOMEM);
680
681 __drm_atomic_helper_bridge_reset(bridge, bridge_state);
682 return bridge_state;
683}
684EXPORT_SYMBOL(drm_atomic_helper_bridge_reset);
685