From 012f865aa9951f8dabd1a17980dc4687adea94dc Mon Sep 17 00:00:00 2001 Message-Id: <012f865aa9951f8dabd1a17980dc4687adea94dc.1663777662.git.quic_gokukris@quicinc.com> In-Reply-To: References: From: Gokul krishna Krishnakumar Date: Mon, 12 Sep 2022 11:41:31 -0700 Subject: [PATCH v2 1/2] firmware: qcom_scm: Remove memory alloc call from qcom_scm_pas_init_image() The memory for metadata is allocated in mdt loader and scm driver 1]. 163 data = kmalloc(ehdr_size + hash_size, GFP_KERNEL); 2]. 477 mdata_buf = dma_alloc_coherent(__scm->dev, size, &mdata_phys, 478 GFP_KERNEL); The SCM driver is meant to only pack arguments provided to it from clients for making the secure world calls. This change removes the logic of doing a dma alloc coherent from the SCM driver and moves it into the mdt loader Signed-off-by: Gokul krishna Krishnakumar --- drivers/firmware/qcom_scm.c | 33 +++------------------------------ drivers/soc/qcom/mdt_loader.c | 3 ++- include/linux/qcom_scm.h | 4 +--- 3 files changed, 6 insertions(+), 34 deletions(-) diff --git a/drivers/firmware/qcom_scm.c b/drivers/firmware/qcom_scm.c index cdbfe54..05ec03c 100644 --- a/drivers/firmware/qcom_scm.c +++ b/drivers/firmware/qcom_scm.c @@ -442,11 +442,9 @@ static void qcom_scm_set_download_mode(bool enable) * state machine for a given peripheral, using the * metadata * @peripheral: peripheral id - * @metadata: pointer to memory containing ELF header, program header table + * @mdata_phys: pointer to memory containing ELF header, program header table * and optional blob of data used for authenticating the metadata * and the rest of the firmware - * @size: size of the metadata - * @ctx: optional metadata context * * Return: 0 on success. * @@ -454,11 +452,8 @@ static void qcom_scm_set_download_mode(bool enable) * track the metadata allocation, this needs to be released by invoking * qcom_scm_pas_metadata_release() by the caller. */ -int qcom_scm_pas_init_image(u32 peripheral, const void *metadata, size_t size, - struct qcom_scm_pas_metadata *ctx) +int qcom_scm_pas_init_image(u32 peripheral, dma_addr_t mdata_phys) { - dma_addr_t mdata_phys; - void *mdata_buf; int ret; struct qcom_scm_desc desc = { .svc = QCOM_SCM_SVC_PIL, @@ -469,22 +464,9 @@ int qcom_scm_pas_init_image(u32 peripheral, const void *metadata, size_t size, }; struct qcom_scm_res res; - /* - * During the scm call memory protection will be enabled for the meta - * data blob, so make sure it's physically contiguous, 4K aligned and - * non-cachable to avoid XPU violations. - */ - mdata_buf = dma_alloc_coherent(__scm->dev, size, &mdata_phys, - GFP_KERNEL); - if (!mdata_buf) { - dev_err(__scm->dev, "Allocation of metadata buffer failed.\n"); - return -ENOMEM; - } - memcpy(mdata_buf, metadata, size); - ret = qcom_scm_clk_enable(); if (ret) - goto out; + return ret; ret = qcom_scm_bw_enable(); if (ret) @@ -497,15 +479,6 @@ int qcom_scm_pas_init_image(u32 peripheral, const void *metadata, size_t size, qcom_scm_bw_disable(); qcom_scm_clk_disable(); -out: - if (ret < 0 || !ctx) { - dma_free_coherent(__scm->dev, size, mdata_buf, mdata_phys); - } else if (ctx) { - ctx->ptr = mdata_buf; - ctx->phys = mdata_phys; - ctx->size = size; - } - return ret ? : res.result[0]; } EXPORT_SYMBOL(qcom_scm_pas_init_image); diff --git a/drivers/soc/qcom/mdt_loader.c b/drivers/soc/qcom/mdt_loader.c index 3f11554..8d06125 100644 --- a/drivers/soc/qcom/mdt_loader.c +++ b/drivers/soc/qcom/mdt_loader.c @@ -210,6 +210,7 @@ int qcom_mdt_pas_init(struct device *dev, const struct firmware *fw, const struct elf32_hdr *ehdr; phys_addr_t min_addr = PHYS_ADDR_MAX; phys_addr_t max_addr = 0; + dma_addr_t mdata_phys; size_t metadata_len; void *metadata; int ret; @@ -238,7 +239,7 @@ int qcom_mdt_pas_init(struct device *dev, const struct firmware *fw, goto out; } - ret = qcom_scm_pas_init_image(pas_id, metadata, metadata_len, ctx); + ret = qcom_scm_pas_init_image(pas_id, mdata_phys); kfree(metadata); if (ret) { /* Invalid firmware metadata */ diff --git a/include/linux/qcom_scm.h b/include/linux/qcom_scm.h index f833564..751436a 100644 --- a/include/linux/qcom_scm.h +++ b/include/linux/qcom_scm.h @@ -74,9 +74,7 @@ struct qcom_scm_pas_metadata { ssize_t size; }; -extern int qcom_scm_pas_init_image(u32 peripheral, const void *metadata, - size_t size, - struct qcom_scm_pas_metadata *ctx); +extern int qcom_scm_pas_init_image(u32 peripheral, dma_addr_t metadata); void qcom_scm_pas_metadata_release(struct qcom_scm_pas_metadata *ctx); extern int qcom_scm_pas_mem_setup(u32 peripheral, phys_addr_t addr, phys_addr_t size); -- 2.7.4