i915_utils.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright © 2016 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. *
  23. */
  24. #ifndef __I915_UTILS_H
  25. #define __I915_UTILS_H
  26. #include <linux/overflow.h>
  27. #include <linux/sched.h>
  28. #include <linux/string_helpers.h>
  29. #include <linux/types.h>
  30. #include <linux/workqueue.h>
  31. #include <linux/sched/clock.h>
  32. #ifdef CONFIG_X86
  33. #include <asm/hypervisor.h>
  34. #endif
  35. struct drm_i915_private;
  36. #define MISSING_CASE(x) WARN(1, "Missing case (%s == %ld)\n", \
  37. __stringify(x), (long)(x))
  38. #define i915_probe_error(i915, fmt, ...) ({ \
  39. drm_err(&(i915)->drm, fmt, ##__VA_ARGS__); \
  40. })
  41. #define fetch_and_zero(ptr) ({ \
  42. typeof(*ptr) __T = *(ptr); \
  43. *(ptr) = (typeof(*ptr))0; \
  44. __T; \
  45. })
  46. /*
  47. * check_user_mbz: Check that a user value exists and is zero
  48. *
  49. * Frequently in our uABI we reserve space for future extensions, and
  50. * two ensure that userspace is prepared we enforce that space must
  51. * be zero. (Then any future extension can safely assume a default value
  52. * of 0.)
  53. *
  54. * check_user_mbz() combines checking that the user pointer is accessible
  55. * and that the contained value is zero.
  56. *
  57. * Returns: -EFAULT if not accessible, -EINVAL if !zero, or 0 on success.
  58. */
  59. #define check_user_mbz(U) ({ \
  60. typeof(*(U)) mbz__; \
  61. get_user(mbz__, (U)) ? -EFAULT : mbz__ ? -EINVAL : 0; \
  62. })
  63. #define __mask_next_bit(mask) ({ \
  64. int __idx = ffs(mask) - 1; \
  65. mask &= ~BIT(__idx); \
  66. __idx; \
  67. })
  68. static inline bool is_power_of_2_u64(u64 n)
  69. {
  70. return (n != 0 && ((n & (n - 1)) == 0));
  71. }
  72. void add_taint_for_CI(struct drm_i915_private *i915, unsigned int taint);
  73. static inline void __add_taint_for_CI(unsigned int taint)
  74. {
  75. /*
  76. * The system is "ok", just about surviving for the user, but
  77. * CI results are now unreliable as the HW is very suspect.
  78. * CI checks the taint state after every test and will reboot
  79. * the machine if the kernel is tainted.
  80. */
  81. add_taint(taint, LOCKDEP_STILL_OK);
  82. }
  83. static inline bool i915_run_as_guest(void)
  84. {
  85. #if IS_ENABLED(CONFIG_X86)
  86. return !hypervisor_is_type(X86_HYPER_NATIVE);
  87. #else
  88. /* Not supported yet */
  89. return false;
  90. #endif
  91. }
  92. bool i915_vtd_active(struct drm_i915_private *i915);
  93. bool i915_direct_stolen_access(struct drm_i915_private *i915);
  94. #endif /* !__I915_UTILS_H */