Skip to content
Merged
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
53 changes: 41 additions & 12 deletions drivers/gpu/drm/asahi/g17/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,25 @@ struct asahi_g17_commit {
/* The domain at the start of the stop, and the raise to full power before any ASC access */
u32 entry;
int raise_ret;
/* Whether the stop raises the domain first (asahi_g17_commit_raises()) */
bool raise;
};

/*
* Whether the commit's stop raises the GPU's domain before it touches the coprocessor: on the
* SoCs the raise was made for, the T8142 (J815: the GPU gates itself between frames and its
* registers may not answer below full power) and the T6050. Elsewhere the stop goes straight
* to the idle poll, as before the raise. On the T8140 (J700) the domain reads its target on
* and nothing powered under automatic power at the commit (0x1000230f); a raise from there
* times out with BUSY latched, the PMP's AP IDLE then goes unanswered, the sleep takes the
* deep path and the PMP and GPU firmware don't come back from it.
*/
static bool asahi_g17_commit_raises(struct device *dev)
{
return of_device_is_compatible(dev->of_node, "apple,agx-t8142") ||
of_device_is_compatible(dev->of_node, "apple,agx-g17s");
}

/*
* down() at the commit, every refusal behind it: both instances idled by polling, mailboxes
* and run bits off, the gating hold, the PMP request withdrawn while the PMP still runs, then
Expand All @@ -384,15 +401,18 @@ static int asahi_g17_commit_stop(void *data)
* 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.
* asahi_g17_power_raise() does, and keep the word from before for the resume. Only where
* asahi_g17_commit_raises() says so.
*/
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);
if (c->raise) {
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) {
Expand All @@ -417,8 +437,14 @@ static int asahi_g17_commit_stop(void *data)
c->request_ret = c->request ? apple_pmp_report_entry_withdraw_polled(c->request) : 0;
apple_sleep_note_sub(5);

/* Off automatic management, still at full power, for the bridge. */
writel(readl(c->ps) & ~(PS_AUTO_ENABLE | PS_BUSY | PS_FLAGS), c->ps);
/*
* Off automatic management, for the bridge (still at full power after a raise). Without
* the raise, the word for the resume is the one found here, after the idle.
*/
val = readl(c->ps);
if (!c->raise)
c->saved = val;
writel(val & ~(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);
Expand Down Expand Up @@ -574,6 +600,7 @@ struct asahi_g17_commit *asahi_g17_commit_prepare(struct device *dev,
c->rtk[1] = secondary_rtk;
c->mbox[1] = secondary_mbox;
c->count = secondary_rtk ? 2 : 1;
c->raise = asahi_g17_commit_raises(dev);

ret = -EOPNOTSUPP;
for (i = 0; i < c->count; i++) {
Expand Down Expand Up @@ -663,6 +690,7 @@ struct asahi_g17_commit *asahi_g16_commit_prepare(struct device *dev, struct app
c->dev = dev;
c->rtk[0] = rtk;
c->count = 1;
c->raise = asahi_g17_commit_raises(dev);

ret = -ENODEV;
c->cpu[0] = asahi_g17_map(dev->of_node, "asc", 0, ASC_CPU_CONTROL, 8);
Expand Down Expand Up @@ -704,8 +732,9 @@ 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);
if (c->raise)
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);
Expand Down
Loading