diff mbox series

[v2,2/4] hwspinlock: qcom: implement bust operation

Message ID 20240524-hwspinlock-bust-v2-2-fb88fd17ca0b@quicinc.com
State Superseded
Headers show
Series Add support for hwspinlock bust | expand

Commit Message

Chris Lew May 25, 2024, 1:26 a.m. UTC
From: Richard Maina <quic_rmaina@quicinc.com>

Implement a new operation qcom_hwspinlock_bust() which can be invoked
to bust any locks that are in use when a remoteproc is stopped or
crashed.

Signed-off-by: Richard Maina <quic_rmaina@quicinc.com>
Signed-off-by: Chris Lew <quic_clew@quicinc.com>
---
 drivers/hwspinlock/qcom_hwspinlock.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

Comments

Bjorn Andersson May 29, 2024, 2:09 a.m. UTC | #1
On Fri, May 24, 2024 at 06:26:41PM -0700, Chris Lew wrote:
> From: Richard Maina <quic_rmaina@quicinc.com>
> 
> Implement a new operation qcom_hwspinlock_bust() which can be invoked
> to bust any locks that are in use when a remoteproc is stopped or
> crashed.
> 
> Signed-off-by: Richard Maina <quic_rmaina@quicinc.com>
> Signed-off-by: Chris Lew <quic_clew@quicinc.com>

Reviewed-by: Bjorn Andersson <andersson@kernel.org>

Regards,
Bjorn

> ---
>  drivers/hwspinlock/qcom_hwspinlock.c | 25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)
> 
> diff --git a/drivers/hwspinlock/qcom_hwspinlock.c b/drivers/hwspinlock/qcom_hwspinlock.c
> index 814dfe8697bf..0390979fd765 100644
> --- a/drivers/hwspinlock/qcom_hwspinlock.c
> +++ b/drivers/hwspinlock/qcom_hwspinlock.c
> @@ -64,9 +64,34 @@ static void qcom_hwspinlock_unlock(struct hwspinlock *lock)
>  		pr_err("%s: failed to unlock spinlock\n", __func__);
>  }
>  
> +static int qcom_hwspinlock_bust(struct hwspinlock *lock, unsigned int id)
> +{
> +	struct regmap_field *field = lock->priv;
> +	u32 owner;
> +	int ret;
> +
> +	ret = regmap_field_read(field, &owner);
> +	if (ret) {
> +		dev_err(lock->bank->dev, "unable to query spinlock owner\n");
> +		return ret;
> +	}
> +
> +	if (owner != id)
> +		return 0;
> +
> +	ret = regmap_field_write(field, 0);
> +	if (ret) {
> +		dev_err(lock->bank->dev, "failed to bust spinlock\n");
> +		return ret;
> +	}
> +
> +	return 0;
> +}
> +
>  static const struct hwspinlock_ops qcom_hwspinlock_ops = {
>  	.trylock	= qcom_hwspinlock_trylock,
>  	.unlock		= qcom_hwspinlock_unlock,
> +	.bust		= qcom_hwspinlock_bust,
>  };
>  
>  static const struct regmap_config sfpb_mutex_config = {
> 
> -- 
> 2.25.1
>
diff mbox series

Patch

diff --git a/drivers/hwspinlock/qcom_hwspinlock.c b/drivers/hwspinlock/qcom_hwspinlock.c
index 814dfe8697bf..0390979fd765 100644
--- a/drivers/hwspinlock/qcom_hwspinlock.c
+++ b/drivers/hwspinlock/qcom_hwspinlock.c
@@ -64,9 +64,34 @@  static void qcom_hwspinlock_unlock(struct hwspinlock *lock)
 		pr_err("%s: failed to unlock spinlock\n", __func__);
 }
 
+static int qcom_hwspinlock_bust(struct hwspinlock *lock, unsigned int id)
+{
+	struct regmap_field *field = lock->priv;
+	u32 owner;
+	int ret;
+
+	ret = regmap_field_read(field, &owner);
+	if (ret) {
+		dev_err(lock->bank->dev, "unable to query spinlock owner\n");
+		return ret;
+	}
+
+	if (owner != id)
+		return 0;
+
+	ret = regmap_field_write(field, 0);
+	if (ret) {
+		dev_err(lock->bank->dev, "failed to bust spinlock\n");
+		return ret;
+	}
+
+	return 0;
+}
+
 static const struct hwspinlock_ops qcom_hwspinlock_ops = {
 	.trylock	= qcom_hwspinlock_trylock,
 	.unlock		= qcom_hwspinlock_unlock,
+	.bust		= qcom_hwspinlock_bust,
 };
 
 static const struct regmap_config sfpb_mutex_config = {