hc
2024-01-31 f9004dbfff8a3fbbd7e2a88c8a4327c7f2f8e5b2
kernel/include/drm/drm_atomic.h
....@@ -29,12 +29,13 @@
2929 #define DRM_ATOMIC_H_
3030
3131 #include <drm/drm_crtc.h>
32
+#include <drm/drm_util.h>
3233
3334 /**
3435 * struct drm_crtc_commit - track modeset commits on a CRTC
3536 *
3637 * This structure is used to track pending modeset changes and atomic commit on
37
- * a per-CRTC basis. Since updating the list should never block this structure
38
+ * a per-CRTC basis. Since updating the list should never block, this structure
3839 * is reference counted to allow waiters to safely wait on an event to complete,
3940 * without holding any locks.
4041 *
....@@ -59,8 +60,8 @@
5960 * wait for flip_done <----
6061 * clean up atomic state
6162 *
62
- * The important bit to know is that cleanup_done is the terminal event, but the
63
- * ordering between flip_done and hw_done is entirely up to the specific driver
63
+ * The important bit to know is that &cleanup_done is the terminal event, but the
64
+ * ordering between &flip_done and &hw_done is entirely up to the specific driver
6465 * and modeset state change.
6566 *
6667 * For an implementation of how to use this look at
....@@ -91,6 +92,9 @@
9192 * commit is sent to userspace, or when an out-fence is singalled. Note
9293 * that for most hardware, in most cases this happens after @hw_done is
9394 * signalled.
95
+ *
96
+ * Completion of this stage is signalled implicitly by calling
97
+ * drm_crtc_send_vblank_event() on &drm_crtc_state.event.
9498 */
9599 struct completion flip_done;
96100
....@@ -99,13 +103,16 @@
99103 *
100104 * Will be signalled when all hw register changes for this commit have
101105 * been written out. Especially when disabling a pipe this can be much
102
- * later than than @flip_done, since that can signal already when the
106
+ * later than @flip_done, since that can signal already when the
103107 * screen goes black, whereas to fully shut down a pipe more register
104108 * I/O is required.
105109 *
106110 * Note that this does not need to include separately reference-counted
107111 * resources like backing storage buffer pinning, or runtime pm
108112 * management.
113
+ *
114
+ * Drivers should call drm_atomic_helper_commit_hw_done() to signal
115
+ * completion of this stage.
109116 */
110117 struct completion hw_done;
111118
....@@ -117,6 +124,9 @@
117124 * a vblank wait completed it might be a bit later. This completion is
118125 * useful to throttle updates and avoid hardware updates getting ahead
119126 * of the buffer cleanup too much.
127
+ *
128
+ * Drivers should call drm_atomic_helper_commit_cleanup_done() to signal
129
+ * completion of this stage.
120130 */
121131 struct completion cleanup_done;
122132
....@@ -138,9 +148,9 @@
138148 /**
139149 * @abort_completion:
140150 *
141
- * A flag that's set after drm_atomic_helper_setup_commit takes a second
142
- * reference for the completion of $drm_crtc_state.event. It's used by
143
- * the free code to remove the second reference if commit fails.
151
+ * A flag that's set after drm_atomic_helper_setup_commit() takes a
152
+ * second reference for the completion of $drm_crtc_state.event. It's
153
+ * used by the free code to remove the second reference if commit fails.
144154 */
145155 bool abort_completion;
146156 };
....@@ -191,7 +201,7 @@
191201 * private objects. The structure itself is used as a vtable to identify the
192202 * associated private object type. Each private object type that needs to be
193203 * added to the atomic states is expected to have an implementation of these
194
- * hooks and pass a pointer to it's drm_private_state_funcs struct to
204
+ * hooks and pass a pointer to its drm_private_state_funcs struct to
195205 * drm_atomic_get_private_obj_state().
196206 */
197207 struct drm_private_state_funcs {
....@@ -227,8 +237,30 @@
227237 * Currently only tracks the state update functions and the opaque driver
228238 * private state itself, but in the future might also track which
229239 * &drm_modeset_lock is required to duplicate and update this object's state.
240
+ *
241
+ * All private objects must be initialized before the DRM device they are
242
+ * attached to is registered to the DRM subsystem (call to drm_dev_register())
243
+ * and should stay around until this DRM device is unregistered (call to
244
+ * drm_dev_unregister()). In other words, private objects lifetime is tied
245
+ * to the DRM device lifetime. This implies that:
246
+ *
247
+ * 1/ all calls to drm_atomic_private_obj_init() must be done before calling
248
+ * drm_dev_register()
249
+ * 2/ all calls to drm_atomic_private_obj_fini() must be done after calling
250
+ * drm_dev_unregister()
230251 */
231252 struct drm_private_obj {
253
+ /**
254
+ * @head: List entry used to attach a private object to a &drm_device
255
+ * (queued to &drm_mode_config.privobj_list).
256
+ */
257
+ struct list_head head;
258
+
259
+ /**
260
+ * @lock: Modeset lock to protect the state object.
261
+ */
262
+ struct drm_modeset_lock lock;
263
+
232264 /**
233265 * @state: Current atomic state for this driver private object.
234266 */
....@@ -242,6 +274,18 @@
242274 */
243275 const struct drm_private_state_funcs *funcs;
244276 };
277
+
278
+/**
279
+ * drm_for_each_privobj() - private object iterator
280
+ *
281
+ * @privobj: pointer to the current private object. Updated after each
282
+ * iteration
283
+ * @dev: the DRM device we want get private objects from
284
+ *
285
+ * Allows one to iterate over all private objects attached to @dev
286
+ */
287
+#define drm_for_each_privobj(privobj, dev) \
288
+ list_for_each_entry(privobj, &(dev)->mode_config.privobj_list, head)
245289
246290 /**
247291 * struct drm_private_state - base struct for driver private object state
....@@ -264,7 +308,6 @@
264308 * struct drm_atomic_state - the global state object for atomic updates
265309 * @ref: count of all references to this state (will not be freed until zero)
266310 * @dev: parent DRM device
267
- * @allow_modeset: allow full modeset
268311 * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
269312 * @async_update: hint for asynchronous plane update
270313 * @planes: pointer to array of structures with per-plane data
....@@ -283,9 +326,27 @@
283326 struct kref ref;
284327
285328 struct drm_device *dev;
329
+
330
+ /**
331
+ * @allow_modeset:
332
+ *
333
+ * Allow full modeset. This is used by the ATOMIC IOCTL handler to
334
+ * implement the DRM_MODE_ATOMIC_ALLOW_MODESET flag. Drivers should
335
+ * never consult this flag, instead looking at the output of
336
+ * drm_atomic_crtc_needs_modeset().
337
+ */
286338 bool allow_modeset : 1;
287339 bool legacy_cursor_update : 1;
288340 bool async_update : 1;
341
+ /**
342
+ * @duplicated:
343
+ *
344
+ * Indicates whether or not this atomic state was duplicated using
345
+ * drm_atomic_helper_duplicate_state(). Drivers and atomic helpers
346
+ * should use this to fixup normal inconsistencies in duplicated
347
+ * states.
348
+ */
349
+ bool duplicated : 1;
289350 struct __drm_planes_state *planes;
290351 struct __drm_crtcs_state *crtcs;
291352 int num_connector;
....@@ -302,7 +363,7 @@
302363 * When a connector or plane is not bound to any CRTC, it's still important
303364 * to preserve linearity to prevent the atomic states from being freed to early.
304365 *
305
- * This commit (if set) is not bound to any crtc, but will be completed when
366
+ * This commit (if set) is not bound to any CRTC, but will be completed when
306367 * drm_atomic_helper_commit_hw_done() is called.
307368 */
308369 struct drm_crtc_commit *fake_commit;
....@@ -384,9 +445,6 @@
384445 struct drm_crtc_state * __must_check
385446 drm_atomic_get_crtc_state(struct drm_atomic_state *state,
386447 struct drm_crtc *crtc);
387
-int drm_atomic_crtc_set_property(struct drm_crtc *crtc,
388
- struct drm_crtc_state *state, struct drm_property *property,
389
- uint64_t val);
390448 struct drm_plane_state * __must_check
391449 drm_atomic_get_plane_state(struct drm_atomic_state *state,
392450 struct drm_plane *plane);
....@@ -394,7 +452,8 @@
394452 drm_atomic_get_connector_state(struct drm_atomic_state *state,
395453 struct drm_connector *connector);
396454
397
-void drm_atomic_private_obj_init(struct drm_private_obj *obj,
455
+void drm_atomic_private_obj_init(struct drm_device *dev,
456
+ struct drm_private_obj *obj,
398457 struct drm_private_state *state,
399458 const struct drm_private_state_funcs *funcs);
400459 void drm_atomic_private_obj_fini(struct drm_private_obj *obj);
....@@ -402,14 +461,27 @@
402461 struct drm_private_state * __must_check
403462 drm_atomic_get_private_obj_state(struct drm_atomic_state *state,
404463 struct drm_private_obj *obj);
464
+struct drm_private_state *
465
+drm_atomic_get_old_private_obj_state(struct drm_atomic_state *state,
466
+ struct drm_private_obj *obj);
467
+struct drm_private_state *
468
+drm_atomic_get_new_private_obj_state(struct drm_atomic_state *state,
469
+ struct drm_private_obj *obj);
470
+
471
+struct drm_connector *
472
+drm_atomic_get_old_connector_for_encoder(struct drm_atomic_state *state,
473
+ struct drm_encoder *encoder);
474
+struct drm_connector *
475
+drm_atomic_get_new_connector_for_encoder(struct drm_atomic_state *state,
476
+ struct drm_encoder *encoder);
405477
406478 /**
407
- * drm_atomic_get_existing_crtc_state - get crtc state, if it exists
479
+ * drm_atomic_get_existing_crtc_state - get CRTC state, if it exists
408480 * @state: global atomic state object
409
- * @crtc: crtc to grab
481
+ * @crtc: CRTC to grab
410482 *
411
- * This function returns the crtc state for the given crtc, or NULL
412
- * if the crtc is not part of the global atomic state.
483
+ * This function returns the CRTC state for the given CRTC, or NULL
484
+ * if the CRTC is not part of the global atomic state.
413485 *
414486 * This function is deprecated, @drm_atomic_get_old_crtc_state or
415487 * @drm_atomic_get_new_crtc_state should be used instead.
....@@ -422,12 +494,12 @@
422494 }
423495
424496 /**
425
- * drm_atomic_get_old_crtc_state - get old crtc state, if it exists
497
+ * drm_atomic_get_old_crtc_state - get old CRTC state, if it exists
426498 * @state: global atomic state object
427
- * @crtc: crtc to grab
499
+ * @crtc: CRTC to grab
428500 *
429
- * This function returns the old crtc state for the given crtc, or
430
- * NULL if the crtc is not part of the global atomic state.
501
+ * This function returns the old CRTC state for the given CRTC, or
502
+ * NULL if the CRTC is not part of the global atomic state.
431503 */
432504 static inline struct drm_crtc_state *
433505 drm_atomic_get_old_crtc_state(struct drm_atomic_state *state,
....@@ -436,12 +508,12 @@
436508 return state->crtcs[drm_crtc_index(crtc)].old_state;
437509 }
438510 /**
439
- * drm_atomic_get_new_crtc_state - get new crtc state, if it exists
511
+ * drm_atomic_get_new_crtc_state - get new CRTC state, if it exists
440512 * @state: global atomic state object
441
- * @crtc: crtc to grab
513
+ * @crtc: CRTC to grab
442514 *
443
- * This function returns the new crtc state for the given crtc, or
444
- * NULL if the crtc is not part of the global atomic state.
515
+ * This function returns the new CRTC state for the given CRTC, or
516
+ * NULL if the CRTC is not part of the global atomic state.
445517 */
446518 static inline struct drm_crtc_state *
447519 drm_atomic_get_new_crtc_state(struct drm_atomic_state *state,
....@@ -598,24 +670,8 @@
598670 }
599671
600672 int __must_check
601
-drm_atomic_set_mode_for_crtc(struct drm_crtc_state *state,
602
- const struct drm_display_mode *mode);
603
-int __must_check
604
-drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state,
605
- struct drm_property_blob *blob);
606
-int __must_check
607
-drm_atomic_set_crtc_for_plane(struct drm_plane_state *plane_state,
608
- struct drm_crtc *crtc);
609
-void drm_atomic_set_fb_for_plane(struct drm_plane_state *plane_state,
610
- struct drm_framebuffer *fb);
611
-void drm_atomic_set_fence_for_plane(struct drm_plane_state *plane_state,
612
- struct dma_fence *fence);
613
-int __must_check
614
-drm_atomic_set_crtc_for_connector(struct drm_connector_state *conn_state,
615
- struct drm_crtc *crtc);
616
-int drm_atomic_set_writeback_fb_for_connector(
617
- struct drm_connector_state *conn_state,
618
- struct drm_framebuffer *fb);
673
+drm_atomic_add_encoder_bridges(struct drm_atomic_state *state,
674
+ struct drm_encoder *encoder);
619675 int __must_check
620676 drm_atomic_add_affected_connectors(struct drm_atomic_state *state,
621677 struct drm_crtc *crtc);
....@@ -649,6 +705,7 @@
649705 (__i)++) \
650706 for_each_if ((__state)->connectors[__i].ptr && \
651707 ((connector) = (__state)->connectors[__i].ptr, \
708
+ (void)(connector) /* Only to avoid unused-but-set-variable warning */, \
652709 (old_connector_state) = (__state)->connectors[__i].old_state, \
653710 (new_connector_state) = (__state)->connectors[__i].new_state, 1))
654711
....@@ -670,6 +727,7 @@
670727 (__i)++) \
671728 for_each_if ((__state)->connectors[__i].ptr && \
672729 ((connector) = (__state)->connectors[__i].ptr, \
730
+ (void)(connector) /* Only to avoid unused-but-set-variable warning */, \
673731 (old_connector_state) = (__state)->connectors[__i].old_state, 1))
674732
675733 /**
....@@ -690,7 +748,9 @@
690748 (__i)++) \
691749 for_each_if ((__state)->connectors[__i].ptr && \
692750 ((connector) = (__state)->connectors[__i].ptr, \
693
- (new_connector_state) = (__state)->connectors[__i].new_state, 1))
751
+ (void)(connector) /* Only to avoid unused-but-set-variable warning */, \
752
+ (new_connector_state) = (__state)->connectors[__i].new_state, \
753
+ (void)(new_connector_state) /* Only to avoid unused-but-set-variable warning */, 1))
694754
695755 /**
696756 * for_each_oldnew_crtc_in_state - iterate over all CRTCs in an atomic update
....@@ -710,7 +770,9 @@
710770 (__i)++) \
711771 for_each_if ((__state)->crtcs[__i].ptr && \
712772 ((crtc) = (__state)->crtcs[__i].ptr, \
773
+ (void)(crtc) /* Only to avoid unused-but-set-variable warning */, \
713774 (old_crtc_state) = (__state)->crtcs[__i].old_state, \
775
+ (void)(old_crtc_state) /* Only to avoid unused-but-set-variable warning */, \
714776 (new_crtc_state) = (__state)->crtcs[__i].new_state, 1))
715777
716778 /**
....@@ -749,7 +811,9 @@
749811 (__i)++) \
750812 for_each_if ((__state)->crtcs[__i].ptr && \
751813 ((crtc) = (__state)->crtcs[__i].ptr, \
752
- (new_crtc_state) = (__state)->crtcs[__i].new_state, 1))
814
+ (void)(crtc) /* Only to avoid unused-but-set-variable warning */, \
815
+ (new_crtc_state) = (__state)->crtcs[__i].new_state, \
816
+ (void)(new_crtc_state) /* Only to avoid unused-but-set-variable warning */, 1))
753817
754818 /**
755819 * for_each_oldnew_plane_in_state - iterate over all planes in an atomic update
....@@ -769,6 +833,7 @@
769833 (__i)++) \
770834 for_each_if ((__state)->planes[__i].ptr && \
771835 ((plane) = (__state)->planes[__i].ptr, \
836
+ (void)(plane) /* Only to avoid unused-but-set-variable warning */, \
772837 (old_plane_state) = (__state)->planes[__i].old_state,\
773838 (new_plane_state) = (__state)->planes[__i].new_state, 1))
774839
....@@ -829,7 +894,9 @@
829894 (__i)++) \
830895 for_each_if ((__state)->planes[__i].ptr && \
831896 ((plane) = (__state)->planes[__i].ptr, \
832
- (new_plane_state) = (__state)->planes[__i].new_state, 1))
897
+ (void)(plane) /* Only to avoid unused-but-set-variable warning */, \
898
+ (new_plane_state) = (__state)->planes[__i].new_state, \
899
+ (void)(new_plane_state) /* Only to avoid unused-but-set-variable warning */, 1))
833900
834901 /**
835902 * for_each_oldnew_private_obj_in_state - iterate over all private objects in an atomic update
....@@ -913,9 +980,92 @@
913980 state->connectors_changed;
914981 }
915982
916
-int drm_atomic_set_property(struct drm_atomic_state *state,
917
- struct drm_mode_object *obj,
918
- struct drm_property *prop,
919
- uint64_t prop_value);
983
+/**
984
+ * drm_atomic_crtc_effectively_active - compute whether CRTC is actually active
985
+ * @state: &drm_crtc_state for the CRTC
986
+ *
987
+ * When in self refresh mode, the crtc_state->active value will be false, since
988
+ * the CRTC is off. However in some cases we're interested in whether the CRTC
989
+ * is active, or effectively active (ie: it's connected to an active display).
990
+ * In these cases, use this function instead of just checking active.
991
+ */
992
+static inline bool
993
+drm_atomic_crtc_effectively_active(const struct drm_crtc_state *state)
994
+{
995
+ return state->active || state->self_refresh_active;
996
+}
997
+
998
+/**
999
+ * struct drm_bus_cfg - bus configuration
1000
+ *
1001
+ * This structure stores the configuration of a physical bus between two
1002
+ * components in an output pipeline, usually between two bridges, an encoder
1003
+ * and a bridge, or a bridge and a connector.
1004
+ *
1005
+ * The bus configuration is stored in &drm_bridge_state separately for the
1006
+ * input and output buses, as seen from the point of view of each bridge. The
1007
+ * bus configuration of a bridge output is usually identical to the
1008
+ * configuration of the next bridge's input, but may differ if the signals are
1009
+ * modified between the two bridges, for instance by an inverter on the board.
1010
+ * The input and output configurations of a bridge may differ if the bridge
1011
+ * modifies the signals internally, for instance by performing format
1012
+ * conversion, or modifying signals polarities.
1013
+ */
1014
+struct drm_bus_cfg {
1015
+ /**
1016
+ * @format: format used on this bus (one of the MEDIA_BUS_FMT_* format)
1017
+ *
1018
+ * This field should not be directly modified by drivers
1019
+ * (drm_atomic_bridge_chain_select_bus_fmts() takes care of the bus
1020
+ * format negotiation).
1021
+ */
1022
+ u32 format;
1023
+
1024
+ /**
1025
+ * @flags: DRM_BUS_* flags used on this bus
1026
+ */
1027
+ u32 flags;
1028
+};
1029
+
1030
+/**
1031
+ * struct drm_bridge_state - Atomic bridge state object
1032
+ */
1033
+struct drm_bridge_state {
1034
+ /**
1035
+ * @base: inherit from &drm_private_state
1036
+ */
1037
+ struct drm_private_state base;
1038
+
1039
+ /**
1040
+ * @bridge: the bridge this state refers to
1041
+ */
1042
+ struct drm_bridge *bridge;
1043
+
1044
+ /**
1045
+ * @input_bus_cfg: input bus configuration
1046
+ */
1047
+ struct drm_bus_cfg input_bus_cfg;
1048
+
1049
+ /**
1050
+ * @output_bus_cfg: input bus configuration
1051
+ */
1052
+ struct drm_bus_cfg output_bus_cfg;
1053
+};
1054
+
1055
+static inline struct drm_bridge_state *
1056
+drm_priv_to_bridge_state(struct drm_private_state *priv)
1057
+{
1058
+ return container_of(priv, struct drm_bridge_state, base);
1059
+}
1060
+
1061
+struct drm_bridge_state *
1062
+drm_atomic_get_bridge_state(struct drm_atomic_state *state,
1063
+ struct drm_bridge *bridge);
1064
+struct drm_bridge_state *
1065
+drm_atomic_get_old_bridge_state(struct drm_atomic_state *state,
1066
+ struct drm_bridge *bridge);
1067
+struct drm_bridge_state *
1068
+drm_atomic_get_new_bridge_state(struct drm_atomic_state *state,
1069
+ struct drm_bridge *bridge);
9201070
9211071 #endif /* DRM_ATOMIC_H_ */