1/* $NetBSD: clock.c,v 1.41 2011/02/08 20:20:07 rmind Exp $ */
2
3/*
4 * Copyright (c) 1988 University of Utah.
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#include <sys/cdefs.h>
42__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.41 2011/02/08 20:20:07 rmind Exp $");
43
44#include <sys/param.h>
45#include <sys/kernel.h>
46#include <sys/systm.h>
47#include <sys/device.h>
48
49#include <machine/autoconf.h>
50#include <machine/cpuconf.h>
51#include <machine/cpu_counter.h>
52
53#include <alpha/alpha/clockvar.h>
54
55#define PCC_QUAL	1000
56
57void (*clock_init)(void *);
58void *clockdev;
59
60void
61clockattach(void (*fns)(void *), void *dev)
62{
63
64	/*
65	 * Just bookkeeping.
66	 */
67	if (clock_init != NULL)
68		panic("clockattach: multiple clocks");
69	clock_init = fns;
70	clockdev = dev;
71}
72
73/*
74 * Start the real-time and statistics clocks. Leave stathz 0 since there
75 * are no other timers available.
76 */
77void
78cpu_initclocks(void)
79{
80	uint64_t pcc_freq;
81
82	if (clock_init == NULL)
83		panic("cpu_initclocks: no clock attached");
84
85	/*
86	 * Establish the clock interrupt; it's a special case.
87	 *
88	 * We establish the clock interrupt this late because if
89	 * we do it at clock attach time, we may have never been at
90	 * spl0() since taking over the system.  Some versions of
91	 * PALcode save a clock interrupt, which would get delivered
92	 * when we spl0() in autoconf.c.  If established the clock
93	 * interrupt handler earlier, that interrupt would go to
94	 * hardclock, which would then fall over because p->p_stats
95	 * isn't set at that time.
96	 */
97	platform.clockintr = hardclock;
98	schedhz = 16;
99
100	/*
101	 * Initialize PCC timecounter.
102	 */
103	pcc_freq = cpu_frequency(curcpu());
104	cc_init(NULL, pcc_freq, "PCC", PCC_QUAL);
105
106	/*
107	 * Get the clock started.
108	 */
109	(*clock_init)(clockdev);
110}
111
112/*
113 * We assume newhz is either stathz or profhz, and that neither will
114 * change after being set up above.  Could recalculate intervals here
115 * but that would be a drag.
116 */
117void
118setstatclockrate(int newhz)
119{
120
121	/* nothing we can do */
122}
123