remoteproc: qcom: q6v5: Decouple driver from MDT loader
Subsystems (4)
PATCH 1/5 remoteproc: qcom: q6v5: Decouple driver from MDT loader
Rather than duplicating half of the MDT loader in the validation step move the entire MDT parser into the q6v5 driver. This allows us to make the shared MDT-loader call the SCM PAS operations directly which simplifies the client code and allows for better reuse of the code.
--- drivers/remoteproc/Kconfig | 1 - drivers/remoteproc/qcom_q6v5_pil.c | 149 +++++++++++++++++++++++-------------- 2 files changed, 92 insertions(+), 58 deletions(-)
drivers/remoteproc/Kconfig +0 -1
@@ -92,7 +92,6 @@ config QCOM_Q6V5_PIL depends on QCOM_SMEM depends on REMOTEPROC select MFD_SYSCON - select QCOM_MDT_LOADER select QCOM_SCM help Say y here to support the Qualcomm Peripherial Image Loader for the
drivers/remoteproc/qcom_q6v5_pil.c +92 -57
202 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH 2/5 remoteproc: qcom: mdt_loader: Don't overwrite firmware object
The "fw" firmware object is passed from the remoteproc core and should not be overwritten, as that results in leaked buffers and a double free of the the last firmware object.
--- drivers/remoteproc/qcom_mdt_loader.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/remoteproc/qcom_mdt_loader.c +4 -3
@@ -116,6 +116,7 @@ int qcom_mdt_load(struct rproc *rproc,const struct elf32_phdr *phdrs;const struct elf32_phdr *phdr;const struct elf32_hdr *ehdr; +const struct firmware *seg_fw;size_t fw_name_len;char *fw_name;void *ptr;
@@ -154,16 +155,16 @@ int qcom_mdt_load(struct rproc *rproc,if (phdr->p_filesz) {sprintf (fw_name + fw_name_len -3 ,"b%02d" , i); - ret =request_firmware (&fw, fw_name, &rproc->dev); + ret =request_firmware (&seg_fw, fw_name, &rproc->dev);if (ret) {dev_err (&rproc->dev,"failed to load %s\n" , fw_name);break ; } -memcpy (ptr, fw->data, fw->size); +memcpy (ptr, seg_fw->data, seg_fw->size); -release_firmware (fw); +release_firmware (seg_fw); }if (phdr->p_memsz > phdr->p_filesz)
Signature · 1 line
2.11.0
PATCH 3/5 remoteproc: qcom: mdt_loader: Refactor MDT loader
In reply to Bjorn AnderssonPushing the SCM calls into the MDT loader reduces duplication in the callers and allows for non-remoteproc clients to use the helper for parsing and loading MDT files.
--- drivers/remoteproc/qcom_adsp_pil.c | 29 +------- drivers/remoteproc/qcom_mdt_loader.c | 134 +++++++++++++++++++++++------------ drivers/remoteproc/qcom_mdt_loader.h | 6 +- drivers/remoteproc/qcom_q6v5_pil.c | 4 +- drivers/remoteproc/qcom_wcnss.c | 29 +------- 5 files changed, 100 insertions(+), 102 deletions(-)
drivers/remoteproc/qcom_adsp_pil.c +2 -27
@@ -65,34 +65,9 @@ struct qcom_adsp {static int adsp_load (struct rproc *rproc,const struct firmware *fw) {struct qcom_adsp *adsp = (struct qcom_adsp *)rproc->priv; -phys_addr_t fw_addr; -size_t fw_size; -bool relocate; -int ret; - - ret =qcom_scm_pas_init_image (ADSP_PAS_ID , fw->data, fw->size); -if (ret) { -dev_err (&rproc->dev,"invalid firmware metadata\n" ); -return ret; - } - - ret =qcom_mdt_parse (fw, &fw_addr, &fw_size, &relocate); -if (ret) { -dev_err (&rproc->dev,"failed to parse mdt header\n" ); -return ret; - } - -if (relocate) { - adsp->mem_reloc = fw_addr; - - ret =qcom_scm_pas_mem_setup (ADSP_PAS_ID , adsp->mem_phys, fw_size); -if (ret) { -dev_err (&rproc->dev,"unable to setup memory for image\n" ); -return ret; - } - } -return qcom_mdt_load (rproc, fw, rproc->firmware); +return qcom_mdt_load (adsp->dev, fw, rproc->firmware,ADSP_PAS_ID , + adsp->mem_region, adsp->mem_phys, adsp->mem_size); }static const struct rproc_fw_ops adsp_fw_ops = {
drivers/remoteproc/qcom_mdt_loader.c +89 -45
213 lines not on this page · raw message
drivers/remoteproc/qcom_mdt_loader.h +4 -2
@@ -6,8 +6,10 @@#define QCOM_MDT_RELOCATABLE BIT(27)struct resource_table *qcom_mdt_find_rsc_table (struct rproc *rproc,const struct firmware *fw,int *tablesz); -int qcom_mdt_load (struct rproc *rproc,const struct firmware *fw,const char *fw_name); -int qcom_mdt_parse (const struct firmware *fw,phys_addr_t *fw_addr,size_t *fw_size,bool *fw_relocate); +ssize_t qcom_mdt_get_size (const struct firmware *fw); +int qcom_mdt_load (struct device *dev,const struct firmware *fw, +const char *fw_name,int pas_id,void *mem_region, +phys_addr_t mem_phys,size_t mem_size);#endif
drivers/remoteproc/qcom_q6v5_pil.c +3 -1
@@ -496,6 +496,7 @@ static int q6v5_mpss_load(struct q6v5 *qproc)const struct firmware *fw;struct elf32_hdr *ehdr;phys_addr_t mpss_reloc; +phys_addr_t boot_addr;phys_addr_t min_addr = (phys_addr_t )ULLONG_MAX ;phys_addr_t max_addr =0 ;bool relocate = false;
@@ -576,7 +577,8 @@ static int q6v5_mpss_load(struct q6v5 *qproc) size =readl (qproc->rmb_base +RMB_PMI_CODE_LENGTH_REG );if (!size) { -writel (mpss_reloc, qproc->rmb_base +RMB_PMI_CODE_START_REG ); + boot_addr = relocate ? qproc->mpss_phys : min_addr; +writel (boot_addr, qproc->rmb_base +RMB_PMI_CODE_START_REG );writel (RMB_CMD_LOAD_READY , qproc->rmb_base +RMB_MBA_COMMAND_REG ); }
drivers/remoteproc/qcom_wcnss.c +2 -27
@@ -152,34 +152,9 @@ void qcom_wcnss_assign_iris(struct qcom_wcnss *wcnss,static int wcnss_load (struct rproc *rproc,const struct firmware *fw) {struct qcom_wcnss *wcnss = (struct qcom_wcnss *)rproc->priv; -phys_addr_t fw_addr; -size_t fw_size; -bool relocate; -int ret; - - ret =qcom_scm_pas_init_image (WCNSS_PAS_ID , fw->data, fw->size); -if (ret) { -dev_err (&rproc->dev,"invalid firmware metadata\n" ); -return ret; - } - - ret =qcom_mdt_parse (fw, &fw_addr, &fw_size, &relocate); -if (ret) { -dev_err (&rproc->dev,"failed to parse mdt header\n" ); -return ret; - } - -if (relocate) { - wcnss->mem_reloc = fw_addr; - - ret =qcom_scm_pas_mem_setup (WCNSS_PAS_ID , wcnss->mem_phys, fw_size); -if (ret) { -dev_err (&rproc->dev,"unable to setup memory for image\n" ); -return ret; - } - } -return qcom_mdt_load (rproc, fw, rproc->firmware); +return qcom_mdt_load (wcnss->dev, fw, rproc->firmware,WCNSS_PAS_ID , + wcnss->mem_region, wcnss->mem_phys, wcnss->mem_size); }static const struct rproc_fw_ops wcnss_fw_ops = {
Signature · 1 line
2.11.0
PATCH 4/5 remoteproc: qcom-common: Extract non-mdt related helper
In reply to Bjorn AnderssonIn preparation for moving the mdt loader out of remoteproc let's move the somewhat unrelated resource table dummy helper to a Qualcomm "common" file.
--- drivers/remoteproc/Kconfig | 6 +++++ drivers/remoteproc/Makefile | 1 + drivers/remoteproc/qcom_adsp_pil.c | 1 + drivers/remoteproc/qcom_common.c | 46 ++++++++++++++++++++++++++++++++++++ drivers/remoteproc/qcom_common.h | 11 +++++++++ drivers/remoteproc/qcom_mdt_loader.c | 19 --------------- drivers/remoteproc/qcom_mdt_loader.h | 1 - drivers/remoteproc/qcom_q6v5_pil.c | 1 + drivers/remoteproc/qcom_wcnss.c | 1 + 9 files changed, 67 insertions(+), 20 deletions(-) create mode 100644 drivers/remoteproc/qcom_common.c create mode 100644 drivers/remoteproc/qcom_common.h
drivers/remoteproc/Kconfig +6 -0
@@ -78,11 +78,15 @@ config QCOM_ADSP_PIL depends on QCOM_SMEM select MFD_SYSCON select QCOM_MDT_LOADER + select QCOM_RPROC_COMMON select QCOM_SCM help Say y here to support the TrustZone based Peripherial Image Loader for the Qualcomm ADSP remote processors. +config QCOM_RPROC_COMMON + tristate + config QCOM_MDT_LOADER tristate
@@ -92,6 +96,7 @@ config QCOM_Q6V5_PIL depends on QCOM_SMEM depends on REMOTEPROC select MFD_SYSCON + select QCOM_RPROC_COMMON select QCOM_SCM help Say y here to support the Qualcomm Peripherial Image Loader for the
@@ -104,6 +109,7 @@ config QCOM_WCNSS_PIL depends on QCOM_SMEM depends on REMOTEPROC select QCOM_MDT_LOADER + select QCOM_RPROC_COMMON select QCOM_SCM help Say y here to support the Peripheral Image Loader for the Qualcomm
drivers/remoteproc/Makefile +1 -0
@@ -13,6 +13,7 @@ obj-$(CONFIG_WKUP_M3_RPROC) += wkup_m3_rproc.o obj-$(CONFIG_DA8XX_REMOTEPROC) += da8xx_remoteproc.o obj-$(CONFIG_QCOM_ADSP_PIL) += qcom_adsp_pil.o obj-$(CONFIG_QCOM_MDT_LOADER) += qcom_mdt_loader.o +obj-$(CONFIG_QCOM_RPROC_COMMON) += qcom_common.o obj-$(CONFIG_QCOM_Q6V5_PIL) += qcom_q6v5_pil.o obj-$(CONFIG_QCOM_WCNSS_PIL) += qcom_wcnss_pil.o qcom_wcnss_pil-y += qcom_wcnss.o
drivers/remoteproc/qcom_adsp_pil.c +1 -0
@@ -29,6 +29,7 @@#include <linux/soc/qcom/smem.h> #include <linux/soc/qcom/smem_state.h> +#include "qcom_common.h" #include "qcom_mdt_loader.h" #include "remoteproc_internal.h"
drivers/remoteproc/qcom_common.c new file +46 -0
46 lines not on this page · raw message
drivers/remoteproc/qcom_common.h new file +11 -0
@@ -0,0 +1,11 @@ +#ifndef __RPROC_QCOM_COMMON_H__ +#define __RPROC_QCOM_COMMON_H__ + +struct resource_table ; +struct rproc ; + +struct resource_table *qcom_mdt_find_rsc_table (struct rproc *rproc, +const struct firmware *fw, +int *tablesz); + +#endif
drivers/remoteproc/qcom_mdt_loader.c +0 -19
@@ -27,25 +27,6 @@#include "remoteproc_internal.h" #include "qcom_mdt_loader.h" -/** -* qcom_mdt_find_rsc_table() - provide dummy resource table for remoteproc -* @rproc: remoteproc handle -* @fw: firmware header -* @tablesz: outgoing size of the table -* -* Returns a dummy table. -*/ -struct resource_table *qcom_mdt_find_rsc_table (struct rproc *rproc, -const struct firmware *fw, -int *tablesz) -{ -static struct resource_table table = { .ver =1 , }; - - *tablesz =sizeof (table); -return &table; -} -EXPORT_SYMBOL_GPL (qcom_mdt_find_rsc_table); -static bool mdt_phdr_valid (const struct elf32_phdr *phdr) {if (phdr->p_type !=PT_LOAD )
drivers/remoteproc/qcom_mdt_loader.h +0 -1
@@ -5,7 +5,6 @@#define QCOM_MDT_TYPE_HASH (2 << 24)#define QCOM_MDT_RELOCATABLE BIT(27) -struct resource_table *qcom_mdt_find_rsc_table (struct rproc *rproc,const struct firmware *fw,int *tablesz);ssize_t qcom_mdt_get_size (const struct firmware *fw); int qcom_mdt_load(struct device *dev, const struct firmware *fw,
drivers/remoteproc/qcom_q6v5_pil.c +1 -0
@@ -33,6 +33,7 @@#include <linux/soc/qcom/smem_state.h> #include "remoteproc_internal.h" +#include "qcom_common.h" #include "qcom_mdt_loader.h" #include <linux/qcom_scm.h>
drivers/remoteproc/qcom_wcnss.c +1 -0
@@ -32,6 +32,7 @@#include <linux/soc/qcom/smem_state.h> #include <linux/rpmsg/qcom_smd.h> +#include "qcom_common.h" #include "qcom_mdt_loader.h" #include "remoteproc_internal.h" #include "qcom_wcnss.h"
Signature · 1 line
2.11.0
PATCH 5/5 soc/qcom: Move qcom_mdt_loader from remoteproc
In reply to Bjorn AnderssonWith the remoteproc parts cleaned out of the MDT loader we can move it to drivers/soc/qcom.
---
For testing purposes a temporary branch containing these patches can be found here:
https://github.com/andersson/kernel/commits/linux-next/rproc-q6v5
drivers/remoteproc/Kconfig | 3 ---
drivers/remoteproc/Makefile | 1 -
drivers/remoteproc/qcom_adsp_pil.c | 2 +-
drivers/remoteproc/qcom_q6v5_pil.c | 2 +-
drivers/remoteproc/qcom_wcnss.c | 2 +-
drivers/soc/qcom/Kconfig | 4 ++++
drivers/soc/qcom/Makefile | 1 +
drivers/{remoteproc/qcom_mdt_loader.c => soc/qcom/mdt_loader.c} | 4 +---
.../qcom_mdt_loader.h => include/linux/soc/qcom/mdt_loader.h | 4 ++++
9 files changed, 13 insertions(+), 10 deletions(-)
rename drivers/{remoteproc/qcom_mdt_loader.c => soc/qcom/mdt_loader.c} (98%)
rename drivers/remoteproc/qcom_mdt_loader.h => include/linux/soc/qcom/mdt_loader.h (87%)drivers/remoteproc/Kconfig +0 -3
@@ -87,9 +87,6 @@ config QCOM_ADSP_PIL config QCOM_RPROC_COMMON tristate -config QCOM_MDT_LOADER - tristate - config QCOM_Q6V5_PIL tristate "Qualcomm Hexagon V5 Peripherial Image Loader" depends on OF && ARCH_QCOM
drivers/remoteproc/Makefile +0 -1
@@ -12,7 +12,6 @@ obj-$(CONFIG_OMAP_REMOTEPROC) += omap_remoteproc.o obj-$(CONFIG_WKUP_M3_RPROC) += wkup_m3_rproc.o obj-$(CONFIG_DA8XX_REMOTEPROC) += da8xx_remoteproc.o obj-$(CONFIG_QCOM_ADSP_PIL) += qcom_adsp_pil.o -obj-$(CONFIG_QCOM_MDT_LOADER) += qcom_mdt_loader.o obj-$(CONFIG_QCOM_RPROC_COMMON) += qcom_common.o obj-$(CONFIG_QCOM_Q6V5_PIL) += qcom_q6v5_pil.o obj-$(CONFIG_QCOM_WCNSS_PIL) += qcom_wcnss_pil.o
drivers/remoteproc/qcom_adsp_pil.c +1 -1
@@ -26,11 +26,11 @@#include <linux/qcom_scm.h> #include <linux/regulator/consumer.h> #include <linux/remoteproc.h> +#include <linux/soc/qcom/mdt_loader.h> #include <linux/soc/qcom/smem.h> #include <linux/soc/qcom/smem_state.h> #include "qcom_common.h" -#include "qcom_mdt_loader.h" #include "remoteproc_internal.h" #define ADSP_CRASH_REASON_SMEM 423
drivers/remoteproc/qcom_q6v5_pil.c +1 -1
@@ -29,12 +29,12 @@#include <linux/regulator/consumer.h> #include <linux/remoteproc.h> #include <linux/reset.h> +#include <linux/soc/qcom/mdt_loader.h> #include <linux/soc/qcom/smem.h> #include <linux/soc/qcom/smem_state.h> #include "remoteproc_internal.h" #include "qcom_common.h" -#include "qcom_mdt_loader.h" #include <linux/qcom_scm.h>
drivers/remoteproc/qcom_wcnss.c +1 -1
@@ -28,12 +28,12 @@#include <linux/qcom_scm.h> #include <linux/regulator/consumer.h> #include <linux/remoteproc.h> +#include <linux/soc/qcom/mdt_loader.h> #include <linux/soc/qcom/smem.h> #include <linux/soc/qcom/smem_state.h> #include <linux/rpmsg/qcom_smd.h> #include "qcom_common.h" -#include "qcom_mdt_loader.h" #include "remoteproc_internal.h" #include "qcom_wcnss.h"
drivers/soc/qcom/Kconfig +4 -0
@@ -10,6 +10,10 @@ config QCOM_GSBI functions for connecting the underlying serial UART, SPI, and I2C devices to the output pins. +config QCOM_MDT_LOADER + tristate + select QCOM_SCM + config QCOM_PM bool "Qualcomm Power Management" depends on ARCH_QCOM && !ARM64
drivers/soc/qcom/Makefile +1 -0
@@ -1,4 +1,5 @@ obj-$(CONFIG_QCOM_GSBI) += qcom_gsbi.o +obj-$(CONFIG_QCOM_MDT_LOADER) += mdt_loader.o obj-$(CONFIG_QCOM_PM) += spm.o obj-$(CONFIG_QCOM_SMD) += smd.o obj-$(CONFIG_QCOM_SMD_RPM) += smd-rpm.o
drivers/soc/qcom/mdt_loader.c renamed from drivers/remoteproc/qcom_mdt_loader.c +1 -3
@@ -23,9 +23,7 @@#include <linux/remoteproc.h> #include <linux/sizes.h> #include <linux/slab.h> - -#include "remoteproc_internal.h" -#include "qcom_mdt_loader.h" +#include <linux/soc/qcom/mdt_loader.h> static bool mdt_phdr_valid (const struct elf32_phdr *phdr) {
include/linux/soc/qcom/mdt_loader.h renamed from drivers/remoteproc/qcom_mdt_loader.h +4 -0
@@ -1,10 +1,14 @@#ifndef __QCOM_MDT_LOADER_H__#define __QCOM_MDT_LOADER_H__ +#include <linux/types.h> +#define QCOM_MDT_TYPE_MASK (7 << 24)#define QCOM_MDT_TYPE_HASH (2 << 24)#define QCOM_MDT_RELOCATABLE BIT(27) +struct device ; +struct firmware ;ssize_t qcom_mdt_get_size (const struct firmware *fw); int qcom_mdt_load(struct device *dev, const struct firmware *fw,
Signature · 1 line
2.11.0
Re: [PATCH 5/5] soc/qcom: Move qcom_mdt_loader from remoteproc
Quoted 2 lines · Bjorn Andersson
With the remoteproc parts cleaned out of the MDT loader we can move it to
drivers/soc/qcom.
<snip>
drivers/soc/qcom/Kconfig config QCOM_GSBI · line 15
Quoted 11 lines
drivers/soc/qcom/Kconfig +3
-0@@ -10,6 +10,10 @@ config QCOM_GSBI functions for connecting the underlying serial UART, SPI, and I2C devices to the output pins. +config QCOM_MDT_LOADER + tristate + select QCOM_SCM
Do we need a help description here?
drivers/soc/qcom/Kconfig config QCOM_GSBI · line 19
Quoted 4 lines
drivers/soc/qcom/Kconfig +1
-0+ config QCOM_PM bool "Qualcomm Power Management" depends on ARCH_QCOM && !ARM64
Add the description on the next set and add my ack as well.
Re: [PATCH 3/5] remoteproc: qcom: mdt_loader: Refactor MDT loader
In reply to Bjorn AnderssonHi Bjorn,
Thanks for the patch!
Quoted 14 lines · Bjorn Andersson
Pushing the SCM calls into the MDT loader reduces duplication in the callers and allows for non-remoteproc clients to use the helper for parsing and loading MDT files.
Cc Andy Gross <[email protected]>Signed-off-by Bjorn Andersson <[email protected]>--- drivers/remoteproc/qcom_adsp_pil.c | 29 +------- drivers/remoteproc/qcom_mdt_loader.c | 134 +++++++++++++++++++++++------------ drivers/remoteproc/qcom_mdt_loader.h | 6 +- drivers/remoteproc/qcom_q6v5_pil.c | 4 +- drivers/remoteproc/qcom_wcnss.c | 29 +------- 5 files changed, 100 insertions(+), 102 deletions(-)
<snip>
drivers/remoteproc/qcom_mdt_loader.c line 23
Quoted 10 lines
drivers/remoteproc/qcom_mdt_loader.c +1
-0@@ -19,6 +19,7 @@#include <linux/firmware.h> #include <linux/kernel.h> #include <linux/module.h> +#include <linux/qcom_scm.h> #include <linux/remoteproc.h>
Please delete remoteproc.h it is not needed anymore.
Quoted 20 lines
drivers/remoteproc/qcom_mdt_loader.c +14
-0#include <linux/sizes.h> #include <linux/slab.h> @@ -45,24 +46,33 @@ struct resource_table *qcom_mdt_find_rsc_table(struct rproc *rproc, }EXPORT_SYMBOL_GPL (qcom_mdt_find_rsc_table); +static bool mdt_phdr_valid (const struct elf32_phdr *phdr) +{ +if (phdr->p_type !=PT_LOAD ) +return false; + +if ((phdr->p_flags &QCOM_MDT_TYPE_MASK ) ==QCOM_MDT_TYPE_HASH ) +return false; + +if (!phdr->p_memsz) +return false; + +return true; +} +
<snip>
Signature · 2 lines
regards, Stan
Re: [PATCH 3/5] remoteproc: qcom: mdt_loader: Refactor MDT loader
In reply to Bjorn AnderssonHi Bjorn,
Quoted 109 lines · Bjorn Andersson
Pushing the SCM calls into the MDT loader reduces duplication in the callers and allows for non-remoteproc clients to use the helper for parsing and loading MDT files.
Cc Andy Gross <[email protected]>Signed-off-by Bjorn Andersson <[email protected]>--- drivers/remoteproc/qcom_adsp_pil.c | 29 +------- drivers/remoteproc/qcom_mdt_loader.c | 134 +++++++++++++++++++++++------------ drivers/remoteproc/qcom_mdt_loader.h | 6 +- drivers/remoteproc/qcom_q6v5_pil.c | 4 +- drivers/remoteproc/qcom_wcnss.c | 29 +------- 5 files changed, 100 insertions(+), 102 deletions(-)/**
- *qcom_mdt_load()- load the firmware which header is defined in fw
- * @rproc: rproc handle
- * @fw: frimware object for the header
- * @firmware: filename of the firmware, for building .bXX names
+ *qcom_mdt_load()- load the firmware which header is loaded as fw
+ * @dev: device handle to associate resources with
+ * @fw: firmware object for the mdt file
+ * @firmware: name of the firmware, for construction of segment file names
+ * @pas_id: PAS identifier
+ * @mem_region: allocated memory region to load firmware into
+ * @mem_phys: physical address of allocated memory region
+ * @mem_size: size of the allocated memory region
*
* Returns 0 on success, negative errno otherwise.
*/drivers/remoteproc/qcom_mdt_loader.c +47
-7-int qcom_mdt_load (struct rproc *rproc, -const struct firmware *fw, -const char *firmware) +int qcom_mdt_load (struct device *dev,const struct firmware *fw, +const char *firmware,int pas_id,void *mem_region, +phys_addr_t mem_phys,size_t mem_size) {const struct elf32_phdr *phdrs;const struct elf32_phdr *phdr;const struct elf32_hdr *ehdr;const struct firmware *seg_fw; +phys_addr_t mem_reloc; +phys_addr_t min_addr = (phys_addr_t )ULLONG_MAX ; +phys_addr_t max_addr =0 ;size_t fw_name_len; +size_t offset;char *fw_name; +bool relocate = false;void *ptr;int ret;int i; +if (!fw || !mem_region || !mem_phys || !mem_size) +return -EINVAL ; + ehdr = (struct elf32_hdr *)fw->data; phdrs = (struct elf32_phdr *)(ehdr +1 );@@ -134,31 +140,68 @@ int qcom_mdt_load(struct rproc *rproc,if (!fw_name)return -ENOMEM ; + ret =qcom_scm_pas_init_image (pas_id, fw->data, fw->size); +if (ret) { +dev_err (dev,"invalid firmware metadata\n" ); + goto out; + } +for (i =0 ; i < ehdr->e_phnum; i++) { phdr = &phdrs[i]; -if (phdr->p_type !=PT_LOAD ) +if (!mdt_phdr_valid (phdr))continue ; -if ((phdr->p_flags &QCOM_MDT_TYPE_MASK ) ==QCOM_MDT_TYPE_HASH ) -continue ; +if (phdr->p_flags &QCOM_MDT_RELOCATABLE ) + relocate = true; + +if (phdr->p_paddr < min_addr) + min_addr = phdr->p_paddr; + +if (phdr->p_paddr + phdr->p_memsz > max_addr) + max_addr =ALIGN (phdr->p_paddr + phdr->p_memsz,SZ_4K ); + } + +if (relocate) { + ret =qcom_scm_pas_mem_setup (pas_id, mem_phys, max_addr - min_addr); +if (ret) { +dev_err (dev,"unable to setup relocation\n" ); + goto out; + } + +/* +* The image is relocatable, so offset each segment based on +* the lowest segment address. +*/ + mem_reloc = min_addr; + }else { +/* +* Image is not relocatable, so offset each segment based on +* the allocated physical chunk of memory. +*/ + mem_reloc = mem_phys; + } -if (!phdr->p_memsz)
drivers/remoteproc/qcom_mdt_loader.c int qcom_mdt_load(struct rproc *rproc, · line 191
Quoted 10 lines
drivers/remoteproc/qcom_mdt_loader.c +5
-3+for (i =0 ; i < ehdr->e_phnum; i++) { + phdr = &phdrs[i]; + +if (!mdt_phdr_valid (phdr))continue ; - ptr =rproc_da_to_va (rproc, phdr->p_paddr, phdr->p_memsz); -if (!ptr) { -dev_err (&rproc->dev,"segment outside memory range\n" ); + offset = phdr->p_paddr - mem_reloc;
Shouldn't 'offset' variable be of signed type i.e. ssize_t? Also p_paddr is of type Elf32_Addr and mem_reloc is of type phys_addr_t which on 64bit systems is 64bit long, I think it should be better to make mem_reloc of the same type as p_paddr.
Quoted 19 lines
drivers/remoteproc/qcom_mdt_loader.c +6
-3+if (offset <0 || offset + phdr->p_memsz > mem_size) { +dev_err (dev,"segment outside memory range\n" ); ret = -EINVAL ;break ; } + ptr = mem_region + offset; +if (phdr->p_filesz) {sprintf (fw_name + fw_name_len -3 ,"b%02d" , i); - ret =request_firmware (&seg_fw, fw_name, &rproc->dev); + ret =request_firmware (&seg_fw, fw_name, dev);if (ret) { -dev_err (&rproc->dev,"failed to load %s\n" , - fw_name); +dev_err (dev,"failed to load %s\n" , fw_name);break ; }
Signature · 2 lines
regards, Stan
Re: [PATCH 3/5] remoteproc: qcom: mdt_loader: Refactor MDT loader
Quoted 3 lines · Stanimir Varbanov
Hi Bjorn,
On 01/30/2017 06:55 PM, Bjorn Andersson wrote:
[..]
Quoted 1 line
Quoted 1 line
+int qcom_mdt_load(struct device *dev, const struct firmware *fw,
[..]
Quoted 1 line
Quoted 1 line
drivers/remoteproc/qcom_mdt_loader.c +1
-0+size_t offset;
[..]
Quoted 6 lines
Quoted 6 lines
drivers/remoteproc/qcom_mdt_loader.c +4
-0+for (i =0 ; i < ehdr->e_phnum; i++) { + phdr = &phdrs[i]; + +if (!mdt_phdr_valid (phdr))continue ;
Quoted 6 lines
drivers/remoteproc/qcom_mdt_loader.c int qcom_mdt_load(struct rproc *rproc, · line 191
Quoted 4 lines
drivers/remoteproc/qcom_mdt_loader.c +1
-3- ptr =rproc_da_to_va (rproc, phdr->p_paddr, phdr->p_memsz); -if (!ptr) { -dev_err (&rproc->dev,"segment outside memory range\n" ); + offset = phdr->p_paddr - mem_reloc;Shouldn't 'offset' variable be of signed type i.e.
ssize_t?
It should, as a small "negative" value will wrap back into the acceptable range of the second part of the check below. I got another report of this as well yesterday, so I will prepare a patch for this.
Quoted 4 lines
Also
p_paddris of typeElf32_Addrandmem_relocis of typephys_addr_twhich on 64bit systems is 64bit long, I think it should be better to makemem_relocof the same type asp_paddr.
If I remember what the C standard says, mem_reloc would in the 64-bit case have higher "rank" and the type of p_paddr would therefor be converted to the type of mem_reloc (i.e. u64) and the result would be stored in a 64 bit type. But it's been a while and I can't find my C reference manual right now...
Casting mem_reloc to the type of p_paddr would cause invalid results in the event that the system is configured to actually load a relocatable blob into memory above 4GB.
Quoted 6 lines
Quoted 6 lines
drivers/remoteproc/qcom_mdt_loader.c +2
-0+if (offset <0 || offset + phdr->p_memsz > mem_size) { +dev_err (dev,"segment outside memory range\n" ); ret = -EINVAL ;break ; }
Quoted 14 lines
drivers/remoteproc/qcom_mdt_loader.c int qcom_mdt_load(struct rproc *rproc, · line 206
Quoted 13 lines
drivers/remoteproc/qcom_mdt_loader.c +4
-3+ ptr = mem_region + offset; +if (phdr->p_filesz) {sprintf (fw_name + fw_name_len -3 ,"b%02d" , i); - ret =request_firmware (&seg_fw, fw_name, &rproc->dev); + ret =request_firmware (&seg_fw, fw_name, dev);if (ret) { -dev_err (&rproc->dev,"failed to load %s\n" , - fw_name); +dev_err (dev,"failed to load %s\n" , fw_name);break ; }
Regards,
Bjorn