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
105 changes: 98 additions & 7 deletions drivers/gpu/drm/imagination/pvr_apple_s8003.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,15 @@ struct pvr_apple_s8003 {
struct t7000_phases t7000_ph[APPLE_ENGINES];
/* The 3D record the last fragment job was written to (T7000_RCH_W or T7000_RCH1_W) */
u32 t7000_frag_w;
/*
* The compute record a job of each parity was written to (S8003_CH_W or
* T7000_CU_W1); how often the job before a compute job showed its
* finish stamp but not yet its mirror stamp when the new job's submit
* saw it done (the firmware still retiring it: one record would have
* been rewritten under it), and the longest wait for a mirror stamp.
*/
u32 t7000_cu_w[2];
u64 t7000_cu_mirror_behind, t7000_cu_mirror_wait_max_us;
/*
* The A8's firmware interrupts by what the check that took each one
* found (t7000_irq_checked()): its job, or nothing after a poll had
Expand Down Expand Up @@ -4686,6 +4695,57 @@ static void t7000_publish(struct pvr_apple *apple, enum pvr_apple_engine engine,

/* The A8's compute record: the A9's with every offset from 0x10 on 8 further */
#define T7000_CU_W_SIZE 0x298
/*
* The second compute record and microsequence, in the root page behind the
* compute channel's (T7000_CU_CHANNEL + 0x1000, unused before), at offsets
* from the channel's address.
*/
#define T7000_CU_SLOT1 0x1000
#define T7000_CU_W1 (T7000_CU_SLOT1 + 0x000)
#define T7000_CU_USEQ1 (T7000_CU_SLOT1 + 0x400)

/*
* The firmware retires a job after its finish stamp: it reads the record
* for the mirror stamp (address and value at W+0x260..0x268), writes it,
* and runs the microsequence to its end op (0x40000017). On the A7 a
* compute job every few thousand, written into the one record right after
* the job before it showed its finish stamp, was never taken: the job
* before it showed its finish stamp but never its mirror stamp ("stamps
* N-2 N-1"), so the firmware never finished retiring it, and doorbells did
* not help. Two records alternate, and a record is rewritten only once the
* job that last used it shows its mirror stamp too, as the A9's completion
* check waits for both stamps and Apple's kext reuses a record only after
* its stamps retire.
*/

/*
* Wait until compute job @seq shows its mirror stamp (the channel's first
* stamp word), the end of its retirement as the host can see it.
* submit_lock held.
*/
static int t7000_cu_mirror_wait(struct pvr_apple *apple, u32 seq)
{
struct pvr_apple_s8003 *s = apple->chip_data;
const u8 *p = s8003_channel(s, APPLE_ENGINE_COMPUTE);
u64 t0 = ktime_get_ns(), us;
u32 mirror;
int err;

if ((s32)(get32(p + S8003_CU_STAMP) - seq) >= 0)
return 0;
err = read_poll_timeout(get32, mirror,
(s32)(mirror - seq) >= 0 || READ_ONCE(apple->fault), 5,
S8003_RING_TIMEOUT_US, false, p + S8003_CU_STAMP);
us = (ktime_get_ns() - t0) / NSEC_PER_USEC;
s->t7000_cu_mirror_wait_max_us = max(s->t7000_cu_mirror_wait_max_us, us);
if (err || (s32)(mirror - seq) < 0) {
dev_err(apple_dev(apple),
"compute: job %u shows its finish stamp but no mirror stamp %llu us on (stamps %u %u): the firmware stalled retiring it before the next job was written\n",
seq, us, get32(p + S8003_CU_STAMP), get32(p + S8003_CU_STAMP + 4));
return err ?: -EIO;
}
return 0;
}
#define T7000_CU_TERMINATE1 0x00900004 /* the terminate program's descriptor (A9 0x00a00004) */

/*
Expand All @@ -4704,22 +4764,38 @@ static int t7000_submit_compute(struct pvr_apple *apple, struct s8003_vm *vm, st
struct pvr_apple_s8003 *s = apple->chip_data;
u32 addr = s8003_channel_addr(s, APPLE_ENGINE_COMPUTE);
u32 global = s8003_object_addr(&s->layout, S8003_CHANNEL + 2);
u32 w = addr + S8003_CH_W, stamp = addr + S8003_CU_STAMP, slot = vm->slot[0], seq, k;
u32 stamp = addr + S8003_CU_STAMP, slot = vm->slot[0], seq, k, w_off, useq_off, w, reuse;
u8 *p = s8003_channel(s, APPLE_ENGINE_COMPUTE);
u8 *work = p + S8003_CH_W;
u8 *work;
unsigned int i;
int err;

BUILD_BUG_ON(T7000_CU_W1 + T7000_CU_W_SIZE > T7000_CU_USEQ1);
BUILD_BUG_ON(T7000_CU_CHANNEL + T7000_CU_USEQ1 + S8003_CU_USEQ_SIZE > T7000_TA_CHANNEL);
err = s8003_wait_done(apple, APPLE_ENGINE_COMPUTE, apple->last_seq);
if (err)
return s8003_submit_error(apple, vm, "compute", err, S8003_REFUSED_SLOT_WAIT,
"record slot wait");
seq = apple->last_seq + 1;
k = seq - 1;
/* the record this job takes, and the job that used it last */
w_off = seq & 1 ? T7000_CU_W1 : S8003_CH_W;
useq_off = seq & 1 ? T7000_CU_USEQ1 : S8003_CU_USEQ;
/* seq - 2, or seq - 1 for the first job after a reset left the record before in use */
reuse = s->t7000_cu_w[(seq - 1) & 1] == w_off ? seq - 1 : seq - 2;
/* statistics: the job before this one still retiring when its finish stamp was seen */
if ((s32)(get32(p + S8003_CU_STAMP) - apple->last_seq) < 0)
s->t7000_cu_mirror_behind++;
err = t7000_cu_mirror_wait(apple, reuse);
if (err)
return s8003_submit_error(apple, vm, "compute", err, S8003_REFUSED_SLOT_WAIT,
"record slot wait (mirror stamp)");
err = t7000_publish_check(apple, APPLE_ENGINE_COMPUTE);
if (err)
return s8003_submit_error(apple, vm, "compute", err, S8003_REFUSED_PUBLISH,
"publish");
seq = apple->last_seq + 1;
k = seq - 1;
w = addr + w_off;
work = p + w_off;
{
const u32 useq[] = {
0x32, w + 0x18, w + 0x68, global + 0x720, addr, slot, k, k, 0, w + 0x1f0,
Expand All @@ -4733,8 +4809,8 @@ static int t7000_submit_compute(struct pvr_apple *apple, struct s8003_vm *vm, st
};

BUILD_BUG_ON(sizeof(useq) > S8003_CU_USEQ_SIZE);
memset(p + S8003_CU_USEQ, 0, S8003_CU_USEQ_SIZE);
useq_put(p + S8003_CU_USEQ, useq, ARRAY_SIZE(useq));
memset(p + useq_off, 0, S8003_CU_USEQ_SIZE);
useq_put(p + useq_off, useq, ARRAY_SIZE(useq));
}
memset(work, 0, T7000_CU_W_SIZE);
put32(work, 3);
Expand All @@ -4745,7 +4821,7 @@ static int t7000_submit_compute(struct pvr_apple *apple, struct s8003_vm *vm, st
put64(work + 0x68, g->tail);
put64(work + 0x70, g->pds_resume);
put64(work + 0x78, cmd->cmd.regs.cdm_ctrl_stream_base);
put32(work + 0x1e8, addr + S8003_CU_USEQ);
put32(work + 0x1e8, addr + useq_off);
put32(work + 0x1ec, S8003_CU_USEQ_SIZE);
for (i = 0; i < 4; i++)
put64(work + 0x1f4 + i * 8, g->state[i]);
Expand All @@ -4763,6 +4839,7 @@ static int t7000_submit_compute(struct pvr_apple *apple, struct s8003_vm *vm, st
put32(work + 0x278, seq);
put32(work + 0x27c, k);
put32(p + S8003_CH_RING + ((seq - 1) % S8003_CH_ENTRIES) * 4, w);
s->t7000_cu_w[seq & 1] = w_off;
apple->last_seq = seq;
t7000_publish(apple, APPLE_ENGINE_COMPUTE, seq % S8003_CH_ENTRIES);
return seq;
Expand Down Expand Up @@ -5890,6 +5967,14 @@ static void t7000_report_hang(struct pvr_apple *apple)
names[engine], s8003_submitted(apple, engine), get32(p + stamp),
get32(p + stamp + 4), get32(ctl + S8003_RING_CONSUMER),
get32(ctl + S8003_RING_PRODUCER));
if (engine == APPLE_ENGINE_COMPUTE)
dev_err(apple_dev(apple),
"hang: compute: watermarks %u %u %u %u host %u; records seq %u %u; previous job still retiring at submit %llu, longest mirror wait %llu us\n",
get32(p + S8003_CH_CTL), get32(p + S8003_CH_CTL + 0x10),
get32(p + S8003_CH_CTL + 0x20), get32(p + S8003_CH_CTL + 0x30),
get32(p + S8003_CH_CTL + S8003_CH_CTL_HOST),
get32(p + S8003_CH_W + 0x278), get32(p + T7000_CU_W1 + 0x278),
s->t7000_cu_mirror_behind, s->t7000_cu_mirror_wait_max_us);
}
dev_err(apple_dev(apple), "hang: firmware %s, Fender state %#x\n",
s->failed ? "rings unreadable" : READ_ONCE(apple->fault) ? "posted a fault" :
Expand Down Expand Up @@ -5997,6 +6082,8 @@ static void t7000_job_retired(struct pvr_apple *apple, enum pvr_apple_engine eng
w = p + T7000_RCH1_W;
times = T7000_RCH1_TIMES;
}
if (engine == APPLE_ENGINE_COMPUTE && s->t7000_cu_w[seq & 1])
w = p + s->t7000_cu_w[seq & 1];
if (get32(w + at[engine].seq) != seq)
return;
if (run / T7000_FW_TICKS_PER_US <= USEC_PER_SEC)
Expand Down Expand Up @@ -6050,6 +6137,8 @@ static void t7000_debugfs_reset(struct pvr_apple *apple)
atomic64_set(&s->doorbell_wakes, 0);
atomic64_set(&s->doorbell_pll_unlocked, 0);
atomic64_set(&s->doorbell_refused, 0);
s->t7000_cu_mirror_behind = 0;
s->t7000_cu_mirror_wait_max_us = 0;
for (i = 0; i < S8003_REFUSALS; i++)
atomic64_set(&s->refused[i], 0);
}
Expand Down Expand Up @@ -6207,6 +6296,8 @@ static void t7000_debugfs_show(struct pvr_apple *apple, struct seq_file *m)
clamp(max(READ_ONCE(a8_pm_blocks), READ_ONCE(s->t7000_pm_floor)), 2u,
(u32)T7000_PM_BLOCKS_MAX),
READ_ONCE(a8_pm_blocks), READ_ONCE(s->t7000_pm_floor), (u32)T7000_PM_BLOCKS_MAX);
seq_printf(m, "a8 compute prev_still_retiring %llu longest_mirror_wait_us %llu\n",
s->t7000_cu_mirror_behind, s->t7000_cu_mirror_wait_max_us);
seq_printf(m, "a8 doorbells %lld in_fender_state_0 %lld pll5_relocking %lld not_rung %lld\n",
(long long)atomic64_read(&s->doorbells),
(long long)atomic64_read(&s->doorbell_wakes),
Expand Down
Loading