drivers/tee/optee/protmem.c
Source file repositories/reference/linux-study-clean/drivers/tee/optee/protmem.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/tee/optee/protmem.c- Extension
.c- Size
- 7788 bytes
- Lines
- 336
- 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/errno.hlinux/genalloc.hlinux/slab.hlinux/string.hlinux/tee_core.hlinux/types.hoptee_private.h
Detected Declarations
struct optee_protmem_dyn_poolfunction to_protmem_dyn_poolfunction init_dyn_protmemfunction get_dyn_protmemfunction release_dyn_protmemfunction put_dyn_protmemfunction protmem_pool_op_dyn_allocfunction protmem_pool_op_dyn_freefunction protmem_pool_op_dyn_update_shmfunction pool_op_dyn_destroy_poolfunction get_protmem_config
Annotated Snippet
struct optee_protmem_dyn_pool {
struct tee_protmem_pool pool;
struct gen_pool *gen_pool;
struct optee *optee;
size_t page_count;
u32 *mem_attrs;
u_int mem_attr_count;
refcount_t refcount;
u32 use_case;
struct tee_shm *protmem;
/* Protects when initializing and tearing down this struct */
struct mutex mutex;
};
static struct optee_protmem_dyn_pool *
to_protmem_dyn_pool(struct tee_protmem_pool *pool)
{
return container_of(pool, struct optee_protmem_dyn_pool, pool);
}
static int init_dyn_protmem(struct optee_protmem_dyn_pool *rp)
{
int rc;
rp->protmem = tee_shm_alloc_dma_mem(rp->optee->ctx, rp->page_count);
if (IS_ERR(rp->protmem)) {
rc = PTR_ERR(rp->protmem);
goto err_null_protmem;
}
/*
* TODO unmap the memory range since the physical memory will
* become inaccesible after the lend_protmem() call.
*
* If the platform supports a hypervisor at EL2, it will unmap the
* intermediate physical memory for us and stop cache pre-fetch of
* the memory.
*/
rc = rp->optee->ops->lend_protmem(rp->optee, rp->protmem,
rp->mem_attrs,
rp->mem_attr_count, rp->use_case);
if (rc)
goto err_put_shm;
rp->protmem->flags |= TEE_SHM_DYNAMIC;
rp->gen_pool = gen_pool_create(PAGE_SHIFT, -1);
if (!rp->gen_pool) {
rc = -ENOMEM;
goto err_reclaim;
}
rc = gen_pool_add(rp->gen_pool, rp->protmem->paddr,
rp->protmem->size, -1);
if (rc)
goto err_free_pool;
refcount_set(&rp->refcount, 1);
return 0;
err_free_pool:
gen_pool_destroy(rp->gen_pool);
rp->gen_pool = NULL;
err_reclaim:
rp->optee->ops->reclaim_protmem(rp->optee, rp->protmem);
err_put_shm:
tee_shm_put(rp->protmem);
err_null_protmem:
rp->protmem = NULL;
return rc;
}
static int get_dyn_protmem(struct optee_protmem_dyn_pool *rp)
{
int rc = 0;
if (!refcount_inc_not_zero(&rp->refcount)) {
mutex_lock(&rp->mutex);
if (rp->gen_pool) {
/*
* Another thread has already initialized the pool
* before us, or the pool was just about to be torn
* down. Either way we only need to increase the
* refcount and we're done.
*/
refcount_inc(&rp->refcount);
} else {
rc = init_dyn_protmem(rp);
}
mutex_unlock(&rp->mutex);
}
Annotation
- Immediate include surface: `linux/errno.h`, `linux/genalloc.h`, `linux/slab.h`, `linux/string.h`, `linux/tee_core.h`, `linux/types.h`, `optee_private.h`.
- Detected declarations: `struct optee_protmem_dyn_pool`, `function to_protmem_dyn_pool`, `function init_dyn_protmem`, `function get_dyn_protmem`, `function release_dyn_protmem`, `function put_dyn_protmem`, `function protmem_pool_op_dyn_alloc`, `function protmem_pool_op_dyn_free`, `function protmem_pool_op_dyn_update_shm`, `function pool_op_dyn_destroy_pool`.
- 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.