From patchwork Fri Jun 22 19:49:07 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: 10482979 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 0FC6760383 for ; Fri, 22 Jun 2018 20:02:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F1EF220415 for ; Fri, 22 Jun 2018 20:02:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E5F1C29001; Fri, 22 Jun 2018 20:02:56 +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 741E120415 for ; Fri, 22 Jun 2018 20:02:56 +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=pqzTzM8MlB6QeSyzrBP9h6aiI830Kk5LViScJmNwBaU=; b=Aa8QJk+vUf72yZCfxIxCyJMOuT wZHqTmuiGQURmbhZjVn7Ojkg38ywdg0hTcPINyvcFBexh4/BhL+eOvQ0iyPi5+WfiCqfp6PlZBcu7 X4ELWmK9eMTHoaUgZW9iRbcpuEiQ1vCEOKli0N5ttIGSyjrPnTEa2cKvQuMyR7Rk+eVQiF39plSBC ZtWBQGuDVXMVpe04+hk1IXTmDJRV5yjidWWWamegg6ien/61nB7GETLpmxpXzfzQbtNDinoBTcf5v 8xED2ZIDtiF/UM6t8Y2Jv3nzYJVKfPXzZWJqsaFrkFnQbEYhrWdrJ9nDtPGRAja1SEC1X57lXl41o bRYrmLIw==; 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 1fWSGe-0001CE-Ts; Fri, 22 Jun 2018 20:02:48 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fWSGc-00017l-Vm for linux-arm-kernel@bombadil.infradead.org; Fri, 22 Jun 2018 20:02:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=g8ZxVOfIfMHg1PZqvhaFUK3tMxmJvX64rwPnFlSHvL4=; b=rCQiVuuaQoco3tdMF7Nn3V+aE SrqzP1pN0bx2tvARRf+JYY8wwP0YZmSZFx2EFIgiXY65uUFWOUgIr95kCxEb+1mSMdMVImxrvEVoe immoZq2f4BTwTxyr73msAS0Fid7UQJNQnAaHHY9FNb8eGo2GgLx50dcL0OReyEfL6TXH9pwnbGa/U EtOEhicW154nMfMrEV5no6pi7hBYuFLJKBFVNT4QcXQwcTQwQkH8Qjmlrc50FdaBAzN8ssjV1DvCM voSVF8ANqETegIEhXZel5gGMYhfHT2dEYkt2t+oKhVtBpXx76Z+MigI+4rWMH4wTxM7MmawAUou0y u1sNNwSpA==; Received: from smtp.codeaurora.org ([198.145.29.96]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fWS3o-0001Nd-UB for linux-arm-kernel@lists.infradead.org; Fri, 22 Jun 2018 19:49:35 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 4D0FF60B13; Fri, 22 Jun 2018 19:49:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1529696959; bh=AH8T3jo+B+L+PGietlvIy1LRfolwVcoS5IPo5cxCCY8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JGWzeq8uQJy7/0v3EZceHlfBMoi7x5k6d/wajm9vKWArTBUEZVhXNPI5FRL1s48B6 x1iW9mCMZwJF/rzWcahOJue34fCdZo0sO9RuZG+rBIB9ybygwtoCh++6OKlmu8jed9 Bc2OaQWV1YK23Yp5cfHfcWG+hJYG5yo/IYRs7jGo= 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 3613A60B11; Fri, 22 Jun 2018 19:49:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1529696958; bh=AH8T3jo+B+L+PGietlvIy1LRfolwVcoS5IPo5cxCCY8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bDHD74TKvYxzrGrDPBBTHkQflI6j5OlTsPUn0xYDAiEuPtnLSrho4Cs2b6H1smQJ2 T5DeGCC5lppfA9zvLKG18tSxOvtvHo8cRCXCzDHV5t6CQnMzaBZvDaJ5sCe7axIoRR XCxZ3XxViEyp9vYJk2NxT8fwUrm13FtCqtaF/qek= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 3613A60B11 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 V3 2/3] arm_pmu: acpi: add support for CPU PMU variant detection Date: Fri, 22 Jun 2018 15:49:07 -0400 Message-Id: <1529696948-16991-2-git-send-email-agustinv@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1529696948-16991-1-git-send-email-agustinv@codeaurora.org> References: <1529696948-16991-1-git-send-email-agustinv@codeaurora.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180622_204933_417425_88BCF514 X-CRM114-Status: GOOD ( 19.75 ) 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: timur@codeaurora.org, agustinv@codeaurora.org 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 5894049..f1be62a 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -600,6 +600,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 15bfb15..9c410cf 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -1153,6 +1153,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 40036a5..ff43d65 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;