From 87d724a4870f844d99e3a3861ae68e51a0e14f95 Mon Sep 17 00:00:00 2001 From: Sahitya Tummala Date: Thu, 5 Oct 2017 14:39:40 +0530 Subject: [PATCH 1/3] uio: msm_sharedmem: add guard page around shared memory If guard_memory dtsi property is set, then the shared memory region will be guarded by SZ_4K at the start and at the end. This is needed to overcome the XPU limitation on few MSM HW, so as to make this memory not contiguous with other allocations that may possibly happen from other clients in the system. Change-Id: I57637619cea8fe7f0f7254624e07177ea4a4fce0 Signed-off-by: Sahitya Tummala --- drivers/uio/msm_sharedmem/msm_sharedmem.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/uio/msm_sharedmem/msm_sharedmem.c b/drivers/uio/msm_sharedmem/msm_sharedmem.c index faced5a29d36..329688e39417 100644 --- a/drivers/uio/msm_sharedmem/msm_sharedmem.c +++ b/drivers/uio/msm_sharedmem/msm_sharedmem.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2015-2019, The Linux Foundation. All rights reserved. + * Copyright (c) 2015-2020, The Linux Foundation. All rights reserved. */ #define DRIVER_NAME "msm_sharedmem" @@ -97,9 +97,11 @@ static int msm_sharedmem_probe(struct platform_device *pdev) struct resource *clnt_res = NULL; u32 client_id = ((u32)~0U); u32 shared_mem_size = 0; + u32 shared_mem_tot_sz = 0; void *shared_mem = NULL; phys_addr_t shared_mem_pyhsical = 0; bool is_addr_dynamic = false; + bool guard_memory = false; /* Get the addresses from platform-data */ if (!pdev->dev.of_node) { @@ -134,10 +136,27 @@ static int msm_sharedmem_probe(struct platform_device *pdev) if (shared_mem_pyhsical == 0) { is_addr_dynamic = true; - shared_mem = dma_alloc_coherent(&pdev->dev, shared_mem_size, + + /* + * If guard_memory is set, then the shared memory region + * will be guarded by SZ_4K at the start and at the end. + * This is needed to overcome the XPU limitation on few + * MSM HW, so as to make this memory not contiguous with + * other allocations that may possibly happen from other + * clients in the system. + */ + guard_memory = of_property_read_bool(pdev->dev.of_node, + "qcom,guard-memory"); + + shared_mem_tot_sz = guard_memory ? shared_mem_size + SZ_8K : + shared_mem_size; + + shared_mem = dma_alloc_coherent(&pdev->dev, shared_mem_tot_sz, &shared_mem_pyhsical, GFP_KERNEL); if (shared_mem == NULL) return -ENOMEM; + if (guard_memory) + shared_mem_pyhsical += SZ_4K; } /* Set up the permissions for the shared ram that was allocated. */ From a980ed9830721bad4cc5ec7b1172fe55e58d35de Mon Sep 17 00:00:00 2001 From: Sridhar Arra Date: Wed, 31 Jul 2019 16:50:41 +0530 Subject: [PATCH 2/3] soc: qcom: secure_buffer: add support for VMID_NAV Add support for VMID_NAV and shared memory region will be given access to vm-nav-path also. Change-Id: I9798e095a1f8bb7a76abcc0ec0949ff26989ad6f Signed-off-by: Sridhar Arra Signed-off-by: Sahitya Tummala --- drivers/soc/qcom/secure_buffer.c | 2 ++ include/soc/qcom/secure_buffer.h | 1 + 2 files changed, 3 insertions(+) diff --git a/drivers/soc/qcom/secure_buffer.c b/drivers/soc/qcom/secure_buffer.c index e19919583c4d..83637675b322 100644 --- a/drivers/soc/qcom/secure_buffer.c +++ b/drivers/soc/qcom/secure_buffer.c @@ -282,6 +282,8 @@ const char *msm_secure_vmid_to_string(int secure_vmid) return "VMID_CP_SPSS_HLOS_SHARED"; case VMID_INVAL: return "VMID_INVAL"; + case VMID_NAV: + return "VMID_NAV"; default: return "Unknown VMID"; } diff --git a/include/soc/qcom/secure_buffer.h b/include/soc/qcom/secure_buffer.h index c69a97783a3e..510b020d9603 100644 --- a/include/soc/qcom/secure_buffer.h +++ b/include/soc/qcom/secure_buffer.h @@ -33,6 +33,7 @@ enum vmid { VMID_CP_SPSS_SP_SHARED = 0x22, VMID_CP_SPSS_HLOS_SHARED = 0x24, VMID_CP_CDSP = 0x2A, + VMID_NAV = 0x2B, VMID_LAST, VMID_INVAL = -1 }; From 2504614ed45b027ee189ba8bad47be6d3db41e39 Mon Sep 17 00:00:00 2001 From: Sridhar Arra Date: Mon, 25 Nov 2019 16:17:12 +0530 Subject: [PATCH 3/3] uio: msm_sharedmem: shared memory region access is also given to vm-nav If vm-nav-path dtsi property is set, then the shared memory region will be given access to vm-nav-path also. Change-Id: I0aef894dbee78c2e3d7d67f61a238a889050037a Signed-off-by: Sridhar Arra Signed-off-by: Sahitya Tummala --- drivers/uio/msm_sharedmem/msm_sharedmem.c | 37 ++++++++++++++++++----- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/drivers/uio/msm_sharedmem/msm_sharedmem.c b/drivers/uio/msm_sharedmem/msm_sharedmem.c index 329688e39417..811dc2d3d634 100644 --- a/drivers/uio/msm_sharedmem/msm_sharedmem.c +++ b/drivers/uio/msm_sharedmem/msm_sharedmem.c @@ -66,21 +66,33 @@ static int sharedmem_mmap(struct uio_info *info, struct vm_area_struct *vma) } /* Setup the shared ram permissions. - * This function currently supports the mpss client only. + * This function currently supports the mpss and nav clients only. */ -static void setup_shared_ram_perms(u32 client_id, phys_addr_t addr, u32 size) +static void setup_shared_ram_perms(u32 client_id, phys_addr_t addr, u32 size, + bool vm_nav_path) { int ret; u32 source_vmlist[1] = {VMID_HLOS}; - int dest_vmids[2] = {VMID_HLOS, VMID_MSS_MSA}; - int dest_perms[2] = {PERM_READ|PERM_WRITE, - PERM_READ|PERM_WRITE}; if (client_id != MPSS_RMTS_CLIENT_ID) return; - ret = hyp_assign_phys(addr, size, source_vmlist, 1, dest_vmids, - dest_perms, 2); + if (vm_nav_path) { + int dest_vmids[3] = {VMID_HLOS, VMID_MSS_MSA, VMID_NAV}; + int dest_perms[3] = {PERM_READ|PERM_WRITE, + PERM_READ|PERM_WRITE, + PERM_READ|PERM_WRITE}; + + ret = hyp_assign_phys(addr, size, source_vmlist, 1, dest_vmids, + dest_perms, 3); + } else { + int dest_vmids[2] = {VMID_HLOS, VMID_MSS_MSA}; + int dest_perms[2] = {PERM_READ|PERM_WRITE, + PERM_READ|PERM_WRITE}; + + ret = hyp_assign_phys(addr, size, source_vmlist, 1, dest_vmids, + dest_perms, 2); + } if (ret != 0) { if (ret == -EINVAL) pr_warn("hyp_assign_phys is not supported!\n"); @@ -102,6 +114,7 @@ static int msm_sharedmem_probe(struct platform_device *pdev) phys_addr_t shared_mem_pyhsical = 0; bool is_addr_dynamic = false; bool guard_memory = false; + bool vm_nav_path = false; /* Get the addresses from platform-data */ if (!pdev->dev.of_node) { @@ -159,8 +172,16 @@ static int msm_sharedmem_probe(struct platform_device *pdev) shared_mem_pyhsical += SZ_4K; } + /* + * If this dtsi property is set, then the shared memory region + * will be given access to vm-nav-path also. + */ + vm_nav_path = of_property_read_bool(pdev->dev.of_node, + "qcom,vm-nav-path"); + /* Set up the permissions for the shared ram that was allocated. */ - setup_shared_ram_perms(client_id, shared_mem_pyhsical, shared_mem_size); + setup_shared_ram_perms(client_id, shared_mem_pyhsical, shared_mem_size, + vm_nav_path); /* Setup device */ info->mmap = sharedmem_mmap; /* Custom mmap function. */