Skip to content
Closed
Show file tree
Hide file tree
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
95 changes: 95 additions & 0 deletions drivers/media/platform/apple/prores/apple-prores-desc.c
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,101 @@ u32 apr_ring_advance(u32 ptr, u32 bytes, u32 ring_bytes)
}
EXPORT_SYMBOL_IF_KUNIT(apr_ring_advance);

/*
* Ring pointers carry a generation bit above the offset, so a pointer names
* one of 2 * ring_bytes positions and a full ring differs from an empty one.
*/
static u32 apr_ring_pos(u32 ptr, u32 ring_bytes)
{
return (ptr & APR_RING_OFFSET_MASK) +
(ptr & APR_RING_GENERATION ? ring_bytes : 0);
}

/* Bytes from @from forward to @to. */
u32 apr_ring_distance(u32 from, u32 to, u32 ring_bytes)
{
u32 span = 2 * ring_bytes;

return (apr_ring_pos(to, ring_bytes) + span -
apr_ring_pos(from, ring_bytes)) % span;
}
EXPORT_SYMBOL_IF_KUNIT(apr_ring_distance);

/* Bytes the producer may still write; @done is what the engine consumed. */
u32 apr_ring_free(u32 done, u32 head, u32 ring_bytes)
{
u32 used = apr_ring_distance(done, head, ring_bytes);

return used < ring_bytes ? ring_bytes - used : 0;
}
EXPORT_SYMBOL_IF_KUNIT(apr_ring_free);

/*
* Has the consumer @tail moved past the descriptor that ends at @end? @done
* is the start of the oldest descriptor still owned by the engine.
*/
bool apr_ring_passed(u32 done, u32 end, u32 tail, u32 ring_bytes)
{
return apr_ring_distance(done, end, ring_bytes) <=
apr_ring_distance(done, tail, ring_bytes);
}
EXPORT_SYMBOL_IF_KUNIT(apr_ring_passed);

/* A tail the engine reports must lie between what it consumed and the head. */
bool apr_ring_tail_valid(u32 done, u32 tail, u32 head, u32 ring_bytes)
{
return !(tail & ~APR_RING_PTR_MASK) &&
(tail & APR_RING_OFFSET_MASK) < ring_bytes &&
apr_ring_distance(done, tail, ring_bytes) <=
apr_ring_distance(done, head, ring_bytes);
}
EXPORT_SYMBOL_IF_KUNIT(apr_ring_tail_valid);

/*
* Decode job ids are device-wide and never 0: the engine reports the id of
* the last job it finished, and that report reads 0 after a reset, before
* any job has run.
*/
u16 apr_next_job_id(u16 id)
{
return id == U16_MAX ? 1 : id + 1;
}
EXPORT_SYMBOL_IF_KUNIT(apr_next_job_id);

/*
* Has the engine finished job @id, given the last finished id @done_id?
* Jobs finish in ring order and far fewer than 2^15 are ever outstanding,
* so the signed distance decides, across the wrap as well.
*/
bool apr_job_id_done(u16 done_id, u16 id)
{
return (u16)(done_id - id) < 0x8000;
}
EXPORT_SYMBOL_IF_KUNIT(apr_job_id_done);

/*
* Classify @done_id, the last finished id ST1 reports, against @next_id, the
* id the next decode job gets. 0 is what ST1 reads before any job finished
* since the reset. Ids from @next_id on, half the id space, are not issued
* yet; the other half are issued ids, finished or still in the ring.
*/
enum apr_done_id apr_job_id_check(u16 done_id, u16 next_id)
{
if (!done_id)
return APR_DONE_ID_NONE;
if (apr_job_id_done(done_id, next_id))
return APR_DONE_ID_FUTURE;
return APR_DONE_ID_ISSUED;
}
EXPORT_SYMBOL_IF_KUNIT(apr_job_id_check);

/* No further job may enter the ring with @jobs in it, @encodes of them encodes. */
bool apr_jobs_full(unsigned int jobs, unsigned int encodes)
{
return jobs >= APR_MAX_INFLIGHT || encodes >= APR_ENCODE_MAX_INFLIGHT;
}
EXPORT_SYMBOL_IF_KUNIT(apr_jobs_full);

void apr_ring_write(u8 *ring, u32 ring_bytes, u32 ptr, const u8 *desc,
u32 desc_bytes)
{
Expand Down
Loading