i915_utils.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // SPDX-License-Identifier: MIT
  2. /*
  3. * Copyright © 2019 Intel Corporation
  4. */
  5. #include <linux/device.h>
  6. #include <drm/drm_drv.h>
  7. #include "i915_drv.h"
  8. #include "i915_reg.h"
  9. #include "i915_utils.h"
  10. void add_taint_for_CI(struct drm_i915_private *i915, unsigned int taint)
  11. {
  12. drm_notice(&i915->drm, "CI tainted: %#x by %pS\n",
  13. taint, __builtin_return_address(0));
  14. /* Failures that occur during fault injection testing are expected */
  15. if (!i915_error_injected())
  16. __add_taint_for_CI(taint);
  17. }
  18. #if IS_ENABLED(CONFIG_DRM_I915_DEBUG)
  19. static unsigned int i915_probe_fail_count;
  20. int __i915_inject_probe_error(struct drm_i915_private *i915, int err,
  21. const char *func, int line)
  22. {
  23. if (i915_probe_fail_count >= i915_modparams.inject_probe_failure)
  24. return 0;
  25. if (++i915_probe_fail_count < i915_modparams.inject_probe_failure)
  26. return 0;
  27. drm_info(&i915->drm, "Injecting failure %d at checkpoint %u [%s:%d]\n",
  28. err, i915_modparams.inject_probe_failure, func, line);
  29. i915_modparams.inject_probe_failure = 0;
  30. return err;
  31. }
  32. bool i915_error_injected(void)
  33. {
  34. return i915_probe_fail_count && !i915_modparams.inject_probe_failure;
  35. }
  36. #endif
  37. void cancel_timer(struct timer_list *t)
  38. {
  39. if (!timer_active(t))
  40. return;
  41. del_timer(t);
  42. WRITE_ONCE(t->expires, 0);
  43. }
  44. void set_timer_ms(struct timer_list *t, unsigned long timeout)
  45. {
  46. if (!timeout) {
  47. cancel_timer(t);
  48. return;
  49. }
  50. timeout = msecs_to_jiffies(timeout);
  51. /*
  52. * Paranoia to make sure the compiler computes the timeout before
  53. * loading 'jiffies' as jiffies is volatile and may be updated in
  54. * the background by a timer tick. All to reduce the complexity
  55. * of the addition and reduce the risk of losing a jiffy.
  56. */
  57. barrier();
  58. /* Keep t->expires = 0 reserved to indicate a canceled timer. */
  59. mod_timer(t, jiffies + timeout ?: 1);
  60. }
  61. bool i915_vtd_active(struct drm_i915_private *i915)
  62. {
  63. if (device_iommu_mapped(i915->drm.dev))
  64. return true;
  65. /* Running as a guest, we assume the host is enforcing VT'd */
  66. return i915_run_as_guest();
  67. }
  68. bool i915_direct_stolen_access(struct drm_i915_private *i915)
  69. {
  70. /*
  71. * Wa_22018444074
  72. *
  73. * Access via BAR can hang MTL, go directly to GSM/DSM,
  74. * except for VM guests which won't have access to it.
  75. *
  76. * Normally this would not work but on MTL the system firmware
  77. * should have relaxed the access permissions sufficiently.
  78. * 0x138914==0x1 indicates that the firmware has done its job.
  79. */
  80. return IS_METEORLAKE(i915) && !i915_run_as_guest() &&
  81. intel_uncore_read(&i915->uncore, MTL_PCODE_STOLEN_ACCESS) == STOLEN_ACCESS_ALLOWED;
  82. }