xref: /netbsd-src/sys/arch/arc/arc/timer.c (revision 5b84b3983f71fd20a534cfa5d1556623a8aaa717)
1 /* $NetBSD: timer.c,v 1.3 2005/01/22 07:35:33 tsutsui 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.3 2005/01/22 07:35:33 tsutsui 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(struct device *dev, const struct timerfns *fns)
96 {
97 
98 	/*
99 	 * Just bookkeeping.
100 	 */
101 
102 	if (timerfns != NULL)
103 		panic("timerattach: multiple timers");
104 	timerdev = dev;
105 	timerfns = fns;
106 }
107 
108 /*
109  * Machine-dependent clock routines.
110  */
111 
112 /*
113  * Start the real-time and statistics clocks. Leave stathz 0 since there
114  * are no other timers available.
115  */
116 void
117 cpu_initclocks(void)
118 {
119 	if (timerfns == NULL)
120 		panic("cpu_initclocks: no timer attached");
121 
122 	tick = 1000000 / hz;	/* number of microseconds between interrupts */
123 	tickfix = 1000000 - (hz * tick);
124 	if (tickfix) {
125 		int ftp;
126 
127 		ftp = min(ffs(tickfix), ffs(hz));
128 		tickfix >>= (ftp - 1);
129 		tickfixinterval = hz >> (ftp - 1);
130         }
131 
132 	/*
133 	 * Get the clock started.
134 	 */
135 	(*timerfns->tf_init)(timerdev);
136 }
137 
138 /*
139  * We assume newhz is either stathz or profhz, and that neither will
140  * change after being set up above.  Could recalculate intervals here
141  * but that would be a drag.
142  */
143 void
144 setstatclockrate(int newhz)
145 {
146 
147 	/* nothing we can do */
148 }
149 
150 /*
151  * Wait "n" microseconds.
152  * XXX Should be calibrated with the cycle counter.
153  */
154 void
155 delay(int n)
156 {
157 
158 	DELAY(n);
159 }
160