From patchwork Wed Dec 12 20:27:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Yariv X-Patchwork-Id: 1870281 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 3FBE53FC71 for ; Wed, 12 Dec 2012 20:29:58 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Tistk-0006Zr-D2; Wed, 12 Dec 2012 20:27:20 +0000 Received: from mail-we0-f177.google.com ([74.125.82.177]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Tistg-0006Yj-D0 for linux-arm-kernel@lists.infradead.org; Wed, 12 Dec 2012 20:27:17 +0000 Received: by mail-we0-f177.google.com with SMTP id x48so491279wey.36 for ; Wed, 12 Dec 2012 12:27:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:x-gm-message-state; bh=pOPcVrmTcSJG8qfWWqqHCAzBMPbRoknRXp9ol+334tY=; b=LTDuFcq9yiE4QTm6hmW6w9cj7T3WQ32sJjYJghcWMUMaWkHlWMTRZWq+KWkV+ejwlI 2x53q1V3f5jCCB7wPecBh8BtICQE5JL9QlXzRpmpH7iFyFNdmS0jxLJI/U/2HMdYsYgv TCBk1IPc6geJQW6dYXTcOPcvhkokUc8YS68GLODFo0M68Z9O9+hw7Rn9fC5Cs02mWscT W9M4mKWcAwJt8XoXkCOSdqAIlOkDnbQCaZ2BDBmCeFHQmCI1TCtTPMqk7DgdLFGKGxKx qkL4qorDT95RoLedokCPY+4CNIFaSpb9FeZBACLNjq4xc7kBp6diwQ70wVvHoz+Vq6vP 3R1w== Received: by 10.194.173.38 with SMTP id bh6mr4131413wjc.26.1355344034830; Wed, 12 Dec 2012 12:27:14 -0800 (PST) Received: from WorkStation.localnet (bzq-79-183-234-152.red.bezeqint.net. [79.183.234.152]) by mx.google.com with ESMTPS id p3sm4597559wic.8.2012.12.12.12.27.13 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 12 Dec 2012 12:27:14 -0800 (PST) From: Ido Yariv To: Ohad Ben-Cohen , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-omap@vger.kernel.org Subject: [PATCH] hwspinlock/core: Add testing capabilities Date: Wed, 12 Dec 2012 22:27:06 +0200 Message-Id: <1355344026-17222-1-git-send-email-ido@wizery.com> X-Mailer: git-send-email 1.7.7.6 X-Gm-Message-State: ALoCoQnVxhPNRQEa0SOGf++hSALcHVdWCN+4+aBDBEu2hFZAoFNBQiDGLVzxYN0mk7nli8outzed X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121212_152716_658821_98EE9F4A X-CRM114-Status: GOOD ( 14.05 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.82.177 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Ido Yariv X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Add testing capabilities for verifying correctness of the underlying hwspinlock layers. This can be handy especially during development. These tests are performed only once as part of the hwspinlock registration. Signed-off-by: Ido Yariv --- drivers/hwspinlock/Kconfig | 9 +++++ drivers/hwspinlock/hwspinlock_core.c | 54 ++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 0 deletions(-) diff --git a/drivers/hwspinlock/Kconfig b/drivers/hwspinlock/Kconfig index c7c3128..ad632cd 100644 --- a/drivers/hwspinlock/Kconfig +++ b/drivers/hwspinlock/Kconfig @@ -8,6 +8,15 @@ config HWSPINLOCK menu "Hardware Spinlock drivers" +config HWSPINLOCK_TEST + bool "Verify underlying hwspinlock implementation" + depends on HWSPINLOCK + help + Say Y here to perform tests on the underlying hwspinlock + implementation. The tests are only performed once per implementation. + + Say N, unless you absolutely know what you are doing. + config HWSPINLOCK_OMAP tristate "OMAP Hardware Spinlock device" depends on ARCH_OMAP4 diff --git a/drivers/hwspinlock/hwspinlock_core.c b/drivers/hwspinlock/hwspinlock_core.c index 085e28e..1874e85 100644 --- a/drivers/hwspinlock/hwspinlock_core.c +++ b/drivers/hwspinlock/hwspinlock_core.c @@ -307,6 +307,53 @@ out: return hwlock; } +#ifdef CONFIG_HWSPINLOCK_TEST +#define NUM_OF_TEST_ITERATIONS 100 +static int hwspin_lock_tests(const struct hwspinlock_ops *ops, + struct hwspinlock *hwlock) +{ + int i; + int ret; + + for (i = 0; i < NUM_OF_TEST_ITERATIONS; i++) { + ret = ops->trylock(hwlock); + if (!ret) { + pr_err("%s: Initial lock failed\n", __func__); + return -EFAULT; + } + + /* Verify lock actually works - re-acquiring it should fail */ + ret = ops->trylock(hwlock); + if (ret) { + /* Keep locks balanced even in failure cases */ + ops->unlock(hwlock); + ops->unlock(hwlock); + pr_err("%s: Recursive lock succeeded unexpectedly\n", + __func__); + return -EFAULT; + } + + /* Verify unlock by re-acquiring the lock after releasing it */ + ops->unlock(hwlock); + ret = ops->trylock(hwlock); + if (!ret) { + pr_err("%s: Unlock failed\n", __func__); + return -EINVAL; + } + + ops->unlock(hwlock); + } + + return 0; +} +#else /* CONFIG_HWSPINLOCK_TEST*/ +static int hwspin_lock_tests(const struct hwspinlock_ops *ops, + struct hwspinlock *hwlock) +{ + return 0; +} +#endif + /** * hwspin_lock_register() - register a new hw spinlock device * @bank: the hwspinlock device, which usually provides numerous hw locks @@ -345,6 +392,13 @@ int hwspin_lock_register(struct hwspinlock_device *bank, struct device *dev, spin_lock_init(&hwlock->lock); hwlock->bank = bank; + ret = hwspin_lock_tests(ops, hwlock); + if (ret) { + pr_err("hwspinlock tests failed on lock %d\n", + base_id + i); + goto reg_failed; + } + ret = hwspin_lock_register_single(hwlock, base_id + i); if (ret) goto reg_failed;