drm_util.h 2.6 KB

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