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