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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@ description: |
properties:
compatible:
enum:
- apple,t8122-sleep
- apple,t8132-sleep
- apple,t8140-sleep
- apple,t8142-sleep

reg:
minItems: 25
minItems: 21
maxItems: 41

reg-names:
minItems: 25
minItems: 21
maxItems: 41

apple,wake-enable:
Expand Down Expand Up @@ -105,6 +106,41 @@ required:
- apple,display-coprocessors

allOf:
- if:
properties:
compatible:
contains:
const: apple,t8122-sleep
then:
required:
- apple,wake-enable
properties:
reg:
minItems: 21
maxItems: 21
reg-names:
items:
- const: ps
- const: pwrgate
- const: cpu-start
- const: cllt
- const: cluster
- const: commit
- const: wdt
- const: spmi
- const: spmi-hpm
- const: wake
- const: ps-aon
- const: mcc-a
- const: mcc-b
- const: mcc-c
- const: mcc-d
- const: apcie-axi
- const: apcie-rc
- const: apcie-clkgen
- const: apcie-phy
- const: apcie-phy-ip
- const: apcie-port0
- if:
properties:
compatible:
Expand Down
10 changes: 10 additions & 0 deletions arch/arm64/boot/dts/apple/t8122-j613-j615.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -503,3 +503,13 @@
};
};
};

&mcc {
apple,boot-dma-devices = <&pmp>;
status = "okay";
};

&sleep {
apple,debug-port = <&hpm0>;
status = "okay";
};
7 changes: 2 additions & 5 deletions arch/arm64/boot/dts/apple/t8122-peripherals.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,9 @@
status = "disabled";
};

mcc: memory-controller@2d03c0000 {
mcc: memory-controller@220000000 {
compatible = "apple,t8122-mcc", "apple,mcc";
reg = <0x2 0xd03c0000 0x0 0x20000>,
<0x2 0xd0478000 0x0 0x149c>,
<0x2 0xd0780000 0x0 0x4000>,
<0x2 0x20000000 0x0 0x2000000>,
reg = <0x2 0x20000000 0x0 0x2000000>,
<0x2 0x22000000 0x0 0x2000000>;
status = "disabled";
};
Expand Down
36 changes: 36 additions & 0 deletions arch/arm64/boot/dts/apple/t8122.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@
mboxes = <&sep_mbox>;
mbox-names = "mbox";
iommus = <&sep_dart 0>;
power-domains = <&ps_sep>, <&ps_gpio>;
status = "disabled";
};

Expand Down Expand Up @@ -893,6 +894,41 @@
/* child nodes are added in t8122-pmgr.dtsi */
};

sleep: sleep-controller@2d0700000 {
compatible = "apple,t8122-sleep";
reg = <0x2 0xd0700000 0x0 0x14000>,
<0x2 0xd0724000 0x0 0x4000>,
<0x2 0xd0734000 0x0 0x10>,
<0x2 0xd0768000 0x0 0x40>,
<0x2 0xd0780000 0x0 0x8>,
<0x2 0xe42d4000 0x0 0x4>,
<0x2 0xe42b0000 0x0 0x30>,
<0x2 0xe4714000 0x0 0x100>,
<0x2 0xe4908000 0x0 0x100>,
<0x2 0xe4004000 0x0 0x48>,
<0x2 0xe4280000 0x0 0x4000>,
<0x2 0x20024000 0x0 0x1000>,
<0x2 0x20064000 0x0 0x1000>,
<0x2 0x20158000 0x0 0x1000>,
<0x2 0x20400000 0x0 0x1000>,
<0x5 0x9c000000 0x0 0x2000>,
<0x5 0x91000000 0x0 0x1000>,
<0x5 0x9e088000 0x0 0x3000>,
<0x5 0x9e000000 0x0 0x10000>,
<0x5 0x9e040000 0x0 0x10000>,
<0x5 0x94008000 0x0 0x5000>;
reg-names = "ps", "pwrgate", "cpu-start", "cllt",
"cluster", "commit", "wdt", "spmi",
"spmi-hpm", "wake", "ps-aon",
"mcc-a", "mcc-b", "mcc-c", "mcc-d",
"apcie-axi", "apcie-rc", "apcie-clkgen",
"apcie-phy", "apcie-phy-ip", "apcie-port0";
apple,wake-enable = <155>;
apple,display-coprocessors = <&dcp>;
apple,pinctrl = <&pinctrl_ap>;
status = "disabled";
};

pmp_mbox: mbox@2d0c08000 {
compatible = "apple,t8122-asc-mailbox", "apple,asc-mailbox-v4";
reg = <0x2 0xd0c08000 0x0 0x4000>;
Expand Down
2 changes: 2 additions & 0 deletions drivers/gpu/drm/apple/dcp-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,8 @@ struct apple_dcp {
struct delayed_work secure_poll_wq;
/* Stopped and not restarted, which outlives a suspend that gets refused. */
bool s2r_fw_down;
/* Stopped cold for firmware-driven sleep, with no restart until reboot. */
bool sleep_cold_stopped;
/*
* Its last system suspend left the firmware running and its domains on
* (wakeup path), see dcp_sleep_keeps_firmware(). Cleared by the next
Expand Down
45 changes: 44 additions & 1 deletion drivers/gpu/drm/apple/dcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -10428,11 +10428,25 @@ static void dcp_dpms_power_off(struct apple_dcp *dcp)
__dcp_dpms_power_off(dcp);
}

/*
* Internal 26.6 DCP firmware stops cold when firmware-driven deep sleep will
* cut display power, because there is no cold-restart path for it yet. In a
* sleep dry run the coprocessor is left running and takes the ordinary suspend
* path instead.
*/
static bool dcp_sleep_owned(struct apple_dcp *dcp)
{
return IS_ENABLED(CONFIG_APPLE_SOC_SLEEP) && dcp->fw_compat == DCP_FIRMWARE_V_26_6 &&
!dcp->external && apple_sleep_commit_stops_coprocs() && !apple_sleep_dry_run();
}

bool dcp_s2r_firmware_stopped(struct platform_device *pdev)
{
struct apple_dcp *dcp = platform_get_drvdata(pdev);

return READ_ONCE(dcp->s2r_fw_down);
/* Whichever of this and the display subsystem suspends first: nothing commits to it. */
return READ_ONCE(dcp->s2r_fw_down) || READ_ONCE(dcp->sleep_cold_stopped) ||
(pm_suspend_via_firmware() && dcp_sleep_owned(dcp));
}

#include "dcp-v27-sleep.inc"
Expand Down Expand Up @@ -10551,6 +10565,31 @@ 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 (READ_ONCE(dcp->sleep_cold_stopped))
return 0;
if (pm_suspend_via_firmware() && dcp_sleep_owned(dcp)) {
u32 control = readl(dcp->coproc_reg + APPLE_DCP_COPROC_CPU_CONTROL);
struct apple_rtkit *rtk = dcp->rtk ?: dcp_v26_rtkit(dcp);

dev_warn(dev, "display coprocessor stopped cold for sleep (control %#x); panel stays off until reboot\n",
control);
WRITE_ONCE(dcp->quiescing, true);
/*
* Run the 26.6 firmware's panel-off and sleep-entry calls, then
* request RTKit AP and IOP idle before halting the coprocessor.
*/
dcp_v26_sleep_calls(dcp, 2);
if (!IS_ERR_OR_NULL(rtk)) {
int ret = apple_rtkit_idle_with(rtk, dcp_secure_port_idle, dcp);

if (ret)
dev_warn(dev, "RTKit idle before cold stop failed: %d\n", ret);
}
WRITE_ONCE(dcp->sleep_cold_stopped, true);
dcp_s2r_cpu_stop(dcp);
return 0;
}

/*
* J813 uses the same qualified stop as DPMS off. Probe already gates
* its derived power layout on appledrm.s2r_untested; without this
Expand Down Expand Up @@ -10722,6 +10761,10 @@ static int dcp_platform_resume(struct device *dev)
if (dcp_v27_sleep_selected(dcp) && READ_ONCE(dcp->sleep_v27_closed))
return dcp_v27_sleep_resume(dcp);

/* Stopped cold, with no restart path until reboot. */
if (READ_ONCE(dcp->sleep_cold_stopped))
return 0;

if (dcp->s2r_stopped)
return dcp_s2r_resume(dcp);

Expand Down
99 changes: 98 additions & 1 deletion drivers/gpu/drm/apple/iomfb_v26_6.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,24 @@ static int dcp_v26_callback(void *cookie, u32 tag,
}
if (tag == D(576) && SHAPE(4, 0))
return 0;
/*
* Callbacks the firmware sends when the display is powered down (A473, observed in
* macOS's panel-off and in Linux's sleep calls), answered as the H17P and M4 drivers
* answer them: a no-op (D2), swap_complete_intent_gated (D592, a no-op),
* powerUpDART (D572, success) and get_calendar_time_ms (D209).
*/
if ((tag == D(2) && SHAPE(0, 0)) || (tag == D(592) && SHAPE(20, 0)))
return 0;
if (tag == D(572) && SHAPE(4, 4)) {
if (v26->dcp)
dcp_s2r_dart_power(v26->dcp, get_unaligned_le32(in));
memset(out, 0, 4);
return 0;
}
if (tag == D(209) && SHAPE(0, 8)) {
put_unaligned_le64(ktime_get_real_ns() / NSEC_PER_MSEC, out);
return 0;
}
if (tag == D(300) && SHAPE(16, 0)) {
dcp_v26_publish(v26, in);
return 0;
Expand Down Expand Up @@ -1774,7 +1792,8 @@ void iomfb_v26_6_flush(struct apple_dcp *dcp, struct drm_crtc *crtc,
p = crtc->primary->state;
fb = p && p->visible ? p->fb : NULL;
dcp->swap_start = ktime_get();
if (!dcp->v26 || !dcp_v26_present(dcp->v26, fb, dcp->notch_height, &presented, cs)) {
if (READ_ONCE(dcp->sleep_cold_stopped) || !dcp->v26 ||
!dcp_v26_present(dcp->v26, fb, dcp->notch_height, &presented, cs)) {
dcp_v26_cancel_event(dcp);
return;
}
Expand Down Expand Up @@ -1928,3 +1947,81 @@ void iomfb_v26_6_poweroff(struct apple_dcp *dcp)
dcp_v26_present(dcp->v26, NULL, 0, NULL, NULL);
}
}

/*
* Calls the 26.6 firmware receives from macOS before a system sleep, in the order and
* with the inputs observed on its mailbox and RPC memory.
* The panel-off group: A414 (8 zero bytes; reply 1), A478 (reply 1) twice, A476(1),
* A478, A412 (reply 1), A473 (16 zero bytes; reply 8 zero bytes), A500 (0, 0).
* The sleep-entry group: A478, A476(1), A473 (bytes 8, 11 and 12 set to 1), A115
* (reply 0), A500 (0, 1). @groups: 1 sends the sleep-entry group only, 2 sends the
* panel-off group first, then the sleep-entry group. Every reply is compared with
* the expected firmware reply; a mismatch returns -EPROTO.
*/
static int dcp_v26_sleep_call(struct apple_dcp_v26 *v26, u32 tag, const void *in, u32 in_size,
const void *want, u32 want_size, bool *same)
{
u8 out[8] = {};
int ret;

ret = dcp_v26_call(v26, tag, in, in_size, want_size ? out : NULL, want_size, 0);
if (!ret && want_size && memcmp(out, want, want_size)) {
dev_warn(v26->dev, "sleep call %#x reply %*ph, expected %*ph\n", tag, want_size,
out, want_size, want);
*same = false;
}
return ret;
}

int dcp_v26_sleep_calls(struct apple_dcp *dcp, int groups)
{
static const u8 zero16[16], one[4] = { 1 }, one8[8] = { 1 };
static const u8 a473_entry[16] = { [8] = 1, [11] = 1, [12] = 1 };
static const u8 a500_off[4] = { 0, 0 }, a500_entry[4] = { 0, 1 };
struct apple_dcp_v26 *v26 = dcp->v26;
bool same = true;
int ret = 0;

if (!v26 || !v26->started)
return -ENODEV;
mutex_lock(&v26->lock);
if (groups >= 2) {
ret = dcp_v26_sleep_call(v26, A(414), zero16, 8, one8, 8, &same);
if (!ret)
ret = dcp_v26_sleep_call(v26, A(478), NULL, 0, one, 4, &same);
if (!ret)
ret = dcp_v26_sleep_call(v26, A(478), NULL, 0, one, 4, &same);
if (!ret)
ret = dcp_v26_sleep_call(v26, A(476), one, 4, NULL, 0, &same);
if (!ret)
ret = dcp_v26_sleep_call(v26, A(478), NULL, 0, one, 4, &same);
if (!ret)
ret = dcp_v26_sleep_call(v26, A(412), NULL, 0, one, 4, &same);
if (!ret)
ret = dcp_v26_sleep_call(v26, A(473), zero16, 16, zero16, 8, &same);
if (!ret)
ret = dcp_v26_sleep_call(v26, A(500), a500_off, 4, NULL, 0, &same);
dev_dbg(v26->dev, "panel-off calls before sleep: %d\n", ret);
}
if (!ret)
ret = dcp_v26_sleep_call(v26, A(478), NULL, 0, one, 4, &same);
if (!ret)
ret = dcp_v26_sleep_call(v26, A(476), one, 4, NULL, 0, &same);
if (!ret)
ret = dcp_v26_sleep_call(v26, A(473), a473_entry, 16, zero16, 8, &same);
if (!ret)
ret = dcp_v26_sleep_call(v26, A(115), NULL, 0, zero16, 4, &same);
if (!ret)
ret = dcp_v26_sleep_call(v26, A(500), a500_entry, 4, NULL, 0, &same);
mutex_unlock(&v26->lock);
if (!ret && !same)
ret = -EPROTO;
dev_dbg(v26->dev, "sleep calls (groups %d): %d, replies %s expected\n", groups, ret,
same ? "matched" : "differed from");
return ret;
}

struct apple_rtkit *dcp_v26_rtkit(struct apple_dcp *dcp)
{
return dcp->v26 ? dcp->v26->rtk : NULL;
}
4 changes: 4 additions & 0 deletions drivers/gpu/drm/apple/iomfb_v26_6.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <linux/types.h>

struct apple_dcp;
struct apple_rtkit;
struct apple_dcp_v26;
struct dcp_v26_board;
struct device;
Expand Down Expand Up @@ -51,5 +52,8 @@ void iomfb_v26_6_flush(struct apple_dcp *dcp, struct drm_crtc *crtc,
struct drm_atomic_commit *state);
void iomfb_v26_6_poweron(struct apple_dcp *dcp);
void iomfb_v26_6_poweroff(struct apple_dcp *dcp);
/* Pre-sleep shutdown calls and the session's RTKit for firmware-driven sleep. */
int dcp_v26_sleep_calls(struct apple_dcp *dcp, int groups);
struct apple_rtkit *dcp_v26_rtkit(struct apple_dcp *dcp);

#endif /* __APPLE_IOMFB_V26_6_H__ */
Loading
Loading