From patchwork Fri May 12 12:21:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Komal Bajaj X-Patchwork-Id: 93157 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp5061242vqo; Fri, 12 May 2023 05:26:11 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7SFWoq6pgY/4Hbned6L+SHJ8C15MmSkCbEo4YH2uf23K84M8+e/NCQvh1q3Bf3qS4wyhw+ X-Received: by 2002:a05:6a20:e68e:b0:103:8f9a:8743 with SMTP id mz14-20020a056a20e68e00b001038f9a8743mr8161584pzb.43.1683894371020; Fri, 12 May 2023 05:26:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683894371; cv=none; d=google.com; s=arc-20160816; b=WssDlDtjD+0vlaFb/41b0exFgd+2WoA21TAoEK1WMpBbVN+xxU4g74Cr2no24XUdb8 wJoDDDNKzgvNr/mi09bRjvrnSfhSH5vUsEH5X2MMfgHbU/oSZJlZvcbfYgnNWyiCUq9M RXkdVmWO1K6oWsm7SxX4Hky57FoyfOcMqyr44xhD1pKetYYHJUH2cInOMajyrCzMaGCb YJSA/AEGtZTDOUaAvC5VNr/JywVVpyUx867oeZ3UQZr6zotp3+j3NsdPvU56ugiXZ6gO 5IRh80CROTIt8XO2mCxcHlea0sxNwdfsErckleWVpd3mbO00r9JsEXFOEUhhVbKaJKa7 NSXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=+LndOLhgaboh2RsKKF5Vywj7MYfEohnX8f2bSvtXnJc=; b=H7CnNVj31bnoREOc3R0jIgvNOey0Ma9fqHr3OQbNP0+GWvlLE12PmEZK2gO9a6LIcf n9etO+DxkXKNhVJMDNo3Y+f4/uXegMpZrlDNtTk7lWv+oYNKqsLktW9BclvqSub0x5+9 Ny/QvH6lhaPBaWGc2PUe8eWcocUh/Svty4mYVst/EkwSUBwv+5YFcW4UjgsD5vjI5tix MjPM6W/GB5zuOLLfHi5APbddafJ6IsWN9FWoj+YsdURwdu4oTOnVqBlpuEtXkGKnkV8+ 4/o8ZbvOe6s+duGrBulJthpdd4btPSHnnbqXI6Agm/T/V0ZzVYDczxyr5krRtLVo2b9+ H2qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=hzvElVH8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t9-20020a639549000000b00528a9f56705si8734376pgn.602.2023.05.12.05.25.56; Fri, 12 May 2023 05:26:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=hzvElVH8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240724AbjELMVz (ORCPT + 99 others); Fri, 12 May 2023 08:21:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240683AbjELMVx (ORCPT ); Fri, 12 May 2023 08:21:53 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E2E5D059; Fri, 12 May 2023 05:21:52 -0700 (PDT) Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34CBoaKT025544; Fri, 12 May 2023 12:21:49 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; s=qcppdkim1; bh=+LndOLhgaboh2RsKKF5Vywj7MYfEohnX8f2bSvtXnJc=; b=hzvElVH8/qg6QZp0u/YZl9uFAMQYN+YcgqxcIdDARHGVHklcAKWsuK6/6eO6Z09X4Val fROG3aJ1eeHtywLgUaEKyu5Yff6ljMkqsEz2iWDhkyTVW1rKLVumpfTjN1/mYUitbBXL v7FnODiorGuJaLqJa2G/oglHUCZo50C6pridnaMSP5ysedvw1hRb+mmh36oku/Yzkus9 1cPt4AcIm6lEfpFBLwf5VxV/PH/Ry16VPnHMymxUJikYNjBMusnv4Yz6RADACS92ZMsx /HTdoKofCFNuAUx9Ab2Z+FZHlUAhqGWhhld4GvE2We5Uyck1IdQy64HOK8vo/yQr530H 7Q== Received: from apblrppmta01.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com [103.229.18.19]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3qh8hm1hgn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 12 May 2023 12:21:48 +0000 Received: from pps.filterd (APBLRPPMTA01.qualcomm.com [127.0.0.1]) by APBLRPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTP id 34CCLj5V028989; Fri, 12 May 2023 12:21:45 GMT Received: from pps.reinject (localhost [127.0.0.1]) by APBLRPPMTA01.qualcomm.com (PPS) with ESMTP id 3qdy59u1un-1; Fri, 12 May 2023 12:21:45 +0000 Received: from APBLRPPMTA01.qualcomm.com (APBLRPPMTA01.qualcomm.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34CCLi9Y028984; Fri, 12 May 2023 12:21:45 GMT Received: from hu-maiyas-hyd.qualcomm.com (hu-kbajaj-hyd.qualcomm.com [10.147.247.189]) by APBLRPPMTA01.qualcomm.com (PPS) with ESMTP id 34CCLiUn028983; Fri, 12 May 2023 12:21:44 +0000 Received: by hu-maiyas-hyd.qualcomm.com (Postfix, from userid 2340697) id 353AC52974D; Fri, 12 May 2023 17:51:44 +0530 (+0530) From: Komal Bajaj To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Rob Herring , Krzysztof Kozlowski , Srinivas Kandagatla , Conor Dooley Cc: Komal Bajaj , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v3 01/10] nvmem: qfprom: Add support for secure reading Date: Fri, 12 May 2023 17:51:25 +0530 Message-Id: <20230512122134.24339-2-quic_kbajaj@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230512122134.24339-1-quic_kbajaj@quicinc.com> References: <20230512122134.24339-1-quic_kbajaj@quicinc.com> X-QCInternal: smtphost X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: Tj4wnpfm4LZLj-oioTeMjT-Mx1gp-aLE X-Proofpoint-ORIG-GUID: Tj4wnpfm4LZLj-oioTeMjT-Mx1gp-aLE X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-12_08,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 lowpriorityscore=0 mlxscore=0 malwarescore=0 bulkscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 spamscore=0 adultscore=0 impostorscore=0 clxscore=1011 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305120103 X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765691223802323225?= X-GMAIL-MSGID: =?utf-8?q?1765691223802323225?= For some of the Qualcomm SoC's, it is possible that some of the fuse regions or entire qfprom region is protected from non-secure access. In such situations, linux will have to use secure calls to read the region. With that motivation, add the support of reading secure regions in qfprom driver. Ensuring the address to read is word aligned since our secure I/O only supports word size I/O. Signed-off-by: Komal Bajaj --- drivers/nvmem/Kconfig | 1 + drivers/nvmem/qfprom.c | 69 +++++++++++++++++++++++++++++++++--------- 2 files changed, 55 insertions(+), 15 deletions(-) -- 2.17.1 diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig index b291b27048c7..3d896ba29b89 100644 --- a/drivers/nvmem/Kconfig +++ b/drivers/nvmem/Kconfig @@ -209,6 +209,7 @@ config NVMEM_QCOM_QFPROM tristate "QCOM QFPROM Support" depends on ARCH_QCOM || COMPILE_TEST depends on HAS_IOMEM + select QCOM_SCM help Say y here to enable QFPROM support. The QFPROM provides access functions for QFPROM data to rest of the drivers via nvmem interface. diff --git a/drivers/nvmem/qfprom.c b/drivers/nvmem/qfprom.c index c1e893c8a247..20662e2d3732 100644 --- a/drivers/nvmem/qfprom.c +++ b/drivers/nvmem/qfprom.c @@ -16,6 +16,7 @@ #include #include #include +#include /* Blow timer clock frequency in Mhz */ #define QFPROM_BLOW_TIMER_OFFSET 0x03c @@ -59,21 +60,22 @@ struct qfprom_soc_data { /** * struct qfprom_priv - structure holding qfprom attributes * - * @qfpraw: iomapped memory space for qfprom-efuse raw address space. - * @qfpconf: iomapped memory space for qfprom-efuse configuration address - * space. + * @qfpraw: iomapped memory space for qfprom-efuse raw address space. + * @qfpconf: iomapped memory space for qfprom-efuse configuration address space. * @qfpcorrected: iomapped memory space for qfprom corrected address space. - * @qfpsecurity: iomapped memory space for qfprom security control space. - * @dev: qfprom device structure. - * @secclk: Clock supply. - * @vcc: Regulator supply. - * @soc_data: Data that for things that varies from SoC to SoC. + * @qfpsecurity: iomapped memory space for qfprom security control space. + * @qfpseccorrected: starting physical address for qfprom secure corrected address space. + * @dev: qfprom device structure. + * @secclk: Clock supply. + * @vcc: Regulator supply. + * @soc_data: Data that for things that varies from SoC to SoC. */ struct qfprom_priv { void __iomem *qfpraw; void __iomem *qfpconf; void __iomem *qfpcorrected; void __iomem *qfpsecurity; + phys_addr_t qfpseccorrected; struct device *dev; struct clk *secclk; struct regulator *vcc; @@ -99,10 +101,12 @@ struct qfprom_touched_values { * * @keepout: Array of keepout regions for this SoC. * @nkeepout: Number of elements in the keepout array. + * @secure: Is qfprom region for this SoC protected from non-secure access. */ struct qfprom_soc_compatible_data { const struct nvmem_keepout *keepout; unsigned int nkeepout; + bool secure; }; static const struct nvmem_keepout sc7180_qfprom_keepout[] = { @@ -334,6 +338,34 @@ static int qfprom_reg_read(void *context, return 0; } +static int qfprom_sec_reg_read(void *context, unsigned int reg, void *_val, size_t bytes) +{ + struct qfprom_priv *priv = context; + u8 *val = _val; + int buf_start, buf_end, index, i = 0; + char *buffer; + u32 read_val; + + buf_start = ALIGN_DOWN(reg, 4); + buf_end = ALIGN(reg + bytes, 4); + buffer = kzalloc(buf_end - buf_start, GFP_KERNEL); + if (!buffer) + return -ENOMEM; + + for (index = buf_start; index < buf_end; index += 4, i += 4) { + if (qcom_scm_io_readl(priv->qfpseccorrected + index, &read_val)) { + dev_err(priv->dev, "Couldn't access feature register\n"); + kfree_sensitive(buffer); + return -EINVAL; + } + memcpy(buffer + i, &read_val, 4); + } + + memcpy(val, buffer + reg % 4, bytes); + kfree_sensitive(buffer); + return 0; +} + static void qfprom_runtime_disable(void *data) { pm_runtime_disable(data); @@ -373,13 +405,6 @@ static int qfprom_probe(struct platform_device *pdev) if (!priv) return -ENOMEM; - /* The corrected section is always provided */ - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - priv->qfpcorrected = devm_ioremap_resource(dev, res); - if (IS_ERR(priv->qfpcorrected)) - return PTR_ERR(priv->qfpcorrected); - - econfig.size = resource_size(res); econfig.dev = dev; econfig.priv = priv; @@ -390,6 +415,20 @@ static int qfprom_probe(struct platform_device *pdev) econfig.nkeepout = soc_data->nkeepout; } + /* The corrected section is always provided */ + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + + if (soc_data && soc_data->secure) { + priv->qfpseccorrected = res->start; + econfig.reg_read = qfprom_sec_reg_read; + } else { + priv->qfpcorrected = devm_ioremap_resource(dev, res); + if (IS_ERR(priv->qfpcorrected)) + return PTR_ERR(priv->qfpcorrected); + } + + econfig.size = resource_size(res); + /* * If more than one region is provided then the OS has the ability * to write.