| @@ -35,6 +35,7 @@ · 34 unmodified lines |
| 35 | 35 | */ |
| 36 | 36 | |
| 37 | 37 | #include <linux/acpi.h> |
| 38 | +#include <linux/acpi_iort.h> |
| 38 | 39 | #include <linux/bitfield.h> |
| 39 | 40 | #include <linux/bitops.h> |
| 40 | 41 | #include <linux/cpuhotplug.h> |
| @@ -93,6 +94,8 @@ · 52 unmodified lines |
| 93 | 94 | |
| 94 | 95 | #define SMMU_PMCG_PA_SHIFT 12 |
| 95 | 96 | |
| 97 | +#define SMMU_PMCG_EVCNTR_RDONLY BIT(0) |
| 98 | + |
| 96 | 99 | static int cpuhp_state_num; |
| 97 | 100 | |
| 98 | 101 | struct smmu_pmu { |
| @@ -108,6 +111,7 @@ struct smmu_pmu { · 9 unmodified lines |
| 108 | 111 | void __iomem *reg_base; |
| 109 | 112 | void __iomem *reloc_base; |
| 110 | 113 | u64 counter_mask; |
| 114 | + u32 options; |
| 111 | 115 | bool global_filter; |
| 112 | 116 | u32 global_filter_span; |
| 113 | 117 | u32 global_filter_sid; |
| @@ -222,15 +226,27 @@ static void smmu_pmu_set_period(struct smmu_pmu *smmu_pmu, · 108 unmodified lines |
| 222 | 226 | u32 idx = hwc->idx; |
| 223 | 227 | u64 new; |
| 224 | 228 | |
| 225 | | − /* |
| 226 | | − * We limit the max period to half the max counter value of the counter |
| 227 | | − * size, so that even in the case of extreme interrupt latency the |
| 228 | | − * counter will (hopefully) not wrap past its initial value. |
| 229 | | − */ |
| 230 | | − new = smmu_pmu->counter_mask >> 1; |
| 229 | + if (smmu_pmu->options & SMMU_PMCG_EVCNTR_RDONLY) { |
| 230 | + /* |
| 231 | + * On platforms that require this quirk, if the counter starts |
| 232 | + * at < half_counter value and wraps, the current logic of |
| 233 | + * handling the overflow may not work. It is expected that, |
| 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 | 249 | local64_set(&hwc->prev_count, new); |
| 233 | | − smmu_pmu_counter_set_value(smmu_pmu, idx, new); |
| 234 | 250 | } |
| 235 | 251 | |
| 236 | 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 | 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 | 700 | static int smmu_pmu_probe(struct platform_device *pdev) |
| 669 | 701 | { |
| 670 | 702 | struct smmu_pmu *smmu_pmu; |
| @@ -744,6 +776,8 @@ static int smmu_pmu_probe(struct platform_device *pdev) · 73 unmodified lines |
| 744 | 776 | return -EINVAL; |
| 745 | 777 | } |
| 746 | 778 | |
| 779 | + smmu_pmu_get_acpi_options(smmu_pmu); |
| 780 | + |
| 747 | 781 | /* Pick one CPU to be the preferred one to use */ |
| 748 | 782 | smmu_pmu->on_cpu = raw_smp_processor_id(); |
| 749 | 783 | WARN_ON(irq_set_affinity_hint(smmu_pmu->irq, |