From patchwork Tue Jul 30 12:38:20 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arpit Goel X-Patchwork-Id: 263371 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 1FED72C00AD for ; Tue, 30 Jul 2013 22:42:48 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753579Ab3G3MmR (ORCPT ); Tue, 30 Jul 2013 08:42:17 -0400 Received: from [65.55.88.15] ([65.55.88.15]:15906 "EHLO tx2outboundpool.messaging.microsoft.com" rhost-flags-FAIL-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1752783Ab3G3MmO (ORCPT ); Tue, 30 Jul 2013 08:42:14 -0400 Received: from mail176-tx2-R.bigfish.com (10.9.14.236) by TX2EHSOBE014.bigfish.com (10.9.40.34) with Microsoft SMTP Server id 14.1.225.22; Tue, 30 Jul 2013 12:39:43 +0000 Received: from mail176-tx2 (localhost [127.0.0.1]) by mail176-tx2-R.bigfish.com (Postfix) with ESMTP id B825C800EF; Tue, 30 Jul 2013 12:39:43 +0000 (UTC) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-SpamScore: 7 X-BigFish: VS7(zzzz1f42h208ch1ee6h1de0h1fdah2073h1202h1e76h1d1ah1d2ah1fc6h1082kz70kd2iz1de098h8275bh1de097hz2dh2a8h668h839he5bhf0ah1288h12a5h12a9h12bdh12e5h137ah139eh13b6h1441h1504h1537h162dh1631h1758h1898h18e1h1946h19b5h1ad9h1b0ah1d0ch1d2eh1d3fh1de2h1dfeh1dffh1e23h1155h) Received: from mail176-tx2 (localhost.localdomain [127.0.0.1]) by mail176-tx2 (MessageSwitch) id 1375187982126054_16744; Tue, 30 Jul 2013 12:39:42 +0000 (UTC) Received: from TX2EHSMHS039.bigfish.com (unknown [10.9.14.252]) by mail176-tx2.bigfish.com (Postfix) with ESMTP id 0DD42340046; Tue, 30 Jul 2013 12:39:42 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by TX2EHSMHS039.bigfish.com (10.9.99.139) with Microsoft SMTP Server (TLS) id 14.16.227.3; Tue, 30 Jul 2013 12:39:33 +0000 Received: from tx30smr01.am.freescale.net (10.81.153.31) by 039-SN1MMR1-001.039d.mgd.msft.net (10.84.1.13) with Microsoft SMTP Server (TLS) id 14.3.136.1; Tue, 30 Jul 2013 12:39:33 +0000 Received: from localhost.ap.freescale.net (udp166521uds.ap.freescale.net [10.232.132.223]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id r6UCcb9O022542; Tue, 30 Jul 2013 05:39:25 -0700 From: Arpit Goel To: , , , , , , , , , , , , , , , CC: , , , , , , , Arpit Goel Subject: [PATCH 2/2] Convert PowerPC macro spin_event_timeout() to architecture independent macro Date: Tue, 30 Jul 2013 18:08:20 +0530 Message-ID: <1375187900-17582-3-git-send-email-B44344@freescale.com> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1375187900-17582-1-git-send-email-B44344@freescale.com> References: <1375187900-17582-1-git-send-email-B44344@freescale.com> MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-FOPE-CONNECTOR: Id%0$Dn%*$RO%0$TLS%0$FQDN%$TlsDn% Sender: sparclinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: sparclinux@vger.kernel.org This patch ports PowerPC implementation of spin_event_timeout() for generic use. Architecture specific implementation can be added to asm/delay.h, which will override the generic linux implementation. Signed-off-by: Arpit Goel --- include/linux/delay.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/include/linux/delay.h b/include/linux/delay.h index a6ecb34..e975994 100644 --- a/include/linux/delay.h +++ b/include/linux/delay.h @@ -52,4 +52,44 @@ static inline void ssleep(unsigned int seconds) msleep(seconds * 1000); } +#ifndef spin_event_timeout +/** + * spin_event_timeout - spin until a condition gets true or a timeout elapses + * @condition: a C expression to evalate + * @timeout: timeout, in microseconds + * @delay: the number of microseconds to delay between each evaluation of + * @condition + * + * The process spins until the condition evaluates to true (non-zero) or the + * timeout elapses. The return value of this macro is the value of + * @condition when the loop terminates. This allows you to determine the cause + * of the loop terminates. If the return value is zero, then you know a + * timeout has occurred. + * + * This primary purpose of this macro is to poll on a hardware register + * until a status bit changes. The timeout ensures that the loop still + * terminates even if the bit never changes. The delay is for devices that + * need a delay in between successive reads. + * + * gcc will optimize out the if-statement if @delay is a constant. + * + * This is copied from PowerPC based spin_event_timeout() implementation + * and modified for generic usecase. + */ +#define spin_event_timeout(condition, timeout, delay) \ +({ \ + typeof(condition) __ret; \ + unsigned long __loops = timeout/USECS_PER_JIFFY; \ + unsigned long __start = jiffies; \ + while (!(__ret = (condition)) && \ + time_before(jiffies, __start + __loops + 1)) \ + if (delay) \ + udelay(delay); \ + else \ + schedule(); \ + if (!__ret) \ + __ret = (condition); \ + __ret; \ +}) +#endif #endif /* defined(_LINUX_DELAY_H) */