Linux Audio

Check our new training course

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