From patchwork Sun Feb 15 22:54:41 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 450 Received: from mail.zeus03.de (zeus03.de [194.117.254.33]) (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 4294830BBAE for ; Sun, 15 Feb 2026 22:55:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.117.254.33 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771196121; cv=none; b=CZgFz9x3sRpEnvNb6zBbe8xX3tPQ+kjSFgyDMW6eTZxRlIi5BaE+aYrn7O+ii2k9SaLehZIzqmKOfDEKBg70Ex0ubEGSKvLNW0vHNJPyziB2jAFdvaiH0AMUYQ/fFcnjbW9OYebKinBUZS/BZJcSMYGzxyIzKrDCezA1XPdYxAk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771196121; c=relaxed/simple; bh=9Ocg3jq1rBVcFXg3EEoW7RleW9cSPA0dvHAGBYBfgfw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L1vDEWT4falNECrgvmIKzw8tnp+OWwT+HvxLp3aqtlSsUEE01Y2vYY+xfCUdIwXM2KaOql+bMxt8lUzuCu6sdP+/tsn9zQqH+dCeRGam47sUsZNO0oyoHjFFJIqqq8OuJ7WgUfISVw4nFRUXMC66SyDVn2+Bwaj7aI7hTde81PQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com; spf=pass smtp.mailfrom=sang-engineering.com; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b=N0wgZhmO; arc=none smtp.client-ip=194.117.254.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b="N0wgZhmO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= sang-engineering.com; h=from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; s=k1; bh=bwdQ2TfNm0AqCHbct36CNSsYA2zZVoG3ZIXiKj6F9PM=; b=N0wgZh mOJqk8DIfyDC7r2BSjtcJCxL8fkw8ejRXqiXXmqU/Z0OE2MmoDDpTj7Uofj3M5sl XyNamFFFErH6a5i+gclLE8THanQEXNSaoEQPpa1xCIVbH4QMLD4yo/+BF0iNVEG5 rZOqfr+v/B6Su8drF/9B7noHPU2SNJkfXqJzIWTetHlY+NZu+W803yulG/HXHJiF tJ2CMQ3QamAjJ/cymXydvMRMlAykt7kRYX6Sb/yOIb1m0se5nB9prw1PAPae3ai4 9oRWTbLW0v3Z9aHARcHoqVJIwmUdfNDsP87viZwYNoxvDmykQ1m15tei26qpWzv3 MuN/QwY8I1TkjzcA== Received: (qmail 3011330 invoked from network); 15 Feb 2026 23:55:05 +0100 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 15 Feb 2026 23:55:05 +0100 X-UD-Smtp-Session: l3s3148p1@nvu0uuRKaIQujns5 From: Wolfram Sang To: linux-renesas-soc@vger.kernel.org Cc: Andy Shevchenko , linux-arm-kernel@lists.infradead.org, Wolfram Sang , Bjorn Andersson , Baolin Wang , Orson Zhai , Chunyan Zhang , Maxime Coquelin , Alexandre Torgue , Wilken Gottwalt , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , linux-remoteproc@vger.kernel.org, linux-omap@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-sunxi@lists.linux.dev Subject: [RFC PATCH v2 01/13] hwspinlock: add helpers to retrieve core data Date: Sun, 15 Feb 2026 23:54:41 +0100 Message-ID: <20260215225501.6365-2-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260215225501.6365-1-wsa+renesas@sang-engineering.com> References: <20260215225501.6365-1-wsa+renesas@sang-engineering.com> Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Status: O This is a first step to hide internal core structs from hwspinlock providers. It adds helper functions to retrieve the data needed by them. Because all users are only within the hwspinlock subsystem and the change there is trivial, conversion is included in this patch as well. Signed-off-by: Wolfram Sang --- drivers/hwspinlock/hwspinlock_core.c | 12 ++++++++++++ drivers/hwspinlock/omap_hwspinlock.c | 4 ++-- drivers/hwspinlock/qcom_hwspinlock.c | 11 ++++++----- drivers/hwspinlock/sprd_hwspinlock.c | 6 +++--- drivers/hwspinlock/stm32_hwspinlock.c | 4 ++-- drivers/hwspinlock/sun6i_hwspinlock.c | 4 ++-- include/linux/hwspinlock.h | 2 ++ 7 files changed, 29 insertions(+), 14 deletions(-) diff --git a/drivers/hwspinlock/hwspinlock_core.c b/drivers/hwspinlock/hwspinlock_core.c index cc8e952a6772..2c9eceba7fe8 100644 --- a/drivers/hwspinlock/hwspinlock_core.c +++ b/drivers/hwspinlock/hwspinlock_core.c @@ -888,5 +888,17 @@ struct hwspinlock *devm_hwspin_lock_request_specific(struct device *dev, } EXPORT_SYMBOL_GPL(devm_hwspin_lock_request_specific); +void *hwspin_lock_get_priv(struct hwspinlock *hwlock) +{ + return hwlock->priv; +} +EXPORT_SYMBOL_GPL(hwspin_lock_get_priv); + +struct device *hwspin_lock_get_dev(struct hwspinlock *hwlock) +{ + return hwlock->bank->dev; +} +EXPORT_SYMBOL_GPL(hwspin_lock_get_dev); + MODULE_DESCRIPTION("Hardware spinlock interface"); MODULE_AUTHOR("Ohad Ben-Cohen "); diff --git a/drivers/hwspinlock/omap_hwspinlock.c b/drivers/hwspinlock/omap_hwspinlock.c index 1832e0c3af6b..5bf0061d3fd6 100644 --- a/drivers/hwspinlock/omap_hwspinlock.c +++ b/drivers/hwspinlock/omap_hwspinlock.c @@ -37,7 +37,7 @@ static int omap_hwspinlock_trylock(struct hwspinlock *lock) { - void __iomem *lock_addr = lock->priv; + void __iomem *lock_addr = hwspin_lock_get_priv(lock); /* attempt to acquire the lock by reading its value */ return (SPINLOCK_NOTTAKEN == readl(lock_addr)); @@ -45,7 +45,7 @@ static int omap_hwspinlock_trylock(struct hwspinlock *lock) static void omap_hwspinlock_unlock(struct hwspinlock *lock) { - void __iomem *lock_addr = lock->priv; + void __iomem *lock_addr = hwspin_lock_get_priv(lock); /* release the lock by writing 0 to it */ writel(SPINLOCK_NOTTAKEN, lock_addr); diff --git a/drivers/hwspinlock/qcom_hwspinlock.c b/drivers/hwspinlock/qcom_hwspinlock.c index 0390979fd765..7ff89c3e8c6b 100644 --- a/drivers/hwspinlock/qcom_hwspinlock.c +++ b/drivers/hwspinlock/qcom_hwspinlock.c @@ -27,7 +27,7 @@ struct qcom_hwspinlock_of_data { static int qcom_hwspinlock_trylock(struct hwspinlock *lock) { - struct regmap_field *field = lock->priv; + struct regmap_field *field = hwspin_lock_get_priv(lock); u32 lock_owner; int ret; @@ -44,7 +44,7 @@ static int qcom_hwspinlock_trylock(struct hwspinlock *lock) static void qcom_hwspinlock_unlock(struct hwspinlock *lock) { - struct regmap_field *field = lock->priv; + struct regmap_field *field = hwspin_lock_get_priv(lock); u32 lock_owner; int ret; @@ -66,13 +66,14 @@ static void qcom_hwspinlock_unlock(struct hwspinlock *lock) static int qcom_hwspinlock_bust(struct hwspinlock *lock, unsigned int id) { - struct regmap_field *field = lock->priv; + struct regmap_field *field = hwspin_lock_get_priv(lock); + struct device *dev = hwspin_lock_get_dev(lock); u32 owner; int ret; ret = regmap_field_read(field, &owner); if (ret) { - dev_err(lock->bank->dev, "unable to query spinlock owner\n"); + dev_err(dev, "unable to query spinlock owner\n"); return ret; } @@ -81,7 +82,7 @@ static int qcom_hwspinlock_bust(struct hwspinlock *lock, unsigned int id) ret = regmap_field_write(field, 0); if (ret) { - dev_err(lock->bank->dev, "failed to bust spinlock\n"); + dev_err(dev, "failed to bust spinlock\n"); return ret; } diff --git a/drivers/hwspinlock/sprd_hwspinlock.c b/drivers/hwspinlock/sprd_hwspinlock.c index 22e2ffb91743..0d08efbdfb07 100644 --- a/drivers/hwspinlock/sprd_hwspinlock.c +++ b/drivers/hwspinlock/sprd_hwspinlock.c @@ -40,8 +40,8 @@ struct sprd_hwspinlock_dev { static int sprd_hwspinlock_trylock(struct hwspinlock *lock) { struct sprd_hwspinlock_dev *sprd_hwlock = - dev_get_drvdata(lock->bank->dev); - void __iomem *addr = lock->priv; + dev_get_drvdata(hwspin_lock_get_dev(lock)); + void __iomem *addr = hwspin_lock_get_priv(lock); int user_id, lock_id; if (!readl(addr)) @@ -59,7 +59,7 @@ static int sprd_hwspinlock_trylock(struct hwspinlock *lock) /* unlock the hardware spinlock */ static void sprd_hwspinlock_unlock(struct hwspinlock *lock) { - void __iomem *lock_addr = lock->priv; + void __iomem *lock_addr = hwspin_lock_get_priv(lock); writel(HWSPINLOCK_NOTTAKEN, lock_addr); } diff --git a/drivers/hwspinlock/stm32_hwspinlock.c b/drivers/hwspinlock/stm32_hwspinlock.c index bb5c7e5f7a80..1d75dc03f4ad 100644 --- a/drivers/hwspinlock/stm32_hwspinlock.c +++ b/drivers/hwspinlock/stm32_hwspinlock.c @@ -27,7 +27,7 @@ struct stm32_hwspinlock { static int stm32_hwspinlock_trylock(struct hwspinlock *lock) { - void __iomem *lock_addr = lock->priv; + void __iomem *lock_addr = hwspin_lock_get_priv(lock); u32 status; writel(STM32_MUTEX_LOCK_BIT | STM32_MUTEX_COREID, lock_addr); @@ -38,7 +38,7 @@ static int stm32_hwspinlock_trylock(struct hwspinlock *lock) static void stm32_hwspinlock_unlock(struct hwspinlock *lock) { - void __iomem *lock_addr = lock->priv; + void __iomem *lock_addr = hwspin_lock_get_priv(lock); writel(STM32_MUTEX_COREID, lock_addr); } diff --git a/drivers/hwspinlock/sun6i_hwspinlock.c b/drivers/hwspinlock/sun6i_hwspinlock.c index c2d314588046..8ff81cb5880a 100644 --- a/drivers/hwspinlock/sun6i_hwspinlock.c +++ b/drivers/hwspinlock/sun6i_hwspinlock.c @@ -62,14 +62,14 @@ static void sun6i_hwspinlock_debugfs_init(struct sun6i_hwspinlock_data *priv) static int sun6i_hwspinlock_trylock(struct hwspinlock *lock) { - void __iomem *lock_addr = lock->priv; + void __iomem *lock_addr = hwspin_lock_get_priv(lock); return (readl(lock_addr) == SPINLOCK_NOTTAKEN); } static void sun6i_hwspinlock_unlock(struct hwspinlock *lock) { - void __iomem *lock_addr = lock->priv; + void __iomem *lock_addr = hwspin_lock_get_priv(lock); writel(SPINLOCK_NOTTAKEN, lock_addr); } diff --git a/include/linux/hwspinlock.h b/include/linux/hwspinlock.h index 74b91244fe0e..dffa1dff7289 100644 --- a/include/linux/hwspinlock.h +++ b/include/linux/hwspinlock.h @@ -27,6 +27,8 @@ struct hwspinlock_ops; #ifdef CONFIG_HWSPINLOCK +void *hwspin_lock_get_priv(struct hwspinlock *hwlock); +struct device *hwspin_lock_get_dev(struct hwspinlock *hwlock); int hwspin_lock_register(struct hwspinlock_device *bank, struct device *dev, const struct hwspinlock_ops *ops, int base_id, int num_locks); int hwspin_lock_unregister(struct hwspinlock_device *bank); From patchwork Sun Feb 15 22:54:47 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 449 Received: from mail.zeus03.de (zeus03.de [194.117.254.33]) (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 E660730B53B for ; Sun, 15 Feb 2026 22:55:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.117.254.33 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771196130; cv=none; b=l3MDSPcWjmGHP2Esw/H10d7z0lSjqat/Ly9CrxATCEOPGKI1nXG5MICXRq8gFaC/qITwXRWY1zG2MknN1pzXnVeb5buGSm6XeIAyGiQuB2w8afdfy0+09zw1zIWW82iB7pKXPPQNvADLamPrOZMUQjWROFJrQJJc114NQNj6mvA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771196130; c=relaxed/simple; bh=OG3F3DPzsyur1bsJvpPZ62ALOswPTRmdYs02gUy2bho=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t6mbsgLWfeZmZWZlDNbK7uGGZTtyMmlIYPhGeKxrhl/90QEhE+qF/m1w1aO945Xwpuib/sZPKk5tST7z+0xPsQ5px4CDC7rBXdGW/OcUI9xy1+ypipX0Idd7O9V3LRE0P/YgGH2H76u3NnTfvKEKGwg+LVTniLbgvvFYeoqVxT0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com; spf=pass smtp.mailfrom=sang-engineering.com; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b=NtkXmGX1; arc=none smtp.client-ip=194.117.254.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b="NtkXmGX1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= sang-engineering.com; h=from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; s=k1; bh=YFkjV39h9bUTsT9T2mmQ33w6bCMkVVVBeqpoOYjV1AY=; b=NtkXmG X18CRt1bIaz1PA5hfD6uvx/rt6Wey1hMiI84/CxBFaF+SkOBQAnUzsDw2yq0/s2N OtIwPB6Hhjxv3PB2c+mohROVCjWBWC8TPRhONWSjuo3EOzpAwJdF30fBFy7VwDUy NrjdI1Uogy26hFLXd9GgMDioKlbCr4OH1FnHJWz9/xoSv0Io6Wo2QY5IT6vSI12k 8KZrANuSkdD9bPejP8OjMvfY/VfqyRf7EJHnBU7DStysrhGJaBoHGtCv6e2phyLG h/+edhXklO56xPKELqEpCbTQcn41SXQ1PpaZBs4ReKXLm9pr+JjrJLPtr9s/DlTw w8kyMeZ8jGaFOVpA== Received: (qmail 3011465 invoked from network); 15 Feb 2026 23:55:12 +0100 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 15 Feb 2026 23:55:12 +0100 X-UD-Smtp-Session: l3s3148p1@mK8Su+RK5MAujns5 From: Wolfram Sang To: linux-renesas-soc@vger.kernel.org Cc: Andy Shevchenko , linux-arm-kernel@lists.infradead.org, Wolfram Sang , Wilken Gottwalt , Bjorn Andersson , Baolin Wang , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , linux-remoteproc@vger.kernel.org, linux-sunxi@lists.linux.dev Subject: [RFC PATCH v2 07/13] hwspinlock: sun6i: use new callback to initialize hwspinlock priv Date: Sun, 15 Feb 2026 23:54:47 +0100 Message-ID: <20260215225501.6365-8-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260215225501.6365-1-wsa+renesas@sang-engineering.com> References: <20260215225501.6365-1-wsa+renesas@sang-engineering.com> Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Status: O Apply the new helper to avoid using internal structures from the core. Remove superfluous setting of drvdata while here. Signed-off-by: Wolfram Sang --- drivers/hwspinlock/sun6i_hwspinlock.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/hwspinlock/sun6i_hwspinlock.c b/drivers/hwspinlock/sun6i_hwspinlock.c index 8ff81cb5880a..7d0c639c0e82 100644 --- a/drivers/hwspinlock/sun6i_hwspinlock.c +++ b/drivers/hwspinlock/sun6i_hwspinlock.c @@ -74,9 +74,17 @@ static void sun6i_hwspinlock_unlock(struct hwspinlock *lock) writel(SPINLOCK_NOTTAKEN, lock_addr); } +static void *sun6i_hwspinlock_init_priv(int local_id, void *init_data) +{ + void __iomem *io_base_ofs = init_data; + + return io_base_ofs + sizeof(u32) * local_id; +} + static const struct hwspinlock_ops sun6i_hwspinlock_ops = { .trylock = sun6i_hwspinlock_trylock, .unlock = sun6i_hwspinlock_unlock, + .init_priv = sun6i_hwspinlock_init_priv, }; static void sun6i_hwspinlock_disable(void *data) @@ -91,10 +99,9 @@ static void sun6i_hwspinlock_disable(void *data) static int sun6i_hwspinlock_probe(struct platform_device *pdev) { struct sun6i_hwspinlock_data *priv; - struct hwspinlock *hwlock; void __iomem *io_base; u32 num_banks; - int err, i; + int err; io_base = devm_platform_ioremap_resource(pdev, SPINLOCK_BASE_ID); if (IS_ERR(io_base)) @@ -161,11 +168,6 @@ static int sun6i_hwspinlock_probe(struct platform_device *pdev) goto bank_fail; } - for (i = 0; i < priv->nlocks; ++i) { - hwlock = &priv->bank->lock[i]; - hwlock->priv = io_base + SPINLOCK_LOCK_REGN + sizeof(u32) * i; - } - /* failure of debugfs is considered non-fatal */ sun6i_hwspinlock_debugfs_init(priv); if (IS_ERR(priv->debugfs)) @@ -177,10 +179,8 @@ static int sun6i_hwspinlock_probe(struct platform_device *pdev) goto bank_fail; } - platform_set_drvdata(pdev, priv); - return devm_hwspin_lock_register(&pdev->dev, priv->bank, &sun6i_hwspinlock_ops, - SPINLOCK_BASE_ID, priv->nlocks); + SPINLOCK_BASE_ID, priv->nlocks, io_base + SPINLOCK_LOCK_REGN); bank_fail: clk_disable_unprepare(priv->ahb_clk); From patchwork Sun Feb 15 22:54:48 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 448 Received: from mail.zeus03.de (zeus03.de [194.117.254.33]) (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 CF5B230B52A for ; Sun, 15 Feb 2026 22:55:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.117.254.33 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771196133; cv=none; b=q4BGvGsuD/1u3ouFpIWEtSabecYa0CBxpapu4r70z0arZWjsHMXRJqA3UPjMhgGor8uP9iT5B7uUoooh04bXJ8LG2/esuOvO9LvF8Bm/k4seHCHyY5XF69lv3tWZWGJPDnEvuoDsvXPmctY9a1bKmuLyHmGS5IbwHRA9uCBxrJQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771196133; c=relaxed/simple; bh=M9jwiFFUyTVXmINlqXJUjONm52xyGmsK0AqCY77SlvU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I0kTuGAxWT/cTTp1NcSYzWfUJURoKX1+SgN17mMN7MLxhhUBwEYN7tUAQG1lUuCqkhBZ03BNa6W8V2g1hwQK+l3ABoOq0mUDazX7FdUmaVxhhD2JdiV8Px7W/5A+mWyqepSEUuCGY2O2v7c9hGcDfPiIYp1iOjxXXxJ38pRt8/k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com; spf=pass smtp.mailfrom=sang-engineering.com; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b=goAWzttq; arc=none smtp.client-ip=194.117.254.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b="goAWzttq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= sang-engineering.com; h=from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; s=k1; bh=ebCf8IAGgl2B/372c2QLceVUsgeqo2XZMEmzfMHhLb4=; b=goAWzt tqa7xKol9ZWL/DrW1QbOpXEcLfzNhLol8Zt7yh4/0H/GCuduAoLKKVGIpak6D/Yn BHsYtHPI3mioE8FQ5dKryvw432BvjoDHNwJtnpAFvfXzQkYPBEtOnI8lqExiUj8l 42KjrBsmZ4bOtYm7xhuvyg3IYiBJXaqzVlh6YValGbaN/W6kGGGLBVmgni/is20e Lquu4K9Y3As5wrWLmAQxRwvI2iRtg1z6I3zNhNN4ui8W8LINAdncVSn1bXlIoQR5 eb4Km/EVlE5/nbbrI5T0JJf/faG3olFjUZDCuhL9M1ae/re1Azcw0rxvmqBKeuua 583zjJ9O3f9x+y7A== Received: (qmail 3011526 invoked from network); 15 Feb 2026 23:55:14 +0100 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 15 Feb 2026 23:55:14 +0100 X-UD-Smtp-Session: l3s3148p1@ptstu+RK9MAujns5 From: Wolfram Sang To: linux-renesas-soc@vger.kernel.org Cc: Andy Shevchenko , linux-arm-kernel@lists.infradead.org, Wolfram Sang , Bjorn Andersson , Baolin Wang , Orson Zhai , Chunyan Zhang , Maxime Coquelin , Alexandre Torgue , Wilken Gottwalt , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , linux-remoteproc@vger.kernel.org, linux-omap@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-sunxi@lists.linux.dev Subject: [RFC PATCH v2 08/13] hwspinlock: handle hwspinlock device allocation in the core Date: Sun, 15 Feb 2026 23:54:48 +0100 Message-ID: <20260215225501.6365-9-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260215225501.6365-1-wsa+renesas@sang-engineering.com> References: <20260215225501.6365-1-wsa+renesas@sang-engineering.com> Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Status: O Providers have been refactored to avoid using core internal structures. As a result, they do not need to allocate the hwspinlock device on their own anymore because they can access everything they need with helpers. So, the allocation is moved to the core. As a result, the registering functions now return a pointer to the (soon) opaque hwspinlock device which may be needed for unregistering only. Because the argument list of the registering functions is changed, all users are changed here as well. Signed-off-by: Wolfram Sang --- drivers/hwspinlock/hwspinlock_core.c | 48 +++++++++++++++------------ drivers/hwspinlock/omap_hwspinlock.c | 10 ++---- drivers/hwspinlock/qcom_hwspinlock.c | 11 ++---- drivers/hwspinlock/sprd_hwspinlock.c | 17 ++++------ drivers/hwspinlock/stm32_hwspinlock.c | 7 ++-- drivers/hwspinlock/sun6i_hwspinlock.c | 12 ++----- include/linux/hwspinlock.h | 17 ++++++---- 7 files changed, 52 insertions(+), 70 deletions(-) diff --git a/drivers/hwspinlock/hwspinlock_core.c b/drivers/hwspinlock/hwspinlock_core.c index afe1e7ce2829..a7610ba755b4 100644 --- a/drivers/hwspinlock/hwspinlock_core.c +++ b/drivers/hwspinlock/hwspinlock_core.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "hwspinlock_internal.h" @@ -502,7 +503,6 @@ static struct hwspinlock *hwspin_lock_unregister_single(unsigned int id) /** * hwspin_lock_register() - register a new hw spinlock device - * @bank: the hwspinlock device, which usually provides numerous hw locks * @dev: the backing device * @ops: hwspinlock handlers for this device * @base_id: id of the first hardware spinlock in this bank @@ -514,21 +514,25 @@ static struct hwspinlock *hwspin_lock_unregister_single(unsigned int id) * * Should be called from a process context (might sleep) * - * Returns: %0 on success, or an appropriate error code on failure + * Returns: a pointer to the device (needed for unregistering), or an + * appropriate error pointer on failure */ -int hwspin_lock_register(struct hwspinlock_device *bank, struct device *dev, - const struct hwspinlock_ops *ops, int base_id, int num_locks, - void *init_data) +struct hwspinlock_device *hwspin_lock_register(struct device *dev, const struct hwspinlock_ops *ops, + int base_id, int num_locks, void *init_data) { + struct hwspinlock_device *bank; struct hwspinlock *hwlock; int ret, i; - if (!bank || !ops || !dev || !num_locks || !ops->trylock || - !ops->unlock) { + if (!ops || !dev || !num_locks || !ops->trylock || !ops->unlock) { pr_err("invalid parameters\n"); - return -EINVAL; + return ERR_PTR(-EINVAL); } + bank = kzalloc(struct_size(bank, lock, num_locks), GFP_KERNEL); + if (!bank) + return ERR_PTR(-ENOMEM); + bank->dev = dev; bank->ops = ops; bank->base_id = base_id; @@ -553,12 +557,13 @@ int hwspin_lock_register(struct hwspinlock_device *bank, struct device *dev, goto reg_failed; } - return 0; + return bank; reg_failed: while (--i >= 0) hwspin_lock_unregister_single(base_id + i); - return ret; + kfree(bank); + return ERR_PTR(ret); } EXPORT_SYMBOL_GPL(hwspin_lock_register); @@ -589,6 +594,8 @@ int hwspin_lock_unregister(struct hwspinlock_device *bank) WARN_ON(tmp != hwlock); } + kfree(bank); + return 0; } EXPORT_SYMBOL_GPL(hwspin_lock_unregister); @@ -639,7 +646,6 @@ EXPORT_SYMBOL_GPL(devm_hwspin_lock_unregister); * devm_hwspin_lock_register() - register a new hw spinlock device for * a managed device * @dev: the backing device - * @bank: the hwspinlock device, which usually provides numerous hw locks * @ops: hwspinlock handlers for this device * @base_id: id of the first hardware spinlock in this bank * @num_locks: number of hwspinlocks provided by this device @@ -650,29 +656,27 @@ EXPORT_SYMBOL_GPL(devm_hwspin_lock_unregister); * * Should be called from a process context (might sleep) * - * Returns: %0 on success, or an appropriate error code on failure + * Returns: a pointer to the device (usable for unregistering), or an + * appropriate error pointer on failure */ -int devm_hwspin_lock_register(struct device *dev, - struct hwspinlock_device *bank, - const struct hwspinlock_ops *ops, - int base_id, int num_locks, void *init_data) +struct hwspinlock_device *devm_hwspin_lock_register(struct device *dev, const struct hwspinlock_ops *ops, + int base_id, int num_locks, void *init_data) { - struct hwspinlock_device **ptr; - int ret; + struct hwspinlock_device **ptr, *bank; ptr = devres_alloc(devm_hwspin_lock_unreg, sizeof(*ptr), GFP_KERNEL); if (!ptr) - return -ENOMEM; + return ERR_PTR(-ENOMEM); - ret = hwspin_lock_register(bank, dev, ops, base_id, num_locks, init_data); - if (!ret) { + bank = hwspin_lock_register(dev, ops, base_id, num_locks, init_data); + if (!IS_ERR(bank)) { *ptr = bank; devres_add(dev, ptr); } else { devres_free(ptr); } - return ret; + return bank; } EXPORT_SYMBOL_GPL(devm_hwspin_lock_register); diff --git a/drivers/hwspinlock/omap_hwspinlock.c b/drivers/hwspinlock/omap_hwspinlock.c index 9a9cb3692348..f1ff6406db46 100644 --- a/drivers/hwspinlock/omap_hwspinlock.c +++ b/drivers/hwspinlock/omap_hwspinlock.c @@ -82,7 +82,6 @@ static const struct hwspinlock_ops omap_hwspinlock_ops = { static int omap_hwspinlock_probe(struct platform_device *pdev) { - struct hwspinlock_device *bank; void __iomem *io_base; int num_locks, i, ret; /* Only a single hwspinlock block device is supported */ @@ -119,13 +118,8 @@ static int omap_hwspinlock_probe(struct platform_device *pdev) num_locks = i * 32; /* actual number of locks in this device */ - bank = devm_kzalloc(&pdev->dev, struct_size(bank, lock, num_locks), - GFP_KERNEL); - if (!bank) - return -ENOMEM; - - return devm_hwspin_lock_register(&pdev->dev, bank, &omap_hwspinlock_ops, - base_id, num_locks, io_base + LOCK_BASE_OFFSET); + return devm_hwspin_lock_register_errno(&pdev->dev, &omap_hwspinlock_ops, base_id, + num_locks, io_base + LOCK_BASE_OFFSET); } static const struct of_device_id omap_hwspinlock_of_match[] = { diff --git a/drivers/hwspinlock/qcom_hwspinlock.c b/drivers/hwspinlock/qcom_hwspinlock.c index 73b280988109..e2836d6728e8 100644 --- a/drivers/hwspinlock/qcom_hwspinlock.c +++ b/drivers/hwspinlock/qcom_hwspinlock.c @@ -223,9 +223,7 @@ static struct regmap *qcom_hwspinlock_probe_mmio(struct platform_device *pdev, static int qcom_hwspinlock_probe(struct platform_device *pdev) { struct qcom_hwspinlock_priv_init_data init; - struct hwspinlock_device *bank; struct regmap *regmap; - size_t array_size; regmap = qcom_hwspinlock_probe_syscon(pdev, &init.base, &init.stride); if (IS_ERR(regmap) && PTR_ERR(regmap) == -ENODEV) @@ -234,16 +232,11 @@ static int qcom_hwspinlock_probe(struct platform_device *pdev) if (IS_ERR(regmap)) return PTR_ERR(regmap); - array_size = QCOM_MUTEX_NUM_LOCKS * sizeof(struct hwspinlock); - bank = devm_kzalloc(&pdev->dev, sizeof(*bank) + array_size, GFP_KERNEL); - if (!bank) - return -ENOMEM; - init.dev = &pdev->dev; init.regmap = regmap; - return devm_hwspin_lock_register(&pdev->dev, bank, &qcom_hwspinlock_ops, - 0, QCOM_MUTEX_NUM_LOCKS, &init); + return devm_hwspin_lock_register_errno(&pdev->dev, &qcom_hwspinlock_ops, + 0, QCOM_MUTEX_NUM_LOCKS, &init); } static struct platform_driver qcom_hwspinlock_driver = { diff --git a/drivers/hwspinlock/sprd_hwspinlock.c b/drivers/hwspinlock/sprd_hwspinlock.c index c19b680d5fdf..95b254e9b6a0 100644 --- a/drivers/hwspinlock/sprd_hwspinlock.c +++ b/drivers/hwspinlock/sprd_hwspinlock.c @@ -33,15 +33,14 @@ struct sprd_hwspinlock_dev { void __iomem *base; struct clk *clk; - struct hwspinlock_device bank; }; /* try to lock the hardware spinlock */ static int sprd_hwspinlock_trylock(struct hwspinlock *lock) { - struct sprd_hwspinlock_dev *sprd_hwlock = - dev_get_drvdata(hwspin_lock_get_dev(lock)); void __iomem *addr = hwspin_lock_get_priv(lock); + struct device *dev = hwspin_lock_get_dev(lock); + struct sprd_hwspinlock_dev *sprd_hwlock = dev_get_drvdata(dev); int user_id, lock_id; if (!readl(addr)) @@ -50,8 +49,7 @@ static int sprd_hwspinlock_trylock(struct hwspinlock *lock) lock_id = hwlock_to_id(lock); /* get the hardware spinlock master/user id */ user_id = readl(sprd_hwlock->base + HWSPINLOCK_MASTERID(lock_id)); - dev_warn(sprd_hwlock->bank.dev, - "hwspinlock [%d] lock failed and master/user id = %d!\n", + dev_warn(dev, "hwspinlock [%d] lock failed and master/user id = %d!\n", lock_id, user_id); return 0; } @@ -99,9 +97,7 @@ static int sprd_hwspinlock_probe(struct platform_device *pdev) if (!pdev->dev.of_node) return -ENODEV; - sprd_hwlock = devm_kzalloc(&pdev->dev, - struct_size(sprd_hwlock, bank.lock, SPRD_HWLOCKS_NUM), - GFP_KERNEL); + sprd_hwlock = devm_kzalloc(&pdev->dev, sizeof(*sprd_hwlock), GFP_KERNEL); if (!sprd_hwlock) return -ENOMEM; @@ -132,9 +128,8 @@ static int sprd_hwspinlock_probe(struct platform_device *pdev) platform_set_drvdata(pdev, sprd_hwlock); - return devm_hwspin_lock_register(&pdev->dev, &sprd_hwlock->bank, - &sprd_hwspinlock_ops, 0, - SPRD_HWLOCKS_NUM, sprd_hwlock->base); + return devm_hwspin_lock_register_errno(&pdev->dev, &sprd_hwspinlock_ops, 0, + SPRD_HWLOCKS_NUM, sprd_hwlock->base); } static const struct of_device_id sprd_hwspinlock_of_match[] = { diff --git a/drivers/hwspinlock/stm32_hwspinlock.c b/drivers/hwspinlock/stm32_hwspinlock.c index 02db950c9450..a966e967dcdb 100644 --- a/drivers/hwspinlock/stm32_hwspinlock.c +++ b/drivers/hwspinlock/stm32_hwspinlock.c @@ -22,7 +22,6 @@ struct stm32_hwspinlock { struct clk *clk; - struct hwspinlock_device bank; }; static int stm32_hwspinlock_trylock(struct hwspinlock *lock) @@ -87,7 +86,7 @@ static int stm32_hwspinlock_probe(struct platform_device *pdev) if (IS_ERR(io_base)) return PTR_ERR(io_base); - hw = devm_kzalloc(dev, struct_size(hw, bank.lock, STM32_MUTEX_NUM_LOCKS), GFP_KERNEL); + hw = devm_kzalloc(dev, sizeof(*hw), GFP_KERNEL); if (!hw) return -ENOMEM; @@ -114,8 +113,8 @@ static int stm32_hwspinlock_probe(struct platform_device *pdev) return ret; } - ret = devm_hwspin_lock_register(dev, &hw->bank, &stm32_hwspinlock_ops, - 0, STM32_MUTEX_NUM_LOCKS, io_base); + ret = devm_hwspin_lock_register_errno(dev, &stm32_hwspinlock_ops, + 0, STM32_MUTEX_NUM_LOCKS, io_base); if (ret) dev_err(dev, "Failed to register hwspinlock\n"); diff --git a/drivers/hwspinlock/sun6i_hwspinlock.c b/drivers/hwspinlock/sun6i_hwspinlock.c index 7d0c639c0e82..8e17deb503c7 100644 --- a/drivers/hwspinlock/sun6i_hwspinlock.c +++ b/drivers/hwspinlock/sun6i_hwspinlock.c @@ -27,7 +27,6 @@ #define SPINLOCK_NOTTAKEN 0 struct sun6i_hwspinlock_data { - struct hwspinlock_device *bank; struct reset_control *reset; struct clk *ahb_clk; struct dentry *debugfs; @@ -161,13 +160,6 @@ static int sun6i_hwspinlock_probe(struct platform_device *pdev) goto bank_fail; } - priv->bank = devm_kzalloc(&pdev->dev, struct_size(priv->bank, lock, priv->nlocks), - GFP_KERNEL); - if (!priv->bank) { - err = -ENOMEM; - goto bank_fail; - } - /* failure of debugfs is considered non-fatal */ sun6i_hwspinlock_debugfs_init(priv); if (IS_ERR(priv->debugfs)) @@ -179,8 +171,8 @@ static int sun6i_hwspinlock_probe(struct platform_device *pdev) goto bank_fail; } - return devm_hwspin_lock_register(&pdev->dev, priv->bank, &sun6i_hwspinlock_ops, - SPINLOCK_BASE_ID, priv->nlocks, io_base + SPINLOCK_LOCK_REGN); + return devm_hwspin_lock_register_errno(&pdev->dev, &sun6i_hwspinlock_ops, SPINLOCK_BASE_ID, + priv->nlocks, io_base + SPINLOCK_LOCK_REGN); bank_fail: clk_disable_unprepare(priv->ahb_clk); diff --git a/include/linux/hwspinlock.h b/include/linux/hwspinlock.h index 094a6d0d39d6..58733cda7a9a 100644 --- a/include/linux/hwspinlock.h +++ b/include/linux/hwspinlock.h @@ -29,8 +29,8 @@ struct hwspinlock_ops; void *hwspin_lock_get_priv(struct hwspinlock *hwlock); struct device *hwspin_lock_get_dev(struct hwspinlock *hwlock); -int hwspin_lock_register(struct hwspinlock_device *bank, struct device *dev, - const struct hwspinlock_ops *ops, int base_id, int num_locks, void *init_data); +struct hwspinlock_device *hwspin_lock_register(struct device *dev, const struct hwspinlock_ops *ops, + int base_id, int num_locks, void *init_data); int hwspin_lock_unregister(struct hwspinlock_device *bank); struct hwspinlock *hwspin_lock_request_specific(unsigned int id); int hwspin_lock_free(struct hwspinlock *hwlock); @@ -46,10 +46,15 @@ struct hwspinlock *devm_hwspin_lock_request_specific(struct device *dev, unsigned int id); int devm_hwspin_lock_unregister(struct device *dev, struct hwspinlock_device *bank); -int devm_hwspin_lock_register(struct device *dev, - struct hwspinlock_device *bank, - const struct hwspinlock_ops *ops, - int base_id, int num_locks, void *init_data); +struct hwspinlock_device *devm_hwspin_lock_register(struct device *dev, const struct hwspinlock_ops *ops, + int base_id, int num_locks, void *init_data); + +static inline int devm_hwspin_lock_register_errno(struct device *dev, + const struct hwspinlock_ops *ops, + int base_id, int num_locks, void *init_data) +{ + return PTR_ERR_OR_ZERO(devm_hwspin_lock_register(dev, ops, base_id, num_locks, init_data)); +} #else /* !CONFIG_HWSPINLOCK */ From patchwork Sun Feb 15 22:54:49 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 447 Received: from mail.zeus03.de (zeus03.de [194.117.254.33]) (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 ECFC330B53B for ; Sun, 15 Feb 2026 22:55:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.117.254.33 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771196136; cv=none; b=nijyJKcPwZJilsxDxDVWod1VqO2jwA1bCEyZaxS7bvecqufGsI2omxmnm4uApotE14UO7W9WdD5yjCPIafneZsVTmGXp7fIe+u1k5cCK2RUExYJC7mwDiihZF/UqdyYxsuO4GFRY3ZJyk8xypKLlKBUt5Cgr/PlZNJdMMu88K9M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771196136; c=relaxed/simple; bh=uzc3fyoi8FSR6bwgllT3vuutQc1YoByfPGRM76QKxto=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i1QUk0FEO8pbKjCsqQTXEh3Odz7a2m1Sgd3N8D6ggu1PrhK2LAg/FcEuQ0NJL65G/xYZOiI3wLvwiMcu9U6MtDCJ9X/6NGGAtweV2eKQM3M/6cW4Y8OK6CWOocfpNdZCgc8yauqoBYcrMpduh/VKjX3VShmG9jioHPKNRPnNu9Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com; spf=pass smtp.mailfrom=sang-engineering.com; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b=NvN8AVbc; arc=none smtp.client-ip=194.117.254.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b="NvN8AVbc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= sang-engineering.com; h=from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; s=k1; bh=huat1Y/wJ/zb768/t+yGa5XgKV25MRf5vTJTHiQcbnY=; b=NvN8AV bcA5+t3BSWpu4Yxi5SeahcfOkLf2MlG/O5tz5YcxFdGPaPWcHQ8IzmZ4S0OQScA0 0bC7Awg+it2QiSr50BkF/nUQxc/J2WjdTuAe8w2hhZDL1iRr3AyUMfUwqlX28C1N la9KM60Dl5Nrn2qOuWhnQq3vr1lRE0XncUwosMG7Zq/CTocb4YfHDVu8z4VSi1yZ Q+dnoUrdM8FuSviASxQfsfJ9lA32HGBGIyL2sn+7W+7VjPTc56mHBzoI7RQsZmpS 779A5fFr9KYsSYIwODUcJ265th+TEHj2563XbktOZUYI5mPx7EDCP/khtSTDzCb5 NTnrz4Dv7csXKEEQ== Received: (qmail 3011557 invoked from network); 15 Feb 2026 23:55:16 +0100 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 15 Feb 2026 23:55:16 +0100 X-UD-Smtp-Session: l3s3148p1@qVdLu+RK+sAujns5 From: Wolfram Sang To: linux-renesas-soc@vger.kernel.org Cc: Andy Shevchenko , linux-arm-kernel@lists.infradead.org, Wolfram Sang , Bjorn Andersson , Baolin Wang , Orson Zhai , Chunyan Zhang , Maxime Coquelin , Alexandre Torgue , Wilken Gottwalt , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , linux-remoteproc@vger.kernel.org, linux-omap@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-sunxi@lists.linux.dev Subject: [RFC PATCH v2 09/13] hwspinlock: move entries from internal to public header Date: Sun, 15 Feb 2026 23:54:49 +0100 Message-ID: <20260215225501.6365-10-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260215225501.6365-1-wsa+renesas@sang-engineering.com> References: <20260215225501.6365-1-wsa+renesas@sang-engineering.com> Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Status: O Providers need the ops-structure and the hwlock_to_id-function. Move these entries to the public header. With this change, all providers are also updated to use the public header only. The internal header is now used by the core only. Signed-off-by: Wolfram Sang --- drivers/hwspinlock/hwspinlock_core.c | 8 +++++++ drivers/hwspinlock/hwspinlock_internal.h | 29 ------------------------ drivers/hwspinlock/omap_hwspinlock.c | 2 -- drivers/hwspinlock/qcom_hwspinlock.c | 2 -- drivers/hwspinlock/sprd_hwspinlock.c | 2 -- drivers/hwspinlock/stm32_hwspinlock.c | 2 -- drivers/hwspinlock/sun6i_hwspinlock.c | 2 -- include/linux/hwspinlock.h | 23 +++++++++++++++++++ 8 files changed, 31 insertions(+), 39 deletions(-) diff --git a/drivers/hwspinlock/hwspinlock_core.c b/drivers/hwspinlock/hwspinlock_core.c index a7610ba755b4..e0227d027cf2 100644 --- a/drivers/hwspinlock/hwspinlock_core.c +++ b/drivers/hwspinlock/hwspinlock_core.c @@ -915,5 +915,13 @@ struct device *hwspin_lock_get_dev(struct hwspinlock *hwlock) } EXPORT_SYMBOL_GPL(hwspin_lock_get_dev); +int hwlock_to_id(struct hwspinlock *hwlock) +{ + int local_id = hwlock - &hwlock->bank->lock[0]; + + return hwlock->bank->base_id + local_id; +} +EXPORT_SYMBOL_GPL(hwlock_to_id); + MODULE_DESCRIPTION("Hardware spinlock interface"); MODULE_AUTHOR("Ohad Ben-Cohen "); diff --git a/drivers/hwspinlock/hwspinlock_internal.h b/drivers/hwspinlock/hwspinlock_internal.h index 3c835d96bf86..20ae531fc389 100644 --- a/drivers/hwspinlock/hwspinlock_internal.h +++ b/drivers/hwspinlock/hwspinlock_internal.h @@ -15,28 +15,6 @@ struct hwspinlock_device; -/** - * struct hwspinlock_ops - platform-specific hwspinlock handlers - * - * @trylock: make a single attempt to take the lock. returns 0 on - * failure and true on success. may _not_ sleep. - * @unlock: release the lock. always succeed. may _not_ sleep. - * @bust: optional, platform-specific bust handler, called by hwspinlock - * core to bust a specific lock. - * @relax: optional, platform-specific relax handler, called by hwspinlock - * core while spinning on a lock, between two successive - * invocations of @trylock. may _not_ sleep. - * @init_priv: optional, callback used when registering the hwspinlock device. - * Its return value will be used to fill the per-lock 'priv' data. - */ -struct hwspinlock_ops { - int (*trylock)(struct hwspinlock *lock); - void (*unlock)(struct hwspinlock *lock); - int (*bust)(struct hwspinlock *lock, unsigned int id); - void (*relax)(struct hwspinlock *lock); - void *(*init_priv)(int local_id, void *init_data); -}; - /** * struct hwspinlock - this struct represents a single hwspinlock instance * @bank: the hwspinlock_device structure which owns this lock @@ -65,11 +43,4 @@ struct hwspinlock_device { struct hwspinlock lock[]; }; -static inline int hwlock_to_id(struct hwspinlock *hwlock) -{ - int local_id = hwlock - &hwlock->bank->lock[0]; - - return hwlock->bank->base_id + local_id; -} - #endif /* __HWSPINLOCK_HWSPINLOCK_H */ diff --git a/drivers/hwspinlock/omap_hwspinlock.c b/drivers/hwspinlock/omap_hwspinlock.c index f1ff6406db46..96fdc35ef642 100644 --- a/drivers/hwspinlock/omap_hwspinlock.c +++ b/drivers/hwspinlock/omap_hwspinlock.c @@ -23,8 +23,6 @@ #include #include -#include "hwspinlock_internal.h" - /* Spinlock register offsets */ #define SYSSTATUS_OFFSET 0x0014 #define LOCK_BASE_OFFSET 0x0800 diff --git a/drivers/hwspinlock/qcom_hwspinlock.c b/drivers/hwspinlock/qcom_hwspinlock.c index e2836d6728e8..22cc6f9003df 100644 --- a/drivers/hwspinlock/qcom_hwspinlock.c +++ b/drivers/hwspinlock/qcom_hwspinlock.c @@ -14,8 +14,6 @@ #include #include -#include "hwspinlock_internal.h" - #define QCOM_MUTEX_APPS_PROC_ID 1 #define QCOM_MUTEX_NUM_LOCKS 32 diff --git a/drivers/hwspinlock/sprd_hwspinlock.c b/drivers/hwspinlock/sprd_hwspinlock.c index 95b254e9b6a0..d2aa4714e2ea 100644 --- a/drivers/hwspinlock/sprd_hwspinlock.c +++ b/drivers/hwspinlock/sprd_hwspinlock.c @@ -15,8 +15,6 @@ #include #include -#include "hwspinlock_internal.h" - /* hwspinlock registers definition */ #define HWSPINLOCK_RECCTRL 0x4 #define HWSPINLOCK_MASTERID(_X_) (0x80 + 0x4 * (_X_)) diff --git a/drivers/hwspinlock/stm32_hwspinlock.c b/drivers/hwspinlock/stm32_hwspinlock.c index a966e967dcdb..08762cd96cee 100644 --- a/drivers/hwspinlock/stm32_hwspinlock.c +++ b/drivers/hwspinlock/stm32_hwspinlock.c @@ -14,8 +14,6 @@ #include #include -#include "hwspinlock_internal.h" - #define STM32_MUTEX_COREID BIT(8) #define STM32_MUTEX_LOCK_BIT BIT(31) #define STM32_MUTEX_NUM_LOCKS 32 diff --git a/drivers/hwspinlock/sun6i_hwspinlock.c b/drivers/hwspinlock/sun6i_hwspinlock.c index 8e17deb503c7..5c6d20eb24b5 100644 --- a/drivers/hwspinlock/sun6i_hwspinlock.c +++ b/drivers/hwspinlock/sun6i_hwspinlock.c @@ -17,8 +17,6 @@ #include #include -#include "hwspinlock_internal.h" - #define DRIVER_NAME "sun6i_hwspinlock" #define SPINLOCK_BASE_ID 0 /* there is only one hwspinlock device per SoC */ diff --git a/include/linux/hwspinlock.h b/include/linux/hwspinlock.h index 58733cda7a9a..4f5b6932712e 100644 --- a/include/linux/hwspinlock.h +++ b/include/linux/hwspinlock.h @@ -27,8 +27,31 @@ struct hwspinlock_ops; #ifdef CONFIG_HWSPINLOCK +/** + * struct hwspinlock_ops - platform-specific hwspinlock handlers + * + * @trylock: make a single attempt to take the lock. returns 0 on + * failure and true on success. may _not_ sleep. + * @unlock: release the lock. always succeed. may _not_ sleep. + * @bust: optional, platform-specific bust handler, called by hwspinlock + * core to bust a specific lock. + * @relax: optional, platform-specific relax handler, called by hwspinlock + * core while spinning on a lock, between two successive + * invocations of @trylock. may _not_ sleep. + * @init_priv: optional, callback used when registering the hwspinlock device. + * Its return value will be used to fill the per-lock 'priv' data. + */ +struct hwspinlock_ops { + int (*trylock)(struct hwspinlock *lock); + void (*unlock)(struct hwspinlock *lock); + int (*bust)(struct hwspinlock *lock, unsigned int id); + void (*relax)(struct hwspinlock *lock); + void *(*init_priv)(int local_id, void *init_data); +}; + void *hwspin_lock_get_priv(struct hwspinlock *hwlock); struct device *hwspin_lock_get_dev(struct hwspinlock *hwlock); +int hwlock_to_id(struct hwspinlock *hwlock); struct hwspinlock_device *hwspin_lock_register(struct device *dev, const struct hwspinlock_ops *ops, int base_id, int num_locks, void *init_data); int hwspin_lock_unregister(struct hwspinlock_device *bank); From patchwork Sun Feb 15 22:54:52 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 446 Received: from mail.zeus03.de (zeus03.de [194.117.254.33]) (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 59A1530B53B for ; Sun, 15 Feb 2026 22:55:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.117.254.33 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771196142; cv=none; b=faabftsAgASeeCF1sjBkptOHz7OKWln7ul7EO8Nn2UZugojJtvaGZ9dCfzK4qiplbd112RL0PjDT++46FdFEz0/DxefAIWG92bV9A5bemSn2s8+aIHZybQb0lsc5QRvpBn9AsUUnmvgitXe2/XQBWuhKNk9/dRtsIkgacNdBq3o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771196142; c=relaxed/simple; bh=B6oiWoJekyOt88Ci/SiJiaCueiS0d3nbQCbuLNiyKMk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tJlSC59oPA3no7jesQmIhP29SWMj6xhfwVfvkITgLjZoZ4GPErjIr1XuJlHYpWFVRl7mDB5aqOZFg+iX/vihFzgROVUtBnRUcLArnCHP5XqTZPIy6yg1nH8zExvcN4Zs7uvrEODMAZs/SQggjTbYv4dc1ux/dPKBXbRamHuTA5w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com; spf=pass smtp.mailfrom=sang-engineering.com; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b=P4ZzrPOn; arc=none smtp.client-ip=194.117.254.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sang-engineering.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b="P4ZzrPOn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= sang-engineering.com; h=from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; s=k1; bh=v5n+dNUs/sl4SVM136Ix4+IYgDSC7nyhR22DxT/PH9E=; b=P4ZzrP OnYDGDcT2KBiLdRtqM/EPxiZL2p7kiz0Mz6ufSheZsOytf2TpDaW1NI4bcBFm++H QSRMalkbG6J2o4iwB8lV/rnS5+FIImoETc55izlAnCmSm28k+4fBu+1EW9/pht8s vuPLZ0xG9Y3l0yDChNTesAVV5oVathKPYejDH+/jv/rQ6wuDceFit6Nn7QG6gouz Q94NGQ+p0tyC8L22d8e/hR46EaeS+tYJU8cZCOZlHXr1QHtNdcdxSYd1amfgKcIp 92CFF/PJ9YB/1dkSvyamILR6UucVLRMDkLZwkOccmLQnxpmZK6hkYNqBN6Cniufy OdMVWyk7LViMEXhQ== Received: (qmail 3011705 invoked from network); 15 Feb 2026 23:55:19 +0100 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 15 Feb 2026 23:55:19 +0100 X-UD-Smtp-Session: l3s3148p1@XC6Hu+RKIMEujns5 From: Wolfram Sang To: linux-renesas-soc@vger.kernel.org Cc: Andy Shevchenko , linux-arm-kernel@lists.infradead.org, Wolfram Sang , Bjorn Andersson , Baolin Wang , Orson Zhai , Chunyan Zhang , Maxime Coquelin , Alexandre Torgue , Wilken Gottwalt , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , linux-remoteproc@vger.kernel.org, linux-omap@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-sunxi@lists.linux.dev Subject: [RFC PATCH v2 12/13] hwspinlock: refactor provider.h from public header Date: Sun, 15 Feb 2026 23:54:52 +0100 Message-ID: <20260215225501.6365-13-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260215225501.6365-1-wsa+renesas@sang-engineering.com> References: <20260215225501.6365-1-wsa+renesas@sang-engineering.com> Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Status: O Factor out the entries only needed for providers from the generic public header. This allows for a clean separation between providers and consumers. All providers are in the hwspinlock subsystem currently and are trivially converted here as well. Signed-off-by: Wolfram Sang --- MAINTAINERS | 1 + drivers/hwspinlock/hwspinlock_core.c | 1 + drivers/hwspinlock/omap_hwspinlock.c | 2 +- drivers/hwspinlock/qcom_hwspinlock.c | 2 +- drivers/hwspinlock/sprd_hwspinlock.c | 2 +- drivers/hwspinlock/stm32_hwspinlock.c | 2 +- drivers/hwspinlock/sun6i_hwspinlock.c | 2 +- include/linux/hwspinlock.h | 44 -------------------- include/linux/hwspinlock/provider.h | 60 +++++++++++++++++++++++++++ 9 files changed, 67 insertions(+), 49 deletions(-) create mode 100644 include/linux/hwspinlock/provider.h diff --git a/MAINTAINERS b/MAINTAINERS index dcdbb7c10dce..f9131b8cd5d2 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -11215,6 +11215,7 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/andersson/remoteproc.git hw F: Documentation/devicetree/bindings/hwlock/ F: Documentation/locking/hwspinlock.rst F: drivers/hwspinlock/ +F: include/linux/hwspinlock/ F: include/linux/hwspinlock.h HARDWARE TRACING FACILITIES diff --git a/drivers/hwspinlock/hwspinlock_core.c b/drivers/hwspinlock/hwspinlock_core.c index adf6fefb382f..6c8a03deb00c 100644 --- a/drivers/hwspinlock/hwspinlock_core.c +++ b/drivers/hwspinlock/hwspinlock_core.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include diff --git a/drivers/hwspinlock/omap_hwspinlock.c b/drivers/hwspinlock/omap_hwspinlock.c index 96fdc35ef642..338ae9fa89f0 100644 --- a/drivers/hwspinlock/omap_hwspinlock.c +++ b/drivers/hwspinlock/omap_hwspinlock.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include diff --git a/drivers/hwspinlock/qcom_hwspinlock.c b/drivers/hwspinlock/qcom_hwspinlock.c index 22cc6f9003df..7fdbb1e58b29 100644 --- a/drivers/hwspinlock/qcom_hwspinlock.c +++ b/drivers/hwspinlock/qcom_hwspinlock.c @@ -4,7 +4,7 @@ * Copyright (c) 2015, Sony Mobile Communications AB */ -#include +#include #include #include #include diff --git a/drivers/hwspinlock/sprd_hwspinlock.c b/drivers/hwspinlock/sprd_hwspinlock.c index d2aa4714e2ea..f6014b314432 100644 --- a/drivers/hwspinlock/sprd_hwspinlock.c +++ b/drivers/hwspinlock/sprd_hwspinlock.c @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/drivers/hwspinlock/stm32_hwspinlock.c b/drivers/hwspinlock/stm32_hwspinlock.c index 08762cd96cee..a22ebabe1921 100644 --- a/drivers/hwspinlock/stm32_hwspinlock.c +++ b/drivers/hwspinlock/stm32_hwspinlock.c @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include #include diff --git a/drivers/hwspinlock/sun6i_hwspinlock.c b/drivers/hwspinlock/sun6i_hwspinlock.c index 5c6d20eb24b5..4dab91800745 100644 --- a/drivers/hwspinlock/sun6i_hwspinlock.c +++ b/drivers/hwspinlock/sun6i_hwspinlock.c @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/include/linux/hwspinlock.h b/include/linux/hwspinlock.h index 4f5b6932712e..4fe1c8831cd1 100644 --- a/include/linux/hwspinlock.h +++ b/include/linux/hwspinlock.h @@ -27,34 +27,6 @@ struct hwspinlock_ops; #ifdef CONFIG_HWSPINLOCK -/** - * struct hwspinlock_ops - platform-specific hwspinlock handlers - * - * @trylock: make a single attempt to take the lock. returns 0 on - * failure and true on success. may _not_ sleep. - * @unlock: release the lock. always succeed. may _not_ sleep. - * @bust: optional, platform-specific bust handler, called by hwspinlock - * core to bust a specific lock. - * @relax: optional, platform-specific relax handler, called by hwspinlock - * core while spinning on a lock, between two successive - * invocations of @trylock. may _not_ sleep. - * @init_priv: optional, callback used when registering the hwspinlock device. - * Its return value will be used to fill the per-lock 'priv' data. - */ -struct hwspinlock_ops { - int (*trylock)(struct hwspinlock *lock); - void (*unlock)(struct hwspinlock *lock); - int (*bust)(struct hwspinlock *lock, unsigned int id); - void (*relax)(struct hwspinlock *lock); - void *(*init_priv)(int local_id, void *init_data); -}; - -void *hwspin_lock_get_priv(struct hwspinlock *hwlock); -struct device *hwspin_lock_get_dev(struct hwspinlock *hwlock); -int hwlock_to_id(struct hwspinlock *hwlock); -struct hwspinlock_device *hwspin_lock_register(struct device *dev, const struct hwspinlock_ops *ops, - int base_id, int num_locks, void *init_data); -int hwspin_lock_unregister(struct hwspinlock_device *bank); struct hwspinlock *hwspin_lock_request_specific(unsigned int id); int hwspin_lock_free(struct hwspinlock *hwlock); int of_hwspin_lock_get_id(struct device_node *np, int index); @@ -67,18 +39,6 @@ int hwspin_lock_bust(struct hwspinlock *hwlock, unsigned int id); int devm_hwspin_lock_free(struct device *dev, struct hwspinlock *hwlock); struct hwspinlock *devm_hwspin_lock_request_specific(struct device *dev, unsigned int id); -int devm_hwspin_lock_unregister(struct device *dev, - struct hwspinlock_device *bank); -struct hwspinlock_device *devm_hwspin_lock_register(struct device *dev, const struct hwspinlock_ops *ops, - int base_id, int num_locks, void *init_data); - -static inline int devm_hwspin_lock_register_errno(struct device *dev, - const struct hwspinlock_ops *ops, - int base_id, int num_locks, void *init_data) -{ - return PTR_ERR_OR_ZERO(devm_hwspin_lock_register(dev, ops, base_id, num_locks, init_data)); -} - #else /* !CONFIG_HWSPINLOCK */ /* @@ -87,10 +47,6 @@ static inline int devm_hwspin_lock_register_errno(struct device *dev, * code path get compiled away. This way, if CONFIG_HWSPINLOCK is not * required on a given setup, users will still work. * - * The only exception is hwspin_lock_register/hwspin_lock_unregister, with which - * we _do_ want users to fail (no point in registering hwspinlock instances if - * the framework is not available). - * * Note: ERR_PTR(-ENODEV) will still be considered a success for NULL-checking * users. Others, which care, can still check this with IS_ERR. */ diff --git a/include/linux/hwspinlock/provider.h b/include/linux/hwspinlock/provider.h new file mode 100644 index 000000000000..73c7b0cb6735 --- /dev/null +++ b/include/linux/hwspinlock/provider.h @@ -0,0 +1,60 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Hardware spinlock public header for providers + * + * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com + * Copyright (C) 2026 Sang Engineering + * Copyright (C) 2026 Renesas Solutions Corp. + */ + +#ifndef __LINUX_HWSPINLOCK_PROVIDER_H +#define __LINUX_HWSPINLOCK_PROVIDER_H + +#include + +struct device; +struct hwspinlock; +struct hwspinlock_device; + +/** + * struct hwspinlock_ops - platform-specific hwspinlock handlers + * + * @trylock: make a single attempt to take the lock. returns 0 on + * failure and true on success. may _not_ sleep. + * @unlock: release the lock. always succeed. may _not_ sleep. + * @bust: optional, platform-specific bust handler, called by hwspinlock + * core to bust a specific lock. + * @relax: optional, platform-specific relax handler, called by hwspinlock + * core while spinning on a lock, between two successive + * invocations of @trylock. may _not_ sleep. + * @init_priv: optional, callback used when registering the hwspinlock device. + * Its return value will be used to fill the per-lock 'priv' data. + */ +struct hwspinlock_ops { + int (*trylock)(struct hwspinlock *lock); + void (*unlock)(struct hwspinlock *lock); + int (*bust)(struct hwspinlock *lock, unsigned int id); + void (*relax)(struct hwspinlock *lock); + void *(*init_priv)(int local_id, void *init_data); +}; + +void *hwspin_lock_get_priv(struct hwspinlock *hwlock); +struct device *hwspin_lock_get_dev(struct hwspinlock *hwlock); +int hwlock_to_id(struct hwspinlock *hwlock); +struct hwspinlock_device *hwspin_lock_register(struct device *dev, const struct hwspinlock_ops *ops, + int base_id, int num_locks, void *init_data); +int hwspin_lock_unregister(struct hwspinlock_device *bank); + +struct hwspinlock_device *devm_hwspin_lock_register(struct device *dev, const struct hwspinlock_ops *ops, + int base_id, int num_locks, void *init_data); +int devm_hwspin_lock_unregister(struct device *dev, + struct hwspinlock_device *bank); + +static inline int devm_hwspin_lock_register_errno(struct device *dev, + const struct hwspinlock_ops *ops, + int base_id, int num_locks, void *init_data) +{ + return PTR_ERR_OR_ZERO(devm_hwspin_lock_register(dev, ops, base_id, num_locks, init_data)); +} + +#endif /* __LINUX_HWSPINLOCK_PROVIDER_H */