Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Shuai Xue <xueshuai@linux.alibaba.com>
To: Yicong Yang <yang.yicong@picoheart.com>,
	renyu.zj@linux.alibaba.com, will@kernel.org,
	mark.rutland@arm.com, jic23@kernel.org, bhelgaas@google.com,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: jingoohan1@gmail.com, mani@kernel.org, juwenlong@picoheart.com,
	geshijian@picoheart.com, douyufan@picoheart.com
Subject: Re: [PATCH v2 3/3] perf/dwc_pcie: Convert to faux device interface
Date: Tue, 30 Jun 2026 17:19:54 +0800	[thread overview]
Message-ID: <530a5e65-8bcf-4aa7-bd1f-aba8bc8a878d@linux.alibaba.com> (raw)
In-Reply-To: <20260629092717.74946-4-yang.yicong@picoheart.com>



On 6/29/26 5:27 PM, Yicong Yang wrote:
> The DWC PCIe PMU makes use of the platform device interface but
> is not the real device, it's actually the RAS DES capability of
> the root port. It's more appropriate to use the lightweight
> faux framework to abstract this, it'll be more simple and no
> need for the complete device and drivers model. So convert to
> the faux device interface.
> 
> Move the cpuhp state registration prior to faux device creation
> since the probe depends on this and will run by the faux device
> creation.
> 
> No functional changes intended.
> 
> Reviewed-by: Jonathan Cameron <jic23@kernel.org>
> Signed-off-by: Yicong Yang <yang.yicong@picoheart.com>
> ---
>   drivers/perf/dwc_pcie_pmu.c | 101 +++++++++++++++++-------------------
>   1 file changed, 48 insertions(+), 53 deletions(-)
> 
> diff --git a/drivers/perf/dwc_pcie_pmu.c b/drivers/perf/dwc_pcie_pmu.c
> index 7ec8302d4090..3a9965b5abf4 100644
> --- a/drivers/perf/dwc_pcie_pmu.c
> +++ b/drivers/perf/dwc_pcie_pmu.c
> @@ -10,6 +10,7 @@
>   #include <linux/cpuhotplug.h>
>   #include <linux/cpumask.h>
>   #include <linux/device.h>
> +#include <linux/device/faux.h>
>   #include <linux/errno.h>
>   #include <linux/hrtimer.h>
>   #include <linux/kernel.h>
> @@ -17,7 +18,6 @@
>   #include <linux/pcie-dwc.h>
>   #include <linux/perf_event.h>
>   #include <linux/pci.h>
> -#include <linux/platform_device.h>
>   #include <linux/smp.h>
>   #include <linux/sysfs.h>
>   #include <linux/types.h>
> @@ -110,9 +110,10 @@ static struct list_head dwc_pcie_dev_info_head =
>   static bool notify;
>   
>   struct dwc_pcie_dev_info {
> -	struct platform_device *plat_dev;
> +	struct faux_device *fdev;
>   	struct pci_dev *pdev;
>   	struct list_head dev_node;
> +	char *name;
>   };
>   
>   static ssize_t cpumask_show(struct device *dev,
> @@ -658,6 +659,12 @@ static void dwc_pcie_unregister_pmu(void *data)
>   	perf_pmu_unregister(&pcie_pmu->pmu);
>   }
>   
> +static int dwc_pcie_pmu_probe(struct faux_device *fdev);
> +
> +static struct faux_device_ops dwc_pcie_faux_ops = {
> +	.probe = dwc_pcie_pmu_probe,
> +};
> +
>   static u16 dwc_pcie_des_cap(struct pci_dev *pdev)
>   {
>   	const struct dwc_pcie_vsec_id *vid;
> @@ -684,31 +691,41 @@ static u16 dwc_pcie_des_cap(struct pci_dev *pdev)
>   
>   static void dwc_pcie_unregister_dev(struct dwc_pcie_dev_info *dev_info)
>   {
> -	platform_device_unregister(dev_info->plat_dev);
> +	faux_device_destroy(dev_info->fdev);
>   	list_del(&dev_info->dev_node);
> +	kfree(dev_info->name);
>   	kfree(dev_info);
>   }
>   
>   static int dwc_pcie_register_dev(struct pci_dev *pdev)
>   {
> -	struct platform_device *plat_dev;
>   	struct dwc_pcie_dev_info *dev_info;
> +	struct faux_device *fdev;
> +	char *name;
>   	u32 sbdf;
>   
>   	sbdf = (pci_domain_nr(pdev->bus) << 16) | PCI_DEVID(pdev->bus->number, pdev->devfn);
> -	plat_dev = platform_device_register_simple("dwc_pcie_pmu", sbdf, NULL, 0);
> -	if (IS_ERR(plat_dev))
> -		return PTR_ERR(plat_dev);
> +	name = kasprintf(GFP_KERNEL, "dwc_pcie_pmu_%x", sbdf);
> +	if (!name)
> +		return -ENOMEM;
> +
> +	fdev = faux_device_create(name, &pdev->dev, &dwc_pcie_faux_ops);
> +	if (!fdev) {
> +		kfree(name);
> +		return -ENODEV;
> +	}
>   
>   	dev_info = kzalloc_obj(*dev_info);
>   	if (!dev_info) {
> -		platform_device_unregister(plat_dev);
> +		faux_device_destroy(fdev);
> +		kfree(name);
>   		return -ENOMEM;
>   	}
>   
> -	/* Cache platform device to handle pci device hotplug */
> -	dev_info->plat_dev = plat_dev;
> +	/* Cache faux device to handle pci device hotplug */
> +	dev_info->fdev = fdev;
>   	dev_info->pdev = pdev;
> +	dev_info->name = name;
>   	list_add(&dev_info->dev_node, &dwc_pcie_dev_info_head);
>   
>   	return 0;
> @@ -743,33 +760,25 @@ static struct notifier_block dwc_pcie_pmu_nb = {
>   	.notifier_call = dwc_pcie_pmu_notifier,
>   };
>   
> -static int dwc_pcie_pmu_probe(struct platform_device *plat_dev)
> +static int dwc_pcie_pmu_probe(struct faux_device *fdev)
>   {
> -	struct pci_dev *pdev;
> +	struct pci_dev *pdev = to_pci_dev(fdev->dev.parent);
>   	struct dwc_pcie_pmu *pcie_pmu;
>   	char *name;
>   	u32 sbdf;
>   	u16 vsec;
>   	int ret;
>   
> -	sbdf = plat_dev->id;
> -	pdev = pci_get_domain_bus_and_slot(sbdf >> 16, PCI_BUS_NUM(sbdf & 0xffff),
> -					   sbdf & 0xff);
> -	if (!pdev) {
> -		pr_err("No pdev found for the sbdf 0x%x\n", sbdf);
> -		return -ENODEV;
> -	}
> +	sbdf = (pci_domain_nr(pdev->bus) << 16) | PCI_DEVID(pdev->bus->number, pdev->devfn);
> +	name = devm_kasprintf(&fdev->dev, GFP_KERNEL, "dwc_rootport_%x", sbdf);
> +	if (!name)
> +		return -ENOMEM;
>   
>   	vsec = dwc_pcie_des_cap(pdev);
>   	if (!vsec)
>   		return -ENODEV;
>   
> -	pci_dev_put(pdev);
> -	name = devm_kasprintf(&plat_dev->dev, GFP_KERNEL, "dwc_rootport_%x", sbdf);
> -	if (!name)
> -		return -ENOMEM;
> -
> -	pcie_pmu = devm_kzalloc(&plat_dev->dev, sizeof(*pcie_pmu), GFP_KERNEL);
> +	pcie_pmu = devm_kzalloc(&fdev->dev, sizeof(*pcie_pmu), GFP_KERNEL);
>   	if (!pcie_pmu)
>   		return -ENOMEM;
>   
> @@ -789,7 +798,7 @@ static int dwc_pcie_pmu_probe(struct platform_device *plat_dev)
>   
>   	pcie_pmu->pmu = (struct pmu){
>   		.name		= name,
> -		.parent		= &plat_dev->dev,
> +		.parent		= &fdev->dev,
>   		.module		= THIS_MODULE,
>   		.attr_groups	= dwc_pcie_attr_groups,
>   		.capabilities	= PERF_PMU_CAP_NO_EXCLUDE,
> @@ -811,7 +820,7 @@ static int dwc_pcie_pmu_probe(struct platform_device *plat_dev)
>   	}
>   
>   	/* Unwind when platform driver removes */

Minor: a stale comment.


Reviewed-by: Shuai Xue <xueshuai@linux.alibaba.com>

Thanks.
Shuai

      parent reply	other threads:[~2026-06-30  9:20 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-29  9:27 [PATCH v2 0/3] New vendor support and optimizations for DWC PCIe PMU Yicong Yang
2026-06-29  9:27 ` [PATCH v2 1/3] perf/dwc_pcie: Add support for Picoheart vendor devices Yicong Yang
2026-06-29  9:40   ` sashiko-bot
2026-06-29 17:43   ` Bjorn Helgaas
2026-06-30  3:35   ` Shuai Xue
2026-06-30 11:31   ` Niklas Cassel
2026-06-29  9:27 ` [PATCH v2 2/3] perf/dwc_pcie: Support narrowed time-based counter for long time monitoring Yicong Yang
2026-06-29  9:42   ` sashiko-bot
2026-06-30  8:50   ` Shuai Xue
2026-06-29  9:27 ` [PATCH v2 3/3] perf/dwc_pcie: Convert to faux device interface Yicong Yang
2026-06-29  9:40   ` sashiko-bot
2026-06-30  9:19   ` Shuai Xue [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=530a5e65-8bcf-4aa7-bd1f-aba8bc8a878d@linux.alibaba.com \
    --to=xueshuai@linux.alibaba.com \
    --cc=bhelgaas@google.com \
    --cc=douyufan@picoheart.com \
    --cc=geshijian@picoheart.com \
    --cc=jic23@kernel.org \
    --cc=jingoohan1@gmail.com \
    --cc=juwenlong@picoheart.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=mani@kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=renyu.zj@linux.alibaba.com \
    --cc=will@kernel.org \
    --cc=yang.yicong@picoheart.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox