Path: blob/master/arch/powerpc/include/asm/delay.h
15117 views
#ifndef _ASM_POWERPC_DELAY_H1#define _ASM_POWERPC_DELAY_H2#ifdef __KERNEL__34#include <asm/time.h>56/*7* Copyright 1996, Paul Mackerras.8* Copyright (C) 2009 Freescale Semiconductor, Inc. All rights reserved.9*10* This program is free software; you can redistribute it and/or11* modify it under the terms of the GNU General Public License12* as published by the Free Software Foundation; either version13* 2 of the License, or (at your option) any later version.14*15* PPC64 Support added by Dave Engebretsen, Todd Inglett, Mike Corrigan,16* Anton Blanchard.17*/1819extern void __delay(unsigned long loops);20extern void udelay(unsigned long usecs);2122/*23* On shared processor machines the generic implementation of mdelay can24* result in large errors. While each iteration of the loop inside mdelay25* is supposed to take 1ms, the hypervisor could sleep our partition for26* longer (eg 10ms). With the right timing these errors can add up.27*28* Since there is no 32bit overflow issue on 64bit kernels, just call29* udelay directly.30*/31#ifdef CONFIG_PPC6432#define mdelay(n) udelay((n) * 1000)33#endif3435/**36* spin_event_timeout - spin until a condition gets true or a timeout elapses37* @condition: a C expression to evalate38* @timeout: timeout, in microseconds39* @delay: the number of microseconds to delay between each evaluation of40* @condition41*42* The process spins until the condition evaluates to true (non-zero) or the43* timeout elapses. The return value of this macro is the value of44* @condition when the loop terminates. This allows you to determine the cause45* of the loop terminates. If the return value is zero, then you know a46* timeout has occurred.47*48* This primary purpose of this macro is to poll on a hardware register49* until a status bit changes. The timeout ensures that the loop still50* terminates even if the bit never changes. The delay is for devices that51* need a delay in between successive reads.52*53* gcc will optimize out the if-statement if @delay is a constant.54*/55#define spin_event_timeout(condition, timeout, delay) \56({ \57typeof(condition) __ret; \58unsigned long __loops = tb_ticks_per_usec * timeout; \59unsigned long __start = get_tbl(); \60while (!(__ret = (condition)) && (tb_ticks_since(__start) <= __loops)) \61if (delay) \62udelay(delay); \63else \64cpu_relax(); \65if (!__ret) \66__ret = (condition); \67__ret; \68})6970#endif /* __KERNEL__ */71#endif /* _ASM_POWERPC_DELAY_H */727374