Register and enable an IOMMU perfmon for each active IOMMU device.
The failure of IOMMU perfmon registration doesn't impact other
functionalities of an IOMMU device.
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Link: https://lore.kernel.org/r/20230128200428.1459118-8-kan.liang@linux.intel.com
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
 
                err = iommu_device_register(&iommu->iommu, &intel_iommu_ops, NULL);
                if (err)
                        goto err_sysfs;
+
+               iommu_pmu_register(iommu);
        }
 
        drhd->iommu = iommu;
 static void free_iommu(struct intel_iommu *iommu)
 {
        if (intel_iommu_enabled && !iommu->drhd->ignored) {
+               iommu_pmu_unregister(iommu);
                iommu_device_unregister(&iommu->iommu);
                iommu_device_sysfs_remove(&iommu->iommu);
        }
 
 #include "../iommu-sva.h"
 #include "pasid.h"
 #include "cap_audit.h"
+#include "perfmon.h"
 
 #define ROOT_SIZE              VTD_PAGE_SIZE
 #define CONTEXT_SIZE           VTD_PAGE_SIZE
                                       intel_iommu_groups,
                                       "%s", iommu->name);
                iommu_device_register(&iommu->iommu, &intel_iommu_ops, NULL);
+
+               iommu_pmu_register(iommu);
        }
        up_read(&dmar_global_lock);