xref: /linux/drivers/gpu/drm/i915/display/intel_global_state.h (revision 79790b6818e96c58fe2bffee1b418c16e64e7b80)
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright © 2020 Intel Corporation
4  */
5 
6 #ifndef __INTEL_GLOBAL_STATE_H__
7 #define __INTEL_GLOBAL_STATE_H__
8 
9 #include <linux/kref.h>
10 #include <linux/list.h>
11 
12 struct drm_i915_private;
13 struct intel_atomic_state;
14 struct intel_global_obj;
15 struct intel_global_state;
16 
17 struct intel_global_state_funcs {
18 	struct intel_global_state *(*atomic_duplicate_state)(struct intel_global_obj *obj);
19 	void (*atomic_destroy_state)(struct intel_global_obj *obj,
20 				     struct intel_global_state *state);
21 };
22 
23 struct intel_global_obj {
24 	struct list_head head;
25 	struct intel_global_state *state;
26 	const struct intel_global_state_funcs *funcs;
27 };
28 
29 #define intel_for_each_global_obj(obj, dev_priv) \
30 	list_for_each_entry(obj, &(dev_priv)->display.global.obj_list, head)
31 
32 #define for_each_new_global_obj_in_state(__state, obj, new_obj_state, __i) \
33 	for ((__i) = 0; \
34 	     (__i) < (__state)->num_global_objs && \
35 		     ((obj) = (__state)->global_objs[__i].ptr, \
36 		      (new_obj_state) = (__state)->global_objs[__i].new_state, 1); \
37 	     (__i)++) \
38 		for_each_if(obj)
39 
40 #define for_each_old_global_obj_in_state(__state, obj, old_obj_state, __i) \
41 	for ((__i) = 0; \
42 	     (__i) < (__state)->num_global_objs && \
43 		     ((obj) = (__state)->global_objs[__i].ptr, \
44 		      (old_obj_state) = (__state)->global_objs[__i].old_state, 1); \
45 	     (__i)++) \
46 		for_each_if(obj)
47 
48 #define for_each_oldnew_global_obj_in_state(__state, obj, old_obj_state, new_obj_state, __i) \
49 	for ((__i) = 0; \
50 	     (__i) < (__state)->num_global_objs && \
51 		     ((obj) = (__state)->global_objs[__i].ptr, \
52 		      (old_obj_state) = (__state)->global_objs[__i].old_state, \
53 		      (new_obj_state) = (__state)->global_objs[__i].new_state, 1); \
54 	     (__i)++) \
55 		for_each_if(obj)
56 
57 struct intel_global_commit;
58 
59 struct intel_global_state {
60 	struct intel_global_obj *obj;
61 	struct intel_atomic_state *state;
62 	struct intel_global_commit *commit;
63 	struct kref ref;
64 	bool changed, serialized;
65 };
66 
67 struct __intel_global_objs_state {
68 	struct intel_global_obj *ptr;
69 	struct intel_global_state *state, *old_state, *new_state;
70 };
71 
72 void intel_atomic_global_obj_init(struct drm_i915_private *dev_priv,
73 				  struct intel_global_obj *obj,
74 				  struct intel_global_state *state,
75 				  const struct intel_global_state_funcs *funcs);
76 void intel_atomic_global_obj_cleanup(struct drm_i915_private *dev_priv);
77 
78 struct intel_global_state *
79 intel_atomic_get_global_obj_state(struct intel_atomic_state *state,
80 				  struct intel_global_obj *obj);
81 struct intel_global_state *
82 intel_atomic_get_old_global_obj_state(struct intel_atomic_state *state,
83 				      struct intel_global_obj *obj);
84 struct intel_global_state *
85 intel_atomic_get_new_global_obj_state(struct intel_atomic_state *state,
86 				      struct intel_global_obj *obj);
87 
88 void intel_atomic_swap_global_state(struct intel_atomic_state *state);
89 void intel_atomic_clear_global_state(struct intel_atomic_state *state);
90 int intel_atomic_lock_global_state(struct intel_global_state *obj_state);
91 int intel_atomic_serialize_global_state(struct intel_global_state *obj_state);
92 
93 int intel_atomic_global_state_setup_commit(struct intel_atomic_state *state);
94 void intel_atomic_global_state_commit_done(struct intel_atomic_state *state);
95 int intel_atomic_global_state_wait_for_dependencies(struct intel_atomic_state *state);
96 
97 bool intel_atomic_global_state_is_serialized(struct intel_atomic_state *state);
98 
99 #endif
100