2 * Copyright © 2016 Intel Corporation
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:
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
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
25 #include "../i915_selftest.h"
27 #include "gt/intel_gt.h"
29 static int intel_fw_table_check(const struct intel_forcewake_range *ranges,
30 unsigned int num_ranges,
36 for (i = 0, prev = -1; i < num_ranges; i++, ranges++) {
37 /* Check that the table is watertight */
38 if (is_watertight && (prev + 1) != (s32)ranges->start) {
39 pr_err("%s: entry[%d]:(%x, %x) is not watertight to previous (%x)\n",
40 __func__, i, ranges->start, ranges->end, prev);
44 /* Check that the table never goes backwards */
45 if (prev >= (s32)ranges->start) {
46 pr_err("%s: entry[%d]:(%x, %x) is less than the previous (%x)\n",
47 __func__, i, ranges->start, ranges->end, prev);
51 /* Check that the entry is valid */
52 if (ranges->start >= ranges->end) {
53 pr_err("%s: entry[%d]:(%x, %x) has negative length\n",
54 __func__, i, ranges->start, ranges->end);
64 static int intel_shadow_table_check(void)
67 const struct i915_range *regs;
70 { gen8_shadowed_regs, ARRAY_SIZE(gen8_shadowed_regs) },
71 { gen11_shadowed_regs, ARRAY_SIZE(gen11_shadowed_regs) },
72 { gen12_shadowed_regs, ARRAY_SIZE(gen12_shadowed_regs) },
73 { dg2_shadowed_regs, ARRAY_SIZE(dg2_shadowed_regs) },
74 { mtl_shadowed_regs, ARRAY_SIZE(mtl_shadowed_regs) },
75 { xelpmp_shadowed_regs, ARRAY_SIZE(xelpmp_shadowed_regs) },
77 const struct i915_range *range;
81 for (j = 0; j < ARRAY_SIZE(range_lists); ++j) {
82 range = range_lists[j].regs;
83 for (i = 0, prev = -1; i < range_lists[j].size; i++, range++) {
84 if (range->end < range->start) {
85 pr_err("%s: range[%d]:(%06x-%06x) has end before start\n",
86 __func__, i, range->start, range->end);
90 if (prev >= (s32)range->start) {
91 pr_err("%s: range[%d]:(%06x-%06x) is before end of previous (%06x)\n",
92 __func__, i, range->start, range->end, prev);
96 if (range->start % 4) {
97 pr_err("%s: range[%d]:(%06x-%06x) has non-dword-aligned start\n",
98 __func__, i, range->start, range->end);
109 int intel_uncore_mock_selftests(void)
112 const struct intel_forcewake_range *ranges;
113 unsigned int num_ranges;
116 { __vlv_fw_ranges, ARRAY_SIZE(__vlv_fw_ranges), false },
117 { __chv_fw_ranges, ARRAY_SIZE(__chv_fw_ranges), false },
118 { __gen9_fw_ranges, ARRAY_SIZE(__gen9_fw_ranges), true },
119 { __gen11_fw_ranges, ARRAY_SIZE(__gen11_fw_ranges), true },
120 { __gen12_fw_ranges, ARRAY_SIZE(__gen12_fw_ranges), true },
121 { __mtl_fw_ranges, ARRAY_SIZE(__mtl_fw_ranges), true },
122 { __xelpmp_fw_ranges, ARRAY_SIZE(__xelpmp_fw_ranges), true },
126 for (i = 0; i < ARRAY_SIZE(fw); i++) {
127 err = intel_fw_table_check(fw[i].ranges,
129 fw[i].is_watertight);
134 err = intel_shadow_table_check();
141 static int live_forcewake_ops(void *arg)
143 static const struct reg {
147 unsigned long platforms;
162 struct intel_gt *gt = arg;
163 struct intel_uncore_forcewake_domain *domain;
164 struct intel_uncore *uncore = gt->uncore;
165 struct intel_engine_cs *engine;
166 enum intel_engine_id id;
167 intel_wakeref_t wakeref;
171 GEM_BUG_ON(gt->awake);
173 /* vlv/chv with their pcu behave differently wrt reads */
174 if (IS_VALLEYVIEW(gt->i915) || IS_CHERRYVIEW(gt->i915)) {
175 pr_debug("PCU fakes forcewake badly; skipping\n");
180 * Not quite as reliable across the gen as one would hope.
182 * Either our theory of operation is incorrect, or there remain
183 * external parties interfering with the powerwells.
185 * https://bugs.freedesktop.org/show_bug.cgi?id=110210
187 if (!IS_ENABLED(CONFIG_DRM_I915_SELFTEST_BROKEN))
190 /* We have to pick carefully to get the exact behaviour we need */
191 for (r = registers; r->name; r++)
192 if (IS_GRAPHICS_VER(gt->i915, r->min_graphics_ver, r->max_graphics_ver))
195 pr_debug("Forcewaked register not known for %s; skipping\n",
196 intel_platform_name(INTEL_INFO(gt->i915)->platform));
200 wakeref = intel_runtime_pm_get(uncore->rpm);
202 for_each_fw_domain(domain, uncore, tmp) {
203 smp_store_mb(domain->active, false);
204 if (!hrtimer_cancel(&domain->timer))
207 intel_uncore_fw_release_timer(&domain->timer);
210 for_each_engine(engine, gt, id) {
211 i915_reg_t mmio = _MMIO(engine->mmio_base + r->offset);
212 u32 __iomem *reg = intel_uncore_regs(uncore) + engine->mmio_base + r->offset;
213 enum forcewake_domains fw_domains;
216 if (!engine->default_state)
219 fw_domains = intel_uncore_forcewake_for_reg(uncore, mmio,
224 for_each_fw_domain_masked(domain, fw_domains, uncore, tmp) {
225 if (!domain->wake_count)
228 pr_err("fw_domain %s still active, aborting test!\n",
229 intel_uncore_forcewake_domain_to_str(domain->id));
234 intel_uncore_forcewake_get(uncore, fw_domains);
236 intel_uncore_forcewake_put(uncore, fw_domains);
238 /* Flush the forcewake release (delayed onto a timer) */
239 for_each_fw_domain_masked(domain, fw_domains, uncore, tmp) {
240 smp_store_mb(domain->active, false);
241 if (hrtimer_cancel(&domain->timer))
242 intel_uncore_fw_release_timer(&domain->timer);
245 err = wait_ack_clear(domain, FORCEWAKE_KERNEL);
248 pr_err("Failed to clear fw_domain %s\n",
249 intel_uncore_forcewake_domain_to_str(domain->id));
255 pr_err("%s:%s was zero while fw was held!\n",
256 engine->name, r->name);
261 /* We then expect the read to return 0 outside of the fw */
262 if (wait_for(readl(reg) == 0, 100)) {
263 pr_err("%s:%s=%0x, fw_domains 0x%x still up after 100ms!\n",
264 engine->name, r->name, readl(reg), fw_domains);
271 intel_runtime_pm_put(uncore->rpm, wakeref);
275 static int live_forcewake_domains(void *arg)
277 #define FW_RANGE 0x40000
278 struct intel_gt *gt = arg;
279 struct intel_uncore *uncore = gt->uncore;
280 unsigned long *valid;
284 if (!HAS_FPGA_DBG_UNCLAIMED(gt->i915) &&
285 !IS_VALLEYVIEW(gt->i915) &&
286 !IS_CHERRYVIEW(gt->i915))
290 * This test may lockup the machine or cause GPU hangs afterwards.
292 if (!IS_ENABLED(CONFIG_DRM_I915_SELFTEST_BROKEN))
295 valid = bitmap_zalloc(FW_RANGE, GFP_KERNEL);
299 intel_uncore_forcewake_get(uncore, FORCEWAKE_ALL);
301 check_for_unclaimed_mmio(uncore);
302 for (offset = 0; offset < FW_RANGE; offset += 4) {
303 i915_reg_t reg = { offset };
305 intel_uncore_posting_read_fw(uncore, reg);
306 if (!check_for_unclaimed_mmio(uncore))
307 set_bit(offset, valid);
310 intel_uncore_forcewake_put(uncore, FORCEWAKE_ALL);
313 for_each_set_bit(offset, valid, FW_RANGE) {
314 i915_reg_t reg = { offset };
316 iosf_mbi_punit_acquire();
317 intel_uncore_forcewake_reset(uncore);
318 iosf_mbi_punit_release();
320 check_for_unclaimed_mmio(uncore);
322 intel_uncore_posting_read_fw(uncore, reg);
323 if (check_for_unclaimed_mmio(uncore)) {
324 pr_err("Unclaimed mmio read to register 0x%04x\n",
334 static int live_fw_table(void *arg)
336 struct intel_gt *gt = arg;
338 /* Confirm the table we load is still valid */
339 return intel_fw_table_check(gt->uncore->fw_domains_table,
340 gt->uncore->fw_domains_table_entries,
341 GRAPHICS_VER(gt->i915) >= 9);
344 int intel_uncore_live_selftests(struct drm_i915_private *i915)
346 static const struct i915_subtest tests[] = {
347 SUBTEST(live_fw_table),
348 SUBTEST(live_forcewake_ops),
349 SUBTEST(live_forcewake_domains),
352 return intel_gt_live_subtests(tests, to_gt(i915));