/* SPDX-License-Identifier: GPL-2.0-or-later */1#ifndef _ASM_POWERPC_DELAY_H2#define _ASM_POWERPC_DELAY_H3#ifdef __KERNEL__45#include <linux/processor.h>6#include <asm/time.h>78/*9* Copyright 1996, Paul Mackerras.10* Copyright (C) 2009 Freescale Semiconductor, Inc. All rights reserved.11*12* PPC64 Support added by Dave Engebretsen, Todd Inglett, Mike Corrigan,13* Anton Blanchard.14*/1516extern void __delay(unsigned long loops);17extern void udelay(unsigned long usecs);1819/*20* On shared processor machines the generic implementation of mdelay can21* result in large errors. While each iteration of the loop inside mdelay22* is supposed to take 1ms, the hypervisor could sleep our partition for23* longer (eg 10ms). With the right timing these errors can add up.24*25* Since there is no 32bit overflow issue on 64bit kernels, just call26* udelay directly.27*/28#ifdef CONFIG_PPC6429#define mdelay(n) udelay((n) * 1000)30#endif3132/**33* spin_event_timeout - spin until a condition gets true or a timeout elapses34* @condition: a C expression to evalate35* @timeout: timeout, in microseconds36* @delay: the number of microseconds to delay between each evaluation of37* @condition38*39* The process spins until the condition evaluates to true (non-zero) or the40* timeout elapses. The return value of this macro is the value of41* @condition when the loop terminates. This allows you to determine the cause42* of the loop terminates. If the return value is zero, then you know a43* timeout has occurred.44*45* This primary purpose of this macro is to poll on a hardware register46* until a status bit changes. The timeout ensures that the loop still47* terminates even if the bit never changes. The delay is for devices that48* need a delay in between successive reads.49*50* gcc will optimize out the if-statement if @delay is a constant.51*/52#define spin_event_timeout(condition, timeout, delay) \53({ \54typeof(condition) __ret; \55unsigned long __loops = tb_ticks_per_usec * timeout; \56unsigned long __start = mftb(); \57\58if (delay) { \59while (!(__ret = (condition)) && \60(tb_ticks_since(__start) <= __loops)) \61udelay(delay); \62} else { \63spin_begin(); \64while (!(__ret = (condition)) && \65(tb_ticks_since(__start) <= __loops)) \66spin_cpu_relax(); \67spin_end(); \68} \69if (!__ret) \70__ret = (condition); \71__ret; \72})7374#endif /* __KERNEL__ */75#endif /* _ASM_POWERPC_DELAY_H */767778