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