Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 #ifndef _ASM_POWERPC_DELAY_H
0003 #define _ASM_POWERPC_DELAY_H
0004 #ifdef __KERNEL__
0005 
0006 #include <linux/processor.h>
0007 #include <asm/time.h>
0008 
0009 /*
0010  * Copyright 1996, Paul Mackerras.
0011  * Copyright (C) 2009 Freescale Semiconductor, Inc. All rights reserved.
0012  *
0013  * PPC64 Support added by Dave Engebretsen, Todd Inglett, Mike Corrigan,
0014  * Anton Blanchard.
0015  */
0016 
0017 extern void __delay(unsigned long loops);
0018 extern void udelay(unsigned long usecs);
0019 
0020 /*
0021  * On shared processor machines the generic implementation of mdelay can
0022  * result in large errors. While each iteration of the loop inside mdelay
0023  * is supposed to take 1ms, the hypervisor could sleep our partition for
0024  * longer (eg 10ms). With the right timing these errors can add up.
0025  *
0026  * Since there is no 32bit overflow issue on 64bit kernels, just call
0027  * udelay directly.
0028  */
0029 #ifdef CONFIG_PPC64
0030 #define mdelay(n)   udelay((n) * 1000)
0031 #endif
0032 
0033 /**
0034  * spin_event_timeout - spin until a condition gets true or a timeout elapses
0035  * @condition: a C expression to evalate
0036  * @timeout: timeout, in microseconds
0037  * @delay: the number of microseconds to delay between each evaluation of
0038  *         @condition
0039  *
0040  * The process spins until the condition evaluates to true (non-zero) or the
0041  * timeout elapses.  The return value of this macro is the value of
0042  * @condition when the loop terminates. This allows you to determine the cause
0043  * of the loop terminates.  If the return value is zero, then you know a
0044  * timeout has occurred.
0045  *
0046  * This primary purpose of this macro is to poll on a hardware register
0047  * until a status bit changes.  The timeout ensures that the loop still
0048  * terminates even if the bit never changes.  The delay is for devices that
0049  * need a delay in between successive reads.
0050  *
0051  * gcc will optimize out the if-statement if @delay is a constant.
0052  */
0053 #define spin_event_timeout(condition, timeout, delay)                          \
0054 ({                                                                             \
0055     typeof(condition) __ret;                                               \
0056     unsigned long __loops = tb_ticks_per_usec * timeout;                   \
0057     unsigned long __start = mftb();                                     \
0058                                                                                \
0059     if (delay) {                                                           \
0060         while (!(__ret = (condition)) &&                               \
0061                 (tb_ticks_since(__start) <= __loops))          \
0062             udelay(delay);                                         \
0063     } else {                                                               \
0064         spin_begin();                                                  \
0065         while (!(__ret = (condition)) &&                               \
0066                 (tb_ticks_since(__start) <= __loops))          \
0067             spin_cpu_relax();                                      \
0068         spin_end();                                                    \
0069     }                                                                      \
0070     if (!__ret)                                                            \
0071         __ret = (condition);                                           \
0072     __ret;                                                             \
0073 })
0074 
0075 #endif /* __KERNEL__ */
0076 #endif /* _ASM_POWERPC_DELAY_H */