Message ID | 1679070482-8391-2-git-send-email-quic_mojha@quicinc.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp442208wrt; Fri, 17 Mar 2023 09:41:40 -0700 (PDT) X-Google-Smtp-Source: AK7set8VElY7aNfdifYnSalMV1MgUzAwgfz8CfXmQ20eRIfJiQ1ijbgPqSB+ic2OR5ro0GVdZ0IA X-Received: by 2002:a17:90a:4ca4:b0:23d:1bef:8594 with SMTP id k33-20020a17090a4ca400b0023d1bef8594mr6950097pjh.1.1679071300078; Fri, 17 Mar 2023 09:41:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679071300; cv=none; d=google.com; s=arc-20160816; b=rWY+/b+z5sJkq9By1xR7yfC8rTv7wHzo7fu5b47Jk174gUOffzI/wJgBzurSk2/LS1 fFzfKvzwTUjhck5eOQA5Pt20zE4MIv+OOpdU7JE+Mm7Pu3UVpXfNXdoUdRZTfvnRQ67+ TUwce7CxLB543J5OWUtMImb0wFUTTjbjoDwE7ob3w+QDztrhjzO+dR8IcYBEbsxYxcdw gvG29EMdq4tkMkO+7KhsICXFpQhc9N9uiPYcJs84+zCfbgtnYan9uKaMCkAqO4FLBDEO V789ABS3WJX+a3KHb1Emjy9EaW81EzRi3plidTF4jfrG5uSPhR1/URDxxihtcEsrlGS2 KuLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=nkBsAZfODivvEozfpAZNG7SNQg7Qpw0wy0KI5RRCxaw=; b=S31gm8OOi7zOuclfI2mg50agQj8VqLAyMJP6QHuXBFIyONzXUgiONgt2ukvnz+YTnu uro+loLVOPs4wsn6ZOu67gXTKO+mmiFsJVz8CTlqAOufVQiUPVEWjD9ll4KehMToMFrA s9gpQJ/WwOHrxYD3/EtTBnlUZ7ytG6jak/J3RATfnSwe6LwAmoPl3EXu9hy7CN5W7Wpk SXpes63NT8YPWePbjOPy+UgyHKpm5ubpnE4UPf3MjGX27VmNAl19lW4DYIFOs+peSxZ3 L7ujNuCuUH/Aa0CDlIQiPXW9f6gFFzMhvzwlI+86EAGkZWdlEBPtufDxn/bVWYf6HMuw XNJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=e8X6xN0p; 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 cu6-20020a17090afa8600b00215dedefc32si2516077pjb.163.2023.03.17.09.41.27; Fri, 17 Mar 2023 09:41:40 -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=e8X6xN0p; 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 S230011AbjCQQ2w (ORCPT <rfc822;chrisfriedt@gmail.com> + 99 others); Fri, 17 Mar 2023 12:28:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229599AbjCQQ2q (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 17 Mar 2023 12:28:46 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C0ED4E5F7; Fri, 17 Mar 2023 09:28:32 -0700 (PDT) Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32H90I3q017582; Fri, 17 Mar 2023 16:28:29 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-type; s=qcppdkim1; bh=nkBsAZfODivvEozfpAZNG7SNQg7Qpw0wy0KI5RRCxaw=; b=e8X6xN0p18Ikao4Ni+u0cMFOpLXbogh/pfvGYK3yQkJG5iw1u7iT0Od7OTF3UsVRurgt nZK+dGKQjdtXrMnwgKYQow00u5CDFk2HWjuK8EweKzT3u7MbCcaazzQACnq3U8RJQs6v 5A63KVKQ3FozEWyzaK3WI6aT7dhWoWEeewqZnKkeYiSDy2dYl1hd+7OEocgCxuz0ZwqA rLPsHrbr7fQLi2J+pVunors3xkzCMbOqfKyLYmNFXKREFptRSNJkEP1+Mo85yGEg1bUz FbLRSX272XKMw2YiKH31lmwb68v+vgydSUXFjUTXy2gzdHztuyaf0y45VDBxEH3JeLZz aw== Received: from nasanppmta03.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3pcn6f1hhb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 17 Mar 2023 16:28:29 +0000 Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 32HGSSu8016728 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 17 Mar 2023 16:28:28 GMT Received: from hu-mojha-hyd.qualcomm.com (10.80.80.8) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Fri, 17 Mar 2023 09:28:26 -0700 From: Mukesh Ojha <quic_mojha@quicinc.com> To: <agross@kernel.org>, <andersson@kernel.org>, <konrad.dybcio@linaro.org>, <linus.walleij@linaro.org> CC: <linux-arm-msm@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <linux-gpio@vger.kernel.org>, Mukesh Ojha <quic_mojha@quicinc.com> Subject: [PATCH v3 1/5] firmware: qcom_scm: provide a read-modify-write function Date: Fri, 17 Mar 2023 21:57:58 +0530 Message-ID: <1679070482-8391-2-git-send-email-quic_mojha@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1679070482-8391-1-git-send-email-quic_mojha@quicinc.com> References: <1679070482-8391-1-git-send-email-quic_mojha@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: uUt2XbfI64IbJNjCfQHJ4ig6XrSdfnhm X-Proofpoint-ORIG-GUID: uUt2XbfI64IbJNjCfQHJ4ig6XrSdfnhm 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-03-17_10,2023-03-16_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 adultscore=0 priorityscore=1501 spamscore=0 clxscore=1015 suspectscore=0 malwarescore=0 mlxlogscore=601 lowpriorityscore=0 impostorscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303150002 definitions=main-2303170110 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760633867354635097?= X-GMAIL-MSGID: =?utf-8?q?1760633867354635097?= |
Series |
Refactor to support multiple download mode
|
|
Commit Message
Mukesh Ojha
March 17, 2023, 4:27 p.m. UTC
It was released by Srinivas K. that there is a need of
read-modify-write scm exported function so that it can
be used by multiple clients.
Let's introduce qcom_scm_io_update_field() which masks
out the bits and write the passed value to that
bit-offset. Subsequent patch will use this function.
Suggested-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Mukesh Ojha <quic_mojha@quicinc.com>
---
drivers/firmware/qcom_scm.c | 15 +++++++++++++++
include/linux/firmware/qcom/qcom_scm.h | 2 ++
2 files changed, 17 insertions(+)
Comments
On 3/17/2023 9:57 PM, Mukesh Ojha wrote: > It was released by Srinivas K. that there is a need of Typo: s/released/realized -- Mukesh > read-modify-write scm exported function so that it can > be used by multiple clients. > > Let's introduce qcom_scm_io_update_field() which masks > out the bits and write the passed value to that > bit-offset. Subsequent patch will use this function. > > Suggested-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> > Signed-off-by: Mukesh Ojha <quic_mojha@quicinc.com> > --- > drivers/firmware/qcom_scm.c | 15 +++++++++++++++ > include/linux/firmware/qcom/qcom_scm.h | 2 ++ > 2 files changed, 17 insertions(+) > > diff --git a/drivers/firmware/qcom_scm.c b/drivers/firmware/qcom_scm.c > index 3e020d1..aca2556 100644 > --- a/drivers/firmware/qcom_scm.c > +++ b/drivers/firmware/qcom_scm.c > @@ -407,6 +407,21 @@ int qcom_scm_set_remote_state(u32 state, u32 id) > } > EXPORT_SYMBOL(qcom_scm_set_remote_state); > > +int qcom_scm_io_update_field(phys_addr_t addr, unsigned int mask, unsigned int val) > +{ > + unsigned int old, new; > + int ret; > + > + ret = qcom_scm_io_readl(addr, &old); > + if (ret) > + return ret; > + > + new = (old & ~mask) | val; > + > + return qcom_scm_io_writel(addr, new); > +} > +EXPORT_SYMBOL(qcom_scm_io_update_field); > + > static int __qcom_scm_set_dload_mode(struct device *dev, bool enable) > { > struct qcom_scm_desc desc = { > diff --git a/include/linux/firmware/qcom/qcom_scm.h b/include/linux/firmware/qcom/qcom_scm.h > index 1e449a5..203a781 100644 > --- a/include/linux/firmware/qcom/qcom_scm.h > +++ b/include/linux/firmware/qcom/qcom_scm.h > @@ -84,6 +84,8 @@ extern bool qcom_scm_pas_supported(u32 peripheral); > > extern int qcom_scm_io_readl(phys_addr_t addr, unsigned int *val); > extern int qcom_scm_io_writel(phys_addr_t addr, unsigned int val); > +extern int qcom_scm_io_update_field(phys_addr_t addr, unsigned int mask, > + unsigned int val); > > extern bool qcom_scm_restore_sec_cfg_available(void); > extern int qcom_scm_restore_sec_cfg(u32 device_id, u32 spare);
On Fri, Mar 17, 2023 at 5:28 PM Mukesh Ojha <quic_mojha@quicinc.com> wrote: > It was released by Srinivas K. that there is a need of > read-modify-write scm exported function so that it can > be used by multiple clients. > > Let's introduce qcom_scm_io_update_field() which masks > out the bits and write the passed value to that > bit-offset. Subsequent patch will use this function. > > Suggested-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> > Signed-off-by: Mukesh Ojha <quic_mojha@quicinc.com> This is starting to reimplement regmap. In this case regmap_update_bits(). What about just using regmap as accessor for these registers instead? Yours, Linus Walleij
On Fri, Mar 17, 2023 at 09:56:59PM +0100, Linus Walleij wrote: > On Fri, Mar 17, 2023 at 5:28 PM Mukesh Ojha <quic_mojha@quicinc.com> wrote: > > > It was released by Srinivas K. that there is a need of > > read-modify-write scm exported function so that it can > > be used by multiple clients. > > > > Let's introduce qcom_scm_io_update_field() which masks > > out the bits and write the passed value to that > > bit-offset. Subsequent patch will use this function. > > > > Suggested-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> > > Signed-off-by: Mukesh Ojha <quic_mojha@quicinc.com> > > This is starting to reimplement regmap. > In this case regmap_update_bits(). > > What about just using regmap as accessor for these > registers instead? > I'm not sure it would be beneficial... The regmap interface provides a standardized representation of a block of registers, with the suitable accessors backing it. But in both cases touched upon in this series, the addressed registers are part of regions already handled by the kernel. So it wouldn't be suitable to create a regmap-abstraction for "a block of secure registers", at best that would give us two kinds of regmaps abstracting the same register block. Instead I believe we'd need to extend the struct regmap_config to introduce a new table telling a new secure-or-unsecure-mmio-regmap which accessor (secure or unsecure read/write) shoudl be used, and then have e.g. pinctrl-msm register such regmap, passing the information about which registers in its memory region is secure. We'd still need qcom_scm_io_readl() and qcom_scm_io_writel() exported to implement the new custom regmap implementation - and the struct regmap_config needed in just pinctrl-msm alone would be larger than the one function it replaces. But please let me know if I'm missing something? Regards, Bjorn
On Mon, Mar 20, 2023 at 4:19 AM Bjorn Andersson <andersson@kernel.org> wrote: > > This is starting to reimplement regmap. > > In this case regmap_update_bits(). > > > > What about just using regmap as accessor for these > > registers instead? > > > > I'm not sure it would be beneficial... Me neither, I don't know the details, I just notice the similarity in the accessors. > The regmap interface provides a standardized representation of a block > of registers, with the suitable accessors backing it. But in both cases > touched upon in this series, the addressed registers are part of regions > already handled by the kernel. > > So it wouldn't be suitable to create a regmap-abstraction for "a block > of secure registers", at best that would give us two kinds of regmaps > abstracting the same register block. From my viewpoint regmap does three things: - Abstract one coherent region of registers under a shared lock, with nifty accessors (such as mask-and-set with regmap_update_bits()) - Maps access patterns/permissions and permissible access range - Optionally cache the contents The way I would use it if these secure registers are in the same range as a bunch of non-secure ones is for sharing a lock and the regmap accessors. I wouldn't worry about access patterns and such. That usecase (block access to certain registers or bits) is partly overdesign in some cases IMO. If regmap abstraction isn't helpful overall then we shouldn't do it. Yours, Linus Walleij
On 17/03/2023 16:27, Mukesh Ojha wrote: > It was released by Srinivas K. that there is a need of > read-modify-write scm exported function so that it can > be used by multiple clients. > > Let's introduce qcom_scm_io_update_field() which masks > out the bits and write the passed value to that > bit-offset. Subsequent patch will use this function. > > Suggested-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> > Signed-off-by: Mukesh Ojha <quic_mojha@quicinc.com> > --- > drivers/firmware/qcom_scm.c | 15 +++++++++++++++ > include/linux/firmware/qcom/qcom_scm.h | 2 ++ > 2 files changed, 17 insertions(+) > > diff --git a/drivers/firmware/qcom_scm.c b/drivers/firmware/qcom_scm.c > index 3e020d1..aca2556 100644 > --- a/drivers/firmware/qcom_scm.c > +++ b/drivers/firmware/qcom_scm.c > @@ -407,6 +407,21 @@ int qcom_scm_set_remote_state(u32 state, u32 id) > } > EXPORT_SYMBOL(qcom_scm_set_remote_state); > > +int qcom_scm_io_update_field(phys_addr_t addr, unsigned int mask, unsigned int val) > +{ > + unsigned int old, new; > + int ret; > + > + ret = qcom_scm_io_readl(addr, &old); > + if (ret) > + return ret; > + > + new = (old & ~mask) | val; thanks for doing this, With field semantics, val should be shifted within the function, so the caller only sets value for field rather than passing a shifted value. so this should be: new = (old & ~mask) | (val << ffs(mask) - 1); --srini > + > + return qcom_scm_io_writel(addr, new); > +} > +EXPORT_SYMBOL(qcom_scm_io_update_field); > + > static int __qcom_scm_set_dload_mode(struct device *dev, bool enable) > { > struct qcom_scm_desc desc = { > diff --git a/include/linux/firmware/qcom/qcom_scm.h b/include/linux/firmware/qcom/qcom_scm.h > index 1e449a5..203a781 100644 > --- a/include/linux/firmware/qcom/qcom_scm.h > +++ b/include/linux/firmware/qcom/qcom_scm.h > @@ -84,6 +84,8 @@ extern bool qcom_scm_pas_supported(u32 peripheral); > > extern int qcom_scm_io_readl(phys_addr_t addr, unsigned int *val); > extern int qcom_scm_io_writel(phys_addr_t addr, unsigned int val); > +extern int qcom_scm_io_update_field(phys_addr_t addr, unsigned int mask, > + unsigned int val); > > extern bool qcom_scm_restore_sec_cfg_available(void); > extern int qcom_scm_restore_sec_cfg(u32 device_id, u32 spare);
diff --git a/drivers/firmware/qcom_scm.c b/drivers/firmware/qcom_scm.c index 3e020d1..aca2556 100644 --- a/drivers/firmware/qcom_scm.c +++ b/drivers/firmware/qcom_scm.c @@ -407,6 +407,21 @@ int qcom_scm_set_remote_state(u32 state, u32 id) } EXPORT_SYMBOL(qcom_scm_set_remote_state); +int qcom_scm_io_update_field(phys_addr_t addr, unsigned int mask, unsigned int val) +{ + unsigned int old, new; + int ret; + + ret = qcom_scm_io_readl(addr, &old); + if (ret) + return ret; + + new = (old & ~mask) | val; + + return qcom_scm_io_writel(addr, new); +} +EXPORT_SYMBOL(qcom_scm_io_update_field); + static int __qcom_scm_set_dload_mode(struct device *dev, bool enable) { struct qcom_scm_desc desc = { diff --git a/include/linux/firmware/qcom/qcom_scm.h b/include/linux/firmware/qcom/qcom_scm.h index 1e449a5..203a781 100644 --- a/include/linux/firmware/qcom/qcom_scm.h +++ b/include/linux/firmware/qcom/qcom_scm.h @@ -84,6 +84,8 @@ extern bool qcom_scm_pas_supported(u32 peripheral); extern int qcom_scm_io_readl(phys_addr_t addr, unsigned int *val); extern int qcom_scm_io_writel(phys_addr_t addr, unsigned int val); +extern int qcom_scm_io_update_field(phys_addr_t addr, unsigned int mask, + unsigned int val); extern bool qcom_scm_restore_sec_cfg_available(void); extern int qcom_scm_restore_sec_cfg(u32 device_id, u32 spare);