1 /* $NetBSD: gio.c,v 1.30 2009/02/10 06:11:49 rumble Exp $ */
4 * Copyright (c) 2000 Soren S. Jorvang
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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.
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: gio.c,v 1.30 2009/02/10 06:11:49 rumble Exp $");
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/device.h>
44 #define _SGIMIPS_BUS_DMA_PRIVATE
45 #include <machine/bus.h>
46 #include <machine/machtype.h>
47 #include <machine/sysconf.h>
49 #include <sgimips/gio/gioreg.h>
50 #include <sgimips/gio/giovar.h>
51 #include <sgimips/gio/giodevs_data.h>
61 #include <sgimips/gio/newportvar.h>
65 #include <sgimips/gio/grtwovar.h>
69 #include <sgimips/gio/lightvar.h>
73 extern int imc_gio64_arb_config(int, uint32_t);
77 extern int pic_gio32_arb_config(int, uint32_t);
85 static int gio_match(struct device
*, struct cfdata
*, void *);
86 static void gio_attach(struct device
*, struct device
*, void *);
87 static int gio_print(void *, const char *);
88 static int gio_search(struct device
*, struct cfdata
*,
90 static int gio_submatch(struct device
*, struct cfdata
*,
93 CFATTACH_DECL(gio
, sizeof(struct gio_softc
),
94 gio_match
, gio_attach
, NULL
, NULL
);
100 uint32_t mach_subtype
;
104 * Expansion Slot Base Addresses
106 * IP12, IP20 and IP24 have two GIO connectors: GIO_SLOT_EXP0 and
109 * On IP24 these slots exist on the graphics board or the IOPLUS
110 * "mezzanine" on Indy and Challenge S, respectively. The IOPLUS or
111 * graphics board connects to the mainboard via a single GIO64 connector.
113 * IP22 has either three or four physical connectors, but only two
114 * electrically distinct slots: GIO_SLOT_GFX and GIO_SLOT_EXP0.
116 * It should also be noted that DMA is (mostly) not supported in Challenge
117 * S's GIO_SLOT_EXP1. See gio(4) for the story.
119 static const struct gio_probe slot_bases
[] = {
120 { GIO_SLOT_GFX
, 0x1f000000, MACH_SGI_IP22
, MACH_SGI_IP22_FULLHOUSE
},
122 { GIO_SLOT_EXP0
, 0x1f400000, MACH_SGI_IP12
, -1 },
123 { GIO_SLOT_EXP0
, 0x1f400000, MACH_SGI_IP20
, -1 },
124 { GIO_SLOT_EXP0
, 0x1f400000, MACH_SGI_IP22
, -1 },
126 { GIO_SLOT_EXP1
, 0x1f600000, MACH_SGI_IP12
, -1 },
127 { GIO_SLOT_EXP1
, 0x1f600000, MACH_SGI_IP20
, -1 },
128 { GIO_SLOT_EXP1
, 0x1f600000, MACH_SGI_IP22
, MACH_SGI_IP22_GUINNESS
},
134 * Graphic Board Base Addresses
136 * Graphics boards are not treated like expansion slot cards. Their base
137 * addresses do not necessarily correspond to GIO slot addresses and they
138 * do not contain product identification words.
140 static const struct gio_probe gfx_bases
[] = {
141 /* grtwo, and newport on IP22 */
142 { -1, 0x1f000000, MACH_SGI_IP12
, -1 },
143 { -1, 0x1f000000, MACH_SGI_IP20
, -1 },
144 { -1, 0x1f000000, MACH_SGI_IP22
, -1 },
147 { -1, 0x1f3f0000, MACH_SGI_IP12
, -1 },
148 { -1, 0x1f3f0000, MACH_SGI_IP20
, -1 },
150 /* light (dual headed) */
151 { -1, 0x1f3f8000, MACH_SGI_IP12
, -1 },
152 { -1, 0x1f3f8000, MACH_SGI_IP20
, -1 },
154 /* grtwo, and newport on IP22 */
155 { -1, 0x1f400000, MACH_SGI_IP12
, -1 },
156 { -1, 0x1f400000, MACH_SGI_IP20
, -1 },
157 { -1, 0x1f400000, MACH_SGI_IP22
, -1 },
160 { -1, 0x1f600000, MACH_SGI_IP12
, -1 },
161 { -1, 0x1f600000, MACH_SGI_IP20
, -1 },
162 { -1, 0x1f600000, MACH_SGI_IP22
, -1 },
165 { -1, 0x1f800000, MACH_SGI_IP22
, MACH_SGI_IP22_FULLHOUSE
},
168 { -1, 0x1fc00000, MACH_SGI_IP22
, MACH_SGI_IP22_FULLHOUSE
},
173 /* maximum number of graphics boards possible (arbitrarily large estimate) */
177 gio_match(struct device
*parent
, struct cfdata
*match
, void *aux
)
179 if (mach_type
== MACH_SGI_IP12
|| mach_type
== MACH_SGI_IP20
||
180 mach_type
== MACH_SGI_IP22
)
187 gio_attach(struct device
*parent
, struct device
*self
, void *aux
)
189 struct gio_attach_args ga
;
190 uint32_t gfx
[MAXGFX
];
196 memset(gfx
, 0, sizeof(gfx
));
199 * Attach graphics devices first. They do not contain a Product
200 * Identification Word and have no slot number.
202 * Record addresses to which graphics devices attach so that
203 * we do not confuse them with expansion slots, should the
204 * addresses coincide.
206 for (i
= 0; gfx_bases
[i
].base
!= 0; i
++) {
207 /* skip slots that don't apply to us */
208 if (gfx_bases
[i
].mach_type
!= mach_type
)
211 if (gfx_bases
[i
].mach_subtype
!= -1 &&
212 gfx_bases
[i
].mach_subtype
!= mach_subtype
)
216 ga
.ga_addr
= gfx_bases
[i
].base
;
217 ga
.ga_iot
= SGIMIPS_BUS_SPACE_NORMAL
;
218 ga
.ga_ioh
= MIPS_PHYS_TO_KSEG1(ga
.ga_addr
);
219 ga
.ga_dmat
= &sgimips_default_bus_dma_tag
;
222 if (platform
.badaddr((void *)ga
.ga_ioh
, sizeof(uint32_t)))
225 if (config_found_sm_loc(self
, "gio", NULL
, &ga
, gio_print
,
228 panic("gio_attach: MAXGFX");
229 gfx
[ngfx
++] = gfx_bases
[i
].base
;
234 * Now attach any GIO expansion cards.
236 * Be sure to skip any addresses to which a graphics device has
237 * already been attached.
239 for (i
= 0; slot_bases
[i
].base
!= 0; i
++) {
242 /* skip slots that don't apply to us */
243 if (slot_bases
[i
].mach_type
!= mach_type
)
246 if (slot_bases
[i
].mach_subtype
!= -1 &&
247 slot_bases
[i
].mach_subtype
!= mach_subtype
)
250 for (j
= 0; j
< ngfx
; j
++) {
251 if (slot_bases
[i
].base
== gfx
[j
]) {
259 ga
.ga_slot
= slot_bases
[i
].slot
;
260 ga
.ga_addr
= slot_bases
[i
].base
;
261 ga
.ga_iot
= SGIMIPS_BUS_SPACE_NORMAL
;
262 ga
.ga_ioh
= MIPS_PHYS_TO_KSEG1(ga
.ga_addr
);
263 ga
.ga_dmat
= &sgimips_default_bus_dma_tag
;
265 if (platform
.badaddr((void *)ga
.ga_ioh
, sizeof(uint32_t)))
268 ga
.ga_product
= bus_space_read_4(ga
.ga_iot
, ga
.ga_ioh
, 0);
270 config_found_sm_loc(self
, "gio", NULL
, &ga
, gio_print
,
274 config_search_ia(gio_search
, self
, "gio", &ga
);
278 gio_print(void *aux
, const char *pnp
)
280 struct gio_attach_args
*ga
= aux
;
284 if (ga
->ga_product
== -1)
288 int product
, revision
;
290 product
= GIO_PRODUCT_PRODUCTID(ga
->ga_product
);
292 if (GIO_PRODUCT_32BIT_ID(ga
->ga_product
))
293 revision
= GIO_PRODUCT_REVISION(ga
->ga_product
);
297 while (gio_knowndevs
[i
].productid
!= 0) {
298 if (gio_knowndevs
[i
].productid
== product
) {
299 aprint_normal("%s", gio_knowndevs
[i
].product
);
305 if (gio_knowndevs
[i
].productid
== 0)
306 aprint_normal("unknown GIO card");
308 aprint_normal(" (product 0x%02x revision 0x%02x) at %s",
309 product
, revision
, pnp
);
312 if (ga
->ga_slot
!= GIOCF_SLOT_DEFAULT
)
313 aprint_normal(" slot %d", ga
->ga_slot
);
314 if (ga
->ga_addr
!= (uint32_t) GIOCF_ADDR_DEFAULT
)
315 aprint_normal(" addr 0x%x", ga
->ga_addr
);
321 gio_search(struct device
*parent
, struct cfdata
*cf
,
322 const int *ldesc
, void *aux
)
324 struct gio_attach_args
*ga
= aux
;
327 /* Handled by direct configuration, so skip here */
328 if (cf
->cf_loc
[GIOCF_ADDR
] == GIOCF_ADDR_DEFAULT
)
331 ga
->ga_slot
= cf
->cf_loc
[GIOCF_SLOT
];
332 ga
->ga_addr
= cf
->cf_loc
[GIOCF_ADDR
];
334 ga
->ga_ioh
= MIPS_PHYS_TO_KSEG1(ga
->ga_addr
);
336 if (config_match(parent
, cf
, ga
) > 0)
337 config_attach(parent
, cf
, ga
, gio_print
);
338 } while (cf
->cf_fstate
== FSTATE_STAR
);
344 gio_submatch(struct device
*parent
, struct cfdata
*cf
,
345 const int *ldesc
, void *aux
)
347 struct gio_attach_args
*ga
= aux
;
349 if (cf
->cf_loc
[GIOCF_SLOT
] != GIOCF_SLOT_DEFAULT
&&
350 cf
->cf_loc
[GIOCF_SLOT
] != ga
->ga_slot
)
353 if (cf
->cf_loc
[GIOCF_ADDR
] != GIOCF_ADDR_DEFAULT
&&
354 cf
->cf_loc
[GIOCF_ADDR
] != ga
->ga_addr
)
357 return config_match(parent
, cf
, aux
);
363 struct gio_attach_args ga
;
366 for (i
= 0; gfx_bases
[i
].base
!= 0; i
++) {
367 /* skip bases that don't apply to us */
368 if (gfx_bases
[i
].mach_type
!= mach_type
)
371 if (gfx_bases
[i
].mach_subtype
!= -1 &&
372 gfx_bases
[i
].mach_subtype
!= mach_subtype
)
376 ga
.ga_addr
= gfx_bases
[i
].base
;
377 ga
.ga_iot
= SGIMIPS_BUS_SPACE_NORMAL
;
378 ga
.ga_ioh
= MIPS_PHYS_TO_KSEG1(ga
.ga_addr
);
379 ga
.ga_dmat
= &sgimips_default_bus_dma_tag
;
382 if (platform
.badaddr((void *)ga
.ga_ioh
,sizeof(uint32_t)))
386 if (grtwo_cnattach(&ga
) == 0)
391 if (light_cnattach(&ga
) == 0)
396 if (newport_cnattach(&ga
) == 0)
406 * Devices living in the expansion slots must enable or disable some
407 * GIO arbiter settings. This is accomplished via imc(4) or pic(4)
408 * registers, depending on the machine in question.
411 gio_arb_config(int slot
, uint32_t flags
)
417 if (flags
& ~(GIO_ARB_RT
| GIO_ARB_LB
| GIO_ARB_MST
| GIO_ARB_SLV
|
418 GIO_ARB_PIPE
| GIO_ARB_NOPIPE
| GIO_ARB_32BIT
| GIO_ARB_64BIT
|
419 GIO_ARB_HPC2_32BIT
| GIO_ARB_HPC2_64BIT
))
422 if (((flags
& GIO_ARB_RT
) && (flags
& GIO_ARB_LB
)) ||
423 ((flags
& GIO_ARB_MST
) && (flags
& GIO_ARB_SLV
)) ||
424 ((flags
& GIO_ARB_PIPE
) && (flags
& GIO_ARB_NOPIPE
)) ||
425 ((flags
& GIO_ARB_32BIT
) && (flags
& GIO_ARB_64BIT
)) ||
426 ((flags
& GIO_ARB_HPC2_32BIT
) && (flags
& GIO_ARB_HPC2_64BIT
)))
430 if (mach_type
== MACH_SGI_IP12
)
431 return (pic_gio32_arb_config(slot
, flags
));
435 if (mach_type
== MACH_SGI_IP20
|| mach_type
== MACH_SGI_IP22
)
436 return (imc_gio64_arb_config(slot
, flags
));
443 * Establish an interrupt handler for the specified slot.
445 * Indy and Challenge S have an interrupt per GIO slot. Indigo and Indigo2
446 * share a single interrupt, however.
449 gio_intr_establish(int slot
, int level
, int (*func
)(void *), void *arg
)
456 if (slot
== GIO_SLOT_GFX
)
457 panic("gio_intr_establish: slot %d", slot
);
462 if (mach_subtype
== MACH_SGI_IP22_FULLHOUSE
) {
463 if (slot
== GIO_SLOT_EXP1
)
464 panic("gio_intr_establish: slot %d", slot
);
467 if (slot
== GIO_SLOT_GFX
)
468 panic("gio_intr_establish: slot %d", slot
);
469 intr
= (slot
== GIO_SLOT_EXP0
) ? 22 : 23;
474 panic("gio_intr_establish: mach_type");
477 return (cpu_intr_establish(intr
, level
, func
, arg
));
481 gio_product_string(int prid
)
485 for (i
= 0; gio_knowndevs
[i
].product
!= NULL
; i
++)
486 if (gio_knowndevs
[i
].productid
== prid
)
487 return (gio_knowndevs
[i
].product
);