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