diff --git a/drivers/soc/qcom/secure_buffer.c b/drivers/soc/qcom/secure_buffer.c index 5ee8f5833b1f..7d6d2ecdbdf6 100644 --- a/drivers/soc/qcom/secure_buffer.c +++ b/drivers/soc/qcom/secure_buffer.c @@ -286,6 +286,8 @@ const char *msm_secure_vmid_to_string(int secure_vmid) return "VMID_ADSP_HEAP"; case VMID_INVAL: return "VMID_INVAL"; + case VMID_NAV: + return "VMID_NAV"; default: return "Unknown VMID"; } diff --git a/drivers/uio/msm_sharedmem/msm_sharedmem.c b/drivers/uio/msm_sharedmem/msm_sharedmem.c index faced5a29d36..811dc2d3d634 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" @@ -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"); @@ -97,9 +109,12 @@ 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; + bool vm_nav_path = false; /* Get the addresses from platform-data */ if (!pdev->dev.of_node) { @@ -134,14 +149,39 @@ 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; } + /* + * 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. */ diff --git a/include/soc/qcom/secure_buffer.h b/include/soc/qcom/secure_buffer.h index b4627621b0fa..3c8b3c7146ee 100644 --- a/include/soc/qcom/secure_buffer.h +++ b/include/soc/qcom/secure_buffer.h @@ -35,6 +35,7 @@ enum vmid { VMID_CP_SPSS_HLOS_SHARED = 0x24, VMID_ADSP_HEAP = 0x25, VMID_CP_CDSP = 0x2A, + VMID_NAV = 0x2B, VMID_LAST, VMID_INVAL = -1 };