Skip to contentSkip to conversation

PCI: apple: Add support for t6020

PATCH Superseded Marc Zyngier 5 participants 23 messages Mar 25, 2025 – Mar 31, 2025

Subsystems (7)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Marc Zyngier

author maintainer
#0 lore raw

v2 cover PCI: apple: Add support for t6020

As Alyssa didn't have the bandwidth to deal with this series, I have taken it over. All bugs are therefore mine.

The initial series [1] stated:

"This series adds T6020 support to the Apple PCIe controller. Mostly
Apple shuffled registers around (presumably to accommodate the larger configurations on those machines). So there's a bit of churn here but not too much in the way of functional changes."

The biggest change is affecting the ECAM layer, allowing an ECAM driver to provide its own probe function instead of relying on the .init() callback to do the work. The ECAM layer can therefore be used as a library instead of a convoluted driver.

The rest is a mix of bug fixes, cleanups, and required abstraction.

This has been tested on T6020 (M2-Pro mini) and T8102 (M1 mini).

* From v1[1]:

- Described the PHY registers in the DT binding

- Extracted a ecam bridge creation helper from the host-common layer

- Moved probing into its own function instead of pci_host_common_probe()

- Moved host-specific data to the of_device_id[] table

- Added dynamic allocation of the RID/SID bitmap

- Fixed latent bug in RC-generated interrupts

- Renamed reg_info to hw_info

- Dropped useless max_msimap

- Dropped code being moved around without justification

- Re-split some of the patches to follow a more logical progression

- General cleanup to fit my own taste

[1] https://lore.kernel.org/r/[email protected]

Alyssa Rosenzweig (1):
dt-bindings: pci: apple,pcie: Add t6020 compatible string

Hector Martin (6):
PCI: apple: Fix missing OF node reference in apple_pcie_setup_port
PCI: apple: Move port PHY registers to their own reg items
PCI: apple: Drop poll for CORE_RC_PHYIF_STAT_REFCLK
PCI: apple: Use gpiod_set_value_cansleep in probe flow
PCI: apple: Abstract register offsets via a SoC-specific structure
PCI: apple: Add T602x PCIe support

Janne Grunau (1):
PCI: apple: Set only available ports up

Marc Zyngier (5):
PCI: host-generic: Extract an ecam bridge creation helper from
pci_host_common_probe()
PCI: ecam: Allow cfg->priv to be pre-populated from the root port
device
PCI: apple: Move over to standalone probing
PCI: apple: Dynamically allocate RID-to_SID bitmap
PCI: apple: Move away from INTMSK{SET,CLR} for INTx and private
interrupts

 .../devicetree/bindings/pci/apple,pcie.yaml   |  11 +-
 drivers/pci/controller/pci-host-common.c      |  24 +-
 drivers/pci/controller/pcie-apple.c           | 241 +++++++++++++-----
 drivers/pci/ecam.c                            |   2 +
 include/linux/pci-ecam.h                      |   2 +
 5 files changed, 204 insertions(+), 76 deletions(-)
Signature · 1 line
2.39.2
author maintainer
#1 lore raw

PATCH v2 1/13 dt-bindings: pci: apple,pcie: Add t6020 compatible string

From: Alyssa Rosenzweig <[email protected]>

t6020 adds some register ranges compared to t8103, so requires a new compatible as well as the new PHY registers themselves.

[maz: added PHY registers]
---
 Documentation/devicetree/bindings/pci/apple,pcie.yaml | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/pci/apple,pcie.yaml +10 -1
index c8775f9cb0713..77554899b9420 100644
@@ -17,6 +17,10 @@ description: |
   implements its root ports.  But the ATU found on most DesignWare
   PCIe host bridges is absent.
 
+  On systems derived from T602x, the PHY registers are in a region
+  separate from the port registers. In that case, there is one PHY
+  register range per port register range.
+
   All root ports share a single ECAM space, but separate GPIOs are
   used to take the PCI devices on those ports out of reset.  Therefore
   the standard "reset-gpios" and "max-link-speed" properties appear on
@@ -35,11 +39,12 @@ properties:
           - apple,t8103-pcie
           - apple,t8112-pcie
           - apple,t6000-pcie
+          - apple,t6020-pcie
       - const: apple,pcie
 
   reg:
     minItems: 3
-    maxItems: 6
+    maxItems: 10
 
   reg-names:
     minItems: 3
@@ -50,6 +55,10 @@ properties:
       - const: port1
       - const: port2
       - const: port3
+      - const: phy0
+      - const: phy1
+      - const: phy2
+      - const: phy3
 
   ranges:
     minItems: 2
Signature · 1 line
2.39.2
author maintainer
#7 lore raw

PATCH v2 2/13 PCI: host-generic: Extract an ecam bridge creation helper from pci_host_common_probe()

In reply to Marc Zyngier

pci_host_common_probe() is an extremely userful helper, as it abstracts away most of the gunk that a "mostly-ECAM-compliant" device driver needs.

However, it is structured as a probe function, meaning that a lot of the driver-specific setup has to happen in a .init() callback, after the bridge and config space have been instantiated.

This is a bit awkward, and results in a number of convolutions that could be avoided if the host-common code was more like a library.

Introduce a pci_host_common_init() helper that does exactly that, taking the platform device and a struct pci_ecam_op as parameters.

This can then be called from the probe routine, and a lot of the code that isn't relevant to PCI setup moved away from the .init() callback. This also removes the dependency on the device match data, which is an oddity.

---
 drivers/pci/controller/pci-host-common.c | 24 ++++++++++++++++--------
 include/linux/pci-ecam.h                 |  2 ++
 2 files changed, 18 insertions(+), 8 deletions(-)
drivers/pci/controller/pci-host-common.c +16 -8
index f441bfd6f96a8..466a1e6a7ffcd 100644
@@ -49,23 +49,17 @@ static struct pci_config_window *gen_pci_init(struct device *dev,
 	return cfg;
 }
 
-int pci_host_common_probe(struct platform_device *pdev)
+int pci_host_common_init(struct platform_device *pdev,
+			 const struct pci_ecam_ops *ops)
 {
 	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)
 		return -ENOMEM;
 
-	platform_set_drvdata(pdev, bridge);
-
 	of_pci_check_probe_only();
 
 	/* Parse and map our Configuration Space windows */
@@ -73,6 +67,8 @@ int pci_host_common_probe(struct platform_device *pdev)
 	if (IS_ERR(cfg))
 		return PTR_ERR(cfg);
 
+	platform_set_drvdata(pdev, bridge);
+
 	bridge->sysdata = cfg;
 	bridge->ops = (struct pci_ops *)&ops->pci_ops;
 	bridge->enable_device = ops->enable_device;
@@ -81,6 +77,18 @@ int pci_host_common_probe(struct platform_device *pdev)
 
 	return pci_host_probe(bridge);
 }
+EXPORT_SYMBOL_GPL(pci_host_common_init);
+
+int pci_host_common_probe(struct platform_device *pdev)
+{
+	const struct pci_ecam_ops *ops;
+
+	ops = of_device_get_match_data(&pdev->dev);
+	if (!ops)
+		return -ENODEV;
+
+	return pci_host_common_init(pdev, ops);
+}
 EXPORT_SYMBOL_GPL(pci_host_common_probe);
 
 void pci_host_common_remove(struct platform_device *pdev)
include/linux/pci-ecam.h +2 -0
index 3a10f8cfc3ad5..bc2ca2c72ee23 100644
@@ -97,6 +97,8 @@ extern const struct pci_ecam_ops loongson_pci_ecam_ops; /* Loongson PCIe */
 #if IS_ENABLED(CONFIG_PCI_HOST_COMMON)
 /* for DT-based PCI controllers that support ECAM */
 int pci_host_common_probe(struct platform_device *pdev);
+int pci_host_common_init(struct platform_device *pdev,
+			 const struct pci_ecam_ops *ops);
 void pci_host_common_remove(struct platform_device *pdev);
 #endif
 #endif
Signature · 1 line
2.39.2
author maintainer
#8 lore raw

PATCH v2 3/13 PCI: ecam: Allow cfg->priv to be pre-populated from the root port device

In reply to Marc Zyngier

In order to decouple ecam config space creation from probing via pci_host_common_probe(), allow the private pointer to be populated via the device drvdata pointer.

Crucially, this is set before calling ops->init(), allowing that particular callback to have access to probe data.

This should have no impact on existing code which ignores the current value of cfg->priv.

---
 drivers/pci/ecam.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/pci/ecam.c +2 -0
index 260b7de2dbd57..2c5e6446e00ee 100644
@@ -84,6 +84,8 @@ struct pci_config_window *pci_ecam_create(struct device *dev,
 			goto err_exit_iomap;
 	}
 
+	cfg->priv = dev_get_drvdata(dev);
+
 	if (ops->init) {
 		err = ops->init(cfg);
 		if (err)
Signature · 1 line
2.39.2
author maintainer
#9 lore raw

PATCH v2 4/13 PCI: apple: Move over to standalone probing

In reply to Marc Zyngier

Now that we have the required infrastructure, split the Apple PCIe setup into two categories:

- stuff that has to do with PCI setup stays in the .init() callback

- stuff that is just driver gunk (such as MSI setup) goes into a probe routine, which will eventually call into the host-common code

The result is a far more logical setup process.

---
 drivers/pci/controller/pcie-apple.c | 54 ++++++++++++++++-------------
 1 file changed, 30 insertions(+), 24 deletions(-)
drivers/pci/controller/pcie-apple.c +30 -24
index a7e51bc1c2fe8..9c3103d0d1174 100644
@@ -730,35 +730,15 @@ static void apple_pcie_disable_device(struct pci_host_bridge *bridge, struct pci
 
 static int apple_pcie_init(struct pci_config_window *cfg)
 {
+	struct apple_pcie *pcie = cfg->priv;
 	struct device *dev = cfg->parent;
-	struct platform_device *platform = to_platform_device(dev);
 	struct device_node *of_port;
-	struct apple_pcie *pcie;
 	int ret;
 
-	pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
-	if (!pcie)
-		return -ENOMEM;
-
-	pcie->dev = dev;
-
-	mutex_init(&pcie->lock);
-
-	pcie->base = devm_platform_ioremap_resource(platform, 1);
-	if (IS_ERR(pcie->base))
-		return PTR_ERR(pcie->base);
-
-	cfg->priv = pcie;
-	INIT_LIST_HEAD(&pcie->ports);
-
-	ret = apple_msi_init(pcie);
-	if (ret)
-		return ret;
-
 	for_each_child_of_node(dev->of_node, of_port) {
 		ret = apple_pcie_setup_port(pcie, of_port);
 		if (ret) {
-			dev_err(pcie->dev, "Port %pOF setup fail: %d\n", of_port, ret);
+			dev_err(dev, "Port %pOF setup fail: %d\n", of_port, ret);
 			of_node_put(of_port);
 			return ret;
 		}
@@ -778,14 +758,40 @@ static const struct pci_ecam_ops apple_pcie_cfg_ecam_ops = {
 	}
 };
 
+static int apple_pcie_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct apple_pcie *pcie;
+	int ret;
+
+	pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
+	if (!pcie)
+		return -ENOMEM;
+
+	pcie->dev = dev;
+	pcie->base = devm_platform_ioremap_resource(pdev, 1);
+	if (IS_ERR(pcie->base))
+		return PTR_ERR(pcie->base);
+
+	mutex_init(&pcie->lock);
+	INIT_LIST_HEAD(&pcie->ports);
+	dev_set_drvdata(dev, pcie);
+
+	ret = apple_msi_init(pcie);
+	if (ret)
+		return ret;
+
+	return pci_host_common_init(pdev, &apple_pcie_cfg_ecam_ops);
+}
+
 static const struct of_device_id apple_pcie_of_match[] = {
-	{ .compatible = "apple,pcie", .data = &apple_pcie_cfg_ecam_ops },
+	{ .compatible = "apple,pcie" },
 	{ }
 };
 MODULE_DEVICE_TABLE(of, apple_pcie_of_match);
 
 static struct platform_driver apple_pcie_driver = {
-	.probe	= pci_host_common_probe,
+	.probe	= apple_pcie_probe,
 	.driver	= {
 		.name			= "pcie-apple",
 		.of_match_table		= apple_pcie_of_match,
Signature · 1 line
2.39.2
author maintainer
#10 lore raw

PATCH v2 5/13 PCI: apple: Dynamically allocate RID-to_SID bitmap

In reply to Marc Zyngier

As we move towards supporting SoCs with varying RID-to-SID mapping capabilities, turn the static SID tracking bitmap into a dynamically allocated one. The current allocation size is still the same, but that's about to change.

---
 drivers/pci/controller/pcie-apple.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/pci/controller/pcie-apple.c +5 -1
index 9c3103d0d1174..1f6c55e4b5d68 100644
@@ -147,7 +147,7 @@ struct apple_pcie_port {
 	void __iomem		*base;
 	struct irq_domain	*domain;
 	struct list_head	entry;
-	DECLARE_BITMAP(sid_map, MAX_RID2SID);
+	unsigned long		*sid_map;
 	int			sid_map_sz;
 	int			idx;
 };
@@ -524,6 +524,10 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie,
 	if (!port)
 		return -ENOMEM;
 
+	port->sid_map = devm_bitmap_zalloc(pcie->dev, MAX_RID2SID, GFP_KERNEL);
+	if (!port->sid_map)
+		return -ENOMEM;
+
 	ret = of_property_read_u32_index(np, "reg", 0, &idx);
 	if (ret)
 		return ret;
Signature · 1 line
2.39.2
author maintainer
#11 lore raw

PATCH v2 6/13 PCI: apple: Move away from INTMSK{SET,CLR} for INTx and private interrupts

In reply to Marc Zyngier

T602x seems to have dropped the rather useful SET/CLR accessors to the masking register.

Instead, let's use the mask register directly, and wrap it with a brand new spinlock. No, this isn't moving in the right direction.

---
 drivers/pci/controller/pcie-apple.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/pci/controller/pcie-apple.c +8 -3
index 1f6c55e4b5d68..63ceb5e3debaf 100644
@@ -142,6 +142,7 @@ struct apple_pcie {
 };
 
 struct apple_pcie_port {
+	raw_spinlock_t		lock;
 	struct apple_pcie	*pcie;
 	struct device_node	*np;
 	void __iomem		*base;
@@ -261,14 +262,16 @@ static void apple_port_irq_mask(struct irq_data *data)
 {
 	struct apple_pcie_port *port = irq_data_get_irq_chip_data(data);
 
-	writel_relaxed(BIT(data->hwirq), port->base + PORT_INTMSKSET);
+	guard(raw_spinlock_irqsave)(&port->lock);
+	rmw_set(BIT(data->hwirq), port->base + PORT_INTMSK);
 }
 
 static void apple_port_irq_unmask(struct irq_data *data)
 {
 	struct apple_pcie_port *port = irq_data_get_irq_chip_data(data);
 
-	writel_relaxed(BIT(data->hwirq), port->base + PORT_INTMSKCLR);
+	guard(raw_spinlock_irqsave)(&port->lock);
+	rmw_clear(BIT(data->hwirq), port->base + PORT_INTMSK);
 }
 
 static bool hwirq_is_intx(unsigned int hwirq)
@@ -387,7 +390,7 @@ static int apple_pcie_port_setup_irq(struct apple_pcie_port *port)
 		return -ENOMEM;
 
 	/* Disable all interrupts */
-	writel_relaxed(~0, port->base + PORT_INTMSKSET);
+	writel_relaxed(~0, port->base + PORT_INTMSK);
 	writel_relaxed(~0, port->base + PORT_INTSTAT);
 
 	irq_set_chained_handler_and_data(irq, apple_port_irq_handler, port);
@@ -537,6 +540,8 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie,
 	port->pcie = pcie;
 	port->np = np;
 
+	raw_spin_lock_init(&port->lock);
+
 	port->base = devm_platform_ioremap_resource(platform, port->idx + 2);
 	if (IS_ERR(port->base))
 		return PTR_ERR(port->base);
Signature · 1 line
2.39.2
author maintainer
#12 lore raw

PATCH v2 7/13 PCI: apple: Fix missing OF node reference in apple_pcie_setup_port

In reply to Marc Zyngier

From: Hector Martin <[email protected]>

In the success path, we hang onto a reference to the node, so make sure to grab one. The caller iterator puts our borrowed reference when we return.

---
 drivers/pci/controller/pcie-apple.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/pci/controller/pcie-apple.c +3 -0
index 63ceb5e3debaf..6271533f1b042 100644
@@ -593,6 +593,9 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie,
 	list_add_tail(&port->entry, &pcie->ports);
 	init_completion(&pcie->event);
 
+	/* In the success path, we keep a reference to np around */
+	of_node_get(np);
+
 	ret = apple_pcie_port_register_irqs(port);
 	WARN_ON(ret);
 
Signature · 1 line
2.39.2
author maintainer
#13 lore raw

PATCH v2 8/13 PCI: apple: Set only available ports up

In reply to Marc Zyngier

From: Janne Grunau <[email protected]>

Iterating over disabled ports results in of_irq_parse_raw() parsing the wrong "interrupt-map" entries, as it takes the status of the node into account.

Switching from for_each_child_of_node() to for_each_available_child_of_node() solves this issue.

This became apparent after disabling unused PCIe ports in the Apple Silicon device trees instead of deleting them.

---
 drivers/pci/controller/pcie-apple.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/pcie-apple.c +1 -1
index 6271533f1b042..23d9f62bd2ad4 100644
@@ -747,7 +747,7 @@ static int apple_pcie_init(struct pci_config_window *cfg)
 	struct device_node *of_port;
 	int ret;
 
-	for_each_child_of_node(dev->of_node, of_port) {
+	for_each_available_child_of_node(dev->of_node, of_port) {
 		ret = apple_pcie_setup_port(pcie, of_port);
 		if (ret) {
 			dev_err(dev, "Port %pOF setup fail: %d\n", of_port, ret);
Signature · 1 line
2.39.2
author maintainer
#15 lore raw

PATCH v2 9/13 PCI: apple: Move port PHY registers to their own reg items

In reply to Marc Zyngier

From: Hector Martin <[email protected]>

T602x PCIe cores move these registers around. Instead of hardcoding in another offset, let's move them into their own reg entries. This matches what Apple does on macOS device trees too.

Maintains backwards compatibility with old DTs by using the old offsets.

Note that we open code devm_platform_ioremap_resource_byname() to avoid error messages on older platforms with missing resources in the pcie node. ("pcie-apple 590000000.pcie: invalid resource (null)" on probe)

---
 drivers/pci/controller/pcie-apple.c | 55 +++++++++++++++++++----------
 1 file changed, 37 insertions(+), 18 deletions(-)
drivers/pci/controller/pcie-apple.c +37 -18
index 23d9f62bd2ad4..94c49611b74df 100644
@@ -39,14 +39,18 @@
 #define   CORE_RC_STAT_READY		BIT(0)
 #define CORE_FABRIC_STAT		0x04000
 #define   CORE_FABRIC_STAT_MASK		0x001F001F
-#define CORE_LANE_CFG(port)		(0x84000 + 0x4000 * (port))
-#define   CORE_LANE_CFG_REFCLK0REQ	BIT(0)
-#define   CORE_LANE_CFG_REFCLK1REQ	BIT(1)
-#define   CORE_LANE_CFG_REFCLK0ACK	BIT(2)
-#define   CORE_LANE_CFG_REFCLK1ACK	BIT(3)
-#define   CORE_LANE_CFG_REFCLKEN	(BIT(9) | BIT(10))
-#define CORE_LANE_CTL(port)		(0x84004 + 0x4000 * (port))
-#define   CORE_LANE_CTL_CFGACC		BIT(15)
+
+#define CORE_PHY_DEFAULT_BASE(port)	(0x84000 + 0x4000 * (port))
+
+#define PHY_LANE_CFG			0x00000
+#define   PHY_LANE_CFG_REFCLK0REQ	BIT(0)
+#define   PHY_LANE_CFG_REFCLK1REQ	BIT(1)
+#define   PHY_LANE_CFG_REFCLK0ACK	BIT(2)
+#define   PHY_LANE_CFG_REFCLK1ACK	BIT(3)
+#define   PHY_LANE_CFG_REFCLKEN		(BIT(9) | BIT(10))
+#define   PHY_LANE_CFG_REFCLKCGEN	(BIT(30) | BIT(31))
+#define PHY_LANE_CTL			0x00004
+#define   PHY_LANE_CTL_CFGACC		BIT(15)
 
 #define PORT_LTSSMCTL			0x00080
 #define   PORT_LTSSMCTL_START		BIT(0)
@@ -146,6 +150,7 @@ struct apple_pcie_port {
 	struct apple_pcie	*pcie;
 	struct device_node	*np;
 	void __iomem		*base;
+	void __iomem		*phy;
 	struct irq_domain	*domain;
 	struct list_head	entry;
 	unsigned long		*sid_map;
@@ -476,26 +481,26 @@ static int apple_pcie_setup_refclk(struct apple_pcie *pcie,
 	if (res < 0)
 		return res;
 
-	rmw_set(CORE_LANE_CTL_CFGACC, pcie->base + CORE_LANE_CTL(port->idx));
-	rmw_set(CORE_LANE_CFG_REFCLK0REQ, pcie->base + CORE_LANE_CFG(port->idx));
+	rmw_set(PHY_LANE_CTL_CFGACC, port->phy + PHY_LANE_CTL);
+	rmw_set(PHY_LANE_CFG_REFCLK0REQ, port->phy + PHY_LANE_CFG);
 
-	res = readl_relaxed_poll_timeout(pcie->base + CORE_LANE_CFG(port->idx),
-					 stat, stat & CORE_LANE_CFG_REFCLK0ACK,
+	res = readl_relaxed_poll_timeout(port->phy + PHY_LANE_CFG,
+					 stat, stat & PHY_LANE_CFG_REFCLK0ACK,
 					 100, 50000);
 	if (res < 0)
 		return res;
 
-	rmw_set(CORE_LANE_CFG_REFCLK1REQ, pcie->base + CORE_LANE_CFG(port->idx));
-	res = readl_relaxed_poll_timeout(pcie->base + CORE_LANE_CFG(port->idx),
-					 stat, stat & CORE_LANE_CFG_REFCLK1ACK,
+	rmw_set(PHY_LANE_CFG_REFCLK1REQ, port->phy + PHY_LANE_CFG);
+	res = readl_relaxed_poll_timeout(port->phy + PHY_LANE_CFG,
+					 stat, stat & PHY_LANE_CFG_REFCLK1ACK,
 					 100, 50000);
 
 	if (res < 0)
 		return res;
 
-	rmw_clear(CORE_LANE_CTL_CFGACC, pcie->base + CORE_LANE_CTL(port->idx));
+	rmw_clear(PHY_LANE_CTL_CFGACC, port->phy + PHY_LANE_CTL);
 
-	rmw_set(CORE_LANE_CFG_REFCLKEN, pcie->base + CORE_LANE_CFG(port->idx));
+	rmw_set(PHY_LANE_CFG_REFCLKEN, port->phy + PHY_LANE_CFG);
 	rmw_set(PORT_REFCLK_EN, port->base + PORT_REFCLK);
 
 	return 0;
@@ -515,6 +520,8 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie,
 	struct platform_device *platform = to_platform_device(pcie->dev);
 	struct apple_pcie_port *port;
 	struct gpio_desc *reset;
+	struct resource *res;
+	char name[16];
 	u32 stat, idx;
 	int ret, i;
 
@@ -542,10 +549,22 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie,
 
 	raw_spin_lock_init(&port->lock);
 
-	port->base = devm_platform_ioremap_resource(platform, port->idx + 2);
+	snprintf(name, sizeof(name), "port%d", port->idx);
+	res = platform_get_resource_byname(platform, IORESOURCE_MEM, name);
+	if (!res)
+		res = platform_get_resource(platform, IORESOURCE_MEM, port->idx + 2);
+
+	port->base = devm_ioremap_resource(&platform->dev, res);
 	if (IS_ERR(port->base))
 		return PTR_ERR(port->base);
 
+	snprintf(name, sizeof(name), "phy%d", port->idx);
+	res = platform_get_resource_byname(platform, IORESOURCE_MEM, name);
+	if (res)
+		port->phy = devm_ioremap_resource(&platform->dev, res);
+	else
+		port->phy = pcie->base + CORE_PHY_DEFAULT_BASE(port->idx);
+
 	rmw_set(PORT_APPCLK_EN, port->base + PORT_APPCLK);
 
 	/* Assert PERST# before setting up the clock */
Signature · 1 line
2.39.2
author maintainer
#16 lore raw

PATCH v2 10/13 PCI: apple: Drop poll for CORE_RC_PHYIF_STAT_REFCLK

In reply to Marc Zyngier

From: Hector Martin <[email protected]>

This is checking a core refclk in per-port setup which doesn't make a lot of sense, and the bootloader needs to have gone through this anyway.

It doesn't work on T602x, so just drop it across the board.

---
 drivers/pci/controller/pcie-apple.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/pci/controller/pcie-apple.c +0 -6
index 94c49611b74df..c00ec0781fabc 100644
@@ -475,12 +475,6 @@ static int apple_pcie_setup_refclk(struct apple_pcie *pcie,
 	u32 stat;
 	int res;
 
-	res = readl_relaxed_poll_timeout(pcie->base + CORE_RC_PHYIF_STAT, stat,
-					 stat & CORE_RC_PHYIF_STAT_REFCLK,
-					 100, 50000);
-	if (res < 0)
-		return res;
-
 	rmw_set(PHY_LANE_CTL_CFGACC, port->phy + PHY_LANE_CTL);
 	rmw_set(PHY_LANE_CFG_REFCLK0REQ, port->phy + PHY_LANE_CFG);
 
Signature · 1 line
2.39.2
author maintainer
#17 lore raw

PATCH v2 11/13 PCI: apple: Use gpiod_set_value_cansleep in probe flow

In reply to Marc Zyngier

From: Hector Martin <[email protected]>

We're allowed to sleep here, so tell the GPIO core by using gpiod_set_value_cansleep instead of gpiod_set_value.

Fixes 1e33888fbe44 ("PCI: apple: Add initial hardware bring-up")
---
 drivers/pci/controller/pcie-apple.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/controller/pcie-apple.c +2 -2
index c00ec0781fabc..505adf64bd66d 100644
@@ -562,7 +562,7 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie,
 	rmw_set(PORT_APPCLK_EN, port->base + PORT_APPCLK);
 
 	/* Assert PERST# before setting up the clock */
-	gpiod_set_value(reset, 1);
+	gpiod_set_value_cansleep(reset, 1);
 
 	ret = apple_pcie_setup_refclk(pcie, port);
 	if (ret < 0)
@@ -573,7 +573,7 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie,
 
 	/* Deassert PERST# */
 	rmw_set(PORT_PERST_OFF, port->base + PORT_PERST);
-	gpiod_set_value(reset, 0);
+	gpiod_set_value_cansleep(reset, 0);
 
 	/* Wait for 100ms after PERST# deassertion (PCIe r5.0, 6.6.1) */
 	msleep(100);
Signature · 1 line
2.39.2
author maintainer
#18 lore raw

PATCH v2 12/13 PCI: apple: Abstract register offsets via a SoC-specific structure

In reply to Marc Zyngier

From: Hector Martin <[email protected]>

Newer versions of the Apple PCIe block have a bunch of small, but annoying differences.

In order to embrace this diversity of implementations, move the currently hardcoded offsets into a hw_info structure. Future SoCs will provide their own structure describing the applicable offsets.

[maz: split from original patch to only address T8103]
---
 drivers/pci/controller/pcie-apple.c | 89 +++++++++++++++++++++++------
 1 file changed, 72 insertions(+), 17 deletions(-)
drivers/pci/controller/pcie-apple.c +72 -17
index 505adf64bd66d..847cba753d28d 100644
@@ -18,6 +18,7 @@
  * Author: Marc Zyngier <[email protected]>
  */
 
+#include <linux/bitfield.h>
 #include <linux/gpio/consumer.h>
 #include <linux/kernel.h>
 #include <linux/iopoll.h>
@@ -29,6 +30,7 @@
 #include <linux/of_irq.h>
 #include <linux/pci-ecam.h>
 
+/* T8103 (original M1) and related SoCs */
 #define CORE_RC_PHYIF_CTL		0x00024
 #define   CORE_RC_PHYIF_CTL_RUN		BIT(0)
 #define CORE_RC_PHYIF_STAT		0x00028
@@ -104,7 +106,7 @@
 #define   PORT_REFCLK_CGDIS		BIT(8)
 #define PORT_PERST			0x00814
 #define   PORT_PERST_OFF		BIT(0)
-#define PORT_RID2SID(i16)		(0x00828 + 4 * (i16))
+#define PORT_RID2SID			0x00828
 #define   PORT_RID2SID_VALID		BIT(31)
 #define   PORT_RID2SID_SID_SHIFT	16
 #define   PORT_RID2SID_BUS_SHIFT	8
@@ -122,7 +124,8 @@
 #define   PORT_TUNSTAT_PERST_ACK_PEND	BIT(1)
 #define PORT_PREFMEM_ENABLE		0x00994
 
-#define MAX_RID2SID			64
+#define PORT_MSIMAP_ENABLE	BIT(31)
+#define PORT_MSIMAP_TARGET	GENMASK(7, 0)
 
 /*
  * The doorbell address is set to 0xfffff000, which by convention
@@ -133,10 +136,33 @@
  */
 #define DOORBELL_ADDR		CONFIG_PCIE_APPLE_MSI_DOORBELL_ADDR
 
+struct hw_info {
+	u32 phy_lane_ctl;
+	u32 port_msiaddr;
+	u32 port_msiaddr_hi;
+	u32 port_refclk;
+	u32 port_perst;
+	u32 port_rid2sid;
+	u32 port_msimap;
+	u32 max_rid2sid;
+};
+
+static const struct hw_info t8103_hw = {
+	.phy_lane_ctl		= PHY_LANE_CTL,
+	.port_msiaddr		= PORT_MSIADDR,
+	.port_msiaddr_hi	= 0,
+	.port_refclk		= PORT_REFCLK,
+	.port_perst		= PORT_PERST,
+	.port_rid2sid		= PORT_RID2SID,
+	.port_msimap		= 0,
+	.max_rid2sid		= 64,
+};
+
 struct apple_pcie {
 	struct mutex		lock;
 	struct device		*dev;
 	void __iomem            *base;
+	const struct hw_info	*hw;
 	struct irq_domain	*domain;
 	unsigned long		*bitmap;
 	struct list_head	ports;
@@ -380,7 +406,9 @@ static void apple_port_irq_handler(struct irq_desc *desc)
 static int apple_pcie_port_setup_irq(struct apple_pcie_port *port)
 {
 	struct fwnode_handle *fwnode = &port->np->fwnode;
+	struct apple_pcie *pcie = port->pcie;
 	unsigned int irq;
+	u32 val = 0;
 
 	/* FIXME: consider moving each interrupt under each port */
 	irq = irq_of_parse_and_map(to_of_node(dev_fwnode(port->pcie->dev)),
@@ -402,13 +430,23 @@ static int apple_pcie_port_setup_irq(struct apple_pcie_port *port)
 
 	/* Configure MSI base address */
 	BUILD_BUG_ON(upper_32_bits(DOORBELL_ADDR));
-	writel_relaxed(lower_32_bits(DOORBELL_ADDR), port->base + PORT_MSIADDR);
+	writel_relaxed(lower_32_bits(DOORBELL_ADDR),
+		       port->base + pcie->hw->port_msiaddr);
+	if (pcie->hw->port_msiaddr_hi)
+		writel_relaxed(0, port->base + pcie->hw->port_msiaddr_hi);
 
 	/* Enable MSIs, shared between all ports */
-	writel_relaxed(0, port->base + PORT_MSIBASE);
-	writel_relaxed((ilog2(port->pcie->nvecs) << PORT_MSICFG_L2MSINUM_SHIFT) |
-		       PORT_MSICFG_EN, port->base + PORT_MSICFG);
+	if (pcie->hw->port_msimap) {
+		for (int i = 0; i < pcie->nvecs; i++)
+			writel_relaxed(FIELD_PREP(PORT_MSIMAP_TARGET, i) |
+				       PORT_MSIMAP_ENABLE,
+				       port->base + pcie->hw->port_msimap + 4 * i);
+	} else {
+		writel_relaxed(0, port->base + PORT_MSIBASE);
+		val = ilog2(pcie->nvecs) << PORT_MSICFG_L2MSINUM_SHIFT;
+	}
 
+	writel_relaxed(val | PORT_MSICFG_EN, port->base + PORT_MSICFG);
 	return 0;
 }
 
@@ -475,7 +513,9 @@ static int apple_pcie_setup_refclk(struct apple_pcie *pcie,
 	u32 stat;
 	int res;
 
-	rmw_set(PHY_LANE_CTL_CFGACC, port->phy + PHY_LANE_CTL);
+	if (pcie->hw->phy_lane_ctl)
+		rmw_set(PHY_LANE_CTL_CFGACC, port->phy + pcie->hw->phy_lane_ctl);
+
 	rmw_set(PHY_LANE_CFG_REFCLK0REQ, port->phy + PHY_LANE_CFG);
 
 	res = readl_relaxed_poll_timeout(port->phy + PHY_LANE_CFG,
@@ -492,20 +532,28 @@ static int apple_pcie_setup_refclk(struct apple_pcie *pcie,
 	if (res < 0)
 		return res;
 
-	rmw_clear(PHY_LANE_CTL_CFGACC, port->phy + PHY_LANE_CTL);
+	if (pcie->hw->phy_lane_ctl)
+		rmw_clear(PHY_LANE_CTL_CFGACC, port->phy + pcie->hw->phy_lane_ctl);
 
 	rmw_set(PHY_LANE_CFG_REFCLKEN, port->phy + PHY_LANE_CFG);
-	rmw_set(PORT_REFCLK_EN, port->base + PORT_REFCLK);
+
+	if (pcie->hw->port_refclk)
+		rmw_set(PORT_REFCLK_EN, port->base + pcie->hw->port_refclk);
 
 	return 0;
 }
 
+static void __iomem *port_rid2sid_addr(struct apple_pcie_port *port, int idx)
+{
+	return port->base + port->pcie->hw->port_rid2sid + 4 * idx;
+}
+
 static u32 apple_pcie_rid2sid_write(struct apple_pcie_port *port,
 				    int idx, u32 val)
 {
-	writel_relaxed(val, port->base + PORT_RID2SID(idx));
+	writel_relaxed(val, port_rid2sid_addr(port, idx));
 	/* Read back to ensure completion of the write */
-	return readl_relaxed(port->base + PORT_RID2SID(idx));
+	return readl_relaxed(port_rid2sid_addr(port, idx));
 }
 
 static int apple_pcie_setup_port(struct apple_pcie *pcie,
@@ -528,7 +576,7 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie,
 	if (!port)
 		return -ENOMEM;
 
-	port->sid_map = devm_bitmap_zalloc(pcie->dev, MAX_RID2SID, GFP_KERNEL);
+	port->sid_map = devm_bitmap_zalloc(pcie->dev, pcie->hw->max_rid2sid, GFP_KERNEL);
 	if (!port->sid_map)
 		return -ENOMEM;
 
@@ -572,7 +620,7 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie,
 	usleep_range(100, 200);
 
 	/* Deassert PERST# */
-	rmw_set(PORT_PERST_OFF, port->base + PORT_PERST);
+	rmw_set(PORT_PERST_OFF, port->base + pcie->hw->port_perst);
 	gpiod_set_value_cansleep(reset, 0);
 
 	/* Wait for 100ms after PERST# deassertion (PCIe r5.0, 6.6.1) */
@@ -585,7 +633,11 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie,
 		return ret;
 	}
 
-	rmw_clear(PORT_REFCLK_CGDIS, port->base + PORT_REFCLK);
+	if (pcie->hw->port_refclk)
+		rmw_clear(PORT_REFCLK_CGDIS, port->base + pcie->hw->port_refclk);
+	else
+		rmw_set(PHY_LANE_CFG_REFCLKCGEN, port->phy + PHY_LANE_CFG);
+
 	rmw_clear(PORT_APPCLK_CGDIS, port->base + PORT_APPCLK);
 
 	ret = apple_pcie_port_setup_irq(port);
@@ -593,7 +645,7 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie,
 		return ret;
 
 	/* Reset all RID/SID mappings, and check for RAZ/WI registers */
-	for (i = 0; i < MAX_RID2SID; i++) {
+	for (i = 0; i < pcie->hw->max_rid2sid; i++) {
 		if (apple_pcie_rid2sid_write(port, i, 0xbad1d) != 0xbad1d)
 			break;
 		apple_pcie_rid2sid_write(port, i, 0);
@@ -741,7 +793,7 @@ static void apple_pcie_disable_device(struct pci_host_bridge *bridge, struct pci
 	for_each_set_bit(idx, port->sid_map, port->sid_map_sz) {
 		u32 val;
 
-		val = readl_relaxed(port->base + PORT_RID2SID(idx));
+		val = readl_relaxed(port_rid2sid_addr(port, idx));
 		if ((val & 0xffff) == rid) {
 			apple_pcie_rid2sid_write(port, idx, 0);
 			bitmap_release_region(port->sid_map, idx, 0);
@@ -794,6 +846,9 @@ static int apple_pcie_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	pcie->dev = dev;
+	pcie->hw = of_device_get_match_data(dev);
+	if (!pcie->hw)
+		return -ENODEV;
 	pcie->base = devm_platform_ioremap_resource(pdev, 1);
 	if (IS_ERR(pcie->base))
 		return PTR_ERR(pcie->base);
@@ -810,7 +865,7 @@ static int apple_pcie_probe(struct platform_device *pdev)
 }
 
 static const struct of_device_id apple_pcie_of_match[] = {
-	{ .compatible = "apple,pcie" },
+	{ .compatible = "apple,pcie",		.data = &t8103_hw },
 	{ }
 };
 MODULE_DEVICE_TABLE(of, apple_pcie_of_match);
Signature · 1 line
2.39.2
author maintainer
#19 lore raw

PATCH v2 13/13 PCI: apple: Add T602x PCIe support

In reply to Marc Zyngier

From: Hector Martin <[email protected]>

This version of the hardware moved around a bunch of registers, so we avoid the old compatible for these and introduce register offset structures to handle the differences.

---
 drivers/pci/controller/pcie-apple.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/pci/controller/pcie-apple.c +21 -0
index 847cba753d28d..5b85d9497070c 100644
@@ -124,6 +124,13 @@
 #define   PORT_TUNSTAT_PERST_ACK_PEND	BIT(1)
 #define PORT_PREFMEM_ENABLE		0x00994
 
+/* T602x (M2-pro and co) */
+#define PORT_T602X_MSIADDR	0x016c
+#define PORT_T602X_MSIADDR_HI	0x0170
+#define PORT_T602X_PERST	0x082c
+#define PORT_T602X_RID2SID	0x3000
+#define PORT_T602X_MSIMAP	0x3800
+
 #define PORT_MSIMAP_ENABLE	BIT(31)
 #define PORT_MSIMAP_TARGET	GENMASK(7, 0)
 
@@ -158,6 +165,18 @@ static const struct hw_info t8103_hw = {
 	.max_rid2sid		= 64,
 };
 
+static const struct hw_info t602x_hw = {
+	.phy_lane_ctl		= 0,
+	.port_msiaddr		= PORT_T602X_MSIADDR,
+	.port_msiaddr_hi	= PORT_T602X_MSIADDR_HI,
+	.port_refclk		= 0,
+	.port_perst		= PORT_T602X_PERST,
+	.port_rid2sid		= PORT_T602X_RID2SID,
+	.port_msimap		= PORT_T602X_MSIMAP,
+	/* 16 on t602x, guess for autodetect on future HW */
+	.max_rid2sid		= 512,
+};
+
 struct apple_pcie {
 	struct mutex		lock;
 	struct device		*dev;
@@ -425,6 +444,7 @@ static int apple_pcie_port_setup_irq(struct apple_pcie_port *port)
 	/* Disable all interrupts */
 	writel_relaxed(~0, port->base + PORT_INTMSK);
 	writel_relaxed(~0, port->base + PORT_INTSTAT);
+	writel_relaxed(~0, port->base + PORT_LINKCMDSTS);
 
 	irq_set_chained_handler_and_data(irq, apple_port_irq_handler, port);
 
@@ -865,6 +885,7 @@ static int apple_pcie_probe(struct platform_device *pdev)
 }
 
 static const struct of_device_id apple_pcie_of_match[] = {
+	{ .compatible = "apple,t6020-pcie",	.data = &t602x_hw },
 	{ .compatible = "apple,pcie",		.data = &t8103_hw },
 	{ }
 };
Signature · 1 line
2.39.2
#2 lore raw

Re: [PATCH v2 01/13] dt-bindings: pci: apple,pcie: Add t6020 compatible string

In reply to Marc Zyngier
Quoted 2 lines

From: Marc Zyngier <[email protected]>
Date: Tue, 25 Mar 2025 10:25:58 +0000

Hi Marc,

Sorry for not spotting this in the earlier versions, but:

Quoted 28 lines

From: Alyssa Rosenzweig <[email protected]>

t6020 adds some register ranges compared to t8103, so requires a new compatible as well as the new PHY registers themselves.

[maz: added PHY registers]
---
 Documentation/devicetree/bindings/pci/apple,pcie.yaml | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/pci/apple,pcie.yaml +4 -0
index c8775f9cb0713..77554899b9420 100644
@@ -17,6 +17,10 @@ description: |
   implements its root ports.  But the ATU found on most DesignWare
   PCIe host bridges is absent.
 
+  On systems derived from T602x, the PHY registers are in a region
+  separate from the port registers. In that case, there is one PHY
+  register range per port register range.
+
   All root ports share a single ECAM space, but separate GPIOs are
   used to take the PCI devices on those ports out of reset.  Therefore
   the standard "reset-gpios" and "max-link-speed" properties appear on

Documentation/devicetree/bindings/pci/apple,pcie.yaml properties: · line 43

Quoted 5 lines
Documentation/devicetree/bindings/pci/apple,pcie.yaml +1 -0
@@ -35,11 +39,12 @@ properties:
           - apple,t8103-pcie
           - apple,t8112-pcie
           - apple,t6000-pcie
+          - apple,t6020-pcie
       - const: apple,pcie

Since the T602x PCIe controller has a different register layout, it isn't compatible with the others, so it should not include the "apple,pcie" compatible. The "downstream" device trees for T602x-based devices do indeed not list "apple,pcie" as a compatible. So I think this needs to be written as:

compatible:
oneOf:
- items:
- enum:
- apple,t8103-pcie
- apple,t8112-pcie
- apple,t6000-pcie
- const: apple,pcie
- const: apple,t6020-pcie

Quoted 24 lines
Documentation/devicetree/bindings/pci/apple,pcie.yaml +5 -1
   reg:
     minItems: 3
-    maxItems: 6
+    maxItems: 10
 
   reg-names:
     minItems: 3
@@ -50,6 +55,10 @@ properties:
       - const: port1
       - const: port2
       - const: port3
+      - const: phy0
+      - const: phy1
+      - const: phy2
+      - const: phy3
 
   ranges:
     minItems: 2
Signature · 1 line
2.39.2
author maintainer
#3 lore raw

Re: [PATCH v2 01/13] dt-bindings: pci: apple,pcie: Add t6020 compatible string

Hi Mark,

Quoted 7 lines · Mark Kettenis
Quoted 3 lines

From: Marc Zyngier <[email protected]>
Date: Tue, 25 Mar 2025 10:25:58 +0000

Hi Marc,

Sorry for not spotting this in the earlier versions, but:

No worries -- I expected issues in that department.

Quoted 41 lines
Quoted 29 lines

From: Alyssa Rosenzweig <[email protected]>

t6020 adds some register ranges compared to t8103, so requires a new compatible as well as the new PHY registers themselves.

[maz: added PHY registers]
---
 Documentation/devicetree/bindings/pci/apple,pcie.yaml | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/pci/apple,pcie.yaml +4 -0
index c8775f9cb0713..77554899b9420 100644
@@ -17,6 +17,10 @@ description: |
   implements its root ports.  But the ATU found on most DesignWare
   PCIe host bridges is absent.
 
+  On systems derived from T602x, the PHY registers are in a region
+  separate from the port registers. In that case, there is one PHY
+  register range per port register range.
+
   All root ports share a single ECAM space, but separate GPIOs are
   used to take the PCI devices on those ports out of reset.  Therefore
   the standard "reset-gpios" and "max-link-speed" properties appear on

Documentation/devicetree/bindings/pci/apple,pcie.yaml properties: · line 43

Quoted 5 lines
Documentation/devicetree/bindings/pci/apple,pcie.yaml +1 -0
@@ -35,11 +39,12 @@ properties:
           - apple,t8103-pcie
           - apple,t8112-pcie
           - apple,t6000-pcie
+          - apple,t6020-pcie
       - const: apple,pcie

Since the T602x PCIe controller has a different register layout, it isn't compatible with the others, so it should not include the "apple,pcie" compatible. The "downstream" device trees for T602x-based devices do indeed not list "apple,pcie" as a compatible. So I think this needs to be written as:

Quoted 9 lines

compatible:
oneOf:
- items:
- enum:
- apple,t8103-pcie
- apple,t8112-pcie
- apple,t6000-pcie
- const: apple,pcie
- const: apple,t6020-pcie

Ah, indeed, that's a good point. Thanks for that.

Whilst I have your attention, how about my question below:

Quoted 7 lines
Quoted 7 lines
Documentation/devicetree/bindings/pci/apple,pcie.yaml +1 -1
   reg:
     minItems: 3
-    maxItems: 6
+    maxItems: 10
 
Quoted 10 lines

Documentation/devicetree/bindings/pci/apple,pcie.yaml properties: · line 61

Quoted 10 lines
Documentation/devicetree/bindings/pci/apple,pcie.yaml +4 -0
   reg-names:
     minItems: 3
@@ -50,6 +55,10 @@ properties:
       - const: port1
       - const: port2
       - const: port3
+      - const: phy0
+      - const: phy1
+      - const: phy2
+      - const: phy3

Do we need to make this t6020 specific?

Obviously, separate PHY registers do not make much sense before t6020, but I couldn't find a way to describe that. I don't even know if that's a desirable outcome.

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
maintainer
#14 lore raw

Re: [PATCH v2 08/13] PCI: apple: Set only available ports up

In reply to Marc Zyngier
Quoted 8 lines · Marc Zyngier

From: Janne Grunau <[email protected]>

Iterating over disabled ports results in of_irq_parse_raw() parsing the wrong "interrupt-map" entries, as it takes the status of the node into account.

Switching from for_each_child_of_node() to for_each_available_child_of_node() solves this issue.

I really wish "available" was the default iterator...

Quoted 8 lines

This became apparent after disabling unused PCIe ports in the Apple Silicon device trees instead of deleting them.

Fixes especially for stable should go first in the series.

Quoted 23 lines
---
 drivers/pci/controller/pcie-apple.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/pcie-apple.c +1 -1
index 6271533f1b042..23d9f62bd2ad4 100644
@@ -747,7 +747,7 @@ static int apple_pcie_init(struct pci_config_window *cfg)
 	struct device_node *of_port;
 	int ret;
 
-	for_each_child_of_node(dev->of_node, of_port) {
+	for_each_available_child_of_node(dev->of_node, of_port) {
 		ret = apple_pcie_setup_port(pcie, of_port);
 		if (ret) {
 			dev_err(dev, "Port %pOF setup fail: %d\n", of_port, ret);
Signature · 1 line
2.39.2
maintainer Reviewed-by on the v2 series
#20 lore raw
In reply to Marc Zyngier
Quoted 69 lines · Marc Zyngier

As Alyssa didn't have the bandwidth to deal with this series, I have taken it over. All bugs are therefore mine.

The initial series [1] stated:

"This series adds T6020 support to the Apple PCIe controller. Mostly
Apple shuffled registers around (presumably to accommodate the larger configurations on those machines). So there's a bit of churn here but not too much in the way of functional changes."

The biggest change is affecting the ECAM layer, allowing an ECAM driver to provide its own probe function instead of relying on the .init() callback to do the work. The ECAM layer can therefore be used as a library instead of a convoluted driver.

The rest is a mix of bug fixes, cleanups, and required abstraction.

This has been tested on T6020 (M2-Pro mini) and T8102 (M1 mini).

* From v1[1]:

- Described the PHY registers in the DT binding

- Extracted a ecam bridge creation helper from the host-common layer

- Moved probing into its own function instead of pci_host_common_probe()

- Moved host-specific data to the of_device_id[] table

- Added dynamic allocation of the RID/SID bitmap

- Fixed latent bug in RC-generated interrupts

- Renamed reg_info to hw_info

- Dropped useless max_msimap

- Dropped code being moved around without justification

- Re-split some of the patches to follow a more logical progression

- General cleanup to fit my own taste

[1] https://lore.kernel.org/r/[email protected]

Alyssa Rosenzweig (1):
dt-bindings: pci: apple,pcie: Add t6020 compatible string

Hector Martin (6):
PCI: apple: Fix missing OF node reference in apple_pcie_setup_port
PCI: apple: Move port PHY registers to their own reg items
PCI: apple: Drop poll for CORE_RC_PHYIF_STAT_REFCLK
PCI: apple: Use gpiod_set_value_cansleep in probe flow
PCI: apple: Abstract register offsets via a SoC-specific structure
PCI: apple: Add T602x PCIe support

Janne Grunau (1):
PCI: apple: Set only available ports up

Marc Zyngier (5):
PCI: host-generic: Extract an ecam bridge creation helper from
pci_host_common_probe()
PCI: ecam: Allow cfg->priv to be pre-populated from the root port
device
PCI: apple: Move over to standalone probing
PCI: apple: Dynamically allocate RID-to_SID bitmap
PCI: apple: Move away from INTMSK{SET,CLR} for INTx and private
interrupts

Quoted 6 lines
 .../devicetree/bindings/pci/apple,pcie.yaml   |  11 +-
 drivers/pci/controller/pci-host-common.c      |  24 +-
 drivers/pci/controller/pcie-apple.c           | 241 +++++++++++++-----
 drivers/pci/ecam.c                            |   2 +
 include/linux/pci-ecam.h                      |   2 +
 5 files changed, 204 insertions(+), 76 deletions(-)

For the series,

Acked-by on the v2 series
#21 lore raw
In reply to Marc Zyngier

Thanks maz!

Everything here looks good to me aside from the dt-bindings that I screwed up (sorry!). But I didn't do a thorough review.

Quoted 79 lines · Marc Zyngier

As Alyssa didn't have the bandwidth to deal with this series, I have taken it over. All bugs are therefore mine.

The initial series [1] stated:

"This series adds T6020 support to the Apple PCIe controller. Mostly
Apple shuffled registers around (presumably to accommodate the larger configurations on those machines). So there's a bit of churn here but not too much in the way of functional changes."

The biggest change is affecting the ECAM layer, allowing an ECAM driver to provide its own probe function instead of relying on the .init() callback to do the work. The ECAM layer can therefore be used as a library instead of a convoluted driver.

The rest is a mix of bug fixes, cleanups, and required abstraction.

This has been tested on T6020 (M2-Pro mini) and T8102 (M1 mini).

* From v1[1]:

- Described the PHY registers in the DT binding

- Extracted a ecam bridge creation helper from the host-common layer

- Moved probing into its own function instead of pci_host_common_probe()

- Moved host-specific data to the of_device_id[] table

- Added dynamic allocation of the RID/SID bitmap

- Fixed latent bug in RC-generated interrupts

- Renamed reg_info to hw_info

- Dropped useless max_msimap

- Dropped code being moved around without justification

- Re-split some of the patches to follow a more logical progression

- General cleanup to fit my own taste

[1] https://lore.kernel.org/r/[email protected]

Alyssa Rosenzweig (1):
dt-bindings: pci: apple,pcie: Add t6020 compatible string

Hector Martin (6):
PCI: apple: Fix missing OF node reference in apple_pcie_setup_port
PCI: apple: Move port PHY registers to their own reg items
PCI: apple: Drop poll for CORE_RC_PHYIF_STAT_REFCLK
PCI: apple: Use gpiod_set_value_cansleep in probe flow
PCI: apple: Abstract register offsets via a SoC-specific structure
PCI: apple: Add T602x PCIe support

Janne Grunau (1):
PCI: apple: Set only available ports up

Marc Zyngier (5):
PCI: host-generic: Extract an ecam bridge creation helper from
pci_host_common_probe()
PCI: ecam: Allow cfg->priv to be pre-populated from the root port
device
PCI: apple: Move over to standalone probing
PCI: apple: Dynamically allocate RID-to_SID bitmap
PCI: apple: Move away from INTMSK{SET,CLR} for INTx and private
interrupts

 .../devicetree/bindings/pci/apple,pcie.yaml   |  11 +-
 drivers/pci/controller/pci-host-common.c      |  24 +-
 drivers/pci/controller/pcie-apple.c           | 241 +++++++++++++-----
 drivers/pci/ecam.c                            |   2 +
 include/linux/pci-ecam.h                      |   2 +
 5 files changed, 204 insertions(+), 76 deletions(-)
Signature · 1 line
2.39.2
#4 lore raw

Re: [PATCH v2 01/13] dt-bindings: pci: apple,pcie: Add t6020 compatible string

In reply to Marc Zyngier
Quoted 2 lines

Date: Tue, 25 Mar 2025 11:02:30 +0000
From: Marc Zyngier <[email protected]>

Hi Marc,

Quoted 89 lines

Hi Mark,

Quoted 7 lines · Mark Kettenis
Quoted 3 lines

From: Marc Zyngier <[email protected]>
Date: Tue, 25 Mar 2025 10:25:58 +0000

Hi Marc,

Sorry for not spotting this in the earlier versions, but:

No worries -- I expected issues in that department.

Quoted 41 lines
Quoted 29 lines

From: Alyssa Rosenzweig <[email protected]>

t6020 adds some register ranges compared to t8103, so requires a new compatible as well as the new PHY registers themselves.

[maz: added PHY registers]
---
 Documentation/devicetree/bindings/pci/apple,pcie.yaml | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/pci/apple,pcie.yaml +4 -0
index c8775f9cb0713..77554899b9420 100644
@@ -17,6 +17,10 @@ description: |
   implements its root ports.  But the ATU found on most DesignWare
   PCIe host bridges is absent.
 
+  On systems derived from T602x, the PHY registers are in a region
+  separate from the port registers. In that case, there is one PHY
+  register range per port register range.
+
   All root ports share a single ECAM space, but separate GPIOs are
   used to take the PCI devices on those ports out of reset.  Therefore
   the standard "reset-gpios" and "max-link-speed" properties appear on

Documentation/devicetree/bindings/pci/apple,pcie.yaml properties: · line 43

Quoted 5 lines
Documentation/devicetree/bindings/pci/apple,pcie.yaml +1 -0
@@ -35,11 +39,12 @@ properties:
           - apple,t8103-pcie
           - apple,t8112-pcie
           - apple,t6000-pcie
+          - apple,t6020-pcie
       - const: apple,pcie

Since the T602x PCIe controller has a different register layout, it isn't compatible with the others, so it should not include the "apple,pcie" compatible. The "downstream" device trees for T602x-based devices do indeed not list "apple,pcie" as a compatible. So I think this needs to be written as:

Quoted 9 lines

compatible:
oneOf:
- items:
- enum:
- apple,t8103-pcie
- apple,t8112-pcie
- apple,t6000-pcie
- const: apple,pcie
- const: apple,t6020-pcie

Ah, indeed, that's a good point. Thanks for that.

Whilst I have your attention, how about my question below:

Quoted 7 lines
Quoted 7 lines
Documentation/devicetree/bindings/pci/apple,pcie.yaml +1 -1
   reg:
     minItems: 3
-    maxItems: 6
+    maxItems: 10
 
Quoted 10 lines

Documentation/devicetree/bindings/pci/apple,pcie.yaml properties: · line 61

Quoted 10 lines
Documentation/devicetree/bindings/pci/apple,pcie.yaml +4 -0
   reg-names:
     minItems: 3
@@ -50,6 +55,10 @@ properties:
       - const: port1
       - const: port2
       - const: port3
+      - const: phy0
+      - const: phy1
+      - const: phy2
+      - const: phy3

Do we need to make this t6020 specific?

Quoted 3 lines

Obviously, separate PHY registers do not make much sense before t6020, but I couldn't find a way to describe that. I don't even know if that's a desirable outcome.

I don't think there is a way to do that other than creating a separate binding for t6020. But I'm far from a dt-schema expert. Maybe robh has some advice here.

author maintainer
#5 lore raw

Re: [PATCH v2 01/13] dt-bindings: pci: apple,pcie: Add t6020 compatible string

Quoted 25 lines · Mark Kettenis
Quoted 3 lines

Date: Tue, 25 Mar 2025 11:02:30 +0000
From: Marc Zyngier <[email protected]>

Hi Marc,

Quoted 19 lines

Hi Mark,

Quoted 4 lines · Mark Kettenis
Quoted 3 lines

From: Marc Zyngier <[email protected]>
Date: Tue, 25 Mar 2025 10:25:58 +0000

Quoted 8 lines

Documentation/devicetree/bindings/pci/apple,pcie.yaml properties: · line 61

Quoted 8 lines
Documentation/devicetree/bindings/pci/apple,pcie.yaml +4 -0
@@ -50,6 +55,10 @@ properties:
       - const: port1
       - const: port2
       - const: port3
+      - const: phy0
+      - const: phy1
+      - const: phy2
+      - const: phy3

Do we need to make this t6020 specific?

Quoted 7 lines
Quoted 3 lines

Obviously, separate PHY registers do not make much sense before t6020, but I couldn't find a way to describe that. I don't even know if that's a desirable outcome.

I don't think there is a way to do that other than creating a separate binding for t6020. But I'm far from a dt-schema expert. Maybe robh has some advice here.

Huh, I'd rather not create another binding. The only thing this would buy us is a stricter checking of the register ranges. But it isn't like this block is going to find its way in random HW, and this is only described in a handful of core dtsi files anyway.

Unless someone screams (and provides a reasonable alternative), I will leave it as is.

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
maintainer
#6 lore raw

Re: [PATCH v2 01/13] dt-bindings: pci: apple,pcie: Add t6020 compatible string

Quoted 36 lines · Marc Zyngier
Quoted 25 lines · Mark Kettenis
Quoted 3 lines

Date: Tue, 25 Mar 2025 11:02:30 +0000
From: Marc Zyngier <[email protected]>

Hi Marc,

Quoted 19 lines

Hi Mark,

Quoted 4 lines · Mark Kettenis
Quoted 3 lines

From: Marc Zyngier <[email protected]>
Date: Tue, 25 Mar 2025 10:25:58 +0000

Quoted 8 lines

Documentation/devicetree/bindings/pci/apple,pcie.yaml properties: · line 61

Quoted 8 lines
Documentation/devicetree/bindings/pci/apple,pcie.yaml +4 -0
@@ -50,6 +55,10 @@ properties:
       - const: port1
       - const: port2
       - const: port3
+      - const: phy0
+      - const: phy1
+      - const: phy2
+      - const: phy3

Do we need to make this t6020 specific?

Quoted 7 lines
Quoted 3 lines

Obviously, separate PHY registers do not make much sense before t6020, but I couldn't find a way to describe that. I don't even know if that's a desirable outcome.

I don't think there is a way to do that other than creating a separate binding for t6020. But I'm far from a dt-schema expert. Maybe robh has some advice here.

Quoted 7 lines

Huh, I'd rather not create another binding. The only thing this would buy us is a stricter checking of the register ranges. But it isn't like this block is going to find its way in random HW, and this is only described in a handful of core dtsi files anyway.

Unless someone screams (and provides a reasonable alternative), I will leave it as is.

The simplest thing to do here is (under the 'allOf'):

if:
properties:

    compatible:
      contains:
        const: apple,t6020-pcie

then:
properties:
reg-names:
minItems: 10

If/when we start having different number of ports with phy entries, then it gets messy and each variant has to list out the names or we give up on defining the order.

Rob

maintainer Tested-by on the v2 series
#22 lore raw
In reply to Marc Zyngier
Quoted 69 lines · Marc Zyngier

As Alyssa didn't have the bandwidth to deal with this series, I have taken it over. All bugs are therefore mine.

The initial series [1] stated:

"This series adds T6020 support to the Apple PCIe controller. Mostly
Apple shuffled registers around (presumably to accommodate the larger configurations on those machines). So there's a bit of churn here but not too much in the way of functional changes."

The biggest change is affecting the ECAM layer, allowing an ECAM driver to provide its own probe function instead of relying on the .init() callback to do the work. The ECAM layer can therefore be used as a library instead of a convoluted driver.

The rest is a mix of bug fixes, cleanups, and required abstraction.

This has been tested on T6020 (M2-Pro mini) and T8102 (M1 mini).

* From v1[1]:

- Described the PHY registers in the DT binding

- Extracted a ecam bridge creation helper from the host-common layer

- Moved probing into its own function instead of pci_host_common_probe()

- Moved host-specific data to the of_device_id[] table

- Added dynamic allocation of the RID/SID bitmap

- Fixed latent bug in RC-generated interrupts

- Renamed reg_info to hw_info

- Dropped useless max_msimap

- Dropped code being moved around without justification

- Re-split some of the patches to follow a more logical progression

- General cleanup to fit my own taste

[1] https://lore.kernel.org/r/[email protected]

Alyssa Rosenzweig (1):
dt-bindings: pci: apple,pcie: Add t6020 compatible string

Hector Martin (6):
PCI: apple: Fix missing OF node reference in apple_pcie_setup_port
PCI: apple: Move port PHY registers to their own reg items
PCI: apple: Drop poll for CORE_RC_PHYIF_STAT_REFCLK
PCI: apple: Use gpiod_set_value_cansleep in probe flow
PCI: apple: Abstract register offsets via a SoC-specific structure
PCI: apple: Add T602x PCIe support

Janne Grunau (1):
PCI: apple: Set only available ports up

Marc Zyngier (5):
PCI: host-generic: Extract an ecam bridge creation helper from
pci_host_common_probe()
PCI: ecam: Allow cfg->priv to be pre-populated from the root port
device
PCI: apple: Move over to standalone probing
PCI: apple: Dynamically allocate RID-to_SID bitmap
PCI: apple: Move away from INTMSK{SET,CLR} for INTx and private
interrupts

Quoted 6 lines
 .../devicetree/bindings/pci/apple,pcie.yaml   |  11 +-
 drivers/pci/controller/pci-host-common.c      |  24 +-
 drivers/pci/controller/pcie-apple.c           | 241 +++++++++++++-----
 drivers/pci/ecam.c                            |   2 +
 include/linux/pci-ecam.h                      |   2 +
 5 files changed, 204 insertions(+), 76 deletions(-)

Whole series is

on t6020 and t8103 based Apple silicon devices.

ciao
Janne