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
72 changes: 58 additions & 14 deletions drivers/gpu/drm/imagination/pvr_apple_s8003.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,14 @@
#define S8003_PIO_VA 0xe1c4200000ull

#define S8003_IMAGE_SIZE 0x30000
#define S8003_ROOT_SIZE 0x8000
/*
* 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
* memory.
*/
#define S8003_ROOT_SIZE 0x14000
#define S8003_ROOT_OBJECTS_END 0x8000
#define S8003_ROOT_TA_CHANNEL S8003_ROOT_OBJECTS_END
#define S8003_SHARED_SIZE 0x60000
#define S8003_PIO_FENDER 0x0000 /* offsets from S8003_PIO_VA */
#define S8003_PIO_AIC 0x8000
Expand All @@ -136,6 +143,8 @@
#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 */
#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 */
#define S8003_PM_BLOCKS_MAX 128u /* what one page of free list holds */
Expand Down Expand Up @@ -305,6 +314,7 @@ struct s8003_variant {
unsigned int vm_slots; /* a VM's slots: 2 (geometry and compute, fragment) or 1 */
u32 channel[3]; /* the engines' channels: TA, 3D, CU offsets */
bool channels_root; /* the channels are in the root memory, not the shared */
u32 root_channel[3]; /* if set, the channels' offsets in the root (the Apple layout) */
u32 ldr_conf_count; /* the image's register writes, if a fixed number */
bool touch; /* the firmware needs s8003_touch() */
const struct pvr_meta_ldr_target *ldr;
Expand Down Expand Up @@ -465,6 +475,8 @@ struct t7000_phases {
struct pvr_apple_s8003 {
struct pvr_apple *apple;
const struct s8003_variant *v;
bool ch_root; /* the channels are in the root memory: META's uncached window */
u64 pm_sets_va; /* where the PM sets are mapped, in every VM */
struct delayed_work drain_work; /* reads the rings while the firmware runs */
struct mutex event_lock; /* the rings the firmware posts to */
ktime_t touched; /* s8003_touch() */
Expand Down Expand Up @@ -1041,7 +1053,7 @@ static int s8003_map(struct pvr_apple *apple)
err = s8003_mem_init(apple, &s->shared, S8003_SHARED_VA, S8003_SHARED_SIZE,
DRM_PVR_BO_PM_FW_PROTECT | PVR_BO_DEVICE_CACHE_COHERENT);
if (!err)
err = s8003_mem_init(apple, &s->pmsets, S8003_PM_SETS_VA,
err = s8003_mem_init(apple, &s->pmsets, s->pm_sets_va,
S8003_PM_SETS * S8003_PM_SET_SIZE,
DRM_PVR_BO_PM_FW_PROTECT | PVR_BO_DEVICE_CACHE_COHERENT);
if (!err)
Expand Down Expand Up @@ -1422,17 +1434,19 @@ static u32 s8003_engine(enum pvr_apple_engine engine)

static u32 s8003_channel_offset(const struct pvr_apple_s8003 *s, enum pvr_apple_engine engine)
{
return s->v->channel[s8003_engine(engine)];
u32 e = s8003_engine(engine);

return s->ch_root && !s->v->channels_root ? s->v->root_channel[e] : s->v->channel[e];
}

static u8 *s8003_channel(struct pvr_apple_s8003 *s, enum pvr_apple_engine engine)
{
return (s->v->channels_root ? s->root.map : s->shared.map) + s8003_channel_offset(s, engine);
return (s->ch_root ? s->root.map : s->shared.map) + s8003_channel_offset(s, engine);
}

static u32 s8003_channel_addr(const struct pvr_apple_s8003 *s, enum pvr_apple_engine engine)
{
return s8003_meta_addr((s->v->channels_root ? S8003_ROOT_VA : S8003_SHARED_VA) +
return s8003_meta_addr((s->ch_root ? S8003_ROOT_VA : S8003_SHARED_VA) +
s8003_channel_offset(s, engine));
}

Expand Down Expand Up @@ -1468,6 +1482,30 @@ 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 @@ -1543,7 +1581,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 &&
if (s->v->touch && READ_ONCE(s8003_touch_on) &&
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 @@ -1837,7 +1875,7 @@ static int s8003_vm_map(struct pvr_apple *apple, struct pvr_vm_context *vm_ctx)

if (!s->pmsets.obj)
return -ENODEV;
return pvr_vm_map_reserved(vm_ctx, s->pmsets.obj, S8003_PM_SETS_VA, s->pmsets.size);
return pvr_vm_map_reserved(vm_ctx, s->pmsets.obj, s->pm_sets_va, s->pmsets.size);
}

static int pvr_apple_s8003_vm_init(struct pvr_apple *apple, struct pvr_vm_context *vm_ctx)
Expand Down Expand Up @@ -1995,9 +2033,9 @@ static void s8003_vm_put(struct pvr_apple *apple, struct s8003_vm *vm)
s8003_pm_put(apple->chip_data, &vm->pm[e]);
}

static u64 s8003_pm_set_va(const struct s8003_pm *pm, u32 page)
static u64 s8003_pm_set_va(const struct pvr_apple_s8003 *s, const struct s8003_pm *pm, u32 page)
{
return S8003_PM_SETS_VA + pm->set * S8003_PM_SET_SIZE + page * PVR_DEVICE_PAGE_SIZE;
return s->pm_sets_va + pm->set * S8003_PM_SET_SIZE + page * PVR_DEVICE_PAGE_SIZE;
}

static u64 s8003_pm_aux_va(const struct s8003_pm *pm)
Expand Down Expand Up @@ -2052,7 +2090,7 @@ static int s8003_pm_build(struct pvr_apple *apple, struct s8003_vm *vm, struct s
control = s->pmsets.map + pm->set * S8003_PM_SET_SIZE;
list = control + PVR_DEVICE_PAGE_SIZE;
free = list + PVR_DEVICE_PAGE_SIZE;
list_va = s8003_pm_set_va(pm, 1);
list_va = s8003_pm_set_va(s, pm, 1);
aux_va = s8003_pm_aux_va(pm);
memset(control, 0, S8003_PM_SET_SIZE);
for (j = 0; j < pm->blocks; j++) {
Expand All @@ -2076,7 +2114,7 @@ static int s8003_pm_build(struct pvr_apple *apple, struct s8003_vm *vm, struct s
}
put32(list + 0x60, 1);
put32(control + 0x10, previous);
put64(control + 0x14, s8003_pm_set_va(pm, 2));
put64(control + 0x14, s8003_pm_set_va(s, pm, 2));
put32(control + 0x1c, pm->blocks * 32 * 4);
put32(control + 0x20, pm->blocks * 32);
put32(control + 0x24, pm->blocks * 32 - 1);
Expand Down Expand Up @@ -2837,7 +2875,7 @@ static int s8003_submit_geom(struct pvr_apple *apple, struct s8003_vm *vm, struc
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_object_addr(&s->layout, S8003_CHANNEL),
s8003_meta_addr(s8003_pm_set_va(pm, 0)), pm->set + 1, vm->slot[0], false,
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);
if (pm_record)
Expand Down Expand Up @@ -2895,7 +2933,7 @@ static int s8003_submit_frag(struct pvr_apple *apple, struct s8003_vm *vm, struc
"3D record fill");
s8003_job_write(p, s8003_channel_addr(s, APPLE_ENGINE_FRAG),
s8003_object_addr(&s->layout, S8003_CHANNEL + 1),
s8003_meta_addr(s8003_pm_set_va(pm, 0)), pm->set + 1, vm->slot[1], true, seq,
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);
pm->td_seq = seq;
WRITE_ONCE(s->set_frag[pm->set], seq);
Expand Down Expand Up @@ -3183,6 +3221,9 @@ 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;
INIT_DELAYED_WORK(&s->drain_work, s8003_drain_work);
spin_lock_init(&s->tag_lock);
spin_lock_init(&s->set_lock);
Expand Down Expand Up @@ -6448,7 +6489,7 @@ static const struct s8003_variant s8003_variant_a9 = {
.image_size = S8003_IMAGE_SIZE,
.root_size = S8003_ROOT_SIZE,
.shared_size = S8003_SHARED_SIZE,
.root_objects_end = S8003_ROOT_SIZE,
.root_objects_end = S8003_ROOT_OBJECTS_END,
.shared_objects_end = S8003_TA_CHANNEL,
.objects = s8003_objects_a9,
.nr_objects = ARRAY_SIZE(s8003_objects_a9),
Expand All @@ -6457,6 +6498,9 @@ static const struct s8003_variant s8003_variant_a9 = {
.slot_first = S8003_SLOT_FIRST,
.vm_slots = 2,
.channel = { S8003_TA_CHANNEL, S8003_3D_CHANNEL, S8003_CU_CHANNEL },
.root_channel = { S8003_ROOT_TA_CHANNEL,
S8003_ROOT_TA_CHANNEL + S8003_3D_CHANNEL - S8003_TA_CHANNEL,
S8003_ROOT_TA_CHANNEL + S8003_CU_CHANNEL - S8003_TA_CHANNEL },
.touch = true,
.ldr = &s8003_ldr_target,
.image_configure = s8003_image_configure,
Expand Down
Loading