LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v5 00/14] PCI: Add support for Apple M1
@ 2021-09-29 16:38 Marc Zyngier
  2021-09-29 16:38 ` [PATCH v5 01/14] irqdomain: Make of_phandle_args_to_fwspec generally available Marc Zyngier
                   ` (14 more replies)
  0 siblings, 15 replies; 32+ messages in thread
From: Marc Zyngier @ 2021-09-29 16:38 UTC (permalink / raw)
  To: devicetree, linux-kernel, linux-pci
  Cc: Bjorn Helgaas, Rob Herring, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Alyssa Rosenzweig, Stan Skowronek,
	Mark Kettenis, Sven Peter, Hector Martin, Robin Murphy,
	Joey Gouly, Joerg Roedel, kernel-team

This is v5 of the series adding PCIe support for the M1 SoC. Not a lot
has changed this time around, and most of what I was saying in [1] is
still valid.

Very little has changed code wise (a couple of bug fixes). The series
however now carries a bunch of DT updates so that people can actually
make use of PCIe on an M1 box (OK, not quite, you will still need [2],
or whatever version replaces it). The corresponding bindings are
either already merged, or queued for 5.16 (this is the case for the
PCI binding).

It all should be in a state that makes it mergeable (yeah, I said that
last time... I mean it this time! ;-).

As always, comments welcome.

	M.

[1] https://lore.kernel.org/r/20210922205458.358517-1-maz@kernel.org
[2] https://lore.kernel.org/r/20210921222956.40719-2-joey.gouly@arm.com

Alyssa Rosenzweig (2):
  PCI: apple: Add initial hardware bring-up
  PCI: apple: Set up reference clocks when probing

Marc Zyngier (10):
  irqdomain: Make of_phandle_args_to_fwspec generally available
  of/irq: Allow matching of an interrupt-map local to an interrupt
    controller
  PCI: of: Allow matching of an interrupt-map local to a PCI device
  PCI: apple: Add INTx and per-port interrupt support
  PCI: apple: Implement MSI support
  iommu/dart: Exclude MSI doorbell from PCIe device IOVA range
  PCI: apple: Configure RID to SID mapper on device addition
  arm64: dts: apple: t8103: Add PCIe DARTs
  arm64: dts: apple: t8103: Add root port interrupt routing
  arm64: dts: apple: j274: Expose PCI node for the Ethernet MAC address

Mark Kettenis (2):
  arm64: apple: Add pinctrl nodes
  arm64: apple: Add PCIe node

 MAINTAINERS                              |   7 +
 arch/arm64/boot/dts/apple/t8103-j274.dts |  23 +
 arch/arm64/boot/dts/apple/t8103.dtsi     | 203 ++++++
 drivers/iommu/apple-dart.c               |  27 +
 drivers/of/irq.c                         |  17 +-
 drivers/pci/controller/Kconfig           |  17 +
 drivers/pci/controller/Makefile          |   1 +
 drivers/pci/controller/pcie-apple.c      | 822 +++++++++++++++++++++++
 drivers/pci/of.c                         |  10 +-
 include/linux/irqdomain.h                |   4 +
 kernel/irq/irqdomain.c                   |   6 +-
 11 files changed, 1127 insertions(+), 10 deletions(-)
 create mode 100644 drivers/pci/controller/pcie-apple.c

-- 
2.30.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH v5 01/14] irqdomain: Make of_phandle_args_to_fwspec generally available
  2021-09-29 16:38 [PATCH v5 00/14] PCI: Add support for Apple M1 Marc Zyngier
@ 2021-09-29 16:38 ` Marc Zyngier
  2021-09-29 16:38 ` [PATCH v5 02/14] of/irq: Allow matching of an interrupt-map local to an interrupt controller Marc Zyngier
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 32+ messages in thread
From: Marc Zyngier @ 2021-09-29 16:38 UTC (permalink / raw)
  To: devicetree, linux-kernel, linux-pci
  Cc: Bjorn Helgaas, Rob Herring, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Alyssa Rosenzweig, Stan Skowronek,
	Mark Kettenis, Sven Peter, Hector Martin, Robin Murphy,
	Joey Gouly, Joerg Roedel, kernel-team

of_phandle_args_to_fwspec() can be generally useful to code
extracting a DT of_phandle and using an irq_fwspec to use the
hierarchical irqdomain API.

Make it visible the the rest of the kernel, including modules.

Tested-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
 include/linux/irqdomain.h | 4 ++++
 kernel/irq/irqdomain.c    | 6 +++---
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/include/linux/irqdomain.h b/include/linux/irqdomain.h
index 9ee238ad29ce..553da4899f55 100644
--- a/include/linux/irqdomain.h
+++ b/include/linux/irqdomain.h
@@ -64,6 +64,10 @@ struct irq_fwspec {
 	u32 param[IRQ_DOMAIN_IRQ_SPEC_PARAMS];
 };
 
+/* Conversion function from of_phandle_args fields to fwspec  */
+void of_phandle_args_to_fwspec(struct device_node *np, const u32 *args,
+			       unsigned int count, struct irq_fwspec *fwspec);
+
 /*
  * Should several domains have the same device node, but serve
  * different purposes (for example one domain is for PCI/MSI, and the
diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c
index 4d8fc65cf38f..e14adda218b7 100644
--- a/kernel/irq/irqdomain.c
+++ b/kernel/irq/irqdomain.c
@@ -744,9 +744,8 @@ static int irq_domain_translate(struct irq_domain *d,
 	return 0;
 }
 
-static void of_phandle_args_to_fwspec(struct device_node *np, const u32 *args,
-				      unsigned int count,
-				      struct irq_fwspec *fwspec)
+void of_phandle_args_to_fwspec(struct device_node *np, const u32 *args,
+			       unsigned int count, struct irq_fwspec *fwspec)
 {
 	int i;
 
@@ -756,6 +755,7 @@ static void of_phandle_args_to_fwspec(struct device_node *np, const u32 *args,
 	for (i = 0; i < count; i++)
 		fwspec->param[i] = args[i];
 }
+EXPORT_SYMBOL_GPL(of_phandle_args_to_fwspec);
 
 unsigned int irq_create_fwspec_mapping(struct irq_fwspec *fwspec)
 {
-- 
2.30.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH v5 02/14] of/irq: Allow matching of an interrupt-map local to an interrupt controller
  2021-09-29 16:38 [PATCH v5 00/14] PCI: Add support for Apple M1 Marc Zyngier
  2021-09-29 16:38 ` [PATCH v5 01/14] irqdomain: Make of_phandle_args_to_fwspec generally available Marc Zyngier
@ 2021-09-29 16:38 ` Marc Zyngier
  2021-09-29 16:38 ` [PATCH v5 03/14] PCI: of: Allow matching of an interrupt-map local to a PCI device Marc Zyngier
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 32+ messages in thread
From: Marc Zyngier @ 2021-09-29 16:38 UTC (permalink / raw)
  To: devicetree, linux-kernel, linux-pci
  Cc: Bjorn Helgaas, Rob Herring, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Alyssa Rosenzweig, Stan Skowronek,
	Mark Kettenis, Sven Peter, Hector Martin, Robin Murphy,
	Joey Gouly, Joerg Roedel, kernel-team, Rob Herring

of_irq_parse_raw() has a baked assumption that if a node has an
interrupt-controller property, it cannot possibly also have an
interrupt-map property (the latter being ignored).

This seems to be an odd behaviour, and there is no reason why
we should avoid supporting this use case. This is specially
useful when a PCI root port acts as an interrupt controller for
PCI endpoints, such as this:

pcie0: pcie@690000000 {
	[...]
	port00: pci@0,0 {
		device_type = "pci";
		[...]
		#address-cells = <3>;

		interrupt-controller;
		#interrupt-cells = <1>;

		interrupt-map-mask = <0 0 0 7>;
		interrupt-map = <0 0 0 1 &port00 0 0 0 0>,
				<0 0 0 2 &port00 0 0 0 1>,
				<0 0 0 3 &port00 0 0 0 2>,
				<0 0 0 4 &port00 0 0 0 3>;
	};
};

Handle it by detecting that we have an interrupt-map early in the
parsing, and special case the situation where the phandle in the
interrupt map refers to the current node (which is the interesting
case here).

Reviewed-by: Rob Herring <robh@kernel.org>
Tested-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
 drivers/of/irq.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/of/irq.c b/drivers/of/irq.c
index 352e14b007e7..32be5a03951f 100644
--- a/drivers/of/irq.c
+++ b/drivers/of/irq.c
@@ -156,10 +156,14 @@ int of_irq_parse_raw(const __be32 *addr, struct of_phandle_args *out_irq)
 
 	/* Now start the actual "proper" walk of the interrupt tree */
 	while (ipar != NULL) {
-		/* Now check if cursor is an interrupt-controller and if it is
-		 * then we are done
+		/*
+		 * Now check if cursor is an interrupt-controller and
+		 * if it is then we are done, unless there is an
+		 * interrupt-map which takes precedence.
 		 */
-		if (of_property_read_bool(ipar, "interrupt-controller")) {
+		imap = of_get_property(ipar, "interrupt-map", &imaplen);
+		if (imap == NULL &&
+		    of_property_read_bool(ipar, "interrupt-controller")) {
 			pr_debug(" -> got it !\n");
 			return 0;
 		}
@@ -173,8 +177,6 @@ int of_irq_parse_raw(const __be32 *addr, struct of_phandle_args *out_irq)
 			goto fail;
 		}
 
-		/* Now look for an interrupt-map */
-		imap = of_get_property(ipar, "interrupt-map", &imaplen);
 		/* No interrupt map, check for an interrupt parent */
 		if (imap == NULL) {
 			pr_debug(" -> no map, getting parent\n");
@@ -255,6 +257,11 @@ int of_irq_parse_raw(const __be32 *addr, struct of_phandle_args *out_irq)
 		out_irq->args_count = intsize = newintsize;
 		addrsize = newaddrsize;
 
+		if (ipar == newpar) {
+			pr_debug("%pOF interrupt-map entry to self\n", ipar);
+			return 0;
+		}
+
 	skiplevel:
 		/* Iterate again with new parent */
 		out_irq->np = newpar;
-- 
2.30.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH v5 03/14] PCI: of: Allow matching of an interrupt-map local to a PCI device
  2021-09-29 16:38 [PATCH v5 00/14] PCI: Add support for Apple M1 Marc Zyngier
  2021-09-29 16:38 ` [PATCH v5 01/14] irqdomain: Make of_phandle_args_to_fwspec generally available Marc Zyngier
  2021-09-29 16:38 ` [PATCH v5 02/14] of/irq: Allow matching of an interrupt-map local to an interrupt controller Marc Zyngier
@ 2021-09-29 16:38 ` Marc Zyngier
  2021-09-29 16:38 ` [PATCH v5 04/14] PCI: apple: Add initial hardware bring-up Marc Zyngier
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 32+ messages in thread
From: Marc Zyngier @ 2021-09-29 16:38 UTC (permalink / raw)
  To: devicetree, linux-kernel, linux-pci
  Cc: Bjorn Helgaas, Rob Herring, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Alyssa Rosenzweig, Stan Skowronek,
	Mark Kettenis, Sven Peter, Hector Martin, Robin Murphy,
	Joey Gouly, Joerg Roedel, kernel-team, Rob Herring

Just as we now allow an interrupt map to be parsed when part of an
interrupt controller, there is no reason to ignore an interrupt map that
would be part of a pci device node such as a root port since we already
allow interrupt specifiers.

Allow the matching of such property when local to the node of a PCI
device, which allows the device itself to use the interrupt map for for
its own purpose.

Reviewed-by: Rob Herring <robh@kernel.org>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Tested-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
 drivers/pci/of.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/of.c b/drivers/pci/of.c
index d84381ce82b5..0b1237cff239 100644
--- a/drivers/pci/of.c
+++ b/drivers/pci/of.c
@@ -423,7 +423,7 @@ static int devm_of_pci_get_host_bridge_resources(struct device *dev,
  */
 static int of_irq_parse_pci(const struct pci_dev *pdev, struct of_phandle_args *out_irq)
 {
-	struct device_node *dn, *ppnode;
+	struct device_node *dn, *ppnode = NULL;
 	struct pci_dev *ppdev;
 	__be32 laddr[3];
 	u8 pin;
@@ -452,8 +452,14 @@ static int of_irq_parse_pci(const struct pci_dev *pdev, struct of_phandle_args *
 	if (pin == 0)
 		return -ENODEV;
 
+	/* Local interrupt-map in the device node? Use it! */
+	if (of_get_property(dn, "interrupt-map", NULL)) {
+		pin = pci_swizzle_interrupt_pin(pdev, pin);
+		ppnode = dn;
+	}
+
 	/* Now we walk up the PCI tree */
-	for (;;) {
+	while (!ppnode) {
 		/* Get the pci_dev of our parent */
 		ppdev = pdev->bus->self;
 
-- 
2.30.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH v5 04/14] PCI: apple: Add initial hardware bring-up
  2021-09-29 16:38 [PATCH v5 00/14] PCI: Add support for Apple M1 Marc Zyngier
                   ` (2 preceding siblings ...)
  2021-09-29 16:38 ` [PATCH v5 03/14] PCI: of: Allow matching of an interrupt-map local to a PCI device Marc Zyngier
@ 2021-09-29 16:38 ` Marc Zyngier
  2021-09-29 16:38 ` [PATCH v5 05/14] PCI: apple: Set up reference clocks when probing Marc Zyngier
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 32+ messages in thread
From: Marc Zyngier @ 2021-09-29 16:38 UTC (permalink / raw)
  To: devicetree, linux-kernel, linux-pci
  Cc: Bjorn Helgaas, Rob Herring, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Alyssa Rosenzweig, Stan Skowronek,
	Mark Kettenis, Sven Peter, Hector Martin, Robin Murphy,
	Joey Gouly, Joerg Roedel, kernel-team, Rob Herring

From: Alyssa Rosenzweig <alyssa@rosenzweig.io>

Add a minimal driver to bring up the PCIe bus on Apple system-on-chips,
particularly the Apple M1. This driver exposes the internal bus used for
the USB type-A ports, Ethernet, Wi-Fi, and Bluetooth. Bringing up the
radios requires additional drivers beyond what's necessary for PCIe
itself.

At this stage, nothing is functionnal.

Reviewed-by: Rob Herring <robh@kernel.org>
Reviewed-by: Sven Peter <sven@svenpeter.dev>
Co-developed-by: Stan Skowronek <stan@corellium.com>
Signed-off-by: Stan Skowronek <stan@corellium.com>
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
 MAINTAINERS                         |   7 +
 drivers/pci/controller/Kconfig      |  12 ++
 drivers/pci/controller/Makefile     |   1 +
 drivers/pci/controller/pcie-apple.c | 237 ++++++++++++++++++++++++++++
 4 files changed, 257 insertions(+)
 create mode 100644 drivers/pci/controller/pcie-apple.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 5b33791bb8e9..5e8f773796e7 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1280,6 +1280,13 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/iommu/apple,dart.yaml
 F:	drivers/iommu/apple-dart.c
 
+APPLE PCIE CONTROLLER DRIVER
+M:	Alyssa Rosenzweig <alyssa@rosenzweig.io>
+M:	Marc Zyngier <maz@kernel.org>
+L:	linux-pci@vger.kernel.org
+S:	Maintained
+F:	drivers/pci/controller/pcie-apple.c
+
 APPLE SMC DRIVER
 M:	Henrik Rydberg <rydberg@bitmath.org>
 L:	linux-hwmon@vger.kernel.org
diff --git a/drivers/pci/controller/Kconfig b/drivers/pci/controller/Kconfig
index 326f7d13024f..814833a8120d 100644
--- a/drivers/pci/controller/Kconfig
+++ b/drivers/pci/controller/Kconfig
@@ -312,6 +312,18 @@ config PCIE_HISI_ERR
 	  Say Y here if you want error handling support
 	  for the PCIe controller's errors on HiSilicon HIP SoCs
 
+config PCIE_APPLE
+	tristate "Apple PCIe controller"
+	depends on ARCH_APPLE || COMPILE_TEST
+	depends on OF
+	depends on PCI_MSI_IRQ_DOMAIN
+	help
+	  Say Y here if you want to enable PCIe controller support on Apple
+	  system-on-chips, like the Apple M1. This is required for the USB
+	  type-A ports, Ethernet, Wi-Fi, and Bluetooth.
+
+	  If unsure, say Y if you have an Apple Silicon system.
+
 source "drivers/pci/controller/dwc/Kconfig"
 source "drivers/pci/controller/mobiveil/Kconfig"
 source "drivers/pci/controller/cadence/Kconfig"
diff --git a/drivers/pci/controller/Makefile b/drivers/pci/controller/Makefile
index aaf30b3dcc14..f9d40bad932c 100644
--- a/drivers/pci/controller/Makefile
+++ b/drivers/pci/controller/Makefile
@@ -37,6 +37,7 @@ obj-$(CONFIG_VMD) += vmd.o
 obj-$(CONFIG_PCIE_BRCMSTB) += pcie-brcmstb.o
 obj-$(CONFIG_PCI_LOONGSON) += pci-loongson.o
 obj-$(CONFIG_PCIE_HISI_ERR) += pcie-hisi-error.o
+obj-$(CONFIG_PCIE_APPLE) += pcie-apple.o
 # pcie-hisi.o quirks are needed even without CONFIG_PCIE_DW
 obj-y				+= dwc/
 obj-y				+= mobiveil/
diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c
new file mode 100644
index 000000000000..ba7b2949aaa4
--- /dev/null
+++ b/drivers/pci/controller/pcie-apple.c
@@ -0,0 +1,237 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * PCIe host bridge driver for Apple system-on-chips.
+ *
+ * The HW is ECAM compliant, so once the controller is initialized,
+ * the driver mostly deals MSI mapping and handling of per-port
+ * interrupts (INTx, management and error signals).
+ *
+ * Initialization requires enabling power and clocks, along with a
+ * number of register pokes.
+ *
+ * Copyright (C) 2021 Alyssa Rosenzweig <alyssa@rosenzweig.io>
+ * Copyright (C) 2021 Google LLC
+ * Copyright (C) 2021 Corellium LLC
+ * Copyright (C) 2021 Mark Kettenis <kettenis@openbsd.org>
+ *
+ * Author: Alyssa Rosenzweig <alyssa@rosenzweig.io>
+ * Author: Marc Zyngier <maz@kernel.org>
+ */
+
+#include <linux/gpio/consumer.h>
+#include <linux/kernel.h>
+#include <linux/iopoll.h>
+#include <linux/irqdomain.h>
+#include <linux/module.h>
+#include <linux/msi.h>
+#include <linux/of_irq.h>
+#include <linux/pci-ecam.h>
+
+#define CORE_RC_PHYIF_CTL		0x00024
+#define   CORE_RC_PHYIF_CTL_RUN		BIT(0)
+#define CORE_RC_PHYIF_STAT		0x00028
+#define   CORE_RC_PHYIF_STAT_REFCLK	BIT(4)
+#define CORE_RC_CTL			0x00050
+#define   CORE_RC_CTL_RUN		BIT(0)
+#define CORE_RC_STAT			0x00058
+#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_REFCLK1		BIT(1)
+#define   CORE_LANE_CFG_REFCLK0ACK	BIT(2)
+#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 PORT_LTSSMCTL			0x00080
+#define   PORT_LTSSMCTL_START		BIT(0)
+#define PORT_INTSTAT			0x00100
+#define   PORT_INT_TUNNEL_ERR		31
+#define   PORT_INT_CPL_TIMEOUT		23
+#define   PORT_INT_RID2SID_MAPERR	22
+#define   PORT_INT_CPL_ABORT		21
+#define   PORT_INT_MSI_BAD_DATA		19
+#define   PORT_INT_MSI_ERR		18
+#define   PORT_INT_REQADDR_GT32		17
+#define   PORT_INT_AF_TIMEOUT		15
+#define   PORT_INT_LINK_DOWN		14
+#define   PORT_INT_LINK_UP		12
+#define   PORT_INT_LINK_BWMGMT		11
+#define   PORT_INT_AER_MASK		(15 << 4)
+#define   PORT_INT_PORT_ERR		4
+#define   PORT_INT_INTx(i)		i
+#define   PORT_INT_INTx_MASK		15
+#define PORT_INTMSK			0x00104
+#define PORT_INTMSKSET			0x00108
+#define PORT_INTMSKCLR			0x0010c
+#define PORT_MSICFG			0x00124
+#define   PORT_MSICFG_EN		BIT(0)
+#define   PORT_MSICFG_L2MSINUM_SHIFT	4
+#define PORT_MSIBASE			0x00128
+#define   PORT_MSIBASE_1_SHIFT		16
+#define PORT_MSIADDR			0x00168
+#define PORT_LINKSTS			0x00208
+#define   PORT_LINKSTS_UP		BIT(0)
+#define   PORT_LINKSTS_BUSY		BIT(2)
+#define PORT_LINKCMDSTS			0x00210
+#define PORT_OUTS_NPREQS		0x00284
+#define   PORT_OUTS_NPREQS_REQ		BIT(24)
+#define   PORT_OUTS_NPREQS_CPL		BIT(16)
+#define PORT_RXWR_FIFO			0x00288
+#define   PORT_RXWR_FIFO_HDR		GENMASK(15, 10)
+#define   PORT_RXWR_FIFO_DATA		GENMASK(9, 0)
+#define PORT_RXRD_FIFO			0x0028C
+#define   PORT_RXRD_FIFO_REQ		GENMASK(6, 0)
+#define PORT_OUTS_CPLS			0x00290
+#define   PORT_OUTS_CPLS_SHRD		GENMASK(14, 8)
+#define   PORT_OUTS_CPLS_WAIT		GENMASK(6, 0)
+#define PORT_APPCLK			0x00800
+#define   PORT_APPCLK_EN		BIT(0)
+#define   PORT_APPCLK_CGDIS		BIT(8)
+#define PORT_STATUS			0x00804
+#define   PORT_STATUS_READY		BIT(0)
+#define PORT_REFCLK			0x00810
+#define   PORT_REFCLK_EN		BIT(0)
+#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_VALID		BIT(31)
+#define   PORT_RID2SID_SID_SHIFT	16
+#define   PORT_RID2SID_BUS_SHIFT	8
+#define   PORT_RID2SID_DEV_SHIFT	3
+#define   PORT_RID2SID_FUNC_SHIFT	0
+#define PORT_OUTS_PREQS_HDR		0x00980
+#define   PORT_OUTS_PREQS_HDR_MASK	GENMASK(9, 0)
+#define PORT_OUTS_PREQS_DATA		0x00984
+#define   PORT_OUTS_PREQS_DATA_MASK	GENMASK(15, 0)
+#define PORT_TUNCTRL			0x00988
+#define   PORT_TUNCTRL_PERST_ON		BIT(0)
+#define   PORT_TUNCTRL_PERST_ACK_REQ	BIT(1)
+#define PORT_TUNSTAT			0x0098c
+#define   PORT_TUNSTAT_PERST_ON		BIT(0)
+#define   PORT_TUNSTAT_PERST_ACK_PEND	BIT(1)
+#define PORT_PREFMEM_ENABLE		0x00994
+
+struct apple_pcie {
+	struct device		*dev;
+	void __iomem            *base;
+};
+
+struct apple_pcie_port {
+	struct apple_pcie	*pcie;
+	struct device_node	*np;
+	void __iomem		*base;
+	int			idx;
+};
+
+static void rmw_set(u32 set, void __iomem *addr)
+{
+	writel_relaxed(readl_relaxed(addr) | set, addr);
+}
+
+static int apple_pcie_setup_port(struct apple_pcie *pcie,
+				 struct device_node *np)
+{
+	struct platform_device *platform = to_platform_device(pcie->dev);
+	struct apple_pcie_port *port;
+	struct gpio_desc *reset;
+	u32 stat, idx;
+	int ret;
+
+	reset = gpiod_get_from_of_node(np, "reset-gpios", 0,
+				       GPIOD_OUT_LOW, "#PERST");
+	if (IS_ERR(reset))
+		return PTR_ERR(reset);
+
+	port = devm_kzalloc(pcie->dev, sizeof(*port), GFP_KERNEL);
+	if (!port)
+		return -ENOMEM;
+
+	ret = of_property_read_u32_index(np, "reg", 0, &idx);
+	if (ret)
+		return ret;
+
+	/* Use the first reg entry to work out the port index */
+	port->idx = idx >> 11;
+	port->pcie = pcie;
+	port->np = np;
+
+	port->base = devm_platform_ioremap_resource(platform, port->idx + 2);
+	if (IS_ERR(port->base))
+		return PTR_ERR(port->base);
+
+	rmw_set(PORT_APPCLK_EN, port->base + PORT_APPCLK);
+
+	rmw_set(PORT_PERST_OFF, port->base + PORT_PERST);
+	gpiod_set_value(reset, 1);
+
+	ret = readl_relaxed_poll_timeout(port->base + PORT_STATUS, stat,
+					 stat & PORT_STATUS_READY, 100, 250000);
+	if (ret < 0) {
+		dev_err(pcie->dev, "port %pOF ready wait timeout\n", np);
+		return ret;
+	}
+
+	writel_relaxed(PORT_LTSSMCTL_START, port->base + PORT_LTSSMCTL);
+
+	return 0;
+}
+
+static int apple_pcie_init(struct pci_config_window *cfg)
+{
+	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;
+
+	pcie->base = devm_platform_ioremap_resource(platform, 1);
+	if (IS_ERR(pcie->base))
+		return PTR_ERR(pcie->base);
+
+	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);
+			return ret;
+		}
+	}
+
+	return 0;
+}
+
+static const struct pci_ecam_ops apple_pcie_cfg_ecam_ops = {
+	.init		= apple_pcie_init,
+	.pci_ops	= {
+		.map_bus	= pci_ecam_map_bus,
+		.read		= pci_generic_config_read,
+		.write		= pci_generic_config_write,
+	}
+};
+
+static const struct of_device_id apple_pcie_of_match[] = {
+	{ .compatible = "apple,pcie", .data = &apple_pcie_cfg_ecam_ops },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, apple_pcie_of_match);
+
+static struct platform_driver apple_pcie_driver = {
+	.probe	= pci_host_common_probe,
+	.driver	= {
+		.name			= "pcie-apple",
+		.of_match_table		= apple_pcie_of_match,
+		.suppress_bind_attrs	= true,
+	},
+};
+module_platform_driver(apple_pcie_driver);
+
+MODULE_LICENSE("GPL v2");
-- 
2.30.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH v5 05/14] PCI: apple: Set up reference clocks when probing
  2021-09-29 16:38 [PATCH v5 00/14] PCI: Add support for Apple M1 Marc Zyngier
                   ` (3 preceding siblings ...)
  2021-09-29 16:38 ` [PATCH v5 04/14] PCI: apple: Add initial hardware bring-up Marc Zyngier
@ 2021-09-29 16:38 ` Marc Zyngier
  2021-09-29 16:38 ` [PATCH v5 06/14] PCI: apple: Add INTx and per-port interrupt support Marc Zyngier
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 32+ messages in thread
From: Marc Zyngier @ 2021-09-29 16:38 UTC (permalink / raw)
  To: devicetree, linux-kernel, linux-pci
  Cc: Bjorn Helgaas, Rob Herring, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Alyssa Rosenzweig, Stan Skowronek,
	Mark Kettenis, Sven Peter, Hector Martin, Robin Murphy,
	Joey Gouly, Joerg Roedel, kernel-team

From: Alyssa Rosenzweig <alyssa@rosenzweig.io>

Apple's PCIe controller requires clocks to be configured in order to
bring up the hardware. Add the register pokes required to do so.

Adapted from Corellium's driver via Mark Kettenis's U-Boot patches.

Co-developed-by: Stan Skowronek <stan@corellium.com>
Signed-off-by: Stan Skowronek <stan@corellium.com>
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
 drivers/pci/controller/pcie-apple.c | 46 +++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c
index ba7b2949aaa4..23390e5c54e9 100644
--- a/drivers/pci/controller/pcie-apple.c
+++ b/drivers/pci/controller/pcie-apple.c
@@ -132,6 +132,48 @@ static void rmw_set(u32 set, void __iomem *addr)
 	writel_relaxed(readl_relaxed(addr) | set, addr);
 }
 
+static void rmw_clear(u32 clr, void __iomem *addr)
+{
+	writel_relaxed(readl_relaxed(addr) & ~clr, addr);
+}
+
+static int apple_pcie_setup_refclk(struct apple_pcie *pcie,
+				   struct apple_pcie_port *port)
+{
+	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(CORE_LANE_CTL_CFGACC, pcie->base + CORE_LANE_CTL(port->idx));
+	rmw_set(CORE_LANE_CFG_REFCLK0REQ, pcie->base + CORE_LANE_CFG(port->idx));
+
+	res = readl_relaxed_poll_timeout(pcie->base + CORE_LANE_CFG(port->idx),
+					 stat, stat & CORE_LANE_CFG_REFCLK0ACK,
+					 100, 50000);
+	if (res < 0)
+		return res;
+
+	rmw_set(CORE_LANE_CFG_REFCLK1, pcie->base + CORE_LANE_CFG(port->idx));
+	res = readl_relaxed_poll_timeout(pcie->base + CORE_LANE_CFG(port->idx),
+					 stat, stat & CORE_LANE_CFG_REFCLK1,
+					 100, 50000);
+
+	if (res < 0)
+		return res;
+
+	rmw_clear(CORE_LANE_CTL_CFGACC, pcie->base + CORE_LANE_CTL(port->idx));
+
+	rmw_set(CORE_LANE_CFG_REFCLKEN, pcie->base + CORE_LANE_CFG(port->idx));
+	rmw_set(PORT_REFCLK_EN, port->base + PORT_REFCLK);
+
+	return 0;
+}
+
 static int apple_pcie_setup_port(struct apple_pcie *pcie,
 				 struct device_node *np)
 {
@@ -165,6 +207,10 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie,
 
 	rmw_set(PORT_APPCLK_EN, port->base + PORT_APPCLK);
 
+	ret = apple_pcie_setup_refclk(pcie, port);
+	if (ret < 0)
+		return ret;
+
 	rmw_set(PORT_PERST_OFF, port->base + PORT_PERST);
 	gpiod_set_value(reset, 1);
 
-- 
2.30.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH v5 06/14] PCI: apple: Add INTx and per-port interrupt support
  2021-09-29 16:38 [PATCH v5 00/14] PCI: Add support for Apple M1 Marc Zyngier
                   ` (4 preceding siblings ...)
  2021-09-29 16:38 ` [PATCH v5 05/14] PCI: apple: Set up reference clocks when probing Marc Zyngier
@ 2021-09-29 16:38 ` Marc Zyngier
  2021-09-29 16:38 ` [PATCH v5 07/14] PCI: apple: Implement MSI support Marc Zyngier
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 32+ messages in thread
From: Marc Zyngier @ 2021-09-29 16:38 UTC (permalink / raw)
  To: devicetree, linux-kernel, linux-pci
  Cc: Bjorn Helgaas, Rob Herring, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Alyssa Rosenzweig, Stan Skowronek,
	Mark Kettenis, Sven Peter, Hector Martin, Robin Murphy,
	Joey Gouly, Joerg Roedel, kernel-team

Add support for the per-port interrupt controller that deals
with both INTx signalling and management interrupts.

This allows the Link-up/Link-down interrupts to be wired, allowing
the bring-up to be synchronised (and provide debug information).
The framework can further be used to handle the rest of the per
port events if and when necessary.

Likewise, INTx signalling is implemented so that end-points can
actually be used.

Tested-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
 drivers/pci/controller/pcie-apple.c | 209 ++++++++++++++++++++++++++++
 1 file changed, 209 insertions(+)

diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c
index 23390e5c54e9..09544f0d166c 100644
--- a/drivers/pci/controller/pcie-apple.c
+++ b/drivers/pci/controller/pcie-apple.c
@@ -21,6 +21,7 @@
 #include <linux/gpio/consumer.h>
 #include <linux/kernel.h>
 #include <linux/iopoll.h>
+#include <linux/irqchip/chained_irq.h>
 #include <linux/irqdomain.h>
 #include <linux/module.h>
 #include <linux/msi.h>
@@ -118,12 +119,14 @@
 struct apple_pcie {
 	struct device		*dev;
 	void __iomem            *base;
+	struct completion	event;
 };
 
 struct apple_pcie_port {
 	struct apple_pcie	*pcie;
 	struct device_node	*np;
 	void __iomem		*base;
+	struct irq_domain	*domain;
 	int			idx;
 };
 
@@ -137,6 +140,200 @@ static void rmw_clear(u32 clr, void __iomem *addr)
 	writel_relaxed(readl_relaxed(addr) & ~clr, addr);
 }
 
+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);
+}
+
+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);
+}
+
+static bool hwirq_is_intx(unsigned int hwirq)
+{
+	return BIT(hwirq) & PORT_INT_INTx_MASK;
+}
+
+static void apple_port_irq_ack(struct irq_data *data)
+{
+	struct apple_pcie_port *port = irq_data_get_irq_chip_data(data);
+
+	if (!hwirq_is_intx(data->hwirq))
+		writel_relaxed(BIT(data->hwirq), port->base + PORT_INTSTAT);
+}
+
+static int apple_port_irq_set_type(struct irq_data *data, unsigned int type)
+{
+	/*
+	 * It doesn't seem that there is any way to configure the
+	 * trigger, so assume INTx have to be level (as per the spec),
+	 * and the rest is edge (which looks likely).
+	 */
+	if (hwirq_is_intx(data->hwirq) ^ !!(type & IRQ_TYPE_LEVEL_MASK))
+		return -EINVAL;
+
+	irqd_set_trigger_type(data, type);
+	return 0;
+}
+
+static struct irq_chip apple_port_irqchip = {
+	.name		= "PCIe",
+	.irq_ack	= apple_port_irq_ack,
+	.irq_mask	= apple_port_irq_mask,
+	.irq_unmask	= apple_port_irq_unmask,
+	.irq_set_type	= apple_port_irq_set_type,
+};
+
+static int apple_port_irq_domain_alloc(struct irq_domain *domain,
+				       unsigned int virq, unsigned int nr_irqs,
+				       void *args)
+{
+	struct apple_pcie_port *port = domain->host_data;
+	struct irq_fwspec *fwspec = args;
+	int i;
+
+	for (i = 0; i < nr_irqs; i++) {
+		irq_flow_handler_t flow = handle_edge_irq;
+		unsigned int type = IRQ_TYPE_EDGE_RISING;
+
+		if (hwirq_is_intx(fwspec->param[0] + i)) {
+			flow = handle_level_irq;
+			type = IRQ_TYPE_LEVEL_HIGH;
+		}
+
+		irq_domain_set_info(domain, virq + i, fwspec->param[0] + i,
+				    &apple_port_irqchip, port, flow,
+				    NULL, NULL);
+
+		irq_set_irq_type(virq + i, type);
+	}
+
+	return 0;
+}
+
+static void apple_port_irq_domain_free(struct irq_domain *domain,
+				       unsigned int virq, unsigned int nr_irqs)
+{
+	int i;
+
+	for (i = 0; i < nr_irqs; i++) {
+		struct irq_data *d = irq_domain_get_irq_data(domain, virq + i);
+		irq_set_handler(virq + i, NULL);
+		irq_domain_reset_irq_data(d);
+	}
+}
+
+static const struct irq_domain_ops apple_port_irq_domain_ops = {
+	.translate	= irq_domain_translate_onecell,
+	.alloc		= apple_port_irq_domain_alloc,
+	.free		= apple_port_irq_domain_free,
+};
+
+static void apple_port_irq_handler(struct irq_desc *desc)
+{
+	struct apple_pcie_port *port = irq_desc_get_handler_data(desc);
+	struct irq_chip *chip = irq_desc_get_chip(desc);
+	unsigned long stat;
+	int i;
+
+	chained_irq_enter(chip, desc);
+
+	stat = readl_relaxed(port->base + PORT_INTSTAT);
+
+	for_each_set_bit(i, &stat, 32)
+		generic_handle_domain_irq(port->domain, i);
+
+	chained_irq_exit(chip, desc);
+}
+
+static int apple_pcie_port_setup_irq(struct apple_pcie_port *port)
+{
+	struct fwnode_handle *fwnode = &port->np->fwnode;
+	unsigned int irq;
+
+	/* FIXME: consider moving each interrupt under each port */
+	irq = irq_of_parse_and_map(to_of_node(dev_fwnode(port->pcie->dev)),
+				   port->idx);
+	if (!irq)
+		return -ENXIO;
+
+	port->domain = irq_domain_create_linear(fwnode, 32,
+						&apple_port_irq_domain_ops,
+						port);
+	if (!port->domain)
+		return -ENOMEM;
+
+	/* Disable all interrupts */
+	writel_relaxed(~0, port->base + PORT_INTMSKSET);
+	writel_relaxed(~0, port->base + PORT_INTSTAT);
+
+	irq_set_chained_handler_and_data(irq, apple_port_irq_handler, port);
+
+	return 0;
+}
+
+static irqreturn_t apple_pcie_port_irq(int irq, void *data)
+{
+	struct apple_pcie_port *port = data;
+	unsigned int hwirq = irq_domain_get_irq_data(port->domain, irq)->hwirq;
+
+	switch (hwirq) {
+	case PORT_INT_LINK_UP:
+		dev_info_ratelimited(port->pcie->dev, "Link up on %pOF\n",
+				     port->np);
+		complete_all(&port->pcie->event);
+		break;
+	case PORT_INT_LINK_DOWN:
+		dev_info_ratelimited(port->pcie->dev, "Link down on %pOF\n",
+				     port->np);
+		break;
+	default:
+		return IRQ_NONE;
+	}
+
+	return IRQ_HANDLED;
+}
+
+static int apple_pcie_port_register_irqs(struct apple_pcie_port *port)
+{
+	static struct {
+		unsigned int	hwirq;
+		const char	*name;
+	} port_irqs[] = {
+		{ PORT_INT_LINK_UP,	"Link up",	},
+		{ PORT_INT_LINK_DOWN,	"Link down",	},
+	};
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(port_irqs); i++) {
+		struct irq_fwspec fwspec = {
+			.fwnode		= &port->np->fwnode,
+			.param_count	= 1,
+			.param		= {
+				[0]	= port_irqs[i].hwirq,
+			},
+		};
+		unsigned int irq;
+		int ret;
+
+		irq = irq_domain_alloc_irqs(port->domain, 1, NUMA_NO_NODE,
+					    &fwspec);
+		if (WARN_ON(!irq))
+			continue;
+
+		ret = request_irq(irq, apple_pcie_port_irq, 0,
+				  port_irqs[i].name, port);
+		WARN_ON(ret);
+	}
+
+	return 0;
+}
+
 static int apple_pcie_setup_refclk(struct apple_pcie *pcie,
 				   struct apple_pcie_port *port)
 {
@@ -221,8 +418,20 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie,
 		return ret;
 	}
 
+	ret = apple_pcie_port_setup_irq(port);
+	if (ret)
+		return ret;
+
+	init_completion(&pcie->event);
+
+	ret = apple_pcie_port_register_irqs(port);
+	WARN_ON(ret);
+
 	writel_relaxed(PORT_LTSSMCTL_START, port->base + PORT_LTSSMCTL);
 
+	if (!wait_for_completion_timeout(&pcie->event, HZ / 10))
+		dev_warn(pcie->dev, "%pOF link didn't come up\n", np);
+
 	return 0;
 }
 
-- 
2.30.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH v5 07/14] PCI: apple: Implement MSI support
  2021-09-29 16:38 [PATCH v5 00/14] PCI: Add support for Apple M1 Marc Zyngier
                   ` (5 preceding siblings ...)
  2021-09-29 16:38 ` [PATCH v5 06/14] PCI: apple: Add INTx and per-port interrupt support Marc Zyngier
@ 2021-09-29 16:38 ` Marc Zyngier
  2021-09-29 16:38 ` [PATCH v5 08/14] iommu/dart: Exclude MSI doorbell from PCIe device IOVA range Marc Zyngier
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 32+ messages in thread
From: Marc Zyngier @ 2021-09-29 16:38 UTC (permalink / raw)
  To: devicetree, linux-kernel, linux-pci
  Cc: Bjorn Helgaas, Rob Herring, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Alyssa Rosenzweig, Stan Skowronek,
	Mark Kettenis, Sven Peter, Hector Martin, Robin Murphy,
	Joey Gouly, Joerg Roedel, kernel-team

Probe for the 'msi-ranges' property, and implement the MSI
support in the form of the usual two-level hierarchy.

Note that contrary to the wired interrupts, MSIs are shared among
all the ports.

Tested-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
 drivers/pci/controller/pcie-apple.c | 169 +++++++++++++++++++++++++++-
 1 file changed, 168 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c
index 09544f0d166c..97af5d9f0bcb 100644
--- a/drivers/pci/controller/pcie-apple.c
+++ b/drivers/pci/controller/pcie-apple.c
@@ -116,10 +116,22 @@
 #define   PORT_TUNSTAT_PERST_ACK_PEND	BIT(1)
 #define PORT_PREFMEM_ENABLE		0x00994
 
+/*
+ * The doorbell address is set to 0xfffff000, which by convention
+ * matches what MacOS does, and it is possible to use any other
+ * address (in the bottom 4GB, as the base register is only 32bit).
+ */
+#define DOORBELL_ADDR			0xfffff000
+
 struct apple_pcie {
+	struct mutex		lock;
 	struct device		*dev;
 	void __iomem            *base;
+	struct irq_domain	*domain;
+	unsigned long		*bitmap;
 	struct completion	event;
+	struct irq_fwspec	fwspec;
+	u32			nvecs;
 };
 
 struct apple_pcie_port {
@@ -140,6 +152,101 @@ static void rmw_clear(u32 clr, void __iomem *addr)
 	writel_relaxed(readl_relaxed(addr) & ~clr, addr);
 }
 
+static void apple_msi_top_irq_mask(struct irq_data *d)
+{
+	pci_msi_mask_irq(d);
+	irq_chip_mask_parent(d);
+}
+
+static void apple_msi_top_irq_unmask(struct irq_data *d)
+{
+	pci_msi_unmask_irq(d);
+	irq_chip_unmask_parent(d);
+}
+
+static struct irq_chip apple_msi_top_chip = {
+	.name			= "PCIe MSI",
+	.irq_mask		= apple_msi_top_irq_mask,
+	.irq_unmask		= apple_msi_top_irq_unmask,
+	.irq_eoi		= irq_chip_eoi_parent,
+	.irq_set_affinity	= irq_chip_set_affinity_parent,
+	.irq_set_type		= irq_chip_set_type_parent,
+};
+
+static void apple_msi_compose_msg(struct irq_data *data, struct msi_msg *msg)
+{
+	msg->address_hi = upper_32_bits(DOORBELL_ADDR);
+	msg->address_lo = lower_32_bits(DOORBELL_ADDR);
+	msg->data = data->hwirq;
+}
+
+static struct irq_chip apple_msi_bottom_chip = {
+	.name			= "MSI",
+	.irq_mask		= irq_chip_mask_parent,
+	.irq_unmask		= irq_chip_unmask_parent,
+	.irq_eoi		= irq_chip_eoi_parent,
+	.irq_set_affinity	= irq_chip_set_affinity_parent,
+	.irq_set_type		= irq_chip_set_type_parent,
+	.irq_compose_msi_msg	= apple_msi_compose_msg,
+};
+
+static int apple_msi_domain_alloc(struct irq_domain *domain, unsigned int virq,
+				  unsigned int nr_irqs, void *args)
+{
+	struct apple_pcie *pcie = domain->host_data;
+	struct irq_fwspec fwspec = pcie->fwspec;
+	unsigned int i;
+	int ret, hwirq;
+
+	mutex_lock(&pcie->lock);
+
+	hwirq = bitmap_find_free_region(pcie->bitmap, pcie->nvecs,
+					order_base_2(nr_irqs));
+
+	mutex_unlock(&pcie->lock);
+
+	if (hwirq < 0)
+		return -ENOSPC;
+
+	fwspec.param[1] += hwirq;
+
+	ret = irq_domain_alloc_irqs_parent(domain, virq, nr_irqs, &fwspec);
+	if (ret)
+		return ret;
+
+	for (i = 0; i < nr_irqs; i++) {
+		irq_domain_set_hwirq_and_chip(domain, virq + i, hwirq + i,
+					      &apple_msi_bottom_chip,
+					      domain->host_data);
+	}
+
+	return 0;
+}
+
+static void apple_msi_domain_free(struct irq_domain *domain, unsigned int virq,
+				  unsigned int nr_irqs)
+{
+	struct irq_data *d = irq_domain_get_irq_data(domain, virq);
+	struct apple_pcie *pcie = domain->host_data;
+
+	mutex_lock(&pcie->lock);
+
+	bitmap_release_region(pcie->bitmap, d->hwirq, order_base_2(nr_irqs));
+
+	mutex_unlock(&pcie->lock);
+}
+
+static const struct irq_domain_ops apple_msi_domain_ops = {
+	.alloc	= apple_msi_domain_alloc,
+	.free	= apple_msi_domain_free,
+};
+
+static struct msi_domain_info apple_msi_info = {
+	.flags	= (MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS |
+		   MSI_FLAG_MULTI_PCI_MSI | MSI_FLAG_PCI_MSIX),
+	.chip	= &apple_msi_top_chip,
+};
+
 static void apple_port_irq_mask(struct irq_data *data)
 {
 	struct apple_pcie_port *port = irq_data_get_irq_chip_data(data);
@@ -274,6 +381,15 @@ static int apple_pcie_port_setup_irq(struct apple_pcie_port *port)
 
 	irq_set_chained_handler_and_data(irq, apple_port_irq_handler, port);
 
+	/* Configure MSI base address */
+	BUILD_BUG_ON(upper_32_bits(DOORBELL_ADDR));
+	writel_relaxed(lower_32_bits(DOORBELL_ADDR), port->base + PORT_MSIADDR);
+
+	/* 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);
+
 	return 0;
 }
 
@@ -435,6 +551,55 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie,
 	return 0;
 }
 
+static int apple_msi_init(struct apple_pcie *pcie)
+{
+	struct fwnode_handle *fwnode = dev_fwnode(pcie->dev);
+	struct of_phandle_args args = {};
+	struct irq_domain *parent;
+	int ret;
+
+	ret = of_parse_phandle_with_args(to_of_node(fwnode), "msi-ranges",
+					 "#interrupt-cells", 0, &args);
+	if (ret)
+		return ret;
+
+	ret = of_property_read_u32_index(to_of_node(fwnode), "msi-ranges",
+					 args.args_count + 1, &pcie->nvecs);
+	if (ret)
+		return ret;
+
+	of_phandle_args_to_fwspec(args.np, args.args, args.args_count,
+				  &pcie->fwspec);
+
+	pcie->bitmap = devm_bitmap_zalloc(pcie->dev, pcie->nvecs, GFP_KERNEL);
+	if (!pcie->bitmap)
+		return -ENOMEM;
+
+	parent = irq_find_matching_fwspec(&pcie->fwspec, DOMAIN_BUS_WIRED);
+	if (!parent) {
+		dev_err(pcie->dev, "failed to find parent domain\n");
+		return -ENXIO;
+	}
+
+	parent = irq_domain_create_hierarchy(parent, 0, pcie->nvecs, fwnode,
+					     &apple_msi_domain_ops, pcie);
+	if (!parent) {
+		dev_err(pcie->dev, "failed to create IRQ domain\n");
+		return -ENOMEM;
+	}
+	irq_domain_update_bus_token(parent, DOMAIN_BUS_NEXUS);
+
+	pcie->domain = pci_msi_create_irq_domain(fwnode, &apple_msi_info,
+						 parent);
+	if (!pcie->domain) {
+		dev_err(pcie->dev, "failed to create MSI domain\n");
+		irq_domain_remove(parent);
+		return -ENOMEM;
+	}
+
+	return 0;
+}
+
 static int apple_pcie_init(struct pci_config_window *cfg)
 {
 	struct device *dev = cfg->parent;
@@ -449,6 +614,8 @@ static int apple_pcie_init(struct pci_config_window *cfg)
 
 	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);
@@ -461,7 +628,7 @@ static int apple_pcie_init(struct pci_config_window *cfg)
 		}
 	}
 
-	return 0;
+	return apple_msi_init(pcie);
 }
 
 static const struct pci_ecam_ops apple_pcie_cfg_ecam_ops = {
-- 
2.30.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH v5 08/14] iommu/dart: Exclude MSI doorbell from PCIe device IOVA range
  2021-09-29 16:38 [PATCH v5 00/14] PCI: Add support for Apple M1 Marc Zyngier
                   ` (6 preceding siblings ...)
  2021-09-29 16:38 ` [PATCH v5 07/14] PCI: apple: Implement MSI support Marc Zyngier
@ 2021-09-29 16:38 ` Marc Zyngier
  2021-09-29 16:38 ` [PATCH v5 09/14] PCI: apple: Configure RID to SID mapper on device addition Marc Zyngier
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 32+ messages in thread
From: Marc Zyngier @ 2021-09-29 16:38 UTC (permalink / raw)
  To: devicetree, linux-kernel, linux-pci
  Cc: Bjorn Helgaas, Rob Herring, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Alyssa Rosenzweig, Stan Skowronek,
	Mark Kettenis, Sven Peter, Hector Martin, Robin Murphy,
	Joey Gouly, Joerg Roedel, kernel-team

The MSI doorbell on Apple HW can be any address in the low 4GB
range. However, the MSI write is matched by the PCIe block before
hitting the iommu. It must thus be excluded from the IOVA range
that is assigned to any PCIe device.

Reviewed-by: Sven Peter <sven@svenpeter.dev>
Tested-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
 drivers/iommu/apple-dart.c          | 27 +++++++++++++++++++++++++++
 drivers/pci/controller/Kconfig      |  5 +++++
 drivers/pci/controller/pcie-apple.c |  4 +++-
 3 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c
index 559db9259e65..f1f1f024c604 100644
--- a/drivers/iommu/apple-dart.c
+++ b/drivers/iommu/apple-dart.c
@@ -721,6 +721,31 @@ static int apple_dart_def_domain_type(struct device *dev)
 	return 0;
 }
 
+#ifndef CONFIG_PCIE_APPLE_MSI_DOORBELL_ADDR
+/* Keep things compiling when CONFIG_PCI_APPLE isn't selected */
+#define CONFIG_PCIE_APPLE_MSI_DOORBELL_ADDR	0
+#endif
+#define DOORBELL_ADDR	(CONFIG_PCIE_APPLE_MSI_DOORBELL_ADDR & PAGE_MASK)
+
+static void apple_dart_get_resv_regions(struct device *dev,
+					struct list_head *head)
+{
+	if (IS_ENABLED(CONFIG_PCIE_APPLE) && dev_is_pci(dev)) {
+		struct iommu_resv_region *region;
+		int prot = IOMMU_WRITE | IOMMU_NOEXEC | IOMMU_MMIO;
+
+		region = iommu_alloc_resv_region(DOORBELL_ADDR,
+						 PAGE_SIZE, prot,
+						 IOMMU_RESV_MSI);
+		if (!region)
+			return;
+
+		list_add_tail(&region->list, head);
+	}
+
+	iommu_dma_get_resv_regions(dev, head);
+}
+
 static const struct iommu_ops apple_dart_iommu_ops = {
 	.domain_alloc = apple_dart_domain_alloc,
 	.domain_free = apple_dart_domain_free,
@@ -737,6 +762,8 @@ static const struct iommu_ops apple_dart_iommu_ops = {
 	.device_group = apple_dart_device_group,
 	.of_xlate = apple_dart_of_xlate,
 	.def_domain_type = apple_dart_def_domain_type,
+	.get_resv_regions = apple_dart_get_resv_regions,
+	.put_resv_regions = generic_iommu_put_resv_regions,
 	.pgsize_bitmap = -1UL, /* Restricted during dart probe */
 };
 
diff --git a/drivers/pci/controller/Kconfig b/drivers/pci/controller/Kconfig
index 814833a8120d..b6e7410da254 100644
--- a/drivers/pci/controller/Kconfig
+++ b/drivers/pci/controller/Kconfig
@@ -312,6 +312,11 @@ config PCIE_HISI_ERR
 	  Say Y here if you want error handling support
 	  for the PCIe controller's errors on HiSilicon HIP SoCs
 
+config PCIE_APPLE_MSI_DOORBELL_ADDR
+	hex
+	default 0xfffff000
+	depends on PCIE_APPLE
+
 config PCIE_APPLE
 	tristate "Apple PCIe controller"
 	depends on ARCH_APPLE || COMPILE_TEST
diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c
index 97af5d9f0bcb..a27dd93217f5 100644
--- a/drivers/pci/controller/pcie-apple.c
+++ b/drivers/pci/controller/pcie-apple.c
@@ -120,8 +120,10 @@
  * The doorbell address is set to 0xfffff000, which by convention
  * matches what MacOS does, and it is possible to use any other
  * address (in the bottom 4GB, as the base register is only 32bit).
+ * However, it has to be excluded from the the IOVA range, and the
+ * DART driver has to know about it.
  */
-#define DOORBELL_ADDR			0xfffff000
+#define DOORBELL_ADDR		CONFIG_PCIE_APPLE_MSI_DOORBELL_ADDR
 
 struct apple_pcie {
 	struct mutex		lock;
-- 
2.30.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH v5 09/14] PCI: apple: Configure RID to SID mapper on device addition
  2021-09-29 16:38 [PATCH v5 00/14] PCI: Add support for Apple M1 Marc Zyngier
                   ` (7 preceding siblings ...)
  2021-09-29 16:38 ` [PATCH v5 08/14] iommu/dart: Exclude MSI doorbell from PCIe device IOVA range Marc Zyngier
@ 2021-09-29 16:38 ` Marc Zyngier
  2021-09-29 16:38 ` [PATCH v5 10/14] arm64: apple: Add pinctrl nodes Marc Zyngier
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 32+ messages in thread
From: Marc Zyngier @ 2021-09-29 16:38 UTC (permalink / raw)
  To: devicetree, linux-kernel, linux-pci
  Cc: Bjorn Helgaas, Rob Herring, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Alyssa Rosenzweig, Stan Skowronek,
	Mark Kettenis, Sven Peter, Hector Martin, Robin Murphy,
	Joey Gouly, Joerg Roedel, kernel-team

The Apple PCIe controller doesn't directly feed the endpoint's
Requester ID to the IOMMU (DART), but instead maps RIDs onto
Stream IDs (SIDs). The DART and the PCIe controller must thus
agree on the SIDs that are used for translation (by using
the 'iommu-map' property).

For this purpose, parse the 'iommu-map' property each time a
device gets added, and use the resulting translation to configure
the PCIe RID-to-SID mapper. Similarily, remove the translation
if/when the device gets removed.

This is all driven from a bus notifier which gets registered at
probe time. Hopefully this is the only PCI controller driver
in the whole system.

Reviewed-by: Sven Peter <sven@svenpeter.dev>
Tested-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
 drivers/pci/controller/pcie-apple.c | 165 +++++++++++++++++++++++++++-
 1 file changed, 163 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c
index a27dd93217f5..b4db7a065553 100644
--- a/drivers/pci/controller/pcie-apple.c
+++ b/drivers/pci/controller/pcie-apple.c
@@ -23,8 +23,10 @@
 #include <linux/iopoll.h>
 #include <linux/irqchip/chained_irq.h>
 #include <linux/irqdomain.h>
+#include <linux/list.h>
 #include <linux/module.h>
 #include <linux/msi.h>
+#include <linux/notifier.h>
 #include <linux/of_irq.h>
 #include <linux/pci-ecam.h>
 
@@ -116,6 +118,8 @@
 #define   PORT_TUNSTAT_PERST_ACK_PEND	BIT(1)
 #define PORT_PREFMEM_ENABLE		0x00994
 
+#define MAX_RID2SID			64
+
 /*
  * The doorbell address is set to 0xfffff000, which by convention
  * matches what MacOS does, and it is possible to use any other
@@ -131,6 +135,7 @@ struct apple_pcie {
 	void __iomem            *base;
 	struct irq_domain	*domain;
 	unsigned long		*bitmap;
+	struct list_head	ports;
 	struct completion	event;
 	struct irq_fwspec	fwspec;
 	u32			nvecs;
@@ -141,6 +146,9 @@ struct apple_pcie_port {
 	struct device_node	*np;
 	void __iomem		*base;
 	struct irq_domain	*domain;
+	struct list_head	entry;
+	DECLARE_BITMAP(		sid_map, MAX_RID2SID);
+	int			sid_map_sz;
 	int			idx;
 };
 
@@ -489,6 +497,14 @@ static int apple_pcie_setup_refclk(struct apple_pcie *pcie,
 	return 0;
 }
 
+static u32 apple_pcie_rid2sid_write(struct apple_pcie_port *port,
+				    int idx, u32 val)
+{
+	writel_relaxed(val, port->base + PORT_RID2SID(idx));
+	/* Read back to ensure completion of the write */
+	return readl_relaxed(port->base + PORT_RID2SID(idx));
+}
+
 static int apple_pcie_setup_port(struct apple_pcie *pcie,
 				 struct device_node *np)
 {
@@ -496,7 +512,7 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie,
 	struct apple_pcie_port *port;
 	struct gpio_desc *reset;
 	u32 stat, idx;
-	int ret;
+	int ret, i;
 
 	reset = gpiod_get_from_of_node(np, "reset-gpios", 0,
 				       GPIOD_OUT_LOW, "#PERST");
@@ -540,6 +556,18 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie,
 	if (ret)
 		return ret;
 
+	/* Reset all RID/SID mappings, and check for RAZ/WI registers */
+	for (i = 0; i < MAX_RID2SID; i++) {
+		if (apple_pcie_rid2sid_write(port, i, 0xbad1d) != 0xbad1d)
+			break;
+		apple_pcie_rid2sid_write(port, i, 0);
+	}
+
+	dev_dbg(pcie->dev, "%pOF: %d RID/SID mapping entries\n", np, i);
+
+	port->sid_map_sz = i;
+
+	list_add_tail(&port->entry, &pcie->ports);
 	init_completion(&pcie->event);
 
 	ret = apple_pcie_port_register_irqs(port);
@@ -602,6 +630,121 @@ static int apple_msi_init(struct apple_pcie *pcie)
 	return 0;
 }
 
+static struct apple_pcie_port *apple_pcie_get_port(struct pci_dev *pdev)
+{
+	struct pci_config_window *cfg = pdev->sysdata;
+	struct apple_pcie *pcie = cfg->priv;
+	struct pci_dev *port_pdev = pdev;
+	struct apple_pcie_port *port;
+
+	/* Find the root port this device is on */
+	port_pdev = pcie_find_root_port(pdev);
+
+	/* If finding the port itself, nothing to do */
+	if (WARN_ON(!port_pdev) || pdev == port_pdev)
+		return NULL;
+
+	list_for_each_entry(port, &pcie->ports, entry) {
+		if (port->idx == PCI_SLOT(port_pdev->devfn))
+			return port;
+	}
+
+	return NULL;
+}
+
+static int apple_pcie_add_device(struct apple_pcie_port *port,
+				 struct pci_dev *pdev)
+{
+	u32 sid, rid = PCI_DEVID(pdev->bus->number, pdev->devfn);
+	int idx, err;
+
+	dev_dbg(&pdev->dev, "added to bus %s, index %d\n",
+		pci_name(pdev->bus->self), port->idx);
+
+	err = of_map_id(port->pcie->dev->of_node, rid, "iommu-map",
+			"iommu-map-mask", NULL, &sid);
+	if (err)
+		return err;
+
+	mutex_lock(&port->pcie->lock);
+
+	idx = bitmap_find_free_region(port->sid_map, port->sid_map_sz, 0);
+	if (idx >= 0) {
+		apple_pcie_rid2sid_write(port, idx,
+					 PORT_RID2SID_VALID |
+					 (sid << PORT_RID2SID_SID_SHIFT) | rid);
+
+		dev_dbg(&pdev->dev, "mapping RID%x to SID%x (index %d)\n",
+			rid, sid, idx);
+	}
+
+	mutex_unlock(&port->pcie->lock);
+
+	return idx >= 0 ? 0 : -ENOSPC;
+}
+
+static void apple_pcie_release_device(struct apple_pcie_port *port,
+				      struct pci_dev *pdev)
+{
+	u32 rid = PCI_DEVID(pdev->bus->number, pdev->devfn);
+	int idx;
+
+	mutex_lock(&port->pcie->lock);
+
+	for_each_set_bit(idx, port->sid_map, port->sid_map_sz) {
+		u32 val;
+
+		val = readl_relaxed(port->base + PORT_RID2SID(idx));
+		if ((val & 0xffff) == rid) {
+			apple_pcie_rid2sid_write(port, idx, 0);
+			bitmap_release_region(port->sid_map, idx, 0);
+			dev_dbg(&pdev->dev, "Released %x (%d)\n", val, idx);
+			break;
+		}
+	}
+
+	mutex_unlock(&port->pcie->lock);
+}
+
+static int apple_pcie_bus_notifier(struct notifier_block *nb,
+				   unsigned long action,
+				   void *data)
+{
+	struct device *dev = data;
+	struct pci_dev *pdev = to_pci_dev(dev);
+	struct apple_pcie_port *port;
+	int err;
+
+	/*
+	 * This is a bit ugly. We assume that if we get notified for
+	 * any PCI device, we must be in charge of it, and that there
+	 * is no other PCI controller in the whole system. It probably
+	 * holds for now, but who knows for how long?
+	 */
+	port = apple_pcie_get_port(pdev);
+	if (!port)
+		return NOTIFY_DONE;
+
+	switch (action) {
+	case BUS_NOTIFY_ADD_DEVICE:
+		err = apple_pcie_add_device(port, pdev);
+		if (err)
+			return notifier_from_errno(err);
+		break;
+	case BUS_NOTIFY_DEL_DEVICE:
+		apple_pcie_release_device(port, pdev);
+		break;
+	default:
+		return NOTIFY_DONE;
+	}
+
+	return NOTIFY_OK;
+}
+
+static struct notifier_block apple_pcie_nb = {
+	.notifier_call = apple_pcie_bus_notifier,
+};
+
 static int apple_pcie_init(struct pci_config_window *cfg)
 {
 	struct device *dev = cfg->parent;
@@ -622,6 +765,9 @@ static int apple_pcie_init(struct pci_config_window *cfg)
 	if (IS_ERR(pcie->base))
 		return PTR_ERR(pcie->base);
 
+	cfg->priv = pcie;
+	INIT_LIST_HEAD(&pcie->ports);
+
 	for_each_child_of_node(dev->of_node, of_port) {
 		ret = apple_pcie_setup_port(pcie, of_port);
 		if (ret) {
@@ -633,6 +779,21 @@ static int apple_pcie_init(struct pci_config_window *cfg)
 	return apple_msi_init(pcie);
 }
 
+static int apple_pcie_probe(struct platform_device *pdev)
+{
+	int ret;
+
+	ret = bus_register_notifier(&pci_bus_type, &apple_pcie_nb);
+	if (ret)
+		return ret;
+
+	ret = pci_host_common_probe(pdev);
+	if (ret)
+		bus_unregister_notifier(&pci_bus_type, &apple_pcie_nb);
+
+	return ret;
+}
+
 static const struct pci_ecam_ops apple_pcie_cfg_ecam_ops = {
 	.init		= apple_pcie_init,
 	.pci_ops	= {
@@ -649,7 +810,7 @@ static const struct of_device_id apple_pcie_of_match[] = {
 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,
-- 
2.30.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH v5 10/14] arm64: apple: Add pinctrl nodes
  2021-09-29 16:38 [PATCH v5 00/14] PCI: Add support for Apple M1 Marc Zyngier
                   ` (8 preceding siblings ...)
  2021-09-29 16:38 ` [PATCH v5 09/14] PCI: apple: Configure RID to SID mapper on device addition Marc Zyngier
@ 2021-09-29 16:38 ` Marc Zyngier
  2021-09-29 19:05   ` Linus Walleij
  2021-10-07 16:00   ` Hector Martin
  2021-09-29 16:38 ` [PATCH v5 11/14] arm64: apple: Add PCIe node Marc Zyngier
                   ` (4 subsequent siblings)
  14 siblings, 2 replies; 32+ messages in thread
From: Marc Zyngier @ 2021-09-29 16:38 UTC (permalink / raw)
  To: devicetree, linux-kernel, linux-pci
  Cc: Bjorn Helgaas, Rob Herring, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Alyssa Rosenzweig, Stan Skowronek,
	Mark Kettenis, Sven Peter, Hector Martin, Robin Murphy,
	Joey Gouly, Joerg Roedel, kernel-team, Linus Walleij

From: Mark Kettenis <kettenis@openbsd.org>

Add pinctrl nodes corresponding to the gpio,t8101 nodes in the
Apple device tree for the Mac mini (M1, 2020).

Clock references are left out at the moment and will be added once
the appropriate bindings have been settled upon.

Signed-off-by: Mark Kettenis <kettenis@openbsd.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20210520171310.772-3-mark.kettenis@xs4all.nl
---
 arch/arm64/boot/dts/apple/t8103.dtsi | 83 ++++++++++++++++++++++++++++
 1 file changed, 83 insertions(+)

diff --git a/arch/arm64/boot/dts/apple/t8103.dtsi b/arch/arm64/boot/dts/apple/t8103.dtsi
index a1e22a2ea2e5..503a76fc30e6 100644
--- a/arch/arm64/boot/dts/apple/t8103.dtsi
+++ b/arch/arm64/boot/dts/apple/t8103.dtsi
@@ -9,6 +9,7 @@
 
 #include <dt-bindings/interrupt-controller/apple-aic.h>
 #include <dt-bindings/interrupt-controller/irq.h>
+#include <dt-bindings/pinctrl/apple.h>
 
 / {
 	compatible = "apple,t8103", "apple,arm-platform";
@@ -131,5 +132,87 @@ aic: interrupt-controller@23b100000 {
 			interrupt-controller;
 			reg = <0x2 0x3b100000 0x0 0x8000>;
 		};
+
+		pinctrl_ap: pinctrl@23c100000 {
+			compatible = "apple,t8103-pinctrl", "apple,pinctrl";
+			reg = <0x2 0x3c100000 0x0 0x100000>;
+
+			gpio-controller;
+			#gpio-cells = <2>;
+			gpio-ranges = <&pinctrl_ap 0 0 212>;
+
+			interrupt-controller;
+			interrupt-parent = <&aic>;
+			interrupts = <AIC_IRQ 190 IRQ_TYPE_LEVEL_HIGH>,
+				     <AIC_IRQ 191 IRQ_TYPE_LEVEL_HIGH>,
+				     <AIC_IRQ 192 IRQ_TYPE_LEVEL_HIGH>,
+				     <AIC_IRQ 193 IRQ_TYPE_LEVEL_HIGH>,
+				     <AIC_IRQ 194 IRQ_TYPE_LEVEL_HIGH>,
+				     <AIC_IRQ 195 IRQ_TYPE_LEVEL_HIGH>,
+				     <AIC_IRQ 196 IRQ_TYPE_LEVEL_HIGH>;
+
+			pcie_pins: pcie-pins {
+				pinmux = <APPLE_PINMUX(150, 1)>,
+					 <APPLE_PINMUX(151, 1)>,
+					 <APPLE_PINMUX(32, 1)>;
+			};
+		};
+
+		pinctrl_aop: pinctrl@24a820000 {
+			compatible = "apple,t8103-pinctrl", "apple,pinctrl";
+			reg = <0x2 0x4a820000 0x0 0x4000>;
+
+			gpio-controller;
+			#gpio-cells = <2>;
+			gpio-ranges = <&pinctrl_aop 0 0 42>;
+
+			interrupt-controller;
+			interrupt-parent = <&aic>;
+			interrupts = <AIC_IRQ 268 IRQ_TYPE_LEVEL_HIGH>,
+				     <AIC_IRQ 269 IRQ_TYPE_LEVEL_HIGH>,
+				     <AIC_IRQ 270 IRQ_TYPE_LEVEL_HIGH>,
+				     <AIC_IRQ 271 IRQ_TYPE_LEVEL_HIGH>,
+				     <AIC_IRQ 272 IRQ_TYPE_LEVEL_HIGH>,
+				     <AIC_IRQ 273 IRQ_TYPE_LEVEL_HIGH>,
+				     <AIC_IRQ 274 IRQ_TYPE_LEVEL_HIGH>;
+		};
+
+		pinctrl_nub: pinctrl@23d1f0000 {
+			compatible = "apple,t8103-pinctrl", "apple,pinctrl";
+			reg = <0x2 0x3d1f0000 0x0 0x4000>;
+
+			gpio-controller;
+			#gpio-cells = <2>;
+			gpio-ranges = <&pinctrl_nub 0 0 23>;
+
+			interrupt-controller;
+			interrupt-parent = <&aic>;
+			interrupts = <AIC_IRQ 330 IRQ_TYPE_LEVEL_HIGH>,
+				     <AIC_IRQ 331 IRQ_TYPE_LEVEL_HIGH>,
+				     <AIC_IRQ 332 IRQ_TYPE_LEVEL_HIGH>,
+				     <AIC_IRQ 333 IRQ_TYPE_LEVEL_HIGH>,
+				     <AIC_IRQ 334 IRQ_TYPE_LEVEL_HIGH>,
+				     <AIC_IRQ 335 IRQ_TYPE_LEVEL_HIGH>,
+				     <AIC_IRQ 336 IRQ_TYPE_LEVEL_HIGH>;
+		};
+
+		pinctrl_smc: pinctrl@23e820000 {
+			compatible = "apple,t8103-pinctrl", "apple,pinctrl";
+			reg = <0x2 0x3e820000 0x0 0x4000>;
+
+			gpio-controller;
+			#gpio-cells = <2>;
+			gpio-ranges = <&pinctrl_smc 0 0 16>;
+
+			interrupt-controller;
+			interrupt-parent = <&aic>;
+			interrupts = <AIC_IRQ 391 IRQ_TYPE_LEVEL_HIGH>,
+				     <AIC_IRQ 392 IRQ_TYPE_LEVEL_HIGH>,
+				     <AIC_IRQ 393 IRQ_TYPE_LEVEL_HIGH>,
+				     <AIC_IRQ 394 IRQ_TYPE_LEVEL_HIGH>,
+				     <AIC_IRQ 395 IRQ_TYPE_LEVEL_HIGH>,
+				     <AIC_IRQ 396 IRQ_TYPE_LEVEL_HIGH>,
+				     <AIC_IRQ 397 IRQ_TYPE_LEVEL_HIGH>;
+		};
 	};
 };
-- 
2.30.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH v5 11/14] arm64: apple: Add PCIe node
  2021-09-29 16:38 [PATCH v5 00/14] PCI: Add support for Apple M1 Marc Zyngier
                   ` (9 preceding siblings ...)
  2021-09-29 16:38 ` [PATCH v5 10/14] arm64: apple: Add pinctrl nodes Marc Zyngier
@ 2021-09-29 16:38 ` Marc Zyngier
  2021-10-07 16:01   ` Hector Martin
  2021-09-29 16:38 ` [PATCH v5 12/14] arm64: dts: apple: t8103: Add PCIe DARTs Marc Zyngier
                   ` (3 subsequent siblings)
  14 siblings, 1 reply; 32+ messages in thread
From: Marc Zyngier @ 2021-09-29 16:38 UTC (permalink / raw)
  To: devicetree, linux-kernel, linux-pci
  Cc: Bjorn Helgaas, Rob Herring, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Alyssa Rosenzweig, Stan Skowronek,
	Mark Kettenis, Sven Peter, Hector Martin, Robin Murphy,
	Joey Gouly, Joerg Roedel, kernel-team

From: Mark Kettenis <kettenis@openbsd.org>

Add node corresponding to the apcie,t8103 node in the
Apple device tree for the Mac mini (M1, 2020).

Power domain references and DART (IOMMU) references are left out
at the moment and will be added once the appropriate bindings have
been settled upon.

Acked-by: Marc Zyngier <maz@kernel.org>
Signed-off-by: Mark Kettenis <kettenis@openbsd.org>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20210921183420.436-5-kettenis@openbsd.org
---
 arch/arm64/boot/dts/apple/t8103.dtsi | 63 ++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/arch/arm64/boot/dts/apple/t8103.dtsi b/arch/arm64/boot/dts/apple/t8103.dtsi
index 503a76fc30e6..10956859b4bb 100644
--- a/arch/arm64/boot/dts/apple/t8103.dtsi
+++ b/arch/arm64/boot/dts/apple/t8103.dtsi
@@ -214,5 +214,68 @@ pinctrl_smc: pinctrl@23e820000 {
 				     <AIC_IRQ 396 IRQ_TYPE_LEVEL_HIGH>,
 				     <AIC_IRQ 397 IRQ_TYPE_LEVEL_HIGH>;
 		};
+
+		pcie0: pcie@690000000 {
+			compatible = "apple,t8103-pcie", "apple,pcie";
+			device_type = "pci";
+
+			reg = <0x6 0x90000000 0x0 0x1000000>,
+			      <0x6 0x80000000 0x0 0x100000>,
+			      <0x6 0x81000000 0x0 0x4000>,
+			      <0x6 0x82000000 0x0 0x4000>,
+			      <0x6 0x83000000 0x0 0x4000>;
+			reg-names = "config", "rc", "port0", "port1", "port2";
+
+			interrupt-parent = <&aic>;
+			interrupts = <AIC_IRQ 695 IRQ_TYPE_LEVEL_HIGH>,
+				     <AIC_IRQ 698 IRQ_TYPE_LEVEL_HIGH>,
+				     <AIC_IRQ 701 IRQ_TYPE_LEVEL_HIGH>;
+
+			msi-controller;
+			msi-parent = <&pcie0>;
+			msi-ranges = <&aic AIC_IRQ 704 IRQ_TYPE_EDGE_RISING 32>;
+
+			bus-range = <0 3>;
+			#address-cells = <3>;
+			#size-cells = <2>;
+			ranges = <0x43000000 0x6 0xa0000000 0x6 0xa0000000 0x0 0x20000000>,
+				 <0x02000000 0x0 0xc0000000 0x6 0xc0000000 0x0 0x40000000>;
+
+			pinctrl-0 = <&pcie_pins>;
+			pinctrl-names = "default";
+
+			pci@0,0 {
+				device_type = "pci";
+				reg = <0x0 0x0 0x0 0x0 0x0>;
+				reset-gpios = <&pinctrl_ap 152 0>;
+				max-link-speed = <2>;
+
+				#address-cells = <3>;
+				#size-cells = <2>;
+				ranges;
+			};
+
+			pci@1,0 {
+				device_type = "pci";
+				reg = <0x800 0x0 0x0 0x0 0x0>;
+				reset-gpios = <&pinctrl_ap 153 0>;
+				max-link-speed = <2>;
+
+				#address-cells = <3>;
+				#size-cells = <2>;
+				ranges;
+			};
+
+			pci@2,0 {
+				device_type = "pci";
+				reg = <0x1000 0x0 0x0 0x0 0x0>;
+				reset-gpios = <&pinctrl_ap 33 0>;
+				max-link-speed = <1>;
+
+				#address-cells = <3>;
+				#size-cells = <2>;
+				ranges;
+			};
+		};
 	};
 };
-- 
2.30.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH v5 12/14] arm64: dts: apple: t8103: Add PCIe DARTs
  2021-09-29 16:38 [PATCH v5 00/14] PCI: Add support for Apple M1 Marc Zyngier
                   ` (10 preceding siblings ...)
  2021-09-29 16:38 ` [PATCH v5 11/14] arm64: apple: Add PCIe node Marc Zyngier
@ 2021-09-29 16:38 ` Marc Zyngier
  2021-10-07 16:02   ` Hector Martin
  2021-09-29 16:38 ` [PATCH v5 13/14] arm64: dts: apple: t8103: Add root port interrupt routing Marc Zyngier
                   ` (2 subsequent siblings)
  14 siblings, 1 reply; 32+ messages in thread
From: Marc Zyngier @ 2021-09-29 16:38 UTC (permalink / raw)
  To: devicetree, linux-kernel, linux-pci
  Cc: Bjorn Helgaas, Rob Herring, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Alyssa Rosenzweig, Stan Skowronek,
	Mark Kettenis, Sven Peter, Hector Martin, Robin Murphy,
	Joey Gouly, Joerg Roedel, kernel-team

PCIe on the Apple M1 (aka t8103) requires the use of IOMMUs (aka
DARTs). Add the three instances that deal with the internal PCIe
ports and route each port's traffic through its DART.

Signed-off-by: Marc Zyngier <maz@kernel.org>
---
 arch/arm64/boot/dts/apple/t8103.dtsi | 30 ++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/arch/arm64/boot/dts/apple/t8103.dtsi b/arch/arm64/boot/dts/apple/t8103.dtsi
index 10956859b4bb..2eae6752375f 100644
--- a/arch/arm64/boot/dts/apple/t8103.dtsi
+++ b/arch/arm64/boot/dts/apple/t8103.dtsi
@@ -215,6 +215,30 @@ pinctrl_smc: pinctrl@23e820000 {
 				     <AIC_IRQ 397 IRQ_TYPE_LEVEL_HIGH>;
 		};
 
+		pcie0_dart_0: dart@681008000 {
+			compatible = "apple,t8103-dart";
+			reg = <0x6 0x81008000 0x0 0x4000>;
+			#iommu-cells = <1>;
+			interrupt-parent = <&aic>;
+			interrupts = <AIC_IRQ 696 IRQ_TYPE_LEVEL_HIGH>;
+		};
+
+		pcie0_dart_1: dart@682008000 {
+			compatible = "apple,t8103-dart";
+			reg = <0x6 0x82008000 0x0 0x4000>;
+			#iommu-cells = <1>;
+			interrupt-parent = <&aic>;
+			interrupts = <AIC_IRQ 699 IRQ_TYPE_LEVEL_HIGH>;
+		};
+
+		pcie0_dart_2: dart@683008000 {
+			compatible = "apple,t8103-dart";
+			reg = <0x6 0x83008000 0x0 0x4000>;
+			#iommu-cells = <1>;
+			interrupt-parent = <&aic>;
+			interrupts = <AIC_IRQ 702 IRQ_TYPE_LEVEL_HIGH>;
+		};
+
 		pcie0: pcie@690000000 {
 			compatible = "apple,t8103-pcie", "apple,pcie";
 			device_type = "pci";
@@ -235,6 +259,12 @@ pcie0: pcie@690000000 {
 			msi-parent = <&pcie0>;
 			msi-ranges = <&aic AIC_IRQ 704 IRQ_TYPE_EDGE_RISING 32>;
 
+
+			iommu-map = <0x100 &pcie0_dart_0 1 1>,
+				    <0x200 &pcie0_dart_1 1 1>,
+				    <0x300 &pcie0_dart_2 1 1>;
+			iommu-map-mask = <0xff00>;
+
 			bus-range = <0 3>;
 			#address-cells = <3>;
 			#size-cells = <2>;
-- 
2.30.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH v5 13/14] arm64: dts: apple: t8103: Add root port interrupt routing
  2021-09-29 16:38 [PATCH v5 00/14] PCI: Add support for Apple M1 Marc Zyngier
                   ` (11 preceding siblings ...)
  2021-09-29 16:38 ` [PATCH v5 12/14] arm64: dts: apple: t8103: Add PCIe DARTs Marc Zyngier
@ 2021-09-29 16:38 ` Marc Zyngier
  2021-10-07 16:03   ` Hector Martin
  2021-09-29 16:38 ` [PATCH v5 14/14] arm64: dts: apple: j274: Expose PCI node for the Ethernet MAC address Marc Zyngier
  2021-10-04  8:38 ` [PATCH v5 00/14] PCI: Add support for Apple M1 Lorenzo Pieralisi
  14 siblings, 1 reply; 32+ messages in thread
From: Marc Zyngier @ 2021-09-29 16:38 UTC (permalink / raw)
  To: devicetree, linux-kernel, linux-pci
  Cc: Bjorn Helgaas, Rob Herring, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Alyssa Rosenzweig, Stan Skowronek,
	Mark Kettenis, Sven Peter, Hector Martin, Robin Murphy,
	Joey Gouly, Joerg Roedel, kernel-team

Add the interrupt-map properties that are required for INTx
signalling.

Tested-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
 arch/arm64/boot/dts/apple/t8103.dtsi | 33 +++++++++++++++++++++++++---
 1 file changed, 30 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/boot/dts/apple/t8103.dtsi b/arch/arm64/boot/dts/apple/t8103.dtsi
index 2eae6752375f..e6263c711c18 100644
--- a/arch/arm64/boot/dts/apple/t8103.dtsi
+++ b/arch/arm64/boot/dts/apple/t8103.dtsi
@@ -274,7 +274,7 @@ pcie0: pcie@690000000 {
 			pinctrl-0 = <&pcie_pins>;
 			pinctrl-names = "default";
 
-			pci@0,0 {
+			port00: pci@0,0 {
 				device_type = "pci";
 				reg = <0x0 0x0 0x0 0x0 0x0>;
 				reset-gpios = <&pinctrl_ap 152 0>;
@@ -283,9 +283,18 @@ pci@0,0 {
 				#address-cells = <3>;
 				#size-cells = <2>;
 				ranges;
+
+				interrupt-controller;
+				#interrupt-cells = <1>;
+
+				interrupt-map-mask = <0 0 0 7>;
+				interrupt-map = <0 0 0 1 &port00 0 0 0 0>,
+						<0 0 0 2 &port00 0 0 0 1>,
+						<0 0 0 3 &port00 0 0 0 2>,
+						<0 0 0 4 &port00 0 0 0 3>;
 			};
 
-			pci@1,0 {
+			port01: pci@1,0 {
 				device_type = "pci";
 				reg = <0x800 0x0 0x0 0x0 0x0>;
 				reset-gpios = <&pinctrl_ap 153 0>;
@@ -294,9 +303,18 @@ pci@1,0 {
 				#address-cells = <3>;
 				#size-cells = <2>;
 				ranges;
+
+				interrupt-controller;
+				#interrupt-cells = <1>;
+
+				interrupt-map-mask = <0 0 0 7>;
+				interrupt-map = <0 0 0 1 &port01 0 0 0 0>,
+						<0 0 0 2 &port01 0 0 0 1>,
+						<0 0 0 3 &port01 0 0 0 2>,
+						<0 0 0 4 &port01 0 0 0 3>;
 			};
 
-			pci@2,0 {
+			port02: pci@2,0 {
 				device_type = "pci";
 				reg = <0x1000 0x0 0x0 0x0 0x0>;
 				reset-gpios = <&pinctrl_ap 33 0>;
@@ -305,6 +323,15 @@ pci@2,0 {
 				#address-cells = <3>;
 				#size-cells = <2>;
 				ranges;
+
+				interrupt-controller;
+				#interrupt-cells = <1>;
+
+				interrupt-map-mask = <0 0 0 7>;
+				interrupt-map = <0 0 0 1 &port02 0 0 0 0>,
+						<0 0 0 2 &port02 0 0 0 1>,
+						<0 0 0 3 &port02 0 0 0 2>,
+						<0 0 0 4 &port02 0 0 0 3>;
 			};
 		};
 	};
-- 
2.30.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH v5 14/14] arm64: dts: apple: j274: Expose PCI node for the Ethernet MAC address
  2021-09-29 16:38 [PATCH v5 00/14] PCI: Add support for Apple M1 Marc Zyngier
                   ` (12 preceding siblings ...)
  2021-09-29 16:38 ` [PATCH v5 13/14] arm64: dts: apple: t8103: Add root port interrupt routing Marc Zyngier
@ 2021-09-29 16:38 ` Marc Zyngier
  2021-10-07 16:03   ` Hector Martin
  2021-10-04  8:38 ` [PATCH v5 00/14] PCI: Add support for Apple M1 Lorenzo Pieralisi
  14 siblings, 1 reply; 32+ messages in thread
From: Marc Zyngier @ 2021-09-29 16:38 UTC (permalink / raw)
  To: devicetree, linux-kernel, linux-pci
  Cc: Bjorn Helgaas, Rob Herring, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Alyssa Rosenzweig, Stan Skowronek,
	Mark Kettenis, Sven Peter, Hector Martin, Robin Murphy,
	Joey Gouly, Joerg Roedel, kernel-team

At the moment, all the Minis running Linux have the same MAC
address (00:10:18:00:00:00), which is a bit annoying.

Expose the PCI node corresponding to the Ethernet device, and
declare a 'local-mac-address' property. The bootloader will update
it (m1n1 already has the required feature). And if it doesn't, then
the default value is already present in the DT.

This relies on forcing the bus number for each port so that the
endpoints connected to them are correctly numbered (and keeps dtc
quiet).

Signed-off-by: Marc Zyngier <maz@kernel.org>
---
 arch/arm64/boot/dts/apple/t8103-j274.dts | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/arch/arm64/boot/dts/apple/t8103-j274.dts b/arch/arm64/boot/dts/apple/t8103-j274.dts
index e0f6775b9878..33a80f9501dc 100644
--- a/arch/arm64/boot/dts/apple/t8103-j274.dts
+++ b/arch/arm64/boot/dts/apple/t8103-j274.dts
@@ -17,6 +17,7 @@ / {
 
 	aliases {
 		serial0 = &serial0;
+		ethernet0 = &ethernet0;
 	};
 
 	chosen {
@@ -43,3 +44,25 @@ memory@800000000 {
 &serial0 {
 	status = "okay";
 };
+
+/*
+ * Force the bus number assignments so that we can declare some of the
+ * on-board devices and properties that are populated by the bootloader
+ * (such as MAC addresses).
+ */
+&port00 {
+	bus-range = <1 1>;
+};
+
+&port01 {
+	bus-range = <2 2>;
+};
+
+&port02 {
+	bus-range = <3 3>;
+	ethernet0: pci@0,0 {
+		reg = <0x30000 0x0 0x0 0x0 0x0>;
+		/* To be filled by the loader */
+		local-mac-address = [00 10 18 00 00 00];
+	};
+};
-- 
2.30.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH v5 10/14] arm64: apple: Add pinctrl nodes
  2021-09-29 16:38 ` [PATCH v5 10/14] arm64: apple: Add pinctrl nodes Marc Zyngier
@ 2021-09-29 19:05   ` Linus Walleij
  2021-09-30  8:00     ` Marc Zyngier
  2021-10-07 16:00   ` Hector Martin
  1 sibling, 1 reply; 32+ messages in thread
From: Linus Walleij @ 2021-09-29 19:05 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	linux-kernel, linux-pci, Bjorn Helgaas, Rob Herring,
	Lorenzo Pieralisi, Krzysztof Wilczyński, Alyssa Rosenzweig,
	Stan Skowronek, Mark Kettenis, Sven Peter, Hector Martin,
	Robin Murphy, Joey Gouly, Joerg Roedel, Android Kernel Team

On Wed, Sep 29, 2021 at 6:56 PM Marc Zyngier <maz@kernel.org> wrote:

> From: Mark Kettenis <kettenis@openbsd.org>
>
> Add pinctrl nodes corresponding to the gpio,t8101 nodes in the
> Apple device tree for the Mac mini (M1, 2020).
>
> Clock references are left out at the moment and will be added once
> the appropriate bindings have been settled upon.
>
> Signed-off-by: Mark Kettenis <kettenis@openbsd.org>
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> Signed-off-by: Marc Zyngier <maz@kernel.org>
> Link: https://lore.kernel.org/r/20210520171310.772-3-mark.kettenis@xs4all.nl
(...)
> +               pinctrl_ap: pinctrl@23c100000 {
> +                       compatible = "apple,t8103-pinctrl", "apple,pinctrl";
> +                       reg = <0x2 0x3c100000 0x0 0x100000>;
> +
> +                       gpio-controller;
> +                       #gpio-cells = <2>;
> +                       gpio-ranges = <&pinctrl_ap 0 0 212>;

In other discussions it turns out that the driver is abusing these gpio-ranges
to find out how many pins are in each pinctrl instance. This is not the
idea with gpio-ranges, these can be multiple and map different sets,
so we need something like

apple,npins = <212>;
(+ bindings)

or so...

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH v5 10/14] arm64: apple: Add pinctrl nodes
  2021-09-29 19:05   ` Linus Walleij
@ 2021-09-30  8:00     ` Marc Zyngier
  2021-09-30  9:20       ` Mark Kettenis
  2021-09-30 15:46       ` Linus Walleij
  0 siblings, 2 replies; 32+ messages in thread
From: Marc Zyngier @ 2021-09-30  8:00 UTC (permalink / raw)
  To: Linus Walleij
  Cc: open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	linux-kernel, linux-pci, Bjorn Helgaas, Rob Herring,
	Lorenzo Pieralisi, Krzysztof Wilczyński, Alyssa Rosenzweig,
	Stan Skowronek, Mark Kettenis, Sven Peter, Hector Martin,
	Robin Murphy, Joey Gouly, Joerg Roedel, Android Kernel Team

On Wed, 29 Sep 2021 20:05:42 +0100,
Linus Walleij <linus.walleij@linaro.org> wrote:
> 
> On Wed, Sep 29, 2021 at 6:56 PM Marc Zyngier <maz@kernel.org> wrote:
> 
> > From: Mark Kettenis <kettenis@openbsd.org>
> >
> > Add pinctrl nodes corresponding to the gpio,t8101 nodes in the
> > Apple device tree for the Mac mini (M1, 2020).
> >
> > Clock references are left out at the moment and will be added once
> > the appropriate bindings have been settled upon.
> >
> > Signed-off-by: Mark Kettenis <kettenis@openbsd.org>
> > Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> > Signed-off-by: Marc Zyngier <maz@kernel.org>
> > Link: https://lore.kernel.org/r/20210520171310.772-3-mark.kettenis@xs4all.nl
> (...)
> > +               pinctrl_ap: pinctrl@23c100000 {
> > +                       compatible = "apple,t8103-pinctrl", "apple,pinctrl";
> > +                       reg = <0x2 0x3c100000 0x0 0x100000>;
> > +
> > +                       gpio-controller;
> > +                       #gpio-cells = <2>;
> > +                       gpio-ranges = <&pinctrl_ap 0 0 212>;
> 
> In other discussions it turns out that the driver is abusing these gpio-ranges
> to find out how many pins are in each pinctrl instance. This is not the
> idea with gpio-ranges, these can be multiple and map different sets,
> so we need something like
> 
> apple,npins = <212>;
> (+ bindings)
> 
> or so...

Is it the driver that needs updating? Or the binding? I don't really
care about the former, but the latter is more disruptive as it has
impacts over both u-boot and at least OpenBSD.

How is that solved on other pinctrl blocks? I can't see anyone having
a similar a similar property.

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH v5 10/14] arm64: apple: Add pinctrl nodes
  2021-09-30  8:00     ` Marc Zyngier
@ 2021-09-30  9:20       ` Mark Kettenis
  2021-09-30 15:46       ` Linus Walleij
  1 sibling, 0 replies; 32+ messages in thread
From: Mark Kettenis @ 2021-09-30  9:20 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: linus.walleij, devicetree, linux-kernel, linux-pci, bhelgaas,
	robh+dt, lorenzo.pieralisi, kw, alyssa, stan, kettenis, sven,
	marcan, Robin.Murphy, joey.gouly, joro, kernel-team

> Date: Thu, 30 Sep 2021 09:00:49 +0100
> From: Marc Zyngier <maz@kernel.org>

Hi Linus and Marc,

> On Wed, 29 Sep 2021 20:05:42 +0100,
> Linus Walleij <linus.walleij@linaro.org> wrote:
> > 
> > On Wed, Sep 29, 2021 at 6:56 PM Marc Zyngier <maz@kernel.org> wrote:
> > 
> > > From: Mark Kettenis <kettenis@openbsd.org>
> > >
> > > Add pinctrl nodes corresponding to the gpio,t8101 nodes in the
> > > Apple device tree for the Mac mini (M1, 2020).
> > >
> > > Clock references are left out at the moment and will be added once
> > > the appropriate bindings have been settled upon.
> > >
> > > Signed-off-by: Mark Kettenis <kettenis@openbsd.org>
> > > Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> > > Signed-off-by: Marc Zyngier <maz@kernel.org>
> > > Link: https://lore.kernel.org/r/20210520171310.772-3-mark.kettenis@xs4all.nl
> > (...)
> > > +               pinctrl_ap: pinctrl@23c100000 {
> > > +                       compatible = "apple,t8103-pinctrl", "apple,pinctrl";
> > > +                       reg = <0x2 0x3c100000 0x0 0x100000>;
> > > +
> > > +                       gpio-controller;
> > > +                       #gpio-cells = <2>;
> > > +                       gpio-ranges = <&pinctrl_ap 0 0 212>;
> > 
> > In other discussions it turns out that the driver is abusing these gpio-ranges
> > to find out how many pins are in each pinctrl instance. This is not the
> > idea with gpio-ranges, these can be multiple and map different sets,
> > so we need something like
> > 
> > apple,npins = <212>;
> > (+ bindings)
> > 
> > or so...
> 
> Is it the driver that needs updating? Or the binding? I don't really
> care about the former, but the latter is more disruptive as it has
> impacts over both u-boot and at least OpenBSD.

I don't have a finished OpenBSD driver yet, and U-Boot support is
still in the process of being upstreamed, so tweaking the binding a
bit is not out of the question at this point.  And as long as the
gpio-ranges property continues to be there, things won't break anyway.

> How is that solved on other pinctrl blocks? I can't see anyone having
> a similar a similar property.

I suspect most pinctrl blocks have a well-defined number of pins that
is simply a #define in the driver.  Here we don't really know what the
hardware provides but the "Apple device tree" has a property that
describes the number of pins, which varies between the different
blocks.

Since there is a simple 1:1 mapping between pins and gpios it seemed
natural to me to simply use the value from gpio-ranges.  My thinking
was that having a separate property to encode the number of pins just
increases the chances of the two getting out of sync.  But maybe that
is the whole point Linus is trying to make; not all pins may actually
provide GPIO functionality and gpio-ranges can be used to map only
those pins that actually do.  In this particular case I don't think it
makes sense to map multiple ranges though as we will probably never
know full details for all the pins.

FWIW, there are other U-Boot drivers that use gpio-ranges to get the
pin count.  But I suppose U-Boot has somewhat different standards than
the Linux kernel, prioritising code size and such.

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH v5 10/14] arm64: apple: Add pinctrl nodes
  2021-09-30  8:00     ` Marc Zyngier
  2021-09-30  9:20       ` Mark Kettenis
@ 2021-09-30 15:46       ` Linus Walleij
  1 sibling, 0 replies; 32+ messages in thread
From: Linus Walleij @ 2021-09-30 15:46 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	linux-kernel, linux-pci, Bjorn Helgaas, Rob Herring,
	Lorenzo Pieralisi, Krzysztof Wilczyński, Alyssa Rosenzweig,
	Stan Skowronek, Mark Kettenis, Sven Peter, Hector Martin,
	Robin Murphy, Joey Gouly, Joerg Roedel, Android Kernel Team

On Thu, Sep 30, 2021 at 10:00 AM Marc Zyngier <maz@kernel.org> wrote:

> > In other discussions it turns out that the driver is abusing these gpio-ranges
> > to find out how many pins are in each pinctrl instance. This is not the
> > idea with gpio-ranges, these can be multiple and map different sets,
> > so we need something like
> >
> > apple,npins = <212>;
> > (+ bindings)
> >
> > or so...
>
> Is it the driver that needs updating? Or the binding?

Both, I guess.

> I don't really
> care about the former, but the latter is more disruptive as it has
> impacts over both u-boot and at least OpenBSD.
>
> How is that solved on other pinctrl blocks? I can't see anyone having
> a similar a similar property.

The Apple pincontroller is unique in having four instances using the
same compatible string (I raised this as an issue too).

Most SoCs has one instance of a pin controller, with one compatible
string and then we also know how many pins it has.

The maintainer seeme unhappy about my suggestion to name
the four pin controllers after function and insist to use the same
compatible for all four, which means they instead need to be
parametrized, which means this parameter has to be added
because ranges should not be used in this way.

I guess the code can survive using the ranges as a fallback at
the cost of some more complex code.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH v5 00/14] PCI: Add support for Apple M1
  2021-09-29 16:38 [PATCH v5 00/14] PCI: Add support for Apple M1 Marc Zyngier
                   ` (13 preceding siblings ...)
  2021-09-29 16:38 ` [PATCH v5 14/14] arm64: dts: apple: j274: Expose PCI node for the Ethernet MAC address Marc Zyngier
@ 2021-10-04  8:38 ` Lorenzo Pieralisi
  2021-10-04  9:05   ` Marc Zyngier
  2021-10-04 19:51   ` Rob Herring
  14 siblings, 2 replies; 32+ messages in thread
From: Lorenzo Pieralisi @ 2021-10-04  8:38 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: devicetree, linux-kernel, linux-pci, Bjorn Helgaas, Rob Herring,
	Krzysztof Wilczyński, Alyssa Rosenzweig, Stan Skowronek,
	Mark Kettenis, Sven Peter, Hector Martin, Robin Murphy,
	Joey Gouly, Joerg Roedel, kernel-team

On Wed, Sep 29, 2021 at 05:38:33PM +0100, Marc Zyngier wrote:
> This is v5 of the series adding PCIe support for the M1 SoC. Not a lot
> has changed this time around, and most of what I was saying in [1] is
> still valid.
> 
> Very little has changed code wise (a couple of bug fixes). The series
> however now carries a bunch of DT updates so that people can actually
> make use of PCIe on an M1 box (OK, not quite, you will still need [2],
> or whatever version replaces it). The corresponding bindings are
> either already merged, or queued for 5.16 (this is the case for the
> PCI binding).
> 
> It all should be in a state that makes it mergeable (yeah, I said that
> last time... I mean it this time! ;-).
> 
> As always, comments welcome.
> 
> 	M.
> 
> [1] https://lore.kernel.org/r/20210922205458.358517-1-maz@kernel.org
> [2] https://lore.kernel.org/r/20210921222956.40719-2-joey.gouly@arm.com
> 
> Alyssa Rosenzweig (2):
>   PCI: apple: Add initial hardware bring-up
>   PCI: apple: Set up reference clocks when probing
> 
> Marc Zyngier (10):
>   irqdomain: Make of_phandle_args_to_fwspec generally available
>   of/irq: Allow matching of an interrupt-map local to an interrupt
>     controller
>   PCI: of: Allow matching of an interrupt-map local to a PCI device
>   PCI: apple: Add INTx and per-port interrupt support
>   PCI: apple: Implement MSI support
>   iommu/dart: Exclude MSI doorbell from PCIe device IOVA range
>   PCI: apple: Configure RID to SID mapper on device addition
>   arm64: dts: apple: t8103: Add PCIe DARTs
>   arm64: dts: apple: t8103: Add root port interrupt routing
>   arm64: dts: apple: j274: Expose PCI node for the Ethernet MAC address
> 
> Mark Kettenis (2):
>   arm64: apple: Add pinctrl nodes
>   arm64: apple: Add PCIe node
> 
>  MAINTAINERS                              |   7 +
>  arch/arm64/boot/dts/apple/t8103-j274.dts |  23 +
>  arch/arm64/boot/dts/apple/t8103.dtsi     | 203 ++++++
>  drivers/iommu/apple-dart.c               |  27 +
>  drivers/of/irq.c                         |  17 +-
>  drivers/pci/controller/Kconfig           |  17 +
>  drivers/pci/controller/Makefile          |   1 +
>  drivers/pci/controller/pcie-apple.c      | 822 +++++++++++++++++++++++
>  drivers/pci/of.c                         |  10 +-
>  include/linux/irqdomain.h                |   4 +
>  kernel/irq/irqdomain.c                   |   6 +-
>  11 files changed, 1127 insertions(+), 10 deletions(-)
>  create mode 100644 drivers/pci/controller/pcie-apple.c

I have applied (with very minor log changes) patches [1-9] to
pci/apple for v5.16, I expect the dts changes to go via the
arm-soc tree separately, please let me know if that works for you.

Thanks,
Lorenzo

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH v5 00/14] PCI: Add support for Apple M1
  2021-10-04  8:38 ` [PATCH v5 00/14] PCI: Add support for Apple M1 Lorenzo Pieralisi
@ 2021-10-04  9:05   ` Marc Zyngier
  2021-10-04 18:30     ` Linus Walleij
  2021-10-04 19:51   ` Rob Herring
  1 sibling, 1 reply; 32+ messages in thread
From: Marc Zyngier @ 2021-10-04  9:05 UTC (permalink / raw)
  To: Lorenzo Pieralisi
  Cc: devicetree, linux-kernel, linux-pci, Bjorn Helgaas, Rob Herring,
	Krzysztof Wilczyński, Alyssa Rosenzweig, Stan Skowronek,
	Mark Kettenis, Sven Peter, Hector Martin, Robin Murphy,
	Joey Gouly, Joerg Roedel, kernel-team, Linus Walleij,
	Arnd Bergmann

Hi Lorenzo,

[+LinusW, Arnd]

On Mon, 04 Oct 2021 09:38:45 +0100,
Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> wrote:
> 
> On Wed, Sep 29, 2021 at 05:38:33PM +0100, Marc Zyngier wrote:
> > This is v5 of the series adding PCIe support for the M1 SoC. Not a lot
> > has changed this time around, and most of what I was saying in [1] is
> > still valid.
> > 
> > Very little has changed code wise (a couple of bug fixes). The series
> > however now carries a bunch of DT updates so that people can actually
> > make use of PCIe on an M1 box (OK, not quite, you will still need [2],
> > or whatever version replaces it). The corresponding bindings are
> > either already merged, or queued for 5.16 (this is the case for the
> > PCI binding).
> > 
> > It all should be in a state that makes it mergeable (yeah, I said that
> > last time... I mean it this time! ;-).
> > 
> > As always, comments welcome.
> > 
> > 	M.
> > 
> > [1] https://lore.kernel.org/r/20210922205458.358517-1-maz@kernel.org
> > [2] https://lore.kernel.org/r/20210921222956.40719-2-joey.gouly@arm.com
> > 
> > Alyssa Rosenzweig (2):
> >   PCI: apple: Add initial hardware bring-up
> >   PCI: apple: Set up reference clocks when probing
> > 
> > Marc Zyngier (10):
> >   irqdomain: Make of_phandle_args_to_fwspec generally available
> >   of/irq: Allow matching of an interrupt-map local to an interrupt
> >     controller
> >   PCI: of: Allow matching of an interrupt-map local to a PCI device
> >   PCI: apple: Add INTx and per-port interrupt support
> >   PCI: apple: Implement MSI support
> >   iommu/dart: Exclude MSI doorbell from PCIe device IOVA range
> >   PCI: apple: Configure RID to SID mapper on device addition
> >   arm64: dts: apple: t8103: Add PCIe DARTs
> >   arm64: dts: apple: t8103: Add root port interrupt routing
> >   arm64: dts: apple: j274: Expose PCI node for the Ethernet MAC address
> > 
> > Mark Kettenis (2):
> >   arm64: apple: Add pinctrl nodes
> >   arm64: apple: Add PCIe node
> > 
> >  MAINTAINERS                              |   7 +
> >  arch/arm64/boot/dts/apple/t8103-j274.dts |  23 +
> >  arch/arm64/boot/dts/apple/t8103.dtsi     | 203 ++++++
> >  drivers/iommu/apple-dart.c               |  27 +
> >  drivers/of/irq.c                         |  17 +-
> >  drivers/pci/controller/Kconfig           |  17 +
> >  drivers/pci/controller/Makefile          |   1 +
> >  drivers/pci/controller/pcie-apple.c      | 822 +++++++++++++++++++++++
> >  drivers/pci/of.c                         |  10 +-
> >  include/linux/irqdomain.h                |   4 +
> >  kernel/irq/irqdomain.c                   |   6 +-
> >  11 files changed, 1127 insertions(+), 10 deletions(-)
> >  create mode 100644 drivers/pci/controller/pcie-apple.c
> 
> I have applied (with very minor log changes) patches [1-9] to
> pci/apple for v5.16, I expect the dts changes to go via the
> arm-soc tree separately, please let me know if that works for you.

Yes, that's absolutely fine. I hope we can resolve the issue on the
pinctrl binding pretty quickly, and get the arm-soc folks to pull the
DT changes in for 5.16 too.

This would make the Mini a usable machine with a mainline kernel.

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH v5 00/14] PCI: Add support for Apple M1
  2021-10-04  9:05   ` Marc Zyngier
@ 2021-10-04 18:30     ` Linus Walleij
  2021-10-07 15:43       ` Hector Martin
  0 siblings, 1 reply; 32+ messages in thread
From: Linus Walleij @ 2021-10-04 18:30 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: Lorenzo Pieralisi,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	linux-kernel, linux-pci, Bjorn Helgaas, Rob Herring,
	Krzysztof Wilczyński, Alyssa Rosenzweig, Stan Skowronek,
	Mark Kettenis, Sven Peter, Hector Martin, Robin Murphy,
	Joey Gouly, Joerg Roedel, Android Kernel Team, Arnd Bergmann

On Mon, Oct 4, 2021 at 11:05 AM Marc Zyngier <maz@kernel.org> wrote:

> Yes, that's absolutely fine. I hope we can resolve the issue on the
> pinctrl binding pretty quickly, and get the arm-soc folks to pull the
> DT changes in for 5.16 too.

I think I ACKed a patch for apple,npins = <> yesterday.

> This would make the Mini a usable machine with a mainline kernel.

That seems useful.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH v5 00/14] PCI: Add support for Apple M1
  2021-10-04  8:38 ` [PATCH v5 00/14] PCI: Add support for Apple M1 Lorenzo Pieralisi
  2021-10-04  9:05   ` Marc Zyngier
@ 2021-10-04 19:51   ` Rob Herring
  2021-10-04 20:42     ` Linus Walleij
  1 sibling, 1 reply; 32+ messages in thread
From: Rob Herring @ 2021-10-04 19:51 UTC (permalink / raw)
  To: Lorenzo Pieralisi
  Cc: Marc Zyngier, devicetree, linux-kernel, PCI, Bjorn Helgaas,
	Krzysztof Wilczyński, Alyssa Rosenzweig, Stan Skowronek,
	Mark Kettenis, Sven Peter, Hector Martin, Robin Murphy,
	Joey Gouly, Joerg Roedel, Android Kernel Team

On Mon, Oct 4, 2021 at 3:38 AM Lorenzo Pieralisi
<lorenzo.pieralisi@arm.com> wrote:
>
> On Wed, Sep 29, 2021 at 05:38:33PM +0100, Marc Zyngier wrote:
> > This is v5 of the series adding PCIe support for the M1 SoC. Not a lot
> > has changed this time around, and most of what I was saying in [1] is
> > still valid.
> >
> > Very little has changed code wise (a couple of bug fixes). The series
> > however now carries a bunch of DT updates so that people can actually
> > make use of PCIe on an M1 box (OK, not quite, you will still need [2],
> > or whatever version replaces it). The corresponding bindings are
> > either already merged, or queued for 5.16 (this is the case for the
> > PCI binding).
> >
> > It all should be in a state that makes it mergeable (yeah, I said that
> > last time... I mean it this time! ;-).
> >
> > As always, comments welcome.
> >
> >       M.
> >
> > [1] https://lore.kernel.org/r/20210922205458.358517-1-maz@kernel.org
> > [2] https://lore.kernel.org/r/20210921222956.40719-2-joey.gouly@arm.com
> >
> > Alyssa Rosenzweig (2):
> >   PCI: apple: Add initial hardware bring-up
> >   PCI: apple: Set up reference clocks when probing
> >
> > Marc Zyngier (10):
> >   irqdomain: Make of_phandle_args_to_fwspec generally available
> >   of/irq: Allow matching of an interrupt-map local to an interrupt
> >     controller
> >   PCI: of: Allow matching of an interrupt-map local to a PCI device
> >   PCI: apple: Add INTx and per-port interrupt support
> >   PCI: apple: Implement MSI support
> >   iommu/dart: Exclude MSI doorbell from PCIe device IOVA range
> >   PCI: apple: Configure RID to SID mapper on device addition
> >   arm64: dts: apple: t8103: Add PCIe DARTs
> >   arm64: dts: apple: t8103: Add root port interrupt routing
> >   arm64: dts: apple: j274: Expose PCI node for the Ethernet MAC address
> >
> > Mark Kettenis (2):
> >   arm64: apple: Add pinctrl nodes
> >   arm64: apple: Add PCIe node
> >
> >  MAINTAINERS                              |   7 +
> >  arch/arm64/boot/dts/apple/t8103-j274.dts |  23 +
> >  arch/arm64/boot/dts/apple/t8103.dtsi     | 203 ++++++
> >  drivers/iommu/apple-dart.c               |  27 +
> >  drivers/of/irq.c                         |  17 +-
> >  drivers/pci/controller/Kconfig           |  17 +
> >  drivers/pci/controller/Makefile          |   1 +
> >  drivers/pci/controller/pcie-apple.c      | 822 +++++++++++++++++++++++
> >  drivers/pci/of.c                         |  10 +-
> >  include/linux/irqdomain.h                |   4 +
> >  kernel/irq/irqdomain.c                   |   6 +-
> >  11 files changed, 1127 insertions(+), 10 deletions(-)
> >  create mode 100644 drivers/pci/controller/pcie-apple.c
>
> I have applied (with very minor log changes) patches [1-9] to
> pci/apple for v5.16, I expect the dts changes to go via the
> arm-soc tree separately, please let me know if that works for you.

FYI, I pushed patches 1-3 to kernelCI and didn't see any regressions.
I am a bit worried about changes to the DT interrupt parsing and
ancient platforms (such as PowerMacs). Most likely there wouldn't be
any report until -rc1 or months later on those old systems.

Rob

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH v5 00/14] PCI: Add support for Apple M1
  2021-10-04 19:51   ` Rob Herring
@ 2021-10-04 20:42     ` Linus Walleij
  2021-10-05  9:57       ` Marc Zyngier
  2021-10-06  5:56       ` Michael Ellerman
  0 siblings, 2 replies; 32+ messages in thread
From: Linus Walleij @ 2021-10-04 20:42 UTC (permalink / raw)
  To: Rob Herring, linuxppc-dev@lists.ozlabs.org list, opensuse-ppc
  Cc: Lorenzo Pieralisi, Marc Zyngier,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	linux-kernel, PCI, Bjorn Helgaas, Krzysztof Wilczyński,
	Alyssa Rosenzweig, Stan Skowronek, Mark Kettenis, Sven Peter,
	Hector Martin, Robin Murphy, Joey Gouly, Joerg Roedel,
	Android Kernel Team

On Mon, Oct 4, 2021 at 9:52 PM Rob Herring <robh+dt@kernel.org> wrote:

> FYI, I pushed patches 1-3 to kernelCI and didn't see any regressions.
> I am a bit worried about changes to the DT interrupt parsing and
> ancient platforms (such as PowerMacs). Most likely there wouldn't be
> any report until -rc1 or months later on those old systems.

Lets page the PPC lists to see if someone can test on some powermac.

Linus Walleij

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH v5 00/14] PCI: Add support for Apple M1
  2021-10-04 20:42     ` Linus Walleij
@ 2021-10-05  9:57       ` Marc Zyngier
  2021-10-06  5:56       ` Michael Ellerman
  1 sibling, 0 replies; 32+ messages in thread
From: Marc Zyngier @ 2021-10-05  9:57 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Rob Herring, linuxppc-dev@lists.ozlabs.org list, opensuse-ppc,
	Lorenzo Pieralisi,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	linux-kernel, PCI, Bjorn Helgaas, Krzysztof Wilczyński,
	Alyssa Rosenzweig, Stan Skowronek, Mark Kettenis, Sven Peter,
	Hector Martin, Robin Murphy, Joey Gouly, Joerg Roedel,
	Android Kernel Team

On Mon, 04 Oct 2021 21:42:45 +0100,
Linus Walleij <linus.walleij@linaro.org> wrote:
> 
> On Mon, Oct 4, 2021 at 9:52 PM Rob Herring <robh+dt@kernel.org> wrote:
> 
> > FYI, I pushed patches 1-3 to kernelCI and didn't see any regressions.
> > I am a bit worried about changes to the DT interrupt parsing and
> > ancient platforms (such as PowerMacs). Most likely there wouldn't be
> > any report until -rc1 or months later on those old systems.
> 
> Lets page the PPC lists to see if someone can test on some powermac.

/me eyes the XServe-G5 that hasn't been powered on in 10 years. What
could possibly go wrong?

	M.

-- 
Without deviation from the norm, progress is not possible.

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH v5 00/14] PCI: Add support for Apple M1
  2021-10-04 20:42     ` Linus Walleij
  2021-10-05  9:57       ` Marc Zyngier
@ 2021-10-06  5:56       ` Michael Ellerman
  1 sibling, 0 replies; 32+ messages in thread
From: Michael Ellerman @ 2021-10-06  5:56 UTC (permalink / raw)
  To: Linus Walleij, Rob Herring, linuxppc-dev@lists.ozlabs.org list,
	opensuse-ppc
  Cc: Lorenzo Pieralisi, Marc Zyngier,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	linux-kernel, PCI, Bjorn Helgaas, Krzysztof Wilczyński,
	Alyssa Rosenzweig, Stan Skowronek, Mark Kettenis, Sven Peter,
	Hector Martin, Robin Murphy, Joey Gouly, Joerg Roedel,
	Android Kernel Team

Linus Walleij <linus.walleij@linaro.org> writes:
> On Mon, Oct 4, 2021 at 9:52 PM Rob Herring <robh+dt@kernel.org> wrote:
>
>> FYI, I pushed patches 1-3 to kernelCI and didn't see any regressions.
>> I am a bit worried about changes to the DT interrupt parsing and
>> ancient platforms (such as PowerMacs). Most likely there wouldn't be
>> any report until -rc1 or months later on those old systems.
>
> Lets page the PPC lists to see if someone can test on some powermac.

It boots and everything seems fine on an iMac-G5 of mine.

I don't have access to any other powermac hardware at the moment due to
the lockdown here.

cheers

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH v5 00/14] PCI: Add support for Apple M1
  2021-10-04 18:30     ` Linus Walleij
@ 2021-10-07 15:43       ` Hector Martin
  0 siblings, 0 replies; 32+ messages in thread
From: Hector Martin @ 2021-10-07 15:43 UTC (permalink / raw)
  To: Linus Walleij, Marc Zyngier
  Cc: Lorenzo Pieralisi,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	linux-kernel, linux-pci, Bjorn Helgaas, Rob Herring,
	Krzysztof Wilczyński, Alyssa Rosenzweig, Stan Skowronek,
	Mark Kettenis, Sven Peter, Robin Murphy, Joey Gouly,
	Joerg Roedel, Android Kernel Team, Arnd Bergmann

On 05/10/2021 03.30, Linus Walleij wrote:
> On Mon, Oct 4, 2021 at 11:05 AM Marc Zyngier <maz@kernel.org> wrote:
> 
>> Yes, that's absolutely fine. I hope we can resolve the issue on the
>> pinctrl binding pretty quickly, and get the arm-soc folks to pull the
>> DT changes in for 5.16 too.
> 
> I think I ACKed a patch for apple,npins = <> yesterday.

You reviewed it :)

It still needs some fixes to pass the schema linter though.

-- 
Hector Martin (marcan@marcan.st)
Public Key: https://mrcn.st/pub

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH v5 10/14] arm64: apple: Add pinctrl nodes
  2021-09-29 16:38 ` [PATCH v5 10/14] arm64: apple: Add pinctrl nodes Marc Zyngier
  2021-09-29 19:05   ` Linus Walleij
@ 2021-10-07 16:00   ` Hector Martin
  1 sibling, 0 replies; 32+ messages in thread
From: Hector Martin @ 2021-10-07 16:00 UTC (permalink / raw)
  To: Marc Zyngier, devicetree, linux-kernel, linux-pci
  Cc: Bjorn Helgaas, Rob Herring, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Alyssa Rosenzweig, Stan Skowronek,
	Mark Kettenis, Sven Peter, Robin Murphy, Joey Gouly,
	Joerg Roedel, kernel-team, Linus Walleij

On 30/09/2021 01.38, Marc Zyngier wrote:
> From: Mark Kettenis <kettenis@openbsd.org>
> 
> Add pinctrl nodes corresponding to the gpio,t8101 nodes in the
> Apple device tree for the Mac mini (M1, 2020).
> 
> Clock references are left out at the moment and will be added once
> the appropriate bindings have been settled upon.
> 
> Signed-off-by: Mark Kettenis <kettenis@openbsd.org>
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> Signed-off-by: Marc Zyngier <maz@kernel.org>
> Link: https://lore.kernel.org/r/20210520171310.772-3-mark.kettenis@xs4all.nl
> ---
>   arch/arm64/boot/dts/apple/t8103.dtsi | 83 ++++++++++++++++++++++++++++
>   1 file changed, 83 insertions(+)
> 
> diff --git a/arch/arm64/boot/dts/apple/t8103.dtsi b/arch/arm64/boot/dts/apple/t8103.dtsi
> index a1e22a2ea2e5..503a76fc30e6 100644
[snip]

Looks good. Can you resend just this patch with the apple,npins 
properties added? Once that's settled in the binding (which seems to 
just be waiting on some linter issues) I can merge this and the rest of 
the DT changes through my tree.

-- 
Hector Martin (marcan@marcan.st)
Public Key: https://mrcn.st/pub

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH v5 11/14] arm64: apple: Add PCIe node
  2021-09-29 16:38 ` [PATCH v5 11/14] arm64: apple: Add PCIe node Marc Zyngier
@ 2021-10-07 16:01   ` Hector Martin
  0 siblings, 0 replies; 32+ messages in thread
From: Hector Martin @ 2021-10-07 16:01 UTC (permalink / raw)
  To: Marc Zyngier, devicetree, linux-kernel, linux-pci
  Cc: Bjorn Helgaas, Rob Herring, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Alyssa Rosenzweig, Stan Skowronek,
	Mark Kettenis, Sven Peter, Robin Murphy, Joey Gouly,
	Joerg Roedel, kernel-team

On 30/09/2021 01.38, Marc Zyngier wrote:
> From: Mark Kettenis <kettenis@openbsd.org>
> 
> Add node corresponding to the apcie,t8103 node in the
> Apple device tree for the Mac mini (M1, 2020).
> 
> Power domain references and DART (IOMMU) references are left out
> at the moment and will be added once the appropriate bindings have
> been settled upon.
> 
> Acked-by: Marc Zyngier <maz@kernel.org>
> Signed-off-by: Mark Kettenis <kettenis@openbsd.org>
> Signed-off-by: Marc Zyngier <maz@kernel.org>
> Link: https://lore.kernel.org/r/20210921183420.436-5-kettenis@openbsd.org
> ---
>   arch/arm64/boot/dts/apple/t8103.dtsi | 63 ++++++++++++++++++++++++++++
>   1 file changed, 63 insertions(+)
> 

Acked-by: Hector Martin <marcan@marcan.st>

-- 
Hector Martin (marcan@marcan.st)
Public Key: https://mrcn.st/pub

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH v5 12/14] arm64: dts: apple: t8103: Add PCIe DARTs
  2021-09-29 16:38 ` [PATCH v5 12/14] arm64: dts: apple: t8103: Add PCIe DARTs Marc Zyngier
@ 2021-10-07 16:02   ` Hector Martin
  0 siblings, 0 replies; 32+ messages in thread
From: Hector Martin @ 2021-10-07 16:02 UTC (permalink / raw)
  To: Marc Zyngier, devicetree, linux-kernel, linux-pci
  Cc: Bjorn Helgaas, Rob Herring, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Alyssa Rosenzweig, Stan Skowronek,
	Mark Kettenis, Sven Peter, Robin Murphy, Joey Gouly,
	Joerg Roedel, kernel-team

On 30/09/2021 01.38, Marc Zyngier wrote:
> PCIe on the Apple M1 (aka t8103) requires the use of IOMMUs (aka
> DARTs). Add the three instances that deal with the internal PCIe
> ports and route each port's traffic through its DART.
> 
> Signed-off-by: Marc Zyngier <maz@kernel.org>
> ---
>   arch/arm64/boot/dts/apple/t8103.dtsi | 30 ++++++++++++++++++++++++++++
>   1 file changed, 30 insertions(+)
> 

Acked-by: Hector Martin <marcan@marcan.st>

-- 
Hector Martin (marcan@marcan.st)
Public Key: https://mrcn.st/pub

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH v5 13/14] arm64: dts: apple: t8103: Add root port interrupt routing
  2021-09-29 16:38 ` [PATCH v5 13/14] arm64: dts: apple: t8103: Add root port interrupt routing Marc Zyngier
@ 2021-10-07 16:03   ` Hector Martin
  0 siblings, 0 replies; 32+ messages in thread
From: Hector Martin @ 2021-10-07 16:03 UTC (permalink / raw)
  To: Marc Zyngier, devicetree, linux-kernel, linux-pci
  Cc: Bjorn Helgaas, Rob Herring, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Alyssa Rosenzweig, Stan Skowronek,
	Mark Kettenis, Sven Peter, Robin Murphy, Joey Gouly,
	Joerg Roedel, kernel-team

On 30/09/2021 01.38, Marc Zyngier wrote:
> Add the interrupt-map properties that are required for INTx
> signalling.
> 
> Tested-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
> Signed-off-by: Marc Zyngier <maz@kernel.org>
> ---
>   arch/arm64/boot/dts/apple/t8103.dtsi | 33 +++++++++++++++++++++++++---
>   1 file changed, 30 insertions(+), 3 deletions(-)
> 

Acked-by: Hector Martin <marcan@marcan.st>

-- 
Hector Martin (marcan@marcan.st)
Public Key: https://mrcn.st/pub

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH v5 14/14] arm64: dts: apple: j274: Expose PCI node for the Ethernet MAC address
  2021-09-29 16:38 ` [PATCH v5 14/14] arm64: dts: apple: j274: Expose PCI node for the Ethernet MAC address Marc Zyngier
@ 2021-10-07 16:03   ` Hector Martin
  0 siblings, 0 replies; 32+ messages in thread
From: Hector Martin @ 2021-10-07 16:03 UTC (permalink / raw)
  To: Marc Zyngier, devicetree, linux-kernel, linux-pci
  Cc: Bjorn Helgaas, Rob Herring, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Alyssa Rosenzweig, Stan Skowronek,
	Mark Kettenis, Sven Peter, Robin Murphy, Joey Gouly,
	Joerg Roedel, kernel-team

On 30/09/2021 01.38, Marc Zyngier wrote:
> At the moment, all the Minis running Linux have the same MAC
> address (00:10:18:00:00:00), which is a bit annoying.
> 
> Expose the PCI node corresponding to the Ethernet device, and
> declare a 'local-mac-address' property. The bootloader will update
> it (m1n1 already has the required feature). And if it doesn't, then
> the default value is already present in the DT.
> 
> This relies on forcing the bus number for each port so that the
> endpoints connected to them are correctly numbered (and keeps dtc
> quiet).
> 
> Signed-off-by: Marc Zyngier <maz@kernel.org>
> ---
>   arch/arm64/boot/dts/apple/t8103-j274.dts | 23 +++++++++++++++++++++++
>   1 file changed, 23 insertions(+)
> 

Acked-by: Hector Martin <marcan@marcan.st>

-- 
Hector Martin (marcan@marcan.st)
Public Key: https://mrcn.st/pub

^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2021-10-07 16:03 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-29 16:38 [PATCH v5 00/14] PCI: Add support for Apple M1 Marc Zyngier
2021-09-29 16:38 ` [PATCH v5 01/14] irqdomain: Make of_phandle_args_to_fwspec generally available Marc Zyngier
2021-09-29 16:38 ` [PATCH v5 02/14] of/irq: Allow matching of an interrupt-map local to an interrupt controller Marc Zyngier
2021-09-29 16:38 ` [PATCH v5 03/14] PCI: of: Allow matching of an interrupt-map local to a PCI device Marc Zyngier
2021-09-29 16:38 ` [PATCH v5 04/14] PCI: apple: Add initial hardware bring-up Marc Zyngier
2021-09-29 16:38 ` [PATCH v5 05/14] PCI: apple: Set up reference clocks when probing Marc Zyngier
2021-09-29 16:38 ` [PATCH v5 06/14] PCI: apple: Add INTx and per-port interrupt support Marc Zyngier
2021-09-29 16:38 ` [PATCH v5 07/14] PCI: apple: Implement MSI support Marc Zyngier
2021-09-29 16:38 ` [PATCH v5 08/14] iommu/dart: Exclude MSI doorbell from PCIe device IOVA range Marc Zyngier
2021-09-29 16:38 ` [PATCH v5 09/14] PCI: apple: Configure RID to SID mapper on device addition Marc Zyngier
2021-09-29 16:38 ` [PATCH v5 10/14] arm64: apple: Add pinctrl nodes Marc Zyngier
2021-09-29 19:05   ` Linus Walleij
2021-09-30  8:00     ` Marc Zyngier
2021-09-30  9:20       ` Mark Kettenis
2021-09-30 15:46       ` Linus Walleij
2021-10-07 16:00   ` Hector Martin
2021-09-29 16:38 ` [PATCH v5 11/14] arm64: apple: Add PCIe node Marc Zyngier
2021-10-07 16:01   ` Hector Martin
2021-09-29 16:38 ` [PATCH v5 12/14] arm64: dts: apple: t8103: Add PCIe DARTs Marc Zyngier
2021-10-07 16:02   ` Hector Martin
2021-09-29 16:38 ` [PATCH v5 13/14] arm64: dts: apple: t8103: Add root port interrupt routing Marc Zyngier
2021-10-07 16:03   ` Hector Martin
2021-09-29 16:38 ` [PATCH v5 14/14] arm64: dts: apple: j274: Expose PCI node for the Ethernet MAC address Marc Zyngier
2021-10-07 16:03   ` Hector Martin
2021-10-04  8:38 ` [PATCH v5 00/14] PCI: Add support for Apple M1 Lorenzo Pieralisi
2021-10-04  9:05   ` Marc Zyngier
2021-10-04 18:30     ` Linus Walleij
2021-10-07 15:43       ` Hector Martin
2021-10-04 19:51   ` Rob Herring
2021-10-04 20:42     ` Linus Walleij
2021-10-05  9:57       ` Marc Zyngier
2021-10-06  5:56       ` Michael Ellerman

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).