xref: /linux/drivers/gpu/drm/i915/display/intel_global_state.h (revision 24bce201d79807b668bf9d9e0aca801c5c0d5f78)
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)->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, new_obj_state, __i) \
41 	for ((__i) = 0; \
42 	     (__i) < (__state)->num_global_objs && \
43 		     ((obj) = (__state)->global_objs[__i].ptr, \
44 		      (new_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_state {
58 	struct intel_global_obj *obj;
59 	struct intel_atomic_state *state;
60 	struct kref ref;
61 	bool changed;
62 };
63 
64 struct __intel_global_objs_state {
65 	struct intel_global_obj *ptr;
66 	struct intel_global_state *state, *old_state, *new_state;
67 };
68 
69 void intel_atomic_global_obj_init(struct drm_i915_private *dev_priv,
70 				  struct intel_global_obj *obj,
71 				  struct intel_global_state *state,
72 				  const struct intel_global_state_funcs *funcs);
73 void intel_atomic_global_obj_cleanup(struct drm_i915_private *dev_priv);
74 
75 struct intel_global_state *
76 intel_atomic_get_global_obj_state(struct intel_atomic_state *state,
77 				  struct intel_global_obj *obj);
78 struct intel_global_state *
79 intel_atomic_get_old_global_obj_state(struct intel_atomic_state *state,
80 				      struct intel_global_obj *obj);
81 struct intel_global_state *
82 intel_atomic_get_new_global_obj_state(struct intel_atomic_state *state,
83 				      struct intel_global_obj *obj);
84 
85 void intel_atomic_swap_global_state(struct intel_atomic_state *state);
86 void intel_atomic_clear_global_state(struct intel_atomic_state *state);
87 int intel_atomic_lock_global_state(struct intel_global_state *obj_state);
88 int intel_atomic_serialize_global_state(struct intel_global_state *obj_state);
89 
90 #endif
91