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
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 @@ -1034,6 +1034,8 @@ struct apple_dcp {
bool s2r_fw_down;
/* Stopped cold for firmware-driven sleep, with no restart until reboot. */
bool sleep_cold_stopped;
/* The sleep engine stops it after its last refusal, see dcp_commit_stop_arm(). */
bool commit_stop_armed;
/*
* 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
71 changes: 71 additions & 0 deletions drivers/gpu/drm/apple/dcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -11547,6 +11547,70 @@ static bool dcp_sleep_owned(struct apple_dcp *dcp)
!dcp->external && apple_sleep_commit_stops_coprocs() && !apple_sleep_dry_run();
}

/* Interrupts off, one CPU, after the sleep's last refusal: the idle pair and receive off. */
static int dcp_commit_stop(void *data)
{
struct apple_dcp *dcp = data;
struct apple_rtkit *rtk = dcp->rtk ?: dcp_v26_rtkit(dcp);
void __iomem *control = dcp->coproc_reg + APPLE_DCP_COPROC_CPU_CONTROL;
unsigned int us;
int ret = -ENODEV;

if (!IS_ERR_OR_NULL(rtk)) {
ret = apple_rtkit_sleep_idle_polled(rtk, control, &us);
apple_rtkit_mailbox_recv_off(rtk);
}
/* Registered first, it clears its run bit itself, twice as the engine does. */
writel(readl(control) & ~APPLE_DCP_COPROC_CPU_CONTROL_RUN, control);
writel(readl(control) & ~APPLE_DCP_COPROC_CPU_CONTROL_RUN, control);

return ret;
}

/*
* Any other internal DCP whose firmware a firmware-driven deep sleep's commit
* powers down for good, as the SoC's sleep data says
* (apple_sleep_display_no_restart(), the firmware-27 T8122 DCP for one): its
* suspend is the ordinary one, which leaves the firmware running, and the
* sleep engine idles and stops it after the sleep's last refusal
* (dcp_commit_stop()), in its first pass of coprocessor stops, before the
* wake is armed and macOS's off words drop, then powers the display down.
* A sleep refused before then resumes it as usual; one that got that far
* has stopped it, and it stays stopped until a reboot. If the stop can't be registered the
* firmware is left running and the engine refuses the sleep.
*/
static void dcp_commit_stop_arm(struct apple_dcp *dcp)
{
int ret;

if (!IS_ENABLED(CONFIG_APPLE_SOC_SLEEP) || dcp->external ||
!apple_sleep_display_no_restart(dcp->dev) || !apple_sleep_commit_stops_coprocs() ||
apple_sleep_dry_run())
return;
ret = apple_sleep_coproc_register_first(dcp->dev, dcp_commit_stop, dcp);
if (ret) {
dev_warn(dcp->dev, "no stop registered for the sleep's commit (%d): the sleep is refused\n",
ret);
return;
}
apple_sleep_coproc_set_ready(dcp->dev, true);
dcp->commit_stop_armed = true;
}

/* True when the sleep's commit stopped the firmware (dcp_commit_stop_arm()). */
static bool dcp_commit_stop_disarm(struct apple_dcp *dcp)
{
bool stopped;

if (!dcp->commit_stop_armed)
return false;
dcp->commit_stop_armed = false;
stopped = apple_sleep_coproc_stopped(dcp->dev);
apple_sleep_coproc_unregister(dcp->dev);

return stopped;
}

bool dcp_s2r_firmware_stopped(struct platform_device *pdev)
{
struct apple_dcp *dcp = platform_get_drvdata(pdev);
Expand Down Expand Up @@ -11884,6 +11948,7 @@ static int dcp_platform_suspend(struct device *dev)
dcp_sleep_hold_phys(dcp);
/* Last: the steps above still talk to the coprocessor. */
dcp_hold_for_sleep(dcp);
dcp_commit_stop_arm(dcp);

return 0;
}
Expand Down Expand Up @@ -11912,6 +11977,12 @@ 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);

if (dcp_commit_stop_disarm(dcp)) {
dev_warn(dev, "display coprocessor stopped by the sleep's commit; panel stays off until reboot\n");
WRITE_ONCE(dcp->quiescing, true);
WRITE_ONCE(dcp->sleep_cold_stopped, true);
}

if (dcp_v26_sleep_stopped(dcp))
return dcp_v26_sleep_resume(dcp);

Expand Down
53 changes: 52 additions & 1 deletion drivers/soc/apple/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,19 @@ static bool apple_sleep_dry(const struct apple_sleep *s)
return s->soc->early_context ? s->dry_run : !READ_ONCE(sleep_untested_commit);
}

/*
* The internal display of a SoC whose commit powers it down for good (display_no_restart), with
* its coprocessor's stop registered first and readied by its driver: the engine runs that stop
* in its first pass, after the last refusal, and only then powers the display down, so a
* sleep refused before that leaves the display running. Otherwise the display goes down at the
* start of the entry as before.
*/
static bool sleep_display_late(struct apple_sleep *s)
{
return s->soc->display_no_restart && s->soc->ndisp && s->display[0].np &&
!apple_sleep_dry(s) && apple_sleep_coproc_ready_node(s->display[0].np);
}

/*
* 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
Expand Down Expand Up @@ -1807,6 +1820,21 @@ bool apple_sleep_commit_stops_coprocs(void)
}
EXPORT_SYMBOL_GPL(apple_sleep_commit_stops_coprocs);

/*
* Whether this firmware sleep's commit powers @dev, the internal display coprocessor (the first
* of apple,display-coprocessors), down with no restart after the wake, as the SoC's sleep data
* says (display_no_restart). Its driver then stops it cold itself, before the commit, and leaves
* it stopped until a reboot. Any other display coprocessor isn't covered.
*/
bool apple_sleep_display_no_restart(struct device *dev)
{
struct apple_sleep *s = READ_ONCE(apple_sleep);

return s && dev && s->soc->display_no_restart && s->soc->ndisp &&
s->display[0].np && s->display[0].np == dev->of_node && pm_suspend_via_firmware();
}
EXPORT_SYMBOL_GPL(apple_sleep_display_no_restart);

/* This firmware sleep stops before its commit: a driver must stop nothing it can't restart. */
bool apple_sleep_dry_run(void)
{
Expand Down Expand Up @@ -2050,6 +2078,12 @@ const struct apple_sleep_smc_policy *apple_sleep_smc_policy(void)
}
EXPORT_SYMBOL_GPL(apple_sleep_smc_policy);

/* One sleep, then it clears itself: what a sleep refused at its very last check unwinds. */
static bool sleep_refuse_late;
module_param_named(refuse_late, sleep_refuse_late, bool, 0644);
MODULE_PARM_DESC(refuse_late,
"TEST ONLY: refuse the next early_context sleep at its last check, after every other");

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,
Expand Down Expand Up @@ -3787,6 +3821,9 @@ static int apple_sleep_refuse(struct apple_sleep *s)
dev_info(s->dev, "dry run: the display coprocessor is left running; a sleep that commits stops it cold, until a reboot\n");
continue;
}
/* Stopped after the last refusal: sleep_display_late(). */
if (i == 0 && sleep_display_late(s))
continue;
dev_err(s->dev, "refused: a bound display coprocessor is still running\n");
refused = true;
}
Expand Down Expand Up @@ -6500,6 +6537,7 @@ static int apple_sleep_enter_dry(struct apple_sleep *s)
static int apple_sleep_enter_prepare(struct apple_sleep *s)
{
const char *step = "SoC check";
bool late_display;
int ret;

if (s->soc->ops->check) {
Expand All @@ -6516,7 +6554,8 @@ static int apple_sleep_enter_prepare(struct apple_sleep *s)
if (apple_sleep_dry(s))
return apple_sleep_enter_dry(s);
ret = apple_sleep_cpus_hold(s);
if (!ret) {
late_display = sleep_display_late(s);
if (!ret && !late_display) {
step = "display prepare";
if (s->soc->regions)
s->regs_staged = true;
Expand Down Expand Up @@ -6549,6 +6588,11 @@ static int apple_sleep_enter_prepare(struct apple_sleep *s)
step = "wakeup pending";
ret = -EBUSY;
}
if (!ret && xchg(&sleep_refuse_late, false)) {
step = "test: refuse_late";
ret = -EBUSY;
dev_info(s->dev, "test: refused at the last check (refuse_late)\n");
}
if (ret && s->soc->regions)
dev_info(s->dev, "refused at .enter: %s: %d\n", step, ret);
if (!ret && s->soc->ops->display_stop) {
Expand All @@ -6572,6 +6616,13 @@ static int apple_sleep_enter_prepare(struct apple_sleep *s)
/* No returning error path below this point. */
if (!s->soc->ops->display_stop)
apple_sleep_coprocs_stop(s, true);
/* Its driver's stop ran just above; past the last refusal, a failure goes on. */
if (late_display) {
ret = s->soc->ops->display_off(s);
if (ret)
dev_err(s->dev, "display power-down past the last refusal failed: %d\n",
ret);
}
if (!s->soc->own_wake) {
sleep_wake_arm(s);
s->wake_masks_saved = true;
Expand Down
8 changes: 8 additions & 0 deletions include/linux/soc/apple/sleep.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ int apple_sleep_coproc_wake_error(struct device *dev);
*/
bool apple_sleep_commit_stops_coprocs(void);

/* This firmware sleep's commit stops @dev, the internal display CPU, for good: see sleep.c. */
bool apple_sleep_display_no_restart(struct device *dev);

/* This firmware sleep stops before its commit: a driver must stop nothing it can't restart. */
bool apple_sleep_dry_run(void);

Expand Down Expand Up @@ -444,6 +447,11 @@ static inline bool apple_sleep_dry_run(void)
return false;
}

static inline bool apple_sleep_display_no_restart(struct device *dev)
{
return false;
}

static inline void apple_sleep_usb_set_asleep(bool asleep)
{
}
Expand Down
Loading