xref: /linux/include/linux/firmware/qcom/qcom_tzmem.h (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
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 
13 struct device;
14 struct qcom_tzmem_pool;
15 
16 /**
17  * enum qcom_tzmem_policy - Policy for pool growth.
18  */
19 enum qcom_tzmem_policy {
20 	/**< Static pool, never grow above initial size. */
21 	QCOM_TZMEM_POLICY_STATIC = 1,
22 	/**< When out of memory, add increment * current size of memory. */
23 	QCOM_TZMEM_POLICY_MULTIPLIER,
24 	/**< When out of memory add as much as is needed until max_size. */
25 	QCOM_TZMEM_POLICY_ON_DEMAND,
26 };
27 
28 /**
29  * struct qcom_tzmem_pool_config - TZ memory pool configuration.
30  * @initial_size: Number of bytes to allocate for the pool during its creation.
31  * @policy: Pool size growth policy.
32  * @increment: Used with policies that allow pool growth.
33  * @max_size: Size above which the pool will never grow.
34  */
35 struct qcom_tzmem_pool_config {
36 	size_t initial_size;
37 	enum qcom_tzmem_policy policy;
38 	size_t increment;
39 	size_t max_size;
40 };
41 
42 struct qcom_tzmem_pool *
43 qcom_tzmem_pool_new(const struct qcom_tzmem_pool_config *config);
44 void qcom_tzmem_pool_free(struct qcom_tzmem_pool *pool);
45 struct qcom_tzmem_pool *
46 devm_qcom_tzmem_pool_new(struct device *dev,
47 			 const struct qcom_tzmem_pool_config *config);
48 
49 void *qcom_tzmem_alloc(struct qcom_tzmem_pool *pool, size_t size, gfp_t gfp);
50 void qcom_tzmem_free(void *ptr);
51 
52 DEFINE_FREE(qcom_tzmem, void *, if (_T) qcom_tzmem_free(_T))
53 
54 phys_addr_t qcom_tzmem_to_phys(void *ptr);
55 
56 #endif /* __QCOM_TZMEM */
57