From patchwork Thu Jul 5 20:23:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Agustin Vega-Frias X-Patchwork-Id: 10510269 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EEC836024A for ; Thu, 5 Jul 2018 20:24:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E141226246 for ; Thu, 5 Jul 2018 20:24:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D4A31277D9; Thu, 5 Jul 2018 20:24:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 71E9826246 for ; Thu, 5 Jul 2018 20:24:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=2a6HkQ+tKvgwCww3RTjeJBHNBROISk8dgdtJ4jmVkEo=; b=Gb75QbLRgqPb6jMq5rG53BNrS4 Db1bu5CZLkctxFy2U459UhUHPPRhmPIo4QgMm/be+KzYzHNXcs1aL3YDEK1Kq9KBDYVcHsBAqoqE6 YdbivUTSn2ND+8RRp2zp/y1fU0sY+h0XGMQ2Yy5pT5O4dal5sai38y8b4iRv2JQanrkJMYeNvDium X/2hdkuTpMYmpPD+V7B7bNDgQ9mcgmRb41nAtD+Sd2B0rmEx0oPGIITsVJBt6axUHoFiJgcXRare/ i0f9BcqZUytmDdPiMeYim+6pfWYDVBhEMtMtDnsgb26CTyAXc4YSP6Ka+jHiC4JYEs9nfZyJl/xXf VWalV4wQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fbAnX-0008FJ-5K; Thu, 05 Jul 2018 20:24:15 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fbAnT-0008D2-Ab for linux-arm-kernel@lists.infradead.org; Thu, 05 Jul 2018 20:24:13 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id F037260B71; Thu, 5 Jul 2018 20:24:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1530822244; bh=OBHgcJFOv9Bk28E1jaGgOK2JWySXSYTAWmdAIGT38Ek=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nubuC2S5jDjLPtz4s3ToPkl7Frj1KIhd0h/PcyoCNaY8qUno1ZDQseTKklj0yE1rG qD0cTeUmS+iEkEJDvc5G2/yWSHkrkgGdgbMWv387zUIkYpao9ZOr2OjT2yIJ1CpB+K bX8kPiBShoxtp5iMUNUzdBEuNVKPGJeWWjL3gxe0= Received: from azshara.qualcomm.com (global_nat1_iad_fw.qualcomm.com [129.46.232.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: agustinv@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id E34F060B3B; Thu, 5 Jul 2018 20:24:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1530822243; bh=OBHgcJFOv9Bk28E1jaGgOK2JWySXSYTAWmdAIGT38Ek=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oA/3wN1URyb+s/ySGlcUeZTGN4Xrl2h7xqI91vknv+XKRkEcZxl2knQboJ9S75tyE jwEbnZTeMnyMdVXuiBIqRH0L/AHr+MtqDfv6Y7gmR6MSVtUYv0T5gkkP3ymVHm54y3 nVBP5Vb3aFaqNAt7qASyQlLpqFRBRT11bIOB568c= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org E34F060B3B Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=agustinv@codeaurora.org From: Agustin Vega-Frias To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, Will Deacon , Mark Rutland , Jeremy Linton , Catalin Marinas , Marc Zyngier , Lorenzo Pieralisi , "Rafael J. Wysocki" Subject: [RFC V4 2/4] arm_pmu: acpi: add support for CPU PMU variant detection Date: Thu, 5 Jul 2018 16:23:19 -0400 Message-Id: <1530822201-5890-3-git-send-email-agustinv@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1530822201-5890-1-git-send-email-agustinv@codeaurora.org> References: <1530822201-5890-1-git-send-email-agustinv@codeaurora.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180705_132411_420494_E9625223 X-CRM114-Status: GOOD ( 16.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vijaya Kilari , Jeff Hugo , Phani Pabba , Richard Ruigrok , Agustin Vega-Frias , Rahul Ramasubramanian , Agustin Vega-Frias MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP DT allows CPU PMU variant detection via the PMU device compatible property. ACPI does not have an equivalent mechanism so we introduce a probe table to allow this via a device nested inside the CPU device in the DSDT: Device (CPU0) { Name (_HID, "ACPI0007" /* Processor Device */) ... Device (PMU0) { Name (_HID, "QCOM8150") /* Qualcomm Falkor PMU device */ /* * The device might also contain _DSD properties to indicate other * IMPLEMENTATION DEFINED PMU features. */ Name (_DSD, Package () { ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), Package () { ... } }) } } With this in place we can declare the variant: ACPI_DECLARE_PMU_VARIANT(qcom_falkor, "QCOM8150", falkor_pmu_init); The init function is called after the default PMU initialization and is passed a pointer to the arm_pmu structure and a pointer to the PMU device. The init function can then override arm_pmu callbacks and attributes and query more properties from the PMU device. Signed-off-by: Agustin Vega-Frias --- drivers/perf/arm_pmu_acpi.c | 27 +++++++++++++++++++++++++++ include/asm-generic/vmlinux.lds.h | 1 + include/linux/acpi.h | 11 +++++++++++ include/linux/perf/arm_pmu.h | 1 + 4 files changed, 40 insertions(+) diff --git a/drivers/perf/arm_pmu_acpi.c b/drivers/perf/arm_pmu_acpi.c index 0f19751..6b0ca71 100644 --- a/drivers/perf/arm_pmu_acpi.c +++ b/drivers/perf/arm_pmu_acpi.c @@ -220,6 +220,26 @@ static int arm_pmu_acpi_cpu_starting(unsigned int cpu) return 0; } +/* + * Check if the given child device of the CPU device matches a PMU variant + * device declared with ACPI_DECLARE_PMU_VARIANT, if so, pass the arm_pmu + * structure and the matching device for further initialization. + */ +static int arm_pmu_variant_init(struct device *dev, void *data) +{ + extern struct acpi_device_id ACPI_PROBE_TABLE(pmu); + unsigned int cpu = *((unsigned int *)data); + const struct acpi_device_id *id; + + id = acpi_match_device(&ACPI_PROBE_TABLE(pmu), dev); + if (id) { + armpmu_acpi_init_fn fn = (armpmu_acpi_init_fn)id->driver_data; + + return fn(per_cpu(probed_pmus, cpu), dev); + } + return 0; +} + int arm_pmu_acpi_probe(armpmu_init_fn init_fn) { int pmu_idx = 0; @@ -240,6 +260,7 @@ int arm_pmu_acpi_probe(armpmu_init_fn init_fn) */ for_each_possible_cpu(cpu) { struct arm_pmu *pmu = per_cpu(probed_pmus, cpu); + struct device *dev = get_cpu_device(cpu); char *base_name; if (!pmu || pmu->name) @@ -254,6 +275,10 @@ int arm_pmu_acpi_probe(armpmu_init_fn init_fn) return ret; } + ret = device_for_each_child(dev, &cpu, arm_pmu_variant_init); + if (ret == -ENODEV) + pr_warn("Failed PMU re-init, fallback to plain PMUv3"); + base_name = pmu->name; pmu->name = kasprintf(GFP_KERNEL, "%s_%d", base_name, pmu_idx++); if (!pmu->name) { @@ -290,3 +315,5 @@ static int arm_pmu_acpi_init(void) return ret; } subsys_initcall(arm_pmu_acpi_init) + +ACPI_DECLARE_PMU_SENTINEL(); diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 1ec0411..03d1673 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -609,6 +609,7 @@ IRQCHIP_OF_MATCH_TABLE() \ ACPI_PROBE_TABLE(irqchip) \ ACPI_PROBE_TABLE(timer) \ + ACPI_PROBE_TABLE(pmu) \ EARLYCON_TABLE() #define INIT_TEXT \ diff --git a/include/linux/acpi.h b/include/linux/acpi.h index e54f409..99c6698 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -1158,6 +1158,17 @@ struct acpi_probe_entry { (&ACPI_PROBE_TABLE_END(t) - \ &ACPI_PROBE_TABLE(t))); \ }) + +#define ACPI_DECLARE_PMU_VARIANT(name, hid, init_fn) \ + static const struct acpi_device_id __acpi_probe_##name \ + __used __section(__pmu_acpi_probe_table) \ + = { .id = hid, .driver_data = (kernel_ulong_t)init_fn } + +#define ACPI_DECLARE_PMU_SENTINEL() \ + static const struct acpi_device_id __acpi_probe_sentinel \ + __used __section(__pmu_acpi_probe_table_end) \ + = { .id = "", .driver_data = 0 } + #else static inline int acpi_dev_get_property(struct acpi_device *adev, const char *name, acpi_object_type type, diff --git a/include/linux/perf/arm_pmu.h b/include/linux/perf/arm_pmu.h index ad54444..b02ac52 100644 --- a/include/linux/perf/arm_pmu.h +++ b/include/linux/perf/arm_pmu.h @@ -123,6 +123,7 @@ int armpmu_map_event(struct perf_event *event, u32 raw_event_mask); typedef int (*armpmu_init_fn)(struct arm_pmu *); +typedef int (*armpmu_acpi_init_fn)(struct arm_pmu *, struct device *); struct pmu_probe_info { unsigned int cpuid;