1 /* $NetBSD: drm_util.h,v 1.4 2021/12/19 10:32:47 riastradh Exp $ */ 2 3 /* 4 * Internal Header for the Direct Rendering Manager 5 * 6 * Copyright 2018 Intel Corporation 7 * 8 * Permission is hereby granted, free of charge, to any person obtaining a 9 * copy of this software and associated documentation files (the "Software"), 10 * to deal in the Software without restriction, including without limitation 11 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 12 * and/or sell copies of the Software, and to permit persons to whom the 13 * Software is furnished to do so, subject to the following conditions: 14 * 15 * The above copyright notice and this permission notice (including the next 16 * paragraph) shall be included in all copies or substantial portions of the 17 * Software. 18 * 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 22 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 * OTHER DEALINGS IN THE SOFTWARE. 26 */ 27 28 #ifndef _DRM_UTIL_H_ 29 #define _DRM_UTIL_H_ 30 31 /** 32 * DOC: drm utils 33 * 34 * Macros and inline functions that does not naturally belong in other places 35 */ 36 37 #include <linux/interrupt.h> 38 #include <linux/kgdb.h> 39 #include <linux/preempt.h> 40 #include <linux/smp.h> 41 42 #ifdef __NetBSD__ 43 #include <drm/drm_wait_netbsd.h> 44 #endif 45 46 /* 47 * Use EXPORT_SYMBOL_FOR_TESTS_ONLY() for functions that shall 48 * only be visible for drmselftests. 49 */ 50 #if defined(CONFIG_DRM_EXPORT_FOR_TESTS) 51 #define EXPORT_SYMBOL_FOR_TESTS_ONLY(x) EXPORT_SYMBOL(x) 52 #else 53 #define EXPORT_SYMBOL_FOR_TESTS_ONLY(x) 54 #endif 55 56 /** 57 * for_each_if - helper for handling conditionals in various for_each macros 58 * @condition: The condition to check 59 * 60 * Typical use:: 61 * 62 * #define for_each_foo_bar(x, y) \' 63 * list_for_each_entry(x, y->list, head) \' 64 * for_each_if(x->something == SOMETHING) 65 * 66 * The for_each_if() macro makes the use of for_each_foo_bar() less error 67 * prone. 68 */ 69 #define for_each_if(condition) if (!(condition)) {} else 70 71 /** 72 * drm_can_sleep - returns true if currently okay to sleep 73 * 74 * This function shall not be used in new code. 75 * The check for running in atomic context may not work - see linux/preempt.h. 76 * 77 * FIXME: All users of drm_can_sleep should be removed (see todo.rst) 78 * 79 * Returns: 80 * False if kgdb is active, we are in atomic context or irqs are disabled. 81 */ 82 static inline bool drm_can_sleep(void) 83 { 84 #ifdef __NetBSD__ 85 return false; /* XXX */ 86 #else 87 if (in_atomic() || in_dbg_master() || irqs_disabled()) 88 return false; 89 return true; 90 #endif 91 } 92 93 #endif 94