/* * push_buffer * * The push buffer is a circular array of words to be fetched by command DMA. * Note that it works slightly differently to the sync queue; fence == pos * means that the push buffer is full, not empty.
*/
/* * Typically the commands written into the push buffer are a pair of words. We * use slots to represent each of these pairs and to simplify things. Note the * strange number of slots allocated here. 512 slots will fit exactly within a * single memory page. We also need one additional word at the end of the push * buffer for the RESTART opcode that will instruct the CDMA to jump back to * the beginning of the push buffer. With 512 slots, this means that we'll use * 2 memory pages and waste 4092 bytes of the second page that will never be * used.
*/ #define HOST1X_PUSHBUFFER_SLOTS 511
/* * Push two words to the push buffer * Caller must ensure push buffer is not full
*/ staticvoid host1x_pushbuffer_push(struct push_buffer *pb, u32 op1, u32 op2)
{
u32 *p = (u32 *)((void *)pb->mapped + pb->pos);
/* * Pop a number of two word slots from the push buffer * Caller must ensure push buffer is not empty
*/ staticvoid host1x_pushbuffer_pop(struct push_buffer *pb, unsignedint slots)
{ /* Advance the next write position */
pb->fence += slots * 8;
if (pb->fence >= pb->size)
pb->fence -= pb->size;
}
/* * Return the number of two word slots free in the push buffer
*/ static u32 host1x_pushbuffer_space(struct push_buffer *pb)
{ unsignedint fence = pb->fence;
if (pb->fence < pb->pos)
fence += pb->size;
return (fence - pb->pos) / 8;
}
/* * Sleep (if necessary) until the requested event happens * - CDMA_EVENT_SYNC_QUEUE_EMPTY : sync queue is completely empty. * - Returns 1 * - CDMA_EVENT_PUSH_BUFFER_SPACE : there is space in the push buffer * - Return the amount of space (> 0) * Must be called with the cdma lock held.
*/ unsignedint host1x_cdma_wait_locked(struct host1x_cdma *cdma, enum cdma_event event)
{ for (;;) { struct push_buffer *pb = &cdma->push_buffer; unsignedint space;
switch (event) { case CDMA_EVENT_SYNC_QUEUE_EMPTY:
space = list_empty(&cdma->sync_queue) ? 1 : 0; break;
case CDMA_EVENT_PUSH_BUFFER_SPACE:
space = host1x_pushbuffer_space(pb); break;
/* * Sleep (if necessary) until the push buffer has enough free space. * * Must be called with the cdma lock held.
*/ staticint host1x_cdma_wait_pushbuffer_space(struct host1x *host1x, struct host1x_cdma *cdma, unsignedint needed)
{ while (true) { struct push_buffer *pb = &cdma->push_buffer; unsignedint space;
space = host1x_pushbuffer_space(pb); if (space >= needed) break;
return 0;
} /* * Start timer that tracks the time spent by the job. * Must be called with the cdma lock held.
*/ staticvoid cdma_start_timer_locked(struct host1x_cdma *cdma, struct host1x_job *job)
{ if (cdma->timeout.client) { /* timer already started */ return;
}
/* * Stop timer when a buffer submission completes. * Must be called with the cdma lock held.
*/ staticvoid stop_cdma_timer_locked(struct host1x_cdma *cdma)
{
cancel_delayed_work(&cdma->timeout.wq);
cdma->timeout.client = NULL;
}
/* * For all sync queue entries that have already finished according to the * current sync point registers: * - unpin & unref their mems * - pop their push buffer slots * - remove them from the sync queue * This is normally called from the host code's worker thread, but can be * called manually if necessary. * Must be called with the cdma lock held.
*/ staticvoid update_cdma_locked(struct host1x_cdma *cdma)
{ bool signal = false; struct host1x_job *job, *n;
/* * Walk the sync queue, reading the sync point registers as necessary, * to consume as many sync queue entries as possible without blocking
*/
list_for_each_entry_safe(job, n, &cdma->sync_queue, list) { struct host1x_syncpt *sp = job->syncpt;
/* Check whether this syncpt has completed, and bail if not */ if (!host1x_syncpt_is_expired(sp, job->syncpt_end) &&
!job->cancelled) { /* Start timer on next pending syncpt */ if (job->timeout)
cdma_start_timer_locked(cdma, job);
break;
}
/* Cancel timeout, when a buffer completes */ if (cdma->timeout.client)
stop_cdma_timer_locked(cdma);
/* Unpin the memory */
host1x_job_unpin(job);
/* Pop push buffer slots */ if (job->num_slots) { struct push_buffer *pb = &cdma->push_buffer;
host1x_pushbuffer_pop(pb, job->num_slots);
if (cdma->event == CDMA_EVENT_PUSH_BUFFER_SPACE)
signal = true;
}
list_del(&job->list);
host1x_job_put(job);
}
if (cdma->event == CDMA_EVENT_SYNC_QUEUE_EMPTY &&
list_empty(&cdma->sync_queue))
signal = true;
if (signal) {
cdma->event = CDMA_EVENT_NONE;
complete(&cdma->complete);
}
}
/* * Move the sync_queue read pointer to the first entry that hasn't * completed based on the current HW syncpt value. It's likely there * won't be any (i.e. we're still at the head), but covers the case * where a syncpt incr happens just prior/during the teardown.
*/
dev_dbg(dev, "%s: skip completed buffers still in sync_queue\n",
__func__);
list_for_each_entry(job, &cdma->sync_queue, list) { if (syncpt_val < job->syncpt_end) {
if (!list_is_last(&job->list, &cdma->sync_queue))
next_job = list_next_entry(job, list);
goto syncpt_incr;
}
host1x_job_dump(dev, job);
}
/* all jobs have been completed */
job = NULL;
syncpt_incr:
/* * Increment with CPU the remaining syncpts of a partially executed job. * * CDMA will continue execution starting with the next job or will get * into idle state.
*/ if (next_job)
restart_addr = next_job->first_get; else
restart_addr = cdma->last_pos;
if (!job) goto resume;
/* do CPU increments for the remaining syncpts */ if (job->syncpt_recovery) {
dev_dbg(dev, "%s: perform CPU incr on pending buffers\n",
__func__);
/* won't need a timeout when replayed */
job->timeout = 0;
for (i = 0; i < job->num_slots; i++) { unsignedint slot = (job->first_get/8 + i) %
HOST1X_PUSHBUFFER_SLOTS;
u32 *mapped = cdma->push_buffer.mapped;
/* * Overwrite opcodes with 0 word writes * to offset 0xbad. This does nothing but * has a easily detected signature in debug * traces. * * On systems with MLOCK enforcement enabled, * the above 0 word writes would fall foul of * the enforcement. As such, in the first slot * put a RESTART_W opcode to the beginning * of the next job. We don't use this for older * chips since those only support the RESTART * opcode with inconvenient alignment requirements.
*/ if (i == 0 && host1x->info->has_wide_gather) { unsignedint next_job = (job->first_get/8 + job->num_slots)
% HOST1X_PUSHBUFFER_SLOTS;
mapped[2*slot+0] = (0xd << 28) | (next_job * 2);
mapped[2*slot+1] = 0x0;
} else {
mapped[2*slot+0] = 0x1bad0000;
mapped[2*slot+1] = 0x1bad0000;
}
}
job->cancelled = true;
}
wmb();
update_cdma_locked(cdma);
}
resume: /* roll back DMAGET and start up channel again */
host1x_hw_cdma_resume(host1x, cdma, restart_addr);
}
/* * Begin a cdma submit
*/ int host1x_cdma_begin(struct host1x_cdma *cdma, struct host1x_job *job)
{ struct host1x *host1x = cdma_to_host1x(cdma);
mutex_lock(&cdma->lock);
/* * Check if syncpoint was locked due to previous job timeout. * This needs to be done within the cdma lock to avoid a race * with the timeout handler.
*/ if (job->syncpt->locked) {
mutex_unlock(&cdma->lock); return -EPERM;
}
if (job->timeout) { /* init state on first submit with timeout value */ if (!cdma->timeout.initialized) { int err;
/* * Push two words into a push buffer slot * Blocks as necessary if the push buffer is full.
*/ void host1x_cdma_push(struct host1x_cdma *cdma, u32 op1, u32 op2)
{ struct push_buffer *pb = &cdma->push_buffer;
u32 slots_free = cdma->slots_free;
if (host1x_debug_trace_cmdbuf)
trace_host1x_cdma_push(dev_name(cdma_to_channel(cdma)->dev),
op1, op2);
if (slots_free == 0)
slots_free = host1x_cdma_wait_locked(cdma,
CDMA_EVENT_PUSH_BUFFER_SPACE);
/* * Push four words into two consecutive push buffer slots. Note that extra * care needs to be taken not to split the two slots across the end of the * push buffer. Otherwise the RESTART opcode at the end of the push buffer * that ensures processing will restart at the beginning will break up the * four words. * * Blocks as necessary if the push buffer is full.
*/ void host1x_cdma_push_wide(struct host1x_cdma *cdma, u32 op1, u32 op2,
u32 op3, u32 op4)
{ struct host1x_channel *channel = cdma_to_channel(cdma); struct host1x *host1x = cdma_to_host1x(cdma); struct push_buffer *pb = &cdma->push_buffer; unsignedint space, needed = 2, extra = 0;
if (host1x_debug_trace_cmdbuf)
trace_host1x_cdma_push_wide(dev_name(channel->dev), op1, op2,
op3, op4);
/* compute number of extra slots needed for padding */ if (pb->pos + 16 > pb->size) {
extra = (pb->size - pb->pos) / 8;
needed += extra;
}
host1x_cdma_wait_pushbuffer_space(host1x, cdma, needed);
space = host1x_pushbuffer_space(pb);
cdma->slots_free = space - needed;
cdma->slots_used += needed;
if (extra > 0) { /* * If there isn't enough space at the tail of the pushbuffer, * insert a RESTART(0) here to go back to the beginning. * The code above adjusted the indexes appropriately.
*/
host1x_pushbuffer_push(pb, (0x5 << 28), 0xdead0000);
}
/* * End a cdma submit * Kick off DMA, add job to the sync queue, and a number of slots to be freed * from the pushbuffer. The handles for a submit must all be pinned at the same * time, but they can be unpinned in smaller chunks.
*/ void host1x_cdma_end(struct host1x_cdma *cdma, struct host1x_job *job)
{ struct host1x *host1x = cdma_to_host1x(cdma); bool idle = list_empty(&cdma->sync_queue);
/* * Update cdma state according to current sync point values
*/ void host1x_cdma_update(struct host1x_cdma *cdma)
{
schedule_work(&cdma->update_work);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.