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 * Heiko Carstens <heiko.carstens@de.ibm.com>, 8 */ 9 10#include <linux/sched.h> 11#include <linux/delay.h> 12#include <linux/timex.h> 13#include <linux/export.h> 14#include <linux/irqflags.h> 15#include <linux/interrupt.h> 16#include <linux/jump_label.h> 17#include <linux/irq.h> 18#include <asm/vtimer.h> 19#include <asm/div64.h> 20#include <asm/idle.h> 21 22void __delay(unsigned long loops) 23{ 24 /* 25 * To end the bloody studid and useless discussion about the 26 * BogoMips number I took the liberty to define the __delay 27 * function in a way that that resulting BogoMips number will 28 * yield the megahertz number of the cpu. The important function 29 * is udelay and that is done using the tod clock. -- martin. 30 */ 31 asm volatile("0: brct %0,0b" : : "d" ((loops/2) + 1)); 32} 33EXPORT_SYMBOL(__delay); 34 35static void delay_loop(unsigned long delta) 36{ 37 unsigned long end; 38 39 end = get_tod_clock_monotonic() + delta; 40 while (!tod_after(get_tod_clock_monotonic(), end)) 41 cpu_relax(); 42} 43 44void __udelay(unsigned long usecs) 45{ 46 delay_loop(usecs << 12); 47} 48EXPORT_SYMBOL(__udelay); 49 50void __ndelay(unsigned long nsecs) 51{ 52 nsecs <<= 9; 53 do_div(nsecs, 125); 54 delay_loop(nsecs); 55} 56EXPORT_SYMBOL(__ndelay); 57