Loading...
1// SPDX-License-Identifier: MIT
2/*
3 * Copyright © 2019 Intel Corporation
4 */
5
6#include <linux/device.h>
7
8#include <drm/drm_drv.h>
9
10#include "i915_drv.h"
11#include "i915_reg.h"
12#include "i915_utils.h"
13
14void add_taint_for_CI(struct drm_i915_private *i915, unsigned int taint)
15{
16 drm_notice(&i915->drm, "CI tainted: %#x by %pS\n",
17 taint, __builtin_return_address(0));
18
19 /* Failures that occur during fault injection testing are expected */
20 if (!i915_error_injected())
21 __add_taint_for_CI(taint);
22}
23
24#if IS_ENABLED(CONFIG_DRM_I915_DEBUG)
25static unsigned int i915_probe_fail_count;
26
27int __i915_inject_probe_error(struct drm_i915_private *i915, int err,
28 const char *func, int line)
29{
30 if (i915_probe_fail_count >= i915_modparams.inject_probe_failure)
31 return 0;
32
33 if (++i915_probe_fail_count < i915_modparams.inject_probe_failure)
34 return 0;
35
36 drm_info(&i915->drm, "Injecting failure %d at checkpoint %u [%s:%d]\n",
37 err, i915_modparams.inject_probe_failure, func, line);
38
39 i915_modparams.inject_probe_failure = 0;
40 return err;
41}
42
43bool i915_error_injected(void)
44{
45 return i915_probe_fail_count && !i915_modparams.inject_probe_failure;
46}
47
48#endif
49
50void cancel_timer(struct timer_list *t)
51{
52 if (!timer_active(t))
53 return;
54
55 del_timer(t);
56 WRITE_ONCE(t->expires, 0);
57}
58
59void set_timer_ms(struct timer_list *t, unsigned long timeout)
60{
61 if (!timeout) {
62 cancel_timer(t);
63 return;
64 }
65
66 timeout = msecs_to_jiffies(timeout);
67
68 /*
69 * Paranoia to make sure the compiler computes the timeout before
70 * loading 'jiffies' as jiffies is volatile and may be updated in
71 * the background by a timer tick. All to reduce the complexity
72 * of the addition and reduce the risk of losing a jiffy.
73 */
74 barrier();
75
76 /* Keep t->expires = 0 reserved to indicate a canceled timer. */
77 mod_timer(t, jiffies + timeout ?: 1);
78}
79
80bool i915_vtd_active(struct drm_i915_private *i915)
81{
82 if (device_iommu_mapped(i915->drm.dev))
83 return true;
84
85 /* Running as a guest, we assume the host is enforcing VT'd */
86 return i915_run_as_guest();
87}
88
89bool i915_direct_stolen_access(struct drm_i915_private *i915)
90{
91 /*
92 * Wa_22018444074
93 *
94 * Access via BAR can hang MTL, go directly to GSM/DSM,
95 * except for VM guests which won't have access to it.
96 *
97 * Normally this would not work but on MTL the system firmware
98 * should have relaxed the access permissions sufficiently.
99 * 0x138914==0x1 indicates that the firmware has done its job.
100 */
101 return IS_METEORLAKE(i915) && !i915_run_as_guest() &&
102 intel_uncore_read(&i915->uncore, MTL_PCODE_STOLEN_ACCESS) == STOLEN_ACCESS_ALLOWED;
103}
1// SPDX-License-Identifier: MIT
2/*
3 * Copyright © 2019 Intel Corporation
4 */
5
6#include <linux/device.h>
7
8#include <drm/drm_drv.h>
9
10#include "i915_drv.h"
11#include "i915_utils.h"
12
13#define FDO_BUG_MSG "Please file a bug on drm/i915; see " FDO_BUG_URL " for details."
14
15void
16__i915_printk(struct drm_i915_private *dev_priv, const char *level,
17 const char *fmt, ...)
18{
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];
23 struct va_format vaf;
24 va_list args;
25
26 if (is_debug && !drm_debug_enabled(DRM_UT_DRIVER))
27 return;
28
29 va_start(args, fmt);
30
31 vaf.fmt = fmt;
32 vaf.va = &args;
33
34 if (is_error)
35 dev_printk(level, kdev, "%pV", &vaf);
36 else
37 dev_printk(level, kdev, "[" DRM_NAME ":%ps] %pV",
38 __builtin_return_address(0), &vaf);
39
40 va_end(args);
41
42 if (is_error && !shown_bug_once) {
43 /*
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
46 * module parameters.
47 */
48 if (!test_taint(TAINT_USER))
49 dev_notice(kdev, "%s", FDO_BUG_MSG);
50 shown_bug_once = true;
51 }
52}
53
54void add_taint_for_CI(struct drm_i915_private *i915, unsigned int taint)
55{
56 __i915_printk(i915, KERN_NOTICE, "CI tainted:%#x by %pS\n",
57 taint, (void *)_RET_IP_);
58
59 /* Failures that occur during fault injection testing are expected */
60 if (!i915_error_injected())
61 __add_taint_for_CI(taint);
62}
63
64#if IS_ENABLED(CONFIG_DRM_I915_DEBUG)
65static unsigned int i915_probe_fail_count;
66
67int __i915_inject_probe_error(struct drm_i915_private *i915, int err,
68 const char *func, int line)
69{
70 if (i915_probe_fail_count >= i915_modparams.inject_probe_failure)
71 return 0;
72
73 if (++i915_probe_fail_count < i915_modparams.inject_probe_failure)
74 return 0;
75
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;
80 return err;
81}
82
83bool i915_error_injected(void)
84{
85 return i915_probe_fail_count && !i915_modparams.inject_probe_failure;
86}
87
88#endif
89
90void cancel_timer(struct timer_list *t)
91{
92 if (!timer_active(t))
93 return;
94
95 del_timer(t);
96 WRITE_ONCE(t->expires, 0);
97}
98
99void set_timer_ms(struct timer_list *t, unsigned long timeout)
100{
101 if (!timeout) {
102 cancel_timer(t);
103 return;
104 }
105
106 timeout = msecs_to_jiffies(timeout);
107
108 /*
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.
113 */
114 barrier();
115
116 /* Keep t->expires = 0 reserved to indicate a canceled timer. */
117 mod_timer(t, jiffies + timeout ?: 1);
118}
119
120bool i915_vtd_active(struct drm_i915_private *i915)
121{
122 if (device_iommu_mapped(i915->drm.dev))
123 return true;
124
125 /* Running as a guest, we assume the host is enforcing VT'd */
126 return i915_run_as_guest();
127}