Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Sherry Sun <sherry.sun@nxp.com>
Cc: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org,
	Frank.Li@nxp.com, s.hauer@pengutronix.de, kernel@pengutronix.de,
	festevam@gmail.com, lpieralisi@kernel.org,
	kwilczynski@kernel.org, mani@kernel.org, bhelgaas@google.com,
	hongxing.zhu@nxp.com, l.stach@pengutronix.de,
	imx@lists.linux.dev, linux-pci@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH V14 02/12] PCI: host-generic: Add common helpers for parsing Root Port properties
Date: Wed, 13 May 2026 17:49:44 -0500	[thread overview]
Message-ID: <20260513224944.GA341451@bhelgaas> (raw)
In-Reply-To: <20260422093549.407022-3-sherry.sun@nxp.com>

On Wed, Apr 22, 2026 at 05:35:39PM +0800, Sherry Sun wrote:
> Introduce generic helper functions to parse Root Port device tree nodes
> and extract common properties like reset GPIOs. This allows multiple
> PCI host controller drivers to share the same parsing logic.
> 
> Define struct pci_host_port to hold common Root Port properties
> (currently only list of PERST# GPIO descriptors) and add
> pci_host_common_parse_ports() to parse Root Port nodes from device tree.
> 
> Also add the 'ports' list to struct pci_host_bridge for better maintain
> parsed Root Port information.
> ...

> +static int pci_host_common_parse_port(struct device *dev,
> +				      struct pci_host_bridge *bridge,
> +				      struct device_node *node)
> +{
> +	struct pci_host_port *port;
> +	int ret;
> +
> +	port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL);
> +	if (!port)
> +		return -ENOMEM;
> +
> +	INIT_LIST_HEAD(&port->perst);
> +
> +	ret = pci_host_common_parse_perst(dev, port, node);
> +	if (ret)
> +		return ret;
> +
> +	/*
> +	 * 1. PERST# found in RP or its child nodes - list is not empty, continue
> +	 * 2. PERST# not found in RP/children, but found in RC node - return -ENODEV
> +	 *    to fallback legacy binding
> +	 * 3. PERST# not found anywhere - list is empty, continue (optional PERST#)
> +	 */
> +	if (list_empty(&port->perst)) {
> +		if (of_property_present(dev->of_node, "reset-gpios") ||
> +		    of_property_present(dev->of_node, "reset-gpio"))
> +			return -ENODEV;

This doesn't seem right to me.  The parser of per-Root Port properties
should not be responsible for deciding whether legacy methods are
valid, i.e., whether a property is in the Root Complex node.  I think
it's up to the caller to decide whether it needs to look elsewhere.

I don't think this even needs to return a "success/failure" value
because there may be more properties in the future, and not all will
be required.  This function can't tell which properties a specific
driver requires and which are optional.

The caller can check whether we found what it needs and fall back to a
legacy method as needed.

> +	}
> +
> +	INIT_LIST_HEAD(&port->list);
> +	list_add_tail(&port->list, &bridge->ports);
> +
> +	return 0;
> +}
> +
> +/**
> + * pci_host_common_parse_ports - Parse Root Port nodes from device tree
> + * @dev: Device pointer
> + * @bridge: PCI host bridge
> + *
> + * This function iterates through child nodes of the host bridge and parses
> + * Root Port properties (currently only reset GPIOs).
> + *
> + * Returns: 0 on success, -ENODEV if no ports found or PERST# found in RC node
> + * (legacy binding should be used), Other negative error codes on failure.
> + */
> +int pci_host_common_parse_ports(struct device *dev, struct pci_host_bridge *bridge)
> +{
> +	int ret = -ENODEV;
> +
> +	for_each_available_child_of_node_scoped(dev->of_node, of_port) {
> +		if (!of_node_is_type(of_port, "pci"))
> +			continue;
> +		ret = pci_host_common_parse_port(dev, bridge, of_port);
> +		if (ret)
> +			goto err_cleanup;
> +	}

I think we should export pci_host_common_parse_port() itself and drop
this so we deal with a single Root Port, and drivers that support
multiple RPs should include their own loop similar to this.  That way
the driver can do several things at once in each iteration of that
loop, e.g., get resources, power up, configure, etc.

I see that would require some rework of the devm_add_action_or_reset()
cleanup.

> +	if (ret)
> +		return ret;
> +
> +	return devm_add_action_or_reset(dev, pci_host_common_delete_ports,
> +					&bridge->ports);
> +
> +err_cleanup:
> +	pci_host_common_delete_ports(&bridge->ports);
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(pci_host_common_parse_ports);
> ...

> + * struct pci_host_perst - PERST# GPIO descriptor
> + * @list: List node for linking multiple PERST# GPIOs
> + * @desc: GPIO descriptor for PERST# signal
> + *
> + * This structure holds a single PERST# GPIO descriptor.
> + */
> +struct pci_host_perst {
> +	struct list_head	list;
> +	struct gpio_desc	*desc;
> +};

How do we associate an element of this list with something?

Based on the imx6 changes, I guess we don't; we don't even associate
the pci_host_port with an RP.  We just assert/deassert PERST# for
every RP at once, and we do it for every GPIO associated with each RP.

There's no way to assert PERST# for a single RP.  I guess we don't
need that?

> +/**
> + * struct pci_host_port - Generic Root Port properties
> + * @list: List node for linking multiple ports
> + * @perst: List of PERST# GPIO descriptors for this port and its children
> + *
> + * This structure contains common properties that can be parsed from
> + * Root Port device tree nodes.
> + */
> +struct pci_host_port {

"host_port" is not really a standard term.  And despite the comments
above and below, I don't think the list is restricted to Root Ports
because we traverse the whole hierarchy below the RP.

> +	struct list_head	list;
> +	struct list_head	perst;
> +};

> +	struct list_head ports;		/* Root Port list (pci_host_port) */


  reply	other threads:[~2026-05-13 22:49 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-22  9:35 [PATCH V14 00/12] pci-imx6: Add support for parsing the reset property in new Root Port binding Sherry Sun
2026-04-22  9:35 ` [PATCH V14 01/12] dt-bindings: PCI: fsl,imx6q-pcie: Add reset GPIO in Root Port node Sherry Sun
2026-04-22  9:35 ` [PATCH V14 02/12] PCI: host-generic: Add common helpers for parsing Root Port properties Sherry Sun
2026-05-13 22:49   ` Bjorn Helgaas [this message]
2026-04-22  9:35 ` [PATCH V14 03/12] PCI: imx6: Assert PERST# before enabling regulators Sherry Sun
2026-05-08  3:15   ` Hongxing Zhu
2026-04-22  9:35 ` [PATCH V14 04/12] PCI: imx6: Add support for parsing the reset property in new Root Port binding Sherry Sun
2026-05-08  3:15   ` Hongxing Zhu
2026-04-22  9:35 ` [PATCH V14 05/12] arm: dts: imx6qdl: Add Root Port node and PERST property Sherry Sun
2026-04-22  9:35 ` [PATCH V14 06/12] arm: dts: imx6sx: " Sherry Sun
2026-04-22  9:35 ` [PATCH V14 07/12] arm: dts: imx7d: " Sherry Sun
2026-04-22  9:35 ` [PATCH V14 08/12] arm64: dts: imx8mm: " Sherry Sun
2026-04-22  9:35 ` [PATCH V14 09/12] arm64: dts: imx8mp: " Sherry Sun
2026-04-22  9:35 ` [PATCH V14 10/12] arm64: dts: imx8mq: " Sherry Sun
2026-04-22  9:35 ` [PATCH V14 11/12] arm64: dts: imx8dxl/qm/qxp: " Sherry Sun
2026-04-22  9:35 ` [PATCH V14 12/12] arm64: dts: imx95: " Sherry Sun
2026-05-12 12:55 ` (subset) [PATCH V14 00/12] pci-imx6: Add support for parsing the reset property in new Root Port binding Manivannan Sadhasivam
2026-05-13  2:01   ` Sherry Sun
2026-05-13 18:56     ` Frank Li

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=20260513224944.GA341451@bhelgaas \
    --to=helgaas@kernel.org \
    --cc=Frank.Li@nxp.com \
    --cc=bhelgaas@google.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=festevam@gmail.com \
    --cc=hongxing.zhu@nxp.com \
    --cc=imx@lists.linux.dev \
    --cc=kernel@pengutronix.de \
    --cc=krzk+dt@kernel.org \
    --cc=kwilczynski@kernel.org \
    --cc=l.stach@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=mani@kernel.org \
    --cc=robh@kernel.org \
    --cc=s.hauer@pengutronix.de \
    --cc=sherry.sun@nxp.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