aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Salter <msalter@redhat.com>2014-10-13 20:49:43 -0400
committerGraeme Gregory <graeme.gregory@linaro.org>2015-07-07 14:36:07 +0100
commit32f9530f9d0b4a3380871c8230d31d1f97afc2f9 (patch)
treee4f834f4d3ac6418cf4a019a476490ee514baf59
parent325c9758bd4b7f35faa83e1fb89332ca0800dab5 (diff)
downloadleg-kernel-32f9530f9d0b4a3380871c8230d31d1f97afc2f9.tar.gz
arm64/perf: add ACPI support
Add ACPI support to perf_event driver. This involves getting the irq info from the MADT and registering a platform device when booting with ACPI. This requires updated firmware for Mustang and FM for PMU driver to get correct info from ACPI. Signed-off-by: Mark Salter <msalter@redhat.com>
-rw-r--r--arch/arm64/kernel/perf_event.c102
1 files changed, 102 insertions, 0 deletions
diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c
index b31e9a4b6275..1d04b10365f9 100644
--- a/arch/arm64/kernel/perf_event.c
+++ b/arch/arm64/kernel/perf_event.c
@@ -31,6 +31,7 @@
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/uaccess.h>
+#include <linux/acpi.h>
#include <asm/cputype.h>
#include <asm/irq.h>
@@ -1375,6 +1376,107 @@ static int __init register_pmu_driver(void)
}
device_initcall(register_pmu_driver);
+#ifdef CONFIG_ACPI
+struct acpi_pmu_irq {
+ int gsi;
+ int trigger;
+};
+
+static struct acpi_pmu_irq acpi_pmu_irqs[NR_CPUS] __initdata;
+
+static int __init
+acpi_parse_pmu_irqs(struct acpi_subtable_header *header,
+ const unsigned long end)
+{
+ struct acpi_madt_generic_interrupt *gic;
+ int cpu;
+ u64 mpidr;
+
+ gic = (struct acpi_madt_generic_interrupt *)header;
+ if (BAD_MADT_ENTRY(gic, end))
+ return -EINVAL;
+
+ mpidr = gic->arm_mpidr & MPIDR_HWID_BITMASK;
+
+ for_each_possible_cpu(cpu) {
+ if (cpu_logical_map(cpu) != mpidr)
+ continue;
+
+ acpi_pmu_irqs[cpu].gsi = gic->performance_interrupt;
+ if (gic->flags & ACPI_MADT_PERFORMANCE_IRQ_MODE)
+ acpi_pmu_irqs[cpu].trigger = ACPI_EDGE_SENSITIVE;
+ else
+ acpi_pmu_irqs[cpu].trigger = ACPI_LEVEL_SENSITIVE;
+ return 0;
+ }
+
+ return -EINVAL;
+}
+
+static int __init pmu_acpi_init(void)
+{
+ struct platform_device *pdev;
+ struct acpi_pmu_irq *pirq = acpi_pmu_irqs;
+ struct resource *res, *r;
+ int err = -ENOMEM;
+ int i, count, irq;
+
+ if (acpi_disabled)
+ return 0;
+
+ count = acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_INTERRUPT,
+ acpi_parse_pmu_irqs, num_possible_cpus());
+ /* Must have irq for boot boot cpu, at least */
+ if (count <= 0 || pirq->gsi == 0)
+ return -EINVAL;
+
+ irq = acpi_register_gsi(NULL, pirq->gsi, pirq->trigger,
+ ACPI_ACTIVE_HIGH);
+
+ if (irq_is_percpu(irq))
+ count = 1;
+
+ pdev = platform_device_alloc("arm-pmu", -1);
+ if (!pdev)
+ return err;
+
+ res = kcalloc(count, sizeof(*res), GFP_KERNEL);
+ if (!res)
+ goto err_free_device;
+
+ for (i = 0, r = res; i < count; i++, pirq++, r++) {
+ if (i)
+ irq = acpi_register_gsi(NULL, pirq->gsi, pirq->trigger,
+ ACPI_ACTIVE_HIGH);
+ r->start = r->end = irq;
+ r->flags = IORESOURCE_IRQ;
+ if (pirq->trigger == ACPI_EDGE_SENSITIVE)
+ r->flags |= IORESOURCE_IRQ_HIGHEDGE;
+ else
+ r->flags |= IORESOURCE_IRQ_HIGHLEVEL;
+ }
+
+ err = platform_device_add_resources(pdev, res, count);
+ if (err)
+ goto err_free_res;
+
+ err = platform_device_add(pdev);
+ if (err)
+ goto err_free_res;
+
+ return 0;
+
+err_free_res:
+ kfree(res);
+
+err_free_device:
+ platform_device_put(pdev);
+ return err;
+}
+arch_initcall(pmu_acpi_init);
+
+#endif /* ACPI */
+
static struct pmu_hw_events *armpmu_get_cpu_events(void)
{
return this_cpu_ptr(&cpu_hw_events);