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: 1870241 Return-Path: X-Original-To: patchwork-linux-omap@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 869553FC71 for ; Wed, 12 Dec 2012 20:27:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755045Ab2LLU1Q (ORCPT ); Wed, 12 Dec 2012 15:27:16 -0500 Received: from mail-wg0-f46.google.com ([74.125.82.46]:43347 "EHLO mail-wg0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754383Ab2LLU1Q (ORCPT ); Wed, 12 Dec 2012 15:27:16 -0500 Received: by mail-wg0-f46.google.com with SMTP id dr13so448508wgb.1 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=L6F868ChT2hZ1daJS8QcO5HlPwKu1bPtL+Z61eJaLZewDIO0eVvOdIg9orl9DglKud fcd3VrwxqDzKou56sac2P+sQsDrwtE8b3ZLp6C7MFn0FeINEzNxlQUIRQhRSufF6WJAE yFrEC4zl5l3fwOvq2BUXHwA/Zx3C40LHo78GWci4uwzVENdnbSt/Vv9tkFDHOvdM/Rn3 gI4E51GBBdBeXkq0juMmuUgb1Hus1J28c8CgVb5tn+Vh+fDD+KzeHLHYC6/PJ+lh+fci H+/ZlmywIe5qQCTXJXG94qSuCI9fq/pQIUXxz7rXfiPyaKgoHdTvU313okSEv8tG7gPo jRlA== 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 Cc: Ido Yariv 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: ALoCoQkiddFQzPCjOWCx4LLJthwahFCo7KbnQlEBhR2h1NcvP5XiMrtwQXHDNc05nk94hJsxLcsU Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.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;