Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions arch/arm64/boot/dts/apple/t8132-usb4.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <AIC_IRQ 1314 IRQ_TYPE_LEVEL_HIGH>;
#iommu-cells = <5>;
power-domains = <&ps_atc0_cio>;
};

usb4_0_nhi: nhi@f00000 {
Expand Down Expand Up @@ -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 = <AIC_IRQ 1376 IRQ_TYPE_LEVEL_HIGH>;
#iommu-cells = <5>;
power-domains = <&ps_atc1_cio>;
};

usb4_1_nhi: nhi@f00000 {
Expand Down
43 changes: 43 additions & 0 deletions scripts/dtc/apple-dart-pd-check-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
36 changes: 35 additions & 1 deletion scripts/dtc/apple-dart-pd-check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=-@.
Expand All @@ -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"),
Expand Down Expand Up @@ -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):
Expand All @@ -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
Expand Down
Loading