xref: /netbsd-src/sys/arch/arc/arc/timer.c (revision 952c1ac435a694dec490ab331a2d13e47ad33c87)
1 /* $NetBSD: timer.c,v 1.12 2023/08/30 17:10:17 tsutsui Exp $ */
2 /* NetBSD: clock.c,v 1.31 2001/05/27 13:53:24 sommerfeld Exp  */
3 
4 /*
5  * Copyright (c) 1988 University of Utah.
6  * Copyright (c) 1992, 1993
7  *	The Regents of the University of California.  All rights reserved.
8  *
9  * This code is derived from software contributed to Berkeley by
10  * the Systems Programming Group of the University of Utah Computer
11  * Science Department and Ralph Campbell.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  * 1. Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright
19  *    notice, this list of conditions and the following disclaimer in the
20  *    documentation and/or other materials provided with the distribution.
21  * 3. Neither the name of the University nor the names of its contributors
22  *    may be used to endorse or promote products derived from this software
23  *    without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  *
37  * from: Utah Hdr: clock.c 1.18 91/01/21
38  *
39  *	@(#)clock.c	8.1 (Berkeley) 6/10/93
40  */
41 
42 #include <sys/cdefs.h>
43 __KERNEL_RCSID(0, "$NetBSD: timer.c,v 1.12 2023/08/30 17:10:17 tsutsui Exp $");
44 
45 #include <sys/param.h>
46 #include <sys/kernel.h>
47 #include <sys/systm.h>
48 
49 #include <mips/locore.h>
50 #include <mips/mips3_clock.h>
51 
52 #include <arc/arc/timervar.h>
53 
54 device_t timerdev;
55 const struct timerfns *timerfns;
56 int timerinitted;
57 uint32_t last_cp0_count;
58 
59 void
timerattach(device_t dev,const struct timerfns * fns)60 timerattach(device_t dev, const struct timerfns *fns)
61 {
62 
63 	/*
64 	 * Just bookkeeping.
65 	 */
66 
67 	if (timerfns != NULL)
68 		panic("timerattach: multiple timers");
69 	timerdev = dev;
70 	timerfns = fns;
71 }
72 
73 /*
74  * Machine-dependent clock routines.
75  */
76 
77 /*
78  * Start the real-time and statistics clocks. Leave stathz 0 since there
79  * are no other timers available.
80  */
81 void
cpu_initclocks(void)82 cpu_initclocks(void)
83 {
84 
85 	if (timerfns == NULL)
86 		panic("cpu_initclocks: no timer attached");
87 
88 	/*
89 	 * Get the clock started.
90 	 */
91 	(*timerfns->tf_init)(timerdev);
92 
93 	/* init timecounter */
94 	mips3_init_tc();
95 }
96 
97 /*
98  * This does not need to do anything, as we don't use a timer for statclock
99  * and profhz == stathz == hz.
100  */
101 void
setstatclockrate(int newhz)102 setstatclockrate(int newhz)
103 {
104 
105 	/* nothing to do */
106 }
107