From patchwork Fri May 1 14:45:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Salter X-Patchwork-Id: 6309731 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2D07DBEEE1 for ; Fri, 1 May 2015 14:49:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 44F2F2043C for ; Fri, 1 May 2015 14:49:04 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5CCD320435 for ; Fri, 1 May 2015 14:49:03 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YoCCo-000502-11; Fri, 01 May 2015 14:46:18 +0000 Received: from mx1.redhat.com ([209.132.183.28]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YoCCk-0004xz-VA for linux-arm-kernel@lists.infradead.org; Fri, 01 May 2015 14:46:15 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id BC0B68E3E5; Fri, 1 May 2015 14:45:53 +0000 (UTC) Received: from deneb.redhat.com (ovpn-113-148.phx2.redhat.com [10.3.113.148]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t41Ejq4F014404; Fri, 1 May 2015 10:45:53 -0400 From: Mark Salter To: Will Deacon , Catalin Marinas Subject: [PATCH] arm64/perf: add ACPI support Date: Fri, 1 May 2015 10:45:48 -0400 Message-Id: <1430491548-9896-1-git-send-email-msalter@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150501_074615_053130_FE35CDF6 X-CRM114-Status: GOOD ( 16.32 ) X-Spam-Score: -5.0 (-----) Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Mark Salter X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When using ACPI, the perf_event irq info needs to be parsed from the MADT and a corresponding platform device needs to be created and registered. The only change to the existing driver is a check to avoid unnecessary devicetree parsing. Signed-off-by: Mark Salter --- arch/arm64/kernel/perf_event.c | 106 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c index 195991d..1e53b26 100644 --- a/arch/arm64/kernel/perf_event.c +++ b/arch/arm64/kernel/perf_event.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -1315,6 +1316,10 @@ static int armpmu_device_probe(struct platform_device *pdev) if (!cpu_pmu) return -ENODEV; + /* skip the devicetree parsing if we're using ACPI */ + if (!acpi_disabled) + goto done; + irqs = kcalloc(pdev->num_resources, sizeof(*irqs), GFP_KERNEL); if (!irqs) return -ENOMEM; @@ -1350,6 +1355,7 @@ static int armpmu_device_probe(struct platform_device *pdev) else kfree(irqs); +done: cpu_pmu->plat_device = pdev; return 0; } @@ -1368,6 +1374,106 @@ 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) + goto err_free_gsi; + + 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) + err = platform_device_add(pdev); + kfree(res); + if (!err) + return 0; + +err_free_device: + platform_device_put(pdev); + +err_free_gsi: + for (i = 0; i < count; i++) + acpi_unregister_gsi(acpi_pmu_irqs[i].gsi); + + 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);