xref: /netbsd-src/sys/external/bsd/drm2/dist/include/drm/drm_util.h (revision c58db6da0a032dee0aaaa7fd27f9ee2294505f83)
1*c58db6daSriastradh /*	$NetBSD: drm_util.h,v 1.4 2021/12/19 10:32:47 riastradh Exp $	*/
24e390cabSriastradh 
34e390cabSriastradh /*
44e390cabSriastradh  * Internal Header for the Direct Rendering Manager
54e390cabSriastradh  *
64e390cabSriastradh  * Copyright 2018 Intel Corporation
74e390cabSriastradh  *
84e390cabSriastradh  * Permission is hereby granted, free of charge, to any person obtaining a
94e390cabSriastradh  * copy of this software and associated documentation files (the "Software"),
104e390cabSriastradh  * to deal in the Software without restriction, including without limitation
114e390cabSriastradh  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
124e390cabSriastradh  * and/or sell copies of the Software, and to permit persons to whom the
134e390cabSriastradh  * Software is furnished to do so, subject to the following conditions:
144e390cabSriastradh  *
154e390cabSriastradh  * The above copyright notice and this permission notice (including the next
164e390cabSriastradh  * paragraph) shall be included in all copies or substantial portions of the
174e390cabSriastradh  * Software.
184e390cabSriastradh  *
194e390cabSriastradh  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
204e390cabSriastradh  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
214e390cabSriastradh  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
224e390cabSriastradh  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
234e390cabSriastradh  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
244e390cabSriastradh  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
254e390cabSriastradh  * OTHER DEALINGS IN THE SOFTWARE.
264e390cabSriastradh  */
274e390cabSriastradh 
284e390cabSriastradh #ifndef _DRM_UTIL_H_
294e390cabSriastradh #define _DRM_UTIL_H_
304e390cabSriastradh 
314e390cabSriastradh /**
324e390cabSriastradh  * DOC: drm utils
334e390cabSriastradh  *
344e390cabSriastradh  * Macros and inline functions that does not naturally belong in other places
354e390cabSriastradh  */
364e390cabSriastradh 
374e390cabSriastradh #include <linux/interrupt.h>
384e390cabSriastradh #include <linux/kgdb.h>
394e390cabSriastradh #include <linux/preempt.h>
404e390cabSriastradh #include <linux/smp.h>
414e390cabSriastradh 
42*c58db6daSriastradh #ifdef __NetBSD__
43*c58db6daSriastradh #include <drm/drm_wait_netbsd.h>
44*c58db6daSriastradh #endif
45*c58db6daSriastradh 
464e390cabSriastradh /*
474e390cabSriastradh  * Use EXPORT_SYMBOL_FOR_TESTS_ONLY() for functions that shall
484e390cabSriastradh  * only be visible for drmselftests.
494e390cabSriastradh  */
504e390cabSriastradh #if defined(CONFIG_DRM_EXPORT_FOR_TESTS)
514e390cabSriastradh #define EXPORT_SYMBOL_FOR_TESTS_ONLY(x) EXPORT_SYMBOL(x)
524e390cabSriastradh #else
534e390cabSriastradh #define EXPORT_SYMBOL_FOR_TESTS_ONLY(x)
544e390cabSriastradh #endif
554e390cabSriastradh 
564e390cabSriastradh /**
574e390cabSriastradh  * for_each_if - helper for handling conditionals in various for_each macros
584e390cabSriastradh  * @condition: The condition to check
594e390cabSriastradh  *
604e390cabSriastradh  * Typical use::
614e390cabSriastradh  *
624e390cabSriastradh  *	#define for_each_foo_bar(x, y) \'
634e390cabSriastradh  *		list_for_each_entry(x, y->list, head) \'
644e390cabSriastradh  *			for_each_if(x->something == SOMETHING)
654e390cabSriastradh  *
664e390cabSriastradh  * The for_each_if() macro makes the use of for_each_foo_bar() less error
674e390cabSriastradh  * prone.
684e390cabSriastradh  */
694e390cabSriastradh #define for_each_if(condition) if (!(condition)) {} else
704e390cabSriastradh 
714e390cabSriastradh /**
724e390cabSriastradh  * drm_can_sleep - returns true if currently okay to sleep
734e390cabSriastradh  *
744e390cabSriastradh  * This function shall not be used in new code.
754e390cabSriastradh  * The check for running in atomic context may not work - see linux/preempt.h.
764e390cabSriastradh  *
774e390cabSriastradh  * FIXME: All users of drm_can_sleep should be removed (see todo.rst)
784e390cabSriastradh  *
794e390cabSriastradh  * Returns:
804e390cabSriastradh  * False if kgdb is active, we are in atomic context or irqs are disabled.
814e390cabSriastradh  */
drm_can_sleep(void)824e390cabSriastradh static inline bool drm_can_sleep(void)
834e390cabSriastradh {
842b0f1cf4Sriastradh #ifdef __NetBSD__
852b0f1cf4Sriastradh 	return false;		/* XXX */
862b0f1cf4Sriastradh #else
874e390cabSriastradh 	if (in_atomic() || in_dbg_master() || irqs_disabled())
884e390cabSriastradh 		return false;
894e390cabSriastradh 	return true;
902b0f1cf4Sriastradh #endif
914e390cabSriastradh }
924e390cabSriastradh 
934e390cabSriastradh #endif
94