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