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