diff --git a/arch/arm64/boot/dts/apple/t6031-j516c.dts b/arch/arm64/boot/dts/apple/t6031-j516c.dts index 562491755117f1..4d9e71ca938ce5 100644 --- a/arch/arm64/boot/dts/apple/t6031-j516c.dts +++ b/arch/arm64/boot/dts/apple/t6031-j516c.dts @@ -12,6 +12,7 @@ #include "t6031.dtsi" #include "t6031-dcp.dtsi" #include "t603x-j514-j516.dtsi" +#include "t6031-usb4.dtsi" / { compatible = "apple,j516c", "apple,t6031", "apple,arm-platform"; diff --git a/arch/arm64/boot/dts/apple/t6031-usb4.dtsi b/arch/arm64/boot/dts/apple/t6031-usb4.dtsi new file mode 100644 index 00000000000000..5194596d33599b --- /dev/null +++ b/arch/arm64/boot/dts/apple/t6031-usb4.dtsi @@ -0,0 +1,346 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * T6031 (M3 Max) USB4 PCIe tunnels on ATC0, ATC1 and ATC2, modelled on + * t6030-usb4.dtsi. + * + * Every value is from the J516C ADT (/arm-io/apciecN, dart-apciecN, + * apciecN-piodma, acioN). The register windows and tunables match T6030. + * The AIC numbers differ, and T6031 uses the four-cell, die-numbered AIC + * specifier. MSIs come from the ADT's shared window at AIC 1854: the + * internal apcie0 owns its first 32 vectors (t6031-die0.dtsi) and the tunnel + * hosts take the next three 32-vector slices: ATC0 0x20, ATC1 0x40, ATC2 0x60. + * + * m1n1 fills apple,tunable-{rc,fabric,debug} through the usb4_N_pcie alias, + * the root port's apple,tunable, and apple,tunable-pcie-adapter through + * usb4_N_pcie_adapter. No bootloader fills the DART and OE fabric tunables, + * so they are carried here. + */ + +/ { + aliases { + usb4_0_pcie = &usb4_0_pcie; + usb4_0_pcie_adapter = &usb4_0_acio; + usb4_1_pcie = &usb4_1_pcie; + usb4_1_pcie_adapter = &usb4_1_acio; + usb4_2_pcie = &usb4_2_pcie; + usb4_2_pcie_adapter = &usb4_2_acio; + }; +}; + +&usb4_0_acio { + /* + * ADT acioN reg[5] is the PCIe adapter window m1n1 tunes. Unlike + * T6030 there is no "cpu" window: the T6031 ACIO uses the t8103 + * start sequence. + */ + reg = <0x7 0x01ac0000 0x0 0xc000>, + <0x7 0x01080000 0x0 0x20000>, + <0x7 0x01e44000 0x0 0x4000>; + reg-names = "rc", "sram", "pcie-adapter"; + power-domains = <&ps_atc0_cio>, <&ps_atc0_cio_pcie>, + <&ps_atc0_cio_usb>, <&ps_atc0_pcie>; + post-init-providers = <&ps_atc0_cio>, <&ps_atc0_cio_pcie>, + <&ps_atc0_cio_usb>, <&ps_atc0_pcie>; + apple,pcie-tunnel = <&usb4_0_pcie_tunnel>; +}; + +&usb4_1_acio { + /* + * ADT acioN reg[5] is the PCIe adapter window m1n1 tunes. Unlike + * T6030 there is no "cpu" window: the T6031 ACIO uses the t8103 + * start sequence. + */ + reg = <0xb 0x01ac0000 0x0 0xc000>, + <0xb 0x01080000 0x0 0x20000>, + <0xb 0x01e44000 0x0 0x4000>; + reg-names = "rc", "sram", "pcie-adapter"; + power-domains = <&ps_atc1_cio>, <&ps_atc1_cio_pcie>, + <&ps_atc1_cio_usb>, <&ps_atc1_pcie>; + post-init-providers = <&ps_atc1_cio>, <&ps_atc1_cio_pcie>, + <&ps_atc1_cio_usb>, <&ps_atc1_pcie>; + apple,pcie-tunnel = <&usb4_1_pcie_tunnel>; +}; + +&usb4_2_acio { + /* + * ADT acioN reg[5] is the PCIe adapter window m1n1 tunes. Unlike + * T6030 there is no "cpu" window: the T6031 ACIO uses the t8103 + * start sequence. + */ + reg = <0xf 0x01ac0000 0x0 0xc000>, + <0xf 0x01080000 0x0 0x20000>, + <0xf 0x01e44000 0x0 0x4000>; + reg-names = "rc", "sram", "pcie-adapter"; + power-domains = <&ps_atc2_cio>, <&ps_atc2_cio_pcie>, + <&ps_atc2_cio_usb>, <&ps_atc2_pcie>; + post-init-providers = <&ps_atc2_cio>, <&ps_atc2_cio_pcie>, + <&ps_atc2_cio_usb>, <&ps_atc2_pcie>; + apple,pcie-tunnel = <&usb4_2_pcie_tunnel>; +}; + +/ { + usb4_0_pcie_tunnel: usb4-pcie-tunnel-0 { + #address-cells = <2>; + #size-cells = <2>; + ranges; + nonposted-mmio; + /* Preserve the SoC DMA window after moving the virtual container. */ + dma-ranges = <0 0 0 0 0xffffffff 0xffffc000>; + + usb4_0_pcie_dart: iommu@721008000 { + compatible = "apple,t6031-dart", "apple,t8110-dart"; + reg = <0x7 0x21008000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = ; + #iommu-cells = <1>; + /* ADT dart-apciec0 dart-tunables-instance-0 */ + apple,tunable = + <0x20c 0x800001b7 0x800001b7>, + <0x220 0xf0f0f 0xf0f0f>, + <0x224 0xffffff 0x80808>, + <0x300 0x1f31 0x1>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x318 0x1f31 0x1>, + <0x320 0x3ffffffc 0x1f00000>, + <0x328 0x3ffffffc 0x1f0bffc>; + }; + + usb4_0_pcie: pcie@730000000 { + compatible = "apple,t8122-pciec", "apple,t8103-pciec"; + device_type = "pci"; + reg = <0x7 0x30000000 0x0 0x10000000>, + <0x7 0x20000000 0x0 0x4000>, + <0x7 0x21000000 0x0 0x8000>, + <0x7 0x20004000 0x0 0x4000>, + <0x7 0x20200000 0x0 0x4000>, + <0x7 0x21010000 0x0 0x4000>, + <0x7 0x20008000 0x0 0x4000>, + <0x7 0x2100c000 0x0 0x4000>; + reg-names = "config", "rc", "port0", "fabric", + "debug", "ltssm", "oe-fabric", "intr2axi"; + interrupt-parent = <&aic>; + interrupts = ; + power-domains = <&ps_atc0_cio_pcie>; + apple,pciec-kernel-init; + /* ADT apciec0-piodma atc-apcie-oe-fabric-tunables */ + apple,tunable-oe-fabric = + <0x4 0x70007 0x40004>, + <0x8 0x1 0x1>, + <0xc 0x1 0x1>, + <0x10 0x801f 0x4>, + <0x18 0x801f 0x4>, + <0x20 0x801f 0x4>; + msi-controller; + msi-parent = <&usb4_0_pcie>; + msi-ranges = <&aic AIC_IRQ 0 (1854 + 0x20) IRQ_TYPE_EDGE_RISING 32>; + apple,msi-vector-base = <0x20>; + iommu-map = <0x0 &usb4_0_pcie_dart 0x0 0x40>; + iommu-map-mask = <0x3f>; + bus-range = <0x0 0x7f>; + #address-cells = <3>; + #size-cells = <2>; + ranges = <0x43000000 0x8 0x0 + 0x8 0x0 0x2 0x0>, + <0x02000000 0x0 0x100000 + 0xa 0x100000 0x0 0x3ff00000>, + <0x42000000 0x0 0x40000000 + 0xa 0x40000000 0x0 0x40000000>; + + usb4_0_pcie_port: pci@0,0 { + device_type = "pci"; + reg = <0x0 0x0 0x0 0x0 0x0>; + external-facing; + /* apple,tunable is filled by the bootloader */ + #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 &usb4_0_pcie_port 0 0 0 0>, + <0 0 0 2 &usb4_0_pcie_port 0 0 0 1>, + <0 0 0 3 &usb4_0_pcie_port 0 0 0 2>, + <0 0 0 4 &usb4_0_pcie_port 0 0 0 3>; + }; + }; + }; +}; + +/ { + usb4_1_pcie_tunnel: usb4-pcie-tunnel-1 { + #address-cells = <2>; + #size-cells = <2>; + ranges; + nonposted-mmio; + /* Preserve the SoC DMA window after moving the virtual container. */ + dma-ranges = <0 0 0 0 0xffffffff 0xffffc000>; + + usb4_1_pcie_dart: iommu@b21008000 { + compatible = "apple,t6031-dart", "apple,t8110-dart"; + reg = <0xb 0x21008000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = ; + #iommu-cells = <1>; + /* ADT dart-apciec1 dart-tunables-instance-0 */ + apple,tunable = + <0x20c 0x800001b7 0x800001b7>, + <0x220 0xf0f0f 0xf0f0f>, + <0x224 0xffffff 0x80808>, + <0x300 0x1f31 0x1>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x318 0x1f31 0x1>, + <0x320 0x3ffffffc 0x1f00000>, + <0x328 0x3ffffffc 0x1f0bffc>; + }; + + usb4_1_pcie: pcie@b30000000 { + compatible = "apple,t8122-pciec", "apple,t8103-pciec"; + device_type = "pci"; + reg = <0xb 0x30000000 0x0 0x10000000>, + <0xb 0x20000000 0x0 0x4000>, + <0xb 0x21000000 0x0 0x8000>, + <0xb 0x20004000 0x0 0x4000>, + <0xb 0x20200000 0x0 0x4000>, + <0xb 0x21010000 0x0 0x4000>, + <0xb 0x20008000 0x0 0x4000>, + <0xb 0x2100c000 0x0 0x4000>; + reg-names = "config", "rc", "port0", "fabric", + "debug", "ltssm", "oe-fabric", "intr2axi"; + interrupt-parent = <&aic>; + interrupts = ; + power-domains = <&ps_atc1_cio_pcie>; + apple,pciec-kernel-init; + /* ADT apciec1-piodma atc-apcie-oe-fabric-tunables */ + apple,tunable-oe-fabric = + <0x4 0x70007 0x40004>, + <0x8 0x1 0x1>, + <0xc 0x1 0x1>, + <0x10 0x801f 0x4>, + <0x18 0x801f 0x4>, + <0x20 0x801f 0x4>; + msi-controller; + msi-parent = <&usb4_1_pcie>; + msi-ranges = <&aic AIC_IRQ 0 (1854 + 0x40) IRQ_TYPE_EDGE_RISING 32>; + apple,msi-vector-base = <0x40>; + iommu-map = <0x0 &usb4_1_pcie_dart 0x0 0x40>; + iommu-map-mask = <0x3f>; + bus-range = <0x0 0x7f>; + #address-cells = <3>; + #size-cells = <2>; + ranges = <0x43000000 0xc 0x0 + 0xc 0x0 0x2 0x0>, + <0x02000000 0x0 0x100000 + 0xe 0x100000 0x0 0x3ff00000>, + <0x42000000 0x0 0x40000000 + 0xe 0x40000000 0x0 0x40000000>; + + usb4_1_pcie_port: pci@0,0 { + device_type = "pci"; + reg = <0x0 0x0 0x0 0x0 0x0>; + external-facing; + /* apple,tunable is filled by the bootloader */ + #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 &usb4_1_pcie_port 0 0 0 0>, + <0 0 0 2 &usb4_1_pcie_port 0 0 0 1>, + <0 0 0 3 &usb4_1_pcie_port 0 0 0 2>, + <0 0 0 4 &usb4_1_pcie_port 0 0 0 3>; + }; + }; + }; +}; + +/ { + usb4_2_pcie_tunnel: usb4-pcie-tunnel-2 { + #address-cells = <2>; + #size-cells = <2>; + ranges; + nonposted-mmio; + /* Preserve the SoC DMA window after moving the virtual container. */ + dma-ranges = <0 0 0 0 0xffffffff 0xffffc000>; + + usb4_2_pcie_dart: iommu@f21008000 { + compatible = "apple,t6031-dart", "apple,t8110-dart"; + reg = <0xf 0x21008000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = ; + #iommu-cells = <1>; + /* ADT dart-apciec2 dart-tunables-instance-0 */ + apple,tunable = + <0x20c 0x800001b7 0x800001b7>, + <0x220 0xf0f0f 0xf0f0f>, + <0x224 0xffffff 0x80808>, + <0x300 0x1f31 0x1>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x318 0x1f31 0x1>, + <0x320 0x3ffffffc 0x1f00000>, + <0x328 0x3ffffffc 0x1f0bffc>; + }; + + usb4_2_pcie: pcie@f30000000 { + compatible = "apple,t8122-pciec", "apple,t8103-pciec"; + device_type = "pci"; + reg = <0xf 0x30000000 0x0 0x10000000>, + <0xf 0x20000000 0x0 0x4000>, + <0xf 0x21000000 0x0 0x8000>, + <0xf 0x20004000 0x0 0x4000>, + <0xf 0x20200000 0x0 0x4000>, + <0xf 0x21010000 0x0 0x4000>, + <0xf 0x20008000 0x0 0x4000>, + <0xf 0x2100c000 0x0 0x4000>; + reg-names = "config", "rc", "port0", "fabric", + "debug", "ltssm", "oe-fabric", "intr2axi"; + interrupt-parent = <&aic>; + interrupts = ; + power-domains = <&ps_atc2_cio_pcie>; + apple,pciec-kernel-init; + /* ADT apciec2-piodma atc-apcie-oe-fabric-tunables */ + apple,tunable-oe-fabric = + <0x4 0x70007 0x40004>, + <0x8 0x1 0x1>, + <0xc 0x1 0x1>, + <0x10 0x801f 0x4>, + <0x18 0x801f 0x4>, + <0x20 0x801f 0x4>; + msi-controller; + msi-parent = <&usb4_2_pcie>; + msi-ranges = <&aic AIC_IRQ 0 (1854 + 0x60) IRQ_TYPE_EDGE_RISING 32>; + apple,msi-vector-base = <0x60>; + iommu-map = <0x0 &usb4_2_pcie_dart 0x0 0x40>; + iommu-map-mask = <0x3f>; + bus-range = <0x0 0x7f>; + #address-cells = <3>; + #size-cells = <2>; + ranges = <0x43000000 0x10 0x0 + 0x10 0x0 0x2 0x0>, + <0x02000000 0x0 0x100000 + 0x12 0x100000 0x0 0x3ff00000>, + <0x42000000 0x0 0x40000000 + 0x12 0x40000000 0x0 0x40000000>; + + usb4_2_pcie_port: pci@0,0 { + device_type = "pci"; + reg = <0x0 0x0 0x0 0x0 0x0>; + external-facing; + /* apple,tunable is filled by the bootloader */ + #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 &usb4_2_pcie_port 0 0 0 0>, + <0 0 0 2 &usb4_2_pcie_port 0 0 0 1>, + <0 0 0 3 &usb4_2_pcie_port 0 0 0 2>, + <0 0 0 4 &usb4_2_pcie_port 0 0 0 3>; + }; + }; + }; +}; diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c index 805ff1a8d084f2..d20f5dc8b2bb1a 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -1834,11 +1834,25 @@ static const struct msi_parent_ops apple_msi_parent_ops = { .init_dev_msi_info = apple_msi_init_dev_msi_info, }; -/* T6030 has one shared AIC MSI window, partitioned by its ADT bridges. */ -static bool apple_t6030_msi_slice_valid(u32 base, u32 count, u32 aic_irq) +/* + * T6030 and T6031 have one shared 512-vector AIC MSI window, partitioned by + * their ADT bridges. Only its first AIC number differs. Returns 0 on other + * SoCs. + */ +static u32 apple_t603x_msi_window(void) +{ + if (of_machine_is_compatible("apple,t6030")) + return 1342; + if (of_machine_is_compatible("apple,t6031")) + return 1854; + return 0; +} + +static bool apple_t603x_msi_slice_valid(u32 window, u32 base, u32 count, + u32 aic_irq) { return (base == 0x20 || base == 0x40 || base == 0x60) && - count == 32 && aic_irq == 1342 + base; + count == 32 && aic_irq == window + base; } static int apple_msi_init(struct apple_pcie *pcie) @@ -1872,11 +1886,13 @@ static int apple_msi_init(struct apple_pcie *pcie) * entry to the corresponding shared-window vector. */ if (pcie->hw == &t8122_pciec_hw) { + u32 window = apple_t603x_msi_window(); struct resource ecam; + unsigned int irq; u32 expected_base; - /* These ECAM apertures identify the three T6030 ADT bridges. */ - if (!of_machine_is_compatible("apple,t6030") || + /* These ECAM apertures identify the three T6030/T6031 ADT bridges. */ + if (!window || of_address_to_resource(to_of_node(fwnode), 0, &ecam)) goto invalid_slice; switch (ecam.start) { @@ -1892,15 +1908,25 @@ static int apple_msi_init(struct apple_pcie *pcie) default: goto invalid_slice; } - if (args.args_count != 3 || args.args[0] != 0 || - args.args[2] != IRQ_TYPE_EDGE_RISING) + /* + * T6030's AIC takes . T6031's takes + * , and every tunnel host is on die 0. + */ + if (args.args_count == 3) + irq = 1; + else if (args.args_count == 4 && args.args[1] == 0) + irq = 2; + else + goto invalid_slice; + if (args.args[0] != 0 || + args.args[irq + 1] != IRQ_TYPE_EDGE_RISING) goto invalid_slice; ret = of_property_read_u32(to_of_node(fwnode), "apple,msi-vector-base", &pcie->msi_vector_base); if (!of_find_property(to_of_node(fwnode), "apple,msi-vector-base", NULL) && - args.args[1] == 1342 && pcie->nvecs == 512) { + args.args[irq] == window && pcie->nvecs == 512) { /* * Old experimental boot DTs exposed the global window to * each host. Correct it here so old recovery kernels can @@ -1908,15 +1934,15 @@ static int apple_msi_init(struct apple_pcie *pcie) */ pcie->msi_vector_base = expected_base; pcie->nvecs = 32; - args.args[1] += expected_base; + args.args[irq] += expected_base; dev_info(pcie->dev, "correcting legacy MSI window to IRQ %u count 32\n", - args.args[1]); + args.args[irq]); } else if (ret) { goto invalid_slice; } if (pcie->msi_vector_base != expected_base || - !apple_t6030_msi_slice_valid(pcie->msi_vector_base, - pcie->nvecs, args.args[1])) + !apple_t603x_msi_slice_valid(window, pcie->msi_vector_base, + pcie->nvecs, args.args[irq])) goto invalid_slice; } @@ -3246,9 +3272,12 @@ int apple_pcie_tunnel_prepare(struct device *dev, struct device_node *tunnel) pcie->dev = dev; pcie->hw = match->data; - /* Keep the previous fallback on unqualified M3-family machines. */ + /* + * Keep the previous fallback on M3-family machines other than T6030 + * and T6031, the two with a known MSI window. + */ if (pcie->hw == &t8122_pciec_hw && - !of_machine_is_compatible("apple,t6030") && + !apple_t603x_msi_window() && of_device_is_compatible(dev->of_node, "apple,t8103-pciec")) pcie->hw = &t8103_pciec_hw; pcie->kernel_init = kernel_init;