1 /* SPDX-License-Identifier: GPL-2.0 OR MIT */ 1 2 3 #ifndef __DRM_EXEC_H__ 4 #define __DRM_EXEC_H__ 5 6 #include <linux/compiler.h> 7 #include <linux/ww_mutex.h> 8 9 #define DRM_EXEC_INTERRUPTIBLE_WAIT BIT(0) 10 #define DRM_EXEC_IGNORE_DUPLICATES BIT(1) 11 12 struct drm_gem_object; 13 14 /** 15 * struct drm_exec - Execution context 16 */ 17 struct drm_exec { 18 /** 19 * @flags: Flags to control locking be 20 */ 21 u32 flags; 22 23 /** 24 * @ticket: WW ticket used for acquiri 25 */ 26 struct ww_acquire_ctx ticket; 27 28 /** 29 * @num_objects: number of objects loc 30 */ 31 unsigned int num_objects; 32 33 /** 34 * @max_objects: maximum objects in ar 35 */ 36 unsigned int max_objects; 37 38 /** 39 * @objects: array of the locked objec 40 */ 41 struct drm_gem_object **objects; 42 43 /** 44 * @contended: contended GEM object we 45 */ 46 struct drm_gem_object *contended; 47 48 /** 49 * @prelocked: already locked GEM obje 50 */ 51 struct drm_gem_object *prelocked; 52 }; 53 54 /** 55 * drm_exec_obj() - Return the object for a gi 56 * @exec: Pointer to the drm_exec context 57 * @index: The index. 58 * 59 * Return: Pointer to the locked object corres 60 * index is within the number of locked object 61 */ 62 static inline struct drm_gem_object * 63 drm_exec_obj(struct drm_exec *exec, unsigned l 64 { 65 return index < exec->num_objects ? exe 66 } 67 68 /** 69 * drm_exec_for_each_locked_object - iterate o 70 * @exec: drm_exec object 71 * @index: unsigned long index for the iterati 72 * @obj: the current GEM object 73 * 74 * Iterate over all the locked GEM objects ins 75 */ 76 #define drm_exec_for_each_locked_object(exec, 77 for ((index) = 0; ((obj) = drm_exec_ob 78 79 /** 80 * drm_exec_for_each_locked_object_reverse - i 81 * objects in reverse locking order 82 * @exec: drm_exec object 83 * @index: unsigned long index for the iterati 84 * @obj: the current GEM object 85 * 86 * Iterate over all the locked GEM objects ins 87 * reverse locking order. Note that @index may 88 * but that will be caught by drm_exec_obj(), 89 */ 90 #define drm_exec_for_each_locked_object_revers 91 for ((index) = (exec)->num_objects - 1 92 ((obj) = drm_exec_obj(exec, index 93 94 /** 95 * drm_exec_until_all_locked - loop until all 96 * @exec: drm_exec object 97 * 98 * Core functionality of the drm_exec object. 99 * locked and no more contention exists. At th 100 * guaranteed that no GEM object is locked. 101 * 102 * Since labels can't be defined local to the 103 * to make sure that the retry is only used fr 104 */ 105 #define drm_exec_until_all_locked(exec) 106 __PASTE(__drm_exec_, __LINE__): 107 for (void *__drm_exec_retry_ptr; ({ 108 __drm_exec_retry_ptr = &&__PAS 109 (void)__drm_exec_retry_ptr; 110 drm_exec_cleanup(exec); 111 });) 112 113 /** 114 * drm_exec_retry_on_contention - restart the 115 * @exec: drm_exec object 116 * 117 * Control flow helper to continue when a cont 118 * clean up and re-start the loop to prepare a 119 */ 120 #define drm_exec_retry_on_contention(exec) 121 do { 122 if (unlikely(drm_exec_is_conte 123 goto *__drm_exec_retry 124 } while (0) 125 126 /** 127 * drm_exec_is_contended - check for contentio 128 * @exec: drm_exec object 129 * 130 * Returns true if the drm_exec object has run 131 * locking a GEM object and needs to clean up. 132 */ 133 static inline bool drm_exec_is_contended(struc 134 { 135 return !!exec->contended; 136 } 137 138 void drm_exec_init(struct drm_exec *exec, u32 139 void drm_exec_fini(struct drm_exec *exec); 140 bool drm_exec_cleanup(struct drm_exec *exec); 141 int drm_exec_lock_obj(struct drm_exec *exec, s 142 void drm_exec_unlock_obj(struct drm_exec *exec 143 int drm_exec_prepare_obj(struct drm_exec *exec 144 unsigned int num_fenc 145 int drm_exec_prepare_array(struct drm_exec *ex 146 struct drm_gem_obje 147 unsigned int num_ob 148 unsigned int num_fe 149 150 #endif 151
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.