Home | History | Annotate | Line # | Download | only in dev
plumiobus.c revision 1.2.2.1
      1  1.2.2.1  wrstuden /*	$NetBSD: plumiobus.c,v 1.2.2.1 1999/12/27 18:32:02 wrstuden Exp $ */
      2      1.1       uch 
      3      1.1       uch /*
      4      1.1       uch  * Copyright (c) 1999, by UCHIYAMA Yasushi
      5      1.1       uch  * All rights reserved.
      6      1.1       uch  *
      7      1.1       uch  * Redistribution and use in source and binary forms, with or without
      8      1.1       uch  * modification, are permitted provided that the following conditions
      9      1.1       uch  * are met:
     10      1.1       uch  * 1. Redistributions of source code must retain the above copyright
     11      1.1       uch  *    notice, this list of conditions and the following disclaimer.
     12      1.1       uch  * 2. The name of the developer may NOT be used to endorse or promote products
     13      1.1       uch  *    derived from this software without specific prior written permission.
     14      1.1       uch  *
     15      1.1       uch  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     16      1.1       uch  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     17      1.1       uch  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     18      1.1       uch  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     19      1.1       uch  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     20      1.1       uch  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     21      1.1       uch  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22      1.1       uch  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     23      1.1       uch  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24      1.1       uch  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25      1.1       uch  * SUCH DAMAGE.
     26      1.1       uch  *
     27      1.1       uch  */
     28      1.1       uch 
     29      1.1       uch #include "opt_tx39_debug.h"
     30      1.1       uch 
     31      1.1       uch #include <sys/param.h>
     32      1.1       uch #include <sys/systm.h>
     33      1.1       uch #include <sys/device.h>
     34      1.1       uch #include <sys/malloc.h>
     35      1.1       uch 
     36      1.1       uch #include <machine/bus.h>
     37      1.1       uch #include <machine/intr.h>
     38      1.1       uch 
     39      1.1       uch #include <hpcmips/tx/tx39var.h>
     40      1.1       uch #include <hpcmips/dev/plumvar.h>
     41      1.1       uch #include <hpcmips/dev/plumicuvar.h>
     42      1.1       uch #include <hpcmips/dev/plumpowervar.h>
     43      1.1       uch #include <hpcmips/dev/plumiobusreg.h>
     44      1.1       uch #include <hpcmips/dev/plumiobusvar.h>
     45      1.1       uch 
     46      1.1       uch #include "locators.h"
     47      1.1       uch 
     48      1.1       uch int	plumiobus_match __P((struct device*, struct cfdata*, void*));
     49      1.1       uch void	plumiobus_attach __P((struct device*, struct device*, void*));
     50      1.1       uch int	plumiobus_print __P((void*, const char*));
     51      1.1       uch int	plumiobus_search __P((struct device*, struct cfdata*, void*));
     52      1.1       uch 
     53      1.1       uch struct plumisa_resource {
     54      1.1       uch 	int		pr_irq;
     55      1.1       uch 	bus_space_tag_t	pr_iot;
     56      1.1       uch 	int		pr_enabled;
     57      1.1       uch };
     58      1.1       uch 
     59      1.1       uch struct plumiobus_softc {
     60      1.1       uch 	struct	device		sc_dev;
     61      1.1       uch 	plum_chipset_tag_t	sc_pc;
     62      1.1       uch 	bus_space_tag_t		sc_regt;
     63      1.1       uch 	bus_space_handle_t	sc_regh;
     64      1.1       uch 	bus_space_tag_t		sc_iot;
     65      1.1       uch 	bus_space_handle_t	sc_ioh;
     66      1.1       uch 	struct plumisa_resource	sc_isa[PLUM_IOBUS_IO5CSMAX];
     67      1.1       uch };
     68      1.1       uch 
     69      1.1       uch struct cfattach plumiobus_ca = {
     70      1.1       uch 	sizeof(struct plumiobus_softc), plumiobus_match, plumiobus_attach
     71      1.1       uch };
     72      1.1       uch 
     73      1.1       uch void	plumiobus_dump __P((struct plumiobus_softc*));
     74      1.1       uch bus_space_tag_t __plumiobus_subregion __P((bus_space_tag_t, bus_addr_t, bus_size_t));
     75      1.1       uch 
     76      1.1       uch int
     77      1.1       uch plumiobus_match(parent, cf, aux)
     78      1.1       uch 	struct device *parent;
     79      1.1       uch 	struct cfdata *cf;
     80      1.1       uch 	void *aux;
     81      1.1       uch {
     82      1.1       uch 	return 1;
     83      1.1       uch }
     84      1.1       uch 
     85      1.1       uch void
     86      1.1       uch plumiobus_attach(parent, self, aux)
     87      1.1       uch 	struct device *parent;
     88      1.1       uch 	struct device *self;
     89      1.1       uch 	void *aux;
     90      1.1       uch {
     91      1.1       uch 	struct plum_attach_args *pa = aux;
     92      1.1       uch 	struct plumiobus_softc *sc = (void*)self;
     93      1.1       uch 	struct plumisa_resource *pr;
     94      1.1       uch 
     95      1.1       uch 	sc->sc_pc	= pa->pa_pc;
     96      1.1       uch 	sc->sc_regt	= pa->pa_regt;
     97      1.1       uch 	sc->sc_iot	= pa->pa_iot;
     98      1.1       uch 
     99      1.1       uch 	if (bus_space_map(sc->sc_regt, PLUM_IOBUS_REGBASE,
    100      1.1       uch 			  PLUM_IOBUS_REGSIZE, 0, &sc->sc_regh)) {
    101      1.1       uch 		printf(": register map failed.\n");
    102      1.1       uch 		return;
    103      1.1       uch 	}
    104      1.1       uch 	printf("\n");
    105      1.2       uch 	plum_power_establish(sc->sc_pc, PLUM_PWR_IO5);
    106      1.2       uch 
    107      1.1       uch 	/* Address space <-> IRQ mapping */
    108      1.1       uch 	pr = &sc->sc_isa[IO5CS0];
    109      1.1       uch 	pr->pr_irq = PLUM_INT_EXT5IO0;
    110      1.1       uch 	pr->pr_iot = __plumiobus_subregion(
    111      1.1       uch 		sc->sc_iot,
    112      1.1       uch 		PLUM_IOBUS_IOBASE + PLUM_IOBUS_IO5CS0BASE,
    113      1.1       uch 		PLUM_IOBUS_IO5SIZE);
    114      1.1       uch 
    115      1.1       uch 	pr = &sc->sc_isa[IO5CS1];
    116      1.1       uch 	pr->pr_irq = PLUM_INT_EXT5IO1;
    117      1.1       uch 	pr->pr_iot = __plumiobus_subregion(
    118      1.1       uch 		sc->sc_iot,
    119      1.1       uch 		PLUM_IOBUS_IOBASE + PLUM_IOBUS_IO5CS1BASE,
    120      1.1       uch 		PLUM_IOBUS_IO5SIZE);
    121      1.1       uch 
    122      1.1       uch 	pr = &sc->sc_isa[IO5CS2];
    123      1.1       uch 	pr->pr_irq = PLUM_INT_EXT5IO2;
    124      1.1       uch 	pr->pr_iot = __plumiobus_subregion(
    125      1.1       uch 		sc->sc_iot,
    126      1.1       uch 		PLUM_IOBUS_IOBASE + PLUM_IOBUS_IO5CS2BASE,
    127      1.1       uch 		PLUM_IOBUS_IO5SIZE);
    128      1.1       uch 
    129      1.1       uch 	pr = &sc->sc_isa[IO5CS3];
    130      1.1       uch 	pr->pr_irq = PLUM_INT_EXT5IO3;
    131      1.1       uch 	pr->pr_iot = __plumiobus_subregion(
    132      1.1       uch 		sc->sc_iot,
    133      1.1       uch 		PLUM_IOBUS_IOBASE + PLUM_IOBUS_IO5CS3BASE,
    134      1.1       uch 		PLUM_IOBUS_IO5SIZE);
    135      1.1       uch 
    136      1.1       uch 	pr = &sc->sc_isa[IO5CS4];
    137      1.1       uch 	pr->pr_irq = PLUM_INT_EXT3IO0; /* XXX */
    138      1.1       uch 	pr->pr_iot = __plumiobus_subregion(
    139      1.1       uch 		sc->sc_iot,
    140      1.1       uch 		PLUM_IOBUS_IOBASE + PLUM_IOBUS_IO5CS4BASE,
    141      1.1       uch 		PLUM_IOBUS_IO5SIZE);
    142      1.1       uch 
    143      1.1       uch 
    144      1.1       uch 	pr = &sc->sc_isa[IO5NCS];
    145      1.1       uch 	pr->pr_irq = PLUM_INT_EXT3IO1;
    146      1.1       uch 	pr->pr_iot = __plumiobus_subregion(
    147      1.1       uch 		sc->sc_iot,
    148      1.1       uch 		PLUM_IOBUS_IOBASE + PLUM_IOBUS_IO5CS5BASE,
    149      1.1       uch 		PLUM_IOBUS_IO5SIZE);
    150      1.1       uch 
    151      1.1       uch 
    152      1.1       uch 	plumiobus_dump(sc);
    153      1.2       uch 
    154      1.1       uch 	config_search(plumiobus_search, self, plumiobus_print);
    155      1.1       uch }
    156      1.1       uch 
    157      1.1       uch /* XXX something kludge */
    158      1.1       uch bus_space_tag_t
    159      1.1       uch __plumiobus_subregion(t, ofs, size)
    160      1.1       uch 	bus_space_tag_t t;
    161      1.1       uch 	bus_addr_t ofs;
    162      1.1       uch 	bus_size_t size;
    163      1.1       uch {
    164      1.1       uch 	struct hpcmips_bus_space *hbs;
    165      1.1       uch 
    166      1.1       uch 	if (!(hbs = malloc(sizeof(struct hpcmips_bus_space),
    167      1.1       uch 			   M_DEVBUF, M_NOWAIT))) {
    168      1.1       uch 		panic ("__plumiobus_subregion: no memory.");
    169      1.1       uch 	}
    170      1.1       uch 	*hbs = *t;
    171      1.1       uch 	hbs->t_base += ofs;
    172      1.1       uch 	hbs->t_size = size;
    173      1.1       uch 
    174      1.1       uch 	return hbs;
    175      1.1       uch }
    176      1.1       uch 
    177      1.1       uch int
    178      1.1       uch plumiobus_search(parent, cf, aux)
    179      1.1       uch 	struct device *parent;
    180      1.1       uch 	struct cfdata *cf;
    181      1.1       uch 	void *aux;
    182      1.1       uch {
    183      1.1       uch 	struct plumiobus_softc *sc = (void*)parent;
    184      1.1       uch 	struct plumiobus_attach_args pba;
    185      1.1       uch 	int slot;
    186      1.1       uch 
    187      1.1       uch 	/* Disallow wildcarded IO5CS slot */
    188      1.1       uch 	if (cf->cf_loc[PLUMIOBUSIFCF_SLOT] == PLUMIOBUSIFCF_SLOT_DEFAULT) {
    189      1.1       uch 		printf("plumiobus_search: wildcarded slot, skipping\n");
    190      1.1       uch 		return 0;
    191      1.1       uch 	}
    192      1.1       uch 	slot = pba.pba_slot = cf->cf_loc[PLUMIOBUSIFCF_SLOT];
    193      1.1       uch 
    194      1.1       uch 	pba.pba_pc	= sc->sc_pc;
    195      1.1       uch 	pba.pba_iot	= sc->sc_isa[slot].pr_iot;
    196      1.1       uch 	pba.pba_irq	= sc->sc_isa[slot].pr_irq;
    197      1.1       uch 	pba.pba_busname	= "plumisab";
    198      1.1       uch 
    199      1.1       uch 	if (!(sc->sc_isa[slot].pr_enabled) && /* not attached slot */
    200      1.1       uch 	    (*cf->cf_attach->ca_match)(parent, cf, &pba)) {
    201      1.1       uch 		config_attach(parent, cf, &pba, plumiobus_print);
    202      1.1       uch 		sc->sc_isa[slot].pr_enabled = 1;
    203      1.1       uch 	}
    204      1.1       uch 
    205      1.1       uch 	return 0;
    206      1.1       uch }
    207      1.1       uch 
    208      1.1       uch int
    209      1.1       uch plumiobus_print(aux, pnp)
    210      1.1       uch 	void *aux;
    211      1.1       uch 	const char *pnp;
    212      1.1       uch {
    213      1.1       uch 	return pnp ? QUIET : UNCONF;
    214      1.1       uch }
    215      1.1       uch 
    216      1.1       uch void
    217      1.1       uch plumiobus_dump(sc)
    218      1.1       uch 	struct plumiobus_softc *sc;
    219      1.1       uch {
    220      1.1       uch 	bus_space_tag_t regt = sc->sc_regt;
    221      1.1       uch 	bus_space_handle_t regh = sc->sc_regh;
    222      1.1       uch 	plumreg_t reg;
    223      1.1       uch 	int i, wait;
    224      1.1       uch 
    225      1.1       uch 	reg = plum_conf_read(regt, regh, PLUM_IOBUS_IOXBSZ_REG);
    226      1.1       uch 	printf("8bit port:");
    227      1.1       uch 	for (i = 0; i < 6; i++) {
    228      1.1       uch 		if (reg & (1 << i)) {
    229      1.1       uch 			printf(" IO5CS%d", i);
    230      1.1       uch 		}
    231      1.1       uch 	}
    232      1.1       uch 	printf("\n");
    233      1.1       uch 
    234      1.1       uch 	reg = PLUM_IOBUS_IOXCCNT_MASK &
    235      1.1       uch 		plum_conf_read(regt, regh, PLUM_IOBUS_IOXCCNT_REG);
    236      1.1       uch 	printf(" # of wait to become from the access begining: %d clock\n",
    237      1.1       uch 	       reg + 1);
    238      1.1       uch 	reg = plum_conf_read(regt, regh, PLUM_IOBUS_IOXACNT_REG);
    239      1.1       uch 	printf(" # of wait in access clock: ");
    240      1.1       uch 	for (i = 0; i < 5; i++) {
    241      1.1       uch 		wait = (reg >> (i * PLUM_IOBUS_IOXACNT_SHIFT))
    242      1.1       uch 			& PLUM_IOBUS_IOXACNT_MASK;
    243      1.1       uch 		printf("[CS%d:%d] ", i, wait + 1);
    244      1.1       uch 	}
    245      1.1       uch 	printf("\n");
    246      1.1       uch 
    247      1.1       uch 	reg = PLUM_IOBUS_IOXSCNT_MASK &
    248      1.1       uch 		plum_conf_read(regt, regh, PLUM_IOBUS_IOXSCNT_REG);
    249      1.1       uch 	printf(" # of wait during access by I/O bus : %d clock\n", reg + 1);
    250      1.1       uch 
    251      1.1       uch 	reg = plum_conf_read(regt, regh, PLUM_IOBUS_IDEMODE_REG);
    252      1.1       uch 	if (reg & PLUM_IOBUS_IDEMODE) {
    253      1.1       uch 		printf("IO5CS3,4 IDE mode\n");
    254      1.1       uch 	}
    255      1.1       uch 
    256      1.1       uch }
    257      1.1       uch 
    258