summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu/amdgpu_device.c')
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_device.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index ef9ff30c0a7b..1f67ad0233d5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -33,6 +33,7 @@
#include <linux/console.h>
#include <linux/slab.h>
#include <linux/iommu.h>
+#include <linux/amd-iommu.h>
#include <linux/pci.h>
#include <linux/pci-p2pdma.h>
#include <linux/apple-gmux.h>
@@ -3751,6 +3752,28 @@ amdgpu_device_should_register_switcheroo(struct amdgpu_device *adev, bool px)
apple_gmux_detect(NULL, NULL)));
}
+static inline bool amdgpu_device_identity(struct amdgpu_device *adev)
+{
+ struct pci_dev *pdev = adev->pdev;
+ struct iommu_domain *domain = iommu_get_domain_for_dev(&pdev->dev);
+
+ if (!domain)
+ return false;
+
+ return domain->type == IOMMU_DOMAIN_IDENTITY;
+}
+
+static bool amdgpu_device_use_perfopt(struct amdgpu_device *adev)
+{
+ if (amdgpu_iommu_perfopt == 0)
+ return false;
+
+ if (!(adev->flags & AMD_IS_APU))
+ return false;
+
+ return amdgpu_device_identity(adev);
+}
+
/**
* amdgpu_device_init - initialize the driver
*
@@ -3958,6 +3981,16 @@ int amdgpu_device_init(struct amdgpu_device *adev,
if (r)
return r;
+ if (amdgpu_device_use_perfopt(adev)) {
+ int perfopt_ret = amd_iommu_enable_perfopt(pdev);
+
+ /* Optional optimization; a failure to arm it must not abort probe. */
+ if (perfopt_ret)
+ dev_warn(adev->dev,
+ "Failed to enable IOMMU PerfOpt (%d); continuing without it\n",
+ perfopt_ret);
+ }
+
/*
* No need to remove conflicting FBs for non-display class devices.
* This prevents the sysfb from being freed accidently.
@@ -4327,6 +4360,9 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)
amdgpu_gart_dummy_page_fini(adev);
+ if (amdgpu_device_use_perfopt(adev))
+ amd_iommu_disable_perfopt(adev->pdev);
+
if (pci_dev_is_disconnected(adev->pdev))
amdgpu_device_unmap_mmio(adev);
@@ -4690,6 +4726,20 @@ int amdgpu_device_resume(struct drm_device *dev, bool notify_clients)
if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
return 0;
+ if (amdgpu_device_use_perfopt(adev)) {
+ int perfopt_ret = amd_iommu_enable_perfopt(adev->pdev);
+
+ /*
+ * Must not return on failure: a bare return would leak the
+ * SR-IOV VF exclusive-mode acquisition taken above (released
+ * via the exit: path).
+ */
+ if (perfopt_ret)
+ dev_warn(adev->dev,
+ "Failed to enable IOMMU PerfOpt (%d); continuing without it\n",
+ perfopt_ret);
+ }
+
if (adev->in_s0ix)
amdgpu_dpm_gfx_state_change(adev, sGpuChangeState_D0Entry);