timer_hb.c revision 1.3 1 /* $NetBSD: timer_hb.c,v 1.3 2002/10/02 04:40:08 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/param.h>
40 #include <sys/kernel.h>
41 #include <sys/systm.h>
42 #include <sys/device.h>
43
44 #include <uvm/uvm_extern.h>
45
46 #include <machine/cpu.h>
47 #include <machine/bus.h>
48
49 #include <dev/clock_subr.h>
50
51 #include <news68k/news68k/isr.h>
52 #include <news68k/news68k/clockvar.h>
53
54 #include <news68k/dev/hbvar.h>
55
56 /*
57 * interrupt level for clock
58 */
59
60 #define TIMER_LEVEL 6
61 #define TIMER_SIZE 8 /* XXX */
62
63 int timer_hb_match(struct device *, struct cfdata *, void *);
64 void timer_hb_attach(struct device *, struct device *, void *);
65 void timer_hb_initclocks(int, int);
66 void clock_intr(struct clockframe *);
67
68 static __inline void leds_intr __P((void));
69
70 extern void _isr_clock __P((void)); /* locore.s */
71
72 CFATTACH_DECL(timer_hb, sizeof(struct device),
73 timer_hb_match, timer_hb_attach, NULL, NULL);
74
75 static volatile u_int8_t *ctrl_timer; /* XXX */
76
77 extern volatile u_char *ctrl_led; /* XXX */
78 extern struct cfdriver timer_cd;
79
80 int
81 timer_hb_match(parent, cf, aux)
82 struct device *parent;
83 struct cfdata *cf;
84 void *aux;
85 {
86 struct hb_attach_args *ha = aux;
87 static int timer_hb_matched;
88
89 /* Only one timer, please. */
90 if (timer_hb_matched)
91 return (0);
92
93 if (strcmp(ha->ha_name, timer_cd.cd_name))
94 return (0);
95
96 if (ha->ha_ipl == -1)
97 ha->ha_ipl = TIMER_LEVEL;
98
99 ha->ha_size = TIMER_SIZE;
100
101 timer_hb_matched = 1;
102
103 return 1;
104 }
105
106 void
107 timer_hb_attach(parent, self, aux)
108 struct device *parent, *self;
109 void *aux;
110 {
111 struct hb_attach_args *ha = aux;
112
113 if (ha->ha_ipl != TIMER_LEVEL)
114 panic("clock_hb_attach: wrong interrupt level");
115
116 ctrl_timer = (u_int8_t *)IIOV(ha->ha_address); /* XXX needs bus_space */
117
118 printf("\n");
119
120 timer_config(timer_hb_initclocks);
121
122 #if 0 /* XXX this will be done in timer_hb_initclocks() */
123 isrlink_custom(ha->ha_ipl, (void *)_isr_clock);
124 #endif
125 }
126
127 /*
128 * Set up the interval timer (enable clock interrupts).
129 * Leave stathz 0 since there is no secondary clock available.
130 * Note that clock interrupts MUST STAY DISABLED until here.
131 */
132 void
133 timer_hb_initclocks(tick, statint)
134 int tick, statint;
135 {
136 int s;
137
138 s = splhigh();
139
140 /* Install isr (in locore.s) that calls clock_intr(). */
141 isrlink_custom(TIMER_LEVEL, (void *)_isr_clock);
142
143 /* enable the clock */
144 *ctrl_timer = 1;
145 splx(s);
146 }
147
148 /*
149 * Clock interrupt handler.
150 * This is is called by the "custom" interrupt handler.
151 *
152 * from sun3/sun3x/clock.c -tsutsui
153 */
154 void
155 clock_intr(cf)
156 struct clockframe *cf;
157 {
158 #ifdef LED_IDLE_CHECK
159 extern char _Idle[]; /* locore.s */
160 #endif
161
162 /* Pulse the clock intr. enable low. */
163 *ctrl_timer = 0;
164 *ctrl_timer = 1;
165 intrcnt[TIMER_LEVEL]++;
166
167 /* Entertainment! */
168 #ifdef LED_IDLE_CHECK
169 if (cf.cf_pc == (long)_Idle)
170 #endif
171 leds_intr();
172
173 /* Call common clock interrupt handler. */
174 hardclock(cf);
175 uvmexp.intrs++;
176 }
177
178 /* heartbeat LED */
179 #define LED0 0x01
180 #define LED1 0x02
181
182 static __inline void
183 leds_intr()
184 {
185 static u_char led_countdown, led_stat;
186 u_char i;
187
188 if (led_countdown) {
189 led_countdown--;
190 return;
191 }
192
193 i = led_stat ^ LED0;
194 *ctrl_led = i;
195 led_stat = i;
196 led_countdown = hz;
197 }
198
199