18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Internal Header for the Direct Rendering Manager 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright 2018 Intel Corporation 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 78c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 88c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation 98c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 108c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 118c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 128c2ecf20Sopenharmony_ci * 138c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the next 148c2ecf20Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 158c2ecf20Sopenharmony_ci * Software. 168c2ecf20Sopenharmony_ci * 178c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 188c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 198c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 208c2ecf20Sopenharmony_ci * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 218c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 228c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 238c2ecf20Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE. 248c2ecf20Sopenharmony_ci */ 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci#ifndef _DRM_UTIL_H_ 278c2ecf20Sopenharmony_ci#define _DRM_UTIL_H_ 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci/** 308c2ecf20Sopenharmony_ci * DOC: drm utils 318c2ecf20Sopenharmony_ci * 328c2ecf20Sopenharmony_ci * Macros and inline functions that does not naturally belong in other places 338c2ecf20Sopenharmony_ci */ 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 368c2ecf20Sopenharmony_ci#include <linux/kgdb.h> 378c2ecf20Sopenharmony_ci#include <linux/preempt.h> 388c2ecf20Sopenharmony_ci#include <linux/smp.h> 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci/* 418c2ecf20Sopenharmony_ci * Use EXPORT_SYMBOL_FOR_TESTS_ONLY() for functions that shall 428c2ecf20Sopenharmony_ci * only be visible for drmselftests. 438c2ecf20Sopenharmony_ci */ 448c2ecf20Sopenharmony_ci#if defined(CONFIG_DRM_EXPORT_FOR_TESTS) 458c2ecf20Sopenharmony_ci#define EXPORT_SYMBOL_FOR_TESTS_ONLY(x) EXPORT_SYMBOL(x) 468c2ecf20Sopenharmony_ci#else 478c2ecf20Sopenharmony_ci#define EXPORT_SYMBOL_FOR_TESTS_ONLY(x) 488c2ecf20Sopenharmony_ci#endif 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci/** 518c2ecf20Sopenharmony_ci * for_each_if - helper for handling conditionals in various for_each macros 528c2ecf20Sopenharmony_ci * @condition: The condition to check 538c2ecf20Sopenharmony_ci * 548c2ecf20Sopenharmony_ci * Typical use:: 558c2ecf20Sopenharmony_ci * 568c2ecf20Sopenharmony_ci * #define for_each_foo_bar(x, y) \' 578c2ecf20Sopenharmony_ci * list_for_each_entry(x, y->list, head) \' 588c2ecf20Sopenharmony_ci * for_each_if(x->something == SOMETHING) 598c2ecf20Sopenharmony_ci * 608c2ecf20Sopenharmony_ci * The for_each_if() macro makes the use of for_each_foo_bar() less error 618c2ecf20Sopenharmony_ci * prone. 628c2ecf20Sopenharmony_ci */ 638c2ecf20Sopenharmony_ci#define for_each_if(condition) if (!(condition)) {} else 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci/** 668c2ecf20Sopenharmony_ci * drm_can_sleep - returns true if currently okay to sleep 678c2ecf20Sopenharmony_ci * 688c2ecf20Sopenharmony_ci * This function shall not be used in new code. 698c2ecf20Sopenharmony_ci * The check for running in atomic context may not work - see linux/preempt.h. 708c2ecf20Sopenharmony_ci * 718c2ecf20Sopenharmony_ci * FIXME: All users of drm_can_sleep should be removed (see todo.rst) 728c2ecf20Sopenharmony_ci * 738c2ecf20Sopenharmony_ci * Returns: 748c2ecf20Sopenharmony_ci * False if kgdb is active, we are in atomic context or irqs are disabled. 758c2ecf20Sopenharmony_ci */ 768c2ecf20Sopenharmony_cistatic inline bool drm_can_sleep(void) 778c2ecf20Sopenharmony_ci{ 788c2ecf20Sopenharmony_ci if (in_atomic() || in_dbg_master() || irqs_disabled()) 798c2ecf20Sopenharmony_ci return false; 808c2ecf20Sopenharmony_ci return true; 818c2ecf20Sopenharmony_ci} 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci#endif 84