drivers/tee/tee_heap.c
Source file repositories/reference/linux-study-clean/drivers/tee/tee_heap.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/tee/tee_heap.c- Extension
.c- Size
- 10857 bytes
- Lines
- 501
- Domain
- Driver Families
- Bucket
- drivers/tee
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/dma-buf.hlinux/dma-heap.hlinux/genalloc.hlinux/module.hlinux/scatterlist.hlinux/slab.hlinux/tee_core.hlinux/xarray.htee_private.h
Detected Declarations
struct tee_dma_heapstruct tee_heap_bufferstruct tee_heap_attachmentstruct tee_protmem_static_poolfunction tee_heap_releasefunction put_tee_heapfunction get_tee_heapfunction copy_sg_tablefunction tee_heap_attachfunction tee_heap_detachfunction tee_heap_map_dma_buffunction tee_heap_unmap_dma_buffunction tee_heap_buf_freefunction alloc_dma_heapfunction tee_device_register_dma_heapfunction tee_device_put_all_dma_heapsfunction xa_for_eachfunction tee_heap_update_from_dma_buffunction tee_device_register_dma_heapfunction tee_device_put_all_dma_heapsfunction tee_heap_update_from_dma_buffunction to_protmem_static_poolfunction protmem_pool_op_static_allocfunction protmem_pool_op_static_freefunction protmem_pool_op_static_update_shmfunction protmem_pool_op_static_destroy_poolexport tee_device_register_dma_heapexport tee_device_put_all_dma_heapsexport tee_device_register_dma_heapexport tee_device_put_all_dma_heapsexport tee_protmem_static_pool_alloc
Annotated Snippet
struct tee_dma_heap {
struct dma_heap *heap;
enum tee_dma_heap_id id;
struct kref kref;
struct tee_protmem_pool *pool;
struct tee_device *teedev;
bool shutting_down;
/* Protects pool, teedev, and shutting_down above */
struct mutex mu;
};
struct tee_heap_buffer {
struct tee_dma_heap *heap;
size_t size;
size_t offs;
struct sg_table table;
};
struct tee_heap_attachment {
struct sg_table table;
struct device *dev;
};
struct tee_protmem_static_pool {
struct tee_protmem_pool pool;
struct gen_pool *gen_pool;
phys_addr_t pa_base;
};
#if IS_ENABLED(CONFIG_TEE_DMABUF_HEAPS)
static DEFINE_XARRAY_ALLOC(tee_dma_heap);
static void tee_heap_release(struct kref *kref)
{
struct tee_dma_heap *h = container_of(kref, struct tee_dma_heap, kref);
h->pool->ops->destroy_pool(h->pool);
tee_device_put(h->teedev);
h->pool = NULL;
h->teedev = NULL;
}
static void put_tee_heap(struct tee_dma_heap *h)
{
kref_put(&h->kref, tee_heap_release);
}
static void get_tee_heap(struct tee_dma_heap *h)
{
kref_get(&h->kref);
}
static int copy_sg_table(struct sg_table *dst, struct sg_table *src)
{
struct scatterlist *dst_sg;
struct scatterlist *src_sg;
int ret;
int i;
ret = sg_alloc_table(dst, src->orig_nents, GFP_KERNEL);
if (ret)
return ret;
dst_sg = dst->sgl;
for_each_sgtable_sg(src, src_sg, i) {
sg_set_page(dst_sg, sg_page(src_sg), src_sg->length,
src_sg->offset);
dst_sg = sg_next(dst_sg);
}
return 0;
}
static int tee_heap_attach(struct dma_buf *dmabuf,
struct dma_buf_attachment *attachment)
{
struct tee_heap_buffer *buf = dmabuf->priv;
struct tee_heap_attachment *a;
int ret;
a = kzalloc_obj(*a);
if (!a)
return -ENOMEM;
ret = copy_sg_table(&a->table, &buf->table);
if (ret) {
kfree(a);
return ret;
}
Annotation
- Immediate include surface: `linux/dma-buf.h`, `linux/dma-heap.h`, `linux/genalloc.h`, `linux/module.h`, `linux/scatterlist.h`, `linux/slab.h`, `linux/tee_core.h`, `linux/xarray.h`.
- Detected declarations: `struct tee_dma_heap`, `struct tee_heap_buffer`, `struct tee_heap_attachment`, `struct tee_protmem_static_pool`, `function tee_heap_release`, `function put_tee_heap`, `function get_tee_heap`, `function copy_sg_table`, `function tee_heap_attach`, `function tee_heap_detach`.
- Atlas domain: Driver Families / drivers/tee.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.