diff --git a/Documentation/devicetree/bindings/display/apple,dcp.yaml b/Documentation/devicetree/bindings/display/apple,dcp.yaml index 4e70062dde612..d4d30bbe11ed9 100644 --- a/Documentation/devicetree/bindings/display/apple,dcp.yaml +++ b/Documentation/devicetree/bindings/display/apple,dcp.yaml @@ -37,6 +37,7 @@ properties: - apple,t6041-dcpext - apple,t8122-dcpext - apple,t6050-dcpext + - apple,t8142-dcpext - const: apple,dcpext - items: - const: apple,t8140-dcpext @@ -636,7 +637,8 @@ allOf: properties: compatible: contains: - enum: ['apple,t6050-dcp', 'apple,t6050-dcpext', 'apple,t8142-dcp'] + enum: ['apple,t6050-dcp', 'apple,t6050-dcpext', + 'apple,t8142-dcp', 'apple,t8142-dcpext'] then: properties: clocks: @@ -654,7 +656,7 @@ allOf: properties: compatible: contains: - const: apple,t8142-dcp + enum: ['apple,t8142-dcp', 'apple,t8142-dcpext'] then: properties: clocks: diff --git a/Documentation/devicetree/bindings/display/apple,t8140-display-power.yaml b/Documentation/devicetree/bindings/display/apple,t8140-display-power.yaml index 41bd5586820f2..7d15745134267 100644 --- a/Documentation/devicetree/bindings/display/apple,t8140-display-power.yaml +++ b/Documentation/devicetree/bindings/display/apple,t8140-display-power.yaml @@ -4,7 +4,7 @@ $id: http://devicetree.org/schemas/display/apple,t8140-display-power.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: Apple T8140 display power words +title: Apple T8140 and T8142 display power words maintainers: - Diljit Singh @@ -17,25 +17,56 @@ description: properties: compatible: - const: apple,t8140-display-power + enum: + - apple,t8140-display-power + - apple,t8142-display-power reg: - items: - - description: the display PMC word that counts the powered coprocessors - - description: the power manager's power state words - - description: the power manager's power gate words + minItems: 2 + maxItems: 3 reg-names: - items: - - const: pmc-dcp - - const: ps - - const: pwrgate + minItems: 2 + maxItems: 3 required: - compatible - reg - reg-names +allOf: + - if: + properties: + compatible: + const: apple,t8140-display-power + then: + properties: + reg: + items: + - description: the display PMC word that counts the powered coprocessors + - description: the power manager's power state words + - description: the power manager's power gate words + reg-names: + items: + - const: pmc-dcp + - const: ps + - const: pwrgate + - if: + properties: + compatible: + const: apple,t8142-display-power + then: + # T8142's PMC keeps no count of the powered coprocessors: no pmc-dcp word. + properties: + reg: + items: + - description: the power manager's power gate words + - description: the power manager's power state words + reg-names: + items: + - const: pwrgate + - const: ps + additionalProperties: false examples: @@ -52,3 +83,16 @@ examples: reg-names = "pmc-dcp", "ps", "pwrgate"; }; }; + + - | + soc { + #address-cells = <2>; + #size-cells = <2>; + + display-power@380724000 { + compatible = "apple,t8142-display-power"; + reg = <0x3 0x80724000 0x0 0x2000>, + <0x3 0x80700000 0x0 0x14000>; + reg-names = "pwrgate", "ps"; + }; + }; diff --git a/Documentation/devicetree/bindings/gpu/apple,agx.yaml b/Documentation/devicetree/bindings/gpu/apple,agx.yaml index 10ca0ca54d9f6..7794c0e13b939 100644 --- a/Documentation/devicetree/bindings/gpu/apple,agx.yaml +++ b/Documentation/devicetree/bindings/gpu/apple,agx.yaml @@ -85,10 +85,11 @@ properties: Shared global variables, preserved firmware data or text segment of the loaded GPU firmware - description: Additional firmware crash-log data on T8142 + - description: Combined firmware text on T8142 memory-region-names: minItems: 3 - maxItems: 7 + maxItems: 8 apple,clpc: $ref: /schemas/types.yaml#/definitions/phandle @@ -595,6 +596,7 @@ allOf: - description: GFX coprocessor mailbox - description: GFX1 coprocessor mailbox memory-region: + minItems: 7 items: - description: GPU MMU TTBs - description: GPU MMU page tables @@ -603,7 +605,9 @@ allOf: - description: GFX firmware data - description: GFX1 firmware data - description: Combined firmware data and shared read-only crash logs + - description: Combined GFX and GFX1 firmware text memory-region-names: + minItems: 7 items: - const: ttbs - const: pagetables @@ -612,6 +616,18 @@ allOf: - const: gfx-data - const: gfx1-data - const: fw-data + - const: fw-text + oneOf: + - properties: + memory-region: + maxItems: 7 + memory-region-names: + maxItems: 7 + - properties: + memory-region: + minItems: 8 + memory-region-names: + minItems: 8 required: - reg-names - mboxes diff --git a/Documentation/devicetree/bindings/iommu/apple,dart.yaml b/Documentation/devicetree/bindings/iommu/apple,dart.yaml index 0cc59590ce0ed..6e7fdf9af5fdd 100644 --- a/Documentation/devicetree/bindings/iommu/apple,dart.yaml +++ b/Documentation/devicetree/bindings/iommu/apple,dart.yaml @@ -85,13 +85,15 @@ properties: Address filter (DAPF) registers, which restrict the physical addresses the DART lets its masters reach, or the slice of the fabric filter (GAPF) that protects the power state of the - coprocessor CPU behind this DART, cleared to power that CPU down + coprocessor CPU behind this DART, cleared to power that CPU down, + or the shared PS write-disable register that holds this DART's + bit for the same purpose (T8142) reg-names: minItems: 1 items: - const: dart - - enum: [dapf, gapf, auxiliary] + - enum: [dapf, gapf, ps-wr-dis, auxiliary] interrupts: maxItems: 1 @@ -234,6 +236,14 @@ properties: present and the word reads one of the two; otherwise it refuses the sleep. Set by the boot loader. + apple,ps-wr-dis-bit: + $ref: /schemas/types.yaml#/definitions/uint32 + maximum: 31 + description: > + This DART's bit in the ps-wr-dis register: set, the fabric rejects + writes to the power state of the coprocessor CPU behind it. Required + with a ps-wr-dis register; only that bit of the register is changed. + apple,manual-availability: type: boolean description: > diff --git a/Documentation/devicetree/bindings/phy/apple,atcphy.yaml b/Documentation/devicetree/bindings/phy/apple,atcphy.yaml index 6aeff7fff911e..41ecaccc8a0ae 100644 --- a/Documentation/devicetree/bindings/phy/apple,atcphy.yaml +++ b/Documentation/devicetree/bindings/phy/apple,atcphy.yaml @@ -36,6 +36,10 @@ description: > display crossbar is not part of the PHY resource. SuperSpeed calibration is supplied in banked lists so that no list spans that crossbar. + The T8142 variant adds an optional LIOA bank for DisplayPort calibration. + DisplayPort also requires separate bootloader-provided calibration lists + for that bank and the common configuration in the lpdptx region. + allOf: - $ref: /schemas/usb/usb-switch.yaml# - if: @@ -46,6 +50,7 @@ allOf: - apple,t8122-atcphy - apple,t6030-atcphy - apple,t6031-atcphy + - apple,t8142-atcphy then: properties: reg: @@ -56,6 +61,7 @@ allOf: - description: AXI to Apple Fabric interface - description: USB2 PHY - description: USB3 PIPE interface + - description: Local IO address translation controls (T8142) reg-names: minItems: 1 items: @@ -64,6 +70,7 @@ allOf: - const: axi2af - const: usb2phy - const: pipehandler + - const: lioa oneOf: - properties: reg: @@ -141,6 +148,23 @@ allOf: - const: pwrctl required: - power-domains + - if: + properties: + compatible: + contains: + const: apple,t8142-atcphy + then: + properties: + reg: + minItems: 5 + maxItems: 6 + reg-names: + minItems: 5 + maxItems: 6 + else: + properties: + apple,tunable-dp-lioa: false + apple,tunable-dp-common-config: false - if: properties: compatible: @@ -168,6 +192,7 @@ allOf: enum: - apple,t8132-atcphy - apple,t8140-atcphy + - apple,t8142-atcphy then: properties: reg: @@ -429,6 +454,18 @@ properties: Note that lane here refers to a USB RX and TX pair re-used for DisplayPort and not to an individual DisplayPort differential lane. + apple,tunable-dp-lioa: + $ref: "#/$defs/apple,tunable" + description: > + T8142 DisplayPort calibration for the lioa register region. Applied + after the common and lane tunables, before common configuration. + + apple,tunable-dp-common-config: + $ref: "#/$defs/apple,tunable" + description: > + T8142 DisplayPort common configuration for the lpdptx register region, + applied after the LIOA list. Both lists are required for DisplayPort. + apple,tunable-dp-common-pre: $ref: "#/$defs/apple,tunable" maxItems: 5461 diff --git a/Documentation/devicetree/bindings/soc/apple/apple,cluster-pwrgate.yaml b/Documentation/devicetree/bindings/soc/apple/apple,cluster-pwrgate.yaml index d9d39a5432022..43539cc51a6a3 100644 --- a/Documentation/devicetree/bindings/soc/apple/apple,cluster-pwrgate.yaml +++ b/Documentation/devicetree/bindings/soc/apple/apple,cluster-pwrgate.yaml @@ -23,6 +23,7 @@ properties: - apple,t6050-cluster-pwrgate - apple,t8132-cluster-pwrgate - apple,t8140-cluster-pwrgate + - apple,t8142-cluster-pwrgate - const: apple,cluster-pwrgate reg: diff --git a/Documentation/devicetree/bindings/soc/apple/apple,t8140-sleep.yaml b/Documentation/devicetree/bindings/soc/apple/apple,t8140-sleep.yaml index bdbe2a5ccadaf..25228d7c80251 100644 --- a/Documentation/devicetree/bindings/soc/apple/apple,t8140-sleep.yaml +++ b/Documentation/devicetree/bindings/soc/apple/apple,t8140-sleep.yaml @@ -21,14 +21,15 @@ properties: enum: - apple,t8132-sleep - apple,t8140-sleep + - apple,t8142-sleep reg: minItems: 25 - maxItems: 28 + maxItems: 41 reg-names: minItems: 25 - maxItems: 28 + maxItems: 41 apple,wake-enable: $ref: /schemas/types.yaml#/definitions/uint32-array @@ -36,6 +37,20 @@ properties: The wake source IDs left enabled across suspend-to-RAM. Every other source is masked. + apple,spmi-pmu-sources: + $ref: /schemas/types.yaml#/definitions/uint32-array + items: + - minimum: 0x600 + maximum: 0x61c + multipleOf: 4 + - minimum: 1 + description: | + Offset of a Gen4 SPMI peripheral interrupt status word and the mask of + PMU sources owned by the sleep controller. Only these latched sources + are acknowledged at entry and wake. On T8142 they are enabled after + programming the RTC alarm, with their prior enable state restored on + return. Other peripheral interrupt sources are left unchanged. + apple,apcie: $ref: /schemas/types.yaml#/definitions/phandle description: @@ -60,6 +75,23 @@ properties: description: The USB-C port controller that carries the debug link, stopped for a sleep. + apple,radio-host: + $ref: /schemas/types.yaml#/definitions/phandle + description: + The PCIe host of the radio's link, which the boot loader trained. Its root + port loses its configuration in a deep sleep and is trained again after + the wake. + + apple,radio-perst: + $ref: /schemas/types.yaml#/definitions/phandle-array + items: + - items: + - description: Phandle of the radio GPIO controller. + - description: Pin number. + - description: GPIO flags. + description: + The GPIO that drives the radio's PERST#, held across that retraining. + apple,display-coprocessors: $ref: /schemas/types.yaml#/definitions/phandle-array description: @@ -154,5 +186,71 @@ allOf: - const: clk-perf - const: cluster-dcs - const: ps-prot + - if: + properties: + compatible: + contains: + const: apple,t8142-sleep + then: + required: + - apple,wake-enable + properties: + reg: + minItems: 36 + maxItems: 41 + reg-names: + minItems: 36 + items: + - const: ps + - const: pwrgate + - const: cpu-start + - const: cllt + - const: cluster + - const: commit + - const: wdt + - const: aon-misc + - const: wake + - const: spmi + - const: ps-aon + - const: spmi-a0 + - const: pmc-voters + - const: clk-perf + - const: dcs + - const: acc-e + - const: acc-p + - const: amcc0 + - const: amcc1 + - const: amcc2 + - const: amcc3 + - const: socni0 + - const: socni1 + - const: socni2 + - const: socni3 + - const: socni4 + - const: socni5 + - const: mcc0 + - const: mcc1 + - const: mcc2 + - const: mcc3 + - const: mcc4 + - const: mcc5 + - const: mcc6 + - const: mcc7 + - const: mem-clk + - const: clk-slots + - const: amcc-cfg0 + - const: amcc-cfg1 + - const: amcc-cfg2 + - const: amcc-cfg3 + - if: + not: + properties: + compatible: + contains: + const: apple,t8142-sleep + then: + properties: + apple,radio-host: false + apple,radio-perst: false additionalProperties: false diff --git a/arch/arm64/boot/dts/apple/t8142-j813-dcpext.dtsi b/arch/arm64/boot/dts/apple/t8142-j813-dcpext.dtsi new file mode 100644 index 0000000000000..96c71b8c43d42 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8142-j813-dcpext.dtsi @@ -0,0 +1,313 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * External displays of the T8142 MacBook Airs (J813, J815): DisplayPort alt + * mode on the two USB-C ports. + * + * iBoot preloads both external display processors with the internal DCP's + * image and leaves them running idle. The boot loader checks each one and + * hands it over: it reserves the firmware, publishes its version and enables + * the processor, its mailbox, its DARTs and its Type-C route together. Until + * then everything here stays disabled and the ports are plain USB. + * + * dcpext0 serves the front port (ATC0), dcpext1 the rear port (ATC1): one + * processor per port, so two displays need no arbitration. Crossbar source + * numbers are twice the ADT dp-switch-ufp-endpoint (dcpext0 1, dcpext1 2). + * Addresses and interrupts are from the J815AP ADT (the J813AP 27.0 ADT is + * identical in every node used here); the bandwidth scratch + * slots are the /arm-io/pmgr bwr-agent indexes of DISP_EXT0 (3) and DISP_EXT1 + * (4) at 0x20000 + n * 0x4000. The T8142 topology follows the J704's. + */ + +/ { + aliases { + dcpext0 = &dcpext0; + dcpext1 = &dcpext1; + }; +}; + +&{/soc} { + pmgr_dcpext0: power-management@38272c000 { + reg = <3 0x8272c000 0 0x8>, <3 0x827b0000 0 0x4>; + reg-names = "dcp-bw-scratch", "dcp-bw-doorbell"; + #apple,bw-scratch-cells = <3>; + #apple,bw-doorbell-cells = <2>; + }; + + pmgr_dcpext1: power-management@382730000 { + reg = <3 0x82730000 0 0x8>, <3 0x827b4000 0 0x4>; + reg-names = "dcp-bw-scratch", "dcp-bw-doorbell"; + #apple,bw-scratch-cells = <3>; + #apple,bw-doorbell-cells = <2>; + }; + + dcpext0_mbox: mailbox@506e08000 { + compatible = "apple,t8142-asc-mailbox", "apple,asc-mailbox-v4"; + reg = <5 0x06e08000 0 0x4000>; + interrupts = , + , + , + ; + interrupt-names = "send-empty", "send-not-empty", + "recv-empty", "recv-not-empty"; + #mbox-cells = <0>; + status = "disabled"; + }; + + dcpext0: dcp@506e00000 { + compatible = "apple,t8142-dcpext", "apple,dcpext"; + reg = <5 0x06e00000 0 0x4000>, + <5 0x04000000 0 0xb1c000>, + <5 0x06240000 0 0x10000>, + <5 0x063ac000 0 0x4000>, + <5 0x06800000 0 0x800000>, + <3 0x82700000 0 0x114000>, + <5 0x06850000 0 0x4000>; + reg-names = "coproc", "disp-0", "disp-1", "disp-2", + "disp-3", "disp-4", "iop-vbar"; + mboxes = <&dcpext0_mbox>; + mbox-names = "mbox"; + iommus = <&dcpext0_dart 23>; + /* The firmware's clocks: /arm-io/dispext0 clock-ids, as on disp0. */ + apple,clock-ids = <369 432>; + clocks = <&clkref>, <&dcpext_fw_clk369>, <&dcpext_fw_clk432>; + clock-names = "clock-154", "firmware-0", "firmware-1"; + apple,bw-scratch = <&pmgr_dcpext0 0 5 0>; + apple,bw-doorbell = <&pmgr_dcpext0 1 6>; + apple,iomfb-surfaces = <0 0 1 0>; + apple,dcp-index = <1>; + apple,connector-type = "USB-C"; + apple,typec-dptx-phys = <0>; + apple,typec-mux-indices = <2>; + phys = <&atcphy0 PHY_TYPE_DP>; + phy-names = "typec0"; + mux-controls = <&dpxbar0 0>; + mux-control-names = "typec0"; + /* Enabled by the boot loader once it has checked the session. */ + status = "disabled"; + + piodma { + iommus = <&dispext0_dart 16>; + }; + + typec-routes { + #address-cells = <1>; + #size-cells = <0>; + + route@0 { + reg = <0>; + mode-switch; + status = "disabled"; + + port { + dcpext0_typec0: endpoint { + remote-endpoint = <&typec0_display>; + }; + }; + }; + }; + }; + + dcpext1_mbox: mailbox@3aae08000 { + compatible = "apple,t8142-asc-mailbox", "apple,asc-mailbox-v4"; + reg = <3 0xaae08000 0 0x4000>; + interrupts = , + , + , + ; + interrupt-names = "send-empty", "send-not-empty", + "recv-empty", "recv-not-empty"; + #mbox-cells = <0>; + status = "disabled"; + }; + + dcpext1: dcp@3aae00000 { + compatible = "apple,t8142-dcpext", "apple,dcpext"; + reg = <3 0xaae00000 0 0x4000>, + <3 0xa8000000 0 0xb1c000>, + <3 0xaa240000 0 0x10000>, + <3 0xaa3ac000 0 0x4000>, + <3 0xaa800000 0 0x800000>, + <3 0x82700000 0 0x114000>, + <3 0xaa850000 0 0x4000>; + reg-names = "coproc", "disp-0", "disp-1", "disp-2", + "disp-3", "disp-4", "iop-vbar"; + mboxes = <&dcpext1_mbox>; + mbox-names = "mbox"; + iommus = <&dcpext1_dart 23>; + /* The firmware's clocks: /arm-io/dispext1 clock-ids, as on disp0. */ + apple,clock-ids = <372 433>; + clocks = <&clkref>, <&dcpext_fw_clk372>, <&dcpext_fw_clk433>; + clock-names = "clock-154", "firmware-0", "firmware-1"; + apple,bw-scratch = <&pmgr_dcpext1 0 5 0>; + apple,bw-doorbell = <&pmgr_dcpext1 1 6>; + apple,iomfb-surfaces = <0 0 1 0>; + apple,dcp-index = <2>; + apple,connector-type = "USB-C"; + apple,typec-dptx-phys = <1>; + apple,typec-mux-indices = <4>; + phys = <&atcphy1 PHY_TYPE_DP>; + phy-names = "typec0"; + mux-controls = <&dpxbar1 0>; + mux-control-names = "typec0"; + /* Enabled by the boot loader once it has checked the session. */ + status = "disabled"; + + piodma { + iommus = <&dispext1_dart 16>; + }; + + typec-routes { + #address-cells = <1>; + #size-cells = <0>; + + route@0 { + reg = <0>; + mode-switch; + status = "disabled"; + + port { + dcpext1_typec1: endpoint { + remote-endpoint = <&typec1_display>; + }; + }; + }; + }; + }; + + /* Each ATC's display crossbar sits behind its PHY's core window. */ + dpxbar0: mux-controller@40304c000 { + compatible = "apple,t8142-display-crossbar"; + reg = <4 0x0304c000 0 0x4000>; + #mux-control-cells = <1>; + power-domains = <&ps_atc0_usb>; + }; + + dpxbar1: mux-controller@40b04c000 { + compatible = "apple,t8142-display-crossbar"; + reg = <4 0x0b04c000 0 0x4000>; + #mux-control-cells = <1>; + power-domains = <&ps_atc1_usb>; + }; +}; + +/* + * DisplayPort needs the LIOA bank (in the AXI2AF window) for the calibration + * the boot loader copies from the ADT. Without both, the PHY stays USB only. + */ +&atcphy0 { + reg = <4 0x03000000 0 0x4c000>, + <4 0x03050000 0 0x8000>, + <4 0x00000000 0 0x8000>, + <4 0x02a90000 0 0x4000>, + <4 0x02a84000 0 0x4000>, + <4 0x00020000 0 0x4000>; + reg-names = "core", "lpdptx", "axi2af", "usb2phy", "pipehandler", "lioa"; +}; + +&atcphy1 { + reg = <4 0x0b000000 0 0x4c000>, + <4 0x0b050000 0 0x8000>, + <4 0x08000000 0 0x8000>, + <4 0x0aa90000 0 0x4000>, + <4 0x0aa84000 0 0x4000>, + <4 0x08020000 0 0x4000>; + reg-names = "core", "lpdptx", "axi2af", "usb2phy", "pipehandler", "lioa"; +}; + +&typec0 { + ports { + port@3 { + reg = <3>; + + typec0_display: endpoint { + remote-endpoint = <&dcpext0_typec0>; + }; + }; + }; +}; + +&typec1 { + ports { + port@3 { + reg = <3>; + + typec1_display: endpoint { + remote-endpoint = <&dcpext1_typec1>; + }; + }; + }; +}; + +/* Scanout and PIODMA share the first register window, as on disp0. */ +&dispext0_dart { + reg = <5 0x06300000 0 0xc000>; + apple,dma-range = <0x100 0x0 0x10 0x0>; +}; + +&dcpext0_dart { + apple,dma-range = <0x100 0x0 0x10 0x0>; +}; + +&dispext1_dart { + reg = <3 0xaa300000 0 0xc000>; + apple,dma-range = <0x100 0x0 0x10 0x0>; +}; + +&dcpext1_dart { + apple,dma-range = <0x100 0x0 0x10 0x0>; +}; + +/ { + /* + * The external DCP firmware's clocks (/arm-io/dispext0 clock-ids 369 and + * 432, dispext1 372 and 433; the same on the J813 and the J815). Their + * rates are /arm-io clock-frequencies entries 0x71 and 0x74 (ids 0x100 + * up), as 712 MHz is entry 0x49 for disp0's 585: 300 MHz and + * 468.75 MHz. 432 and 433 have no entry, as disp0's 431 has none. + * Firmware 27 reads only the first one (see dcp_fw_clk585). + */ + dcpext_fw_clk369: clock-dcpext-firmware-369 { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <300000000>; + clock-output-names = "dcpext_firmware_369"; + }; + + dcpext_fw_clk432: clock-dcpext-firmware-432 { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <0>; + clock-output-names = "dcpext_firmware_432"; + }; + + dcpext_fw_clk372: clock-dcpext-firmware-372 { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <468750000>; + clock-output-names = "dcpext_firmware_372"; + }; + + dcpext_fw_clk433: clock-dcpext-firmware-433 { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <0>; + clock-output-names = "dcpext_firmware_433"; + }; +}; + +/* TEST: full firmware shutdown for J813 suspend-to-RAM. */ +&dcpext0 { apple,display-power = <&dcp_power>; }; +&dcpext1 { apple,display-power = <&dcp_power>; }; +&dcpext0_dart { + reg = <5 0x06340000 0 0x20000>, <3 0x80717fe8 0 4>; + reg-names = "dart", "ps-wr-dis"; + apple,ps-wr-dis-bit = <15>; +}; +&dcpext1_dart { + reg = <3 0xaa340000 0 0x20000>, <3 0x80717fec 0 4>; + reg-names = "dart", "ps-wr-dis"; + apple,ps-wr-dis-bit = <31>; +}; +&{/soc/sleep-controller@380700000} { + apple,display-coprocessors = <&dcp &dcpext0 &dcpext1>; +}; diff --git a/arch/arm64/boot/dts/apple/t8142-j813-j815-sleep.dtsi b/arch/arm64/boot/dts/apple/t8142-j813-j815-sleep.dtsi new file mode 100644 index 0000000000000..08df0f8f46787 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8142-j813-j815-sleep.dtsi @@ -0,0 +1,162 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * Suspend-to-RAM on the 13- and 15-inch M5 MacBook Air (J813, J815): the sleep controller, + * the shared PCIe block the wake brings back, and the port controllers' sleep power state. + * Included at the end of each board's device tree, after the nodes it refers to. + * + * The boot core's power gate (cluster_pwrgate) and the DCP DART's PS write-disable bit come + * with the board's own nodes (aurora-silicon/linux#1942, #1941). + */ + +#include + +/* + * Suspend-to-RAM (apple,t8142-sleep): derived from macOS 27.2.1 and T8132's measurements, and + * dry-run gated in the driver (apple_sleep.deep, apple_sleep.untested_commit). The J813 and J815 + * ADTs (27.0) differ only in audio, product and CLPC power-limit properties: every block, wake + * source, GPIO and PCIe window below is the same on both. + */ +&{/soc} { + /* + * Suspend-to-RAM. The blocks are T8132's, at the same J815 ADT indices: /arm-io/pmgr + * reg[32] (ps), [34] (pwrgate), [42] (cpu-start), [45] (cllt; EARLY_WAKEUP_CFG at + * +0x50), [36] (cluster), [40] + 0x4000 (commit), [38] (aon-misc), [4] (wake: nine mask + * and nine status words), [1] (ps-aon), /arm-io/wdt, nub-spmi0, nub-spmi-a0, the + * PMC's voter floors (as &pmc), and the SoC and DCS perf-state words that + * AppleT8142PMGR::setPerfState writes (reg[2] + 0x24000, + 0x25000). + * Derived from macOS 27.2.1 and T8132's measurements, never run on an M5: the driver + * stops each sleep at a dry run unless booted with apple_sleep.untested_commit=1, + * and deep sleep is only used when asked for (mem_sleep). + */ + sleep: sleep-controller@380700000 { + compatible = "apple,t8142-sleep"; + reg = <0x3 0x80700000 0x0 0x18000>, + <0x3 0x80724000 0x0 0x2000>, + <0x3 0x80734000 0x0 0x10>, + <0x3 0x80768000 0x0 0x54>, + <0x3 0x80780000 0x0 0x8>, + <0x3 0x882d4000 0x0 0x4>, + <0x3 0x882b0000 0x0 0x30>, + <0x3 0x882b8000 0x0 0x44>, + <0x3 0x88004000 0x0 0x50>, + /* SPMI gen 4: queue at +0x200..0x220, notify enable/ack +0x420/+0x620 */ + <0x3 0x88714000 0x0 0x1000>, + <0x3 0x88280000 0x0 0x10000>, + /* nub-spmi-a0's notify enable word (gen 4: +0x420; gen 1 had +0x40) */ + <0x3 0x88908420 0x0 0x4>, + <0x3 0x82700000 0x0 0x10000>, + <0x3 0x80024000 0x0 0x4>, + <0x3 0x80025000 0x0 0x4>, + /* + * Each complex's ACC word 0x40f8 (ADT pmgr reg[7] E, reg[18] P, + 0x40f8), + * which AppleT8142PMGR sets to 1 after the complex powers on and at the + * end of restoreHW. + */ + <0x2 0x10e440f8 0x0 0x4>, + <0x2 0x11e440f8 0x0 0x4>, + /* + * The memory side macOS steps down last (J813 trace, same ADT mcc layout + * on J815): each AMCC plane's +0x28000 word (mcc reg[1], planes 0x40000 + * apart), the six SoC NI tables (reg[2..7]), the eight DCS channels' + * words from +0x580 (reg[10..17]) and the clock word 0x380038000. + */ + <0x2 0x20028000 0x0 0x8>, + <0x2 0x20068000 0x0 0x8>, + <0x2 0x200a8000 0x0 0x8>, + <0x2 0x200e8000 0x0 0x8>, + <0x2 0x4f010000 0x0 0x104>, + <0x2 0x50010000 0x0 0x104>, + <0x2 0x51010000 0x0 0x104>, + <0x2 0x52010000 0x0 0x104>, + <0x2 0x53010000 0x0 0x104>, + <0x2 0x54010000 0x0 0x104>, + <0x2 0x21000580 0x0 0x104>, + <0x2 0x21200580 0x0 0x104>, + <0x2 0x21400580 0x0 0x104>, + <0x2 0x21600580 0x0 0x104>, + <0x2 0x21800580 0x0 0x104>, + <0x2 0x21a00580 0x0 0x104>, + <0x2 0x21c00580 0x0 0x104>, + <0x2 0x21e00580 0x0 0x104>, + <0x3 0x80038000 0x0 0x4>, + /* + * What the deep sleep loses and XNU restores at the wake (J813 ten-core + * trace, 2026-11-16): the PMGR clkgen's 126 slots (0x20 apart from + * 0x380038100) and each AMCC plane's control words (+0x2a000..+0x2e003). + * The SoC NI tables above reach their strobe word at +0x100. + */ + <0x3 0x80038100 0x0 0xfc0>, + <0x2 0x2002a000 0x0 0x4004>, + <0x2 0x2006a000 0x0 0x4004>, + <0x2 0x200aa000 0x0 0x4004>, + <0x2 0x200ea000 0x0 0x4004>; + reg-names = "ps", "pwrgate", "cpu-start", "cllt", "cluster", + "commit", "wdt", "aon-misc", "wake", "spmi", + "ps-aon", "spmi-a0", "pmc-voters", "clk-perf", "dcs", + "acc-e", "acc-p", + "amcc0", "amcc1", "amcc2", "amcc3", + "socni0", "socni1", "socni2", "socni3", "socni4", "socni5", + "mcc0", "mcc1", "mcc2", "mcc3", "mcc4", "mcc5", "mcc6", "mcc7", + "mem-clk", "clk-slots", + "amcc-cfg0", "amcc-cfg1", "amcc-cfg2", "amcc-cfg3"; + /* + * From the J815 ADT's /arm-io/pmgr ap-wake-sources, the same sources + * as T8132's by name: NUB.SPMI0.SW3, ATC0.USBWakeup, SMC.CPUWakeupAP, + * SMC.OutboxNotEmpty, MTP.DOCK.CHANNELS.AP0.IRQ and MTP.OutboxNotEmpty. + */ + apple,wake-enable = <152 72 168 190 89 108>; + /* + * The DCP, then the external DCPs once the tree describes them (dcpext0, dcpext1): + * the sleep lowers them with the display, and refuses while an undescribed one is up. + */ + apple,display-coprocessors = <&dcp>; + /* ANS's link's shared block, and the radio's link, which only aura trains */ + apple,apcie = <&apcie_shared>; + apple,radio-host = <&pcie0>; + /* ADT pci-bridge0 function-perst: AP GPIO 192 */ + apple,radio-perst = <&pinctrl_ap 192 GPIO_ACTIVE_LOW>; + apple,pinctrl = <&pinctrl_ap>; + /* The ADT's no-restore-gpio-pins: reading pin 78 raises an SError. */ + apple,pinctrl-skip-pins = <78 203>; + }; + + /* + * ANS's side of the shared PCIe block, which the sleep controller brings back after a + * real sleep in AppleT8142PCIe's order (as aura's j813_n1.c at boot): ADT /arm-io/apcie + * reg[1] (rc), [2] (phy-block; its PHY-PHY control words are reg[3], 0x20000 in), [4] + * (phy-ip) and [5] (axi2af, as far as its tables reach). Then the radio's port 0, which + * it trains again after the wake: reg[8] (radio-port), [10] (radio-lane) and the root + * port's configuration space (radio-cfg, the ECAM's first 4 KiB). reg[6] (clkgen, the + * pcieclkgen whose PLLs APCIECoreRCGen4 shuts down before the power goes; AppleT8142PCIe + * maps reg[7] as its AUS5 AON top, unused here). aura copies the ADT's + * apcie-{axi2af,phy,phy-ip-pll,phy-ip-auspma}-tunables and pci-bridge0's + * apcie-config-tunables and pcie-rc{,-gen3-shadow,-gen4-shadow}-tunables here. No + * driver binds it. + */ + apcie_shared: pcie-shared@48c000000 { + reg = <0x4 0x8c000000 0x0 0x4000>, + <0x4 0x8f000000 0x0 0x40000>, + <0x4 0x8f040000 0x0 0x20000>, + <0x4 0x8e000000 0x0 0x24000>, + <0x4 0x88028000 0x0 0x8000>, + <0x4 0x8f010000 0x0 0x4000>, + <0x1c 0xb0000000 0x0 0x1000>, + <0x4 0x8d044000 0x0 0x4000>; + reg-names = "rc", "phy-block", "phy-ip", "axi2af", + "radio-port", "radio-lane", "radio-cfg", "clkgen"; + }; +}; + +/* + * The port controllers' system power state (SSPS 3 before the commit, 0 at the wake), as + * macOS's AppleHPM sends it on the J700 and J714s, measured there on the same SN201202x; + * not traced on an M5 Air. Only a firmware-driven sleep sends it, and a controller that + * does not take S3 refuses the sleep (tipd sleep_s3_refuse). + */ +&hpm0 { + apple,sleep-ssps; +}; + +&hpm1 { + apple,sleep-ssps; +}; diff --git a/arch/arm64/boot/dts/apple/t8142-j813-sep.dtsi b/arch/arm64/boot/dts/apple/t8142-j813-sep.dtsi new file mode 100644 index 0000000000000..3429ee9661d60 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8142-j813-sep.dtsi @@ -0,0 +1,69 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * The J813's Secure Enclave, for the sleep: only its driver can ask it to sleep, which it + * has to before the SoC goes down (at macOS's commit its domain reads DEV_DISABLE, actual 0). + * From the J813 ADT: /arm-io/sep 0xfa600000 (+0x210000000), ascwrap v6, IRQs 445-448, + * dart-sep; PMGR SEP word +0xc00 (always on, the enclave gates it itself), GPIO +0x120. + */ + +/ { + aliases { + /* aura's dt_set_sep(): sepfw reserved, the boot-object manifests published */ + sep = &sep; + }; +}; + +&pmgr { + ps_gpio: power-controller@120 { + compatible = "apple,t8142-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x120 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "gpio"; + apple,always-on; + }; + + ps_sep: power-controller@c00 { + compatible = "apple,t8142-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xc00 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "sep"; + apple,always-on; + }; +}; + +&{/soc} { + sep: sep@30a600000 { + compatible = "apple,sep"; + reg = <0x3 0x0a600000 0x0 0x88000>; + mboxes = <&sep_mbox>; + mbox-names = "mbox"; + iommus = <&sep_dart 0>; + power-domains = <&ps_sep>, <&ps_gpio>; + }; + + sep_mbox: mailbox@30a608000 { + compatible = "apple,t8142-asc-mailbox", "apple,asc-mailbox-v4"; + reg = <0x3 0x0a608000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = , + , + , + ; + interrupt-names = "send-empty", "send-not-empty", + "recv-empty", "recv-not-empty"; + #mbox-cells = <0>; + }; +}; + +/* + * The SEP consumes the high IOVA on the wire, as in the ADT's vm-base-0. + * An offset on a low DMA window moves only the DART mapping, not the address + * sent in the shared-memory registration. Leave the DART disabled until + * apple-sep enables it (dt.rs), with this window already described. + */ +&sep_dart { + apple,dma-range = /bits/ 64 <0x10000004000 0xffff0000>; + apple,dma-offset = /bits/ 64 <0x0>; +}; diff --git a/arch/arm64/boot/dts/apple/t8142-j813.dts b/arch/arm64/boot/dts/apple/t8142-j813.dts index 2f7fe931cf295..c0b2d42c9dcc3 100644 --- a/arch/arm64/boot/dts/apple/t8142-j813.dts +++ b/arch/arm64/boot/dts/apple/t8142-j813.dts @@ -182,12 +182,69 @@ }; }; +/* + * N1 functions behind apcie port 0 (0000:00:00.0 -> 01:00.{0,1,2}), so the + * loader has somewhere to put the factory addresses: it copies ADT /chosen + * mac-address-wifi0 and mac-address-bluetooth0 into the wifi0/bluetooth0 + * alias targets. Same nodes as t8142-j815.dts (same N1, same PCI IDs). + */ +/ { + aliases { + wifi0 = &n1_alpha; + bluetooth0 = &n1_beta; + }; +}; + +&pcie0 { + n1_port: pci@0,0 { + device_type = "pci"; + reg = <0x0 0x0 0x0 0x0 0x0>; + bus-range = <1 1>; + #address-cells = <3>; + #size-cells = <2>; + ranges; + + n1_control: control@0,0 { + compatible = "apple,t8142-centauri-control", "pci106b,1900"; + reg = <0x10000 0x0 0x0 0x0 0x0>; + }; + + n1_alpha: wifi@0,1 { + compatible = "pci106b,1902"; + reg = <0x10100 0x0 0x0 0x0 0x0>; + /* Filled by the loader */ + local-mac-address = [00 00 00 00 00 00]; + }; + + n1_beta: bluetooth@0,2 { + compatible = "pci106b,1903"; + reg = <0x10200 0x0 0x0 0x0 0x0>; + /* Filled by the loader */ + local-bd-address = [00 00 00 00 00 00]; + }; + }; +}; + &mtp_hid { multi-touch { firmware-name = "apple/tpmtfw-j813.bin"; }; }; +&{/soc} { + /* + * The CPU clusters' power-gate enables, in /arm-io/pmgr reg[34]: E at + * +0x0 and P at +0x60, the offsets T8132 has and the two words + * AppleT8142PMGR's restoreHW sets. iBoot leaves P's clear, and the + * boot core (P core 0) then never powers down in WFI. + */ + cluster_pwrgate: power-gate@380724000 { + compatible = "apple,t8142-cluster-pwrgate", "apple,cluster-pwrgate"; + reg = <0x3 0x80724000 0x0 0x4>, + <0x3 0x80724060 0x0 0x4>; + }; +}; + /* * The video encoder, its two DARTs and the VENC power tree. The J813 ADT has * the same ave and dart-ave as the J815. The boot loader hands over iBoot's @@ -279,3 +336,64 @@ &ave { status = "okay"; }; + +#include "t8142-j813-sep.dtsi" +#include "t8142-j813-j815-sleep.dtsi" + +#include "t8142-j813-dcpext.dtsi" + +&sleep { + /* PMU RTC: peripheral source 2, routed through NUB.SPMI0.SW3. */ + apple,spmi-pmu-sources = <0x600 0x4>; +}; + +&{/soc} { + /* + * The internal display's power words for a DCP firmware stop (DPMS off): + * /arm-io/pmgr reg[34] (pwrgate: DISP_CPU's retention words 0x11cc and + * 0x11f0, the pmgr's retention_config_ff/_mem) and reg[32] (ps: DISP_CPU + * 0x10000, DISP_FE 0x318, DISP_SYS 0x290). T8142's PMC keeps no count of + * powered DCPs, so there is no pmc-dcp word. + */ + dcp_power: display-power@380724000 { + compatible = "apple,t8142-display-power"; + reg = <3 0x80724000 0 0x2000>, + <3 0x80700000 0 0x14000>; + reg-names = "pwrgate", "ps"; + }; +}; + +&dcp { + apple,display-power = <&dcp_power>; +}; + +&dcp_dart { + /* PMGR PS write-disable for DISP_CPU: offset 0x3fdc, bit 6. */ + reg = <2 0x86340000 0 0x20000>, + <3 0x80717fdc 0 0x4>; + reg-names = "dart", "ps-wr-dis"; + apple,ps-wr-dis-bit = <6>; +}; + +&{/reserved-memory} { + /* + * Both roles' __TEXT, contiguous (ADT gfx-asc and gfx1-asc segment-ranges), + * which the driver identifies before it starts the firmware. Fixed at the + * macOS 27.0 address like fw-data, until the bootloader fills it in; under + * 27.2 (26B123) iBoot loads it at 0x100_00e5_4000 and the DATA at + * 0x100_0245_8000. + */ + gpu_fw_text: fw-text { + reg = <0x100 0x00e44000 0x0 0x9c000>; + no-map; + }; +}; + +&gpu { + memory-region = <&uat_ttbs>, <&uat_pagetables>, <&uat_handoff>, + <&uat_l2_pagetables>, <&gfx_data>, <&gfx1_data>, + <&gpu_fw_data>, <&gpu_fw_text>; + memory-region-names = "ttbs", "pagetables", "handoff", + "shared-l2", "gfx-data", "gfx1-data", "fw-data", + "fw-text"; +}; diff --git a/arch/arm64/include/asm/cpu_ops.h b/arch/arm64/include/asm/cpu_ops.h index cecf75e5b3c24..0de73a0c7cefd 100644 --- a/arch/arm64/include/asm/cpu_ops.h +++ b/arch/arm64/include/asm/cpu_ops.h @@ -77,6 +77,8 @@ void spin_table_unhold_parked(void); int spin_table_stop_parked(void); void spin_table_release_stopped(void); void spin_table_release_cpus(const struct cpumask *cpus); +void spin_table_pen_deep_arm(bool on); +void spin_table_pen_deep_el1(bool on); void spin_table_stop_finished(void); bool spin_table_cpus_stuck(void); bool spin_table_cpu_tracked_off(unsigned int cpu); @@ -95,6 +97,8 @@ static inline int spin_table_stop_parked(void) static inline void spin_table_release_stopped(void) {} static inline void spin_table_release_cpus(const struct cpumask *cpus) {} +static inline void spin_table_pen_deep_arm(bool on) {} +static inline void spin_table_pen_deep_el1(bool on) {} static inline void spin_table_stop_finished(void) {} static inline int spin_table_set_power_ops(const struct spin_table_power_ops *ops) diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index a596a8d347183..f1ed960e10530 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -408,11 +408,48 @@ SYM_FUNC_START(secondary_holding_pen) mov_q x1, MPIDR_HWID_BITMASK and x2, x2, x1 adr_l x3, secondary_holding_pen_release + adr_l x6, secondary_pen_deep pen: ldr x4, [x3] cmp x4, x2 b.eq secondary_startup + ldr x5, [x6] + cbnz x5, 1f wfe b pen + /* + * Restarted after a system sleep's commit: the Apple deep-sleep bits, then WFI, as + * macOS's parked cores do. A core spinning here would keep its cluster from powering down. + */ +1: mrs_s x4, sys_reg(3, 5, 15, 6, 2) + orr x4, x4, #1 + orr x4, x4, #0x8000000000000000 + msr_s sys_reg(3, 5, 15, 6, 2), x4 + /* + * 2 = the sleep driver asked for the last WFI at EL1 (apple_sleep.el1_wfi=2): from EL2, + * MMU off (as here), every exception masked, no traps, stage 2 off, fast IPIs acked. + */ + cmp x5, #2 + b.ne 2f + mrs x4, CurrentEL + cmp x4, #CurrentEL_EL2 + b.ne 2f + mov x4, #1 + msr_s sys_reg(3, 5, 15, 1, 1), x4 + mov_q x4, INIT_SCTLR_EL1_MMU_OFF + msr_s SYS_SCTLR_EL12, x4 + isb + mov_q x4, (HCR_RW | HCR_E2H) + msr hcr_el2, x4 + mov x4, #(PSR_MODE_EL1h | PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT) + msr spsr_el2, x4 + adr x4, 2f + msr elr_el2, x4 + isb + eret +2: dsb sy + isb + wfi + b 2b SYM_FUNC_END(secondary_holding_pen) /* diff --git a/arch/arm64/kernel/smp_spin_table.c b/arch/arm64/kernel/smp_spin_table.c index df948fa43d8f0..e66806dbbf9c5 100644 --- a/arch/arm64/kernel/smp_spin_table.c +++ b/arch/arm64/kernel/smp_spin_table.c @@ -24,6 +24,13 @@ extern void secondary_holding_pen(void); volatile unsigned long __section(".mmuoff.data.read") secondary_holding_pen_release = INVALID_HWID; +/* + * Once set, after a sleep's commit, a core that the SoC restarts at its reset vector and that + * comes back to the holding pen takes the deep-sleep WFI there instead of spinning (head.S), + * as macOS's parked cores do. Read with the MMU off. + */ +volatile unsigned long __section(".mmuoff.data.read") secondary_pen_deep; + static phys_addr_t cpu_release_addr[NR_CPUS]; /* @@ -284,10 +291,33 @@ bool spin_table_cpu_tracked_off(unsigned int cpu) return cpumask_test_cpu(cpu, &spin_table_cpus_off); } +static bool spin_table_pen_deep_armed, spin_table_pen_el1_on; + +void spin_table_pen_deep_arm(bool on) +{ + spin_table_pen_deep_armed = on; +} + +/* The pen's last WFI at EL1 (2) instead of the kernel's EL (1), for the next release */ +void spin_table_pen_deep_el1(bool on) +{ + spin_table_pen_el1_on = on; +} + +static void spin_table_pen_deep_set(unsigned long on) +{ + void *start = (void *)&secondary_pen_deep; + + secondary_pen_deep = on; + dcache_clean_inval_poc((unsigned long)start, (unsigned long)start + sizeof(secondary_pen_deep)); +} + /* After the commit: the stopped CPUs take their last WFI. */ void spin_table_release_stopped(void) { WRITE_ONCE(spin_table_stop_released, true); + if (spin_table_pen_deep_armed) + spin_table_pen_deep_set(spin_table_pen_el1_on ? 2 : 1); dsb(ish); sev(); } @@ -298,6 +328,9 @@ void spin_table_release_stopped(void) */ void spin_table_stop_finished(void) { + /* Before any CPU is started again: the pen must let them boot. */ + if (secondary_pen_deep) + spin_table_pen_deep_set(0); WRITE_ONCE(spin_table_hold_requested, false); WRITE_ONCE(spin_table_stop_requested, false); WRITE_ONCE(spin_table_stop_released, false); @@ -316,12 +349,14 @@ 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_cpu(cpu, &spin_table_cpus_off)) { + /* + * Still off until it runs smp_rvbar_spin_table_postboot(): a start that times out + * leaves it here, so another online attempt pulses it again. + */ ret = spin_table_power->cpu_on(mpidr); - if (ret) { - cpumask_set_cpu(cpu, &spin_table_cpus_off); + if (ret) return ret; - } } else if (cpumask_test_cpu(cpu, &spin_table_cpus_parked)) { cpumask_set_cpu(cpu, &spin_table_cpus_unpark); } @@ -438,6 +473,7 @@ static int smp_rvbar_spin_table_cpu_kill(unsigned int cpu) static void smp_rvbar_spin_table_postboot(void) { + cpumask_clear_cpu(smp_processor_id(), &spin_table_cpus_off); if (READ_ONCE(spin_table_power) && spin_table_power->cpu_restore) spin_table_power->cpu_restore(read_cpuid_mpidr() & MPIDR_HWID_BITMASK); } diff --git a/drivers/bluetooth/btcentauri.c b/drivers/bluetooth/btcentauri.c index 84f9789f9a2bf..11bbc9d0cc6d1 100644 --- a/drivers/bluetooth/btcentauri.c +++ b/drivers/bluetooth/btcentauri.c @@ -137,6 +137,14 @@ struct cen_bt { u32 hrb_connection_events; u8 hrb_last_link_type; u32 scan_dup_rewritten, accept_list_hidden; + bool transport_paused, transport_sleep_sent; + /* MSI backed by a DMA buffer, outside the PCI core's IRQ allocation. */ + struct { + u32 lo, hi; + u16 flags, data; + u8 cap; + bool saved; + } sleep_msi; }; static u16 cen_tail(struct cen_bt *bt, u16 ring) @@ -539,7 +547,7 @@ static void cen_poll(struct work_struct *work) int budget = CEN_RX_SLOTS; mutex_lock(&bt->lock); - if (!bt->running) + if (!bt->running || bt->transport_paused) goto unlock; if (readl(bt->bar + 0x18) != 2 || readl(bt->bar) != 2) { /* Preserve already completed diagnostics after abort, without posting @@ -913,6 +921,11 @@ static int cen_status_show(struct seq_file *s, void *unused) readl(bt->bar + 0x18), readl(bt->bar), bt->running, bt->tx_head, cen_tail(bt, 1), bt->rx_head, cen_tail(bt, 7), skb_queue_len(&bt->txq)); + seq_printf(s, "peripheral_exec=%u peripheral_ipc=%u sleep_status=%u transport_paused=%u\n", + le32_to_cpu(READ_ONCE(*(__le32 *)(bt->arena + 0x68))), + le32_to_cpu(READ_ONCE(*(__le32 *)(bt->arena + 0x6c))), + le32_to_cpu(READ_ONCE(*(__le32 *)(bt->arena + 0x70))), + bt->transport_paused); seq_printf(s, "commands=%u events=%u tx_bytes=%u rx_bytes=%u tx_errors=%u rx_errors=%u\n", bt->hdev->stat.cmd_tx, bt->hdev->stat.evt_rx, bt->hdev->stat.byte_tx, bt->hdev->stat.byte_rx, @@ -1104,27 +1117,129 @@ static void cen_remove(struct pci_dev *pdev) * bus mastering off, and the next poll stopped the transport for good) and * the PCIe host powered. Polling pauses across the sleep. */ +/* + * 26B123 AirshipDK: Beta sleep_control is BAR0 + 0x1078. Host sleep + * writes 3 and waits for peripheral_info.sleep_status == 3; wake writes + * 0 and waits for status 0 (active) or 1 (device sleep). The peripheral + * info block is at context + 0x68, with sleep_status at +8. + * + * Qualified on J813 with the installed Linux firmware. + * All ring doorbells must stay paused until the wake acknowledgment. + */ +static u32 cen_sleep_status(struct cen_bt *bt) +{ + return le32_to_cpu(READ_ONCE(*(__le32 *)(bt->arena + 0x70))); +} + +static int cen_transport_state(struct cen_bt *bt, bool asleep) +{ + u32 status; + int ret; + + if (readl(bt->bar + 0x18) != 2 || readl(bt->bar) != 2) + return -EIO; + dma_wmb(); + writel(asleep ? 3 : 0, bt->bar + 0x1078); + ret = read_poll_timeout(cen_sleep_status, status, + asleep ? status == 3 : status <= 1, + 100, 2000000, false, bt); + dma_rmb(); + dev_dbg(&bt->pdev->dev, + "ACIPC host %s: ret=%d status=%u exec=%u ipc=%u\n", + asleep ? "sleep" : "wake", ret, status, + readl(bt->bar + 0x18), readl(bt->bar)); + return ret; +} + +static int cen_resume(struct device *dev); + static int cen_suspend(struct device *dev) { struct cen_bt *bt = pci_get_drvdata(to_pci_dev(dev)); + struct pci_dev *pdev = bt->pdev; + u16 flags; + int cap, ret; + mutex_lock(&bt->lock); + bt->transport_paused = true; + mutex_unlock(&bt->lock); cancel_delayed_work_sync(&bt->poll); + if (of_machine_is_compatible("apple,j813") && bt->ipc_requested) { + bt->transport_sleep_sent = true; + ret = cen_transport_state(bt, true); + if (ret) + goto undo; + } + bt->sleep_msi.saved = false; + cap = pci_find_capability(pdev, PCI_CAP_ID_MSI); + if (cap && !pdev->msi_enabled && + !pci_read_config_word(pdev, cap + PCI_MSI_FLAGS, &flags) && + (flags & PCI_MSI_FLAGS_ENABLE) && (flags & PCI_MSI_FLAGS_64BIT)) { + bt->sleep_msi.cap = cap; + bt->sleep_msi.flags = flags; + bt->sleep_msi.saved = + !pci_read_config_dword(pdev, cap + PCI_MSI_ADDRESS_LO, &bt->sleep_msi.lo) && + !pci_read_config_dword(pdev, cap + PCI_MSI_ADDRESS_HI, &bt->sleep_msi.hi) && + !pci_read_config_word(pdev, cap + PCI_MSI_DATA_64, &bt->sleep_msi.data); + } + dev_dbg(dev, "Beta suspend exec=%x ipc=%x fallback MSI saved=%d\n", + readl(bt->bar + 0x18), readl(bt->bar), bt->sleep_msi.saved); device_set_awake_path(dev); - return pci_save_state(to_pci_dev(dev)); + ret = pci_save_state(pdev); + if (!ret) + return 0; +undo: + cen_resume(dev); + return ret; +} + +static int cen_resume_noirq(struct device *dev) +{ + struct cen_bt *bt = pci_get_drvdata(to_pci_dev(dev)); + struct pci_dev *pdev = bt->pdev; + int cap = bt->sleep_msi.cap; + + dev_dbg(dev, "Beta noirq exec=%x ipc=%x fallback MSI saved=%d\n", + readl(bt->bar + 0x18), readl(bt->bar), bt->sleep_msi.saved); + /* + * PERST clears MSI. The PCI core only restores vectors it allocated; + * Centauri's DMA-backed MSI mailbox is programmed directly by the + * Control driver. Restore it before interrupts and polling resume. + */ + if (bt->sleep_msi.saved && !pdev->msi_enabled) { + pci_write_config_word(pdev, cap + PCI_MSI_FLAGS, + bt->sleep_msi.flags & ~PCI_MSI_FLAGS_ENABLE); + pci_write_config_dword(pdev, cap + PCI_MSI_ADDRESS_LO, bt->sleep_msi.lo); + pci_write_config_dword(pdev, cap + PCI_MSI_ADDRESS_HI, bt->sleep_msi.hi); + pci_write_config_word(pdev, cap + PCI_MSI_DATA_64, bt->sleep_msi.data); + pci_write_config_word(pdev, cap + PCI_MSI_FLAGS, bt->sleep_msi.flags); + } + return 0; } static int cen_resume(struct device *dev) { struct cen_bt *bt = pci_get_drvdata(to_pci_dev(dev)); + int ret; + if (bt->transport_sleep_sent) { + ret = cen_transport_state(bt, false); + if (ret) + return ret; + bt->transport_sleep_sent = false; + } mutex_lock(&bt->lock); + bt->transport_paused = false; if (bt->running) schedule_delayed_work(&bt->poll, 0); mutex_unlock(&bt->lock); return 0; } -static DEFINE_SIMPLE_DEV_PM_OPS(cen_pm_ops, cen_suspend, cen_resume); +static const struct dev_pm_ops cen_pm_ops = { + SYSTEM_SLEEP_PM_OPS(cen_suspend, cen_resume) + NOIRQ_SYSTEM_SLEEP_PM_OPS(NULL, cen_resume_noirq) +}; static const struct pci_device_id cen_ids[] = { { PCI_DEVICE(PCI_VENDOR_ID_APPLE, 0x1903) }, diff --git a/drivers/gpu/drm/apple/afk.c b/drivers/gpu/drm/apple/afk.c index b45857d3f8759..c081f57761543 100644 --- a/drivers/gpu/drm/apple/afk.c +++ b/drivers/gpu/drm/apple/afk.c @@ -1742,15 +1742,14 @@ static void afk_recv_handle_init(struct apple_dcp_afkep *ep, u32 channel, } if (ret == -ENOENT && (ep->dcp->hw.iomfb_method_profile == DCP_IOMFB_METHODS_H17G || + (ep->dcp->fw_compat == DCP_FIRMWARE_V_27_0 && + ep->dcp->hw.firmware_compat == DCP_FIRMWARE_H17P) || ep->dcp->v27_j714s || (ep->dcp->v27_sleep_transport && !strcmp(name, "md-manager")))) { /* - * M5 (H17G) announces powerlog-service with only - * ep-has-desc-mgr and interface-id, and firmware 27 - * its descriptor manager (md-manager) without EPIC - * keys; match them by the announced name, as for - * props-less announces. J716c admits only md-manager - * here; its normal service matching stays unchanged. + * H17G and firmware-27 T8142 can omit EPIC identity + * for powerlog-service. J716c's sleep transport + * admits only md-manager by name here. */ epic_name = NULL; epic_class = NULL; diff --git a/drivers/gpu/drm/apple/apple_drv.c b/drivers/gpu/drm/apple/apple_drv.c index 26a68a21734df..dddbacc0cf41a 100644 --- a/drivers/gpu/drm/apple/apple_drv.c +++ b/drivers/gpu/drm/apple/apple_drv.c @@ -394,6 +394,8 @@ static void apple_crtc_atomic_enable(struct drm_crtc *crtc, } if (crtc_state->active && (crtc_state->active_changed || dcp_crtc_needs_route_start(dcp))) { + /* The HPD of the link dcp_poweron() reconnects precedes our mode set. */ + WRITE_ONCE(dcp->typec_enable_pending, true); dcp_poweron(apple_crtc->dcp); crtc_state->color_mgmt_changed = true; } else if (crtc_state->active && drm_atomic_crtc_needs_modeset(crtc_state)) { @@ -408,6 +410,8 @@ static void apple_crtc_atomic_enable(struct drm_crtc *crtc, dcp_drm_crtc_error(apple_crtc, crtc_state, ret); } } + /* The mode set of the enable has run: a sink still without one has a bad link. */ + WRITE_ONCE(dcp->typec_enable_pending, false); dcp_typec_follow_done(locked); return; @@ -418,6 +422,7 @@ static void apple_crtc_atomic_enable(struct drm_crtc *crtc, dev_err(dcp->dev, "CRTC route unavailable (%d); modeset deferred\n", ret); /* Flush completes any pending flip without issuing a firmware swap. */ schedule_work(&dcp->vblank_wq); + WRITE_ONCE(dcp->typec_enable_pending, false); if (dcp->connector) dcp_route_failure_notify(dcp->connector); dcp_typec_follow_done(locked); diff --git a/drivers/gpu/drm/apple/dcp-fabric-test.c b/drivers/gpu/drm/apple/dcp-fabric-test.c index c10c4a0e1e500..254b1bb74358d 100644 --- a/drivers/gpu/drm/apple/dcp-fabric-test.c +++ b/drivers/gpu/drm/apple/dcp-fabric-test.c @@ -2447,6 +2447,32 @@ static void relink_unplug_test(struct kunit *test) KUNIT_EXPECT_TRUE(test, dcp_relink_unplug(&s, 7, relink_ms(t, 62000))); } +/* + * A sink attached while the outputs were off gets its link trained at the + * CRTC's first enable, minutes later: the window starts there, and the + * attachment keeps its retries. + */ +static void relink_first_enable_test(struct kunit *test) +{ + unsigned long t = 100000; + struct dcp_relink_state s; + unsigned int i; + + relink_fresh(&s, 5, t); + KUNIT_EXPECT_FALSE(test, dcp_relink_unplug(&s, 5, relink_ms(t, 137000))); + dcp_relink_link_up(&s, 5, relink_ms(t, 135000)); + KUNIT_EXPECT_TRUE(test, dcp_relink_unplug(&s, 5, relink_ms(t, 137000))); + dcp_relink_end(&s); + + /* no fresh budget: unlike a DPMS wake, the enable does not reset it */ + for (i = s.tries; i < DCP_RELINK_RETRIES; i++) { + KUNIT_EXPECT_TRUE(test, dcp_relink_unplug(&s, 5, relink_ms(t, 137000))); + dcp_relink_end(&s); + } + dcp_relink_link_up(&s, 5, relink_ms(t, 200000)); + KUNIT_EXPECT_FALSE(test, dcp_relink_unplug(&s, 5, relink_ms(t, 201000))); +} + /* One relink at a time; the replay keeps the retries of its attachment. */ static void relink_running_test(struct kunit *test) { @@ -2623,6 +2649,7 @@ static struct kunit_case fabric_tests[] = { KUNIT_CASE(fabric_t8132_clock_refused_test), KUNIT_CASE(fabric_t6050_merged_limit_test), KUNIT_CASE(relink_unplug_test), + KUNIT_CASE(relink_first_enable_test), KUNIT_CASE(relink_running_test), KUNIT_CASE(relink_budget_test), KUNIT_CASE(relink_disabled_test), diff --git a/drivers/gpu/drm/apple/dcp-fabric.c b/drivers/gpu/drm/apple/dcp-fabric.c index ff780bf537e09..150cd163924f1 100644 --- a/drivers/gpu/drm/apple/dcp-fabric.c +++ b/drivers/gpu/drm/apple/dcp-fabric.c @@ -1848,13 +1848,31 @@ static int dcp_typec_route_prepare(struct typec_mux_dev *mux, return 0; } +/* + * A T8142 external processor (firmware 27) behind a Type-C PHY of the T8122 + * generation: the firmware probes AUX as soon as its route is offered, so the + * route is applied only once the PHY has finished its own mode change. + */ +static bool dcp_t8142_ext(struct apple_dcp *dcp) +{ + return dcp->fw_compat == DCP_FIRMWARE_V_27_0 && + of_device_is_compatible(dcp->dev->of_node, "apple,t8142-dcpext"); +} + +static int dcp_typec_route_apply(struct typec_mux_dev *mux, + struct typec_mux_state *state); + static int dcp_typec_route_finish(struct typec_mux_dev *mux, struct typec_mux_state *state) { - struct apple_dcp_typec_port *port = - ((struct apple_dcp_typec_route *)typec_mux_get_drvdata(mux))->port; + struct apple_dcp_typec_route *route = typec_mux_get_drvdata(mux); + struct apple_dcp_typec_port *port = route->port; int ret; + /* Every provider's set phase (including the PHY) has completed. */ + if (dcp_t8142_ext(route->dcp) && state->mode != TYPEC_STATE_SAFE) + return dcp_typec_route_apply(mux, state); + guard(mutex)(&dcp_typec_fabric_lock); if (state->mode != TYPEC_STATE_SAFE || !port->safe_pending || port->safe_finish_ready) @@ -1911,8 +1929,8 @@ static int dcp_typec_port_busy(struct apple_dcp_typec_port *port, return -ENOSPC; } -static int dcp_typec_route_set(struct typec_mux_dev *mux, - struct typec_mux_state *state) +static int dcp_typec_route_apply(struct typec_mux_dev *mux, + struct typec_mux_state *state) { struct apple_dcp_typec_route *route = typec_mux_get_drvdata(mux); struct apple_dcp_typec_port *port = route->port; @@ -1997,7 +2015,8 @@ static int dcp_typec_route_set(struct typec_mux_dev *mux, * another port is refused as busy. The route is taken again * when HPD returns. */ - if (dcp->fw_compat == DCP_FIRMWARE_V_26_6_DESKTOP) { + if (dcp->fw_compat == DCP_FIRMWARE_V_26_6_DESKTOP || + dcp_t8142_ext(dcp)) { port->preferred_route = port->owner; port->hpd = false; /* @@ -2122,7 +2141,8 @@ static int dcp_typec_route_set(struct typec_mux_dev *mux, * would otherwise hold it against the port that has one. */ if (!port->owner && !hpd && - route->dcp->fw_compat == DCP_FIRMWARE_V_26_6_DESKTOP) { + (route->dcp->fw_compat == DCP_FIRMWARE_V_26_6_DESKTOP || + dcp_t8142_ext(route->dcp))) { port->applied_valid = true; return 0; } @@ -2190,6 +2210,16 @@ static int dcp_typec_route_set(struct typec_mux_dev *mux, return 0; } +static int dcp_typec_route_set(struct typec_mux_dev *mux, + struct typec_mux_state *state) +{ + struct apple_dcp_typec_route *route = typec_mux_get_drvdata(mux); + + if (dcp_t8142_ext(route->dcp) && state->mode != TYPEC_STATE_SAFE) + return 0; + return dcp_typec_route_apply(mux, state); +} + /* The T8142-layout crossbar (one per ATC on T6050) */ static bool dcp_xbar_t8142(struct mux_control *mux) { @@ -2535,6 +2565,25 @@ static int dcp_direct_crossbar_link_t6050(struct apple_dcp *dcp, bool up) * output's mux (or NULL on a Type-C-only pipeline). */ xbar = dcp->active_typec_route ? dcp->active_typec_route->active_xbar : dcp->xbar; + /* + * T8142's Type-C PHYs are of the T8122 generation and have no link + * report: they always drive PCLK1 with 8b/10b coding (as on the J704). + */ + if (dcp_t8142_ext(dcp)) { + if (dcp->dptx_tunnel || !xbar) + return 0; + if (!up) + return dcp_dpxbar_link(xbar, false); + configure = symbol_get(apple_dpxbar_link_configure); + if (!configure) + return -ENODEV; + ret = configure(xbar, 1, false); + symbol_put(apple_dpxbar_link_configure); + /* A link that is already up keeps its configuration. */ + if (ret == -EBUSY) + return 0; + return ret ? ret : dcp_dpxbar_link(xbar, true); + } if (dcp->dptx_tunnel || !dcp->phy || !xbar) return 0; get_config = symbol_get(apple_dp_phy_link_config); diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index a964be895b6ad..ea38c3fd64de7 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -227,6 +227,24 @@ struct dcp_panel { const struct dcp_color_space *color_target; }; +/* + * The internal display's power words for hw.s2r, see dcp_s2r_domains_off(): its domains' + * offsets in "ps", its retention controls in "pwrgate" (the PMGR's per-device "retention" + * words: flip-flops 3 off / 0 on, memories 0 off / 1 on), and the DART streams its firmware + * and scanout use. + */ +struct dcp_s2r_layout { + u32 disp_cpu; + u32 disp_fe; + u32 disp_sys; + u32 ret_ff; + u32 ret_mem; + u32 dcp_streams; + u32 disp_streams; + /* "pmc-dcp" counts the powered DCPs: T8132 and T8140 only */ + bool pmc_dcp; +}; + /* * Identity of a fixed internal panel, for the EDID published on its * connector. Any processor with an internal panel allocates it; the boot @@ -286,6 +304,17 @@ struct apple_dcp_hw_data { * every board but the one it has run on (dcp.c, dcp_j714s_ext()). */ bool link_report; + /* + * The endpoint the DPTX port services are announced on, where it is not + * the firmware's default (DPTX_ENDPOINT_V2 on firmware 27): the T8142 + * dcpext announces them on DPTX_ENDPOINT. 0: the default. + */ + u8 dptx_endpoint; + /* + * Open the DPTX controller endpoint before the ports, as for H17P + * externals: the T8142 dcpext announces AppleDCPDPTXController there. + */ + bool dptx_controller; /* * With H17P firmware: a firmware-driven system sleep stops the internal processor's * firmware and powers it down, as DPMS off does, then restarts it warm, see @@ -298,6 +327,15 @@ struct apple_dcp_hw_data { /* A firmware 27 sleep in progress, and how it ended */ bool v27_sleep_protocol; bool v27_sleep_recovery; + /* Required with @s2r */ + const struct dcp_s2r_layout *s2r_layout; + /* @s2r with derived power words: off unless appledrm.s2r_untested is set */ + bool s2r_untested; + /* + * @s2r without a secure mailbox: the SoC's ADT has no dcp-exclave-mailbox (T8142, on + * firmware 27.0 and 27.2.1), so there is no secure port to idle before the IOP. + */ + bool s2r_no_secure_port; }; enum dcp_test_point { @@ -983,6 +1021,8 @@ struct apple_dcp { u64 typec_follow_gen; /* dcp_poweron() reconnects DPTX; its own modeset follows the HPD */ bool typec_poweron_hpd; + /* A Type-C CRTC enable runs: its own mode set follows, the link is not bad */ + bool typec_enable_pending; /* IOMFB reports its video interface ready after DPTX link training. */ struct completion typec_iomfb_hpd_ready; struct delayed_work typec_reconnect_wq; diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index a95a285af3a85..7cde46e009096 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -290,13 +290,16 @@ static int dcp_secure_port_init(struct apple_dcp *dcp) * Stopping the firmware (DPMS off and system sleep with hw.s2r or hw.s2r_ext) powers the * display domains through apple,display-power, and the internal DCP only takes IOP idle * once its secure port has gone idle. A device tree without those keeps the firmware - * running: DPMS is the backlight alone and the display stays up across a sleep. + * running: DPMS is the backlight alone and the display stays up across a sleep. A SoC + * without a secure mailbox says so (hw.s2r_no_secure_port), and one behind + * appledrm.s2r_untested stops its firmware for DPMS off and J813 system sleep. */ static void dcp_s2r_check_dt(struct apple_dcp *dcp) { struct device_node *np = dcp->dev->of_node; bool power = of_property_present(np, "apple,display-power"); - bool secure = of_property_match_string(np, "mbox-names", "secure") >= 0; + bool secure = dcp->hw.s2r_no_secure_port || + of_property_match_string(np, "mbox-names", "secure") >= 0; if (dcp->hw.s2r && (!power || !secure)) { dev_info(dcp->dev, "no %s in the device tree, the firmware keeps running\n", @@ -307,6 +310,8 @@ static void dcp_s2r_check_dt(struct apple_dcp *dcp) dev_info(dcp->dev, "no apple,display-power in the device tree, the firmware keeps running\n"); dcp->hw.s2r_ext = false; } + if (dcp->hw.s2r && dcp->hw.s2r_untested) + dev_info(dcp->dev, "firmware stop enabled (appledrm.s2r_untested)\n"); } static void dcp_release_rtkit(void *data) @@ -469,6 +474,16 @@ static bool dcp_j714s_ext(struct device *dev) of_device_is_compatible(dev->of_node, "apple,t6050-dcpext"); } +/* + * The firmware stop on a SoC whose display power words were derived from its macOS device + * tree instead of measured (T8142). J813 supports DPMS off and system sleep with this + * opt-in. Off by default: such a DCP keeps its firmware running. + */ +static bool s2r_untested; +module_param(s2r_untested, bool, 0444); +MODULE_PARM_DESC(s2r_untested, + "Stop the DCP firmware on DPMS off and J813 system sleep using derived T8142 power words (default 0)"); + bool dcp_t6041_ext_enabled(void) { return t6041_dcpext; @@ -4652,7 +4667,8 @@ int dcp_start(struct platform_device *pdev) ret); if (dcp->hw.iomfb_method_profile == - DCP_IOMFB_METHODS_H17P_EXTERNAL || dcp_is_ext26(dcp)) { + DCP_IOMFB_METHODS_H17P_EXTERNAL || dcp_is_ext26(dcp) || + dcp->hw.dptx_controller) { ret = dptx_controller_init(dcp); if (ret) return dev_err_probe(dcp->dev, ret, @@ -5054,6 +5070,18 @@ void dcp_poweron(struct platform_device *pdev) dcp_relink_wake(&dcp->relink, READ_ONCE(dcp->typec_generation), jiffies); spin_unlock_irqrestore(&dcp->relink_lock, flags); + } else if (READ_ONCE(dcp->typec_cable_connected)) { + unsigned long flags; + + /* + * The first enable for a sink that was attached while the + * outputs were off: DCP trains its link only now. Time the + * relink window from here, keeping the attachment's retries. + */ + spin_lock_irqsave(&dcp->relink_lock, flags); + dcp_relink_link_up(&dcp->relink, + READ_ONCE(dcp->typec_generation), jiffies); + spin_unlock_irqrestore(&dcp->relink_lock, flags); } /* @@ -5788,11 +5816,12 @@ static enum dcp_firmware_version dcp_check_firmware_version(struct device *dev) * T8142 (J813) on macOS 27.0: the H17P interface written for its 26.x * firmware makes the 27.0 DCP firmware panic right after the first * hotplug ("ap_link: callback failed with: 0x5"). It runs the T6050's - * firmware-27 generation. + * firmware-27 generation, and so does 27.2, with the 27.2 method table. */ if (of_device_is_compatible(dev->of_node, "apple,t8142-dcp")) { ret = dcp_read_fw_version(dev, "apple,firmware-compat", compat_str); - if (ret >= 0 && !strcmp(compat_str, "27.0.0")) + if (ret >= 0 && (!strcmp(compat_str, "27.0.0") || + !strcmp(compat_str, "27.2.0"))) return DCP_FIRMWARE_V_27_0; } @@ -6538,7 +6567,7 @@ static void dcp_ext_give_up(struct apple_dcp *dcp, int err, const char *when); /* * The external processors whose failure must not take the DRM device down: - * T8122's, T6041's and T6050's dcpext. One that fails to probe or bind joins + * T8122's, T6041's, T6050's and T8142's dcpext. One that fails to probe or bind joins * as an unusable pipe (ext_dead), and the other displays go on without it. * With every processor failed the DRM device has no pipe and does not bind. */ @@ -6546,7 +6575,8 @@ static bool dcp_ext_is_failsafe(struct device_node *np) { return of_device_is_compatible(np, "apple,t8122-dcpext") || of_device_is_compatible(np, "apple,t6041-dcpext") || - of_device_is_compatible(np, "apple,t6050-dcpext"); + of_device_is_compatible(np, "apple,t6050-dcpext") || + of_device_is_compatible(np, "apple,t8142-dcpext"); } /* @@ -7056,6 +7086,14 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev) if (fw_compat == DCP_FIRMWARE_V_27_0 && of_device_is_compatible(dev->of_node, "apple,t8142-dcp")) dcp->hw.iomfb_method_profile = DCP_IOMFB_METHODS_DEFAULT; + /* + * A SoC with derived power words is offered the stop only when asked for, and only on + * firmware 27.0, whose calls are the ones that ran with them. + */ + if (dcp->hw.s2r && (!dcp->hw.s2r_layout || + (dcp->hw.s2r_untested && + (!s2r_untested || fw_compat != DCP_FIRMWARE_V_27_0)))) + dcp->hw.s2r = false; dcp->v27_sleep_transport = dcp_v27_sleep_transport_supported(dcp); /* The display such a processor finds at boot is its first sink. */ if (dcp_sink_metadata(dcp)) @@ -7098,6 +7136,9 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev) dcp->fixed_connector_type = dcp_connector_type_from_dt(dev->of_node); dcp->connector_type = dcp->fixed_connector_type; of_property_read_u32(dev->of_node, "apple,dcp-index", &dcp->index); + if (of_device_is_compatible(dev->of_node, "apple,t8142-dcpext") && + (dcp->index < 1 || dcp->index > 2)) + return dev_err_probe(dev, -EINVAL, "invalid external display index\n"); of_property_read_u32(dev->of_node, "apple,dcp-endpoint", &dcp->peer_endpoint); if (of_property_read_bool(dev->of_node, "apple,typec-hybrid-first")) dcp_typec_hybrid_first_dt(); @@ -7959,9 +8000,58 @@ static void dcp_platform_complete(struct device *dev) * The firmware takes IOP idle only with its secure mailbox answered, see * dcp_s2r_answer_secure_port(). */ -#define DCP_S2R_DISP_STREAMS (BIT(0) | BIT(3) | BIT(4) | BIT(16)) -#define DCP_S2R_DCP_STREAMS (BIT(23) | BIT(24)) #define DCP_S2R_D572_TIMEOUT_MS 1000 /* macOS: about 170 ms after A473(0) */ + +/* T8140's, measured. Its DCPEXT uses the same DCP streams. */ +static const struct dcp_s2r_layout dcp_s2r_t8140 = { + .disp_cpu = 0x10000, + .disp_fe = 0x318, + .disp_sys = 0x280, + .ret_ff = 0xc8c, + .ret_mem = 0xcd0, + .dcp_streams = BIT(23) | BIT(24), + .disp_streams = BIT(0) | BIT(3) | BIT(4) | BIT(16), + .pmc_dcp = true, +}; + +/* + * T8142's, derived from macOS 27.2.1 and run for DPMS off on a J813: the domains + * from the ADT's PMGR devices (DISP_SYS moved to 0x290), the retention words from the + * pmgr's retention_config_ff/_mem for DISP_CPU (device 0xb7), which ApplePMGR's + * _setPwrGateRetention writes into PMGR_SOC_PWRGATE with the same values T8140 measured, + * and the streams from dart-dcp's sid 23 + vm-base-24 and dart-disp0's sids 0 and 16 (no + * exclave streams). AppleT8142PMC has no count of powered DCPs: no pmc-dcp. + */ +static const struct dcp_s2r_layout dcp_s2r_t8142 = { + .disp_cpu = 0x10000, + .disp_fe = 0x318, + .disp_sys = 0x290, + .ret_ff = 0x11cc, + .ret_mem = 0x11f0, + .dcp_streams = BIT(23) | BIT(24), + .disp_streams = BIT(0) | BIT(16), + .pmc_dcp = false, +}; + +/* TEST: J813 external processors, ADT DISPEXT0/1 power words. */ +static const struct dcp_s2r_layout dcp_s2r_t8142_ext[] = { + { .disp_cpu = 0x428, .disp_fe = 0x418, .disp_sys = 0x308, + .dcp_streams = BIT(23) | BIT(24), .disp_streams = BIT(0) | BIT(16) }, + { .disp_cpu = 0x3b8, .disp_fe = 0x3a8, .disp_sys = 0x2b8, + .dcp_streams = BIT(23) | BIT(24), .disp_streams = BIT(0) | BIT(16) }, +}; + +static bool dcp_s2r_is_t8142_ext(struct apple_dcp *dcp) +{ + return of_device_is_compatible(dcp->dev->of_node, "apple,t8142-dcpext"); +} + +static const struct dcp_s2r_layout *dcp_s2r_layout(struct apple_dcp *dcp) +{ + if (dcp_s2r_is_t8142_ext(dcp)) + return &dcp_s2r_t8142_ext[dcp->index - 1]; + return dcp->hw.s2r_layout ?: &dcp_s2r_t8140; +} #define DCP_PS_MIN GENMASK(19, 16) static struct device *dcp_s2r_find_dart(struct device_node *np) @@ -8008,13 +8098,37 @@ void dcp_s2r_dart_power(struct apple_dcp *dcp, u32 on) return; if (dcp->s2r_disp_dart) - apple_dart_display_streams(dcp->s2r_disp_dart, DCP_S2R_DISP_STREAMS, on, false); + apple_dart_display_streams(dcp->s2r_disp_dart, dcp_s2r_layout(dcp)->disp_streams, + on, false); complete(&dcp->s2r_dart_done); } static bool dcp_s2r_capable(struct apple_dcp *dcp) { - return dcp->fw_compat == DCP_FIRMWARE_H17P && dcp->hw.s2r; + /* + * Firmware 27.2 and 27.3 run as V_27_0 with their own tables, which have no tag for the + * AP link's release (27.2 moved it to A550): an empty tag panics the firmware. + */ + if (dcp->fw_compat == DCP_FIRMWARE_V_27_0 && + (!dcp->v27_methods || !dcp->v27_methods[dcpep_unnamed_500].tag[0])) + return false; + return (dcp->fw_compat == DCP_FIRMWARE_H17P || dcp->fw_compat == DCP_FIRMWARE_V_27_0) && + dcp->hw.s2r; +} + +/* The same calls on 27.0, under their own tags (A484, A500, ...): iomfb_v27.c. */ +static int dcp_s2r_power(struct apple_dcp *dcp, bool on, bool named_calls, bool oob) +{ + if (dcp->fw_compat == DCP_FIRMWARE_V_27_0) + return iomfb_s2r_power_v27(dcp, on, named_calls, oob); + return iomfb_s2r_power_h17p(dcp, on, named_calls, oob); +} + +static int dcp_s2r_500(struct apple_dcp *dcp) +{ + if (dcp->fw_compat == DCP_FIRMWARE_V_27_0) + return iomfb_s2r_500_v27(dcp); + return iomfb_s2r_500_h17p(dcp); } static void dcp_s2r_cpu_stop(struct apple_dcp *dcp) @@ -8071,7 +8185,7 @@ static int dcp_s2r_quiesce(struct apple_dcp *dcp, u32 *status) } /* In band, 3 of 3 on macOS. */ - ret = iomfb_s2r_power_h17p(dcp, false, true, false); + ret = dcp_s2r_power(dcp, false, true, false); if (ret) { dev_err(dcp->dev, "no reply to set_power_state(0): %d\n", ret); goto err; @@ -8096,7 +8210,7 @@ static int dcp_s2r_quiesce(struct apple_dcp *dcp, u32 *status) if (read_poll_timeout(iomfb_channels_idle, idle, idle, 1000, 100000, false, dcp)) dev_warn(dcp->dev, "firmware calls still in flight before A500\n"); - ret = iomfb_s2r_500_h17p(dcp); + ret = dcp_s2r_500(dcp); if (ret) { dev_err(dcp->dev, "no reply to A500: %d\n", ret); goto err; @@ -8169,7 +8283,8 @@ static int dcp_s2r_stop_streams(struct apple_dcp *dcp) if (!dcp->s2r_dcp_dart) return -ENODEV; - return apple_dart_display_streams(dcp->s2r_dcp_dart, DCP_S2R_DCP_STREAMS, false, true); + return apple_dart_display_streams(dcp->s2r_dcp_dart, dcp_s2r_layout(dcp)->dcp_streams, + false, true); } static int dcp_s2r_stop_firmware(struct apple_dcp *dcp) @@ -8204,6 +8319,9 @@ static int dcp_s2r_stop_firmware(struct apple_dcp *dcp) */ static bool dcp_s2r_ext_capable(struct apple_dcp *dcp) { + if (dcp->fw_compat == DCP_FIRMWARE_V_27_0) + return dcp->hw.s2r_ext && s2r_untested && dcp->v27_methods && + dcp->v27_methods[dcpep_unnamed_500].tag[0]; return dcp->fw_compat == DCP_FIRMWARE_H17P && dcp->hw.s2r_ext; } @@ -8338,7 +8456,7 @@ static int dcp_s2r_ext_suspend(struct apple_dcp *dcp) /* The display's link went above: its crossbar output follows, as on macOS. */ dcp_typec_route_park(dcp); - ret = iomfb_s2r_500_h17p(dcp); + ret = dcp_s2r_500(dcp); if (ret) { dev_err(dcp->dev, "no reply to A500: %d\n", ret); WRITE_ONCE(dcp->crashed, true); @@ -8441,40 +8559,57 @@ static void dcp_s2r_ps_lower(void __iomem *reg) writel((val & ~GENMASK(3, 0)) | GENMASK(9, 8), reg); } -/* macOS's power-off, measured 3 of 3. The firmware is stopped and its DARTs are off. */ -static int dcp_s2r_domains_off(struct apple_dcp *dcp) +/* Its display-power words, pmc-dcp only where the layout has one. */ +static int dcp_s2r_map_power(struct apple_dcp *dcp, void __iomem **ps, void __iomem **pwrgate, + void __iomem **pmc) { struct device_node *np; - void __iomem *ps = NULL, *pwrgate = NULL, *pmc = NULL; - u32 val; - int ret = -ENODEV; - dcp->s2r_domains_up = false; + *ps = *pwrgate = *pmc = NULL; np = of_parse_phandle(dcp->dev->of_node, "apple,display-power", 0); if (!np) return -ENODEV; - ps = of_iomap(np, of_property_match_string(np, "reg-names", "ps")); - pwrgate = of_iomap(np, of_property_match_string(np, "reg-names", "pwrgate")); - pmc = of_iomap(np, of_property_match_string(np, "reg-names", "pmc-dcp")); + *ps = of_iomap(np, of_property_match_string(np, "reg-names", "ps")); + *pwrgate = of_iomap(np, of_property_match_string(np, "reg-names", "pwrgate")); + if (dcp_s2r_layout(dcp)->pmc_dcp) + *pmc = of_iomap(np, of_property_match_string(np, "reg-names", "pmc-dcp")); of_node_put(np); - if (!ps || !pwrgate || !pmc) + + return *ps && *pwrgate && (*pmc || !dcp_s2r_layout(dcp)->pmc_dcp) ? 0 : -ENODEV; +} + +/* macOS's power-off, measured 3 of 3 on T8140. The firmware is stopped and its DARTs are off. */ +static int dcp_s2r_domains_off(struct apple_dcp *dcp) +{ + const struct dcp_s2r_layout *l = dcp_s2r_layout(dcp); + void __iomem *ps, *pwrgate, *pmc; + u32 val; + int ret; + + dcp->s2r_domains_up = false; + ret = dcp_s2r_map_power(dcp, &ps, &pwrgate, &pmc); + if (ret) goto out; - dcp_pmc_set(dcp, pmc, false); - val = readl(ps + 0x10000); + if (pmc) + dcp_pmc_set(dcp, pmc, false); + val = readl(ps + l->disp_cpu); if (val & BIT(28)) - writel(val & ~(BIT(28) | GENMASK(9, 8)), ps + 0x10000); - writel(3, pwrgate + 0xc8c); - writel(0, pwrgate + 0xcd0); - dcp_s2r_ps_lower(ps + 0x10000); - dcp_s2r_ps_lower(ps + 0x318); - dcp_s2r_ps_lower(ps + 0x280); - - ret = readl_poll_timeout(ps + 0x10000, val, !FIELD_GET(GENMASK(7, 4), val), 100, 50000); + writel(val & ~(BIT(28) | GENMASK(9, 8)), ps + l->disp_cpu); + if (l->ret_ff) { + writel(3, pwrgate + l->ret_ff); + writel(0, pwrgate + l->ret_mem); + } + dcp_s2r_ps_lower(ps + l->disp_cpu); + dcp_s2r_ps_lower(ps + l->disp_fe); + dcp_s2r_ps_lower(ps + l->disp_sys); + + ret = readl_poll_timeout(ps + l->disp_cpu, val, !FIELD_GET(GENMASK(7, 4), val), 100, + 50000); if (ret) dev_err(dcp->dev, "DISP_CPU did not power off: %#x\n", val); - dev_dbg(dcp->dev, "display domains off: CPU %#x FE %#x SYS %#x\n", readl(ps + 0x10000), - readl(ps + 0x318), readl(ps + 0x280)); + dev_dbg(dcp->dev, "display domains off: CPU %#x FE %#x SYS %#x\n", + readl(ps + l->disp_cpu), readl(ps + l->disp_fe), readl(ps + l->disp_sys)); out: if (ps) iounmap(ps); @@ -8492,34 +8627,36 @@ static int dcp_s2r_domains_off(struct apple_dcp *dcp) */ static int dcp_s2r_domains_on(struct apple_dcp *dcp) { - struct device_node *np; - void __iomem *ps = NULL, *pwrgate = NULL, *pmc = NULL; + const struct dcp_s2r_layout *l = dcp_s2r_layout(dcp); + void __iomem *ps, *pwrgate, *pmc; u32 val; - int ret = -ENODEV; + int ret; - np = of_parse_phandle(dcp->dev->of_node, "apple,display-power", 0); - if (!np) - return -ENODEV; - ps = of_iomap(np, of_property_match_string(np, "reg-names", "ps")); - pwrgate = of_iomap(np, of_property_match_string(np, "reg-names", "pwrgate")); - pmc = of_iomap(np, of_property_match_string(np, "reg-names", "pmc-dcp")); - of_node_put(np); - if (!ps || !pwrgate || !pmc) + ret = dcp_s2r_map_power(dcp, &ps, &pwrgate, &pmc); + if (ret) goto out; - val = readl(ps + 0x280) & ~(GENMASK(9, 8) | GENMASK(3, 0) | BIT(28)); - writel(val | 0xf, ps + 0x280); - writel(val | 0xf | BIT(28), ps + 0x280); - val = readl(ps + 0x318) & ~(GENMASK(9, 8) | GENMASK(3, 0)); - writel(val | 0xf, ps + 0x318); - val = readl(ps + 0x10000) & ~(GENMASK(9, 8) | GENMASK(3, 0) | BIT(28)); - writel(val | 0xf, ps + 0x10000); - writel(0, pwrgate + 0xc8c); - writel(1, pwrgate + 0xcd0); - writel(val | 0xf | BIT(28), ps + 0x10000); - dcp_pmc_set(dcp, pmc, true); - - ret = readl_poll_timeout(ps + 0x10000, val, FIELD_GET(GENMASK(7, 4), val) == 0xf, + val = readl(ps + l->disp_sys) & ~(GENMASK(9, 8) | GENMASK(3, 0) | BIT(28)); + writel(val | 0xf, ps + l->disp_sys); + writel(val | 0xf | BIT(28), ps + l->disp_sys); + val = readl(ps + l->disp_fe) & ~(GENMASK(9, 8) | GENMASK(3, 0)); + writel(val | 0xf, ps + l->disp_fe); + val = readl(ps + l->disp_cpu) & ~(GENMASK(9, 8) | GENMASK(3, 0) | BIT(28)); + if (dcp_s2r_is_t8142_ext(dcp)) { + /* Retain the CPU when idle, as in the measured J813 wake sequence. */ + val = (val & ~DCP_PS_MIN) | FIELD_PREP(DCP_PS_MIN, 4); + writel(val, ps + l->disp_cpu); + } + writel(val | 0xf, ps + l->disp_cpu); + if (l->ret_ff) { + writel(0, pwrgate + l->ret_ff); + writel(1, pwrgate + l->ret_mem); + } + writel(val | 0xf | BIT(28), ps + l->disp_cpu); + if (pmc) + dcp_pmc_set(dcp, pmc, true); + + ret = readl_poll_timeout(ps + l->disp_cpu, val, FIELD_GET(GENMASK(7, 4), val) == 0xf, 100, 50000); if (ret) dev_err(dcp->dev, "DISP_CPU did not power on: %#x\n", val); @@ -8548,6 +8685,9 @@ static int dcp_s2r_ext_domains_on(struct apple_dcp *dcp) u32 val; int i, ret = -ENODEV; + if (dcp_s2r_is_t8142_ext(dcp)) + return dcp_s2r_domains_on(dcp); + np = of_parse_phandle(dcp->dev->of_node, "apple,display-power", 0); if (!np) return -ENODEV; @@ -8617,7 +8757,8 @@ static int dcp_s2r_ext_start(struct apple_dcp *dcp, bool cycled) if (ret) return ret; /* After the domains, whose writes it would reject, the DART protects them again. */ - apple_dart_display_streams(dcp->s2r_dcp_dart, DCP_S2R_DCP_STREAMS, true, false); + apple_dart_display_streams(dcp->s2r_dcp_dart, dcp_s2r_layout(dcp)->dcp_streams, true, + false); if (!cycled) return apple_rtkit_sleep_return(dcp->rtk, control); @@ -8641,6 +8782,9 @@ static int dcp_s2r_ext_domains_off(struct apple_dcp *dcp) int i, ret = -ENODEV; u32 val; + if (dcp_s2r_is_t8142_ext(dcp)) + return dcp_s2r_domains_off(dcp); + np = of_parse_phandle(dcp->dev->of_node, "apple,display-power", 0); if (!np) return -ENODEV; @@ -8697,7 +8841,8 @@ static bool dcp_s2r_ext_cpu_on(struct apple_dcp *dcp) of_node_put(np); if (!ps) return false; - on = FIELD_GET(GENMASK(7, 4), readl(ps + 0x328)); + on = FIELD_GET(GENMASK(7, 4), readl(ps + (dcp_s2r_is_t8142_ext(dcp) ? + dcp_s2r_layout(dcp)->disp_cpu : 0x328))); iounmap(ps); return on; @@ -8758,7 +8903,8 @@ static int dcp_s2r_warm_restart(struct apple_dcp *dcp) /* After the domains, whose writes it would reject, the DART protects them again. */ if (dcp->s2r_dcp_dart) - apple_dart_display_streams(dcp->s2r_dcp_dart, DCP_S2R_DCP_STREAMS, true, false); + apple_dart_display_streams(dcp->s2r_dcp_dart, dcp_s2r_layout(dcp)->dcp_streams, + true, false); if (dcp->secure_rtk) { dcp_secure_poll_stop(dcp); @@ -8813,7 +8959,7 @@ static int dcp_s2r_display_on(struct apple_dcp *dcp) WRITE_ONCE(dcp->s2r_active, true); /* Out of band; either channel answered on macOS. */ - ret = iomfb_s2r_power_h17p(dcp, true, true, true); + ret = dcp_s2r_power(dcp, true, true, true); if (ret) { dev_err(dcp->dev, "no reply to set_power_state(1): %d\n", ret); goto out; @@ -9061,7 +9207,7 @@ static void dcp_s2r_light_running(struct apple_dcp *dcp) dcp_s2r_find_darts(dcp); reinit_completion(&dcp->s2r_dart_done); WRITE_ONCE(dcp->s2r_active, true); - ret = iomfb_s2r_power_h17p(dcp, true, true, true); + ret = dcp_s2r_power(dcp, true, true, true); if (!ret && !wait_for_completion_timeout(&dcp->s2r_dart_done, msecs_to_jiffies(DCP_S2R_D572_TIMEOUT_MS))) dev_warn(dcp->dev, "no D572 after set_power_state(1), scanout DART left off\n"); @@ -9250,7 +9396,13 @@ static int dcp_platform_suspend(struct device *dev) if (pm_suspend_via_firmware() && dcp_v27_sleep_selected(dcp)) return dcp_v27_sleep_suspend(dcp); - if (pm_suspend_via_firmware() && dcp_s2r_capable(dcp)) { + /* + * J813 uses the same qualified stop as DPMS off. Probe already gates + * its derived power layout on appledrm.s2r_untested; without this + * system-suspend path an active panel leaves the DCP running. + */ + if (pm_suspend_via_firmware() && dcp_s2r_capable(dcp) && + (!dcp->hw.s2r_untested || of_machine_is_compatible("apple,j813"))) { int ret = dcp_s2r_suspend(dcp); /* Lit by the last resume with its CRTC off: the next resume finds it off by DPMS. */ @@ -9471,6 +9623,7 @@ static const struct apple_dcp_hw_data apple_dcp_hw_t8140 = { .firmware_scratch = 0x20000, .firmware_request = 0x68000, .s2r = true, + .s2r_layout = &dcp_s2r_t8140, }; /* Separate from the established internal-panel H17P profile. */ @@ -9496,6 +9649,11 @@ static const struct apple_dcp_hw_data apple_dcp_hw_t8142 = { .iomfb_method_profile = DCP_IOMFB_METHODS_H17G, .adopt_live_session = true, .firmware_compat = DCP_FIRMWARE_H17P, + /* Firmware 27.0's sleep calls (iomfb_v27.c): only with appledrm.s2r_untested */ + .s2r = true, + .s2r_untested = true, + .s2r_no_secure_port = true, + .s2r_layout = &dcp_s2r_t8142, }; static const struct apple_dcp_hw_data apple_dcp_hw_dcp = { @@ -9576,7 +9734,31 @@ static const struct apple_dcp_hw_data apple_dcp_hw_t6050_dcpext = { .link_report = true, }; +/* + * T8142's external processors (dcpext0/1: the Airs' two USB-C ports, the + * J704's HDMI) run the internal DCP's firmware 27 image and are left running + * idle by iBoot, like T6050's. Their services sit where macOS 27.2 binds + * them on a J815 (IORegistry under iop-dcpextN-nub): AppleDCPDPTXController + * (dcpav-/dcpdp-controller-epic, units 0 and 1) on DPTX_CONTROLLER_ENDPOINT, + * and AppleDCPDPTXRemotePort (dcpdptx-port-epic, units 0 and 1) on + * DPTX_ENDPOINT, not on firmware 27's DPTX_ENDPOINT_V2. The J704's tree + * (dmitzsaz) opens the same ones. Type-C uses port 0. + */ +static const struct apple_dcp_hw_data apple_dcp_hw_t8142_dcpext = { + .num_dptx_ports = 2, + .adopt_live_session = true, + .firmware_compat = DCP_FIRMWARE_V_27_0, + .sink_metadata_edid = true, + .dptx_endpoint = DPTX_ENDPOINT, + .dptx_controller = true, + /* TEST: firmware 27.2 link release, gated by appledrm.s2r_untested. */ + .s2r_ext = true, + .s2r_no_secure_port = true, + .s2r_layout = &dcp_s2r_t8142_ext[0], +}; + static const struct of_device_id of_match[] = { + { .compatible = "apple,t8142-dcpext", .data = &apple_dcp_hw_t8142_dcpext }, { .compatible = "apple,t6041-dcp", .data = &apple_dcp_hw_t6041, }, { .compatible = "apple,t6041-dcpext", .data = &apple_dcp_hw_t6041_dcpext, }, { .compatible = "apple,t6050-dcp", .data = &apple_dcp_hw_t6050 }, diff --git a/drivers/gpu/drm/apple/dcp_backlight.c b/drivers/gpu/drm/apple/dcp_backlight.c index 7432513a7ba25..17047f04fd2e0 100644 --- a/drivers/gpu/drm/apple/dcp_backlight.c +++ b/drivers/gpu/drm/apple/dcp_backlight.c @@ -435,9 +435,16 @@ int dcp_backlight_prepare(struct apple_dcp *dcp, bool have_surface, spin_lock_irqsave(&dcp->backlight.lock, flags); ret = dcp_bl_prepare(&dcp->backlight.state, have_surface, present); - /* No reservation: carry the last completed level on an ordinary present. */ - if (ret == -EALREADY) + /* + * No reservation: carry the last completed level on an ordinary + * present, and on one without a surface, which cannot apply a new + * level. A pending level waits for the next present with a surface. + */ + if (ret == -EALREADY || + (ret == -ENODATA && !have_surface && dcp->backlight.state.ready)) { present->nits = dcp->backlight.state.actual; + ret = -EALREADY; + } spin_unlock_irqrestore(&dcp->backlight.lock, flags); return ret; } diff --git a/drivers/gpu/drm/apple/dptxep.c b/drivers/gpu/drm/apple/dptxep.c index c75079dced540..71bf6ea2e995e 100644 --- a/drivers/gpu/drm/apple/dptxep.c +++ b/drivers/gpu/drm/apple/dptxep.c @@ -1597,7 +1597,9 @@ int dptx_controller_init(struct apple_dcp *dcp) if (IS_ERR(ep)) return PTR_ERR(ep); /* Controller interfaces require the same OPEN handshake as the port. */ - ep->wire_v2 = dcp_is_ext26(dcp) || dcp->hw.iomfb_method_profile == + ep->wire_v2 = dcp_is_ext26(dcp) || + (dcp->hw.dptx_controller && dcp->fw_compat == DCP_FIRMWARE_V_27_0) || + dcp->hw.iomfb_method_profile == DCP_IOMFB_METHODS_H17P_EXTERNAL; dcp->dptx_controller_ep = ep; @@ -1628,7 +1630,9 @@ int dptxep_init(struct apple_dcp *dcp) init_completion(&dcp->dptxport[0].linkcfg_completion); init_completion(&dcp->dptxport[1].linkcfg_completion); - ep = afk_init(dcp, wire_v2 && !dcp_is_ext26(dcp) ? DPTX_ENDPOINT_V2 : DPTX_ENDPOINT, dptxep_ops); + ep = afk_init(dcp, dcp->hw.dptx_endpoint ?: + (wire_v2 && !dcp_is_ext26(dcp) ? DPTX_ENDPOINT_V2 : DPTX_ENDPOINT), + dptxep_ops); if (IS_ERR(ep)) return PTR_ERR(ep); ep->wire_v2 = wire_v2; diff --git a/drivers/gpu/drm/apple/iomfb.c b/drivers/gpu/drm/apple/iomfb.c index 4cfa7da81ae88..1f3e97e6c5e9f 100644 --- a/drivers/gpu/drm/apple/iomfb.c +++ b/drivers/gpu/drm/apple/iomfb.c @@ -1996,6 +1996,15 @@ void dcp_hotplug(struct work_struct *work) * again, and that wake does the same, forever. */ !READ_ONCE(dcp->typec_crtc_off) && + /* + * Nor while a Type-C CRTC enable runs: dcp_poweron() reconnects + * the link, and the HPD that answers it comes before the mode + * set of that enable, not after a failed one. A bad link there + * makes wlroots destroy the output it is enabling, which + * disables the CRTC, and the next enable does the same, forever. + */ + !READ_ONCE(dcp->typec_enable_pending) && + !READ_ONCE(dcp->mode_state.changing) && (!dcp_uses_t6020_tunnel_flow(dcp) || dcp->tunnel_power_cycles < DCP_TUNNEL_POWER_CYCLES)) { bool power_cycle = dcp_uses_t6020_tunnel_flow(dcp); diff --git a/drivers/gpu/drm/apple/iomfb_template.c b/drivers/gpu/drm/apple/iomfb_template.c index 8a4812678d164..066c7a5f1cfdd 100644 --- a/drivers/gpu/drm/apple/iomfb_template.c +++ b/drivers/gpu/drm/apple/iomfb_template.c @@ -638,7 +638,8 @@ DCP_THUNK_INOUT(dcp_pipe_cfg_414, dcpep_pipe_cfg_414, u64, u64); DCP_THUNK_OUT(dcp_pipe_query_478, dcpep_pipe_query_478, u32); DCP_THUNK_OUT(dcp_pipe_query_474, dcpep_pipe_query_474, u32); DCP_THUNK_IN(dcp_pipe_set_476, dcpep_pipe_set_476, u32); -#if DCP_FW_VER < DCP_FW_VERSION(27, 0, 0) +/* Built for 27.0 too, which still dispatches it as A500; the sleep checks the build has it. */ +#if DCP_FW_VER <= DCP_FW_VERSION(27, 0, 0) DCP_THUNK_IN(dcp_unnamed_500, dcpep_unnamed_500, u32); #endif #endif @@ -2644,8 +2645,8 @@ static void complete_set_powerstate(struct apple_dcp *dcp, void *out, } } -/* V27 shares the h17p template prefix, but does not own its sleep RPCs. */ -#if DCP_FW_H17(DCP_FW_VER) && DCP_FW_VER < DCP_FW_VERSION(27, 0, 0) +/* V27 shares the h17p template prefix; iomfb_v27.c renames these two to their _v27 names. */ +#if DCP_FW_H17(DCP_FW_VER) /* * set_power_state around a firmware-driven suspend. What macOS sends before it in * either direction: A414(0), A478 twice, A476(1), A478, A412. All are named in diff --git a/drivers/gpu/drm/apple/iomfb_v14_7_backlight_test.c b/drivers/gpu/drm/apple/iomfb_v14_7_backlight_test.c index 3c1fc2f45d534..a84e45338793e 100644 --- a/drivers/gpu/drm/apple/iomfb_v14_7_backlight_test.c +++ b/drivers/gpu/drm/apple/iomfb_v14_7_backlight_test.c @@ -554,6 +554,25 @@ static void v14_bl_t6030_work(struct kunit *test) KUNIT_EXPECT_TRUE(test, dcp_backlight_pending(f.dcp)); } +/* + * A present without a surface cannot apply a new level: it carries the last + * completed one and reserves nothing, so it is still sent, and the request + * waits for the next present with a surface. + */ +static void v14_bl_surfaceless_present(struct kunit *test) +{ + struct v14_bl_fixture f = v14_bl_fixture(test, &dcp_v14_board_t6030, true); + struct dcp_backlight_present p = { .nits = U32_MAX }; + + v14_bl_request(test, f.dcp, 250); + KUNIT_EXPECT_EQ(test, dcp_backlight_prepare(f.dcp, false, &p), -EALREADY); + KUNIT_EXPECT_EQ(test, p.nits, DCP_V14_NITS_DEFAULT); + KUNIT_EXPECT_TRUE(test, f.dcp->backlight.state.dirty); + KUNIT_EXPECT_FALSE(test, f.dcp->backlight.state.in_flight); + KUNIT_ASSERT_EQ(test, dcp_backlight_prepare(f.dcp, true, &p), 0); + KUNIT_EXPECT_EQ(test, p.nits, 250U); +} + static struct kunit_case v14_backlight_cases[] = { KUNIT_CASE(v14_bl_binary64), KUNIT_CASE(v14_bl_level_block), @@ -562,6 +581,7 @@ static struct kunit_case v14_backlight_cases[] = { KUNIT_CASE(v14_bl_gate_transitions), KUNIT_CASE(v14_bl_plan), KUNIT_CASE(v14_bl_policy), + KUNIT_CASE(v14_bl_surfaceless_present), KUNIT_CASE(v14_bl_other_boards_untouched), KUNIT_CASE(v14_bl_external_untouched), KUNIT_CASE(v14_bl_t6030_swap_levels), diff --git a/drivers/gpu/drm/apple/iomfb_v27.c b/drivers/gpu/drm/apple/iomfb_v27.c index 5902edc7013ee..a1ccdb537d54f 100644 --- a/drivers/gpu/drm/apple/iomfb_v27.c +++ b/drivers/gpu/drm/apple/iomfb_v27.c @@ -158,6 +158,12 @@ static const struct dcp_method_entry dcp_methods_27_0[dcpep_num_methods] = { IOMFB_METHOD("A479", iomfbep_abort_swaps_dcp), IOMFB_METHOD("A484", dcpep_set_power_state), IOMFB_METHOD("A483", dcpep_register_dfb_surface), + /* + * The AP link's release, unnamed: H17P's and 26.6's A500, (0x4, 0). The 27.0 firmware + * still dispatches it as A500 (t8142dcp 1317.1.1: cmp 'A500', then 'A500' | 1), unlike + * the IOMFB calls around it; 27.2 moved both to A550/A551. + */ + IOMFB_METHOD("A500", dcpep_unnamed_500), }; /* @@ -165,9 +171,9 @@ static const struct dcp_method_entry dcp_methods_27_0[dcpep_num_methods] = { * A400/A401, so IOMobileFramebufferAP moved up by 50 (start_signal A451, * get_color_remap_mode A477), and set_create_DFB and vi_set_temperature_hint * up by one. The UPPipe A0xx and A1xx IDs are unchanged. The firmware rejects - * an unknown tag with a panic ("link_rpc_lookup callback not found"), so - * dfb_ready_query, whose 27.2 tag has not been seen in a call, has no entry - * here and is not sent to this build (boot_5()). + * an unknown tag with a panic ("link_rpc_lookup callback not found"). + * dfb_ready_query is A385, one above its 27.0 ID: the 27.3 trace sends it + * there, and the J813's DCP answers it at A385 on 27.2. */ static const struct dcp_method_entry dcp_methods_27_2[dcpep_num_methods] = { IOMFB_METHOD("A000", dcpep_late_init_signal), @@ -193,6 +199,7 @@ static const struct dcp_method_entry dcp_methods_27_2[dcpep_num_methods] = { IOMFB_METHOD("A104", dcpep_set_dfb_dimensions), IOMFB_METHOD("A105", dcpep_commit_dfb_info), IOMFB_METHOD("A035", dcpep_dfb_query), + IOMFB_METHOD("A385", dcpep_dfb_ready_query), IOMFB_METHOD("A353", dcpep_pipe_query_353), IOMFB_METHOD("A352", dcpep_pipe_set_352), IOMFB_METHOD("A465", dcpep_pipe_cfg_415), @@ -302,8 +309,9 @@ const char *iomfb_v27_missing_method(const struct dcp_method_entry *methods, *count = 0; for (i = 0; i < dcpep_num_methods; i++) { + /* Only a firmware sleep sends unnamed_500, and it checks the build's table. */ if (!dcp_methods_27_0[i].tag[0] || methods[i].tag[0] || - i == dcpep_dfb_ready_query) + i == dcpep_dfb_ready_query || i == dcpep_unnamed_500) continue; if (!first) first = dcp_methods_27_0[i].name; @@ -323,6 +331,8 @@ const char *iomfb_v27_missing_method(const struct dcp_method_entry *methods, #define iomfb_shutdown_h17p iomfb_shutdown_v27 #define iomfb_present_backlight_h17p iomfb_present_backlight_v27 #define iomfb_present_matrix_h17p iomfb_present_matrix_v27 +#define iomfb_s2r_500_h17p iomfb_s2r_500_v27 +#define iomfb_s2r_power_h17p iomfb_s2r_power_v27 #define DCP_FW h17p #define DCP_FW_VER DCP_FW_VERSION(27, 0, 0) @@ -357,6 +367,21 @@ static bool trampoline_get_frequency_v27(struct apple_dcp *dcp, int tag, return true; } +/* + * D572, as on H17P: the firmware powers the display DART's streams with it, 0 when it's done + * with the display. Only a sleep's stop acts on it (dcp_s2r_dart_power()). + */ +static bool trampoline_dart_power_v27(struct apple_dcp *dcp, int tag, + void *out, void *in) +{ + const struct dcp_packet_header *header = in - sizeof(*header); + + if (header->in_len >= sizeof(u32)) + dcp_s2r_dart_power(dcp, get_unaligned_le32(in)); + + return trampoline_zero(dcp, tag, out, in); +} + static bool trampoline_hotplug_h17p(struct apple_dcp *dcp, int tag, void *out, void *in) { @@ -669,7 +694,7 @@ static const iomfb_cb_handler cb_handlers[IOMFB_MAX_CB] = { [565] = trampoline_true, [567] = trampoline_true, [569] = trampoline_set_boolean_property_v27, - [572] = trampoline_zero, + [572] = trampoline_dart_power_v27, /* powerUpDART */ [574] = iomfbep_cb_video_range_h17p, [575] = trampoline_hotplug_h17p, [576] = trampoline_nop, diff --git a/drivers/gpu/drm/apple/iomfb_v27.h b/drivers/gpu/drm/apple/iomfb_v27.h index 915de53c68bf5..d6978e36a49d3 100644 --- a/drivers/gpu/drm/apple/iomfb_v27.h +++ b/drivers/gpu/drm/apple/iomfb_v27.h @@ -145,5 +145,7 @@ void iomfb_poweroff_v27(struct apple_dcp *dcp); void iomfb_sleep_v27(struct apple_dcp *dcp); void iomfb_present_backlight_v27(struct apple_dcp *dcp); void iomfb_present_matrix_v27(struct apple_dcp *dcp); +int iomfb_s2r_500_v27(struct apple_dcp *dcp); +int iomfb_s2r_power_v27(struct apple_dcp *dcp, bool on, bool named_calls, bool oob); #endif diff --git a/drivers/gpu/drm/asahi/fwid.rs b/drivers/gpu/drm/asahi/fwid.rs index c7d2e84797cfb..df20d3c406626 100644 --- a/drivers/gpu/drm/asahi/fwid.rs +++ b/drivers/gpu/drm/asahi/fwid.rs @@ -590,4 +590,32 @@ mod tests { assert!(admit(t, d, &e[..1], h).is_none()); } } + + #[test] + fn t8142_identifies_each_build() { + use crate::g17::fw::m5::initdata::RootProfile; + let crate::g17::fw::variant::Firmware::Identified(builds) = crate::hw::t8142::CONFIG.firmware + else { + panic!("the J813 must identify its loaded firmware"); + }; + assert_eq!(builds.len(), 2); + // Same TEXT and DATA sizes for both builds, so each is told apart by its digest at its + // own record offsets. + t6050_admits_only(builds); + let [a428, b123] = [&builds[0].images[0], &builds[1].images[0]]; + for (image, other) in [(a428, builds[1].images), (b123, builds[0].images)] { + assert!(lookup(other, image.text_size, image.data_size, |_| { + Some(image.text_sha256) + }) + .is_none()); + } + // 26A428 runs the board as probed; 26B123 runs it on the 26B123 graph. + assert!(builds[0].config.is_none()); + let config = builds[1].config.unwrap(); + assert_eq!(config.m5.unwrap().graph.profile, RootProfile::J873G18G26B123); + assert_eq!( + crate::hw::t8142::CONFIG.m5.unwrap().graph.profile, + RootProfile::J873G18G26A428 + ); + } } diff --git a/drivers/gpu/drm/asahi/g17/fw/m5/initdata.rs b/drivers/gpu/drm/asahi/g17/fw/m5/initdata.rs index b5e8ce3cebc27..fa59271630930 100644 --- a/drivers/gpu/drm/asahi/g17/fw/m5/initdata.rs +++ b/drivers/gpu/drm/asahi/g17/fw/m5/initdata.rs @@ -36,6 +36,11 @@ pub(crate) enum RootProfile { J873G18G26A428, J714G17S26A428, + + /// The common interface of macOS 27.2 (26B123, RTKit 3514.41.1): the + /// [`Self::J873G18G26A428`] graph with a longer policy and status config + /// ([`COMMON26B123_LAYOUTS`]). The J813's G17G build runs it as the J873's G18G one does. + J873G18G26B123, } impl RootProfile { @@ -44,13 +49,28 @@ impl RootProfile { Self::J700G17P => INITDATA_VERSION_WORD, Self::J813G17G25G76 => 0x0c8a_a322_039e_04c0, Self::J873G18G26A428 => COMMON26_INITDATA_VERSION_WORD, + Self::J873G18G26B123 => COMMON26B123_INITDATA_VERSION_WORD, Self::J714G17S26A428 => M5_INITDATA_VERSION_WORD, } } + /// Either common-interface build, 26A428 or 26B123. + pub(crate) const fn is_common26(self) -> bool { + matches!(self, Self::J873G18G26A428 | Self::J873G18G26B123) + } + + /// The shared, private and per-object layouts of a common-interface build. + pub(crate) const fn common26_layouts(self) -> Option<&'static Common26Layouts> { + match self { + Self::J873G18G26A428 => Some(&COMMON26_LAYOUTS), + Self::J873G18G26B123 => Some(&COMMON26B123_LAYOUTS), + Self::J700G17P | Self::J813G17G25G76 | Self::J714G17S26A428 => None, + } + } + pub(crate) const fn root_size(self, role: InstanceRole) -> usize { match self { - Self::J873G18G26A428 => COMMON26_ROOT_SIZE, + Self::J873G18G26A428 | Self::J873G18G26B123 => COMMON26_ROOT_SIZE, Self::J714G17S26A428 => M5_ROOT_SIZE, Self::J700G17P | Self::J813G17G25G76 => root_size(role), } @@ -58,10 +78,10 @@ impl RootProfile { pub(crate) const fn control_opening_opcode(self, role: InstanceRole) -> u32 { match (self, role) { - (Self::J873G18G26A428, InstanceRole::Primary) => { + (Self::J873G18G26A428 | Self::J873G18G26B123, InstanceRole::Primary) => { COMMON26_CONTROL_OPENING_OPCODE_PRIMARY } - (Self::J873G18G26A428, InstanceRole::Secondary) => { + (Self::J873G18G26A428 | Self::J873G18G26B123, InstanceRole::Secondary) => { COMMON26_CONTROL_OPENING_OPCODE_SECONDARY } (Self::J714G17S26A428, InstanceRole::Primary) => M5_CONTROL_OPENING_OPCODE_PRIMARY, @@ -75,7 +95,7 @@ impl RootProfile { pub(crate) const fn control_register_opcode(self) -> Option { match self { - Self::J873G18G26A428 | Self::J714G17S26A428 => None, + Self::J873G18G26A428 | Self::J873G18G26B123 | Self::J714G17S26A428 => None, Self::J700G17P | Self::J813G17G25G76 => Some(CONTROL_OPENING_PRIMARY_REGISTER_OPCODE), } } @@ -83,6 +103,7 @@ impl RootProfile { pub(crate) const fn bundle_view_offsets(self) -> [usize; 5] { match self { Self::J873G18G26A428 => COMMON26_BUNDLE_VIEW_OFFSETS, + Self::J873G18G26B123 => COMMON26B123_BUNDLE_VIEW_OFFSETS, Self::J714G17S26A428 => M5_BUNDLE_VIEW_OFFSETS, Self::J700G17P | Self::J813G17G25G76 => BUNDLE_VIEW_OFFSETS, } @@ -90,7 +111,8 @@ impl RootProfile { pub(crate) const fn bundle_view_extents(self) -> [usize; 5] { match self { - Self::J873G18G26A428 => COMMON26_BUNDLE_VIEW_EXTENTS, + // 26B123 grows only the policy and the status config; the five views keep their sizes. + Self::J873G18G26A428 | Self::J873G18G26B123 => COMMON26_BUNDLE_VIEW_EXTENTS, Self::J714G17S26A428 => M5_BUNDLE_VIEW_EXTENTS, Self::J700G17P | Self::J813G17G25G76 => BUNDLE_VIEW_EXTENTS, } @@ -99,7 +121,7 @@ impl RootProfile { /// The GPU-visible aliases of the firmware's own tables the main config names. pub(crate) const fn region_view_low_addrs(self) -> [u64; 2] { match self { - Self::J873G18G26A428 => COMMON26_REGION_VIEW_LOW_ADDRS, + Self::J873G18G26A428 | Self::J873G18G26B123 => COMMON26_REGION_VIEW_LOW_ADDRS, Self::J714G17S26A428 | Self::J700G17P | Self::J813G17G25G76 => REGION_VIEW_LOW_ADDRS, } } @@ -107,6 +129,7 @@ impl RootProfile { pub(crate) const fn repeated_region_bundle_offset(self) -> usize { match self { Self::J873G18G26A428 => COMMON26_SHARED_LAYOUT.block_88, + Self::J873G18G26B123 => COMMON26B123_SHARED_LAYOUT.block_88, Self::J714G17S26A428 => M5_SHARED_LAYOUT.block_88, Self::J700G17P | Self::J813G17G25G76 => MAIN_REPEATED_REGION_BUNDLE_OFFSET, } @@ -115,6 +138,7 @@ impl RootProfile { pub(crate) const fn work_ring_bundle_offsets(self) -> [usize; WORK_CHANNEL_COUNT] { match self { Self::J873G18G26A428 => COMMON26_WORK_RING_BUNDLE_OFFSETS, + Self::J873G18G26B123 => COMMON26B123_WORK_RING_BUNDLE_OFFSETS, Self::J714G17S26A428 => M5_WORK_RING_BUNDLE_OFFSETS, Self::J700G17P | Self::J813G17G25G76 => WORK_RING_BUNDLE_OFFSETS, } @@ -876,18 +900,17 @@ pub(crate) fn encode_main_config_for_profile( RootProfile::J700G17P => MAIN_SECONDARY_KIND_VALUE, RootProfile::J813G17G25G76 => 0xc, - RootProfile::J873G18G26A428 | RootProfile::J714G17S26A428 => { - COMMON26_MAIN_SECONDARY_KIND - } + RootProfile::J873G18G26A428 | RootProfile::J873G18G26B123 + | RootProfile::J714G17S26A428 => COMMON26_MAIN_SECONDARY_KIND, }); if profile == RootProfile::J714G17S26A428 { put_u64(out, COMMON26_MAIN_SECONDARY_POLICY_PTR, bundle + M5_SHARED_LAYOUT.policy as u64); - } else if profile == RootProfile::J873G18G26A428 { + } else if let Some(layouts) = profile.common26_layouts() { put_u64(out, COMMON26_MAIN_SECONDARY_POLICY_PTR, - bundle + COMMON26_SHARED_LAYOUT.policy as u64); + bundle + layouts.shared.policy as u64); } else { let extra = bundle @@ -909,7 +932,7 @@ pub(crate) fn encode_region_c_for_profile( if out.len() != REGION_C_SIZE { return Err(InitdataError::BufferSize); } - if profile == RootProfile::J873G18G26A428 { + if profile.is_common26() { return encode_common26_region_c(out); } @@ -976,7 +999,7 @@ pub(crate) fn encode_secondary_root_extra_1_for_profile( out.fill(0); write_runs(out, SECONDARY_ROOT_EXTRA_1_RUNS); - if matches!(profile, RootProfile::J813G17G25G76 | RootProfile::J873G18G26A428) { + if profile == RootProfile::J813G17G25G76 || profile.is_common26() { put_u32(out, 0x10, 2); } Ok(()) @@ -1904,16 +1927,213 @@ const _: () = { <= COMMON26_STATUS_B_SPAN); }; +// --- The common interface of macOS 27.2 (26B123, RTKit 3514.41.1) ------------------------------- +// +// Against 26A428, the same changes as the J873's G18G build of this release: +// +// - Both roles expect the InitData root version word with bit 45 set. +// - The policy grows by 0x60 (0x7168 -> 0x71c8 for G17G; 0x7800 -> 0x7860 in the common table) +// and the status config by 8 (0x6d0 -> 0x6d8); the other 22 allocations keep their sizes. +// - Policy and status-config fields move as the bands below describe. The new words carry a new +// accelerator power-controller field (accel +0x1122c), which the generic power and performance +// setup sets to 5000 and the G17G one leaves alone. +// - Every other InitData object keeps its field offsets. + +/// FW_PROVEN 26B123: u16 {0x04c0, 0x83a0, 0x6339, 0x0c8b}. +pub(crate) const COMMON26B123_INITDATA_VERSION_WORD: u64 = 0x0c8b_6339_83a0_04c0; + +/// The common 26A428 table with the 26B123 policy and status config. +pub(crate) const ABI_ALLOCATION_SIZES_26B123: [usize; 24] = [ + 0x2848, 0x0c18, 0x1048, 0x0e10, 0x7860, 0x0068, 0x0800, 0x0088, 0x1800, 0x04c0, 0x4000, 0x0030, + 0xe730, 0x06d8, 0x0020, 0x01b0, 0x4800, 0x28800, 0x79800, 0x9000, 0x0060, 0x0008, 0x0e80, 0x00e4, +]; + +/// Everything after the policy in the shared cluster moves by 0x80 (64-byte packing); the page +/// total is unchanged. +pub(crate) const COMMON26B123_SHARED_LAYOUT: SharedClusterLayout = + shared_cluster_layout(&ABI_ALLOCATION_SIZES_26B123); +/// 0x6d8 packs to the 0x700 that 0x6d0 took: the private cluster is the 26A428 one. +pub(crate) const COMMON26B123_PRIVATE_LAYOUT: PrivateClusterLayout = + private_cluster_layout(&ABI_ALLOCATION_SIZES_26B123); + +pub(crate) const COMMON26B123_BUNDLE_VIEW_OFFSETS: [usize; 5] = [ + COMMON26B123_SHARED_LAYOUT.block_c18, + COMMON26B123_SHARED_LAYOUT.block_1048, + COMMON26B123_SHARED_LAYOUT.block_e10, + COMMON26B123_SHARED_LAYOUT.block_68, + COMMON26B123_SHARED_LAYOUT.block_800, +]; + +pub(crate) const COMMON26B123_WORK_RING_BUNDLE_OFFSETS: [usize; WORK_CHANNEL_COUNT] = + work_ring_offsets(&COMMON26B123_SHARED_LAYOUT); + +/// Policy 26A428 -> 26B123. +/// +/// - +0x2f08 stays; the accelerator's power-controller words at +0x2f0c..+0x2f17 move by 0x10 +/// and the new field is the u32 at +0x2f28. +/// - +0x2f18..+0x2fb3 holds nothing the host writes in either build. +/// - From +0x2fb4 to the last 26A428 store (+0x6d98, u64) everything moves by 0x18, among them +/// the policy state pointer, the AON PTD pointer and the boot timestamp. The host writes +/// nothing past +0x6da0. +const COMMON26B123_POLICY_BANDS: &[LayoutBand] = &[ + band(0x0000, 0x2f0c, 0, Evidence::ProducerChecked), + band(0x2f0c, 0x2f18, 0x10, Evidence::ProducerChecked), + band(0x2fb4, 0x6da0, 0x18, Evidence::ProducerChecked), +]; +const COMMON26B123_POLICY_NEW_WORDS: &[(usize, u32)] = &[(0x2f28, 5000)]; + +/// Status config 26A428 -> 26B123: +0x59c..+0x5b3 move by 4 and +0x5b4 to the end by 8 (the +/// link word and pointer among them). The new +0x59c stays zero (only the zeroing of +/// +0x590..+0x59f covers it); +0x5b8 is the new accelerator field. +const COMMON26B123_STATUS_CONFIG_BANDS: &[LayoutBand] = &[ + band(0x000, 0x59c, 0, Evidence::ProducerChecked), + band(0x59c, 0x5b4, 4, Evidence::ProducerChecked), + band(0x5b4, 0x6d0, 8, Evidence::ProducerChecked), +]; +const COMMON26B123_STATUS_CONFIG_NEW_WORDS: &[(usize, u32)] = &[(0x5b8, 5000)]; + +/// How a later build moves the blocks the 26A428 encoders produce. +pub(crate) struct Common26Relayout { + policy_bands: &'static [LayoutBand], + policy_new_words: &'static [(usize, u32)], + status_config_bands: &'static [LayoutBand], + status_config_new_words: &'static [(usize, u32)], +} + +/// The layouts of one common-interface build. +pub(crate) struct Common26Layouts { + pub(crate) shared: SharedClusterLayout, + pub(crate) private: PrivateClusterLayout, + pub(crate) policy_size: usize, + pub(crate) status_config_size: usize, + /// None for 26A428, which the encoders produce directly. + relayout: Option, +} + +pub(crate) const COMMON26_LAYOUTS: Common26Layouts = Common26Layouts { + shared: COMMON26_SHARED_LAYOUT, + private: COMMON26_PRIVATE_LAYOUT, + policy_size: COMMON26_POLICY_SIZE, + status_config_size: COMMON26_STATUS_CONFIG_SIZE, + relayout: None, +}; + +pub(crate) const COMMON26B123_LAYOUTS: Common26Layouts = Common26Layouts { + shared: COMMON26B123_SHARED_LAYOUT, + private: COMMON26B123_PRIVATE_LAYOUT, + policy_size: ABI_ALLOCATION_SIZES_26B123[ALLOC_POLICY], + status_config_size: ABI_ALLOCATION_SIZES_26B123[ALLOC_STATUS_CONFIG], + relayout: Some(Common26Relayout { + policy_bands: COMMON26B123_POLICY_BANDS, + policy_new_words: COMMON26B123_POLICY_NEW_WORDS, + status_config_bands: COMMON26B123_STATUS_CONFIG_BANDS, + status_config_new_words: COMMON26B123_STATUS_CONFIG_NEW_WORDS, + }), +}; + +/// The common 26B123 build (macOS 27.2; the J813). +pub(crate) const COMMON26B123_GRAPH: Graph = Graph { + profile: RootProfile::J873G18G26B123, + private: COMMON26B123_PRIVATE_LAYOUT, + shared: COMMON26B123_SHARED_LAYOUT, + policy_size: COMMON26B123_LAYOUTS.policy_size, + bundle_view_offsets: COMMON26B123_BUNDLE_VIEW_OFFSETS, + bundle_view_extents: COMMON26_BUNDLE_VIEW_EXTENTS, + work_ring_offsets: COMMON26B123_WORK_RING_BUNDLE_OFFSETS, + state_grids: state_grids(&COMMON26B123_PRIVATE_LAYOUT), + power_assert_tally: COMMON26_GRAPH.power_assert_tally, +}; + +const _: () = { + let (old, new) = (COMMON26_SHARED_LAYOUT, COMMON26B123_SHARED_LAYOUT); + assert!(new.total == old.total && new.policy == old.policy); + assert!(new.block_68 == old.block_68 + 0x80 && new.main_config[0] == old.main_config[0] + 0x80); + assert!(COMMON26B123_PRIVATE_LAYOUT.total == COMMON26_PRIVATE_LAYOUT.total); + assert!(COMMON26B123_PRIVATE_LAYOUT.status_config == COMMON26_PRIVATE_LAYOUT.status_config); + assert!(COMMON26B123_PRIVATE_LAYOUT.roles[0].status_a == COMMON26_PRIVATE_LAYOUT.roles[0].status_a); + assert!(COMMON26B123_PRIVATE_LAYOUT.policy_state == COMMON26_PRIVATE_LAYOUT.policy_state); + assert!(COMMON26_STATUS_CONFIG_IN_STATUS_B + COMMON26B123_LAYOUTS.status_config_size + <= COMMON26_STATUS_B_SPAN); + assert!(bands_fit(COMMON26B123_POLICY_BANDS, COMMON26_POLICY_SIZE, + COMMON26B123_LAYOUTS.policy_size)); + assert!(bands_fit(COMMON26B123_STATUS_CONFIG_BANDS, COMMON26_STATUS_CONFIG_SIZE, + COMMON26B123_LAYOUTS.status_config_size)); +}; + +/// Whether `bands` are ascending, move no byte down, keep their order once moved and land +/// inside `new_size`, so [`relayout_by_bands`] can move them in place. +const fn bands_fit(bands: &[LayoutBand], old_size: usize, new_size: usize) -> bool { + let mut index = 0; + while index < bands.len() { + let band = bands[index]; + if band.delta < 0 || band.start >= band.end || band.end > old_size + || band.end + band.delta as usize > new_size { + return false; + } + if index > 0 { + let previous = bands[index - 1]; + if previous.end > band.start + || previous.end + previous.delta as usize > band.start + band.delta as usize { + return false; + } + } + index += 1; + } + true +} + +/// Move a block encoded in the 26A428 layout (the first `old_size` bytes of `out`) to the layout +/// `bands` describe, in place, and zero what the bands leave behind. A nonzero byte no band +/// carries has no place in the new layout and is refused. +fn relayout_by_bands(bands: &[LayoutBand], old_size: usize, out: &mut [u8]) + -> Result<(), InitdataError> { + let old = out.get(..old_size).ok_or(InitdataError::BufferSize)?; + if old.iter().enumerate().any(|(offset, byte)| { + *byte != 0 && relocate_by_bands(bands, offset).is_none() + }) { + return Err(InitdataError::InterfaceMismatch); + } + for band in bands.iter().rev() { + let delta = band.delta as usize; + if delta == 0 { + continue; + } + let target = band.start + delta; + if target + (band.end - band.start) > out.len() { + return Err(InitdataError::BufferSize); + } + out.copy_within(band.start..band.end, target); + out[band.start..band.end.min(target)].fill(0); + } + Ok(()) +} + +/// Bring a block the 26A428 encoder produced to the build's layout and set the words the build +/// added. +fn relayout_common26( + bands: &[LayoutBand], + new_words: &[(usize, u32)], + old_size: usize, + out: &mut [u8], +) -> Result<(), InitdataError> { + relayout_by_bands(bands, old_size, out)?; + for &(offset, value) in new_words { + put_u32(out, offset, value); + } + Ok(()) +} + impl Graph { pub(crate) fn is_common26(&self) -> bool { - self.profile == RootProfile::J873G18G26A428 + self.profile.is_common26() } } -/// Encode the common 26A428 primary status-B span: status B, status config and the gap to -/// status A. The status config carries the board's 25G76 words relocated, the fields 26A428 -/// added and its new cross-link to status B. +/// Encode the common primary status-B span: status B, status config and the gap to status A. The +/// status config carries the board's 25G76 words relocated, the fields 26A428 added and its new +/// cross-link to status B, moved to the layout of the build `layouts` describes. fn encode_common26_primary_status_b( + layouts: &Common26Layouts, fwctl_state: u64, fwctl_ring: u64, status_b: u64, @@ -1926,15 +2146,24 @@ fn encode_common26_primary_status_b( required_address(fwctl_ring)?; required_address(status_b)?; let config = COMMON26_STATUS_CONFIG_IN_STATUS_B; + // Where the build keeps the status config's half of the cross-link. + let link_word = match &layouts.relayout { + Some(relayout) => relocate_by_bands(relayout.status_config_bands, + COMMON26_STATUS_CONFIG_LINK_WORD) + .ok_or(InitdataError::InterfaceMismatch)?, + None => COMMON26_STATUS_CONFIG_LINK_WORD, + }; out.fill(0); encode_status_block(&mut out[..STATUS_BLOCK_SIZE])?; put_u64(out, COMMON26_STATUS_B_FWCTL_STATE, fwctl_state); put_u64(out, COMMON26_STATUS_B_FWCTL_RING, fwctl_ring); put_u32(out, COMMON26_STATUS_B_CONFIG_HEADER, 1); put_u32(out, COMMON26_STATUS_B_LINK_WORD, 0); - put_u64(out, COMMON26_STATUS_B_LINK_PTR, - status_b + (config + COMMON26_STATUS_CONFIG_LINK_WORD) as u64); - let status_config = &mut out[config..config + COMMON26_STATUS_CONFIG_SIZE]; + put_u64(out, COMMON26_STATUS_B_LINK_PTR, status_b + (config + link_word) as u64); + // The 26A428 encoding fills the first COMMON26_STATUS_CONFIG_SIZE bytes; a later build's + // layout is made from it below. + let status_config = out.get_mut(config..config + layouts.status_config_size) + .ok_or(InitdataError::BufferSize)?; write_relocated_words(M5_25G76_STATUS_CONFIG_WORDS, 0, COMMON26_STATUS_CONFIG_BANDS, status_config)?; for (offset, value) in COMMON26_STATUS_CONFIG_NEW_WORDS { @@ -1964,18 +2193,24 @@ fn encode_common26_primary_status_b( put_u32(status_config, COMMON26_STATUS_CONFIG_LINK_WORD, 1); put_u64(status_config, COMMON26_STATUS_CONFIG_LINK_PTR, status_b + COMMON26_STATUS_B_LINK_WORD as u64); + if let Some(relayout) = &layouts.relayout { + relayout_common26(relayout.status_config_bands, relayout.status_config_new_words, + COMMON26_STATUS_CONFIG_SIZE, status_config)?; + } Ok(()) } -/// Encode the common 26A428 private cluster mapped at `private_base`: the status-B span, both -/// status A blocks, the secondary root's 0x60 object and one opening-producer entry per control -/// channel. +/// Encode the private cluster of the common build `profile` mapped at `private_base`: the +/// status-B span, both status A blocks, the secondary root's 0x60 object and one opening-producer +/// entry per control channel. pub(crate) fn encode_common26_private_cluster( + profile: RootProfile, private_base: u64, fwctl_state: u64, out: &mut [u8], ) -> Result<(), InitdataError> { - let layout = COMMON26_PRIVATE_LAYOUT; + let layouts = profile.common26_layouts().ok_or(InitdataError::InterfaceMismatch)?; + let layout = layouts.private; if out.len() != layout.total { return Err(InitdataError::BufferSize); } @@ -1995,13 +2230,14 @@ pub(crate) fn encode_common26_private_cluster( out.fill(0); let status_b = layout.status_b; let status_a = layout.roles[0].status_a; - encode_common26_primary_status_b(fwctl_state, fwctl_ring, private_base + status_b as u64, + encode_common26_primary_status_b(layouts, fwctl_state, fwctl_ring, + private_base + status_b as u64, &mut out[status_b..status_a])?; for role in layout.roles { encode_status_block(&mut out[role.status_a..role.status_a + STATUS_BLOCK_SIZE])?; } let extra = layout.secondary_extra_1; - encode_secondary_root_extra_1_for_profile(RootProfile::J873G18G26A428, + encode_secondary_root_extra_1_for_profile(profile, &mut out[extra..extra + STATUS_BLOCK_SIZE])?; put_u32(out, layout.control_state + CHANNEL_STATE_PRODUCER * CHANNEL_STATE_SPACING, CONTROL_OPENING_PRIMARY_PRODUCER); @@ -2010,15 +2246,18 @@ pub(crate) fn encode_common26_private_cluster( Ok(()) } -/// Encode the six common 26A428 blocks after the HW data (0xc18, 0x1048, 0xe10, perf/policy, -/// 0x68, 0x800): the board's 25G76 policy words relocated, the fields 26A428 added and the owned -/// pointers. Preserves the HW data and everything from the BRN table on. +/// Encode the six common blocks after the HW data (0xc18, 0x1048, 0xe10, perf/policy, 0x68, +/// 0x800): the board's 25G76 policy words relocated, the fields 26A428 added and the owned +/// pointers, in the layout of the board's build. Preserves the HW data and everything from the +/// BRN table on. pub(crate) fn encode_common26_bundle_policy( board: &Board, bindings: M5PolicyBindings, out: &mut [u8], ) -> Result<(), InitdataError> { - let layout = COMMON26_SHARED_LAYOUT; + let layouts = board.graph.profile.common26_layouts() + .ok_or(InitdataError::InterfaceMismatch)?; + let layout = layouts.shared; if out.len() < layout.brn_table { return Err(InitdataError::BufferSize); } @@ -2043,7 +2282,10 @@ pub(crate) fn encode_common26_bundle_policy( return Err(InitdataError::BufferSize); } } - let policy = &mut out[layout.policy..layout.policy + COMMON26_POLICY_SIZE]; + // The 26A428 encoding fills the first COMMON26_POLICY_SIZE bytes; a later build's layout is + // made from it below. + let policy = out.get_mut(layout.policy..layout.policy + layouts.policy_size) + .ok_or(InitdataError::BufferSize)?; for &(offset, value) in M5_25G76_POLICY_WORDS { if (m5.policy..m5_policy_end).contains(&offset) { write_relocated_words(&[(offset, value)], m5.policy, COMMON26_POLICY_BANDS, policy)?; @@ -2067,6 +2309,10 @@ pub(crate) fn encode_common26_bundle_policy( put_u64(policy, COMMON26_POLICY_STATE_PTR, bindings.state); put_u64(policy, COMMON26_POLICY_AON_PTD_PTR, bindings.aon_ptd); put_u64(policy, COMMON26_POLICY_BOOT_TIMESTAMP, bindings.boot_timestamp); + if let Some(relayout) = &layouts.relayout { + relayout_common26(relayout.policy_bands, relayout.policy_new_words, COMMON26_POLICY_SIZE, + policy)?; + } Ok(()) } @@ -2304,6 +2550,12 @@ pub(crate) const J813: Board = Board { completion_inputs: false, }; +/// The J813 on its macOS 27.2 (26B123) firmware: the same board on the common 26B123 graph. +pub(crate) const J813_26B123: Board = Board { + graph: &COMMON26B123_GRAPH, + ..J813 +}; + const _: () = { use super::target::min_parameter_buffer_pages; assert!(J714.min_parameter_buffer as u64 == min_parameter_buffer_pages(J714.clusters) << 15); diff --git a/drivers/gpu/drm/asahi/g17/initdata/m5.rs b/drivers/gpu/drm/asahi/g17/initdata/m5.rs index cf6f8e3f8650b..7b641965cdc70 100644 --- a/drivers/gpu/drm/asahi/g17/initdata/m5.rs +++ b/drivers/gpu/drm/asahi/g17/initdata/m5.rs @@ -205,7 +205,7 @@ impl InitData { m::encode_common26_board_region_c( &mut self.object_mut(self.region_c)?.bytes_mut()[..m::REGION_C_SIZE]) .map_err(|_| EINVAL)?; - m::encode_common26_private_cluster(PRIVATE, FWCTL, + m::encode_common26_private_cluster(board.graph.profile, PRIVATE, FWCTL, &mut self.object_mut(self.cluster)?.bytes_mut()[..private.total]) .map_err(|_| EINVAL)?; } else { diff --git a/drivers/gpu/drm/asahi/g17/sleep.c b/drivers/gpu/drm/asahi/g17/sleep.c index 5f6d9e0ef3a3a..917965e360142 100644 --- a/drivers/gpu/drm/asahi/g17/sleep.c +++ b/drivers/gpu/drm/asahi/g17/sleep.c @@ -360,6 +360,9 @@ struct asahi_g17_commit { u32 saved; u32 lowered; int lower_ret; + /* The domain at the start of the stop, and the raise to full power before any ASC access */ + u32 entry; + int raise_ret; }; /* @@ -375,8 +378,31 @@ static int asahi_g17_commit_stop(void *data) u32 val; c->ran = true; + apple_sleep_note_sub(1); + /* + * The GPU gates itself between frames (~95 times a second on J815), and at the commit its + * domain read 0x244 (actual 4, J815 boot 12505746): its coprocessor's and mailbox's + * registers may not answer there, and with interrupts off a stalled read ends at WD2 (J815 + * boot 3c93d5a2: PMU note 0x44, the first commit stop). Bring it to full power first, as + * asahi_g17_power_raise() does, and keep the word from before for the resume. + */ + c->entry = readl(c->ps); + c->saved = c->entry; + if (FIELD_GET(PS_ACTUAL, c->entry) != PS_ACTIVE) { + writel(asahi_g17_ps_on(c->dev, c->entry, c->entry), c->ps); + c->raise_ret = readl_poll_timeout_atomic(c->ps, val, + FIELD_GET(PS_ACTUAL, val) == PS_ACTIVE, + 10, PS_TIMEOUT_US); + } + apple_sleep_note_sub(2); + if (c->raise_ret) { + /* Its registers can't be trusted to answer: lower the domain only. */ + c->idle[0] = c->raise_ret; + goto lower; + } for (i = 0; i < c->count; i++) c->idle[i] = apple_rtkit_sleep_idle_polled(c->rtk[i], c->cpu[i], &c->idle_us[i]); + apple_sleep_note_sub(3); for (i = 0; i < c->count; i++) { c->status[i] = readl(c->cpu[i] + ASC_CPU_STATUS); apple_rtkit_mailbox_recv_off(c->rtk[i]); @@ -387,10 +413,12 @@ static int asahi_g17_commit_stop(void *data) if (!i && c->bridge) writel(readl(c->gating) | SGX_GATING_HOLD, c->gating); } + apple_sleep_note_sub(4); c->request_ret = c->request ? apple_pmp_report_entry_withdraw_polled(c->request) : 0; + apple_sleep_note_sub(5); - c->saved = readl(c->ps); - writel(c->saved & ~(PS_AUTO_ENABLE | PS_BUSY | PS_FLAGS), c->ps); + /* Off automatic management, still at full power, for the bridge. */ + writel(readl(c->ps) & ~(PS_AUTO_ENABLE | PS_BUSY | PS_FLAGS), c->ps); if (c->bridge) { for (i = 0; i < SGX_BRIDGE_WORDS; i++) c->words[i] = readl(c->bridge + 4 * i); @@ -398,12 +426,15 @@ static int asahi_g17_commit_stop(void *data) for (i = 0; i < SGX_BRIDGE_WORDS; i++) writel(c->words[i] & ~SGX_BRIDGE_ENABLE, c->bridge + 4 * i); } + apple_sleep_note_sub(6); +lower: val = readl(c->ps); writel((val & ~(PS_AUTO_ENABLE | PS_BUSY | PS_FLAGS | PS_TARGET)) | PS_FLAGS, c->ps); c->lower_ret = readl_poll_timeout_atomic(c->ps, c->lowered, !FIELD_GET(PS_ACTUAL, c->lowered) && !(c->lowered & PS_BUSY), 10, PS_TIMEOUT_US); + apple_sleep_note_sub(7); return (c->idle[0] || c->idle[1] || c->request_ret || c->lower_ret) ? 1 : 0; } @@ -673,6 +704,8 @@ bool asahi_g17_commit_finish(struct asahi_g17_commit *c, u32 *saved) c->idle_us[0], c->idle_us[1], c->status[0], c->status[1]); dev_dbg(c->dev, "GPU at the commit: bridge %#x %#x gating %#x, domain %#x now %#x\n", c->words[0], c->words[1], c->words[2], c->saved, c->lowered); + dev_info(c->dev, "GPU domain at the commit stop: %#x, raise to full %d\n", + c->entry, c->raise_ret); *saved = c->saved; } asahi_g17_commit_free(c); diff --git a/drivers/gpu/drm/asahi/hw/t8142.rs b/drivers/gpu/drm/asahi/hw/t8142.rs index 26fe2e49abcdb..9bc380afce9a7 100644 --- a/drivers/gpu/drm/asahi/hw/t8142.rs +++ b/drivers/gpu/drm/asahi/hw/t8142.rs @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-only OR MIT -//! M5 (T8142, MacBook Air J813) on the macOS 27.0 (26A428) GPU firmware. +//! M5 (T8142, MacBook Air J813) on the macOS 27.0 (26A428) and 27.2 (26B123) GPU firmware. //! //! Bring-up only: the M5 graph ([`crate::g17::fw::m5::initdata`]) has no J813 board yet, so //! [`PROBE`] stops at the identity check, after `get_g17_id` has logged the ID registers and @@ -57,8 +57,15 @@ pub(crate) const PROBE: Config = Config { }, }; -/// The J813 on the M5 graph: [`PROBE`] with the GPU's identity and the J813 board. +/// The J813 on the M5 graph: [`PROBE`] with the GPU's identity and the J813 board. It runs +/// either firmware build of [`BUILDS`]; 26B123 runs [`CONFIG_26B123`]. pub(crate) const CONFIG: Config = Config { + firmware: crate::g17::fw::variant::Firmware::Identified(&BUILDS), + ..BASE +}; + +/// The J813 board and identity, before a firmware build is chosen. +const BASE: Config = Config { identity: Identity { family: 0xb, variant: 2, @@ -76,9 +83,78 @@ pub(crate) const CONFIG: Config = Config { deflake: crate::g17::fw::render::Deflake::ONE_CLUSTER, compute_blocks: crate::g17::fw::freelist::COMPUTE_BLOCKS, }, + // TEST: the sleep's commit stops the firmware and a real wake restarts it warm, as on + // T8140. Not yet run through a real sleep on the J813. + sleep_restart: true, ..PROBE }; +/// The J813 on the 27.2 firmware: the board on the common 26B123 graph. +pub(crate) const CONFIG_26B123: Config = Config { + m5: Some(&crate::g17::fw::m5::initdata::J813_26B123), + firmware: crate::g17::fw::variant::Firmware::Identified(&[BUILD_26B123]), + ..BASE +}; + +/// The firmware in `fw-text` must be one of these builds. iBoot loads the G17G c000 image of the +/// primary (TEXT 0x50000) and the c010 image of the secondary (0x4c000) back to back. The digest +/// is that of both TEXTs with the entropy records and the ranges iBoot fills zeroed (the image +/// header's load fields at +0x224 and +0x23c, the 0x740 bytes of boot arguments before each +/// role's GKTS record and the 0x231 bytes of records from it); it is that of the stock images +/// in the IPSW with the same ranges zeroed, and was measured on two 27.0 boots and one 27.2 boot. +const BUILDS: [crate::g17::fw::variant::Build; 2] = [ + BUILD_26A428, + crate::g17::fw::variant::Build { + config: Some(&CONFIG_26B123), + ..BUILD_26B123 + }, +]; + +const BUILD_26A428: crate::g17::fw::variant::Build = crate::g17::fw::variant::Build { + os_version: [27, 0, 0], + name: "27.0 (26A428), G17G", + images: &[crate::fwid::FirmwareBuild { + name: "26A428 for T8142 G17G, primary then secondary", + text_size: 0x9c000, + data_size: 0x184000, + entropy: &[[0x49d10, 0x49df3], [0x997d0, 0x998b3]], + boot_filled: &[ + (0x224, 4), (0x23c, 8), (0x495d0, 0x740), (0x49d10, 0x231), + (0x50224, 4), (0x5023c, 8), (0x99090, 0x740), (0x997d0, 0x231), + ], + text_sha256: [ + 0xec, 0xff, 0x40, 0xe3, 0xad, 0xb8, 0x9c, 0x90, 0x62, 0xe9, 0x1d, 0xb6, 0x3f, + 0x31, 0xba, 0xaf, 0x75, 0xeb, 0x5d, 0x3f, 0x97, 0x22, 0xe3, 0x06, 0x95, 0x45, + 0x3f, 0xad, 0x02, 0xfc, 0xf5, 0x0c, + ], + }], + variant: &crate::g17::fw::variant::V26A428_M5, + config: None, +}; + +/// RTKit 3514.41.1: the 26A428 protocol on the 26B123 InitData graph. +const BUILD_26B123: crate::g17::fw::variant::Build = crate::g17::fw::variant::Build { + os_version: [27, 2, 0], + name: "27.2 (26B123), G17G", + images: &[crate::fwid::FirmwareBuild { + name: "26B123 for T8142 G17G, primary then secondary", + text_size: 0x9c000, + data_size: 0x184000, + entropy: &[[0x49d54, 0x49e37], [0x997e4, 0x998c7]], + boot_filled: &[ + (0x224, 4), (0x23c, 8), (0x49614, 0x740), (0x49d54, 0x231), + (0x50224, 4), (0x5023c, 8), (0x990a4, 0x740), (0x997e4, 0x231), + ], + text_sha256: [ + 0xe3, 0xab, 0x32, 0x7b, 0x73, 0x1b, 0xf2, 0xf1, 0x74, 0x9b, 0x04, 0x44, 0x1f, + 0x5c, 0xb5, 0xab, 0xfc, 0x23, 0xf3, 0x41, 0xc3, 0x99, 0x72, 0x8e, 0x2c, 0xb4, + 0x6f, 0x68, 0xb1, 0x7a, 0x39, 0xb9, + ], + }], + variant: &crate::g17::fw::variant::V26A428_M5, + config: None, +}; + // Each compute operand bank holds 6 KiB per core slot of the board. const _: () = assert!( CONFIG.core_layout.operand_state.bank_bytes() diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index b97b0c3378e45..4bb6491eedb8c 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -361,8 +361,17 @@ struct apple_dart { void __iomem *regs; void __iomem *gapf; - /* The GAPF slice as it read at probe; a deep sleep resets it to 0 */ + /* + * The GAPF slice as the boot left it, read before the first write (U32_MAX until + * then); a deep sleep resets it to 0. Stays 0 for a shared PS write-disable + * register, of which only gapf_protect is ever written. + */ u32 gapf_boot; + /* + * The bit that protects the coprocessor's power state: bit 4 of a GAPF slice, or + * this DART's bit in a shared PS write-disable register (T8142) + */ + u32 gapf_protect; bool sleep_flushed; /* The firmware 27 display sleep owns it: never replay locked trees. */ struct device *m5_sleep_owner; @@ -5537,7 +5546,26 @@ static int apple_dart_probe(struct platform_device *pdev) dart->gapf = devm_platform_ioremap_resource_byname(pdev, "gapf"); if (IS_ERR(dart->gapf)) return PTR_ERR(dart->gapf); - dart->gapf_boot = readl(dart->gapf); + /* Read at its first use, a sleep's: a boot without one never touches it. */ + dart->gapf_boot = U32_MAX; + dart->gapf_protect = APPLE_DART_GAPF_PROTECT; + } else if (platform_get_resource_byname(pdev, IORESOURCE_MEM, "ps-wr-dis")) { + u32 bit; + + /* + * T8142: the SPTM's dart-ps-wr-dis-entries give each DART a bit in a register + * of a PSWRDIS block instead of a GAPF slice. The register is shared, so + * only this DART's bit is ever changed: nothing of the boot value is put + * back (gapf_boot stays 0). + */ + ret = of_property_read_u32(dev->of_node, "apple,ps-wr-dis-bit", &bit); + if (ret || bit > 31) + return dev_err_probe(dev, ret ?: -EINVAL, + "ps-wr-dis needs apple,ps-wr-dis-bit\n"); + dart->gapf = devm_platform_ioremap_resource_byname(pdev, "ps-wr-dis"); + if (IS_ERR(dart->gapf)) + return PTR_ERR(dart->gapf); + dart->gapf_protect = BIT(bit); } /* T8132's ISP DART names its DAPF page but has no ranges to restore. */ if (platform_get_resource_byname(pdev, IORESOURCE_MEM, "dapf") && @@ -7483,9 +7511,21 @@ int apple_dart_dcp_dispext_state(struct device_node *consumer) EXPORT_SYMBOL_GPL(apple_dart_dcp_dispext_state); #endif +/* The slice as the boot left it is the first value read, before any write. */ +static u32 apple_dart_gapf_read(struct apple_dart *dart) +{ + u32 val = readl(dart->gapf); + + if (dart->gapf_boot == U32_MAX) + dart->gapf_boot = val; + + return val; +} + /* - * Bit 4 of this DART's GAPF slice makes the fabric reject writes to its coprocessor's - * CPU power state. It's clear from the flush until the streams come back on. + * Bit 4 of this DART's GAPF slice (or its PS write-disable bit) makes the fabric reject + * writes to its coprocessor's CPU power state. It's clear from the flush until the + * streams come back on. */ static int apple_dart_gapf_release(struct apple_dart *dart) { @@ -7494,10 +7534,10 @@ static int apple_dart_gapf_release(struct apple_dart *dart) if (!dart->gapf) return 0; - val = readl(dart->gapf); - writel(val & ~APPLE_DART_GAPF_PROTECT, dart->gapf); - if (readl(dart->gapf) & APPLE_DART_GAPF_PROTECT) { - dev_err(dart->dev, "GAPF slice stayed protected: %#x\n", val); + val = apple_dart_gapf_read(dart); + writel(val & ~dart->gapf_protect, dart->gapf); + if (readl(dart->gapf) & dart->gapf_protect) { + dev_err(dart->dev, "power state write protection stayed set: %#x\n", val); return -EIO; } dev_dbg(dart->dev, "GAPF slice %#x -> %#x\n", val, readl(dart->gapf)); @@ -7510,11 +7550,11 @@ static void apple_dart_gapf_protect(struct apple_dart *dart) { u32 val; - if (!dart->gapf || !dart->sleep_flushed) + if (!dart->gapf || !dart->sleep_flushed || dart->gapf_boot == U32_MAX) return; val = readl(dart->gapf); - writel(val | dart->gapf_boot | APPLE_DART_GAPF_PROTECT, dart->gapf); + writel(val | dart->gapf_boot | dart->gapf_protect, dart->gapf); dev_dbg(dart->dev, "GAPF slice %#x -> %#x\n", val, readl(dart->gapf)); } @@ -7523,7 +7563,7 @@ int apple_dart_gapf_ready(struct device *dev) { struct apple_dart *dart = dev_get_drvdata(dev); - if (!dart->gapf || !(readl(dart->gapf) & APPLE_DART_GAPF_PROTECT)) + if (!dart->gapf || !(apple_dart_gapf_read(dart) & dart->gapf_protect)) return 0; return apple_dart_gapf_release(dart); diff --git a/drivers/irqchip/irq-apple-aic.c b/drivers/irqchip/irq-apple-aic.c index 7f144760fb1c5..0a9aeced27721 100644 --- a/drivers/irqchip/irq-apple-aic.c +++ b/drivers/irqchip/irq-apple-aic.c @@ -375,6 +375,8 @@ static const struct aic_info aic3_t8142_info __initconst = { .fast_ipi = true, .local_fast_ipi = true, .vm_timer_fiq_readonly = true, + /* AIC3 as on T8132: its configuration is lost with the SoC's power in a deep sleep. */ + .fw_suspend = true, }; static const struct of_device_id aic_info_match[] = { diff --git a/drivers/mfd/macsmc.c b/drivers/mfd/macsmc.c index acd46a48e2c8a..5204c960ebe9d 100644 --- a/drivers/mfd/macsmc.c +++ b/drivers/mfd/macsmc.c @@ -652,6 +652,9 @@ static int apple_smc_probe(struct platform_device *pdev) of_device_is_compatible(dev->of_node, "apple,t6050-smc"); if (smc->saved_enabled && of_machine_is_compatible("apple,j714s")) smc->wake_reasons = apple_smc_j714s_wake_reasons; + /* J813's late notice needs the bounded, IRQ-independent transport too. */ + if (of_machine_is_compatible("apple,j813")) + smc->saved_enabled = true; smc->sram_base = devm_platform_get_and_ioremap_resource(pdev, 1, &smc->sram); if (IS_ERR(smc->sram_base)) return dev_err_probe(dev, PTR_ERR(smc->sram_base), "Failed to map SRAM region"); @@ -1132,7 +1135,8 @@ static int apple_smc_sleep_saved_begin(void *data) struct apple_smc *smc = data; int ret; - if (!smc->saved_enabled || !smc->sleep_policy) + if (!smc->saved_enabled || + (!smc->sleep_policy && !apple_sleep_smc_defer_notice())) return -EOPNOTSUPP; if (!mutex_trylock(&smc->mutex)) return -EBUSY; @@ -1184,7 +1188,7 @@ static int apple_smc_sleep_saved_begin(void *data) return ret; } -static int apple_smc_sleep_saved_end(void *data) +static int apple_smc_sleep_saved_release(void *data, bool wake_ap) { struct apple_smc *smc = data; int ret, restore = 0; @@ -1197,7 +1201,7 @@ static int apple_smc_sleep_saved_end(void *data) /* Bounded reconciliation; never release pending ownership on timeout. */ if (!ret && smc->saved_pending) ret = apple_smc_saved_wait_reply(smc); - if (smc->ap_notified) { + if (wake_ap && smc->ap_notified) { restore = apple_rtkit_m5_saved_ap_power(smc->rtk, true, NULL, NULL); if (!restore) { smc->ap_notified = false; @@ -1219,6 +1223,23 @@ static int apple_smc_sleep_saved_end(void *data) return ret; } +static int apple_smc_sleep_saved_end(void *data) +{ + return apple_smc_sleep_saved_release(data, true); +} + +/* + * J813's ordinary wake notice belongs in macsmc's resume_noirq, after the + * device dependencies have resumed. Platform wake precedes every noirq + * device callback; an AP ON there can wake the radio before its DMA path. + * Release the bounded transport here, retaining ap_notified for the usual + * noirq wake callback. A refused entry never posted AP IDLE. + */ +static int apple_smc_j813_saved_end(void *data) +{ + return apple_smc_sleep_saved_release(data, false); +} + /* Readiness is a returning operation BEFORE SEP/ANS/PMP stop. A drained * notification remains retained and can cancel only on this side of the boundary. */ @@ -1338,6 +1359,42 @@ static const struct apple_sleep_smc_saved_ops apple_smc_saved_ops = { .pmvc = apple_smc_sleep_saved_pmvc, }; +/* + * J813 retains its existing MBSE/AP sequence and delay floors. The transport + * is the saved lane: no scheduler, jiffies, IRQ worker or SRAM reuse is needed + * after the peer stops. Unrelated notifications are retained until resume. + */ +static int apple_smc_sleep_after_peers(void *data, u64 *sent, u64 *ack) +{ + struct apple_smc *smc = data; + int ret; + + lockdep_assert_held(&smc->mutex); + *sent = *ack = 0; + if (!irqs_disabled() || !smc->saved_scope || !smc->sleep_warned || + smc->ap_notified) + return -EINVAL; + + smc->saved_committed = true; + ret = apple_smc_saved_write_u32(smc, SMC_KEY(MBSE), SMC_KEY(slpa)); + if (ret) + goto out; + mdelay(SMC_SLEEP_ARM_MS); + smc->ap_notified = true; + ret = apple_rtkit_m5_saved_ap_power(smc->rtk, false, sent, ack); + if (!ret) + mdelay(SMC_SLEEP_IDLE_MS); +out: + smc->saved_notice_error = ret; + return ret; +} + +static const struct apple_sleep_smc_saved_ops apple_smc_j813_saved_ops = { + .begin = apple_smc_sleep_saved_begin, + .late_notice = apple_smc_sleep_after_peers, + .end = apple_smc_j813_saved_end, +}; + static int apple_smc_prepare_policy(struct apple_smc *smc) { const struct apple_sleep_smc_policy *p = smc->sleep_policy; @@ -1403,6 +1460,8 @@ static int apple_smc_sleep_prepare(struct apple_smc *smc) else apple_smc_sleep_warn(smc); + if (apple_sleep_smc_defer_notice()) + return apple_sleep_smc_register_saved(smc->dev, &apple_smc_j813_saved_ops, smc); return 0; } @@ -1516,6 +1575,9 @@ static int apple_smc_sleep_enter(struct apple_smc *smc) apple_smc_outbox_poll(smc, "late sleep warning", SMC_SLEEP_WARN_MS, 0); } + /* Warning and debug-link handling stay in noirq; only the notice moves. */ + if (apple_sleep_smc_defer_notice()) + return 0; return apple_smc_sleep_commit(smc); } @@ -1558,7 +1620,7 @@ static int apple_smc_resume_noirq(struct device *dev) if (smc->saved_enabled && (smc->saved_recovery || smc->saved_pending || smc->saved_fault)) return smc->saved_restore_error ?: smc->saved_fault ?: -EBUSY; - if (smc->saved_enabled && smc->sleep_policy) { + if (smc->saved_enabled && (smc->sleep_policy || smc->saved_wake)) { if (smc->saved_wake) { apple_smc_set_polled(smc, true); apple_smc_sleep_wake(smc); diff --git a/drivers/net/wireless/apple/centauri/centauri.h b/drivers/net/wireless/apple/centauri/centauri.h index 2ea9c2f7923b9..fa937c1c4e2e3 100644 --- a/drivers/net/wireless/apple/centauri/centauri.h +++ b/drivers/net/wireless/apple/centauri/centauri.h @@ -99,5 +99,7 @@ int centauri_alpha_resources(struct centauri *c, struct cen_alpha_resources *res int centauri_alpha_log_buffer(struct centauri *c, void **cpu, dma_addr_t *dma, size_t *size); int centauri_wifi_register(struct centauri *c); void centauri_wifi_unregister(struct centauri *c); +int centauri_wifi_suspend(struct centauri *c); +int centauri_wifi_resume(struct centauri *c); void centauri_wifi_kick(struct centauri *c); #endif diff --git a/drivers/net/wireless/apple/centauri/centauri_pci.c b/drivers/net/wireless/apple/centauri/centauri_pci.c index c44e22717f0b5..598671387565a 100644 --- a/drivers/net/wireless/apple/centauri/centauri_pci.c +++ b/drivers/net/wireless/apple/centauri/centauri_pci.c @@ -261,11 +261,26 @@ static void centauri_remove(struct pci_dev *pdev) */ static int centauri_suspend(struct device *dev) { + struct pci_dev *pdev = to_pci_dev(dev); + struct centauri *c = pci_get_drvdata(pdev); + int ret; + + ret = centauri_wifi_suspend(c); + if (ret) + return ret; device_set_awake_path(dev); - return pci_save_state(to_pci_dev(dev)); + ret = pci_save_state(pdev); + if (ret) + centauri_wifi_resume(c); + return ret; +} + +static int centauri_resume(struct device *dev) +{ + return centauri_wifi_resume(pci_get_drvdata(to_pci_dev(dev))); } -static DEFINE_SIMPLE_DEV_PM_OPS(centauri_pm_ops, centauri_suspend, NULL); +static DEFINE_SIMPLE_DEV_PM_OPS(centauri_pm_ops, centauri_suspend, centauri_resume); /* 0x1903 is the Beta (Bluetooth) function: btcentauri claims it. This driver needs functions * 0 and 1 (1 is enabled here, its BAR is used by the Wi-Fi code) and reaches function 2 only diff --git a/drivers/net/wireless/apple/centauri/centauri_wifi.c b/drivers/net/wireless/apple/centauri/centauri_wifi.c index 1246675e50e38..48d1deca69ab2 100644 --- a/drivers/net/wireless/apple/centauri/centauri_wifi.c +++ b/drivers/net/wireless/apple/centauri/centauri_wifi.c @@ -85,6 +85,10 @@ static bool station_link_addresses; module_param(station_link_addresses, bool, 0400); MODULE_PARM_DESC(station_link_addresses, "Diagnostic: use the netdev address for each firmware link in this single-link WPA2 client"); +static bool alpha_sleep_untested; +module_param(alpha_sleep_untested, bool, 0600); +MODULE_PARM_DESC(alpha_sleep_untested, "TEST ONLY: J813 Alpha host-power and ACIPC sleep handshake"); + struct centauri_rx_snapshot { __le32 version, count; struct { @@ -117,6 +121,7 @@ struct centauri_wifi { u32 reply_command, channels_seen, scans_done, beacons_seen; bool reply_valid, registered, configured; bool stopping; + bool transport_paused, transport_sleep_sent, host_sleep_sent; bool connecting, connected, connect_event, disconnect_event; bool associated, pmk_seen, pmk_matches; u8 expected_pmk[32]; @@ -217,6 +222,8 @@ static int alpha_message(struct centauri_wifi *wifi, const void *message, size_t u8 *descriptor; unsigned long deadline = jiffies + msecs_to_jiffies(2000); + if (READ_ONCE(wifi->transport_paused)) + return -EBUSY; if (head >= 15 || size > 512) return -ENOSPC; memcpy(wifi->a.messages + (head + 1) * 512, message, size); @@ -542,11 +549,13 @@ static void drain_data_tx(struct centauri_wifi *wifi) netif_wake_queue(wifi->netdev); } -static void drain(struct centauri_wifi *wifi) +static void drain_control(struct centauri_wifi *wifi, bool pm_command) { unsigned int ring; bool posted = false; + if (READ_ONCE(wifi->transport_paused) && !pm_command) + return; for (ring = 2; ring <= 4; ring++) { unsigned int budget = ring_size[ring]; @@ -714,16 +723,26 @@ static void drain(struct centauri_wifi *wifi) completions(wifi); if (posted) writel(1, wifi->a.bar + 0x1004); - drain_data_rx(wifi); - drain_data_tx(wifi); + if (!READ_ONCE(wifi->transport_paused)) { + drain_data_rx(wifi); + drain_data_tx(wifi); + } } -static int command(struct centauri_wifi *wifi, u32 id, const void *payload, size_t size) +static void drain(struct centauri_wifi *wifi) +{ + drain_control(wifi, false); +} + +static int command_control(struct centauri_wifi *wifi, u32 id, const void *payload, + size_t size, bool pm_command) { u16 slot = wifi->command_head, sequence = ++wifi->sequence; u8 *packet, *descriptor; unsigned long deadline = jiffies + msecs_to_jiffies(1500); + if (READ_ONCE(wifi->transport_paused) && !pm_command) + return -EBUSY; if (size + 24 > BUFFER_SIZE) return -EMSGSIZE; if ((slot + 1) % ring_size[1] == index_read(wifi, 1, 1)) @@ -746,7 +765,7 @@ static int command(struct centauri_wifi *wifi, u32 id, const void *payload, size dma_wmb(); writel(1, wifi->a.bar + 0x1004); do { - drain(wifi); + drain_control(wifi, pm_command); if (readl(wifi->a.bar + 8) != 2) return -EIO; /* Bit 30 is more-data-pending, not part of the command identity. @@ -766,6 +785,11 @@ static int command(struct centauri_wifi *wifi, u32 id, const void *payload, size return -ETIMEDOUT; } +static int command(struct centauri_wifi *wifi, u32 id, const void *payload, size_t size) +{ + return command_control(wifi, id, payload, size, false); +} + static int radio_start(struct centauri_wifi *wifi) { u8 start[5 + 4 + 3 * ETH_ALEN] = { 0, 0x0b, 0, 0, 0 }; @@ -1324,6 +1348,10 @@ static void link_worker(struct work_struct *work) bool disconnected; mutex_lock(&wifi->lock); + if (wifi->transport_paused) { + mutex_unlock(&wifi->lock); + return; + } drain(wifi); disconnected = wifi->disconnect_event || READ_ONCE(wifi->stopping) || readl(wifi->a.bar + 8) != 2; @@ -1345,7 +1373,8 @@ void centauri_wifi_kick(struct centauri *c) { struct centauri_wifi *wifi = READ_ONCE(c->wifi); - if (wifi && READ_ONCE(wifi->connected) && !READ_ONCE(wifi->stopping)) + if (wifi && READ_ONCE(wifi->connected) && !READ_ONCE(wifi->stopping) && + !READ_ONCE(wifi->transport_paused)) mod_delayed_work(system_percpu_wq, &wifi->link_work, 0); } @@ -1538,6 +1567,10 @@ static netdev_tx_t net_transmit(struct sk_buff *skb, struct net_device *netdev) { struct centauri_wifi *wifi = *(struct centauri_wifi **)netdev_priv(netdev); + if (READ_ONCE(wifi->transport_paused)) { + netif_stop_queue(netdev); + return NETDEV_TX_BUSY; + } if (READ_ONCE(wifi->stopping) || !READ_ONCE(wifi->connected) || skb->len < ETH_HLEN || skb->len > BUFFER_SIZE) { netdev->stats.tx_dropped++; @@ -1684,6 +1717,10 @@ static ssize_t fwlog_ack_write(struct file *file, const char __user *input, if (ret) return ret; mutex_lock(&wifi->fwlog_lock); + if (READ_ONCE(wifi->transport_paused)) { + ret = -EBUSY; + goto out; + } if (!wifi->fwlog_ready || readl(wifi->a.bar + 8) != 2) { ret = -ENETDOWN; goto out; @@ -1889,6 +1926,8 @@ static int transmit_eapol_start(struct centauri_wifi *wifi) u64 metadata = 0; unsigned int attempt; + if (READ_ONCE(wifi->transport_paused)) + return -EBUSY; if (readl(wifi->a.bar + 8) != 2 || !(wifi->data_probe_done & BIT(3))) return -ENETDOWN; /* Eight independent buffers bound the probe without ring reuse. */ @@ -2559,6 +2598,167 @@ int centauri_wifi_register(struct centauri *c) return ret; } +/* + * 26B123 t2026-CentauriAlpha uses BAR0 + 0x1024 for sleep_control. + * AirshipDK's ACIPC host-sleep handshake writes 3 and waits for status 3; + * wake writes 0 and waits for status 0 or 1. The peripheral-info block + * starts at context + 0x68, with sleep_status at +8, as on Beta. + * Stop every ring producer before requesting host sleep. Keep them stopped + * until the wake acknowledgment, including when suspend entry is refused. + */ +static u32 alpha_sleep_status(struct centauri_wifi *wifi) +{ + return le32_to_cpu(READ_ONCE(*(__le32 *)(wifi->a.context + 0x70))); +} + +static int alpha_transport_state(struct centauri_wifi *wifi, bool asleep) +{ + u32 status; + int ret; + + lockdep_assert_held(&wifi->lock); + if (readl(wifi->a.bar + 8) != 2 || readl(wifi->a.bar + 0xc) != 2) + return -EIO; + dma_wmb(); + writel(asleep ? 3 : 0, wifi->a.bar + 0x1024); + ret = read_poll_timeout(alpha_sleep_status, status, + (asleep ? status == 3 : status <= 1) || + readl(wifi->a.bar + 8) != 2, + 100, 2000000, false, wifi); + dma_rmb(); + if (readl(wifi->a.bar + 8) != 2) + ret = -EIO; + dev_info(&wifi->control->pdev->dev, + "TEST: Alpha ACIPC host %s: ret=%d status=%u exec=%u ipc=%u\n", + asleep ? "sleep" : "wake", ret, status, + readl(wifi->a.bar + 8), readl(wifi->a.bar + 0xc)); + return ret; +} + +/* + * WLANACIAdapter sends command 6 before ACIPC host sleep. For an interface + * already disconnected by cfg80211, its LPNA mode is firmware state 3. + * The first fields are le16 state and u8 hint. Native sleep also includes + * TLV 303 (value 1) and TLV 280 (the filtered event list); wake restores all + * events. Installed Alpha 48ef6696 rejects TLV 280 lengths >= 87 and + * event counts >= 86, so use its 85 events rather than 26B123's 91. + * The data-ring producers stay paused while this control command + * and its response use the command/management rings. + */ +static int alpha_host_power(struct centauri_wifi *wifi, bool asleep) +{ + static const u8 sleep_events[] = { 24, 26, 27, 15, 51, 8, 9, 10, 84 }; + u8 payload[98] = {}, events[86] = {}, sleep_option = 1; + size_t size = 3; + int i, ret; + + lockdep_assert_held(&wifi->lock); + if (readl(wifi->a.bar + 8) != 2) + return -EIO; + if (asleep) { + put_unaligned_le16(3, payload); + payload[2] = 3; + append_tlv(payload, &size, 303, &sleep_option, sizeof(sleep_option)); + events[0] = ARRAY_SIZE(sleep_events); + memcpy(events + 1, sleep_events, sizeof(sleep_events)); + } else { + events[0] = sizeof(events) - 1; + for (i = 0; i < events[0]; i++) + events[i + 1] = i; + } + append_tlv(payload, &size, 280, events, sizeof(events)); + ret = command_control(wifi, 6, payload, size, true); + dev_info(&wifi->control->pdev->dev, + "TEST: Alpha firmware host %s: ret=%d status=%u exec=%u\n", + asleep ? "LPNA" : "awake", ret, wifi->reply_status, + readl(wifi->a.bar + 8)); + return ret; +} + +static int alpha_resume_locked(struct centauri_wifi *wifi) +{ + int ret; + + lockdep_assert_held(&wifi->lock); + if (!wifi->transport_sleep_sent && !wifi->host_sleep_sent) + return 0; + if (wifi->transport_sleep_sent) { + ret = alpha_transport_state(wifi, false); + if (ret) + return ret; + wifi->transport_sleep_sent = false; + } + if (wifi->host_sleep_sent) { + ret = alpha_host_power(wifi, false); + if (ret) + return ret; + wifi->host_sleep_sent = false; + } + mutex_lock(&wifi->fwlog_lock); + WRITE_ONCE(wifi->transport_paused, false); + mutex_unlock(&wifi->fwlog_lock); + if (wifi->connected && !READ_ONCE(wifi->stopping)) { + if (netif_running(wifi->netdev)) + netif_wake_queue(wifi->netdev); + mod_delayed_work(system_percpu_wq, &wifi->link_work, 0); + } + return 0; +} + +int centauri_wifi_resume(struct centauri *c) +{ + struct centauri_wifi *wifi = c->wifi; + int ret; + + if (!wifi || !of_machine_is_compatible("apple,j813")) + return 0; + mutex_lock(&wifi->lock); + ret = alpha_resume_locked(wifi); + mutex_unlock(&wifi->lock); + return ret; +} + +int centauri_wifi_suspend(struct centauri *c) +{ + struct centauri_wifi *wifi = c->wifi; + int ret, restore; + + if (!wifi || !of_machine_is_compatible("apple,j813") || + !READ_ONCE(alpha_sleep_untested)) + return 0; + mutex_lock(&wifi->lock); + if (wifi->transport_paused || wifi->connected || wifi->connecting || wifi->scan_request || + READ_ONCE(wifi->stopping)) { + mutex_unlock(&wifi->lock); + return -EBUSY; + } + mutex_lock(&wifi->fwlog_lock); + WRITE_ONCE(wifi->transport_paused, true); + mutex_unlock(&wifi->fwlog_lock); + mutex_unlock(&wifi->lock); + netif_tx_disable(wifi->netdev); + cancel_work_sync(&wifi->scan_work); + cancel_work_sync(&wifi->connect_work); + cancel_delayed_work_sync(&wifi->link_work); + + mutex_lock(&wifi->lock); + wifi->host_sleep_sent = true; + ret = alpha_host_power(wifi, true); + if (!ret) { + wifi->transport_sleep_sent = true; + ret = alpha_transport_state(wifi, true); + } + if (ret) { + restore = alpha_resume_locked(wifi); + if (restore) + dev_err(&c->pdev->dev, + "Alpha transport remains paused after refused sleep: %d\n", + restore); + } + mutex_unlock(&wifi->lock); + return ret; +} + void centauri_wifi_unregister(struct centauri *c) { struct centauri_wifi *wifi = c->wifi; diff --git a/drivers/nvme/host/apple.c b/drivers/nvme/host/apple.c index af32c89ff07be..d743916e99398 100644 --- a/drivers/nvme/host/apple.c +++ b/drivers/nvme/host/apple.c @@ -221,6 +221,8 @@ struct apple_nvme_hw { bool cold_reset; /* Firmware-driven suspend has been traced on this controller. */ bool sleep_traced; + /* ... or derived and never run: only with nvme_apple.sleep_untested */ + bool sleep_untested; /* The last endpoint map reply from that trace */ u32 sleep_epmap_last_mask; /* Higher namespaces are the firmware's, and a Flush to one faults the controller. */ @@ -356,6 +358,15 @@ module_param(flush_interval, uint, 0644); MODULE_PARM_DESC(flush_interval, "Grace period in msecs between flushes (ignored on post-M4 ANS)"); +/* + * Stop ANS for a deep sleep on a controller whose sleep path was never run (T8142). Off by + * default: the root disk stays up through a sleep the SoC refuses. + */ +static bool sleep_untested; +module_param(sleep_untested, bool, 0444); +MODULE_PARM_DESC(sleep_untested, + "Stop ANS for a deep sleep where that path is untested (default 0)"); + static_assert(sizeof(struct nvme_command) == 64); static_assert(sizeof(struct apple_nvmmu_tcb) == 128); @@ -2844,7 +2855,9 @@ static int apple_nvme_probe(struct platform_device *pdev) INIT_DELAYED_WORK(&anv->flush_dwork, apple_nvme_flush_work); - if (anv->hw->sleep_traced) { + if (anv->hw->sleep_traced && (!anv->hw->sleep_untested || sleep_untested)) { + if (anv->hw->sleep_untested) + dev_warn(anv->dev, "firmware stop for sleep enabled, untested on this SoC\n"); anv->sleep_registered = !apple_sleep_coproc_register(anv->dev, anv->mmio_coproc, true, apple_nvme_sleep_last_stop, anv); @@ -3295,6 +3308,12 @@ static const struct apple_nvme_hw apple_nvme_t8142_hw = { .has_separate_nvmmu = true, .needs_ioq_registers = true, .max_queue_depth = 64, + /* T8140's values, as T8132 runs them: never run on T8142. */ + .sleep_traced = true, + .sleep_untested = true, + .sleep_epmap_last_mask = BIT(0), + .sleep_flush_max_nsid = 1, + .sleep_shn = NVME_CC_SHN_MASK, .quirks = NVME_QUIRK_BROKEN_FUA, }; diff --git a/drivers/pci/controller/pcie-apple-msi.c b/drivers/pci/controller/pcie-apple-msi.c index d3757b6aa8704..02809d9e26c7a 100644 --- a/drivers/pci/controller/pcie-apple-msi.c +++ b/drivers/pci/controller/pcie-apple-msi.c @@ -22,6 +22,7 @@ #include #include #include +#include #define PORT_MSICFG 0x0124 #define PORT_MSICFG_EN BIT(0) @@ -35,6 +36,8 @@ struct apple_msi { struct mutex lock; struct irq_fwspec fwspec; unsigned long *bitmap; + void __iomem **ports; + unsigned int nports; u32 nvecs; }; @@ -114,6 +117,33 @@ static const struct msi_parent_ops apple_msi_parent_ops = { .init_dev_msi_info = msi_lib_init_dev_msi_info, }; +/* On every port, MSI data N goes to the Nth interrupt of msi-ranges. */ +static void apple_msi_hw_init(struct apple_msi *msi) +{ + unsigned int p, i; + + for (p = 0; p < msi->nports; p++) { + void __iomem *port = msi->ports[p]; + + writel(lower_32_bits(DOORBELL_ADDR), port + PORT_MSIADDR); + for (i = 0; i < msi->nvecs; i++) + writel(PORT_MSIMAP_ENABLE | i, port + PORT_MSIMAP + 4 * i); + writel(readl(port + PORT_MSICFG) | PORT_MSICFG_EN, port + PORT_MSICFG); + } +} + +/* The platform wake has brought the port back before device noirq resume. */ +static int apple_msi_resume_noirq(struct device *dev) +{ + if (pm_resume_via_firmware()) + apple_msi_hw_init(dev_get_drvdata(dev)); + return 0; +} + +static const struct dev_pm_ops apple_msi_pm_ops = { + .resume_noirq = apple_msi_resume_noirq, +}; + static int apple_msi_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -171,15 +201,10 @@ static int apple_msi_probe(struct platform_device *pdev) info.size = msi->nvecs; info.host_data = msi; - /* On every port, MSI data N goes to the Nth interrupt of msi-ranges. */ - while (nports--) { - void __iomem *port = ports[nports]; - - writel(lower_32_bits(DOORBELL_ADDR), port + PORT_MSIADDR); - for (i = 0; i < msi->nvecs; i++) - writel(PORT_MSIMAP_ENABLE | i, port + PORT_MSIMAP + 4 * i); - writel(readl(port + PORT_MSICFG) | PORT_MSICFG_EN, port + PORT_MSICFG); - } + msi->ports = ports; + msi->nports = nports; + platform_set_drvdata(pdev, msi); + apple_msi_hw_init(msi); if (!msi_create_parent_irq_domain(&info, &apple_msi_parent_ops)) return -ENOMEM; @@ -198,6 +223,7 @@ static struct platform_driver apple_msi_driver = { .name = "pcie-apple-msi", .of_match_table = apple_msi_of_match, .suppress_bind_attrs = true, + .pm = &apple_msi_pm_ops, }, }; builtin_platform_driver(apple_msi_driver); diff --git a/drivers/phy/apple/atc.c b/drivers/phy/apple/atc.c index e8be316134872..34d3aa12b8f4c 100644 --- a/drivers/phy/apple/atc.c +++ b/drivers/phy/apple/atc.c @@ -531,6 +531,8 @@ enum atcphy_lane_mode { #define PIPEHANDLER_NONSELECTED_OVERRIDE 0x20 #define PIPEHANDLER_NATIVE_RESET BIT(12) #define PIPEHANDLER_DUMMY_PHY_EN BIT(15) +/* Boot-owned PIPE hold, released before selecting the dummy backend. */ +#define PIPEHANDLER_NONSELECTED_BOOT_HOLD BIT(16) #define PIPEHANDLER_NATIVE_POWER_DOWN GENMASK(3, 0) #define PIPEHANDLER_LOCK_ACK_TIMEOUT_US 1000 @@ -688,6 +690,8 @@ struct apple_atcphy; * generation has none) and the SuperSpeed tunables; USB2 * still works without the latter * @park_pipe_unlocked: A stopped controller may park without a PIPE handshake + * @clear_boot_hold: Release the boot PIPE hold before dummy backend selection + * @dp_banked_tunables: DisplayPort requires separate LIOA/common calibration * @dp_t8122: DisplayPort runs the T8122 AUX, AUSPLL and lane sequences * @park_dummy_phy: Enable the dummy PIPE backend whenever the PIPE is parked on * it; the lock handshake that starts the next PIPE change is @@ -715,8 +719,10 @@ struct atcphy_hw { bool optional_tunables; bool has_t8140_dp; bool dp_t8122; + bool dp_banked_tunables; bool park_pipe_unlocked; bool park_dummy_phy; + bool clear_boot_hold; bool restore_after_pd_off; bool idle_power_off; }; @@ -865,6 +871,8 @@ struct apple_atcphy { struct apple_tunable *lane_usb4[2]; struct apple_tunable *usb2phy_reg_dflt; struct apple_tunable *usb3_dp; + struct apple_tunable *dp_lioa; + struct apple_tunable *dp_common_config; struct apple_tunable *dp_common_pre; struct apple_tunable *dp_lpdptx; struct apple_tunable *dp_common_post; @@ -977,11 +985,13 @@ struct apple_atcphy { void __iomem *pipehandler; void __iomem *lpdptx; void __iomem *pwrctl; + void __iomem *lioa; } regs; struct { struct resource *core; struct resource *lpdptx; + struct resource *lioa; struct resource *axi2af; struct resource *usb2phy_reg; } res; @@ -1822,6 +1832,9 @@ static int atcphy_configure_pipehandler_usb4(struct apple_atcphy *atcphy) */ static void atcphy_enable_dummy_phy(struct apple_atcphy *atcphy) { + if (atcphy->hw->clear_boot_hold) + clear32(atcphy->regs.pipehandler + PIPEHANDLER_NONSELECTED_OVERRIDE, + PIPEHANDLER_NONSELECTED_BOOT_HOLD); set32(atcphy->regs.pipehandler + PIPEHANDLER_NONSELECTED_OVERRIDE, PIPEHANDLER_DUMMY_PHY_EN); } @@ -4176,7 +4189,8 @@ static int atcphy_configure(struct apple_atcphy *atcphy, enum atcphy_mode mode) if (ret) return ret; } - if (atcphy->hw->has_t8140_dp && atcphy_modes[mode].enable_dp_aux && + if ((atcphy->hw->has_t8140_dp || atcphy->hw->dp_banked_tunables) && + atcphy_modes[mode].enable_dp_aux && !atcphy->dp_tunables) return -EOPNOTSUPP; if (atcphy->hw->has_t8140_dp && @@ -4247,6 +4261,10 @@ static int atcphy_configure(struct apple_atcphy *atcphy, enum atcphy_mode mode) } atcphy_apply_tunables(atcphy, mode); + if (atcphy->hw->dp_banked_tunables && atcphy_modes[mode].enable_dp_aux) { + apple_tunable_apply(atcphy->regs.lioa, atcphy->tunables.dp_lioa); + apple_tunable_apply(atcphy->regs.lpdptx, atcphy->tunables.dp_common_config); + } atcphy->hw->configure_post_tunable(atcphy, mode); /* Setup AUX channel if DP altmode is requested */ @@ -4536,6 +4554,14 @@ static int atcphy_usb2_init(struct phy *phy) if (!atcphy->fixed_usb2) { if (atcphy->mode == APPLE_ATCPHY_MODE_OFF || atcphy->mode_dirty) return atcphy_configure(atcphy, atcphy->typec_mode); + /* + * Reset assertion stops USB2 even when a DisplayPort mode keeps + * the common block running. An aborted suspend need not produce + * a new mux event: restore USB2 without disturbing the DP link. + */ + if ((readl(atcphy->regs.usb2phy + USB2PHY_USBCTL) & + USB2PHY_USBCTL_USB_MODE) != USB2PHY_USBCTL_RUN) + atcphy_usb2_power_on(atcphy); return 0; } @@ -4839,6 +4865,14 @@ static int atcphy_dpphy_validate(struct phy *phy, enum phy_mode mode, int submod if (submode != 0 && !atcphy_t8132_dp_on(atcphy)) return -EINVAL; + /* The Type-C mux owns lane setup; validate observes its completed epoch. */ + guard(mutex)(&atcphy->lock); + if (atcphy->hw->dp_t8122 && + (atcphy->mode_dirty || !atcphy->dp_t8122.aux)) { + opts->lanes = 0; + return 0; + } + switch (atcphy->mode) { case APPLE_ATCPHY_MODE_USB3_DP: opts->lanes = 2; @@ -5754,6 +5788,26 @@ static enum atcphy_mode atcphy_typec_target_mode(struct apple_atcphy *atcphy, } } + /* + * T8142 runs DisplayPort only with the boot loader's LIOA and common + * configuration banks, and the mode switch refuses a DP mode without + * them. Serve a DP Alt Mode partner's USB then, as on T8132: USB2 next + * to four DP lanes, USB3 next to two. + */ + if (atcphy->hw->dp_banked_tunables && !atcphy->dp_tunables) { + enum atcphy_mode usb_mode = target_mode; + + if (target_mode == APPLE_ATCPHY_MODE_DP) + usb_mode = APPLE_ATCPHY_MODE_USB2; + else if (target_mode == APPLE_ATCPHY_MODE_USB3_DP) + usb_mode = APPLE_ATCPHY_MODE_USB3; + if (usb_mode != target_mode) { + dev_warn(atcphy->dev, + "DisplayPort calibration missing: serving the partner's USB only\n"); + target_mode = usb_mode; + } + } + if (atcphy->hw->usb2_only && (!atcphy->t8132_ss || !atcphy->ss_tunables) && (target_mode == APPLE_ATCPHY_MODE_USB3 || target_mode == APPLE_ATCPHY_MODE_USB3_DP)) @@ -6287,6 +6341,36 @@ static int atcphy_load_t8132_tunables(struct apple_atcphy *atcphy) return 0; } +static int atcphy_load_dp_banks(struct apple_atcphy *atcphy) +{ + struct apple_tunable *lioa, *common; + + if (!atcphy->res.lioa) { + atcphy->dp_tunables = false; + return 0; + } + + lioa = devm_apple_tunable_parse(atcphy->dev, atcphy->np, + "apple,tunable-dp-lioa", atcphy->res.lioa); + common = devm_apple_tunable_parse(atcphy->dev, atcphy->np, + "apple,tunable-dp-common-config", atcphy->res.lpdptx); + if (IS_ERR(lioa) || IS_ERR(common)) { + int ret = IS_ERR(lioa) ? PTR_ERR(lioa) : PTR_ERR(common); + + if ((IS_ERR(lioa) && PTR_ERR(lioa) != -ENOENT) || + (IS_ERR(common) && PTR_ERR(common) != -ENOENT)) + return ret == -ENOENT ? PTR_ERR(common) : ret; + atcphy->dp_tunables = false; + dev_warn(atcphy->dev, "DisplayPort bank calibration missing; DP disabled\n"); + return 0; + } + if (!lioa->sz || !common->sz) + return -EINVAL; + atcphy->tunables.dp_lioa = lioa; + atcphy->tunables.dp_common_config = common; + return 0; +} + static int atcphy_load_tunables(struct apple_atcphy *atcphy) { size_t tunable_count; @@ -6399,6 +6483,12 @@ static int atcphy_load_tunables(struct apple_atcphy *atcphy) atcphy->ss_tunables = !ss_missing; if (atcphy->hw->dp_t8122) atcphy->dp_tunables = !common_missing; + if (atcphy->hw->dp_banked_tunables) { + int ret = atcphy_load_dp_banks(atcphy); + + if (ret) + return ret; + } if (atcphy->dp_only && !atcphy->dp_tunables) dev_warn(atcphy->dev, "Calibration tunables missing, DisplayPort disabled\n"); else if (ss_missing && atcphy->dp_tunables && !atcphy->dp_only) @@ -6484,6 +6574,21 @@ static int atcphy_map_resources(struct platform_device *pdev, struct apple_atcph *resources[i].res = res; } + /* + * Device trees written before DisplayPort was supported have no LIOA + * bank: the PHY then serves USB as before, without DisplayPort. + */ + res = atcphy->hw->dp_banked_tunables ? + platform_get_resource_byname(pdev, IORESOURCE_MEM, "lioa") : NULL; + if (res) { + addr = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(addr)) + return dev_err_probe(atcphy->dev, PTR_ERR(addr), + "Unable to map LIOA bank\n"); + atcphy->res.lioa = res; + atcphy->regs.lioa = addr; + } + if (atcphy->hw->has_usb2phy_reg) { res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "usb2phy-reg"); addr = devm_ioremap_resource(&pdev->dev, res); @@ -7293,8 +7398,9 @@ static int atcphy_suspend_noirq(struct device *dev) */ static void atcphy_sleep_lost_common(struct apple_atcphy *atcphy) { - if (!atcphy->hw->has_t8140_dp || !atcphy->hw->restore_after_pd_off || - !pm_resume_via_firmware()) + if ((!atcphy->hw->has_t8140_dp && + !of_device_is_compatible(atcphy->np, "apple,t8142-atcphy")) || + !atcphy->hw->restore_after_pd_off || !pm_resume_via_firmware()) return; WRITE_ONCE(atcphy->pd_was_off, true); dev_dbg(atcphy->dev, "mode %d lost in the sleep: setting it up again\n", atcphy->mode); @@ -7870,6 +7976,11 @@ static const struct atcphy_hw atcphy_hw_t8142 = { .pipe_mux_clk = PIPEHANDLER_MUX_CTRL_CLK_T8142, .pipe_mux_data = PIPEHANDLER_MUX_CTRL_DATA_T8142, .has_usb4 = true, + .dp_t8122 = true, + .dp_banked_tunables = true, + .park_dummy_phy = true, + .restore_after_pd_off = true, + .clear_boot_hold = true, }; static const struct of_device_id atcphy_match[] = { diff --git a/drivers/pinctrl/pinctrl-apple-gpio.c b/drivers/pinctrl/pinctrl-apple-gpio.c index 3e8ab5a9b933b..2f0c25e38c67f 100644 --- a/drivers/pinctrl/pinctrl-apple-gpio.c +++ b/drivers/pinctrl/pinctrl-apple-gpio.c @@ -315,6 +315,13 @@ static void apple_gpio_irq_mask(struct irq_data *data) gpiochip_disable_irq(gc, data->hwirq); } +static void apple_gpio_irq_mask_ack(struct irq_data *data) +{ + /* Resume can leave the pin enabled while the IRQ core still has it masked. */ + apple_gpio_irq_mask(data); + apple_gpio_irq_ack(data); +} + static void apple_gpio_irq_unmask(struct irq_data *data) { struct gpio_chip *gc = irq_data_get_irq_chip_data(data); @@ -382,6 +389,7 @@ static const struct irq_chip apple_gpio_irqchip = { .name = "Apple-GPIO", .irq_startup = apple_gpio_irq_startup, .irq_ack = apple_gpio_irq_ack, + .irq_mask_ack = apple_gpio_irq_mask_ack, .irq_mask = apple_gpio_irq_mask, .irq_unmask = apple_gpio_irq_unmask, .irq_set_type = apple_gpio_irq_set_type, diff --git a/drivers/pmdomain/apple/pmc.c b/drivers/pmdomain/apple/pmc.c index 586e3f675db9e..e93dc40bc10c1 100644 --- a/drivers/pmdomain/apple/pmc.c +++ b/drivers/pmdomain/apple/pmc.c @@ -1553,6 +1553,12 @@ static int apple_pmc_resume_early(struct device *dev) ret = ret ?: err; } } + /* + * The AP agent's word also holds its DCS vote, which a deep sleep's commit zeroes + * (apple-sleep, T8132 and T8142). Cast it again: a no-op if it stayed. + */ + if (!(pmc->floor_rails & BIT(pmc->hw->dcs_rail))) + apple_pmc_dcs_vote(pmc); raw_spin_unlock_irqrestore(&pmc->lock, flags); if (ret) dev_err(dev, "state not restored after sleep: %d\n", ret); diff --git a/drivers/soc/apple/mcc.c b/drivers/soc/apple/mcc.c index a13f8b85eb4eb..ae15c4ea54e1b 100644 --- a/drivers/soc/apple/mcc.c +++ b/drivers/soc/apple/mcc.c @@ -29,6 +29,7 @@ #define MCC_CACHE_WAYS_ENABLED GENMASK(4, 0) #define MCC_CACHE_POWER 0x2804 #define MCC_CACHE_WAYS_POWERED GENMASK(30, 24) +#define MCC_CACHE_TAGS_POWERED GENMASK(14, 8) #define MCC_CACHE_FLUSH 0x2844 #define MCC_CACHE_FLUSH_BUSY BIT(0) @@ -41,6 +42,12 @@ struct apple_mcc { unsigned int nr_planes; bool enabled; bool retained; + /* + * T8142: a deep sleep also turns the cache's ways off, as AppleT8142MCC's sleep action + * does, and the wake puts the boot's way count back. + */ + bool ways_off; + u32 ways; /* Turned off for a deep sleep, to be turned back on after it. */ bool sleep_disabled; }; @@ -183,6 +190,34 @@ static void apple_mcc_disable_planes(struct apple_mcc *mcc, unsigned int count) dev_err(mcc->dev, "plane %u flush timed out\n", i); } +/* + * AppleT8142MCC's mccEnableCacheMode and aura's cold-boot enable: every plane's way count, + * then each plane's data and tag ways (0x2804 [30:24] and [14:8]) waited for until both + * read it. macOS waits without a limit. + */ +static int apple_mcc_set_ways(struct apple_mcc *mcc, u32 ways) +{ + unsigned int i; + u32 val; + int ret; + + for (i = 0; i < mcc->nr_planes; i++) + apple_mcc_writel(mcc, i, ways, MCC_CACHE_WAYS); + + for (i = 0; i < mcc->nr_planes; i++) { + ret = readl_poll_timeout_atomic(mcc->planes[i] + MCC_CACHE_POWER, val, + FIELD_GET(MCC_CACHE_WAYS_POWERED, val) == ways && + FIELD_GET(MCC_CACHE_TAGS_POWERED, val) == ways, + 10, MCC_FLUSH_TIMEOUT_US); + if (ret) { + dev_err(mcc->dev, "plane %u ways did not reach %u: %#x\n", i, ways, val); + return ret; + } + } + + return 0; +} + static int apple_mcc_enable(struct apple_mcc *mcc) { unsigned int i; @@ -229,6 +264,7 @@ static int apple_mcc_probe(struct platform_device *pdev) mcc->dev = dev; mcc->retained = of_device_is_compatible(dev->of_node, "apple,t8132-mcc"); + mcc->ways_off = of_device_is_compatible(dev->of_node, "apple,t8142-mcc"); while (platform_get_resource(pdev, IORESOURCE_MEM, mcc->nr_planes)) { struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, mcc->nr_planes); @@ -258,6 +294,9 @@ static int apple_mcc_probe(struct platform_device *pdev) return ret; mcc->enabled = true; + if (mcc->ways_off) + mcc->ways = FIELD_GET(MCC_CACHE_WAYS_ENABLED, + readl(mcc->planes[0] + MCC_CACHE_WAYS)); dev_info(dev, "system level cache allocation enabled on %u planes\n", mcc->nr_planes); return 0; } @@ -306,6 +345,14 @@ static int apple_mcc_suspend_noirq(struct device *dev) if (!mcc->enabled) return 0; apple_mcc_quiesce(mcc); + /* + * T8142 has no skip-mcc-off-to-s2r (only T8140's J700 does), so macOS turns the ways + * off before the sleep: way count 0. The flush above (the kext's own cacheFlush) has + * written everything back already, so a timeout here loses nothing and only leaves + * the ways as they were. + */ + if (mcc->ways_off && mcc->ways) + apple_mcc_set_ways(mcc, 0); mcc->sleep_disabled = true; return 0; @@ -319,6 +366,10 @@ static int apple_mcc_resume_noirq(struct device *dev) if (!mcc->sleep_disabled) return 0; mcc->sleep_disabled = false; + /* The way count the boot set, back (it reads 0 after the power loss, or after the above). */ + if (mcc->ways_off && mcc->ways && + FIELD_GET(MCC_CACHE_WAYS_ENABLED, readl(mcc->planes[0] + MCC_CACHE_WAYS)) != mcc->ways) + apple_mcc_set_ways(mcc, mcc->ways); /* Only a performance setting: a cache not ready after the wake stays off. */ ret = mcc->retained ? apple_mcc_enable_t8132(mcc) : apple_mcc_enable(mcc); mcc->enabled = !ret; @@ -335,6 +386,7 @@ static const struct dev_pm_ops apple_mcc_pm_ops = { static const struct of_device_id apple_mcc_of_match[] = { { .compatible = "apple,t8132-mcc" }, { .compatible = "apple,t8140-mcc" }, + { .compatible = "apple,t8142-mcc" }, {} }; MODULE_DEVICE_TABLE(of, apple_mcc_of_match); diff --git a/drivers/soc/apple/profile.rs b/drivers/soc/apple/profile.rs index f809e18433557..87904639a780f 100644 --- a/drivers/soc/apple/profile.rs +++ b/drivers/soc/apple/profile.rs @@ -713,8 +713,9 @@ fn select( if has(b"apple,t8132") && (has(b"apple,j713") || has(b"apple,j715")) { return Ok(&T8132); } - // Only the J815, whose ADT was read; the J813's sensor bus is unchecked. - if has(b"apple,t8142") && has(b"apple,j815") { + // The J815 and the J813, whose ADTs were read: both have the sensor (mesa) on spi2 + // at 0x3a5108000. + if has(b"apple,t8142") && (has(b"apple,j815") || has(b"apple,j813")) { return Ok(&T8142); } Err(ENODEV) diff --git a/drivers/soc/apple/sleep-t8142-mem.h b/drivers/soc/apple/sleep-t8142-mem.h new file mode 100644 index 0000000000000..5b7a51ba8e1a1 --- /dev/null +++ b/drivers/soc/apple/sleep-t8142-mem.h @@ -0,0 +1,1141 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ +/* + * T8142: XNU's AppleT8142MCC start as macOS 27.2 runs it on the J813 (trace g01, 2026-11-16), + * every memory-side access in its order: op bit 0 write, bit 1 64-bit, bit 4 a read that comes + * before the first write of its word (iBoot's value: the fingerprint). Included by sleep.c. + */ +/* Generated from the J813 trace g01 (XNU's AppleT8142MCC start, -218749 .. -218594 ms): 1120 records */ +static const u64 t8142_mem_pages[] = { + 0x220008000ULL, 0x220028000ULL, 0x22002c000ULL, 0x220068000ULL, + 0x22006c000ULL, 0x2200a8000ULL, 0x2200ac000ULL, 0x2200e8000ULL, + 0x2200ec000ULL, 0x221000000ULL, 0x221004000ULL, 0x221200000ULL, + 0x221204000ULL, 0x221400000ULL, 0x221404000ULL, 0x221600000ULL, + 0x221604000ULL, 0x221800000ULL, 0x221804000ULL, 0x221a00000ULL, + 0x221c00000ULL, 0x221e00000ULL, 0x24f010000ULL, 0x24f014000ULL, + 0x250010000ULL, 0x250014000ULL, 0x251010000ULL, 0x251014000ULL, + 0x252010000ULL, 0x252014000ULL, 0x253010000ULL, 0x253014000ULL, + 0x254010000ULL, 0x254014000ULL, +}; + +static const struct t8142_mem_op t8142_mem_boot[] = { + { 0x221001d50, 0x2400240, 0x0 }, + { 0x221201d50, 0x2400240, 0x0 }, + { 0x221401d50, 0x2400240, 0x0 }, + { 0x221601d50, 0x2400240, 0x0 }, + { 0x221801d50, 0x2400240, 0x0 }, + { 0x221a01d50, 0x2400240, 0x0 }, + { 0x221c01d50, 0x2400240, 0x0 }, + { 0x221e01d50, 0x2400240, 0x0 }, + { 0x22000a034, 0x8, 0x0 }, + { 0x22000a038, 0x10, 0x0 }, + { 0x22000a038, 0x10, 0x0 }, + { 0x22000a03c, 0x20, 0x0 }, + { 0x22000a03c, 0x20, 0x0 }, + { 0x22000a03c, 0x20, 0x0 }, + { 0x22000a008, 0x20, 0x0 }, + { 0x22000a008, 0x20, 0x0 }, + { 0x22000a01c, 0x20, 0x0 }, + { 0x22000a020, 0xa, 0x0 }, + { 0x22000a02c, 0x20, 0x0 }, + { 0x22000a044, 0x10, 0x0 }, + { 0x22000a04c, 0x20, 0x0 }, + { 0x22000a054, 0x20, 0x0 }, + { 0x22000a07c, 0x10, 0x0 }, + { 0x22000a040, 0x10, 0x0 }, + { 0x22000a00c, 0x20, 0x0 }, + { 0x22000a010, 0x20, 0x0 }, + { 0x22000a014, 0x20, 0x0 }, + { 0x22000a018, 0x20, 0x0 }, + { 0x22000a078, 0x20, 0x0 }, + { 0x22000a024, 0x20, 0x0 }, + { 0x22000a030, 0x8, 0x0 }, + { 0x22000a058, 0x20, 0x0 }, + { 0x22000a058, 0x20, 0x0 }, + { 0x22000a058, 0x20, 0x0 }, + { 0x22000a000, 0x20, 0x0 }, + { 0x22000a000, 0x20, 0x0 }, + { 0x22000a000, 0x20, 0x0 }, + { 0x22000a000, 0x20, 0x0 }, + { 0x22000a004, 0x4, 0x0 }, + { 0x22000a004, 0x4, 0x0 }, + { 0x22000a004, 0x4, 0x0 }, + { 0x22000a074, 0x4, 0x0 }, + { 0x22000a060, 0x4, 0x0 }, + { 0x22000a068, 0x4, 0x0 }, + { 0x22000a070, 0x4, 0x0 }, + { 0x22000a050, 0x20, 0x0 }, + { 0x22000a06c, 0x4, 0x0 }, + { 0x22000a05c, 0x4, 0x0 }, + { 0x22000a05c, 0x4, 0x0 }, + { 0x22000a05c, 0x4, 0x0 }, + { 0x22000a05c, 0x4, 0x0 }, + { 0x22000a064, 0x4, 0x0 }, + { 0x22000a064, 0x4, 0x0 }, + { 0x22000a060, 0x4, 0x0 }, + { 0x220069008, 0x0, 0x2 }, + { 0x220068000, 0x0, 0x12 }, + { 0x220068000, 0x2, 0x3 }, + { 0x220069010, 0x0, 0x2 }, + { 0x220068000, 0x2, 0x2 }, + { 0x220068000, 0x6, 0x3 }, + { 0x2200a9028, 0x0, 0x2 }, + { 0x2200a8000, 0x0, 0x12 }, + { 0x2200a8000, 0x20, 0x3 }, + { 0x2200a9030, 0x0, 0x2 }, + { 0x2200a8000, 0x20, 0x2 }, + { 0x2200a8000, 0x60, 0x3 }, + { 0x220069028, 0x0, 0x2 }, + { 0x220068000, 0x6, 0x2 }, + { 0x220068000, 0x26, 0x3 }, + { 0x220069030, 0x0, 0x2 }, + { 0x220068000, 0x26, 0x2 }, + { 0x220068000, 0x66, 0x3 }, + { 0x220029018, 0x0, 0x2 }, + { 0x220028000, 0x0, 0x12 }, + { 0x220028000, 0x8, 0x3 }, + { 0x220029020, 0x0, 0x2 }, + { 0x220028000, 0x8, 0x2 }, + { 0x220028000, 0x18, 0x3 }, + { 0x220069038, 0x0, 0x2 }, + { 0x220068000, 0x66, 0x2 }, + { 0x220068000, 0xe6, 0x3 }, + { 0x220069040, 0x0, 0x2 }, + { 0x220068000, 0xe6, 0x2 }, + { 0x220068000, 0x1e6, 0x3 }, + { 0x220029008, 0x0, 0x2 }, + { 0x220028000, 0x18, 0x2 }, + { 0x220028000, 0x1a, 0x3 }, + { 0x220029010, 0x0, 0x2 }, + { 0x220028000, 0x1a, 0x2 }, + { 0x220028000, 0x1e, 0x3 }, + { 0x220069018, 0x0, 0x2 }, + { 0x220068000, 0x1e6, 0x2 }, + { 0x220068000, 0x1ee, 0x3 }, + { 0x220069020, 0x0, 0x2 }, + { 0x220068000, 0x1ee, 0x2 }, + { 0x220068000, 0x1fe, 0x3 }, + { 0x2200a9038, 0x0, 0x2 }, + { 0x2200a8000, 0x60, 0x2 }, + { 0x2200a8000, 0xe0, 0x3 }, + { 0x2200a9040, 0x0, 0x2 }, + { 0x2200a8000, 0xe0, 0x2 }, + { 0x2200a8000, 0x1e0, 0x3 }, + { 0x220029038, 0x0, 0x2 }, + { 0x220028000, 0x1e, 0x2 }, + { 0x220028000, 0x9e, 0x3 }, + { 0x220029040, 0x0, 0x2 }, + { 0x220028000, 0x9e, 0x2 }, + { 0x220028000, 0x19e, 0x3 }, + { 0x2200a9018, 0x0, 0x2 }, + { 0x2200a8000, 0x1e0, 0x2 }, + { 0x2200a8000, 0x1e8, 0x3 }, + { 0x2200a9020, 0x0, 0x2 }, + { 0x2200a8000, 0x1e8, 0x2 }, + { 0x2200a8000, 0x1f8, 0x3 }, + { 0x220029028, 0x0, 0x2 }, + { 0x220028000, 0x19e, 0x2 }, + { 0x220028000, 0x1be, 0x3 }, + { 0x220029030, 0x0, 0x2 }, + { 0x220028000, 0x1be, 0x2 }, + { 0x220028000, 0x1fe, 0x3 }, + { 0x2200a9008, 0x0, 0x2 }, + { 0x2200a8000, 0x1f8, 0x2 }, + { 0x2200a8000, 0x1fa, 0x3 }, + { 0x2200a9010, 0x0, 0x2 }, + { 0x2200a8000, 0x1fa, 0x2 }, + { 0x2200a8000, 0x1fe, 0x3 }, + { 0x24f014000, 0x0, 0x2 }, + { 0x24f010000, 0x3, 0x1 }, + { 0x24f010100, 0x1, 0x1 }, + { 0x24f014008, 0x0, 0x2 }, + { 0x24f010004, 0x3, 0x1 }, + { 0x24f010100, 0x1, 0x1 }, + { 0x24f014010, 0x0, 0x2 }, + { 0x24f010008, 0x3, 0x1 }, + { 0x24f010100, 0x1, 0x1 }, + { 0x24f014018, 0x0, 0x2 }, + { 0x24f01000c, 0x3, 0x1 }, + { 0x24f010100, 0x1, 0x1 }, + { 0x24f014020, 0x0, 0x2 }, + { 0x24f010010, 0x3, 0x1 }, + { 0x24f010100, 0x1, 0x1 }, + { 0x24f014028, 0x0, 0x2 }, + { 0x24f010014, 0x3, 0x1 }, + { 0x24f010100, 0x1, 0x1 }, + { 0x24f014030, 0x0, 0x2 }, + { 0x24f010018, 0x3, 0x1 }, + { 0x24f010100, 0x1, 0x1 }, + { 0x24f014038, 0x0, 0x2 }, + { 0x24f01001c, 0x3, 0x1 }, + { 0x24f010100, 0x1, 0x1 }, + { 0x24f014040, 0x0, 0x2 }, + { 0x24f010020, 0x3, 0x1 }, + { 0x24f010100, 0x1, 0x1 }, + { 0x24f014048, 0x0, 0x2 }, + { 0x24f010024, 0x3, 0x1 }, + { 0x24f010100, 0x1, 0x1 }, + { 0x24f014050, 0x0, 0x2 }, + { 0x24f010028, 0x3, 0x1 }, + { 0x24f010100, 0x1, 0x1 }, + { 0x24f014058, 0x0, 0x2 }, + { 0x24f01002c, 0x3, 0x1 }, + { 0x24f010100, 0x1, 0x1 }, + { 0x24f014060, 0x0, 0x2 }, + { 0x24f010030, 0x3, 0x1 }, + { 0x24f010100, 0x1, 0x1 }, + { 0x24f014068, 0x0, 0x2 }, + { 0x24f010034, 0x3, 0x1 }, + { 0x24f010100, 0x1, 0x1 }, + { 0x24f014070, 0x0, 0x2 }, + { 0x24f010038, 0x3, 0x1 }, + { 0x24f010100, 0x1, 0x1 }, + { 0x250014000, 0x0, 0x2 }, + { 0x250010000, 0x3, 0x1 }, + { 0x250010100, 0x1, 0x1 }, + { 0x250014008, 0x0, 0x2 }, + { 0x250010004, 0x3, 0x1 }, + { 0x250010100, 0x1, 0x1 }, + { 0x250014010, 0x0, 0x2 }, + { 0x250010008, 0x3, 0x1 }, + { 0x250010100, 0x1, 0x1 }, + { 0x250014018, 0x0, 0x2 }, + { 0x25001000c, 0x3, 0x1 }, + { 0x250010100, 0x1, 0x1 }, + { 0x250014020, 0x0, 0x2 }, + { 0x250010010, 0x3, 0x1 }, + { 0x250010100, 0x1, 0x1 }, + { 0x250014028, 0x0, 0x2 }, + { 0x250010014, 0x3, 0x1 }, + { 0x250010100, 0x1, 0x1 }, + { 0x250014030, 0x0, 0x2 }, + { 0x250010018, 0x3, 0x1 }, + { 0x250010100, 0x1, 0x1 }, + { 0x250014038, 0x0, 0x2 }, + { 0x25001001c, 0x3, 0x1 }, + { 0x250010100, 0x1, 0x1 }, + { 0x250014040, 0x0, 0x2 }, + { 0x250010020, 0x3, 0x1 }, + { 0x250010100, 0x1, 0x1 }, + { 0x250014048, 0x0, 0x2 }, + { 0x250010024, 0x3, 0x1 }, + { 0x250010100, 0x1, 0x1 }, + { 0x250014050, 0x0, 0x2 }, + { 0x250010028, 0x3, 0x1 }, + { 0x250010100, 0x1, 0x1 }, + { 0x250014058, 0x0, 0x2 }, + { 0x25001002c, 0x3, 0x1 }, + { 0x250010100, 0x1, 0x1 }, + { 0x250014060, 0x0, 0x2 }, + { 0x250010030, 0x3, 0x1 }, + { 0x250010100, 0x1, 0x1 }, + { 0x250014068, 0x0, 0x2 }, + { 0x250010034, 0x3, 0x1 }, + { 0x250010100, 0x1, 0x1 }, + { 0x250014070, 0x0, 0x2 }, + { 0x250010038, 0x3, 0x1 }, + { 0x250010100, 0x1, 0x1 }, + { 0x250014078, 0x0, 0x2 }, + { 0x25001003c, 0x3, 0x1 }, + { 0x250010100, 0x1, 0x1 }, + { 0x251014000, 0x0, 0x2 }, + { 0x251010000, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014008, 0x0, 0x2 }, + { 0x251010004, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014010, 0x0, 0x2 }, + { 0x251010008, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014018, 0x0, 0x2 }, + { 0x25101000c, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014020, 0x0, 0x2 }, + { 0x251010010, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014028, 0x0, 0x2 }, + { 0x251010014, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014030, 0x0, 0x2 }, + { 0x251010018, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014038, 0x0, 0x2 }, + { 0x25101001c, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014040, 0x0, 0x2 }, + { 0x251010020, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014048, 0x0, 0x2 }, + { 0x251010024, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014050, 0x0, 0x2 }, + { 0x251010028, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014058, 0x0, 0x2 }, + { 0x25101002c, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014060, 0x0, 0x2 }, + { 0x251010030, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014068, 0x0, 0x2 }, + { 0x251010034, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014070, 0x0, 0x2 }, + { 0x251010038, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014078, 0x0, 0x2 }, + { 0x25101003c, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014080, 0x0, 0x2 }, + { 0x251010040, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014088, 0x0, 0x2 }, + { 0x251010044, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014090, 0x0, 0x2 }, + { 0x251010048, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x251014098, 0x0, 0x2 }, + { 0x25101004c, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x2510140a0, 0x0, 0x2 }, + { 0x251010050, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x2510140a8, 0x0, 0x2 }, + { 0x251010054, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x2510140b0, 0x0, 0x2 }, + { 0x251010058, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x2510140b8, 0x0, 0x2 }, + { 0x25101005c, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x2510140c0, 0x0, 0x2 }, + { 0x251010060, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x2510140c8, 0x0, 0x2 }, + { 0x251010064, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x2510140d0, 0x0, 0x2 }, + { 0x251010068, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x2510140d8, 0x0, 0x2 }, + { 0x25101006c, 0x3, 0x1 }, + { 0x251010100, 0x1, 0x1 }, + { 0x252014000, 0x0, 0x2 }, + { 0x252010000, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014008, 0x0, 0x2 }, + { 0x252010004, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014010, 0x0, 0x2 }, + { 0x252010008, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014018, 0x0, 0x2 }, + { 0x25201000c, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014020, 0x0, 0x2 }, + { 0x252010010, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014028, 0x0, 0x2 }, + { 0x252010014, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014030, 0x0, 0x2 }, + { 0x252010018, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014038, 0x0, 0x2 }, + { 0x25201001c, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014040, 0x0, 0x2 }, + { 0x252010020, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014048, 0x0, 0x2 }, + { 0x252010024, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014050, 0x0, 0x2 }, + { 0x252010028, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014058, 0x0, 0x2 }, + { 0x25201002c, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014060, 0x0, 0x2 }, + { 0x252010030, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014068, 0x0, 0x2 }, + { 0x252010034, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014070, 0x0, 0x2 }, + { 0x252010038, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014078, 0x0, 0x2 }, + { 0x25201003c, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014080, 0x0, 0x2 }, + { 0x252010040, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014088, 0x0, 0x2 }, + { 0x252010044, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014090, 0x0, 0x2 }, + { 0x252010048, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x252014098, 0x0, 0x2 }, + { 0x25201004c, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x2520140a0, 0x0, 0x2 }, + { 0x252010050, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x2520140a8, 0x0, 0x2 }, + { 0x252010054, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x2520140b0, 0x0, 0x2 }, + { 0x252010058, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x2520140b8, 0x0, 0x2 }, + { 0x25201005c, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x2520140c0, 0x0, 0x2 }, + { 0x252010060, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x2520140c8, 0x0, 0x2 }, + { 0x252010064, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x2520140d0, 0x0, 0x2 }, + { 0x252010068, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x2520140d8, 0x0, 0x2 }, + { 0x25201006c, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x2520140e0, 0x0, 0x2 }, + { 0x252010070, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x2520140e8, 0x0, 0x2 }, + { 0x252010074, 0x3, 0x1 }, + { 0x252010100, 0x1, 0x1 }, + { 0x253014000, 0x0, 0x2 }, + { 0x253010000, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014008, 0x0, 0x2 }, + { 0x253010004, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014010, 0x0, 0x2 }, + { 0x253010008, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014018, 0x0, 0x2 }, + { 0x25301000c, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014020, 0x0, 0x2 }, + { 0x253010010, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014028, 0x0, 0x2 }, + { 0x253010014, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014030, 0x0, 0x2 }, + { 0x253010018, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014038, 0x0, 0x2 }, + { 0x25301001c, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014040, 0x0, 0x2 }, + { 0x253010020, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014048, 0x0, 0x2 }, + { 0x253010024, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014050, 0x0, 0x2 }, + { 0x253010028, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014058, 0x0, 0x2 }, + { 0x25301002c, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014060, 0x0, 0x2 }, + { 0x253010030, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014068, 0x0, 0x2 }, + { 0x253010034, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014070, 0x0, 0x2 }, + { 0x253010038, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014078, 0x0, 0x2 }, + { 0x25301003c, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014080, 0x0, 0x2 }, + { 0x253010040, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014088, 0x0, 0x2 }, + { 0x253010044, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014090, 0x0, 0x2 }, + { 0x253010048, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x253014098, 0x0, 0x2 }, + { 0x25301004c, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x2530140a0, 0x0, 0x2 }, + { 0x253010050, 0x3, 0x1 }, + { 0x253010100, 0x1, 0x1 }, + { 0x254014000, 0x0, 0x2 }, + { 0x254010000, 0x3, 0x1 }, + { 0x254010100, 0x1, 0x1 }, + { 0x254014008, 0x0, 0x2 }, + { 0x254010004, 0x3, 0x1 }, + { 0x254010100, 0x1, 0x1 }, + { 0x254014010, 0x0, 0x2 }, + { 0x254010008, 0x3, 0x1 }, + { 0x254010100, 0x1, 0x1 }, + { 0x254014018, 0x0, 0x2 }, + { 0x25401000c, 0x3, 0x1 }, + { 0x254010100, 0x1, 0x1 }, + { 0x254014020, 0x0, 0x2 }, + { 0x254010010, 0x3, 0x1 }, + { 0x254010100, 0x1, 0x1 }, + { 0x254014028, 0x0, 0x2 }, + { 0x254010014, 0x3, 0x1 }, + { 0x254010100, 0x1, 0x1 }, + { 0x254014030, 0x0, 0x2 }, + { 0x254010018, 0x3, 0x1 }, + { 0x254010100, 0x1, 0x1 }, + { 0x254014038, 0x0, 0x2 }, + { 0x25401001c, 0x3, 0x1 }, + { 0x254010100, 0x1, 0x1 }, + { 0x254014040, 0x0, 0x2 }, + { 0x254010020, 0x3, 0x1 }, + { 0x254010100, 0x1, 0x1 }, + { 0x254014048, 0x0, 0x2 }, + { 0x254010024, 0x3, 0x1 }, + { 0x254010100, 0x1, 0x1 }, + { 0x254014050, 0x0, 0x2 }, + { 0x254010028, 0x3, 0x1 }, + { 0x254010100, 0x1, 0x1 }, + { 0x254014058, 0x0, 0x2 }, + { 0x25401002c, 0x3, 0x1 }, + { 0x254010100, 0x1, 0x1 }, + { 0x254014060, 0x0, 0x2 }, + { 0x254010030, 0x3, 0x1 }, + { 0x254010100, 0x1, 0x1 }, + { 0x254014068, 0x0, 0x2 }, + { 0x254010034, 0x3, 0x1 }, + { 0x254010100, 0x1, 0x1 }, + { 0x221000590, 0x3ff001a, 0x1 }, + { 0x221000594, 0x0, 0x1 }, + { 0x221000598, 0x33, 0x1 }, + { 0x22100059c, 0x0, 0x1 }, + { 0x2210005a0, 0x0, 0x1 }, + { 0x2210005a4, 0x1ff, 0x1 }, + { 0x221004000, 0x0, 0x2 }, + { 0x221000580, 0x0, 0x10 }, + { 0x221000580, 0x11, 0x1 }, + { 0x221000584, 0x0, 0x10 }, + { 0x221000584, 0x1, 0x1 }, + { 0x2210005a8, 0x3ff001a, 0x1 }, + { 0x2210005ac, 0x0, 0x1 }, + { 0x2210005b0, 0x31, 0x1 }, + { 0x2210005b4, 0x0, 0x1 }, + { 0x2210005b8, 0x0, 0x1 }, + { 0x2210005bc, 0x1ff, 0x1 }, + { 0x221004008, 0x0, 0x2 }, + { 0x221000580, 0x11, 0x0 }, + { 0x221000580, 0x31, 0x1 }, + { 0x221000584, 0x1, 0x0 }, + { 0x221000584, 0x3, 0x1 }, + { 0x2210005c0, 0x3ff001a, 0x1 }, + { 0x2210005c4, 0x0, 0x1 }, + { 0x2210005c8, 0x31, 0x1 }, + { 0x2210005cc, 0x0, 0x1 }, + { 0x2210005d0, 0x0, 0x1 }, + { 0x2210005d4, 0x2, 0x1 }, + { 0x221004010, 0x0, 0x2 }, + { 0x221000580, 0x31, 0x0 }, + { 0x221000580, 0x71, 0x1 }, + { 0x221000584, 0x3, 0x0 }, + { 0x221000584, 0x7, 0x1 }, + { 0x2210005d8, 0x3ff001a, 0x1 }, + { 0x2210005dc, 0x0, 0x1 }, + { 0x2210005e0, 0x31, 0x1 }, + { 0x2210005e4, 0x0, 0x1 }, + { 0x2210005e8, 0x0, 0x1 }, + { 0x2210005ec, 0x4, 0x1 }, + { 0x221004018, 0x0, 0x2 }, + { 0x221000580, 0x71, 0x0 }, + { 0x221000580, 0xf1, 0x1 }, + { 0x221000584, 0x7, 0x0 }, + { 0x221000584, 0xf, 0x1 }, + { 0x2210005f0, 0x3ff001a, 0x1 }, + { 0x2210005f4, 0x0, 0x1 }, + { 0x2210005f8, 0x31, 0x1 }, + { 0x2210005fc, 0x0, 0x1 }, + { 0x221000600, 0x0, 0x1 }, + { 0x221000604, 0x8, 0x1 }, + { 0x221004020, 0x0, 0x2 }, + { 0x221000580, 0xf1, 0x0 }, + { 0x221000580, 0x1f1, 0x1 }, + { 0x221000584, 0xf, 0x0 }, + { 0x221000584, 0x1f, 0x1 }, + { 0x221000608, 0x3ff001a, 0x1 }, + { 0x22100060c, 0x0, 0x1 }, + { 0x221000610, 0x31, 0x1 }, + { 0x221000614, 0x0, 0x1 }, + { 0x221000618, 0x0, 0x1 }, + { 0x22100061c, 0x10, 0x1 }, + { 0x221004028, 0x0, 0x2 }, + { 0x221000580, 0x1f1, 0x0 }, + { 0x221000580, 0x3f1, 0x1 }, + { 0x221000584, 0x1f, 0x0 }, + { 0x221000584, 0x3f, 0x1 }, + { 0x221000620, 0x3ff001a, 0x1 }, + { 0x221000624, 0x0, 0x1 }, + { 0x221000628, 0x31, 0x1 }, + { 0x22100062c, 0x0, 0x1 }, + { 0x221000630, 0x0, 0x1 }, + { 0x221000634, 0x20, 0x1 }, + { 0x221004030, 0x0, 0x2 }, + { 0x221000580, 0x3f1, 0x0 }, + { 0x221000580, 0x7f1, 0x1 }, + { 0x221000584, 0x3f, 0x0 }, + { 0x221000584, 0x7f, 0x1 }, + { 0x221000638, 0x3ff001a, 0x1 }, + { 0x22100063c, 0x0, 0x1 }, + { 0x221000640, 0x31, 0x1 }, + { 0x221000644, 0x0, 0x1 }, + { 0x221000648, 0x0, 0x1 }, + { 0x22100064c, 0x40, 0x1 }, + { 0x221004038, 0x0, 0x2 }, + { 0x221000580, 0x7f1, 0x0 }, + { 0x221000580, 0xff1, 0x1 }, + { 0x221000584, 0x7f, 0x0 }, + { 0x221000584, 0xff, 0x1 }, + { 0x221000650, 0x3ff001a, 0x1 }, + { 0x221000654, 0x0, 0x1 }, + { 0x221000658, 0x31, 0x1 }, + { 0x22100065c, 0x0, 0x1 }, + { 0x221000660, 0x0, 0x1 }, + { 0x221000664, 0x80, 0x1 }, + { 0x221004040, 0x0, 0x2 }, + { 0x221000580, 0xff1, 0x0 }, + { 0x221000580, 0x1ff1, 0x1 }, + { 0x221000584, 0xff, 0x0 }, + { 0x221000584, 0x1ff, 0x1 }, + { 0x221000668, 0x3ff001a, 0x1 }, + { 0x22100066c, 0x0, 0x1 }, + { 0x221000670, 0x31, 0x1 }, + { 0x221000674, 0x0, 0x1 }, + { 0x221000678, 0x0, 0x1 }, + { 0x22100067c, 0x100, 0x1 }, + { 0x221004048, 0x0, 0x2 }, + { 0x221000580, 0x1ff1, 0x0 }, + { 0x221000580, 0x3ff1, 0x1 }, + { 0x221000584, 0x1ff, 0x0 }, + { 0x221000584, 0x3ff, 0x1 }, + { 0x221200590, 0x3ff001a, 0x1 }, + { 0x221200594, 0x0, 0x1 }, + { 0x221200598, 0x32, 0x1 }, + { 0x22120059c, 0x0, 0x1 }, + { 0x2212005a0, 0x0, 0x1 }, + { 0x2212005a4, 0x1ff, 0x1 }, + { 0x221204000, 0x0, 0x2 }, + { 0x221200580, 0x0, 0x10 }, + { 0x221200580, 0x11, 0x1 }, + { 0x221200584, 0x0, 0x10 }, + { 0x221200584, 0x1, 0x1 }, + { 0x2212005a8, 0x3ff001a, 0x1 }, + { 0x2212005ac, 0x0, 0x1 }, + { 0x2212005b0, 0x32, 0x1 }, + { 0x2212005b4, 0x0, 0x1 }, + { 0x2212005b8, 0x0, 0x1 }, + { 0x2212005bc, 0x2, 0x1 }, + { 0x221204008, 0x0, 0x2 }, + { 0x221200580, 0x11, 0x0 }, + { 0x221200580, 0x31, 0x1 }, + { 0x221200584, 0x1, 0x0 }, + { 0x221200584, 0x3, 0x1 }, + { 0x2212005c0, 0x3ff001a, 0x1 }, + { 0x2212005c4, 0x0, 0x1 }, + { 0x2212005c8, 0x32, 0x1 }, + { 0x2212005cc, 0x0, 0x1 }, + { 0x2212005d0, 0x0, 0x1 }, + { 0x2212005d4, 0x4, 0x1 }, + { 0x221204010, 0x0, 0x2 }, + { 0x221200580, 0x31, 0x0 }, + { 0x221200580, 0x71, 0x1 }, + { 0x221200584, 0x3, 0x0 }, + { 0x221200584, 0x7, 0x1 }, + { 0x2212005d8, 0x3ff001a, 0x1 }, + { 0x2212005dc, 0x0, 0x1 }, + { 0x2212005e0, 0x32, 0x1 }, + { 0x2212005e4, 0x0, 0x1 }, + { 0x2212005e8, 0x0, 0x1 }, + { 0x2212005ec, 0x8, 0x1 }, + { 0x221204018, 0x0, 0x2 }, + { 0x221200580, 0x71, 0x0 }, + { 0x221200580, 0xf1, 0x1 }, + { 0x221200584, 0x7, 0x0 }, + { 0x221200584, 0xf, 0x1 }, + { 0x2212005f0, 0x3ff001a, 0x1 }, + { 0x2212005f4, 0x0, 0x1 }, + { 0x2212005f8, 0x32, 0x1 }, + { 0x2212005fc, 0x0, 0x1 }, + { 0x221200600, 0x0, 0x1 }, + { 0x221200604, 0x10, 0x1 }, + { 0x221204020, 0x0, 0x2 }, + { 0x221200580, 0xf1, 0x0 }, + { 0x221200580, 0x1f1, 0x1 }, + { 0x221200584, 0xf, 0x0 }, + { 0x221200584, 0x1f, 0x1 }, + { 0x221200608, 0x3ff001a, 0x1 }, + { 0x22120060c, 0x0, 0x1 }, + { 0x221200610, 0x32, 0x1 }, + { 0x221200614, 0x0, 0x1 }, + { 0x221200618, 0x0, 0x1 }, + { 0x22120061c, 0x20, 0x1 }, + { 0x221204028, 0x0, 0x2 }, + { 0x221200580, 0x1f1, 0x0 }, + { 0x221200580, 0x3f1, 0x1 }, + { 0x221200584, 0x1f, 0x0 }, + { 0x221200584, 0x3f, 0x1 }, + { 0x221200620, 0x3ff001a, 0x1 }, + { 0x221200624, 0x0, 0x1 }, + { 0x221200628, 0x32, 0x1 }, + { 0x22120062c, 0x0, 0x1 }, + { 0x221200630, 0x0, 0x1 }, + { 0x221200634, 0x40, 0x1 }, + { 0x221204030, 0x0, 0x2 }, + { 0x221200580, 0x3f1, 0x0 }, + { 0x221200580, 0x7f1, 0x1 }, + { 0x221200584, 0x3f, 0x0 }, + { 0x221200584, 0x7f, 0x1 }, + { 0x221200638, 0x3ff001a, 0x1 }, + { 0x22120063c, 0x0, 0x1 }, + { 0x221200640, 0x32, 0x1 }, + { 0x221200644, 0x0, 0x1 }, + { 0x221200648, 0x0, 0x1 }, + { 0x22120064c, 0x80, 0x1 }, + { 0x221204038, 0x0, 0x2 }, + { 0x221200580, 0x7f1, 0x0 }, + { 0x221200580, 0xff1, 0x1 }, + { 0x221200584, 0x7f, 0x0 }, + { 0x221200584, 0xff, 0x1 }, + { 0x221200650, 0x3ff001a, 0x1 }, + { 0x221200654, 0x0, 0x1 }, + { 0x221200658, 0x32, 0x1 }, + { 0x22120065c, 0x0, 0x1 }, + { 0x221200660, 0x0, 0x1 }, + { 0x221200664, 0x100, 0x1 }, + { 0x221204040, 0x0, 0x2 }, + { 0x221200580, 0xff1, 0x0 }, + { 0x221200580, 0x1ff1, 0x1 }, + { 0x221200584, 0xff, 0x0 }, + { 0x221200584, 0x1ff, 0x1 }, + { 0x221200668, 0x3ff0039, 0x1 }, + { 0x22120066c, 0x0, 0x1 }, + { 0x221200670, 0x33, 0x1 }, + { 0x221200674, 0x0, 0x1 }, + { 0x221200678, 0x0, 0x1 }, + { 0x22120067c, 0x1ff, 0x1 }, + { 0x221204048, 0x0, 0x2 }, + { 0x221200580, 0x1ff1, 0x0 }, + { 0x221200580, 0x3ff1, 0x1 }, + { 0x221200584, 0x1ff, 0x0 }, + { 0x221200584, 0x3ff, 0x1 }, + { 0x221400590, 0x3ff0039, 0x1 }, + { 0x221400594, 0x0, 0x1 }, + { 0x221400598, 0x33, 0x1 }, + { 0x22140059c, 0x0, 0x1 }, + { 0x2214005a0, 0x0, 0x1 }, + { 0x2214005a4, 0x2, 0x1 }, + { 0x221404000, 0x0, 0x2 }, + { 0x221400580, 0x0, 0x10 }, + { 0x221400580, 0x11, 0x1 }, + { 0x221400584, 0x0, 0x10 }, + { 0x221400584, 0x1, 0x1 }, + { 0x2214005a8, 0x3ff0039, 0x1 }, + { 0x2214005ac, 0x0, 0x1 }, + { 0x2214005b0, 0x33, 0x1 }, + { 0x2214005b4, 0x0, 0x1 }, + { 0x2214005b8, 0x0, 0x1 }, + { 0x2214005bc, 0x4, 0x1 }, + { 0x221404008, 0x0, 0x2 }, + { 0x221400580, 0x11, 0x0 }, + { 0x221400580, 0x31, 0x1 }, + { 0x221400584, 0x1, 0x0 }, + { 0x221400584, 0x3, 0x1 }, + { 0x2214005c0, 0x3ff0039, 0x1 }, + { 0x2214005c4, 0x0, 0x1 }, + { 0x2214005c8, 0x33, 0x1 }, + { 0x2214005cc, 0x0, 0x1 }, + { 0x2214005d0, 0x0, 0x1 }, + { 0x2214005d4, 0x8, 0x1 }, + { 0x221404010, 0x0, 0x2 }, + { 0x221400580, 0x31, 0x0 }, + { 0x221400580, 0x71, 0x1 }, + { 0x221400584, 0x3, 0x0 }, + { 0x221400584, 0x7, 0x1 }, + { 0x2214005d8, 0x3ff0039, 0x1 }, + { 0x2214005dc, 0x0, 0x1 }, + { 0x2214005e0, 0x33, 0x1 }, + { 0x2214005e4, 0x0, 0x1 }, + { 0x2214005e8, 0x0, 0x1 }, + { 0x2214005ec, 0x10, 0x1 }, + { 0x221404018, 0x0, 0x2 }, + { 0x221400580, 0x71, 0x0 }, + { 0x221400580, 0xf1, 0x1 }, + { 0x221400584, 0x7, 0x0 }, + { 0x221400584, 0xf, 0x1 }, + { 0x2214005f0, 0x3ff0039, 0x1 }, + { 0x2214005f4, 0x0, 0x1 }, + { 0x2214005f8, 0x33, 0x1 }, + { 0x2214005fc, 0x0, 0x1 }, + { 0x221400600, 0x0, 0x1 }, + { 0x221400604, 0x20, 0x1 }, + { 0x221404020, 0x0, 0x2 }, + { 0x221400580, 0xf1, 0x0 }, + { 0x221400580, 0x1f1, 0x1 }, + { 0x221400584, 0xf, 0x0 }, + { 0x221400584, 0x1f, 0x1 }, + { 0x221400608, 0x3ff0039, 0x1 }, + { 0x22140060c, 0x0, 0x1 }, + { 0x221400610, 0x33, 0x1 }, + { 0x221400614, 0x0, 0x1 }, + { 0x221400618, 0x0, 0x1 }, + { 0x22140061c, 0x40, 0x1 }, + { 0x221404028, 0x0, 0x2 }, + { 0x221400580, 0x1f1, 0x0 }, + { 0x221400580, 0x3f1, 0x1 }, + { 0x221400584, 0x1f, 0x0 }, + { 0x221400584, 0x3f, 0x1 }, + { 0x221400620, 0x3ff0039, 0x1 }, + { 0x221400624, 0x0, 0x1 }, + { 0x221400628, 0x33, 0x1 }, + { 0x22140062c, 0x0, 0x1 }, + { 0x221400630, 0x0, 0x1 }, + { 0x221400634, 0x80, 0x1 }, + { 0x221404030, 0x0, 0x2 }, + { 0x221400580, 0x3f1, 0x0 }, + { 0x221400580, 0x7f1, 0x1 }, + { 0x221400584, 0x3f, 0x0 }, + { 0x221400584, 0x7f, 0x1 }, + { 0x221400638, 0x3ff0039, 0x1 }, + { 0x22140063c, 0x0, 0x1 }, + { 0x221400640, 0x33, 0x1 }, + { 0x221400644, 0x0, 0x1 }, + { 0x221400648, 0x0, 0x1 }, + { 0x22140064c, 0x100, 0x1 }, + { 0x221404038, 0x0, 0x2 }, + { 0x221400580, 0x7f1, 0x0 }, + { 0x221400580, 0xff1, 0x1 }, + { 0x221400584, 0x7f, 0x0 }, + { 0x221400584, 0xff, 0x1 }, + { 0x221400650, 0x3ff003a, 0x1 }, + { 0x221400654, 0x0, 0x1 }, + { 0x221400658, 0x33, 0x1 }, + { 0x22140065c, 0x0, 0x1 }, + { 0x221400660, 0x0, 0x1 }, + { 0x221400664, 0x1ff, 0x1 }, + { 0x221404040, 0x0, 0x2 }, + { 0x221400580, 0xff1, 0x0 }, + { 0x221400580, 0x1ff1, 0x1 }, + { 0x221400584, 0xff, 0x0 }, + { 0x221400584, 0x1ff, 0x1 }, + { 0x221400668, 0x3ff003a, 0x1 }, + { 0x22140066c, 0x0, 0x1 }, + { 0x221400670, 0x33, 0x1 }, + { 0x221400674, 0x0, 0x1 }, + { 0x221400678, 0x0, 0x1 }, + { 0x22140067c, 0x2, 0x1 }, + { 0x221404048, 0x0, 0x2 }, + { 0x221400580, 0x1ff1, 0x0 }, + { 0x221400580, 0x3ff1, 0x1 }, + { 0x221400584, 0x1ff, 0x0 }, + { 0x221400584, 0x3ff, 0x1 }, + { 0x221600590, 0x3ff003a, 0x1 }, + { 0x221600594, 0x0, 0x1 }, + { 0x221600598, 0x33, 0x1 }, + { 0x22160059c, 0x0, 0x1 }, + { 0x2216005a0, 0x0, 0x1 }, + { 0x2216005a4, 0x4, 0x1 }, + { 0x221604000, 0x0, 0x2 }, + { 0x221600580, 0x0, 0x10 }, + { 0x221600580, 0x11, 0x1 }, + { 0x221600584, 0x0, 0x10 }, + { 0x221600584, 0x1, 0x1 }, + { 0x2216005a8, 0x3ff003a, 0x1 }, + { 0x2216005ac, 0x0, 0x1 }, + { 0x2216005b0, 0x33, 0x1 }, + { 0x2216005b4, 0x0, 0x1 }, + { 0x2216005b8, 0x0, 0x1 }, + { 0x2216005bc, 0x8, 0x1 }, + { 0x221604008, 0x0, 0x2 }, + { 0x221600580, 0x11, 0x0 }, + { 0x221600580, 0x31, 0x1 }, + { 0x221600584, 0x1, 0x0 }, + { 0x221600584, 0x3, 0x1 }, + { 0x2216005c0, 0x3ff003a, 0x1 }, + { 0x2216005c4, 0x0, 0x1 }, + { 0x2216005c8, 0x33, 0x1 }, + { 0x2216005cc, 0x0, 0x1 }, + { 0x2216005d0, 0x0, 0x1 }, + { 0x2216005d4, 0x10, 0x1 }, + { 0x221604010, 0x0, 0x2 }, + { 0x221600580, 0x31, 0x0 }, + { 0x221600580, 0x71, 0x1 }, + { 0x221600584, 0x3, 0x0 }, + { 0x221600584, 0x7, 0x1 }, + { 0x2216005d8, 0x3ff003a, 0x1 }, + { 0x2216005dc, 0x0, 0x1 }, + { 0x2216005e0, 0x33, 0x1 }, + { 0x2216005e4, 0x0, 0x1 }, + { 0x2216005e8, 0x0, 0x1 }, + { 0x2216005ec, 0x20, 0x1 }, + { 0x221604018, 0x0, 0x2 }, + { 0x221600580, 0x71, 0x0 }, + { 0x221600580, 0xf1, 0x1 }, + { 0x221600584, 0x7, 0x0 }, + { 0x221600584, 0xf, 0x1 }, + { 0x2216005f0, 0x3ff003a, 0x1 }, + { 0x2216005f4, 0x0, 0x1 }, + { 0x2216005f8, 0x33, 0x1 }, + { 0x2216005fc, 0x0, 0x1 }, + { 0x221600600, 0x0, 0x1 }, + { 0x221600604, 0x40, 0x1 }, + { 0x221604020, 0x0, 0x2 }, + { 0x221600580, 0xf1, 0x0 }, + { 0x221600580, 0x1f1, 0x1 }, + { 0x221600584, 0xf, 0x0 }, + { 0x221600584, 0x1f, 0x1 }, + { 0x221600608, 0x3ff003a, 0x1 }, + { 0x22160060c, 0x0, 0x1 }, + { 0x221600610, 0x33, 0x1 }, + { 0x221600614, 0x0, 0x1 }, + { 0x221600618, 0x0, 0x1 }, + { 0x22160061c, 0x80, 0x1 }, + { 0x221604028, 0x0, 0x2 }, + { 0x221600580, 0x1f1, 0x0 }, + { 0x221600580, 0x3f1, 0x1 }, + { 0x221600584, 0x1f, 0x0 }, + { 0x221600584, 0x3f, 0x1 }, + { 0x221600620, 0x3ff003a, 0x1 }, + { 0x221600624, 0x0, 0x1 }, + { 0x221600628, 0x33, 0x1 }, + { 0x22160062c, 0x0, 0x1 }, + { 0x221600630, 0x0, 0x1 }, + { 0x221600634, 0x100, 0x1 }, + { 0x221604030, 0x0, 0x2 }, + { 0x221600580, 0x3f1, 0x0 }, + { 0x221600580, 0x7f1, 0x1 }, + { 0x221600584, 0x3f, 0x0 }, + { 0x221600584, 0x7f, 0x1 }, + { 0x221600638, 0x3ff0013, 0x1 }, + { 0x22160063c, 0x0, 0x1 }, + { 0x221600640, 0x0, 0x1 }, + { 0x221600644, 0x0, 0x1 }, + { 0x221600648, 0x0, 0x1 }, + { 0x22160064c, 0x1ff, 0x1 }, + { 0x221604038, 0x0, 0x2 }, + { 0x221600580, 0x7f1, 0x0 }, + { 0x221600580, 0xff1, 0x1 }, + { 0x221600584, 0x7f, 0x0 }, + { 0x221600584, 0xff, 0x1 }, + { 0x221600650, 0x3ff0016, 0x1 }, + { 0x221600654, 0x0, 0x1 }, + { 0x221600658, 0x0, 0x1 }, + { 0x22160065c, 0x0, 0x1 }, + { 0x221600660, 0x0, 0x1 }, + { 0x221600664, 0x1ff, 0x1 }, + { 0x221604040, 0x0, 0x2 }, + { 0x221600580, 0xff1, 0x0 }, + { 0x221600580, 0x1ff1, 0x1 }, + { 0x221600584, 0xff, 0x0 }, + { 0x221600584, 0x1ff, 0x1 }, + { 0x221004050, 0x0, 0x2 }, + { 0x221000680, 0x1010101, 0x10 }, + { 0x221000680, 0x1010101, 0x1 }, + { 0x22100058c, 0xffffffff, 0x10 }, + { 0x22100058c, 0xffffffff, 0x1 }, + { 0x221000588, 0x0, 0x10 }, + { 0x221000588, 0x10000, 0x1 }, + { 0x221000588, 0x0, 0x0 }, + { 0x221000588, 0x1, 0x1 }, + { 0x221004058, 0x0, 0x2 }, + { 0x221000680, 0x1010101, 0x0 }, + { 0x221000680, 0x1010001, 0x1 }, + { 0x22100058c, 0xffffffff, 0x0 }, + { 0x22100058c, 0xffff02ff, 0x1 }, + { 0x221000588, 0x1, 0x0 }, + { 0x221000588, 0x100001, 0x1 }, + { 0x221000588, 0x1, 0x0 }, + { 0x221000588, 0x11, 0x1 }, + { 0x221204050, 0x0, 0x2 }, + { 0x221200680, 0x1010101, 0x10 }, + { 0x221200680, 0x1010100, 0x1 }, + { 0x22120058c, 0xffffffff, 0x10 }, + { 0x22120058c, 0xffffff04, 0x1 }, + { 0x221200588, 0x0, 0x10 }, + { 0x221200588, 0x10000, 0x1 }, + { 0x221200588, 0x0, 0x0 }, + { 0x221200588, 0x1, 0x1 }, + { 0x221204058, 0x0, 0x2 }, + { 0x221200680, 0x1010100, 0x0 }, + { 0x221200680, 0x1010000, 0x1 }, + { 0x22120058c, 0xffffff04, 0x0 }, + { 0x22120058c, 0xffff0804, 0x1 }, + { 0x221200588, 0x1, 0x0 }, + { 0x221200588, 0x100001, 0x1 }, + { 0x221200588, 0x1, 0x0 }, + { 0x221200588, 0x11, 0x1 }, + { 0x221404050, 0x0, 0x2 }, + { 0x221400680, 0x1010101, 0x10 }, + { 0x221400680, 0x1010100, 0x1 }, + { 0x22140058c, 0xffffffff, 0x10 }, + { 0x22140058c, 0xffffff10, 0x1 }, + { 0x221400588, 0x0, 0x10 }, + { 0x221400588, 0x10000, 0x1 }, + { 0x221400588, 0x0, 0x0 }, + { 0x221400588, 0x1, 0x1 }, + { 0x221404058, 0x0, 0x2 }, + { 0x221400680, 0x1010100, 0x0 }, + { 0x221400680, 0x1010000, 0x1 }, + { 0x22140058c, 0xffffff10, 0x0 }, + { 0x22140058c, 0xffff2010, 0x1 }, + { 0x221400588, 0x1, 0x0 }, + { 0x221400588, 0x100001, 0x1 }, + { 0x221400588, 0x1, 0x0 }, + { 0x221400588, 0x11, 0x1 }, + { 0x221604050, 0x0, 0x2 }, + { 0x221600680, 0x1010101, 0x10 }, + { 0x221600680, 0x1010100, 0x1 }, + { 0x22160058c, 0xffffffff, 0x10 }, + { 0x22160058c, 0xffffff40, 0x1 }, + { 0x221600588, 0x0, 0x10 }, + { 0x221600588, 0x10000, 0x1 }, + { 0x221600588, 0x0, 0x0 }, + { 0x221600588, 0x1, 0x1 }, + { 0x221604058, 0x0, 0x2 }, + { 0x221600680, 0x1010100, 0x0 }, + { 0x221600680, 0x1010000, 0x1 }, + { 0x22160058c, 0xffffff40, 0x0 }, + { 0x22160058c, 0xffff8040, 0x1 }, + { 0x221600588, 0x1, 0x0 }, + { 0x221600588, 0x100001, 0x1 }, + { 0x221600588, 0x1, 0x0 }, + { 0x221600588, 0x11, 0x1 }, + { 0x221804050, 0x0, 0x2 }, + { 0x221800680, 0x1010101, 0x10 }, + { 0x221800680, 0x1010101, 0x1 }, + { 0x22180058c, 0xffffffff, 0x10 }, + { 0x22180058c, 0xffffff00, 0x1 }, + { 0x221800588, 0x0, 0x10 }, + { 0x221800588, 0x10000, 0x1 }, + { 0x221800588, 0x0, 0x0 }, + { 0x221800588, 0x1, 0x1 }, + { 0x221004060, 0x0, 0x2 }, + { 0x221000680, 0x1010001, 0x0 }, + { 0x221000680, 0x1010001, 0x1 }, + { 0x22100058c, 0xffff02ff, 0x0 }, + { 0x22100058c, 0xffff02ff, 0x1 }, + { 0x221000588, 0x11, 0x0 }, + { 0x221000588, 0x1000011, 0x1 }, + { 0x221000588, 0x11, 0x0 }, + { 0x221000588, 0x111, 0x1 }, + { 0x221004068, 0x0, 0x2 }, + { 0x221000680, 0x1010001, 0x0 }, + { 0x221000680, 0x10001, 0x1 }, + { 0x22100058c, 0xffff02ff, 0x0 }, + { 0x22100058c, 0x2ff02ff, 0x1 }, + { 0x221000588, 0x111, 0x0 }, + { 0x221000588, 0x10000111, 0x1 }, + { 0x221000588, 0x111, 0x0 }, + { 0x221000588, 0x1111, 0x1 }, + { 0x221204060, 0x0, 0x2 }, + { 0x221200680, 0x1010000, 0x0 }, + { 0x221200680, 0x1000000, 0x1 }, + { 0x22120058c, 0xffff0804, 0x0 }, + { 0x22120058c, 0xff040804, 0x1 }, + { 0x221200588, 0x11, 0x0 }, + { 0x221200588, 0x1000011, 0x1 }, + { 0x221200588, 0x11, 0x0 }, + { 0x221200588, 0x111, 0x1 }, + { 0x221204068, 0x0, 0x2 }, + { 0x221200680, 0x1000000, 0x0 }, + { 0x221200680, 0x0, 0x1 }, + { 0x22120058c, 0xff040804, 0x0 }, + { 0x22120058c, 0x8040804, 0x1 }, + { 0x221200588, 0x111, 0x0 }, + { 0x221200588, 0x10000111, 0x1 }, + { 0x221200588, 0x111, 0x0 }, + { 0x221200588, 0x1111, 0x1 }, + { 0x221404060, 0x0, 0x2 }, + { 0x221400680, 0x1010000, 0x0 }, + { 0x221400680, 0x1000000, 0x1 }, + { 0x22140058c, 0xffff2010, 0x0 }, + { 0x22140058c, 0xff102010, 0x1 }, + { 0x221400588, 0x11, 0x0 }, + { 0x221400588, 0x1000011, 0x1 }, + { 0x221400588, 0x11, 0x0 }, + { 0x221400588, 0x111, 0x1 }, + { 0x221404068, 0x0, 0x2 }, + { 0x221400680, 0x1000000, 0x0 }, + { 0x221400680, 0x0, 0x1 }, + { 0x22140058c, 0xff102010, 0x0 }, + { 0x22140058c, 0x20102010, 0x1 }, + { 0x221400588, 0x111, 0x0 }, + { 0x221400588, 0x10000111, 0x1 }, + { 0x221400588, 0x111, 0x0 }, + { 0x221400588, 0x1111, 0x1 }, + { 0x221604060, 0x0, 0x2 }, + { 0x221600680, 0x1010000, 0x0 }, + { 0x221600680, 0x1000000, 0x1 }, + { 0x22160058c, 0xffff8040, 0x0 }, + { 0x22160058c, 0xff408040, 0x1 }, + { 0x221600588, 0x11, 0x0 }, + { 0x221600588, 0x1000011, 0x1 }, + { 0x221600588, 0x11, 0x0 }, + { 0x221600588, 0x111, 0x1 }, + { 0x221604068, 0x0, 0x2 }, + { 0x221600680, 0x1000000, 0x0 }, + { 0x221600680, 0x0, 0x1 }, + { 0x22160058c, 0xff408040, 0x0 }, + { 0x22160058c, 0x80408040, 0x1 }, + { 0x221600588, 0x111, 0x0 }, + { 0x221600588, 0x10000111, 0x1 }, + { 0x221600588, 0x111, 0x0 }, + { 0x221600588, 0x1111, 0x1 }, + { 0x221804060, 0x0, 0x2 }, + { 0x221800680, 0x1010101, 0x0 }, + { 0x221800680, 0x1010101, 0x1 }, + { 0x22180058c, 0xffffff00, 0x0 }, + { 0x22180058c, 0xff00ff00, 0x1 }, + { 0x221800588, 0x1, 0x0 }, + { 0x221800588, 0x1000001, 0x1 }, + { 0x221800588, 0x1, 0x0 }, + { 0x221800588, 0x101, 0x1 }, + { 0x22002a058, 0x0, 0x2 }, + { 0x22002a060, 0x0, 0x2 }, + { 0x22002a010, 0x10000000, 0x3 }, + { 0x22002e000, 0x100, 0x1 }, + { 0x22002a008, 0x300, 0x3 }, + { 0x22002a000, 0x11, 0x3 }, + { 0x22006e000, 0x100, 0x1 }, + { 0x22006a008, 0x308, 0x3 }, + { 0x22006a000, 0x1, 0x3 }, + { 0x2200ae000, 0x100, 0x1 }, + { 0x2200aa008, 0x310, 0x3 }, + { 0x2200aa000, 0x1, 0x3 }, + { 0x2200ee000, 0x100, 0x1 }, + { 0x2200ea008, 0x318, 0x3 }, + { 0x2200ea000, 0x1, 0x3 }, + { 0x221000024, 0x7000100, 0x10 }, + { 0x221000024, 0x7001100, 0x1 }, + { 0x221200024, 0x7000100, 0x10 }, + { 0x221200024, 0x7001100, 0x1 }, + { 0x221400024, 0x7000100, 0x10 }, + { 0x221400024, 0x7001100, 0x1 }, + { 0x221600024, 0x7000100, 0x10 }, + { 0x221600024, 0x7001100, 0x1 }, + { 0x221800024, 0x7000100, 0x10 }, + { 0x221800024, 0x7001100, 0x1 }, + { 0x221a00024, 0x7000100, 0x10 }, + { 0x221a00024, 0x7001100, 0x1 }, + { 0x221c00024, 0x7000100, 0x10 }, + { 0x221c00024, 0x7001100, 0x1 }, + { 0x221e00024, 0x7000100, 0x10 }, + { 0x221e00024, 0x7001100, 0x1 }, +}; diff --git a/drivers/soc/apple/sleep-test.c b/drivers/soc/apple/sleep-test.c index 0c2eb05209002..fff01f6447e5a 100644 --- a/drivers/soc/apple/sleep-test.c +++ b/drivers/soc/apple/sleep-test.c @@ -5,10 +5,11 @@ */ #include -/* Qualified profiles and explicitly unavailable inventory-only profiles. */ +/* Qualified, commit-gated and explicitly unavailable inventory-only profiles. */ static const char *const apple_sleep_test_profiles[] = { "apple,t8140-sleep", "apple,t8132-sleep", + "apple,t8142-sleep", "apple,t6050-sleep", "apple,t6050-j716c-sleep", }; @@ -58,6 +59,12 @@ static void apple_sleep_test_known_profiles(struct kunit *test) KUNIT_EXPECT_NOT_NULL_MSG(test, id->data, "%s has no data", id->compatible); KUNIT_ASSERT_LT(test, n, ARRAY_SIZE(apple_sleep_test_profiles)); KUNIT_EXPECT_STREQ(test, id->compatible, apple_sleep_test_profiles[n]); + if (!strcmp(id->compatible, "apple,t8142-sleep")) { + const struct apple_sleep_soc *soc = id->data; + + KUNIT_ASSERT_NOT_NULL(test, soc); + KUNIT_EXPECT_TRUE(test, soc->untested); + } } KUNIT_EXPECT_EQ(test, n, ARRAY_SIZE(apple_sleep_test_profiles)); } @@ -84,9 +91,13 @@ static void apple_sleep_test_words(struct kunit *test) continue; apple_sleep_test_full(test, c, "ps_all", all); apple_sleep_test_full(test, c, "ps_aon_all", aon); + /* 0: a word the SoC doesn't name (a second display, T8142's USB words). */ for (i = 0; i < ARRAY_SIZE(named); i++) - apple_sleep_test_in(test, c, "named", all, named[i]); - apple_sleep_test_in(test, c, "debug switch", aon, soc->ps_aon_debug_switch); + if (named[i]) + apple_sleep_test_in(test, c, "named", all, named[i]); + /* An untested SoC only reads its debug switch, outside the lists. */ + if (!soc->untested) + apple_sleep_test_in(test, c, "debug switch", aon, soc->ps_aon_debug_switch); apple_sleep_test_list_in(test, c, "ps_macos_on", all, &soc->ps_macos_on); apple_sleep_test_list_in(test, c, "ps_macos_off", all, &soc->ps_macos_off); apple_sleep_test_list_in(test, c, "ps_wake_order", all, &soc->ps_wake_order); @@ -190,7 +201,6 @@ static void apple_sleep_test_layout(struct kunit *test) for (id = apple_sleep_of_match; id->compatible[0]; id++) { const struct apple_sleep_soc *soc = id->data; - /* Region-based profiles keep their words in their own tables */ if (soc->regions) continue; KUNIT_EXPECT_GE(test, soc->ncluster_cpu, 1); @@ -198,13 +208,26 @@ static void apple_sleep_test_layout(struct kunit *test) KUNIT_EXPECT_GT(test, soc->cpu_start_stride, 0); KUNIT_EXPECT_LE(test, soc->nclk_mux_parked, SLEEP_CLK_MUX_MAX); KUNIT_EXPECT_LE(test, soc->ncllt, SLEEP_CLLT_MAX); + /* Every SoC steps its memory controller down (T8142: from the J813 trace). */ KUNIT_EXPECT_GE(test, soc->nmcc, 1); KUNIT_EXPECT_LE(test, soc->nmcc, MCC_CHANNELS); KUNIT_EXPECT_LE(test, soc->namcc, SLEEP_AMCC_MAX); + /* Each SoC NI table is mapped 0x80 bytes long (the T8142 sleep node). */ + KUNIT_EXPECT_LE(test, soc->nsocni, SLEEP_SOCNI_MAX); + KUNIT_EXPECT_EQ(test, !!soc->socni_words, !!soc->nsocni); + for (int j = 0; j < soc->nsocni; j++) + KUNIT_EXPECT_LE(test, soc->socni_words[j] * 4, 0x80); KUNIT_EXPECT_GE(test, soc->wake_words, 1); KUNIT_EXPECT_LE(test, soc->wake_words, WAKE_WORDS); KUNIT_EXPECT_GE(test, soc->wake_status, soc->wake_mask + soc->wake_words * 4); KUNIT_EXPECT_LT(test, soc->pmu_usid, 16); + /* PS write-disable words: in "ps" (0x18000 on T8142), aligned, one bit each */ + KUNIT_EXPECT_LE(test, soc->nps_wr_dis, SLEEP_PS_WR_DIS_MAX); + for (int i = 0; i < soc->nps_wr_dis; i++) { + KUNIT_EXPECT_EQ(test, soc->ps_wr_dis[i].offset % 4, 0); + KUNIT_EXPECT_LT(test, soc->ps_wr_dis[i].offset, 0x18000); + KUNIT_EXPECT_LT(test, soc->ps_wr_dis[i].bit, 32); + } } } diff --git a/drivers/soc/apple/sleep.c b/drivers/soc/apple/sleep.c index 7d9c6a03fa040..465e30fef8236 100644 --- a/drivers/soc/apple/sleep.c +++ b/drivers/soc/apple/sleep.c @@ -146,6 +146,12 @@ struct aura_s2r_mailbox { #define WDT_SUSPEND_SECS 120 #define AON_AP_DEADLINE 0x08 +/* + * T8142: a word of the watchdog's second page (/arm-io/wdt + 0x802c). macOS's entry + * read-modify-writes it from 0 to 0x20 right before WD0's control and WD2 (26B131 trace, + * 11.1 ms before the S2R timer); XNU writes 0x10 there during boot. Meaning unknown. + */ +#define AON_WDT_SLEEP 0x2c /* Wake sources: a mask, so 0 enables. Status words are sticky. Where and how many: the SoC. */ #define WAKE_WORDS 9 @@ -187,10 +193,51 @@ struct aura_s2r_mailbox { #define HPM_CONTRACT_MS 1500 #define HPM_RESET_TRIES 3 +/* + * T8142's controllers are SPMI gen 4 (ADT "gen" = 4 on nub-spmi0, nub-spmi-a0 and the others). + * macOS 27.2.1's AppleSPMI Gen4 class, from its init: status +0x200 (RX empty bit 30), request + * FIFO +0x210, response FIFO +0x220, IRQ enable bank +0x400 and ack bank +0x600, word 8 (the + * notification word) at +0x420/+0x620 as gen 1's at 0x40/0x80. Gen 1's offsets land on other + * registers there: +0x4 is the FIFO flush, and +0x0 never reads RX empty. + */ +#define SPMI4_STATUS 0x200 +#define SPMI4_STATUS_RX_EMPTY BIT(30) +#define SPMI4_CMD 0x210 +#define SPMI4_REPLY 0x220 +#define SPMI4_NOTIFY_ENABLE 0x420 +#define SPMI4_NOTIFY_ACK 0x620 +/* + * Gen 4: the peripheral sources' status words, below the controller's own (write 1 to + * clear). A latched source that is enabled holds the controller's interrupt output, an AP + * wake source, up (T6050, aurora-silicon/linux#1963 commit 24). + */ +#define SPMI4_SRC_ENABLE 0x400 +#define SPMI4_SRC_STATUS 0x600 +#define SPMI4_SRC_WORDS 8 +/* A FIFO holds a few replies at most; never spin on a status that doesn't change. */ +#define SPMI_DRAIN_MAX 16 + /* A one-byte register write on the sleep's SPMI bus, to the PMU's USID */ #define SPMI_CMD_WRITE (BIT(15) | 0x30) #define SPMI_CMD_USID GENMASK(11, 8) +/* A PMU write: the reply's vector masked, then acknowledged, so none is left raised. */ +static inline void apple_sleep_pmu_write(void __iomem *spmi, u8 usid, u16 reg, u8 val) +{ + u32 status, enable; + + enable = readl(spmi + SPMI_NOTIFY_ENABLE); + writel(enable & ~SPMI_NOTIFY_REPLY, spmi + SPMI_NOTIFY_ENABLE); + writel(((u32)reg << 16) | SPMI_CMD_WRITE | FIELD_PREP(SPMI_CMD_USID, usid), + spmi + SPMI_CMD); + writel(val, spmi + SPMI_CMD); + if (!readl_poll_timeout_atomic(spmi + SPMI_STATUS, status, + !(status & SPMI_STATUS_RX_EMPTY), 1, 1000)) + readl(spmi + SPMI_REPLY); + writel(1, spmi + SPMI_NOTIFY_ACK); + writel(enable, spmi + SPMI_NOTIFY_ENABLE); +} + /* T8132's power words where they aren't T8140's */ #define T8132_PS_ATC0_COMMON 0x378 #define T8132_PS_AON_ATC0_USB_AON 0xb0 @@ -303,6 +350,18 @@ struct aura_s2r_mailbox { #define SLEEP_COPROCS 16 #define SLEEP_GATES_MAX 16 +/* + * T8142 (APCIECoreRCGen4): the two PHY-IP words its _shutdownGen4Phy writes, and the PLL + * control word in pcieclkgen (/arm-io/apcie reg[6]), whose run, off and busy bits are the + * clock generator's above. + */ +#define APCIE_GEN4_PHY_IP_38 0x38 +#define APCIE_GEN4_PHY_IP_38_EN GENMASK(27, 26) +#define APCIE_GEN4_PHY_IP_8C 0x8c +#define APCIE_GEN4_PHY_IP_8C_OV GENMASK(27, 24) +#define APCIE_GEN4_CLK_HOLD GENMASK(4, 3) +#define APCIE_GEN4_CLK_EN BIT(0) + static struct apple_sleep_coproc { struct device *dev; void __iomem *asc; @@ -350,6 +409,7 @@ static struct { #define SLEEP_CLK_MUX_MAX 4 #define SLEEP_CLLT_MAX 4 #define SLEEP_AMCC_MAX 16 +#define SLEEP_SOCNI_MAX 8 /* cpm-dvfm */ #define DVFM_CTL 0x178 @@ -370,6 +430,19 @@ struct apple_sleep_word { u32 offset; }; +#define T8142_PS_ATC0_COMMON 0x2c8 +#define T8142_PS_PMP 0x598 +#define T8142_PS_AON_ATC0_USB_AON 0xc8 +#define T8142_PS_AON_ATC0_USB 0xd0 + +/* A power word the match leaves alone when its group's bit is set in apple_sleep.ps_keep */ +struct apple_sleep_ps_keep { + const char *name; + u32 offset; + bool aon; + u8 group; +}; + /* Power words by their offsets */ struct apple_sleep_words { const u32 *offset; @@ -407,6 +480,20 @@ struct apple_sleep_clear { u32 clear; }; +/* + * T8142: a DART's PS write-disable bit (SPTM's /chosen/dart-ps-wr-dis-entries), as an offset + * in "ps" and a bit. While it is set the PMGR drops the AP's writes to that DART's power word, + * so a word lowered with it set stays on with BUSY latched. macOS's SPTM clears each right + * before the domain goes down; without SPTM the sleep clears them itself. + */ +struct apple_sleep_ps_wr_dis { + const char *name; + u32 offset; + u8 bit; +}; + +#define SLEEP_PS_WR_DIS_MAX 8 + /* The power words in "ps" that the sleep drives itself */ struct apple_sleep_domains { /* CPU, front end and system, of the DCP and then of the external DCP */ @@ -427,6 +514,9 @@ struct apple_sleep_domains { u32 apcie_st; u32 apcie_sys_st; u32 apcie_phy_sw; + /* T8142: the shared block's AUS5 pair, the last its gate loop powers */ + u32 apcie_aus5_aon; + u32 apcie_aus5; }; struct apple_sleep; @@ -462,6 +552,14 @@ static int sleep_v27_final_stop(struct apple_sleep *s); * way. The refusals, the coprocessor stops, macOS's power words, the mailbox and the commit * word are shared, and run around these. */ +struct apple_sleep_extra_off { + const char *name; + u32 offset; + u32 parent; +}; + +#define SLEEP_EXTRA_OFF_MAX 16 + struct apple_sleep_ops { /* What makes a core's last WFI end in a reset, after its timers are masked */ void (*deep_wfi_arm)(void); @@ -519,6 +617,8 @@ struct apple_sleep_ops { int (*check)(struct apple_sleep *s); /* Optional traffic strictly after timer, before AIC/release/DEEP. */ void (*post_timer)(struct apple_sleep *s); + /* The dry run's list: does macOS have this ps word off at its commit? */ + bool (*macos_off_at_commit)(u32 offset); }; /* @@ -536,6 +636,21 @@ struct apple_sleep_soc { bool wake_optional; unsigned int ndisp; bool lower_unbound_displays; + /* + * apple_sleep.dispext: the external displays (index 1 and up) are lowered only with it on, + * and a missing phandle for one is no error. Each one's PS write-disable bit (offset, bit; + * offset 0 = none) is cleared before its lowering, as macOS's SPTM leaves it. + */ + bool dispext_optional; + u32 disp_wr_dis[SLEEP_DISPLAYS_MAX][2]; + /* + * apple_sleep.extra_off: each display's ADMA word (a child of its SYS word; 0 = none), + * lowered before the display's own, and the words lower_io lowers first, children before + * parents, each restored at the wake only once its parent (0 = root) is on. + */ + u32 disp_adma[SLEEP_DISPLAYS_MAX]; + const struct apple_sleep_extra_off *extra_off; + unsigned int nextra_off; /* The clock-protection slice guarding each display's CPU word, 0 if none needs clearing. */ u8 disp_prot_slice[SLEEP_DISPLAYS_MAX]; /* Which display to lower next, in macOS's order: index into ps.disp. */ @@ -586,6 +701,11 @@ struct apple_sleep_soc { /* In "cllt": bits cleared before the commit */ struct apple_sleep_clear cllt[SLEEP_CLLT_MAX]; unsigned int ncllt; + /* In "ps": PS write-disable bits cleared after the enclave's stop, before the others' */ + const struct apple_sleep_ps_wr_dis *ps_wr_dis; + unsigned int nps_wr_dis; + /* In "aon-misc": AON_WDT_SLEEP's bits set before WD2 is armed (0: none) */ + u32 aon_wdt_sleep; /* The PMU on the sleep's SPMI bus, and the byte it is told the AP sleeps with */ u8 pmu_usid; u16 pmu_sleep_reg; @@ -595,6 +715,9 @@ struct apple_sleep_soc { /* "mcc0".. and "amcc0"..: how many the SoC has */ unsigned int nmcc; unsigned int namcc; + /* "socni0"..: the SoC NI tables macOS zeroes before the memory goes down, in words */ + const u8 *socni_words; + unsigned int nsocni; /* In "wake": the mask and status words, and how many */ u32 wake_mask; u32 wake_status; @@ -624,9 +747,17 @@ struct apple_sleep_soc { struct apple_sleep_words ps_still_on; /* The wake's timed power-gate polls: off with BUSY clear at the commit, on macOS */ struct apple_sleep_words ps_engine_polled; + /* Put under AUTO_ENABLE by XNU's PMGR start at boot, iBoot leaving them on without it */ + struct apple_sleep_words ps_boot_auto; + struct apple_sleep_words ps_aon_boot_auto; + /* T8142: replay XNU's memory-controller start at the entry (apple_sleep.mem_boot) */ + bool mem_boot; /* Lowered at the last step if still on, with no user left */ const struct apple_sleep_word *stray; unsigned int nstray; + /* Words the match leaves as they are, by group (apple_sleep.ps_keep) */ + const struct apple_sleep_ps_keep *ps_keep; + unsigned int nps_keep; /* Off on macOS by the last step: one still on only warns. */ const struct apple_sleep_word *gate_off; unsigned int ngate_off; @@ -642,6 +773,37 @@ struct apple_sleep_soc { /* The PMC whose cluster vote for the encoders needs the complex up, and its bit */ const char *ave_pmc; u32 ave_pmc_cluster; + /* What macOS reads once after its complex words; reported if still on. */ + struct apple_sleep_words quiesce; + /* Blocks the SoC doesn't have, by reg-name, NULL-terminated: left unmapped. */ + const char *const *regs_absent; + /* The sleep's SPMI bus has gen 4's queue layout (T8142). */ + bool spmi_gen4; + /* + * Derived from the binaries and another SoC's measurements, never through a full sleep and + * wake: deep sleep is offered only with apple_sleep.deep=1 and is never the default, a + * sleep stops before the commit unless apple_sleep.untested_commit=1, and each step is + * noted in PMU scratch for after a reset. + */ + bool untested; + /* + * ANS's PCIe block is T8142's (APCIECoreRCGen4): no clock generator or CIO3 PLL tables, + * and its PHY's control words this far into "phy-block" (0: APCIE_PHY_CTRL). + */ + bool apcie_gen4; + u32 apcie_phy_ctrl; + /* + * The radio's link is the loader's, under a generic ECAM host ("apple,radio-host"): it is + * stopped at the commit and trained again after the wake by this driver. + */ + bool radio_retrain; + /* A core restarted after the commit takes the deep WFI in the holding pen. */ + bool pen_deep; + /* + * The stopped cores take their deep WFI before the boot core's last mile, not after + * the commit (apple_sleep.early_wfi): XNU's order (T8142, J813 ten-core trace). + */ + bool early_cpu_wfi; }; struct apple_sleep { @@ -680,6 +842,9 @@ struct apple_sleep { unsigned long *driver_down; void __iomem *clk_mux; void __iomem *mcc[MCC_CHANNELS]; + void __iomem *socni[SLEEP_SOCNI_MAX]; + /* T8142: the clock word macOS writes after the memory controller ("mem-clk") */ + void __iomem *mem_clk; void __iomem *ptd; void __iomem *clk_perf; void __iomem *cluster_dcs; @@ -689,6 +854,32 @@ struct apple_sleep { u32 *ps_aon_saved; u32 *ps_aon_on_saved; u32 *ps_aon_auto_saved; + /* apple_sleep.ps_keep as the match took it, for its undo and lower_io */ + unsigned int ps_keep_mask; + /* apple_sleep.boot_auto: the words it put on AUTO_ENABLE (ps first, then ps-aon) */ + u64 boot_auto_set; + u32 boot_auto_saved[64]; + /* Of those, how many read AUTO_ENABLE back right after the write */ + unsigned int boot_auto_nset, boot_auto_stuck; + /* apple_sleep.mem_boot: the pages, the fingerprint's mismatches, whether it ran */ + void __iomem *mem_boot_page[40]; + unsigned int mem_boot_mismatch; + bool mem_boot_done, mem_floor_done; + /* apple_sleep.pmp_off: PMP's word as lower_io found it, and whether it went off */ + u32 pmp_saved; + bool pmp_lowered; + int pmp_off_ret; + /* apple_sleep.dispext: each external display's CPU, FE, SYS words before the lowering */ + u32 dispext_saved[SLEEP_DISPLAYS_MAX][3]; + u8 dispext_lowered; + u8 dispext_note; + /* apple_sleep.extra_off */ + u32 disp_adma_saved[SLEEP_DISPLAYS_MAX]; + u8 disp_adma_lowered; + u32 extra_saved[SLEEP_EXTRA_OFF_MAX]; + u16 extra_lowered; + /* bits 0-15 extra_off's words, bit 31 a display's ADMA */ + u32 extra_stuck; /* For each word of ps_all and ps_aon_all: at the commit, as the wake found it, late */ u32 *ps_commit; u32 *ps_aon_commit; @@ -726,6 +917,22 @@ struct apple_sleep { u64 resumes_after; /* T8132: ATC0's words as they were before the commit path lowered them. */ u32 atc0_saved[3]; + /* + * T8142: what the deep sleep loses and XNU puts back at the wake (J813 ten-core trace, + * 2026-11-16): the memory side as it was before the entry's stop (amcc, socni, mcc, + * "amcc-cfg"), the clock word and the PMGR clkgen slots ("clk-slots"). + */ + void __iomem *amcc_cfg[SLEEP_AMCC_MAX]; + void __iomem *clk_slots; + u64 amcc_saved[SLEEP_AMCC_MAX]; + u64 amcc_cfg_saved[SLEEP_AMCC_MAX][3]; + u32 amcc_ctl_saved[SLEEP_AMCC_MAX]; + u32 socni_saved[SLEEP_SOCNI_MAX][32]; + u32 mcc_saved[MCC_CHANNELS][65]; + u32 clk_slot_saved[126][2]; + u32 mem_clk_saved; + bool mem_saved, clk_saved; + int mem_restore_ret; int cluster_e_ret; int cluster_ave_ret; /* The AVE complex, as the parent domain of the encoders' enabled domains */ @@ -816,6 +1023,55 @@ struct apple_sleep { unsigned int ps_unlatched_count; /* T8132: what macOS polls off after its complex words, still on at that point. */ u32 quiesce_still_on; + /* The sleep bus's queue, by its SPMI generation */ + u32 spmi_status; + u32 spmi_rx_empty; + u32 spmi_cmd; + u32 spmi_reply; + u32 spmi_notify_enable; + u32 spmi_notify_ack; + /* + * Gen 4: nub-spmi0's controller device, whose exchange lock the sleep's own PMU writes + * take (apple_spmi_fifo_trylock()); the PMU's latched sources in its status words, from + * apple,spmi-pmu-sources; the words as read at the entry and at the wake; and how many + * PMU writes found the lock taken. + */ + struct device *pmu_bus; + u32 spmi_pmu_status, spmi_pmu_bits; + u32 spmi_pmu_enable_saved; + bool spmi_pmu_wake_armed; + u32 spmi_src[2][SPMI4_SRC_WORDS]; + bool spmi_src_read[2]; + unsigned int pmu_busy, pmu_busy_forced; + /* + * T8142: each PS write-disable word as read at the entry and after the wake, and which + * of the SoC's bits the entry cleared; AON_WDT_SLEEP as read before WD2 was armed. + */ + u32 ps_wr_dis_entry[SLEEP_PS_WR_DIS_MAX]; + u32 ps_wr_dis_wake[SLEEP_PS_WR_DIS_MAX]; + u32 ps_wr_dis_cleared; + bool ps_wr_dis_read; + u32 aon_wdt_saved; + bool aon_wdt_marked; + /* T8142: each complex's ACC word 0xe440f8 (optional), and what its steps returned */ + void __iomem *acc_e; + void __iomem *acc_p; + int cluster_p_ret; + int perf_soc_ret; + int perf_dcs_ret; + unsigned int perf_dcs_from; + /* With radio_retrain: the radio's PCIe host, and its port's blocks and tables */ + struct device_node *radio_host_np; + void __iomem *radio_port; + void __iomem *radio_lane; + void __iomem *radio_cfg; + struct apple_tunable *radio_port_tunable; + struct apple_tunable *radio_rc_tunable[3]; + bool radio_trainable; + int radio_train_ret; + /* The radio's port stop at the commit (sleep_radio_port_stop()), and its first timeout */ + int radio_stop_ret; + const char *radio_stop_step; }; static struct apple_sleep *apple_sleep; @@ -863,6 +1119,34 @@ static bool apple_sleep_coproc_ready_node(const struct device_node *np) return false; } +/* + * Untested SoCs (apple_sleep_soc.untested): deep sleep offered at all, and the commit allowed. + * The second is for one sleep at a time: aurora-sleep-test sets it and clears it after. + */ +static bool sleep_deep; +module_param_named(deep, sleep_deep, bool, 0444); +MODULE_PARM_DESC(deep, "Untested SoC: offer deep sleep in mem_sleep (never the default)"); +static bool sleep_untested_commit; +module_param_named(untested_commit, sleep_untested_commit, bool, 0644); +MODULE_PARM_DESC(untested_commit, + "Untested SoC: let a deep sleep through to the commit (else a dry run that refuses)"); + +/* + * Untested SoCs: each step of a sleep in PMU scratch, readable after a reset. J815's ADT + * pmu-main info-scrpad is 0x8000 + 0x2800; aurora-silicon/linux#1664 (T6041) notes its steps + * at 0x8308 too. +0 magic, +1 the last step, +2/+4 the step's own detail, +3 the attempt's + * count this boot. The boot after reads and clears them. + */ +#define PMU_NOTE_BASE 0x8308 +#define PMU_NOTE_MAGIC 0xa5 +static bool sleep_pmu_notes = true; +module_param_named(pmu_notes, sleep_pmu_notes, bool, 0644); +MODULE_PARM_DESC(pmu_notes, "Untested SoC: note each sleep step in PMU scratch, for after a reset"); + +static void sleep_note(struct apple_sleep *s, u8 step); +static void sleep_note_at(struct apple_sleep *s, u8 off, u8 val); +static int sleep_ps_restore(void __iomem *reg, u32 saved); + static bool sleep_usb_asleep; void apple_sleep_usb_set_asleep(bool asleep) @@ -1445,6 +1729,9 @@ static void apple_sleep_coproc_stop(struct apple_sleep *s, struct apple_sleep_co s->pcie_ans_stopped |= c->pcie_ans; if (c->stopped) return; + /* +2: the slot being stopped (1-based), +4: its own step (apple_sleep_note_sub). */ + sleep_note_at(s, 2, c - apple_sleep_coprocs + 1); + sleep_note_at(s, 4, 0); c->stop_ret = c->last_stop ? c->last_stop(c->data) : 0; if (s->soc->regions && c->pcie_ans && c->stop_ret) s->ans_m5_wake_error = -EIO; @@ -1485,6 +1772,18 @@ const struct apple_sleep_smc_policy *apple_sleep_smc_policy(void) } EXPORT_SYMBOL_GPL(apple_sleep_smc_policy); +static bool sleep_j813_smc_late = true; +module_param_named(j813_smc_late, sleep_j813_smc_late, bool, 0444); +MODULE_PARM_DESC(j813_smc_late, + "TEST ONLY: J813 final SMC sleep notice after peer stops"); + +bool apple_sleep_smc_defer_notice(void) +{ + return apple_sleep && READ_ONCE(sleep_j813_smc_late) && + of_machine_is_compatible("apple,j813") && pm_suspend_via_firmware(); +} +EXPORT_SYMBOL_GPL(apple_sleep_smc_defer_notice); + int apple_sleep_smc_register(struct device *dev, int (*late_notice)(void *data, u64 *sent, u64 *ack), void *data) { @@ -1509,8 +1808,8 @@ int apple_sleep_smc_register_saved(struct device *dev, struct apple_sleep *s = apple_sleep; guard(mutex)(&apple_sleep_smc_lock); - if (!s || !s->soc->early_context || !s->soc->smc_policy || - !pm_suspend_via_firmware()) + if (!s || ((!s->soc->early_context || !s->soc->smc_policy) && + !apple_sleep_smc_defer_notice()) || !pm_suspend_via_firmware()) return -EOPNOTSUPP; if (!ops || !ops->begin || !ops->late_notice || !ops->end || s->smc.dev) return -EBUSY; @@ -1634,6 +1933,413 @@ static void t8140_deep_wfi_arm(void) sysreg_clear_set_s(SYS_APL_DEEP_SLEEP, 0, DEEP_SLEEP_ENABLE); } +/* + * T8142 (M5): the core's power-down control, S3_5_C15_C1_6 (#1963's M5_C1_6 on T6050). XNU's + * per-core init sets its bits 28:26 (26B131 kernelcache +0x4ed4098: orr #0x1c000000) and a + * kext programs the rest; iBoot leaves them clear. #1963 measured on the M5 Pro that a core + * running at EL2 without them stays powered in its last WFI, so its cluster never goes down and + * WD2 resets the SoC ~5 s after the commit: the J815's signature on every committing sleep (note + * 0x65, P complex BUSY). Set right before each core's last deep WFI, never for idle (a core that + * powered off in Linux's idle would not come back); a reset follows, so nothing restores it. + * apple_sleep.m5_pwrdn=0 leaves it alone (A/B). + */ +#define SLEEP_M5_C1_6 sys_reg(3, 5, 15, 1, 6) +#define SLEEP_M5_C1_6_PWRDN GENMASK_ULL(28, 26) +static bool sleep_m5_pwrdn = true; +module_param_named(m5_pwrdn, sleep_m5_pwrdn, bool, 0644); +MODULE_PARM_DESC(m5_pwrdn, "T8142: set S3_5_C15_C1_6[28:26] before each core's last deep WFI"); + +/* Probe: each core's value as the boot left it (E cores powered off in b45, the boot core's P complex did not). */ +static void t8142_c1_6_read(void *info) +{ + ((u64 *)info)[smp_processor_id()] = read_sysreg_s(SLEEP_M5_C1_6); +} + +static void t8142_c1_6_report(struct device *dev) +{ + u64 *v = kcalloc(nr_cpu_ids, sizeof(*v), GFP_KERNEL); + char line[256]; + int cpu, n = 0; + + if (!v) + return; + on_each_cpu(t8142_c1_6_read, v, 1); + for_each_online_cpu(cpu) { + n += scnprintf(line + n, sizeof(line) - n, " %d:%llx", cpu, v[cpu]); + } + dev_info(dev, "probe: S3_5_C15_C1_6 per cpu (boot cpu%d; bits 28:26 = 0x1c000000 set before each last WFI: %s):%s\n", + raw_smp_processor_id(), READ_ONCE(sleep_m5_pwrdn) ? "yes" : "no, m5_pwrdn=0", line); + kfree(v); +} + +/* + * T8142: each core's CoreSight external debug block (J815 ADT cpuN coresight-reg 0x210010000 + + * cluster * 0x1000000 + core * 0x100000, the T6040 layout). XNU's ml_arm_sleep (26B131 kc + * +0x4ed7470) unlocks it (EDLAR := 0xc5acce55) and writes EDPRCR := 0 on every core, boot and + * secondary, right before arm64_prepare_for_sleep(1); with EDPRCR.CORENPDRQ left set a core only + * emulates its power-down. apple_sleep.ed_release=0 leaves it alone (A/B). + */ +#define T8142_ED_BASE_PA 0x210010000ULL +#define T8142_ED_CLUSTER_STRIDE 0x1000000ULL +#define T8142_ED_CORE_STRIDE 0x100000ULL +#define T8142_ED_EDPRCR 0x310 +#define T8142_ED_EDPRSR 0x314 +#define T8142_ED_EDLAR 0xfb0 +#define T8142_ED_KEY 0xc5acce55 +#define T8142_ED_CLUSTERS 2 +#define T8142_ED_CORES 6 +static void __iomem *t8142_ed[T8142_ED_CLUSTERS][T8142_ED_CORES]; +static bool sleep_ed_release = true; +module_param_named(ed_release, sleep_ed_release, bool, 0644); +MODULE_PARM_DESC(ed_release, "T8142: EDLAR unlock + EDPRCR := 0 before each core's last deep WFI"); + +static void t8142_ed_unmap(void *p) +{ + iounmap((void __iomem *)p); +} + +static void t8142_ed_map(struct device *dev) +{ + unsigned int cpu, n = 0; + + for_each_possible_cpu(cpu) { + u64 mpidr = cpu_logical_map(cpu); + unsigned int c = MPIDR_AFFINITY_LEVEL(mpidr, 2), k = MPIDR_AFFINITY_LEVEL(mpidr, 0); + void __iomem *ed; + + if (c >= T8142_ED_CLUSTERS || k >= T8142_ED_CORES || t8142_ed[c][k]) + continue; + ed = ioremap_np(T8142_ED_BASE_PA + c * T8142_ED_CLUSTER_STRIDE + + k * T8142_ED_CORE_STRIDE, 0x1000); + if (!ed || devm_add_action_or_reset(dev, t8142_ed_unmap, (void __force *)ed)) + continue; + t8142_ed[c][k] = ed; + n++; + } + dev_info(dev, "probe: %u external debug windows mapped (EDPRCR := 0 before each last WFI: %s)\n", + n, READ_ONCE(sleep_ed_release) ? "yes" : "no, ed_release=0"); +} + +/* The dry run: every core's EDPRCR/EDPRSR, read from the boot core while all are up and held */ +static void t8142_ed_report(struct device *dev) +{ + char line[256]; + unsigned int cpu, n = 0; + + for_each_possible_cpu(cpu) { + u64 mpidr = cpu_logical_map(cpu); + unsigned int c = MPIDR_AFFINITY_LEVEL(mpidr, 2), k = MPIDR_AFFINITY_LEVEL(mpidr, 0); + void __iomem *ed = (c < T8142_ED_CLUSTERS && k < T8142_ED_CORES) ? t8142_ed[c][k] : NULL; + + if (ed) + n += scnprintf(line + n, sizeof(line) - n, " %d:%x/%x", cpu, + readl_relaxed(ed + T8142_ED_EDPRCR), + readl_relaxed(ed + T8142_ED_EDPRSR)); + } + dev_info(dev, "dry run: EDPRCR/EDPRSR per cpu (CORENPDRQ = EDPRCR bit 0):%s\n", line); +} + +static void t8142_ed_release(void) +{ + u64 mpidr = read_cpuid_mpidr(); + unsigned int c = MPIDR_AFFINITY_LEVEL(mpidr, 2), k = MPIDR_AFFINITY_LEVEL(mpidr, 0); + void __iomem *ed; + + if (!READ_ONCE(sleep_ed_release) || c >= T8142_ED_CLUSTERS || k >= T8142_ED_CORES) + return; + ed = t8142_ed[c][k]; + if (!ed) + return; + writel_relaxed(T8142_ED_KEY, ed + T8142_ED_EDLAR); + writel_relaxed(0, ed + T8142_ED_EDPRCR); +} + +/* + * The core's own FIQ sources, quiet before its last WFI (a pending one ends the WFI, masked or + * not). With VHE, sleep_deep_wfi_arm's cntp/cntv_ctl_el0 reach the EL2 timers only; the EL1 + * pair (_EL02) is what macOS masks (per-core init: cntp_ctl = 2). XNU's core-offline path + * (26B131 kc +0x4ed69d4) also stops the core PMU (PMCR0 := 0) before its deep WFI. + * apple_sleep.m5_quiet=0 leaves them alone (A/B). + */ +#define T8142_PMCR0 sys_reg(3, 1, 15, 0, 0) +#define T8142_UPMCR0 sys_reg(3, 7, 15, 0, 4) +#define T8142_UPMSR sys_reg(3, 7, 15, 6, 4) +#define T8142_VM_TMR_FIQ_ENA sys_reg(3, 5, 15, 1, 3) +#define T8142_CLPC_C5_0 sys_reg(3, 7, 15, 5, 0) +static bool sleep_m5_quiet = true; +module_param_named(m5_quiet, sleep_m5_quiet, bool, 0644); +MODULE_PARM_DESC(m5_quiet, "T8142: mask the EL1 timers and stop the core PMU before each core's last deep WFI"); + +/* + * The last WFI at EL1, not EL2. Under aura on J815 (kit v10, 2026-11-16), macOS's own sleep + * completed when its cores took their last WFI natively at EL1 (sleep-go-keep) and reset on WD2 + * when aura took the same WFI at EL2 for them (sleep-go-el2): Linux's signature (note 0x65, + * E complex off, P complex asked off but BUSY, the boot core's WFI held: b45 observer 0x98). + * Linux runs at EL2 (VHE), so each core drops to EL1h, MMU off, every exception masked, stage 2 + * off, no traps, and loops on WFI there. Nothing returns: a reset or the wake (RVBAR) follows. + * apple_sleep.el1_wfi: 0 = at EL2 (default), 1 = the boot core only, 2 = every core. + */ +/* + * The dry run's register readouts (IMPDEF sysregs, every core's ED block, the C1_6 write test): + * never booted before 2026-11-16, and a dry-run report has reset the Mac before (b32), so they + * only run when asked: echo 1 > /sys/module/apple_sleep/parameters/dry_regs. + */ +static bool sleep_dry_regs; +module_param_named(dry_regs, sleep_dry_regs, bool, 0644); +MODULE_PARM_DESC(dry_regs, "T8142: print the core register readouts at each dry run (off by default)"); + +/* + * Default 0 again since 2026-11-16 14:4x: with 2, the E complex stayed BUSY 2 s after the commit + * (note 0x67, boot 475520fe); with 0 it powered off, in either release order (fe1573cb, 2335a7e7). + */ +static unsigned int sleep_el1_wfi; +module_param_named(el1_wfi, sleep_el1_wfi, uint, 0644); +MODULE_PARM_DESC(el1_wfi, "T8142: take the last WFI at EL1: 0 no, 1 boot core, 2 every core"); + +/* + * Where the stopped cores take their deep WFI. XNU (ml_arm_sleep): each other core writes its + * stop bit, waits for the boot core's flag, then takes its deep WFI; the boot core clears the + * flag and only then runs the platform quiesce actions, the PMGR's last mile and the S2R + * timer among them. Thomas's J813 trace (all ten cores, 27.2, 2026-11-16) has it so: the nine + * stop bits at -6.7..-6.06 ms, the boot core's first PCIe word at -5.79 ms, the timer at 0. + * Linux held them in WFE through the memory stop and the clusters' off words and released + * them after the timer (#1963's T6050 order). 1 (default): XNU's order, the cores in their + * deep WFI before the last mile; 0: after the commit, as before. + */ +static bool sleep_early_wfi = true; +module_param_named(early_wfi, sleep_early_wfi, bool, 0644); +MODULE_PARM_DESC(early_wfi, "T8142: stopped cores take their deep WFI before the last mile (XNU's order), not after the commit"); +#define SLEEP_EARLY_WFI_SETTLE_US 300 + +/* + * T8142 DIAGNOSTIC, b45's observer back on the current tree (2026-11-16 14:4x): E core 0 does not + * take its last WFI; it waits for the boot core's, samples at +20 ms, +300 ms and +observer_ms, + * writes note 0x6a (one flag byte per sample: bit 0 commit word nonzero, 1/2 complex E/P asked + * on, 3/4 E/P busy, 5 the boot core's WFI came back, 6 an armed wake source pending, 7 the boot + * core reached its WFI), then takes its own last WFI, so the sleep can still complete. It answers + * what the post-commit probe can't: does complex P power down once the boot core is in its WFI. + * 0: off (default). + */ +static unsigned int sleep_observer_ms; +module_param_named(observer_ms, sleep_observer_ms, uint, 0644); +MODULE_PARM_DESC(observer_ms, "T8142 DIAGNOSTIC: E core 0 watches complex P for this many ms after the boot core's last WFI (note 0x6a), then sleeps (0 = off)"); +static u32 t8142_obs_boot_wfi, t8142_obs_wfi_back; + +/* + * T8142 DIAGNOSTIC (b43's post_commit_note, back on the current tree, 2026-11-16): after the + * commit and the other cores' release, the boot core spins this many ms instead of taking its + * WFI, writes note 0x66 (what the engine left: the commit word, both complexes, a pending armed + * wake, the perf states, the PMC voters), then takes its WFI, so the sleep can still go down. + * The one J815 run that slept and ran the engine's wake program (b43 run 32535966) was such a + * probe. 0: off (default). The SPMI writes come after the S2R timer, as macOS's own do. + */ +static unsigned int sleep_post_commit_ms; +module_param_named(post_commit_ms, sleep_post_commit_ms, uint, 0644); +MODULE_PARM_DESC(post_commit_ms, "T8142 DIAGNOSTIC: the boot core notes the engine's state this many ms after the commit, then takes its WFI (0 = off)"); +/* + * With post_commit_ms: after note 0x66, every core's EDPRSR through its external debug window + * (bit 0 PU = the core is powered, bit 1 SPD = it powered down since the last read), note 0x67. + * A read that hangs leaves 0x66 in the PMU. 0 skips it. + */ +/* Off by default: in boot 475520fe it read PU 0 for every core, the running boot core too. */ +static bool sleep_post_commit_ed; +module_param_named(post_commit_ed, sleep_post_commit_ed, bool, 0644); +MODULE_PARM_DESC(post_commit_ed, "T8142 DIAGNOSTIC: with post_commit_ms, also note each core's EDPRSR power status (note 0x67)"); + +/* + * T8142: words the T8132-derived lists lower but macOS 27.2 leaves on at the commit (J813 trace + * g01, 2026-11-16). Bit 0: PMS_C1PPT, SOC_RC. Bit 1: I2C0/2/4, SPI0/1/3/5. macOS raises both + * groups with AUTO_ENABLE at boot and at each wake and writes neither before any of the run's + * three committed sleeps; none has a node in the J815 DT, so only this match touches them. + * Bit 2: ATC1_COMMON, ATC1_USB(_AON). Bit 3: ATC0_USB(_AON), ATC0_COMMON at + * lower_io. Both ATC ports were hidden from that guest, so bits 2 and 3 have no evidence + * behind them yet and are off by default. + */ +/* + * T8142: XNU's PMGR start puts 54 power words under AUTO_ENABLE at boot (J813 trace g01: read, + * the value with its flags cleared, then the same | AUTO_ENABLE), the same 22 + 4 as at each + * wake and 28 more. iBoot leaves them on with AUTO_ENABLE clear, and on J815 Linux leaves them + * so (dry run: PMS_C1PPT 0x2ff, I2C0 0xff): T6050's seq-boot does the same for its own words + * ("so none can gate"). This does it at the deep entry, right after the dry-run gate, for the + * words that are on without it; a refusal before the commit takes it back. + */ +static bool sleep_boot_auto_on = true; +module_param_named(boot_auto, sleep_boot_auto_on, bool, 0644); +MODULE_PARM_DESC(boot_auto, "T8142: put XNU's boot list of power words under AUTO_ENABLE at the deep entry (default Y)"); +/* + * T8142: XNU's AppleT8142MCC start (J813 trace g01: ~1120 accesses in the first ms of XNU, 677 + * writes): DCS channels' +0x580/+0x584 enables bit by bit, their lanes (+0x588 strobe/enable with + * +0x680/+0x58c), the group words, every channel's +0x24 bit 12, the AMCC planes' sleep bits 1..8 + * and config, the SoC NI tables with their +0x100 strobe. iBoot leaves all of it at reset values + * and no Linux driver does it, so J815's memory side reads 0 where macOS has 0x3ff1, 0x11, ... + * Replayed at the deep entry after the last refusal point, only if the 34 words XNU reads before + * its first write hold exactly what they hold on the J813 (iBoot's values). J813 constants on + * J815's memory controller: default off. + */ +static bool sleep_mem_boot; +module_param_named(mem_boot, sleep_mem_boot, bool, 0644); +MODULE_PARM_DESC(mem_boot, "T8142 EXPERIMENT: replay XNU's memory-controller start at the deep entry if iBoot's fingerprint matches (default N)"); +/* + * T8142: T6050's memory performance floor (its voter 1: 2, 1 at 9 ms, then 0 before the memory + * stop; "the value read back stays 0"). No T8142 evidence: J813's trace didn't hook the voters. + */ +/* + * T8142: PMP's power domain off after its firmware's final stop (Thomas Glanzmann, + * m0d16l14n1/linux#4 e754b17c, 2026-11-16): the PMP is idled and RUN cleared, but its domain + * stayed at target f; macOS lowers it (J813 g01: 0x598 0x0f0f00ff -> 0x0f0f03f0 at -12.2 ms), + * and PMS_SRAM then gates by itself. On J813 the first real sleep and return came with it. + */ +static bool sleep_pmp_off = true; +module_param_named(pmp_off, sleep_pmp_off, bool, 0644); +MODULE_PARM_DESC(pmp_off, "T8142: power the PMP's domain off after its final stop, as macOS (default Y)"); + +/* + * J815 macOS 26B131 (notes/sleep-trace/t8142-j815-26B131-entry.md): DISPEXT0, then DISPEXT1, + * then DISP, each SYS/FE up, the CPU word down in four steps, SYS/FE down, 159-137 ms before + * the S2R timer; all six DISPEXT words are off at macOS's commit. Linux's T8142 profile only + * lowered the internal DCP, while both external DCPs are bound here and their FE/SYS words read + * 0x20ff in the dry run. + */ +static bool sleep_dispext = true; +module_param_named(dispext, sleep_dispext, bool, 0644); +MODULE_PARM_DESC(dispext, "T8142: lower the external DCPs' domains with the display, as macOS (default Y)"); + +/* + * The OS-managed words (not no_ps in the J815 ADT) that macOS has off at its commit (J813 g01 + * end state) and no other step of Linux's sleep lowers: SIO_CPU (on from iBoot, no driver on + * J815; macOS lowers it 53 ms before the timer, Thomas's "inactive SIO CPU domain"), FPWM0 (the + * keyboard backlight), GLOBAL_AUX_CTRL0/1, the PCIe OCLAs (children of APCIE_SYS_GP/ST, which + * lower_io lowers) and the displays' ADMA words (children of their SYS words). Each only if on. + */ +static bool sleep_extra_off = true; +module_param_named(extra_off, sleep_extra_off, bool, 0644); +MODULE_PARM_DESC(extra_off, "T8142: lower the words macOS has off at its commit that nothing else lowers (default Y)"); + +static bool sleep_mem_floor; +module_param_named(mem_floor, sleep_mem_floor, bool, 0644); +MODULE_PARM_DESC(mem_floor, "T8142 EXPERIMENT: step PMC voter 1 down (2, 1, 0) as T6050 does (default N)"); + +static bool sleep_boot_auto_dry = true; +module_param_named(boot_auto_dry, sleep_boot_auto_dry, bool, 0644); +MODULE_PARM_DESC(boot_auto_dry, "T8142: a dry run also does boot_auto's writes, reads them back and undoes them (default Y)"); + +static unsigned int sleep_ps_keep = 0x3; +module_param_named(ps_keep, sleep_ps_keep, uint, 0644); +MODULE_PARM_DESC(ps_keep, "T8142: power words left as they are at the match, by group (bit 0 PMS_C1PPT/SOC_RC, 1 I2C/SPI, 2 ATC1, 3 ATC0 at lower_io; default 0x3)"); + +/* The T8142 wake's own restores (J813 trace), each switchable for an A/B. */ +static bool sleep_mem_restore = true; +module_param_named(mem_restore, sleep_mem_restore, bool, 0644); +MODULE_PARM_DESC(mem_restore, "T8142: put the memory side (AMCC, SoC NI, DCS) back at the wake as XNU does"); +static bool sleep_clk_restore = true; +module_param_named(clk_restore, sleep_clk_restore, bool, 0644); +MODULE_PARM_DESC(clk_restore, "T8142: put the 126 PMGR clkgen slots and the memory clock word back at the wake as XNU does"); +static bool sleep_perf_down = true; +module_param_named(perf_down, sleep_perf_down, bool, 0644); +MODULE_PARM_DESC(perf_down, "T8142: SoC/DCS perf states down before the memory stop (macOS on J813 never writes them; A/B)"); +static u64 t8142_boot_mpidr = ~0ULL; + +extern char t8142_el1_wfi_stub[], t8142_el1_wfi_stub_end[]; +asm(".pushsection .text, \"ax\"\n" + ".balign 64\n" + ".global t8142_el1_wfi_stub\n" + "t8142_el1_wfi_stub:\n" + "1: dsb sy\n" + " isb\n" + " wfi\n" + " b 1b\n" + ".global t8142_el1_wfi_stub_end\n" + "t8142_el1_wfi_stub_end:\n" + ".popsection\n"); + +static void __noreturn t8142_el1_wfi(void) +{ + write_sysreg_s(INIT_SCTLR_EL1_MMU_OFF, SYS_SCTLR_EL12); + isb(); + write_sysreg(HCR_RW | HCR_E2H, hcr_el2); + write_sysreg(PSR_MODE_EL1h | PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT, spsr_el2); + write_sysreg(__pa_symbol(t8142_el1_wfi_stub), elr_el2); + /* The EL1 loop acks nothing: no fast IPI may be left pending to end its WFI. */ + write_sysreg_s(IPI_SR_PENDING, SYS_APL_IPI_SR_EL1); + isb(); + asm volatile("eret" ::: "memory"); + unreachable(); +} + +static bool t8142_el1_wfi_here(void) +{ + unsigned int mode = READ_ONCE(sleep_el1_wfi); + + if (!is_kernel_in_hyp_mode() || !mode) + return false; + return mode >= 2 || (read_cpuid_mpidr() & MPIDR_HWID_BITMASK) == READ_ONCE(t8142_boot_mpidr); +} + +static void t8142_deep_wfi_arm(void) +{ + if (READ_ONCE(sleep_m5_pwrdn) && is_kernel_in_hyp_mode()) + sysreg_clear_set_s(SLEEP_M5_C1_6, 0, SLEEP_M5_C1_6_PWRDN); + if (READ_ONCE(sleep_m5_quiet)) { + if (is_kernel_in_hyp_mode()) { + write_sysreg_s(ARCH_TIMER_CTRL_IT_MASK, SYS_CNTP_CTL_EL02); + write_sysreg_s(ARCH_TIMER_CTRL_IT_MASK, SYS_CNTV_CTL_EL02); + } + write_sysreg_s(0, T8142_PMCR0); + isb(); + } + t8142_ed_release(); + t8140_deep_wfi_arm(); + if (t8142_el1_wfi_here()) { + dsb(sy); + t8142_el1_wfi(); + } +} + +static u8 t8142_fiq_sources(void) +{ + u8 m = 0; +#define FIRING(v) (((v) & (ARCH_TIMER_CTRL_ENABLE | ARCH_TIMER_CTRL_IT_MASK | ARCH_TIMER_CTRL_IT_STAT)) == \ + (ARCH_TIMER_CTRL_ENABLE | ARCH_TIMER_CTRL_IT_STAT)) + if (FIRING(read_sysreg(cntp_ctl_el0))) + m |= 0x01; + if (FIRING(read_sysreg(cntv_ctl_el0))) + m |= 0x02; + if (is_kernel_in_hyp_mode()) { + if (FIRING(read_sysreg_s(SYS_CNTP_CTL_EL02))) + m |= 0x04; + if (FIRING(read_sysreg_s(SYS_CNTV_CTL_EL02))) + m |= 0x08; + } +#undef FIRING + if (read_sysreg_s(T8142_PMCR0) & BIT(11)) + m |= 0x10; + if (read_sysreg_s(SYS_APL_IPI_SR_EL1) & IPI_SR_PENDING) + m |= 0x20; + if (read_sysreg_s(T8142_UPMSR) & BIT(0)) + m |= 0x40; + return m; +} + +/* + * The boot core's last WFI (at EL2) returned while it should be powered off: note 0x6c once, 100 ms + * into the loop (past the engine's 33 ms window, so no SPMI traffic while the sleep can still + * go through): +2 0x80 | ISR_EL1's A/I/F (bits 2/1/0), +4 the core's own FIQ sources still + * firing (0x01 CNTP/EL2, 0x02 CNTV/EL2, 0x04 CNTP_EL02, 0x08 CNTV_EL02, 0x10 PMC, 0x20 IPI, + * 0x40 UPMC). The next boot reads 0x6c (it woke over and over) or 0x65 (it sat in WFI). + */ +static void t8142_wfi_returned(struct apple_sleep *s, u64 t0, bool *noted) +{ + u64 isr; + + if (*noted || read_sysreg(cntpct_el0) - t0 < arch_timer_get_cntfrq() / 10) + return; + *noted = true; + isr = read_sysreg(isr_el1); + sleep_note_at(s, 2, 0x80 | ((isr >> 6) & 7)); + sleep_note_at(s, 4, t8142_fiq_sources()); + sleep_note(s, 0x6c); +} + static void sleep_deep_wfi_arm(void) { /* A timer left running ends the WFI, and costs power until reset. */ @@ -1663,8 +2369,67 @@ static void sleep_cpu_stop(u64 mpidr) dsb(sy); } +static u8 t8142_obs_sample(struct apple_sleep *s) +{ + const struct apple_sleep_soc *soc = s->soc; + u32 e = readl(s->cluster + soc->cluster_cpu[0]); + u32 p = readl(s->cluster + soc->cluster_cpu[1]); + u8 f = 0; + int i; + + if (readl(s->commit)) + f |= BIT(0); + if (e & CLUSTER_ON) + f |= BIT(1); + if (p & CLUSTER_ON) + f |= BIT(2); + if (e & BIT(4)) + f |= BIT(3); + if (p & BIT(4)) + f |= BIT(4); + if (READ_ONCE(t8142_obs_wfi_back)) + f |= BIT(5); + for (i = 0; i < soc->wake_words; i++) + if (readl(s->wake + soc->wake_status + 4 * i) & s->wake_armed[i]) + f |= BIT(6); + if (READ_ONCE(t8142_obs_boot_wfi)) + f |= BIT(7); + return f; +} + +/* E core 0 with apple_sleep.observer_ms: see sleep_observer_ms. */ +static void t8142_observe(struct apple_sleep *s, unsigned int ms) +{ + u64 freq = arch_timer_get_cntfrq(), t0 = read_sysreg(cntpct_el0); + static const unsigned int at_ms[2] = { 20, 300 }; + u8 b[3]; + int i; + + /* At most 30 s for the boot core to get there (a hang before it ends at WD2 anyway). */ + while (!READ_ONCE(t8142_obs_boot_wfi) && read_sysreg(cntpct_el0) - t0 < 30 * freq) + cpu_relax(); + t0 = read_sysreg(cntpct_el0); + for (i = 0; i < 3; i++) { + u64 wait = (i < 2 ? at_ms[i] : max(ms, 301U)) * freq / 1000; + + while (read_sysreg(cntpct_el0) - t0 < wait) + cpu_relax(); + b[i] = t8142_obs_sample(s); + } + sleep_note_at(s, 2, b[0]); + sleep_note_at(s, 3, b[1]); + sleep_note_at(s, 4, b[2]); + sleep_note(s, 0x6a); +} + static void sleep_cpu_off(u64 mpidr) { + struct apple_sleep *s = apple_sleep; + unsigned int ms = READ_ONCE(sleep_observer_ms); + + if (ms && s && s->soc->ops->deep_wfi_arm == t8142_deep_wfi_arm && + (mpidr & MPIDR_HWID_BITMASK) == 0) + t8142_observe(s, ms); sleep_deep_wfi(); } @@ -1676,13 +2441,91 @@ static void sleep_cpu_down_off(u64 mpidr) sleep_deep_wfi(); } +/* + * apple_sleep.cpu_on_trace: after a sleep, one line per core start. aura's spin-table slot is + * { mpidr, flag, target, ... } with cpu-release-addr = &target, and aura bumps flag as the core + * enters its reset path: "flag a -> b" tells a core that never left reset from one that ran + * and stopped later (in the kernel's pen or its bring-up). Also the cpu-start words before and + * after, the core's power and power-gate words and its EDPRSR (bit 0 PU). + */ +static bool sleep_cpu_on_trace = true; +module_param_named(cpu_on_trace, sleep_cpu_on_trace, bool, 0644); +MODULE_PARM_DESC(cpu_on_trace, "Report each core start after a sleep (aura slot flag, cpu-start words, EDPRSR)"); + +static void __iomem *sleep_cpu_slot[NR_CPUS]; + +static void __iomem *sleep_cpu_slot_map(int cpu) +{ + struct device_node *np; + u64 rel; + + if (cpu < 0 || cpu >= NR_CPUS) + return NULL; + if (sleep_cpu_slot[cpu]) + return sleep_cpu_slot[cpu]; + np = of_get_cpu_node(cpu, NULL); + if (!np) + return NULL; + if (!of_property_read_u64(np, "cpu-release-addr", &rel) && rel >= 16) + sleep_cpu_slot[cpu] = ioremap_cache(rel - 16, 24); + of_node_put(np); + return sleep_cpu_slot[cpu]; +} + +static u64 sleep_cpu_slot_read(void __iomem *slot, unsigned int off) +{ + dcache_inval_poc((unsigned long)slot + off, (unsigned long)slot + off + 8); + return readq(slot + off); +} + +static void sleep_cpu_start_words(struct apple_sleep *s, u32 *w) +{ + w[0] = readl(s->cpu_start + CPU_START_STOP); + w[1] = readl(s->cpu_start + CPU_START_SYS); + w[2] = readl(s->cpu_start + CPU_START_CLUSTER(0)); + w[3] = readl(s->cpu_start + CPU_START_CLUSTER(1)); +} + static int sleep_cpu_on(u64 mpidr) { struct apple_sleep *s = apple_sleep; - unsigned int cluster = sleep_cpu_cluster(s, mpidr); + unsigned int cluster = sleep_cpu_cluster(s, mpidr), core = sleep_cpu_core(mpidr); + bool trace = READ_ONCE(sleep_cpu_on_trace) && s->soc->cpu_clusters >= 2; + int cpu = get_logical_index(mpidr & MPIDR_HWID_BITMASK); + void __iomem *slot = trace ? sleep_cpu_slot_map(cpu) : NULL; + u32 before[4], after[4], ps = 0, gate = 0, edprsr = ~0U; + u64 flag0 = 0, flag1 = 0; + unsigned int us = 0; + + if (trace) { + sleep_cpu_start_words(s, before); + if (slot) + flag0 = sleep_cpu_slot_read(slot, 8); + } writel(sleep_cpu_start_bit(s, mpidr), s->cpu_start + CPU_START_SYS); - writel(BIT(sleep_cpu_core(mpidr)), s->cpu_start + CPU_START_CLUSTER(cluster)); + writel(BIT(core), s->cpu_start + CPU_START_CLUSTER(cluster)); + + if (!trace) + return 0; + /* Up to 20 ms for aura's entry to count it; the kernel's own wait is 5 s. */ + for (us = 0; slot && us < 20000; us += 20) { + flag1 = sleep_cpu_slot_read(slot, 8); + if (flag1 != flag0) + break; + udelay(20); + } + sleep_cpu_start_words(s, after); + if (s->soc->ops->deep_wfi_arm == t8142_deep_wfi_arm) { + /* T8142 core words: E k at 8k, P k at 0x30 + 8k; power gates at a 0x10 stride */ + ps = readl(s->ps + (cluster ? 0x30 : 0) + 8 * core); + gate = readl(s->pwrgate + (cluster ? 0x60 : 0) + 0x10 * core); + if (cluster < T8142_ED_CLUSTERS && core < T8142_ED_CORES && t8142_ed[cluster][core]) + edprsr = readl_relaxed(t8142_ed[cluster][core] + T8142_ED_EDPRSR); + } + pr_info("apple-sleep: cpu%d start %#llx: stop/sys/e/p %x/%x/%x/%x -> %x/%x/%x/%x; aura slot %s flag %llu -> %llu after %u us; ps %#x pwrgate %#x edprsr %#x\n", + cpu, mpidr, before[0], before[1], before[2], before[3], after[0], after[1], + after[2], after[3], slot ? "mapped" : "UNMAPPED", flag0, flag1, us, ps, gate, edprsr); return 0; } @@ -1803,6 +2646,22 @@ static bool sleep_ps_full(struct apple_sleep *s, u32 offset) return FIELD_GET(PS_ACTUAL, readl(s->ps + offset)) == FIELD_MAX(PS_ACTUAL); } +/* + * A coprocessor CPU's run bit, read only where it can answer: its domain at full power. Below + * that the hardware has idled the block (these words are hardware-managed, PS_AUTO_ENABLE) and + * a read of its registers can stall the bus; at .enter, with interrupts off on the last CPU, + * nothing then runs until WD2 resets the SoC. On J815 every sleep that reached .enter did + * exactly that (b28, boots 5343a2e5 to 03fd8d38; again after the port onto the per-SoC ops, + * boot 14343f67: last PMU note 0x10), while every pm_test step up to core came back. An idled + * CPU isn't running, so below full power this says no. Without a power word nothing says the + * block is powered: no read either. + */ +static bool sleep_asc_running(struct apple_sleep *s, u32 ps, void __iomem *asc) +{ + return ps && asc && sleep_ps_full(s, ps) && + (readl(asc + ASC_CPU_CONTROL) & ASC_CPU_CONTROL_RUN); +} + /* @pd's word in "ps": a power controller node, child of the PMGR that "ps" maps. */ static int sleep_ps_offset(struct apple_sleep *s, struct device_node *pd) { @@ -2077,7 +2936,7 @@ static void apple_sleep_stray_restore(struct apple_sleep *s) s->stray_lowered = 0; } -static int apple_sleep_lower_stray(struct apple_sleep *s) +static int apple_sleep_lower_stray(struct apple_sleep *s, bool dry) { const struct apple_sleep_word *stray = s->soc->stray; int i, ret = 0; @@ -2094,6 +2953,16 @@ static int apple_sleep_lower_stray(struct apple_sleep *s) stray[i].name); continue; } + /* + * A dry run writes no power word. J815's first one with every check passing reset + * the Mac by WD2 (boot 1e652ea3) right after the core step had passed, and this + * lowering, of a domain whose block may still run, was the only write in it. + */ + if (dry) { + dev_info(s->dev, "%s is on at the last step: a real sleep lowers it here\n", + stray[i].name); + continue; + } sleep_ps_lower(s, off); s->stray_lowered |= BIT(i); if (sleep_ps_wait_off(s, off)) { @@ -2228,8 +3097,7 @@ static bool apple_sleep_gate_failed(struct apple_sleep *s) dev_err(s->dev, "%s isn't bound\n", g->name); bad++; /* Nothing will stop it, and a commit over a running CPU resets the SoC. */ - if (g->must_stop && g->asc && g->ps && sleep_ps_full(s, g->ps) && - (readl(g->asc + ASC_CPU_CONTROL) & ASC_CPU_CONTROL_RUN)) { + if (g->must_stop && sleep_asc_running(s, g->ps, g->asc)) { dev_err(s->dev, "%s runs unbound: control %#x status %#x\n", g->name, readl(g->asc + ASC_CPU_CONTROL), readl(g->asc + ASC_CPU_STATUS)); @@ -2239,24 +3107,36 @@ static bool apple_sleep_gate_failed(struct apple_sleep *s) running++; continue; } + if (!g->must_stop) + continue; /* A CPU whose domain is off isn't running, and its registers aren't there. */ if (g->ps && !sleep_ps_on(s, g->ps)) continue; - if (g->must_stop && (!g->asc || - ((readl(g->asc + ASC_CPU_CONTROL) & ASC_CPU_CONTROL_RUN) && - !apple_sleep_coproc_ready_node(g->np) && - !sleep_v27_gate_prepared(g->np)))) { - if (g->allow_unstarted || s->soc->regions) - dev_err(s->dev, "%s didn't stop: control %#x\n", g->name, - g->asc ? readl(g->asc + ASC_CPU_CONTROL) : 0); - else - dev_err(s->dev, "%s didn't stop: control %#x status %#x\n", g->name, - g->asc ? readl(g->asc + ASC_CPU_CONTROL) : 0, - g->asc ? readl(g->asc + ASC_CPU_STATUS) : 0); - bad++; - running++; - } - } + /* Its driver quiesced it: as before, that answers for a run bit, now unread. */ + if (g->asc && apple_sleep_coproc_ready_node(g->np)) + continue; + /* A firmware 27 display whose driver prepared its gate for the late stop. */ + if (g->asc && sleep_v27_gate_prepared(g->np)) + continue; + /* Idled below full power, or stopped: its registers read only at full power. */ + if (g->asc && g->ps && !sleep_asc_running(s, g->ps, g->asc)) + continue; + if (g->asc && g->ps && (g->allow_unstarted || s->soc->regions)) + dev_err(s->dev, "%s didn't stop: control %#x\n", g->name, + readl(g->asc + ASC_CPU_CONTROL)); + else if (g->asc && g->ps) + /* At full power (sleep_asc_running): its registers answer. */ + dev_err(s->dev, "%s didn't stop: control %#x status %#x\n", g->name, + readl(g->asc + ASC_CPU_CONTROL), readl(g->asc + ASC_CPU_STATUS)); + else + dev_err(s->dev, "%s didn't stop: %s\n", g->name, + g->asc ? "no power word says its registers can be read" : + "no CPU registers mapped"); + bad++; + running++; + } + + sleep_note(s, 0x26); for (i = 0; i < s->soc->ngate_off; i++) { const struct apple_sleep_word *w = &s->soc->gate_off[i]; @@ -2312,6 +3192,7 @@ static int apple_sleep_refuse(struct apple_sleep *s) bool refused = false, idled = false; int i; + sleep_note(s, 0x20); for (i = 0; i < SLEEP_COPROCS; i++) { struct apple_sleep_coproc *c = &apple_sleep_coprocs[i]; @@ -2348,6 +3229,21 @@ static int apple_sleep_refuse(struct apple_sleep *s) refused = true; } + sleep_note(s, 0x21); + /* Its first config access after the power loss would hang on the untrained link. */ + if (s->radio_host_np && !s->radio_trainable) { + struct platform_device *host = of_find_device_by_node(s->radio_host_np); + + if (host && READ_ONCE(host->dev.driver)) { + dev_err(s->dev, "refused: %s holds the radio's PCIe link, and its port can't be trained again after a real sleep\n", + dev_name(&host->dev)); + refused = true; + } + if (host) + put_device(&host->dev); + } + + sleep_note(s, 0x22); /* ANS's link needs these after a real power loss. */ if (idled && !s->soc->regions && !s->apcie_phy_tunable) { dev_err(s->dev, "refused: no tunables to bring ANS's PCIe block back\n"); @@ -2360,25 +3256,46 @@ static int apple_sleep_refuse(struct apple_sleep *s) refused = true; } + sleep_note(s, 0x23); /* The engine waits for DISP_CPU with no timeout, so this must never slip. */ for (i = 0; i < s->soc->ndisp; i++) { u32 ps = d->disp[i][0]; - if (s->display[i].bound && sleep_ps_on(s, ps) && - (readl(s->display[i].asc + ASC_CPU_CONTROL) & ASC_CPU_CONTROL_RUN) && + /* + * T8142's external DCPs have no sleep stop in their driver (no s2r_ext, not + * T6050's late stop): with apple_sleep.dispext the display's lowering stops each + * one's CPU cold, as for an unbound DCP, so a running one is no refusal. + */ + if (i != 0 && s->soc->dispext_optional) { + /* + * Undescribed (no phandle), it can't be stopped here, and iBoot leaves its + * firmware running with the domain up: the engine would wait on it. + */ + if (READ_ONCE(sleep_dispext) && !s->display[i].np && sleep_ps_on(s, ps)) { + dev_err(s->dev, + "refused: external display coprocessor %d is on (%#x: %#x) and not in apple,display-coprocessors\n", + i - 1, ps, readl(sleep_power_reg(s, ps))); + refused = true; + } + continue; + } + if (s->display[i].bound && sleep_asc_running(s, ps, s->display[i].asc) && (!apple_sleep_v27_late() || sleep_v27_final_check(i))) { dev_err(s->dev, "refused: a bound display coprocessor is still running\n"); refused = true; } } + sleep_note(s, 0x24); if (apple_sleep_gate_failed(s)) refused = true; if (refused) return -EBUSY; - return apple_sleep_lower_stray(s); + sleep_note(s, 0x28); + /* A dry run, which stops right after this, writes no power word (as in b27). */ + return apple_sleep_lower_stray(s, s->soc->untested && !READ_ONCE(sleep_untested_commit)); } static void sleep_wake_arm(struct apple_sleep *s) @@ -2416,18 +3333,62 @@ static void sleep_wake_restore(struct apple_sleep *s) * writes. The coprocessors' secure mailboxes are not used here. Whether that * holds is open. */ +static bool sleep_dispext_skip(struct apple_sleep *s, int i) +{ + return i != 0 && s->soc->dispext_optional && + (!READ_ONCE(sleep_dispext) || !s->display[i].np); +} + +/* + * apple_sleep.dispext: an external display's words back as the lowering found them, parents + * first (SYS, FE, CPU), after a refusal or at the wake (the commit saw them off, so the rewake + * leaves them). Its firmware was stopped cold; its driver's resume starts it again. + */ +static void sleep_dispext_restore(struct apple_sleep *s) +{ + const u32 (*domains)[3] = s->soc->ps.disp; + int i, k; + + for (i = 1; i < s->soc->ndisp; i++) { + if (!(s->dispext_lowered & BIT(i))) + continue; + for (k = 2; k >= 0; k--) + if (FIELD_GET(PS_TARGET, s->dispext_saved[i][k])) + sleep_ps_restore(s->ps + domains[i][k], s->dispext_saved[i][k]); + } + s->dispext_lowered = 0; + /* + * An external display's ADMA once its SYS word is up again. The internal display's stays + * off: no Linux driver uses it, and its SYS word comes back with the DCP's own resume. + */ + for (i = 1; i < s->soc->ndisp; i++) { + if (!(s->disp_adma_lowered & BIT(i))) + continue; + if (FIELD_GET(PS_ACTUAL, readl(s->ps + domains[i][2]))) + sleep_ps_restore(sleep_power_reg(s, s->soc->disp_adma[i]), + s->disp_adma_saved[i]); + s->disp_adma_lowered &= ~BIT(i); + } +} + static int sleep_display_off(struct apple_sleep *s) { const struct apple_sleep_soc *soc = s->soc; const u32 (*domains)[3] = soc->ps.disp; int n = soc->ndisp, j, i, ret = 0; + s->dispext_lowered = 0; + s->disp_adma_lowered = 0; + s->extra_stuck = 0; + s->dispext_note = soc->dispext_optional && READ_ONCE(sleep_dispext) ? 1 : 0; for (j = 0; j < n; j++) { void __iomem *asc; i = soc->display_order[j]; asc = s->display[i].asc; + if (sleep_dispext_skip(s, i)) + continue; /* * T8140's engine doesn't wait for its external display. On T8132 macOS has them * all off. @@ -2443,15 +3404,52 @@ static int sleep_display_off(struct apple_sleep *s) writel(readl(slice) & ~PS_PROT_SLICE_ON, slice); } } + if (i != 0 && soc->dispext_optional) { + int k; + + for (k = 0; k < 3; k++) + s->dispext_saved[i][k] = readl(s->ps + domains[i][k]); + s->dispext_lowered |= BIT(i); + /* +22 bits 1/2 (DISPEXT0) and 3/4 (DISPEXT1): CPU on, FE or SYS on */ + if (i <= 2 && FIELD_GET(PS_ACTUAL, s->dispext_saved[i][0])) + s->dispext_note |= BIT(2 * i - 1); + if (i <= 2 && (FIELD_GET(PS_ACTUAL, s->dispext_saved[i][1]) || + FIELD_GET(PS_ACTUAL, s->dispext_saved[i][2]))) + s->dispext_note |= BIT(2 * i); + if (sleep_asc_running(s, domains[i][0], asc)) + s->dispext_note |= 0x20; + if (soc->disp_wr_dis[i][0]) { + void __iomem *wr = s->ps + soc->disp_wr_dis[i][0]; + u32 bit = BIT(soc->disp_wr_dis[i][1]); + + if (readl(wr) & bit) { + writel(readl(wr) & ~bit, wr); + s->dispext_note |= 0x40; + } + } + } - if (sleep_ps_on(s, domains[i][0]) && asc && - (readl(asc + ASC_CPU_CONTROL) & ASC_CPU_CONTROL_RUN)) { - writel(0, asc + ASC_CPU_CONTROL); + /* apple_sleep.extra_off: the display's ADMA, a child of its SYS word, first */ + if (soc->disp_adma[i] && READ_ONCE(sleep_extra_off)) { + u32 a = soc->disp_adma[i], v = readl(sleep_power_reg(s, a)); + + s->disp_adma_saved[i] = v; + if (FIELD_GET(PS_ACTUAL, v)) { + sleep_ps_lower(s, a); + s->disp_adma_lowered |= BIT(i); + if (sleep_ps_wait_off(s, a)) + s->extra_stuck |= BIT(31); + } + } + + if (sleep_asc_running(s, domains[i][0], asc)) { + writel(0, asc + ASC_CPU_CONTROL); writel(0, asc + ASC_CPU_CONTROL); } /* Reads as a count of the DCPs powered, and macOS ends at 0. */ - writel(n - 1 - j, s->pmc_dcp); + if (s->pmc_dcp) + writel(n - 1 - j, s->pmc_dcp); if (soc->pwrgate_disp[i][0]) { if (readl(s->ps + domains[i][0]) & PS_AUTO_ENABLE) writel(readl(s->ps + domains[i][0]) & @@ -2467,6 +3465,8 @@ static int sleep_display_off(struct apple_sleep *s) for (i = 0; i < n; i++) { int err; + if (sleep_dispext_skip(s, i)) + continue; if (i != 0 && !s->display[i].bound && !s->soc->lower_unbound_displays) continue; @@ -2475,9 +3475,13 @@ static int sleep_display_off(struct apple_sleep *s) if (err) { dev_err(s->dev, "refused: display domain %#x stayed on: %#x\n", domains[i][0], readl(s->ps + domains[i][0])); + if (i != 0 && soc->dispext_optional) + s->dispext_note |= 0x80; ret = err; } } + if (soc->dispext_optional) + sleep_note_at(s, 22, s->dispext_note); return ret; } @@ -2834,6 +3838,124 @@ static void sleep_apcie_clk_off(struct apple_sleep *s) writel(readl(clk) | APCIE_CLK_OFF2, clk); } +/* The PHY's control words: at the start of "phy-block", or this far in (T8142). */ +static void __iomem *sleep_apcie_ctrl(struct apple_sleep *s) +{ + return s->apcie_phy + (s->soc->apcie_phy_ctrl ?: APCIE_PHY_CTRL); +} + +/* + * APCIECoreRCGen4::_shutdownGen4Phy (AppleT8142PCIe, macOS 27.2.1): T8132's PHY stop with + * the UP bit set first, two PHY-IP words and its delays around it. + */ +static void sleep_apcie_gen4_phy_off(struct apple_sleep *s) +{ + void __iomem *ctrl = sleep_apcie_ctrl(s); + void __iomem *run = ctrl + (APCIE_PHY_RUN - APCIE_PHY_CTRL); + void __iomem *ip = s->apcie_phy_ip; + u32 val; + + writel(readl(ctrl) | APCIE_PHY_CTRL_UP, ctrl); + udelay(10); + writel(readl(ip + APCIE_GEN4_PHY_IP_38) & ~APCIE_GEN4_PHY_IP_38_EN, + ip + APCIE_GEN4_PHY_IP_38); + writel(readl(ip + APCIE_GEN4_PHY_IP_8C) | APCIE_GEN4_PHY_IP_8C_OV, + ip + APCIE_GEN4_PHY_IP_8C); + udelay(5); + writel(readl(ctrl) | APCIE_PHY_CTRL_RESET, ctrl); + udelay(1); + writel(readl(ctrl) & ~APCIE_PHY_CTRL_CLK1REQ, ctrl); + readl_poll_timeout_atomic(ctrl, val, !(val & APCIE_PHY_CTRL_CLK1ACK), 1, APCIE_POLL_US); + udelay(1); + writel(readl(ctrl) & ~APCIE_PHY_CTRL_CLK0REQ, ctrl); + readl_poll_timeout_atomic(ctrl, val, !(val & APCIE_PHY_CTRL_CLK0ACK), 1, APCIE_POLL_US); + udelay(1); + writel(readl(ctrl) & ~APCIE_PHY_CTRL_UP, ctrl); + udelay(10); + writel(readl(run) & ~APCIE_PHY_RUN_EN2, run); + writel(readl(run) & ~APCIE_PHY_RUN_EN, run); +} + +/* + * APCIECoreRCGen4::_shutdownPciePLLs: the only pcieclkgen writes in the kext. Nothing starts + * the PLLs again: they come back with the block's power. + */ +static void sleep_apcie_gen4_pll_off(struct apple_sleep *s) +{ + void __iomem *clk = s->apcie_clkgen + APCIE_CLK_CTRL; + u32 val; + + writel((readl(clk) | APCIE_GEN4_CLK_HOLD) & ~APCIE_CLK_RUN, clk); + writel(readl(clk) | APCIE_CLK_OFF, clk); + writel(readl(clk) & ~APCIE_GEN4_CLK_EN, clk); + readl_poll_timeout_atomic(clk, val, !(val & APCIE_CLK_BUSY), 1, APCIE_POLL_US); + writel(readl(clk) | APCIE_CLK_OFF2, clk); + writel((readl(clk) & ~APCIE_CLK_OFF) | APCIE_GEN4_CLK_EN, clk); +} + +/* + * T8142's, from AppleT8142PCIe (APCIECoreRCGen4's power-down, then its gate loop), with all + * of the block's domains still on: the PHY stopped, the AUS5 domains off inside an UP-bit + * window (only once the PHY's first clock request is down), the PLLs off, the AXI enables + * cleared. Then the gate loop: gates 4 down to 0, SYS_ST, ST, SYS_GP, GP, ANS. PHY_SW is + * left on, as macOS leaves it. The radio's port is stopped first (sleep_radio_port_stop()), + * and its link is trained again after the wake (apple_sleep_radio_train()). + */ +static int sleep_radio_port_stop(struct apple_sleep *s); + +static void apple_sleep_lower_apcie_gen4(struct apple_sleep *s) +{ + const struct apple_sleep_domains *d = &s->soc->ps; + void __iomem *ctrl = sleep_apcie_ctrl(s); + bool on = sleep_ps_on(s, d->apcie_gp) && sleep_ps_on(s, d->apcie_sys_gp) && + sleep_ps_on(s, d->apcie_st) && sleep_ps_on(s, d->apcie_sys_st) && + sleep_ps_on(s, d->apcie_phy_sw); + bool clk0; + + /* The radio's port first: its link runs on this block's PHY. */ + if (s->radio_trainable && on) { + s->radio_stop_ret = sleep_radio_port_stop(s); + } else if (s->radio_trainable) { + s->radio_stop_step = "shared block already off"; + s->radio_stop_ret = -ENOLINK; + } + + if (on && s->apcie_phy && s->apcie_phy_ip && sleep_ps_on(s, d->apcie_aus5_aon) && + sleep_ps_on(s, d->apcie_aus5)) { + udelay(10); + sleep_apcie_gen4_phy_off(s); + clk0 = readl(ctrl) & APCIE_PHY_CTRL_CLK0REQ; + writel(readl(ctrl) | APCIE_PHY_CTRL_UP, ctrl); + udelay(10); + if (!clk0) { + sleep_ps_lower(s, d->apcie_aus5); + sleep_ps_lower(s, d->apcie_aus5_aon); + } + writel(readl(ctrl) & ~APCIE_PHY_CTRL_UP, ctrl); + } else { + sleep_ps_lower(s, d->apcie_aus5); + sleep_ps_lower(s, d->apcie_aus5_aon); + } + if (on && s->apcie_clkgen) + sleep_apcie_gen4_pll_off(s); + if (on && s->apcie_axi) { + writel(readl(s->apcie_axi + APCIE_AXI_EN0) & ~BIT(0), s->apcie_axi + APCIE_AXI_EN0); + writel(readl(s->apcie_axi + APCIE_AXI_EN1) & ~BIT(0), s->apcie_axi + APCIE_AXI_EN1); + } + + /* + * macOS's order on T8142 (26B131 trace, 13.0..12.8 ms before the timer): AUS5, AUS5_AON, + * PHY_SW, SYS_ST, ST, SYS_GP, GP, ANS. apple_sleep_raise_apcie_gen4() brings PHY_SW back + * after SYS_ST. + */ + sleep_ps_lower(s, d->apcie_phy_sw); + sleep_ps_lower(s, d->apcie_sys_st); + sleep_ps_lower(s, d->apcie_st); + sleep_ps_lower(s, d->apcie_sys_gp); + sleep_ps_lower(s, d->apcie_gp); + sleep_ps_lower(s, d->ans); +} + /* * ANS's own link runs on this block, and macOS takes it down with the domains. Its * order, measured on one sleep, in the same microseconds as the power words. A block's @@ -2844,6 +3966,10 @@ static void apple_sleep_lower_apcie(struct apple_sleep *s) const struct apple_sleep_domains *d = &s->soc->ps; u32 val; + if (s->soc->apcie_gen4) { + apple_sleep_lower_apcie_gen4(s); + return; + } sleep_apcie_port_stop_once(s); /* The PHY's registers need both domains on. */ if (s->apcie_phy && sleep_ps_on(s, d->apcie_phy_sw) && sleep_ps_on(s, d->apcie_sys_st)) @@ -2900,6 +4026,294 @@ static void sleep_apcie_phy_ip_apply(struct apple_sleep *s) writel(readl(ctl) & ~APCIE_PHY_IP_PLL_HOLD, ctl); } +/* + * T8142's, as AppleT8142PCIe brings the block up and as aura does at boot, where it trains + * the radio's link after it (j813_n1.c): the domains with the AXI enables the lowering + * cleared, the PHY table and its reference PLL, the PHY's clocks out of reset, its run + * enables around the PLL and lane tables, the AXI tables, then the root complex. No clock + * generator or CIO3 PLL tables. Never run after a sleep. + */ +static int apple_sleep_raise_apcie_gen4(struct apple_sleep *s) +{ + const struct apple_sleep_domains *d = &s->soc->ps; + void __iomem *ctrl = sleep_apcie_ctrl(s); + void __iomem *run = ctrl + (APCIE_PHY_RUN - APCIE_PHY_CTRL); + void __iomem *ready = ctrl + (APCIE_PHY_READY - APCIE_PHY_CTRL); + void __iomem *common = s->apcie_phy + APCIE_PHY_COMMON; + u32 val; + int ret; + + ret = sleep_ps_raise(s, d->ans); + ret |= sleep_ps_raise(s, d->apcie_gp); + ret |= sleep_ps_raise_start(s, d->apcie_sys_gp); + if (!ret) { + writel(readl(s->apcie_axi + APCIE_AXI_EN0) | BIT(0), s->apcie_axi + APCIE_AXI_EN0); + writel(readl(s->apcie_axi + APCIE_AXI_EN1) | BIT(0), s->apcie_axi + APCIE_AXI_EN1); + } + sleep_ps_raise_finish(s, d->apcie_sys_gp); + ret |= sleep_ps_raise(s, d->apcie_st); + ret |= sleep_ps_raise(s, d->apcie_sys_st); + ret |= sleep_ps_raise(s, d->apcie_phy_sw); + /* The gate loop powers all eight in the ADT's order: the AUS5 pair last. */ + ret |= sleep_ps_raise(s, d->apcie_aus5_aon); + ret |= sleep_ps_raise(s, d->apcie_aus5); + if (ret) + return ret; + + /* _apcieGPInit: the PHY table, then its reference PLL's clock-good. */ + apple_tunable_apply(s->apcie_phy, s->apcie_phy_tunable); + ret = readl_poll_timeout_atomic(common, val, val & BIT(31), 1, APCIE_POLL_US); + if (ret) + return ret; + + /* _initializeGen4Phy */ + writel(readl(ctrl) | APCIE_PHY_CTRL_CLK0REQ, ctrl); + ret = readl_poll_timeout_atomic(ctrl, val, val & APCIE_PHY_CTRL_CLK0ACK, 1, APCIE_POLL_US); + if (ret) + return ret; + udelay(1000); + writel(readl(ctrl) | APCIE_PHY_CTRL_CLK1REQ, ctrl); + ret = readl_poll_timeout_atomic(ctrl, val, val & APCIE_PHY_CTRL_CLK1ACK, 1, APCIE_POLL_US); + if (ret) + return ret; + writel(readl(ctrl) & ~APCIE_PHY_CTRL_RESET, ctrl); + udelay(1000); + writel(readl(run) | APCIE_PHY_RUN_EN, run); + sleep_apcie_phy_ip_apply(s); + writel(readl(run) | APCIE_PHY_RUN_EN2, run); + ret = readl_poll_timeout_atomic(ready, val, val & BIT(0), 1, APCIE_POLL_US); + if (ret) + return ret; + writel(readl(common) | BIT(0), common); + writel(readl(ctrl) | APCIE_PHY_CTRL_UP, ctrl); + apple_tunable_apply(s->apcie_axi, s->apcie_axi_tunable); + + /* _enableRootComplex */ + writel(0x140, s->apcie_rc + APCIE_RC_READY_CFG); + writel(readl(s->apcie_rc + APCIE_RC_READY_START) | BIT(0), + s->apcie_rc + APCIE_RC_READY_START); + + return readl_poll_timeout_atomic(s->apcie_rc + APCIE_RC_READY_STAT, val, val & BIT(0), 1, + APCIE_POLL_US); +} + +/* T8142's radio port, as aura trains it at boot (j813_n1.c: APCIECoreRCGen4Port) */ +#define RADIO_PORT_LTSSMCTL 0x80 +#define RADIO_PORT_PIPE_STS 0xa8 +#define RADIO_PORT_LINKSTS 0x208 +#define RADIO_PORT_LINKSTS_UP BIT(0) +#define RADIO_PORT_LINKSTS_BUSY BIT(2) +#define RADIO_PORT_APPCLK 0x800 +#define RADIO_PORT_STATUS 0x804 +#define RADIO_PORT_PERST 0x82c +#define RADIO_LANE_REQ0 BIT(0) +#define RADIO_LANE_REQ1 BIT(1) +#define RADIO_LANE_ACK0 BIT(2) +#define RADIO_LANE_ACK1 BIT(3) +#define RADIO_LANE_HOLD BIT(4) +#define RADIO_LANE_EN0 BIT(9) +#define RADIO_LANE_EN1 BIT(10) +#define RADIO_CFG_BUSES 0x18 +#define RADIO_CFG_RO_WR 0x8bc +#define RADIO_LINK_US 1000000 +#define PIN_MODE GENMASK(3, 1) +#define PIN_MODE_OUT 1 + +/* APCIECoreRCGen4Port::_resetPortHardware */ +static const u32 radio_port_reset[][2] = { + { 0x088, 0x110 }, { 0x148, 0xffffffff }, { 0x210, 0xffffffff }, { 0x084, 0 }, + { 0x104, 0xfffffff0 }, { 0x124, 0x100 }, { 0x16c, 0 }, { 0x13c, 0 }, + { 0x800, 0x100100 }, { 0x808, 0x1001ff }, { 0x82c, 0x10000 }, { 0x130, 0x3020000 }, + { 0x140, 0x10 }, { 0x144, 0x253770 }, { 0x834, 0 }, { 0x83c, 0 }, +}; + +static void sleep_radio_perst(struct apple_sleep *s, bool asserted) +{ + void __iomem *reg = s->pins + PIN_REG(s->radio_perst); + bool high = asserted == !s->radio_perst_low; + + writel((readl(reg) & ~(PIN_MODE | PIN_DATA)) | FIELD_PREP(PIN_MODE, PIN_MODE_OUT) | + (high ? PIN_DATA : 0), reg); +} + +/* + * After the power loss the radio's link is down, and the generic host's first config + * access to it would hang. Trained again as aura does it at boot, after the shared block + * (apple_sleep_raise_apcie_gen4()): the radio held in reset, the port's reset values and + * table, its application clock, the lane's reference clock buffer, PERST# released, the + * root port's tables with its read-only registers opened, then the LTSSM. The SMC's N1 + * reset at boot isn't repeated: the SMC keeps its state across the sleep, as T8140's + * radio keeps its rail. macOS 27.2.1's AppleCentauriManager doesn't repeat it at a wake + * either: its function-reset (SMC gP13) runs at start, at shutdown, and to recover a + * crashed driver or a chip found in ROM, after two tries of function-warm_reset (SMC + * 'bpli'). Never run after a sleep. + */ +static int apple_sleep_radio_train(struct apple_sleep *s) +{ + void __iomem *port = s->radio_port, *lane = s->radio_lane, *cfg = s->radio_cfg; + unsigned int i; + u32 val; + int ret; + + if (!sleep_ps_on(s, s->soc->ps.gpio)) + return -ENODEV; + sleep_radio_perst(s, true); + + for (i = 0; i < ARRAY_SIZE(radio_port_reset); i++) + writel(radio_port_reset[i][1], port + radio_port_reset[i][0]); + apple_tunable_apply(port, s->radio_port_tunable); + writel(readl(port + RADIO_PORT_APPCLK) | BIT(0), port + RADIO_PORT_APPCLK); + + /* APCIECoreRCGen4Port::_initializeRefclkBuffer */ + writel(readl(lane) | RADIO_LANE_REQ0, lane); + ret = readl_poll_timeout_atomic(lane, val, val & RADIO_LANE_ACK0, 1, APCIE_POLL_US); + if (ret) + return ret; + writel(readl(lane) | RADIO_LANE_REQ1, lane); + ret = readl_poll_timeout_atomic(lane, val, val & RADIO_LANE_ACK1, 1, APCIE_POLL_US); + if (ret) + return ret; + writel(readl(lane) & ~RADIO_LANE_HOLD, lane); + udelay(1000); + writel(readl(lane) | RADIO_LANE_EN0, lane); + writel(readl(lane) | RADIO_LANE_EN1, lane); + /* T(refclk-to-PERST#) */ + udelay(1000); + + writel(readl(port + RADIO_PORT_PERST) | BIT(0), port + RADIO_PORT_PERST); + sleep_radio_perst(s, false); + ret = readl_poll_timeout_atomic(port + RADIO_PORT_PIPE_STS, val, val & BIT(0), 1, + APCIE_POLL_US * 2); + if (!ret) + ret = readl_poll_timeout_atomic(port + RADIO_PORT_STATUS, val, val & BIT(0), 1, + APCIE_POLL_US * 5); + if (!ret) + ret = readl_poll_timeout_atomic(port + RADIO_PORT_LINKSTS, val, + !(val & RADIO_PORT_LINKSTS_BUSY), 1, + APCIE_POLL_US * 10); + if (ret) + return ret; + + /* _initializeRootComplex: its tables need the read-only registers open. */ + writel(readl(cfg + RADIO_CFG_RO_WR) | BIT(0), cfg + RADIO_CFG_RO_WR); + for (i = 0; i < ARRAY_SIZE(s->radio_rc_tunable); i++) + apple_tunable_apply(cfg, s->radio_rc_tunable[i]); + writel(readl(cfg + RADIO_CFG_RO_WR) & ~BIT(0), cfg + RADIO_CFG_RO_WR); + writel(1, port + RADIO_PORT_LTSSMCTL); + ret = readl_poll_timeout_atomic(port + RADIO_PORT_LINKSTS, val, + val & RADIO_PORT_LINKSTS_UP, 1, RADIO_LINK_US); + if (ret) + return ret; + + /* The root port's buses as the loader set them; the PCI core restores the rest. */ + writel(0x00010100, cfg + RADIO_CFG_BUSES); + /* PCIe's 100 ms from PERST# release to the first configuration request */ + mdelay(100); + + return 0; +} + +/* + * The radio port's stop: APCIECoreRCGen4Port::disablePortHardware in macOS 27.2.1's + * AppleT8142PCIe, the same class (APCIECoreRCGen4Port.cpp) the M5 Pro's AppleT6050PCIe + * builds and pcie-apple.c's apple_pcie_t6050_port_disable() follows. + */ +#define RADIO_PORT_INTSTAT 0x100 +#define RADIO_PORT_PERST_GUARD 0x13c +#define RADIO_PORT_LINKSTS_PHY_ALL0 BIT(12) +#define RADIO_PORT_OUTS_TRANS 0x820 +#define RADIO_PORT_STATUS_RESET BIT(2) +#define RADIO_LANE_CGEN BIT(31) +#define RADIO_CFG_DEBUG0 0x728 +#define RADIO_CFG_LTSSM GENMASK(5, 0) +#define RADIO_CFG_LTSSM_L1_IDLE 0x14 + +/* One of disablePortHardware's waits: macOS logs a timeout and goes on, and so does this. */ +static int sleep_radio_poll(struct apple_sleep *s, const char *step, void __iomem *reg, + u32 mask, u32 want, unsigned int us) +{ + u32 val; + int ret = readl_poll_timeout_atomic(reg, val, (val & mask) == want, 1, us); + + if (ret && !s->radio_stop_step) + s->radio_stop_step = step; + return ret; +} + +/* + * The reverse of apple_sleep_radio_train(), just before the shared block's PHY stops and its + * power goes, in disablePortHardware's order (27.2.1 AppleT8142PCIe; its timeouts in + * brackets): PORT_STS's link reset flag (10 ms), the outstanding transactions drained + * (10 ms), the PERST# guard bit, the link out of L1 (errata #55), PHY_STATUS_ALL0 (5 ms), + * the lane's PIPE reset status (10 ms), the port's PERST# handshake with LANE_UCTRL_IDLE_ACK + * (2 ms), PERST# asserted in the port, the lane's reference clocks off, the interrupts + * cleared, the application clock off and the port's ready flag gone. Like macOS, a wait + * that times out is only noted, and the rest still runs. Then PERST# on the pin, as macOS + * holds the Neo's radio across a sleep (T8140, measured): in reset, its power and firmware + * kept, until the wake's train releases it. Before this the N1 saw its link vanish with + * PERST# released. Derived from the binary, never run. + */ +static int sleep_radio_port_stop(struct apple_sleep *s) +{ + void __iomem *port = s->radio_port, *lane = s->radio_lane, *cfg = s->radio_cfg; + void __iomem *perst = port + RADIO_PORT_PERST; + u32 val; + int ret = 0, err; + + /* A port the loader never brought up has no link to stop. */ + if (!(readl(port + RADIO_PORT_STATUS) & BIT(0))) { + s->radio_stop_step = "port not ready"; + ret = -ENOLINK; + goto pin; + } + + ret |= sleep_radio_poll(s, "PORT_STS link reset", port + RADIO_PORT_STATUS, + RADIO_PORT_STATUS_RESET, RADIO_PORT_STATUS_RESET, 10000); + err = readl_poll_timeout_atomic(port + RADIO_PORT_OUTS_TRANS, val, + !(val & GENMASK(8, 0)) || !(val & GENMASK(23, 16)), + 1, 10000); + if (err && !s->radio_stop_step) + s->radio_stop_step = "OUTS_TRANS_STS"; + ret |= err; + writel(readl(port + RADIO_PORT_PERST_GUARD) | BIT(8), port + RADIO_PORT_PERST_GUARD); + + err = read_poll_timeout_atomic(readl, val, + FIELD_GET(RADIO_CFG_LTSSM, val) != RADIO_CFG_LTSSM_L1_IDLE, + 5, 5000, false, cfg + RADIO_CFG_DEBUG0); + if (err && !s->radio_stop_step) + s->radio_stop_step = "LTSSM stuck in L1 idle"; + ret |= err; + ret |= sleep_radio_poll(s, "PHY_STATUS_ALL0", port + RADIO_PORT_LINKSTS, + RADIO_PORT_LINKSTS_PHY_ALL0, RADIO_PORT_LINKSTS_PHY_ALL0, 5000); + ret |= sleep_radio_poll(s, "LANE_PIPE_RESET_STATUS", port + RADIO_PORT_PIPE_STS, BIT(0), + BIT(0), 10000); + writel(readl(perst) | BIT(24), perst); + ret |= sleep_radio_poll(s, "LANE_UCTRL_IDLE_ACK", port + RADIO_PORT_PIPE_STS, BIT(16), + BIT(16), 2000); + writel(readl(perst) | BIT(16), perst); + udelay(1); + writel(readl(perst) & ~BIT(0), perst); + udelay(1); + writel(readl(perst) & ~BIT(24), perst); + writel(readl(port + RADIO_PORT_PERST_GUARD) & ~BIT(8), port + RADIO_PORT_PERST_GUARD); + + writel(readl(lane) & ~RADIO_LANE_CGEN, lane); + writel(readl(lane) & ~RADIO_LANE_EN1, lane); + writel(readl(lane) & ~RADIO_LANE_EN0, lane); + writel(readl(lane) | RADIO_LANE_HOLD, lane); + writel(readl(lane) & ~RADIO_LANE_REQ0, lane); + writel(readl(lane) & ~RADIO_LANE_REQ1, lane); + + writel(~0, port + RADIO_PORT_INTSTAT); + writel(readl(port + RADIO_PORT_APPCLK) & ~BIT(0), port + RADIO_PORT_APPCLK); + ret |= sleep_radio_poll(s, "port stop", port + RADIO_PORT_STATUS, BIT(0), 0, 250000); + ret = ret ? -ETIMEDOUT : 0; +pin: + if (sleep_ps_on(s, s->soc->ps.gpio)) + sleep_radio_perst(s, true); + return ret; +} + /* * Brought up from power-off in macOS's order, measured on one sleep: all of it follows * the domains on the waking core, well before ANS runs. Whether ANS needs each step is @@ -2913,6 +4327,9 @@ static int apple_sleep_raise_apcie(struct apple_sleep *s) u32 val; int ret; + if (s->soc->apcie_gen4) + return apple_sleep_raise_apcie_gen4(s); + ret = sleep_ps_raise(s, d->ans); ret |= sleep_ps_raise(s, d->apcie_gp); ret |= sleep_ps_raise_start(s, d->apcie_sys_gp); @@ -3175,22 +4592,180 @@ static void sleep_ps_rewake_report(struct apple_sleep *s) #define T8132_PS_AON_ON_STATE 4 -/* As macOS writes the PMU: the reply's vector masked, then acknowledged, so none is left raised. */ -static void sleep_pmu_write(struct apple_sleep *s, u16 reg, u8 val) +/* + * Gen 4: the SPMI driver's exchange lock, tried. A debug note gives way to an exchange under + * way; a write the sleep needs (@must) goes ahead as before and is counted. Returns whether + * the lock is held (and must be released). + */ +static bool sleep_pmu_lock(struct apple_sleep *s, bool must, bool *skip) +{ + int ret; + + *skip = false; + if (!s->pmu_bus) + return false; + ret = apple_spmi_fifo_trylock(s->pmu_bus); + if (!ret) + return true; + /* -ENODEV: its driver is not bound, and nothing else is on the bus. */ + if (ret == -EBUSY) { + if (must) + s->pmu_busy_forced++; + else + *skip = true; + s->pmu_busy++; + } + return false; +} + +static void sleep_pmu_write_one(struct apple_sleep *s, u16 reg, u8 val, bool must) { u32 status, enable; + bool locked, skip; + int i; + + if (!s->soc->spmi_gen4) { + apple_sleep_pmu_write(s->spmi, s->soc->pmu_usid, reg, val); + return; + } + locked = sleep_pmu_lock(s, must, &skip); + if (skip) + return; - enable = readl(s->spmi + SPMI_NOTIFY_ENABLE); - writel(enable & ~SPMI_NOTIFY_REPLY, s->spmi + SPMI_NOTIFY_ENABLE); + enable = readl(s->spmi + s->spmi_notify_enable); + writel(enable & ~SPMI_NOTIFY_REPLY, s->spmi + s->spmi_notify_enable); + /* + * Gen 4 (T8142): a reply someone else left (aura writes the PMU on this queue at a wake) + * would be taken for ours, and ours left for the SPMI driver's next command. Drain before + * and after, each bounded, as aurora-silicon/linux#1664 does on T6041. + */ + for (i = 0; s->soc->spmi_gen4 && i < SPMI_DRAIN_MAX && + !(readl(s->spmi + s->spmi_status) & s->spmi_rx_empty); i++) + readl(s->spmi + s->spmi_reply); writel(((u32)reg << 16) | SPMI_CMD_WRITE | - FIELD_PREP(SPMI_CMD_USID, s->soc->pmu_usid), s->spmi + SPMI_CMD); - writel(val, s->spmi + SPMI_CMD); - if (!readl_poll_timeout_atomic(s->spmi + SPMI_STATUS, status, - !(status & SPMI_STATUS_RX_EMPTY), 1, 1000)) - readl(s->spmi + SPMI_REPLY); - writel(1, s->spmi + SPMI_NOTIFY_ACK); - writel(enable, s->spmi + SPMI_NOTIFY_ENABLE); + FIELD_PREP(SPMI_CMD_USID, s->soc->pmu_usid), s->spmi + s->spmi_cmd); + writel(val, s->spmi + s->spmi_cmd); + if (!readl_poll_timeout_atomic(s->spmi + s->spmi_status, status, + !(status & s->spmi_rx_empty), 1, 1000)) + readl(s->spmi + s->spmi_reply); + for (i = 0; s->soc->spmi_gen4 && i < SPMI_DRAIN_MAX && + !(readl(s->spmi + s->spmi_status) & s->spmi_rx_empty); i++) + readl(s->spmi + s->spmi_reply); + writel(1, s->spmi + s->spmi_notify_ack); + writel(enable, s->spmi + s->spmi_notify_enable); + if (locked) + apple_spmi_fifo_unlock(s->pmu_bus); +} + +static void sleep_pmu_write(struct apple_sleep *s, u16 reg, u8 val) +{ + sleep_pmu_write_one(s, reg, val, false); +} + +/* + * The PMU alarm also needs its peripheral interrupt routed by nub-spmi0. + * Arm only the DT-owned sources, after the old RTC event has been cleared and + * the next compare programmed. A latched event from the previous alarm must + * not turn this sleep into an immediate wake. + */ +static void sleep_spmi_alarm_wake_arm(struct apple_sleep *s) +{ + void __iomem *enable; + u32 latched, val; + + if (!s->spmi_pmu_bits) + return; + enable = s->spmi + SPMI4_SRC_ENABLE + s->spmi_pmu_status - SPMI4_SRC_STATUS; + latched = readl(s->spmi + s->spmi_pmu_status) & s->spmi_pmu_bits; + if (latched) + writel(latched, s->spmi + s->spmi_pmu_status); + val = readl(enable); + s->spmi_pmu_enable_saved = val & s->spmi_pmu_bits; + s->spmi_pmu_wake_armed = true; + writel(val | s->spmi_pmu_bits, enable); +} + +/* + * Gen 4: nub-spmi0's peripheral source words, read at the entry (@when 0) and at the wake + * (1), and the PMU's latched sources among them acknowledged where the DT names them. The + * T6050 sleep found that after the first sleep's alarm every later sleep was back within a + * second, the latched alarm holding the controller's output (an AP wake source) up; macOS + * acknowledges it at each wake. T8142's nub-spmi0 is the same generation and its output is + * the same wake source (NUB.SPMI0.SW3). Without the property the words are only read, so + * that a sleep's report shows which bits to name. + */ +static void sleep_spmi_sources(struct apple_sleep *s, unsigned int when) +{ + u32 latched; + int i; + + if (!s->soc->spmi_gen4 || s->soc->regions) + return; + for (i = 0; i < SPMI4_SRC_WORDS; i++) + s->spmi_src[when][i] = readl(s->spmi + SPMI4_SRC_STATUS + 4 * i); + s->spmi_src_read[when] = true; + if (!s->spmi_pmu_bits) + return; + latched = s->spmi_src[when][(s->spmi_pmu_status - SPMI4_SRC_STATUS) / 4] & + s->spmi_pmu_bits; + if (latched) + writel(latched, s->spmi + s->spmi_pmu_status); + if (when && s->spmi_pmu_wake_armed) { + void __iomem *enable = s->spmi + SPMI4_SRC_ENABLE + + s->spmi_pmu_status - SPMI4_SRC_STATUS; + + writel((readl(enable) & ~s->spmi_pmu_bits) | s->spmi_pmu_enable_saved, + enable); + s->spmi_pmu_wake_armed = false; + } +} + +static void sleep_spmi_sources_report(struct apple_sleep *s) +{ + static const char *const when[] = { "entry", "wake" }; + u32 *w; + int i; + + for (i = 0; i < 2; i++) { + if (!s->spmi_src_read[i]) + continue; + s->spmi_src_read[i] = false; + w = s->spmi_src[i]; + dev_info(s->dev, "nub-spmi0 sources at the %s: %08x %08x %08x %08x %08x %08x %08x %08x%s\n", + when[i], w[0], w[1], w[2], w[3], w[4], w[5], w[6], w[7], + s->spmi_pmu_bits ? ", PMU's acknowledged" : ""); + } + if (s->pmu_busy) + dev_info(s->dev, "PMU writes found the SPMI exchange lock taken %u times (%u went ahead)\n", + s->pmu_busy, s->pmu_busy_forced); + s->pmu_busy = s->pmu_busy_forced = 0; +} + +static bool sleep_notes_on(struct apple_sleep *s) +{ + return s && s->spmi && s->soc->untested && READ_ONCE(sleep_pmu_notes); +} + +/* + * Only where nothing else talks SPMI: from .prepare (every device suspended) to .wake (none + * resumed yet), on the one CPU left or before the others go. + */ +static void sleep_note_at(struct apple_sleep *s, u8 off, u8 val) +{ + if (sleep_notes_on(s)) + sleep_pmu_write(s, PMU_NOTE_BASE + off, val); +} + +static void sleep_note(struct apple_sleep *s, u8 step) +{ + sleep_note_at(s, 1, step); +} + +void apple_sleep_note_sub(u8 step) +{ + sleep_note_at(apple_sleep, 4, step); } +EXPORT_SYMBOL_GPL(apple_sleep_note_sub); /* * The DRAM-kept wake writes each of these words and gives its switch 171 us to report closed. @@ -3227,38 +4802,212 @@ static bool apple_sleep_ps_unlatch(struct apple_sleep *s) return stuck; } -static void apple_sleep_match(struct apple_sleep *s) +struct t8142_mem_op { + u64 pa; + u64 val; + u8 op; +}; +#define T8142_MEM_WRITE BIT(0) +#define T8142_MEM_64 BIT(1) +#define T8142_MEM_FP BIT(4) +#include "sleep-t8142-mem.h" + +static void t8142_mem_map(struct apple_sleep *s) { - const struct apple_sleep_soc *soc = s->soc; - int i, raised = 0, lowered = 0, failed = 0; + unsigned int i; - writel(0, s->wdt + WDT_WD0_COUNT); - writel(0, s->wdt + WDT_WD1_COUNT); - sleep_pmu_write(s, soc->pmu_sleep_reg, soc->pmu_sleep_val); + BUILD_BUG_ON(ARRAY_SIZE(t8142_mem_pages) > ARRAY_SIZE(s->mem_boot_page)); + for (i = 0; i < ARRAY_SIZE(t8142_mem_pages); i++) + s->mem_boot_page[i] = devm_ioremap(s->dev, t8142_mem_pages[i], SZ_16K); +} - s->spmi_saved[0] = readl(s->spmi + SPMI_NOTIFY_ENABLE); - s->spmi_saved[1] = readl(s->spmi_a0); - writel(soc->spmi_notify_sleep, s->spmi + SPMI_NOTIFY_ENABLE); - writel(soc->spmi_notify_sleep, s->spmi_a0); +static void __iomem *t8142_mem_va(struct apple_sleep *s, u64 pa) +{ + unsigned int i; - for (i = 0; i < soc->ps_macos_on.count; i++) { - u32 offset = soc->ps_macos_on.offset[i]; + for (i = 0; i < ARRAY_SIZE(t8142_mem_pages); i++) + if ((pa & ~(u64)(SZ_16K - 1)) == t8142_mem_pages[i]) + return s->mem_boot_page[i] ? s->mem_boot_page[i] + (pa & (SZ_16K - 1)) : NULL; + return NULL; +} - s->ps_on_saved[i] = readl(sleep_power_reg(s, offset)); - /* State 4 reads as on, and macOS has these at f. */ - if (FIELD_GET(PS_ACTUAL, s->ps_on_saved[i]) == 0xf) - continue; - /* Measured at the commit with AUTO_ENABLE clear, unlike after a wake. */ - if (sleep_ps_raise_start(s, offset)) - failed++; - raised++; - } - for (i = 0; i < soc->ps_macos_off.count; i++) { - u32 offset = soc->ps_macos_off.offset[i]; +/* The words XNU reads before its first write, against J813's (iBoot's) values: mismatches. */ +static unsigned int t8142_mem_fingerprint(struct apple_sleep *s, u64 *pa, u64 *got, u64 *want) +{ + unsigned int i, bad = 0; + + *pa = 0; + for (i = 0; i < ARRAY_SIZE(t8142_mem_boot); i++) { + const struct t8142_mem_op *o = &t8142_mem_boot[i]; + void __iomem *va; + u64 v; + + if (!(o->op & T8142_MEM_FP)) + continue; + va = t8142_mem_va(s, o->pa); + if (!va) { + bad++; + continue; + } + v = (o->op & T8142_MEM_64) ? readq(va) : readl(va); + if (v == o->val) + continue; + if (!bad++) { + *pa = o->pa; + *got = v; + *want = o->val; + } + } + return bad; +} + +/* XNU's accesses in its order: the writes as it wrote them, the reads done and dropped. */ +static void t8142_mem_replay(struct apple_sleep *s) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(t8142_mem_boot); i++) { + const struct t8142_mem_op *o = &t8142_mem_boot[i]; + void __iomem *va = t8142_mem_va(s, o->pa); + + if (!va) + continue; + if (o->op & T8142_MEM_WRITE) { + if (o->op & T8142_MEM_64) + writeq(o->val, va); + else + writel(o->val, va); + } else if (o->op & T8142_MEM_64) { + readq(va); + } else { + readl(va); + } + } +} + +static void t8142_mem_boot_entry(struct apple_sleep *s) +{ + u64 pa, got, want; + + s->mem_boot_done = false; + s->mem_boot_mismatch = 0; + if (!s->soc->mem_boot || !READ_ONCE(sleep_mem_boot)) + return; + s->mem_boot_mismatch = t8142_mem_fingerprint(s, &pa, &got, &want); + if (s->mem_boot_mismatch) + return; + t8142_mem_replay(s); + s->mem_boot_done = true; +} + +static void __iomem *sleep_boot_auto_reg(struct apple_sleep *s, unsigned int i) +{ + unsigned int n = s->soc->ps_boot_auto.count; + + return i < n ? s->ps + s->soc->ps_boot_auto.offset[i] : + s->ps_aon + s->soc->ps_aon_boot_auto.offset[i - n]; +} + +static unsigned int sleep_boot_auto_count(struct apple_sleep *s) +{ + return min_t(unsigned int, s->soc->ps_boot_auto.count + s->soc->ps_aon_boot_auto.count, + ARRAY_SIZE(s->boot_auto_saved)); +} + +/* As XNU's PMGR start: the value with its flags cleared, then AUTO_ENABLE. On words that are on. */ +static int sleep_boot_auto(struct apple_sleep *s) +{ + unsigned int i, n = sleep_boot_auto_count(s); + int set = 0; + + s->boot_auto_set = 0; + s->boot_auto_nset = s->boot_auto_stuck = 0; + if (!READ_ONCE(sleep_boot_auto_on)) + return 0; + for (i = 0; i < n; i++) { + void __iomem *reg = sleep_boot_auto_reg(s, i); + u32 v = readl(reg); + + if ((v & PS_AUTO_ENABLE) || !FIELD_GET(PS_TARGET, v) || !FIELD_GET(PS_ACTUAL, v)) + continue; + s->boot_auto_saved[i] = v; + s->boot_auto_set |= BIT_ULL(i); + writel(v & ~PS_FLAGS, reg); + readl(reg); + writel((v & ~PS_FLAGS) | PS_AUTO_ENABLE, reg); + set++; + if (readl(reg) & PS_AUTO_ENABLE) + s->boot_auto_stuck++; + } + s->boot_auto_nset = set; + return set; +} + +/* A refusal before the commit: AUTO_ENABLE off again where this set it, the target as it was. */ +static void sleep_boot_auto_undo(struct apple_sleep *s) +{ + unsigned int i, n = sleep_boot_auto_count(s); + + for (i = 0; i < n; i++) + if (s->boot_auto_set & BIT_ULL(i)) + writel(s->boot_auto_saved[i] & ~PS_FLAGS, sleep_boot_auto_reg(s, i)); + s->boot_auto_set = 0; +} + +/* Whether the match leaves this word as it is (apple_sleep.ps_keep, as the match took it) */ +static bool sleep_ps_kept(struct apple_sleep *s, u32 offset, bool aon) +{ + unsigned int i; + + for (i = 0; i < s->soc->nps_keep; i++) { + const struct apple_sleep_ps_keep *k = &s->soc->ps_keep[i]; + + if (k->offset == offset && k->aon == aon) + return s->ps_keep_mask & BIT(k->group); + } + + return false; +} + +static void apple_sleep_match(struct apple_sleep *s) +{ + const struct apple_sleep_soc *soc = s->soc; + int i, raised = 0, lowered = 0, failed = 0, kept = 0; + + s->ps_keep_mask = READ_ONCE(sleep_ps_keep); + + writel(0, s->wdt + WDT_WD0_COUNT); + writel(0, s->wdt + WDT_WD1_COUNT); + sleep_pmu_write_one(s, soc->pmu_sleep_reg, soc->pmu_sleep_val, true); + + sleep_spmi_sources(s, 0); + s->spmi_saved[0] = readl(s->spmi + s->spmi_notify_enable); + s->spmi_saved[1] = readl(s->spmi_a0); + writel(soc->spmi_notify_sleep, s->spmi + s->spmi_notify_enable); + writel(soc->spmi_notify_sleep, s->spmi_a0); + + for (i = 0; i < soc->ps_macos_on.count; i++) { + u32 offset = soc->ps_macos_on.offset[i]; + + s->ps_on_saved[i] = readl(sleep_power_reg(s, offset)); + /* State 4 reads as on, and macOS has these at f. */ + if (FIELD_GET(PS_ACTUAL, s->ps_on_saved[i]) == 0xf) + continue; + /* Measured at the commit with AUTO_ENABLE clear, unlike after a wake. */ + if (sleep_ps_raise_start(s, offset)) + failed++; + raised++; + } + for (i = 0; i < soc->ps_macos_off.count; i++) { + u32 offset = soc->ps_macos_off.offset[i]; s->ps_off_saved[i] = readl(sleep_power_reg(s, offset)); if (!sleep_ps_on(s, offset)) continue; + if (sleep_ps_kept(s, offset, false)) { + kept++; + continue; + } sleep_ps_lower(s, offset); lowered++; } @@ -3269,6 +5018,10 @@ static void apple_sleep_match(struct apple_sleep *s) s->ps_aon_saved[i] = val; if (!FIELD_GET(PS_ACTUAL, val)) continue; + if (sleep_ps_kept(s, soc->ps_aon_macos_off.offset[i], true)) { + kept++; + continue; + } if (val & PS_AUTO_ENABLE) { val &= ~(PS_AUTO_ENABLE | PS_FLAGS); writel(val, reg); @@ -3303,12 +5056,14 @@ static void apple_sleep_match(struct apple_sleep *s) for (i = 0; i < soc->ps_macos_off.count; i++) { u32 offset = soc->ps_macos_off.offset[i]; + if (sleep_ps_kept(s, offset, false)) + continue; if (sleep_ps_wait_off(s, offset)) dev_dbg(s->dev, "still on, macOS has it off: %x = %x\n", offset, readl(sleep_power_reg(s, offset))); } - dev_dbg(s->dev, "macOS's power words: raised %d, %d of them failed, lowered %d\n", - raised, failed, lowered); + dev_dbg(s->dev, "macOS's power words: raised %d, %d of them failed, lowered %d, kept on %d\n", + raised, failed, lowered, kept); } /* Back as they were, after a refusal past the match or a real wake. */ @@ -3328,11 +5083,13 @@ static void apple_sleep_match_undo(struct apple_sleep *s) writel(s->ps_aon_auto_saved[i] & ~PS_FLAGS, s->ps_aon + soc->ps_aon_macos_no_auto.offset[i]); for (i = soc->ps_aon_macos_off.count - 1; i >= 0; i--) - if (FIELD_GET(PS_ACTUAL, s->ps_aon_saved[i])) + if (FIELD_GET(PS_ACTUAL, s->ps_aon_saved[i]) && + !sleep_ps_kept(s, soc->ps_aon_macos_off.offset[i], true)) writel(s->ps_aon_saved[i] & ~PS_FLAGS, s->ps_aon + soc->ps_aon_macos_off.offset[i]); for (i = soc->ps_macos_off.count - 1; i >= 0; i--) - if (FIELD_GET(PS_ACTUAL, s->ps_off_saved[i])) + if (FIELD_GET(PS_ACTUAL, s->ps_off_saved[i]) && + !sleep_ps_kept(s, soc->ps_macos_off.offset[i], false)) sleep_ps_raise(s, soc->ps_macos_off.offset[i]); for (i = soc->ps_macos_on.count - 1; i >= 0; i--) { u32 val = s->ps_on_saved[i]; @@ -3342,13 +5099,69 @@ static void apple_sleep_match_undo(struct apple_sleep *s) else if (FIELD_GET(PS_ACTUAL, val) != 0xf) writel(val & ~PS_FLAGS, s->ps + soc->ps_macos_on.offset[i]); } - writel(s->spmi_saved[0], s->spmi + SPMI_NOTIFY_ENABLE); + /* What the PMU sent while the SoC slept (its wake), before the run-time mask */ + sleep_spmi_sources(s, 1); + writel(s->spmi_saved[0], s->spmi + s->spmi_notify_enable); writel(s->spmi_saved[1], s->spmi_a0); } +/* + * After the enclave's stop, with nothing left that refuses: each PS write-disable bit the SoC + * names, cleared where set, so that the coprocessor stops and the lowering below reach their + * words. They are not set again after the wake. Linux never needs them, the drivers' power-ups + * would be dropped if they were, and a deep sleep loses the PMGR's state anyway; the words + * are read again after the wake so the report shows what the PMGR came back with. + */ +static void sleep_ps_wr_dis_clear(struct apple_sleep *s) +{ + const struct apple_sleep_soc *soc = s->soc; + int i; + + s->ps_wr_dis_cleared = 0; + for (i = 0; i < soc->nps_wr_dis; i++) { + void __iomem *reg = s->ps + soc->ps_wr_dis[i].offset; + u32 val = readl(reg); + + s->ps_wr_dis_entry[i] = val; + if (!(val & BIT(soc->ps_wr_dis[i].bit))) + continue; + writel(val & ~BIT(soc->ps_wr_dis[i].bit), reg); + s->ps_wr_dis_cleared |= BIT(i); + } +} + +static void sleep_ps_wr_dis_woke(struct apple_sleep *s) +{ + int i; + + for (i = 0; i < s->soc->nps_wr_dis; i++) + s->ps_wr_dis_wake[i] = readl(s->ps + s->soc->ps_wr_dis[i].offset); + s->ps_wr_dis_read = s->soc->nps_wr_dis > 0; +} + +static void sleep_ps_wr_dis_report(struct apple_sleep *s) +{ + const struct apple_sleep_ps_wr_dis *e = s->soc->ps_wr_dis; + int i; + + if (!s->ps_wr_dis_read) + return; + s->ps_wr_dis_read = false; + for (i = 0; i < s->soc->nps_wr_dis; i++) + dev_info(s->dev, "PS write-disable %s (ps+%#x bit %u): %#x at the entry%s, %#x after the wake\n", + e[i].name, e[i].offset, e[i].bit, s->ps_wr_dis_entry[i], + s->ps_wr_dis_cleared & BIT(i) ? " (cleared)" : "", + s->ps_wr_dis_wake[i]); +} + /* The safety net, as macOS arms it. */ static void apple_sleep_arm_wd2(struct apple_sleep *s) { + if (s->soc->aon_wdt_sleep) { + s->aon_wdt_saved = readl(s->aon_misc + AON_WDT_SLEEP); + writel(s->aon_wdt_saved | s->soc->aon_wdt_sleep, s->aon_misc + AON_WDT_SLEEP); + s->aon_wdt_marked = true; + } writel(0, s->wdt + WDT_WD0_CTL); apple_sleep_set_wd2(s, WDT_SLEEP_SECS); writel(0, s->aon_misc + AON_AP_DEADLINE); @@ -3432,12 +5245,25 @@ static void apple_sleep_dcs_down(struct apple_sleep *s) /* The boot core's last WFI. An event that ends it is taken, and the WFI taken again. */ static void __noreturn sleep_boot_wfi(struct apple_sleep *s) { + bool t8142 = s->soc->ops->deep_wfi_arm == t8142_deep_wfi_arm, noted = false; + bool observed = t8142 && READ_ONCE(sleep_observer_ms); + u64 t0; + + if (observed) { + WRITE_ONCE(t8142_obs_boot_wfi, 1); + dsb(sy); + } sleep_deep_wfi_arm(); + t0 = read_sysreg(cntpct_el0); while (true) { dsb(sy); isb(); wfi(); + if (observed) + WRITE_ONCE(t8142_obs_wfi_back, READ_ONCE(t8142_obs_wfi_back) + 1); + else if (t8142) + t8142_wfi_returned(s, t0, ¬ed); s->soc->ops->aic_ack(); write_sysreg_s(IPI_SR_PENDING, SYS_APL_IPI_SR_EL1); } @@ -3465,10 +5291,13 @@ static void apple_sleep_wait_still_on(struct apple_sleep *s) * before this, with no SPMI traffic near the engine. */ static bool sleep_v27_selected_for(struct apple_sleep *s); +static void t8142_last_mile(struct apple_sleep *s); +static void t8142_post_commit_probe(struct apple_sleep *s, unsigned int ms); static int apple_sleep_commit(unsigned long unused) { struct apple_sleep *s = apple_sleep; + bool early; if (s->soc->ops->commit_begin) s->soc->ops->commit_begin(s); @@ -3478,7 +5307,20 @@ static int apple_sleep_commit(unsigned long unused) * stay coherent until the commit. */ s->siq_cfg = read_sysreg_s(SYS_APL_SIQ_CFG_EL1); + WRITE_ONCE(t8142_boot_mpidr, read_cpuid_mpidr() & MPIDR_HWID_BITMASK); + sleep_note(s, 0x60); + WRITE_ONCE(t8142_obs_boot_wfi, 0); + WRITE_ONCE(t8142_obs_wfi_back, 0); + early = s->soc->early_cpu_wfi && READ_ONCE(sleep_early_wfi); + if (early) { + /* Released before the stop: each core goes from its stop bit to its deep WFI. */ + spin_table_pen_deep_el1(s->soc->ops->deep_wfi_arm == t8142_deep_wfi_arm && + is_kernel_in_hyp_mode() && READ_ONCE(sleep_el1_wfi) >= 2); + spin_table_release_stopped(); + } s->cpus_stop_ret = spin_table_stop_parked(); + if (early) + udelay(SLEEP_EARLY_WFI_SETTLE_US); if (s->soc->ops->commit_regs) { /* A SoC whose irreversible steps share nothing with the ones below. */ @@ -3514,9 +5356,15 @@ static int apple_sleep_commit(unsigned long unused) s->soc->ops->post_timer(s); /* Each core's deep WFI comes after the commit, this one last. No SPMI from here on. */ - spin_table_release_stopped(); + if (!early) { + spin_table_pen_deep_el1(s->soc->ops->deep_wfi_arm == t8142_deep_wfi_arm && + is_kernel_in_hyp_mode() && READ_ONCE(sleep_el1_wfi) >= 2); + spin_table_release_stopped(); + } if (s->soc->boot_wfi_delay_ms) mdelay(s->soc->boot_wfi_delay_ms); + if (s->soc->ops->last_mile == t8142_last_mile && READ_ONCE(sleep_post_commit_ms)) + t8142_post_commit_probe(s, READ_ONCE(sleep_post_commit_ms)); sleep_boot_wfi(s); } @@ -3750,8 +5598,8 @@ static void t8132_last_mile(struct apple_sleep *s) writel(0, s->cluster + soc->cluster_cpu[i]); s->quiesce_still_on = 0; - for (i = 0; i < ARRAY_SIZE(t8132_quiesce_words); i++) - if (sleep_ps_on(s, t8132_quiesce_words[i])) + for (i = 0; i < soc->quiesce.count; i++) + if (sleep_ps_on(s, soc->quiesce.offset[i])) s->quiesce_still_on |= BIT(i); /* All four read back unchanged on macOS. */ @@ -3922,11 +5770,12 @@ static void t8132_wake(struct apple_sleep *s) static int apple_sleep_smc_late_notice(struct apple_sleep *s) { - if (!s->soc->smc_policy) + if (!s->soc->smc_policy && !apple_sleep_smc_defer_notice()) return 0; if (!s->smc.dev || !s->smc.late_notice) return -ENODEV; - if (s->soc->early_context && (!s->smc.saved_ops || !s->smc.held)) + if ((s->soc->early_context || apple_sleep_smc_defer_notice()) && + (!s->smc.saved_ops || !s->smc.held)) return -EBUSY; return s->smc.late_notice(s->smc.data, &s->smc_idle_sent, &s->smc_idle_ack); } @@ -4104,6 +5953,9 @@ static int apple_sleep_enter_early(struct apple_sleep *s) return ret; } +static void t8142_mem_save(struct apple_sleep *s); +static void t8142_clk_save(struct apple_sleep *s); + static int apple_sleep_enter(suspend_state_t state) { struct apple_sleep *s = apple_sleep; @@ -4112,35 +5964,344 @@ static int apple_sleep_enter(suspend_state_t state) if (s->soc->early_context) return apple_sleep_enter_early(s); + /* Refuse while all peer stops are still reversible. */ + if (apple_sleep_smc_defer_notice()) { + if (!s->smc.dev || !s->smc.late_notice) + return -ENODEV; + if (!s->smc.saved_ops || !s->smc.held) + return -EBUSY; + } + + sleep_note(s, 0x10); ret = apple_sleep_refuse(s); - if (ret) + if (ret) { + sleep_note(s, 0x2f); return ret; + } + sleep_note(s, 0x29); + /* + * An untested SoC stops here unless asked: every check has run, the stray words are + * lowered (and come back below), and nothing that can't be undone has. + */ + if (s->soc->untested && !READ_ONCE(sleep_untested_commit)) { + sleep_note(s, 0x31); + apple_sleep_stray_restore(s); + /* nub-spmi0's latched sources as a sleep would find them, for apple,spmi-pmu-sources: + * read only while the DT names no bits (then this acknowledges them, as the entry does). + */ + sleep_spmi_sources(s, 0); + sleep_spmi_sources_report(s); + /* The boot core's power controls here, to diff against macOS's at its commit (aura's + * R.* ring markers). Reads only: interrupts are off and the secondaries are held. + */ + if (READ_ONCE(sleep_dry_regs) && s->soc->ops->deep_wfi_arm == t8142_deep_wfi_arm && is_kernel_in_hyp_mode()) + dev_info(s->dev, "dry run: boot cpu%d C1_6 %#llx C6_2 %#llx C5_0 %#llx C10_4 %#llx C7_4 %#llx C1_1 %#llx\n", + raw_smp_processor_id(), read_sysreg_s(SLEEP_M5_C1_6), + read_sysreg_s(sys_reg(3, 5, 15, 6, 2)), read_sysreg_s(sys_reg(3, 5, 15, 5, 0)), + read_sysreg_s(sys_reg(3, 4, 15, 10, 4)), read_sysreg_s(sys_reg(3, 1, 15, 7, 4)), + read_sysreg_s(sys_reg(3, 5, 15, 1, 1))); + /* What XNU's per-core init (26B131 kc +0x4ed3d3c) writes on every core: c1_5 = 0, + * c14_6 = 3, c10_4 = 0, c9_6 |= ..|0xf, c0_5 = 1, c13_4 = 2; cntkctl |= 3. + */ + if (READ_ONCE(sleep_dry_regs) && s->soc->ops->deep_wfi_arm == t8142_deep_wfi_arm && is_kernel_in_hyp_mode()) + dev_info(s->dev, "dry run: boot cpu XNU-init regs: s3_1_c15_c1_5 %#llx s3_4_c15_c14_6 %#llx s3_4_c15_c9_6 %#llx s3_1_c15_c0_5 %#llx s3_1_c15_c13_4 %#llx cntkctl %#llx\n", + read_sysreg_s(sys_reg(3, 1, 15, 1, 5)), read_sysreg_s(sys_reg(3, 4, 15, 14, 6)), + read_sysreg_s(sys_reg(3, 4, 15, 9, 6)), read_sysreg_s(sys_reg(3, 1, 15, 0, 5)), + read_sysreg_s(sys_reg(3, 1, 15, 13, 4)), read_sysreg(cntkctl_el1)); + if (READ_ONCE(sleep_dry_regs) && s->soc->ops->deep_wfi_arm == t8142_deep_wfi_arm) { + dev_info(s->dev, "dry run: boot cpu FIQ sources: PMCR0 %#llx UPMCR0 %#llx UPMSR %#llx IPI_SR %#llx cntp/cntv_el0 %#llx/%#llx cntp/cntv_el02 %#llx/%#llx VM_TMR_FIQ_ENA %#llx ISR %#llx CLPC C5_0 %#llx; still firing %#x\n", + read_sysreg_s(T8142_PMCR0), read_sysreg_s(T8142_UPMCR0), read_sysreg_s(T8142_UPMSR), + read_sysreg_s(SYS_APL_IPI_SR_EL1), read_sysreg(cntp_ctl_el0), read_sysreg(cntv_ctl_el0), + is_kernel_in_hyp_mode() ? read_sysreg_s(SYS_CNTP_CTL_EL02) : 0, + is_kernel_in_hyp_mode() ? read_sysreg_s(SYS_CNTV_CTL_EL02) : 0, + is_kernel_in_hyp_mode() ? read_sysreg_s(T8142_VM_TMR_FIQ_ENA) : 0, + read_sysreg(isr_el1), read_sysreg_s(T8142_CLPC_C5_0), t8142_fiq_sources()); + t8142_ed_report(s->dev); + if (is_kernel_in_hyp_mode()) { + u64 o = read_sysreg_s(SLEEP_M5_C1_6), w; + + write_sysreg_s(o | SLEEP_M5_C1_6_PWRDN, SLEEP_M5_C1_6); + isb(); + w = read_sysreg_s(SLEEP_M5_C1_6); + write_sysreg_s(o, SLEEP_M5_C1_6); + isb(); + dev_info(s->dev, "dry run: C1_6 write test: %#llx | 0x1c000000 reads back %#llx (%s)\n", + o, w, (w & SLEEP_M5_C1_6_PWRDN) == SLEEP_M5_C1_6_PWRDN ? "sticks" : "IGNORED"); + } + } + /* The wake restores' reads, here too, so a read that hangs shows in the ladder. */ + if (s->soc->ops->last_mile == t8142_last_mile) { + t8142_mem_save(s); + t8142_clk_save(s); + dev_info(s->dev, "dry run: wake saves: mem %d (amcc0 %#llx cfg0 %#llx ch0 %#x/%#x/%#x) clk %d (slot0 %#x:%#x) early_wfi %d\n", + s->mem_saved, s->amcc_saved[0], s->amcc_cfg_saved[0][0], + s->mcc_saved[0][0], s->mcc_saved[0][MCC_ENABLES / 4], + s->mcc_saved[0][MCC_LANES / 4], s->clk_saved, + s->clk_slot_saved[0][1], s->clk_slot_saved[0][0], + s->soc->early_cpu_wfi && READ_ONCE(sleep_early_wfi)); + s->mem_saved = s->clk_saved = false; + } + /* Read-only: what the match would find in the words macOS leaves on (ps_keep). */ + if (s->soc->nps_keep) { + char line[400]; + int i, n = 0; + + for (i = 0; i < s->soc->nps_keep; i++) { + const struct apple_sleep_ps_keep *k = &s->soc->ps_keep[i]; + + n += scnprintf(line + n, sizeof(line) - n, " %s %#x", k->name, + readl((k->aon ? s->ps_aon : s->ps) + k->offset)); + } + n += scnprintf(line + n, sizeof(line) - n, " ATC0_COMMON %#x ATC0_USB_AON %#x ATC0_USB %#x", + readl(s->ps + T8142_PS_ATC0_COMMON), + readl(s->ps_aon + T8142_PS_AON_ATC0_USB_AON), + readl(s->ps_aon + T8142_PS_AON_ATC0_USB)); + dev_info(s->dev, "dry run: ps_keep %#x, the words:%s\n", + READ_ONCE(sleep_ps_keep), line); + } + /* Read-only: XNU's boot AUTO_ENABLE list as Linux has it (apple_sleep.boot_auto) */ + if (sleep_boot_auto_count(s)) { + char line[700]; + unsigned int i, n = 0, missing = 0, autoed = 0, off_words = 0; + u32 v; + + for (i = 0; i < sleep_boot_auto_count(s); i++) { + bool aon = i >= s->soc->ps_boot_auto.count; + u32 off = aon ? s->soc->ps_aon_boot_auto.offset[i - s->soc->ps_boot_auto.count] : + s->soc->ps_boot_auto.offset[i]; + + v = readl(sleep_boot_auto_reg(s, i)); + if (v & PS_AUTO_ENABLE) { + autoed++; + } else if (FIELD_GET(PS_TARGET, v) && FIELD_GET(PS_ACTUAL, v)) { + missing++; + n += scnprintf(line + n, sizeof(line) - n, " %s%x=%x", + aon ? "a" : "", off, v); + } else { + off_words++; + } + } + dev_info(s->dev, "dry run: boot_auto %d: of XNU's %u AUTO_ENABLE words %u already have it, %u are off, %u on without it:%s\n", + READ_ONCE(sleep_boot_auto_on), sleep_boot_auto_count(s), autoed, + off_words, missing, line); + /* + * The one power-word write a dry run makes (apple_sleep.boot_auto_dry): XNU's + * boot write on those words, each read back at once and 1 ms later, then undone. + */ + if (READ_ONCE(sleep_boot_auto_on) && READ_ONCE(sleep_boot_auto_dry)) { + u32 now[64]; + unsigned int set; + + sleep_note(s, 0x3d); + set = sleep_boot_auto(s); + mdelay(1); + n = 0; + for (i = 0; i < sleep_boot_auto_count(s); i++) { + bool aon = i >= s->soc->ps_boot_auto.count; + u32 off = aon ? s->soc->ps_aon_boot_auto.offset[i - s->soc->ps_boot_auto.count] : + s->soc->ps_boot_auto.offset[i]; + + if (!(s->boot_auto_set & BIT_ULL(i))) + continue; + now[i] = readl(sleep_boot_auto_reg(s, i)); + n += scnprintf(line + n, sizeof(line) - n, " %s%x=%x", aon ? "a" : "", + off, now[i]); + } + sleep_boot_auto_undo(s); + dev_info(s->dev, "dry run: boot_auto write test: %u set, %u read AUTO_ENABLE back at once; 1 ms later:%s (undone)\n", + set, s->boot_auto_stuck, line); + } + } + /* Read-only: the memory-controller start's fingerprint and the PMC's four voters */ + if (s->soc->mem_boot) { + u64 pa = 0, got = 0, want = 0; + unsigned int bad = t8142_mem_fingerprint(s, &pa, &got, &want); + + dev_info(s->dev, "dry run: mem_boot %d mem_floor %d: fingerprint %u of 34 differ (first %#llx: %#llx, J813 %#llx); PMC voters +0/+4: %#x/%#x %#x/%#x %#x/%#x %#x/%#x\n", + READ_ONCE(sleep_mem_boot), READ_ONCE(sleep_mem_floor), bad, pa, got, want, + readl(s->pmc_voters), readl(s->pmc_voters + 4), + readl(s->pmc_voters + PMC_VOTER_STRIDE), + readl(s->pmc_voters + PMC_VOTER_STRIDE + 4), + readl(s->pmc_voters + 2 * PMC_VOTER_STRIDE), + readl(s->pmc_voters + 2 * PMC_VOTER_STRIDE + 4), + readl(s->pmc_voters + 3 * PMC_VOTER_STRIDE), + readl(s->pmc_voters + 3 * PMC_VOTER_STRIDE + 4)); + } + /* Read-only: every word of the match's off lists that reads on, i.e. that it lowers. */ + if (s->soc->ps_macos_off.count || s->soc->ps_aon_macos_off.count) { + const struct apple_sleep_words *off = &s->soc->ps_macos_off; + const struct apple_sleep_words *aoff = &s->soc->ps_aon_macos_off; + char line[800]; + int i, n = 0; + u32 v; + + for (i = 0; i < off->count; i++) { + v = readl(sleep_power_reg(s, off->offset[i])); + if (FIELD_GET(PS_ACTUAL, v)) + n += scnprintf(line + n, sizeof(line) - n, " %x=%x", + off->offset[i], v); + } + n += scnprintf(line + n, sizeof(line) - n, " | aon"); + for (i = 0; i < aoff->count; i++) { + v = readl(s->ps_aon + aoff->offset[i]); + if (FIELD_GET(PS_ACTUAL, v)) + n += scnprintf(line + n, sizeof(line) - n, " %x=%x", + aoff->offset[i], v); + } + dev_info(s->dev, "dry run: macos_off words on now (the match lowers them unless kept):%s\n", + line); + } + /* Read-only: what apple_sleep.dispext lowers (T8142's external DCPs). */ + if (s->soc->dispext_optional) { + char line[400]; + int i, k, n = 0; + + for (i = 1; i < s->soc->ndisp; i++) { + n += scnprintf(line + n, sizeof(line) - n, " | ext%d %s:", i - 1, + !s->display[i].np ? "no node" : + s->display[i].bound ? "bound" : "unbound"); + for (k = 0; k < 3; k++) + n += scnprintf(line + n, sizeof(line) - n, " %x=%x", + s->soc->ps.disp[i][k], + readl(s->ps + s->soc->ps.disp[i][k])); + n += scnprintf(line + n, sizeof(line) - n, " run %d", + sleep_asc_running(s, s->soc->ps.disp[i][0], + s->display[i].asc)); + if (s->soc->disp_wr_dis[i][0]) + n += scnprintf(line + n, sizeof(line) - n, " wr-dis %d", + !!(readl(s->ps + s->soc->disp_wr_dis[i][0]) & + BIT(s->soc->disp_wr_dis[i][1]))); + } + dev_info(s->dev, "dry run: dispext %d:%s\n", READ_ONCE(sleep_dispext), line); + } + /* Read-only: what apple_sleep.extra_off would lower (only those on). */ + if (s->soc->nextra_off) { + static char line[900]; + int i, n = 0; + + for (i = 0; i < s->soc->nextra_off; i++) + n += scnprintf(line + n, sizeof(line) - n, " %s %x=%x", + s->soc->extra_off[i].name, s->soc->extra_off[i].offset, + readl(sleep_power_reg(s, s->soc->extra_off[i].offset))); + for (i = 0; i < s->soc->ndisp; i++) + if (s->soc->disp_adma[i]) + n += scnprintf(line + n, sizeof(line) - n, " adma%d %x=%x", i, + s->soc->disp_adma[i], + readl(sleep_power_reg(s, s->soc->disp_adma[i]))); + dev_info(s->dev, "dry run: extra_off %d:%s\n", READ_ONCE(sleep_extra_off), line); + } + /* + * Read-only, before the display, coprocessor and match steps: every ps word on + * (index:offset=value; * = macOS has it off at its commit), the list the commit's PMU + * digest can only count; aon: every word on without AUTO_ENABLE. + */ + if (s->soc->ops->macos_off_at_commit) { + const struct apple_sleep_words *all = &s->soc->ps_all; + const struct apple_sleep_words *aon = &s->soc->ps_aon_all; + /* Interrupts are off here: no allocation. */ + static char line[1024]; + int i, n = 0; + u32 v; + + line[0] = 0; + for (i = 0; i < all->count; i++) { + v = readl(s->ps + all->offset[i]); + if (!FIELD_GET(PS_ACTUAL, v)) + continue; + n += scnprintf(line + n, 1024 - n, " %d:%x=%x%s", i, all->offset[i], v, + s->soc->ops->macos_off_at_commit(all->offset[i]) ? "*" : ""); + /* printk would cut a long line: a new one every 24 words */ + if (n > 400) { + dev_info(s->dev, "dry run: ps on (* = off at macOS's commit):%s\n", + line); + n = 0; + line[0] = 0; + } + } + dev_info(s->dev, "dry run: ps on (* = off at macOS's commit):%s\n", line); + line[0] = 0; + for (i = 0, n = 0; i < aon->count; i++) { + v = readl(s->ps_aon + aon->offset[i]); + if (!FIELD_GET(PS_ACTUAL, v) || (v & PS_AUTO_ENABLE)) + continue; + n += scnprintf(line + n, 1024 - n, " %d:%x=%x", i, aon->offset[i], v); + } + dev_info(s->dev, "dry run: aon on without AUTO:%s\n", line); + } + dev_info(s->dev, + "dry run: every check passed; refusing before the commit (untested SoC, apple_sleep.untested_commit=1 lets it through)\n"); + return -EAGAIN; + } + if (sleep_boot_auto_count(s)) { + sleep_note(s, 0x3e); + sleep_note_at(s, 2, min(sleep_boot_auto(s), 255)); + } + sleep_note(s, 0x40); ret = apple_sleep_cpus_hold(s); /* As on macOS, the display goes off before the GPU. */ - if (!ret) + if (!ret) { + sleep_note(s, 0x41); ret = sleep_display_off(s); - if (!ret) + } + if (!ret) { + sleep_note(s, 0x42); ret = apple_sleep_coprocs_check(s); + } /* Cover the platform's own preparation, after the PM core's early check. */ if (!ret && pm_wakeup_pending()) ret = -EBUSY; - if (!ret) + if (!ret) { + sleep_note(s, 0x43); ret = apple_sleep_enclave_stop(s); + } if (ret) { dev_dbg(s->dev, "refused before any commit coprocessor stop: %d\n", ret); spin_table_unhold_parked(); + sleep_dispext_restore(s); + sleep_boot_auto_undo(s); apple_sleep_stray_restore(s); return ret; } + sleep_note(s, 0x44); + sleep_ps_wr_dis_clear(s); apple_sleep_coprocs_stop(s, true); - + if (s->soc->mem_boot && READ_ONCE(sleep_mem_boot)) { + sleep_note(s, 0x4c); + t8142_mem_boot_entry(s); + } + s->mem_floor_done = false; + if (s->soc->mem_boot && READ_ONCE(sleep_mem_floor)) { + /* T6050's stage: the floor's voter stepped down 2, then 1, 9 ms apart */ + sleep_note(s, 0x4d); + writel(2, s->pmc_voters + PMC_VOTER_STRIDE * 1); + mdelay(9); + writel(1, s->pmc_voters + PMC_VOTER_STRIDE * 1); + mdelay(9); + s->mem_floor_done = true; + } + + sleep_note(s, 0x45); sleep_wake_arm(s); + sleep_note(s, 0x46); apple_sleep_match(s); + sleep_note(s, 0x48); /* Acknowledge a leftover done flag, as the DCS word has none on macOS. */ if (s->soc->ack_cluster_dcs && (readl(s->cluster_dcs) & CLUSTER_UP_DONE)) writel(readl(s->cluster_dcs), s->cluster_dcs); apple_sleep_coprocs_stop(s, false); + /* + * J813 native trace: ANS idle completes before SMC slpa/AP IDLE. + * In the battery failure SMC faulted at ANS + 0xc110 after ANS's + * idle ACK was missed. Keep its final notice behind the peer stops + * and ahead of the domain power-down in the last mile. + */ + if (apple_sleep_smc_defer_notice()) { + ret = apple_sleep_smc_late_notice(s); + dev_info(s->dev, "TEST: SMC notice after peer stops: %d\n", ret); + if (ret) + panic("J813 SMC notice failed after peer stops: %d", ret); + } /* Done by now unless no SMC driver is bound. */ apple_sleep_usb_down(s); s->deep_once = READ_ONCE(sleep_deep_requested); @@ -4149,13 +6310,16 @@ static int apple_sleep_enter(suspend_state_t state) s->cntkctl = read_sysreg(cntkctl_el1); pm_set_resume_via_firmware(); + sleep_note(s, 0x4a); ret = cpu_suspend(0, apple_sleep_commit); if (ret) panic("Apple committed sleep returned without physical wake: %d", ret); apple_sleep_return(s); + sleep_note(s, 0x50); if (s->deep_once) sleep_slp_ddr_set_deep_once(false); + sleep_ps_wr_dis_woke(s); apple_sleep_match_undo(s); apple_sleep_stray_restore(s); sleep_wake_restore(s); @@ -4413,7 +6577,8 @@ static int apple_sleep_smc_scope_begin(void) struct apple_sleep *s = apple_sleep; int ret = 0; - if (!s->soc->early_context || !s->soc->smc_policy) + if ((!s->soc->early_context || !s->soc->smc_policy) && + !apple_sleep_smc_defer_notice()) return 0; mutex_lock(&apple_sleep_smc_lock); if (!s->smc.saved_ops || !s->smc.dev) { @@ -4488,10 +6653,16 @@ static void apple_sleep_late_scope_finish(void) static int apple_sleep_prepare(void) { struct apple_sleep *s = apple_sleep; + static u8 attempts; int i; /* Every device .suspend has run: no owner registers after this. */ sleep_ans_late_close(); + sleep_note_at(s, 0, PMU_NOTE_MAGIC); + sleep_note_at(s, 2, 0); + sleep_note_at(s, 3, ++attempts); + sleep_note(s, 0x02); + /* With an encoder's domain linked, genpd has it off once the encoders are. */ if (s->soc->has_ave && !s->ave_pd_owned) apple_sleep_ave_off(s); @@ -4545,6 +6716,8 @@ static void apple_sleep_report(void) const struct apple_sleep_wake_name *names = s->soc->wake_names; int i; + /* Back in Linux, before any device resumes: a reset after this is in the resume. */ + sleep_note(s, 0x7e); if (s->soc->ops->finish) s->soc->ops->finish(s); apple_sleep_smc_scope_end(); @@ -4570,8 +6743,11 @@ static void apple_sleep_report(void) if (s->wake_status[id / 32] & BIT(id % 32)) dev_info(s->dev, "wake source: %s\n", names[i].name); } - if (!s->soc->regions) + if (!s->soc->regions) { sleep_ps_rewake_report(s); + sleep_spmi_sources_report(s); + sleep_ps_wr_dis_report(s); + } for (i = 0; i < SLEEP_COPROCS; i++) { struct apple_sleep_coproc *c = &apple_sleep_coprocs[i]; @@ -4580,12 +6756,25 @@ static void apple_sleep_report(void) dev_err(s->dev, "%s stop reported %d; physical sleep completed\n", dev_name(c->dev), c->stop_ret); } - for (i = 0; i < ARRAY_SIZE(t8132_quiesce_words); i++) + for (i = 0; i < s->soc->quiesce.count; i++) if (s->quiesce_still_on & BIT(i)) dev_err(s->dev, "power word %#x was on at the last step\n", - t8132_quiesce_words[i]); + s->soc->quiesce.offset[i]); if (s->cpus_stop_ret) dev_err(s->dev, "other CPUs did not stop: %d\n", s->cpus_stop_ret); + if (s->perf_soc_ret || s->perf_dcs_ret) + dev_warn(s->dev, "sleep perf states: SoC %d, DCS %d (DCS was %u)\n", s->perf_soc_ret, + s->perf_dcs_ret, s->perf_dcs_from); + if (s->cluster_p_ret) + dev_err(s->dev, "P complex did not come back on: %d\n", s->cluster_p_ret); + if (s->radio_trainable && s->radio_stop_ret) + dev_warn(s->dev, "the radio's port stop at the commit: first timeout at %s: %d\n", + s->radio_stop_step ?: "?", s->radio_stop_ret); + if (s->radio_trainable && s->radio_train_ret) + dev_err(s->dev, "the radio's PCIe link did not train after the wake: %d\n", + s->radio_train_ret); + else if (s->radio_trainable) + dev_info(s->dev, "the radio's PCIe link trained again after the wake\n"); if (s->cluster_e_ret || s->cluster_ave_ret || s->cluster_ave_commit_ret) dev_err(s->dev, "cluster power timed out: E %d AVE %d, AVE at the commit %d\n", s->cluster_e_ret, s->cluster_ave_ret, s->cluster_ave_commit_ret); @@ -4598,10 +6787,19 @@ static void apple_sleep_report(void) s->pcie_ans_on_ret); } +static int apple_sleep_valid(suspend_state_t state) +{ + if (state != PM_SUSPEND_MEM) + return 0; + return !apple_sleep || !apple_sleep->soc->untested || READ_ONCE(sleep_deep); +} + static const struct platform_suspend_ops apple_sleep_ops = { - .valid = suspend_valid_only_mem, + .valid = apple_sleep_valid, .begin = apple_sleep_begin, .prepare = apple_sleep_prepare, + .prepare_late = apple_sleep_smc_scope_begin, + .finish = apple_sleep_smc_scope_end, .enter = apple_sleep_enter, .wake = apple_sleep_report, .end = apple_sleep_end, @@ -4646,6 +6844,10 @@ static int apple_sleep_map_displays(struct apple_sleep *s) int index; np = of_parse_phandle(s->dev->of_node, "apple,display-coprocessors", i); + if (!np && i != 0 && s->soc->dispext_optional) { + dev_info(s->dev, "no external display coprocessor %d: not lowered\n", i); + continue; + } if (!np) return dev_err_probe(s->dev, -ENODEV, "no display coprocessor %d\n", i); s->display[i].np = np; @@ -4727,6 +6929,45 @@ static int apple_sleep_map_numbered(struct apple_sleep *s, const char *prefix, return 0; } +static void apple_sleep_put_device(void *dev) +{ + put_device(dev); +} + +/* + * Gen 4: the controller at this node's "spmi" block (nub-spmi0), as the T6050 profile finds + * it, and the PMU's sources in its status words: apple,spmi-pmu-sources = , the + * word's offset in 0x600..0x61c. Neither is required. + */ +static void sleep_map_pmu_bus(struct apple_sleep *s) +{ + struct resource *own = platform_get_resource_byname(to_platform_device(s->dev), + IORESOURCE_MEM, "spmi"); + struct device_node *np; + struct resource res; + u32 v[2]; + + for_each_compatible_node(np, NULL, "apple,t8142-spmi") { + struct platform_device *bus; + + if (!own || of_address_to_resource(np, 0, &res) || res.start != own->start) + continue; + bus = of_find_device_by_node(np); + if (bus && !devm_add_action_or_reset(s->dev, apple_sleep_put_device, &bus->dev)) + s->pmu_bus = &bus->dev; + of_node_put(np); + break; + } + if (!of_property_read_u32_array(s->dev->of_node, "apple,spmi-pmu-sources", v, 2) && + v[1] && v[0] >= SPMI4_SRC_STATUS && v[0] < SPMI4_NOTIFY_ACK && !(v[0] % 4)) { + s->spmi_pmu_status = v[0]; + s->spmi_pmu_bits = v[1]; + } + dev_info(s->dev, "PMU's SPMI controller %s, latched sources %s\n", + s->pmu_bus ? dev_name(s->pmu_bus) : "not found (writes unlocked)", + s->spmi_pmu_bits ? "acknowledged at entry and wake" : "only reported"); +} + static int apple_sleep_map_regs(struct apple_sleep *s) { int i, ret; @@ -4734,12 +6975,24 @@ static int apple_sleep_map_regs(struct apple_sleep *s) for (i = 0; i < ARRAY_SIZE(apple_sleep_regs); i++) { void __iomem **field = (void __iomem **)((u8 *)s + apple_sleep_regs[i].offset); + if (s->soc->regs_absent && + match_string(s->soc->regs_absent, -1, apple_sleep_regs[i].name) >= 0) + continue; *field = apple_sleep_map(s->dev, apple_sleep_regs[i].name); if (IS_ERR(*field)) return dev_err_probe(s->dev, PTR_ERR(*field), "no %s registers\n", apple_sleep_regs[i].name); } + if (s->soc->spmi_gen4 && !s->soc->regions) + sleep_map_pmu_bus(s); + + /* T8142: each complex's ACC word, used only with apple_sleep.acc_wake */ + s->acc_e = apple_sleep_map(s->dev, "acc-e"); + s->acc_p = apple_sleep_map(s->dev, "acc-p"); + if (IS_ERR(s->acc_e) || IS_ERR(s->acc_p)) + s->acc_e = s->acc_p = NULL; + ret = apple_sleep_map_numbered(s, "mcc", s->mcc, s->soc->nmcc); if (ret) return ret; @@ -4748,6 +7001,31 @@ static int apple_sleep_map_regs(struct apple_sleep *s) if (ret) return ret; + ret = apple_sleep_map_numbered(s, "socni", s->socni, s->soc->nsocni); + if (ret) + return ret; + + s->mem_clk = apple_sleep_map(s->dev, "mem-clk"); + if (IS_ERR(s->mem_clk)) + s->mem_clk = NULL; + + /* T8142's memory-controller start, mapped page by page (shared with nothing that binds) */ + if (s->soc->mem_boot) + t8142_mem_map(s); + + /* T8142's wake restores (optional: a tree without them skips that restore). */ + s->clk_slots = apple_sleep_map(s->dev, "clk-slots"); + if (IS_ERR(s->clk_slots)) + s->clk_slots = NULL; + for (i = 0; i < s->soc->namcc; i++) { + char name[16]; + + snprintf(name, sizeof(name), "amcc-cfg%d", i); + s->amcc_cfg[i] = apple_sleep_map(s->dev, name); + if (IS_ERR(s->amcc_cfg[i])) + s->amcc_cfg[i] = NULL; + } + /* Lowering an unbound display clears its clock protection first. */ if (s->soc->lower_unbound_displays) { s->ps_prot = apple_sleep_map(s->dev, "ps-prot"); @@ -4847,8 +7125,18 @@ static void apple_sleep_map_apcie(struct apple_sleep *s) &s->apcie_phy_ip_pll); s->apcie_phy_ip_lanes = apple_sleep_apcie_tunable(s, np, "phy-ip", "apple,tunable-phy-ip-auspma"); - if (!s->apcie_axi || !s->apcie_cio3pll || !s->apcie_clkgen || !s->apcie_phy || - !s->apcie_rc || !s->apcie_phy_ip || !s->apcie_phy_ip_lanes) { + /* + * T8142's block has neither table: those steps are skipped. Its clock generator + * (pcieclkgen) is only written at the power-down, with no table. + */ + if (s->soc->apcie_gen4) { + s->apcie_cio3pll = NULL; + s->apcie_cio3pll_tunable = s->apcie_clkgen_tunable = NULL; + s->apcie_clkgen = apple_sleep_apcie_block(s, np, "clkgen", NULL, NULL); + } + if (!s->apcie_axi || !s->apcie_phy || !s->apcie_rc || !s->apcie_phy_ip || + !s->apcie_phy_ip_lanes || + (!s->soc->apcie_gen4 && (!s->apcie_cio3pll || !s->apcie_clkgen))) { dev_info(s->dev, "no PCIe tunables for ANS: suspend-to-RAM with it stopped will be refused\n"); s->apcie_phy_tunable = NULL; @@ -4927,6 +7215,53 @@ static void apple_sleep_map_pins(struct apple_sleep *s) of_node_put(np); } +/* + * T8142's radio port: its blocks with the shared block's ("apple,apcie": radio-port, + * radio-lane and radio-cfg, the root port's configuration space), the loader's tables for + * them, and its PERST# ("apple,radio-perst", on the AP pins). All of it, or the port isn't + * trained again and a real sleep is refused while its host is held. + */ +static void apple_sleep_map_radio(struct apple_sleep *s) +{ + static const char *const rc[] = { + "apple,tunable-radio-rc", "apple,tunable-radio-rc-gen3", "apple,tunable-radio-rc-gen4", + }; + struct device_node *np, *pins; + struct of_phandle_args args; + unsigned int i; + + if (!s->soc->radio_retrain || !s->radio_host_np || !s->pins) + return; + np = of_parse_phandle(s->dev->of_node, "apple,apcie", 0); + if (!np) + return; + s->radio_port = apple_sleep_apcie_block(s, np, "radio-port", "apple,tunable-radio-port", + &s->radio_port_tunable); + s->radio_lane = apple_sleep_apcie_block(s, np, "radio-lane", NULL, NULL); + s->radio_cfg = apple_sleep_apcie_block(s, np, "radio-cfg", NULL, NULL); + for (i = 0; i < ARRAY_SIZE(rc); i++) + s->radio_rc_tunable[i] = apple_sleep_apcie_tunable(s, np, "radio-cfg", rc[i]); + of_node_put(np); + + pins = of_parse_phandle(s->dev->of_node, "apple,pinctrl", 0); + if (!of_parse_phandle_with_args(s->dev->of_node, "apple,radio-perst", "#gpio-cells", 0, + &args)) { + if (args.np == pins && args.args_count >= 2 && args.args[0] < s->npins && + !test_bit(args.args[0], s->pins_skip)) { + s->radio_perst = args.args[0]; + s->radio_perst_low = args.args[1] & GPIO_ACTIVE_LOW; + } + of_node_put(args.np); + } + of_node_put(pins); + + s->radio_trainable = s->radio_port && s->radio_lane && s->radio_cfg && + s->radio_port_tunable && s->radio_rc_tunable[0] && + s->radio_rc_tunable[1] && s->radio_rc_tunable[2] && s->radio_perst >= 0; + if (!s->radio_trainable) + dev_info(s->dev, "the radio's port can't be trained after a sleep: a real sleep is refused while its host is bound\n"); +} + static void apple_sleep_map_debug_port(struct apple_sleep *s) { struct device_node *np = of_parse_phandle(s->dev->of_node, "apple,debug-port", 0); @@ -4934,6 +7269,12 @@ static void apple_sleep_map_debug_port(struct apple_sleep *s) if (!np) return; + /* Its commands are written for the gen 1 layout only. */ + if (s->soc->spmi_gen4) { + dev_warn(s->dev, "apple,debug-port on SPMI gen 4: not driven\n"); + of_node_put(np); + return; + } bus = of_get_parent(np); if (bus && !of_property_read_u32_index(np, "reg", 0, &s->hpm_sid)) s->hpm_spmi = of_iomap(bus, 0); @@ -4950,7 +7291,8 @@ static int apple_sleep_alloc_books(struct apple_sleep *s) struct device *dev = s->dev; /* One bit, and one gate, for each */ - if (soc->nstray > BITS_PER_LONG || soc->ngate_coprocs > SLEEP_GATES_MAX) + if (soc->nstray > BITS_PER_LONG || soc->ngate_coprocs > SLEEP_GATES_MAX || + soc->nps_wr_dis > SLEEP_PS_WR_DIS_MAX) return dev_err_probe(dev, -EINVAL, "the SoC's lists are too long\n"); s->ps_on_saved = devm_kcalloc(dev, soc->ps_macos_on.count, sizeof(u32), GFP_KERNEL); @@ -4977,6 +7319,11 @@ static int apple_sleep_alloc_books(struct apple_sleep *s) return 0; } +static void apple_sleep_put_node(void *np) +{ + of_node_put(np); +} + #include "sleep-t6050.h" /* ANS's sleep owner on T6050: registered at its .suspend, its final stop in the last steps. */ @@ -5326,6 +7673,21 @@ static int apple_sleep_probe(struct platform_device *pdev) s->soc = of_device_get_match_data(dev); if (!s->soc) return -ENODEV; + if (s->soc->spmi_gen4) { + s->spmi_status = SPMI4_STATUS; + s->spmi_rx_empty = SPMI4_STATUS_RX_EMPTY; + s->spmi_cmd = SPMI4_CMD; + s->spmi_reply = SPMI4_REPLY; + s->spmi_notify_enable = SPMI4_NOTIFY_ENABLE; + s->spmi_notify_ack = SPMI4_NOTIFY_ACK; + } else { + s->spmi_status = SPMI_STATUS; + s->spmi_rx_empty = SPMI_STATUS_RX_EMPTY; + s->spmi_cmd = SPMI_CMD; + s->spmi_reply = SPMI_REPLY; + s->spmi_notify_enable = SPMI_NOTIFY_ENABLE; + s->spmi_notify_ack = SPMI_NOTIFY_ACK; + } ret = apple_sleep_profile_check(s); if (ret) @@ -5380,7 +7742,14 @@ static int apple_sleep_probe(struct platform_device *pdev) return ret; if (!s->soc->regions) apple_sleep_map_apcie(s); + if (s->soc->radio_retrain) { + s->radio_host_np = of_parse_phandle(dev->of_node, "apple,radio-host", 0); + if (s->radio_host_np && + devm_add_action_or_reset(dev, apple_sleep_put_node, s->radio_host_np)) + return -ENOMEM; + } apple_sleep_map_pins(s); + apple_sleep_map_radio(s); apple_sleep_map_debug_port(s); platform_set_drvdata(pdev, s); @@ -5389,11 +7758,40 @@ static int apple_sleep_probe(struct platform_device *pdev) &sleep_cpu_power_ops); if (ret) return dev_err_probe(dev, ret, "cannot control CPU power\n"); + if (s->soc->pen_deep) + spin_table_pen_deep_arm(true); /* Last: the exported helpers take it as a probed driver, and a failure frees s. */ apple_sleep = s; /* Deep becomes the default sleep state, unless mem_sleep_default= chose another. */ suspend_set_ops(s->soc->early_context ? &apple_sleep_early_ops : &apple_sleep_ops); + /* Not on a SoC whose data is derived: there it is asked for by name. */ + if (s->soc->untested) { + if (mem_sleep_current == PM_SUSPEND_MEM) + mem_sleep_current = PM_SUSPEND_TO_IDLE; + if (s->soc->ops->deep_wfi_arm == t8142_deep_wfi_arm && is_kernel_in_hyp_mode()) + t8142_c1_6_report(dev); + if (s->soc->ops->deep_wfi_arm == t8142_deep_wfi_arm) { + t8142_ed_map(dev); + dcache_clean_poc((unsigned long)t8142_el1_wfi_stub, + (unsigned long)t8142_el1_wfi_stub_end); + dev_info(dev, "probe: last WFI at %s (stub at PA %pa)\n", + !is_kernel_in_hyp_mode() || !READ_ONCE(sleep_el1_wfi) ? "the kernel's EL" : + READ_ONCE(sleep_el1_wfi) >= 2 ? "EL1 on every core" : "EL1 on the boot core", + &(phys_addr_t){ __pa_symbol(t8142_el1_wfi_stub) }); + } + dev_info(dev, "probe: pwrgate wake %#x %#x cpm %#x %#x, commit %#x, clusters %#x %#x\n", + readl(s->pwrgate + s->soc->pwrgate_wake[0]), + readl(s->pwrgate + s->soc->pwrgate_wake[1]), + readl(s->pwrgate + s->soc->pwrgate_cpm[0]), + readl(s->pwrgate + s->soc->pwrgate_cpm[1]), readl(s->commit), + readl(s->cluster + s->soc->cluster_cpu[0]), + readl(s->cluster + s->soc->cluster_cpu[1])); + dev_warn(dev, "sleep data derived for this SoC, untested: deep sleep is %s, and %s\n", + READ_ONCE(sleep_deep) ? "offered (apple_sleep.deep=1)" : "off (apple_sleep.deep=1 offers it)", + READ_ONCE(sleep_untested_commit) ? "the commit is allowed" : + "a sleep stops before the commit (dry run)"); + } dev_info(dev, "deep sleep %s: boot object resumes %llu\n", mem_sleep_current == PM_SUSPEND_MEM ? "is the default" : @@ -5818,15 +8216,1289 @@ static const struct apple_sleep_soc t8132_sleep_soc = { .wake_names = t8132_wake_names, .nwake_names = ARRAY_SIZE(t8132_wake_names), .wake_last_word = GENMASK(20, 0), + .quiesce = SLEEP_WORDS(t8132_quiesce_words), +}; + +/* + * T8142 (M5: MacBook Air J813/J815, MacBook Pro J704). No M5 sleep has been traced: this is + * T8132's sleep with T8142's words, translated by name from the J815 ADT and checked against + * the macOS 27.2.1 kernelcache (26B131) where the code says more: + * - XNU's last-WFI path is the same code for both SoCs. + * - AppleT8142PMGR's sleep entry and restoreHW are T8132's in order. A complex comes on as + * (word | 0xf), then bit 4 clears; restoreHW then sets pwrgate +0x0 and +0x60, the boot + * cores of E and P, read-modify-write. + * - Its quiescePerfState takes the SoC to 3 and DCS to 3, through 5 from 6 and up, before + * the complexes go off, and adds a "sleep hack" right before the S2R timer: + * PMGR_SOC_CLLT.EARLY_WAKEUP_CFG (+0x50) bits 17:16 cleared. Its EVENT_CFG step calls a + * method that is empty on T8142. The S2R timer is T8132's commit word. + * - The wake block has nine mask words (sources 0..267), then nine status words. + * - No clock mux and no memory-controller lane step: AppleT8142MCC turns the cache's ways + * off as its platform sleep action, which mcc.c does at suspend_noirq. + * - Its SPMI controllers are gen 4. + * iBoot leaves the boot core's power-gate enable (+0x60) clear: with it clear the boot core + * never powers off in its last WFI, the P complex stays BUSY, and WD2 resets the SoC after + * the commit. The DT's cluster power gate sets it at boot (apple-cluster-pwrgate.c), as on + * T8132 and T6050. + */ +#define T8142_PMC_VOTER_AP (3 * PMC_VOTER_STRIDE) +#define T8142_CLUSTER_BUSY BIT(4) +/* + * AppleT8142PMGR::setPerfState's words in PMGRCLKGEN_SOC_TOP (/arm-io/pmgr reg[2]): the SoC's + * at 0x24000, DCS's at 0x25000, each like T8132's: [3:0] asks, [11:8] has reached, bit 31 busy. + */ +#define T8142_PERF_REQ GENMASK(3, 0) +#define T8142_DCS_SLEEP_STATE 3 +#define T8142_DCS_STEP_STATE 5 +#define T8142_DCS_STEP_FROM 6 +#define T8142_DCS_MAX_STATE 10 + +/* + * Every Linux access to the complexes' ACC word 0xe440f8 has hung J815 so far: a read at + * probe, an on-demand read, and the one wake that wrote it (the only T8142 sleep that went + * down, then hung on its way back). macOS writes 1 after each complex powers on and at the + * end of restoreHW; here that is only done when asked for. + */ +static bool sleep_acc_wake; +module_param_named(acc_wake, sleep_acc_wake, bool, 0644); +MODULE_PARM_DESC(acc_wake, + "T8142: write ACC 0xe440f8 = 1 per complex at a wake, as restoreHW does (default 0)"); + +static int t8142_perf_request(void __iomem *reg, unsigned int state) +{ + writel((readl(reg) & ~T8142_PERF_REQ) | FIELD_PREP(T8142_PERF_REQ, state), reg); + return sleep_perf_wait(reg, state); +} + +/* + * AppleT8142PMGR::quiescePerfState, the PMGR's first sleep step: the SoC to Vmin (3), then DCS + * to 3, through 5 from 6..10. macOS waits on BUSY with no limit and panics on a DCS state + * above 10; here each wait is bounded, and such a state is left alone. + */ +static void t8142_perf_down(struct apple_sleep *s) +{ + unsigned int state = FIELD_GET(DCS_STATE, readl(s->dcs)); + + s->perf_dcs_from = state; + s->perf_soc_ret = t8142_perf_request(s->clk_perf + CLK_PERF_SOC, SOC_SLEEP_STATE); + if (state > T8142_DCS_MAX_STATE) { + s->perf_dcs_ret = -ERANGE; + return; + } + if (state >= T8142_DCS_STEP_FROM) + t8142_perf_request(s->dcs, T8142_DCS_STEP_STATE); + s->perf_dcs_ret = t8142_perf_request(s->dcs, T8142_DCS_SLEEP_STATE); +} + +/* AppleT8142PMGR vtable 0xfa0: each complex's CPM gate word, read-modify-write. */ +static void t8142_cpm_on(struct apple_sleep *s) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(s->soc->pwrgate_cpm); i++) { + void __iomem *reg = s->pwrgate + s->soc->pwrgate_cpm[i]; + + writel(readl(reg) | PWRGATE_ON, reg); + } +} + +/* + * apple_sleep.extra_off, after every coprocessor's last stop and before ATC0/PCIe/PMP: each listed + * word that is on, in the list's order (children first), waited off; one that stays on is noted, + * not refused (past the last refusal point). + */ +static void t8142_extra_lower(struct apple_sleep *s) +{ + const struct apple_sleep_soc *soc = s->soc; + unsigned int i; + + s->extra_lowered = 0; + if (!READ_ONCE(sleep_extra_off)) + return; + for (i = 0; i < min_t(unsigned int, soc->nextra_off, SLEEP_EXTRA_OFF_MAX); i++) { + u32 off = soc->extra_off[i].offset, v = readl(sleep_power_reg(s, off)); + + s->extra_saved[i] = v; + if (!FIELD_GET(PS_ACTUAL, v)) + continue; + sleep_ps_lower(s, off); + s->extra_lowered |= BIT(i); + if (sleep_ps_wait_off(s, off)) + s->extra_stuck |= BIT(i); + } +} + +/* At the wake, parents first: each lowered word back once its parent reads on. */ +static void t8142_extra_restore(struct apple_sleep *s) +{ + const struct apple_sleep_soc *soc = s->soc; + int i; + + for (i = min_t(unsigned int, soc->nextra_off, SLEEP_EXTRA_OFF_MAX) - 1; i >= 0; i--) { + u32 parent = soc->extra_off[i].parent; + + if (!(s->extra_lowered & BIT(i))) + continue; + if (!parent || FIELD_GET(PS_ACTUAL, readl(sleep_power_reg(s, parent)))) + sleep_ps_restore(sleep_power_reg(s, soc->extra_off[i].offset), + s->extra_saved[i]); + } + s->extra_lowered = 0; +} + +/* T8132's, with T8142's ATC0 words; ANS's PCIe block in AppleT8142PCIe's order. */ +static void t8142_lower_io(struct apple_sleep *s) +{ + sleep_note(s, 0x61); + t8132_clean_ram(); + sleep_note(s, 0x62); + t8142_extra_lower(s); + s->atc0_saved[0] = readl(s->ps_aon + T8142_PS_AON_ATC0_USB); + s->atc0_saved[1] = readl(s->ps_aon + T8142_PS_AON_ATC0_USB_AON); + s->atc0_saved[2] = readl(s->ps + T8142_PS_ATC0_COMMON); + /* apple_sleep.ps_keep bit 3: as macOS would, if its ports weren't hidden in the trace */ + if (!(s->ps_keep_mask & BIT(3))) { + t8132_aon_lower(s, T8142_PS_AON_ATC0_USB); + if (!READ_ONCE(sleep_usb_asleep)) + t8132_aon_lower(s, T8142_PS_AON_ATC0_USB_AON); + sleep_ps_lower(s, T8142_PS_ATC0_COMMON); + } + if (s->pcie_ans_stopped) { + apple_sleep_lower_apcie(s); + s->ans_off_ret = sleep_ps_wait_off(s, s->soc->ps.ans); + } + /* PMP's final stop has idled its firmware and saved its SRAM; RUN is clear (#4). */ + s->pmp_lowered = false; + s->pmp_off_ret = 0; + if (READ_ONCE(sleep_pmp_off) && sleep_ps_on(s, T8142_PS_PMP)) { + s->pmp_saved = readl(s->ps + T8142_PS_PMP); + sleep_ps_lower(s, T8142_PS_PMP); + s->pmp_lowered = true; + s->pmp_off_ret = sleep_ps_wait_off(s, T8142_PS_PMP); + } + sleep_note(s, 0x63); +} + +/* + * The last note before the cores' window (0x65): +2 flags, +4 the first armed wake source + * already pending (low 8 bits; 0xff none). Flags: 0x01 a parked CPU didn't stop, 0x02 the SoC + * perf state, 0x04 the DCS state didn't settle, 0x08 an armed wake source is pending, 0x10 it + * is >= 256, 0x20 the commit word read non-zero (it reads 1 from boot on J815). No PMU traffic + * after it: the engine gives the cores 33 ms from the complex words to their WFI. + */ +/* + * The PMU's RTC alarm after the S2R timer, as macOS 27.2 sends it on the J813 (Thomas + * Glanzmann, m0d16l14n1/linux#3, from trace g01: 0.11 to 0.25 ms after the timer, boot core): + * read RTC_CTL, 0x43 if it had fired, the 4-byte compare at 0x2008, 0x200e <- 0, RTC_CTL <- + * 0x41. T6050's post-timer step at the same addresses (apple,pmu-alarm-rearm 0x43 0x41). The + * opcode carries the byte count (his follow-up fix). The compare and the counter are read here, + * before the cores' window, with the notes; the compare is now + apple_sleep.t8142_wake_s + * (0 keeps the PMU's own), which is also a wake source: J815 has no RTC device under Linux. + * J813 still resets with it (PMU took all four commands), so this is parity, not the fix. + */ +static bool sleep_pmu_alarm = true; +module_param_named(pmu_alarm, sleep_pmu_alarm, bool, 0644); +MODULE_PARM_DESC(pmu_alarm, "T8142: send the PMU's RTC alarm after the S2R timer, as macOS does (default Y)"); +static unsigned int t8142_wake_s = 30; +module_param(t8142_wake_s, uint, 0644); +MODULE_PARM_DESC(t8142_wake_s, "T8142: the PMU RTC alarm this many s after the commit (0: keep the PMU's)"); +static u8 t8142_alarm[4]; +static bool t8142_alarm_ok; +static int t8142_post_ret = -ENODATA; +static u64 t8142_alarm_counter; + +static int t8142_pmu(struct apple_sleep *s, u32 mask, u8 opcode, u16 address, const u8 *wr, + u8 *rd, unsigned int len) +{ + return t6050_sleep_pmu_xfer_post(s, mask, opcode | (len - 1), address, wr, rd, len); +} + +static void t8142_alarm_prepare(struct apple_sleep *s) +{ + u32 mask = s->soc->spmi_notify_sleep; + u8 ticks[8] = {}; + + t8142_alarm_ok = false; + t8142_post_ret = -ENODATA; + if (!s->spmi || !READ_ONCE(sleep_pmu_alarm)) + return; + t6050_sleep_pmu_drain(s); + if (!t8142_pmu(s, mask, T6050_SPMI_EXT_READL, T6050_RTC_COMPARE, NULL, t8142_alarm, 4) && + !t8142_pmu(s, mask, T6050_SPMI_EXT_READL, T6050_RTC_COUNTER, NULL, ticks, 6)) { + t8142_alarm_counter = get_unaligned_le64(ticks) >> 16; + if (READ_ONCE(t8142_wake_s)) + put_unaligned_le32(t8142_alarm_counter + READ_ONCE(t8142_wake_s), t8142_alarm); + t8142_alarm_ok = true; + } + t6050_sleep_pmu_drain(s); +} + +static void t8142_post_timer(struct apple_sleep *s) +{ + u32 mask = s->soc->spmi_notify_sleep & ~M5_SPMI_IRQ_DONE; + u8 ctl = 0, v; + int ret; + + if (!t8142_alarm_ok) + return; + ret = t8142_pmu(s, mask, T6050_SPMI_EXT_READL, T6050_RTC_CTL, NULL, &ctl, 1); + if (!ret && (ctl & T6050_RTC_CTL_FIRED)) { + v = 0x43; + ret = t8142_pmu(s, mask, T6050_SPMI_EXT_WRITEL, T6050_RTC_CTL, &v, NULL, 1); + } + if (!ret) + ret = t8142_pmu(s, mask, T6050_SPMI_EXT_WRITEL, T6050_RTC_COMPARE, t8142_alarm, NULL, 4); + if (!ret) { + v = 0; + ret = t8142_pmu(s, mask, T6050_SPMI_EXT_WRITEL, T6050_RTC_MASK, &v, NULL, 1); + } + if (!ret) { + v = 0x41; + ret = t8142_pmu(s, mask, T6050_SPMI_EXT_WRITEL, T6050_RTC_CTL, &v, NULL, 1); + } + if (!ret) + sleep_spmi_alarm_wake_arm(s); + t8142_post_ret = ret; +} + +/* + * What survives the reset, at 0x8310.. (J813's #4 used the same bytes): the power words as the + * commit has them. +8 ps_all words on without AUTO_ENABLE, +9 ps_all words on that macOS has off, + * +10/+11 ps_all words on that macOS never touched (past the CPUs) and the first one's index + * (0xff none), +12 ps_aon_all words on + * without it, +13 the first such index, +14/+15 the SEP word's bits 7:0 and 31:24 (macOS: 0x0f, + * 0x10), +5..+7 and +16..+19 the first seven of +9's. PMU scratch from 0x831f up holds data + * that isn't Linux's (the same on every boot): nothing is written there. + */ +#define T8142_PS_SEP 0xc00 +/* + * The ps_all words macOS has OFF (actual state 0) at its commit: the last value each had in the + * J813 g01 end state (notes/sleep-trace/macos-ps-endstate-g01-sleep1.txt). Of t8142_ps_all's + * 156: 66 off, 38 on, 52 never touched in the trace (unknown). By actual state only: a written + * 0x100000ff reads back without AUTO_ENABLE on macOS too, so that bit can't be compared. + */ +static bool t8142_macos_off_at_commit(u32 offset) +{ + static const u32 off[] = { + 0x190, 0x198, 0x1a0, 0x1a8, 0x1b0, 0x290, 0x298, 0x2a0, 0x2a8, 0x2b8, + 0x2c0, 0x2e8, 0x2f0, 0x2f8, 0x300, 0x308, 0x310, 0x318, 0x320, 0x328, + 0x330, 0x350, 0x360, 0x3a0, 0x3a8, 0x3b0, 0x3b8, 0x3c0, 0x3c8, 0x3d0, + 0x3d8, 0x3e0, 0x408, 0x410, 0x418, 0x420, 0x428, 0x440, 0x450, 0x460, + 0x4d8, 0x4e0, 0x4e8, 0x4f0, 0x518, 0x520, 0x560, 0x568, 0x578, 0x580, + 0x598, 0xc00, 0x4020, 0x4030, 0x4048, 0x4050, 0x8000, 0x8008, 0x8010, 0x8018, + 0x8020, 0xc000, 0xc008, 0xc010, 0x10000, 0x10068, + }; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(off); i++) + if (off[i] == offset) + return true; + return false; +} + +/* The 38 ps_all words macOS has ON at its commit (same end state, actual state != 0) */ +static bool t8142_macos_on_at_commit(u32 offset) +{ + static const u32 on[] = { + 0x110, 0x118, 0x120, 0x138, 0x140, 0x148, 0x150, 0x158, 0x160, 0x168, + 0x170, 0x178, 0x180, 0x2c8, 0x2d0, 0x340, 0x348, 0x358, 0x368, 0x370, + 0x378, 0x380, 0x388, 0x390, 0x398, 0x430, 0x438, 0x448, 0x458, 0x468, + 0x470, 0x478, 0x480, 0x488, 0x490, 0x498, 0x4a0, 0x5a0, + }; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(on); i++) + if (on[i] == offset) + return true; + return false; +} + +/* + * Neither: never touched in macOS's trace. Past the CPU words (< 0x60), all but ATC2/3 are no_ps + * children of the displays and ISP, which their firmware lowers, not the AP: one left on by a + * cold-stopped DCP keeps its FE word up. + */ +static bool t8142_macos_untraced(u32 offset) +{ + return offset >= 0x60 && !t8142_macos_on_at_commit(offset) && + !t8142_macos_off_at_commit(offset); +} + +static void t8142_commit_digest(struct apple_sleep *s) +{ + const struct apple_sleep_words *all = &s->soc->ps_all, *aon = &s->soc->ps_aon_all; + u8 noauto = 0, untraced = 0, first[1] = { 0xff }, aon_noauto = 0, aon_first = 0xff; + unsigned int i; + u32 v; + + for (i = 0; i < all->count; i++) { + v = readl(s->ps + all->offset[i]); + if (!FIELD_GET(PS_ACTUAL, v)) + continue; + /* +10/+11: untraced words on (count, first index): see t8142_macos_untraced */ + if (t8142_macos_untraced(all->offset[i])) { + if (!untraced) + first[0] = min(i, 254U); + untraced += untraced < 255; + } + if (v & PS_AUTO_ENABLE) + continue; + noauto += noauto < 255; + } + for (i = 0; i < aon->count; i++) { + v = readl(s->ps_aon + aon->offset[i]); + if (!FIELD_GET(PS_ACTUAL, v) || (v & PS_AUTO_ENABLE)) + continue; + if (!aon_noauto) + aon_first = min(i, 254U); + aon_noauto += aon_noauto < 255; + } + v = readl(s->ps + T8142_PS_SEP); + sleep_note_at(s, 8, noauto); + sleep_note_at(s, 10, untraced); + sleep_note_at(s, 11, first[0]); + sleep_note_at(s, 12, aon_noauto); + sleep_note_at(s, 13, aon_first); + sleep_note_at(s, 14, v & 0xff); + sleep_note_at(s, 15, v >> 24); + + /* + * +5..+7, +16..+19: the first seven ps_all indices on here (actual state, AUTO_ENABLE or + * not) that macOS has off at its commit (t8142_macos_off_at_commit); 0xff = none. +9 their + * count (replaces the AUTO count). The full list is the dry run's. + */ + { + static const u8 slot[] = { 5, 6, 7, 16, 17, 18, 19 }; + unsigned int nodd = 0; + + for (i = 0; i < all->count; i++) { + v = readl(s->ps + all->offset[i]); + if (!FIELD_GET(PS_ACTUAL, v) || !t8142_macos_off_at_commit(all->offset[i])) + continue; + if (nodd < ARRAY_SIZE(slot)) + sleep_note_at(s, slot[nodd], min(i, 254U)); + nodd++; + } + for (i = nodd; i < ARRAY_SIZE(slot); i++) + sleep_note_at(s, slot[i], 0xff); + sleep_note_at(s, 9, min(nodd, 255U)); + } +} + +static void t8142_commit_note(struct apple_sleep *s) +{ + u8 flags = 0, src = 0xff; + int i; + + if (!sleep_notes_on(s)) + return; + if (s->cpus_stop_ret) + flags |= 0x01; + if (s->perf_soc_ret) + flags |= 0x02; + if (s->perf_dcs_ret) + flags |= 0x04; + for (i = 0; i < s->soc->wake_words; i++) { + u32 pend = readl(s->wake + s->soc->wake_status + i * 4) & s->wake_armed[i]; + + if (!pend) + continue; + if (!(flags & 0x08)) { + u32 id = i * 32 + __ffs(pend); + + src = id & 0xff; + if (id > 0xff) + flags |= 0x10; + } + flags |= 0x08; + } + if (readl(s->commit)) + flags |= 0x20; + t8142_commit_digest(s); + t8142_alarm_prepare(s); + /* +20: the alarm read (1 = ready, 0 = off or failed) */ + sleep_note_at(s, 20, t8142_alarm_ok); + /* +21: mem_boot (bit 0 asked, bit 1 replayed, bit 2 floor stepped), +22 fingerprint mismatches */ + sleep_note_at(s, 21, (READ_ONCE(sleep_mem_boot) ? 1 : 0) | (s->mem_boot_done ? 2 : 0) | + (s->mem_floor_done ? 4 : 0) | (s->pmp_lowered ? 8 : 0) | + (s->pmp_off_ret ? 0x10 : 0) | + (READ_ONCE(sleep_extra_off) ? 0x20 : 0) | + (s->extra_lowered || s->disp_adma_lowered ? 0x40 : 0) | + (s->extra_stuck ? 0x80 : 0)); + /* +22: dispext (sleep_display_off) */ + sleep_note_at(s, 2, flags); + sleep_note_at(s, 4, src); + sleep_note(s, 0x65); +} + +/* + * T8142's memory side, as macOS steps it down 4.6 to 2.7 ms before the S2R timer (J813, 27.2.1, + * all ten cores: gig3m's trace, gist 89aedeca, 2026-11-15; the J815 ADT has the same mcc + * layout). The PMGR words around it match our J815 trace write for write. + * + * - AMCC: each plane's +0x28000 word (mapped as "amcc") holds 0x1fe; macOS clears it two + * bits at a time, in the order below (plane, bit pair), 64-bit read-modify-writes. Whatever + * is left on a plane macOS didn't list (the fourth, on J813) goes the same way, low bit first. + * - SoC NI (mcc reg[2..7], "socni"): each table zeroed from its first word, as many as + * macOS writes. + * - DCS channels (reg[10..17] + 0x580, "mcc"): the enables down a bit at a time, low bit + * first; then two lanes per channel per pass, as T8140's, with +0x680 rewritten before each + * lane and only the lanes that are enabled (J813's fifth channel has lanes 0 and 2). + */ +#define T8142_AMCC_SLEEP_BITS GENMASK_ULL(8, 1) +#define T8142_MCC_LANE_EXTRA 0x100 +#define T8142_MEM_CLK_SLEEP 0x30000 + +/* + * What T8142's deep sleep loses and XNU writes back at the wake, before the AMCC/MCC and + * clkgen drivers' state is used again (Thomas's J813 trace, 27.2, all ten cores, 2026-11-16; + * the J815 ADT has the same mcc and clkgen layout). Every one of the 411 memory-side words + * XNU writes at the wake ends at the value it held before the entry's stop, and the clkgen + * slots at the values it read 3.2 ms before the timer: so this saves J815's own values and + * replays them in XNU's order. Nothing here is a J813 constant but the clkgen slot commands. + */ +/* + * The AMCC sleep bits by (plane, pair), the pair's bits being 2 * pair + 1 and 2 * pair + 2: + * the order XNU clears them in at the entry and sets them again at the wake. + */ +static const u8 t8142_amcc_order[][2] = { + { 1, 0 }, { 2, 2 }, { 1, 2 }, { 0, 1 }, { 1, 3 }, { 0, 0 }, + { 1, 1 }, { 2, 3 }, { 0, 3 }, { 2, 1 }, { 0, 2 }, { 2, 0 }, +}; + +#define T8142_CLK_SLOTS 126 +#define T8142_CLK_SLOT(n) ((n) * 0x20) +#define T8142_CLK_SLOT_LO 0x10 +#define T8142_CLK_SLOT_HI 0x14 +/* The command XNU writes to each slot's +0x0 after its value (4, or 5 for these 48 slots). */ +static const u64 t8142_clk_slot_cmd5[2] = { 0x54aaaaaaaa000000ULL, 0x02aaaaaaa9555555ULL }; +/* Per DCS channel ("mcc" = +0x580): +0x0 enables, +0x4 groups, +0x10.. six words a group */ +#define T8142_MCC_SAVE_WORDS 65 +#define T8142_MCC_GROUPS 10 +#define T8142_MCC_GROUP(k) (0x10 + (k) * 0x18) +/* Per AMCC plane ("amcc-cfg" = plane + 0x2a000): 64-bit +0x0, +0x8, +0x10; 32-bit +0x4000 */ +#define T8142_AMCC_CFG_CTL 0x4000 +#define T8142_SOCNI_STROBE 0x100 + +static void t8142_mem_save(struct apple_sleep *s) +{ + const struct apple_sleep_soc *soc = s->soc; + int i, n; + + s->mem_saved = false; + if (!READ_ONCE(sleep_mem_restore)) + return; + for (i = 0; i < soc->namcc; i++) { + s->amcc_saved[i] = readq(s->amcc[i]); + if (!s->amcc_cfg[i]) + continue; + for (n = 0; n < 3; n++) + s->amcc_cfg_saved[i][n] = readq(s->amcc_cfg[i] + 8 * n); + s->amcc_ctl_saved[i] = readl(s->amcc_cfg[i] + T8142_AMCC_CFG_CTL); + } + for (i = 0; i < soc->nsocni; i++) + for (n = 0; n < soc->socni_words[i] && n < ARRAY_SIZE(s->socni_saved[0]); n++) + s->socni_saved[i][n] = readl(s->socni[i] + 4 * n); + for (i = 0; i < soc->nmcc; i++) + for (n = 0; n < T8142_MCC_SAVE_WORDS; n++) + s->mcc_saved[i][n] = readl(s->mcc[i] + 4 * n); + s->mem_saved = true; +} + +static void t8142_clk_save(struct apple_sleep *s) +{ + int i; + + s->clk_saved = false; + if (!s->clk_slots || !READ_ONCE(sleep_clk_restore)) + return; + for (i = 0; i < T8142_CLK_SLOTS; i++) { + void __iomem *slot = s->clk_slots + T8142_CLK_SLOT(i); + u32 hi, lo; + int tries = 4; + + /* As XNU reads them: high, low, high again (bounded: interrupts are off). */ + do { + hi = readl(slot + T8142_CLK_SLOT_HI); + lo = readl(slot + T8142_CLK_SLOT_LO); + } while (readl(slot + T8142_CLK_SLOT_HI) != hi && --tries); + s->clk_slot_saved[i][0] = lo; + s->clk_slot_saved[i][1] = hi; + } + s->clk_saved = true; +} + +/* XNU's wake at +4.6..8.8 ms: each slot's value, then its command; then the memory clock word. */ +static void t8142_clk_restore(struct apple_sleep *s) +{ + int i; + + if (s->clk_saved) { + for (i = 0; i < T8142_CLK_SLOTS; i++) { + void __iomem *slot = s->clk_slots + T8142_CLK_SLOT(i); + bool five = t8142_clk_slot_cmd5[i / 64] & BIT_ULL(i % 64); + + writel(s->clk_slot_saved[i][0], slot + T8142_CLK_SLOT_LO); + writel(s->clk_slot_saved[i][1], slot + T8142_CLK_SLOT_HI); + writel(five ? 5 : 4, slot); + } + s->clk_saved = false; + } + if (s->mem_clk && s->mem_clk_saved && READ_ONCE(sleep_clk_restore)) + writel(s->mem_clk_saved, s->mem_clk); +} + +/* One bit at a time, low first, as XNU raises each AMCC pair back. */ +static void t8142_amcc_set(void __iomem *reg, u64 bits) +{ + u64 val = readq(reg); + unsigned int b; + + for_each_set_bit(b, (unsigned long *)&bits, 64) { + if (val & BIT_ULL(b)) + continue; + val |= BIT_ULL(b); + writeq(val, reg); + val = readq(reg); + } +} + +/* Byte @n of @reg back to its saved value, as XNU does before each lane comes up. */ +static void t8142_byte_restore(void __iomem *reg, u32 saved, int n) +{ + u32 mask = GENMASK(8 * n + 7, 8 * n); + + writel((readl(reg) & ~mask) | (saved & mask), reg); +} + +/* + * XNU's wake from +9.06 ms, in its order: the AMCC planes' sleep bits back in the entry's pair + * order; each SoC NI table word with its strobe; each DCS channel's region groups, each + * followed by its enable bits; the lanes, two per channel per pass; the AMCC planes' control + * words. Skipped: XNU's read-and-rewrite of each channel's +0x24 (outside the DT's map). + */ +static int t8142_mem_restore(struct apple_sleep *s, const u8 (*order)[2], int norder) +{ + const struct apple_sleep_soc *soc = s->soc; + int i, n, ch, pass, k; + + if (!s->mem_saved) + return -ENODATA; + + for (i = 0; i < norder; i++) { + int plane = order[i][0]; + + if (plane >= soc->namcc) + continue; + t8142_amcc_set(s->amcc[plane], s->amcc_saved[plane] & + GENMASK_ULL(2 * order[i][1] + 2, 2 * order[i][1] + 1)); + } + for (i = 0; i < soc->namcc; i++) + t8142_amcc_set(s->amcc[i], s->amcc_saved[i] & T8142_AMCC_SLEEP_BITS); + + for (i = 0; i < soc->nsocni; i++) + for (n = 0; n < soc->socni_words[i] && n < ARRAY_SIZE(s->socni_saved[0]); n++) { + writel(s->socni_saved[i][n], s->socni[i] + 4 * n); + writel(1, s->socni[i] + T8142_SOCNI_STROBE); + } + + for (ch = 0; ch < soc->nmcc; ch++) { + void __iomem *mcc = s->mcc[ch]; + const u32 *sv = s->mcc_saved[ch]; + u32 en = 0, groups = 0; + + for (k = 0; k < T8142_MCC_GROUPS; k++) { + if (!(sv[MCC_ENABLES / 4] & BIT(k))) + continue; + for (n = 0; n < 6; n++) + writel(sv[(T8142_MCC_GROUP(k) + 4 * n) / 4], + mcc + T8142_MCC_GROUP(k) + 4 * n); + en |= GENMASK(3, 0) | BIT(4 + k); + groups |= BIT(k); + writel(readl(mcc) | (sv[0] & en), mcc); + writel(readl(mcc + MCC_ENABLES) | (sv[MCC_ENABLES / 4] & groups), + mcc + MCC_ENABLES); + } + /* Whatever else was on, as XNU's last group leaves the words at their old values. */ + if (readl(mcc) != sv[0]) + writel(sv[0], mcc); + if (readl(mcc + MCC_ENABLES) != sv[MCC_ENABLES / 4]) + writel(sv[MCC_ENABLES / 4], mcc + MCC_ENABLES); + } + + for (pass = 0; pass < 2; pass++) { + for (ch = 0; ch < soc->nmcc; ch++) { + void __iomem *mcc = s->mcc[ch]; + const u32 *sv = s->mcc_saved[ch]; + + for (n = 2 * pass; n < 2 * pass + 2; n++) { + if (!(sv[MCC_LANES / 4] & MCC_LANE(n))) + continue; + t8142_byte_restore(mcc + T8142_MCC_LANE_EXTRA, + sv[T8142_MCC_LANE_EXTRA / 4], n); + t8142_byte_restore(mcc + MCC_LANES_MASK, sv[MCC_LANES_MASK / 4], n); + writel(readl(mcc + MCC_LANES) | MCC_LANE_STROBE(n), mcc + MCC_LANES); + writel(readl(mcc + MCC_LANES) | MCC_LANE(n), mcc + MCC_LANES); + } + } + } + for (ch = 0; ch < soc->nmcc; ch++) { + void __iomem *mcc = s->mcc[ch]; + const u32 *sv = s->mcc_saved[ch]; + + if (readl(mcc + T8142_MCC_LANE_EXTRA) != sv[T8142_MCC_LANE_EXTRA / 4]) + writel(sv[T8142_MCC_LANE_EXTRA / 4], mcc + T8142_MCC_LANE_EXTRA); + if (readl(mcc + MCC_LANES_MASK) != sv[MCC_LANES_MASK / 4]) + writel(sv[MCC_LANES_MASK / 4], mcc + MCC_LANES_MASK); + } + + /* +14.56 ms: plane 0's +0x10, then each plane's +0x4000, +0x8, +0x0. */ + for (i = 0; i < soc->namcc; i++) { + void __iomem *cfg = s->amcc_cfg[i]; + + if (!cfg) + continue; + if (i == 0) + writeq(s->amcc_cfg_saved[i][2], cfg + 0x10); + writel(s->amcc_ctl_saved[i], cfg + T8142_AMCC_CFG_CTL); + writeq(s->amcc_cfg_saved[i][1], cfg + 0x8); + writeq(s->amcc_cfg_saved[i][0], cfg); + } + s->mem_saved = false; + return 0; +} + +static void t8142_amcc_clear(void __iomem *reg, u64 bits) +{ + u64 val = readq(reg); + unsigned int b; + + for_each_set_bit(b, (unsigned long *)&bits, 64) { + if (!(val & BIT_ULL(b))) + continue; + val &= ~BIT_ULL(b); + writeq(val, reg); + val = readq(reg); + } +} + +static void t8142_sleep_mcc_stop(struct apple_sleep *s) +{ + const u8 (*order)[2] = t8142_amcc_order; + const struct apple_sleep_soc *soc = s->soc; + int i, plane, ch, pass, n; + + /* What the wake puts back (t8142_mem_restore), before anything here changes it. */ + t8142_mem_save(s); + + for (i = 0; i < ARRAY_SIZE(t8142_amcc_order); i++) { + if (order[i][0] >= soc->namcc) + continue; + t8142_amcc_clear(s->amcc[order[i][0]], GENMASK_ULL(2 * order[i][1] + 2, + 2 * order[i][1] + 1)); + } + for (plane = 0; plane < soc->namcc; plane++) + t8142_amcc_clear(s->amcc[plane], T8142_AMCC_SLEEP_BITS); + + for (i = 0; i < soc->nsocni; i++) + for (n = 0; n < soc->socni_words[i]; n++) + writel(0, s->socni[i] + 4 * n); + + for (ch = 0; ch < soc->nmcc; ch++) + t8132_mcc_step_down(s->mcc[ch] + MCC_ENABLES); + + for (pass = 0; pass < 2; pass++) { + for (ch = 0; ch < soc->nmcc; ch++) { + void __iomem *mcc = s->mcc[ch]; + + for (n = 2 * pass; n < 2 * pass + 2; n++) { + if (!(readl(mcc + MCC_LANES) & MCC_LANE(n))) + continue; + writel(readl(mcc + T8142_MCC_LANE_EXTRA), mcc + T8142_MCC_LANE_EXTRA); + writel(readl(mcc + MCC_LANES_MASK), mcc + MCC_LANES_MASK); + writel(readl(mcc + MCC_LANES) | MCC_LANE_STROBE(n), mcc + MCC_LANES); + writel(readl(mcc + MCC_LANES) & ~MCC_LANE(n), mcc + MCC_LANES); + } + } + } + + if (s->mem_clk) { + s->mem_clk_saved = readl(s->mem_clk); + writel(T8142_MEM_CLK_SLEEP, s->mem_clk); + } + /* macOS reads the clkgen slots right after the clock word (-3.2 ms). */ + t8142_clk_save(s); +} + +/* + * T8132's order after the cores stopped, ATC0 and ANS lowered and WD2: quiescePerfState, the + * CPM gates around the AP's PMC vote (agent 3, as T8132's), the complexes off, the quiesce + * read, the early wake-up bits off, the words saved. + */ +static void t8142_last_mile(struct apple_sleep *s) +{ + const struct apple_sleep_soc *soc = s->soc; + int i; + + /* Not in macOS's J813 entry (its perf-state page is untouched in the whole trace): A/B. */ + if (READ_ONCE(sleep_perf_down)) + t8142_perf_down(s); + sleep_note(s, 0x64); + + /* T6050's commit window: the floor's voter to 0, not read, right before the memory stop */ + if (s->mem_floor_done) + writel(0, s->pmc_voters + PMC_VOTER_STRIDE * 1); + /* The memory controller, after the SoC and DCS states, as on T8132 (and macOS on J813). */ + t8142_sleep_mcc_stop(s); + sleep_note(s, 0x66); + + t8142_cpm_on(s); + t8142_cpm_on(s); + readl(s->pmc_voters + T8142_PMC_VOTER_AP); + writel(0, s->pmc_voters + T8142_PMC_VOTER_AP); + readl(s->pmc_voters + T8142_PMC_VOTER_AP + 4); + t8142_cpm_on(s); + + t8142_commit_note(s); + + for (i = 0; i < soc->ncluster_cpu; i++) + writel(0, s->cluster + soc->cluster_cpu[i]); + + s->quiesce_still_on = 0; + for (i = 0; i < soc->quiesce.count; i++) + if (sleep_ps_on(s, soc->quiesce.offset[i])) + s->quiesce_still_on |= BIT(i); + + /* "Applying Sleep hacks": the early wake-up bits off, right before the S2R timer. */ + for (i = 0; i < soc->ncllt; i++) + writel(readl(s->cllt + soc->cllt[i].offset) & ~soc->cllt[i].clear, + s->cllt + soc->cllt[i].offset); + + sleep_ps_save(s); +} + +/* + * Note 0x67 (replaces 0x66 once every read came back): +2 E cores' PU bits [5:0], bit 6 complex + * E busy, bit 7 complex P busy; +3 P cores' PU bits [3:0], bit 4 commit word nonzero, bit 5 an + * armed wake pending, bit 6 E asked on, bit 7 P asked on; +4 E cores' SPD bits [5:0], bit 6 any + * P core's SPD, bit 7 a window read all-ones (no answer). Unmapped windows read as PU 1. + */ +static void t8142_post_commit_ed(u8 b2_0x66) +{ + u8 b2 = 0, b3 = 0, b4 = 0; + int k; + + for (k = 0; k < T8142_ED_CORES; k++) { + u32 v; + + if (k < 6) { + v = t8142_ed[0][k] ? readl_relaxed(t8142_ed[0][k] + T8142_ED_EDPRSR) : 1; + if (v == ~0U) + b4 |= BIT(7); + if (v & BIT(0)) + b2 |= BIT(k); + if (v & BIT(1)) + b4 |= BIT(k); + } + if (k < 4) { + v = t8142_ed[1][k] ? readl_relaxed(t8142_ed[1][k] + T8142_ED_EDPRSR) : 1; + if (v == ~0U) + b4 |= BIT(7); + if (v & BIT(0)) + b3 |= BIT(k); + if (v & BIT(1)) + b4 |= BIT(6); + } + } + b2 |= (b2_0x66 & BIT(3) ? BIT(6) : 0) | (b2_0x66 & BIT(4) ? BIT(7) : 0); + b3 |= (b2_0x66 & BIT(0) ? BIT(4) : 0) | (b2_0x66 & BIT(5) ? BIT(5) : 0) | + (b2_0x66 & BIT(1) ? BIT(6) : 0) | (b2_0x66 & BIT(2) ? BIT(7) : 0); + sleep_note_at(apple_sleep, 2, b2); + sleep_note_at(apple_sleep, 3, b3); + sleep_note_at(apple_sleep, 4, b4); + sleep_note(apple_sleep, 0x67); +} + +/* + * apple_sleep.post_commit_ms: note 0x66, decoded by aurora-bootlog as b43's was. + * +2: bit 0 commit word nonzero, 1/2 complex E/P asked on, 3/4 E/P busy, 5 an armed wake source + * pending. +3: SoC perf state [3:0], bit 4 DCS busy, bit 5 SoC busy. +4: DCS state [3:0], + * bits 4..7 PMC voters PMP/CLPC/GFX/AP nonzero. + */ +static void t8142_post_commit_probe(struct apple_sleep *s, unsigned int ms) +{ + const struct apple_sleep_soc *soc = s->soc; + u32 e, p, soc_perf = 0, dcs = 0; + u8 b2 = 0, b3, b4; + int i; + + mdelay(ms); + e = readl(s->cluster + soc->cluster_cpu[0]); + p = readl(s->cluster + soc->cluster_cpu[1]); + if (readl(s->commit)) + b2 |= BIT(0); + if (e & CLUSTER_ON) + b2 |= BIT(1); + if (p & CLUSTER_ON) + b2 |= BIT(2); + if (e & T8142_CLUSTER_BUSY) + b2 |= BIT(3); + if (p & T8142_CLUSTER_BUSY) + b2 |= BIT(4); + for (i = 0; i < soc->wake_words; i++) + if (readl(s->wake + soc->wake_status + 4 * i) & s->wake_armed[i]) + b2 |= BIT(5); + if (s->clk_perf) + soc_perf = readl(s->clk_perf + CLK_PERF_SOC); + if (s->dcs) + dcs = readl(s->dcs); + b3 = FIELD_GET(DCS_STATE, soc_perf) | (dcs & DCS_BUSY ? BIT(4) : 0) | + (soc_perf & DCS_BUSY ? BIT(5) : 0); + b4 = FIELD_GET(DCS_STATE, dcs); + for (i = 0; s->pmc_voters && i < 4; i++) + if (readl(s->pmc_voters + i * PMC_VOTER_STRIDE)) + b4 |= BIT(4 + i); + sleep_note_at(s, 2, b2); + sleep_note_at(s, 3, b3); + sleep_note_at(s, 4, b4); + sleep_note(s, 0x66); + if (READ_ONCE(sleep_post_commit_ed)) + t8142_post_commit_ed(b2); +} + +/* + * AppleT8142PMGR's complex power-on: ApplePMGR's cluster method writes (word & ~0xf) | 0xf and + * waits for bit 4 to clear; T8142's override then writes 1 to the complex's ACC word. + */ +static int t8142_cluster_on(struct apple_sleep *s, u32 word, void __iomem *acc) +{ + void __iomem *reg = s->cluster + word; + u32 val; + int ret; + + writel(readl(reg) | CLUSTER_ON, reg); + ret = readl_poll_timeout_atomic(reg, val, !(val & T8142_CLUSTER_BUSY), 1, + CLUSTER_TIMEOUT_US); + if (!ret && acc && READ_ONCE(sleep_acc_wake)) + writel(1, acc); + return ret; +} + +/* + * AppleT8142PMGR::restoreHW: each complex on, pwrgate +0x0 and +0x60 read-modify-written, the + * words back, the CPM gates, the ACC words once more. Its two "early wake hacks" (SEP's ps + * word, map 0x4e's ten words) are gated by flags its constructor clears and nothing sets. + * Then T8132's: ATC0's words, SEP, WD2, ANS's PCIe block and the radio's link. + */ +static void t8142_wake(struct apple_sleep *s) +{ + if (t8142_alarm_ok) + pr_info("apple-sleep: T8142 PMU alarm after the timer: %d (counter %llu, compare %u)\n", + t8142_post_ret, t8142_alarm_counter, get_unaligned_le32(t8142_alarm)); + + const struct apple_sleep_soc *soc = s->soc; + u32 val; + int i; + + s->cluster_e_ret = t8142_cluster_on(s, soc->cluster_cpu[0], s->acc_e); + s->cluster_p_ret = t8142_cluster_on(s, soc->cluster_cpu[1], s->acc_p); + + for (i = 0; i < ARRAY_SIZE(soc->pwrgate_wake); i++) { + void __iomem *reg = s->pwrgate + soc->pwrgate_wake[i]; + + writel(readl(reg) | PWRGATE_ON, reg); + } + + sleep_ps_rewake(s); + /* Off at the commit by pmp_off, so the rewake left it: back as lower_io found it. */ + if (s->pmp_lowered) { + s->pmp_lowered = false; + sleep_ps_restore(s->ps + T8142_PS_PMP, s->pmp_saved); + } + /* Off at the commit by dispext, likewise: back before the display drivers resume. */ + sleep_dispext_restore(s); + t8142_extra_restore(s); + /* The commit saved ATC0's words already lowered: reverse of the lowering. */ + sleep_ps_restore(s->ps + T8142_PS_ATC0_COMMON, s->atc0_saved[2]); + sleep_ps_restore(s->ps_aon + T8142_PS_AON_ATC0_USB_AON, s->atc0_saved[1]); + sleep_ps_restore(s->ps_aon + T8142_PS_AON_ATC0_USB, s->atc0_saved[0]); + + s->deep_ran = sleep_ps_woke_on(s, soc->ps.ap_tmm); + + val = readl(s->ps + soc->ps.sep); + if (val & PS_DEV_DISABLE) + writel(val & ~PS_DEV_DISABLE, s->ps + soc->ps.sep); + + /* XNU's order: the clkgen slots and the memory clock, the CPM gates, the memory side. */ + t8142_clk_restore(s); + t8142_cpm_on(s); + s->mem_restore_ret = t8142_mem_restore(s, t8142_amcc_order, ARRAY_SIZE(t8142_amcc_order)); + if (READ_ONCE(sleep_acc_wake) && s->acc_e && s->acc_p) { + writel(1, s->acc_e); + writel(1, s->acc_p); + } + + /* macOS's wake is not traced: back to what the entry read, before WD2's re-arm. */ + if (s->aon_wdt_marked) { + writel(s->aon_wdt_saved, s->aon_misc + AON_WDT_SLEEP); + s->aon_wdt_marked = false; + } + apple_sleep_set_wd2(s, WDT_SUSPEND_SECS); + + if (s->pcie_ans_stopped) + s->pcie_ans_on_ret = apple_sleep_raise_apcie(s); + /* Before the PCI core restores the radio's functions, which needs the link. */ + if (s->radio_trainable) + s->radio_train_ret = s->pcie_ans_stopped && !s->pcie_ans_on_ret ? + apple_sleep_radio_train(s) : -ENOLINK; + s->apcie_port_down = true; + s->pins_lost = s->pins_saved_valid; +} + +/* The J815 ADT's /arm-io/pmgr ap-wake-sources, all of them. */ +static const struct apple_sleep_wake_name t8142_wake_names[] = { + { 5, "AOP.CPUWakeupAP" }, { 12, "AOP.GPIO.IRQ4" }, { 14, "AOP.GPIO.IRQ6" }, + { 44, "AOP.OutboxNotEmpty" }, { 63, "AOP.SPMI0.SW3" }, { 67, "AOP.SPMI1.SW3" }, + { 71, "ATC0.CIOWakeup" }, { 72, "ATC0.USBWakeup" }, { 73, "ATC1.CIOWakeup" }, + { 74, "ATC1.USBWakeup" }, { 75, "ATC2.CIOWakeup" }, { 76, "ATC2.USBWakeup" }, + { 77, "ATC3.CIOWakeup" }, { 78, "ATC3.USBWakeup" }, + { 89, "MTP.DOCK.CHANNELS.AP0.IRQ" }, { 108, "MTP.OutboxNotEmpty" }, + { 128, "NUB.APWakeupTime" }, { 129, "PMGR_AON.APWatchdog" }, { 146, "NUB.GPIO.IRQ6" }, + { 152, "NUB.SPMI0.SW3" }, { 157, "NUB.SPMI1.SW3" }, { 163, "NUB.WakeupAP" }, + { 168, "SMC.CPUWakeupAP" }, { 190, "SMC.OutboxNotEmpty" }, + { 237, "AOP.TrustedOutboxNotEmpty" }, { 256, "AOP2.TrustedOutboxNotEmpty" }, + { 261, "AOP2.CPUWakeAP" }, +}; + +/* + * Every word in the J815 ADT's /arm-io/pmgr power states, in "ps" and in "ps-aon". The lists + * after them are T8132's measured ones, each word translated to T8142's by its ADT name; a + * T8132 word with no T8142 namesake is dropped. + */ +/* + * Less DCS0..7 (0x1d8, 0x1e0, 0x1e8, 0x1f0, 0x218, 0x220, 0x228, 0x230): DRAM slices, no_ps in + * the J815 ADT and left to the memory controller. Reading or writing one at .enter stalled J815 + * (boot 45257eaf, DCS5 in the match), so neither the dry run's report, the commit's save nor the + * rewake after a wake touches them. + */ +/* + * Also less the 34 words that are OS-managed on T8132 (or absent there) but no_ps in the J815 + * ADT (PCPM_SRAM, SBR, PMS(_BUSIF), PMGR_SOC_OCLA, PIOGW, the AF* fabrics and AMCC ports, SIO, + * FPWM1, TRACE_FAB, DPTX_PHY, ISP_CPU*, ISP_FE, DISP_SMB*): the rewake after a wake writes back + * any word of this list whose control bits moved, and on T8142 these are firmware's to move + * (rule: t8142_ps_macos_off). + */ +static const u32 t8142_ps_all[] = { + 0x8, 0x10, 0x18, 0x20, 0x28, 0x30, 0x38, 0x40, 0x48, 0x50, + 0x58, 0x110, 0x118, 0x120, 0x138, 0x140, 0x148, 0x150, 0x158, 0x160, + 0x168, 0x170, 0x178, 0x180, 0x190, 0x198, 0x1a0, 0x1a8, 0x1b0, 0x290, + 0x298, 0x2a0, 0x2a8, 0x2b8, 0x2c0, 0x2c8, 0x2d0, 0x2d8, 0x2e0, 0x2e8, + 0x2f0, 0x2f8, 0x300, 0x308, 0x310, 0x318, 0x320, 0x328, 0x330, 0x340, + 0x348, 0x350, 0x358, 0x360, 0x368, 0x370, 0x378, 0x380, 0x388, 0x390, + 0x398, 0x3a0, 0x3a8, 0x3b0, 0x3b8, 0x3c0, 0x3c8, 0x3d0, 0x3d8, 0x3e0, + 0x3e8, 0x3f0, 0x3f8, 0x400, 0x408, 0x410, 0x418, 0x420, 0x428, 0x430, + 0x438, 0x440, 0x448, 0x450, 0x458, 0x460, 0x468, 0x470, 0x478, 0x480, + 0x488, 0x490, 0x498, 0x4a0, 0x4a8, 0x4b0, 0x4b8, 0x4c0, 0x4c8, 0x4d0, + 0x4d8, 0x4e0, 0x4e8, 0x4f0, 0x4f8, 0x500, 0x508, 0x510, 0x518, 0x520, + 0x528, 0x530, 0x538, 0x540, 0x548, 0x550, 0x558, 0x560, 0x568, 0x570, + 0x578, 0x580, 0x598, 0x5a0, 0xc00, 0x4020, 0x4028, 0x4030, 0x4038, 0x4040, + 0x4048, 0x4050, 0x4058, 0x4060, 0x8000, 0x8008, 0x8010, 0x8018, 0x8020, 0xc000, + 0xc008, 0xc010, 0x10000, 0x10008, 0x10010, 0x10018, 0x10020, 0x10028, 0x10030, 0x10038, + 0x10040, 0x10048, 0x10050, 0x10068, 0x10070, 0x10078, +}; + +/* + * Less the 9 AON words T8142 took from the OS (no_ps here, OS-managed or absent on T8132): + * NUB_AON, NUB_OCLA, NUB_FABRIC, NUB_SRAM, DEBUG_SWITCH, AOP_DART, AOP_I2CM3, AOP2_PIODMA, + * AOP2_CPU. Same reason as t8142_ps_all. + */ +static const u32 t8142_ps_aon_all[] = { + 0x58, 0x60, 0x68, 0x70, 0x78, 0x88, 0x98, 0xa0, 0xa8, 0xc8, + 0xd0, 0xd8, 0xe0, 0xe8, 0xf0, 0xf8, 0x100, 0x4000, 0x4008, 0x4010, + 0x4018, 0x4028, 0x4030, 0x4038, 0x4048, 0x4050, 0x4058, 0x4060, 0x4068, 0x4070, + 0x4078, 0x4080, 0x4088, 0x4090, 0x40a0, 0x40a8, 0x40b8, 0x40c0, 0x40c8, 0x40d0, + 0x40d8, 0x40e0, 0x40e8, 0x40f0, 0x40f8, 0x4100, 0x4108, 0x4110, 0x4118, 0x4120, + 0x4128, 0x4130, 0x4138, 0x4140, 0x4148, 0x4150, 0x4158, 0x4160, 0x4168, 0x4170, + 0x4178, 0x4180, 0x4188, 0x8000, 0x8008, 0x8010, 0x8018, 0x8020, 0x8028, 0x8030, + 0x8038, 0x8040, 0x8048, 0x8050, 0x8058, 0x8060, 0x8068, 0x8070, 0x8078, 0x8080, + 0x8088, 0xc000, 0xc008, 0xc010, 0xc018, 0xc020, 0xc028, 0xc030, 0xc038, 0xc040, + 0xc048, 0xc050, 0xc058, 0xc060, +}; + +/* + * XNU's own wake order on T8142 (J813 27.2 trace, 2026-11-16: the 22 words it raises with + * AUTO_ENABLE right after the clusters and SEP), then the rest of the T8132-derived list. A + * word is only raised if Linux had it on at the commit (sleep_ps_rewake). + */ +static const u32 t8142_ps_wake_order[] = { + 0xc00, 0x118, 0x120, 0x138, 0x170, 0x178, 0x180, 0x348, 0x358, 0x368, + 0x390, 0x398, 0x430, 0x438, 0x448, 0x458, 0x468, 0x470, 0x478, 0x480, + 0x488, 0x5a0, + 0x598, 0x300, 0x2f0, 0x408, 0x410, 0x520, 0x560, 0x328, 0x2a8, 0x320, + 0x2b8, 0x3a8, 0x3b8, 0x290, 0x318, 0x10000, 0x308, 0x418, 0x428, 0x440, + 0x360, +}; + +/* XNU's PMGR start at boot (J813 trace g01, -218649 ms): put on AUTO_ENABLE, in its order */ +static const u32 t8142_ps_boot_auto[] = { + 0x118, 0x120, 0x138, 0x140, 0x170, 0x178, 0x180, 0x290, 0x2b8, 0x2c8, + 0x2d0, 0x2f0, 0x300, 0x308, 0x328, 0x348, 0x350, 0x358, 0x360, 0x368, + 0x390, 0x398, 0x3a0, 0x3a8, 0x410, 0x418, 0x430, 0x438, 0x440, 0x448, + 0x450, 0x458, 0x460, 0x468, 0x470, 0x478, 0x480, 0x488, 0x578, 0x598, + 0x5a0, +}; + +static const u32 t8142_ps_aon_boot_auto[] = { + 0x58, 0x60, 0x68, 0x70, 0x78, 0x88, 0x98, 0xa0, 0xa8, 0xc8, + 0xd0, 0xd8, 0xe0, +}; + +static const u32 t8142_ps_aon_wake_order[] = { + 0x88, 0x98, 0xa0, 0xa8, +}; + +/* + * T8132's match raises its AFIMCCNI0/1, FAB_AFC0, AMCC0/1, DCS5 and DCS7 (and DWI). On T8142 every + * one of those, by name or by its split (AFCMCCNI0, AMCC0_P0..P3), is no_ps in the J815 ADT: the + * memory path's words belong to firmware there, and J815 stalled the first time a sleep wrote + * one (DCS5, boot 45257eaf). T8142 raises none; see t8142_ps_macos_off for the rule. + */ + +/* + * T8132's lowered words by name, less those T8142 took out of the OS's hands: ISP_FE, + * ISP_CPU_CORE1/0, ISP_CPU, DPTX_PHY, TRACE_FAB, FPWM1 and AFIAFT are OS-managed on T8132 but + * no_ps in the J815 ADT (FPWM1 next to T8142's own no_ps SMC_FPWM0..3). J815 stalled lowering + * FPWM1 (boot b7f0f04d: PMU note 0x47, phase 5, index 44). The rule for T8142's sleep lists: + * no word the J815 ADT marks no_ps, unless T8132 writes the same no_ps word (its AON audio ones). + */ +static const u32 t8142_ps_macos_off[] = { + 0xc010, 0xc008, 0xc000, 0x8020, 0x8018, 0x8010, 0x8008, 0x8000, 0x510, 0x508, + 0x500, 0x4f8, 0x4f0, 0x4e8, 0x4e0, 0x4d8, 0x460, 0x458, 0x450, 0x448, + 0x440, 0x438, 0x430, 0x400, 0x3f8, 0x3f0, 0x3e8, 0x3e0, 0x3d8, 0x3d0, + 0x3c8, 0x3c0, 0x3a0, 0x368, 0x360, 0x358, 0x350, 0x348, 0x320, 0x310, + 0x2f8, 0x2e8, 0x2e0, 0x2d8, 0x2d0, 0x2c0, 0x2a8, 0x2a0, 0x298, 0x1b0, + 0x198, 0x190, 0x178, 0x170, +}; + +static const u32 t8142_ps_aon_macos_off[] = { + 0x4180, 0x4108, 0x40f8, 0x40d8, 0x40b8, 0x4080, 0x100, 0xf8, 0xf0, 0xe8, + 0xe0, 0xd8, +}; + +/* + * T8142 has no ps_aon_macos_on list. These audio domains are no_ps in its + * ADT and remain at actual/target zero in the J813 macOS sleep snapshot; + * the traced AP never accesses them. The T8132 state-4 rule does not apply. + */ + +/* + * T8132's quiesce words by name: the ATC commons, the display's and DISPEXT's SYS, ANS, AVD, + * VENC, JPG and APCIE's SYS_GP. GFX's is in its own block here. + */ +static const u32 t8142_quiesce_words[] = { + 0x2c8, 0x2d0, 0x2d8, 0x2e0, 0x290, 0x308, 0x2b8, 0x300, 0x310, 0x298, + 0x2a0, 0x408, +}; +static_assert(ARRAY_SIZE(t8142_quiesce_words) <= 32); + +/* In t8142_ps_macos_off / t8142_ps_aon_macos_off, but on at macOS 27.2's commit (apple_sleep.ps_keep) */ +static const struct apple_sleep_ps_keep t8142_ps_keep[] = { + { "PMS_C1PPT", 0x170, false, 0 }, { "SOC_RC", 0x178, false, 0 }, + { "I2C0", 0x348, false, 1 }, { "I2C2", 0x358, false, 1 }, + { "I2C4", 0x368, false, 1 }, { "SPI0", 0x430, false, 1 }, + { "SPI1", 0x438, false, 1 }, { "SPI3", 0x448, false, 1 }, + { "SPI5", 0x458, false, 1 }, + { "ATC1_COMMON", 0x2d0, false, 2 }, { "ATC1_USB_AON", 0xd8, true, 2 }, + { "ATC1_USB", 0xe0, true, 2 }, +}; + +static const struct apple_sleep_word t8142_stray_words[] = { + { "AVD_SYS", 0x310 }, { "VENC_SYS", 0x298 }, { "JPG", 0x2a0 }, +}; + +static const struct apple_sleep_word t8142_gate_off[] = { + { "ane_sys", 0x2e8 }, { "isp_sys", 0x2f8 }, { "avd_sys", 0x310 }, + { "jpg", 0x2a0 }, { "venc_sys", 0x298 }, +}; + +/* T8142's, from the J815 tree. GFX's word is in its own block, not "ps". */ +static const struct apple_sleep_gate_coproc t8142_gate_coprocs[] = { + { "/soc/dcp@286e00000", true, 0x10000 }, + { "/soc/dcp@506e00000", true, 0x428 }, + { "/soc/dcp@3aae00000", true, 0x3b8 }, + { "/soc/pmp@380500000", true }, + { "/soc/nvme@4c5cc0000" }, { "/soc/mtp@394600000" }, + { "/soc/aop@390c00000" }, { "/soc/smc@38c600000" }, + { "/soc/sep@30a600000" }, + { "/soc/gpu@582600000", true }, +}; + + +static const struct apple_sleep_ops t8142_sleep_ops = { + /* XNU's last-WFI helper is the same code as T8132's and T8140's; plus M5's power-down bits. */ + .deep_wfi_arm = t8142_deep_wfi_arm, + .lower_io = t8142_lower_io, + .last_mile = t8142_last_mile, + /* WD2 is at T8132's address (/arm-io/wdt), so the same stub restarts it. */ + .resume = t8132_resume_stub, + .pre_commit = t8132_pre_commit, + .post_timer = t8142_post_timer, + .macos_off_at_commit = t8142_macos_off_at_commit, + .wake = t8142_wake, + .aic_mask_all = aic_sleep_mask_all, + .aic_ack = aic_sleep_ack, + .aic_restore = aic_sleep_restore, +}; + +/* + * The J815 /chosen/dart-ps-wr-dis-entries that macOS's SPTM clears during its entry (26B131 + * trace), but the DCP's (ps+0x17fdc bit 6, which the DART driver owns) and DCPEXT0/1's (no + * external DCP in this tree), in the trace's order. The rest of each word stays set, as on macOS. + */ +static const struct apple_sleep_ps_wr_dis t8142_ps_wr_dis[] = { + { "SEP (InvalidateHmac)", 0x17fe0, 12 }, + { "centauri-beta", 0x17fe8, 10 }, + { "PMP", 0x17ff8, 17 }, + { "SIO DMA", 0x17ff0, 28 }, +}; + +/* mcc reg[2..7]: the words macOS zeroes in each SoC NI table (J813 trace) */ +static const u8 t8142_socni_words[] = { 15, 16, 28, 30, 21, 14 }; + +static const char *const t8142_regs_absent[] = { + "pmc-dcp", "clk-mux", "ptd", "cluster-dcs", "dvfm-e", "dvfm-p", NULL, +}; + +/* Children before parents (J815 ADT pmgr devices: parent ids) */ +static const struct apple_sleep_extra_off t8142_extra_off[] = { + { "SYS_GP_OCLA", 0x518, 0x408 }, /* parent APCIE_SYS_GP */ + { "SYS_ST_OCLA", 0x568, 0x520 }, /* parent APCIE_SYS_ST */ + { "GLOBAL_AUX_CTRL0", 0x1a0, 0 }, + { "GLOBAL_AUX_CTRL1", 0x1a8, 0 }, + { "FPWM0", 0x330, 0x2b0 }, /* parent SIO */ + { "SIO_CPU", 0x328, 0x2b0 }, /* parent SIO; macOS -53 ms */ + /* ATC2/3: no port on the Airs, never touched by macOS; lowered only if on */ + { "ATC2_CIO_PCIE", 0x4f8, 0x3f0 }, + { "ATC2_CIO_USB", 0x500, 0x3f0 }, + { "ATC2_PCIE", 0x3e8, 0x2d8 }, + { "ATC2_CIO", 0x3f0, 0x2d8 }, + { "ATC2_COMMON", 0x2d8, 0 }, + { "ATC3_CIO_PCIE", 0x508, 0x400 }, + { "ATC3_CIO_USB", 0x510, 0x400 }, + { "ATC3_PCIE", 0x3f8, 0x2e0 }, + { "ATC3_CIO", 0x400, 0x2e0 }, + { "ATC3_COMMON", 0x2e0, 0 }, +}; + +static const struct apple_sleep_soc t8142_sleep_soc = { + .ops = &t8142_sleep_ops, + .untested = true, + .regs_absent = t8142_regs_absent, + .spmi_gen4 = true, + .boot_wfi_delay_ms = 3, + .wake_optional = true, + /* + * DCP, DISPEXT0 (0x428/0x418/0x308), DISPEXT1 (0x3b8/0x3a8/0x2b8), lowered in macOS's order + * (J815 26B131: DISPEXT0, DISPEXT1, DISP). Both external DCPs are bound on J813/J815 now; + * apple_sleep.dispext=0 leaves them as before. macOS writes no pwrgate word for them. Their + * DARTs' PS write-disable bits (trace pmgr-soc-ps+0x3fe8 bit 15, +0x3fec bit 31) are clear + * at macOS's commit. + */ + .ndisp = 3, + .display_order = { 1, 2, 0 }, + .dispext_optional = true, + .disp_wr_dis = { { 0 }, { 0x17fe8, 15 }, { 0x17fec, 31 } }, + /* DISP_ADMA (pmgr base 1 +0x68), DISPEXT0_ADMA, DISPEXT1_ADMA */ + .disp_adma = { 0x10068, 0x420, 0x3b0 }, + .extra_off = t8142_extra_off, + .nextra_off = ARRAY_SIZE(t8142_extra_off), + /* E, P (ADT soc-clusters) */ + .cluster_cpu = { 0x0, 0x4 }, + .ncluster_cpu = 2, + /* Six E cores: E bits 0-5, P bits 6-9, the boot core P0. */ + .cpu_start_stride = 6, + .cllt = { { 0x50, GENMASK(17, 16) } }, + .ncllt = 1, + .ps_wr_dis = t8142_ps_wr_dis, + .nps_wr_dis = ARRAY_SIZE(t8142_ps_wr_dis), + /* ADT mcc: amcc-plane-enable-mask 0xf, dcs-count-per-amcc 8, socni-count 6 */ + .namcc = 4, + .nmcc = 8, + .socni_words = t8142_socni_words, + .nsocni = ARRAY_SIZE(t8142_socni_words), + .aon_wdt_sleep = 0x20, + /* The same PMU, and the same boot-stage byte, as T8132 (J815 ADT info-leg_scrpad). */ + .pmu_usid = 0xe, + .pmu_sleep_reg = 0xf801, + .pmu_sleep_val = 0x50, + .spmi_notify_sleep = 0x2000001, + .wake_mask = 0x08, + /* AppleT8142PMGR, 27.2.1: masks at map 0x42 + 0x08..0x28, status 0x2c..0x4c */ + .wake_status = 0x2c, + .wake_words = 9, + .ps = { + .disp = { + { 0x10000, 0x318, 0x290 }, + { 0x428, 0x418, 0x308 }, + { 0x3b8, 0x3a8, 0x2b8 }, + }, + .sio_cpu = 0x328, + .sep = 0xc00, + .ap_tmm = 0x1b0, + .gpio = 0x120, + .ans = 0x300, + .apcie_gp = 0x2f0, + .apcie_sys_gp = 0x408, + .apcie_st = 0x410, + .apcie_sys_st = 0x520, + .apcie_phy_sw = 0x560, + .apcie_aus5_aon = 0x578, + .apcie_aus5 = 0x580, + }, + .ps_aon_debug_switch = 0xc0, + /* ADT /arm-io/apcie: the PHY-PHY block (reg[3]) is 0x20000 into the PHY's (reg[2]). */ + .apcie_phy_ctrl = 0x20000, + .apcie_gen4 = true, + .radio_retrain = true, + .pen_deep = true, + .early_cpu_wfi = true, + .pwrgate_wake = { 0x000, 0x060 }, + /* AppleT8142PMGR vtable 0xfa0: 0xa0 + 8 * complex */ + .pwrgate_cpm = { 0x0a0, 0x0a8 }, + /* DISP_CPU's retention words: the J815 pmgr's retention_config_ff/_mem (device 0xb7) */ + .pwrgate_disp = { { 0x11cc, 0x11f0 } }, + .ps_all = SLEEP_WORDS(t8142_ps_all), + .ps_aon_all = SLEEP_WORDS(t8142_ps_aon_all), + .ps_macos_off = SLEEP_WORDS(t8142_ps_macos_off), + .ps_aon_macos_off = SLEEP_WORDS(t8142_ps_aon_macos_off), + .ps_wake_order = SLEEP_WORDS(t8142_ps_wake_order), + .ps_aon_wake_order = SLEEP_WORDS(t8142_ps_aon_wake_order), + .ps_boot_auto = SLEEP_WORDS(t8142_ps_boot_auto), + .ps_aon_boot_auto = SLEEP_WORDS(t8142_ps_aon_boot_auto), + .mem_boot = true, + .quiesce = SLEEP_WORDS(t8142_quiesce_words), + .stray = t8142_stray_words, + .nstray = ARRAY_SIZE(t8142_stray_words), + .ps_keep = t8142_ps_keep, + .nps_keep = ARRAY_SIZE(t8142_ps_keep), + .gate_off = t8142_gate_off, + .ngate_off = ARRAY_SIZE(t8142_gate_off), + .gate_coprocs = t8142_gate_coprocs, + .ngate_coprocs = ARRAY_SIZE(t8142_gate_coprocs), + .wake_names = t8142_wake_names, + .nwake_names = ARRAY_SIZE(t8142_wake_names), + /* AppleT8142PMGR's valid-source table: word 8 holds sources 256..267. */ + .wake_last_word = GENMASK(11, 0), }; /* * Qualified profiles expose system sleep. Inventory-only profiles match for a * precise refusal and cannot reach hardware preparation or suspend_set_ops(). + * T8142 remains opt-in and requires its separate physical-commit gate. */ static const struct of_device_id apple_sleep_of_match[] = { { .compatible = "apple,t8140-sleep", .data = &t8140_sleep_soc }, { .compatible = "apple,t8132-sleep", .data = &t8132_sleep_soc }, + { .compatible = "apple,t8142-sleep", .data = &t8142_sleep_soc }, { .compatible = "apple,t6050-sleep", .data = &t6050_sleep_soc }, { .compatible = "apple,t6050-j716c-sleep", .data = &t6050_j716c_sleep_soc }, { } diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple-controller.c index fe05f21cf104f..c5f8829cfeb45 100644 --- a/drivers/spmi/spmi-apple-controller.c +++ b/drivers/spmi/spmi-apple-controller.c @@ -235,14 +235,22 @@ static int apple_spmi_wait_rx_not_empty(struct spmi_controller *ctrl) * late, or the stray one that was read in a reply's place, is read out instead: the bus gets a * command's whole timeout to finish, then the reply FIFO is read until it is empty. Nothing of * an old exchange can then answer a new command. A FIFO that does not empty keeps the failure. - * On the boards with a T6050 sleep only, the J714s and the J716c; on every other generation 4 - * machine a failed exchange refuses the later commands, as before. + * On the J714s, J716c, J813 and J815, whose deep sleep writes the PMU on this queue. + * Other generation 4 machines keep refusing later commands after a failed exchange. */ +static bool apple_spmi_gen4_recovers(void) +{ + return of_machine_is_compatible("apple,j714s") || + of_machine_is_compatible("apple,j716c") || + of_machine_is_compatible("apple,j813") || + of_machine_is_compatible("apple,j815"); +} + static int apple_spmi_gen4_recover(struct spmi_controller *ctrl, struct apple_spmi *spmi) { unsigned int i; - if (!of_machine_is_compatible("apple,j714s") && !of_machine_is_compatible("apple,j716c")) + if (!apple_spmi_gen4_recovers()) return -EIO; usleep_range(REG_POLL_TIMEOUT_US, 2 * REG_POLL_TIMEOUT_US); for (i = 0; i < SPMI_GEN4_REPLY_DRAIN_MAX; i++) { diff --git a/drivers/usb/dwc3/dwc3-apple.c b/drivers/usb/dwc3/dwc3-apple.c index 500b0f85fb949..4d9b4ac0d8346 100644 --- a/drivers/usb/dwc3/dwc3-apple.c +++ b/drivers/usb/dwc3/dwc3-apple.c @@ -953,10 +953,11 @@ static int dwc3_apple_set_role(struct dwc3_apple *appledwc, enum dwc3_apple_stat } dev_warn(appledwc->dev, "USB3 PHY setup failed, USB2 only, err=%d\n", ret); } else if (host && appledwc->usb3_phy && - of_device_is_compatible(appledwc->dev->of_node, "apple,t8132-dwc3")) { + (of_device_is_compatible(appledwc->dev->of_node, "apple,t8132-dwc3") || + of_device_is_compatible(appledwc->dev->of_node, "apple,t8142-dwc3"))) { /* - * The T8132 PHY does not bring a SuperSpeed link back from U3 once - * the core has suspended it: keep it out of P3 from here on. + * These PHYs do not bring a SuperSpeed link back from U3 once + * the core has suspended them: keep them out of P3 from here on. */ appledwc->dwc.dis_u3_susphy_quirk = true; dwc3_enable_susphy(&appledwc->dwc, true); diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index 586669455193b..6ad1d66a67fb9 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -354,12 +354,16 @@ static int tps6598x_disconnect(struct tps6598x *tps, u32 status) /* * The sleep's rules for the port controllers' system power state command (the controller is * woken first, the command's end is read at intervals, a failed S3 refuses the sleep, the - * command's limit and its lines) are in force on the T6050 boards that sleep, the J714s and - * the J716c. Elsewhere the command is as it was. + * command's limit and its lines) apply on the J714s, J716c, J813 and J815. + * These boards send the command (apple,sleep-ssps) during firmware-driven + * sleep. Other boards retain the original command behavior. */ static bool tipd_sleep_ssps_rules(void) { - return of_machine_is_compatible("apple,j714s") || of_machine_is_compatible("apple,j716c"); + return of_machine_is_compatible("apple,j714s") || + of_machine_is_compatible("apple,j716c") || + of_machine_is_compatible("apple,j813") || + of_machine_is_compatible("apple,j815"); } /* diff --git a/include/linux/soc/apple/sleep.h b/include/linux/soc/apple/sleep.h index b2767f37602dc..cec1e88452676 100644 --- a/include/linux/soc/apple/sleep.h +++ b/include/linux/soc/apple/sleep.h @@ -38,6 +38,8 @@ struct apple_sleep_smc_saved_ops { #if IS_ENABLED(CONFIG_APPLE_SOC_SLEEP) const struct apple_sleep_smc_policy *apple_sleep_smc_policy(void); +/* J813 experiment: send the final SMC notice after the peer idle handshakes. */ +bool apple_sleep_smc_defer_notice(void); int apple_sleep_smc_register(struct device *dev, int (*late_notice)(void *data, u64 *sent, u64 *ack), void *data); int apple_sleep_smc_register_saved(struct device *dev, @@ -108,6 +110,12 @@ bool apple_sleep_coproc_stopped(struct device *dev); */ bool apple_sleep_commit_stops_coprocs(void); +/* + * Untested SoCs: a coprocessor's last stop notes its own step in PMU scratch (kept across a + * WD2 reset), next to the sleep driver's step and the coprocessor's slot. + */ +void apple_sleep_note_sub(u8 step); + /* * The USB host sleeps in place for this sleep, as macOS's does: its always-on domain stays * up through the commit. Its PHY sets it once the controller is in its hibernation state, @@ -235,6 +243,7 @@ void apple_sleep_restore_pins(void); int apple_sleep_engine_reset(struct device *dev); #else static inline const struct apple_sleep_smc_policy *apple_sleep_smc_policy(void) { return NULL; } +static inline bool apple_sleep_smc_defer_notice(void) { return false; } static inline int apple_sleep_smc_register(struct device *dev, int (*late_notice)(void *data, u64 *sent, u64 *ack), void *data) { return -EOPNOTSUPP; } static inline int apple_sleep_smc_register_saved(struct device *dev, @@ -300,6 +309,8 @@ static inline bool apple_sleep_coproc_stopped(struct device *dev) return false; } +static inline void apple_sleep_note_sub(u8 step) {} + static inline bool apple_sleep_commit_stops_coprocs(void) { return false; diff --git a/tools/asahi/atc-usb3-tests.py b/tools/asahi/atc-usb3-tests.py index 6d92c105c45be..3a7955197c9f9 100644 --- a/tools/asahi/atc-usb3-tests.py +++ b/tools/asahi/atc-usb3-tests.py @@ -77,7 +77,8 @@ def block(source, marker): STUBS = r''' struct atcphy_hw { enum atcphy_generation gen; - bool has_t8140_dp, dp_t8122, has_usb4, park_pipe_unlocked, park_dummy_phy, usb2_only; }; + bool has_t8140_dp, dp_t8122, has_usb4, park_pipe_unlocked, park_dummy_phy, usb2_only; + bool clear_boot_hold, dp_banked_tunables; }; struct device_node { const char *const *compatible; unsigned int count; }; static bool of_device_is_compatible(const struct device_node *root, const char *compatible) { if (!root) return false; diff --git a/tools/asahi/backlight-coldboot-tests.py b/tools/asahi/backlight-coldboot-tests.py index dfe0012f4e2de..0779154a4ef48 100755 --- a/tools/asahi/backlight-coldboot-tests.py +++ b/tools/asahi/backlight-coldboot-tests.py @@ -119,6 +119,7 @@ def function(source, name): static void cancel_work_sync(struct work_struct *p) { (void)p; } static int dcp_external_start_locked(struct apple_dcp *p) { (void)p;return 0; } static void dcp_relink_wake(int *r,unsigned g,unsigned long j) { (void)r;(void)g;(void)j; } +static void dcp_relink_link_up(int *r,unsigned g,unsigned long j) { (void)r;(void)g;(void)j; } static int dcp_dptx_connect(struct apple_dcp *p,int n) { (void)p;(void)n;return 0; } static void dcp_queue_typec_reconnect(struct apple_dcp *p,int n) { (void)p;(void)n; } static unsigned long wait_for_completion_timeout(int *p,unsigned long n) { (void)p;return n; } diff --git a/tools/asahi/dcpext26-modeset-tests.py b/tools/asahi/dcpext26-modeset-tests.py index 0a3862e20a048..b18d0c2e32c2d 100644 --- a/tools/asahi/dcpext26-modeset-tests.py +++ b/tools/asahi/dcpext26-modeset-tests.py @@ -66,10 +66,11 @@ #include #define dev_warn(...) ((void)0) #define dev_err(...) ((void)0) +#define WRITE_ONCE(x, v) ((x) = (v)) struct drm_crtc {int unused;}; struct drm_crtc_state {bool active,active_changed,color_mgmt_changed;}; struct drm_atomic_commit {struct drm_crtc_state *state;unsigned failed_routes;}; -struct apple_dcp {void *dev;bool native,main_display;int mode_state,vblank_wq;void *connector;}; +struct apple_dcp {void *dev;bool native,main_display,typec_enable_pending;int mode_state,vblank_wq;void *connector;}; struct apple_crtc {struct apple_dcp *dcp;bool fabric_held;}; static struct apple_crtc owner; static struct apple_crtc *to_apple_crtc(struct drm_crtc *c){return &owner;} @@ -88,7 +89,7 @@ static bool dcp_crtc_needs_route_start(struct apple_dcp *d){return false;} static int dcp_typec_prepare_route(struct apple_dcp *d){return 0;} static int apple_drm_fabric_hold(void){return 0;} -static void dcp_poweron(struct apple_dcp *d){powered++;} +static void dcp_poweron(struct apple_dcp *d){assert(d->typec_enable_pending);powered++;} static void dcp_external_recover(struct apple_dcp *d){} static bool drm_atomic_crtc_needs_modeset(struct drm_crtc_state *s){return true;} static int dcp_crtc_atomic_modeset(struct drm_crtc *c,struct drm_atomic_commit *a){programmed++;return mode_error;} @@ -104,13 +105,13 @@ for(unsigned i=0;i<4;i++){ done=woken=notified=invalidated=powered=programmed=0;mode_error=errors[i];d.mode_state=1; apple_crtc_atomic_enable(&crtc,&commit); - assert(done==1&&woken==1&¬ified==1&&invalidated==1&&programmed==1&&powered==1&&!d.mode_state); + assert(done==1&&woken==1&¬ified==1&&invalidated==1&&programmed==1&&powered==1&&!d.mode_state&&!d.typec_enable_pending); } done=woken=notified=invalidated=0;mode_error=0; - apple_crtc_atomic_enable(&crtc,&commit);assert(done==1&&!woken&&!notified&&!invalidated); + apple_crtc_atomic_enable(&crtc,&commit);assert(done==1&&!woken&&!notified&&!invalidated&&!d.typec_enable_pending); // Existing non-native error policy is preserved. d.native=false;done=woken=notified=invalidated=0;mode_error=-EIO; - apple_crtc_atomic_enable(&crtc,&commit);assert(done==1&&!woken&&!notified&&!invalidated&&classic_errors==1); + apple_crtc_atomic_enable(&crtc,&commit);assert(done==1&&!woken&&!notified&&!invalidated&&classic_errors==1&&!d.typec_enable_pending); } ''' with tempfile.TemporaryDirectory() as t: diff --git a/tools/asahi/dcpext26-startup-tests.py b/tools/asahi/dcpext26-startup-tests.py index d6adc408d9b93..042cc22190f7f 100644 --- a/tools/asahi/dcpext26-startup-tests.py +++ b/tools/asahi/dcpext26-startup-tests.py @@ -93,7 +93,7 @@ def run(name,code,reject=False): struct apple_epic_service_ops {const char *name;bool reusable,optional,open_later;int (*prepare)(struct apple_epic_service *,const char *,const char *,s64);int (*revalidate)(struct apple_epic_service *,const char *,const char *,s64);void (*init)(struct apple_epic_service *,const char *,const char *,s64);void (*teardown)(struct apple_epic_service *);void (*init_props)(struct apple_epic_service *,s64,const void *,size_t);}; struct apple_epic_service {struct apple_dcp_afkep *ep;const struct apple_epic_service_ops *ops;bool enabled,torndown,pending_open,defer_start;unsigned users;int lock;u32 channel;void *cookie;const char *pending_name,*pending_class;s64 pending_unit;int cmd_map[1];}; struct dptx_port {struct apple_epic_service *service;s64 unit;bool enabled,connected;int enable_completion;}; -struct apple_dcp {const void *push_out_prefill;bool native,ext26_services_open,v27_j714s,v27_sleep_transport;int fw_compat,index,dptx_controller_ready;struct {unsigned num_dptx_ports;int iomfb_method_profile;} hw;struct dptx_port dptxport[2];void *dev;struct apple_dcp_afkep *systemep,*ibootep,*dptx_controller_ep,*dcpavservep,*dptxep,*ext26_aux[3];}; +struct apple_dcp {const void *push_out_prefill;bool native,ext26_services_open,v27_j714s,v27_sleep_transport;int fw_compat,index,dptx_controller_ready;struct {unsigned num_dptx_ports;int iomfb_method_profile,firmware_compat;} hw;struct dptx_port dptxport[2];void *dev;struct apple_dcp_afkep *systemep,*ibootep,*dptx_controller_ep,*dcpavservep,*dptxep,*ext26_aux[3];}; struct apple_dcp_afkep {struct apple_dcp *dcp;u32 endpoint,num_channels;bool wire_v2,stopping,match_epic_name,compact;int lock;void *wq,*service_work;const struct apple_epic_service_ops *ops;struct apple_epic_service services[AFK_MAX_CHANNEL];}; static bool dcp_is_ext26(struct apple_dcp *d){return d->native;} static bool dcp_fail_stop(struct apple_dcp *d){return d->native;} diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/cases.c b/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/cases.c index 00f670245e7a5..70cd7d36bd211 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/cases.c +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/cases.c @@ -473,6 +473,42 @@ static void legacy_restore(void) } puts("PASS: M1/M2/J700 aborted shutdown blocks PIPE and restores saved lane mode"); } + +/* A cancelled sleep restarts USB beside a DP link that never powered down. */ +static void retained_dp_restart(void) +{ + struct fixture f; + u32 power; + unsigned int before; + + initial(&f, 1, false, false); + f.atc.mode = APPLE_ATCPHY_MODE_USB3_DP; + f.atc.typec_mode = APPLE_ATCPHY_MODE_USB3_DP; + f.atc.dp_t8122.aux = true; + f.atc.dp_t8122.pll = true; + usb2_regs[USB2PHY_USBCTL / 4] = USB2PHY_USBCTL_RUN; + usb2_regs[USB2PHY_SIG / 4] = USB2PHY_SIG_HOST; + power = core_regs[ATCPHY_POWER_CTRL / 4]; + before = usb2_starts; + + assert(exit_apple(&f) == 0); + assert(f.atc.mode == APPLE_ATCPHY_MODE_USB3_DP); + assert(!(usb2_regs[USB2PHY_USBCTL / 4] & USB2PHY_USBCTL_RUN)); + assert(core_regs[ATCPHY_POWER_CTRL / 4] == power); + assert(role(&f, USB_ROLE_HOST) == 0); + assert(usb2_regs[USB2PHY_USBCTL / 4] == USB2PHY_USBCTL_RUN); + assert(usb2_starts == before + 1); + assert(usb2_regs[USB2PHY_SIG / 4] == USB2PHY_SIG_HOST); + assert(f.atc.mode == APPLE_ATCPHY_MODE_USB3_DP); + assert(f.atc.dp_t8122.aux && f.atc.dp_t8122.pll); + assert(core_regs[ATCPHY_POWER_CTRL / 4] == power); + assert(atcphy_usb2_init(&f.p2) == 0 && usb2_starts == before + 1); + assert(exit_apple(&f) == 0); + assert(!f.p2.init_count && !f.p2.power_count); + assert(!f.p3.init_count && !f.p3.power_count); + puts("PASS: USB2 returns beside retained DisplayPort without a mux event"); +} + static void removal_and_generic(void) { struct fixture f; @@ -532,6 +568,7 @@ int main(int argc, char **argv) partial_release(); init_failures(); legacy_restore(); + retained_dp_restart(); removal_and_generic(); tunnel_role(); puts("PASS: Apple teardown actual-function qualification"); diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c b/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c index d7563f0a4e12f..2461f130fa7f1 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c @@ -8,11 +8,13 @@ struct apple_atcphy { struct { bool prepared; } cio_sleep; - struct { void *usb3_dp; } tunables; + struct { + void *usb3_dp, *dp_lioa, *dp_common_config; + } tunables; const struct atcphy_hw *hw; struct { - unsigned char *core, *lpdptx, *pipehandler, *usb2phy; + unsigned char *core, *lpdptx, *lioa, *pipehandler, *usb2phy; } regs; struct reset_controller_dev rcdev; void *dev; @@ -255,11 +257,22 @@ static int __attribute__((unused)) atcphy_configure_pipehandler_usb3_host_t8132( { (void)p; assert(false); return -EOPNOTSUPP; } -/* USB2 power-on is outside this teardown/recovery control. */ +/* Model the USB2 power-on boundary's running state. */ +static unsigned int usb2_starts; static void atcphy_usb2_power_on(struct apple_atcphy *p) { - (void)p; + usb2_starts++; + writel(USB2PHY_USBCTL_RUN, p->regs.usb2phy + USB2PHY_USBCTL); +} + +/* This teardown fixture never selects T8142 DP calibration. */ +static void apple_tunable_apply(void *base, void *tunable) +{ + (void)base; + (void)tunable; + assert(!"unexpected banked DP calibration"); } + static void atcphy_apply_tunables(struct apple_atcphy *p, enum atcphy_mode m) { (void)p; diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py b/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py index 625c3d07c7b1d..4b5ae242b0259 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py @@ -100,7 +100,7 @@ def function(file,signature): struct apple_dcp { void *dev;int fw_compat;struct apple_dcp_afkep *dcpavservep;struct apple_connector *connector; bool external_physically_absent,hpd_mutex,quiescing,typec_cable_connected;u64 typec_generation;unsigned int nr_modes; - struct { int iomfb_method_profile; bool fw_14_7_endpoints; unsigned int num_dptx_ports; } hw; bool ext_dead,external_native; + struct { int iomfb_method_profile,firmware_compat; bool fw_14_7_endpoints; unsigned int num_dptx_ports; } hw; bool ext_dead,external_native; struct { bool lock,enabled;u64 epoch;int enable_completion;struct apple_epic_service *service,*opened; u64 opened_epoch,close_gen,terminated_epoch,close_epoch;bool opening;struct work_struct close_wq; } dcpavserv; /* A J714s firmware 27 processor's: this one is not. */ diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py b/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py index 709b01ec2fb32..9aa4f2041961b 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py @@ -1221,7 +1221,10 @@ def block(marker): struct device { struct device_node *of_node; }; struct platform_device { struct device dev; int num_resources; struct resource resources[10]; }; #define to_platform_device(d) ((struct platform_device *)(d)) +/* Resource-profile tests carry, but never dereference, the sleep layout. */ +static const unsigned dcp_s2r_t8140; struct apple_dcp_hw_data { + const void *s2r_layout; unsigned num_dptx_ports; bool adopt_live_session; int iomfb_method_profile,firmware_compat; const struct resource *firmware_clock; diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/phy.py b/tools/testing/selftests/drivers/gpu/apple-dcp/phy.py index 7998abe4b8ac9..26c0f62dabb25 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/phy.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/phy.py @@ -37,12 +37,12 @@ def function(source, name): bool t8132_ss, t8132_common_owned, t8132_failed, cio_tunables, t8132_dp_alt; /* A CIO sleep is T8132's too, covered by tools/asahi/atc-cio-sleep-tests.py. */ struct { bool prepared; } cio_sleep; - struct { void *usb3_dp; } tunables; + struct { void *usb3_dp, *dp_lioa, *dp_common_config; } tunables; /* A sleep took the USB host's domains down; never set here. */ bool sleep_dead; const struct atcphy_hw *hw; - struct { unsigned char *core, *lpdptx, *pipehandler, *usb2phy; } regs; + struct { unsigned char *core, *lpdptx, *lioa, *pipehandler, *usb2phy; } regs; struct reset_controller_dev rcdev; void *dev; int lock, dp_link_rate; @@ -135,6 +135,10 @@ def function(source, name): #define readl_poll_timeout readl_poll_timeout_atomic /* Observation is read-only and separately tested; retain production caller control flow. */ static void atcphy_usb2_power_on(struct apple_atcphy *p) { (void)p; usb2_on++; } +/* Calibration writes are leaves; the profile test checks their dispatch. */ +static unsigned int dp_bank_writes; +static void apple_tunable_apply(void *base, void *tunable) +{ (void)base; (void)tunable; dp_bank_writes++; } static void atcphy_apply_tunables(struct apple_atcphy *p, enum atcphy_mode mode) { (void)p; (void)mode; } static void atc_tunnel_stop_t8103(struct apple_atcphy *p) { (void)p; } @@ -1237,13 +1241,15 @@ def adverse(root): for (unsigned int m=0; mdp_banked_tunables && atcphy_modes[modes[m]].enable_dp_aux ? 2U : 0U)); for (unsigned int i=before; i=1; - if(gen==1 && !usb3) assert(p.dp_t8122.aux && atc_t8122_dp_aux_is_on(p.regs.core)); + if(p.hw->dp_t8122 && !usb3) assert(p.dp_t8122.aux && atc_t8122_dp_aux_is_on(p.regs.core)); assert(rcal==wake); assert(!!(registers[AUS_COMMON_SHIM_BLK_BIAS_REG/4]&AUS_COMMON_SHIM_BLK_BIAS_REG_BGBIAS_OV)==wake); assert(!!(registers[ACIOPHY_SLEEP_CTRL/4]&ACIOPHY_SLEEP_CTRL_TX_CLAMP_OV)==(gen==0)); @@ -1933,7 +1939,7 @@ def function(name): bool t8132_ss, t8132_common_owned, t8132_failed, cio_tunables, t8132_dp_alt; /* A CIO sleep is T8132's too, covered by tools/asahi/atc-cio-sleep-tests.py. */ struct { bool prepared; } cio_sleep; - struct { void *usb3_dp; } tunables; + struct { void *usb3_dp, *dp_lioa, *dp_common_config; } tunables; bool dp_only, pd_was_off, tunnel_clock_on; unsigned int tunnel_rate, tunnel_users; @@ -2333,13 +2339,13 @@ def function(source, name): bool t8132_ss, t8132_common_owned, t8132_failed, cio_tunables, t8132_dp_alt; /* A CIO sleep is T8132's too, covered by tools/asahi/atc-cio-sleep-tests.py. */ struct { bool prepared; } cio_sleep; - struct { void *usb3_dp; } tunables; + struct { void *usb3_dp, *dp_lioa, *dp_common_config; } tunables; bool dp_only, pd_was_off, tunnel_clock_on; unsigned int tunnel_rate, tunnel_users; struct { bool aux, pll; unsigned int pairs, rate; } dp_t8122; const struct atcphy_hw *hw; - struct { unsigned char *core, *lpdptx; } regs; + struct { unsigned char *core, *lpdptx, *lioa; } regs; void *dev; int lock, dp_link_rate; bool fixed_usb2, host_active, swap_lanes, ss_tunables, dp_tunables; @@ -2394,6 +2400,9 @@ def function(source, name): polls == fail_poll || !(condition) ? -ETIMEDOUT : 0; }) #define readl_poll_timeout readl_poll_timeout_atomic static void atcphy_usb2_power_on(struct apple_atcphy *p) { (void)p; usb2_on++; } +/* These ownership fixtures have no T8142 DP calibration banks. */ +static void apple_tunable_apply(void *base, void *tunable) +{ (void)base; (void)tunable; assert(!"unexpected banked DP calibration"); } static void atcphy_apply_tunables(struct apple_atcphy *p, enum atcphy_mode mode) { (void)p; (void)mode; } static void atc_tunnel_stop_t8103(struct apple_atcphy *p) { (void)p; } @@ -2655,7 +2664,7 @@ def aux(root): bool t8132_ss, t8132_common_owned, t8132_failed, cio_tunables, t8132_dp_alt; /* A CIO sleep is T8132's too, covered by tools/asahi/atc-cio-sleep-tests.py. */ struct { bool prepared; } cio_sleep; - struct { void *usb3_dp; } tunables; + struct { void *usb3_dp, *dp_lioa, *dp_common_config; } tunables; bool dp_only, pd_was_off, tunnel_clock_on; unsigned int tunnel_rate, tunnel_users; diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/quiesce.py b/tools/testing/selftests/drivers/gpu/apple-dcp/quiesce.py index b36cb733ddd2e..46c5bf457d02f 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/quiesce.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/quiesce.py @@ -77,6 +77,10 @@ def make_unit(source, parent=False, reference=None): static void ordinary_initial(void); static void ordinary_usb2_check(void); static void event(char c) { assert(count+1external; } static int dcp_dptx_disconnect_oob(void *dev,u32 index) { (void)dev;assert(index==0);event('Q');stops++;if(power_error){display.external_error=power_error;return power_error;}display.external_cable=false;display.external_stopped=true;display.dptxport[0].connected=false;display.typec_cable_connected=false;connector.connected=false;return 0; } static struct drm_device *dcp_typec_drm(void) { return NULL; } @@ -164,6 +168,9 @@ def make_unit(source, parent=False, reference=None): #define phy_get_drvdata(p) ((p)->data) #define USB2PHY_SIG 0 #define USB2PHY_SIG_HOST 1 +USB2_RUN_DEFINES +/* Retained USB2 power is exercised by dwc3-teardown, not these role removals. */ +static u32 readl(void *p) { (void)p;assert(false);return 0; } static struct { enum atcphy_pipehandler_state pipehandler_state; bool enable_dp_aux; } atcphy_modes[7]; static struct apple_atcphy ordinary_phy; static struct phy usb_phy={.data=&ordinary_phy}; @@ -200,6 +207,10 @@ def make_unit(source, parent=False, reference=None): ''' # The ordinary port is the T8122 profile unless a case selects the T8103 # generation, whose live legacy PIPE park the mux switch now consults. + ordinary_phy=ordinary_phy.replace('USB2_RUN_DEFINES', '\n'.join( + line for line in atc.splitlines() + if line.startswith(('#define USB2PHY_USBCTL ', '#define USB2PHY_USBCTL_USB_MODE ', + '#define USB2PHY_USBCTL_RUN ')))) generation='enum atcphy_generation {' in atc ordinary_phy=ordinary_phy.replace('GENERATION_ENUM\n',block(atc,'enum atcphy_generation {')+';\n' if generation else '',1) ordinary_phy=ordinary_phy.replace('GENERATION_FIELD ','enum atcphy_generation gen; ' if generation else '',1) diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/transaction.py b/tools/testing/selftests/drivers/gpu/apple-dcp/transaction.py index 82201fbdb1339..bcf5b0d3f1b0f 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/transaction.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/transaction.py @@ -163,7 +163,14 @@ def check(name, unit, cases=((),), negative=False, flags=()): pos=actual.index('static struct typec_mux_dev phy_provider') # route_set asks whether a tunnel holds any of the port's slots: the real helper. tunneled='#ifndef ARRAY_SIZE\n#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))\n#endif\n'+apple_function(ROOT,'dcp_typec_port_tunneled') - actual=actual[:pos]+tunneled+block(dcp,'static bool dcp_typec_route_is_dp(')+'\n'+block(dcp,'static int dcp_typec_route_set(')+'\n'+actual[pos:] + route_apply=apple_function(ROOT,'dcp_typec_route_apply') + if route_apply: + # The ordinary SAFE fixture supplies a leaf for the T8142-only finish + # path. Here set must execute the complete production apply body too. + stub=block(actual,'static int dcp_typec_route_apply(') + actual=actual.replace(stub, 'static int dcp_typec_route_apply(struct typec_mux_dev *,struct typec_mux_state *);', 1) + pos=actual.index('static struct typec_mux_dev phy_provider') + actual=actual[:pos]+tunneled+block(dcp,'static bool dcp_typec_route_is_dp(')+'\n'+route_apply+block(dcp,'static int dcp_typec_route_set(')+'\n'+actual[pos:] actual=actual.replace(block(actual,'static int display_set('),'''static int display_set(struct typec_mux_dev *m,struct typec_mux_state *s) { event('S');return dcp_typec_route_set(m,s); }''',1) actual=actual.replace("(void)m;assert(s->mode==TYPEC_STATE_SAFE);event('L');", "(void)m;(void)s;event('L');",1) actual=actual.replace('connector=(struct connector){.connected=true};','connector=(struct connector){.connected=true};',1)