cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

delay.c (1163B)


      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         * To end the bloody studid and useless discussion about the
     18         * BogoMips number I took the liberty to define the __delay
     19         * function in a way that that resulting BogoMips number will
     20         * yield the megahertz number of the cpu. The important function
     21         * is udelay and that is done using the tod clock. -- martin.
     22         */
     23	asm volatile("0: brct %0,0b" : : "d" ((loops/2) + 1));
     24}
     25EXPORT_SYMBOL(__delay);
     26
     27static void delay_loop(unsigned long delta)
     28{
     29	unsigned long end;
     30
     31	end = get_tod_clock_monotonic() + delta;
     32	while (!tod_after(get_tod_clock_monotonic(), end))
     33		cpu_relax();
     34}
     35
     36void __udelay(unsigned long usecs)
     37{
     38	delay_loop(usecs << 12);
     39}
     40EXPORT_SYMBOL(__udelay);
     41
     42void __ndelay(unsigned long nsecs)
     43{
     44	nsecs <<= 9;
     45	do_div(nsecs, 125);
     46	delay_loop(nsecs);
     47}
     48EXPORT_SYMBOL(__ndelay);