Linux Audio

Check our new training course

Loading...
v5.4
  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/irq.h>
 17#include <asm/vtimer.h>
 18#include <asm/div64.h>
 19#include <asm/idle.h>
 20
 21void __delay(unsigned long loops)
 22{
 23        /*
 24         * To end the bloody studid and useless discussion about the
 25         * BogoMips number I took the liberty to define the __delay
 26         * function in a way that that resulting BogoMips number will
 27         * yield the megahertz number of the cpu. The important function
 28         * is udelay and that is done using the tod clock. -- martin.
 29         */
 30	asm volatile("0: brct %0,0b" : : "d" ((loops/2) + 1));
 31}
 32EXPORT_SYMBOL(__delay);
 33
 34static void __udelay_disabled(unsigned long long usecs)
 35{
 36	unsigned long cr0, cr0_new, psw_mask;
 37	struct s390_idle_data idle;
 38	u64 end;
 39
 40	end = get_tod_clock() + (usecs << 12);
 41	__ctl_store(cr0, 0, 0);
 42	cr0_new = cr0 & ~CR0_IRQ_SUBCLASS_MASK;
 43	cr0_new |= (1UL << (63 - 52)); /* enable clock comparator irq */
 44	__ctl_load(cr0_new, 0, 0);
 45	psw_mask = __extract_psw() | PSW_MASK_EXT | PSW_MASK_WAIT;
 46	set_clock_comparator(end);
 47	set_cpu_flag(CIF_IGNORE_IRQ);
 48	psw_idle(&idle, psw_mask);
 49	clear_cpu_flag(CIF_IGNORE_IRQ);
 50	set_clock_comparator(S390_lowcore.clock_comparator);
 51	__ctl_load(cr0, 0, 0);
 52}
 53
 54static void __udelay_enabled(unsigned long long usecs)
 55{
 56	u64 clock_saved, end;
 57
 58	end = get_tod_clock_fast() + (usecs << 12);
 59	do {
 60		clock_saved = 0;
 61		if (tod_after(S390_lowcore.clock_comparator, end)) {
 62			clock_saved = local_tick_disable();
 63			set_clock_comparator(end);
 64		}
 65		enabled_wait();
 66		if (clock_saved)
 67			local_tick_enable(clock_saved);
 68	} while (get_tod_clock_fast() < end);
 69}
 70
 71/*
 72 * Waits for 'usecs' microseconds using the TOD clock comparator.
 73 */
 74void __udelay(unsigned long long usecs)
 75{
 76	unsigned long flags;
 77
 78	preempt_disable();
 79	local_irq_save(flags);
 80	if (in_irq()) {
 81		__udelay_disabled(usecs);
 82		goto out;
 83	}
 84	if (in_softirq()) {
 85		if (raw_irqs_disabled_flags(flags))
 86			__udelay_disabled(usecs);
 87		else
 88			__udelay_enabled(usecs);
 89		goto out;
 90	}
 91	if (raw_irqs_disabled_flags(flags)) {
 92		local_bh_disable();
 93		__udelay_disabled(usecs);
 94		_local_bh_enable();
 95		goto out;
 96	}
 97	__udelay_enabled(usecs);
 98out:
 99	local_irq_restore(flags);
100	preempt_enable();
101}
102EXPORT_SYMBOL(__udelay);
103
104/*
105 * Simple udelay variant. To be used on startup and reboot
106 * when the interrupt handler isn't working.
107 */
108void udelay_simple(unsigned long long usecs)
109{
110	u64 end;
111
112	end = get_tod_clock_fast() + (usecs << 12);
113	while (get_tod_clock_fast() < end)
114		cpu_relax();
115}
116
117void __ndelay(unsigned long long nsecs)
118{
119	u64 end;
120
121	nsecs <<= 9;
122	do_div(nsecs, 125);
123	end = get_tod_clock_fast() + nsecs;
124	if (nsecs & ~0xfffUL)
125		__udelay(nsecs >> 12);
126	while (get_tod_clock_fast() < end)
127		barrier();
128}
129EXPORT_SYMBOL(__ndelay);
v5.14.15
 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);