1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
/* $NetBSD: ioc.c,v 1.13 2021/08/07 16:19:04 thorpej Exp $ */
/*
* Copyright (c) 2003 Christopher Sekiya
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed for the
* NetBSD Project. See http://www.NetBSD.org/ for
* information about NetBSD.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* ip20/22/24 I/O Controller (IOC)
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ioc.c,v 1.13 2021/08/07 16:19:04 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/kernel.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/errno.h>
#include <sys/syslog.h>
#include <uvm/uvm_extern.h>
#include <sys/bus.h>
#include <machine/cpu.h>
#include <machine/locore.h>
#include <machine/autoconf.h>
#include <machine/machtype.h>
#include <sgimips/ioc/iocreg.h>
#include <sgimips/ioc/iocvar.h>
#include "locators.h"
struct ioc_softc {
bus_space_tag_t sc_iot;
bus_space_handle_t sc_ioh;
};
static int ioc_match(device_t, cfdata_t, void *);
static void ioc_attach(device_t, device_t, void *);
#if defined(notyet)
static int ioc_print(void *, const char *);
static int ioc_search(device_t, cfdata_t, const int *, void *);
#endif
CFATTACH_DECL_NEW(ioc, sizeof(struct ioc_softc),
ioc_match, ioc_attach, NULL, NULL);
#if defined(BLINK)
static callout_t ioc_blink_ch;
static void ioc_blink(void *);
#endif
static int
ioc_match(device_t parent, cfdata_t match, void *aux)
{
if (mach_type == MACH_SGI_IP22)
return 1;
return 0;
}
static void
ioc_attach(device_t parent, device_t self, void *aux)
{
struct ioc_softc *sc = device_private(self);
struct mainbus_attach_args *maa = aux;
u_int32_t sysid;
#ifdef BLINK
callout_init(&ioc_blink_ch, 0);
#endif
sc->sc_iot = normal_memt;
if (bus_space_map(sc->sc_iot, maa->ma_addr, 0x100,
BUS_SPACE_MAP_LINEAR, &sc->sc_ioh))
panic("ioc_attach: could not allocate memory\n");
sysid = bus_space_read_4(sc->sc_iot, sc->sc_ioh, IOC_SYSID) & 0x01;
if (sysid)
mach_subtype = MACH_SGI_IP22_FULLHOUSE;
else
mach_subtype = MACH_SGI_IP22_GUINNESS;
aprint_normal(": rev %d, machine %s, board rev %d\n",
((sysid & IOC_SYSID_CHIPREV) >> IOC_SYSID_CHIPREV_SHIFT),
(sysid & IOC_SYSID_SYSTYPE) ? "Indigo2 (Fullhouse)" :
"Indy (Guinness)",
((sysid & IOC_SYSID_BOARDREV) >> IOC_SYSID_BOARDREV_SHIFT));
/* Reset IOC */
bus_space_write_4(sc->sc_iot, sc->sc_ioh, IOC_RESET,
IOC_RESET_PARALLEL | IOC_RESET_PCKBC |
IOC_RESET_EISA | IOC_RESET_ISDN |
IOC_RESET_LED_GREEN );
/*
* Set the 10BaseT port to use UTP cable, set autoselect mode for
* the ethernet interface (AUI vs. TP), set the two serial ports
* to PC mode.
*/
bus_space_write_4(sc->sc_iot, sc->sc_ioh, IOC_WRITE,
IOC_WRITE_ENET_AUTO | IOC_WRITE_ENET_UTP |
IOC_WRITE_PC_UART2 | IOC_WRITE_PC_UART1);
/* XXX: the firmware should have taken care of this already */
#if 0
if (mach_subtype == MACH_SGI_IP22_GUINNESS) {
bus_space_write_4(sc->sc_iot, sc->sc_ioh, IOC_GCSEL, 0xff);
bus_space_write_4(sc->sc_iot, sc->sc_ioh, IOC_GCREG, 0xff);
}
#endif
#if defined(BLINK)
ioc_blink(sc);
#endif
#if defined(notyet)
/*
* pckbc, zstty, and lpt should attach under the IOC. This begs the
* question of how we sort things out with ip20, which has no IOC.
* For now, we pretend that everything attaches at HPC and ignore
* the IOC.
*/
config_search(self, NULL,
CFARGS(.search = ioc_search));
#endif
}
#if defined(notyet)
static int
ioc_print(void *aux, const char *pnp)
{
struct ioc_attach_args *iaa = aux;
if (pnp != 0)
return QUIET;
if (iaa->iaa_offset != IOCCF_OFFSET_DEFAULT)
aprint_normal(" offset 0x%lx", iaa->iaa_offset);
if (iaa->iaa_intr != IOCCF_INTR_DEFAULT)
aprint_normal(" intr %d", iaa->iaa_intr);
return UNCONF;
}
static int
ioc_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
{
struct ioc_softc *sc = device_private(parent);
struct ioc_attach_args iaa;
int tryagain;
do {
iaa.iaa_offset = cf->cf_loc[IOCCF_OFFSET];
iaa.iaa_intr = cf->cf_loc[IOCCF_INTR];
iaa.iaa_st = normal_memt;
iaa.iaa_sh = sc->sc_ioh; /* XXX */
tryagain = 0;
if (config_probe(parent, cf, &iaa)) {
config_attach(parent, cf, &iaa, ioc_print, CFARGS_NONE);
tryagain = (cf->cf_fstate == FSTATE_STAR);
}
} while (tryagain);
return 0;
}
#endif
#if defined(BLINK)
static void
ioc_blink(void *self)
{
struct ioc_softc *sc = device_private(self);
register int s;
int value;
s = splhigh();
/* This is a bit odd. To strobe the green LED, we have to toggle the
red control bit. */
value = bus_space_read_4(sc->sc_iot, sc->sc_ioh, IOC_RESET) & 0xff;
value ^= IOC_RESET_LED_RED;
bus_space_write_4(sc->sc_iot, sc->sc_ioh, IOC_RESET, value);
splx(s);
/*
* Blink rate is:
* full cycle every second if completely idle (loadav = 0)
* full cycle every 2 seconds if loadav = 1
* full cycle every 3 seconds if loadav = 2
* etc.
*/
s = (((averunnable.ldavg[0] + FSCALE) * hz) >> (FSHIFT + 1));
callout_reset(&ioc_blink_ch, s, ioc_blink, sc);
}
#endif
|