Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3371591pxk; Mon, 7 Sep 2020 10:58:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbs4mcpFZczjUie8YJkjF8iFGE6UOGQS0CoAp8/522IFwKV5Rcdo3rh1aGkhfpNxroHDvm X-Received: by 2002:a17:906:1b04:: with SMTP id o4mr23224204ejg.332.1599501480480; Mon, 07 Sep 2020 10:58:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599501480; cv=none; d=google.com; s=arc-20160816; b=Z5irZM6hBuAp4hQHaXuCG6oWCXmgWcnM79Vw7rq24q9O9jQnP4HiCYOnGzqTZgHq90 7VkbsJ/eavzoNxv94KOpemov/xq43QpUakSZszlKoBKc1DYOpuKY0prNt9+5zWho9o1f +WxjPB7Yw3B8MSQWCuClCX3ulh3v8326R2yWyzh3KaPqM/rHhxBP9WXnVumNzWQksvwm CbYH28x4Y54YrsKYT8qKxSAmUENlzA3G23wqILMvnK+2PkXJ5hgdcuP5fW9J7dR6u7t3 C4k1lU6kfKzaBj46awfcdn8U1m1BgUmeCOqxONmZxy6kI2d8XetL7lYAFCKMXPQkYwei qy6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=qV82i/cMU0pqMIc58JJkjw0lpHaVPatepxqNNBoGXnQ=; b=ROp6mJMCrzGkzLMszuknlE4+0GpbIp+BLsnbPBE4DT7IEjzG1CtkBrLflQ0RFYrGxF 78TndtauhbT4FwnqiwI6Q1ptZjeI+FOrtSrLwSp0JX0A1qSjH1aBo1NSKvwN8UXywK15 glK2OpG3QGneApsm4PmUxBJLmwjlQ0hC/d19PNCexXI0Ung/LZZkEeQIvvp4fFofK8cc BgIQ9SjVAyWR+ZJ1QdeyBIaKk3WrtxjaTOmhv1NxsA6X3MGR/Ty2t/kA0QWD7kZnGX9Z CID9d5xBWDkxDpzLdxQQbCwycDRDWmZ0hkGMBYNDs9AVchyF5mpiDE+kzpgpnZR4A+V7 o2Og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WuU9qRi8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ga23si9969819ejb.691.2020.09.07.10.57.38; Mon, 07 Sep 2020 10:58:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WuU9qRi8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728675AbgIGR4U (ORCPT + 99 others); Mon, 7 Sep 2020 13:56:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:46832 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728761AbgIGLUn (ORCPT ); Mon, 7 Sep 2020 07:20:43 -0400 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A825121473; Mon, 7 Sep 2020 11:02:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599476561; bh=5LnHy+uS2JT8LQglM7XzLIkWp4JKXPHRBbX6klDBkg8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=WuU9qRi8sYGjNywoL7UYUJslezd7VyaemYbf0n59dKheUMNgiGZcGyL0iIA+ekKMr 1n0OxJUCDNmE9jatlVJMFMrPu7ZTVbtmOwlniSc1ceecRfVkZWf2cBfkel6un0Q1Ry fOi6tQehwaxjsT3805WgwTU/n/v0XNj+5Jspsmck= Date: Mon, 7 Sep 2020 12:02:37 +0100 From: Will Deacon To: Tuan Phan , suzuki.poulose@arm.com Cc: patches@amperecomputing.com, Mark Rutland , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] perf: arm_dsu: Support DSU ACPI devices Message-ID: <20200907110236.GA12174@willie-the-truck> References: <1597451980-11405-1-git-send-email-tuanphan@os.amperecomputing.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1597451980-11405-1-git-send-email-tuanphan@os.amperecomputing.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [+ Suzuki as I'd like his Ack on this] On Fri, Aug 14, 2020 at 05:39:40PM -0700, Tuan Phan wrote: > Add support for probing device from ACPI node. > Each DSU ACPI node and its associated cpus are inside a cluster node. > > Signed-off-by: Tuan Phan > --- > Changes in v3: > - Based on the latest ARM ACPI binding at: https://developer.arm.com/documentation/den0093/c/ > > Changes in v2: > - Removed IRQF_SHARED. > - Fixed ACPI runtime detection. > > drivers/perf/arm_dsu_pmu.c | 68 ++++++++++++++++++++++++++++++++++++++++------ > 1 file changed, 60 insertions(+), 8 deletions(-) > > diff --git a/drivers/perf/arm_dsu_pmu.c b/drivers/perf/arm_dsu_pmu.c > index 96ed93c..4be355d 100644 > --- a/drivers/perf/arm_dsu_pmu.c > +++ b/drivers/perf/arm_dsu_pmu.c > @@ -11,6 +11,7 @@ > #define DRVNAME PMUNAME "_pmu" > #define pr_fmt(fmt) DRVNAME ": " fmt > > +#include > #include > #include > #include > @@ -603,18 +604,21 @@ static struct dsu_pmu *dsu_pmu_alloc(struct platform_device *pdev) > } > > /** > - * dsu_pmu_dt_get_cpus: Get the list of CPUs in the cluster. > + * dsu_pmu_dt_get_cpus: Get the list of CPUs in the cluster > + * from device tree. > */ > -static int dsu_pmu_dt_get_cpus(struct device_node *dev, cpumask_t *mask) > +static int dsu_pmu_dt_get_cpus(struct platform_device *pdev) > { > int i = 0, n, cpu; > struct device_node *cpu_node; > + struct dsu_pmu *dsu_pmu = > + (struct dsu_pmu *) platform_get_drvdata(pdev); > > - n = of_count_phandle_with_args(dev, "cpus", NULL); > + n = of_count_phandle_with_args(pdev->dev.of_node, "cpus", NULL); > if (n <= 0) > return -ENODEV; > for (; i < n; i++) { > - cpu_node = of_parse_phandle(dev, "cpus", i); > + cpu_node = of_parse_phandle(pdev->dev.of_node, "cpus", i); > if (!cpu_node) > break; > cpu = of_cpu_node_to_id(cpu_node); > @@ -626,11 +630,51 @@ static int dsu_pmu_dt_get_cpus(struct device_node *dev, cpumask_t *mask) > */ > if (cpu < 0) > continue; > - cpumask_set_cpu(cpu, mask); > + cpumask_set_cpu(cpu, &dsu_pmu->associated_cpus); > } > return 0; > } > > +/** > + * dsu_pmu_acpi_get_cpus: Get the list of CPUs in the cluster > + * from ACPI. > + */ > +static int dsu_pmu_acpi_get_cpus(struct platform_device *pdev) > +{ > + int cpu; > + struct dsu_pmu *dsu_pmu = (struct dsu_pmu *) platform_get_drvdata(pdev); > + > + /* > + * A dsu pmu node is inside a cluster parent node along with cpu nodes. > + * We need to find out all cpus that have the same parent with this pmu. > + */ > + for_each_possible_cpu(cpu) { > + struct acpi_device *acpi_dev = ACPI_COMPANION(get_cpu_device(cpu)); > + > + if (acpi_dev && > + acpi_dev->parent == ACPI_COMPANION(&pdev->dev)->parent) > + cpumask_set_cpu(cpu, &dsu_pmu->associated_cpus); > + } > + > + return 0; > +} > + > +static int dsu_pmu_platform_get_cpus(struct platform_device *pdev) > +{ > + int ret = -ENOENT; > + struct fwnode_handle *fwnode = dev_fwnode(&pdev->dev); > + > + if (IS_ERR_OR_NULL(fwnode)) > + return ret; > + > + if (is_of_node(fwnode)) > + ret = dsu_pmu_dt_get_cpus(pdev); > + else if (is_acpi_device_node(fwnode)) > + ret = dsu_pmu_acpi_get_cpus(pdev); > + > + return ret; > +} > + > /* > * dsu_pmu_probe_pmu: Probe the PMU details on a CPU in the cluster. > */ > @@ -683,7 +727,9 @@ static int dsu_pmu_device_probe(struct platform_device *pdev) > if (IS_ERR(dsu_pmu)) > return PTR_ERR(dsu_pmu); > > - rc = dsu_pmu_dt_get_cpus(pdev->dev.of_node, &dsu_pmu->associated_cpus); > + platform_set_drvdata(pdev, dsu_pmu); Hmm, this is a bit nasty because we haven't finished initialising the dsu_pmu yet. I think it would actually be cleaner if you kept: static int dsu_pmu_dt_get_cpus(struct device_node *dev, cpumask_t *mask) for the DT case and added: static int dsu_pmu_acpi_get_cpus(struct device *dev, cpumask_t *mask) for the ACPI case. I suppose the DT case could take the struct device * too if you wanted the prototypes to be the same. > + rc = dsu_pmu_platform_get_cpus(pdev); > if (rc) { > dev_warn(&pdev->dev, "Failed to parse the CPUs\n"); > return rc; > @@ -705,7 +751,6 @@ static int dsu_pmu_device_probe(struct platform_device *pdev) > } > > dsu_pmu->irq = irq; > - platform_set_drvdata(pdev, dsu_pmu); > rc = cpuhp_state_add_instance(dsu_pmu_cpuhp_state, > &dsu_pmu->cpuhp_node); > if (rc) > @@ -752,11 +797,19 @@ static const struct of_device_id dsu_pmu_of_match[] = { > { .compatible = "arm,dsu-pmu", }, > {}, > }; > +MODULE_DEVICE_TABLE(of, dsu_pmu_of_match); > + > +static const struct acpi_device_id dsu_pmu_acpi_match[] = { > + { "ARMHD500", 0}, > + {}, > +}; > +MODULE_DEVICE_TABLE(acpi, dsu_pmu_acpi_match); > > static struct platform_driver dsu_pmu_driver = { > .driver = { > .name = DRVNAME, > .of_match_table = of_match_ptr(dsu_pmu_of_match), > + .acpi_match_table = ACPI_PTR(dsu_pmu_acpi_match), > .suppress_bind_attrs = true, > }, > .probe = dsu_pmu_device_probe, > @@ -826,7 +879,6 @@ static void __exit dsu_pmu_exit(void) > module_init(dsu_pmu_init); > module_exit(dsu_pmu_exit); > > -MODULE_DEVICE_TABLE(of, dsu_pmu_of_match); Why have you moved this line? Will