From 60d2415a0db63316af1c5a11ac5d5aae58bf30c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Sat, 14 Nov 2026 17:05:06 +0100 Subject: [PATCH 01/49] ci: mask the pattern list of unmatched-property dt-schema messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A "does not match any of the regexes" message lists every pattern the schema allows, vendor-prefixes.yaml included. A change that adds a vendor prefix lengthens that list, so each such warning the base already has is reported once as removed and once as new, and the check fails although no device tree changed. Mask the list the way phandle values already are. Signed-off-by: František Balázsy --- scripts/dtc/apple-dt-check.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/dtc/apple-dt-check.sh b/scripts/dtc/apple-dt-check.sh index 04b634e886427..820d8dc2daf41 100755 --- a/scripts/dtc/apple-dt-check.sh +++ b/scripts/dtc/apple-dt-check.sh @@ -2,7 +2,9 @@ # SPDX-License-Identifier: GPL-2.0-only # apple-dt-check.sh BASE HEAD WORKDIR: run CHECK_DTBS on every Apple device tree at BASE and at HEAD # and fail when HEAD has a warning BASE does not. Also runs dt_binding_check on every binding HEAD -# changes. Phandle values in the messages are masked, so renumbering is not a new warning. +# changes. Phandle values in the messages are masked, so renumbering is not a new warning, and so +# is the pattern list of a "does not match any of the regexes" message, which grows with every +# vendor prefix the bindings add. # Needs dtschema (dt-validate), clang/lld (LLVM=1), flex, bison. Prints a summary. set -u BASE=$1 HEAD=$2 W=$3 @@ -17,7 +19,7 @@ warnings() { # rev tag local rc=$? grep -E '\.dtb: |[Ww]arning|rror' "$W/$2.log" | grep -v '^ ' | sed -E "s#$t/##g; s#$o/##g" | - perl -pe 's{(\[\[[^:]*?\]\])}{(my $x = $1) =~ s/\d+/N/g; $x}ge; s{b\x27(?:\\.|[^\x27])*\x27}{b\x27N\x27}g' | + perl -pe 's{(\[\[[^:]*?\]\])}{(my $x = $1) =~ s/\d+/N/g; $x}ge; s{b\x27(?:\\.|[^\x27])*\x27}{b\x27N\x27}g; s{( not match any of the regexes): .*}{$1: ...}' | sort -u > "$W/$2.warn" echo "$2: make rc=$rc, $(wc -l < "$W/$2.warn") warning lines, $(echo $dtbs | wc -w) DTBs" return $rc From c8666fb370383324c0258316ff081a91f264c76e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Tue, 10 Nov 2026 16:34:02 +0100 Subject: [PATCH 02/49] dt-bindings: apple: T6040 sleep controller, ProRes, PCIe, ATC PHY, DP audio and USB4 properties MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Describe what the J616s (M4 Pro, T6040) sleep and restore paths read from the device tree: the T6040 sleep controller node, the T6041 ProRes compatible, the PCIe and ATC PHY properties used after a power loss, the DP audio and USB4 ACIO additions, nonposted-mmio on a PMGR block and the pin controller's apple,resume-restore-all. Signed-off-by: František Balázsy --- .../bindings/arm/apple/apple,pmgr.yaml | 2 + .../bindings/media/apple,prores.yaml | 6 +- .../devicetree/bindings/pci/apple,pcie.yaml | 2 +- .../bindings/phy/apple,t6040-atcphy.yaml | 28 +++++++ .../bindings/pinctrl/apple,pinctrl.yaml | 8 ++ .../bindings/power/apple,t6040-sleep.yaml | 80 +++++++++++++++++++ .../bindings/sound/apple,t6030-dpaudio.yaml | 2 + .../thunderbolt/apple,t8103-usb4-acio.yaml | 6 ++ 8 files changed, 132 insertions(+), 2 deletions(-) create mode 100644 Documentation/devicetree/bindings/power/apple,t6040-sleep.yaml diff --git a/Documentation/devicetree/bindings/arm/apple/apple,pmgr.yaml b/Documentation/devicetree/bindings/arm/apple/apple,pmgr.yaml index 91ae5a3ce1bca..4c736d06122dd 100644 --- a/Documentation/devicetree/bindings/arm/apple/apple,pmgr.yaml +++ b/Documentation/devicetree/bindings/arm/apple/apple,pmgr.yaml @@ -53,6 +53,8 @@ properties: reg: maxItems: 1 + nonposted-mmio: true + "#address-cells": const: 1 diff --git a/Documentation/devicetree/bindings/media/apple,prores.yaml b/Documentation/devicetree/bindings/media/apple,prores.yaml index 69be59afd4e70..827863013b202 100644 --- a/Documentation/devicetree/bindings/media/apple,prores.yaml +++ b/Documentation/devicetree/bindings/media/apple,prores.yaml @@ -248,8 +248,12 @@ allOf: maxItems: 1 iommus: maxItems: 1 + resets: + description: + The shared codec reset. It also clears the + translations of the engine's DART, so a board may + leave it out and have a hung engine refused instead. required: - - resets - reg-names - if: properties: diff --git a/Documentation/devicetree/bindings/pci/apple,pcie.yaml b/Documentation/devicetree/bindings/pci/apple,pcie.yaml index 55d40f9a40cc7..dea7da061a73f 100644 --- a/Documentation/devicetree/bindings/pci/apple,pcie.yaml +++ b/Documentation/devicetree/bindings/pci/apple,pcie.yaml @@ -504,7 +504,7 @@ allOf: properties: reg: minItems: 8 - maxItems: 8 + maxItems: 9 interrupts: minItems: 6 maxItems: 6 diff --git a/Documentation/devicetree/bindings/phy/apple,t6040-atcphy.yaml b/Documentation/devicetree/bindings/phy/apple,t6040-atcphy.yaml index 3178de1a8b7e4..68ee0945b02d0 100644 --- a/Documentation/devicetree/bindings/phy/apple,t6040-atcphy.yaml +++ b/Documentation/devicetree/bindings/phy/apple,t6040-atcphy.yaml @@ -172,6 +172,29 @@ properties: $ref: "#/$defs/apple,tunable" description: USB2 host tunables, applied to the bank0 region. + apple,tunable-cio-lane0: + $ref: "#/$defs/apple,tunable" + description: > + Lane 0 receiver defaults for CIO (USB4/Thunderbolt) mode, applied to the + core region when the port enters USB4 or Thunderbolt. CIO mode is offered + only when both lane tables are present. + + apple,tunable-cio-lane1: + $ref: "#/$defs/apple,tunable" + description: Lane 1 receiver defaults for CIO mode, applied to the core region. + + apple,tunable-cio-uc-regs: + $ref: "#/$defs/apple,tunable" + description: Optional PHY microcontroller defaults for CIO mode, core region. + + apple,tunable-cio-lane0-eq: + $ref: "#/$defs/apple,tunable" + description: Optional lane 0 receiver equalization for CIO mode, core region. + + apple,tunable-cio-lane1-eq: + $ref: "#/$defs/apple,tunable" + description: Optional lane 1 receiver equalization for CIO mode, core region. + required: - compatible - reg @@ -199,6 +222,11 @@ allOf: mode-switch: false port: false ports: false + apple,tunable-cio-lane0: false + apple,tunable-cio-lane1: false + apple,tunable-cio-uc-regs: false + apple,tunable-cio-lane0-eq: false + apple,tunable-cio-lane1-eq: false additionalProperties: false diff --git a/Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml b/Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml index e2bec4d954de9..228151a45575d 100644 --- a/Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml +++ b/Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml @@ -69,6 +69,14 @@ properties: $ref: /schemas/types.yaml#/definitions/uint32 description: The number of pins in this GPIO controller. + apple,resume-restore-all: + type: boolean + description: + After a sleep that powers the block down, every pin's configuration is + written back, not only the pins a driver has claimed, as the vendor + firmware does for this block. The pins in gpio-reserved-ranges are left + as the wake found them. + gpio-reserved-ranges: true interrupts: diff --git a/Documentation/devicetree/bindings/power/apple,t6040-sleep.yaml b/Documentation/devicetree/bindings/power/apple,t6040-sleep.yaml new file mode 100644 index 0000000000000..29ab8c7267c18 --- /dev/null +++ b/Documentation/devicetree/bindings/power/apple,t6040-sleep.yaml @@ -0,0 +1,80 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/power/apple,t6040-sleep.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Apple T6040 system sleep controller + +maintainers: + - František Balázsy + +description: + The power states the platform checks before it lets the T6040 sleep engine take + the SoC down (the ADT's device-check-ps-b4-sleep table). Each entry names a + PMGR register block, the offset of a display pipe's CPU power state and the + offset of its last sub-block; the states in between are 8 bytes apart. + + The optional register blocks are the SoC words the entry and the wake write. + All of them are shared with the drivers that own them, and are touched only + once nothing blocks the sleep any more. + +properties: + compatible: + const: apple,t6040-sleep + + reg: + minItems: 2 + items: + - description: CPU start/stop block (pmgr + 0x88000) + - description: AON watchdog + - description: control words of the three CPU complexes + - description: SoC power gate, wake and retention voters + - description: clock generator, the clock mux park words + - description: SPMI controller of the PMU (boot stage, notify, hibernate) + - description: second SPMI controller's notify word + - description: MasterMini block with the S2R timer + - description: SOC-East retention and power words + - description: PMGR power words of the west axi2af bridges + - description: AOP global block, S2R control and wake masks + + reg-names: + minItems: 2 + items: + - const: cpu-start + - const: wdt + - const: cluster-ctl + - const: soc-pwrgate + - const: clkgen + - const: spmi0 + - const: spmi-a0 + - const: mastermini + - const: soc-east + - const: soc-ps + - const: aop-global + + apple,check-ps-b4-sleep: + $ref: /schemas/types.yaml#/definitions/phandle-array + items: + items: + - description: PMGR syscon + - description: offset of the pipe's CPU power state + - description: offset of its last sub-block's power state + + apple,check-ps-b4-sleep-names: + description: One name per apple,check-ps-b4-sleep entry. + +required: + - compatible + - apple,check-ps-b4-sleep + - apple,check-ps-b4-sleep-names + +additionalProperties: false + +examples: + - | + sleep-controller { + compatible = "apple,t6040-sleep"; + apple,check-ps-b4-sleep = <&pmgr_disp 0x0 0x58>; + apple,check-ps-b4-sleep-names = "disp"; + }; diff --git a/Documentation/devicetree/bindings/sound/apple,t6030-dpaudio.yaml b/Documentation/devicetree/bindings/sound/apple,t6030-dpaudio.yaml index 78dcee199f937..c730e4f46a020 100644 --- a/Documentation/devicetree/bindings/sound/apple,t6030-dpaudio.yaml +++ b/Documentation/devicetree/bindings/sound/apple,t6030-dpaudio.yaml @@ -50,6 +50,8 @@ properties: power-domains: maxItems: 1 + post-init-providers: true + ports: $ref: /schemas/graph.yaml#/properties/ports properties: diff --git a/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml b/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml index 562fb2f315e5c..b18a475f5a355 100644 --- a/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml +++ b/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml @@ -129,6 +129,12 @@ properties: phy-names: const: cio + apple,atc-phy: + $ref: /schemas/types.yaml#/definitions/phandle + description: + Type-C PHY of this router's port. On T6040 the router starts only while + that PHY is in CIO mode and tells it when it stops. + apple,pcie-tunnel: $ref: /schemas/types.yaml#/definitions/phandle description: From 12f467f6e307f7ac1792b518f2149378eb5dc3cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Tue, 10 Nov 2026 16:34:05 +0100 Subject: [PATCH 03/49] arm64: dts: apple: t6040: J616s sleep controller, ProRes, JPEG and DP audio MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Describe the T6040 sleep controller and enable ProRes, JPEG and DP audio on the J616s. Signed-off-by: František Balázsy --- arch/arm64/boot/dts/apple/t6040-j616s.dts | 108 ++++++++++++++++++++++ arch/arm64/boot/dts/apple/t6040.dtsi | 66 +++++++++++++ 2 files changed, 174 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t6040-j616s.dts b/arch/arm64/boot/dts/apple/t6040-j616s.dts index e81fb8b6b5d0d..2a1e83d454c7c 100644 --- a/arch/arm64/boot/dts/apple/t6040-j616s.dts +++ b/arch/arm64/boot/dts/apple/t6040-j616s.dts @@ -71,6 +71,15 @@ adj-height-mm = <216>; }; +/* + * The AOP firmware reports the lid angle to the SMC once a second on its own, + * and every report on this mailbox ends a suspend-to-idle period: keep its + * messages in the FIFO across system sleep. + */ +&aop_mbox { + apple,hold-rx-in-sleep; +}; + &aop_audio { apple,chassis-name = "J616"; }; @@ -388,3 +397,102 @@ &aes { status = "okay"; }; + +/* + * The ProRes encoder: the shared codec power state (below the always-on + * fabric domain), its DART and the PMP soc-device record SCODEC0 (27). + * No reset: the shared codec's reset also clears the DART's translations, + * so the driver refuses a hung engine instead. + */ +&ps_fab1_soc { + status = "okay"; +}; + +&ps_scodec { + status = "okay"; +}; + +&pmp_report { + pmp_report_scodec: report@1b { + compatible = "apple,t6041-pmp-v2-report-entry", + "apple,t6000-pmp-v2-report-entry"; + reg = <0x1b>; + label = "pmp-scodec"; + #power-domain-cells = <0>; + power-domains = <&ps_scodec>; + }; +}; + +&apr0_dart { + status = "okay"; +}; + +&apr0 { + power-domains = <&ps_scodec>, <&pmp_report_scodec>; + power-domain-names = "core", "perf"; + /delete-property/ resets; + status = "okay"; +}; + +/* + * The JPEG engines share the PMP soc-device record JPEG0 (26): hold it as + * their performance request while an engine runs. + */ +&pmp_report { + pmp_report_jpg: report@1a { + compatible = "apple,t6041-pmp-v2-report-entry", + "apple,t6000-pmp-v2-report-entry"; + reg = <0x1a>; + label = "pmp-jpg"; + #power-domain-cells = <0>; + power-domains = <&ps_jpg>; + }; +}; + +&jpeg0 { + power-domains = <&ps_jpg>, <&pmp_report_jpg>; + power-domain-names = "core", "perf"; +}; + +&jpeg1 { + power-domains = <&ps_jpg>, <&pmp_report_jpg>; + power-domain-names = "core", "perf"; +}; + +/* + * DP/HDMI audio: the clients behind dcpext0/dcpext1, their power states and + * the SIO the boot loader publishes. Neither side may hold the other at + * probe: audio needs the SIO only when a stream opens, and the external + * displays must come up whether the audio clients bind or not. Only + * properties are added to the display processors: their status belongs to + * the display gate. + */ +&ps_dpa_p { + status = "okay"; +}; + +&ps_dpa1 { + status = "okay"; +}; + +&ps_dpa2 { + status = "okay"; +}; + +&dpaudio1 { + post-init-providers = <&sio>; + status = "okay"; +}; + +&dpaudio2 { + post-init-providers = <&sio>; + status = "okay"; +}; + +&dcpext0 { + post-init-providers = <&dpaudio1>; +}; + +&dcpext1 { + post-init-providers = <&dpaudio2>; +}; diff --git a/arch/arm64/boot/dts/apple/t6040.dtsi b/arch/arm64/boot/dts/apple/t6040.dtsi index 2cc327c7a2f8f..3d657f7c9a6dd 100644 --- a/arch/arm64/boot/dts/apple/t6040.dtsi +++ b/arch/arm64/boot/dts/apple/t6040.dtsi @@ -9,6 +9,10 @@ /* Blocks and properties the T6041 tree does not describe yet. */ / { + aliases { + sio = &sio; + }; + opp_p0: opp-table-p0 { compatible = "operating-points-v2"; opp-shared; @@ -241,9 +245,71 @@ pmgr_disp: power-management@502290000 { compatible = "apple,t6041-pmgr", "apple,t8103-pmgr", "syscon", "simple-mfd"; reg = <0x5 0x02290000 0x0 0x4000>; + /* DISP_CPU's power word takes non-posted accesses (nGnRnE). */ + nonposted-mmio; #address-cells = <1>; #size-cells = <1>; }; + + sleep-controller { + compatible = "apple,t6040-sleep"; + /* + * The SoC blocks the (currently unreachable) commit and wake + * write, all shared read/write with their owning drivers and + * touched only once no blocker remains: + * cpu-start pmgr reg0 + 0x88000 (misc-cores): CPU start/stop + * wdt the AON watchdog, the sleep's WD2 safety net + * cluster-ctl 0x502820000: the three CPU complexes E/P0/P1 + * soc-pwrgate 0x50282c000: wake + CPM retention voters + * clkgen 0x500000000: the clk-mux park words + * spmi0 0x509014000: the PMU boot-stage + NOTIFY + go-hib + * spmi-a0 0x509188000: the second SPMI NOTIFY + * mastermini 0x508900000: the S2R timer at +0x4000 (the commit) + * soc-east 0x502280000: SOC-East retention + east power words + * soc-ps 0x502800000: the west axi2af power words + * aop-global 0x508004000: the S2R control + wake masks/status + * The handler refuses before touching any of them. + */ + reg = <0x5 0x02888000 0x0 0x20>, + <0x5 0x0836c000 0x0 0x4000>, + <0x5 0x02820000 0x0 0x20>, + <0x5 0x0282c000 0x0 0x1000>, + <0x5 0x00000000 0x0 0x80000>, + <0x5 0x09014000 0x0 0x1000>, + <0x5 0x09188000 0x0 0x1000>, + <0x5 0x08900000 0x0 0x8000>, + <0x5 0x02280000 0x0 0x1000>, + <0x5 0x02800000 0x0 0x1000>, + <0x5 0x08004000 0x0 0x1000>; + reg-names = "cpu-start", "wdt", "cluster-ctl", "soc-pwrgate", + "clkgen", "spmi0", "spmi-a0", "mastermini", + "soc-east", "soc-ps", "aop-global"; + /* + * ADT pmgr device-check-ps-b4-sleep (check-ps-b4-sleep = 0x1f): per + * display pipe its CPU and its last sub-block, 8 bytes apart. + */ + apple,check-ps-b4-sleep = <&pmgr_disp 0x0 0x58>, <&pmgr_aux 0x350 0x388>, + <&pmgr_aux 0x4a0 0x4d8>, <&pmgr_aux 0x4f0 0x528>, + <&pmgr_aux 0x2e8 0x320>; + apple,check-ps-b4-sleep-names = "disp", "dispext0", "dispext1", "dispext2", + "dispext3"; + /* + * ANS's storage PCIe (two ST lanes + shared PHY), for its sleep. The boot + * object (aura) publishes apple,apcie here plus the axi2af/cio3pll/ + * clkgen/phy-block/phy-ip windows and apple,tunable-* arrays onto the + * internal PCIe host (apple,t6020-pcie, identified by its "rc" + * reg-name) from the ADT /arm-io/apcie0 at boot, matching aurora + * #1208's single-lane t8140 shape. That publish is idempotent and + * returns early if apple,apcie is already present, so there must be NO + * static apple,apcie or apcie-storage node here -- a static one blocks + * the loader (seen on the J616s: a static apple,apcie made + * the driver see an empty node and refuse). Until the loader fills it, + * the driver NULL-guards every window and a real sleep with ANS stopped + * refuses (suspend-to-idle stays the default). The ST power words + * (ps_ans, ps_apcie_st0/st1, ps_apcie_sys_st0/st1) live in SOC-East and + * are driven by the controller's soc-east window, not from a node here. + */ + }; }; &pmc { From d7c68acf229ff5d46ea3c79a7104d1bdcebe9f75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Tue, 10 Nov 2026 18:12:27 +0100 Subject: [PATCH 04/49] arm64: dts: apple: t6040: give each USB4 router its Type-C PHY MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The T6040 ACIO driver starts a router only over its port's Type-C PHY in CIO mode and refuses to probe without apple,atc-phy, but the routers' nodes never named their PHY. With the J616s left back port's router enabled, ACIO0 failed to probe ("Missing apple,atc-phy"), and the three of them would on any board that enables them. Name atcphy0..2, the PHY at the same port as the router (ADT acioN atc-phy-parent), and make the property required for the T6040 router. Signed-off-by: František Balázsy --- .../bindings/thunderbolt/apple,t8103-usb4-acio.yaml | 1 + arch/arm64/boot/dts/apple/t6040-usb4.dtsi | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml b/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml index b18a475f5a355..c684093b994d9 100644 --- a/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml +++ b/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml @@ -291,6 +291,7 @@ allOf: - nhi@1f00000 - interrupts - interrupt-names + - apple,atc-phy else: required: - iommu@a80000 diff --git a/arch/arm64/boot/dts/apple/t6040-usb4.dtsi b/arch/arm64/boot/dts/apple/t6040-usb4.dtsi index cd3b2c21aca7a..13b50c18e50c0 100644 --- a/arch/arm64/boot/dts/apple/t6040-usb4.dtsi +++ b/arch/arm64/boot/dts/apple/t6040-usb4.dtsi @@ -36,6 +36,8 @@ pinctrl-names = "lstx"; pinctrl-0 = <&usb4_0_lstx_pins>; lstx-gpios = <&pinctrl_aop 49 GPIO_ACTIVE_HIGH>; + /* The router starts only over its port's Type-C PHY in CIO mode. */ + apple,atc-phy = <&atcphy0>; power-domains = <&ps_atc0_cio>, <&ps_atc0_cio_pcie>, <&ps_atc0_cio_usb>, <&ps_atc0_pcie>; thunderbolt-switch; @@ -133,6 +135,8 @@ pinctrl-names = "lstx"; pinctrl-0 = <&usb4_1_lstx_pins>; lstx-gpios = <&pinctrl_aop 51 GPIO_ACTIVE_HIGH>; + /* The router starts only over its port's Type-C PHY in CIO mode. */ + apple,atc-phy = <&atcphy1>; power-domains = <&ps_atc1_cio>, <&ps_atc1_cio_pcie>, <&ps_atc1_cio_usb>, <&ps_atc1_pcie>; thunderbolt-switch; @@ -230,6 +234,8 @@ pinctrl-names = "lstx"; pinctrl-0 = <&usb4_2_lstx_pins>; lstx-gpios = <&pinctrl_aop 53 GPIO_ACTIVE_HIGH>; + /* The router starts only over its port's Type-C PHY in CIO mode. */ + apple,atc-phy = <&atcphy2>; power-domains = <&ps_atc2_cio>, <&ps_atc2_cio_pcie>, <&ps_atc2_cio_usb>, <&ps_atc2_pcie>; thunderbolt-switch; From ff6a5d2ef2e03ab017a090225d969647b7636ea2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Tue, 10 Nov 2026 22:50:10 +0100 Subject: [PATCH 05/49] arm64: dts: apple: put every AP pin back after a T6040 S2R MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The arch/arm64/boot/dts/apple/t604x.dtsi part of "pinctrl: apple: put every AP pin back after a T6040 S2R", which goes with the device tree changes; the rest of that commit is with the sleep controller changes. The AP GPIO block needs the saved configuration of every pin back on the system wake, except the pins the ADT lists in no-restore-gpio-pins (190-192 on J616s). Linux put back only the pins it set up itself. A sleep that cuts the block's power then left the pins the boot loader set up for others at their reset values, among them the chip select of the internal panel's TCON bus; after the wake the display firmware powered the panel's rails and never saw it come up ("No device added after powering on the rails. HPD=0"). Mark the AP block apple,resume-restore-all with the ADT's no-restore list, snapshot every readable pin from the hardware at suspend_noirq and write back the ones that changed at resume_noirq, logging the pins that were not Linux's. Signed-off-by: František Balázsy --- arch/arm64/boot/dts/apple/t604x.dtsi | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t604x.dtsi b/arch/arm64/boot/dts/apple/t604x.dtsi index 3484262fa7a43..a032ea8b3b07f 100644 --- a/arch/arm64/boot/dts/apple/t604x.dtsi +++ b/arch/arm64/boot/dts/apple/t604x.dtsi @@ -1370,6 +1370,10 @@ #gpio-cells = <2>; gpio-ranges = <&pinctrl 0 0 200>; apple,npins = <200>; + /* ADT gpio0: every pin is put back after a sleep, except no-restore-gpio-pins. */ + apple,resume-restore-all; + /* Pins the firmware lists as no-restore */ + gpio-reserved-ranges = <190 3>; interrupt-controller; #interrupt-cells = <2>; From 3e320127b55bdb58dfc0b8f48d3b6b467d8a9f56 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Thu, 12 Nov 2026 18:14:11 +1100 Subject: [PATCH 06/49] arm64: dts: apple: name the T8140 driver instead of its pull request MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The arch/arm64/boot/dts/apple/t6040.dtsi part of "soc: apple: t6040-sleep: name the T8140 driver instead of its pull request", which goes with the device tree changes; the rest of that commit is with the sleep controller changes. Comments in the T6040 sleep code, the display driver and the T6040 device tree pointed at the T8140 sleep driver by a pull request number. Name the driver (sleep.c) or the T8140 instead, and drop the "currently unreachable" note on the sleep controller node. No functional change. Signed-off-by: Ryan Murray Signed-off-by: František Balázsy --- arch/arm64/boot/dts/apple/t6040.dtsi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t6040.dtsi b/arch/arm64/boot/dts/apple/t6040.dtsi index 3d657f7c9a6dd..d34974207ded0 100644 --- a/arch/arm64/boot/dts/apple/t6040.dtsi +++ b/arch/arm64/boot/dts/apple/t6040.dtsi @@ -254,7 +254,7 @@ sleep-controller { compatible = "apple,t6040-sleep"; /* - * The SoC blocks the (currently unreachable) commit and wake + * The SoC blocks the commit and wake * write, all shared read/write with their owning drivers and * touched only once no blocker remains: * cpu-start pmgr reg0 + 0x88000 (misc-cores): CPU start/stop @@ -298,8 +298,8 @@ * object (aura) publishes apple,apcie here plus the axi2af/cio3pll/ * clkgen/phy-block/phy-ip windows and apple,tunable-* arrays onto the * internal PCIe host (apple,t6020-pcie, identified by its "rc" - * reg-name) from the ADT /arm-io/apcie0 at boot, matching aurora - * #1208's single-lane t8140 shape. That publish is idempotent and + * reg-name) from the ADT /arm-io/apcie0 at boot, matching the + * single-lane t8140 shape. That publish is idempotent and * returns early if apple,apcie is already present, so there must be NO * static apple,apcie or apcie-storage node here -- a static one blocks * the loader (seen on the J616s: a static apple,apcie made From 152b2c075c7f4bc3ad1efb19343cddefd1c46396 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Thu, 12 Nov 2026 08:55:43 +0100 Subject: [PATCH 07/49] arm64: dts: apple: enable the sleep controller per board MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The arch/arm64/boot/dts/apple/t6040-j616s.dts, arch/arm64/boot/dts/apple/t6040.dtsi part of "arm64: dts: apple: t6040: enable the sleep controller per board", which goes with the device tree changes; the rest of that commit is with the sleep controller changes. The T6040 sleep controller's node is in the SoC's file, so every T6040 board has it, while its sleep has been run on the J616s alone. It maps fixed T6040 blocks and installs suspend operations that make deep the default state and then refuse it without t6040_sleep.allow_entry, which is of no use on a board nobody has tested, and distribution kernels build the controller. Disable the node in t6040.dtsi and enable it in t6040-j616s.dts. On the J614s and the J773s the controller no longer binds: suspend-to-idle stays their sleep, and the debugfs preflight file is gone there. The interrupt controller saved its configuration for a sleep on every apple,t6041-aic3 whenever the controller was built. Key that on the enabled node as well, so that the other machines with this AIC keep their suspend and hibernation paths as they were. Signed-off-by: František Balázsy --- arch/arm64/boot/dts/apple/t6040-j616s.dts | 5 +++++ arch/arm64/boot/dts/apple/t6040.dtsi | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/apple/t6040-j616s.dts b/arch/arm64/boot/dts/apple/t6040-j616s.dts index 2a1e83d454c7c..4cf87185fe811 100644 --- a/arch/arm64/boot/dts/apple/t6040-j616s.dts +++ b/arch/arm64/boot/dts/apple/t6040-j616s.dts @@ -84,6 +84,11 @@ apple,chassis-name = "J616"; }; +/* Suspend-to-RAM through the boot object has been tested on this board. */ +&t6040_sleep { + status = "okay"; +}; + &sound { compatible = "apple,j616-macaudio", "apple,macaudio"; model = "MacBook Pro J616"; diff --git a/arch/arm64/boot/dts/apple/t6040.dtsi b/arch/arm64/boot/dts/apple/t6040.dtsi index d34974207ded0..d2d5622ff64d0 100644 --- a/arch/arm64/boot/dts/apple/t6040.dtsi +++ b/arch/arm64/boot/dts/apple/t6040.dtsi @@ -251,7 +251,7 @@ #size-cells = <1>; }; - sleep-controller { + t6040_sleep: sleep-controller { compatible = "apple,t6040-sleep"; /* * The SoC blocks the commit and wake @@ -309,6 +309,8 @@ * (ps_ans, ps_apcie_st0/st1, ps_apcie_sys_st0/st1) live in SOC-East and * are driven by the controller's soc-east window, not from a node here. */ + /* Only on a board whose sleep has been tested. */ + status = "disabled"; }; }; From dd04dd7b1d85a85dc8b837b992ca22fca7398819 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Thu, 12 Nov 2026 09:11:07 +0100 Subject: [PATCH 08/49] dt-bindings: power: apple,t6040-sleep: describe the node and add apple,apcie MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The description spoke of what a driver does with the node. Say what the node is: the blocks an operating system at EL2 drives itself to suspend the T6040 to RAM, and the display power states that have to be off before it. The boot loader adds apple,apcie to the node, the PCIe host whose shared registers and tunables the storage controller's link needs after a sleep, as on the T8140. The binding did not allow it. The pipe list also lacked the description a vendor property needs, which the binding check reported. Signed-off-by: František Balázsy --- .../bindings/power/apple,t6040-sleep.yaml | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/Documentation/devicetree/bindings/power/apple,t6040-sleep.yaml b/Documentation/devicetree/bindings/power/apple,t6040-sleep.yaml index 29ab8c7267c18..820e0b636b1d2 100644 --- a/Documentation/devicetree/bindings/power/apple,t6040-sleep.yaml +++ b/Documentation/devicetree/bindings/power/apple,t6040-sleep.yaml @@ -9,15 +9,19 @@ title: Apple T6040 system sleep controller maintainers: - František Balázsy -description: - The power states the platform checks before it lets the T6040 sleep engine take - the SoC down (the ADT's device-check-ps-b4-sleep table). Each entry names a - PMGR register block, the offset of a display pipe's CPU power state and the - offset of its last sub-block; the states in between are 8 bytes apart. +description: | + What an operating system that runs at EL2, with no firmware below it to ask, + drives itself to suspend the T6040 to RAM and to bring it back: the CPU + start block, the always-on watchdog, the complex and power-gate words, the + PMU's SPMI controllers and the always-on timer that starts the SoC's sleep + engine. All of these register blocks are shared with the devices that own + them. Without the blocks a suspend can be checked, and not entered. - The optional register blocks are the SoC words the entry and the wake write. - All of them are shared with the drivers that own them, and are touched only - once nothing blocks the sleep any more. + The sleep engine waits for the display pipes, so the node lists the power + states that have to be off before a sleep, as the ADT's + device-check-ps-b4-sleep table does. Each entry names a PMGR register block, + the offset of a display pipe's CPU power state and the offset of its last + sub-block; the states in between are 8 bytes apart. properties: compatible: @@ -55,6 +59,9 @@ properties: apple,check-ps-b4-sleep: $ref: /schemas/types.yaml#/definitions/phandle-array + description: + The display pipes whose power states have to be off before a sleep, one + entry per pipe. items: items: - description: PMGR syscon @@ -64,6 +71,14 @@ properties: apple,check-ps-b4-sleep-names: description: One name per apple,check-ps-b4-sleep entry. + apple,apcie: + $ref: /schemas/types.yaml#/definitions/phandle + description: + The PCIe host whose shared registers and tunables the storage controller's + link depends on. The boot loader adds it, with those registers and + tunables on the host's node. Without it the storage controller can't be + stopped for a sleep. + required: - compatible - apple,check-ps-b4-sleep From 6e41315b7fddc5782a80e453d23ab4f8ab57f74a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Thu, 12 Nov 2026 09:11:07 +0100 Subject: [PATCH 09/49] MAINTAINERS: describe the T6040 part as it is MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The MAINTAINERS part of "soc: apple: sleep: describe the T6040 part as it is", which goes with the device tree changes; the rest of that commit is with the sleep controller changes. The file's opening comment still explained why the T6040 controller was a driver of its own next to the generic one, and several comments named functions the generic driver no longer has. Describe the part as it is now, with suspend-to-RAM offered only to a system booted with t6040_sleep.allow_entry=1, name the generic driver's functions, and say in sleep.c that a SoC may bring a part. List the private header next to the driver's sources. Signed-off-by: František Balázsy --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index 3f919f3e327f3..5cec0c882a568 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2136,6 +2136,7 @@ F: drivers/rtc/rtc-apple-pmu.c F: drivers/soc/apple/aop.rs F: drivers/soc/apple/mcc.c F: drivers/soc/apple/sleep*.c +F: drivers/soc/apple/sleep-internal.h F: drivers/tty/serial/apple_dockchannel* F: include/linux/soc/apple/pci-apple-piodma.h F: include/linux/soc/apple/sleep.h From 8842a1ff871e85d020756de3886a3c2a1c4b0a8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Thu, 12 Nov 2026 20:12:02 +0100 Subject: [PATCH 10/49] dt-bindings: display: Add Apple T6041 display power words MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The T6041 display coprocessors (apple,t6041-dcp, apple,t6041-dcpext) name an apple,display-power node whose "ps" and "pmc-dcp" windows hold the power-state words their driver lowers after it stops the firmware for a suspend-to-RAM and raises on the wake, and the display PMC word that counts the powered coprocessors. The boot loader publishes it with the compatible apple,t6041-display-power: one node over the east power manager block for the internal coprocessor, one over the west block that both external coprocessors name. Describe it, as apple,t8140-display-power.yaml does for T8140. Signed-off-by: František Balázsy --- .../display/apple,t6041-display-power.yaml | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Documentation/devicetree/bindings/display/apple,t6041-display-power.yaml diff --git a/Documentation/devicetree/bindings/display/apple,t6041-display-power.yaml b/Documentation/devicetree/bindings/display/apple,t6041-display-power.yaml new file mode 100644 index 0000000000000..ab19f769ea9f4 --- /dev/null +++ b/Documentation/devicetree/bindings/display/apple,t6041-display-power.yaml @@ -0,0 +1,73 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/display/apple,t6041-display-power.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Apple T6040 display power words + +maintainers: + - František Balázsy + +description: | + The words a T6040 (M4 Pro) display coprocessor's driver writes to lower + its power domains after it stops the firmware for a suspend-to-RAM and to + raise them again on the wake. A display coprocessor names this node in its + apple,display-power property. The words belong to the power manager and + the display block, so no driver binds it. + + The internal display coprocessor has its power-state words in the SoC's + east power manager block, the external ones in the west block, each at its + own offsets; the display PMC word that counts the powered coprocessors is + shared by all three. The boot loader publishes one node for the internal + coprocessor and one that both external coprocessors name. + +properties: + compatible: + const: apple,t6041-display-power + + reg: + items: + - description: a register window, named by reg-names + - description: a register window, named by reg-names + + reg-names: + description: + pmc-dcp is the display PMC word that counts the powered coprocessors, + ps the power manager block that holds the coprocessors' power-state + words. The two may come in either order. + oneOf: + - items: + - const: pmc-dcp + - const: ps + - items: + - const: ps + - const: pmc-dcp + +required: + - compatible + - reg + - reg-names + +additionalProperties: false + +examples: + - | + soc { + #address-cells = <2>; + #size-cells = <2>; + + display-power@5048a9c14 { + compatible = "apple,t6041-display-power"; + reg = <0x5 0x048a9c14 0x0 0x8>, + <0x5 0x02280000 0x0 0x14000>; + reg-names = "pmc-dcp", "ps"; + }; + + display-power@502800000 { + compatible = "apple,t6041-display-power"; + reg = <0x5 0x02800000 0x0 0x14000>, + <0x5 0x048a9c14 0x0 0x8>; + reg-names = "ps", "pmc-dcp"; + }; + }; From 8f54ea6eb5376be9359f389861dd570aa643b438 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Thu, 12 Nov 2026 20:19:27 +0100 Subject: [PATCH 11/49] arm64: dts: apple: t6040: describe what the boot loader adds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The comment on the sleep controller's storage link described how the boot loader's publish behaves and recalled what a static property had done on a J616s. Say what the tree has to give and what the boot loader adds: apple,apcie and the PCIe host's windows and tunables come from the boot loader, which leaves a node that has apple,apcie alone, so the tree gives neither. Comment only; the DTBs are unchanged. Signed-off-by: František Balázsy --- arch/arm64/boot/dts/apple/t6040.dtsi | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t6040.dtsi b/arch/arm64/boot/dts/apple/t6040.dtsi index d2d5622ff64d0..10d88b34510fc 100644 --- a/arch/arm64/boot/dts/apple/t6040.dtsi +++ b/arch/arm64/boot/dts/apple/t6040.dtsi @@ -294,20 +294,17 @@ apple,check-ps-b4-sleep-names = "disp", "dispext0", "dispext1", "dispext2", "dispext3"; /* - * ANS's storage PCIe (two ST lanes + shared PHY), for its sleep. The boot - * object (aura) publishes apple,apcie here plus the axi2af/cio3pll/ - * clkgen/phy-block/phy-ip windows and apple,tunable-* arrays onto the - * internal PCIe host (apple,t6020-pcie, identified by its "rc" - * reg-name) from the ADT /arm-io/apcie0 at boot, matching the - * single-lane t8140 shape. That publish is idempotent and - * returns early if apple,apcie is already present, so there must be NO - * static apple,apcie or apcie-storage node here -- a static one blocks - * the loader (seen on the J616s: a static apple,apcie made - * the driver see an empty node and refuse). Until the loader fills it, - * the driver NULL-guards every window and a real sleep with ANS stopped - * refuses (suspend-to-idle stays the default). The ST power words - * (ps_ans, ps_apcie_st0/st1, ps_apcie_sys_st0/st1) live in SOC-East and - * are driven by the controller's soc-east window, not from a node here. + * apple,apcie, for the sleep of ANS's storage PCIe link (two ST lanes + * and a shared PHY), comes from the boot loader. From the ADT's + * /arm-io/apcie0 it adds it here and puts the axi2af, cio3pll, clkgen, + * phy-block and phy-ip windows and the apple,tunable-* arrays on the + * internal PCIe host (apple,t6020-pcie, the one with an "rc" + * reg-name), in the single-lane T8140 shape. It leaves a node that + * already has apple,apcie alone, so this tree must give neither + * apple,apcie nor an apcie-storage node. Without it a sleep with ANS + * stopped is refused, and suspend-to-idle stays the default. The ST + * power words (ps_ans, ps_apcie_st0/st1, ps_apcie_sys_st0/st1) are in + * SOC-East and are driven through the soc-east window. */ /* Only on a board whose sleep has been tested. */ status = "disabled"; From 9257f406f053c78a0cbaebda14b89f6f4255bd16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Thu, 12 Nov 2026 20:21:48 +0100 Subject: [PATCH 12/49] arm64: dts: apple: t6040: give the sleep controller its unit address MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The sleep controller has registers but its node had no unit address, which dtc reports (unit_address_vs_reg). Name it after its first register block, as the T8140 tree does. The boot loader and the kernel find the node by its compatible, not by its path. Signed-off-by: František Balázsy --- arch/arm64/boot/dts/apple/t6040.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/apple/t6040.dtsi b/arch/arm64/boot/dts/apple/t6040.dtsi index 10d88b34510fc..c3d887b9cff2f 100644 --- a/arch/arm64/boot/dts/apple/t6040.dtsi +++ b/arch/arm64/boot/dts/apple/t6040.dtsi @@ -251,7 +251,7 @@ #size-cells = <1>; }; - t6040_sleep: sleep-controller { + t6040_sleep: sleep-controller@502888000 { compatible = "apple,t6040-sleep"; /* * The SoC blocks the commit and wake From 7f78dbc7338d8223f6779375773152860a667afd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Thu, 12 Nov 2026 20:25:25 +0100 Subject: [PATCH 13/49] dt-bindings: soc: apple: move the T6040 sleep controller next to T8140 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The T6040 sleep controller binding sat under power/, the T8140 one under soc/apple/, for the same kind of block. Move it next to the T8140 one, give apple,check-ps-b4-sleep-names its string-array type, and list the file under the Apple SoC entry in MAINTAINERS. Signed-off-by: František Balázsy --- .../bindings/{power => soc/apple}/apple,t6040-sleep.yaml | 3 ++- MAINTAINERS | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) rename Documentation/devicetree/bindings/{power => soc/apple}/apple,t6040-sleep.yaml (96%) diff --git a/Documentation/devicetree/bindings/power/apple,t6040-sleep.yaml b/Documentation/devicetree/bindings/soc/apple/apple,t6040-sleep.yaml similarity index 96% rename from Documentation/devicetree/bindings/power/apple,t6040-sleep.yaml rename to Documentation/devicetree/bindings/soc/apple/apple,t6040-sleep.yaml index 820e0b636b1d2..3b4ad81508271 100644 --- a/Documentation/devicetree/bindings/power/apple,t6040-sleep.yaml +++ b/Documentation/devicetree/bindings/soc/apple/apple,t6040-sleep.yaml @@ -1,7 +1,7 @@ # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) %YAML 1.2 --- -$id: http://devicetree.org/schemas/power/apple,t6040-sleep.yaml# +$id: http://devicetree.org/schemas/soc/apple/apple,t6040-sleep.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# title: Apple T6040 system sleep controller @@ -69,6 +69,7 @@ properties: - description: offset of its last sub-block's power state apple,check-ps-b4-sleep-names: + $ref: /schemas/types.yaml#/definitions/string-array description: One name per apple,check-ps-b4-sleep entry. apple,apcie: diff --git a/MAINTAINERS b/MAINTAINERS index 5cec0c882a568..8ef75ca7eca68 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2110,6 +2110,7 @@ F: Documentation/devicetree/bindings/rtc/apple,j700-pmu-rtc.yaml F: Documentation/devicetree/bindings/serial/apple,dockchannel-uart.yaml F: Documentation/devicetree/bindings/soc/apple/apple,dockchannel.yaml F: Documentation/devicetree/bindings/soc/apple/apple,rtk-helper-asc4.yaml +F: Documentation/devicetree/bindings/soc/apple/apple,t6040-sleep.yaml F: Documentation/devicetree/bindings/soc/apple/apple,t6041-aop.yaml F: Documentation/devicetree/bindings/soc/apple/apple,t8140-aop.yaml F: Documentation/devicetree/bindings/soc/apple/apple,t8140-mcc.yaml From 05bc00c4c6fa15d97d752ed094758a2727dbaef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Thu, 12 Nov 2026 20:28:06 +0100 Subject: [PATCH 14/49] dt-bindings: chosen: document aurora,s2r-mailbox MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The boot object publishes /chosen/aurora,s2r-mailbox, and the arm64 CPU ops, the spin-table hibernation and the Apple sleep driver read it, but no binding described it. Document what its presence means and the layout of the mailbox it points at. Signed-off-by: František Balázsy --- .../bindings/chosen/aurora,s2r-mailbox.yaml | 48 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 49 insertions(+) create mode 100644 Documentation/devicetree/bindings/chosen/aurora,s2r-mailbox.yaml diff --git a/Documentation/devicetree/bindings/chosen/aurora,s2r-mailbox.yaml b/Documentation/devicetree/bindings/chosen/aurora,s2r-mailbox.yaml new file mode 100644 index 0000000000000..a48f9bbc5ae3e --- /dev/null +++ b/Documentation/devicetree/bindings/chosen/aurora,s2r-mailbox.yaml @@ -0,0 +1,48 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/chosen/aurora,s2r-mailbox.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Return path of a boot object that owns the CPU reset vectors + +maintainers: + - František Balázsy + +description: | + On Apple silicon the boot firmware locks every CPU's reset vector to the + boot object it started. A CPU that comes back from a power-off, and every + CPU after a suspend to RAM, therefore restarts in the boot object, not in the + kernel. A boot object that sends such a CPU back to the kernel says so with + this property: a secondary CPU returns through its spin-table release + address, and the boot CPU of a resume jumps, at EL2 with the MMU off, to the + address the kernel left in the mailbox. Its presence also tells the kernel + that its spin-table CPUs may leave the kernel and come back. + + The mailbox is four 64-bit words in the CPU's byte order: + 0: the magic value 0x3152325341525541 ("AURAS2R1"), written by the boot + object before the kernel starts + 1: the MPIDR of the only CPU that may take the resume address + 2: the resume address, set by the kernel before it suspends and cleared + by the boot object when a CPU takes it + 3: how many times the resume address was taken + +select: + properties: + $nodename: + const: chosen + required: + - $nodename + +properties: + $nodename: + const: chosen + + aurora,s2r-mailbox: + $ref: /schemas/types.yaml#/definitions/uint64 + description: + Physical address of the mailbox, inside the boot object's own memory, + which the kernel does not use. + +additionalProperties: true +... diff --git a/MAINTAINERS b/MAINTAINERS index 8ef75ca7eca68..91be6606d41ff 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2094,6 +2094,7 @@ F: include/linux/mt7932.h F: include/linux/soc/apple/pmp-report.h F: Documentation/devicetree/bindings/chosen/apple,dcp-rtkit-quiesced.yaml F: Documentation/devicetree/bindings/chosen/aurora,ctxr-exec-window.yaml +F: Documentation/devicetree/bindings/chosen/aurora,s2r-mailbox.yaml F: Documentation/devicetree/bindings/display/apple,dcp.yaml F: Documentation/devicetree/bindings/display/apple,display-subsystem.yaml F: Documentation/devicetree/bindings/display/apple,t8140-display-power.yaml From 9953429fc4d203792c3255e5702b017a57456b5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Fri, 13 Nov 2026 00:01:52 +0100 Subject: [PATCH 15/49] dt-bindings: chosen: document the aura hibernation layout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The kernel hibernates on Apple silicon only where the boot object says, in /chosen, that it keeps the same memory layout on every boot, and it reads the device tree of the resuming boot at the address the boot object gives there. Neither property had a binding, and their prefix was not a registered one. Register the prefix and describe the two properties. The prefix is the name of the boot loader that defined them, as u-boot's is: its released versions publish the properties under this name, so a kernel that looked for another one would not hibernate with any of them. Signed-off-by: František Balázsy --- .../bindings/chosen/aura,hibernate.yaml | 64 +++++++++++++++++++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + MAINTAINERS | 1 + 3 files changed, 67 insertions(+) create mode 100644 Documentation/devicetree/bindings/chosen/aura,hibernate.yaml diff --git a/Documentation/devicetree/bindings/chosen/aura,hibernate.yaml b/Documentation/devicetree/bindings/chosen/aura,hibernate.yaml new file mode 100644 index 0000000000000..8c8e9390b1e60 --- /dev/null +++ b/Documentation/devicetree/bindings/chosen/aura,hibernate.yaml @@ -0,0 +1,64 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/chosen/aura,hibernate.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Memory layout a boot object keeps the same on every boot + +maintainers: + - František Balázsy + +description: | + A hibernation image puts every saved page back into the frame it was taken + from, so the boot that resumes an image has to give the kernel the same RAM, + and keep the same ranges from it, as the boot that wrote the image. On Apple + silicon the boot firmware loads the boot object at an address that changes + from boot to boot, and what the boot object keeps alive after the hand-off + moves with it. A boot object that instead keeps everything from the start of + RAM up to a fixed end from the kernel, at the same addresses on every boot, + says so with aura,hibernate-layout. Without it the kernel neither hibernates + nor resumes. + + The boot firmware still places some firmware segments anew on every boot, + inside that range, and a kernel restored from an image holds the device tree + of the boot that wrote the image. The boot object therefore puts the device + tree of every boot at one address inside the range, given in + aura,hibernate-dt. The image does not contain that memory, so the restored + kernel reads there what the resuming boot placed. + + The properties are named after aura, the boot loader that defined them and + whose released versions publish them. + +select: + properties: + $nodename: + const: chosen + required: + - $nodename + +properties: + $nodename: + const: chosen + + aura,hibernate-layout: + $ref: /schemas/types.yaml#/definitions/uint64-array + description: + The range of RAM that is kept from the kernel and laid out the same on + every boot. + items: + - description: Physical address of the start of RAM. + - description: Physical address of the end of the range, exclusive. + + aura,hibernate-dt: + $ref: /schemas/types.yaml#/definitions/uint64 + description: + Physical address, inside the range of aura,hibernate-layout, of the + device tree the kernel is started with. The kernel reads at most 2 MiB + there. + +dependencies: + aura,hibernate-dt: [ 'aura,hibernate-layout' ] + +additionalProperties: true +... diff --git a/Documentation/devicetree/bindings/vendor-prefixes.yaml b/Documentation/devicetree/bindings/vendor-prefixes.yaml index 4775b267e1f77..ed0d32cde3614 100644 --- a/Documentation/devicetree/bindings/vendor-prefixes.yaml +++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml @@ -207,6 +207,8 @@ patternProperties: description: Atmel Corporation "^auo,.*": description: AU Optronics Corporation + "^aura,.*": + description: aura boot loader for Apple silicon "^aurora,.*": description: Aurora Silicon "^auvidea,.*": diff --git a/MAINTAINERS b/MAINTAINERS index 91be6606d41ff..b7da6fb00b4d3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2093,6 +2093,7 @@ F: drivers/soc/apple/pmp.rs F: include/linux/mt7932.h F: include/linux/soc/apple/pmp-report.h F: Documentation/devicetree/bindings/chosen/apple,dcp-rtkit-quiesced.yaml +F: Documentation/devicetree/bindings/chosen/aura,hibernate.yaml F: Documentation/devicetree/bindings/chosen/aurora,ctxr-exec-window.yaml F: Documentation/devicetree/bindings/chosen/aurora,s2r-mailbox.yaml F: Documentation/devicetree/bindings/display/apple,dcp.yaml From c4404fc705d173febc5644de3934ca75d09b5cae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Fri, 13 Nov 2026 14:52:26 +0100 Subject: [PATCH 16/49] dt-bindings: soc: apple: t6040-sleep: require the register blocks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The sleep controller cannot enter a suspend or undo one without any of its eleven register blocks, and every T6040 board lists all of them. Make reg and reg-names required with all eleven entries instead of accepting a node with only the first two, and give the example the node it describes. Signed-off-by: František Balázsy --- .../bindings/soc/apple/apple,t6040-sleep.yaml | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/Documentation/devicetree/bindings/soc/apple/apple,t6040-sleep.yaml b/Documentation/devicetree/bindings/soc/apple/apple,t6040-sleep.yaml index 3b4ad81508271..443c335cf7df5 100644 --- a/Documentation/devicetree/bindings/soc/apple/apple,t6040-sleep.yaml +++ b/Documentation/devicetree/bindings/soc/apple/apple,t6040-sleep.yaml @@ -15,7 +15,7 @@ description: | start block, the always-on watchdog, the complex and power-gate words, the PMU's SPMI controllers and the always-on timer that starts the SoC's sleep engine. All of these register blocks are shared with the devices that own - them. Without the blocks a suspend can be checked, and not entered. + them, and all of them are needed to enter a suspend and to undo it. The sleep engine waits for the display pipes, so the node lists the power states that have to be off before a sleep, as the ADT's @@ -28,7 +28,6 @@ properties: const: apple,t6040-sleep reg: - minItems: 2 items: - description: CPU start/stop block (pmgr + 0x88000) - description: AON watchdog @@ -43,7 +42,6 @@ properties: - description: AOP global block, S2R control and wake masks reg-names: - minItems: 2 items: - const: cpu-start - const: wdt @@ -82,6 +80,8 @@ properties: required: - compatible + - reg + - reg-names - apple,check-ps-b4-sleep - apple,check-ps-b4-sleep-names @@ -89,8 +89,27 @@ additionalProperties: false examples: - | - sleep-controller { - compatible = "apple,t6040-sleep"; - apple,check-ps-b4-sleep = <&pmgr_disp 0x0 0x58>; - apple,check-ps-b4-sleep-names = "disp"; + soc { + #address-cells = <2>; + #size-cells = <2>; + + sleep-controller@502888000 { + compatible = "apple,t6040-sleep"; + reg = <0x5 0x02888000 0x0 0x20>, + <0x5 0x0836c000 0x0 0x4000>, + <0x5 0x02820000 0x0 0x20>, + <0x5 0x0282c000 0x0 0x1000>, + <0x5 0x00000000 0x0 0x80000>, + <0x5 0x09014000 0x0 0x1000>, + <0x5 0x09188000 0x0 0x1000>, + <0x5 0x08900000 0x0 0x8000>, + <0x5 0x02280000 0x0 0x1000>, + <0x5 0x02800000 0x0 0x1000>, + <0x5 0x08004000 0x0 0x1000>; + reg-names = "cpu-start", "wdt", "cluster-ctl", "soc-pwrgate", + "clkgen", "spmi0", "spmi-a0", "mastermini", + "soc-east", "soc-ps", "aop-global"; + apple,check-ps-b4-sleep = <&pmgr_disp 0x0 0x58>; + apple,check-ps-b4-sleep-names = "disp"; + }; }; From eedb5c236474c689e43d0aeeeb090b01af8d6e46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Fri, 13 Nov 2026 14:52:39 +0100 Subject: [PATCH 17/49] dt-bindings: soc: apple: t6040-sleep: size the power word pages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The soc-east and soc-ps windows are the SOC-East and SOC power word pages, which the driver reads and writes as one range each: 0xd000 and 0x9000 bytes. Describe them as the pages they are, so that one mapping of each serves every power word in them. Signed-off-by: František Balázsy --- .../devicetree/bindings/soc/apple/apple,t6040-sleep.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Documentation/devicetree/bindings/soc/apple/apple,t6040-sleep.yaml b/Documentation/devicetree/bindings/soc/apple/apple,t6040-sleep.yaml index 443c335cf7df5..eab4fcf4725fd 100644 --- a/Documentation/devicetree/bindings/soc/apple/apple,t6040-sleep.yaml +++ b/Documentation/devicetree/bindings/soc/apple/apple,t6040-sleep.yaml @@ -37,8 +37,8 @@ properties: - description: SPMI controller of the PMU (boot stage, notify, hibernate) - description: second SPMI controller's notify word - description: MasterMini block with the S2R timer - - description: SOC-East retention and power words - - description: PMGR power words of the west axi2af bridges + - description: SOC-East page with retention, fabric, DCS, SIO and other power words + - description: SOC page with the west axi2af, ATC, fabric and DCS power words - description: AOP global block, S2R control and wake masks reg-names: @@ -103,8 +103,8 @@ examples: <0x5 0x09014000 0x0 0x1000>, <0x5 0x09188000 0x0 0x1000>, <0x5 0x08900000 0x0 0x8000>, - <0x5 0x02280000 0x0 0x1000>, - <0x5 0x02800000 0x0 0x1000>, + <0x5 0x02280000 0x0 0xd000>, + <0x5 0x02800000 0x0 0x9000>, <0x5 0x08004000 0x0 0x1000>; reg-names = "cpu-start", "wdt", "cluster-ctl", "soc-pwrgate", "clkgen", "spmi0", "spmi-a0", "mastermini", From 5983f84a5b57b630f9992d42dc2a31ea5494bbb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Fri, 13 Nov 2026 14:52:39 +0100 Subject: [PATCH 18/49] arm64: dts: apple: t6040: size the sleep controller's power word pages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Give the soc-east and soc-ps windows of the sleep controller the extent of the SOC-East (0x502280000) and SOC (0x502800000) power word pages, 0xd000 and 0x9000 bytes, instead of the first 0x1000 of each. The addresses are unchanged. Signed-off-by: František Balázsy --- arch/arm64/boot/dts/apple/t6040.dtsi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t6040.dtsi b/arch/arm64/boot/dts/apple/t6040.dtsi index c3d887b9cff2f..6440c686c1af2 100644 --- a/arch/arm64/boot/dts/apple/t6040.dtsi +++ b/arch/arm64/boot/dts/apple/t6040.dtsi @@ -265,8 +265,8 @@ * spmi0 0x509014000: the PMU boot-stage + NOTIFY + go-hib * spmi-a0 0x509188000: the second SPMI NOTIFY * mastermini 0x508900000: the S2R timer at +0x4000 (the commit) - * soc-east 0x502280000: SOC-East retention + east power words - * soc-ps 0x502800000: the west axi2af power words + * soc-east 0x502280000: SOC-East page, retention + east power words + * soc-ps 0x502800000: SOC page, the west axi2af power words * aop-global 0x508004000: the S2R control + wake masks/status * The handler refuses before touching any of them. */ @@ -278,8 +278,8 @@ <0x5 0x09014000 0x0 0x1000>, <0x5 0x09188000 0x0 0x1000>, <0x5 0x08900000 0x0 0x8000>, - <0x5 0x02280000 0x0 0x1000>, - <0x5 0x02800000 0x0 0x1000>, + <0x5 0x02280000 0x0 0xd000>, + <0x5 0x02800000 0x0 0x9000>, <0x5 0x08004000 0x0 0x1000>; reg-names = "cpu-start", "wdt", "cluster-ctl", "soc-pwrgate", "clkgen", "spmi0", "spmi-a0", "mastermini", From 9caa407d37e1ed08dee6b157aa3d6c7d2275d422 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Fri, 13 Nov 2026 15:42:11 +0100 Subject: [PATCH 19/49] dt-bindings: soc: apple: describe the sleep controllers in one schema MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The T6040, T8132 and T8140 sleep controllers do the same job and were described by two schemas that named the same blocks differently. Describe them in apple,sleep.yaml, with the register names per compatible, and give the blocks the T6040 shares with the T8140 the T8140's names: cluster for the CPU complexes' control words, pwrgate for the power-gate and voter block, spmi for the PMU's SPMI controller and wake for the AOP block with the wake masks. The schema keeps what each SoC requires and refuses: the T6040 needs all eleven of its register blocks, the SOC-East and SOC pages sized as the driver maps them, and the display power-state table; the T8140 needs its 28 blocks, the wake sources and the display coprocessors; the T8132 its 25 blocks, the clock protection page as an optional 26th, and the display coprocessors. The controllers are listed in MAINTAINERS under the one file. The T6040 device tree and driver follow in the next two patches. Signed-off-by: František Balázsy --- .../bindings/soc/apple/apple,sleep.yaml | 262 ++++++++++++++++++ .../bindings/soc/apple/apple,t6040-sleep.yaml | 115 -------- .../bindings/soc/apple/apple,t8140-sleep.yaml | 158 ----------- MAINTAINERS | 3 +- 4 files changed, 263 insertions(+), 275 deletions(-) create mode 100644 Documentation/devicetree/bindings/soc/apple/apple,sleep.yaml delete mode 100644 Documentation/devicetree/bindings/soc/apple/apple,t6040-sleep.yaml delete mode 100644 Documentation/devicetree/bindings/soc/apple/apple,t8140-sleep.yaml diff --git a/Documentation/devicetree/bindings/soc/apple/apple,sleep.yaml b/Documentation/devicetree/bindings/soc/apple/apple,sleep.yaml new file mode 100644 index 0000000000000..d084121d3bfb1 --- /dev/null +++ b/Documentation/devicetree/bindings/soc/apple/apple,sleep.yaml @@ -0,0 +1,262 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/soc/apple/apple,sleep.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Apple SoC system sleep controls + +maintainers: + - Diljit Singh + - František Balázsy + +description: | + The registers a kernel running directly at EL2 on an Apple SoC writes to enter + and return from suspend-to-RAM and to power its secondary CPUs off. They belong + to several hardware blocks, some of which other drivers also use, so this node + overlaps those drivers' register ranges and the driver does not claim them. + Each SoC has its own compatible, as its power domains differ. Blocks that + several SoCs have are named alike. + + On the T6040 the sleep engine waits for the display pipes, so the node lists + the power states that have to be off before a sleep, as the ADT's + device-check-ps-b4-sleep table does. Each entry names a PMGR register block, + the offset of a display pipe's CPU power state and the offset of its last + sub-block; the states in between are 8 bytes apart. All of the T6040's + register blocks are needed to enter a suspend and to undo it. + +properties: + compatible: + enum: + - apple,t6040-sleep + - apple,t8132-sleep + - apple,t8140-sleep + + reg: + minItems: 11 + maxItems: 28 + + reg-names: + minItems: 11 + maxItems: 28 + + apple,wake-enable: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: + The wake source IDs left enabled across suspend-to-RAM. Every other + source is masked. + + apple,apcie: + $ref: /schemas/types.yaml#/definitions/phandle + description: + The PCIe host whose shared registers and tunables the storage controller's + link depends on. They are needed even with that host disabled. On the + T6040 the boot loader adds it, with those registers and tunables on the + host's node; without it the storage controller can't be stopped for a + sleep. + + apple,pinctrl: + $ref: /schemas/types.yaml#/definitions/phandle + description: + The pin controller whose pins a deep sleep resets. Its pins are saved + before a sleep and put back after it, before the storage controller + starts. + + apple,pinctrl-skip-pins: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: + Pins of that controller to leave alone across a sleep, neither saved nor + put back. + + apple,debug-port: + $ref: /schemas/types.yaml#/definitions/phandle + description: + The USB-C port controller that carries the debug link, stopped for a sleep. + + apple,display-coprocessors: + $ref: /schemas/types.yaml#/definitions/phandle-array + description: + The DCP and the external DCPs, which must be off before a commit, in that + order. + + apple,check-ps-b4-sleep: + $ref: /schemas/types.yaml#/definitions/phandle-array + description: + The display pipes whose power states have to be off before a sleep, one + entry per pipe. + items: + items: + - description: PMGR syscon + - description: offset of the pipe's CPU power state + - description: offset of its last sub-block's power state + + apple,check-ps-b4-sleep-names: + $ref: /schemas/types.yaml#/definitions/string-array + description: One name per apple,check-ps-b4-sleep entry. + +required: + - compatible + +allOf: + - if: + properties: + compatible: + const: apple,t6040-sleep + then: + properties: + reg: + items: + - description: CPU start/stop block (pmgr + 0x88000) + - description: AON watchdog + - description: control words of the three CPU complexes + - description: SoC power gate, wake and retention voters + - description: clock generator, the clock mux park words + - description: SPMI controller of the PMU (boot stage, notify, hibernate) + - description: second SPMI controller's notify word + - description: MasterMini block with the S2R timer + - description: SOC-East page with retention, fabric, DCS, SIO and other power words + - description: SOC page with the west axi2af, ATC, fabric and DCS power words + - description: AOP global block, S2R control and wake masks + reg-names: + items: + - const: cpu-start + - const: wdt + - const: cluster + - const: pwrgate + - const: clkgen + - const: spmi + - const: spmi-a0 + - const: mastermini + - const: soc-east + - const: soc-ps + - const: wake + apple,wake-enable: false + apple,pinctrl: false + apple,pinctrl-skip-pins: false + apple,debug-port: false + apple,display-coprocessors: false + required: + - reg + - reg-names + - apple,check-ps-b4-sleep + - apple,check-ps-b4-sleep-names + + - if: + properties: + compatible: + const: apple,t8132-sleep + then: + properties: + reg: + minItems: 25 + maxItems: 26 + reg-names: + minItems: 25 + items: + - const: ps + - const: pwrgate + - const: cpu-start + - const: cllt + - const: cluster + - const: commit + - const: wdt + - const: aon-misc + - const: wake + - const: amcc0 + - const: amcc1 + - const: pmc-dcp + - const: dvfm-e + - const: dvfm-p + - const: spmi + - const: pmc-voters + - const: dcs + - const: ps-aon + - const: spmi-a0 + - const: clk-mux + - const: mcc0 + - const: mcc1 + - const: ptd + - const: clk-perf + - const: cluster-dcs + - const: ps-prot + apple,check-ps-b4-sleep: false + apple,check-ps-b4-sleep-names: false + required: + - reg + - reg-names + - apple,display-coprocessors + + - if: + properties: + compatible: + const: apple,t8140-sleep + then: + properties: + reg: + minItems: 28 + reg-names: + items: + - const: ps + - const: pwrgate + - const: cpu-start + - const: cllt + - const: cluster + - const: commit + - const: wdt + - const: aon-misc + - const: wake + - const: amcc0 + - const: amcc1 + - const: amcc2 + - const: amcc3 + - const: pmc-dcp + - const: dvfm-e + - const: dvfm-p + - const: spmi + - const: pmc-voters + - const: dcs + - const: ps-aon + - const: spmi-a0 + - const: clk-mux + - const: mcc0 + - const: mcc1 + - const: mcc2 + - const: ptd + - const: clk-perf + - const: cluster-dcs + apple,check-ps-b4-sleep: false + apple,check-ps-b4-sleep-names: false + required: + - reg + - reg-names + - apple,wake-enable + - apple,display-coprocessors + +additionalProperties: false + +examples: + - | + soc { + #address-cells = <2>; + #size-cells = <2>; + + sleep-controller@502888000 { + compatible = "apple,t6040-sleep"; + reg = <0x5 0x02888000 0x0 0x20>, + <0x5 0x0836c000 0x0 0x4000>, + <0x5 0x02820000 0x0 0x20>, + <0x5 0x0282c000 0x0 0x1000>, + <0x5 0x00000000 0x0 0x80000>, + <0x5 0x09014000 0x0 0x1000>, + <0x5 0x09188000 0x0 0x1000>, + <0x5 0x08900000 0x0 0x8000>, + <0x5 0x02280000 0x0 0xd000>, + <0x5 0x02800000 0x0 0x9000>, + <0x5 0x08004000 0x0 0x1000>; + reg-names = "cpu-start", "wdt", "cluster", "pwrgate", + "clkgen", "spmi", "spmi-a0", "mastermini", + "soc-east", "soc-ps", "wake"; + apple,check-ps-b4-sleep = <&pmgr_disp 0x0 0x58>; + apple,check-ps-b4-sleep-names = "disp"; + }; + }; diff --git a/Documentation/devicetree/bindings/soc/apple/apple,t6040-sleep.yaml b/Documentation/devicetree/bindings/soc/apple/apple,t6040-sleep.yaml deleted file mode 100644 index eab4fcf4725fd..0000000000000 --- a/Documentation/devicetree/bindings/soc/apple/apple,t6040-sleep.yaml +++ /dev/null @@ -1,115 +0,0 @@ -# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) -%YAML 1.2 ---- -$id: http://devicetree.org/schemas/soc/apple/apple,t6040-sleep.yaml# -$schema: http://devicetree.org/meta-schemas/core.yaml# - -title: Apple T6040 system sleep controller - -maintainers: - - František Balázsy - -description: | - What an operating system that runs at EL2, with no firmware below it to ask, - drives itself to suspend the T6040 to RAM and to bring it back: the CPU - start block, the always-on watchdog, the complex and power-gate words, the - PMU's SPMI controllers and the always-on timer that starts the SoC's sleep - engine. All of these register blocks are shared with the devices that own - them, and all of them are needed to enter a suspend and to undo it. - - The sleep engine waits for the display pipes, so the node lists the power - states that have to be off before a sleep, as the ADT's - device-check-ps-b4-sleep table does. Each entry names a PMGR register block, - the offset of a display pipe's CPU power state and the offset of its last - sub-block; the states in between are 8 bytes apart. - -properties: - compatible: - const: apple,t6040-sleep - - reg: - items: - - description: CPU start/stop block (pmgr + 0x88000) - - description: AON watchdog - - description: control words of the three CPU complexes - - description: SoC power gate, wake and retention voters - - description: clock generator, the clock mux park words - - description: SPMI controller of the PMU (boot stage, notify, hibernate) - - description: second SPMI controller's notify word - - description: MasterMini block with the S2R timer - - description: SOC-East page with retention, fabric, DCS, SIO and other power words - - description: SOC page with the west axi2af, ATC, fabric and DCS power words - - description: AOP global block, S2R control and wake masks - - reg-names: - items: - - const: cpu-start - - const: wdt - - const: cluster-ctl - - const: soc-pwrgate - - const: clkgen - - const: spmi0 - - const: spmi-a0 - - const: mastermini - - const: soc-east - - const: soc-ps - - const: aop-global - - apple,check-ps-b4-sleep: - $ref: /schemas/types.yaml#/definitions/phandle-array - description: - The display pipes whose power states have to be off before a sleep, one - entry per pipe. - items: - items: - - description: PMGR syscon - - description: offset of the pipe's CPU power state - - description: offset of its last sub-block's power state - - apple,check-ps-b4-sleep-names: - $ref: /schemas/types.yaml#/definitions/string-array - description: One name per apple,check-ps-b4-sleep entry. - - apple,apcie: - $ref: /schemas/types.yaml#/definitions/phandle - description: - The PCIe host whose shared registers and tunables the storage controller's - link depends on. The boot loader adds it, with those registers and - tunables on the host's node. Without it the storage controller can't be - stopped for a sleep. - -required: - - compatible - - reg - - reg-names - - apple,check-ps-b4-sleep - - apple,check-ps-b4-sleep-names - -additionalProperties: false - -examples: - - | - soc { - #address-cells = <2>; - #size-cells = <2>; - - sleep-controller@502888000 { - compatible = "apple,t6040-sleep"; - reg = <0x5 0x02888000 0x0 0x20>, - <0x5 0x0836c000 0x0 0x4000>, - <0x5 0x02820000 0x0 0x20>, - <0x5 0x0282c000 0x0 0x1000>, - <0x5 0x00000000 0x0 0x80000>, - <0x5 0x09014000 0x0 0x1000>, - <0x5 0x09188000 0x0 0x1000>, - <0x5 0x08900000 0x0 0x8000>, - <0x5 0x02280000 0x0 0xd000>, - <0x5 0x02800000 0x0 0x9000>, - <0x5 0x08004000 0x0 0x1000>; - reg-names = "cpu-start", "wdt", "cluster-ctl", "soc-pwrgate", - "clkgen", "spmi0", "spmi-a0", "mastermini", - "soc-east", "soc-ps", "aop-global"; - apple,check-ps-b4-sleep = <&pmgr_disp 0x0 0x58>; - apple,check-ps-b4-sleep-names = "disp"; - }; - }; diff --git a/Documentation/devicetree/bindings/soc/apple/apple,t8140-sleep.yaml b/Documentation/devicetree/bindings/soc/apple/apple,t8140-sleep.yaml deleted file mode 100644 index bdbe2a5ccadaf..0000000000000 --- a/Documentation/devicetree/bindings/soc/apple/apple,t8140-sleep.yaml +++ /dev/null @@ -1,158 +0,0 @@ -# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) -%YAML 1.2 ---- -$id: http://devicetree.org/schemas/soc/apple/apple,t8140-sleep.yaml# -$schema: http://devicetree.org/meta-schemas/core.yaml# - -title: Apple SoC system sleep controls - -maintainers: - - Diljit Singh - -description: | - The registers a kernel running directly at EL2 on an Apple SoC writes to enter - and return from suspend-to-RAM and to power its secondary CPUs off. They belong - to several hardware blocks, some of which other drivers also use, so this node - overlaps those drivers' register ranges and the driver does not claim them. - Each SoC has its own compatible, as its power domains differ. - -properties: - compatible: - enum: - - apple,t8132-sleep - - apple,t8140-sleep - - reg: - minItems: 25 - maxItems: 28 - - reg-names: - minItems: 25 - maxItems: 28 - - apple,wake-enable: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: - The wake source IDs left enabled across suspend-to-RAM. Every other - source is masked. - - apple,apcie: - $ref: /schemas/types.yaml#/definitions/phandle - description: - The PCIe host whose shared registers and tunables the storage controller's - link depends on. They are needed even with that host disabled. - - apple,pinctrl: - $ref: /schemas/types.yaml#/definitions/phandle - description: - The pin controller whose pins a deep sleep resets. Its pins are saved - before a sleep and put back after it, before the storage controller - starts. - - apple,pinctrl-skip-pins: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: - Pins of that controller to leave alone across a sleep, neither saved nor - put back. - - apple,debug-port: - $ref: /schemas/types.yaml#/definitions/phandle - description: - The USB-C port controller that carries the debug link, stopped for a sleep. - - apple,display-coprocessors: - $ref: /schemas/types.yaml#/definitions/phandle-array - description: - The DCP and the external DCPs, which must be off before a commit, in that - order. - -required: - - compatible - - reg - - reg-names - - apple,display-coprocessors - -allOf: - - if: - properties: - compatible: - contains: - const: apple,t8140-sleep - then: - required: - - apple,wake-enable - properties: - reg: - minItems: 28 - maxItems: 28 - reg-names: - items: - - const: ps - - const: pwrgate - - const: cpu-start - - const: cllt - - const: cluster - - const: commit - - const: wdt - - const: aon-misc - - const: wake - - const: amcc0 - - const: amcc1 - - const: amcc2 - - const: amcc3 - - const: pmc-dcp - - const: dvfm-e - - const: dvfm-p - - const: spmi - - const: pmc-voters - - const: dcs - - const: ps-aon - - const: spmi-a0 - - const: clk-mux - - const: mcc0 - - const: mcc1 - - const: mcc2 - - const: ptd - - const: clk-perf - - const: cluster-dcs - - if: - properties: - compatible: - contains: - const: apple,t8132-sleep - then: - properties: - reg: - minItems: 25 - maxItems: 26 - reg-names: - minItems: 25 - items: - - const: ps - - const: pwrgate - - const: cpu-start - - const: cllt - - const: cluster - - const: commit - - const: wdt - - const: aon-misc - - const: wake - - const: amcc0 - - const: amcc1 - - const: pmc-dcp - - const: dvfm-e - - const: dvfm-p - - const: spmi - - const: pmc-voters - - const: dcs - - const: ps-aon - - const: spmi-a0 - - const: clk-mux - - const: mcc0 - - const: mcc1 - - const: ptd - - const: clk-perf - - const: cluster-dcs - - const: ps-prot - -additionalProperties: false diff --git a/MAINTAINERS b/MAINTAINERS index b7da6fb00b4d3..70fe19771d80e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2112,11 +2112,10 @@ F: Documentation/devicetree/bindings/rtc/apple,j700-pmu-rtc.yaml F: Documentation/devicetree/bindings/serial/apple,dockchannel-uart.yaml F: Documentation/devicetree/bindings/soc/apple/apple,dockchannel.yaml F: Documentation/devicetree/bindings/soc/apple/apple,rtk-helper-asc4.yaml -F: Documentation/devicetree/bindings/soc/apple/apple,t6040-sleep.yaml +F: Documentation/devicetree/bindings/soc/apple/apple,sleep.yaml F: Documentation/devicetree/bindings/soc/apple/apple,t6041-aop.yaml F: Documentation/devicetree/bindings/soc/apple/apple,t8140-aop.yaml F: Documentation/devicetree/bindings/soc/apple/apple,t8140-mcc.yaml -F: Documentation/devicetree/bindings/soc/apple/apple,t8140-sleep.yaml F: Documentation/devicetree/bindings/sound/apple,t6041-aop-audio.yaml F: Documentation/devicetree/bindings/sound/apple,t8140-aop-audio.yaml F: Documentation/devicetree/bindings/usb/vialab,vl122.yaml From d05b2d3f1ab7a132d3c0b3c247bc4725d22abd98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Fri, 13 Nov 2026 15:43:26 +0100 Subject: [PATCH 20/49] arm64: dts: apple: t6040: name the sleep controller's blocks as the T8140's MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Give the register blocks of the T6040 sleep controller that the T8140's controller has too the names the schema uses for both: cluster, pwrgate, spmi and wake. The addresses, sizes and order are unchanged; the compiled tree differs only in those four names. The driver looks the blocks up by these names and follows in the next patch. Signed-off-by: František Balázsy --- arch/arm64/boot/dts/apple/t6040.dtsi | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t6040.dtsi b/arch/arm64/boot/dts/apple/t6040.dtsi index 6440c686c1af2..37ce82fc38171 100644 --- a/arch/arm64/boot/dts/apple/t6040.dtsi +++ b/arch/arm64/boot/dts/apple/t6040.dtsi @@ -259,15 +259,15 @@ * touched only once no blocker remains: * cpu-start pmgr reg0 + 0x88000 (misc-cores): CPU start/stop * wdt the AON watchdog, the sleep's WD2 safety net - * cluster-ctl 0x502820000: the three CPU complexes E/P0/P1 - * soc-pwrgate 0x50282c000: wake + CPM retention voters + * cluster 0x502820000: the three CPU complexes E/P0/P1 + * pwrgate 0x50282c000: wake + CPM retention voters * clkgen 0x500000000: the clk-mux park words - * spmi0 0x509014000: the PMU boot-stage + NOTIFY + go-hib + * spmi 0x509014000: the PMU boot-stage + NOTIFY + go-hib * spmi-a0 0x509188000: the second SPMI NOTIFY * mastermini 0x508900000: the S2R timer at +0x4000 (the commit) * soc-east 0x502280000: SOC-East page, retention + east power words * soc-ps 0x502800000: SOC page, the west axi2af power words - * aop-global 0x508004000: the S2R control + wake masks/status + * wake 0x508004000: the S2R control + wake masks/status * The handler refuses before touching any of them. */ reg = <0x5 0x02888000 0x0 0x20>, @@ -281,9 +281,9 @@ <0x5 0x02280000 0x0 0xd000>, <0x5 0x02800000 0x0 0x9000>, <0x5 0x08004000 0x0 0x1000>; - reg-names = "cpu-start", "wdt", "cluster-ctl", "soc-pwrgate", - "clkgen", "spmi0", "spmi-a0", "mastermini", - "soc-east", "soc-ps", "aop-global"; + reg-names = "cpu-start", "wdt", "cluster", "pwrgate", + "clkgen", "spmi", "spmi-a0", "mastermini", + "soc-east", "soc-ps", "wake"; /* * ADT pmgr device-check-ps-b4-sleep (check-ps-b4-sleep = 0x1f): per * display pipe its CPU and its last sub-block, 8 bytes apart. From fae08585692221ea99cabb1a23c83d743ce28b40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Fri, 13 Nov 2026 15:46:35 +0100 Subject: [PATCH 21/49] dt-bindings: thunderbolt: apple: name the router's Type-C PHY in phys MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The T6040 USB4 router runs only over its port's Type-C PHY and tells the PHY when it starts and stops. The PHY was named in a vendor phandle, which the router resolved to a device node and looked up by hand for each call. Describe it with the standard phys property and the "cio" name the T8132 routers already use for the same PHY, so the PHY framework resolves it and orders the router after the PHY. The T6040 routers require both. Not run on a USB4/Thunderbolt device. Signed-off-by: František Balázsy --- .../bindings/thunderbolt/apple,t8103-usb4-acio.yaml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml b/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml index c684093b994d9..b51948af8b09f 100644 --- a/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml +++ b/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml @@ -124,17 +124,12 @@ properties: description: The Type-C PHY whose lanes carry the router's CIO link. A host that power-cycles the router for a deep sleep takes the PHY through the - sleep with it. + sleep with it. On T6040 the router starts only while that PHY is in + CIO mode and tells it when it stops. phy-names: const: cio - apple,atc-phy: - $ref: /schemas/types.yaml#/definitions/phandle - description: - Type-C PHY of this router's port. On T6040 the router starts only while - that PHY is in CIO mode and tells it when it stops. - apple,pcie-tunnel: $ref: /schemas/types.yaml#/definitions/phandle description: @@ -291,7 +286,8 @@ allOf: - nhi@1f00000 - interrupts - interrupt-names - - apple,atc-phy + - phys + - phy-names else: required: - iommu@a80000 From a37cf5d0e61da8d0b8eb9e186c6b3cc4539f5070 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Fri, 13 Nov 2026 15:46:36 +0100 Subject: [PATCH 22/49] arm64: dts: apple: t6040: give the USB4 routers their PHY in phys MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Name each router's Type-C PHY with phys, as the binding now describes, instead of the vendor phandle. The routers stay disabled here, so no default board changes. The built J616s device tree passes the router schema. Not run on a USB4/Thunderbolt device. Signed-off-by: František Balázsy --- arch/arm64/boot/dts/apple/t6040-usb4.dtsi | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t6040-usb4.dtsi b/arch/arm64/boot/dts/apple/t6040-usb4.dtsi index 13b50c18e50c0..cf75493f031b3 100644 --- a/arch/arm64/boot/dts/apple/t6040-usb4.dtsi +++ b/arch/arm64/boot/dts/apple/t6040-usb4.dtsi @@ -37,7 +37,8 @@ pinctrl-0 = <&usb4_0_lstx_pins>; lstx-gpios = <&pinctrl_aop 49 GPIO_ACTIVE_HIGH>; /* The router starts only over its port's Type-C PHY in CIO mode. */ - apple,atc-phy = <&atcphy0>; + phys = <&atcphy0 PHY_TYPE_USB2>; + phy-names = "cio"; power-domains = <&ps_atc0_cio>, <&ps_atc0_cio_pcie>, <&ps_atc0_cio_usb>, <&ps_atc0_pcie>; thunderbolt-switch; @@ -136,7 +137,8 @@ pinctrl-0 = <&usb4_1_lstx_pins>; lstx-gpios = <&pinctrl_aop 51 GPIO_ACTIVE_HIGH>; /* The router starts only over its port's Type-C PHY in CIO mode. */ - apple,atc-phy = <&atcphy1>; + phys = <&atcphy1 PHY_TYPE_USB2>; + phy-names = "cio"; power-domains = <&ps_atc1_cio>, <&ps_atc1_cio_pcie>, <&ps_atc1_cio_usb>, <&ps_atc1_pcie>; thunderbolt-switch; @@ -235,7 +237,8 @@ pinctrl-0 = <&usb4_2_lstx_pins>; lstx-gpios = <&pinctrl_aop 53 GPIO_ACTIVE_HIGH>; /* The router starts only over its port's Type-C PHY in CIO mode. */ - apple,atc-phy = <&atcphy2>; + phys = <&atcphy2 PHY_TYPE_USB2>; + phy-names = "cio"; power-domains = <&ps_atc2_cio>, <&ps_atc2_cio_pcie>, <&ps_atc2_cio_usb>, <&ps_atc2_pcie>; thunderbolt-switch; From c44d77bad3f206dd3165ab9f8e3f01dcc36e3c4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Tue, 10 Nov 2026 16:34:02 +0100 Subject: [PATCH 23/49] PM: hibernate: tell drivers a restored image from a failed one, and allow a platform-fixed layout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Drivers that hand a coprocessor over across hibernation need to know, in their restore callbacks, whether the image was really restored or the PM core is unwinding an aborted hibernation. Add pm_hibernate_is_restored() (with a Rust helper) and let a boot chain that keeps the memory layout fixed (aura hib=1) admit hibernation where the platform would otherwise be refused. Signed-off-by: František Balázsy --- .../admin-guide/kernel-parameters.txt | 9 +++ include/linux/suspend.h | 6 ++ kernel/power/hibernate.c | 42 +++++++++++++- kernel/power/power.h | 1 + kernel/power/snapshot.c | 46 +++++++++++++++ kernel/power/swap.c | 58 ++++++++++++++++++- 6 files changed, 159 insertions(+), 3 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 2e6fa8b49752e..9ce5baf6854e7 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -549,6 +549,15 @@ Kernel parameters autoconf= [IPV6] See Documentation/networking/ipv6.rst. + apple_pmuv3_traps= + [ARM64,EARLY] Enable the IMPDEF PMUv3 trapping of KVM + guests (HACR_EL2 bit 56) on Apple cores where it has + not been verified yet, currently the M4 Pro/Max (T6040) + E and P cores. With it, KVM advertises a PMUv3 to its + guests backed by the Apple CPU PMU driver; without it + those guests see no PMU. Default: off on these cores. + Format: , a bare "apple_pmuv3_traps" means on. + apm= [APM] Advanced Power Management See header of arch/x86/kernel/apm_32.c. diff --git a/include/linux/suspend.h b/include/linux/suspend.h index 365437ce2cc02..2ebbb01fa14cc 100644 --- a/include/linux/suspend.h +++ b/include/linux/suspend.h @@ -453,6 +453,12 @@ bool pm_hibernation_mode_is_suspend(void); static inline bool pm_hibernation_mode_is_suspend(void) { return false; } #endif +#ifdef CONFIG_HIBERNATION +bool pm_hibernate_is_restored(void); +#else +static inline bool pm_hibernate_is_restored(void) { return false; } +#endif + int arch_resume_nosmt(void); #ifdef CONFIG_HIBERNATION_SNAPSHOT_DEV diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c index 890bf7b447f89..a8d992bb4a2c7 100644 --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -81,6 +82,25 @@ static const struct platform_hibernation_ops *hibernation_ops; static atomic_t hibernate_atomic = ATOMIC_INIT(1); +/* Set when swsusp_arch_suspend() returned in a kernel restored from an image. */ +static bool hibernate_restored; + +/** + * pm_hibernate_is_restored - Whether this kernel was just restored from an image. + * + * Devices get PMSG_RESTORE both in the kernel restored from a hibernation image + * and in the kernel that hibernated when hibernation is aborted before the image + * is created (a device failed to freeze, a wakeup event). Only in the first case + * did the hardware go through a boot. True from the restore until the next + * hibernation starts (hibernation_snapshot()); meant for the restore callbacks + * and the PM_POST_HIBERNATION notifiers. + */ +bool pm_hibernate_is_restored(void) +{ + return READ_ONCE(hibernate_restored); +} +EXPORT_SYMBOL_GPL(pm_hibernate_is_restored); + #ifdef CONFIG_SUSPEND /** * pm_hibernation_mode_is_suspend - Check if hibernation has been set to suspend @@ -123,7 +143,13 @@ bool hibernation_in_progress(void) */ static bool hibernation_platform_blocked(void) { - return of_machine_is_compatible("apple,arm-platform"); + /* + * Except where the boot object gives the OS a fixed memory layout and + * the drivers rebuild their coprocessor state from the cold boot that + * restores the image (aura hib=1, see aura-hibernate.c). + */ + return of_machine_is_compatible("apple,arm-platform") && + !aura_hibernate_layout_fixed(); } static bool hibernation_generic_available(void) @@ -399,6 +425,7 @@ static int create_image(int platform_mode) if (!in_suspend) { events_check_enabled = false; clear_or_poison_free_pages(); + WRITE_ONCE(hibernate_restored, !error); } platform_leave(platform_mode); @@ -438,6 +465,7 @@ int hibernation_snapshot(int platform_mode) int error; pm_suspend_clear_flags(); + WRITE_ONCE(hibernate_restored, false); error = platform_begin(platform_mode); if (error) goto Close; @@ -774,6 +802,18 @@ static int load_image_and_restore(void) } error = swsusp_read(&flags); + if (!error) { + /* + * The image is in memory now. Clear its on-disk signature + * before the device restore, so that a restore which hangs + * (for example a co-processor that does not come back after + * the cold boot) cannot leave a valid image for the next boot + * to resume into the same hang. swsusp_close() releases the + * resume device, so do it while that is still open. + */ + if (swsusp_invalidate_sig()) + pr_warn("could not invalidate the image signature; a failed restore may repeat\n"); + } swsusp_close(); if (!error) error = hibernation_restore(flags & SF_PLATFORM_MODE); diff --git a/kernel/power/power.h b/kernel/power/power.h index 75b63843886ee..6c269ce9410ec 100644 --- a/kernel/power/power.h +++ b/kernel/power/power.h @@ -201,6 +201,7 @@ extern void swsusp_free(void); extern int swsusp_read(unsigned int *flags_p); extern int swsusp_write(unsigned int flags); void swsusp_close(void); +int swsusp_invalidate_sig(void); #ifdef CONFIG_SUSPEND extern int swsusp_unmark(void); #else diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c index b209712cb2c3a..6ab21287493b5 100644 --- a/kernel/power/snapshot.c +++ b/kernel/power/snapshot.c @@ -36,6 +36,7 @@ #include #include #include +#include #include "power.h" @@ -2750,6 +2751,49 @@ static void *get_buffer(struct memory_bitmap *bm, struct chain_allocator *ca) return pbe->address; } +#ifdef CONFIG_ARM64 +/* + * Most image pages are loaded straight into their original frames through + * the cacheable linear map (only conflicting pages go through restore_pblist). + * Non-coherent DMA masters (on Apple SoCs: the GPU page table walker, DCP, + * every RTKit co-processor, the NVMe queues) read DRAM, and a later eviction + * of a dirty line would overwrite what a device wrote since. Clean and + * invalidate every image page to the PoC before the jump. + */ +static void swsusp_clean_restored_image(void) +{ + unsigned long pfn, n = 0, skipped = 0; + + memory_bm_position_reset(&orig_bm); + for (pfn = memory_bm_next_pfn(&orig_bm); pfn != BM_END_OF_MAP; + pfn = memory_bm_next_pfn(&orig_bm)) { + unsigned long va; + + if (!pfn_valid(pfn)) + continue; + /* + * Not in the boot kernel's linear map (for example the linear + * alias of the kernel image, which faults when touched): + * nothing was loaded there through the linear map. Such frames + * are restored by the restore_pblist copy, which cleans each + * copied page itself. + */ + if (!kernel_page_present(pfn_to_page(pfn))) { + skipped++; + continue; + } + va = (unsigned long)page_address(pfn_to_page(pfn)); + dcache_clean_inval_poc(va, va + PAGE_SIZE); + if (!(++n & 0xffff)) + cond_resched(); + } + pr_debug("%lu image pages cleaned to PoC, %lu outside the linear map left to the copy\n", + n, skipped); +} +#else +static inline void swsusp_clean_restored_image(void) {} +#endif + /** * snapshot_write_next - Get the address to store the next image page. * @handle: Snapshot handle structure to guide the writing. @@ -2871,6 +2915,8 @@ int snapshot_write_finalize(struct snapshot_handle *handle) error = hibernate_restore_protect_page(handle->buffer); /* Do that only if we have loaded the image entirely */ if (handle->cur > 1 && handle->cur > nr_meta_pages + nr_copy_pages + nr_zero_pages) { + /* while orig_bm still lists the image: recycling overwrites it */ + swsusp_clean_restored_image(); memory_bm_recycle(&orig_bm); free_highmem_data(); } diff --git a/kernel/power/swap.c b/kernel/power/swap.c index c78f1593600bb..8cc439448e053 100644 --- a/kernel/power/swap.c +++ b/kernel/power/swap.c @@ -483,11 +483,27 @@ static int flush_swap_writer(struct swap_map_handle *handle) static int swap_writer_finish(struct swap_map_handle *handle, unsigned int flags, int error) { + int flush; + if (!error) { pr_info("S"); error = mark_swapfiles(handle, flags); pr_cont("|\n"); flush_swap_writer(handle); + /* + * Make the image durable now: otherwise the device cache is + * flushed only by the device shutdown in the power-off that + * follows, and a platform whose power-off does not get that far + * loses the image. A failed flush leaves no durable image: drop + * the signature durably (unlike swsusp_unmark()) so that no + * later boot resumes from freed swap. + */ + flush = blkdev_issue_flush(file_bdev(hib_resume_bdev_file)); + if (!error && flush) { + if (swsusp_invalidate_sig()) + pr_err("image flush failed and the signature could not be dropped\n"); + error = flush; + } } if (error) @@ -1583,8 +1599,13 @@ int swsusp_check(bool exclusive) if (!memcmp(HIBERNATE_SIG, swsusp_header->sig, 10)) { memcpy(swsusp_header->sig, swsusp_header->orig_sig, 10); swsusp_header_flags = swsusp_header->flags; - /* Reset swap signature now */ - error = hib_submit_io_sync(REQ_OP_WRITE | REQ_SYNC, + /* + * Reset swap signature now. FUA: a REQ_SYNC write + * can sit in a volatile device cache, and a hard + * power-off of a hung restore then loses it and the + * next boot resumes the same image again. + */ + error = hib_submit_io_sync(REQ_OP_WRITE | REQ_SYNC | REQ_FUA, swsusp_resume_block, swsusp_header); } else { @@ -1625,6 +1646,39 @@ void swsusp_close(void) fput(hib_resume_bdev_file); } +/* + * Clear the on-disk image signature without freeing the swap pages. + * Called on the resume path right after the image is read into memory and + * before the device restore, so a restore that hangs (a co-processor that does + * not come back after a cold boot) cannot leave a valid image that the next + * boot resumes into the same hang. Unlike swsusp_unmark() this keeps the swap + * pages: the resuming kernel is about to jump into the restored image, and + * freeing swap here would desync the restored kernel's swap accounting. + */ +int swsusp_invalidate_sig(void) +{ + int error; + + error = hib_submit_io_sync(REQ_OP_READ, swsusp_resume_block, swsusp_header); + if (error) + return error; + /* + * swsusp_check() normally reset the signature already; that write may + * still be in the device's volatile cache, so rewrite the header with + * FUA either way and make the reset durable before the restore. + */ + if (!memcmp(HIBERNATE_SIG, swsusp_header->sig, 10)) + memcpy(swsusp_header->sig, swsusp_header->orig_sig, 10); + else if (memcmp(swsusp_header->sig, swsusp_header->orig_sig, 10)) + return -ENODEV; + error = hib_submit_io_sync(REQ_OP_WRITE | REQ_SYNC | REQ_FUA, + swsusp_resume_block, swsusp_header); + /* A device that ignores FUA still honours an explicit cache flush. */ + if (!error) + error = blkdev_issue_flush(file_bdev(hib_resume_bdev_file)); + return error; +} + /** * swsusp_unmark - Unmark swsusp signature in the resume device * From 95ba8c3214821549c7b538f965285572a02f3d3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Tue, 10 Nov 2026 16:34:02 +0100 Subject: [PATCH 24/49] arm64: hibernate and spin-table CPUs at EL2 on M4 Pro (T6040) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With Linux at EL2 under aura, secondary CPUs come up from a spin table and the boot CPU has no enable-method. Let the spin-table CPUs be parked and released again across hibernation and suspend-to-RAM (a pen in the kernel image the locked RVBAR relay returns to), restore the EL2 state the hibernation resume needs, and keep the T6040 errata on the restored CPUs. An offlined RVBAR spin-table CPU waits in the kernel's own text, so spin_table_cpus_stuck() refuses kexec and hibernation for it. For a hibernation the pen is what takes those CPUs out of the memory the restore overwrites: a kernel that has it (KEXEC_CORE, for cpu_soft_restart()) is not stuck there, and swsusp_arch_suspend() asks spin_table_hibernate_cpus_stuck() instead. kexec keeps the check. Signed-off-by: František Balázsy --- arch/arm64/include/asm/cpu_ops.h | 19 ++ arch/arm64/kernel/Makefile | 3 + arch/arm64/kernel/cpu_errata.c | 34 +++- arch/arm64/kernel/hibernate-asm.S | 11 +- arch/arm64/kernel/hibernate.c | 149 +++++++++++++++- arch/arm64/kernel/smp.c | 23 ++- arch/arm64/kernel/smp_spin_table.c | 233 ++++++++++++++++++++++++- arch/arm64/kernel/smp_spin_table_pen.S | 34 ++++ 8 files changed, 480 insertions(+), 26 deletions(-) create mode 100644 arch/arm64/kernel/smp_spin_table_pen.S diff --git a/arch/arm64/include/asm/cpu_ops.h b/arch/arm64/include/asm/cpu_ops.h index 4ed50e0dc0b5c..6626229cbec35 100644 --- a/arch/arm64/include/asm/cpu_ops.h +++ b/arch/arm64/include/asm/cpu_ops.h @@ -66,6 +66,12 @@ struct spin_table_power_ops { #ifdef CONFIG_HOTPLUG_CPU int spin_table_set_power_ops(const struct spin_table_power_ops *ops); +#ifdef CONFIG_HIBERNATION +int spin_table_hibernate_pen_begin(phys_addr_t image_ttbr1, int primary); +void spin_table_hibernate_pen_end(bool frozen); +void spin_table_hibernate_restored(void); +bool spin_table_hibernate_cpus_stuck(void); +#endif int spin_table_hold_parked(void); void spin_table_unhold_parked(void); int spin_table_stop_parked(void); @@ -99,6 +105,19 @@ static inline bool spin_table_cpus_stuck(void) } #endif +#if !defined(CONFIG_HOTPLUG_CPU) || !defined(CONFIG_HIBERNATION) +static inline int spin_table_hibernate_pen_begin(phys_addr_t image_ttbr1, int primary) +{ + return 0; +} +static inline void spin_table_hibernate_pen_end(bool frozen) {} +static inline void spin_table_hibernate_restored(void) {} +static inline bool spin_table_hibernate_cpus_stuck(void) +{ + return false; +} +#endif + int __init init_cpu_ops(int cpu); extern const struct cpu_operations *get_cpu_ops(int cpu); diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index cac465111055b..263d682d48620 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -65,6 +65,9 @@ obj-$(CONFIG_ARM64_ACPI_PARKING_PROTOCOL) += acpi_parking_protocol.o obj-$(CONFIG_PARAVIRT) += paravirt.o obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o obj-$(CONFIG_HIBERNATION) += hibernate.o hibernate-asm.o +ifdef CONFIG_HOTPLUG_CPU +obj-$(CONFIG_HIBERNATION) += smp_spin_table_pen.o +endif obj-$(CONFIG_ELF_CORE) += elfcore.o obj-$(CONFIG_KEXEC_CORE) += machine_kexec.o relocate_kernel.o \ cpu-reset.o diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index fa1a6a83caa97..d5c3fe7533802 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -291,6 +292,29 @@ static const struct midr_range apple_cpus[] = { {}, }; +/* + * Apple cores that aren't in apple_cpus whose IMPDEF PMUv3 traps (HACR_EL2 + * bit 56) are turned on only when asked for on the command line + * (apple_pmuv3_traps), until they have been verified on these cores. + */ +static const struct midr_range apple_m4_cpus[] = { + MIDR_ALL_VERSIONS(MIDR_APPLE_T6040_E), + MIDR_ALL_VERSIONS(MIDR_APPLE_T6040_P), + {}, +}; + +static bool apple_pmuv3_traps_optin __ro_after_init; + +static int __init early_apple_pmuv3_traps_cfg(char *arg) +{ + /* A bare "apple_pmuv3_traps" enables the traps. */ + if (!arg || !*arg) + arg = "on"; + + return kstrtobool(arg, &apple_pmuv3_traps_optin); +} +early_param("apple_pmuv3_traps", early_apple_pmuv3_traps_cfg); + static bool has_impdef_pmuv3(const struct arm64_cpu_capabilities *entry, int scope) { u64 dfr0 = read_sanitised_ftr_reg(SYS_ID_AA64DFR0_EL1); @@ -304,13 +328,13 @@ static bool has_impdef_pmuv3(const struct arm64_cpu_capabilities *entry, int sco if (pmuver != ID_AA64DFR0_EL1_PMUVer_IMP_DEF) return false; - return is_midr_in_range_list(apple_cpus); + if (is_midr_in_range_list(apple_cpus)) + return true; + + return apple_pmuv3_traps_optin && is_midr_in_range_list(apple_m4_cpus); } -/* - * Apple cores with the same vGIC as M1/M2 that aren't in apple_cpus yet: - * that list also turns on the IMPDEF PMUv3 traps, unverified here. - */ +/* Apple cores with the same vGIC as M1/M2 that aren't in apple_cpus yet. */ static const struct midr_range apple_broken_seis_cpus[] = { MIDR_ALL_VERSIONS(MIDR_APPLE_T6040_E), MIDR_ALL_VERSIONS(MIDR_APPLE_T6040_P), diff --git a/arch/arm64/kernel/hibernate-asm.S b/arch/arm64/kernel/hibernate-asm.S index 2baefe7a82d36..f30269635a4fd 100644 --- a/arch/arm64/kernel/hibernate-asm.S +++ b/arch/arm64/kernel/hibernate-asm.S @@ -67,19 +67,24 @@ SYM_CODE_START(swsusp_arch_suspend_exit) copy_page x0, x1, x2, x3, x4, x5, x6, x7, x8, x9 add x1, x10, #PAGE_SIZE - /* Clean the copied page to PoU - based on caches_clean_inval_pou() */ + /* + * Clean the copied page to PoC, not only PoU: on Apple SoCs the + * coprocessors (GPU UAT walker, DCP, ...) are not cache coherent and + * read the restored pages from DRAM. Clean+invalidate to PoC also + * covers what caches_clean_inval_pou() did for the I-side. + */ raw_dcache_line_size x2, x3 sub x3, x2, #1 bic x4, x10, x3 2: /* clean D line / unified line */ -alternative_insn "dc cvau, x4", "dc civac, x4", ARM64_WORKAROUND_CLEAN_CACHE + dc civac, x4 add x4, x4, x2 cmp x4, x1 b.lo 2b ldr x19, [x19, #HIBERN_PBE_NEXT] cbnz x19, 1b - dsb ish /* wait for PoU cleaning to finish */ + dsb ish /* wait for PoC cleaning to finish */ /* switch to the restored kernels page tables */ break_before_make_ttbr_switch x25, x21, x6, x8 diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c index 9398c8d0ecb03..048a29d5d54fd 100644 --- a/arch/arm64/kernel/hibernate.c +++ b/arch/arm64/kernel/hibernate.c @@ -12,9 +12,12 @@ #define pr_fmt(x) "hibernate: " x #include #include +#include +#include #include #include #include +#include #include #include @@ -81,6 +84,9 @@ static struct arch_hibernate_hdr { phys_addr_t __hyp_stub_vectors; u64 sleep_cpu_mpidr; + + /* What the boot loader decided for the boot that wrote the image. */ + u64 boot_layout; } resume_hdr; static inline void arch_hdr_invariants(struct arch_hibernate_hdr_invariants *i) @@ -89,13 +95,127 @@ static inline void arch_hdr_invariants(struct arch_hibernate_hdr_invariants *i) memcpy(i->uts_version, init_utsname()->version, sizeof(i->uts_version)); } +static u64 hibernate_layout_mix(u64 h, const void *p, size_t len) +{ + const u8 *b = p; + + while (len--) { + h ^= *b++; + h *= 0x100000001b3ULL; /* FNV-1a */ + } + return h; +} + +/* + * The image restores every page to the frame it came from, so the boot that + * resumes it must give the kernel what the boot that wrote it did: the same + * RAM, and on Apple machines at EL2 the same CTXR exec window (secondaries only + * execute inside it) and aura's fixed hibernation layout. A boot loader decides + * them on every boot; the kernel build check above cannot see them. + * + * aura's own image moves with the boot object, and its CPU release addresses + * and S2R mailbox with it, inside the range the layout keeps from Linux. The + * restored kernel uses neither address of the boot that wrote the image: its + * CPUs come back from the boot kernel's pen, a CPU started at its reset vector + * again finds the release target the boot kernel wrote (both kernels run at the + * window's fixed address), and the T6040 sleep driver takes this boot's mailbox + * from aura's tree after the restore. What has to match is the spin table's + * shape (the same CPUs, at the same offsets from the mailbox) and that this + * boot keeps all of it out of the image. + */ +/* + * Mix one memory span less the parts in @ex, ranges that this boot keeps out of + * the image. iBoot's no-map allocations inside aura's fixed layout (the DCP + * oslogs, ANS firmware) move with the boot object and split memblock's regions + * differently on every boot; what lies there never holds an image page. + */ +static u64 hibernate_mix_span(u64 h, u64 b, u64 e, u32 flags, const u64 (*ex)[2], int nex) +{ + u64 size; + + if (b >= e) + return h; + if (nex && e > ex[0][0] && b < ex[0][1]) { + h = hibernate_mix_span(h, b, ex[0][0], flags, ex + 1, nex - 1); + return hibernate_mix_span(h, ex[0][1], e, flags, ex + 1, nex - 1); + } + if (nex) + return hibernate_mix_span(h, b, e, flags, ex + 1, nex - 1); + size = e - b; + h = hibernate_layout_mix(h, &b, sizeof(b)); + h = hibernate_layout_mix(h, &size, sizeof(size)); + return hibernate_layout_mix(h, &flags, sizeof(flags)); +} + +static u64 hibernate_boot_layout(void) +{ + static const char * const chosen_props[] = { + "aura,hibernate-layout", "aura,hibernate-dt", + "aurora,ctxr-exec-window", + }; + u64 h = 0xcbf29ce484222325ULL, mbox = 0, rel, hwid; + u64 layout[2], win[2], ex[2][2]; + struct memblock_region *r; + int nex = 0; + struct device_node *np; + bool have_mbox = false; + const void *v; + u8 kept; + int i, len; + + np = of_find_node_by_path("/chosen"); + for (i = 0; np && i < ARRAY_SIZE(chosen_props); i++) { + v = of_get_property(np, chosen_props[i], &len); + if (!v) + continue; + h = hibernate_layout_mix(h, chosen_props[i], strlen(chosen_props[i])); + h = hibernate_layout_mix(h, v, len); + } + if (np && !of_property_read_u64(np, "aurora,s2r-mailbox", &mbox)) { + have_mbox = true; + kept = aura_hibernate_pfn_nosave(PHYS_PFN(mbox)); + h = hibernate_layout_mix(h, "aurora,s2r-mailbox", strlen("aurora,s2r-mailbox")); + h = hibernate_layout_mix(h, &kept, sizeof(kept)); + } + /* aura's layout less the OS window, only where all of it is kept out of the image */ + if (np && !of_property_read_u64_array(np, "aura,hibernate-layout", layout, 2) && + !of_property_read_u64_array(np, "aurora,ctxr-exec-window", win, 2) && + layout[0] <= win[0] && win[0] + win[1] <= layout[1]) { + ex[nex][0] = layout[0]; + ex[nex][1] = win[0]; + if (aura_hibernate_range_nosave(ex[nex][0], ex[nex][1])) + nex++; + ex[nex][0] = win[0] + win[1]; + ex[nex][1] = layout[1]; + if (aura_hibernate_range_nosave(ex[nex][0], ex[nex][1])) + nex++; + } + of_node_put(np); + + for_each_of_cpu_node(np) { + if (of_property_read_u64(np, "cpu-release-addr", &rel)) + continue; + hwid = of_get_cpu_hwid(np, 0); + kept = aura_hibernate_pfn_nosave(PHYS_PFN(rel)); + if (have_mbox) + rel -= mbox; + h = hibernate_layout_mix(h, &hwid, sizeof(hwid)); + h = hibernate_layout_mix(h, &rel, sizeof(rel)); + h = hibernate_layout_mix(h, &kept, sizeof(kept)); + } + + for_each_mem_region(r) + h = hibernate_mix_span(h, r->base, r->base + r->size, r->flags, ex, nex); + return h; +} + int pfn_is_nosave(unsigned long pfn) { unsigned long nosave_begin_pfn = sym_to_pfn(&__nosave_begin); unsigned long nosave_end_pfn = sym_to_pfn(&__nosave_end - 1); return ((pfn >= nosave_begin_pfn) && (pfn <= nosave_end_pfn)) || - crash_is_nosave(pfn); + crash_is_nosave(pfn) || aura_hibernate_pfn_nosave(pfn); } void notrace save_processor_state(void) @@ -129,8 +249,9 @@ int arch_hibernation_header_save(void *addr, unsigned int max_size) return -ENODEV; } hdr->sleep_cpu_mpidr = cpu_logical_map(sleep_cpu); - pr_info("Hibernating on CPU %d [mpidr:0x%llx]\n", sleep_cpu, - hdr->sleep_cpu_mpidr); + hdr->boot_layout = hibernate_boot_layout(); + pr_info("Hibernating on CPU %d [mpidr:0x%llx], boot layout %016llx\n", sleep_cpu, + hdr->sleep_cpu_mpidr, hdr->boot_layout); return 0; } @@ -147,6 +268,12 @@ int arch_hibernation_header_restore(void *addr) pr_crit("Hibernate image not generated by this kernel!\n"); return -EINVAL; } + if (hdr->boot_layout != hibernate_boot_layout()) { + pr_crit("Hibernate image written under another boot layout (%016llx, this boot %016llx): not restored\n", + hdr->boot_layout, hibernate_boot_layout()); + return -EINVAL; + } + pr_info("Hibernate image written under this boot layout (%016llx)\n", hdr->boot_layout); sleep_cpu = get_logical_index(hdr->sleep_cpu_mpidr); pr_info("Hibernated on CPU %d [mpidr:0x%llx]\n", sleep_cpu, @@ -337,7 +464,7 @@ int swsusp_arch_suspend(void) unsigned long flags; struct sleep_stack_data state; - if (cpus_are_stuck_in_kernel() || spin_table_cpus_stuck()) { + if (cpus_are_stuck_in_kernel() || spin_table_hibernate_cpus_stuck()) { pr_err("Can't hibernate: no mechanism to offline secondary CPUs.\n"); return -EBUSY; } @@ -386,6 +513,9 @@ int swsusp_arch_suspend(void) sleep_cpu = -EINVAL; __cpu_suspend_exit(); + /* The boot kernel's secondaries are in its pen, not where the image parked them. */ + spin_table_hibernate_restored(); + /* * Just in case the boot kernel did turn the SSBD * mitigation off behind our back, let's set the state @@ -489,10 +619,19 @@ int __nocfi swsusp_arch_resume(void) int hibernate_resume_nonboot_cpu_disable(void) { + int ret; + if (sleep_cpu < 0) { pr_err("Failing to resume from hibernate on an unknown CPU.\n"); return -ENODEV; } - return freeze_secondary_cpus(sleep_cpu); + /* Parking spin-table CPUs wait outside the image while it is restored. */ + ret = spin_table_hibernate_pen_begin(resume_hdr.ttbr1_el1, sleep_cpu); + if (ret) + return ret; + ret = freeze_secondary_cpus(sleep_cpu); + spin_table_hibernate_pen_end(!ret); + + return ret; } diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c index f6b5decff53da..02badcc245d05 100644 --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -1354,14 +1354,29 @@ bool smp_crash_stop_failed(void) } #endif +/* + * The CPUs that have to leave the kernel are the others. A boot CPU whose node + * carries no enable-method (Apple boot objects describe only the secondaries' + * spin table) has no operations of its own: then every other possible CPU must + * have a way out. + */ static bool have_cpu_die(void) { #ifdef CONFIG_HOTPLUG_CPU - int any_cpu = raw_smp_processor_id(); - const struct cpu_operations *ops = get_cpu_ops(any_cpu); + int this_cpu = raw_smp_processor_id(), cpu; + const struct cpu_operations *ops = get_cpu_ops(this_cpu); - if (ops && ops->cpu_die) - return true; + if (ops) + return ops->cpu_die != NULL; + + for_each_possible_cpu(cpu) { + if (cpu == this_cpu) + continue; + ops = get_cpu_ops(cpu); + if (!ops || !ops->cpu_die) + return false; + } + return num_possible_cpus() > 1; #endif return false; } diff --git a/arch/arm64/kernel/smp_spin_table.c b/arch/arm64/kernel/smp_spin_table.c index 2d7660bd22f80..2326f3f5df57a 100644 --- a/arch/arm64/kernel/smp_spin_table.c +++ b/arch/arm64/kernel/smp_spin_table.c @@ -5,10 +5,12 @@ * Copyright (C) 2013 ARM Ltd. */ +#include #include #include #include #include +#include #include #include @@ -163,6 +165,198 @@ static bool spin_table_stop_released; #define SPIN_TABLE_WAIT_US 100000 +#if defined(CONFIG_HIBERNATION) && defined(CONFIG_KEXEC_CORE) +/* + * Resuming from hibernation, the boot kernel takes its secondaries offline and + * then overwrites every page the image saved, the park and its cpumasks + * included. A CPU parked there would run on in memory that changes under it, + * and its translation tables with it. On that path a CPU leaving the kernel + * waits instead in a pen the image doesn't contain: the code and a slot per + * CPU in .data..nosave, run with the MMU off. arm64 resumes only an image of + * the kernel build that is running; with the boot kernel loaded at the image + * kernel's physical address (checked when the resume starts) the pen is at the + * same place in both, and the restored kernel reads what the boot kernel left + * there. It + * starts each CPU from the pen through secondary_holding_pen, as at boot. + * Nothing is powered off, so this needs no platform power ops. + */ +#define SPIN_TABLE_PEN_MAGIC 0x314e455034535053ULL /* "SPS4PEN1" */ +#define SPIN_TABLE_PEN_HERE 0x45524548ULL /* "HERE", from the pen */ + +struct spin_table_pen_slot { + u64 release; /* where the CPU goes; 0 holds it */ + u64 here; /* the CPU reached the pen */ + u64 mpidr; +} __aligned(ARCH_DMA_MINALIGN); + +static struct { + u64 magic; + u64 self; /* this record's address in the kernel that wrote it */ + unsigned long penned[BITS_TO_LONGS(NR_CPUS)]; + struct spin_table_pen_slot slot[NR_CPUS]; +} spin_table_pen __nosavedata __aligned(ARCH_DMA_MINALIGN); + +extern char spin_table_hibernate_pen[]; +extern const struct cpu_operations smp_rvbar_spin_table_ops; +static struct cpumask spin_table_cpus_penned; +static bool spin_table_pen_requested; + +static void spin_table_pen_clean(void *start, size_t size) +{ + dcache_clean_inval_poc((unsigned long)start, (unsigned long)start + size); +} + +/* + * Resuming from hibernation, before the boot kernel takes its secondaries offline. + * The restored kernel finds the pen only where it is in its own image, which holds + * when the boot kernel is loaded at the image kernel's physical address. arm64 can + * restore from a boot kernel placed elsewhere (@image_ttbr1, the image's + * swapper_pg_dir, is used for the jump), but there the pen's frames are image + * frames: the restore would overwrite them while the penned CPUs run from them with + * the MMU off. Refuse the resume then, as long as a CPU other than @primary (the + * one that stays online) would need the pen. + */ +int spin_table_hibernate_pen_begin(phys_addr_t image_ttbr1, int primary) +{ + int cpu; + + /* No record of an earlier, abandoned resume may reach the restored kernel. */ + spin_table_pen.magic = 0; + spin_table_pen_clean(&spin_table_pen, sizeof(spin_table_pen.magic)); + + if (image_ttbr1 != __pa_symbol(swapper_pg_dir)) { + for_each_online_cpu(cpu) { + if (cpu == primary || get_cpu_ops(cpu) != &smp_rvbar_spin_table_ops) + continue; + pr_err("hibernation: the image's kernel ran at another physical address (swapper_pg_dir %pa, here %pa): spin-table CPUs cannot wait in this kernel's pen, resume refused\n", + &image_ttbr1, &(phys_addr_t){ __pa_symbol(swapper_pg_dir) }); + return -EINVAL; + } + return 0; + } + WRITE_ONCE(spin_table_pen_requested, true); + return 0; +} + +/* + * After they went offline. With all of them frozen, the restored kernel finds the + * record; otherwise the resume is abandoned and they go back online from the pen. + */ +void spin_table_hibernate_pen_end(bool frozen) +{ + unsigned int cpu; + + WRITE_ONCE(spin_table_pen_requested, false); + if (!frozen || cpumask_empty(&spin_table_cpus_penned)) + return; + + bitmap_zero(spin_table_pen.penned, NR_CPUS); + for_each_cpu(cpu, &spin_table_cpus_penned) + __set_bit(cpu, spin_table_pen.penned); + spin_table_pen.self = __pa_symbol(&spin_table_pen); + spin_table_pen.magic = SPIN_TABLE_PEN_MAGIC; + spin_table_pen_clean(&spin_table_pen, offsetof(typeof(spin_table_pen), slot)); + pr_info("hibernation: %u CPUs wait outside the image\n", + cpumask_weight(&spin_table_cpus_penned)); +} + +/* + * In the restored kernel, right after the image took over: the CPUs the image parked + * before its snapshot are in the boot kernel's pen now. + */ +void spin_table_hibernate_restored(void) +{ + unsigned int cpu, found = 0; + + if (spin_table_pen.magic != SPIN_TABLE_PEN_MAGIC) + return; + spin_table_pen.magic = 0; + spin_table_pen_clean(&spin_table_pen, sizeof(spin_table_pen.magic)); + if (spin_table_pen.self != __pa_symbol(&spin_table_pen)) { + pr_err("hibernation: the boot kernel's CPU pen was at %#llx, not here: its CPUs stay offline\n", + spin_table_pen.self); + return; + } + + cpumask_clear(&spin_table_cpus_penned); + for_each_present_cpu(cpu) { + if (!test_bit(cpu, spin_table_pen.penned)) + continue; + if (spin_table_pen.slot[cpu].mpidr != cpu_logical_map(cpu)) { + pr_err("hibernation: CPU%u: the pen holds MPIDR %#llx, not %#llx\n", cpu, + spin_table_pen.slot[cpu].mpidr, cpu_logical_map(cpu)); + continue; + } + cpumask_clear_cpu(cpu, &spin_table_cpus_parked); + cpumask_clear_cpu(cpu, &spin_table_cpus_held); + cpumask_clear_cpu(cpu, &spin_table_cpus_unpark); + cpumask_clear_cpu(cpu, &spin_table_cpus_off); + cpumask_set_cpu(cpu, &spin_table_cpus_penned); + found++; + } + pr_info("hibernation: %u CPUs start from the boot kernel's pen\n", found); +} + +/* Leaves the kernel for the pen; the boot CPU waits for it to arrive (cpu_kill). */ +static void __noreturn smp_rvbar_spin_table_pen(unsigned int cpu, u64 mpidr) +{ + struct spin_table_pen_slot *slot = &spin_table_pen.slot[cpu]; + typeof(cpu_soft_restart) *restart; + + slot->release = 0; + slot->here = 0; + slot->mpidr = mpidr; + spin_table_pen_clean(slot, sizeof(*slot)); + cpumask_set_cpu(cpu, &spin_table_cpus_penned); + + cpu_install_idmap(); + restart = (void *)__pa_symbol(cpu_soft_restart); + restart(0, __pa_symbol(spin_table_hibernate_pen), __pa_symbol(slot), 0, 0); + unreachable(); +} + +static bool spin_table_pen_arrived(unsigned int cpu) +{ + struct spin_table_pen_slot *slot = &spin_table_pen.slot[cpu]; + + /* Written with the MMU off: drop any copy of the line before reading. */ + dcache_inval_poc((unsigned long)slot, (unsigned long)(slot + 1)); + return READ_ONCE(slot->here) == SPIN_TABLE_PEN_HERE; +} + +/* Starts a CPU waiting in the pen; it goes on to secondary_holding_pen. */ +static void spin_table_pen_release(unsigned int cpu) +{ + struct spin_table_pen_slot *slot = &spin_table_pen.slot[cpu]; + + WRITE_ONCE(slot->release, __pa_symbol(secondary_holding_pen)); + spin_table_pen_clean(slot, sizeof(*slot)); +} +#else +static const bool spin_table_pen_requested; +static struct cpumask spin_table_cpus_penned; + +static void smp_rvbar_spin_table_pen(unsigned int cpu, u64 mpidr) +{ +} + +static bool spin_table_pen_arrived(unsigned int cpu) +{ + return false; +} + +static void spin_table_pen_release(unsigned int cpu) +{ +} + +#ifdef CONFIG_HIBERNATION +/* Without cpu_soft_restart() a CPU cannot leave the kernel: nothing to keep. */ +int spin_table_hibernate_pen_begin(phys_addr_t image_ttbr1, int primary) { return 0; } +void spin_table_hibernate_pen_end(bool frozen) {} +void spin_table_hibernate_restored(void) {} +#endif +#endif + int spin_table_set_power_ops(const struct spin_table_power_ops *ops) { return cmpxchg(&spin_table_power, NULL, ops) ? -EBUSY : 0; @@ -208,6 +402,9 @@ int spin_table_hold_parked(void) { int us; + if (!READ_ONCE(spin_table_power)) + return -EOPNOTSUPP; + WRITE_ONCE(spin_table_hold_requested, true); dsb(ish); sev(); @@ -278,7 +475,9 @@ static int smp_rvbar_spin_table_cpu_boot(unsigned int cpu) /* The CPU may run straight into the pen: release it before it starts. */ write_pen_release(mpidr); - if (cpumask_test_and_clear_cpu(cpu, &spin_table_cpus_off)) { + if (cpumask_test_and_clear_cpu(cpu, &spin_table_cpus_penned)) { + spin_table_pen_release(cpu); + } else if (cpumask_test_and_clear_cpu(cpu, &spin_table_cpus_off)) { ret = spin_table_power->cpu_on(mpidr); if (ret) { cpumask_set_cpu(cpu, &spin_table_cpus_off); @@ -301,10 +500,11 @@ static bool smp_rvbar_spin_table_cpu_can_disable(unsigned int cpu) static int smp_rvbar_spin_table_cpu_disable(unsigned int cpu) { - if (!IS_ENABLED(CONFIG_KEXEC_CORE)) - return -EOPNOTSUPP; - - return READ_ONCE(spin_table_power) ? 0 : -EOPNOTSUPP; + /* + * A parked CPU comes back through cpu_soft_restart(). Only stopping it for a + * suspend needs the platform's power ops (spin_table_hold_parked()). + */ + return IS_ENABLED(CONFIG_KEXEC_CORE) ? 0 : -EOPNOTSUPP; } #ifdef CONFIG_KEXEC_CORE @@ -350,11 +550,14 @@ static void smp_rvbar_spin_table_cpu_die(unsigned int cpu) u64 mpidr = cpu_logical_map(cpu); /* The early-boot and crash paths get here without hotplug support. */ - if (!READ_ONCE(spin_table_power) || !IS_ENABLED(CONFIG_KEXEC_CORE)) { + if (!IS_ENABLED(CONFIG_KEXEC_CORE)) { while (1) wfe(); } + if (READ_ONCE(spin_table_pen_requested)) + smp_rvbar_spin_table_pen(cpu, mpidr); + cpumask_set_cpu(cpu, &spin_table_cpus_parked); while (!cpumask_test_cpu(cpu, &spin_table_cpus_unpark)) { @@ -373,12 +576,11 @@ static int smp_rvbar_spin_table_cpu_kill(unsigned int cpu) { int us; - if (!READ_ONCE(spin_table_power)) - return 0; - for (us = 0; us < SPIN_TABLE_WAIT_US; us += 10) { if (cpumask_test_cpu(cpu, &spin_table_cpus_parked)) return 0; + if (cpumask_test_cpu(cpu, &spin_table_cpus_penned) && spin_table_pen_arrived(cpu)) + return 0; udelay(10); } @@ -409,4 +611,17 @@ bool spin_table_cpus_stuck(void) return true; return false; } + +#ifdef CONFIG_HIBERNATION +/* + * For a hibernation that only holds without the pen. With it the kernel that + * resumes an image takes its offlined CPUs out of the memory the restore + * overwrites before it starts (spin_table_hibernate_pen_begin()), and the + * restored kernel starts them from there. + */ +bool spin_table_hibernate_cpus_stuck(void) +{ + return !IS_ENABLED(CONFIG_KEXEC_CORE) && spin_table_cpus_stuck(); +} +#endif #endif /* CONFIG_HOTPLUG_CPU */ diff --git a/arch/arm64/kernel/smp_spin_table_pen.S b/arch/arm64/kernel/smp_spin_table_pen.S new file mode 100644 index 0000000000000..4610bc09ad002 --- /dev/null +++ b/arch/arm64/kernel/smp_spin_table_pen.S @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Where a parking spin-table CPU waits while the kernel resuming from + * hibernation overwrites memory with the image (smp_spin_table.c). + */ + +#include +#include + +/* + * x0: the CPU's struct spin_table_pen_slot: the entry address at offset 0, + * written by the kernel that starts the CPU again, and the arrival word at 8, + * written here. + * + * Entered from cpu_soft_restart() with the MMU and caches off and interrupts + * masked, so nothing here depends on the kernel's page tables or on cache + * maintenance by this CPU. The code and the slots are in .data..nosave: the + * image never contains them, so the restore leaves both as the boot kernel + * wrote them, at the same physical address in the restored kernel. + */ + .pushsection ".data..nosave", "aw" + .balign 64 +SYM_CODE_START(spin_table_hibernate_pen) + movz x1, #0x4548 + movk x1, #0x4552, lsl #16 // "HERE" + str x1, [x0, #8] + dsb sy +1: ldr x1, [x0] + cbnz x1, 2f + wfe + b 1b +2: br x1 +SYM_CODE_END(spin_table_hibernate_pen) + .popsection From 11e47b642eaa2d34c8058a2aa08e284639b39f7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Tue, 10 Nov 2026 16:34:02 +0100 Subject: [PATCH 25/49] soc: apple: hibernation under aura's fixed layout and RTKit coprocessor handoff MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit aura-hibernate reads the fixed boot layout aura publishes (hib=1) and refuses hibernation without it. RTKit gains a cold-restart/re-adopt path for a coprocessor the restored kernel finds running (or halted) under it, used by the DCP, AOP, SEP, ANE and SMC drivers after S4 and S2R. Signed-off-by: František Balázsy --- drivers/soc/apple/aura-hibernate.c | 461 +++++++++++++++++++++++ drivers/soc/apple/rtkit-helper.c | 243 +++++++++++- drivers/soc/apple/rtkit-hib-handoff.c | 211 +++++++++++ drivers/soc/apple/rtkit.c | 57 +++ include/linux/soc/apple/aura-hibernate.h | 38 ++ include/linux/soc/apple/rtkit-helper.h | 16 + include/linux/soc/apple/rtkit.h | 56 +++ rust/bindings/bindings_helper.h | 1 + rust/kernel/soc/apple/rtkit.rs | 9 + 9 files changed, 1089 insertions(+), 3 deletions(-) create mode 100644 drivers/soc/apple/aura-hibernate.c create mode 100644 drivers/soc/apple/rtkit-hib-handoff.c create mode 100644 include/linux/soc/apple/aura-hibernate.h diff --git a/drivers/soc/apple/aura-hibernate.c b/drivers/soc/apple/aura-hibernate.c new file mode 100644 index 0000000000000..59cfe189a4313 --- /dev/null +++ b/drivers/soc/apple/aura-hibernate.c @@ -0,0 +1,461 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Hibernation on Apple Silicon under an aura boot object. + * + * A hibernation image restores every saved page to the frame it was taken from, and swsusp saves + * reserved pages as long as they are mapped. Under aura the memory below Linux's own allocations + * holds what the boot loader keeps alive across the hand-off: aura itself (resident at EL2), its + * heap with the firmware buffers it handed over, the device tree, the initramfs, and the ranges + * the boot firmware placed for the co-processors. Restoring old contents there would overwrite + * the running boot loader and the live firmware state of the resuming boot. + * + * aura marks a boot whose layout is the same on every boot with /chosen/aura,hibernate-layout + * (start, end of the range it keeps from Linux). On such a boot every /memreserve/ range and every + * non-reusable /reserved-memory range is registered as nosave, except the kernel image itself. + * Without the property, hibernation and resume are refused, since the reserved ranges move. + * + * The boot firmware still places some firmware segments anew on every boot (the AOP __OS_LOG), + * inside the range aura keeps from Linux. A kernel restored from an image knows the device tree of the boot + * it was started on, not of the boot that resumed it. aura therefore hands Linux its device tree + * at a fixed address inside that range (/chosen/aura,hibernate-dt): the image does not save it, + * so after a resume the kernel finds this boot's tree at the address it was started with, and + * aura_hibernate_boot_fw_regions() reads a device's firmware regions from it. + * + * aura itself moves with the boot object, and with it its S2R mailbox: a restored kernel reads the + * mailbox of the boot it runs on from that tree too (aura_hibernate_boot_chosen_u64()). + */ + +#define pr_fmt(fmt) "aura-hibernate: " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static bool aura_layout_fixed; +static u64 aura_layout[2]; +/* Where aura puts the device tree on every boot; 0 when it does not. */ +static phys_addr_t aura_boot_dt; +#define AURA_BOOT_DT_MAX SZ_2M + +/* + * Ranges kept out of the image, in page frames. Filled once at late_initcall, + * read by arm64's pfn_is_nosave() for reserved pages. A static table avoids + * register_nosave_region(), which allocates from memblock and is meant for + * setup_arch() time. + */ +#define AURA_NOSAVE_MAX 128 +static struct { unsigned long start, end; } aura_nosave[AURA_NOSAVE_MAX]; +static unsigned int aura_nosave_count; + +bool aura_hibernate_layout_fixed(void) +{ + return aura_layout_fixed; +} + +bool aura_hibernate_pfn_nosave(unsigned long pfn) +{ + unsigned int i; + + for (i = 0; i < aura_nosave_count; i++) + if (pfn >= aura_nosave[i].start && pfn < aura_nosave[i].end) + return true; + return false; +} + +/* Whether the ranges kept out of the image cover all of [start, end). */ +bool aura_hibernate_range_nosave(u64 start, u64 end) +{ + unsigned long pfn = PFN_DOWN(start), last = PFN_UP(end); + unsigned int i; + bool moved; + + while (pfn < last) { + moved = false; + for (i = 0; i < aura_nosave_count; i++) { + if (pfn >= aura_nosave[i].start && pfn < aura_nosave[i].end) { + pfn = aura_nosave[i].end; + moved = true; + } + } + if (!moved) + return false; + } + return true; +} + +static void __init aura_nosave_add(unsigned long s, unsigned long e) +{ + if (s >= e) + return; + if (aura_nosave_count == AURA_NOSAVE_MAX) { + pr_warn("more than %d reserved ranges; hibernation stays disabled\n", AURA_NOSAVE_MAX); + aura_nosave_count++; + return; + } + if (aura_nosave_count < AURA_NOSAVE_MAX) { + aura_nosave[aura_nosave_count].start = s; + aura_nosave[aura_nosave_count].end = e; + aura_nosave_count++; + } +} + +static void __init aura_nosave_range(u64 start, u64 end, unsigned long kstart, unsigned long kend, + const char *what) +{ + unsigned long s = PFN_DOWN(start), e = PFN_UP(end); + + if (s >= e) + return; + /* The kernel image is Linux's own and is saved; split the range around it. */ + if (s < kend && e > kstart) { + if (s < kstart) + aura_nosave_add(s, kstart); + if (e > kend) + aura_nosave_add(kend, e); + } else { + aura_nosave_add(s, e); + } + pr_debug("nosave %s [%#llx, %#llx)\n", what, start, end); +} + +static bool aura_fw_region_kept(u64 start, u64 size) +{ + u64 end = start + size, a; + + if (end < start) + return false; + /* + * Inside the range aura keeps from Linux below its device tree slot, where the boot firmware places the + * firmware: reserved, and not saved in the image. Not the slot or aura's heap above it. + */ + if (start >= aura_layout[0] && end <= aura_boot_dt) + return true; + /* Otherwise Linux must neither own nor map any of it (no-map or not RAM). */ + for (a = start & PAGE_MASK; a < end; a += PAGE_SIZE) + if (memblock_is_map_memory(a)) + return false; + return true; +} + +/* + * Whether @fdt, mapped from @slot, is a tree aura wrote there: a valid header that fits the slot, and + * a /chosen naming this slot and the fixed layout @layout. + */ +static bool aura_slot_tree_valid(const void *fdt, phys_addr_t slot, const u64 layout[2]) +{ + const fdt64_t *v; + int node, len; + + if (fdt_check_header(fdt) || fdt_totalsize(fdt) > AURA_BOOT_DT_MAX) + return false; + node = fdt_path_offset(fdt, "/chosen"); + if (node < 0) + return false; + v = fdt_getprop(fdt, node, "aura,hibernate-dt", &len); + if (!v || len != sizeof(*v) || fdt64_ld(v) != slot) + return false; + v = fdt_getprop(fdt, node, "aura,hibernate-layout", &len); + return v && len == 2 * sizeof(*v) && fdt64_ld(&v[0]) == layout[0] && + fdt64_ld(&v[1]) == layout[1]; +} + +/* + * Reads the firmware memory-regions of @np (its memory-region phandles, each + * region's reg and the iommu-addresses entry naming @np) from the device tree + * of the running boot, which after a resume from disk is not the one the + * kernel was started with. Returns the number of regions, at most @max, or a + * negative errno: -ENODEV when aura does not hand the tree over at a fixed + * address. Only flat, untranslated layouts are accepted: @np's parent without + * dma-ranges, a /reserved-memory without a non-empty ranges. + */ +int aura_hibernate_boot_fw_regions(struct device_node *np, struct aura_fw_region *out, + unsigned int max) +{ + const fdt32_t *phandles, *p; + unsigned int n = 0; + int node, parent, len, ret, i; + u32 own; + char *path; + void *fdt; + + if (!aura_boot_dt || !np) + return -ENODEV; + fdt = memremap(aura_boot_dt, AURA_BOOT_DT_MAX, MEMREMAP_WB); + if (!fdt) + return -ENOMEM; + ret = -EINVAL; + /* The tree aura handed over on this boot, with the same fixed layout. */ + if (!aura_slot_tree_valid(fdt, aura_boot_dt, aura_layout)) + goto out; + + path = kasprintf(GFP_KERNEL, "%pOF", np); + if (!path) { + ret = -ENOMEM; + goto out; + } + node = fdt_path_offset(fdt, path); + kfree(path); + ret = -ENOENT; + if (node < 0) + goto out; + ret = -EINVAL; + own = fdt_get_phandle(fdt, node); + parent = fdt_parent_offset(fdt, node); + if (!own || parent < 0 || fdt_getprop(fdt, parent, "dma-ranges", NULL)) + goto out; + phandles = fdt_getprop(fdt, node, "memory-region", &len); + if (!phandles || len <= 0 || len % sizeof(*phandles)) + goto out; + + for (i = 0; i < len / (int)sizeof(*phandles); i++) { + int region, rparent, ac, sc, cells, pos, plen; + const fdt32_t *reg, *iommu; + u64 phys, size, iova = 0, length = 0; + bool found = false; + + region = fdt_node_offset_by_phandle(fdt, fdt32_to_cpu(phandles[i])); + if (region < 0) + goto out; + rparent = fdt_parent_offset(fdt, region); + if (rparent < 0) + goto out; + p = fdt_getprop(fdt, rparent, "ranges", &plen); + if (p && plen) + goto out; + ac = fdt_address_cells(fdt, rparent); + sc = fdt_size_cells(fdt, rparent); + reg = fdt_getprop(fdt, region, "reg", &plen); + if (ac < 1 || ac > 2 || sc < 1 || sc > 2 || !reg || + plen < (int)((ac + sc) * sizeof(*reg))) + goto out; + phys = fdt32_to_cpu(reg[0]); + if (ac == 2) + phys = phys << 32 | fdt32_to_cpu(reg[1]); + size = fdt32_to_cpu(reg[ac]); + if (sc == 2) + size = size << 32 | fdt32_to_cpu(reg[ac + 1]); + + /* Entries: owner phandle, then an address and a size in the owner's bus cells. */ + iommu = fdt_getprop(fdt, region, "iommu-addresses", &plen); + if (!iommu || plen <= 0 || plen % sizeof(*iommu)) + goto out; + cells = plen / sizeof(*iommu); + for (pos = 0; pos < cells;) { + u32 ph = fdt32_to_cpu(iommu[pos++]); + int owner = fdt_node_offset_by_phandle(fdt, ph), op, oac, osc; + + if (owner < 0) + goto out; + op = fdt_parent_offset(fdt, owner); + if (op < 0) + goto out; + oac = fdt_address_cells(fdt, op); + osc = fdt_size_cells(fdt, op); + if (oac < 1 || oac > 2 || osc < 1 || osc > 2 || oac + osc > cells - pos) + goto out; + if (ph == own) { + if (found) + goto out; + found = true; + iova = fdt32_to_cpu(iommu[pos]); + if (oac == 2) + iova = iova << 32 | fdt32_to_cpu(iommu[pos + 1]); + length = fdt32_to_cpu(iommu[pos + oac]); + if (osc == 2) + length = length << 32 | fdt32_to_cpu(iommu[pos + oac + 1]); + } + pos += oac + osc; + } + if (!found || length != size || !size) + goto out; + if (!aura_fw_region_kept(phys, size)) { + pr_warn("%pOF: this boot's firmware region [%#llx, +%#llx) is memory Linux owns\n", + np, phys, size); + ret = -EBUSY; + goto out; + } + if (n == max) { + ret = -E2BIG; + goto out; + } + out[n].phys = phys; + out[n].iova = iova; + out[n].size = size; + n++; + } + ret = n; +out: + memunmap(fdt); + return ret; +} +EXPORT_SYMBOL_GPL(aura_hibernate_boot_fw_regions); + +/* + * Reads the u64 property @name of /chosen from the device tree of the running boot, which after a + * resume from disk is not the one the kernel was started with. Returns 0, -ENODEV when aura does + * not hand the tree over at a fixed address, -EINVAL when the slot holds no tree for this layout, + * -ENOENT when the tree has no such property. + */ +int aura_hibernate_boot_chosen_u64(const char *name, u64 *val) +{ + const fdt64_t *v; + int node, len, ret; + void *fdt; + + if (!aura_boot_dt) + return -ENODEV; + fdt = memremap(aura_boot_dt, AURA_BOOT_DT_MAX, MEMREMAP_WB); + if (!fdt) + return -ENOMEM; + ret = -EINVAL; + if (!aura_slot_tree_valid(fdt, aura_boot_dt, aura_layout)) + goto out; + ret = -ENOENT; + node = fdt_path_offset(fdt, "/chosen"); + v = node < 0 ? NULL : fdt_getprop(fdt, node, name, &len); + if (!v || len != sizeof(*v)) + goto out; + *val = fdt64_ld(v); + ret = 0; +out: + memunmap(fdt); + return ret; +} +EXPORT_SYMBOL_GPL(aura_hibernate_boot_chosen_u64); + +struct aura_hibernate_reprobe { + struct work_struct work; + struct device *dev; +}; + +static void aura_hibernate_reprobe_work(struct work_struct *work) +{ + struct aura_hibernate_reprobe *rp = container_of(work, struct aura_hibernate_reprobe, work); + int ret; + + ret = device_reprobe(rp->dev); + if (ret) + dev_err(rp->dev, "probe after the resume from disk failed: %d\n", ret); + put_device(rp->dev); + kfree(rp); +} + +/* + * Unbinds @dev and probes it again once the tasks are thawed, for a driver whose co-processor + * the boot that resumed the image left halted: its unbind and its probe know how to drop a + * session that died under it and start the firmware anew, as at boot, and a restore callback + * cannot run either. The work runs on the freezable workqueue, which the restore finds frozen, + * so it starts after every device's restore and its complete step, when probing is allowed + * again. Built in, so that a driver module going away meanwhile leaves nothing behind. + */ +int aura_hibernate_reprobe_after_thaw(struct device *dev) +{ + struct aura_hibernate_reprobe *rp; + + rp = kzalloc_obj(*rp); + if (!rp) + return -ENOMEM; + INIT_WORK(&rp->work, aura_hibernate_reprobe_work); + rp->dev = get_device(dev); + queue_work(system_freezable_wq, &rp->work); + return 0; +} +EXPORT_SYMBOL_GPL(aura_hibernate_reprobe_after_thaw); + +static int __init aura_hibernate_init(void) +{ + unsigned long kstart = PFN_DOWN(__pa_symbol(_text)), kend = PFN_UP(__pa_symbol(_end)); + struct device_node *chosen, *rmem, *child; + unsigned int count = 0; + const void *fdt = initial_boot_params; + u64 layout[2], dt_slot; + int i, n; + + /* Only a boot loader that keeps the layout fixed publishes it. */ + chosen = of_find_node_by_path("/chosen"); + if (!chosen || + of_property_read_u64_array(chosen, "aura,hibernate-layout", layout, 2)) { + of_node_put(chosen); + return 0; + } + /* + * The device tree slot. Trusted where this kernel's tree is, or, when a later stage (U-Boot and + * the EFI stub) handed the kernel its own copy of aura's tree, where the slot still holds aura's + * tree for this layout: those stages do not move the firmware segments, so aura's tree and the + * kernel's copy agree on them. + */ + if (!of_property_read_u64(chosen, "aura,hibernate-dt", &dt_slot)) { + bool in_layout = dt_slot >= layout[0] && dt_slot + AURA_BOOT_DT_MAX <= layout[1]; + void *slot_fdt; + + if (in_layout && dt_slot == __fdt_pointer) { + aura_boot_dt = dt_slot; + } else if (in_layout) { + slot_fdt = memremap(dt_slot, AURA_BOOT_DT_MAX, MEMREMAP_WB); + if (slot_fdt && aura_slot_tree_valid(slot_fdt, dt_slot, layout)) { + aura_boot_dt = dt_slot; + pr_info("device tree handed over at %pa; using aura's tree at %#llx\n", + &__fdt_pointer, dt_slot); + } else { + pr_warn("device tree at %pa, aura's slot %#llx holds no tree for this layout\n", + &__fdt_pointer, dt_slot); + } + if (slot_fdt) + memunmap(slot_fdt); + } else { + pr_warn("device tree slot %#llx outside the fixed layout\n", dt_slot); + } + } + of_node_put(chosen); + + if (fdt) { + n = fdt_num_mem_rsv(fdt); + for (i = 0; i < n; i++) { + u64 addr, size; + + if (fdt_get_mem_rsv(fdt, i, &addr, &size) || !size) + continue; + aura_nosave_range(addr, addr + size, kstart, kend, "memreserve"); + count++; + } + } + + rmem = of_find_node_by_path("/reserved-memory"); + for_each_available_child_of_node(rmem, child) { + struct resource r; + + if (of_property_read_bool(child, "reusable")) + continue; + if (of_address_to_resource(child, 0, &r)) + continue; + aura_nosave_range(r.start, r.end + 1, kstart, kend, "reserved-memory"); + count++; + } + of_node_put(rmem); + + if (aura_nosave_count > AURA_NOSAVE_MAX) { + aura_nosave_count = 0; + return 0; + } + aura_layout[0] = layout[0]; + aura_layout[1] = layout[1]; + aura_layout_fixed = true; + pr_info("fixed boot layout [%#llx, %#llx), %u reserved ranges kept out of the image%s\n", + layout[0], layout[1], count, + aura_boot_dt ? ", device tree at a fixed address" : ""); + return 0; +} +late_initcall(aura_hibernate_init); diff --git a/drivers/soc/apple/rtkit-helper.c b/drivers/soc/apple/rtkit-helper.c index 8c518ef4349e9..93aa9bb6af850 100644 --- a/drivers/soc/apple/rtkit-helper.c +++ b/drivers/soc/apple/rtkit-helper.c @@ -48,6 +48,12 @@ struct apple_rtkit_helper { bool idle_pending; /* Ends a sleep whose .prepare failed, which gets no .complete. */ struct notifier_block pm_nb; + /* Boot kernel of a resume from disk: RX held for the image. */ + bool rx_held; + /* This restore took over the session the boot kernel started. */ + bool readopted; + /* This restore found the co-processor of our own session halted. */ + bool halted_underneath; void __iomem *asc_base; @@ -63,6 +69,22 @@ bool apple_rtkit_helper_preserves_input(struct device *dev) } EXPORT_SYMBOL_GPL(apple_rtkit_helper_preserves_input); +bool apple_rtkit_helper_readopted(struct device *dev) +{ + struct apple_rtkit_helper *helper = dev_get_drvdata(dev); + + return helper && helper->readopted; +} +EXPORT_SYMBOL_GPL(apple_rtkit_helper_readopted); + +bool apple_rtkit_helper_halted_underneath(struct device *dev) +{ + struct apple_rtkit_helper *helper = dev_get_drvdata(dev); + + return helper && helper->halted_underneath; +} +EXPORT_SYMBOL_GPL(apple_rtkit_helper_halted_underneath); + static int apple_rtkit_helper_shmem_setup(void *cookie, struct apple_rtkit_shmem *bfr) { struct apple_rtkit_helper *helper = cookie; @@ -119,9 +141,12 @@ static const struct apple_rtkit_ops apple_rtkit_helper_ops = { .shmem_destroy = apple_rtkit_helper_shmem_destroy, }; -static void apple_rtkit_helper_release(void *rtk) +static void apple_rtkit_helper_release(void *data) { - apple_rtkit_free_retaining_buffers(rtk); + struct apple_rtkit_helper *helper = data; + + /* The current session object: a hibernation restore may have replaced it. */ + apple_rtkit_free_retaining_buffers(helper->rtk); } /* @@ -347,7 +372,7 @@ static int apple_rtkit_helper_probe(struct platform_device *pdev) "Failed to adopt RTKit\n"); ret = devm_add_action_or_reset(dev, apple_rtkit_helper_release, - helper->rtk); + helper); if (ret) return ret; ret = apple_rtkit_helper_pm_register(helper); @@ -388,6 +413,18 @@ static void apple_rtkit_helper_remove(struct platform_device *pdev) if (helper->adopted || helper->preserved) return; + /* + * After a resume from disk the boot loader left the coprocessor halted + * with fresh firmware loaded, while the restored host session still + * believes it runs: nothing would answer the quiesce. Drop the session + * without a handshake so that the next probe starts the CPU again. + */ + if (!(readl_relaxed(helper->asc_base + APPLE_ASC_CPU_CONTROL) & + APPLE_ASC_CPU_CONTROL_RUN)) { + dev_info(&pdev->dev, "co-processor halted underneath (resume from disk): removed without quiesce\n"); + return; + } + if (apple_rtkit_is_running(helper->rtk)) apple_rtkit_quiesce(helper->rtk); @@ -554,6 +591,201 @@ static int __maybe_unused apple_rtkit_helper_resume(struct device *dev) return 0; } +#ifdef CONFIG_HIBERNATION +/* + * What the boot kernel of a resume from disk leaves for the restored kernel + * about a session it started itself: the shared buffers the firmware holds. + */ +struct apple_rtkit_helper_hib { + u32 count; + u32 reserved; + struct apple_rtkit_buffer_desc buf[APPLE_RTKIT_BUF_COUNT]; +}; +static_assert(sizeof(struct apple_rtkit_helper_hib) <= APPLE_RTKIT_HIB_HANDOFF_MAX); + +static void apple_rtkit_helper_hib_tag(struct device *dev, char *tag, size_t len) +{ + snprintf(tag, len, "rtkh:%s", dev_name(dev)); +} + +static bool apple_rtkit_helper_cpu_running(struct apple_rtkit_helper *helper) +{ + return readl_relaxed(helper->asc_base + APPLE_ASC_CPU_CONTROL) & + APPLE_ASC_CPU_CONTROL_RUN; +} + +/* + * Hibernation of an adopted session. The image is written while the firmware + * keeps running; its buffers live in SRAM or in no-map reserved RAM, so they + * are not part of the image and the host side has nothing to quiesce. The + * restore re-adopts the instance the boot loader started for the resume boot, + * exactly as probe adopted the first one. + * + * A session this driver started itself is left running as well: MTP does not + * come back from QUIESCED (RTKit endpoint discovery fails with -ETIME on the + * next start). When this is the boot kernel of a resume from disk (it started + * MTP so that the disk passphrase can be typed), it hands the running + * firmware to the image: mailbox RX is held, so that what the firmware sends + * now stays queued for the restored kernel, the messages already received + * are handled, and the shared buffers are described for the restored kernel, + * which can only take the session over if its own buffers sit at the same + * IOVAs (the firmware keeps writing to the IOVAs it was given, and after the + * restore the DART translates them through the image's page tables). + */ +static int apple_rtkit_helper_freeze(struct device *dev) +{ + struct apple_rtkit_helper *helper = dev_get_drvdata(dev); + struct apple_rtkit_helper_hib rec = {}; + char tag[32]; + int n, ret; + + helper->readopted = false; + helper->halted_underneath = false; + if (helper->adopted || !apple_rtkit_hib_restoring()) + return 0; + if (!apple_rtkit_helper_cpu_running(helper) || + !apple_rtkit_is_running(helper->rtk)) + return 0; + + apple_rtkit_hold_rx(helper->rtk); + apple_rtkit_flush_rx(helper->rtk); + helper->rx_held = true; + + n = apple_rtkit_describe_buffers(helper->rtk, rec.buf, ARRAY_SIZE(rec.buf)); + if (n < 0) { + dev_warn(dev, "resume from disk: cannot describe the RTKit buffers: %d\n", n); + return 0; + } + rec.count = n; + apple_rtkit_helper_hib_tag(dev, tag, sizeof(tag)); + ret = apple_rtkit_hib_handoff_put(tag, &rec, sizeof(rec)); + if (ret) + dev_warn(dev, "resume from disk: no hand-off record for the image: %d\n", ret); + else + dev_info(dev, "resume from disk: RTKit session left running for the image (%d buffers)\n", + n); + return 0; +} + +static int apple_rtkit_helper_thaw(struct device *dev) +{ + struct apple_rtkit_helper *helper = dev_get_drvdata(dev); + char tag[32]; + + /* The jump into the image failed: this kernel keeps the session. */ + if (helper->rx_held) { + helper->rx_held = false; + apple_rtkit_helper_hib_tag(dev, tag, sizeof(tag)); + apple_rtkit_hib_handoff_drop(tag); + apple_rtkit_resume_rx(helper->rtk); + } + return 0; +} + +/* + * A session this driver started itself, after a resume from disk. Taken over + * in place when the boot kernel left it running and its buffers match ours; + * otherwise left as before (stale until the driver is reloaded). + */ +static int apple_rtkit_helper_restore_own(struct apple_rtkit_helper *helper) +{ + struct device *dev = helper->dev; + struct apple_rtkit_helper_hib rec = {}, own = {}; + char tag[32]; + int i, n, ret; + + apple_rtkit_helper_hib_tag(dev, tag, sizeof(tag)); + ret = apple_rtkit_hib_handoff_take(tag, &rec, sizeof(rec)); + if (ret < 0) { + if (apple_rtkit_helper_cpu_running(helper)) { + dev_warn(dev, "resume from disk: co-processor runs without a hand-off from the boot kernel (%d): not taken over\n", + ret); + } else { + helper->halted_underneath = true; + dev_info(dev, "resume from disk: self-started RTKit session left for a reload\n"); + } + return 0; + } + if (!apple_rtkit_helper_cpu_running(helper)) { + helper->halted_underneath = true; + dev_warn(dev, "resume from disk: hand-off present but the co-processor is halted: not taken over\n"); + return 0; + } + + n = apple_rtkit_describe_buffers(helper->rtk, own.buf, ARRAY_SIZE(own.buf)); + own.count = n < 0 ? 0 : n; + if (n < 0 || rec.count > ARRAY_SIZE(rec.buf) || own.count != rec.count || + memcmp(own.buf, rec.buf, rec.count * sizeof(rec.buf[0]))) { + dev_err(dev, "resume from disk: RTKit buffers of the boot kernel differ from the image's: not taken over\n"); + for (i = 0; i < min_t(u32, rec.count, ARRAY_SIZE(rec.buf)); i++) + dev_err(dev, " boot kind %u iova %#llx size %#llx\n", + rec.buf[i].kind, rec.buf[i].iova, rec.buf[i].size); + for (i = 0; i < own.count; i++) + dev_err(dev, " image kind %u iova %#llx size %#llx\n", + own.buf[i].kind, own.buf[i].iova, own.buf[i].size); + return 0; + } + + ret = apple_rtkit_readopt(helper->rtk); + if (ret) { + dev_err(dev, "resume from disk: RTKit session not taken over: %d\n", ret); + return 0; + } + helper->readopted = true; + dev_info(dev, "resume from disk: took over the RTKit session the boot kernel started (%d buffers at the same IOVAs)\n", + n); + return 0; +} + +static int apple_rtkit_helper_restore(struct device *dev) +{ + struct apple_rtkit_helper *helper = dev_get_drvdata(dev); + struct apple_rtkit_inherited_buffer buffers[APPLE_RTKIT_HELPER_MAX_BUFFERS] = {}; + struct apple_rtkit *old, *rtk; + int count, live; + + /* Hibernation aborted before the image (PMSG_RESTORE then too): nothing restarted. */ + if (!pm_hibernate_is_restored()) + return apple_rtkit_helper_thaw(dev); + + if (!helper->adopted) + return apple_rtkit_helper_restore_own(helper); + + /* + * The restored tree still carries the handoff the image's boot stage + * wrote. The resume boot's loader hands the same firmware over at the + * same SRAM and no-map addresses (the inventory comes from the firmware + * carveouts, not from the kernel allocator), so re-read it and check + * that a CPU is running behind it. + */ + live = apple_rtkit_helper_live(helper); + if (live < 0) + return dev_err_probe(dev, live, "hibernation restore: invalid live RTKit handoff\n"); + if (!live) + return dev_err_probe(dev, -ENODEV, + "hibernation restore: no live RTKit session to re-adopt\n"); + count = apple_rtkit_helper_inherit_buffers(helper, buffers); + if (count < 0) + return dev_err_probe(dev, count, + "hibernation restore: invalid inherited RTKit buffers\n"); + + rtk = apple_rtkit_init_adopted_with_buffers(dev, helper, NULL, 0, + &apple_rtkit_helper_ops, buffers, count); + if (IS_ERR(rtk)) + return dev_err_probe(dev, PTR_ERR(rtk), + "hibernation restore: failed to re-adopt RTKit\n"); + + /* The old object described an instance that no longer exists. */ + old = helper->rtk; + helper->rtk = rtk; + helper->strict_buffers = count > 0 || + of_device_is_compatible(dev->of_node, "apple,t8132-mtp"); + apple_rtkit_free_retaining_buffers(old); + dev_info(dev, "re-adopted the running RTKit session after hibernation (%d retained buffers)\n", + count); + return 0; +} +#else static int __maybe_unused apple_rtkit_helper_freeze(struct device *dev) { struct apple_rtkit_helper *helper = dev_get_drvdata(dev); @@ -561,6 +793,7 @@ static int __maybe_unused apple_rtkit_helper_freeze(struct device *dev) /* A hibernation image cannot recreate the firmware's live DMA ownership. */ return helper->adopted ? -EBUSY : 0; } +#endif static const struct dev_pm_ops apple_rtkit_helper_pm_ops = { .prepare = pm_sleep_ptr(apple_rtkit_helper_prepare), @@ -569,6 +802,10 @@ static const struct dev_pm_ops apple_rtkit_helper_pm_ops = { .resume = pm_sleep_ptr(apple_rtkit_helper_resume), .freeze = pm_sleep_ptr(apple_rtkit_helper_freeze), .poweroff = pm_sleep_ptr(apple_rtkit_helper_freeze), +#ifdef CONFIG_HIBERNATION + .thaw = apple_rtkit_helper_thaw, + .restore = apple_rtkit_helper_restore, +#endif }; static const struct of_device_id apple_rtkit_helper_of_match[] = { diff --git a/drivers/soc/apple/rtkit-hib-handoff.c b/drivers/soc/apple/rtkit-hib-handoff.c new file mode 100644 index 0000000000000..bf5705142b8b1 --- /dev/null +++ b/drivers/soc/apple/rtkit-hib-handoff.c @@ -0,0 +1,211 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * Apple RTKit: hand a running co-processor session from the kernel that loads + * a hibernation image (the boot kernel) to the kernel restored from it. + * + * A co-processor that the boot kernel started keeps running across the jump + * into the image, but everything the boot kernel knew about it is overwritten + * by the image. The few facts the restored kernel needs to take the session + * over (where the firmware's shared buffers are, how far a receive ring got) + * are left in __nosavedata: the image never saves those pages, so after the + * restore they still hold what the boot kernel wrote, provided both kernels + * are the same build loaded at the same physical address. Each record carries + * its own physical address and a checksum, so a record from a kernel loaded + * elsewhere, or no record at all, reads as absent. + * + * The storage must be in the kernel image, so this only works with RTKit + * built in. A taken record is cleared. + */ + +#include +#include +#include +#include +#include +#include + +#if IS_BUILTIN(CONFIG_APPLE_RTKIT) && IS_ENABLED(CONFIG_HIBERNATION) + +#define HANDOFF_MAGIC 0x52544b48 /* "RTKH" */ +#define HANDOFF_VERSION 1 +#define HANDOFF_SLOTS 4 +#define HANDOFF_TAG 32 + +struct apple_rtkit_hib_slot { + u32 magic; + u32 version; + u64 self_phys; + char tag[HANDOFF_TAG]; + u32 len; + u32 sum; + u8 data[APPLE_RTKIT_HIB_HANDOFF_MAX]; +}; + +static struct apple_rtkit_hib_slot handoff[HANDOFF_SLOTS] __nosavedata; +static DEFINE_SPINLOCK(handoff_lock); +static bool restoring; + +/* FNV-1a over everything but the checksum itself. */ +static u32 handoff_sum(const struct apple_rtkit_hib_slot *s) +{ + const u8 *p = (const u8 *)s; + size_t off = offsetof(struct apple_rtkit_hib_slot, sum); + u32 h = 0x811c9dc5; + size_t i; + + for (i = 0; i < sizeof(*s); i++) { + if (i >= off && i < off + sizeof(s->sum)) + continue; + h ^= p[i]; + h *= 0x01000193; + } + return h; +} + +static bool handoff_valid(const struct apple_rtkit_hib_slot *s) +{ + return s->magic == HANDOFF_MAGIC && s->version == HANDOFF_VERSION && + s->self_phys == __pa_symbol(s) && + s->len <= APPLE_RTKIT_HIB_HANDOFF_MAX && + s->tag[HANDOFF_TAG - 1] == '\0' && s->sum == handoff_sum(s); +} + +static struct apple_rtkit_hib_slot *handoff_find(const char *tag) +{ + int i; + + for (i = 0; i < HANDOFF_SLOTS; i++) + if (handoff_valid(&handoff[i]) && !strcmp(handoff[i].tag, tag)) + return &handoff[i]; + return NULL; +} + +bool apple_rtkit_hib_restoring(void) +{ + return READ_ONCE(restoring); +} +EXPORT_SYMBOL_GPL(apple_rtkit_hib_restoring); + +int apple_rtkit_hib_handoff_put(const char *tag, const void *data, size_t len) +{ + struct apple_rtkit_hib_slot *s; + unsigned long flags; + int i, ret = 0; + + if (len > APPLE_RTKIT_HIB_HANDOFF_MAX || strlen(tag) >= HANDOFF_TAG) + return -EINVAL; + + spin_lock_irqsave(&handoff_lock, flags); + s = handoff_find(tag); + for (i = 0; !s && i < HANDOFF_SLOTS; i++) + if (!handoff_valid(&handoff[i])) + s = &handoff[i]; + if (s) { + memset(s, 0, sizeof(*s)); + s->magic = HANDOFF_MAGIC; + s->version = HANDOFF_VERSION; + s->self_phys = __pa_symbol(s); + strscpy(s->tag, tag, sizeof(s->tag)); + s->len = len; + memcpy(s->data, data, len); + s->sum = handoff_sum(s); + } else { + ret = -ENOSPC; + } + spin_unlock_irqrestore(&handoff_lock, flags); + return ret; +} +EXPORT_SYMBOL_GPL(apple_rtkit_hib_handoff_put); + +int apple_rtkit_hib_handoff_take(const char *tag, void *data, size_t len) +{ + struct apple_rtkit_hib_slot *s; + unsigned long flags; + int ret; + + spin_lock_irqsave(&handoff_lock, flags); + s = handoff_find(tag); + if (!s) { + ret = -ENOENT; + } else if (s->len != len) { + ret = -EINVAL; + } else { + memcpy(data, s->data, len); + ret = len; + } + if (s) + memset(s, 0, sizeof(*s)); + spin_unlock_irqrestore(&handoff_lock, flags); + return ret; +} +EXPORT_SYMBOL_GPL(apple_rtkit_hib_handoff_take); + +void apple_rtkit_hib_handoff_drop(const char *tag) +{ + struct apple_rtkit_hib_slot *s; + unsigned long flags; + + spin_lock_irqsave(&handoff_lock, flags); + s = handoff_find(tag); + if (s) + memset(s, 0, sizeof(*s)); + spin_unlock_irqrestore(&handoff_lock, flags); +} +EXPORT_SYMBOL_GPL(apple_rtkit_hib_handoff_drop); + +static int apple_rtkit_hib_notify(struct notifier_block *nb, + unsigned long action, void *data) +{ + switch (action) { + case PM_RESTORE_PREPARE: + WRITE_ONCE(restoring, true); + break; + case PM_POST_RESTORE: + /* The image was not restored: this kernel goes on. */ + WRITE_ONCE(restoring, false); + break; + } + return NOTIFY_DONE; +} + +static struct notifier_block apple_rtkit_hib_nb = { + .notifier_call = apple_rtkit_hib_notify, +}; + +static int __init apple_rtkit_hib_init(void) +{ + /* + * A kernel restored from an image runs this only on its own first + * boot, and the flag is saved false in the image: in the restored + * kernel it reads false. + */ + return register_pm_notifier(&apple_rtkit_hib_nb); +} +core_initcall(apple_rtkit_hib_init); + +#else + +bool apple_rtkit_hib_restoring(void) +{ + return false; +} +EXPORT_SYMBOL_GPL(apple_rtkit_hib_restoring); + +int apple_rtkit_hib_handoff_put(const char *tag, const void *data, size_t len) +{ + return -EOPNOTSUPP; +} +EXPORT_SYMBOL_GPL(apple_rtkit_hib_handoff_put); + +int apple_rtkit_hib_handoff_take(const char *tag, void *data, size_t len) +{ + return -ENOENT; +} +EXPORT_SYMBOL_GPL(apple_rtkit_hib_handoff_take); + +void apple_rtkit_hib_handoff_drop(const char *tag) +{ +} +EXPORT_SYMBOL_GPL(apple_rtkit_hib_handoff_drop); + +#endif diff --git a/drivers/soc/apple/rtkit.c b/drivers/soc/apple/rtkit.c index 8230ebe11d411..6c6d75a9428e7 100644 --- a/drivers/soc/apple/rtkit.c +++ b/drivers/soc/apple/rtkit.c @@ -1641,6 +1641,63 @@ bool apple_rtkit_has_endpoint(struct apple_rtkit *rtk, u8 ep) } EXPORT_SYMBOL_GPL(apple_rtkit_has_endpoint); +int apple_rtkit_describe_buffers(struct apple_rtkit *rtk, + struct apple_rtkit_buffer_desc *desc, + unsigned int max) +{ + const struct apple_rtkit_shmem *bufs[APPLE_RTKIT_BUF_COUNT] = { + [APPLE_RTKIT_BUF_IOREPORT] = &rtk->ioreport_buffer, + [APPLE_RTKIT_BUF_COREANALYTICS] = &rtk->coreanalytics_buffer, + [APPLE_RTKIT_BUF_CRASHLOG] = &rtk->crashlog_buffer, + [APPLE_RTKIT_BUF_OSLOG] = &rtk->oslog_buffer, + [APPLE_RTKIT_BUF_KDEBUG0] = &rtk->kdebug_buffer0, + [APPLE_RTKIT_BUF_KDEBUG1] = &rtk->kdebug_buffer1, + [APPLE_RTKIT_BUF_PMP_AUX] = &rtk->pmp_aux_buffer, + [APPLE_RTKIT_BUF_SYSLOG] = &rtk->syslog_buffer, + }; + unsigned int i, n = 0; + + for (i = 0; i < APPLE_RTKIT_BUF_COUNT; i++) { + if (!bufs[i]->size) + continue; + if (n == max) + return -ENOSPC; + desc[n].kind = i; + desc[n].is_mapped = bufs[i]->is_mapped; + desc[n].iova = bufs[i]->iova; + desc[n].size = bufs[i]->size; + n++; + } + return n; +} +EXPORT_SYMBOL_GPL(apple_rtkit_describe_buffers); + +int apple_rtkit_readopt(struct apple_rtkit *rtk) +{ + /* + * Only a session that was running when it was left can be taken over: + * its endpoint map, protocol version, syslog geometry and buffers then + * describe the same firmware build and the same IOVAs as the instance + * that runs now (the caller compared the buffers). + */ + if (READ_ONCE(rtk->shutting_down) || !apple_rtkit_is_running(rtk)) + return -EINVAL; + + apple_mbox_hold_rx(rtk->mbox); + /* Acknowledgments still queued belong to the instance that is gone. */ + cancel_work_sync(&rtk->sync_ack_work); + flush_workqueue(rtk->wq); + kfifo_reset(&rtk->sync_ack_fifo); + + reinit_completion(&rtk->iop_pwr_ack_completion); + reinit_completion(&rtk->ap_pwr_ack_completion); + + /* Messages the other kernel left queued in the mailbox arrive now. */ + apple_mbox_release_rx(rtk->mbox); + return 0; +} +EXPORT_SYMBOL_GPL(apple_rtkit_readopt); + int apple_rtkit_start_ep(struct apple_rtkit *rtk, u8 endpoint) { u64 msg; diff --git a/include/linux/soc/apple/aura-hibernate.h b/include/linux/soc/apple/aura-hibernate.h new file mode 100644 index 0000000000000..7c8b80de307be --- /dev/null +++ b/include/linux/soc/apple/aura-hibernate.h @@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __LINUX_SOC_APPLE_AURA_HIBERNATE_H +#define __LINUX_SOC_APPLE_AURA_HIBERNATE_H + +#include +#include + +struct device; +struct device_node; + +/* A firmware memory-region of a device as this boot's device tree gives it. */ +struct aura_fw_region { + u64 phys; + u64 iova; + u64 size; +}; + +/* + * Declared unconditionally so that Rust drivers can bind to them; without + * CONFIG_APPLE_AURA_HIBERNATE they must not call them. + */ +int aura_hibernate_boot_fw_regions(struct device_node *np, struct aura_fw_region *out, + unsigned int max); +int aura_hibernate_reprobe_after_thaw(struct device *dev); + +#ifdef CONFIG_APPLE_AURA_HIBERNATE +bool aura_hibernate_layout_fixed(void); +bool aura_hibernate_pfn_nosave(unsigned long pfn); +bool aura_hibernate_range_nosave(u64 start, u64 end); +int aura_hibernate_boot_chosen_u64(const char *name, u64 *val); +#else +static inline bool aura_hibernate_layout_fixed(void) { return false; } +static inline bool aura_hibernate_pfn_nosave(unsigned long pfn) { return false; } +static inline bool aura_hibernate_range_nosave(u64 start, u64 end) { return false; } +static inline int aura_hibernate_boot_chosen_u64(const char *name, u64 *val) { return -ENODEV; } +#endif + +#endif diff --git a/include/linux/soc/apple/rtkit-helper.h b/include/linux/soc/apple/rtkit-helper.h index 190caf432e098..4c712936e6c15 100644 --- a/include/linux/soc/apple/rtkit-helper.h +++ b/include/linux/soc/apple/rtkit-helper.h @@ -9,4 +9,20 @@ struct device; /* The caller holds a device link to the bound helper supplier. */ bool apple_rtkit_helper_preserves_input(struct device *dev); +/* + * After a resume from disk: the helper took over, in its .restore callback, + * the session that the boot kernel started and left running. Valid from the + * helper's .restore until its next .freeze. + */ +bool apple_rtkit_helper_readopted(struct device *dev); + +/* + * After a resume from disk: the session this helper had started itself was + * found with its co-processor halted (the boot loader stopped it and the boot + * kernel did not start it). Nothing answers until the helper is probed again, + * which starts the co-processor. Valid from the helper's .restore until its + * next .freeze. + */ +bool apple_rtkit_helper_halted_underneath(struct device *dev); + #endif diff --git a/include/linux/soc/apple/rtkit.h b/include/linux/soc/apple/rtkit.h index 244e60bbc6989..60fa2ba2fdeba 100644 --- a/include/linux/soc/apple/rtkit.h +++ b/include/linux/soc/apple/rtkit.h @@ -442,4 +442,60 @@ void apple_rtkit_flush_rx(struct apple_rtkit *rtk); */ bool apple_rtkit_has_endpoint(struct apple_rtkit *rtk, u8 ep); +/* + * A shared buffer of a running session, as the co-processor addresses it. + * @kind is one of APPLE_RTKIT_BUF_*. + */ +#define APPLE_RTKIT_BUF_IOREPORT 0 +#define APPLE_RTKIT_BUF_COREANALYTICS 1 +#define APPLE_RTKIT_BUF_CRASHLOG 2 +#define APPLE_RTKIT_BUF_OSLOG 3 +#define APPLE_RTKIT_BUF_KDEBUG0 4 +#define APPLE_RTKIT_BUF_KDEBUG1 5 +#define APPLE_RTKIT_BUF_PMP_AUX 6 +#define APPLE_RTKIT_BUF_SYSLOG 7 +#define APPLE_RTKIT_BUF_COUNT 8 + +struct apple_rtkit_buffer_desc { + u32 kind; + u32 is_mapped; + u64 iova; + u64 size; +}; + +/* + * Describe the shared buffers the co-processor currently holds, in a fixed + * order. Returns the number of entries written, or -ENOSPC if @max is too + * small. + */ +int apple_rtkit_describe_buffers(struct apple_rtkit *rtk, + struct apple_rtkit_buffer_desc *desc, + unsigned int max); + +/* + * Take over, in place, a firmware instance that another kernel started and + * left running with its shared buffers at the IOVAs this session already + * holds (the caller must have checked that with apple_rtkit_describe_buffers() + * against the other kernel's description). Only host-side transient state is + * reset; no message is sent to the co-processor. + */ +int apple_rtkit_readopt(struct apple_rtkit *rtk); + +/* + * Resume from disk. The kernel that loads a hibernation image (the boot + * kernel) can leave a few bytes for the kernel restored from that image in + * memory that the image does not overwrite. Only available with RTKit + * built in; elsewhere put() fails and take() finds nothing. + * + * apple_rtkit_hib_restoring(): true in the boot kernel between + * PM_RESTORE_PREPARE and the jump into the image (or PM_POST_RESTORE), + * i.e. while its devices are quiesced for the image, not frozen for one. + */ +#define APPLE_RTKIT_HIB_HANDOFF_MAX 256 + +bool apple_rtkit_hib_restoring(void); +int apple_rtkit_hib_handoff_put(const char *tag, const void *data, size_t len); +int apple_rtkit_hib_handoff_take(const char *tag, void *data, size_t len); +void apple_rtkit_hib_handoff_drop(const char *tag); + #endif /* _LINUX_APPLE_RTKIT_H_ */ diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h index 01e0e6cfbced8..3da0006a9c8ea 100644 --- a/rust/bindings/bindings_helper.h +++ b/rust/bindings/bindings_helper.h @@ -114,6 +114,7 @@ #include #include #include +#include #include #include #include diff --git a/rust/kernel/soc/apple/rtkit.rs b/rust/kernel/soc/apple/rtkit.rs index c34f187f4fb10..e4527ff598126 100644 --- a/rust/kernel/soc/apple/rtkit.rs +++ b/rust/kernel/soc/apple/rtkit.rs @@ -367,6 +367,15 @@ impl RtKit { to_result(unsafe { bindings::apple_rtkit_wake(self.rtk) }) } + /// Re-initialises a stopped session so a fresh HELLO/EPMAP boot can be + /// accepted again (hibernation restore of a coprocessor the boot loader + /// cold-restarted): detaches RX, frees inherited buffers, zeroes the + /// endpoint bitmap, reinitialises the completions and restarts the mailbox. + pub fn reinit(self: Pin<&mut Self>) -> Result { + // SAFETY: `rtk` is valid per the type invariant. + to_result(unsafe { bindings::apple_rtkit_reinit(self.rtk) }) + } + /// Waits for the RTKit coprocessor to finish booting. pub fn boot(self: Pin<&mut Self>) -> Result { // SAFETY: `rtk` is valid per the type invariant. From 240d75324cd47268496b570c841e912023200e76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Thu, 12 Nov 2026 06:15:23 +0100 Subject: [PATCH 26/49] KVM: arm64: keep the guests' counters when the physical counter starts again in a sleep MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A guest's virtual and physical counters are the host's physical counter minus an offset that is fixed when the VM is created. A resume from disk is a cold boot: the physical counter has started again, and with the old offsets the guests' counters read less than before the hibernation. A Linux guest takes a clocksource that went backwards for no time passed. It still gets its timer interrupts, but its clock stands still until the host's counter has caught up with the old value, which takes as long as the host had been up. J616s, a guest with two vCPUs that prints its uptime every second, host up for an hour, hibernation and resume: the guest's CVAL went from 0x2076a3246c to 0xfffffce7b9ce8d2f, the guest took a timer interrupt every half second and printed nothing more. Keep the counter's value in a syscore suspend callback. If it reads less in the resume, move every VM's virtual and physical offset by the difference: the guests' counters go on from the value they had when the system went down, as for a VM that was stopped for that long. The time the machine was off is not shown to the guests. A counter that keeps running through a sleep is left alone, and the guests see that sleep as time that passed, as before. The same guest with this change: "the counter started again in the sleep (446875224457 -> 92491224896): the counters of 1 VM(s) kept", and the guest prints on after the resume with its uptime continuous. A suspend to RAM before and one after that hibernation leave it running too; the counter runs through those and the guest's uptime steps by the 25 s of the sleep. Signed-off-by: František Balázsy --- arch/arm64/kvm/arch_timer.c | 54 +++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c index 6ac3321f4c575..0773f1c1209e8 100644 --- a/arch/arm64/kvm/arch_timer.c +++ b/arch/arm64/kvm/arch_timer.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -1436,6 +1437,58 @@ static void kvm_timer_handle_errata(void) } } +/* + * A guest's counters are the physical counter minus an offset that is fixed + * when the VM is made. The physical counter can start again in a sleep: it + * always does across a resume from disk, which is a cold boot. The guest's + * counters then fall back by what the counter lost, and the guest's clock + * stands still until the counter has caught up, which takes as long as the + * host had been up. Move the offsets by the same amount instead: the + * guest's counters go on from the value they had when the system went down, + * as for a VM that was stopped that long. A counter that keeps running + * through the sleep is left alone, and the guest sees the sleep as time that + * passed. + * + * Syscore: one CPU, interrupts off, every task frozen, so no vCPU is loaded + * and nothing changes vm_list. + */ +static u64 kvm_timer_sleep_cnt; + +static int kvm_timer_syscore_suspend(void *data) +{ + kvm_timer_sleep_cnt = kvm_phys_timer_read(); + return 0; +} + +static void kvm_timer_syscore_resume(void *data) +{ + u64 now = kvm_phys_timer_read(); + unsigned int vms = 0; + struct kvm *kvm; + u64 lost; + + if (now >= kvm_timer_sleep_cnt) + return; + lost = kvm_timer_sleep_cnt - now; + list_for_each_entry(kvm, &vm_list, vm_list) { + kvm->arch.timer_data.voffset -= lost; + kvm->arch.timer_data.poffset -= lost; + vms++; + } + if (vms) + kvm_info("the counter started again in the sleep (%llu -> %llu): the counters of %u VM(s) kept\n", + kvm_timer_sleep_cnt, now, vms); +} + +static const struct syscore_ops kvm_timer_syscore_ops = { + .suspend = kvm_timer_syscore_suspend, + .resume = kvm_timer_syscore_resume, +}; + +static struct syscore kvm_timer_syscore = { + .ops = &kvm_timer_syscore_ops, +}; + int __init kvm_timer_hyp_init(bool has_gic) { struct arch_timer_kvm_info *info; @@ -1505,6 +1558,7 @@ int __init kvm_timer_hyp_init(bool has_gic) } kvm_timer_handle_errata(); + register_syscore(&kvm_timer_syscore); return 0; out_free_ptimer_irq: From 9db5869ce5bfd938041d62085ffab22f2ca642a8 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Thu, 12 Nov 2026 14:28:32 +1100 Subject: [PATCH 27/49] arm64: share the sleep registry so one kernel builds both controllers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The arch/arm64/configs/asahi.config part of "soc: apple: share the sleep registry so one kernel builds both controllers", which goes with the hibernation core changes; the rest of that commit is with the sleep controller changes. The T8140 sleep driver (sleep.c) and the T6040 one (t6040-sleep.c) each defined the coprocessor and enclave registry that drivers reach through , so the two exported the same nine symbols and APPLE_T6040_SLEEP had to depend on !APPLE_SOC_SLEEP. The universal config sets APPLE_SOC_SLEEP, so it never built the T6040 controller. Move the registry into sleep-registry.c behind a hidden APPLE_SLEEP_REGISTRY that both options select. The table holds six entries and the superset of the two records. Each controller binds to the registry in its probe with two answers of its own: whether this sleep's commit stops the registered coprocessors, and whether an enclave registration is taken. Both keep their earlier rules: T8140 answers from its own state and pm_suspend_via_firmware() and takes an enclave only when its commit stops coprocessors; T6040 answers as before and takes every enclave. With no controller bound the commit stops nothing and an enclave registration is refused. The controllers bind only to their own compatibles (apple,t8140-sleep, apple,t6040-sleep), so at most one is bound and installs suspend_ops. Drop the dependency, give the registry prototypes their own guard in sleep.h so every combination compiles, and enable APPLE_T6040_SLEEP in asahi.config. Signed-off-by: Ryan Murray Signed-off-by: František Balázsy --- arch/arm64/configs/asahi.config | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/configs/asahi.config b/arch/arm64/configs/asahi.config index 70858dca94b8a..c0b5ba114bf13 100644 --- a/arch/arm64/configs/asahi.config +++ b/arch/arm64/configs/asahi.config @@ -177,3 +177,4 @@ CONFIG_EDAC_APPLE_SOC=m # the ctxr_exec_window= command-line option is given. CONFIG_ARM64_CTXR_EXECMEM=y CONFIG_APPLE_SOC_SLEEP=y +CONFIG_APPLE_T6040_SLEEP=y From a6f9c1df55eb2f544549fbb624ef601aa27f6bec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Thu, 12 Nov 2026 19:51:36 +0100 Subject: [PATCH 28/49] PM: hibernate: mark a restored kernel without testing the error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit create_image() sets hibernate_restored inside if (!in_suspend), which is reached only in a kernel restored from an image: there the arch code has cleared in_suspend and swsusp_arch_suspend() returned 0. So !error is always true at that point; store true. No functional change. Signed-off-by: František Balázsy --- kernel/power/hibernate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c index a8d992bb4a2c7..41784a6771e34 100644 --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c @@ -425,7 +425,7 @@ static int create_image(int platform_mode) if (!in_suspend) { events_check_enabled = false; clear_or_poison_free_pages(); - WRITE_ONCE(hibernate_restored, !error); + WRITE_ONCE(hibernate_restored, true); } platform_leave(platform_mode); From b135dadc34839804b6d3b83e7be1a18552b17359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Thu, 12 Nov 2026 19:51:37 +0100 Subject: [PATCH 29/49] arm64: hibernate: put the boot layout comment above its function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The comment that explains what hibernate_boot_layout() covers sat above hibernate_mix_span(), directly on top of that function's own comment. Move it to hibernate_boot_layout(). Comment move only, no functional change. Signed-off-by: František Balázsy --- arch/arm64/kernel/hibernate.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c index 048a29d5d54fd..e5bdc6a2326c1 100644 --- a/arch/arm64/kernel/hibernate.c +++ b/arch/arm64/kernel/hibernate.c @@ -106,23 +106,6 @@ static u64 hibernate_layout_mix(u64 h, const void *p, size_t len) return h; } -/* - * The image restores every page to the frame it came from, so the boot that - * resumes it must give the kernel what the boot that wrote it did: the same - * RAM, and on Apple machines at EL2 the same CTXR exec window (secondaries only - * execute inside it) and aura's fixed hibernation layout. A boot loader decides - * them on every boot; the kernel build check above cannot see them. - * - * aura's own image moves with the boot object, and its CPU release addresses - * and S2R mailbox with it, inside the range the layout keeps from Linux. The - * restored kernel uses neither address of the boot that wrote the image: its - * CPUs come back from the boot kernel's pen, a CPU started at its reset vector - * again finds the release target the boot kernel wrote (both kernels run at the - * window's fixed address), and the T6040 sleep driver takes this boot's mailbox - * from aura's tree after the restore. What has to match is the spin table's - * shape (the same CPUs, at the same offsets from the mailbox) and that this - * boot keeps all of it out of the image. - */ /* * Mix one memory span less the parts in @ex, ranges that this boot keeps out of * the image. iBoot's no-map allocations inside aura's fixed layout (the DCP @@ -147,6 +130,23 @@ static u64 hibernate_mix_span(u64 h, u64 b, u64 e, u32 flags, const u64 (*ex)[2] return hibernate_layout_mix(h, &flags, sizeof(flags)); } +/* + * The image restores every page to the frame it came from, so the boot that + * resumes it must give the kernel what the boot that wrote it did: the same + * RAM, and on Apple machines at EL2 the same CTXR exec window (secondaries only + * execute inside it) and aura's fixed hibernation layout. A boot loader decides + * them on every boot; the kernel build check above cannot see them. + * + * aura's own image moves with the boot object, and its CPU release addresses + * and S2R mailbox with it, inside the range the layout keeps from Linux. The + * restored kernel uses neither address of the boot that wrote the image: its + * CPUs come back from the boot kernel's pen, a CPU started at its reset vector + * again finds the release target the boot kernel wrote (both kernels run at the + * window's fixed address), and the T6040 sleep driver takes this boot's mailbox + * from aura's tree after the restore. What has to match is the spin table's + * shape (the same CPUs, at the same offsets from the mailbox) and that this + * boot keeps all of it out of the image. + */ static u64 hibernate_boot_layout(void) { static const char * const chosen_props[] = { From 2e3101de479edd0b27437d39423a5f110b6ddcd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Thu, 12 Nov 2026 19:51:37 +0100 Subject: [PATCH 30/49] arm64: smp_spin_table: say what still needs the platform power ops MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The comment over the parking spin table said that CPU hotplug fails until a platform driver provides the power ops. Since the parked CPU comes back through cpu_soft_restart(), only stopping the parked CPUs for a suspend needs them (spin_table_hold_parked() refuses without); hotplug needs KEXEC_CORE. Say so, and rejoin a line break in the pen comment. Comments only, no functional change. Signed-off-by: František Balázsy --- arch/arm64/kernel/smp_spin_table.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kernel/smp_spin_table.c b/arch/arm64/kernel/smp_spin_table.c index 2326f3f5df57a..e65522250995f 100644 --- a/arch/arm64/kernel/smp_spin_table.c +++ b/arch/arm64/kernel/smp_spin_table.c @@ -146,8 +146,10 @@ const struct cpu_operations smp_spin_table_ops = { * masked. From there it goes back through secondary_holding_pen, or, when the * platform suspends the system, it stops and takes its last WFI after the commit. * It is then started again at its reset vector. Stopping and starting a CPU is - * SoC-specific, so a platform driver provides it. Until one has, CPU hotplug - * fails cleanly, as on plain spin-table. + * SoC-specific, so a platform driver provides it (spin_table_set_power_ops()); + * until one has, a suspend that needs the parked CPUs stopped is refused. + * Parking and leaving the park need only cpu_soft_restart(): without + * KEXEC_CORE, CPU hotplug fails cleanly, as on plain spin-table. * * A CPU left awake at the commit can hang the machine, and the commit can't be * undone. So each parked CPU first answers a hold, while the suspend can still @@ -176,9 +178,8 @@ static bool spin_table_stop_released; * the kernel build that is running; with the boot kernel loaded at the image * kernel's physical address (checked when the resume starts) the pen is at the * same place in both, and the restored kernel reads what the boot kernel left - * there. It - * starts each CPU from the pen through secondary_holding_pen, as at boot. - * Nothing is powered off, so this needs no platform power ops. + * there. It starts each CPU from the pen through secondary_holding_pen, as at + * boot. Nothing is powered off, so this needs no platform power ops. */ #define SPIN_TABLE_PEN_MAGIC 0x314e455034535053ULL /* "SPS4PEN1" */ #define SPIN_TABLE_PEN_HERE 0x45524548ULL /* "HERE", from the pen */ From e9c9a50703cc1e2214a7aa3fef2952ae5c983a00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Thu, 12 Nov 2026 20:05:05 +0100 Subject: [PATCH 31/49] soc: apple: rtkit-helper: say why a self-started session keeps running MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The comment cited the error code a test had seen when MTP was started again after a quiesce. Say what the firmware does instead: it does not answer the endpoint discovery of the next start. Comment only, no functional change. Signed-off-by: František Balázsy --- drivers/soc/apple/rtkit-helper.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/soc/apple/rtkit-helper.c b/drivers/soc/apple/rtkit-helper.c index 93aa9bb6af850..a51f2aa50de30 100644 --- a/drivers/soc/apple/rtkit-helper.c +++ b/drivers/soc/apple/rtkit-helper.c @@ -621,16 +621,17 @@ static bool apple_rtkit_helper_cpu_running(struct apple_rtkit_helper *helper) * restore re-adopts the instance the boot loader started for the resume boot, * exactly as probe adopted the first one. * - * A session this driver started itself is left running as well: MTP does not - * come back from QUIESCED (RTKit endpoint discovery fails with -ETIME on the - * next start). When this is the boot kernel of a resume from disk (it started - * MTP so that the disk passphrase can be typed), it hands the running - * firmware to the image: mailbox RX is held, so that what the firmware sends - * now stays queued for the restored kernel, the messages already received - * are handled, and the shared buffers are described for the restored kernel, - * which can only take the session over if its own buffers sit at the same - * IOVAs (the firmware keeps writing to the IOVAs it was given, and after the - * restore the DART translates them through the image's page tables). + * A session this driver started itself is left running as well: the MTP + * firmware does not come back from QUIESCED (it does not answer the endpoint + * discovery of the next start). When this is the boot kernel of a resume from + * disk (it started MTP so that the disk passphrase can be typed), it hands + * the running firmware to the image: mailbox RX is held, so that what the + * firmware sends now stays queued for the restored kernel, the messages + * already received are handled, and the shared buffers are described for the + * restored kernel, which can only take the session over if its own buffers + * sit at the same IOVAs (the firmware keeps writing to the IOVAs it was + * given, and after the restore the DART translates them through the image's + * page tables). */ static int apple_rtkit_helper_freeze(struct device *dev) { From 6c5180789773565cbd7a4a9ea63628cb441fc663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Thu, 12 Nov 2026 20:11:49 +0100 Subject: [PATCH 32/49] arm64: hibernate: compute the boot layout once on restore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit arch_hibernation_header_restore() computed hibernate_boot_layout() a second time to print it on a mismatch, and on a match printed the value the hibernating kernel had already logged. Compute it once, and drop the line on a match. The comparison and its outcome are unchanged. Signed-off-by: František Balázsy --- arch/arm64/kernel/hibernate.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c index e5bdc6a2326c1..1119168a392d8 100644 --- a/arch/arm64/kernel/hibernate.c +++ b/arch/arm64/kernel/hibernate.c @@ -259,6 +259,7 @@ EXPORT_SYMBOL(arch_hibernation_header_save); int arch_hibernation_header_restore(void *addr) { + u64 layout; int ret; struct arch_hibernate_hdr_invariants invariants; struct arch_hibernate_hdr *hdr = addr; @@ -268,12 +269,12 @@ int arch_hibernation_header_restore(void *addr) pr_crit("Hibernate image not generated by this kernel!\n"); return -EINVAL; } - if (hdr->boot_layout != hibernate_boot_layout()) { + layout = hibernate_boot_layout(); + if (hdr->boot_layout != layout) { pr_crit("Hibernate image written under another boot layout (%016llx, this boot %016llx): not restored\n", - hdr->boot_layout, hibernate_boot_layout()); + hdr->boot_layout, layout); return -EINVAL; } - pr_info("Hibernate image written under this boot layout (%016llx)\n", hdr->boot_layout); sleep_cpu = get_logical_index(hdr->sleep_cpu_mpidr); pr_info("Hibernated on CPU %d [mpidr:0x%llx]\n", sleep_cpu, From 5236e296c1bc5885b6c0123307b49dd574fb4150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Thu, 12 Nov 2026 20:11:50 +0100 Subject: [PATCH 33/49] arm64: smp_spin_table: name the pen's physical address in a local MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit spin_table_hibernate_pen_begin() passed a compound literal to pr_err() to print the physical address of swapper_pg_dir. Keep the address in a local, compare against it and print it from there. No functional change. Signed-off-by: František Balázsy --- arch/arm64/kernel/smp_spin_table.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/smp_spin_table.c b/arch/arm64/kernel/smp_spin_table.c index e65522250995f..9d5f26afe4edd 100644 --- a/arch/arm64/kernel/smp_spin_table.c +++ b/arch/arm64/kernel/smp_spin_table.c @@ -219,18 +219,19 @@ static void spin_table_pen_clean(void *start, size_t size) */ int spin_table_hibernate_pen_begin(phys_addr_t image_ttbr1, int primary) { + phys_addr_t here = __pa_symbol(swapper_pg_dir); int cpu; /* No record of an earlier, abandoned resume may reach the restored kernel. */ spin_table_pen.magic = 0; spin_table_pen_clean(&spin_table_pen, sizeof(spin_table_pen.magic)); - if (image_ttbr1 != __pa_symbol(swapper_pg_dir)) { + if (image_ttbr1 != here) { for_each_online_cpu(cpu) { if (cpu == primary || get_cpu_ops(cpu) != &smp_rvbar_spin_table_ops) continue; pr_err("hibernation: the image's kernel ran at another physical address (swapper_pg_dir %pa, here %pa): spin-table CPUs cannot wait in this kernel's pen, resume refused\n", - &image_ttbr1, &(phys_addr_t){ __pa_symbol(swapper_pg_dir) }); + &image_ttbr1, &here); return -EINVAL; } return 0; From 22ce23a4b033cf244dbfb9de778d297ca12998a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Thu, 12 Nov 2026 20:14:12 +0100 Subject: [PATCH 34/49] soc: apple: rtkit-helper: report restore failures with dev_err() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The restore callback reported its failures with dev_err_probe(), which belongs to probe and records a deferral reason against a bound device. Print them with dev_err() and return the error as before. The hand-over and the take-over of a session, which happen on every resume from disk that has them, go to debug level. Only log calls change. Signed-off-by: František Balázsy --- drivers/soc/apple/rtkit-helper.c | 39 ++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/drivers/soc/apple/rtkit-helper.c b/drivers/soc/apple/rtkit-helper.c index a51f2aa50de30..a1428534bcabc 100644 --- a/drivers/soc/apple/rtkit-helper.c +++ b/drivers/soc/apple/rtkit-helper.c @@ -663,8 +663,8 @@ static int apple_rtkit_helper_freeze(struct device *dev) if (ret) dev_warn(dev, "resume from disk: no hand-off record for the image: %d\n", ret); else - dev_info(dev, "resume from disk: RTKit session left running for the image (%d buffers)\n", - n); + dev_dbg(dev, "resume from disk: RTKit session left running for the image (%d buffers)\n", + n); return 0; } @@ -733,8 +733,8 @@ static int apple_rtkit_helper_restore_own(struct apple_rtkit_helper *helper) return 0; } helper->readopted = true; - dev_info(dev, "resume from disk: took over the RTKit session the boot kernel started (%d buffers at the same IOVAs)\n", - n); + dev_dbg(dev, "resume from disk: took over the RTKit session the boot kernel started (%d buffers at the same IOVAs)\n", + n); return 0; } @@ -760,21 +760,26 @@ static int apple_rtkit_helper_restore(struct device *dev) * that a CPU is running behind it. */ live = apple_rtkit_helper_live(helper); - if (live < 0) - return dev_err_probe(dev, live, "hibernation restore: invalid live RTKit handoff\n"); - if (!live) - return dev_err_probe(dev, -ENODEV, - "hibernation restore: no live RTKit session to re-adopt\n"); + if (live < 0) { + dev_err(dev, "hibernation restore: invalid live RTKit handoff: %d\n", live); + return live; + } + if (!live) { + dev_err(dev, "hibernation restore: no live RTKit session to re-adopt\n"); + return -ENODEV; + } count = apple_rtkit_helper_inherit_buffers(helper, buffers); - if (count < 0) - return dev_err_probe(dev, count, - "hibernation restore: invalid inherited RTKit buffers\n"); + if (count < 0) { + dev_err(dev, "hibernation restore: invalid inherited RTKit buffers: %d\n", count); + return count; + } rtk = apple_rtkit_init_adopted_with_buffers(dev, helper, NULL, 0, &apple_rtkit_helper_ops, buffers, count); - if (IS_ERR(rtk)) - return dev_err_probe(dev, PTR_ERR(rtk), - "hibernation restore: failed to re-adopt RTKit\n"); + if (IS_ERR(rtk)) { + dev_err(dev, "hibernation restore: failed to re-adopt RTKit: %pe\n", rtk); + return PTR_ERR(rtk); + } /* The old object described an instance that no longer exists. */ old = helper->rtk; @@ -782,8 +787,8 @@ static int apple_rtkit_helper_restore(struct device *dev) helper->strict_buffers = count > 0 || of_device_is_compatible(dev->of_node, "apple,t8132-mtp"); apple_rtkit_free_retaining_buffers(old); - dev_info(dev, "re-adopted the running RTKit session after hibernation (%d retained buffers)\n", - count); + dev_dbg(dev, "re-adopted the running RTKit session after hibernation (%d retained buffers)\n", + count); return 0; } #else From 2e64582a09606b7fd89eff55ecb905c7306e4c97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Thu, 12 Nov 2026 20:19:11 +0100 Subject: [PATCH 35/49] soc: apple: rtkit-helper: build hibernation callbacks unconditionally MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The hibernation callbacks sat in an #ifdef CONFIG_HIBERNATION block, with a second freeze callback for the other configuration, and .thaw and .restore were set under the same condition. On arm64 the PM core calls .freeze, .poweroff, .thaw and .restore only with CONFIG_HIBERNATION, so the second freeze callback was never called. Drop it, build the callbacks unconditionally and set them with pm_sleep_ptr(). With CONFIG_HIBERNATION the object code is unchanged. Signed-off-by: František Balázsy --- drivers/soc/apple/rtkit-helper.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/drivers/soc/apple/rtkit-helper.c b/drivers/soc/apple/rtkit-helper.c index a1428534bcabc..8f0c72721cb8b 100644 --- a/drivers/soc/apple/rtkit-helper.c +++ b/drivers/soc/apple/rtkit-helper.c @@ -591,7 +591,6 @@ static int __maybe_unused apple_rtkit_helper_resume(struct device *dev) return 0; } -#ifdef CONFIG_HIBERNATION /* * What the boot kernel of a resume from disk leaves for the restored kernel * about a session it started itself: the shared buffers the firmware holds. @@ -791,15 +790,6 @@ static int apple_rtkit_helper_restore(struct device *dev) count); return 0; } -#else -static int __maybe_unused apple_rtkit_helper_freeze(struct device *dev) -{ - struct apple_rtkit_helper *helper = dev_get_drvdata(dev); - - /* A hibernation image cannot recreate the firmware's live DMA ownership. */ - return helper->adopted ? -EBUSY : 0; -} -#endif static const struct dev_pm_ops apple_rtkit_helper_pm_ops = { .prepare = pm_sleep_ptr(apple_rtkit_helper_prepare), @@ -808,10 +798,8 @@ static const struct dev_pm_ops apple_rtkit_helper_pm_ops = { .resume = pm_sleep_ptr(apple_rtkit_helper_resume), .freeze = pm_sleep_ptr(apple_rtkit_helper_freeze), .poweroff = pm_sleep_ptr(apple_rtkit_helper_freeze), -#ifdef CONFIG_HIBERNATION - .thaw = apple_rtkit_helper_thaw, - .restore = apple_rtkit_helper_restore, -#endif + .thaw = pm_sleep_ptr(apple_rtkit_helper_thaw), + .restore = pm_sleep_ptr(apple_rtkit_helper_restore), }; static const struct of_device_id apple_rtkit_helper_of_match[] = { From f11a999e367b9fc81a307d13debbe836387b98f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Thu, 12 Nov 2026 23:13:25 +0100 Subject: [PATCH 36/49] soc: apple: rtkit-helper: adopt by one buffer rule at probe and restore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An adopted MTP session keeps the buffers it negotiated with the boot stage that started it, so on boards where the firmware cannot give them up a request for a buffer the inventory does not list is refused. Probe decides that for a session with an inventory, for T8132, and for the J614s MTP. The restore after a hibernation adopts the session of the resume boot the same way but decided again with a copy of the rule that lacked the J614s: there a session adopted with an empty inventory refused new buffers after probe and granted them after a resume from disk, replacing storage the firmware still uses. Take the decision in one helper, and in the restore make it before the new session's receive path starts, as probe does. Signed-off-by: František Balázsy --- drivers/soc/apple/rtkit-helper.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/drivers/soc/apple/rtkit-helper.c b/drivers/soc/apple/rtkit-helper.c index 8f0c72721cb8b..bcd666f166da4 100644 --- a/drivers/soc/apple/rtkit-helper.c +++ b/drivers/soc/apple/rtkit-helper.c @@ -271,6 +271,21 @@ static int apple_rtkit_helper_inherit_buffers( return count; } +/* + * Whether an adopted session refuses buffers its inventory does not list. With + * an inventory, and on T8132 and the J614s without one, no new allocation is + * safe: the firmware still uses what it negotiated with its first host. + * Producers that predate the inventory (T8140) keep mapping IOVAs inside the + * SRAM region. Probe and the restore after a hibernation adopt by this rule. + */ +static bool apple_rtkit_helper_strict(struct device *dev, int count) +{ + return count > 0 || + of_device_is_compatible(dev->of_node, "apple,t8132-mtp") || + (of_machine_is_compatible("apple,j614s") && + of_device_is_compatible(dev->of_node, "apple,t6041-mtp")); +} + static int apple_rtkit_helper_pm_register(struct apple_rtkit_helper *helper); static int apple_rtkit_helper_probe(struct platform_device *pdev) @@ -355,16 +370,9 @@ static int apple_rtkit_helper_probe(struct platform_device *pdev) } if (live) { - /* - * Set before RX starts: with an inventory, or on T8132, no new - * buffer allocation is safe here. Producers that predate the - * inventory (T8140) keep mapping IOVAs inside the SRAM region. - */ + /* Set before RX starts, which may bring a buffer request. */ helper->adopted = true; - helper->strict_buffers = count > 0 || - of_device_is_compatible(dev->of_node, "apple,t8132-mtp") || - (of_machine_is_compatible("apple,j614s") && - of_device_is_compatible(dev->of_node, "apple,t6041-mtp")); + helper->strict_buffers = apple_rtkit_helper_strict(dev, count); helper->rtk = apple_rtkit_init_adopted_with_buffers( dev, helper, NULL, 0, &apple_rtkit_helper_ops, buffers, count); if (IS_ERR(helper->rtk)) @@ -773,6 +781,8 @@ static int apple_rtkit_helper_restore(struct device *dev) return count; } + /* As at probe, before the new session's RX starts. */ + helper->strict_buffers = apple_rtkit_helper_strict(dev, count); rtk = apple_rtkit_init_adopted_with_buffers(dev, helper, NULL, 0, &apple_rtkit_helper_ops, buffers, count); if (IS_ERR(rtk)) { @@ -783,8 +793,6 @@ static int apple_rtkit_helper_restore(struct device *dev) /* The old object described an instance that no longer exists. */ old = helper->rtk; helper->rtk = rtk; - helper->strict_buffers = count > 0 || - of_device_is_compatible(dev->of_node, "apple,t8132-mtp"); apple_rtkit_free_retaining_buffers(old); dev_dbg(dev, "re-adopted the running RTKit session after hibernation (%d retained buffers)\n", count); From 50547e30af8361ecb4366dfc20e3be8ff43ce11f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Thu, 12 Nov 2026 23:54:00 +0100 Subject: [PATCH 37/49] arm64: errata: drop the apple_pmuv3_traps boot parameter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The parameter turned on the implementation defined PMUv3 traps for KVM guests on the T6040 cores, which are not in apple_cpus, until the traps are verified there. They have not been, the parameter is off by default, and a boot parameter is no place for a test switch: once the traps are verified, the two MIDRs belong in apple_cpus. Remove the parameter and its documentation. The file is again as it was before the parameter: guests on these cores see no PMU. Signed-off-by: František Balázsy --- .../admin-guide/kernel-parameters.txt | 9 ----- arch/arm64/kernel/cpu_errata.c | 34 +++---------------- 2 files changed, 5 insertions(+), 38 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 9ce5baf6854e7..2e6fa8b49752e 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -549,15 +549,6 @@ Kernel parameters autoconf= [IPV6] See Documentation/networking/ipv6.rst. - apple_pmuv3_traps= - [ARM64,EARLY] Enable the IMPDEF PMUv3 trapping of KVM - guests (HACR_EL2 bit 56) on Apple cores where it has - not been verified yet, currently the M4 Pro/Max (T6040) - E and P cores. With it, KVM advertises a PMUv3 to its - guests backed by the Apple CPU PMU driver; without it - those guests see no PMU. Default: off on these cores. - Format: , a bare "apple_pmuv3_traps" means on. - apm= [APM] Advanced Power Management See header of arch/x86/kernel/apm_32.c. diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index d5c3fe7533802..fa1a6a83caa97 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -292,29 +291,6 @@ static const struct midr_range apple_cpus[] = { {}, }; -/* - * Apple cores that aren't in apple_cpus whose IMPDEF PMUv3 traps (HACR_EL2 - * bit 56) are turned on only when asked for on the command line - * (apple_pmuv3_traps), until they have been verified on these cores. - */ -static const struct midr_range apple_m4_cpus[] = { - MIDR_ALL_VERSIONS(MIDR_APPLE_T6040_E), - MIDR_ALL_VERSIONS(MIDR_APPLE_T6040_P), - {}, -}; - -static bool apple_pmuv3_traps_optin __ro_after_init; - -static int __init early_apple_pmuv3_traps_cfg(char *arg) -{ - /* A bare "apple_pmuv3_traps" enables the traps. */ - if (!arg || !*arg) - arg = "on"; - - return kstrtobool(arg, &apple_pmuv3_traps_optin); -} -early_param("apple_pmuv3_traps", early_apple_pmuv3_traps_cfg); - static bool has_impdef_pmuv3(const struct arm64_cpu_capabilities *entry, int scope) { u64 dfr0 = read_sanitised_ftr_reg(SYS_ID_AA64DFR0_EL1); @@ -328,13 +304,13 @@ static bool has_impdef_pmuv3(const struct arm64_cpu_capabilities *entry, int sco if (pmuver != ID_AA64DFR0_EL1_PMUVer_IMP_DEF) return false; - if (is_midr_in_range_list(apple_cpus)) - return true; - - return apple_pmuv3_traps_optin && is_midr_in_range_list(apple_m4_cpus); + return is_midr_in_range_list(apple_cpus); } -/* Apple cores with the same vGIC as M1/M2 that aren't in apple_cpus yet. */ +/* + * Apple cores with the same vGIC as M1/M2 that aren't in apple_cpus yet: + * that list also turns on the IMPDEF PMUv3 traps, unverified here. + */ static const struct midr_range apple_broken_seis_cpus[] = { MIDR_ALL_VERSIONS(MIDR_APPLE_T6040_E), MIDR_ALL_VERSIONS(MIDR_APPLE_T6040_P), From 500a84751ba2a4b58bd8fbd61bf0c2d7da7c51a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Fri, 13 Nov 2026 00:01:53 +0100 Subject: [PATCH 38/49] soc: apple: rtkit-helper: test the coprocessor's run bit in one place MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The helper that reads the ASC's CPU run bit came with the hibernation callbacks, while the hand-off check and the removal read the same bit with a copy of the expression. Move the helper up and use it there. The three tests that read the bit with readl() are left as they are. No functional change: every path reads the bit as often and at the same point as before. With five users the compiler no longer inlines the helper. Signed-off-by: František Balázsy --- drivers/soc/apple/rtkit-helper.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/drivers/soc/apple/rtkit-helper.c b/drivers/soc/apple/rtkit-helper.c index bcd666f166da4..52ea34080b7f5 100644 --- a/drivers/soc/apple/rtkit-helper.c +++ b/drivers/soc/apple/rtkit-helper.c @@ -141,6 +141,13 @@ static const struct apple_rtkit_ops apple_rtkit_helper_ops = { .shmem_destroy = apple_rtkit_helper_shmem_destroy, }; +/* Whether the coprocessor's CPU runs: halted, nothing answers on its mailbox. */ +static bool apple_rtkit_helper_cpu_running(struct apple_rtkit_helper *helper) +{ + return readl_relaxed(helper->asc_base + APPLE_ASC_CPU_CONTROL) & + APPLE_ASC_CPU_CONTROL_RUN; +} + static void apple_rtkit_helper_release(void *data) { struct apple_rtkit_helper *helper = data; @@ -172,8 +179,7 @@ static int apple_rtkit_helper_live(struct apple_rtkit_helper *helper) return -EINVAL; } - if (!(readl_relaxed(helper->asc_base + APPLE_ASC_CPU_CONTROL) & - APPLE_ASC_CPU_CONTROL_RUN)) { + if (!apple_rtkit_helper_cpu_running(helper)) { dev_warn(helper->dev, "RTKit handoff without a running CPU\n"); return -ENODEV; } @@ -427,8 +433,7 @@ static void apple_rtkit_helper_remove(struct platform_device *pdev) * believes it runs: nothing would answer the quiesce. Drop the session * without a handshake so that the next probe starts the CPU again. */ - if (!(readl_relaxed(helper->asc_base + APPLE_ASC_CPU_CONTROL) & - APPLE_ASC_CPU_CONTROL_RUN)) { + if (!apple_rtkit_helper_cpu_running(helper)) { dev_info(&pdev->dev, "co-processor halted underneath (resume from disk): removed without quiesce\n"); return; } @@ -615,12 +620,6 @@ static void apple_rtkit_helper_hib_tag(struct device *dev, char *tag, size_t len snprintf(tag, len, "rtkh:%s", dev_name(dev)); } -static bool apple_rtkit_helper_cpu_running(struct apple_rtkit_helper *helper) -{ - return readl_relaxed(helper->asc_base + APPLE_ASC_CPU_CONTROL) & - APPLE_ASC_CPU_CONTROL_RUN; -} - /* * Hibernation of an adopted session. The image is written while the firmware * keeps running; its buffers live in SRAM or in no-map reserved RAM, so they From 9fe39708e55d7dbd91145848705cd97c99831f5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Fri, 13 Nov 2026 03:40:59 +0100 Subject: [PATCH 39/49] soc: apple: rtkit: add an AP idle notice for use with interrupts off MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit apple_rtkit_ap_power_noirq() polls the mailbox, but it waits with usleep_range() and jiffies and takes the acknowledgment from the receive work. None of that is to be had at a sleep controller's commit, where interrupts are off, one CPU is up and timekeeping is suspended. apple_rtkit_sleep_idle_polled() already sends the AP and IOP idle notices there for a coprocessor that is then stopped: it polls a bounded number of times with udelay() and takes the acknowledgments in the poll. Add apple_rtkit_ap_idle_polled() for a coprocessor that stays up and is only told that the AP goes idle, as the SMC is. It shares the start of the polled idle (what is waiting is taken first, an owed OSLOG counter is echoed) and sends the AP notice alone. Such a coprocessor's client still has traffic on its own endpoints: a reply to a command it sent just before, or an event. While the notice is polled for, a message for an application endpoint therefore goes to recv_message_early as usual, and one that is not taken there is queued for the receive work, which runs again after the wake. Everything else is handled as in the polled idle. Compiled only: its first user is the SMC's sleep commit in the next patch, which has not run on hardware yet. Signed-off-by: František Balázsy --- drivers/soc/apple/rtkit.c | 63 +++++++++++++++++++++++++++------ include/linux/soc/apple/rtkit.h | 10 ++++++ 2 files changed, 63 insertions(+), 10 deletions(-) diff --git a/drivers/soc/apple/rtkit.c b/drivers/soc/apple/rtkit.c index 6c6d75a9428e7..3ee1117bde3c7 100644 --- a/drivers/soc/apple/rtkit.c +++ b/drivers/soc/apple/rtkit.c @@ -2571,18 +2571,21 @@ static int apple_rtkit_polled_state(struct apple_rtkit *rtk, u8 type, unsigned i return -ETIMEDOUT; } -int apple_rtkit_sleep_idle_polled(struct apple_rtkit *rtk, void __iomem *cpu_control, - unsigned int *us) +/* The receive path while a notice is polled for, and the usual one after it. */ +static void apple_rtkit_polled_set_rx(struct apple_rtkit *rtk, + void (*rx)(struct apple_mbox *mbox, + struct apple_mbox_msg msg, void *cookie)) { unsigned long flags; - u64 owed; - u32 status; - int ret; - *us = 0; spin_lock_irqsave(&rtk->mbox->rx_lock, flags); - rtk->mbox->rx = apple_rtkit_polled_rx; + rtk->mbox->rx = rx; spin_unlock_irqrestore(&rtk->mbox->rx_lock, flags); +} + +static void apple_rtkit_polled_owed(struct apple_rtkit *rtk) +{ + u64 owed; /* What's already waiting is answered first, or the firmware may not go idle. */ apple_mbox_poll(rtk->mbox); @@ -2594,6 +2597,17 @@ int apple_rtkit_sleep_idle_polled(struct apple_rtkit *rtk, void __iomem *cpu_con if (!apple_rtkit_polled_send(rtk, echo)) dev_err(rtk->dev, "RTKit: oslog echo failed before the idle\n"); } +} + +int apple_rtkit_sleep_idle_polled(struct apple_rtkit *rtk, void __iomem *cpu_control, + unsigned int *us) +{ + u32 status; + int ret; + + *us = 0; + apple_rtkit_polled_set_rx(rtk, apple_rtkit_polled_rx); + apple_rtkit_polled_owed(rtk); ret = apple_rtkit_polled_state(rtk, APPLE_RTKIT_MGMT_SET_AP_PWR_STATE, &rtk->ap_power_state, us); @@ -2606,14 +2620,43 @@ int apple_rtkit_sleep_idle_polled(struct apple_rtkit *rtk, void __iomem *cpu_con APPLE_ASC_CPU_STATUS_DOWN, APPLE_RTKIT_POLLED_STEP_US, 5000); - spin_lock_irqsave(&rtk->mbox->rx_lock, flags); - rtk->mbox->rx = apple_rtkit_rx; - spin_unlock_irqrestore(&rtk->mbox->rx_lock, flags); + apple_rtkit_polled_set_rx(rtk, apple_rtkit_rx); return ret; } EXPORT_SYMBOL_GPL(apple_rtkit_sleep_idle_polled); +/* + * For a co-processor that stays up: its client may still be owed a reply or an event on + * its own endpoints. Those go the usual way, to recv_message_early and, if it leaves + * them, to the receive work, which runs again after the wake. + */ +static void apple_rtkit_ap_polled_rx(struct apple_mbox *mbox, struct apple_mbox_msg msg, + void *cookie) +{ + if (msg.msg1 >= APPLE_RTKIT_APP_ENDPOINT_START) + apple_rtkit_rx(mbox, msg, cookie); + else + apple_rtkit_polled_rx(mbox, msg, cookie); +} + +int apple_rtkit_ap_idle_polled(struct apple_rtkit *rtk, unsigned int *us) +{ + int ret; + + *us = 0; + apple_rtkit_polled_set_rx(rtk, apple_rtkit_ap_polled_rx); + apple_rtkit_polled_owed(rtk); + + ret = apple_rtkit_polled_state(rtk, APPLE_RTKIT_MGMT_SET_AP_PWR_STATE, + &rtk->ap_power_state, us); + + apple_rtkit_polled_set_rx(rtk, apple_rtkit_rx); + + return ret; +} +EXPORT_SYMBOL_GPL(apple_rtkit_ap_idle_polled); + void apple_rtkit_mailbox_recv_off(struct apple_rtkit *rtk) { apple_mbox_set_recv_enabled(rtk->mbox, false); diff --git a/include/linux/soc/apple/rtkit.h b/include/linux/soc/apple/rtkit.h index 60fa2ba2fdeba..242d36662a1d3 100644 --- a/include/linux/soc/apple/rtkit.h +++ b/include/linux/soc/apple/rtkit.h @@ -310,6 +310,16 @@ int apple_rtkit_ap_power(struct apple_rtkit *rtk, bool on); /* The same, for a noirq phase: device interrupts are off, so it polls. */ int apple_rtkit_ap_power_noirq(struct apple_rtkit *rtk, bool on); +/* + * The idle notice with interrupts off and one CPU up, where nothing can sleep and the + * receive work doesn't run: the mailbox is polled a bounded number of times, with no + * clock read, and the acknowledgment is taken in the poll. A message on one of the + * client's own endpoints still goes to recv_message_early; one it leaves waits for the + * receive work. @us is about how long the acknowledgment took. The wake's notice is + * apple_rtkit_ap_power() or apple_rtkit_ap_power_noirq(), as after any other. + */ +int apple_rtkit_ap_idle_polled(struct apple_rtkit *rtk, unsigned int *us); + /* * Stop a co-processor for a system sleep that may remove its power: idle, wait * for the status that shows it has finished, then clear the run bit. On an error From f6e50ad0d1caceb963feb803c8cf0c2957b139a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Fri, 13 Nov 2026 14:38:24 +0100 Subject: [PATCH 40/49] soc: apple: aura-hibernate: probe again through the aura reprobe helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The drivers/soc/apple/aura-hibernate.c part of "soc: apple: sep: probe again through the aura reprobe helper", which goes with the hibernation core changes; the rest of that commit is with the coprocessor changes. After a resume from disk on a cold boot the SEP is unbound and probed again once the tasks are thawed, to register with the restarted enclave. The driver carried its own work item, spinlock, pending-device pointer and a module-exit guard to cancel the work. aura_hibernate_reprobe_after_thaw() does the same unbind and probe from the freezable workqueue, which the restore finds frozen, so the probe cannot start before every device's restore has completed. The helper is built in, so a module going away in the meantime leaves no work behind and needs no cancel. The registration marker is still removed before the probe is queued, and only once a cold boot is established, as before. A probe that leaves the device without a driver is not reported by device_reprobe(); the helper now logs that case too, as the SEP's own work item did. Without CONFIG_APPLE_AURA_HIBERNATE the probe is not queued and the driver says so, as the AOP does. Signed-off-by: František Balázsy --- drivers/soc/apple/aura-hibernate.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/soc/apple/aura-hibernate.c b/drivers/soc/apple/aura-hibernate.c index 59cfe189a4313..4d73d69fa16a9 100644 --- a/drivers/soc/apple/aura-hibernate.c +++ b/drivers/soc/apple/aura-hibernate.c @@ -347,7 +347,8 @@ static void aura_hibernate_reprobe_work(struct work_struct *work) int ret; ret = device_reprobe(rp->dev); - if (ret) + /* A failed probe is not reported by device_reprobe() itself. */ + if (ret || !READ_ONCE(rp->dev->driver)) dev_err(rp->dev, "probe after the resume from disk failed: %d\n", ret); put_device(rp->dev); kfree(rp); From 48b0af496ac305c19c22380d8e0dd0a49066fcfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Fri, 13 Nov 2026 14:52:54 +0100 Subject: [PATCH 41/49] soc: apple: rtkit: report an idle that kept the firmware's memory apart from an error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A co-processor may acknowledge the idle request of its IOP side with a power state other than idle (the low byte 1 or 2): it is asleep with its firmware and memory kept, which is what the caller wants after the AP side has idled. apple_rtkit_idle() returned -EINVAL for it, the same value as a bad argument or a stale state, and the display driver had to accept -EINVAL as success. Return APPLE_RTKIT_IDLE_RETAINED (-EALREADY) for exactly that acknowledgment. Timeouts and failures of the AP side are returned as before. Every other caller of apple_rtkit_idle(), apple_rtkit_idle_with() and apple_rtkit_sleep_stop() treats any non-zero value as a failure and only forwards or prints it, so for them only the printed number changes. The display driver now accepts the new value instead of -EINVAL and fails on any other error, -EINVAL from the transport included. Signed-off-by: František Balázsy --- drivers/soc/apple/rtkit.c | 22 ++++++++++++++++++---- include/linux/soc/apple/rtkit.h | 8 ++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/drivers/soc/apple/rtkit.c b/drivers/soc/apple/rtkit.c index 3ee1117bde3c7..1f7b101d5d195 100644 --- a/drivers/soc/apple/rtkit.c +++ b/drivers/soc/apple/rtkit.c @@ -2203,8 +2203,9 @@ static int apple_rtkit_set_ap_power_state(struct apple_rtkit *rtk, return 0; } -static int apple_rtkit_set_iop_power_state(struct apple_rtkit *rtk, - unsigned int state) +/* Ask the IOP for a power state and wait for its acknowledgment; the caller judges the state. */ +static int apple_rtkit_send_iop_power_state(struct apple_rtkit *rtk, + unsigned int state) { u64 msg; int ret; @@ -2217,7 +2218,15 @@ static int apple_rtkit_set_iop_power_state(struct apple_rtkit *rtk, if (ret) return ret; - ret = apple_rtkit_wait(rtk, &rtk->iop_pwr_ack_completion); + return apple_rtkit_wait(rtk, &rtk->iop_pwr_ack_completion); +} + +static int apple_rtkit_set_iop_power_state(struct apple_rtkit *rtk, + unsigned int state) +{ + int ret; + + ret = apple_rtkit_send_iop_power_state(rtk, state); if (ret) return ret; @@ -2355,11 +2364,16 @@ int apple_rtkit_idle_with(struct apple_rtkit *rtk, void (*after_ap)(void *data), if (after_ap) after_ap(data); - ret = apple_rtkit_set_iop_power_state(rtk, APPLE_RTKIT_PWR_STATE_IDLE); + ret = apple_rtkit_send_iop_power_state(rtk, APPLE_RTKIT_PWR_STATE_IDLE); if (ret) { dev_err(rtk->dev, "RTKit: IOP idle not acknowledged: %d\n", ret); return ret; } + if (rtk->iop_power_state != APPLE_RTKIT_PWR_STATE_IDLE) { + dev_dbg(rtk->dev, "RTKit: IOP acknowledged %#x instead of idle\n", + rtk->iop_power_state); + return APPLE_RTKIT_IDLE_RETAINED; + } rtk->iop_power_state = APPLE_RTKIT_PWR_STATE_IDLE; rtk->ap_power_state = APPLE_RTKIT_PWR_STATE_IDLE; diff --git a/include/linux/soc/apple/rtkit.h b/include/linux/soc/apple/rtkit.h index 242d36662a1d3..44514f2c32eaa 100644 --- a/include/linux/soc/apple/rtkit.h +++ b/include/linux/soc/apple/rtkit.h @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -264,6 +265,13 @@ int apple_rtkit_poweroff(struct apple_rtkit *rtk); */ int apple_rtkit_cold_restart(struct apple_rtkit *rtk, int (*start)(void *), void *ctx); +/* + * Returned by apple_rtkit_idle() and apple_rtkit_idle_with() when the AP side is idle + * and the IOP acknowledged a power state other than idle: it is asleep with its memory + * kept. No other error carries this value. + */ +#define APPLE_RTKIT_IDLE_RETAINED (-EALREADY) + /* * Put the co-processor into idle mode */ From 06cd2c47d6e2c2d0cdf5bf164b5409070986f24c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Fri, 13 Nov 2026 14:51:32 +0100 Subject: [PATCH 42/49] arm64: build every sleep controller and drop two symbols MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The arch/arm64/configs/asahi.config part of "soc: apple: sleep: build every sleep controller and drop two symbols", which goes with the hibernation core changes; the rest of that commit is with the sleep controller changes. APPLE_SLEEP_REGISTRY has only one selector, APPLE_SOC_SLEEP, and the registry is linked into the same object as the controller, so the symbol selects nothing a user could choose. APPLE_T6040_SLEEP exists for the dependency of the T6040 sleep on the SMC driver and for MFD_SYSCON, but a board that has no T6040 sleep controller already gets none: the node's status in the device tree is the switch. Link the registry into apple-sleep, build the T6040 sleep wherever the SMC driver is built in, as before, and select MFD_SYSCON in that case. The T6040 documentation moves to APPLE_SOC_SLEEP. A kernel with APPLE_SOC_SLEEP and the SMC driver as a module still builds the T8140 sleep alone; with both built in it now also carries the T6040 sleep. The asahi config fragment no longer sets the removed symbol. Signed-off-by: František Balázsy --- arch/arm64/configs/asahi.config | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/arm64/configs/asahi.config b/arch/arm64/configs/asahi.config index c0b5ba114bf13..70858dca94b8a 100644 --- a/arch/arm64/configs/asahi.config +++ b/arch/arm64/configs/asahi.config @@ -177,4 +177,3 @@ CONFIG_EDAC_APPLE_SOC=m # the ctxr_exec_window= command-line option is given. CONFIG_ARM64_CTXR_EXECMEM=y CONFIG_APPLE_SOC_SLEEP=y -CONFIG_APPLE_T6040_SLEEP=y From 5b712148622202e55a6a73ebfc78b8a30fe716b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Fri, 13 Nov 2026 15:42:32 +0100 Subject: [PATCH 43/49] PM: hibernate: tell drivers that an image is being loaded MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A driver that must treat the kernel loading a hibernation image differently from a kernel that freezes for an image of its own has no way to ask: the freeze callbacks run the same in both. The SMC driver and the RTKit hand-off each registered a PM notifier that sets a flag on PM_RESTORE_PREPARE and clears it on PM_POST_RESTORE, and the hand-off copy is read by two more drivers. Keep the flag in the PM core, next to the restored flag, and have the two notifier helpers set it around the PM_RESTORE_PREPARE and PM_POST_RESTORE notifications, whether the load starts from the resume path or from the snapshot device. pm_hibernate_is_loading() reads it. It is true from before the first notifier runs (the copies became true only when their own notifier was reached) until PM_POST_RESTORE has been delivered, and it is cleared again when a notifier refuses the load, where the copies of the notifiers not reached never became true. It is saved in an image as false, like the notifier copies, so the restored kernel reads false. The SMC driver reads the core flag in its freeze callback and drops its notifier, which also removes the registration at probe. The RTKit hand-off keeps apple_rtkit_hib_restoring() for its callers and answers it from the core flag. Signed-off-by: František Balázsy --- drivers/soc/apple/rtkit-hib-handoff.c | 34 +-------------------------- include/linux/suspend.h | 2 ++ kernel/power/hibernate.c | 33 ++++++++++++++++++++++++++ kernel/power/main.c | 13 +++++++++- kernel/power/power.h | 2 ++ 5 files changed, 50 insertions(+), 34 deletions(-) diff --git a/drivers/soc/apple/rtkit-hib-handoff.c b/drivers/soc/apple/rtkit-hib-handoff.c index bf5705142b8b1..0700ab8488284 100644 --- a/drivers/soc/apple/rtkit-hib-handoff.c +++ b/drivers/soc/apple/rtkit-hib-handoff.c @@ -18,7 +18,6 @@ */ #include -#include #include #include #include @@ -43,7 +42,6 @@ struct apple_rtkit_hib_slot { static struct apple_rtkit_hib_slot handoff[HANDOFF_SLOTS] __nosavedata; static DEFINE_SPINLOCK(handoff_lock); -static bool restoring; /* FNV-1a over everything but the checksum itself. */ static u32 handoff_sum(const struct apple_rtkit_hib_slot *s) @@ -82,7 +80,7 @@ static struct apple_rtkit_hib_slot *handoff_find(const char *tag) bool apple_rtkit_hib_restoring(void) { - return READ_ONCE(restoring); + return pm_hibernate_is_loading(); } EXPORT_SYMBOL_GPL(apple_rtkit_hib_restoring); @@ -153,36 +151,6 @@ void apple_rtkit_hib_handoff_drop(const char *tag) } EXPORT_SYMBOL_GPL(apple_rtkit_hib_handoff_drop); -static int apple_rtkit_hib_notify(struct notifier_block *nb, - unsigned long action, void *data) -{ - switch (action) { - case PM_RESTORE_PREPARE: - WRITE_ONCE(restoring, true); - break; - case PM_POST_RESTORE: - /* The image was not restored: this kernel goes on. */ - WRITE_ONCE(restoring, false); - break; - } - return NOTIFY_DONE; -} - -static struct notifier_block apple_rtkit_hib_nb = { - .notifier_call = apple_rtkit_hib_notify, -}; - -static int __init apple_rtkit_hib_init(void) -{ - /* - * A kernel restored from an image runs this only on its own first - * boot, and the flag is saved false in the image: in the restored - * kernel it reads false. - */ - return register_pm_notifier(&apple_rtkit_hib_nb); -} -core_initcall(apple_rtkit_hib_init); - #else bool apple_rtkit_hib_restoring(void) diff --git a/include/linux/suspend.h b/include/linux/suspend.h index 2ebbb01fa14cc..a49c8045af181 100644 --- a/include/linux/suspend.h +++ b/include/linux/suspend.h @@ -455,8 +455,10 @@ static inline bool pm_hibernation_mode_is_suspend(void) { return false; } #ifdef CONFIG_HIBERNATION bool pm_hibernate_is_restored(void); +bool pm_hibernate_is_loading(void); #else static inline bool pm_hibernate_is_restored(void) { return false; } +static inline bool pm_hibernate_is_loading(void) { return false; } #endif int arch_resume_nosmt(void); diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c index 41784a6771e34..a93ee54010450 100644 --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c @@ -101,6 +101,39 @@ bool pm_hibernate_is_restored(void) } EXPORT_SYMBOL_GPL(pm_hibernate_is_restored); +/* Set while this kernel loads a hibernation image, see pm_hibernate_is_loading(). */ +static bool hibernate_loading; + +/** + * pm_hibernate_is_loading - Whether this kernel is loading a hibernation image. + * + * True from the PM_RESTORE_PREPARE notification, which starts the loading of an + * image (from the resume path or through the snapshot device), until the + * PM_POST_RESTORE notification that ends it when the image was not restored + * (or the notification chain refused it). The devices of the kernel that + * loads an image are quiesced for the jump into the image, not frozen for an + * image of their own; the flag lets drivers tell the two apart in their + * freeze callbacks. The kernel restored from an image reads false: the image + * holds the state of the kernel that created it. + */ +bool pm_hibernate_is_loading(void) +{ + return READ_ONCE(hibernate_loading); +} +EXPORT_SYMBOL_GPL(pm_hibernate_is_loading); + +/** + * hibernate_set_loading - Record that an image is being loaded or no longer is. + * @loading: New value of the flag read by pm_hibernate_is_loading(). + * + * Called from the PM notifier chain helpers around PM_RESTORE_PREPARE and + * PM_POST_RESTORE. + */ +void hibernate_set_loading(bool loading) +{ + WRITE_ONCE(hibernate_loading, loading); +} + #ifdef CONFIG_SUSPEND /** * pm_hibernation_mode_is_suspend - Check if hibernation has been set to suspend diff --git a/kernel/power/main.c b/kernel/power/main.c index 5429e9f19b655..ccced400c15c7 100644 --- a/kernel/power/main.c +++ b/kernel/power/main.c @@ -169,14 +169,25 @@ int pm_notifier_call_chain_robust(unsigned long val_up, unsigned long val_down) { int ret; + if (val_up == PM_RESTORE_PREPARE) + hibernate_set_loading(true); + ret = blocking_notifier_call_chain_robust(&pm_chain_head, val_up, val_down, NULL); + if (ret && val_up == PM_RESTORE_PREPARE) + hibernate_set_loading(false); + return notifier_to_errno(ret); } int pm_notifier_call_chain(unsigned long val) { - return blocking_notifier_call_chain(&pm_chain_head, val, NULL); + int ret = blocking_notifier_call_chain(&pm_chain_head, val, NULL); + + if (val == PM_POST_RESTORE) + hibernate_set_loading(false); + + return ret; } /* If set, devices may be suspended and resumed asynchronously. */ diff --git a/kernel/power/power.h b/kernel/power/power.h index 6c269ce9410ec..e43e77f9a999b 100644 --- a/kernel/power/power.h +++ b/kernel/power/power.h @@ -77,6 +77,7 @@ static inline void enable_restore_image_protection(void) {} #endif /* CONFIG_STRICT_KERNEL_RWX */ extern bool hibernation_in_progress(void); +void hibernate_set_loading(bool loading); #else /* !CONFIG_HIBERNATION */ @@ -84,6 +85,7 @@ static inline void hibernate_reserved_size_init(void) {} static inline void hibernate_image_size_init(void) {} static inline bool hibernation_in_progress(void) { return false; } +static inline void hibernate_set_loading(bool loading) {} #endif /* !CONFIG_HIBERNATION */ #define power_attr(_name) \ From db30c722af442a50b0d71004dce246bbef5f0317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Fri, 13 Nov 2026 15:44:23 +0100 Subject: [PATCH 44/49] PM: hibernate: let the architecture clean the pages of a loaded image MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit swsusp cleans every page of a loaded image to the point of coherency before the jump into it, for devices that read memory without snooping the CPU caches, and does so under #ifdef CONFIG_ARM64 in the generic snapshot code, with the justification of one SoC family in its comment. Keep the walk over the image's page frames in snapshot.c and ask the architecture, per frame, through arch_hibernate_clean_image_page(), enabled by ARCH_HIBERNATION_CLEAN_IMAGE. arm64 sets the symbol and provides the function with the body the walk had: a frame that is not in the boot kernel's linear map is left to the restore_pblist copy, any other frame is cleaned and invalidated to the PoC. The frames, their order, the cond_resched() cadence and the clean operations are the same as before; the generated arm64 code matches the removed loop body. Other architectures compile the walk out, as they did. The comment of the copy loop in hibernate-asm.S no longer names a SoC. Signed-off-by: František Balázsy --- arch/arm64/Kconfig | 4 ++++ arch/arm64/kernel/hibernate-asm.S | 8 ++++---- arch/arm64/kernel/hibernate.c | 24 ++++++++++++++++++++++++ include/linux/suspend.h | 17 +++++++++++++++++ kernel/power/snapshot.c | 24 ++++++------------------ 5 files changed, 55 insertions(+), 22 deletions(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 81f92a6fb50f7..224bba9710481 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -2689,6 +2689,10 @@ config ARCH_HIBERNATION_HEADER def_bool y depends on HIBERNATION +config ARCH_HIBERNATION_CLEAN_IMAGE + def_bool y + depends on HIBERNATION + config ARCH_SUSPEND_POSSIBLE def_bool y diff --git a/arch/arm64/kernel/hibernate-asm.S b/arch/arm64/kernel/hibernate-asm.S index f30269635a4fd..89fc1db49f618 100644 --- a/arch/arm64/kernel/hibernate-asm.S +++ b/arch/arm64/kernel/hibernate-asm.S @@ -68,10 +68,10 @@ SYM_CODE_START(swsusp_arch_suspend_exit) add x1, x10, #PAGE_SIZE /* - * Clean the copied page to PoC, not only PoU: on Apple SoCs the - * coprocessors (GPU UAT walker, DCP, ...) are not cache coherent and - * read the restored pages from DRAM. Clean+invalidate to PoC also - * covers what caches_clean_inval_pou() did for the I-side. + * Clean the copied page to PoC, not only PoU: non-coherent DMA + * masters (the coprocessors of some SoCs) read the restored pages + * from DRAM. Clean+invalidate to PoC also covers what + * caches_clean_inval_pou() did for the I-side. */ raw_dcache_line_size x2, x3 sub x3, x2, #1 diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c index 1119168a392d8..b30cc81f2736f 100644 --- a/arch/arm64/kernel/hibernate.c +++ b/arch/arm64/kernel/hibernate.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -209,6 +210,29 @@ static u64 hibernate_boot_layout(void) return h; } +/* + * Most image pages are loaded straight into their original frames through the + * cacheable linear map. Non-coherent DMA masters (on Apple SoCs: the GPU page + * table walker, DCP, every RTKit co-processor, the NVMe queues) read DRAM, and + * a later eviction of a dirty line would overwrite what a device wrote since. + * Clean and invalidate the page to the PoC before the jump. + * + * A frame that is not in the boot kernel's linear map (for example the linear + * alias of the kernel image, which faults when touched) had nothing loaded + * through the linear map: such frames are restored by the restore_pblist copy, + * which cleans each copied page itself. + */ +int arch_hibernate_clean_image_page(unsigned long pfn) +{ + unsigned long va; + + if (!kernel_page_present(pfn_to_page(pfn))) + return 0; + va = (unsigned long)page_address(pfn_to_page(pfn)); + dcache_clean_inval_poc(va, va + PAGE_SIZE); + return 1; +} + int pfn_is_nosave(unsigned long pfn) { unsigned long nosave_begin_pfn = sym_to_pfn(&__nosave_begin); diff --git a/include/linux/suspend.h b/include/linux/suspend.h index a49c8045af181..3f2a60fbdc61a 100644 --- a/include/linux/suspend.h +++ b/include/linux/suspend.h @@ -431,6 +431,23 @@ int hibernate_resume_nonboot_cpu_disable(void); int arch_hibernation_header_save(void *addr, unsigned int max_size); int arch_hibernation_header_restore(void *addr); +#ifdef CONFIG_ARCH_HIBERNATION_CLEAN_IMAGE +/** + * arch_hibernate_clean_image_page - Make a loaded image page visible to devices. + * @pfn: Valid page frame of the image. + * + * Provided by an architecture that sets ARCH_HIBERNATION_CLEAN_IMAGE. + * Called once for every valid page frame of the image after the whole image + * has been loaded, while the list of those frames is still intact, so that + * the architecture can clean the caches for devices that do not snoop them. + * + * Return: 1 when the page was cleaned, 0 when it was left alone because + * nothing was loaded into it through the linear map (the frame is restored + * from restore_pblist). + */ +int arch_hibernate_clean_image_page(unsigned long pfn); +#endif + #else /* CONFIG_HIBERNATION */ static inline void register_nosave_region(unsigned long b, unsigned long e) {} static inline int swsusp_page_is_forbidden(struct page *p) { return 0; } diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c index 6ab21287493b5..42d24f43991f8 100644 --- a/kernel/power/snapshot.c +++ b/kernel/power/snapshot.c @@ -2751,14 +2751,13 @@ static void *get_buffer(struct memory_bitmap *bm, struct chain_allocator *ca) return pbe->address; } -#ifdef CONFIG_ARM64 +#ifdef CONFIG_ARCH_HIBERNATION_CLEAN_IMAGE /* * Most image pages are loaded straight into their original frames through * the cacheable linear map (only conflicting pages go through restore_pblist). - * Non-coherent DMA masters (on Apple SoCs: the GPU page table walker, DCP, - * every RTKit co-processor, the NVMe queues) read DRAM, and a later eviction - * of a dirty line would overwrite what a device wrote since. Clean and - * invalidate every image page to the PoC before the jump. + * Where devices read memory without snooping the CPU caches, a later eviction + * of a dirty line would overwrite what a device wrote since: let the + * architecture clean every image page before the jump. */ static void swsusp_clean_restored_image(void) { @@ -2767,27 +2766,16 @@ static void swsusp_clean_restored_image(void) memory_bm_position_reset(&orig_bm); for (pfn = memory_bm_next_pfn(&orig_bm); pfn != BM_END_OF_MAP; pfn = memory_bm_next_pfn(&orig_bm)) { - unsigned long va; - if (!pfn_valid(pfn)) continue; - /* - * Not in the boot kernel's linear map (for example the linear - * alias of the kernel image, which faults when touched): - * nothing was loaded there through the linear map. Such frames - * are restored by the restore_pblist copy, which cleans each - * copied page itself. - */ - if (!kernel_page_present(pfn_to_page(pfn))) { + if (!arch_hibernate_clean_image_page(pfn)) { skipped++; continue; } - va = (unsigned long)page_address(pfn_to_page(pfn)); - dcache_clean_inval_poc(va, va + PAGE_SIZE); if (!(++n & 0xffff)) cond_resched(); } - pr_debug("%lu image pages cleaned to PoC, %lu outside the linear map left to the copy\n", + pr_debug("%lu image pages cleaned, %lu left to the restore_pblist copy\n", n, skipped); } #else From 02db30e349ca44643f9fc98d88ba60b203ba188f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Fri, 13 Nov 2026 15:45:46 +0100 Subject: [PATCH 45/49] PM: hibernate: let the platform refuse hibernation through a hook MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit hibernation_available() asked of_machine_is_compatible("apple,arm-platform") and aura_hibernate_layout_fixed() in the generic hibernation code, and the log line carried the reason of one platform. Add hibernation_set_platform_check(): platform code registers a function that is true while hibernation must stay refused, with the reason that is logged at the end of the boot when it is. hibernation_available() asks it where it asked the two Apple conditions. The aura hibernation code registers aura_hibernate_blocked(), which is the same expression (Apple platform and no fixed layout), evaluated at the same moments, and the same reason text; the explanation of why the machines refuse moves with it. The check is registered from the init of that code on every boot of a kernel that has it, where the Apple condition used to be compiled into the core unconditionally. To keep that fail-closed, APPLE_AURA_HIBERNATE is no longer a prompt: it is always on with ARCH_APPLE and HIBERNATION, as the refusal belongs to it. Nothing registers before that init runs, which precedes the first possible hibernation (the resume check is a later initcall level and user space starts after all of them). Signed-off-by: František Balázsy --- drivers/soc/apple/aura-hibernate.c | 20 +++++++++++++++ include/linux/suspend.h | 1 + kernel/power/hibernate.c | 41 +++++++++++++++++------------- 3 files changed, 44 insertions(+), 18 deletions(-) diff --git a/drivers/soc/apple/aura-hibernate.c b/drivers/soc/apple/aura-hibernate.c index 4d73d69fa16a9..b97181762ab28 100644 --- a/drivers/soc/apple/aura-hibernate.c +++ b/drivers/soc/apple/aura-hibernate.c @@ -65,6 +65,23 @@ bool aura_hibernate_layout_fixed(void) return aura_layout_fixed; } +/* + * Apple silicon Macs run firmware on their coprocessors (storage, secure + * enclave, display, always-on processor, system controller, GPU and more). + * Restoring an image means a cold boot through the platform boot chain, which + * restarts that firmware, but most of the Linux drivers have no + * freeze/poweroff/restore path that rebuilds their mailbox, ring and DMA state + * from a cold start. The restored kernel would keep using stale state, so + * writing and restoring images stays disabled on these machines, except where + * the boot object gives the OS a fixed memory layout and the drivers rebuild + * their coprocessor state from the cold boot that restores the image (aura + * hib=1, see above). + */ +static bool aura_hibernate_blocked(void) +{ + return of_machine_is_compatible("apple,arm-platform") && !aura_layout_fixed; +} + bool aura_hibernate_pfn_nosave(unsigned long pfn) { unsigned int i; @@ -385,6 +402,9 @@ static int __init aura_hibernate_init(void) u64 layout[2], dt_slot; int i, n; + hibernation_set_platform_check(aura_hibernate_blocked, + "coprocessor firmware state is not restored from an image"); + /* Only a boot loader that keeps the layout fixed publishes it. */ chosen = of_find_node_by_path("/chosen"); if (!chosen || diff --git a/include/linux/suspend.h b/include/linux/suspend.h index 3f2a60fbdc61a..3013208a46c30 100644 --- a/include/linux/suspend.h +++ b/include/linux/suspend.h @@ -422,6 +422,7 @@ extern void hibernation_set_ops(const struct platform_hibernation_ops *ops); extern int hibernate(void); extern bool system_entering_hibernation(void); extern bool hibernation_available(void); +void hibernation_set_platform_check(bool (*blocked)(void), const char *reason); asmlinkage int swsusp_save(void); extern struct pbe *restore_pblist; int pfn_is_nosave(unsigned long pfn); diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c index a93ee54010450..1356560841fd3 100644 --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -34,7 +33,6 @@ #include #include #include -#include #include #include "power.h" @@ -160,29 +158,36 @@ bool hibernation_in_progress(void) return !atomic_read(&hibernate_atomic); } -/* - * Apple silicon Macs run firmware on their coprocessors (storage, secure - * enclave, display, always-on processor, system controller, GPU and more). - * Restoring an image means a cold boot through the platform boot chain, which - * restarts that firmware, but most of the Linux drivers have no - * freeze/poweroff/restore path that rebuilds their mailbox, ring and DMA state - * from a cold start. The restored kernel would keep using stale state, so - * writing and restoring images stays disabled on these machines. +static bool (*hibernation_platform_blocked_fn)(void); +static const char *hibernation_platform_blocked_reason; + +/** + * hibernation_set_platform_check - Let platform code refuse hibernation. + * @blocked: Tells whether hibernation is refused on this platform at the time. + * @reason: Why it is refused, for the log. + * + * A platform whose drivers cannot yet restore their devices from an image + * registers a check that is true until the platform has what it needs. While + * it is true, writing and restoring images stays disabled + * (hibernation_available() is false) and @reason is logged at the end of the + * boot. Only one check can be registered. * * pm_test dry runs are allowed (see hibernate()): every pm_test level stops * before create_image() takes a snapshot, so no image is written or restored. * They exercise the freezer and the device freeze/thaw callbacks that a real * implementation needs. */ +void hibernation_set_platform_check(bool (*blocked)(void), const char *reason) +{ + if (WARN_ON_ONCE(hibernation_platform_blocked_fn)) + return; + hibernation_platform_blocked_reason = reason; + hibernation_platform_blocked_fn = blocked; +} + static bool hibernation_platform_blocked(void) { - /* - * Except where the boot object gives the OS a fixed memory layout and - * the drivers rebuild their coprocessor state from the cold boot that - * restores the image (aura hib=1, see aura-hibernate.c). - */ - return of_machine_is_compatible("apple,arm-platform") && - !aura_hibernate_layout_fixed(); + return hibernation_platform_blocked_fn && hibernation_platform_blocked_fn(); } static bool hibernation_generic_available(void) @@ -201,7 +206,7 @@ bool hibernation_available(void) static int __init hibernation_platform_report(void) { if (hibernation_platform_blocked()) - pr_info("disabled on this platform: coprocessor firmware state is not restored from an image\n"); + pr_info("disabled on this platform: %s\n", hibernation_platform_blocked_reason); return 0; } late_initcall(hibernation_platform_report); From 71d768d2f32d3b3a509a3a4fc52a160e1fbdbe89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Fri, 13 Nov 2026 15:47:36 +0100 Subject: [PATCH 46/49] arm64: hibernate: take platform facts from a hook, not from aura MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit arm64's hibernation code read aura's /chosen properties, called aura's nosave functions and kept aura's layout rules in the boot layout check that is stored with an image and compared before it is restored. Add struct arm64_hibernate_platform with two hooks, registered once at boot: pfn_nosave(), asked by pfn_is_nosave(), and layout(), which adds the platform's facts to the layout cookie. The part of the check that belongs to every arm64 machine stays: the CPU release addresses (as offsets from a base the platform may name, together with whether the platform keeps the page out of the image) and the memory map less the ranges the platform names. The aura hibernation code registers the hooks and carries the rest: the /chosen properties, the S2R mailbox and the split of aura's layout around the exec window, moved as they were, with the comment that explains them. arm64_hibernate_layout_mix() is the mixing function, made visible for the hook. The nosave ranges stay a table in aura-hibernate.c and are not handed to register_nosave_region(): that function allocates from memblock and runs at setup_arch() time, and the table is filled from a late initcall. The aura functions that nothing outside the file calls any more become static, and aura_hibernate_layout_fixed() is dropped. The cookie is bit for bit the same: the old function and the new pair were compiled against the same stubbed device tree and memblock in 200000 randomised boots (properties present or absent, mailbox, window, nosave tables, CPUs with and without release addresses, memory maps); every cookie is identical, and a change of one mixed value in the new code is caught. The set of pages kept out of the image is the table's, asked at the same place. Signed-off-by: František Balázsy --- arch/arm64/include/asm/suspend.h | 32 +++++++ arch/arm64/kernel/hibernate.c | 114 ++++++++++------------- drivers/soc/apple/aura-hibernate.c | 80 ++++++++++++++-- include/linux/soc/apple/aura-hibernate.h | 6 -- 4 files changed, 154 insertions(+), 78 deletions(-) diff --git a/arch/arm64/include/asm/suspend.h b/arch/arm64/include/asm/suspend.h index e9ce68d50ba45..f453f11af781e 100644 --- a/arch/arm64/include/asm/suspend.h +++ b/arch/arm64/include/asm/suspend.h @@ -48,6 +48,38 @@ int swsusp_arch_resume(void); int arch_hibernation_header_save(void *addr, unsigned int max_size); int arch_hibernation_header_restore(void *addr); +/** + * struct arm64_hibernate_layout - What a platform adds to the boot layout check. + * @ex: Ranges that this boot keeps out of the image and that the layout check + * leaves out of the memory it compares, in ascending order. + * @nex: Number of valid entries in @ex. + * @have_base: Whether CPU release addresses are compared as offsets from @base. + * @base: Base address for the release addresses, if @have_base. + */ +struct arm64_hibernate_layout { + u64 ex[2][2]; + int nex; + bool have_base; + u64 base; +}; + +/** + * struct arm64_hibernate_platform - Platform hooks of arm64 hibernation. + * @pfn_nosave: Whether the platform keeps page frame @pfn out of the image. + * @layout: Mix the platform's boot facts into the layout cookie in @h with + * arm64_hibernate_layout_mix(), fill @lay, and return the new hash. The + * cookie is stored with an image and compared before it is restored: the + * boot that resumes an image must give the kernel the layout of the boot + * that wrote it. + */ +struct arm64_hibernate_platform { + bool (*pfn_nosave)(unsigned long pfn); + u64 (*layout)(u64 h, struct arm64_hibernate_layout *lay); +}; + +void arm64_hibernate_set_platform(const struct arm64_hibernate_platform *platform); +u64 arm64_hibernate_layout_mix(u64 h, const void *p, size_t len); + /* Used to resume on the CPU we hibernated on */ int hibernate_resume_nonboot_cpu_disable(void); diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c index b30cc81f2736f..ce251b5b20d0d 100644 --- a/arch/arm64/kernel/hibernate.c +++ b/arch/arm64/kernel/hibernate.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #include @@ -96,7 +95,16 @@ static inline void arch_hdr_invariants(struct arch_hibernate_hdr_invariants *i) memcpy(i->uts_version, init_utsname()->version, sizeof(i->uts_version)); } -static u64 hibernate_layout_mix(u64 h, const void *p, size_t len) +/** + * arm64_hibernate_layout_mix - Mix bytes into the boot layout cookie. + * @h: Hash so far. + * @p: Bytes to mix. + * @len: Number of bytes. + * + * FNV-1a, for the callback of a platform to mix its boot facts into the cookie + * in the same way as the rest of the layout. + */ +u64 arm64_hibernate_layout_mix(u64 h, const void *p, size_t len) { const u8 *b = p; @@ -126,87 +134,65 @@ static u64 hibernate_mix_span(u64 h, u64 b, u64 e, u32 flags, const u64 (*ex)[2] if (nex) return hibernate_mix_span(h, b, e, flags, ex + 1, nex - 1); size = e - b; - h = hibernate_layout_mix(h, &b, sizeof(b)); - h = hibernate_layout_mix(h, &size, sizeof(size)); - return hibernate_layout_mix(h, &flags, sizeof(flags)); + h = arm64_hibernate_layout_mix(h, &b, sizeof(b)); + h = arm64_hibernate_layout_mix(h, &size, sizeof(size)); + return arm64_hibernate_layout_mix(h, &flags, sizeof(flags)); +} + +static const struct arm64_hibernate_platform *hibernate_platform __ro_after_init; + +/** + * arm64_hibernate_set_platform - Register the platform's hibernation hooks. + * @platform: Hooks of the platform; they must stay valid. + * + * Only one platform can register, at boot. + */ +void __init arm64_hibernate_set_platform(const struct arm64_hibernate_platform *platform) +{ + if (WARN_ON_ONCE(hibernate_platform)) + return; + hibernate_platform = platform; +} + +static bool hibernate_platform_pfn_nosave(unsigned long pfn) +{ + return hibernate_platform && hibernate_platform->pfn_nosave && + hibernate_platform->pfn_nosave(pfn); } /* * The image restores every page to the frame it came from, so the boot that * resumes it must give the kernel what the boot that wrote it did: the same - * RAM, and on Apple machines at EL2 the same CTXR exec window (secondaries only - * execute inside it) and aura's fixed hibernation layout. A boot loader decides - * them on every boot; the kernel build check above cannot see them. - * - * aura's own image moves with the boot object, and its CPU release addresses - * and S2R mailbox with it, inside the range the layout keeps from Linux. The - * restored kernel uses neither address of the boot that wrote the image: its - * CPUs come back from the boot kernel's pen, a CPU started at its reset vector - * again finds the release target the boot kernel wrote (both kernels run at the - * window's fixed address), and the T6040 sleep driver takes this boot's mailbox - * from aura's tree after the restore. What has to match is the spin table's - * shape (the same CPUs, at the same offsets from the mailbox) and that this - * boot keeps all of it out of the image. + * RAM, the same CPUs started the same way, and whatever fixed layout the + * platform's boot loader gives the kernel, which the platform's hook adds. A + * boot loader decides them on every boot; the kernel build check above cannot + * see them. */ static u64 hibernate_boot_layout(void) { - static const char * const chosen_props[] = { - "aura,hibernate-layout", "aura,hibernate-dt", - "aurora,ctxr-exec-window", - }; - u64 h = 0xcbf29ce484222325ULL, mbox = 0, rel, hwid; - u64 layout[2], win[2], ex[2][2]; + struct arm64_hibernate_layout lay = {}; + u64 h = 0xcbf29ce484222325ULL, rel, hwid; struct memblock_region *r; - int nex = 0; struct device_node *np; - bool have_mbox = false; - const void *v; u8 kept; - int i, len; - np = of_find_node_by_path("/chosen"); - for (i = 0; np && i < ARRAY_SIZE(chosen_props); i++) { - v = of_get_property(np, chosen_props[i], &len); - if (!v) - continue; - h = hibernate_layout_mix(h, chosen_props[i], strlen(chosen_props[i])); - h = hibernate_layout_mix(h, v, len); - } - if (np && !of_property_read_u64(np, "aurora,s2r-mailbox", &mbox)) { - have_mbox = true; - kept = aura_hibernate_pfn_nosave(PHYS_PFN(mbox)); - h = hibernate_layout_mix(h, "aurora,s2r-mailbox", strlen("aurora,s2r-mailbox")); - h = hibernate_layout_mix(h, &kept, sizeof(kept)); - } - /* aura's layout less the OS window, only where all of it is kept out of the image */ - if (np && !of_property_read_u64_array(np, "aura,hibernate-layout", layout, 2) && - !of_property_read_u64_array(np, "aurora,ctxr-exec-window", win, 2) && - layout[0] <= win[0] && win[0] + win[1] <= layout[1]) { - ex[nex][0] = layout[0]; - ex[nex][1] = win[0]; - if (aura_hibernate_range_nosave(ex[nex][0], ex[nex][1])) - nex++; - ex[nex][0] = win[0] + win[1]; - ex[nex][1] = layout[1]; - if (aura_hibernate_range_nosave(ex[nex][0], ex[nex][1])) - nex++; - } - of_node_put(np); + if (hibernate_platform && hibernate_platform->layout) + h = hibernate_platform->layout(h, &lay); for_each_of_cpu_node(np) { if (of_property_read_u64(np, "cpu-release-addr", &rel)) continue; hwid = of_get_cpu_hwid(np, 0); - kept = aura_hibernate_pfn_nosave(PHYS_PFN(rel)); - if (have_mbox) - rel -= mbox; - h = hibernate_layout_mix(h, &hwid, sizeof(hwid)); - h = hibernate_layout_mix(h, &rel, sizeof(rel)); - h = hibernate_layout_mix(h, &kept, sizeof(kept)); + kept = hibernate_platform_pfn_nosave(PHYS_PFN(rel)); + if (lay.have_base) + rel -= lay.base; + h = arm64_hibernate_layout_mix(h, &hwid, sizeof(hwid)); + h = arm64_hibernate_layout_mix(h, &rel, sizeof(rel)); + h = arm64_hibernate_layout_mix(h, &kept, sizeof(kept)); } for_each_mem_region(r) - h = hibernate_mix_span(h, r->base, r->base + r->size, r->flags, ex, nex); + h = hibernate_mix_span(h, r->base, r->base + r->size, r->flags, lay.ex, lay.nex); return h; } @@ -239,7 +225,7 @@ int pfn_is_nosave(unsigned long pfn) unsigned long nosave_end_pfn = sym_to_pfn(&__nosave_end - 1); return ((pfn >= nosave_begin_pfn) && (pfn <= nosave_end_pfn)) || - crash_is_nosave(pfn) || aura_hibernate_pfn_nosave(pfn); + crash_is_nosave(pfn) || hibernate_platform_pfn_nosave(pfn); } void notrace save_processor_state(void) diff --git a/drivers/soc/apple/aura-hibernate.c b/drivers/soc/apple/aura-hibernate.c index b97181762ab28..8c50b3cd33dba 100644 --- a/drivers/soc/apple/aura-hibernate.c +++ b/drivers/soc/apple/aura-hibernate.c @@ -43,6 +43,7 @@ #include #include #include +#include static bool aura_layout_fixed; static u64 aura_layout[2]; @@ -52,7 +53,7 @@ static phys_addr_t aura_boot_dt; /* * Ranges kept out of the image, in page frames. Filled once at late_initcall, - * read by arm64's pfn_is_nosave() for reserved pages. A static table avoids + * read through the arm64 hibernation platform hooks. A static table avoids * register_nosave_region(), which allocates from memblock and is meant for * setup_arch() time. */ @@ -60,11 +61,6 @@ static phys_addr_t aura_boot_dt; static struct { unsigned long start, end; } aura_nosave[AURA_NOSAVE_MAX]; static unsigned int aura_nosave_count; -bool aura_hibernate_layout_fixed(void) -{ - return aura_layout_fixed; -} - /* * Apple silicon Macs run firmware on their coprocessors (storage, secure * enclave, display, always-on processor, system controller, GPU and more). @@ -82,7 +78,7 @@ static bool aura_hibernate_blocked(void) return of_machine_is_compatible("apple,arm-platform") && !aura_layout_fixed; } -bool aura_hibernate_pfn_nosave(unsigned long pfn) +static bool aura_hibernate_pfn_nosave(unsigned long pfn) { unsigned int i; @@ -93,7 +89,7 @@ bool aura_hibernate_pfn_nosave(unsigned long pfn) } /* Whether the ranges kept out of the image cover all of [start, end). */ -bool aura_hibernate_range_nosave(u64 start, u64 end) +static bool aura_hibernate_range_nosave(u64 start, u64 end) { unsigned long pfn = PFN_DOWN(start), last = PFN_UP(end); unsigned int i; @@ -113,6 +109,73 @@ bool aura_hibernate_range_nosave(u64 start, u64 end) return true; } +/* + * The image restores every page to the frame it came from, so the boot that + * resumes it must give the kernel what the boot that wrote it did: on Apple + * machines at EL2 the same CTXR exec window (secondaries only execute inside + * it) and aura's fixed hibernation layout. They are added to the layout cookie + * of arm64 hibernation. + * + * aura's own image moves with the boot object, and its CPU release addresses + * and S2R mailbox with it, inside the range the layout keeps from Linux. The + * restored kernel uses neither address of the boot that wrote the image: its + * CPUs come back from the boot kernel's pen, a CPU started at its reset vector + * again finds the release target the boot kernel wrote (both kernels run at the + * window's fixed address), and the T6040 sleep driver takes this boot's mailbox + * from aura's tree after the restore. What has to match is the spin table's + * shape (the same CPUs, at the same offsets from the mailbox) and that this + * boot keeps all of it out of the image. + */ +static u64 aura_hibernate_layout(u64 h, struct arm64_hibernate_layout *lay) +{ + static const char * const chosen_props[] = { + "aura,hibernate-layout", "aura,hibernate-dt", + "aurora,ctxr-exec-window", + }; + u64 mbox = 0, layout[2], win[2]; + struct device_node *np; + const void *v; + u8 kept; + int i, len; + + np = of_find_node_by_path("/chosen"); + for (i = 0; np && i < ARRAY_SIZE(chosen_props); i++) { + v = of_get_property(np, chosen_props[i], &len); + if (!v) + continue; + h = arm64_hibernate_layout_mix(h, chosen_props[i], strlen(chosen_props[i])); + h = arm64_hibernate_layout_mix(h, v, len); + } + if (np && !of_property_read_u64(np, "aurora,s2r-mailbox", &mbox)) { + lay->have_base = true; + lay->base = mbox; + kept = aura_hibernate_pfn_nosave(PHYS_PFN(mbox)); + h = arm64_hibernate_layout_mix(h, "aurora,s2r-mailbox", + strlen("aurora,s2r-mailbox")); + h = arm64_hibernate_layout_mix(h, &kept, sizeof(kept)); + } + /* aura's layout less the OS window, only where all of it is kept out of the image */ + if (np && !of_property_read_u64_array(np, "aura,hibernate-layout", layout, 2) && + !of_property_read_u64_array(np, "aurora,ctxr-exec-window", win, 2) && + layout[0] <= win[0] && win[0] + win[1] <= layout[1]) { + lay->ex[lay->nex][0] = layout[0]; + lay->ex[lay->nex][1] = win[0]; + if (aura_hibernate_range_nosave(lay->ex[lay->nex][0], lay->ex[lay->nex][1])) + lay->nex++; + lay->ex[lay->nex][0] = win[0] + win[1]; + lay->ex[lay->nex][1] = layout[1]; + if (aura_hibernate_range_nosave(lay->ex[lay->nex][0], lay->ex[lay->nex][1])) + lay->nex++; + } + of_node_put(np); + return h; +} + +static const struct arm64_hibernate_platform aura_hibernate_platform = { + .pfn_nosave = aura_hibernate_pfn_nosave, + .layout = aura_hibernate_layout, +}; + static void __init aura_nosave_add(unsigned long s, unsigned long e) { if (s >= e) @@ -404,6 +467,7 @@ static int __init aura_hibernate_init(void) hibernation_set_platform_check(aura_hibernate_blocked, "coprocessor firmware state is not restored from an image"); + arm64_hibernate_set_platform(&aura_hibernate_platform); /* Only a boot loader that keeps the layout fixed publishes it. */ chosen = of_find_node_by_path("/chosen"); diff --git a/include/linux/soc/apple/aura-hibernate.h b/include/linux/soc/apple/aura-hibernate.h index 7c8b80de307be..729ced7b3c4cb 100644 --- a/include/linux/soc/apple/aura-hibernate.h +++ b/include/linux/soc/apple/aura-hibernate.h @@ -24,14 +24,8 @@ int aura_hibernate_boot_fw_regions(struct device_node *np, struct aura_fw_region int aura_hibernate_reprobe_after_thaw(struct device *dev); #ifdef CONFIG_APPLE_AURA_HIBERNATE -bool aura_hibernate_layout_fixed(void); -bool aura_hibernate_pfn_nosave(unsigned long pfn); -bool aura_hibernate_range_nosave(u64 start, u64 end); int aura_hibernate_boot_chosen_u64(const char *name, u64 *val); #else -static inline bool aura_hibernate_layout_fixed(void) { return false; } -static inline bool aura_hibernate_pfn_nosave(unsigned long pfn) { return false; } -static inline bool aura_hibernate_range_nosave(u64 start, u64 end) { return false; } static inline int aura_hibernate_boot_chosen_u64(const char *name, u64 *val) { return -ENODEV; } #endif From e8f712670c0430d65ec1dc7d1686d5ea9ef84318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Fri, 13 Nov 2026 15:53:10 +0100 Subject: [PATCH 47/49] PM: hibernate: tell the restored kernel whether another boot loaded it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A driver whose device does not survive a boot cannot tell, in the kernel restored from a hibernation image, whether the machine went through one. pm_hibernate_is_restored() is also true after a test_resume, where the kernel that wrote the image loads it itself and nothing rebooted, and drivers fell back on hardware side channels to tell the two apart. The kernel that loads an image now leaves a record for the restored kernel just before the jump: whether it is the kernel that wrote the image, which is the case only when hibernate() loads the image it has just written for test_resume, or one that was started to resume it. The record lives in the no-save section, which the image neither saves nor overwrites, and carries a magic and its own physical address, so a record from a kernel loaded elsewhere, or none, reads as absent. It is the same requirement that in_suspend and other no-save hand-offs already have: both kernels are the same build at the same physical address. The restored kernel copies it where it sets the restored flag, and pm_hibernate_restored_cold() returns 1 when another boot loaded the image, 0 when this kernel did (or was not restored) and -ENODATA when no record was found. The record is cleared when it is read and when a restore fails, and the value has the lifetime of pm_hibernate_is_restored(). The flag says that the machine booted, not that a given device lost its state: a kexec-style resume would read as another boot with firmware that kept running, and a device that needs more than the boot has to check it itself. Nothing uses it yet. Signed-off-by: František Balázsy --- include/linux/suspend.h | 2 ++ kernel/power/hibernate.c | 63 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/include/linux/suspend.h b/include/linux/suspend.h index 3013208a46c30..f76d9d4a24cdb 100644 --- a/include/linux/suspend.h +++ b/include/linux/suspend.h @@ -474,9 +474,11 @@ static inline bool pm_hibernation_mode_is_suspend(void) { return false; } #ifdef CONFIG_HIBERNATION bool pm_hibernate_is_restored(void); bool pm_hibernate_is_loading(void); +int pm_hibernate_restored_cold(void); #else static inline bool pm_hibernate_is_restored(void) { return false; } static inline bool pm_hibernate_is_loading(void) { return false; } +static inline int pm_hibernate_restored_cold(void) { return 0; } #endif int arch_resume_nosmt(void); diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c index 1356560841fd3..4d3b30055fcb4 100644 --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c @@ -99,6 +99,53 @@ bool pm_hibernate_is_restored(void) } EXPORT_SYMBOL_GPL(pm_hibernate_is_restored); +/* + * What the kernel that loads an image leaves for the kernel restored from it. + * It lives in the no-save section, which the image neither saves nor + * overwrites, so the restored kernel reads what the loading kernel wrote, as + * long as both are the same build loaded at the same physical address (which + * the image's header requires). The record carries its own physical address + * and a magic: a record from a kernel loaded elsewhere, or none, reads as + * absent. + */ +struct hibernate_load_record { + u32 magic; + u32 other_boot; + u64 self_phys; +}; + +#define HIBERNATE_LOAD_MAGIC 0x484c4452 /* "HLDR" */ + +static struct hibernate_load_record hibernate_load_record __nosavedata; + +/* Set while hibernate() loads the image it has just written (test_resume). */ +static bool hibernate_loading_own_image; + +/* Whether the restore came from another boot, see pm_hibernate_restored_cold(). */ +static int hibernate_restored_cold = -ENODATA; + +/** + * pm_hibernate_restored_cold - Whether this kernel was restored by another boot. + * + * Meaningful once pm_hibernate_is_restored() is true, under the same lifetime. + * The kernel that loads an image tells the kernel restored from it whether it + * is the kernel that wrote the image (a test_resume load: the machine did not + * boot) or one that was started to resume it (the boot loader and the + * firmware have been through a boot). Whether a particular device lost its + * state across that boot is for its driver to find out. + * + * Return: 1 if the image was loaded by another boot, 0 if this kernel loaded + * its own image or was not restored, -ENODATA if the record of the loading + * kernel is missing. + */ +int pm_hibernate_restored_cold(void) +{ + if (!READ_ONCE(hibernate_restored)) + return 0; + return READ_ONCE(hibernate_restored_cold); +} +EXPORT_SYMBOL_GPL(pm_hibernate_restored_cold); + /* Set while this kernel loads a hibernation image, see pm_hibernate_is_loading(). */ static bool hibernate_loading; @@ -463,6 +510,12 @@ static int create_image(int platform_mode) if (!in_suspend) { events_check_enabled = false; clear_or_poison_free_pages(); + if (hibernate_load_record.magic == HIBERNATE_LOAD_MAGIC && + hibernate_load_record.self_phys == __pa_symbol(&hibernate_load_record)) + WRITE_ONCE(hibernate_restored_cold, !!hibernate_load_record.other_boot); + else + WRITE_ONCE(hibernate_restored_cold, -ENODATA); + hibernate_load_record.magic = 0; WRITE_ONCE(hibernate_restored, true); } @@ -504,6 +557,7 @@ int hibernation_snapshot(int platform_mode) pm_suspend_clear_flags(); WRITE_ONCE(hibernate_restored, false); + WRITE_ONCE(hibernate_restored_cold, -ENODATA); error = platform_begin(platform_mode); if (error) goto Close; @@ -617,6 +671,9 @@ static int resume_target_kernel(bool platform_mode) save_processor_state(); error = restore_highmem(); if (!error) { + hibernate_load_record.other_boot = !hibernate_loading_own_image; + hibernate_load_record.self_phys = __pa_symbol(&hibernate_load_record); + hibernate_load_record.magic = HIBERNATE_LOAD_MAGIC; error = swsusp_arch_resume(); /* * The code below is only ever reached in case of a failure. @@ -624,6 +681,7 @@ static int resume_target_kernel(bool platform_mode) * swsusp_arch_suspend() was called. */ BUG_ON(!error); + hibernate_load_record.magic = 0; /* * This call to restore_highmem() reverts the changes made by * the previous one. @@ -995,8 +1053,11 @@ int hibernate(void) if (snapshot_test) { pm_pr_dbg("Checking hibernation image\n"); error = swsusp_check(false); - if (!error) + if (!error) { + hibernate_loading_own_image = true; error = load_image_and_restore(); + hibernate_loading_own_image = false; + } } thaw_processes(); From 93b3ce4086c313a00ad25c002edf8db4656eb3fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Fri, 13 Nov 2026 15:57:27 +0100 Subject: [PATCH 48/49] PM: hibernate: recover devices when no image was created MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When hibernation is abandoned before the image exists, hibernation_snapshot() and create_image() resume the frozen devices with PMSG_RESTORE, the event of a kernel restored from an image: in_suspend is clear in both cases, and only the creating kernel with an image sets it. The cases are a device that fails to freeze, a wakeup event, the pm_test levels devices, platform and core, and a failure in the noirq phase before in_suspend is set. The hardware did not boot in any of them, but the drivers get their restore callbacks, run them for a state they cannot have, and some have to be told by pm_hibernate_is_restored() that nothing happened. Pick the event in one function: in_suspend set keeps what it was (PMSG_THAW, PMSG_RECOVER after an error); in_suspend clear is PMSG_RESTORE only when pm_hibernate_is_restored() says this kernel was restored, and PMSG_RECOVER otherwise, which is what the PM core sends after every other failed freeze (dpm_prepare() failing here, dpm_suspend_start()/end() through resume_event()). The restored flag is reset at the start of every hibernation_snapshot() and set right where the restored kernel leaves swsusp_arch_suspend(), before either resume call. What changes: only the calls of an abandoned hibernation, from the restore callbacks to the thaw callbacks (pm_op() maps PM_EVENT_RECOVER to the thaw callbacks as PM_EVENT_THAW), and, for a device with DPM_FLAG_MAY_SKIP_RESUME, dev_pm_skip_resume() now follows must_resume as it does for every other failed freeze. pm_hibernate_is_recovering() is now true there as well, as its documentation says. Nothing changes for a created image, a restored kernel or a test_resume, nor after a failed power-off in platform mode (PMSG_RESTORE from hibernation_platform_enter(); only ACPI sets platform hibernation ops). For the Apple drivers the abandoned case was already a thaw: every restore callback that checks the flag returns or forwards to its thaw (macsmc, the RTKit helper, apple-dart, sn201202x, DCP, NVMe, PCIe, cs42l84) or does nothing where there is no thaw (AOP, t6040 USB2 PHY, RTC, GPIO and SPMI early restores); PCIe's restore_noirq and thaw_noirq agree on the ports. So they now get the thaw directly. The checks in those callbacks stay for now. Signed-off-by: František Balázsy --- kernel/power/hibernate.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c index 4d3b30055fcb4..f771766758f0f 100644 --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c @@ -86,12 +86,12 @@ static bool hibernate_restored; /** * pm_hibernate_is_restored - Whether this kernel was just restored from an image. * - * Devices get PMSG_RESTORE both in the kernel restored from a hibernation image - * and in the kernel that hibernated when hibernation is aborted before the image - * is created (a device failed to freeze, a wakeup event). Only in the first case - * did the hardware go through a boot. True from the restore until the next - * hibernation starts (hibernation_snapshot()); meant for the restore callbacks - * and the PM_POST_HIBERNATION notifiers. + * Devices get PMSG_RESTORE in the kernel restored from a hibernation image, + * whose hardware went through a boot, and PMSG_RECOVER in the kernel that + * hibernated when hibernation is aborted before the image is created (a device + * failed to freeze, a wakeup event). True from the restore until the next + * hibernation starts (hibernation_snapshot()); meant for code that runs after + * the restore, such as the PM_POST_HIBERNATION notifiers. */ bool pm_hibernate_is_restored(void) { @@ -457,6 +457,25 @@ __weak int arch_resume_nosmt(void) return 0; } +/** + * hibernate_resume_event - Pick the event that resumes the devices frozen for an image. + * @error: Result of the image creation so far. + * + * Called once the image is created, restored or given up on. in_suspend is + * set only in the kernel that created the image, so a clear one means either + * that this kernel was restored from an image (devices get PMSG_RESTORE, + * their hardware went through a boot) or that the hibernation was aborted + * before the image existed (a device failed to freeze, a wakeup event, a + * pm_test level): the devices were only frozen, and the right event is + * PMSG_RECOVER, as after any other failed freeze. + */ +static pm_message_t hibernate_resume_event(int error) +{ + if (in_suspend) + return error ? PMSG_RECOVER : PMSG_THAW; + return pm_hibernate_is_restored() ? PMSG_RESTORE : PMSG_RECOVER; +} + /** * create_image - Create a hibernation image. * @platform_mode: Whether or not to use the platform driver. @@ -538,8 +557,7 @@ static int create_image(int platform_mode) Platform_finish: platform_finish(platform_mode); - dpm_resume_start(in_suspend ? - (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE); + dpm_resume_start(hibernate_resume_event(error)); return error; } @@ -605,7 +623,7 @@ int hibernation_snapshot(int platform_mode) if (error || !in_suspend) swsusp_free(); - msg = in_suspend ? (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE; + msg = hibernate_resume_event(error); dpm_resume(msg); if (error || !in_suspend) From cf056ccfcdc33fa9e69345562428d2aeebb5c594 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Bal=C3=A1zsy?= Date: Fri, 13 Nov 2026 15:58:52 +0100 Subject: [PATCH 49/49] soc: apple: rtkit: drop the restore callbacks' checks for an abandoned hibernation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The drivers/soc/apple/rtkit-helper.c part of "soc: apple: drop the restore callbacks' checks for an abandoned hibernation", which goes with the hibernation core changes; the rest of that commit is with the sleep controller changes. An abandoned hibernation resumed its devices with PMSG_RESTORE, so every restore callback that must not act on a state it never lost began with a pm_hibernate_is_restored() check, and most forwarded to their thaw. The PM core now sends PMSG_RECOVER there, which reaches the thaw callbacks, so the check and the forward go from macsmc, the RTKit helper, apple-dart, the sn201202x Type-C controller, the SPMI, GPIO and NVMe restore paths, both PCIe restore callbacks, the DCP and AOP restores, the t6040 USB2 PHY's two and the RTC; cs42l84's restore passes that the codec lost its state. Each callback runs for a restored kernel exactly as before. For an abandoned hibernation the old path was already the thaw or nothing, and the thaw now runs on its own: macsmc, the RTKit helper, apple-dart, sn201202x, NVMe and cs42l84 forwarded to the same function (cs42l84's resume asks pm_resume_via_firmware(), which hibernation_snapshot() has cleared); PCIe's restore_noirq did for a bridge without hibernation tunnelling what its thaw_noirq does, and the same call with it; the AOP, t6040, RTC, GPIO and SPMI restores did nothing and have no thaw. DCP keeps its power-off-failed branch (PMSG_RESTORE after a failed platform power-off, which only a platform with hibernation ops reaches) and loses the abandoned one, whose only other effect was a log line. One path changes: macsmc's thaw, after the SMC was handed over and the image could not be entered, calls apple_smc_restore() to start a new session, and its own check sent that back to the thaw, which did nothing. It now starts the session as the comment says it should. The flag keeps its other users, which are not restore callbacks: the AIC syscore resume, the dockchannel receive interrupt, the SEP's PM notifier. Signed-off-by: František Balázsy --- drivers/soc/apple/rtkit-helper.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/soc/apple/rtkit-helper.c b/drivers/soc/apple/rtkit-helper.c index 52ea34080b7f5..8c3d6d2f313d9 100644 --- a/drivers/soc/apple/rtkit-helper.c +++ b/drivers/soc/apple/rtkit-helper.c @@ -751,10 +751,6 @@ static int apple_rtkit_helper_restore(struct device *dev) struct apple_rtkit *old, *rtk; int count, live; - /* Hibernation aborted before the image (PMSG_RESTORE then too): nothing restarted. */ - if (!pm_hibernate_is_restored()) - return apple_rtkit_helper_thaw(dev); - if (!helper->adopted) return apple_rtkit_helper_restore_own(helper);