0001
0002
0003
0004
0005
0006 #include <linux/device.h>
0007
0008 #include <drm/drm_drv.h>
0009
0010 #include "i915_drv.h"
0011 #include "i915_utils.h"
0012
0013 #define FDO_BUG_MSG "Please file a bug on drm/i915; see " FDO_BUG_URL " for details."
0014
0015 void
0016 __i915_printk(struct drm_i915_private *dev_priv, const char *level,
0017 const char *fmt, ...)
0018 {
0019 static bool shown_bug_once;
0020 struct device *kdev = dev_priv->drm.dev;
0021 bool is_error = level[1] <= KERN_ERR[1];
0022 bool is_debug = level[1] == KERN_DEBUG[1];
0023 struct va_format vaf;
0024 va_list args;
0025
0026 if (is_debug && !drm_debug_enabled(DRM_UT_DRIVER))
0027 return;
0028
0029 va_start(args, fmt);
0030
0031 vaf.fmt = fmt;
0032 vaf.va = &args;
0033
0034 if (is_error)
0035 dev_printk(level, kdev, "%pV", &vaf);
0036 else
0037 dev_printk(level, kdev, "[" DRM_NAME ":%ps] %pV",
0038 __builtin_return_address(0), &vaf);
0039
0040 va_end(args);
0041
0042 if (is_error && !shown_bug_once) {
0043
0044
0045
0046
0047
0048 if (!test_taint(TAINT_USER))
0049 dev_notice(kdev, "%s", FDO_BUG_MSG);
0050 shown_bug_once = true;
0051 }
0052 }
0053
0054 void add_taint_for_CI(struct drm_i915_private *i915, unsigned int taint)
0055 {
0056 __i915_printk(i915, KERN_NOTICE, "CI tainted:%#x by %pS\n",
0057 taint, (void *)_RET_IP_);
0058
0059
0060 if (!i915_error_injected())
0061 __add_taint_for_CI(taint);
0062 }
0063
0064 #if IS_ENABLED(CONFIG_DRM_I915_DEBUG)
0065 static unsigned int i915_probe_fail_count;
0066
0067 int __i915_inject_probe_error(struct drm_i915_private *i915, int err,
0068 const char *func, int line)
0069 {
0070 if (i915_probe_fail_count >= i915_modparams.inject_probe_failure)
0071 return 0;
0072
0073 if (++i915_probe_fail_count < i915_modparams.inject_probe_failure)
0074 return 0;
0075
0076 __i915_printk(i915, KERN_INFO,
0077 "Injecting failure %d at checkpoint %u [%s:%d]\n",
0078 err, i915_modparams.inject_probe_failure, func, line);
0079 i915_modparams.inject_probe_failure = 0;
0080 return err;
0081 }
0082
0083 bool i915_error_injected(void)
0084 {
0085 return i915_probe_fail_count && !i915_modparams.inject_probe_failure;
0086 }
0087
0088 #endif
0089
0090 void cancel_timer(struct timer_list *t)
0091 {
0092 if (!timer_active(t))
0093 return;
0094
0095 del_timer(t);
0096 WRITE_ONCE(t->expires, 0);
0097 }
0098
0099 void set_timer_ms(struct timer_list *t, unsigned long timeout)
0100 {
0101 if (!timeout) {
0102 cancel_timer(t);
0103 return;
0104 }
0105
0106 timeout = msecs_to_jiffies(timeout);
0107
0108
0109
0110
0111
0112
0113
0114 barrier();
0115
0116
0117 mod_timer(t, jiffies + timeout ?: 1);
0118 }
0119
0120 bool i915_vtd_active(struct drm_i915_private *i915)
0121 {
0122 if (device_iommu_mapped(i915->drm.dev))
0123 return true;
0124
0125
0126 return i915_run_as_guest();
0127 }