| 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 | #include <drm/drm_print.h> |
| 10 | |
| 11 | #include "i915_drv.h" |
| 12 | #include "i915_reg.h" |
| 13 | #include "i915_utils.h" |
| 14 | |
| 15 | void add_taint_for_CI(struct drm_i915_private *i915, unsigned int taint) |
| 16 | { |
| 17 | drm_notice(&i915->drm, "CI tainted: %#x by %pS\n" , |
| 18 | taint, __builtin_return_address(0)); |
| 19 | |
| 20 | /* Failures that occur during fault injection testing are expected */ |
| 21 | if (!i915_error_injected()) |
| 22 | __add_taint_for_CI(taint); |
| 23 | } |
| 24 | |
| 25 | #if IS_ENABLED(CONFIG_DRM_I915_DEBUG) |
| 26 | static unsigned int i915_probe_fail_count; |
| 27 | |
| 28 | int __i915_inject_probe_error(struct drm_i915_private *i915, int err, |
| 29 | const char *func, int line) |
| 30 | { |
| 31 | if (i915_probe_fail_count >= i915_modparams.inject_probe_failure) |
| 32 | return 0; |
| 33 | |
| 34 | if (++i915_probe_fail_count < i915_modparams.inject_probe_failure) |
| 35 | return 0; |
| 36 | |
| 37 | drm_info(&i915->drm, "Injecting failure %d at checkpoint %u [%s:%d]\n" , |
| 38 | err, i915_modparams.inject_probe_failure, func, line); |
| 39 | |
| 40 | i915_modparams.inject_probe_failure = 0; |
| 41 | return err; |
| 42 | } |
| 43 | |
| 44 | bool i915_error_injected(void) |
| 45 | { |
| 46 | return i915_probe_fail_count && !i915_modparams.inject_probe_failure; |
| 47 | } |
| 48 | |
| 49 | #endif |
| 50 | |
| 51 | bool i915_vtd_active(struct drm_i915_private *i915) |
| 52 | { |
| 53 | if (device_iommu_mapped(dev: i915->drm.dev)) |
| 54 | return true; |
| 55 | |
| 56 | /* Running as a guest, we assume the host is enforcing VT'd */ |
| 57 | return i915_run_as_guest(); |
| 58 | } |
| 59 | |
| 60 | bool i915_direct_stolen_access(struct drm_i915_private *i915) |
| 61 | { |
| 62 | /* |
| 63 | * Wa_22018444074 |
| 64 | * |
| 65 | * Access via BAR can hang MTL, go directly to GSM/DSM, |
| 66 | * except for VM guests which won't have access to it. |
| 67 | * |
| 68 | * Normally this would not work but on MTL the system firmware |
| 69 | * should have relaxed the access permissions sufficiently. |
| 70 | * 0x138914==0x1 indicates that the firmware has done its job. |
| 71 | */ |
| 72 | return IS_METEORLAKE(i915) && !i915_run_as_guest() && |
| 73 | intel_uncore_read(uncore: &i915->uncore, MTL_PCODE_STOLEN_ACCESS) == STOLEN_ACCESS_ALLOWED; |
| 74 | } |
| 75 | |