1 /* SPDX-License-Identifier: MIT */
3 * Copyright © 2020 Intel Corporation
6 #ifndef __INTEL_GLOBAL_STATE_H__
7 #define __INTEL_GLOBAL_STATE_H__
9 #include <linux/kref.h>
10 #include <linux/list.h>
12 struct drm_i915_private
;
13 struct intel_atomic_state
;
14 struct intel_global_obj
;
15 struct intel_global_state
;
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
);
23 struct intel_global_obj
{
24 struct list_head head
;
25 struct intel_global_state
*state
;
26 const struct intel_global_state_funcs
*funcs
;
29 #define intel_for_each_global_obj(obj, dev_priv) \
30 list_for_each_entry(obj, &(dev_priv)->global_obj_list, head)
32 #define for_each_new_global_obj_in_state(__state, obj, new_obj_state, __i) \
34 (__i) < (__state)->num_global_objs && \
35 ((obj) = (__state)->global_objs[__i].ptr, \
36 (new_obj_state) = (__state)->global_objs[__i].new_state, 1); \
40 #define for_each_old_global_obj_in_state(__state, obj, new_obj_state, __i) \
42 (__i) < (__state)->num_global_objs && \
43 ((obj) = (__state)->global_objs[__i].ptr, \
44 (new_obj_state) = (__state)->global_objs[__i].old_state, 1); \
48 #define for_each_oldnew_global_obj_in_state(__state, obj, old_obj_state, new_obj_state, __i) \
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); \
57 struct intel_global_state
{
58 struct intel_global_obj
*obj
;
59 struct intel_atomic_state
*state
;
64 struct __intel_global_objs_state
{
65 struct intel_global_obj
*ptr
;
66 struct intel_global_state
*state
, *old_state
, *new_state
;
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
);
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
);
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
);