gio.c revision 1.12 1 /* $NetBSD: gio.c,v 1.12 2003/12/15 05:26:56 lonewolf Exp $ */
2
3 /*
4 * Copyright (c) 2000 Soren S. Jorvang
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed for the
18 * NetBSD Project. See http://www.NetBSD.org/ for
19 * information about NetBSD.
20 * 4. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: gio.c,v 1.12 2003/12/15 05:26:56 lonewolf Exp $");
37
38 #include "opt_ddb.h"
39
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/device.h>
43
44 #include <machine/bus.h>
45
46 #include <sgimips/gio/gioreg.h>
47 #include <sgimips/gio/giovar.h>
48
49 #include "locators.h"
50 #include "newport.h"
51
52 #if (NNEWPORT > 0)
53 #include <sgimips/gio/newportvar.h>
54 #endif
55
56 struct gio_softc {
57 struct device sc_dev;
58 };
59
60 static int gio_match(struct device *, struct cfdata *, void *);
61 static void gio_attach(struct device *, struct device *, void *);
62 static int gio_print(void *, const char *);
63 static int gio_search(struct device *, struct cfdata *, void *);
64 static int gio_submatch(struct device *, struct cfdata *, void *);
65
66 CFATTACH_DECL(gio, sizeof(struct gio_softc),
67 gio_match, gio_attach, NULL, NULL);
68
69 static uint32_t gio_slot_addr[] = {
70 0x1f400000,
71 0x1f600000,
72 0x1f000000,
73 0
74 };
75
76 static int
77 gio_match(struct device *parent, struct cfdata *match, void *aux)
78 {
79 struct giobus_attach_args *gba = aux;
80
81 if (strcmp(gba->gba_busname, match->cf_name) != 0)
82 return 0;
83
84 return 1;
85 }
86
87 static void
88 gio_attach(struct device *parent, struct device *self, void *aux)
89 {
90 struct gio_attach_args ga;
91 int i;
92
93 printf("\n");
94
95 for (i=0; gio_slot_addr[i] != 0; i++) {
96 ga.ga_slot = i;
97 ga.ga_addr = gio_slot_addr[i];
98 ga.ga_iot = 0;
99 ga.ga_ioh = MIPS_PHYS_TO_KSEG1(gio_slot_addr[i]);
100
101 #if 0
102 /* XXX */
103 if (bus_space_peek_4(ga.ga_iot, ga.ga_ioh, 0, &ga.ga_product))
104 continue;
105 #else
106
107 if (badaddr((void *)ga.ga_ioh,sizeof(uint32_t)))
108 continue;
109
110 ga.ga_product = bus_space_read_4(ga.ga_iot, ga.ga_ioh, 0);
111 #endif
112
113 config_found_sm(self, &ga, gio_print, gio_submatch);
114 }
115
116 config_search(gio_search, self, &ga);
117 }
118
119 static int
120 gio_print(void *aux, const char *pnp)
121 {
122 struct gio_attach_args *ga = aux;
123
124 if (pnp != NULL) {
125 int product, revision;
126
127 product = GIO_PRODUCT_PRODUCTID(ga->ga_product);
128
129 if (GIO_PRODUCT_32BIT_ID(ga->ga_product))
130 revision = GIO_PRODUCT_REVISION(ga->ga_product);
131 else
132 revision = 0;
133
134 aprint_normal("unknown product 0x%02x revision 0x%02x at %s",
135 product, revision, pnp);
136 }
137
138 if (ga->ga_slot != GIOCF_SLOT_DEFAULT)
139 aprint_normal(" slot %d", ga->ga_slot);
140 if (ga->ga_addr != (uint32_t) GIOCF_ADDR_DEFAULT)
141 aprint_normal(" addr 0x%x", ga->ga_addr);
142
143 return UNCONF;
144 }
145
146 static int
147 gio_search(struct device *parent, struct cfdata *cf, void *aux)
148 {
149 struct gio_attach_args *ga = aux;
150
151 do {
152 /* Handled by direct configuration, so skip here */
153 if (cf->cf_loc[GIOCF_ADDR] == GIOCF_ADDR_DEFAULT)
154 return 0;
155
156 ga->ga_slot = cf->cf_loc[GIOCF_SLOT];
157 ga->ga_addr = cf->cf_loc[GIOCF_ADDR];
158 ga->ga_iot = 0;
159 ga->ga_ioh = MIPS_PHYS_TO_KSEG1(ga->ga_addr);
160
161 if (config_match(parent, cf, ga) > 0)
162 config_attach(parent, cf, ga, gio_print);
163 } while (cf->cf_fstate == FSTATE_STAR);
164
165 return 0;
166 }
167
168 static int
169 gio_submatch(struct device *parent, struct cfdata *cf, void *aux)
170 {
171 struct gio_attach_args *ga = aux;
172
173 if (cf->cf_loc[GIOCF_SLOT] != GIOCF_SLOT_DEFAULT &&
174 cf->cf_loc[GIOCF_SLOT] != ga->ga_slot)
175 return 0;
176
177 if (cf->cf_loc[GIOCF_ADDR] != GIOCF_ADDR_DEFAULT &&
178 cf->cf_loc[GIOCF_ADDR] != ga->ga_addr)
179 return 0;
180
181 return config_match(parent, cf, aux);
182 }
183
184 int
185 gio_cnattach()
186 {
187 struct gio_attach_args ga;
188 int i;
189
190 /* XXX Duplicate code XXX */
191 for (i=0; gio_slot_addr[i] != 0; i++) {
192 ga.ga_slot = i;
193 ga.ga_addr = gio_slot_addr[i];
194 ga.ga_iot = 0;
195 ga.ga_ioh = MIPS_PHYS_TO_KSEG1(gio_slot_addr[i]);
196
197 #if 0
198 /* XXX */
199 if (bus_space_peek_4(ga.ga_iot, ga.ga_ioh, 0, &ga.ga_product))
200 continue;
201 #else
202
203 if (badaddr((void *)ga.ga_ioh,sizeof(uint32_t)))
204 continue;
205
206 ga.ga_product = bus_space_read_4(ga.ga_iot, ga.ga_ioh, 0);
207 #endif
208
209 /* XXX This probably attaches console to the wrong newport on
210 * dualhead Indys, as GFX slot is tried last not first */
211 #if (NNEWPORT > 0)
212 if (newport_cnattach(&ga) == 0)
213 return 0;
214 #endif
215 }
216
217 return ENXIO;
218 }
219