| @@ -35,6 +35,7 @@ · 34 unmodified lines |
| 35 | */ | 35 | */ |
| 36 | | 36 | |
| 37 | #include <linux/acpi.h> | 37 | #include <linux/acpi.h> |
| | 38 | #include <linux/acpi_iort.h> |
| 38 | #include <linux/bitfield.h> | 39 | #include <linux/bitfield.h> |
| 39 | #include <linux/bitops.h> | 40 | #include <linux/bitops.h> |
| 40 | #include <linux/cpuhotplug.h> | 41 | #include <linux/cpuhotplug.h> |
| @@ -93,6 +94,8 @@ · 52 unmodified lines |
| 93 | | 94 | |
| 94 | #define SMMU_PMCG_PA_SHIFT 12 | 95 | #define SMMU_PMCG_PA_SHIFT 12 |
| 95 | | 96 | |
| | 97 | #define SMMU_PMCG_EVCNTR_RDONLY BIT(0) |
| | 98 | |
| 96 | static int cpuhp_state_num; | 99 | static int cpuhp_state_num; |
| 97 | | 100 | |
| 98 | struct smmu_pmu { | 101 | struct smmu_pmu { |
| @@ -108,6 +111,7 @@ struct smmu_pmu { · 9 unmodified lines |
| 108 | void __iomem *reg_base; | 111 | void __iomem *reg_base; |
| 109 | void __iomem *reloc_base; | 112 | void __iomem *reloc_base; |
| 110 | u64 counter_mask; | 113 | u64 counter_mask; |
| | 114 | u32 options; |
| 111 | bool global_filter; | 115 | bool global_filter; |
| 112 | u32 global_filter_span; | 116 | u32 global_filter_span; |
| 113 | u32 global_filter_sid; | 117 | u32 global_filter_sid; |
| @@ -222,15 +226,27 @@ static void smmu_pmu_set_period(struct smmu_pmu *smmu_pmu, · 108 unmodified lines |
| 222 | u32 idx = hwc->idx; | 226 | u32 idx = hwc->idx; |
| 223 | u64 new; | 227 | u64 new; |
| 224 | | 228 | |
| 225 | /* | 229 | if (smmu_pmu->options & SMMU_PMCG_EVCNTR_RDONLY) { |
| 226 | * We limit the max period to half the max counter value of the counter | 230 | /* |
| 227 | * size, so that even in the case of extreme interrupt latency the | 231 | * On platforms that require this quirk, if the counter starts |
| 228 | * counter will (hopefully) not wrap past its initial value. | 232 | * at < half_counter value and wraps, the current logic of |
| 229 | */ | 233 | * handling the overflow may not work. It is expected that, |
| 230 | new = smmu_pmu->counter_mask >> 1; | 234 | * those platforms will have full 64 counter bits implemented |
| | 235 | * so that such a possibility is remote(eg: HiSilicon HIP08). |
| | 236 | */ |
| | 237 | new = smmu_pmu_counter_get_value(smmu_pmu, idx); |
| | 238 | } else { |
| | 239 | /* |
| | 240 | * We limit the max period to half the max counter value |
| | 241 | * of the counter size, so that even in the case of extreme |
| | 242 | * interrupt latency the counter will (hopefully) not wrap |
| | 243 | * past its initial value. |
| | 244 | */ |
| | 245 | new = smmu_pmu->counter_mask >> 1; |
| | 246 | smmu_pmu_counter_set_value(smmu_pmu, idx, new); |
| | 247 | } |
| 231 | | 248 | |
| 232 | local64_set(&hwc->prev_count, new); | 249 | local64_set(&hwc->prev_count, new); |
| 233 | smmu_pmu_counter_set_value(smmu_pmu, idx, new); | | |
| 234 | } | 250 | } |
| 235 | | 251 | |
| 236 | static void smmu_pmu_set_event_filter(struct perf_event *event, | 252 | static void smmu_pmu_set_event_filter(struct perf_event *event, |
| @@ -665,6 +681,22 @@ static void smmu_pmu_reset(struct smmu_pmu *smmu_pmu) · 428 unmodified lines |
| 665 | smmu_pmu->reloc_base + SMMU_PMCG_OVSCLR0); | 681 | smmu_pmu->reloc_base + SMMU_PMCG_OVSCLR0); |
| 666 | } | 682 | } |
| 667 | | 683 | |
| | 684 | static void smmu_pmu_get_acpi_options(struct smmu_pmu *smmu_pmu) |
| | 685 | { |
| | 686 | u32 model; |
| | 687 | |
| | 688 | model = *(u32 *)dev_get_platdata(smmu_pmu->dev); |
| | 689 | |
| | 690 | switch (model) { |
| | 691 | case IORT_SMMU_V3_PMCG_HISI_HIP08: |
| | 692 | /* HiSilicon Erratum 162001800 */ |
| | 693 | smmu_pmu->options |= SMMU_PMCG_EVCNTR_RDONLY; |
| | 694 | break; |
| | 695 | } |
| | 696 | |
| | 697 | dev_notice(smmu_pmu->dev, "option mask 0x%x\n", smmu_pmu->options); |
| | 698 | } |
| | 699 | |
| 668 | static int smmu_pmu_probe(struct platform_device *pdev) | 700 | static int smmu_pmu_probe(struct platform_device *pdev) |
| 669 | { | 701 | { |
| 670 | struct smmu_pmu *smmu_pmu; | 702 | struct smmu_pmu *smmu_pmu; |
| @@ -744,6 +776,8 @@ static int smmu_pmu_probe(struct platform_device *pdev) · 73 unmodified lines |
| 744 | return -EINVAL; | 776 | return -EINVAL; |
| 745 | } | 777 | } |
| 746 | | 778 | |
| | 779 | smmu_pmu_get_acpi_options(smmu_pmu); |
| | 780 | |
| 747 | /* Pick one CPU to be the preferred one to use */ | 781 | /* Pick one CPU to be the preferred one to use */ |
| 748 | smmu_pmu->on_cpu = raw_smp_processor_id(); | 782 | smmu_pmu->on_cpu = raw_smp_processor_id(); |
| 749 | WARN_ON(irq_set_affinity_hint(smmu_pmu->irq, | 783 | WARN_ON(irq_set_affinity_hint(smmu_pmu->irq, |