ctl.c revision 1.1.2.2 1 1.1.2.2 skrll /* $NetBSD: ctl.c,v 1.1.2.2 2009/03/03 18:29:13 skrll Exp $ */
2 1.1.2.2 skrll
3 1.1.2.2 skrll /*
4 1.1.2.2 skrll * Copyright (c) 2009 Stephen M. Rumble
5 1.1.2.2 skrll * All rights reserved.
6 1.1.2.2 skrll *
7 1.1.2.2 skrll * Redistribution and use in source and binary forms, with or without
8 1.1.2.2 skrll * modification, are permitted provided that the following conditions
9 1.1.2.2 skrll * are met:
10 1.1.2.2 skrll * 1. Redistributions of source code must retain the above copyright
11 1.1.2.2 skrll * notice, this list of conditions and the following disclaimer.
12 1.1.2.2 skrll * 2. Redistributions in binary form must reproduce the above copyright
13 1.1.2.2 skrll * notice, this list of conditions and the following disclaimer in the
14 1.1.2.2 skrll * documentation and/or other materials provided with the distribution.
15 1.1.2.2 skrll * 3. The name of the author may not be used to endorse or promote products
16 1.1.2.2 skrll * derived from this software without specific prior written permission.
17 1.1.2.2 skrll *
18 1.1.2.2 skrll * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.1.2.2 skrll * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.1.2.2 skrll * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.1.2.2 skrll * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 1.1.2.2 skrll * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 1.1.2.2 skrll * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 1.1.2.2 skrll * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 1.1.2.2 skrll * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 1.1.2.2 skrll * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 1.1.2.2 skrll * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 1.1.2.2 skrll */
29 1.1.2.2 skrll
30 1.1.2.2 skrll #include <sys/cdefs.h>
31 1.1.2.2 skrll __KERNEL_RCSID(0, "$NetBSD: ctl.c,v 1.1.2.2 2009/03/03 18:29:13 skrll Exp $");
32 1.1.2.2 skrll
33 1.1.2.2 skrll #include <sys/param.h>
34 1.1.2.2 skrll #include <sys/kernel.h>
35 1.1.2.2 skrll #include <sys/device.h>
36 1.1.2.2 skrll #include <sys/systm.h>
37 1.1.2.2 skrll #include <sys/callout.h>
38 1.1.2.2 skrll
39 1.1.2.2 skrll #include <machine/cpu.h>
40 1.1.2.2 skrll #include <machine/locore.h>
41 1.1.2.2 skrll #include <machine/autoconf.h>
42 1.1.2.2 skrll #include <machine/bus.h>
43 1.1.2.2 skrll #include <machine/machtype.h>
44 1.1.2.2 skrll #include <machine/sysconf.h>
45 1.1.2.2 skrll
46 1.1.2.2 skrll #include <sgimips/dev/ctlreg.h>
47 1.1.2.2 skrll
48 1.1.2.2 skrll struct ctl_softc {
49 1.1.2.2 skrll struct device sc_dev;
50 1.1.2.2 skrll
51 1.1.2.2 skrll bus_space_tag_t iot;
52 1.1.2.2 skrll bus_space_handle_t ioh;
53 1.1.2.2 skrll
54 1.1.2.2 skrll };
55 1.1.2.2 skrll
56 1.1.2.2 skrll static int ctl_match(struct device *, struct cfdata *, void *);
57 1.1.2.2 skrll static void ctl_attach(struct device *, struct device *, void *);
58 1.1.2.2 skrll static void ctl_bus_reset(void);
59 1.1.2.2 skrll static void ctl_bus_error(uint32_t, uint32_t, uint32_t, uint32_t);
60 1.1.2.2 skrll static void ctl_watchdog_enable(void);
61 1.1.2.2 skrll static void ctl_watchdog_disable(void);
62 1.1.2.2 skrll static void ctl_watchdog_tickle(void);
63 1.1.2.2 skrll
64 1.1.2.2 skrll #if defined(BLINK)
65 1.1.2.2 skrll static callout_t ctl_blink_ch;
66 1.1.2.2 skrll static void ctl_blink(void *);
67 1.1.2.2 skrll #endif
68 1.1.2.2 skrll
69 1.1.2.2 skrll CFATTACH_DECL(ctl, sizeof(struct ctl_softc),
70 1.1.2.2 skrll ctl_match, ctl_attach, NULL, NULL);
71 1.1.2.2 skrll
72 1.1.2.2 skrll static struct ctl_softc csc;
73 1.1.2.2 skrll
74 1.1.2.2 skrll static int
75 1.1.2.2 skrll ctl_match(struct device * parent, struct cfdata * match, void *aux)
76 1.1.2.2 skrll {
77 1.1.2.2 skrll /*
78 1.1.2.2 skrll * CTL exists on IP6/IP10 systems.
79 1.1.2.2 skrll */
80 1.1.2.2 skrll if (mach_type == MACH_SGI_IP6 || mach_type == MACH_SGI_IP10)
81 1.1.2.2 skrll return 1;
82 1.1.2.2 skrll else
83 1.1.2.2 skrll return 0;
84 1.1.2.2 skrll }
85 1.1.2.2 skrll
86 1.1.2.2 skrll static void
87 1.1.2.2 skrll ctl_attach(struct device * parent, struct device * self, void *aux)
88 1.1.2.2 skrll {
89 1.1.2.2 skrll struct mainbus_attach_args *ma = aux;
90 1.1.2.2 skrll
91 1.1.2.2 skrll #ifdef BLINK
92 1.1.2.2 skrll callout_init(&ctl_blink_ch, 0);
93 1.1.2.2 skrll #endif
94 1.1.2.2 skrll
95 1.1.2.2 skrll csc.iot = SGIMIPS_BUS_SPACE_NORMAL;
96 1.1.2.2 skrll if (bus_space_map(csc.iot, ma->ma_addr, 0,
97 1.1.2.2 skrll BUS_SPACE_MAP_LINEAR, &csc.ioh))
98 1.1.2.2 skrll panic("ctl_attach: could not allocate memory\n");
99 1.1.2.2 skrll
100 1.1.2.2 skrll platform.bus_reset = ctl_bus_reset;
101 1.1.2.2 skrll platform.intr5 = ctl_bus_error;
102 1.1.2.2 skrll platform.watchdog_enable = ctl_watchdog_enable;
103 1.1.2.2 skrll platform.watchdog_disable = ctl_watchdog_disable;
104 1.1.2.2 skrll platform.watchdog_reset = ctl_watchdog_tickle;
105 1.1.2.2 skrll
106 1.1.2.2 skrll bus_space_write_2(csc.iot, csc.ioh, CTL_CPUCTRL,
107 1.1.2.2 skrll (CTL_CPUCTRL_PARITY | CTL_CPUCTRL_SLAVE));
108 1.1.2.2 skrll
109 1.1.2.2 skrll printf("\n");
110 1.1.2.2 skrll
111 1.1.2.2 skrll ctl_bus_reset();
112 1.1.2.2 skrll
113 1.1.2.2 skrll #if defined(BLINK)
114 1.1.2.2 skrll ctl_blink(&csc);
115 1.1.2.2 skrll #endif
116 1.1.2.2 skrll }
117 1.1.2.2 skrll
118 1.1.2.2 skrll static void
119 1.1.2.2 skrll ctl_bus_reset(void)
120 1.1.2.2 skrll {
121 1.1.2.2 skrll
122 1.1.2.2 skrll bus_space_read_1(csc.iot, csc.ioh, CTL_LAN_PAR_CLR);
123 1.1.2.2 skrll bus_space_read_1(csc.iot, csc.ioh, CTL_DMA_PAR_CLR);
124 1.1.2.2 skrll bus_space_read_1(csc.iot, csc.ioh, CTL_CPU_PAR_CLR);
125 1.1.2.2 skrll bus_space_read_1(csc.iot, csc.ioh, CTL_VME_PAR_CLR);
126 1.1.2.2 skrll }
127 1.1.2.2 skrll
128 1.1.2.2 skrll static void
129 1.1.2.2 skrll ctl_bus_error(uint32_t status, uint32_t cause, uint32_t pc, uint32_t ipending)
130 1.1.2.2 skrll {
131 1.1.2.2 skrll
132 1.1.2.2 skrll printf("ctl0: bus error\n");
133 1.1.2.2 skrll ctl_bus_reset();
134 1.1.2.2 skrll }
135 1.1.2.2 skrll
136 1.1.2.2 skrll static void
137 1.1.2.2 skrll ctl_watchdog_enable(void)
138 1.1.2.2 skrll {
139 1.1.2.2 skrll uint32_t reg;
140 1.1.2.2 skrll
141 1.1.2.2 skrll /* XXX- doesn't seem to work properly */
142 1.1.2.2 skrll return;
143 1.1.2.2 skrll
144 1.1.2.2 skrll reg = bus_space_read_2(csc.iot, csc.ioh, CTL_CPUCTRL);
145 1.1.2.2 skrll reg |= CTL_CPUCTRL_WDOG;
146 1.1.2.2 skrll bus_space_write_2(csc.iot, csc.ioh, CTL_CPUCTRL, reg);
147 1.1.2.2 skrll }
148 1.1.2.2 skrll
149 1.1.2.2 skrll static void
150 1.1.2.2 skrll ctl_watchdog_disable(void)
151 1.1.2.2 skrll {
152 1.1.2.2 skrll uint16_t reg;
153 1.1.2.2 skrll
154 1.1.2.2 skrll /* XXX- doesn't seem to work properly */
155 1.1.2.2 skrll return;
156 1.1.2.2 skrll
157 1.1.2.2 skrll reg = bus_space_read_2(csc.iot, csc.ioh, CTL_CPUCTRL_WDOG);
158 1.1.2.2 skrll reg &= ~(CTL_CPUCTRL_WDOG);
159 1.1.2.2 skrll bus_space_write_2(csc.iot, csc.ioh, CTL_CPUCTRL, reg);
160 1.1.2.2 skrll }
161 1.1.2.2 skrll
162 1.1.2.2 skrll static void
163 1.1.2.2 skrll ctl_watchdog_tickle(void)
164 1.1.2.2 skrll {
165 1.1.2.2 skrll
166 1.1.2.2 skrll ctl_watchdog_disable();
167 1.1.2.2 skrll ctl_watchdog_enable();
168 1.1.2.2 skrll }
169 1.1.2.2 skrll
170 1.1.2.2 skrll #if defined(BLINK)
171 1.1.2.2 skrll static void
172 1.1.2.2 skrll ctl_blink(void *self)
173 1.1.2.2 skrll {
174 1.1.2.2 skrll struct ctl_softc *sc = (struct ctl_softc *) self;
175 1.1.2.2 skrll int s, value;
176 1.1.2.2 skrll
177 1.1.2.2 skrll s = splhigh();
178 1.1.2.2 skrll
179 1.1.2.2 skrll value = bus_space_read_1(sc->iot, sc->ioh, CTL_AUX_CPUCTRL);
180 1.1.2.2 skrll value ^= CTL_AUX_CPUCTRL_CONSLED;
181 1.1.2.2 skrll bus_space_write_1(sc->iot, sc->ioh, CTL_AUX_CPUCTRL, value);
182 1.1.2.2 skrll splx(s);
183 1.1.2.2 skrll
184 1.1.2.2 skrll /*
185 1.1.2.2 skrll * Blink rate is:
186 1.1.2.2 skrll * full cycle every second if completely idle (loadav = 0)
187 1.1.2.2 skrll * full cycle every 2 seconds if loadav = 1
188 1.1.2.2 skrll * full cycle every 3 seconds if loadav = 2
189 1.1.2.2 skrll * etc.
190 1.1.2.2 skrll */
191 1.1.2.2 skrll s = (((averunnable.ldavg[0] + FSCALE) * hz) >> (FSHIFT + 1));
192 1.1.2.2 skrll callout_reset(&ctl_blink_ch, s, ctl_blink, sc);
193 1.1.2.2 skrll }
194 1.1.2.2 skrll #endif
195