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