Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2369931imm; Thu, 7 Jun 2018 09:29:23 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJBKQ9tM5g4Ig+VALMIkEQ6Bd3EEh5A7DvmVMIYNg4wbRR6Gqk306YLsZedX04gOTAoBwAG X-Received: by 2002:a17:902:56e:: with SMTP id 101-v6mr2767527plf.25.1528388963159; Thu, 07 Jun 2018 09:29:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528388963; cv=none; d=google.com; s=arc-20160816; b=LjAN/dtjv91zFJPmPH9dKxdDGddaTR1+G+LsRz5ljoZoj313DBFJ592ipkithVDhK7 E9BPsrmklIqKF5dcPeMHFX4YEiNju76fozsA5+494tWqX54aGPlRss5QVWb6I1YjKq2O ePO+hCSc43heggnf6r7hoF/3rQCrtp9v/9JrxatlTKhFkUr4KQiiQYmLQuyJKqnwMoHc HPx7Ip3Jt2SEemPOdrAgEgKP8ROiIfSvU4pv8w7YgqdNNUrV877r5Ecec7MPtNGCe/zY Y3YR8OUEVW0oaDJquUrr95CN7ibjBdMDSPOxU6+VCgS1Ls1nqBeSn9VLSJegRaw6rrAa mNcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=g8ZxVOfIfMHg1PZqvhaFUK3tMxmJvX64rwPnFlSHvL4=; b=quXLIkCQM2Ame6UeFkRyesguU1fv14vclVJJOK6qAc0LmJ0SkAJG8SN0c6QdrKoPE4 DWCPuySC/hPPfdJTfqNwWXM0IU4mv5p9WwRyS/vRzUHZM4ZimZ/RcMN8xmXs3XyBj6iB NX1loGcAEYLCLTAJH22neToQU/RI5QF710rRa7zhGEVTx1gIX4iw1VwgpeLRiINGujzP 3we2LLWmSJZ970n6mW8eLwUpaKyixhvDwznyKqPD1R8E18XFlVAmnEC62H1o1cpdblGt Q5oMUyqkMmcvXYDv7WRMdT2hvlNf0JouDNXWgtruxUhqcw8cprwczfg8+bjomwNbXDiL XswQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=lUlDqcQH; dkim=pass header.i=@codeaurora.org header.s=default header.b=OgmqI2ww; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q10-v6si15831095pgc.456.2018.06.07.09.29.08; Thu, 07 Jun 2018 09:29:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=lUlDqcQH; dkim=pass header.i=@codeaurora.org header.s=default header.b=OgmqI2ww; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932818AbeFGN51 (ORCPT + 99 others); Thu, 7 Jun 2018 09:57:27 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:39584 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932733AbeFGN5Y (ORCPT ); Thu, 7 Jun 2018 09:57:24 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 5B796602FC; Thu, 7 Jun 2018 13:57:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1528379843; bh=AH8T3jo+B+L+PGietlvIy1LRfolwVcoS5IPo5cxCCY8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lUlDqcQHo7OhoOHQwMVwHCuVjyaYww5qR7lh6Ec02h6tSYEZdeY2OHxuURzxQBlI2 D0s4xxPvscNLgeEi3Xfc3gB3wF0jhryDV4NqQVH67mrfeZZmwklallkXX5eaIlfiLr FXDnF5OIcj+AfFlDdVSvMaV5QreKSbbXam4P0d1o= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 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 B6006608BA; Thu, 7 Jun 2018 13:57:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1528379842; bh=AH8T3jo+B+L+PGietlvIy1LRfolwVcoS5IPo5cxCCY8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OgmqI2wwlp65aL4SBZX8O0rxABqpnjrwlOsrsfWoTw6phZw2lEEKt8YlspNj38q6a 2bZHXHcYsJIaKrJa/xIcB6P/ZkBrd5IoryIqv8ffV93khCcWyHQCVpiMFg1AuKfbiC 1YH6DI0772yJGVDn3gGKQSb7ps7AVG2D9tSG8Hx4= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org B6006608BA 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, Will Deacon , Mark Rutland , Jeremy Linton , Catalin Marinas , Marc Zyngier , Lorenzo Pieralisi Cc: timur@codeaurora.org, agustinv@codeaurora.org Subject: [RFC V2 2/3] arm_pmu: acpi: add support for CPU PMU variant detection Date: Thu, 7 Jun 2018 09:56:47 -0400 Message-Id: <1528379808-27970-3-git-send-email-agustinv@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1528379808-27970-1-git-send-email-agustinv@codeaurora.org> References: <1528379808-27970-1-git-send-email-agustinv@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; -- Qualcomm Datacenter Technologies, Inc. on behalf of the Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.