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