xref: /netbsd-src/sys/arch/arc/arc/timer.c (revision 23c8222edbfb0f0932d88a8351d3a0cf817dfb9e)
1 /* $NetBSD: timer.c,v 1.2 2003/08/07 16:26:48 agc Exp $ */
2 /* NetBSD: clock.c,v 1.31 2001/05/27 13:53:24 sommerfeld Exp  */
3 
4 /*
5  * Copyright (c) 1992, 1993
6  *	The Regents of the University of California.  All rights reserved.
7  *
8  * This code is derived from software contributed to Berkeley by
9  * the Systems Programming Group of the University of Utah Computer
10  * Science Department and Ralph Campbell.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  * 3. Neither the name of the University nor the names of its contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  * from: Utah Hdr: clock.c 1.18 91/01/21
37  *
38  *	@(#)clock.c	8.1 (Berkeley) 6/10/93
39  */
40 /*
41  * Copyright (c) 1988 University of Utah.
42  *
43  * This code is derived from software contributed to Berkeley by
44  * the Systems Programming Group of the University of Utah Computer
45  * Science Department and Ralph Campbell.
46  *
47  * Redistribution and use in source and binary forms, with or without
48  * modification, are permitted provided that the following conditions
49  * are met:
50  * 1. Redistributions of source code must retain the above copyright
51  *    notice, this list of conditions and the following disclaimer.
52  * 2. Redistributions in binary form must reproduce the above copyright
53  *    notice, this list of conditions and the following disclaimer in the
54  *    documentation and/or other materials provided with the distribution.
55  * 3. All advertising materials mentioning features or use of this software
56  *    must display the following acknowledgement:
57  *	This product includes software developed by the University of
58  *	California, Berkeley and its contributors.
59  * 4. Neither the name of the University nor the names of its contributors
60  *    may be used to endorse or promote products derived from this software
61  *    without specific prior written permission.
62  *
63  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
64  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
65  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
66  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
67  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
68  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
69  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
70  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
71  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
72  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
73  * SUCH DAMAGE.
74  *
75  * from: Utah Hdr: clock.c 1.18 91/01/21
76  *
77  *	@(#)clock.c	8.1 (Berkeley) 6/10/93
78  */
79 
80 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
81 
82 __KERNEL_RCSID(0, "$NetBSD: timer.c,v 1.2 2003/08/07 16:26:48 agc Exp $");
83 
84 #include <sys/param.h>
85 #include <sys/kernel.h>
86 #include <sys/systm.h>
87 
88 #include <arc/arc/timervar.h>
89 
90 struct device *timerdev;
91 const struct timerfns *timerfns;
92 int timerinitted;
93 
94 void
95 timerattach(dev, fns)
96 	struct device *dev;
97 	const struct timerfns *fns;
98 {
99 
100 	/*
101 	 * Just bookkeeping.
102 	 */
103 
104 	if (timerfns != NULL)
105 		panic("timerattach: multiple timers");
106 	timerdev = dev;
107 	timerfns = fns;
108 }
109 
110 /*
111  * Machine-dependent clock routines.
112  */
113 
114 /*
115  * Start the real-time and statistics clocks. Leave stathz 0 since there
116  * are no other timers available.
117  */
118 void
119 cpu_initclocks()
120 {
121 	if (timerfns == NULL)
122 		panic("cpu_initclocks: no timer attached");
123 
124 	tick = 1000000 / hz;	/* number of microseconds between interrupts */
125 	tickfix = 1000000 - (hz * tick);
126 	if (tickfix) {
127 		int ftp;
128 
129 		ftp = min(ffs(tickfix), ffs(hz));
130 		tickfix >>= (ftp - 1);
131 		tickfixinterval = hz >> (ftp - 1);
132         }
133 
134 	/*
135 	 * Get the clock started.
136 	 */
137 	(*timerfns->tf_init)(timerdev);
138 }
139 
140 /*
141  * We assume newhz is either stathz or profhz, and that neither will
142  * change after being set up above.  Could recalculate intervals here
143  * but that would be a drag.
144  */
145 void
146 setstatclockrate(newhz)
147 	int newhz;
148 {
149 
150 	/* nothing we can do */
151 }
152 
153 /*
154  * Wait "n" microseconds.
155  * XXX Should be calibrated with the cycle counter.
156  */
157 void
158 delay(n)
159 	int n;
160 {
161 
162 	DELAY(n);
163 }
164