1 /* $NetBSD: timervar.h,v 1.13 2021/01/24 07:36:54 mrg Exp $ */
2
3 /*
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 * contributed to Berkeley.
10 *
11 * All advertising materials mentioning features or use of this software
12 * must display the following acknowledgement:
13 * This product includes software developed by the University of
14 * California, Lawrence Berkeley Laboratory.
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE.
39 */
40
41 #include "opt_sparc_arch.h"
42
43 #if defined(SUN4) || defined(SUN4C)
44 int clockintr_4(void *);
45 int statintr_4(void *);
46 void timer_init_4(void);
47
48 void timerattach_obio_4(device_t, device_t, void *);
49 void timerattach_mainbus_4c(device_t, device_t, void *);
50 #endif /* SUN4 || SUN4C */
51
52 #if defined(SUN4M)
53 int clockintr_4m(void *);
54 int statintr_4m(void *);
55 void timer_init_4m(void);
56
57 void timerattach_obio_4m(device_t, device_t, void *);
58 #endif /* SUN4M */
59
60 /* Imported from clock.c: */
61 extern int statvar, statmin, statint;
62 extern int timerblurb;
63 extern void (*timer_init)(void);
64 extern int (*eeprom_nvram_wenable)(int);
65 extern int oldclk;
66 extern int timerblurb;
67 void tickle_tc(void);
68
69 /* Common timer attach routine in timer.c: */
70 void timerattach(volatile int *, volatile int *);
71 extern void *sched_cookie; /* for schedclock() interrupts */
72
73 static inline u_long __attribute__((__unused__))
new_interval(void)74 new_interval(void)
75 {
76 u_long newint, r, var;
77
78 /*
79 * Compute new randomized interval. The intervals are uniformly
80 * distributed on [statint - statvar / 2, statint + statvar / 2],
81 * and therefore have mean statint, giving a stathz frequency clock.
82 */
83 var = statvar;
84 do {
85 r = random() & (var - 1);
86 } while (r == 0);
87 newint = statmin + r;
88 return (newint);
89 }
90