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