Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1239178imm; Fri, 22 Jun 2018 12:51:14 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIj38b4l/xFw17MYEn6vcyRuIWYIWvjuAjQEkHQ97nl4X7QJEJE0cdSP3fCFroMiNk8bCql X-Received: by 2002:a17:902:9344:: with SMTP id g4-v6mr3034652plp.10.1529697074939; Fri, 22 Jun 2018 12:51:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529697074; cv=none; d=google.com; s=arc-20160816; b=xPg5iO1TL6SjJdS7x/YZVGVE8GG2lLBvz8lEeeHrRfcDn8M7lWCdUVzGW7zJoYyziA b9rS2Mj2ECna88cT49vwfdRegxPZ6sICZgrl+H74OmC+zfQFaRdll9yaDJ3Qj97YWkB7 NzjU3E0Vjsnx94Qzo/UfiBSVeyOCoUyPyIb93ri6V8eZ7uWPLTnfbn4jWPJEo9p2MYK5 Ls9I+855loJeqd0ZGSdJMAyQlheWMSnUJqPVserWe5KAqx7issYtAa3BH8u9EvgndxuX IclHjF9KzA45HLs510tluwgrU6tej1OsLHmJUrLGUiYny5YLv7QLHTzp1IG60e+wSZ68 5/Lw== 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=uJujxRVqbEnFSwwZ+yZ61XAIn2sXktkoKLhTmklXUh9RUFUOYPh3XfrGrEJth3yONc ODlQ2zp4xpXnlX0Me7ZkMDaYgh8BUXNjzCG+aPYWPaG+uUTPbDwgoan0K4z9kR4U9i0h bj8S06ht5jx2fe8ZguJGKZ8EMJTQIFsJeFpEQ3Dr7jb5cYPc6jnl4wwhaoVngDhiUGN3 QLwtEk0vvOZGsg/Rn9TkspVVORUMi6uYwCjVPWlQab6tS/M/ukijZEacEE7UNFTQ6vI/ pMDM+kyhwqrOsvVeLirsBfUCt+lkOz1ea1wXLBAjGkwHlx787tk6gOjMoQ+x3yuBkiTQ IAKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=JGWzeq8u; dkim=pass header.i=@codeaurora.org header.s=default header.b=bDHD74TK; 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 b1-v6si8197169plc.403.2018.06.22.12.51.00; Fri, 22 Jun 2018 12:51:14 -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=JGWzeq8u; dkim=pass header.i=@codeaurora.org header.s=default header.b=bDHD74TK; 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 S934565AbeFVTtt (ORCPT + 99 others); Fri, 22 Jun 2018 15:49:49 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:33564 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934499AbeFVTtU (ORCPT ); Fri, 22 Jun 2018 15:49:20 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 9654C60B23; 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= 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 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" Cc: timur@codeaurora.org, agustinv@codeaurora.org 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> 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.