| 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 |  | 
|---|
| 14 | void 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) | 
|---|
| 25 | static unsigned int i915_probe_fail_count; | 
|---|
| 26 |  | 
|---|
| 27 | int __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 |  | 
|---|
| 43 | bool i915_error_injected(void) | 
|---|
| 44 | { | 
|---|
| 45 | return i915_probe_fail_count && !i915_modparams.inject_probe_failure; | 
|---|
| 46 | } | 
|---|
| 47 |  | 
|---|
| 48 | #endif | 
|---|
| 49 |  | 
|---|
| 50 | bool i915_vtd_active(struct drm_i915_private *i915) | 
|---|
| 51 | { | 
|---|
| 52 | if (device_iommu_mapped(dev: i915->drm.dev)) | 
|---|
| 53 | return true; | 
|---|
| 54 |  | 
|---|
| 55 | /* Running as a guest, we assume the host is enforcing VT'd */ | 
|---|
| 56 | return i915_run_as_guest(); | 
|---|
| 57 | } | 
|---|
| 58 |  | 
|---|
| 59 | bool i915_direct_stolen_access(struct drm_i915_private *i915) | 
|---|
| 60 | { | 
|---|
| 61 | /* | 
|---|
| 62 | * Wa_22018444074 | 
|---|
| 63 | * | 
|---|
| 64 | * Access via BAR can hang MTL, go directly to GSM/DSM, | 
|---|
| 65 | * except for VM guests which won't have access to it. | 
|---|
| 66 | * | 
|---|
| 67 | * Normally this would not work but on MTL the system firmware | 
|---|
| 68 | * should have relaxed the access permissions sufficiently. | 
|---|
| 69 | * 0x138914==0x1 indicates that the firmware has done its job. | 
|---|
| 70 | */ | 
|---|
| 71 | return IS_METEORLAKE(i915) && !i915_run_as_guest() && | 
|---|
| 72 | intel_uncore_read(uncore: &i915->uncore, MTL_PCODE_STOLEN_ACCESS) == STOLEN_ACCESS_ALLOWED; | 
|---|
| 73 | } | 
|---|
| 74 |  | 
|---|