Skip to content

Commit 40289e3

Browse files
Bartosz Golaszewskiandersson
authored andcommitted
firmware: qcom: scm: enable the TZ mem allocator
Select the TrustZone memory allocator in Kconfig and create a pool of memory shareable with the TrustZone when probing the SCM driver. This will allow a gradual conversion of all relevant SCM calls to using the dedicated allocator. The policy used for the pool is "on-demand" and the initial size is 0 as - depending on the config - it's possible that no SCM calls needing to allocate memory will be called. The sizes of possible allocations also vary substiantially further warranting the "on-demand" approach. 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-3-ce7afaa58d3a@linaro.org Signed-off-by: Bjorn Andersson <andersson@kernel.org>
1 parent 84f5a7b commit 40289e3

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

drivers/firmware/qcom/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
menu "Qualcomm firmware drivers"
88

99
config QCOM_SCM
10+
select QCOM_TZMEM
1011
tristate
1112

1213
config QCOM_TZMEM

drivers/firmware/qcom/qcom_scm.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
#include <linux/completion.h>
1111
#include <linux/cpumask.h>
1212
#include <linux/dma-mapping.h>
13+
#include <linux/err.h>
1314
#include <linux/export.h>
1415
#include <linux/firmware/qcom/qcom_scm.h>
16+
#include <linux/firmware/qcom/qcom_tzmem.h>
1517
#include <linux/init.h>
1618
#include <linux/interconnect.h>
1719
#include <linux/interrupt.h>
@@ -22,9 +24,11 @@
2224
#include <linux/of_platform.h>
2325
#include <linux/platform_device.h>
2426
#include <linux/reset-controller.h>
27+
#include <linux/sizes.h>
2528
#include <linux/types.h>
2629

2730
#include "qcom_scm.h"
31+
#include "qcom_tzmem.h"
2832

2933
static bool download_mode = IS_ENABLED(CONFIG_QCOM_SCM_DOWNLOAD_MODE_DEFAULT);
3034
module_param(download_mode, bool, 0);
@@ -43,6 +47,8 @@ struct qcom_scm {
4347
int scm_vote_count;
4448

4549
u64 dload_mode_addr;
50+
51+
struct qcom_tzmem_pool *mempool;
4652
};
4753

4854
struct qcom_scm_current_perm_info {
@@ -1824,6 +1830,7 @@ static irqreturn_t qcom_scm_irq_handler(int irq, void *data)
18241830

18251831
static int qcom_scm_probe(struct platform_device *pdev)
18261832
{
1833+
struct qcom_tzmem_pool_config pool_config;
18271834
struct qcom_scm *scm;
18281835
int irq, ret;
18291836

@@ -1899,6 +1906,21 @@ static int qcom_scm_probe(struct platform_device *pdev)
18991906
if (of_property_read_bool(pdev->dev.of_node, "qcom,sdi-enabled"))
19001907
qcom_scm_disable_sdi();
19011908

1909+
ret = qcom_tzmem_enable(__scm->dev);
1910+
if (ret)
1911+
return dev_err_probe(__scm->dev, ret,
1912+
"Failed to enable the TrustZone memory allocator\n");
1913+
1914+
memset(&pool_config, 0, sizeof(pool_config));
1915+
pool_config.initial_size = 0;
1916+
pool_config.policy = QCOM_TZMEM_POLICY_ON_DEMAND;
1917+
pool_config.max_size = SZ_256K;
1918+
1919+
__scm->mempool = devm_qcom_tzmem_pool_new(__scm->dev, &pool_config);
1920+
if (IS_ERR(__scm->mempool))
1921+
return dev_err_probe(__scm->dev, PTR_ERR(__scm->mempool),
1922+
"Failed to create the SCM memory pool\n");
1923+
19021924
/*
19031925
* Initialize the QSEECOM interface.
19041926
*

0 commit comments

Comments
 (0)