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