diff --git a/arch/arm64/boot/dts/apple/t8132-usb4.dtsi b/arch/arm64/boot/dts/apple/t8132-usb4.dtsi index be35c15c9e9ba..7a800738401f8 100644 --- a/arch/arm64/boot/dts/apple/t8132-usb4.dtsi +++ b/arch/arm64/boot/dts/apple/t8132-usb4.dtsi @@ -77,13 +77,18 @@ nonposted-mmio; status = "disabled"; + /* + * No power-domains: the router populates its DART after it has powered + * its own states, and the native CIO sleep powers them off with the DART + * saved. A DART in ps_atc0_cio would hold that state on through the + * NHI's noirq suspend (it suspends after the NHI), and the sleep fails. + */ usb4_0_dart: iommu@a80000 { compatible = "apple,t8132-dart", "apple,t8110-dart"; reg = <0xa80000 0x20000>; interrupt-parent = <&aic>; interrupts = ; #iommu-cells = <5>; - power-domains = <&ps_atc0_cio>; }; usb4_0_nhi: nhi@f00000 { @@ -194,13 +199,18 @@ nonposted-mmio; status = "disabled"; + /* + * No power-domains: the router populates its DART after it has powered + * its own states, and the native CIO sleep powers them off with the DART + * saved. A DART in ps_atc1_cio would hold that state on through the + * NHI's noirq suspend (it suspends after the NHI), and the sleep fails. + */ usb4_1_dart: iommu@a80000 { compatible = "apple,t8132-dart", "apple,t8110-dart"; reg = <0xa80000 0x20000>; interrupt-parent = <&aic>; interrupts = ; #iommu-cells = <5>; - power-domains = <&ps_atc1_cio>; }; usb4_1_nhi: nhi@f00000 { diff --git a/scripts/dtc/apple-dart-pd-check-test.py b/scripts/dtc/apple-dart-pd-check-test.py index adab86a6e6657..00737ba3444cf 100755 --- a/scripts/dtc/apple-dart-pd-check-test.py +++ b/scripts/dtc/apple-dart-pd-check-test.py @@ -174,6 +174,49 @@ def test_disabled_dart_of_an_enabled_user_fails(self): self.assertIn("t8112-j413 /soc/iommu@5000 dart_x apple,t8110-dart disabled: " "power domain /soc/power-controller@3000 is disabled (new)", result.stdout) + ROUTER = ('acio@5000 { compatible = "apple,t8103-usb4-acio"; %s ' + '#address-cells = <1>; #size-cells = <0>; ' + 'dart_x: iommu@a00 { compatible = "apple,t8110-dart"; #iommu-cells = <1>; }; ' + 'nhi@b00 { iommus = <&dart_x 0>; }; };') + + def test_dart_inside_a_powered_device_is_exempt(self): + # A USB4 router's DART: its driver populates it after powering its domains. + router = self.ROUTER % "power-domains = <&ps_x>;" + self.dtb(self.head, "t8112-j413", dts("j413", "t8112", DOMAIN, GAP, router)) + result = self.check() + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + self.assertIn("new: 0", result.stderr) + report = self.check("--report") + self.assertIn("/soc/acio@5000/iommu@a00 dart_x apple,t8110-dart okay: " + "exempt (inside /soc/acio@5000)", report.stdout) + + def test_dart_inside_a_device_without_domains_fails(self): + router = self.ROUTER % "" + self.dtb(self.head, "t8112-j413", dts("j413", "t8112", DOMAIN, GAP, router)) + result = self.check() + self.assertEqual(result.returncode, 1, result.stdout + result.stderr) + self.assertIn("/soc/acio@5000/iommu@a00 dart_x apple,t8110-dart okay: " + "no power-domains (new)", result.stdout) + + def test_dart_inside_a_device_on_a_disabled_domain_fails(self): + disabled = DOMAIN.replace("{", '{ status = "disabled";') + router = self.ROUTER % "power-domains = <&ps_x>;" + self.dtb(self.head, "t8112-j413", dts("j413", "t8112", disabled, GAP, router)) + result = self.check() + self.assertEqual(result.returncode, 1, result.stdout + result.stderr) + self.assertIn("/soc/acio@5000/iommu@a00 dart_x apple,t8110-dart okay: " + "parent's power domain /soc/power-controller@3000 is disabled (new)", + result.stdout) + + def test_dart_inside_a_powered_bus_is_not_exempt(self): + # A simple-bus is populated by platform code, not by a driver. + bus = self.ROUTER.replace('"apple,t8103-usb4-acio"', '"simple-bus"') % \ + "power-domains = <&ps_x>;" + self.dtb(self.head, "t8112-j413", dts("j413", "t8112", DOMAIN, GAP, bus)) + result = self.check() + self.assertEqual(result.returncode, 1, result.stdout + result.stderr) + self.assertIn("no power-domains (new)", result.stdout) + def test_without_baseline_every_gap_fails(self): result = subprocess.run([sys.executable, str(CHECKER), "--dtb-dir", str(self.head)], text=True, capture_output=True) diff --git a/scripts/dtc/apple-dart-pd-check.py b/scripts/dtc/apple-dart-pd-check.py index 59aa7e64947a0..18d50c87985f1 100755 --- a/scripts/dtc/apple-dart-pd-check.py +++ b/scripts/dtc/apple-dart-pd-check.py @@ -14,7 +14,11 @@ block is off as a whole, which is consistent. Exempt: the DARTs of the SEP and of the AOP. Those coprocessors run from -before the handoff on states the AP never switches off. +before the handoff on states the AP never switches off. Also exempt: a DART +that is a child of a device node (not a bus) with power-domains of its own, +such as a USB4 router's. Its parent's driver populates it after powering the +parent's domains, so it is covered by them; the parent's domains must then be +enabled. Install python3-libfdt (or pylibfdt) to read DTBs. Labels are shown when the DTBs were built with DTC_FLAGS=-@. @@ -36,6 +40,7 @@ DART = re.compile(r"apple,.*dart") SOC = re.compile(r"apple,[st]\d{4}$") +BUSES = ("simple-bus", "simple-pm-bus", "simple-mfd", "isa") EXEMPT = ( (re.compile(r"apple,sep$"), "SEP"), (re.compile(r"apple,(t\d+-)?aop$"), "AOP"), @@ -115,6 +120,28 @@ def iommu_cells(offset): consumers.setdefault(phandles[spec[i + 1]], []).append(offset) i += 3 + iommu_cells(phandles[spec[i + 1]]) + def domain_providers(offset): + domains = cells(prop(offset, "power-domains")) + i = 0 + while i < len(domains): + provider = phandles.get(domains[i]) + if provider is None: + break + yield provider + n = cells(prop(provider, "#power-domain-cells")) + i += 1 + (n[0] if n else 0) + + def disabled_domains(offset): + return [nodes[p] for p in domain_providers(offset) if status(p) != "okay"] + + def powered_device(offset): + """A device node (not a bus) with power domains of its own: platform + code does not populate its children, its driver does.""" + compatible = strings(prop(offset, "compatible")) + return (offset != 0 and bool(compatible) and + not any(c in BUSES for c in compatible) and + bool(cells(prop(offset, "power-domains")))) + for offset, path in nodes.items(): compatible = strings(prop(offset, "compatible")) if not any(DART.match(c) for c in compatible): @@ -130,6 +157,13 @@ def iommu_cells(offset): for c in strings(prop(o, "compatible"))] why = [name for pattern, name in EXEMPT if any(pattern.match(c) for c in users)] problem = "exempt (%s)" % why[0] if why else "no power-domains" + parent = offsets[path.rsplit("/", 1)[0] or "/"] + if not why and powered_device(parent): + # The parent device's driver populates this DART once it has + # powered its own domains; it is never probed on its own. + bad = disabled_domains(parent) + problem = ("parent's power domain %s is disabled" % bad[0] if bad else + "exempt (inside %s)" % nodes[parent]) yield path, label, compatible[0], status(offset), problem continue i = 0