drivers/firmware/qcom/qcom_tzmem.c
Source file repositories/reference/linux-study-clean/drivers/firmware/qcom/qcom_tzmem.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/firmware/qcom/qcom_tzmem.c- Extension
.c- Size
- 12309 bytes
- Lines
- 524
- Domain
- Driver Families
- Bucket
- drivers/firmware
- 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/bug.hlinux/cleanup.hlinux/dma-mapping.hlinux/err.hlinux/firmware/qcom/qcom_tzmem.hlinux/genalloc.hlinux/gfp.hlinux/kernel.hlinux/list.hlinux/mm.hlinux/radix-tree.hlinux/slab.hlinux/spinlock.hlinux/types.hqcom_scm.hqcom_tzmem.hlinux/firmware/qcom/qcom_scm.hlinux/of.h
Detected Declarations
struct qcom_tzmem_areastruct qcom_tzmem_poolstruct qcom_tzmem_chunkfunction qcom_tzmem_initfunction qcom_tzmem_init_areafunction qcom_tzmem_cleanup_areafunction qcom_tzmem_initfunction qcom_tzmem_shm_bridge_createfunction qcom_tzmem_shm_bridge_deletefunction qcom_tzmem_init_areafunction qcom_tzmem_cleanup_areafunction qcom_tzmem_pool_add_memoryfunction qcom_tzmem_pool_newfunction qcom_tzmem_pool_freefunction scoped_guardfunction list_for_each_entry_safefunction devm_qcom_tzmem_pool_freefunction devm_qcom_tzmem_pool_newfunction qcom_tzmem_try_grow_poolfunction qcom_tzmem_allocfunction scoped_guardfunction qcom_tzmem_freefunction qcom_tzmem_to_physfunction radix_tree_for_each_slotfunction qcom_tzmem_enableexport qcom_tzmem_shm_bridge_createexport qcom_tzmem_shm_bridge_deleteexport qcom_tzmem_pool_newexport qcom_tzmem_pool_freeexport devm_qcom_tzmem_pool_newexport qcom_tzmem_allocexport qcom_tzmem_freeexport qcom_tzmem_to_physexport qcom_tzmem_enable
Annotated Snippet
struct qcom_tzmem_area {
struct list_head list;
void *vaddr;
dma_addr_t paddr;
size_t size;
void *priv;
};
struct qcom_tzmem_pool {
struct gen_pool *genpool;
struct list_head areas;
enum qcom_tzmem_policy policy;
size_t increment;
size_t max_size;
spinlock_t lock;
};
struct qcom_tzmem_chunk {
size_t size;
struct qcom_tzmem_pool *owner;
};
static struct device *qcom_tzmem_dev;
static RADIX_TREE(qcom_tzmem_chunks, GFP_ATOMIC);
static DEFINE_SPINLOCK(qcom_tzmem_chunks_lock);
#if IS_ENABLED(CONFIG_QCOM_TZMEM_MODE_GENERIC)
static int qcom_tzmem_init(void)
{
return 0;
}
static int qcom_tzmem_init_area(struct qcom_tzmem_area *area)
{
return 0;
}
static void qcom_tzmem_cleanup_area(struct qcom_tzmem_area *area)
{
}
#elif IS_ENABLED(CONFIG_QCOM_TZMEM_MODE_SHMBRIDGE)
#include <linux/firmware/qcom/qcom_scm.h>
#include <linux/of.h>
#define QCOM_SHM_BRIDGE_NUM_VM_SHIFT 9
static bool qcom_tzmem_using_shm_bridge;
/* List of machines that are known to not support SHM bridge correctly. */
static const char *const qcom_tzmem_blacklist[] = {
"qcom,sc7180", /* hang in rmtfs memory assignment */
"qcom,sc8180x",
"qcom,sdm670", /* failure in GPU firmware loading */
"qcom,sdm845", /* reset in rmtfs memory assignment */
"qcom,sm7150", /* reset in rmtfs memory assignment */
"qcom,sm8150", /* reset in rmtfs memory assignment */
NULL
};
static int qcom_tzmem_init(void)
{
const char *const *platform;
int ret;
for (platform = qcom_tzmem_blacklist; *platform; platform++) {
if (of_machine_is_compatible(*platform))
goto notsupp;
}
ret = qcom_scm_shm_bridge_enable(qcom_tzmem_dev);
if (ret == -EOPNOTSUPP)
goto notsupp;
if (!ret)
qcom_tzmem_using_shm_bridge = true;
return ret;
notsupp:
dev_info(qcom_tzmem_dev, "SHM Bridge not supported\n");
return 0;
}
/**
* qcom_tzmem_shm_bridge_create() - Create a SHM bridge.
* @paddr: Physical address of the memory to share.
Annotation
- Immediate include surface: `linux/bug.h`, `linux/cleanup.h`, `linux/dma-mapping.h`, `linux/err.h`, `linux/firmware/qcom/qcom_tzmem.h`, `linux/genalloc.h`, `linux/gfp.h`, `linux/kernel.h`.
- Detected declarations: `struct qcom_tzmem_area`, `struct qcom_tzmem_pool`, `struct qcom_tzmem_chunk`, `function qcom_tzmem_init`, `function qcom_tzmem_init_area`, `function qcom_tzmem_cleanup_area`, `function qcom_tzmem_init`, `function qcom_tzmem_shm_bridge_create`, `function qcom_tzmem_shm_bridge_delete`, `function qcom_tzmem_init_area`.
- Atlas domain: Driver Families / drivers/firmware.
- 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.