]> git.baikalelectronics.ru Git - kernel.git/commitdiff
drm/i915: Use per device iommu check
authorTvrtko Ursulin <tvrtko.ursulin@intel.com>
Fri, 26 Nov 2021 14:14:24 +0000 (14:14 +0000)
committerTvrtko Ursulin <tvrtko.ursulin@intel.com>
Wed, 1 Dec 2021 09:21:47 +0000 (09:21 +0000)
With both integrated and discrete Intel GPUs in a system, the current
global check of intel_iommu_gfx_mapped, as done from intel_vtd_active()
may not be completely accurate.

In this patch we add i915 parameter to intel_vtd_active() in order to
prepare it for multiple GPUs and we also change the check away from Intel
specific intel_iommu_gfx_mapped (global exported by the Intel IOMMU
driver) to probing the presence of IOMMU on a specific device using
device_iommu_mapped().

This will return true both for IOMMU pass-through and address translation
modes which matches the current behaviour. If in the future we wanted to
distinguish between these two modes we could either use
iommu_get_domain_for_dev() and check for __IOMMU_DOMAIN_PAGING bit
indicating address translation, or ask for a new API to be exported from
the IOMMU core code.

v2:
  * Check for dmar translation specifically, not just iommu domain. (Baolu)

v3:
 * Go back to plain "any domain" check for now, rewrite commit message.

v4:
 * Use device_iommu_mapped. (Robin, Baolu)

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Lu Baolu <baolu.lu@linux.intel.com>
Cc: Lucas De Marchi <lucas.demarchi@intel.com>
Cc: Robin Murphy <robin.murphy@arm.com>
Acked-by: Robin Murphy <robin.murphy@arm.com>
Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20211126141424.493753-1-tvrtko.ursulin@linux.intel.com
12 files changed:
drivers/gpu/drm/i915/display/intel_bw.c
drivers/gpu/drm/i915/display/intel_display.c
drivers/gpu/drm/i915/display/intel_fbc.c
drivers/gpu/drm/i915/gem/i915_gem_stolen.c
drivers/gpu/drm/i915/gem/i915_gemfs.c
drivers/gpu/drm/i915/gt/intel_ggtt.c
drivers/gpu/drm/i915/i915_debugfs.c
drivers/gpu/drm/i915/i915_drv.c
drivers/gpu/drm/i915/i915_drv.h
drivers/gpu/drm/i915/i915_gpu_error.c
drivers/gpu/drm/i915/intel_device_info.c
drivers/gpu/drm/i915/intel_pm.c

index 8d9d888e931611f2f9f9558d4468e1299c4bcebd..a4d8088e4f71d624c3cc9ed467d4f1f732e87446 100644 (file)
@@ -490,7 +490,7 @@ static unsigned int intel_bw_data_rate(struct drm_i915_private *dev_priv,
        for_each_pipe(dev_priv, pipe)
                data_rate += bw_state->data_rate[pipe];
 
-       if (DISPLAY_VER(dev_priv) >= 13 && intel_vtd_active())
+       if (DISPLAY_VER(dev_priv) >= 13 && intel_vtd_active(dev_priv))
                data_rate = data_rate * 105 / 100;
 
        return data_rate;
index 17057bc74cec33ed3dbcdc9112dd0fb2ff8fc3a7..06e64289b9d1161d61aaed75045f764d05ed5e0b 100644 (file)
@@ -1919,7 +1919,7 @@ static bool needs_async_flip_vtd_wa(const struct intel_crtc_state *crtc_state)
 {
        struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
 
-       return crtc_state->uapi.async_flip && intel_vtd_active() &&
+       return crtc_state->uapi.async_flip && intel_vtd_active(i915) &&
                (DISPLAY_VER(i915) == 9 || IS_BROADWELL(i915) || IS_HASWELL(i915));
 }
 
index 1f66de77a6b1e4934d62fec188f01607db2ad30d..c4044420642510706eafab2b57400b231d9c9243 100644 (file)
@@ -1539,7 +1539,7 @@ static int intel_sanitize_fbc_option(struct drm_i915_private *dev_priv)
 static bool need_fbc_vtd_wa(struct drm_i915_private *dev_priv)
 {
        /* WaFbcTurnOffFbcWhenHyperVisorIsUsed:skl,bxt */
-       if (intel_vtd_active() &&
+       if (intel_vtd_active(dev_priv) &&
            (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv))) {
                drm_info(&dev_priv->drm,
                         "Disabling framebuffer compression (FBC) to prevent screen flicker with VT-d enabled\n");
index 80680395bb3bb8ffff6f9b9a2483405476dd732b..bce03d74a0b475df16d2000f64ee65abc54ed0e6 100644 (file)
@@ -399,7 +399,7 @@ static int i915_gem_init_stolen(struct intel_memory_region *mem)
                return 0;
        }
 
-       if (intel_vtd_active() && GRAPHICS_VER(i915) < 8) {
+       if (intel_vtd_active(i915) && GRAPHICS_VER(i915) < 8) {
                drm_notice(&i915->drm,
                           "%s, disabling use of stolen memory\n",
                           "DMAR active");
index 182da3c047717ebdd879c9f4b88e5704c7dad73f..7271fbf813fa1162ce54e05d804a47de1e05ad63 100644 (file)
@@ -32,7 +32,7 @@ int i915_gemfs_init(struct drm_i915_private *i915)
         */
 
        opts = NULL;
-       if (intel_vtd_active()) {
+       if (intel_vtd_active(i915)) {
                if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) {
                        opts = huge_opt;
                        drm_info(&i915->drm,
index 57c97554393b9a8942c114cf6e96980267c4cfe9..b943f202e35acecf404a4e7d0a85f967d88e2678 100644 (file)
@@ -104,7 +104,7 @@ static bool needs_idle_maps(struct drm_i915_private *i915)
         * Query intel_iommu to see if we need the workaround. Presumably that
         * was loaded first.
         */
-       if (!intel_vtd_active())
+       if (!intel_vtd_active(i915))
                return false;
 
        if (GRAPHICS_VER(i915) == 5 && IS_MOBILE(i915))
@@ -1216,7 +1216,7 @@ int i915_ggtt_probe_hw(struct drm_i915_private *i915)
        if (ret)
                return ret;
 
-       if (intel_vtd_active())
+       if (intel_vtd_active(i915))
                drm_info(&i915->drm, "VT-d active for gfx access\n");
 
        return 0;
index fe638b5da7c0b95cbc1ff01a640e8988564a4816..390d541f64ea873b7399294fa7aea0da8d9656d7 100644 (file)
@@ -65,6 +65,7 @@ static int i915_capabilities(struct seq_file *m, void *data)
 
        intel_device_info_print_static(INTEL_INFO(i915), &p);
        intel_device_info_print_runtime(RUNTIME_INFO(i915), &p);
+       i915_print_iommu_status(i915, &p);
        intel_gt_info_print(&i915->gt.info, &p);
        intel_driver_caps_print(&i915->caps, &p);
 
index e140628dc0c5b6ea95d065d77aa9a3a172e84407..6ad1555ed8f0bfb3a63987a3338009608f5de3f9 100644 (file)
@@ -738,6 +738,12 @@ static void i915_driver_unregister(struct drm_i915_private *dev_priv)
        i915_gem_driver_unregister(dev_priv);
 }
 
+void
+i915_print_iommu_status(struct drm_i915_private *i915, struct drm_printer *p)
+{
+       drm_printf(p, "iommu: %s\n", enableddisabled(intel_vtd_active(i915)));
+}
+
 static void i915_welcome_messages(struct drm_i915_private *dev_priv)
 {
        if (drm_debug_enabled(DRM_UT_DRIVER)) {
@@ -753,6 +759,7 @@ static void i915_welcome_messages(struct drm_i915_private *dev_priv)
 
                intel_device_info_print_static(INTEL_INFO(dev_priv), &p);
                intel_device_info_print_runtime(RUNTIME_INFO(dev_priv), &p);
+               i915_print_iommu_status(dev_priv, &p);
                intel_gt_info_print(&dev_priv->gt.info, &p);
        }
 
index c6473aa3b2a42452e944f0d7193146d2d13d81b5..8198d13347f689e0c11ad97790d56e9e633bbf19 100644 (file)
@@ -1764,26 +1764,27 @@ static inline bool run_as_guest(void)
 #define HAS_D12_PLANE_MINIMIZATION(dev_priv) (IS_ROCKETLAKE(dev_priv) || \
                                              IS_ALDERLAKE_S(dev_priv))
 
-static inline bool intel_vtd_active(void)
+static inline bool intel_vtd_active(struct drm_i915_private *i915)
 {
-#ifdef CONFIG_INTEL_IOMMU
-       if (intel_iommu_gfx_mapped)
+       if (device_iommu_mapped(i915->drm.dev))
                return true;
-#endif
 
        /* Running as a guest, we assume the host is enforcing VT'd */
        return run_as_guest();
 }
 
+void
+i915_print_iommu_status(struct drm_i915_private *i915, struct drm_printer *p);
+
 static inline bool intel_scanout_needs_vtd_wa(struct drm_i915_private *dev_priv)
 {
-       return GRAPHICS_VER(dev_priv) >= 6 && intel_vtd_active();
+       return GRAPHICS_VER(dev_priv) >= 6 && intel_vtd_active(dev_priv);
 }
 
 static inline bool
 intel_ggtt_update_needs_vtd_wa(struct drm_i915_private *i915)
 {
-       return IS_BROXTON(i915) && intel_vtd_active();
+       return IS_BROXTON(i915) && intel_vtd_active(i915);
 }
 
 static inline bool
index b1e4ce0f798f11a6dbd2a677a4ada6aeed588c0f..a485aa4ca669e3cd577e0777474fb8eb8a406111 100644 (file)
@@ -1754,10 +1754,7 @@ static void capture_gen(struct i915_gpu_coredump *error)
        error->wakelock = atomic_read(&i915->runtime_pm.wakeref_count);
        error->suspended = i915->runtime_pm.suspended;
 
-       error->iommu = -1;
-#ifdef CONFIG_INTEL_IOMMU
-       error->iommu = intel_iommu_gfx_mapped;
-#endif
+       error->iommu = intel_vtd_active(i915);
        error->reset_count = i915_reset_count(&i915->gpu_error);
        error->suspend_count = i915->suspend_count;
 
index 6e6b317bc33ce9186ea31323f0b29141243739dd..e6605b5181a545ef34a9e99b5dcee64bd1e69845 100644 (file)
@@ -83,17 +83,6 @@ const char *intel_platform_name(enum intel_platform platform)
        return platform_names[platform];
 }
 
-static const char *iommu_name(void)
-{
-       const char *msg = "n/a";
-
-#ifdef CONFIG_INTEL_IOMMU
-       msg = enableddisabled(intel_iommu_gfx_mapped);
-#endif
-
-       return msg;
-}
-
 void intel_device_info_print_static(const struct intel_device_info *info,
                                    struct drm_printer *p)
 {
@@ -114,7 +103,6 @@ void intel_device_info_print_static(const struct intel_device_info *info,
                drm_printf(p, "display version: %u\n", info->display.ver);
 
        drm_printf(p, "gt: %d\n", info->gt);
-       drm_printf(p, "iommu: %s\n", iommu_name());
        drm_printf(p, "memory-regions: %x\n", info->memory_regions);
        drm_printf(p, "page-sizes: %x\n", info->page_sizes);
        drm_printf(p, "platform: %s\n", intel_platform_name(info->platform));
@@ -374,7 +362,7 @@ void intel_device_info_runtime_init(struct drm_i915_private *dev_priv)
                        info->display.has_dsc = 0;
        }
 
-       if (GRAPHICS_VER(dev_priv) == 6 && intel_vtd_active()) {
+       if (GRAPHICS_VER(dev_priv) == 6 && intel_vtd_active(dev_priv)) {
                drm_info(&dev_priv->drm,
                         "Disabling ppGTT for VT-d support\n");
                info->ppgtt_type = INTEL_PPGTT_NONE;
index 1f17ca5288e8bfbe5c9c448dad2102368663437a..186b7585041b8bfef8324d696cf1365817f817f3 100644 (file)
@@ -97,7 +97,7 @@ static void gen9_init_clock_gating(struct drm_i915_private *dev_priv)
                 * "Plane N strech max must be programmed to 11b (x1)
                 *  when Async flips are enabled on that plane."
                 */
-               if (!IS_GEMINILAKE(dev_priv) && intel_vtd_active())
+               if (!IS_GEMINILAKE(dev_priv) && intel_vtd_active(dev_priv))
                        intel_uncore_rmw(&dev_priv->uncore, CHICKEN_PIPESL_1(pipe),
                                         SKL_PLANE1_STRETCH_MAX_MASK, SKL_PLANE1_STRETCH_MAX_X1);
        }