From patchwork Wed Aug 14 07:03:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arpit Goel X-Patchwork-Id: 266973 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 518CA2C012D for ; Wed, 14 Aug 2013 17:19:29 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757957Ab3HNHT2 (ORCPT ); Wed, 14 Aug 2013 03:19:28 -0400 Received: from tx2ehsobe002.messaging.microsoft.com ([65.55.88.12]:31684 "EHLO tx2outboundpool.messaging.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757886Ab3HNHT1 (ORCPT ); Wed, 14 Aug 2013 03:19:27 -0400 Received: from mail219-tx2-R.bigfish.com (10.9.14.232) by TX2EHSOBE001.bigfish.com (10.9.40.21) with Microsoft SMTP Server id 14.1.225.22; Wed, 14 Aug 2013 07:19:26 +0000 Received: from mail219-tx2 (localhost [127.0.0.1]) by mail219-tx2-R.bigfish.com (Postfix) with ESMTP id 2742F3C009A; Wed, 14 Aug 2013 07:19:26 +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: 3 X-BigFish: VS3(zzzz1f42h208ch1ee6h1de0h1fdah2073h1202h1e76h1d1ah1d2ah1fc6h1082kzz1de098h8275bh1de097hz2dh2a8h668h839he5bhf0ah1288h12a5h12a9h12bdh12e5h137ah139eh13b6h1441h1504h1537h162dh1631h1758h1898h18e1h1946h19b5h1ad9h1b0ah1b2fh1fb3h1d0ch1d2eh1d3fh1de2h1dfeh1dffh1e23h1fe8h1ff5h1155h) Received: from mail219-tx2 (localhost.localdomain [127.0.0.1]) by mail219-tx2 (MessageSwitch) id 1376464764199699_14173; Wed, 14 Aug 2013 07:19:24 +0000 (UTC) Received: from TX2EHSMHS013.bigfish.com (unknown [10.9.14.238]) by mail219-tx2.bigfish.com (Postfix) with ESMTP id 1D92994004C; Wed, 14 Aug 2013 07:19:24 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by TX2EHSMHS013.bigfish.com (10.9.99.113) with Microsoft SMTP Server (TLS) id 14.16.227.3; Wed, 14 Aug 2013 07:19:23 +0000 Received: from tx30smr01.am.freescale.net (10.81.153.31) by 039-SN1MMR1-003.039d.mgd.msft.net (10.84.1.16) with Microsoft SMTP Server (TLS) id 14.3.136.1; Wed, 14 Aug 2013 07:19:22 +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 r7E7430m003365; Wed, 14 Aug 2013 00:19:14 -0700 From: Arpit Goel To: , , , CC: , , , , , , , , , , , , , , , , , , , , , , Arpit Goel Subject: [PATCH v2 2/2] Convert PowerPC macro spin_event_timeout() to architecture independent macro Date: Wed, 14 Aug 2013 12:33:55 +0530 Message-ID: <1376463835-13040-3-git-send-email-B44344@freescale.com> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1376463835-13040-1-git-send-email-B44344@freescale.com> References: <1376463835-13040-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..2ee7fa8 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 = usecs_to_jiffies(timeout); \ + 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) */