timer_hb.c revision 1.6 1 /* $NetBSD: timer_hb.c,v 1.6 2003/07/15 02:59:26 lukem 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/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: timer_hb.c,v 1.6 2003/07/15 02:59:26 lukem Exp $");
41
42 #include <sys/param.h>
43 #include <sys/kernel.h>
44 #include <sys/systm.h>
45 #include <sys/device.h>
46
47 #include <uvm/uvm_extern.h>
48
49 #include <machine/cpu.h>
50 #include <machine/bus.h>
51
52 #include <dev/clock_subr.h>
53
54 #include <news68k/news68k/isr.h>
55 #include <news68k/news68k/clockvar.h>
56
57 #include <news68k/dev/hbvar.h>
58
59 /*
60 * interrupt level for clock
61 */
62
63 #define TIMER_LEVEL 6
64 #define TIMER_SIZE 8 /* XXX */
65
66 int timer_hb_match(struct device *, struct cfdata *, void *);
67 void timer_hb_attach(struct device *, struct device *, void *);
68 void timer_hb_initclocks(int, int);
69 void clock_intr(struct clockframe *);
70
71 static __inline void leds_intr(void);
72
73 extern void _isr_clock(void); /* locore.s */
74
75 CFATTACH_DECL(timer_hb, sizeof(struct device),
76 timer_hb_match, timer_hb_attach, NULL, NULL);
77
78 static volatile u_int8_t *ctrl_timer; /* XXX */
79
80 extern volatile u_char *ctrl_led; /* XXX */
81 extern struct cfdriver timer_cd;
82
83 int
84 timer_hb_match(parent, cf, aux)
85 struct device *parent;
86 struct cfdata *cf;
87 void *aux;
88 {
89 struct hb_attach_args *ha = aux;
90 static int timer_hb_matched;
91
92 /* Only one timer, please. */
93 if (timer_hb_matched)
94 return (0);
95
96 if (strcmp(ha->ha_name, timer_cd.cd_name))
97 return (0);
98
99 if (ha->ha_ipl == -1)
100 ha->ha_ipl = TIMER_LEVEL;
101
102 ha->ha_size = TIMER_SIZE;
103
104 timer_hb_matched = 1;
105
106 return 1;
107 }
108
109 void
110 timer_hb_attach(parent, self, aux)
111 struct device *parent, *self;
112 void *aux;
113 {
114 struct hb_attach_args *ha = aux;
115
116 if (ha->ha_ipl != TIMER_LEVEL)
117 panic("clock_hb_attach: wrong interrupt level");
118
119 ctrl_timer = (u_int8_t *)IIOV(ha->ha_address); /* XXX needs bus_space */
120
121 printf("\n");
122
123 timer_config(timer_hb_initclocks);
124
125 #if 0 /* XXX this will be done in timer_hb_initclocks() */
126 isrlink_custom(ha->ha_ipl, (void *)_isr_clock);
127 #endif
128 }
129
130 /*
131 * Set up the interval timer (enable clock interrupts).
132 * Leave stathz 0 since there is no secondary clock available.
133 * Note that clock interrupts MUST STAY DISABLED until here.
134 */
135 void
136 timer_hb_initclocks(tick, statint)
137 int tick, statint;
138 {
139 int s;
140
141 s = splhigh();
142
143 /* Install isr (in locore.s) that calls clock_intr(). */
144 isrlink_custom(TIMER_LEVEL, (void *)_isr_clock);
145
146 /* enable the clock */
147 *ctrl_timer = 1;
148 splx(s);
149 }
150
151 /*
152 * Clock interrupt handler.
153 * This is is called by the "custom" interrupt handler.
154 *
155 * from sun3/sun3x/clock.c -tsutsui
156 */
157 void
158 clock_intr(cf)
159 struct clockframe *cf;
160 {
161 #ifdef LED_IDLE_CHECK
162 extern char _Idle[]; /* locore.s */
163 #endif
164
165 /* Pulse the clock intr. enable low. */
166 *ctrl_timer = 0;
167 *ctrl_timer = 1;
168 intrcnt[TIMER_LEVEL]++;
169
170 /* Entertainment! */
171 #ifdef LED_IDLE_CHECK
172 if (cf.cf_pc == (long)_Idle)
173 #endif
174 leds_intr();
175
176 /* Call common clock interrupt handler. */
177 hardclock(cf);
178 uvmexp.intrs++;
179 }
180
181 /* heartbeat LED */
182 #define LED0 0x01
183 #define LED1 0x02
184
185 static __inline void
186 leds_intr()
187 {
188 static u_char led_countdown, led_stat;
189 u_char i;
190
191 if (led_countdown) {
192 led_countdown--;
193 return;
194 }
195
196 i = led_stat ^ LED0;
197 *ctrl_led = i;
198 led_stat = i;
199 led_countdown = hz;
200 }
201
202