Home | History | Annotate | Line # | Download | only in gio
gio.c revision 1.21.18.1
      1  1.21.18.1      tron /*	$NetBSD: gio.c,v 1.21.18.1 2006/09/10 16:59:42 tron 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.21.18.1      tron __KERNEL_RCSID(0, "$NetBSD: gio.c,v 1.21.18.1 2006/09/10 16:59:42 tron 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.21.18.1      tron #define _SGIMIPS_BUS_DMA_PRIVATE
     45       1.12  lonewolf #include <machine/bus.h>
     46  1.21.18.1      tron #include <machine/machtype.h>
     47       1.12  lonewolf 
     48        1.1     soren #include <sgimips/gio/gioreg.h>
     49        1.1     soren #include <sgimips/gio/giovar.h>
     50       1.14    sekiya #include <sgimips/gio/giodevs_data.h>
     51        1.1     soren 
     52        1.1     soren #include "locators.h"
     53       1.12  lonewolf #include "newport.h"
     54       1.16    sekiya #include "grtwo.h"
     55  1.21.18.1      tron #include "imc.h"
     56  1.21.18.1      tron #include "pic.h"
     57       1.12  lonewolf 
     58       1.12  lonewolf #if (NNEWPORT > 0)
     59       1.12  lonewolf #include <sgimips/gio/newportvar.h>
     60       1.12  lonewolf #endif
     61        1.1     soren 
     62       1.16    sekiya #if (NGRTWO > 0)
     63       1.16    sekiya #include <sgimips/gio/grtwovar.h>
     64       1.16    sekiya #endif
     65       1.16    sekiya 
     66  1.21.18.1      tron #if (NIMC > 0)
     67  1.21.18.1      tron extern int imc_gio64_arb_config(int, uint32_t);
     68  1.21.18.1      tron #endif
     69  1.21.18.1      tron 
     70  1.21.18.1      tron #if (NPIC > 0)
     71  1.21.18.1      tron extern int pic_gio32_arb_config(int, uint32_t);
     72  1.21.18.1      tron #endif
     73  1.21.18.1      tron 
     74  1.21.18.1      tron 
     75        1.1     soren struct gio_softc {
     76        1.1     soren 	struct	device sc_dev;
     77        1.1     soren };
     78        1.1     soren 
     79        1.1     soren static int	gio_match(struct device *, struct cfdata *, void *);
     80        1.1     soren static void	gio_attach(struct device *, struct device *, void *);
     81        1.1     soren static int	gio_print(void *, const char *);
     82       1.19  drochner static int	gio_search(struct device *, struct cfdata *,
     83       1.20  drochner 			   const int *, void *);
     84       1.18  drochner static int	gio_submatch(struct device *, struct cfdata *,
     85       1.20  drochner 			     const int *, void *);
     86        1.1     soren 
     87        1.6   thorpej CFATTACH_DECL(gio, sizeof(struct gio_softc),
     88        1.7   thorpej     gio_match, gio_attach, NULL, NULL);
     89        1.1     soren 
     90       1.12  lonewolf static uint32_t gio_slot_addr[] = {
     91       1.12  lonewolf 	0x1f400000,
     92       1.12  lonewolf 	0x1f600000,
     93       1.12  lonewolf 	0x1f000000,
     94       1.12  lonewolf 	0
     95       1.12  lonewolf };
     96       1.12  lonewolf 
     97        1.1     soren static int
     98       1.12  lonewolf gio_match(struct device *parent, struct cfdata *match, void *aux)
     99        1.1     soren {
    100        1.1     soren 
    101        1.2    simonb 	return 1;
    102        1.1     soren }
    103        1.1     soren 
    104        1.1     soren static void
    105       1.12  lonewolf gio_attach(struct device *parent, struct device *self, void *aux)
    106        1.1     soren {
    107        1.1     soren 	struct gio_attach_args ga;
    108       1.12  lonewolf 	int i;
    109        1.1     soren 
    110        1.1     soren 	printf("\n");
    111        1.1     soren 
    112       1.12  lonewolf 	for (i=0; gio_slot_addr[i] != 0; i++) {
    113  1.21.18.1      tron 		ga.ga_slot = (gio_slot_addr[i] == 0x1f000000) ? GIO_SLOT_GFX :
    114  1.21.18.1      tron 		             (gio_slot_addr[i] == 0x1f400000) ? GIO_SLOT_EXP0 :
    115  1.21.18.1      tron 								GIO_SLOT_EXP1;
    116       1.12  lonewolf 		ga.ga_addr = gio_slot_addr[i];
    117       1.12  lonewolf 		ga.ga_iot = 0;
    118       1.12  lonewolf 		ga.ga_ioh = MIPS_PHYS_TO_KSEG1(gio_slot_addr[i]);
    119  1.21.18.1      tron 		ga.ga_dmat = &sgimips_default_bus_dma_tag;
    120       1.12  lonewolf 
    121       1.12  lonewolf #if 0
    122       1.12  lonewolf 		/* XXX */
    123       1.12  lonewolf 		if (bus_space_peek_4(ga.ga_iot, ga.ga_ioh, 0, &ga.ga_product))
    124       1.12  lonewolf 			continue;
    125       1.12  lonewolf #else
    126       1.12  lonewolf 		if (badaddr((void *)ga.ga_ioh,sizeof(uint32_t)))
    127       1.12  lonewolf 			continue;
    128       1.12  lonewolf 
    129       1.12  lonewolf 		ga.ga_product = bus_space_read_4(ga.ga_iot, ga.ga_ioh, 0);
    130       1.12  lonewolf #endif
    131       1.12  lonewolf 
    132       1.18  drochner 		config_found_sm_loc(self, "gio", NULL, &ga, gio_print,
    133       1.18  drochner 				    gio_submatch);
    134       1.12  lonewolf 	}
    135       1.12  lonewolf 
    136       1.19  drochner 	config_search_ia(gio_search, self, "gio", &ga);
    137        1.1     soren }
    138        1.1     soren 
    139        1.1     soren static int
    140       1.12  lonewolf gio_print(void *aux, const char *pnp)
    141        1.1     soren {
    142        1.1     soren 	struct gio_attach_args *ga = aux;
    143       1.13    sekiya 	int i = 0;
    144        1.1     soren 
    145       1.12  lonewolf 	if (pnp != NULL) {
    146       1.12  lonewolf 	  	int product, revision;
    147       1.12  lonewolf 
    148       1.12  lonewolf 		product = GIO_PRODUCT_PRODUCTID(ga->ga_product);
    149       1.12  lonewolf 
    150       1.12  lonewolf 		if (GIO_PRODUCT_32BIT_ID(ga->ga_product))
    151       1.12  lonewolf 			revision = GIO_PRODUCT_REVISION(ga->ga_product);
    152       1.12  lonewolf 		else
    153       1.12  lonewolf 			revision = 0;
    154       1.12  lonewolf 
    155       1.13    sekiya 		while (gio_knowndevs[i].productid != 0) {
    156       1.13    sekiya 			if (gio_knowndevs[i].productid == product) {
    157       1.13    sekiya 				aprint_normal("%s", gio_knowndevs[i].product);
    158       1.13    sekiya 				break;
    159       1.13    sekiya 			}
    160       1.13    sekiya 			i++;
    161       1.13    sekiya 		}
    162       1.13    sekiya 
    163       1.13    sekiya 		if (gio_knowndevs[i].productid == 0)
    164       1.13    sekiya 			aprint_normal("unknown GIO card");
    165       1.13    sekiya 
    166       1.13    sekiya 		aprint_normal(" (product 0x%02x revision 0x%02x) at %s",
    167       1.12  lonewolf 		    product, revision, pnp);
    168       1.12  lonewolf 	}
    169        1.1     soren 
    170        1.1     soren 	if (ga->ga_slot != GIOCF_SLOT_DEFAULT)
    171        1.9   thorpej 		aprint_normal(" slot %d", ga->ga_slot);
    172        1.8   thorpej 	if (ga->ga_addr != (uint32_t) GIOCF_ADDR_DEFAULT)
    173        1.9   thorpej 		aprint_normal(" addr 0x%x", ga->ga_addr);
    174        1.1     soren 
    175        1.1     soren 	return UNCONF;
    176        1.1     soren }
    177        1.1     soren 
    178        1.1     soren static int
    179       1.19  drochner gio_search(struct device *parent, struct cfdata *cf,
    180       1.20  drochner 	   const int *ldesc, void *aux)
    181        1.2    simonb {
    182        1.1     soren 	struct gio_attach_args *ga = aux;
    183        1.1     soren 
    184        1.1     soren 	do {
    185       1.12  lonewolf 		/* Handled by direct configuration, so skip here */
    186       1.12  lonewolf 		if (cf->cf_loc[GIOCF_ADDR] == GIOCF_ADDR_DEFAULT)
    187       1.12  lonewolf 			return 0;
    188       1.12  lonewolf 
    189        1.1     soren 		ga->ga_slot = cf->cf_loc[GIOCF_SLOT];
    190        1.1     soren 		ga->ga_addr = cf->cf_loc[GIOCF_ADDR];
    191        1.1     soren 		ga->ga_iot = 0;
    192        1.1     soren 		ga->ga_ioh = MIPS_PHYS_TO_KSEG1(ga->ga_addr);
    193       1.12  lonewolf 
    194        1.4   thorpej 		if (config_match(parent, cf, ga) > 0)
    195        1.1     soren 			config_attach(parent, cf, ga, gio_print);
    196        1.1     soren 	} while (cf->cf_fstate == FSTATE_STAR);
    197        1.1     soren 
    198        1.1     soren 	return 0;
    199       1.12  lonewolf }
    200       1.12  lonewolf 
    201       1.12  lonewolf static int
    202       1.18  drochner gio_submatch(struct device *parent, struct cfdata *cf,
    203       1.20  drochner 	     const int *ldesc, void *aux)
    204       1.12  lonewolf {
    205       1.12  lonewolf 	struct gio_attach_args *ga = aux;
    206       1.12  lonewolf 
    207       1.12  lonewolf 	if (cf->cf_loc[GIOCF_SLOT] != GIOCF_SLOT_DEFAULT &&
    208       1.12  lonewolf 	    cf->cf_loc[GIOCF_SLOT] != ga->ga_slot)
    209       1.12  lonewolf 		return 0;
    210       1.12  lonewolf 
    211       1.12  lonewolf 	if (cf->cf_loc[GIOCF_ADDR] != GIOCF_ADDR_DEFAULT &&
    212       1.12  lonewolf 	    cf->cf_loc[GIOCF_ADDR] != ga->ga_addr)
    213       1.12  lonewolf 		return 0;
    214       1.12  lonewolf 
    215       1.12  lonewolf 	return config_match(parent, cf, aux);
    216       1.12  lonewolf }
    217       1.12  lonewolf 
    218       1.12  lonewolf int
    219       1.12  lonewolf gio_cnattach()
    220       1.12  lonewolf {
    221       1.12  lonewolf 	struct gio_attach_args ga;
    222       1.12  lonewolf 	int i;
    223       1.12  lonewolf 
    224       1.12  lonewolf 	/* XXX Duplicate code XXX */
    225       1.12  lonewolf 	for (i=0; gio_slot_addr[i] != 0; i++) {
    226       1.12  lonewolf 		ga.ga_slot = i;
    227       1.12  lonewolf 		ga.ga_addr = gio_slot_addr[i];
    228       1.12  lonewolf 		ga.ga_iot = 0;
    229       1.12  lonewolf 		ga.ga_ioh = MIPS_PHYS_TO_KSEG1(gio_slot_addr[i]);
    230       1.12  lonewolf 
    231       1.12  lonewolf #if 0
    232       1.12  lonewolf 		/* XXX */
    233       1.12  lonewolf 		if (bus_space_peek_4(ga.ga_iot, ga.ga_ioh, 0, &ga.ga_product))
    234       1.12  lonewolf 			continue;
    235       1.12  lonewolf #else
    236       1.12  lonewolf 
    237       1.12  lonewolf 		if (badaddr((void *)ga.ga_ioh,sizeof(uint32_t)))
    238       1.12  lonewolf 			continue;
    239       1.12  lonewolf 
    240       1.12  lonewolf 		ga.ga_product = bus_space_read_4(ga.ga_iot, ga.ga_ioh, 0);
    241       1.12  lonewolf #endif
    242       1.12  lonewolf 
    243       1.15    sekiya #if (NGRTWO > 0)
    244       1.15    sekiya 		if (grtwo_cnattach(&ga) == 0)
    245       1.15    sekiya 			return 0;
    246       1.15    sekiya #endif
    247       1.15    sekiya 
    248       1.12  lonewolf 		/* XXX This probably attaches console to the wrong newport on
    249       1.12  lonewolf 		 * dualhead Indys, as GFX slot is tried last not first */
    250       1.12  lonewolf #if (NNEWPORT > 0)
    251       1.12  lonewolf 		if (newport_cnattach(&ga) == 0)
    252       1.12  lonewolf 			return 0;
    253       1.12  lonewolf #endif
    254       1.15    sekiya 
    255       1.12  lonewolf 	}
    256       1.12  lonewolf 
    257       1.12  lonewolf 	return ENXIO;
    258        1.1     soren }
    259  1.21.18.1      tron 
    260  1.21.18.1      tron /*
    261  1.21.18.1      tron  * Devices living in the expansion slots must enable or disable some
    262  1.21.18.1      tron  * GIO arbiter settings. This is accomplished via imc(4) or pic(4)
    263  1.21.18.1      tron  * registers, depending on the machine in question.
    264  1.21.18.1      tron  */
    265  1.21.18.1      tron int
    266  1.21.18.1      tron gio_arb_config(int slot, uint32_t flags)
    267  1.21.18.1      tron {
    268  1.21.18.1      tron 
    269  1.21.18.1      tron 	if (flags == 0)
    270  1.21.18.1      tron 		return (EINVAL);
    271  1.21.18.1      tron 
    272  1.21.18.1      tron 	if (flags & ~(GIO_ARB_RT | GIO_ARB_LB | GIO_ARB_MST | GIO_ARB_SLV |
    273  1.21.18.1      tron 	    GIO_ARB_PIPE | GIO_ARB_NOPIPE))
    274  1.21.18.1      tron 		return (EINVAL);
    275  1.21.18.1      tron 
    276  1.21.18.1      tron 	if (((flags & GIO_ARB_RT)   && (flags & GIO_ARB_LB))  ||
    277  1.21.18.1      tron 	    ((flags & GIO_ARB_MST)  && (flags & GIO_ARB_SLV)) ||
    278  1.21.18.1      tron 	    ((flags & GIO_ARB_PIPE) && (flags & GIO_ARB_NOPIPE)))
    279  1.21.18.1      tron 		return (EINVAL);
    280  1.21.18.1      tron 
    281  1.21.18.1      tron #if (NPIC > 0)
    282  1.21.18.1      tron 	if (mach_type == MACH_SGI_IP12)
    283  1.21.18.1      tron 		return (pic_gio32_arb_config(slot, flags));
    284  1.21.18.1      tron #endif
    285  1.21.18.1      tron 
    286  1.21.18.1      tron #if (NIMC > 0)
    287  1.21.18.1      tron 	if (mach_type == MACH_SGI_IP20 || mach_type == MACH_SGI_IP22)
    288  1.21.18.1      tron 		return (imc_gio64_arb_config(slot, flags));
    289  1.21.18.1      tron #endif
    290  1.21.18.1      tron 
    291  1.21.18.1      tron 	return (EINVAL);
    292  1.21.18.1      tron }
    293  1.21.18.1      tron 
    294  1.21.18.1      tron /*
    295  1.21.18.1      tron  * Establish an interrupt handler for the specified slot.
    296  1.21.18.1      tron  */
    297  1.21.18.1      tron void *
    298  1.21.18.1      tron gio_intr_establish(int slot, int level, int (*func)(void *), void *arg)
    299  1.21.18.1      tron {
    300  1.21.18.1      tron 	int intr;
    301  1.21.18.1      tron 
    302  1.21.18.1      tron 	switch (mach_type) {
    303  1.21.18.1      tron 	case MACH_SGI_IP12:
    304  1.21.18.1      tron 	case MACH_SGI_IP20:
    305  1.21.18.1      tron 		if (slot == GIO_SLOT_GFX)
    306  1.21.18.1      tron 			panic("gio_intr_establish: slot %d", slot);
    307  1.21.18.1      tron 		intr = (slot == GIO_SLOT_EXP0) ? 0 : 6;
    308  1.21.18.1      tron 		break;
    309  1.21.18.1      tron 
    310  1.21.18.1      tron 	case MACH_SGI_IP22:
    311  1.21.18.1      tron 		if (mach_subtype == MACH_SGI_IP22_FULLHOUSE) {
    312  1.21.18.1      tron 			if (slot == GIO_SLOT_EXP1)
    313  1.21.18.1      tron 				panic("gio_intr_establish: slot %d", slot);
    314  1.21.18.1      tron 			intr = (slot == GIO_SLOT_EXP0) ? 0 : 6;
    315  1.21.18.1      tron 		} else {
    316  1.21.18.1      tron 			if (slot == GIO_SLOT_GFX)
    317  1.21.18.1      tron 				panic("gio_intr_establish: slot %d", slot);
    318  1.21.18.1      tron 			intr = (slot == GIO_SLOT_EXP0) ? 22 : 23;
    319  1.21.18.1      tron 		}
    320  1.21.18.1      tron 		break;
    321  1.21.18.1      tron 
    322  1.21.18.1      tron 	default:
    323  1.21.18.1      tron 		panic("gio_intr_establish: mach_type");
    324  1.21.18.1      tron 	}
    325  1.21.18.1      tron 
    326  1.21.18.1      tron 	return (cpu_intr_establish(intr, level, func, arg));
    327  1.21.18.1      tron }
    328  1.21.18.1      tron 
    329  1.21.18.1      tron const char *
    330  1.21.18.1      tron gio_product_string(int prid)
    331  1.21.18.1      tron {
    332  1.21.18.1      tron 	int i;
    333  1.21.18.1      tron 
    334  1.21.18.1      tron 	for (i = 0; gio_knowndevs[i].product != NULL; i++)
    335  1.21.18.1      tron 		if (gio_knowndevs[i].productid == prid)
    336  1.21.18.1      tron 			return (gio_knowndevs[i].product);
    337  1.21.18.1      tron 
    338  1.21.18.1      tron 	return (NULL);
    339  1.21.18.1      tron }
    340