gio.c revision 1.14 1 1.14 sekiya /* $NetBSD: gio.c,v 1.14 2004/01/11 01:48:46 sekiya 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.14 sekiya __KERNEL_RCSID(0, "$NetBSD: gio.c,v 1.14 2004/01/11 01:48:46 sekiya 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.12 lonewolf
53 1.12 lonewolf #if (NNEWPORT > 0)
54 1.12 lonewolf #include <sgimips/gio/newportvar.h>
55 1.12 lonewolf #endif
56 1.1 soren
57 1.1 soren struct gio_softc {
58 1.1 soren struct device sc_dev;
59 1.1 soren };
60 1.1 soren
61 1.1 soren static int gio_match(struct device *, struct cfdata *, void *);
62 1.1 soren static void gio_attach(struct device *, struct device *, void *);
63 1.1 soren static int gio_print(void *, const char *);
64 1.1 soren static int gio_search(struct device *, struct cfdata *, void *);
65 1.12 lonewolf static int gio_submatch(struct device *, struct cfdata *, void *);
66 1.1 soren
67 1.6 thorpej CFATTACH_DECL(gio, sizeof(struct gio_softc),
68 1.7 thorpej gio_match, gio_attach, NULL, NULL);
69 1.1 soren
70 1.12 lonewolf static uint32_t gio_slot_addr[] = {
71 1.12 lonewolf 0x1f400000,
72 1.12 lonewolf 0x1f600000,
73 1.12 lonewolf 0x1f000000,
74 1.12 lonewolf 0
75 1.12 lonewolf };
76 1.12 lonewolf
77 1.1 soren static int
78 1.12 lonewolf gio_match(struct device *parent, struct cfdata *match, void *aux)
79 1.1 soren {
80 1.1 soren struct giobus_attach_args *gba = aux;
81 1.1 soren
82 1.3 thorpej if (strcmp(gba->gba_busname, match->cf_name) != 0)
83 1.1 soren return 0;
84 1.1 soren
85 1.2 simonb return 1;
86 1.1 soren }
87 1.1 soren
88 1.1 soren static void
89 1.12 lonewolf gio_attach(struct device *parent, struct device *self, void *aux)
90 1.1 soren {
91 1.1 soren struct gio_attach_args ga;
92 1.12 lonewolf int i;
93 1.1 soren
94 1.1 soren printf("\n");
95 1.1 soren
96 1.12 lonewolf for (i=0; gio_slot_addr[i] != 0; i++) {
97 1.12 lonewolf ga.ga_slot = i;
98 1.12 lonewolf ga.ga_addr = gio_slot_addr[i];
99 1.12 lonewolf ga.ga_iot = 0;
100 1.12 lonewolf ga.ga_ioh = MIPS_PHYS_TO_KSEG1(gio_slot_addr[i]);
101 1.12 lonewolf
102 1.12 lonewolf #if 0
103 1.12 lonewolf /* XXX */
104 1.12 lonewolf if (bus_space_peek_4(ga.ga_iot, ga.ga_ioh, 0, &ga.ga_product))
105 1.12 lonewolf continue;
106 1.12 lonewolf #else
107 1.12 lonewolf
108 1.12 lonewolf if (badaddr((void *)ga.ga_ioh,sizeof(uint32_t)))
109 1.12 lonewolf continue;
110 1.12 lonewolf
111 1.12 lonewolf ga.ga_product = bus_space_read_4(ga.ga_iot, ga.ga_ioh, 0);
112 1.12 lonewolf #endif
113 1.12 lonewolf
114 1.12 lonewolf config_found_sm(self, &ga, gio_print, gio_submatch);
115 1.12 lonewolf }
116 1.12 lonewolf
117 1.1 soren config_search(gio_search, self, &ga);
118 1.1 soren }
119 1.1 soren
120 1.1 soren static int
121 1.12 lonewolf gio_print(void *aux, const char *pnp)
122 1.1 soren {
123 1.1 soren struct gio_attach_args *ga = aux;
124 1.13 sekiya int i = 0;
125 1.1 soren
126 1.12 lonewolf if (pnp != NULL) {
127 1.12 lonewolf int product, revision;
128 1.12 lonewolf
129 1.12 lonewolf product = GIO_PRODUCT_PRODUCTID(ga->ga_product);
130 1.12 lonewolf
131 1.12 lonewolf if (GIO_PRODUCT_32BIT_ID(ga->ga_product))
132 1.12 lonewolf revision = GIO_PRODUCT_REVISION(ga->ga_product);
133 1.12 lonewolf else
134 1.12 lonewolf revision = 0;
135 1.12 lonewolf
136 1.13 sekiya while (gio_knowndevs[i].productid != 0) {
137 1.13 sekiya if (gio_knowndevs[i].productid == product) {
138 1.13 sekiya aprint_normal("%s", gio_knowndevs[i].product);
139 1.13 sekiya break;
140 1.13 sekiya }
141 1.13 sekiya i++;
142 1.13 sekiya }
143 1.13 sekiya
144 1.13 sekiya if (gio_knowndevs[i].productid == 0)
145 1.13 sekiya aprint_normal("unknown GIO card");
146 1.13 sekiya
147 1.13 sekiya aprint_normal(" (product 0x%02x revision 0x%02x) at %s",
148 1.12 lonewolf product, revision, pnp);
149 1.12 lonewolf }
150 1.1 soren
151 1.1 soren if (ga->ga_slot != GIOCF_SLOT_DEFAULT)
152 1.9 thorpej aprint_normal(" slot %d", ga->ga_slot);
153 1.8 thorpej if (ga->ga_addr != (uint32_t) GIOCF_ADDR_DEFAULT)
154 1.9 thorpej aprint_normal(" addr 0x%x", ga->ga_addr);
155 1.1 soren
156 1.1 soren return UNCONF;
157 1.1 soren }
158 1.1 soren
159 1.1 soren static int
160 1.12 lonewolf gio_search(struct device *parent, struct cfdata *cf, void *aux)
161 1.2 simonb {
162 1.1 soren struct gio_attach_args *ga = aux;
163 1.1 soren
164 1.1 soren do {
165 1.12 lonewolf /* Handled by direct configuration, so skip here */
166 1.12 lonewolf if (cf->cf_loc[GIOCF_ADDR] == GIOCF_ADDR_DEFAULT)
167 1.12 lonewolf return 0;
168 1.12 lonewolf
169 1.1 soren ga->ga_slot = cf->cf_loc[GIOCF_SLOT];
170 1.1 soren ga->ga_addr = cf->cf_loc[GIOCF_ADDR];
171 1.1 soren ga->ga_iot = 0;
172 1.1 soren ga->ga_ioh = MIPS_PHYS_TO_KSEG1(ga->ga_addr);
173 1.12 lonewolf
174 1.4 thorpej if (config_match(parent, cf, ga) > 0)
175 1.1 soren config_attach(parent, cf, ga, gio_print);
176 1.1 soren } while (cf->cf_fstate == FSTATE_STAR);
177 1.1 soren
178 1.1 soren return 0;
179 1.12 lonewolf }
180 1.12 lonewolf
181 1.12 lonewolf static int
182 1.12 lonewolf gio_submatch(struct device *parent, struct cfdata *cf, void *aux)
183 1.12 lonewolf {
184 1.12 lonewolf struct gio_attach_args *ga = aux;
185 1.12 lonewolf
186 1.12 lonewolf if (cf->cf_loc[GIOCF_SLOT] != GIOCF_SLOT_DEFAULT &&
187 1.12 lonewolf cf->cf_loc[GIOCF_SLOT] != ga->ga_slot)
188 1.12 lonewolf return 0;
189 1.12 lonewolf
190 1.12 lonewolf if (cf->cf_loc[GIOCF_ADDR] != GIOCF_ADDR_DEFAULT &&
191 1.12 lonewolf cf->cf_loc[GIOCF_ADDR] != ga->ga_addr)
192 1.12 lonewolf return 0;
193 1.12 lonewolf
194 1.12 lonewolf return config_match(parent, cf, aux);
195 1.12 lonewolf }
196 1.12 lonewolf
197 1.12 lonewolf int
198 1.12 lonewolf gio_cnattach()
199 1.12 lonewolf {
200 1.12 lonewolf struct gio_attach_args ga;
201 1.12 lonewolf int i;
202 1.12 lonewolf
203 1.12 lonewolf /* XXX Duplicate code XXX */
204 1.12 lonewolf for (i=0; gio_slot_addr[i] != 0; i++) {
205 1.12 lonewolf ga.ga_slot = i;
206 1.12 lonewolf ga.ga_addr = gio_slot_addr[i];
207 1.12 lonewolf ga.ga_iot = 0;
208 1.12 lonewolf ga.ga_ioh = MIPS_PHYS_TO_KSEG1(gio_slot_addr[i]);
209 1.12 lonewolf
210 1.12 lonewolf #if 0
211 1.12 lonewolf /* XXX */
212 1.12 lonewolf if (bus_space_peek_4(ga.ga_iot, ga.ga_ioh, 0, &ga.ga_product))
213 1.12 lonewolf continue;
214 1.12 lonewolf #else
215 1.12 lonewolf
216 1.12 lonewolf if (badaddr((void *)ga.ga_ioh,sizeof(uint32_t)))
217 1.12 lonewolf continue;
218 1.12 lonewolf
219 1.12 lonewolf ga.ga_product = bus_space_read_4(ga.ga_iot, ga.ga_ioh, 0);
220 1.12 lonewolf #endif
221 1.12 lonewolf
222 1.12 lonewolf /* XXX This probably attaches console to the wrong newport on
223 1.12 lonewolf * dualhead Indys, as GFX slot is tried last not first */
224 1.12 lonewolf #if (NNEWPORT > 0)
225 1.12 lonewolf if (newport_cnattach(&ga) == 0)
226 1.12 lonewolf return 0;
227 1.12 lonewolf #endif
228 1.12 lonewolf }
229 1.12 lonewolf
230 1.12 lonewolf return ENXIO;
231 1.1 soren }
232