Home | History | Annotate | Line # | Download | only in marvell
obio.c revision 1.5
      1 /*	$NetBSD: obio.c,v 1.5 2004/09/13 12:55:48 drochner Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2002 Allegro Networks, Inc., Wasabi Systems, Inc.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *      This product includes software developed for the NetBSD Project by
     18  *      Allegro Networks, Inc., and Wasabi Systems, Inc.
     19  * 4. The name of Allegro Networks, Inc. may not be used to endorse
     20  *    or promote products derived from this software without specific prior
     21  *    written permission.
     22  * 5. The name of Wasabi Systems, Inc. may not be used to endorse
     23  *    or promote products derived from this software without specific prior
     24  *    written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY ALLEGRO NETWORKS, INC. AND
     27  * WASABI SYSTEMS, INC. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
     28  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
     29  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     30  * IN NO EVENT SHALL EITHER ALLEGRO NETWORKS, INC. OR WASABI SYSTEMS, INC.
     31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  * POSSIBILITY OF SUCH DAMAGE.
     38  */
     39 
     40 /*
     41  * gt.c -- GT system controller driver
     42  */
     43 
     44 #include <sys/cdefs.h>
     45 __KERNEL_RCSID(0, "$NetBSD: obio.c,v 1.5 2004/09/13 12:55:48 drochner Exp $");
     46 
     47 #include "opt_marvell.h"
     48 
     49 #include <sys/param.h>
     50 #include <sys/types.h>
     51 #include <sys/cdefs.h>
     52 #include <sys/extent.h>
     53 #include <sys/device.h>
     54 #include <sys/kernel.h>
     55 #include <sys/malloc.h>
     56 
     57 #define _BUS_SPACE_PRIVATE
     58 #define _BUS_DMA_PRIVATE
     59 #include <machine/bus.h>
     60 
     61 #include <powerpc/spr.h>
     62 #include <powerpc/oea/hid.h>
     63 
     64 #include <dev/pci/pcivar.h>
     65 #include <dev/marvell/gtreg.h>
     66 #include <dev/marvell/gtvar.h>
     67 
     68 #ifdef DEBUG
     69 #include <sys/systm.h>	/* for Debugger() */
     70 #endif
     71 
     72 #include "locators.h"
     73 
     74 static int obio_cfprint(void *, const char *);
     75 static int obio_cfmatch(struct device *, struct cfdata *, void *);
     76 static int obio_cfsearch(struct device *, struct cfdata *,
     77 			 const locdesc_t *, void *);
     78 static void obio_cfattach(struct device *, struct device *, void *);
     79 
     80 struct obio_softc {
     81 	struct device sc_dev;
     82 	bus_space_tag_t sc_memt;
     83 	bus_space_tag_t sc_gt_memt;
     84 	bus_space_tag_t sc_gt_memh;
     85 };
     86 
     87 CFATTACH_DECL(obio, sizeof(struct obio_softc),
     88     obio_cfmatch, obio_cfattach, NULL, NULL);
     89 
     90 extern struct cfdriver obio_cd;
     91 
     92 static const struct {
     93     bus_addr_t low_decode;
     94     bus_addr_t high_decode;
     95 } obio_info[5] = {
     96     { GT_CS0_Low_Decode, GT_CS0_High_Decode, },
     97     { GT_CS1_Low_Decode, GT_CS1_High_Decode, },
     98     { GT_CS2_Low_Decode, GT_CS2_High_Decode, },
     99     { GT_CS3_Low_Decode, GT_CS3_High_Decode, },
    100     { GT_BootCS_Low_Decode, GT_BootCS_High_Decode, },
    101 };
    102 
    103 extern bus_space_tag_t obio_bs_tags[5];
    104 
    105 int
    106 obio_cfprint(void *aux, const char *pnp)
    107 {
    108 	struct obio_attach_args *oa = aux;
    109 
    110 	if (pnp) {
    111 		aprint_normal("%s at %s", oa->oa_name, pnp);
    112 	}
    113 	aprint_normal(" offset %#x size %#x", oa->oa_offset, oa->oa_size);
    114 	if (oa->oa_irq != OBIOCF_IRQ_DEFAULT)
    115 		aprint_normal(" irq %d", oa->oa_irq);
    116 
    117 	return (UNCONF);
    118 }
    119 
    120 
    121 int
    122 obio_cfsearch(struct device *parent, struct cfdata *cf,
    123 	      const locdesc_t *ldesc, void *aux)
    124 {
    125 	struct obio_softc *sc = (struct obio_softc *) parent;
    126 	struct obio_attach_args oa;
    127 
    128 	oa.oa_name = cf->cf_name;
    129 	oa.oa_memt = sc->sc_memt;
    130 	oa.oa_offset = cf->cf_loc[OBIOCF_OFFSET];
    131 	oa.oa_size = cf->cf_loc[OBIOCF_SIZE];
    132 	oa.oa_irq = cf->cf_loc[OBIOCF_IRQ];
    133 
    134 	if (config_match(parent, cf, &oa) > 0)
    135 		config_attach(parent, cf, &oa, obio_cfprint);
    136 
    137 	return (0);
    138 }
    139 
    140 int
    141 obio_cfmatch(struct device *parent, struct cfdata *cf, void *aux)
    142 {
    143 	struct gt_softc * const gt = (struct gt_softc *)parent;
    144 	struct gt_attach_args * const ga = aux;
    145 
    146 	return GT_OBIOOK(gt, ga, &obio_cd);
    147 }
    148 
    149 void
    150 obio_cfattach(struct device *parent, struct device *self, void *aux)
    151 {
    152 	struct gt_softc * const gt = (struct gt_softc *)parent;
    153 	struct obio_softc *sc = (struct obio_softc *)self;
    154 	struct gt_attach_args *ga = aux;
    155 	uint32_t datal, datah;
    156 
    157 	GT_OBIOFOUND(gt, ga);
    158 
    159 	datal = bus_space_read_4(ga->ga_memt, ga->ga_memh,
    160 	    obio_info[ga->ga_unit].low_decode);
    161 	datah = bus_space_read_4(ga->ga_memt, ga->ga_memh,
    162 	    obio_info[ga->ga_unit].high_decode);
    163 
    164 	if (GT_LowAddr_GET(datal) > GT_HighAddr_GET(datah)) {
    165 		aprint_normal(": disabled\n");
    166 		return;
    167 	}
    168 
    169 	sc->sc_memt = obio_bs_tags[ga->ga_unit];
    170 	if (sc->sc_memt == NULL) {
    171 		aprint_normal(": unused\n");
    172 		return;
    173 	}
    174 
    175 	aprint_normal(": addr %#x-%#x, %s-endian\n",
    176 	    GT_LowAddr_GET(datal), GT_HighAddr_GET(datah),
    177 	    GT_PCISwap_GET(datal) == 1 ? "little" : "big");
    178 
    179         config_search_ia(obio_cfsearch, &sc->sc_dev, "obio", NULL);
    180 }
    181