Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp1286799rdb; Fri, 16 Feb 2024 10:39:26 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV8mszur2OBf6nzAapV1eaDZBc96/pnOFJEUUOj5c76mM0S5fJM+xOPcoVWzmbNbKo2bdihEv8XeESz+G4fGQnpMR0DDzscjtBU29KwPQ== X-Google-Smtp-Source: AGHT+IHjTLQn9H+KPZqSbTyMnmUt5tz9RZCuLA2J8HujgNiBhG4KiEmie2cXqKIX5XEQH4fVodus X-Received: by 2002:a17:903:2350:b0:1db:9c9d:fa3b with SMTP id c16-20020a170903235000b001db9c9dfa3bmr4611117plh.55.1708108766616; Fri, 16 Feb 2024 10:39:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708108766; cv=pass; d=google.com; s=arc-20160816; b=n7+EDTt5zncfB56puT16YzYRuqG4Qd8LOw4WI7y4Q+18mTqK6+dNfnuh/V7Y2hhcpP bq/8JAegvMslb7HtJU9g82CQedDb3qGHI0EIVLElhCim6K8zs2ubyJhi4VZdYBJPZd0w q5PH2eYAjsqqPPQufMVEALqDAohTHZII+QG3TWHEdxHpDNQ2KRZx3A6ZTIc0edLXGVjf M0KyqcupzcdSXHFlVlWth1ANC/jzpmDP6n9FSke2G0pXCFA5W+8bcmmearI0n8qPKt2G SKhO6fBIYTXgx4xuCpFy1D65QJp1sUIm+nxYy4MWKtx0tGDh1VfF4bCq92r79CgiPq0D NVHw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ztyarMyzfWKL1I4BZn/v4zA92hfj1C76rrIpVmzM2uk=; fh=GhjMBVk2KYDZXMkcKujxNeyUd7OHopICMipJL3n43tc=; b=kDJ5eUCNXrT8uBg9aSErpCHDyg+zhs77D/thiU7m9907pzGIKAyr7twByxy7WDA1TD 6vTczzdBZ8KWLE3RZm8gAA292H5s3nNwof7EufOKa3wd8XcT3RYh+x0RNmtMrUki6Nxc LkM3ttygjk//UC8AmZ3VWhYbafgtduStLM+CvGwn/FTAfkvx++v11hYsAAgI+X9njhC0 V5Za7HW0bP8rBl9wUFu9xvqfkO2QQ5mhjh4QT0Hd7SOUCMLziS8ZbzL5gfcAnCE80gYh 39NQ1wBo/wjiKk1KlS/02qr04WTnZpL+7ts/TTgiVH5oiV6fuIq5PQFRmLak1w67cpDr oxpw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=P3igEePE; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-69174-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69174-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id z2-20020a170902d54200b001d9ec0d7560si254023plf.28.2024.02.16.10.39.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 10:39:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69174-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=P3igEePE; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-69174-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69174-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 579FC2825FA for ; Fri, 16 Feb 2024 18:39:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C55B61350F1; Fri, 16 Feb 2024 18:39:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="P3igEePE" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E5EC812FB18; Fri, 16 Feb 2024 18:39:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708108757; cv=none; b=N3CQah54tOtbBkgEEpmcVX6os8A7/6OVGNkN5vzbWDJq/vDYYNycTy2hk10wPs53Hh5PO04QmhXlcGgU4OWGrulqfB/E27SzTSF84fz4/oAK4ypSy/NmKvD9LAnGoWsnBEZhGBiZaxzr868btLKKq82ObsqUVnUi+x/w+4gC/TQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708108757; c=relaxed/simple; bh=c52Bjk2RQnn7DIN2AN3Dt13KP2BKtoclcR7LSa6bwgE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mvSFSnL8ghRMaPF9S80X/yTBB6ZBIaLREwirBHXwbaOQ42gP9GNnw/qOhPvJl8LFtmXnY9lZidqkGOAyt7HolhYw3lty+GpWGECiMlrFWANvcEQKCNOvHCU+bt5d70P7hTqdF3aGUkpdtan4LDNmsSWkq8AemM7hkMusOJZb+Xw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=P3igEePE; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE102C433F1; Fri, 16 Feb 2024 18:39:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708108756; bh=c52Bjk2RQnn7DIN2AN3Dt13KP2BKtoclcR7LSa6bwgE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=P3igEePEy1/PnswfNRWUu+JU7dPo6agq07TwhdbIMZqb7HTGvrfAHN0bZ0mx7pIm6 g+6ojphnhIrXU6rG3tJTPQ3smk4UPoAuhjSV2ZblYRfh6L+EZlQ7wvyzvtM6NE2Rh+ KaWcMyUoA13HOqD/KOLXACONwvaaU6dbUdE6+nb6J2zn5M19HnhDRKwuwej7ZIr2E4 mJuktNaCneKE2AuDh9V+YQQwBu2jNRb8epndhA0vghGllgf7QVvbwODZLNJ0nfixcb MG5NYM7ptJXaM8mzKlWznplyHTwIe2I1Low0Y71J4A+dvT+3byreoujfIHzXluUpqP nEqD9/fQwQ4DQ== Date: Fri, 16 Feb 2024 12:39:14 -0600 From: Bjorn Andersson To: Mukesh Ojha Cc: konrad.dybcio@linaro.org, linus.walleij@linaro.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org Subject: Re: [PATCH v11 1/4] firmware: qcom: scm: provide a read-modify-write function Message-ID: References: <1704727654-13999-1-git-send-email-quic_mojha@quicinc.com> <1704727654-13999-2-git-send-email-quic_mojha@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1704727654-13999-2-git-send-email-quic_mojha@quicinc.com> On Mon, Jan 08, 2024 at 08:57:31PM +0530, Mukesh Ojha wrote: > It was realized by Srinivas K. that there is a need of "need" is a strong word for this functionality, unless there's some use case that I'm missing. > read-modify-write scm exported function so that it can > be used by multiple clients. > > Let's introduce qcom_scm_io_rmw() which masks out the bits > and write the passed value to that bit-offset. > > Suggested-by: Srinivas Kandagatla > Signed-off-by: Mukesh Ojha > Tested-by: Kathiravan Thirumoorthy # IPQ9574 and IPQ5332 > --- > drivers/firmware/qcom/qcom_scm.c | 26 ++++++++++++++++++++++++++ > include/linux/firmware/qcom/qcom_scm.h | 1 + > 2 files changed, 27 insertions(+) > > diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c > index 520de9b5633a..25549178a30f 100644 > --- a/drivers/firmware/qcom/qcom_scm.c > +++ b/drivers/firmware/qcom/qcom_scm.c > @@ -19,6 +19,7 @@ > #include > #include > #include > +#include > #include > #include > > @@ -41,6 +42,8 @@ struct qcom_scm { > int scm_vote_count; > > u64 dload_mode_addr; > + /* Atomic context only */ > + spinlock_t lock; > }; > > struct qcom_scm_current_perm_info { > @@ -481,6 +484,28 @@ static int qcom_scm_disable_sdi(void) > return ret ? : res.result[0]; > } > > +int qcom_scm_io_rmw(phys_addr_t addr, unsigned int mask, unsigned int val) > +{ > + unsigned int old, new; > + int ret; > + > + if (!__scm) > + return -EINVAL; > + > + spin_lock(&__scm->lock); Please express that this lock is just for create mutual exclusion between rmw operations, nothing else. Also please make a statement why this is desirable and/or needed. Regards, Bjorn > + ret = qcom_scm_io_readl(addr, &old); > + if (ret) > + goto unlock; > + > + new = (old & ~mask) | (val & mask); > + > + ret = qcom_scm_io_writel(addr, new); > +unlock: > + spin_unlock(&__scm->lock); > + return ret; > +} > +EXPORT_SYMBOL_GPL(qcom_scm_io_rmw); > + > static int __qcom_scm_set_dload_mode(struct device *dev, bool enable) > { > struct qcom_scm_desc desc = { > @@ -1824,6 +1849,7 @@ static int qcom_scm_probe(struct platform_device *pdev) > return ret; > > mutex_init(&scm->scm_bw_lock); > + spin_lock_init(&scm->lock); > > scm->path = devm_of_icc_get(&pdev->dev, NULL); > if (IS_ERR(scm->path)) > diff --git a/include/linux/firmware/qcom/qcom_scm.h b/include/linux/firmware/qcom/qcom_scm.h > index ccaf28846054..3a8bb2e603b3 100644 > --- a/include/linux/firmware/qcom/qcom_scm.h > +++ b/include/linux/firmware/qcom/qcom_scm.h > @@ -82,6 +82,7 @@ bool qcom_scm_pas_supported(u32 peripheral); > > int qcom_scm_io_readl(phys_addr_t addr, unsigned int *val); > int qcom_scm_io_writel(phys_addr_t addr, unsigned int val); > +int qcom_scm_io_rmw(phys_addr_t addr, unsigned int mask, unsigned int val); > > bool qcom_scm_restore_sec_cfg_available(void); > int qcom_scm_restore_sec_cfg(u32 device_id, u32 spare); > -- > 2.7.4 >