From patchwork Thu Mar 19 10:59:25 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 129 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 418BB3C73C3 for ; Thu, 19 Mar 2026 11:00:12 +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=1773918022; cv=none; b=Sh0IZc/cyP354xagZI1N3EttCvpU5MOlSKqkgoO1G6AQwadBQ3aZYvybXUe4acnpJd05ju3QiKpie+4vxzmAxQrEQFbd7PYh3M3YpkkhxWUYfpUJrPEVIvtC0mPPAEaFNbaRzjSbmqZRBXvAlbM5GmwwmD4N+80lQd+nKR3JE/c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773918022; c=relaxed/simple; bh=xy50e2OIp3/2ajapNXpLDbRqFj3IWYNEJO+w4nlrwQM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GL1vXF9OmsAIE3USfGV08XDluN4NTBB8TyqeIG05HnIiAlAGpa8HpVg82aofhiNEiQg6litgRY5bmYxCIlUMUT4MbySs/hXWuKXcvbtugPAUessimpMVhEA87HudQ/klA8YjkM159F8yAAgsLyWrszM+GqLiwZQZyaDW6mmZEUo= 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=DKJvjVcc; 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="DKJvjVcc" 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=IZFdVpEXf9xrxaE4IR8cLQeU2fEvB2OHSkK785cEcYY=; b=DKJvjV ccTsM7Z871WbtxjKI2bNa5gsZMxNOtIeJ1g8Mygg7mHvumDuAHpzJvEYC/B37hbE 7yCrexAoxc0qlUtlA69nSv1rmDPsYgV1OiiHv1d4YYJrpWodqGH0xzD53bnOGUIh EtAIdj5sl5wvTacHXQ3uyztMDHTTLPkIaFvvlr6UXYkmYQbafXso2O/Kc3efIeTN pAvKZkJ49H3xjH0vrae0He38QRZ3eHmpOD1q4NkTax/BeGV6k/fFFOzGUNcPTBFg m6Ds8HPQ4glaWfeVDqNUiKiiXJ1Y12H4HgMKzb5Ybng1oz+B/A+NRH55SSgvW83m bwiRbafqUAzJ9Hyw== Received: (qmail 1099512 invoked from network); 19 Mar 2026 11:59:54 +0100 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 19 Mar 2026 11:59:54 +0100 X-UD-Smtp-Session: l3s3148p1@XVrvd15N4t0gAwDPXzF+ANZpdrMKUeLI From: Wolfram Sang To: linux-renesas-soc@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Wolfram Sang , Chen-Yu Tsai , Bjorn Andersson , Baolin Wang , Orson Zhai , Chunyan Zhang , Maxime Coquelin , Alexandre Torgue , Wilken Gottwalt , 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-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH v5 03/15] hwspinlock: add helpers to retrieve core data Date: Thu, 19 Mar 2026 11:59:25 +0100 Message-ID: <20260319105947.6237-4-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260319105947.6237-1-wsa+renesas@sang-engineering.com> References: <20260319105947.6237-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 Acked-by: Chen-Yu Tsai # for sun6i --- 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 Thu Mar 19 10:59:26 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 130 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 B6BCE3C6A26 for ; Thu, 19 Mar 2026 11:00:17 +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=1773918021; cv=none; b=jJyCEVNRT4qxZHvOwyKZseXqkEOSpcEIsPLq/KHIN02E34e2fNKgvBwGFvwV1D1SY3ZvuXsRiU4m1Ksn/wvV9XdUgg6psktflsTLMzl7yiTVxoe6ixS+QCLCzSNW40Kj/5aqws0fF87rBq+z4Z/EiFqb9lFhHfCGxruQ1GYMYKw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773918021; c=relaxed/simple; bh=j7JsogHPEG2k3FleveztzMhcaRMl7IeOoIUkHDuMsIM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TFsTUD+mVrehztjDwb48lGCENf3Tv3p9aluSrFLHfAXwQv+8rRfVE7vrUp0uTmfn/+tldp+SgIUuDZJfgOsM8wFen7CpgNHOVR7Kmk7EEK+kIOB6MbHTA6bU5JoysIa0cGcNBN9yVuwuLHynGb6Ik8bftjieJk9yj7PfHL86OkE= 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=fK4f3dKO; 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="fK4f3dKO" 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=52UHmgmukdvJVk0o+2tbQ5APoShQb1Fkmq5YJKeK1WA=; b=fK4f3d KOg8BCLXt8Vc1fZQxpxxQyp8tNVbAaLDZZBUSxvEK/pcXPJWX2vg8KXv+bWD+6Yb iD9aNQIv8GYJ/GAyFVAdtTwoXx1IO4Ik6NkG7x+OIZtaNttx9BO5pSDJJk44pglF eP4BkNZUWO9P/31iatpp8upWpSnISRmVkinum8MBMCwz9SGxF7Jkh4vlcYocGexh /fXQiCZIyV81S4ka9tPsFz/PbIFToBV4H0kElmLe7yG8J9IsEMJj3Mq/qFfrVGq3 r9ZgpYbUTNj2DPzhBc0uuVBkvU4MYA7ouUw8k63Gf6sSvHgSiVVSYhf0+3fxpQJY irPjsnr9yuObc6mg== Received: (qmail 1099536 invoked from network); 19 Mar 2026 11:59:56 +0100 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 19 Mar 2026 11:59:56 +0100 X-UD-Smtp-Session: l3s3148p1@byoIeF5N5t0gAwDPXzF+ANZpdrMKUeLI From: Wolfram Sang To: linux-renesas-soc@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Wolfram Sang , Bjorn Andersson , Baolin Wang , Peter Zijlstra , Ingo Molnar , Will Deacon , Boqun Feng , Waiman Long , Jonathan Corbet , Shuah Khan , Orson Zhai , Chunyan Zhang , Maxime Coquelin , Alexandre Torgue , Wilken Gottwalt , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , linux-remoteproc@vger.kernel.org, linux-doc@vger.kernel.org, linux-omap@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH v5 04/15] hwspinlock: add callback to fill private data of a hwspinlock Date: Thu, 19 Mar 2026 11:59:26 +0100 Message-ID: <20260319105947.6237-5-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260319105947.6237-1-wsa+renesas@sang-engineering.com> References: <20260319105947.6237-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 To hide internal core structures from providers, a callback is added to the ops which allows to set the 'priv' field of a hwspinlock. It is called when a hwspinlock device is registered and, thus, iterated over all locks. The register-functions are also extended to pass a data pointer to this callback, so it can do necessary calculations for the priv field of each hwspinlock. Providers are added only an empty placeholder and are converted separately because these changes need dedicated reviews. Signed-off-by: Wolfram Sang Acked-by: Chen-Yu Tsai # for sun6i --- Documentation/locking/hwspinlock.rst | 3 ++- drivers/hwspinlock/hwspinlock_core.c | 19 +++++++++++++++---- drivers/hwspinlock/hwspinlock_internal.h | 19 +++++++++++-------- 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 | 4 ++-- 9 files changed, 35 insertions(+), 20 deletions(-) diff --git a/Documentation/locking/hwspinlock.rst b/Documentation/locking/hwspinlock.rst index a737c702a7d1..cedeeab7387c 100644 --- a/Documentation/locking/hwspinlock.rst +++ b/Documentation/locking/hwspinlock.rst @@ -351,7 +351,8 @@ API for implementors :: int hwspin_lock_register(struct hwspinlock_device *bank, struct device *dev, - const struct hwspinlock_ops *ops, int base_id, int num_locks); + const struct hwspinlock_ops *ops, int base_id, + int num_locks, void *init_data); To be called from the underlying platform-specific implementation, in order to register a new hwspinlock device (which is usually a bank of diff --git a/drivers/hwspinlock/hwspinlock_core.c b/drivers/hwspinlock/hwspinlock_core.c index 2c9eceba7fe8..afe1e7ce2829 100644 --- a/drivers/hwspinlock/hwspinlock_core.c +++ b/drivers/hwspinlock/hwspinlock_core.c @@ -507,6 +507,7 @@ static struct hwspinlock *hwspin_lock_unregister_single(unsigned int id) * @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 + * @init_data: additional data passed on to the init_priv callback * * This function should be called from the underlying platform-specific * implementation, to register a new hwspinlock device instance. @@ -516,10 +517,11 @@ static struct hwspinlock *hwspin_lock_unregister_single(unsigned int id) * Returns: %0 on success, or an appropriate error code on failure */ int hwspin_lock_register(struct hwspinlock_device *bank, struct device *dev, - const struct hwspinlock_ops *ops, int base_id, int num_locks) + const struct hwspinlock_ops *ops, int base_id, int num_locks, + void *init_data) { struct hwspinlock *hwlock; - int ret = 0, i; + int ret, i; if (!bank || !ops || !dev || !num_locks || !ops->trylock || !ops->unlock) { @@ -538,6 +540,14 @@ int hwspin_lock_register(struct hwspinlock_device *bank, struct device *dev, spin_lock_init(&hwlock->lock); hwlock->bank = bank; + if (ops->init_priv) { + hwlock->priv = ops->init_priv(i, init_data); + if (IS_ERR(hwlock->priv)) { + ret = PTR_ERR(hwlock->priv); + goto reg_failed; + } + } + ret = hwspin_lock_register_single(hwlock, base_id + i); if (ret) goto reg_failed; @@ -633,6 +643,7 @@ EXPORT_SYMBOL_GPL(devm_hwspin_lock_unregister); * @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 + * @init_data: additional data passed on to the init_priv callback * * This function should be called from the underlying platform-specific * implementation, to register a new hwspinlock device instance. @@ -644,7 +655,7 @@ EXPORT_SYMBOL_GPL(devm_hwspin_lock_unregister); int devm_hwspin_lock_register(struct device *dev, struct hwspinlock_device *bank, const struct hwspinlock_ops *ops, - int base_id, int num_locks) + int base_id, int num_locks, void *init_data) { struct hwspinlock_device **ptr; int ret; @@ -653,7 +664,7 @@ int devm_hwspin_lock_register(struct device *dev, if (!ptr) return -ENOMEM; - ret = hwspin_lock_register(bank, dev, ops, base_id, num_locks); + ret = hwspin_lock_register(bank, dev, ops, base_id, num_locks, init_data); if (!ret) { *ptr = bank; devres_add(dev, ptr); diff --git a/drivers/hwspinlock/hwspinlock_internal.h b/drivers/hwspinlock/hwspinlock_internal.h index f298fc0ee5ad..3c835d96bf86 100644 --- a/drivers/hwspinlock/hwspinlock_internal.h +++ b/drivers/hwspinlock/hwspinlock_internal.h @@ -18,20 +18,23 @@ 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. + * @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); }; /** diff --git a/drivers/hwspinlock/omap_hwspinlock.c b/drivers/hwspinlock/omap_hwspinlock.c index 5bf0061d3fd6..adff502bcbc4 100644 --- a/drivers/hwspinlock/omap_hwspinlock.c +++ b/drivers/hwspinlock/omap_hwspinlock.c @@ -120,7 +120,7 @@ static int omap_hwspinlock_probe(struct platform_device *pdev) bank->lock[i].priv = io_base + LOCK_BASE_OFFSET + sizeof(u32) * i; return devm_hwspin_lock_register(&pdev->dev, bank, &omap_hwspinlock_ops, - base_id, num_locks); + base_id, num_locks, NULL); } 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 7ff89c3e8c6b..7960a4972eab 100644 --- a/drivers/hwspinlock/qcom_hwspinlock.c +++ b/drivers/hwspinlock/qcom_hwspinlock.c @@ -236,7 +236,7 @@ static int qcom_hwspinlock_probe(struct platform_device *pdev) } return devm_hwspin_lock_register(&pdev->dev, bank, &qcom_hwspinlock_ops, - 0, QCOM_MUTEX_NUM_LOCKS); + 0, QCOM_MUTEX_NUM_LOCKS, NULL); } static struct platform_driver qcom_hwspinlock_driver = { diff --git a/drivers/hwspinlock/sprd_hwspinlock.c b/drivers/hwspinlock/sprd_hwspinlock.c index 0d08efbdfb07..0b91bdd4303d 100644 --- a/drivers/hwspinlock/sprd_hwspinlock.c +++ b/drivers/hwspinlock/sprd_hwspinlock.c @@ -132,7 +132,7 @@ static int sprd_hwspinlock_probe(struct platform_device *pdev) return devm_hwspin_lock_register(&pdev->dev, &sprd_hwlock->bank, &sprd_hwspinlock_ops, 0, - SPRD_HWLOCKS_NUM); + SPRD_HWLOCKS_NUM, NULL); } 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 1d75dc03f4ad..51e8e533ac31 100644 --- a/drivers/hwspinlock/stm32_hwspinlock.c +++ b/drivers/hwspinlock/stm32_hwspinlock.c @@ -110,7 +110,7 @@ static int stm32_hwspinlock_probe(struct platform_device *pdev) hw->bank.lock[i].priv = io_base + i * sizeof(u32); ret = devm_hwspin_lock_register(dev, &hw->bank, &stm32_hwspinlock_ops, - 0, STM32_MUTEX_NUM_LOCKS); + 0, STM32_MUTEX_NUM_LOCKS, NULL); 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 8ff81cb5880a..a0c76bba3f05 100644 --- a/drivers/hwspinlock/sun6i_hwspinlock.c +++ b/drivers/hwspinlock/sun6i_hwspinlock.c @@ -180,7 +180,7 @@ static int sun6i_hwspinlock_probe(struct platform_device *pdev) 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, NULL); bank_fail: clk_disable_unprepare(priv->ahb_clk); diff --git a/include/linux/hwspinlock.h b/include/linux/hwspinlock.h index dffa1dff7289..094a6d0d39d6 100644 --- a/include/linux/hwspinlock.h +++ b/include/linux/hwspinlock.h @@ -30,7 +30,7 @@ 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); + 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); @@ -49,7 +49,7 @@ int devm_hwspin_lock_unregister(struct device *dev, int devm_hwspin_lock_register(struct device *dev, struct hwspinlock_device *bank, const struct hwspinlock_ops *ops, - int base_id, int num_locks); + int base_id, int num_locks, void *init_data); #else /* !CONFIG_HWSPINLOCK */ From patchwork Thu Mar 19 10:59:31 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 128 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 0BEAA3C6A28 for ; Thu, 19 Mar 2026 11:00:23 +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=1773918025; cv=none; b=cM4uizsicmu8xZf5mUWbwndbYtyZ6cUdrnoTuk0OJ8qek/K4BEmw2sucapCWUA7oa/+bsTkapGEiw8NseIrYMV528g24vv83ycAiuPAr+qq14Gnp7zqN1Cyy5BRgsnpJ7DogwxQq2z4TbP15M7mHp0FVAU0olYLtqYLqF6ZZNTw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773918025; c=relaxed/simple; bh=lPUlWLDZEIHKetKHHdMSN3sOG8dRuYx7PE4oGAgK69o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L3+HGKT6kGZQ2jzSB0c6VSodJEZy7Fz01bXg/YuflJQPO7t+gyId7hukbsiMlS92yzmc99b2w5CmWHgJI/b/qP81EWvlsijVVIPruJeSEFOy1X2PK7x48Ek3Vs0yh3oZL0ef6CHAqyyaB6O8neszBWkD/VJGDYQRm8k8Ii1xzhU= 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=Vef3M3MZ; 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="Vef3M3MZ" 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=zC6Y1AkSSP6gBbG0k4SbZrnCH1NvYvCklVNqT+RHEM0=; b=Vef3M3 MZMMYT8RPLvd1Eq3WmfHKWQqATDW/hmqBvASwumh4Xnf6rfnsqDsKQ1HKRxN3h6L LU6FLsKYCdaNhYJgjiK7rMbRKWjRVTxHt/WTrf5VVe0MDCFQr/V6i6FZfKnXLgVs AAsiZodPtcmrySpT31FfDHmqNx0F1k658iF49PvAoam5g68okZpRZ73E/D5cRLGv Dmbm4q4P/d9lza9egT98n0pl/H4o1blkUhORZ659TK3DnaBYPwEQi9ivbVTx3TjB wFoK9R9Q5SdYeY7k8Zr1YuFHMslXdvD1JTWPZCAWaWtGIwO2fpEhEmmdG0MZTCWL /Ss4U0a0ZWgnyXvg== Received: (qmail 1099649 invoked from network); 19 Mar 2026 12:00:00 +0100 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 19 Mar 2026 12:00:00 +0100 X-UD-Smtp-Session: l3s3148p1@d9dHeF5NcpsgAwDPXzF+ANZpdrMKUeLI From: Wolfram Sang To: linux-renesas-soc@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Wolfram Sang , Chen-Yu Tsai , Wilken Gottwalt , Bjorn Andersson , Baolin Wang , Jernej Skrabec , Samuel Holland , linux-remoteproc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH v5 09/15] hwspinlock: sun6i: use new callback to initialize hwspinlock priv Date: Thu, 19 Mar 2026 11:59:31 +0100 Message-ID: <20260319105947.6237-10-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260319105947.6237-1-wsa+renesas@sang-engineering.com> References: <20260319105947.6237-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 Reviewed-by: Chen-Yu Tsai --- drivers/hwspinlock/sun6i_hwspinlock.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/drivers/hwspinlock/sun6i_hwspinlock.c b/drivers/hwspinlock/sun6i_hwspinlock.c index a0c76bba3f05..c3db81cb1793 100644 --- a/drivers/hwspinlock/sun6i_hwspinlock.c +++ b/drivers/hwspinlock/sun6i_hwspinlock.c @@ -74,9 +74,15 @@ 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) +{ + return init_data + 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 +97,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 +166,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 +177,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, NULL); + SPINLOCK_BASE_ID, priv->nlocks, io_base + SPINLOCK_LOCK_REGN); bank_fail: clk_disable_unprepare(priv->ahb_clk); From patchwork Thu Mar 19 10:59:32 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 127 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 1890C36895E for ; Thu, 19 Mar 2026 11:00:29 +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=1773918037; cv=none; b=OGxyF23o/L2PmRjEWI8T6OxCk/njmE8OnSNBDhSFg0vrnR2JKvK/0UVGksJvB2EQwL8LoOYmcf+6c5nOQiufsaMzucAmoEwqBtobPM2rF2V/c5L5YCkNHFJrQGazSLR41+v+yCNkqIYY24wdytIPJJTOBKdXdNBX9+F8FmY/Hzw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773918037; c=relaxed/simple; bh=+w9EJrt58H40phI5QcHf4yLQWIr0DQ5+HQ2Md4lKb3k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GgPMFGjHHzggxykSC704Bk+kTo2dZ5L04LJ9VYih0pb/l8KB1mtj2CUh7hPoS92+Hg7pW4G36D9sk7eV048msUbA6ktylYqX7wFSde+mr1V2vwfxq4AIWT5C4qaDASS5FR+DAVxVRl3DdOsoJaka65HArGLERF4PsOiatUmM4fo= 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=MNRNyBy3; 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="MNRNyBy3" 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=fhsUVtFpKIbK3HJ0EZngkYgaFiPAXt2fCKFcBGLp5ZY=; b=MNRNyB y3QIgSmDv8SrBWbv19HUxFoXrhXBmlBxxrRQbhT4HB0JlUbYAOhDZymhC1+34Cu8 8M803s15RFr0SsSz6eaoFkDUN2fE5MbqTJONvnaAQKlG7OnhneQ768khVwyF5s+d Evxd1Q97sUF/rRhUOCxsaCZyklmG05vecWA2NAh2G4PL3rYQ16xkRc/gD8I7Tk+N v1dNtr0jWdBHLFGkrGDydN+B3tbTKg/ct6yLpj9/CYNf6ug0G9SpcWDm26Do0xRs FDrB0t86Ci9+vsLMf/7LSipEB99KwHEgW+0Zoj/Q1sKHDO+N7sRMx5Ws8qJjLGum s6H0fPOWyFBARlbA== Received: (qmail 1099729 invoked from network); 19 Mar 2026 12:00:02 +0100 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 19 Mar 2026 12:00:02 +0100 X-UD-Smtp-Session: l3s3148p1@X/5geF5NfpsgAwDPXzF+ANZpdrMKUeLI From: Wolfram Sang To: linux-renesas-soc@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Wolfram Sang , Bjorn Andersson , Baolin Wang , Peter Zijlstra , Ingo Molnar , Will Deacon , Boqun Feng , Waiman Long , Jonathan Corbet , Shuah Khan , Orson Zhai , Chunyan Zhang , Maxime Coquelin , Alexandre Torgue , Wilken Gottwalt , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , linux-remoteproc@vger.kernel.org, linux-doc@vger.kernel.org, linux-omap@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH v5 10/15] hwspinlock: handle hwspinlock device allocation in the core Date: Thu, 19 Mar 2026 11:59:32 +0100 Message-ID: <20260319105947.6237-11-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260319105947.6237-1-wsa+renesas@sang-engineering.com> References: <20260319105947.6237-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 Acked-by: Chen-Yu Tsai # for sun6i --- Documentation/locking/hwspinlock.rst | 6 ++-- 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 ++++++---- 8 files changed, 55 insertions(+), 73 deletions(-) diff --git a/Documentation/locking/hwspinlock.rst b/Documentation/locking/hwspinlock.rst index cedeeab7387c..6cf1975b4291 100644 --- a/Documentation/locking/hwspinlock.rst +++ b/Documentation/locking/hwspinlock.rst @@ -350,9 +350,9 @@ API for implementors :: - 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); To be called from the underlying platform-specific implementation, in order to register a new hwspinlock device (which is usually a bank of 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 868b93131796..87ab30614e1d 100644 --- a/drivers/hwspinlock/omap_hwspinlock.c +++ b/drivers/hwspinlock/omap_hwspinlock.c @@ -80,7 +80,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 */ @@ -117,13 +116,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 f906f5fa74ef..bbae37e25243 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; } @@ -97,9 +95,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; @@ -130,9 +126,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 62214f31f909..ed937bc26bf5 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) @@ -85,7 +84,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; @@ -112,8 +111,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 c3db81cb1793..8bbed23af5f4 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; @@ -159,13 +158,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)) @@ -177,8 +169,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 Thu Mar 19 10:59:33 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 126 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 D98273C65F9 for ; Thu, 19 Mar 2026 11:00:33 +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=1773918040; cv=none; b=YgrEtbfeq1fpga+wQDmc+cmjjPqQ1rObQ9Dbp7wNejJS+E6U3qXQ0KsXruijgvzGoWn+c/vTOWxraPa4rx8nmXL0sB+HGlPG8jB4LnzHWSQXdfOHpgIkcMRrS8bBIVJw2BVDUAR9BMiWrRI+7aT34mvqiCrUgjoNXNY9Cryt9eM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773918040; c=relaxed/simple; bh=Qq0o4FNNvBG/mWOA0PE9lYgDNYmGuDSBq6pajGH3Bx0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O+k5GbZJaZnOJiBn34iv8SgD/NAwFjPj8TBthEFdOrImyDsfOyiPzcMh8p+PTTWh8MtPaLyRaO3RvFcysSAyhuUve13qwMoVBiPkES0zWnroq3GISqIHNPRG4DZ1dpMzVEhD+J75Te14Z/SKsxIazRRFh4TO8dASCysdTRZDFOI= 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=aUUAA+TI; 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="aUUAA+TI" 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=2njF1crk5JYsuohHYtW2T9uqDGU7n8lPKWVOP57dVMM=; b=aUUAA+ TIQCX0SJ4pwNyGnHcH0zdCPfLwTWLGDHElsPMF9Ilpu25xYdzGWSOVuOv8sk4aHl smE69sqboqQY9qeCEAW9pn/aMaEIONIEfygCV6MFDpCke67nmnkkgL9+SrJrTWdI Fk6W7yWEOz1FVBXo1TBgzFag76Q8y+Kf9xsOfuQdmbEZIgD/KfRqXDMCcVNluwl/ apT+Lso2+LBs4YnxOp9WV2vTgIa9vIjiXxvMt7gJFZrwxcr7dlztwyx+5ygqV0nQ JZbCWNk0uBEHrqXerCS6/G27bE61SBY0aSzTQ19mdG5NbUSfyHScytsOE+f60u82 S93eOd3pxgDrJy2g== Received: (qmail 1099899 invoked from network); 19 Mar 2026 12:00:08 +0100 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 19 Mar 2026 12:00:08 +0100 X-UD-Smtp-Session: l3s3148p1@MEzEeF5NuK0gAwDPXzF+ANZpdrMKUeLI From: Wolfram Sang To: linux-renesas-soc@vger.kernel.org Cc: linux-kernel@vger.kernel.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-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH v5 11/15] hwspinlock: move entries from internal to public header Date: Thu, 19 Mar 2026 11:59:33 +0100 Message-ID: <20260319105947.6237-12-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260319105947.6237-1-wsa+renesas@sang-engineering.com> References: <20260319105947.6237-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 Acked-by: Chen-Yu Tsai # for sun6i --- 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 87ab30614e1d..41a8812708ef 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 bbae37e25243..0f4fc622e3cd 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 ed937bc26bf5..8eafe1a74b1b 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 8bbed23af5f4..145d284c5ab5 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 Thu Mar 19 10:59:36 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 125 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 3521C3CC9F2 for ; Thu, 19 Mar 2026 11:00:41 +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=1773918047; cv=none; b=UGu8j7yrHUMFB4W3fjGR2qaTWbWe+5/Bsq6gHcCJpb5vrJ4jMZprPdeWtBSXQRnpNx2UprijBo1hwZxHYir/XK3mdq/aBkB6M4eIHEPS0QI60xl5lVYJp/NxS5Un/MH8zt0thZQDLJf+QLRWklM3keh1ZisXx3QgPBioZKh2s5I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773918047; c=relaxed/simple; bh=I2ZMZdq3pMVowiWGvuz/v7eklt+UR4xDaNbvT2+j7d0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CrddjlEQMB37/XQEvKH00RJgAS1b7zTqCLNIQju2P2PZH2tW5I8Ko+o5fyyocMB/zCrX5GNwBa/UkWsTcWF0Du5fNgfYVcgkB7zjLbGVdzYf6R7XzaQVeuIpDibd8aiGVB4MCka+s7jfzAJzq3dRWwYWTTDiW9/dwRgUgII8/NM= 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=OM7oZl4w; 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="OM7oZl4w" 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=4Tuc6A/FvFB15id+FPPkagjKPIMyqvuTmoP13uOV7sE=; b=OM7oZl 4wxQSWnDtuWEqld2AHyoETYmdLYMn7OoPkBh5yoZ54wDEQXV1SdREEMEoyKyTTr5 iGxPSyEmYu1MPIoK7XKUPNs7wcbc5FTYLzgvrfmUMe49WR8WrhwyLydGMOilHJNZ oJXeGE5St7docsKmf0BYcjRDfQgdp1OrOdinTQIXww+bFkj8MDDWfk7X/WGprYPG drSePTuacpgC+pyB6A5klblrODCcxCnZ3Nlnik8oTEWZ6tWHII6SoSgS8EACLOnE y5ZYXBEIdzsXBQflrkRN9IgAYAEJRo4DKYYeSCg7xw7WAwHWaJq2IJhW9q27ybFq vdi5+FYYDr6qtptg== Received: (qmail 1100027 invoked from network); 19 Mar 2026 12:00:12 +0100 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 19 Mar 2026 12:00:12 +0100 X-UD-Smtp-Session: l3s3148p1@MJP5eF5N1q0gAwDPXzF+ANZpdrMKUeLI From: Wolfram Sang To: linux-renesas-soc@vger.kernel.org Cc: linux-kernel@vger.kernel.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-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH v5 14/15] hwspinlock: refactor provider.h from public header Date: Thu, 19 Mar 2026 11:59:36 +0100 Message-ID: <20260319105947.6237-15-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260319105947.6237-1-wsa+renesas@sang-engineering.com> References: <20260319105947.6237-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 Acked-by: Chen-Yu Tsai # for sun6i --- 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 59bccd940fe0..117aa8d118b1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -11211,6 +11211,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 41a8812708ef..1be5c9d5091b 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 0f4fc622e3cd..46b55d939ea8 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 8eafe1a74b1b..2620d722ee1d 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 145d284c5ab5..24e60009fa76 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 */