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
110 changes: 65 additions & 45 deletions drivers/gpu/drm/imagination/pvr_apple_s8003.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
* readings of Apple's kext and firmware.
*/

#include <linux/math64.h>

#include "pvr_apple.h"
#include "pvr_apple_chip.h"
#include "pvr_context.h"
Expand Down Expand Up @@ -118,7 +120,7 @@
#define S8003_IMAGE_SIZE 0x30000
/*
* The root memory: its objects, then, in the Apple layout, the job channels
* (s8003_ch_uncached), at the same offsets from one another as in the shared
* (pvr_apple_s8003_init()), at the same offsets from one another as in the shared
* memory.
*/
#define S8003_ROOT_SIZE 0x14000
Expand All @@ -143,7 +145,7 @@
#define S8003_PM_SETS 12
#define S8003_PM_SET_SIZE (3 * PVR_DEVICE_PAGE_SIZE)
#define S8003_PM_SETS_VA (S8003_SHARED_VA + S8003_SHARED_SIZE)
/* The PM sets in the Apple layout (s8003_pm_uncached): in META's uncached window */
/* The PM sets in the Apple layout (pvr_apple_s8003_init()): in META's uncached window */
#define S8003_PM_SETS_ROOT_VA (S8003_ROOT_VA + SZ_1M)
#define S8003_PM_RECORD 0x80
#define S8003_PM_BLOCK_SIZE SZ_128K /* eight pages of the pool */
Expand Down Expand Up @@ -523,6 +525,7 @@ struct pvr_apple_s8003 {
u32 set_frag[S8003_PM_SETS];
unsigned long wb_sets;
struct s8003_vm *pm_last, *pm_prev; /* last two scenes for cache-line reads */
u64 gpu_ticks[2], gpu_jobs[2], gpu_zero[2]; /* retired TA/3D phase times */
struct pvr_vm_context *park_vm; /* maps what every VM maps, nothing else */

/* Bus addresses the firmware is told: its registers' and ours */
Expand Down Expand Up @@ -1506,30 +1509,6 @@ static void s8003_channels_init(struct pvr_apple_s8003 *s)
/* How often s8003_touch() runs while the firmware works for the host */
#define S8003_TOUCH_US 1000

/*
* Where the firmware reaches the A9's job records and PM sets. Apple's kext
* gives the firmware every per-job object through META's uncached window: on
* the iPad 5 under iOS, the channel states are at 0x43200000, a TA's W at
* 0x43230e80, its PM record at 0x43469880, the stamps at 0x43438000. The A8
* and A7 keep their channels there too. Through the cached window (both 0,
* the earlier A9 layout) a job's finish that comes within ~300 us of a
* doorbell waits for the firmware ~200 us longer than iOS's does, and the
* firmware's writes need s8003_touch() to be seen. Read once, when the GPU is
* probed.
*/
static bool s8003_ch_uncached = true;
module_param_named(apple_ch_uncached, s8003_ch_uncached, bool, 0444);
MODULE_PARM_DESC(apple_ch_uncached,
"A9: job channels (records, microsequences, rings, stamps) in the firmware's uncached window, as Apple's (default 1)");

static bool s8003_pm_uncached = true;
module_param_named(apple_pm_uncached, s8003_pm_uncached, bool, 0444);
MODULE_PARM_DESC(apple_pm_uncached, "A9: PM sets in the firmware's uncached window, as Apple's (default 1)");

static bool s8003_touch_on = true;
module_param_named(apple_touch, s8003_touch_on, bool, 0644);
MODULE_PARM_DESC(apple_touch, "A9: read the firmware's memory every millisecond while it works (default 1)");

static u32 pvr_apple_s8003_engine_done(struct pvr_apple *apple, enum pvr_apple_engine engine);

/*
Expand Down Expand Up @@ -1605,7 +1584,7 @@ static void pvr_apple_s8003_events(struct pvr_apple *apple)
if (!READ_ONCE(apple->booted) || !s->shared.map)
return;
/* An eighth early, so that a check every S8003_TOUCH_US always touches */
if (s->v->touch && READ_ONCE(s8003_touch_on) &&
if (s->v->touch &&
ktime_us_delta(now, READ_ONCE(s->touched)) + S8003_TOUCH_US / 8 >= S8003_TOUCH_US) {
WRITE_ONCE(s->touched, now);
s8003_touch(s);
Expand Down Expand Up @@ -2454,6 +2433,19 @@ static struct s8003_job_slot s8003_slot_of(u32 seq, bool frag)
};
}

/*
* Submissions wait for last_seq - 1 before reusing either of the two records:
* the prior occupant of s8003_slot_of(last_seq + 1) is last_seq - 1. Preserve
* its result before fill_ta/fill_3d clears W. Failed fills do not count it.
*/
static u64 s8003_job_ticks(u8 *p, u32 seq, bool frag)
{
struct s8003_job_slot at = s8003_slot_of(seq, frag);

dma_rmb();
return get_unaligned_le64(p + at.w + (frag ? 0x8ac : 0x550));
}

/* What the 3D engine is waited for between a fragment job's start and finish */
static const u32 s8003_3d_wait[] = {
0x201, 0x138204, 0x10, 0x8388204, 0, 0x104000a, 0x1f,
Expand Down Expand Up @@ -2482,8 +2474,9 @@ static u8 *useq_put(u8 *out, const u32 *words, unsigned int n)
* rebuilt only on a generation change (0xfffffff006cb1940). A fragment job
* waits at @wait_stamp for @wait_seq, its geometry job's stamp.
*/
static void s8003_job_write(u8 *p, u32 addr, u32 global, u32 pm, u32 pm_id, u32 slot, bool frag,
u32 seq, u32 wait_stamp, u32 wait_seq, bool pm_record)
static void s8003_job_write(struct pvr_apple_s8003 *s, u8 *p, u32 addr, u32 global, u32 pm,
u32 pm_id, u32 slot, bool frag, u32 seq, u32 wait_stamp, u32 wait_seq,
bool pm_record, u64 gpu_ticks)
{
struct s8003_job_slot at = s8003_slot_of(seq, frag);
u32 w = addr + at.w, record = pm + S8003_PM_RECORD;
Expand All @@ -2496,6 +2489,13 @@ static void s8003_job_write(u8 *p, u32 addr, u32 global, u32 pm, u32 pm_id, u32
const u32 time_end[] = { 0x18, result, time, time + 4, seq };
const u32 wait_ta = 0x801, end = 0x40000017;

if (gpu_ticks) {
s->gpu_ticks[frag] += gpu_ticks;
s->gpu_jobs[frag]++;
} else {
s->gpu_zero[frag]++;
}

put32(work + (frag ? 0x8ac : 0x550), 0);
put32(work + (frag ? 0x8b0 : 0x554), 0);
put32(work + (frag ? 0x8b4 : 0x558), times);
Expand Down Expand Up @@ -2728,11 +2728,6 @@ static bool pvr_apple_s8003_vm_evictable(struct pvr_apple *apple,
return true;
}

static bool s8003_pm_shared_param = true;
module_param_named(apple_pm_shared, s8003_pm_shared_param, bool, 0644);
MODULE_PARM_DESC(apple_pm_shared,
"Apple A9: one PM pool per set index for all VMs (default 1); read when a set first gets a pool");

static void s8003_debugfs_show(struct pvr_apple *apple, struct seq_file *m)
{
struct pvr_apple_s8003 *s = apple->chip_data;
Expand All @@ -2743,10 +2738,15 @@ static void s8003_debugfs_show(struct pvr_apple *apple, struct seq_file *m)
if (!s)
return;

seq_printf(m, "gpu_ns geometry %llu fragment %llu jobs %llu %llu zero %llu %llu\n",
mul_u64_u32_div(READ_ONCE(s->gpu_ticks[0]), 125, 3),
mul_u64_u32_div(READ_ONCE(s->gpu_ticks[1]), 125, 3),
READ_ONCE(s->gpu_jobs[0]), READ_ONCE(s->gpu_jobs[1]),
READ_ONCE(s->gpu_zero[0]), READ_ONCE(s->gpu_zero[1]));
mutex_lock(&apple->submit_lock);
seq_printf(m, "a9 pm pools bytes %lld shared %d (pools %u x %u blocks) guard_waits %lld\n",
atomic64_read(&s->pm_pool_bytes), READ_ONCE(s8003_pm_shared_param),
READ_ONCE(s->pm_shared_count), S8003_PM_BLOCKS_MAX,
seq_printf(m, "a9 pm pools bytes %lld (shared pools %u x %u blocks) guard_waits %lld\n",
atomic64_read(&s->pm_pool_bytes), READ_ONCE(s->pm_shared_count),
S8003_PM_BLOCKS_MAX,
atomic64_read(&s->pm_guard_waits));
xa_for_each(&s->vms, index, vm) {
for (i = 0; i < ARRAY_SIZE(vm->pm); i++) {
Expand Down Expand Up @@ -2879,7 +2879,7 @@ static int s8003_prepare_job(struct pvr_apple *apple, struct pvr_job *job)
mutex_unlock(&apple->submit_lock);
}
mutex_lock(&apple->submit_lock);
if (!pm->pool && !pm->next_pool && READ_ONCE(s8003_pm_shared_param)) {
if (!pm->pool && !pm->next_pool) {
mutex_unlock(&apple->submit_lock);
err = s8003_pm_shared_get(apple, i);
if (err)
Expand Down Expand Up @@ -2960,6 +2960,7 @@ static int s8003_submit_geom(struct pvr_apple *apple, struct s8003_vm *vm, struc
u8 *p = s8003_channel(s, APPLE_ENGINE_GEOM);
struct s8003_pm *pm = NULL;
struct s8003_rt rt;
u64 gpu_ticks;
u32 seq, blocks;
bool pm_record;
unsigned int i;
Expand All @@ -2986,6 +2987,13 @@ static int s8003_submit_geom(struct pvr_apple *apple, struct s8003_vm *vm, struc
return s8003_submit_error(apple, vm, "geometry", -EBUSY, S8003_REFUSED_PM,
"no PM set");

/*
* The VMs' sets of one index share a pool: wait until the scene of the
* pool's previous user is done. This relies on a scene's geometry and
* fragment jobs being armed in one submission: the job dependencies then
* order this geometry job after the previous VM's fragment job, so a
* scene with td_seq still 0 has no fragment job that could come later.
*/
if (pm->shared) {
unsigned int idx = pm - vm->pm;
const struct s8003_pm *user = s->pm_shared[idx].user;
Expand Down Expand Up @@ -3039,12 +3047,13 @@ static int s8003_submit_geom(struct pvr_apple *apple, struct s8003_vm *vm, struc
if ((s32)(done - pm->rec_seq) < 0)
pm_record = true;
}
gpu_ticks = s8003_job_ticks(p, seq, false);
s8003_fill_ta(p + s8003_slot_of(seq, false).w, job->cmd, job->hwrt, &rt);
s8003_job_write(p, s8003_channel_addr(s, APPLE_ENGINE_GEOM),
s8003_job_write(s, p, s8003_channel_addr(s, APPLE_ENGINE_GEOM),
s8003_object_addr(&s->layout, S8003_CHANNEL),
s8003_meta_addr(s8003_pm_set_va(s, pm, 0)), pm->set + 1, vm->slot[0], false,
seq, s8003_channel_addr(s, APPLE_ENGINE_GEOM) + S8003_CH_STAMP + 4,
pm_record ? 0 : pm->rec_seq, pm_record);
pm_record ? 0 : pm->rec_seq, pm_record, gpu_ticks);
if (pm_record)
pm->rec_seq = seq;
pm->hwrt = job->hwrt;
Expand Down Expand Up @@ -3073,6 +3082,7 @@ static int s8003_submit_frag(struct pvr_apple *apple, struct s8003_vm *vm, struc
struct s8003_pm *pm = NULL;
struct s8003_rt rt;
unsigned int i;
u64 gpu_ticks;
u32 seq;
int err;

Expand All @@ -3094,14 +3104,16 @@ static int s8003_submit_frag(struct pvr_apple *apple, struct s8003_vm *vm, struc
"record slot wait");

seq = apple->frag_seq + 1;
gpu_ticks = s8003_job_ticks(p, seq, true);
err = s8003_fill_3d(p + s8003_slot_of(seq, true).w, job->cmd, job->hwrt, &rt);
if (err)
return s8003_submit_error(apple, vm, "fragment", err, S8003_REFUSED_FILL,
"3D record fill");
s8003_job_write(p, s8003_channel_addr(s, APPLE_ENGINE_FRAG),
s8003_job_write(s, p, s8003_channel_addr(s, APPLE_ENGINE_FRAG),
s8003_object_addr(&s->layout, S8003_CHANNEL + 1),
s8003_meta_addr(s8003_pm_set_va(s, pm, 0)), pm->set + 1, vm->slot[1], true, seq,
s8003_channel_addr(s, APPLE_ENGINE_GEOM) + S8003_CH_STAMP + 4, pm->ta_seq, true);
s8003_channel_addr(s, APPLE_ENGINE_GEOM) + S8003_CH_STAMP + 4, pm->ta_seq, true,
gpu_ticks);
pm->td_seq = seq;
WRITE_ONCE(s->set_frag[pm->set], seq);
apple->frag_seq = seq;
Expand Down Expand Up @@ -3388,9 +3400,17 @@ static int pvr_apple_s8003_init(struct pvr_apple *apple)
apple->chip_data = s;
s->apple = apple;
s->v = v;
s->ch_root = v->channels_root || (v->root_channel[0] && s8003_ch_uncached);
s->pm_sets_va = v->root_channel[0] && s8003_pm_uncached ? S8003_PM_SETS_ROOT_VA :
S8003_PM_SETS_VA;
/*
* Where the firmware reaches the A9's job records and PM sets. Apple's
* kext gives the firmware every per-job object through META's uncached
* window: on the iPad 5 under iOS, the channel states are at 0x43200000,
* a TA's W at 0x43230e80, its PM record at 0x43469880, the stamps at
* 0x43438000. The A8 and A7 keep their channels there too. Through the
* cached window a job's finish that comes within ~300 us of a doorbell
* waits for the firmware ~200 us longer than iOS's does.
*/
s->ch_root = v->channels_root || v->root_channel[0];
s->pm_sets_va = v->root_channel[0] ? S8003_PM_SETS_ROOT_VA : S8003_PM_SETS_VA;
INIT_DELAYED_WORK(&s->drain_work, s8003_drain_work);
spin_lock_init(&s->tag_lock);
spin_lock_init(&s->set_lock);
Expand Down
Loading