aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/x86/events/amd/iommu.c17
-rw-r--r--arch/x86/events/amd/iommu.h9
-rw-r--r--drivers/iommu/amd_iommu_init.c34
-rw-r--r--drivers/iommu/amd_iommu_proto.h2
4 files changed, 31 insertions, 31 deletions
diff --git a/arch/x86/events/amd/iommu.c b/arch/x86/events/amd/iommu.c
index d4375dadd4e9..10f67d39cac5 100644
--- a/arch/x86/events/amd/iommu.c
+++ b/arch/x86/events/amd/iommu.c
@@ -239,14 +239,6 @@ static int perf_iommu_event_init(struct perf_event *event)
239 return -EINVAL; 239 return -EINVAL;
240 } 240 }
241 241
242 /* integrate with iommu base devid (0000), assume one iommu */
243 perf_iommu->max_banks =
244 amd_iommu_pc_get_max_banks(IOMMU_BASE_DEVID);
245 perf_iommu->max_counters =
246 amd_iommu_pc_get_max_counters(IOMMU_BASE_DEVID);
247 if ((perf_iommu->max_banks == 0) || (perf_iommu->max_counters == 0))
248 return -EINVAL;
249
250 /* update the hw_perf_event struct with the iommu config data */ 242 /* update the hw_perf_event struct with the iommu config data */
251 hwc->config = config; 243 hwc->config = config;
252 hwc->extra_reg.config = config1; 244 hwc->extra_reg.config = config1;
@@ -448,6 +440,11 @@ static __init int _init_perf_amd_iommu(
448 return ret; 440 return ret;
449 } 441 }
450 442
443 perf_iommu->max_banks = amd_iommu_pc_get_max_banks(0);
444 perf_iommu->max_counters = amd_iommu_pc_get_max_counters(0);
445 if (!perf_iommu->max_banks || !perf_iommu->max_counters)
446 return -EINVAL;
447
451 perf_iommu->null_group = NULL; 448 perf_iommu->null_group = NULL;
452 perf_iommu->pmu.attr_groups = perf_iommu->attr_groups; 449 perf_iommu->pmu.attr_groups = perf_iommu->attr_groups;
453 450
@@ -457,8 +454,8 @@ static __init int _init_perf_amd_iommu(
457 amd_iommu_pc_exit(); 454 amd_iommu_pc_exit();
458 } else { 455 } else {
459 pr_info("Detected AMD IOMMU (%d banks, %d counters/bank).\n", 456 pr_info("Detected AMD IOMMU (%d banks, %d counters/bank).\n",
460 amd_iommu_pc_get_max_banks(IOMMU_BASE_DEVID), 457 amd_iommu_pc_get_max_banks(0),
461 amd_iommu_pc_get_max_counters(IOMMU_BASE_DEVID)); 458 amd_iommu_pc_get_max_counters(0));
462 } 459 }
463 460
464 return ret; 461 return ret;
diff --git a/arch/x86/events/amd/iommu.h b/arch/x86/events/amd/iommu.h
index 5c5c9329e571..b775107c221e 100644
--- a/arch/x86/events/amd/iommu.h
+++ b/arch/x86/events/amd/iommu.h
@@ -24,19 +24,18 @@
24#define PC_MAX_SPEC_BNKS 64 24#define PC_MAX_SPEC_BNKS 64
25#define PC_MAX_SPEC_CNTRS 16 25#define PC_MAX_SPEC_CNTRS 16
26 26
27/* iommu pc reg masks*/
28#define IOMMU_BASE_DEVID 0x0000
29
30/* amd_iommu_init.c external support functions */ 27/* amd_iommu_init.c external support functions */
31extern int amd_iommu_get_num_iommus(void); 28extern int amd_iommu_get_num_iommus(void);
32 29
33extern bool amd_iommu_pc_supported(void); 30extern bool amd_iommu_pc_supported(void);
34 31
35extern u8 amd_iommu_pc_get_max_banks(u16 devid); 32extern u8 amd_iommu_pc_get_max_banks(unsigned int idx);
36 33
37extern u8 amd_iommu_pc_get_max_counters(u16 devid); 34extern u8 amd_iommu_pc_get_max_counters(unsigned int idx);
38 35
39extern int amd_iommu_pc_get_set_reg_val(u16 devid, u8 bank, u8 cntr, 36extern int amd_iommu_pc_get_set_reg_val(u16 devid, u8 bank, u8 cntr,
40 u8 fxn, u64 *value, bool is_write); 37 u8 fxn, u64 *value, bool is_write);
41 38
39extern struct amd_iommu *get_amd_iommu(int idx);
40
42#endif /*_PERF_EVENT_AMD_IOMMU_H_*/ 41#endif /*_PERF_EVENT_AMD_IOMMU_H_*/
diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
index d3ec9c32c446..8fdf109e6109 100644
--- a/drivers/iommu/amd_iommu_init.c
+++ b/drivers/iommu/amd_iommu_init.c
@@ -2718,6 +2718,18 @@ bool amd_iommu_v2_supported(void)
2718} 2718}
2719EXPORT_SYMBOL(amd_iommu_v2_supported); 2719EXPORT_SYMBOL(amd_iommu_v2_supported);
2720 2720
2721struct amd_iommu *get_amd_iommu(unsigned int idx)
2722{
2723 unsigned int i = 0;
2724 struct amd_iommu *iommu;
2725
2726 for_each_iommu(iommu)
2727 if (i++ == idx)
2728 return iommu;
2729 return NULL;
2730}
2731EXPORT_SYMBOL(get_amd_iommu);
2732
2721/**************************************************************************** 2733/****************************************************************************
2722 * 2734 *
2723 * IOMMU EFR Performance Counter support functionality. This code allows 2735 * IOMMU EFR Performance Counter support functionality. This code allows
@@ -2725,17 +2737,14 @@ EXPORT_SYMBOL(amd_iommu_v2_supported);
2725 * 2737 *
2726 ****************************************************************************/ 2738 ****************************************************************************/
2727 2739
2728u8 amd_iommu_pc_get_max_banks(u16 devid) 2740u8 amd_iommu_pc_get_max_banks(unsigned int idx)
2729{ 2741{
2730 struct amd_iommu *iommu; 2742 struct amd_iommu *iommu = get_amd_iommu(idx);
2731 u8 ret = 0;
2732 2743
2733 /* locate the iommu governing the devid */
2734 iommu = amd_iommu_rlookup_table[devid];
2735 if (iommu) 2744 if (iommu)
2736 ret = iommu->max_banks; 2745 return iommu->max_banks;
2737 2746
2738 return ret; 2747 return 0;
2739} 2748}
2740EXPORT_SYMBOL(amd_iommu_pc_get_max_banks); 2749EXPORT_SYMBOL(amd_iommu_pc_get_max_banks);
2741 2750
@@ -2745,17 +2754,14 @@ bool amd_iommu_pc_supported(void)
2745} 2754}
2746EXPORT_SYMBOL(amd_iommu_pc_supported); 2755EXPORT_SYMBOL(amd_iommu_pc_supported);
2747 2756
2748u8 amd_iommu_pc_get_max_counters(u16 devid) 2757u8 amd_iommu_pc_get_max_counters(unsigned int idx)
2749{ 2758{
2750 struct amd_iommu *iommu; 2759 struct amd_iommu *iommu = get_amd_iommu(idx);
2751 u8 ret = 0;
2752 2760
2753 /* locate the iommu governing the devid */
2754 iommu = amd_iommu_rlookup_table[devid];
2755 if (iommu) 2761 if (iommu)
2756 ret = iommu->max_counters; 2762 return iommu->max_counters;
2757 2763
2758 return ret; 2764 return 0;
2759} 2765}
2760EXPORT_SYMBOL(amd_iommu_pc_get_max_counters); 2766EXPORT_SYMBOL(amd_iommu_pc_get_max_counters);
2761 2767
diff --git a/drivers/iommu/amd_iommu_proto.h b/drivers/iommu/amd_iommu_proto.h
index e8f0710aceb3..cd2257e20c3f 100644
--- a/drivers/iommu/amd_iommu_proto.h
+++ b/drivers/iommu/amd_iommu_proto.h
@@ -59,8 +59,6 @@ extern struct iommu_domain *amd_iommu_get_v2_domain(struct pci_dev *pdev);
59 59
60/* IOMMU Performance Counter functions */ 60/* IOMMU Performance Counter functions */
61extern bool amd_iommu_pc_supported(void); 61extern bool amd_iommu_pc_supported(void);
62extern u8 amd_iommu_pc_get_max_banks(u16 devid);
63extern u8 amd_iommu_pc_get_max_counters(u16 devid);
64extern int amd_iommu_pc_get_set_reg_val(u16 devid, u8 bank, u8 cntr, u8 fxn, 62extern int amd_iommu_pc_get_set_reg_val(u16 devid, u8 bank, u8 cntr, u8 fxn,
65 u64 *value, bool is_write); 63 u64 *value, bool is_write);
66 64