From 8251ad9787f8836b2777d5c31d733c26145daf2c Mon Sep 17 00:00:00 2001 From: Sahitya Tummala Date: Thu, 5 Oct 2017 14:39:40 +0530 Subject: [PATCH] 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 Signed-off-by: Richard Patrick Signed-off-by: Sayali Lokhande --- 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 4bb1e83ebd54..a31f94cf9c20 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-2016, The Linux Foundation. All rights reserved. + * Copyright (c) 2015-2017, 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. */