linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeremy Linton <jeremy.linton@arm.com>
To: linux-pci@vger.kernel.org
Cc: will@kernel.org, bhelgaas@google.com, robh+dt@kernel.org,
	krzysztof.kozlowski+dt@linaro.org, lpieralisi@kernel.org,
	kw@linux.com, mark.rutland@arm.com, sudeep.holla@arm.com,
	boqun.feng@gmail.com, catalin.marinas@arm.com,
	linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Jeremy Linton <jeremy.linton@arm.com>
Subject: [PATCH 3/4] PCI: host-generic: Add firmware managed config ops
Date: Mon, 25 Jul 2022 11:39:04 -0500	[thread overview]
Message-ID: <20220725163905.2024437-4-jeremy.linton@arm.com> (raw)
In-Reply-To: <20220725163905.2024437-1-jeremy.linton@arm.com>

The generic PCI host driver leaves the configuration and mgmt of the
clock/phy/etc on PCI root ports to the firmware and PCIe defined
mechanisms as is done on UEFI/ACPI systems. If the PCIe config
operations were abstracted as well then a number of the resulting
Linux PCie drivers would no longer be needed.

Given that Arm has standardized a generic SMC conduit for reading and
writing the PCIe config space. Using it on DT based systems seems a
natural way to reduce some of the driver diversity on DT based systems
as well.

This patch adds a compatible type "pci-host-smc-generic" which expects
that the 'reg' property of the root port is missing, and the PCI SMCCC
exists. When that happens it binds the SMC to the pci_ecam_ops.

Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
---
 drivers/pci/controller/pci-host-common.c  | 34 ++++++++++++++++-------
 drivers/pci/controller/pci-host-generic.c |  6 ++++
 2 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/drivers/pci/controller/pci-host-common.c b/drivers/pci/controller/pci-host-common.c
index d3924a44db02..2673fd81d3e0 100644
--- a/drivers/pci/controller/pci-host-common.c
+++ b/drivers/pci/controller/pci-host-common.c
@@ -20,22 +20,41 @@ static void gen_pci_unmap_cfg(void *ptr)
 	pci_ecam_free((struct pci_config_window *)ptr);
 }
 
+__weak int pcie_has_fw_conduit(void)
+{
+	return -EOPNOTSUPP;
+}
+
+__weak struct pci_config_window *pci_setup_fw_mapping(struct device *dev,
+		u16 seg, struct resource *bus_res)
+{
+	return NULL;
+}
+
 static struct pci_config_window *gen_pci_init(struct device *dev,
-		struct pci_host_bridge *bridge, const struct pci_ecam_ops *ops)
+		struct pci_host_bridge *bridge)
 {
 	int err;
 	struct resource cfgres;
 	struct resource_entry *bus;
 	struct pci_config_window *cfg;
+	const struct pci_ecam_ops *ops;
+
+	bus = resource_list_first_type(&bridge->windows, IORESOURCE_BUS);
+	if (!bus)
+		return ERR_PTR(-ENODEV);
 
 	err = of_address_to_resource(dev->of_node, 0, &cfgres);
 	if (err) {
+		if (!pcie_has_fw_conduit())
+			return pci_setup_fw_mapping(dev, bridge->busnr, bus->res);
+
 		dev_err(dev, "missing \"reg\" property\n");
 		return ERR_PTR(err);
 	}
 
-	bus = resource_list_first_type(&bridge->windows, IORESOURCE_BUS);
-	if (!bus)
+	ops = of_device_get_match_data(dev);
+	if (!ops)
 		return ERR_PTR(-ENODEV);
 
 	cfg = pci_ecam_create(dev, &cfgres, bus->res, ops);
@@ -54,11 +73,6 @@ int pci_host_common_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct pci_host_bridge *bridge;
 	struct pci_config_window *cfg;
-	const struct pci_ecam_ops *ops;
-
-	ops = of_device_get_match_data(&pdev->dev);
-	if (!ops)
-		return -ENODEV;
 
 	bridge = devm_pci_alloc_host_bridge(dev, 0);
 	if (!bridge)
@@ -69,7 +83,7 @@ int pci_host_common_probe(struct platform_device *pdev)
 	of_pci_check_probe_only();
 
 	/* Parse and map our Configuration Space windows */
-	cfg = gen_pci_init(dev, bridge, ops);
+	cfg = gen_pci_init(dev, bridge);
 	if (IS_ERR(cfg))
 		return PTR_ERR(cfg);
 
@@ -78,7 +92,7 @@ int pci_host_common_probe(struct platform_device *pdev)
 		pci_add_flags(PCI_REASSIGN_ALL_BUS);
 
 	bridge->sysdata = cfg;
-	bridge->ops = (struct pci_ops *)&ops->pci_ops;
+	bridge->ops = (struct pci_ops *)&cfg->ops->pci_ops;
 	bridge->msi_domain = true;
 
 	return pci_host_probe(bridge);
diff --git a/drivers/pci/controller/pci-host-generic.c b/drivers/pci/controller/pci-host-generic.c
index 63865aeb636b..d20d33b3c689 100644
--- a/drivers/pci/controller/pci-host-generic.c
+++ b/drivers/pci/controller/pci-host-generic.c
@@ -56,6 +56,9 @@ static const struct pci_ecam_ops pci_dw_ecam_bus_ops = {
 	}
 };
 
+static const struct pci_ecam_ops pci_generic_smc_ops = {
+};
+
 static const struct of_device_id gen_pci_of_match[] = {
 	{ .compatible = "pci-host-cam-generic",
 	  .data = &gen_pci_cfg_cam_bus_ops },
@@ -63,6 +66,9 @@ static const struct of_device_id gen_pci_of_match[] = {
 	{ .compatible = "pci-host-ecam-generic",
 	  .data = &pci_generic_ecam_ops },
 
+	{ .compatible = "pci-host-smc-generic",
+	  .data = &pci_generic_smc_ops },
+
 	{ .compatible = "marvell,armada8k-pcie-ecam",
 	  .data = &pci_dw_ecam_bus_ops },
 
-- 
2.37.1


  parent reply	other threads:[~2022-07-25 16:39 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-25 16:39 [PATCH 0/4] PCI SMC conduit, now with DT support Jeremy Linton
2022-07-25 16:39 ` [PATCH 1/4] arm64: smccc: Add PCI SMCCCs Jeremy Linton
2022-07-25 16:39 ` [PATCH 2/4] arm64: PCI: Enable SMC conduit Jeremy Linton
2022-07-25 16:39 ` Jeremy Linton [this message]
2022-07-25 16:39 ` [PATCH 4/4] dt-bindings: PCI: Note the use of pci-host-smc-generic Jeremy Linton
2022-07-26 11:40 ` [PATCH 0/4] PCI SMC conduit, now with DT support Will Deacon
2022-07-28 17:20   ` Jeremy Linton
2022-08-16  7:59     ` Catalin Marinas
2022-08-18 21:55       ` Pali Rohár

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=20220725163905.2024437-4-jeremy.linton@arm.com \
    --to=jeremy.linton@arm.com \
    --cc=bhelgaas@google.com \
    --cc=boqun.feng@gmail.com \
    --cc=catalin.marinas@arm.com \
    --cc=devicetree@vger.kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=kw@linux.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=robh+dt@kernel.org \
    --cc=sudeep.holla@arm.com \
    --cc=will@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).