From patchwork Tue May 30 19:34:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 13261046 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83726C7EE32 for ; Tue, 30 May 2023 19:35:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233271AbjE3TfB (ORCPT ); Tue, 30 May 2023 15:35:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233215AbjE3Teu (ORCPT ); Tue, 30 May 2023 15:34:50 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45B0710B; Tue, 30 May 2023 12:34:48 -0700 (PDT) Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34UJPpLO018287; Tue, 30 May 2023 19:34:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=QS76EgvJjXKKaWmp7a7ub1P//dtgRXQ0pPsURfP1vFc=; b=HqGbWtkpcvwozky5HT7CXh09o2V8erkiNGzRcGzaiA2yZe2ie1gvBUBX3iiTlk/V+7sd wrPdLikNbePEl1+Pa4/atSV4Fm1FTFaHgiCKxn6blq7kidmOWsBYS5gqzFpCRNWKnGkq kjO22D3ZIqFI3RBxXQXpdWyP9ZUo7TGy33NjHFF5CVspRBXNbD4nQAX2O/GeRh/0FRsK XZsEdF1yFhHYGbuQuR1N8yHG8R3LaGrXYIjL7d1XH+uGF0gdVYQmTSEgrOuqqZSyg9mk Q3O+roI7vv7p69t+9Wq9TkWcLPfpgN/7H0vryKD1sEdYjw91heSMvNAtrMagGwbODxVo yg== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3qw7rtt23t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 30 May 2023 19:34:43 +0000 Received: from nalasex01c.na.qualcomm.com (nalasex01c.na.qualcomm.com [10.47.97.35]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 34UJYgxe014215 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 30 May 2023 19:34:42 GMT Received: from hu-bjorande-lv.qualcomm.com (10.49.16.6) by nalasex01c.na.qualcomm.com (10.47.97.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Tue, 30 May 2023 12:34:42 -0700 From: Bjorn Andersson To: Bjorn Andersson , Konrad Dybcio , Rob Herring , Krzysztof Kozlowski , Conor Dooley CC: , , Subject: [PATCH 1/2] dt-bindings: reserved-memory: rmtfs: Allow dynamic allocation Date: Tue, 30 May 2023 12:34:35 -0700 Message-ID: <20230530193436.3833889-2-quic_bjorande@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230530193436.3833889-1-quic_bjorande@quicinc.com> References: <20230530193436.3833889-1-quic_bjorande@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01c.na.qualcomm.com (10.47.97.35) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: kKuk1V_8slN4zQbiiBOigzMzPI2ngOdK X-Proofpoint-ORIG-GUID: kKuk1V_8slN4zQbiiBOigzMzPI2ngOdK X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-30_14,2023-05-30_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 spamscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 bulkscore=0 impostorscore=0 lowpriorityscore=0 adultscore=0 priorityscore=1501 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305300157 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Allow instances of the qcom,rmtfs-mem either be defined as a reserved-memory regoin, or just standalone given just a size. This relieve the DeviceTree source author the need to come up with a static memory region for the region. Signed-off-by: Bjorn Andersson --- .../reserved-memory/qcom,rmtfs-mem.yaml | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/reserved-memory/qcom,rmtfs-mem.yaml b/Documentation/devicetree/bindings/reserved-memory/qcom,rmtfs-mem.yaml index bab982f00485..8b5de033f9ac 100644 --- a/Documentation/devicetree/bindings/reserved-memory/qcom,rmtfs-mem.yaml +++ b/Documentation/devicetree/bindings/reserved-memory/qcom,rmtfs-mem.yaml @@ -14,13 +14,16 @@ description: | maintainers: - Bjorn Andersson -allOf: - - $ref: reserved-memory.yaml - properties: compatible: const: qcom,rmtfs-mem + qcom,alloc-size: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + Requested size of the rmtfs memory allocation, when not defined as a + reserved-memory region. + qcom,client-id: $ref: /schemas/types.yaml#/definitions/uint32 description: > @@ -36,6 +39,11 @@ properties: required: - qcom,client-id +oneOf: + - $ref: reserved-memory.yaml + - required: + - qcom,alloc-size + unevaluatedProperties: false examples: @@ -53,3 +61,12 @@ examples: qcom,client-id = <1>; }; }; + - | + rmtfs { + compatible = "qcom,rmtfs-mem"; + + qcom,alloc-size = <(2*1024*1024)>; + qcom,client-id = <1>; + qcom,vmid = <15>; + }; +... From patchwork Tue May 30 19:34:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 13261047 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C662C7EE2F for ; Tue, 30 May 2023 19:35:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233077AbjE3TfB (ORCPT ); Tue, 30 May 2023 15:35:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232648AbjE3Tet (ORCPT ); Tue, 30 May 2023 15:34:49 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB234BE; Tue, 30 May 2023 12:34:47 -0700 (PDT) Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34UJUK2e022992; Tue, 30 May 2023 19:34:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=mpiQCMZW0ekrzjHH3XqOVdBgVCerwNUa7fbHPWFc3w0=; b=cwmkFQVFM0fSFMol5lg5WiSWlDsUGibN+TNzI4IxMsKOVGeotSiIUxcTlRFE9tOdVb0B nRLzWczDpEOt1nsRgjbfjzt8Ccq2y9xdk02EWEWfc1aq+WY/HgAXk96sJy0j+5UvN3qc 0pWCVIJdVrNAeKFkp5uNL3069P8qVKy8Bur8v64wX+UO50lraWYCQ5C78Y8lHZONGqUz B9ilMC/TMr7l7FnzAI6LVa+TQgdE8aR/PARY4NpIvtxNZ6OLIhLFFwLN2ALQb/n8mQR4 GK5Ljz/EBf8RAucy3a8m2YAtprX9XrgEIuN3ACySCxhZ86Cs3OVgviczzH4WjogmoV8m /A== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3qwp69g54a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 30 May 2023 19:34:43 +0000 Received: from nalasex01c.na.qualcomm.com (nalasex01c.na.qualcomm.com [10.47.97.35]) by NALASPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 34UJYhhM023375 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 30 May 2023 19:34:43 GMT Received: from hu-bjorande-lv.qualcomm.com (10.49.16.6) by nalasex01c.na.qualcomm.com (10.47.97.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Tue, 30 May 2023 12:34:42 -0700 From: Bjorn Andersson To: Bjorn Andersson , Konrad Dybcio CC: Rob Herring , Krzysztof Kozlowski , Conor Dooley , , , Subject: [PATCH 2/2] soc: qcom: rmtfs: Support dynamic placement of region Date: Tue, 30 May 2023 12:34:36 -0700 Message-ID: <20230530193436.3833889-3-quic_bjorande@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230530193436.3833889-1-quic_bjorande@quicinc.com> References: <20230530193436.3833889-1-quic_bjorande@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01c.na.qualcomm.com (10.47.97.35) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: xGUzTctcTjN6jw_tTIYXeNywOv9BRaZJ X-Proofpoint-GUID: xGUzTctcTjN6jw_tTIYXeNywOv9BRaZJ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-30_14,2023-05-30_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 mlxscore=0 lowpriorityscore=0 malwarescore=0 suspectscore=0 spamscore=0 mlxlogscore=999 phishscore=0 adultscore=0 bulkscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305300158 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org In some configurations, the exact placement of the rmtfs shared memory region isn't so strict. In the current implementation the author of the DeviceTree source is forced to make up a memory region. Extend the rmtfs memory driver to relieve the author of this responsibility by introducing support for using dynamic allocation in the driver. Signed-off-by: Bjorn Andersson --- arch/arm64/boot/dts/qcom/sdm845-mtp.dts | 10 ++++ drivers/soc/qcom/rmtfs_mem.c | 66 +++++++++++++++++++------ 2 files changed, 61 insertions(+), 15 deletions(-) diff --git a/arch/arm64/boot/dts/qcom/sdm845-mtp.dts b/arch/arm64/boot/dts/qcom/sdm845-mtp.dts index d1440b790fa6..e6191b8ba4c6 100644 --- a/arch/arm64/boot/dts/qcom/sdm845-mtp.dts +++ b/arch/arm64/boot/dts/qcom/sdm845-mtp.dts @@ -12,6 +12,8 @@ #include "pm8998.dtsi" #include "pmi8998.dtsi" +/delete-node/ &rmtfs_mem; + / { model = "Qualcomm Technologies, Inc. SDM845 MTP"; compatible = "qcom,sdm845-mtp", "qcom,sdm845"; @@ -48,6 +50,14 @@ vreg_s4a_1p8: pm8998-smps4 { vin-supply = <&vph_pwr>; }; + rmtfs { + compatible = "qcom,rmtfs-mem"; + + qcom,alloc-size = <(2*1024*1024)>; + qcom,client-id = <1>; + qcom,vmid = <15>; + }; + thermal-zones { xo_thermal: xo-thermal { polling-delay-passive = <0>; diff --git a/drivers/soc/qcom/rmtfs_mem.c b/drivers/soc/qcom/rmtfs_mem.c index f83811f51175..5f56ded9f905 100644 --- a/drivers/soc/qcom/rmtfs_mem.c +++ b/drivers/soc/qcom/rmtfs_mem.c @@ -3,6 +3,8 @@ * Copyright (c) 2017 Linaro Ltd. */ +#include "linux/gfp_types.h" +#include "linux/sizes.h" #include #include #include @@ -168,23 +170,63 @@ static void qcom_rmtfs_mem_release_device(struct device *dev) kfree(rmtfs_mem); } +static int qcom_rmtfs_acquire_mem(struct device *dev, struct qcom_rmtfs_mem *rmtfs_mem) +{ + struct device_node *node = dev->of_node; + struct reserved_mem *rmem; + dma_addr_t dma_addr; + void *mem; + u32 size; + int ret; + + rmem = of_reserved_mem_lookup(node); + if (rmem) { + rmtfs_mem->addr = rmem->base; + rmtfs_mem->size = rmem->size; + + rmtfs_mem->base = devm_memremap(&rmtfs_mem->dev, rmtfs_mem->addr, + rmtfs_mem->size, MEMREMAP_WC); + if (IS_ERR(rmtfs_mem->base)) { + dev_err(dev, "failed to remap rmtfs_mem region\n"); + return PTR_ERR(rmtfs_mem->base); + } + + return 0; + } + + ret = of_property_read_u32(node, "qcom,alloc-size", &size); + if (ret < 0) { + dev_err(dev, "rmtfs of unknown size\n"); + return -EINVAL; + } + + /* + * Ensure that the protected region isn't adjacent to other protected + * regions by allocating an empty page on either side. + */ + mem = dma_alloc_coherent(dev, size + 2 * SZ_4K, &dma_addr, GFP_KERNEL); + if (mem) { + rmtfs_mem->base = mem + SZ_4K; + rmtfs_mem->addr = dma_addr + SZ_4K; + rmtfs_mem->size = size; + + return 0; + } + + dev_err(dev, "unable to allocate memory for rmtfs mem\n"); + return -ENOMEM; +} + static int qcom_rmtfs_mem_probe(struct platform_device *pdev) { struct device_node *node = pdev->dev.of_node; struct qcom_scm_vmperm perms[NUM_MAX_VMIDS + 1]; - struct reserved_mem *rmem; struct qcom_rmtfs_mem *rmtfs_mem; u32 client_id; u32 vmid[NUM_MAX_VMIDS]; int num_vmids; int ret, i; - rmem = of_reserved_mem_lookup(node); - if (!rmem) { - dev_err(&pdev->dev, "failed to acquire memory region\n"); - return -EINVAL; - } - ret = of_property_read_u32(node, "qcom,client-id", &client_id); if (ret) { dev_err(&pdev->dev, "failed to parse \"qcom,client-id\"\n"); @@ -196,22 +238,16 @@ static int qcom_rmtfs_mem_probe(struct platform_device *pdev) if (!rmtfs_mem) return -ENOMEM; - rmtfs_mem->addr = rmem->base; rmtfs_mem->client_id = client_id; - rmtfs_mem->size = rmem->size; device_initialize(&rmtfs_mem->dev); rmtfs_mem->dev.parent = &pdev->dev; rmtfs_mem->dev.groups = qcom_rmtfs_mem_groups; rmtfs_mem->dev.release = qcom_rmtfs_mem_release_device; - rmtfs_mem->base = devm_memremap(&rmtfs_mem->dev, rmtfs_mem->addr, - rmtfs_mem->size, MEMREMAP_WC); - if (IS_ERR(rmtfs_mem->base)) { - dev_err(&pdev->dev, "failed to remap rmtfs_mem region\n"); - ret = PTR_ERR(rmtfs_mem->base); + ret = qcom_rmtfs_acquire_mem(&pdev->dev, rmtfs_mem); + if (ret < 0) goto put_device; - } cdev_init(&rmtfs_mem->cdev, &qcom_rmtfs_mem_fops); rmtfs_mem->cdev.owner = THIS_MODULE;