mirror of
https://git.proxmox.com/git/mirror_ubuntu-kernels.git
synced 2025-12-08 02:38:14 +00:00
We have several SCM calls that require passing buffers to the TrustZone on top of the SMC core which allocates memory for calls that require more than 4 arguments. Currently every user does their own thing which leads to code duplication. Many users call dma_alloc_coherent() for every call which is terribly unperformant (speed- and size-wise). Provide a set of library functions for creating and managing pools of memory which is suitable for sharing with the TrustZone, that is: page-aligned, contiguous and non-cachable as well as provides a way of mapping of kernel virtual addresses to physical space. Make the allocator ready for extending with additional modes of operation which will allow us to support the SHM bridge safety mechanism once all users convert. Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Reviewed-by: Andrew Halaney <ahalaney@redhat.com> Tested-by: Andrew Halaney <ahalaney@redhat.com> # sc8280xp-lenovo-thinkpad-x13s Tested-by: Deepti Jaggi <quic_djaggi@quicinc.com> #sa8775p-ride Reviewed-by: Elliot Berman <quic_eberman@quicinc.com> Link: https://lore.kernel.org/r/20240527-shm-bridge-v10-2-ce7afaa58d3a@linaro.org Signed-off-by: Bjorn Andersson <andersson@kernel.org>
57 lines
1.5 KiB
C
57 lines
1.5 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
/*
|
|
* Copyright (C) 2023-2024 Linaro Ltd.
|
|
*/
|
|
|
|
#ifndef __QCOM_TZMEM_H
|
|
#define __QCOM_TZMEM_H
|
|
|
|
#include <linux/cleanup.h>
|
|
#include <linux/gfp.h>
|
|
#include <linux/types.h>
|
|
|
|
struct device;
|
|
struct qcom_tzmem_pool;
|
|
|
|
/**
|
|
* enum qcom_tzmem_policy - Policy for pool growth.
|
|
*/
|
|
enum qcom_tzmem_policy {
|
|
/**< Static pool, never grow above initial size. */
|
|
QCOM_TZMEM_POLICY_STATIC = 1,
|
|
/**< When out of memory, add increment * current size of memory. */
|
|
QCOM_TZMEM_POLICY_MULTIPLIER,
|
|
/**< When out of memory add as much as is needed until max_size. */
|
|
QCOM_TZMEM_POLICY_ON_DEMAND,
|
|
};
|
|
|
|
/**
|
|
* struct qcom_tzmem_pool_config - TZ memory pool configuration.
|
|
* @initial_size: Number of bytes to allocate for the pool during its creation.
|
|
* @policy: Pool size growth policy.
|
|
* @increment: Used with policies that allow pool growth.
|
|
* @max_size: Size above which the pool will never grow.
|
|
*/
|
|
struct qcom_tzmem_pool_config {
|
|
size_t initial_size;
|
|
enum qcom_tzmem_policy policy;
|
|
size_t increment;
|
|
size_t max_size;
|
|
};
|
|
|
|
struct qcom_tzmem_pool *
|
|
qcom_tzmem_pool_new(const struct qcom_tzmem_pool_config *config);
|
|
void qcom_tzmem_pool_free(struct qcom_tzmem_pool *pool);
|
|
struct qcom_tzmem_pool *
|
|
devm_qcom_tzmem_pool_new(struct device *dev,
|
|
const struct qcom_tzmem_pool_config *config);
|
|
|
|
void *qcom_tzmem_alloc(struct qcom_tzmem_pool *pool, size_t size, gfp_t gfp);
|
|
void qcom_tzmem_free(void *ptr);
|
|
|
|
DEFINE_FREE(qcom_tzmem, void *, if (_T) qcom_tzmem_free(_T))
|
|
|
|
phys_addr_t qcom_tzmem_to_phys(void *ptr);
|
|
|
|
#endif /* __QCOM_TZMEM */
|