Skip to content

apple-sleep: don't let the debug link's cut wake the sleep (debug rig only) - #1374

Closed
DjDeveloperr wants to merge 7 commits into
fix/t8140-slpddr-coproc-crashfrom
fix/apple-sleep-debug-cut-wakes
Closed

DjDeveloperr wants to merge 7 commits into
fix/t8140-slpddr-coproc-crashfrom
fix/apple-sleep-debug-cut-wakes

Conversation

@DjDeveloperr

Copy link
Copy Markdown
Contributor

On a debug cable, the sleep driver cold-resets the debug port's controller to end the KIS link. The SMC takes that as a cable pulled and plugged back. On a J700 it woke the AP right after the commit in all 223 retained sleeps that sent the reset, with USB-C_plug or acdetach in MBSW. All 154 sleeps without the reset ran to their alarm. Without a debug cable there's no link and no cut, so this only affects the rig.

  • macsmc: when this sleep will cut the link, the SMC is warned (slpw) only after the cut, with macOS's 770 ms before slpa.
  • Backstop: if the cut's own port events still wake the sleep, the machine goes back to sleep as a dark wake. That needs all three: only the SMC's sources woke the SoC, MBSW has only acattach/acdetach/USB-C_plug, and this sleep sent the reset. For it, macsmc-input refuses the next sleep only for a lid that opened, and tipd rearms the link only at a full wake.

No wake source is masked. These are the random-wakes lane's four patches, written against #1313, ported to the generic apple-sleep driver.

Untested on hardware.

🤖 Generated with Claude Code

On a debug cable, the sleep driver cold-resets the debug port's
controller in the SMC's noirq suspend, to end the KIS link. The SMC
takes that as a cable pulled and plugged back. It had been warned of
the sleep (MBSE = slpw) at .prepare, and it woke the AP right after
the commit for USB-C_plug or acdetach. On a J700, 223 of 223 sleeps
that sent the reset woke 0.15 to 0.27 s after the commit, with the RTC
alarm 10 to 19 s away, though the outbox had been quiet for 500 ms
before the AP idle notice. All 154 sleeps that sent no reset ran to
their alarm.

macOS never resets a port controller around a sleep, and writes
nothing to the SMC then but MBSE and the AP power notices.

So when the debug link is up at .prepare, warn the SMC in the noirq
suspend instead, after the cut and its events, and leave macOS's
shortest measured gap, 770 ms, before slpa. A sleep without a debug
cable is unchanged.

Signed-off-by: Diljit Singh <hey@djdev.me>
…pened

A dark wake for a closed lid sleeps again, and .prepare refuses that
sleep if the lid reads open by then: the user opened it. A dark wake
can also come with the lid open, for the debug link's cut on a debug
cable. The lid reads open at .prepare there too, and the sleep would be
refused for a lid that never moved.

Note at the dark wake whether the lid was closed, and refuse only then.
A failed read keeps the old behaviour.

Signed-off-by: Diljit Singh <hey@djdev.me>
A dark wake sleeps again with user space still frozen. Rearming the
debug link in its .complete brought KIS back, and the next entry cut
it again, so a wake for the cut's own events would come again. Keep
the rearm pending until a wake that isn't dark. The setup after the
cold reset still runs.

Signed-off-by: Diljit Singh <hey@djdev.me>
…as a dark wake

If the SMC still wakes the AP for the cut's own events, sleep again
through the PM core's dark wake, as for a lid closing. That needs all
three: only the SMC's AIC sources woke the SoC, the wake record has
nothing but acattach, acdetach or USB-C_plug, and this sleep sent the
reset. The link then stays down, so the next entry doesn't cut it, and
runs to its alarm like the 154 J700 sleeps that sent no reset.

Any other source or reason gives a normal wake. Without a debug cable
there is no cut, so a charger plugged in during the sleep wakes the
machine as before.

Signed-off-by: Diljit Singh <hey@djdev.me>
…ug-cut-wakes

Brings in #1208's aop-bootargs host test fix. No conflicts.

Signed-off-by: Diljit Singh <hey@djdev.me>
…ug-cut-wakes

Brings in integration/aurora ac11649 (#1311, PCIe multi power domain
support) through #1208. No conflicts.

Signed-off-by: Diljit Singh <hey@djdev.me>
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Superseded by #1445 (merged as 2b05915); its changes are in integration/aurora. The debug-link cut handling is in drivers/mfd/macsmc.c, drivers/input/misc/macsmc-input.c and drivers/soc/apple/sleep.c.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant