1 // SPDX-License-Identifier: MIT
3 * Copyright © 2019 Intel Corporation
6 #include <linux/device.h>
8 #include <drm/drm_drv.h>
11 #include "i915_utils.h"
13 #define FDO_BUG_MSG "Please file a bug on drm/i915; see " FDO_BUG_URL " for details."
16 __i915_printk(struct drm_i915_private *dev_priv, const char *level,
19 static bool shown_bug_once;
20 struct device *kdev = dev_priv->drm.dev;
21 bool is_error = level[1] <= KERN_ERR[1];
22 bool is_debug = level[1] == KERN_DEBUG[1];
26 if (is_debug && !drm_debug_enabled(DRM_UT_DRIVER))
35 dev_printk(level, kdev, "%pV", &vaf);
37 dev_printk(level, kdev, "[" DRM_NAME ":%ps] %pV",
38 __builtin_return_address(0), &vaf);
42 if (is_error && !shown_bug_once) {
44 * Ask the user to file a bug report for the error, except
45 * if they may have caused the bug by fiddling with unsafe
48 if (!test_taint(TAINT_USER))
49 dev_notice(kdev, "%s", FDO_BUG_MSG);
50 shown_bug_once = true;
54 void add_taint_for_CI(struct drm_i915_private *i915, unsigned int taint)
56 __i915_printk(i915, KERN_NOTICE, "CI tainted:%#x by %pS\n",
57 taint, (void *)_RET_IP_);
59 /* Failures that occur during fault injection testing are expected */
60 if (!i915_error_injected())
61 __add_taint_for_CI(taint);
64 #if IS_ENABLED(CONFIG_DRM_I915_DEBUG)
65 static unsigned int i915_probe_fail_count;
67 int __i915_inject_probe_error(struct drm_i915_private *i915, int err,
68 const char *func, int line)
70 if (i915_probe_fail_count >= i915_modparams.inject_probe_failure)
73 if (++i915_probe_fail_count < i915_modparams.inject_probe_failure)
76 __i915_printk(i915, KERN_INFO,
77 "Injecting failure %d at checkpoint %u [%s:%d]\n",
78 err, i915_modparams.inject_probe_failure, func, line);
79 i915_modparams.inject_probe_failure = 0;
83 bool i915_error_injected(void)
85 return i915_probe_fail_count && !i915_modparams.inject_probe_failure;
90 void cancel_timer(struct timer_list *t)
96 WRITE_ONCE(t->expires, 0);
99 void set_timer_ms(struct timer_list *t, unsigned long timeout)
106 timeout = msecs_to_jiffies(timeout);
109 * Paranoia to make sure the compiler computes the timeout before
110 * loading 'jiffies' as jiffies is volatile and may be updated in
111 * the background by a timer tick. All to reduce the complexity
112 * of the addition and reduce the risk of losing a jiffie.
116 /* Keep t->expires = 0 reserved to indicate a canceled timer. */
117 mod_timer(t, jiffies + timeout ?: 1);
120 bool i915_vtd_active(struct drm_i915_private *i915)
122 if (device_iommu_mapped(i915->drm.dev))
125 /* Running as a guest, we assume the host is enforcing VT'd */
126 return i915_run_as_guest();