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