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/list.h> 10 11 struct drm_i915_private; 12 struct intel_atomic_state; 13 struct intel_global_obj; 14 struct intel_global_state; 15 16 struct intel_global_state_funcs { 17 struct intel_global_state *(*atomic_duplicate_state)(struct intel_global_obj *obj); 18 void (*atomic_destroy_state)(struct intel_global_obj *obj, 19 struct intel_global_state *state); 20 }; 21 22 struct intel_global_obj { 23 struct list_head head; 24 struct intel_global_state *state; 25 const struct intel_global_state_funcs *funcs; 26 }; 27 28 #define intel_for_each_global_obj(obj, dev_priv) \ 29 list_for_each_entry(obj, &(dev_priv)->global_obj_list, head) 30 31 #define for_each_new_global_obj_in_state(__state, obj, new_obj_state, __i) \ 32 for ((__i) = 0; \ 33 (__i) < (__state)->num_global_objs && \ 34 ((obj) = (__state)->global_objs[__i].ptr, \ 35 (new_obj_state) = (__state)->global_objs[__i].new_state, 1); \ 36 (__i)++) \ 37 for_each_if(obj) 38 39 #define for_each_old_global_obj_in_state(__state, obj, new_obj_state, __i) \ 40 for ((__i) = 0; \ 41 (__i) < (__state)->num_global_objs && \ 42 ((obj) = (__state)->global_objs[__i].ptr, \ 43 (new_obj_state) = (__state)->global_objs[__i].old_state, 1); \ 44 (__i)++) \ 45 for_each_if(obj) 46 47 #define for_each_oldnew_global_obj_in_state(__state, obj, old_obj_state, new_obj_state, __i) \ 48 for ((__i) = 0; \ 49 (__i) < (__state)->num_global_objs && \ 50 ((obj) = (__state)->global_objs[__i].ptr, \ 51 (old_obj_state) = (__state)->global_objs[__i].old_state, \ 52 (new_obj_state) = (__state)->global_objs[__i].new_state, 1); \ 53 (__i)++) \ 54 for_each_if(obj) 55 56 struct intel_global_state { 57 struct intel_atomic_state *state; 58 bool changed; 59 }; 60 61 struct __intel_global_objs_state { 62 struct intel_global_obj *ptr; 63 struct intel_global_state *state, *old_state, *new_state; 64 }; 65 66 void intel_atomic_global_obj_init(struct drm_i915_private *dev_priv, 67 struct intel_global_obj *obj, 68 struct intel_global_state *state, 69 const struct intel_global_state_funcs *funcs); 70 void intel_atomic_global_obj_cleanup(struct drm_i915_private *dev_priv); 71 72 struct intel_global_state * 73 intel_atomic_get_global_obj_state(struct intel_atomic_state *state, 74 struct intel_global_obj *obj); 75 struct intel_global_state * 76 intel_atomic_get_old_global_obj_state(struct intel_atomic_state *state, 77 struct intel_global_obj *obj); 78 struct intel_global_state * 79 intel_atomic_get_new_global_obj_state(struct intel_atomic_state *state, 80 struct intel_global_obj *obj); 81 82 void intel_atomic_swap_global_state(struct intel_atomic_state *state); 83 void intel_atomic_clear_global_state(struct intel_atomic_state *state); 84 int intel_atomic_lock_global_state(struct intel_global_state *obj_state); 85 int intel_atomic_serialize_global_state(struct intel_global_state *obj_state); 86 87 #endif 88