drivers/tee/optee/call.c
Source file repositories/reference/linux-study-clean/drivers/tee/optee/call.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/tee/optee/call.c- Extension
.c- Size
- 17374 bytes
- Lines
- 673
- Domain
- Driver Families
- Bucket
- drivers/tee
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.hlinux/err.hlinux/errno.hlinux/mm.hlinux/slab.hlinux/tee_core.hlinux/types.hoptee_private.h
Detected Declarations
struct optee_shm_arg_entryfunction optee_cq_initfunction optee_cq_wait_initfunction optee_cq_wait_for_completionfunction optee_cq_complete_onefunction list_for_each_entryfunction optee_cq_wait_finalfunction optee_cq_incr_sys_thread_countfunction optee_cq_decr_sys_thread_countfunction optee_shm_arg_cache_initfunction optee_shm_arg_cache_uninitfunction optee_msg_arg_sizefunction optee_get_msg_argfunction optee_free_msg_argfunction optee_open_sessionfunction optee_system_sessionfunction optee_cq_incr_sys_thread_countfunction optee_close_session_helperfunction optee_close_sessionfunction optee_invoke_funcfunction optee_cancel_reqfunction is_normal_memoryfunction __check_mem_typefunction for_each_vma_rangefunction optee_check_mem_typefunction simple_call_with_argfunction optee_do_bottom_halffunction optee_stop_async_notif
Annotated Snippet
struct optee_shm_arg_entry {
struct list_head list_node;
struct tee_shm *shm;
DECLARE_BITMAP(map, MAX_ARG_COUNT_PER_ENTRY);
};
void optee_cq_init(struct optee_call_queue *cq, int thread_count)
{
mutex_init(&cq->mutex);
INIT_LIST_HEAD(&cq->waiters);
/*
* If cq->total_thread_count is 0 then we're not trying to keep
* track of how many free threads we have, instead we're relying on
* the secure world to tell us when we're out of thread and have to
* wait for another thread to become available.
*/
cq->total_thread_count = thread_count;
cq->free_thread_count = thread_count;
}
void optee_cq_wait_init(struct optee_call_queue *cq,
struct optee_call_waiter *w, bool sys_thread)
{
unsigned int free_thread_threshold;
bool need_wait = false;
memset(w, 0, sizeof(*w));
/*
* We're preparing to make a call to secure world. In case we can't
* allocate a thread in secure world we'll end up waiting in
* optee_cq_wait_for_completion().
*
* Normally if there's no contention in secure world the call will
* complete and we can cleanup directly with optee_cq_wait_final().
*/
mutex_lock(&cq->mutex);
/*
* We add ourselves to the queue, but we don't wait. This
* guarantees that we don't lose a completion if secure world
* returns busy and another thread just exited and try to complete
* someone.
*/
init_completion(&w->c);
list_add_tail(&w->list_node, &cq->waiters);
w->sys_thread = sys_thread;
if (cq->total_thread_count) {
if (sys_thread || !cq->sys_thread_req_count)
free_thread_threshold = 0;
else
free_thread_threshold = 1;
if (cq->free_thread_count > free_thread_threshold)
cq->free_thread_count--;
else
need_wait = true;
}
mutex_unlock(&cq->mutex);
while (need_wait) {
optee_cq_wait_for_completion(cq, w);
mutex_lock(&cq->mutex);
if (sys_thread || !cq->sys_thread_req_count)
free_thread_threshold = 0;
else
free_thread_threshold = 1;
if (cq->free_thread_count > free_thread_threshold) {
cq->free_thread_count--;
need_wait = false;
}
mutex_unlock(&cq->mutex);
}
}
void optee_cq_wait_for_completion(struct optee_call_queue *cq,
struct optee_call_waiter *w)
{
wait_for_completion(&w->c);
mutex_lock(&cq->mutex);
/* Move to end of list to get out of the way for other waiters */
list_del(&w->list_node);
Annotation
- Immediate include surface: `linux/device.h`, `linux/err.h`, `linux/errno.h`, `linux/mm.h`, `linux/slab.h`, `linux/tee_core.h`, `linux/types.h`, `optee_private.h`.
- Detected declarations: `struct optee_shm_arg_entry`, `function optee_cq_init`, `function optee_cq_wait_init`, `function optee_cq_wait_for_completion`, `function optee_cq_complete_one`, `function list_for_each_entry`, `function optee_cq_wait_final`, `function optee_cq_incr_sys_thread_count`, `function optee_cq_decr_sys_thread_count`, `function optee_shm_arg_cache_init`.
- Atlas domain: Driver Families / drivers/tee.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.