From patchwork Sun Apr 8 03:06:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 132940 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp2483209ljb; Sat, 7 Apr 2018 20:07:26 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/0xL6auOufcORm6Y8DmTdS5NOC60uUWgocjm63sgm/bd24YbI/fGF+zMiS/nhjrWsxajXY X-Received: by 10.99.121.77 with SMTP id u74mr21239658pgc.89.1523156846706; Sat, 07 Apr 2018 20:07:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523156846; cv=none; d=google.com; s=arc-20160816; b=D+1fdv6I5ca4YBKWCpeTcD0hXX7n5GYHgeEq1mL03PenLWzwme6FmkWtFTMR8m6wqR xwphcG/XQ7e9IAdHkQr8Q+xNJhFBEvG0u8G/E9zmZ4zaXgLU6nuXc4Jkc92ZH0xi2o2c eTIQLbT0meY2etHIPCTC6hsNVqgtAlwUBXZlXYXgGO0frZNTGsw9Ygl8hlvojmgfC8GV Mo9Z5hJCDv7NY8tRaESTkY7J7ZpP9eCow25w8jy1kNzdyY01ANwnAKWH+sHKm3c+K8eZ GzXfk/ArHQf6oreP1M0n4Bt5b32SlnctDGZq7j0htjwSvBIWmQaa7A/AOikMsqiP7mUF m/uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=84SSzDTkY2hCkcoLRIfG5McYSjtdMhfQSuVKVSRjK1M=; b=U5ACUMrxffRUmN2B51WzMA1RyrjpfdkCarKJKxi008dmCyjuBX3OnuFp+5ufkoFD/b j5bDu6cyue3ycrkZrqPeEcIWYUgf1cl/vcLaGvagQoB4VJPpx3OHGc/S5f+Vy9ba+cHm ta3/k43EifKJBLcWuXTgP0BVRdYGp4q7Sws4ICOpTBp1kFmzmLHwqbhOcRA+oabVjg19 +SouEkqWe8g52x56PZ739ICj0raK9oDAIlMb6iSUnWey2fw3Wa10FZ0wuV2sDhhaiUMW NeXcRqpTpAruIeBy868XlYYM4SxON48aon1g+RLH9QmD9H1dSgpS0YiIQI/uEaWh+Sqo B1Jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=O7RI3IlH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a22si3459431pgd.825.2018.04.07.20.07.26; Sat, 07 Apr 2018 20:07:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=O7RI3IlH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752652AbeDHDHT (ORCPT + 29 others); Sat, 7 Apr 2018 23:07:19 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:36283 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752498AbeDHDHS (ORCPT ); Sat, 7 Apr 2018 23:07:18 -0400 Received: by mail-pf0-f194.google.com with SMTP id g14so3514434pfh.3 for ; Sat, 07 Apr 2018 20:07:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=84SSzDTkY2hCkcoLRIfG5McYSjtdMhfQSuVKVSRjK1M=; b=O7RI3IlHCnSu1+dOHGZ/GMDqZYI+gqnD1Mxev+/l0Hip9//I9u6C4KZ1IzsLvyRM+g nTzC+XeDag5v/W8uAlwO1h2bWpYYvvkG2GgZkUtpVYZYZlh60PzG1ybNTkgZ5YEbh+TZ uXtL/Fcon8vYJnHVKe8igHaprpe3rD+GGZ4vY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=84SSzDTkY2hCkcoLRIfG5McYSjtdMhfQSuVKVSRjK1M=; b=DojerdgyUSAf4YY2NoaNNgPpnysHai0hezx7uxl2sD+A1Nkg2QO2ex4zUPqqyVOvL0 tafXraOKa6Y/JiQ85PhgWL4pnoJDl1eOMV44gB4dGj3Y3oinEkCkZhe7c4JFIDiZNf4P ij7c7z+wAMAFSdiNnbyZ3fvjUw88WZDMmGlmlXgwXM8CY14b80sItgq3o3oPobZNSjg4 TbD/DVh1IugEflQPbnzMUXbzm1JXWQEJVtLAhB2MtdUzL9CdkwfHD2ankN9tikMAmCcs Hpo8HST1LgAaFoLLtGkEd3w1k/busfmEJJBYW5m9kMMwt+WWm2QsAm+c8c63oZpgc5jE l2og== X-Gm-Message-State: AElRT7HPCvY/azeLf3Mbx52U6L6+Ubm/kkZFtMOiYSQrbu9pZu9aP/jT 0FvXWvIdFbtEN8URN9Zb4KQ0uA== X-Received: by 10.101.73.74 with SMTP id q10mr21893538pgs.323.1523156837857; Sat, 07 Apr 2018 20:07:17 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id t25sm28279825pfj.187.2018.04.07.20.07.15 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 07 Apr 2018 20:07:17 -0700 (PDT) From: Baolin Wang To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: arnd@arndb.de, broonie@kernel.org, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, baolin.wang@linaro.org Subject: [PATCH 1/2] hwspinlock: Convert to use 'switch' statement Date: Sun, 8 Apr 2018 11:06:56 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We have different hwspinlock modes to select, thus it will be more readable to handle different modes with using 'switch' statement instead of 'if' statement. Signed-off-by: Baolin Wang --- drivers/hwspinlock/hwspinlock_core.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) -- 1.7.9.5 diff --git a/drivers/hwspinlock/hwspinlock_core.c b/drivers/hwspinlock/hwspinlock_core.c index 4074441..f4a59f5 100644 --- a/drivers/hwspinlock/hwspinlock_core.c +++ b/drivers/hwspinlock/hwspinlock_core.c @@ -106,12 +106,17 @@ int __hwspin_trylock(struct hwspinlock *hwlock, int mode, unsigned long *flags) * problems with hwspinlock usage (e.g. scheduler checks like * 'scheduling while atomic' etc.) */ - if (mode == HWLOCK_IRQSTATE) + switch (mode) { + case HWLOCK_IRQSTATE: ret = spin_trylock_irqsave(&hwlock->lock, *flags); - else if (mode == HWLOCK_IRQ) + break; + case HWLOCK_IRQ: ret = spin_trylock_irq(&hwlock->lock); - else + break; + default: ret = spin_trylock(&hwlock->lock); + break; + } /* is lock already taken by another context on the local cpu ? */ if (!ret) @@ -122,12 +127,17 @@ int __hwspin_trylock(struct hwspinlock *hwlock, int mode, unsigned long *flags) /* if hwlock is already taken, undo spin_trylock_* and exit */ if (!ret) { - if (mode == HWLOCK_IRQSTATE) + switch (mode) { + case HWLOCK_IRQSTATE: spin_unlock_irqrestore(&hwlock->lock, *flags); - else if (mode == HWLOCK_IRQ) + break; + case HWLOCK_IRQ: spin_unlock_irq(&hwlock->lock); - else + break; + default: spin_unlock(&hwlock->lock); + break; + } return -EBUSY; } @@ -249,12 +259,17 @@ void __hwspin_unlock(struct hwspinlock *hwlock, int mode, unsigned long *flags) hwlock->bank->ops->unlock(hwlock); /* Undo the spin_trylock{_irq, _irqsave} called while locking */ - if (mode == HWLOCK_IRQSTATE) + switch (mode) { + case HWLOCK_IRQSTATE: spin_unlock_irqrestore(&hwlock->lock, *flags); - else if (mode == HWLOCK_IRQ) + break; + case HWLOCK_IRQ: spin_unlock_irq(&hwlock->lock); - else + break; + default: spin_unlock(&hwlock->lock); + break; + } } EXPORT_SYMBOL_GPL(__hwspin_unlock); From patchwork Sun Apr 8 03:06:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 132941 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp2483257ljb; Sat, 7 Apr 2018 20:07:31 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+jJO0dt94P1exsH4aIFKb2gmfcnha4kUsn64Qv9CX8wOGYuSWJWBLWZkvle5mGlZzTlED+ X-Received: by 2002:a17:902:6b03:: with SMTP id o3-v6mr27680473plk.183.1523156850947; Sat, 07 Apr 2018 20:07:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523156850; cv=none; d=google.com; s=arc-20160816; b=ArGo9sHlYqTFXJm46JwQeN8SM27YLnpsBQBe2j8scSdcZ95Amy8o6fAIasrBm3yUbu UkVm4JhudhhFMvKtLuJjJ18qniCEwBuy00JkXW29Z5UsR9ilLmrYPyBhxoglpb5AC9Ns SB1Vopbv7hX5pL0kXMMyjHMhZUDVZscgCZ2ZksNZ6IwASdoUypvZ6d9AwCtqUon0hM9K 48i2CJhrykl7TYqZBdmKU1udlkID8Hi0BlOtfRA3vOnZjRz1QALiP8KBcq51p70AulxT 9WX0kaFchZpcgirO5+FpbqFM2jpfK6IC+o/T3ISZxQY1nOdC0BV4wbtl+uiUHDvqvOLF 7uzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=PKhnu+eL7PQiHIcztMn8ouDbNj4UqGk9EvpLyjIbIlo=; b=mD8vmEFlcZhttfT83eoG4Z6RFB9NyshlmpN7Y/RUjVTXJyyLgAQdYOKNDfakyA6mHg RFYclf8O2cc/fXKd9fa8WM8f9DEcUZuxGE4BbWmMlb/tK1UH/jxn9CNt5kmYl9BoNuAc Pbv80AiNRhsbXJNOyIszMsuxcsWpKPpg42vzRGLRtrwWFyZwdoKDH9yMWVgEXX8x8lPy xv7pSHG4Mk6yTmWTIZa6IXQv9gVHwNZcNn6sEsAw35mQ5p89QfTmACoVsQzT/LZ3+2v5 7LrEPZDfJ/LDNnBX/vYyGqtmoGLmwhQNCKFc5CG8D8T1HqWq0hj/6FmZXnSPe/8zXPvM H0WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dQEpi18b; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1-v6si13966741plk.308.2018.04.07.20.07.30; Sat, 07 Apr 2018 20:07:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dQEpi18b; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752711AbeDHDH1 (ORCPT + 29 others); Sat, 7 Apr 2018 23:07:27 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:43290 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752653AbeDHDHV (ORCPT ); Sat, 7 Apr 2018 23:07:21 -0400 Received: by mail-pl0-f66.google.com with SMTP id a39-v6so3018989pla.10 for ; Sat, 07 Apr 2018 20:07:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=PKhnu+eL7PQiHIcztMn8ouDbNj4UqGk9EvpLyjIbIlo=; b=dQEpi18bTNi27weRdm6Us/2RyCY+YKg7na8j6/nn9+Ke3pVh4eZbm2mgvhvID4TqGf KRn/0ME3NU4ZE2lt80acPKoerYHzts0AMAWS8aZ3a6l1dccun/FNdn/+ZAo2uxeYKzok fMgbLAY4U9pbU8jpXdejZz9akG+TFn+yJ/IBo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=PKhnu+eL7PQiHIcztMn8ouDbNj4UqGk9EvpLyjIbIlo=; b=BNUhh8zK0NXivxN1YDEaOheGI2D5NG1N9Ljdogs+DFjO4ZRR/OVaKKXVKTGDyz/uSi AXAwd4ZHcswIMCbXqFbiNlIVPnjhdU/c5oqV95BCB3PqhLzhCmooaaTEsweqvuA5Rz4m OB5AiyRvQIfU/82vEVVCyWFyi2mJSiKCNy4MTTnw5TO5pFqfWDMibDFzqydhxs1XU37t ZwA5JDMvHoaLZZlhu+4W/OFntJPwyc2aVLryD7nL9gP/po4nnCt9phXMWQdmvIwuoIWl FIhB6KbpBNsTXV4Y2SwFp1tvoL6ru/bFqKLpZBOR7g/pq2xU/cXDOMwYSEPXV3c7F37f AU6A== X-Gm-Message-State: AElRT7EQ0SK4KSw1n6ilnGFfMxDZWCz9u+TrzPUldwbu7g6IFIbkmJXW gYuhfdRx5XV8IwzsG8FNiqLzbg== X-Received: by 2002:a17:902:850b:: with SMTP id bj11-v6mr33775933plb.35.1523156840889; Sat, 07 Apr 2018 20:07:20 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id t25sm28279825pfj.187.2018.04.07.20.07.18 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 07 Apr 2018 20:07:20 -0700 (PDT) From: Baolin Wang To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: arnd@arndb.de, broonie@kernel.org, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, baolin.wang@linaro.org Subject: [PATCH 2/2] hwspinlock: Introduce one new mode for hwspinlock Date: Sun, 8 Apr 2018 11:06:57 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In some scenarios, user need do some time-consuming or sleepable operations under the hardware spinlock protection for synchronization between the multiple subsystems. For example, there is one PMIC efuse on Spreadtrum platform, which need to be accessed under one hardware lock. But during the hardware lock protection, the efuse operation is time-consuming to almost 5 ms, so we can not disable the interrupts or preemption so long in this case. Thus we can introduce one new mode to indicate that we just acquire the hardware lock and do not disable interrupts or preemption, meanwhile we should force user to protect the hardware lock with mutex or spinlock to avoid dead-lock. Signed-off-by: Baolin Wang --- drivers/hwspinlock/hwspinlock_core.c | 34 ++++++++++++++++---- include/linux/hwspinlock.h | 58 ++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 7 deletions(-) -- 1.7.9.5 diff --git a/drivers/hwspinlock/hwspinlock_core.c b/drivers/hwspinlock/hwspinlock_core.c index f4a59f5..5278d05 100644 --- a/drivers/hwspinlock/hwspinlock_core.c +++ b/drivers/hwspinlock/hwspinlock_core.c @@ -71,10 +71,16 @@ * This function attempts to lock an hwspinlock, and will immediately * fail if the hwspinlock is already taken. * - * Upon a successful return from this function, preemption (and possibly - * interrupts) is disabled, so the caller must not sleep, and is advised to - * release the hwspinlock as soon as possible. This is required in order to - * minimize remote cores polling on the hardware interconnect. + * Caution: If the mode is HWLOCK_RAW, that means user must protect the routine + * of getting hardware lock with mutex or spinlock. Since in some scenarios, + * user need some time-consuming or sleepable operations under the hardware + * lock, they need one sleepable lock (like mutex) to protect the operations. + * + * If the mode is not HWLOCK_RAW, upon a successful return from this function, + * preemption (and possibly interrupts) is disabled, so the caller must not + * sleep, and is advised to release the hwspinlock as soon as possible. This is + * required in order to minimize remote cores polling on the hardware + * interconnect. * * The user decides whether local interrupts are disabled or not, and if yes, * whether he wants their previous state to be saved. It is up to the user @@ -113,6 +119,9 @@ int __hwspin_trylock(struct hwspinlock *hwlock, int mode, unsigned long *flags) case HWLOCK_IRQ: ret = spin_trylock_irq(&hwlock->lock); break; + case HWLOCK_RAW: + ret = 1; + break; default: ret = spin_trylock(&hwlock->lock); break; @@ -134,6 +143,9 @@ int __hwspin_trylock(struct hwspinlock *hwlock, int mode, unsigned long *flags) case HWLOCK_IRQ: spin_unlock_irq(&hwlock->lock); break; + case HWLOCK_RAW: + /* Nothing to do */ + break; default: spin_unlock(&hwlock->lock); break; @@ -170,9 +182,14 @@ int __hwspin_trylock(struct hwspinlock *hwlock, int mode, unsigned long *flags) * is already taken, the function will busy loop waiting for it to * be released, but give up after @timeout msecs have elapsed. * - * Upon a successful return from this function, preemption is disabled - * (and possibly local interrupts, too), so the caller must not sleep, - * and is advised to release the hwspinlock as soon as possible. + * Caution: If the mode is HWLOCK_RAW, that means user must protect the routine + * of getting hardware lock with mutex or spinlock. Since in some scenarios, + * user need some time-consuming or sleepable operations under the hardware + * lock, they need one sleepable lock (like mutex) to protect the operations. + * + * If the mode is not HWLOCK_RAW, upon a successful return from this function, + * preemption is disabled (and possibly local interrupts, too), so the caller + * must not sleep, and is advised to release the hwspinlock as soon as possible. * This is required in order to minimize remote cores polling on the * hardware interconnect. * @@ -266,6 +283,9 @@ void __hwspin_unlock(struct hwspinlock *hwlock, int mode, unsigned long *flags) case HWLOCK_IRQ: spin_unlock_irq(&hwlock->lock); break; + case HWLOCK_RAW: + /* Nothing to do */ + break; default: spin_unlock(&hwlock->lock); break; diff --git a/include/linux/hwspinlock.h b/include/linux/hwspinlock.h index 859d673..fe450ee 100644 --- a/include/linux/hwspinlock.h +++ b/include/linux/hwspinlock.h @@ -24,6 +24,7 @@ /* hwspinlock mode argument */ #define HWLOCK_IRQSTATE 0x01 /* Disable interrupts, save state */ #define HWLOCK_IRQ 0x02 /* Disable interrupts, don't save state */ +#define HWLOCK_RAW 0x03 struct device; struct device_node; @@ -176,6 +177,25 @@ static inline int hwspin_trylock_irq(struct hwspinlock *hwlock) } /** + * hwspin_trylock_raw() - attempt to lock a specific hwspinlock + * @hwlock: an hwspinlock which we want to trylock + * + * This function attempts to lock an hwspinlock, and will immediately fail + * if the hwspinlock is already taken. + * + * Caution: User must protect the routine of getting hardware lock with mutex + * or spinlock to avoid dead-lock, that will let user can do some time-consuming + * or sleepable operations under the hardware lock. + * + * Returns 0 if we successfully locked the hwspinlock, -EBUSY if + * the hwspinlock was already taken, and -EINVAL if @hwlock is invalid. + */ +static inline int hwspin_trylock_raw(struct hwspinlock *hwlock) +{ + return __hwspin_trylock(hwlock, HWLOCK_RAW, NULL); +} + +/** * hwspin_trylock() - attempt to lock a specific hwspinlock * @hwlock: an hwspinlock which we want to trylock * @@ -243,6 +263,29 @@ int hwspin_lock_timeout_irq(struct hwspinlock *hwlock, unsigned int to) } /** + * hwspin_lock_timeout_raw() - lock an hwspinlock with timeout limit + * @hwlock: the hwspinlock to be locked + * @to: timeout value in msecs + * + * This function locks the underlying @hwlock. If the @hwlock + * is already taken, the function will busy loop waiting for it to + * be released, but give up when @timeout msecs have elapsed. + * + * Caution: User must protect the routine of getting hardware lock with mutex + * or spinlock to avoid dead-lock, that will let user can do some time-consuming + * or sleepable operations under the hardware lock. + * + * Returns 0 when the @hwlock was successfully taken, and an appropriate + * error code otherwise (most notably an -ETIMEDOUT if the @hwlock is still + * busy after @timeout msecs). The function will never sleep. + */ +static inline +int hwspin_lock_timeout_raw(struct hwspinlock *hwlock, unsigned int to) +{ + return __hwspin_lock_timeout(hwlock, to, HWLOCK_RAW, NULL); +} + +/** * hwspin_lock_timeout() - lock an hwspinlock with timeout limit * @hwlock: the hwspinlock to be locked * @to: timeout value in msecs @@ -302,6 +345,21 @@ static inline void hwspin_unlock_irq(struct hwspinlock *hwlock) } /** + * hwspin_unlock_raw() - unlock hwspinlock + * @hwlock: a previously-acquired hwspinlock which we want to unlock + * + * This function will unlock a specific hwspinlock. + * + * @hwlock must be already locked (e.g. by hwspin_trylock()) before calling + * this function: it is a bug to call unlock on a @hwlock that is already + * unlocked. + */ +static inline void hwspin_unlock_raw(struct hwspinlock *hwlock) +{ + __hwspin_unlock(hwlock, HWLOCK_RAW, NULL); +} + +/** * hwspin_unlock() - unlock hwspinlock * @hwlock: a previously-acquired hwspinlock which we want to unlock *