Add new SCM call for stage two mem translation and enable mss rproc on msm8996
v4 cover Add new SCM call for stage two mem translation and enable mss rproc on msm8996
This patch does following
1- Adds new scm call which helps in stage two translation of a memory region
so that multi proc mem access sharing can be achieved on armv8 and later.
2- Enable mss remoteproc on msm8996
This patchset is based on tip of linux-next.
Avaneesh Kumar Dwivedi (4):
firmware: scm: Add support for shared access of a memory
remoteproc: qcom: refactor mss fw image loading sequence
remoteproc: qcom: Add new secure monitor call for access
remoteproc: qcom: Add support for mss boot on msm8996
.../devicetree/bindings/remoteproc/qcom,q6v5.txt | 4 +- drivers/firmware/qcom_scm-64.c | 27 ++ drivers/firmware/qcom_scm.c | 75 ++++++ drivers/firmware/qcom_scm.h | 4 + drivers/remoteproc/qcom_q6v5_pil.c | 280 ++++++++++++++++++--- include/linux/qcom_scm.h | 14 ++ 6 files changed, 364 insertions(+), 40 deletions(-)
Signature · 2 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
PATCH v4 1/4 firmware: scm: Add support for shared access of a memory
Two different processors on a SOC need to share memory during loading. So memory access between them need to be synchronized, which is done via level two memory mapping by secure layer.
This patch provide interface for making secure monitor call for access sharing or access right transfer between two subsystems.
--- drivers/firmware/qcom_scm-64.c | 27 +++++++++++++++ drivers/firmware/qcom_scm.c | 75 ++++++++++++++++++++++++++++++++++++++++++ drivers/firmware/qcom_scm.h | 4 +++ include/linux/qcom_scm.h | 14 ++++++++ 4 files changed, 120 insertions(+)
drivers/firmware/qcom_scm-64.c +27 -0
@@ -439,3 +439,30 @@ int __qcom_scm_iommu_secure_ptbl_init(struct device *dev, u64 addr, u32 size,return ret; } + +int __qcom_scm_assign_mem (struct device *dev,phys_addr_t mem_addr, +size_t mem_sz,phys_addr_t srcVm,size_t srcVm_sz, +phys_addr_t destVm,size_t destVm_sz) +{ +int ret; +struct qcom_scm_desc desc = {0 }; +struct arm_smccc_res res; + + desc.args[0 ] = mem_addr; + desc.args[1 ] = mem_sz; + desc.args[2 ] = srcVm; + desc.args[3 ] = srcVm_sz; + desc.args[4 ] = destVm; + desc.args[5 ] = destVm_sz; + desc.args[6 ] =0 ; + + desc.arginfo =QCOM_SCM_ARGS (7 ,QCOM_SCM_RO ,QCOM_SCM_VAL , +QCOM_SCM_RO ,QCOM_SCM_VAL ,QCOM_SCM_RO , +QCOM_SCM_VAL ,QCOM_SCM_VAL ); + + ret =qcom_scm_call (dev,QCOM_SCM_SVC_MP , +QCOM_MEM_PROT_ASSIGN_ID , + &desc, &res); + +return ret ? : res.a1; +}
drivers/firmware/qcom_scm.c +75 -0
87 lines not on this page · raw message
drivers/firmware/qcom_scm.h +4 -0
@@ -95,5 +95,9 @@ extern int __qcom_scm_iommu_secure_ptbl_size(struct device *dev, u32 spare, size_t *size);extern int __qcom_scm_iommu_secure_ptbl_init (struct device *dev,u64 addr,u32 size,u32 spare); +#define QCOM_MEM_PROT_ASSIGN_ID 0x16 +extern int __qcom_scm_assign_mem (struct device *dev,phys_addr_t mem_addr, +size_t mem_sz,phys_addr_t srcVm,size_t srcVm_sz, +phys_addr_t destVm,size_t destVm_sz);#endif
include/linux/qcom_scm.h +14 -0
@@ -23,6 +23,18 @@ struct qcom_scm_hdcp_req {u32 val; }; +struct qcom_scm_destVmPerm { +int destVm; +int destVmPerm; +}; + +#define QCOM_SCM_VMID_HLOS 0x3 +#define QCOM_SCM_VMID_MSS_MSA 0xF +#define QCOM_SCM_PERM_READ 0x4 +#define QCOM_SCM_PERM_WRITE 0x2 +#define QCOM_SCM_PERM_EXEC 0x1 +#define QCOM_SCM_PERM_RW (QCOM_SCM_PERM_READ | QCOM_SCM_PERM_WRITE) +#if IS_ENABLED (CONFIG_QCOM_SCM )extern int qcom_scm_set_cold_boot_addr (void *entry,const cpumask_t *cpus);extern int qcom_scm_set_warm_boot_addr (void *entry,const cpumask_t *cpus);
@@ -37,6 +49,8 @@ extern int qcom_scm_pas_mem_setup(u32 peripheral, phys_addr_t addr, phys_addr_t size);extern int qcom_scm_pas_auth_and_reset (u32 peripheral);extern int qcom_scm_pas_shutdown (u32 peripheral); +extern int qcom_scm_assign_mem (phys_addr_t mem_addr,size_t mem_sz,int currVm, +struct qcom_scm_destVmPerm *newVm,size_t newVm_sz);extern void qcom_scm_cpu_power_down (u32 flags);extern u32 qcom_scm_get_version (void );extern int qcom_scm_set_remote_state (u32 state,u32 id);
Signature · 2 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
kbuild test robot
build botRe: [PATCH v4 1/4] firmware: scm: Add support for shared access of a memory
url: https://github.com/0day-ci/linux/commits/Avaneesh-Kumar-Dwivedi/firmware-scm-Add-support-for-shared-access-of-a-memory/20170516-014147 config: arm-multi_v7_defconfig (attached as .config)…
Hi Avaneesh,
[auto build test ERROR on linus/master]
[also build test ERROR on v4.12-rc1 next-20170515]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Avaneesh-Kumar-Dwivedi/firmware-scm-Add-support-for-shared-access-of-a-memory/20170516-014147
config: arm-multi_v7_defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm
All errors (new ones prefixed by >>):
drivers/built-in.o: In function `qcom_scm_assign_mem':
>> sunxi_sid.c:(.text+0x501c2c): undefined reference to `__qcom_scm_assign_mem'
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
PATCH v4 2/4 remoteproc: qcom: refactor mss fw image loading sequence
In reply to Avaneesh Kumar DwivediThis patch refactor code to first load all firmware blobs and then update modem proc to authenticate and boot fw. Also make a trivial change in a error log.
--- drivers/remoteproc/qcom_q6v5_pil.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)
drivers/remoteproc/qcom_q6v5_pil.c +12 -13
@@ -466,9 +466,10 @@ static int q6v5_mpss_init_image(struct q6v5 *qproc, const struct firmware *fw) ret =q6v5_rmb_mba_wait (qproc,RMB_MBA_META_DATA_AUTH_SUCCESS ,1000 );if (ret == -ETIMEDOUT ) -dev_err (qproc->dev,"MPSS header authentication timed out\n" ); +dev_err (qproc->dev,"metadata authentication timed out\n" );else if (ret <0 ) -dev_err (qproc->dev,"MPSS header authentication failed: %d\n" , ret); +dev_err (qproc->dev, +"metadata authentication failed: %d\n" , ret);dma_free_attrs (qproc->dev, fw->size, ptr, phys, dma_attrs);
@@ -503,7 +504,7 @@ static int q6v5_mpss_load(struct q6v5 *qproc)bool relocate = false;char seg_name[10 ];ssize_t offset; -size_t size; +size_t size =0 ;void *ptr;int ret;int i;
@@ -541,7 +542,9 @@ static int q6v5_mpss_load(struct q6v5 *qproc) } mpss_reloc = relocate ? min_addr : qproc->mpss_phys; - +/* Load firmware completely before letting mss to start +* authentication and then boot firmware +*/ for (i =0 ; i < ehdr->e_phnum; i++) { phdr = &phdrs[i];
@@ -574,17 +577,13 @@ static int q6v5_mpss_load(struct q6v5 *qproc)memset (ptr + phdr->p_filesz,0 , phdr->p_memsz - phdr->p_filesz); } - - size =readl (qproc->rmb_base +RMB_PMI_CODE_LENGTH_REG ); -if (!size) { - 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 ); - } - size += phdr->p_memsz; -writel (size, qproc->rmb_base +RMB_PMI_CODE_LENGTH_REG ); } +/* Transfer ownership of modem region with modem fw */ + 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 ); +writel (size, qproc->rmb_base +RMB_PMI_CODE_LENGTH_REG ); ret =q6v5_rmb_mba_wait (qproc,RMB_MBA_AUTH_COMPLETE ,10000 );if (ret == -ETIMEDOUT )
Signature · 2 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
PATCH v4 3/4 remoteproc: qcom: Add new secure monitor call for access
In reply to Avaneesh Kumar DwivediMSS proc on msm8996 can not access fw loaded region without stage second translation of memory pages where mpss image are loaded. This patch to enable mss boot on msm8996 add these secure monitor calls to switch ownership between apps and modem.
--- drivers/remoteproc/qcom_q6v5_pil.c | 84 +++++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 2 deletions(-)
drivers/remoteproc/qcom_q6v5_pil.c +82 -2
@@ -110,6 +110,7 @@ struct rproc_hexagon_res {struct qcom_mss_reg_res *active_supply;char **proxy_clk_names;char **active_clk_names; +bool need_mem_protection; };struct q6v5 {
@@ -151,6 +152,7 @@ struct q6v5 {phys_addr_t mpss_reloc;void *mpss_region;size_t mpss_size; +bool need_mem_protection;struct qcom_rproc_subdev smd_subdev; };
@@ -288,6 +290,43 @@ static struct resource_table *q6v5_find_rsc_table(struct rproc *rproc,return &table; } +static int q6v5_assign_mem_to_subsys (struct q6v5 *qproc, +phys_addr_t addr,size_t size) +{ +struct qcom_scm_destVmPerm next[] = {{QCOM_SCM_VMID_MSS_MSA , + (QCOM_SCM_PERM_READ |QCOM_SCM_PERM_WRITE )} }; +int ret; + + size =ALIGN (size,SZ_4K ); +if (!qproc->need_mem_protection) +return 0 ; + ret =qcom_scm_assign_mem (addr, size, +BIT (QCOM_SCM_VMID_HLOS ), next,sizeof (next)); +if (ret) +pr_err ("%s: Failed to assign memory access, ret = %d\n" , + __func__, ret); +return ret; +} + +static int q6v5_assign_mem_to_linux (struct q6v5 *qproc, +phys_addr_t addr,size_t size) +{ +struct qcom_scm_destVmPerm next[] = { {QCOM_SCM_VMID_HLOS , + (QCOM_SCM_PERM_READ |QCOM_SCM_PERM_WRITE |QCOM_SCM_PERM_EXEC )} + }; +int ret; + + size =ALIGN (size,SZ_4K ); +if (!qproc->need_mem_protection) +return 0 ; + ret =qcom_scm_assign_mem (addr, size, +BIT (QCOM_SCM_VMID_MSS_MSA ), next,sizeof (next)); +if (ret) +pr_err ("%s: Failed to assign memory access, ret = %d\n" , + __func__, ret); +return ret; +} +static int q6v5_load (struct rproc *rproc,const struct firmware *fw) {struct q6v5 *qproc = rproc->priv;
@@ -461,6 +500,13 @@ static int q6v5_mpss_init_image(struct q6v5 *qproc, const struct firmware *fw)memcpy (ptr, fw->data, fw->size); +/* Hypervisor mapping to access metadata by modem */ + ret =q6v5_assign_mem_to_subsys (qproc, phys, fw->size); +if (ret) { +dev_err (qproc->dev, +"Failed to assign metadata memory, ret - %d\n" , ret); +return -ENOMEM ; + }writel (phys, qproc->rmb_base +RMB_PMI_META_DATA_REG );writel (RMB_CMD_META_DATA_READY , qproc->rmb_base +RMB_MBA_COMMAND_REG );
@@ -471,6 +517,11 @@ static int q6v5_mpss_init_image(struct q6v5 *qproc, const struct firmware *fw)dev_err (qproc->dev,"metadata authentication failed: %d\n" , ret); +/* Metadata authentication done, remove modem access */ + ret =q6v5_assign_mem_to_linux (qproc, phys, fw->size); +if (ret) +dev_err (qproc->dev, +"Failed to reclaim metadata memory, ret - %d\n" , ret);dma_free_attrs (qproc->dev, fw->size, ptr, phys, dma_attrs);return ret <0 ? ret :0 ;
@@ -581,6 +632,10 @@ static int q6v5_mpss_load(struct q6v5 *qproc) }/* Transfer ownership of modem region with modem fw */ boot_addr = relocate ? qproc->mpss_phys : min_addr; + ret =q6v5_assign_mem_to_subsys (qproc, + qproc->mpss_phys, qproc->mpss_size); +if (ret) +return ret;writel (boot_addr, qproc->rmb_base +RMB_PMI_CODE_START_REG );writel (RMB_CMD_LOAD_READY , qproc->rmb_base +RMB_MBA_COMMAND_REG );writel (size, qproc->rmb_base +RMB_PMI_CODE_LENGTH_REG );
@@ -600,6 +655,7 @@ static int q6v5_mpss_load(struct q6v5 *qproc)static int q6v5_start (struct rproc *rproc) {struct q6v5 *qproc = (struct q6v5 *)rproc->priv; +int assign_mem_result;int ret; ret = q6v5_regulator_enable(qproc, qproc->proxy_regs,
@@ -635,6 +691,13 @@ static int q6v5_start(struct rproc *rproc) goto assert_reset; } + ret =q6v5_assign_mem_to_subsys (qproc, + qproc->mba_phys, qproc->mba_size); +if (ret) { +dev_err (qproc->dev, +"Failed to assign mba memory access, ret - %d\n" , ret); + goto assert_reset; + }writel (qproc->mba_phys, qproc->rmb_base +RMB_MBA_IMAGE_REG ); ret =q6v5proc_reset (qproc);
@@ -656,16 +719,21 @@ static int q6v5_start(struct rproc *rproc) ret =q6v5_mpss_load (qproc);if (ret) - goto halt_axi_ports; + goto reclaim_mem; ret =wait_for_completion_timeout (&qproc->start_done,msecs_to_jiffies (5000 ));if (ret ==0 ) {dev_err (qproc->dev,"start timed out\n" ); ret = -ETIMEDOUT ; - goto halt_axi_ports; + goto reclaim_mem; } + ret =q6v5_assign_mem_to_linux (qproc, + qproc->mba_phys, qproc->mba_size); +if (ret) +dev_err (qproc->dev, +"Failed to reclaim mba memory, ret - %d\n" , ret); qproc->running = true; q6v5_clk_disable(qproc->dev, qproc->proxy_clks,
@@ -675,12 +743,19 @@ static int q6v5_start(struct rproc *rproc)return 0 ; +reclaim_mem: + assign_mem_result = +q6v5_assign_mem_to_linux (qproc, + qproc->mpss_phys, qproc->mpss_size); halt_axi_ports:q6v5proc_halt_axi_port (qproc, qproc->halt_map, qproc->halt_q6);q6v5proc_halt_axi_port (qproc, qproc->halt_map, qproc->halt_modem);q6v5proc_halt_axi_port (qproc, qproc->halt_map, qproc->halt_nc);q6v5_clk_disable (qproc->dev, qproc->active_clks, qproc->active_clk_count); + assign_mem_result = +q6v5_assign_mem_to_linux (qproc, + qproc->mba_phys, qproc->mba_size); assert_reset:reset_control_assert (qproc->mss_restart); disable_vdd:
@@ -717,6 +792,8 @@ static int q6v5_stop(struct rproc *rproc)q6v5proc_halt_axi_port (qproc, qproc->halt_map, qproc->halt_modem);q6v5proc_halt_axi_port (qproc, qproc->halt_map, qproc->halt_nc); + ret =q6v5_assign_mem_to_linux (qproc, + qproc->mpss_phys, qproc->mpss_size);reset_control_assert (qproc->mss_restart);q6v5_clk_disable (qproc->dev, qproc->active_clks, qproc->active_clk_count);
@@ -1014,6 +1091,7 @@ static int q6v5_probe(struct platform_device *pdev)if (ret) goto free_rproc; + qproc->need_mem_protection = desc->need_mem_protection; ret =q6v5_request_irq (qproc, pdev,"wdog" , q6v5_wdog_interrupt);if (ret <0 ) goto free_rproc;
@@ -1089,6 +1167,7 @@ static int q6v5_remove(struct platform_device *pdev)"mem" ,NULL }, + .need_mem_protection = false, }; static const struct rproc_hexagon_res msm8974_mss = {
@@ -1126,6 +1205,7 @@ static int q6v5_remove(struct platform_device *pdev)"mem" ,NULL }, + .need_mem_protection = false, }; static const struct of_device_id q6v5_of_match[] = {
Signature · 2 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
PATCH v4 4/4 remoteproc: qcom: Add support for mss boot on msm8996
In reply to Avaneesh Kumar DwivediThis patch add support for mss boot on msm8996. Major changes include making appropriate change for executing mss reset sequence, adding private data initialization etc.
--- .../devicetree/bindings/remoteproc/qcom,q6v5.txt | 4 +- drivers/remoteproc/qcom_q6v5_pil.c | 171 ++++++++++++++++++--- 2 files changed, 150 insertions(+), 25 deletions(-)
Documentation/devicetree/bindings/remoteproc/qcom,q6v5.txt +2 -2
@@ -9,8 +9,8 @@ on the Qualcomm Hexagon core. Definition: must be one of: "qcom,q6v5-pil", "qcom,msm8916-mss-pil", - "qcom,msm8974-mss-pil" - + "qcom,msm8974-mss-pil", + "qcom,msm8996-mss-pil" - reg: Usage: required Value type: <prop-encoded-array>
drivers/remoteproc/qcom_q6v5_pil.c +148 -23
253 lines not on this page · raw message
Signature · 2 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.