File Index
Files and directories
Sign in
FILE

qcom_tzmem.h

File preview with syntax highlighting.

linux-6.19.14/include/linux/firmware/qcom/qcom_tzmem.h C
 1/* SPDX-License-Identifier: GPL-2.0-only */
 2/*
 3 * Copyright (C) 2023-2024 Linaro Ltd.
 4 */
 5
 6#ifndef __QCOM_TZMEM_H
 7#define __QCOM_TZMEM_H
 8
 9#include <linux/cleanup.h>
10#include <linux/gfp.h>
11#include <linux/types.h>
12
13struct device;
14struct qcom_tzmem_pool;
15
16/**
17 * enum qcom_tzmem_policy - Policy for pool growth.
18 */
19enum qcom_tzmem_policy {
20	/**
21	 * @QCOM_TZMEM_POLICY_STATIC: Static pool,
22	 * never grow above initial size.
23	 */
24	QCOM_TZMEM_POLICY_STATIC = 1,
25	/**
26	 * @QCOM_TZMEM_POLICY_MULTIPLIER: When out of memory,
27	 * add increment * current size of memory.
28	 */
29	QCOM_TZMEM_POLICY_MULTIPLIER,
30	/**
31	 * @QCOM_TZMEM_POLICY_ON_DEMAND: When out of memory
32	 * add as much as is needed until max_size.
33	 */
34	QCOM_TZMEM_POLICY_ON_DEMAND,
35};
36
37/**
38 * struct qcom_tzmem_pool_config - TZ memory pool configuration.
39 * @initial_size: Number of bytes to allocate for the pool during its creation.
40 * @policy: Pool size growth policy.
41 * @increment: Used with policies that allow pool growth.
42 * @max_size: Size above which the pool will never grow.
43 */
44struct qcom_tzmem_pool_config {
45	size_t initial_size;
46	enum qcom_tzmem_policy policy;
47	size_t increment;
48	size_t max_size;
49};
50
51struct qcom_tzmem_pool *
52qcom_tzmem_pool_new(const struct qcom_tzmem_pool_config *config);
53void qcom_tzmem_pool_free(struct qcom_tzmem_pool *pool);
54struct qcom_tzmem_pool *
55devm_qcom_tzmem_pool_new(struct device *dev,
56			 const struct qcom_tzmem_pool_config *config);
57
58void *qcom_tzmem_alloc(struct qcom_tzmem_pool *pool, size_t size, gfp_t gfp);
59void qcom_tzmem_free(void *ptr);
60
61DEFINE_FREE(qcom_tzmem, void *, if (_T) qcom_tzmem_free(_T))
62
63phys_addr_t qcom_tzmem_to_phys(void *ptr);
64
65#if IS_ENABLED(CONFIG_QCOM_TZMEM_MODE_SHMBRIDGE)
66int qcom_tzmem_shm_bridge_create(phys_addr_t paddr, size_t size, u64 *handle);
67void qcom_tzmem_shm_bridge_delete(u64 handle);
68#else
69static inline int qcom_tzmem_shm_bridge_create(phys_addr_t paddr,
70					       size_t size, u64 *handle)
71{
72	return 0;
73}
74
75static inline void qcom_tzmem_shm_bridge_delete(u64 handle)
76{
77}
78#endif
79
80#endif /* __QCOM_TZMEM */
~/ Read-only file preview.