Home | History | Annotate | Line # | Download | only in dev
plumiobus.c revision 1.6
      1 /*	$NetBSD: plumiobus.c,v 1.6 2002/09/27 03:17:54 thorpej 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 
     41 #include <sys/param.h>
     42 #include <sys/systm.h>
     43 #include <sys/device.h>
     44 #include <sys/malloc.h>
     45 
     46 #include <machine/bus.h>
     47 #include <machine/intr.h>
     48 
     49 #include <hpcmips/tx/tx39var.h>
     50 #include <hpcmips/dev/plumvar.h>
     51 #include <hpcmips/dev/plumicuvar.h>
     52 #include <hpcmips/dev/plumpowervar.h>
     53 #include <hpcmips/dev/plumiobusreg.h>
     54 #include <hpcmips/dev/plumiobusvar.h>
     55 
     56 #include "locators.h"
     57 
     58 #ifdef PLUMIOBUSDEBUG
     59 int	plumiobus_debug = 0;
     60 #define	DPRINTF(arg) if (plumiobus_debug) printf arg;
     61 #define	DPRINTFN(n, arg) if (plumiobus_debug > (n)) printf arg;
     62 #else
     63 #define	DPRINTF(arg)
     64 #define DPRINTFN(n, arg)
     65 #endif
     66 
     67 int plumiobus_match(struct device *, struct cfdata *, void *);
     68 void plumiobus_attach(struct device *, struct device *, void *);
     69 int plumiobus_print(void *, const char *);
     70 int plumiobus_search(struct device *, struct cfdata *, void *);
     71 
     72 struct plumisa_resource {
     73 	int		pr_irq;
     74 	bus_space_tag_t	pr_iot;
     75 	int		pr_enabled;
     76 };
     77 
     78 struct plumiobus_softc {
     79 	struct	device		sc_dev;
     80 	plum_chipset_tag_t	sc_pc;
     81 	bus_space_tag_t		sc_regt;
     82 	bus_space_handle_t	sc_regh;
     83 	bus_space_tag_t		sc_iot;
     84 	bus_space_handle_t	sc_ioh;
     85 	struct plumisa_resource	sc_isa[PLUM_IOBUS_IO5CSMAX];
     86 };
     87 
     88 struct cfattach plumiobus_ca = {
     89 	sizeof(struct plumiobus_softc), plumiobus_match, plumiobus_attach
     90 };
     91 
     92 bus_space_tag_t __plumiobus_subregion(bus_space_tag_t, bus_addr_t,
     93     bus_size_t);
     94 #ifdef PLUMIOBUSDEBUG
     95 void plumiobus_dump(struct plumiobus_softc *);
     96 #endif
     97 
     98 int
     99 plumiobus_match(struct device *parent, struct cfdata *cf, void *aux)
    100 {
    101 
    102 	return (1);
    103 }
    104 
    105 void
    106 plumiobus_attach(struct device *parent, struct device *self, void *aux)
    107 {
    108 	struct plum_attach_args *pa = aux;
    109 	struct plumiobus_softc *sc = (void*)self;
    110 	struct plumisa_resource *pr;
    111 
    112 	sc->sc_pc	= pa->pa_pc;
    113 	sc->sc_regt	= pa->pa_regt;
    114 	sc->sc_iot	= pa->pa_iot;
    115 
    116 	if (bus_space_map(sc->sc_regt, PLUM_IOBUS_REGBASE,
    117 	    PLUM_IOBUS_REGSIZE, 0, &sc->sc_regh)) {
    118 		printf(": register map failed.\n");
    119 		return;
    120 	}
    121 	printf("\n");
    122 	plum_power_establish(sc->sc_pc, PLUM_PWR_IO5);
    123 
    124 	/* Address space <-> IRQ mapping */
    125 	pr = &sc->sc_isa[IO5CS0];
    126 	pr->pr_irq = PLUM_INT_EXT5IO0;
    127 	pr->pr_iot = __plumiobus_subregion(
    128 		sc->sc_iot,
    129 		PLUM_IOBUS_IOBASE + PLUM_IOBUS_IO5CS0BASE,
    130 		PLUM_IOBUS_IO5SIZE);
    131 
    132 	pr = &sc->sc_isa[IO5CS1];
    133 	pr->pr_irq = PLUM_INT_EXT5IO1;
    134 	pr->pr_iot = __plumiobus_subregion(
    135 		sc->sc_iot,
    136 		PLUM_IOBUS_IOBASE + PLUM_IOBUS_IO5CS1BASE,
    137 		PLUM_IOBUS_IO5SIZE);
    138 
    139 	pr = &sc->sc_isa[IO5CS2];
    140 	pr->pr_irq = PLUM_INT_EXT5IO2;
    141 	pr->pr_iot = __plumiobus_subregion(
    142 		sc->sc_iot,
    143 		PLUM_IOBUS_IOBASE + PLUM_IOBUS_IO5CS2BASE,
    144 		PLUM_IOBUS_IO5SIZE);
    145 
    146 	pr = &sc->sc_isa[IO5CS3];
    147 	pr->pr_irq = PLUM_INT_EXT5IO3;
    148 	pr->pr_iot = __plumiobus_subregion(
    149 		sc->sc_iot,
    150 		PLUM_IOBUS_IOBASE + PLUM_IOBUS_IO5CS3BASE,
    151 		PLUM_IOBUS_IO5SIZE);
    152 
    153 	pr = &sc->sc_isa[IO5CS4];
    154 	pr->pr_irq = PLUM_INT_EXT3IO0; /* XXX */
    155 	pr->pr_iot = __plumiobus_subregion(
    156 		sc->sc_iot,
    157 		PLUM_IOBUS_IOBASE + PLUM_IOBUS_IO5CS4BASE,
    158 		PLUM_IOBUS_IO5SIZE);
    159 
    160 
    161 	pr = &sc->sc_isa[IO5NCS];
    162 	pr->pr_irq = PLUM_INT_EXT3IO1;
    163 	pr->pr_iot = __plumiobus_subregion(
    164 		sc->sc_iot,
    165 		PLUM_IOBUS_IOBASE + PLUM_IOBUS_IO5CS5BASE,
    166 		PLUM_IOBUS_IO5SIZE);
    167 
    168 #ifdef PLUMIOBUSDEBUG
    169 	plumiobus_dump(sc);
    170 #endif
    171 
    172 	config_search(plumiobus_search, self, plumiobus_print);
    173 }
    174 
    175 /* XXX something kludge */
    176 bus_space_tag_t
    177 __plumiobus_subregion(bus_space_tag_t t, bus_addr_t ofs, bus_size_t size)
    178 {
    179 	struct hpcmips_bus_space *hbs;
    180 
    181 	if (!(hbs = malloc(sizeof(struct hpcmips_bus_space),
    182 	    M_DEVBUF, M_NOWAIT))) {
    183 		panic ("__plumiobus_subregion: no memory.");
    184 	}
    185 	*hbs = *t;
    186 	hbs->t_base += ofs;
    187 	hbs->t_size = size;
    188 
    189 	return (hbs);
    190 }
    191 
    192 int
    193 plumiobus_search(struct device *parent, struct cfdata *cf, void *aux)
    194 {
    195 	struct plumiobus_softc *sc = (void*)parent;
    196 	struct plumiobus_attach_args pba;
    197 	int slot;
    198 
    199 	/* Disallow wildcarded IO5CS slot */
    200 	if (cf->cf_loc[PLUMIOBUSIFCF_SLOT] == PLUMIOBUSIFCF_SLOT_DEFAULT) {
    201 		printf("plumiobus_search: wildcarded slot, skipping\n");
    202 		return (0);
    203 	}
    204 	slot = pba.pba_slot = cf->cf_loc[PLUMIOBUSIFCF_SLOT];
    205 
    206 	pba.pba_pc	= sc->sc_pc;
    207 	pba.pba_iot	= sc->sc_isa[slot].pr_iot;
    208 	pba.pba_irq	= sc->sc_isa[slot].pr_irq;
    209 	pba.pba_busname	= "plumisab";
    210 
    211 	if (!(sc->sc_isa[slot].pr_enabled) && /* not attached slot */
    212 	    config_match(parent, cf, &pba)) {
    213 		config_attach(parent, cf, &pba, plumiobus_print);
    214 		sc->sc_isa[slot].pr_enabled = 1;
    215 	}
    216 
    217 	return (0);
    218 }
    219 
    220 int
    221 plumiobus_print(void *aux, const char *pnp)
    222 {
    223 
    224 	return (pnp ? QUIET : UNCONF);
    225 }
    226 
    227 #ifdef PLUMIOBUSDEBUG
    228 void
    229 plumiobus_dump(struct plumiobus_softc *sc)
    230 {
    231 	bus_space_tag_t regt = sc->sc_regt;
    232 	bus_space_handle_t regh = sc->sc_regh;
    233 	plumreg_t reg;
    234 	int i, wait;
    235 
    236 	reg = plum_conf_read(regt, regh, PLUM_IOBUS_IOXBSZ_REG);
    237 	printf("8bit port:");
    238 	for (i = 0; i < 6; i++) {
    239 		if (reg & (1 << i)) {
    240 			printf(" IO5CS%d", i);
    241 		}
    242 	}
    243 	printf("\n");
    244 
    245 	reg = PLUM_IOBUS_IOXCCNT_MASK &
    246 	    plum_conf_read(regt, regh, PLUM_IOBUS_IOXCCNT_REG);
    247 	printf(" # of wait to become from the access begining: %d clock\n",
    248 	    reg + 1);
    249 	reg = plum_conf_read(regt, regh, PLUM_IOBUS_IOXACNT_REG);
    250 	printf(" # of wait in access clock: ");
    251 	for (i = 0; i < 5; i++) {
    252 		wait = (reg >> (i * PLUM_IOBUS_IOXACNT_SHIFT))
    253 		    & PLUM_IOBUS_IOXACNT_MASK;
    254 		printf("[CS%d:%d] ", i, wait + 1);
    255 	}
    256 	printf("\n");
    257 
    258 	reg = PLUM_IOBUS_IOXSCNT_MASK &
    259 	    plum_conf_read(regt, regh, PLUM_IOBUS_IOXSCNT_REG);
    260 	printf(" # of wait during access by I/O bus : %d clock\n", reg + 1);
    261 
    262 	reg = plum_conf_read(regt, regh, PLUM_IOBUS_IDEMODE_REG);
    263 	if (reg & PLUM_IOBUS_IDEMODE) {
    264 		printf("IO5CS3,4 IDE mode\n");
    265 	}
    266 }
    267 #endif /* PLUMIOBUSDEBUG */
    268