Skip to content

Commit 449d0d8

Browse files
Bartosz Golaszewskiandersson
authored andcommitted
firmware: qcom: scm: smc: switch to using the SCM allocator
We need to allocate, map and pass a buffer to the trustzone if we have more than 4 arguments for a given SCM call. Let's use the new TrustZone allocator for that memory and shrink the code in process. As this code lives in a different compilation unit than the rest of the SCM code, we need to provide a helper in the form of qcom_scm_get_tzmem_pool() that allows the SMC low-level routines to access the SCM memory pool. 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-4-ce7afaa58d3a@linaro.org Signed-off-by: Bjorn Andersson <andersson@kernel.org>
1 parent 40289e3 commit 449d0d8

File tree

3 files changed

+16
-22
lines changed

3 files changed

+16
-22
lines changed

drivers/firmware/qcom/qcom_scm-smc.c

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
/* Copyright (c) 2015,2019 The Linux Foundation. All rights reserved.
33
*/
44

5+
#include <linux/cleanup.h>
56
#include <linux/io.h>
67
#include <linux/errno.h>
78
#include <linux/delay.h>
89
#include <linux/mutex.h>
910
#include <linux/slab.h>
1011
#include <linux/types.h>
1112
#include <linux/firmware/qcom/qcom_scm.h>
13+
#include <linux/firmware/qcom/qcom_tzmem.h>
1214
#include <linux/arm-smccc.h>
1315
#include <linux/dma-mapping.h>
1416

@@ -150,11 +152,10 @@ int __scm_smc_call(struct device *dev, const struct qcom_scm_desc *desc,
150152
enum qcom_scm_convention qcom_convention,
151153
struct qcom_scm_res *res, bool atomic)
152154
{
155+
struct qcom_tzmem_pool *mempool = qcom_scm_get_tzmem_pool();
153156
int arglen = desc->arginfo & 0xf;
154157
int i, ret;
155-
dma_addr_t args_phys = 0;
156-
void *args_virt = NULL;
157-
size_t alloc_len;
158+
void *args_virt __free(qcom_tzmem) = NULL;
158159
gfp_t flag = atomic ? GFP_ATOMIC : GFP_KERNEL;
159160
u32 smccc_call_type = atomic ? ARM_SMCCC_FAST_CALL : ARM_SMCCC_STD_CALL;
160161
u32 qcom_smccc_convention = (qcom_convention == SMC_CONVENTION_ARM_32) ?
@@ -172,9 +173,9 @@ int __scm_smc_call(struct device *dev, const struct qcom_scm_desc *desc,
172173
smc.args[i + SCM_SMC_FIRST_REG_IDX] = desc->args[i];
173174

174175
if (unlikely(arglen > SCM_SMC_N_REG_ARGS)) {
175-
alloc_len = SCM_SMC_N_EXT_ARGS * sizeof(u64);
176-
args_virt = kzalloc(PAGE_ALIGN(alloc_len), flag);
177-
176+
args_virt = qcom_tzmem_alloc(mempool,
177+
SCM_SMC_N_EXT_ARGS * sizeof(u64),
178+
flag);
178179
if (!args_virt)
179180
return -ENOMEM;
180181

@@ -192,25 +193,10 @@ int __scm_smc_call(struct device *dev, const struct qcom_scm_desc *desc,
192193
SCM_SMC_FIRST_EXT_IDX]);
193194
}
194195

195-
args_phys = dma_map_single(dev, args_virt, alloc_len,
196-
DMA_TO_DEVICE);
197-
198-
if (dma_mapping_error(dev, args_phys)) {
199-
kfree(args_virt);
200-
return -ENOMEM;
201-
}
202-
203-
smc.args[SCM_SMC_LAST_REG_IDX] = args_phys;
196+
smc.args[SCM_SMC_LAST_REG_IDX] = qcom_tzmem_to_phys(args_virt);
204197
}
205198

206-
/* ret error check follows after args_virt cleanup*/
207199
ret = __scm_smc_do(dev, &smc, &smc_res, atomic);
208-
209-
if (args_virt) {
210-
dma_unmap_single(dev, args_phys, alloc_len, DMA_TO_DEVICE);
211-
kfree(args_virt);
212-
}
213-
214200
if (ret)
215201
return ret;
216202

drivers/firmware/qcom/qcom_scm.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ static void qcom_scm_bw_disable(void)
203203
enum qcom_scm_convention qcom_scm_convention = SMC_CONVENTION_UNKNOWN;
204204
static DEFINE_SPINLOCK(scm_query_lock);
205205

206+
struct qcom_tzmem_pool *qcom_scm_get_tzmem_pool(void)
207+
{
208+
return __scm->mempool;
209+
}
210+
206211
static enum qcom_scm_convention __get_convention(void)
207212
{
208213
unsigned long flags;

drivers/firmware/qcom/qcom_scm.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#define __QCOM_SCM_INT_H
66

77
struct device;
8+
struct qcom_tzmem_pool;
89

910
enum qcom_scm_convention {
1011
SMC_CONVENTION_UNKNOWN,
@@ -78,6 +79,8 @@ int scm_legacy_call_atomic(struct device *dev, const struct qcom_scm_desc *desc,
7879
int scm_legacy_call(struct device *dev, const struct qcom_scm_desc *desc,
7980
struct qcom_scm_res *res);
8081

82+
struct qcom_tzmem_pool *qcom_scm_get_tzmem_pool(void);
83+
8184
#define QCOM_SCM_SVC_BOOT 0x01
8285
#define QCOM_SCM_BOOT_SET_ADDR 0x01
8386
#define QCOM_SCM_BOOT_TERMINATE_PC 0x02

0 commit comments

Comments
 (0)