1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Precise Delay Loops for S390
4 *
5 * Copyright IBM Corp. 1999, 2008
6 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>,
7 */
8
9#include <linux/processor.h>
10#include <linux/delay.h>
11#include <asm/div64.h>
12#include <asm/timex.h>
13
14void __delay(unsigned long loops)
15{
16 /*
17 * Loop 'loops' times. Callers must not assume a specific
18 * amount of time passes before this function returns.
19 */
20 asm volatile("0: brct %0,0b" : : "d" ((loops/2) + 1));
21}
22EXPORT_SYMBOL(__delay);
23
24static void delay_loop(unsigned long delta)
25{
26 unsigned long end;
27
28 end = get_tod_clock_monotonic() + delta;
29 while (!tod_after(get_tod_clock_monotonic(), end))
30 cpu_relax();
31}
32
33void __udelay(unsigned long usecs)
34{
35 delay_loop(delta: usecs << 12);
36}
37EXPORT_SYMBOL(__udelay);
38
39void __ndelay(unsigned long nsecs)
40{
41 nsecs <<= 9;
42 do_div(nsecs, 125);
43 delay_loop(delta: nsecs);
44}
45EXPORT_SYMBOL(__ndelay);
46

source code of linux/arch/s390/lib/delay.c