Home | History | Annotate | Line # | Download | only in marvell
obio.c revision 1.2
      1 /*	$NetBSD: obio.c,v 1.2 2003/03/27 07:20:48 matt 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 "opt_marvell.h"
     45 
     46 #include <sys/param.h>
     47 #include <sys/types.h>
     48 #include <sys/cdefs.h>
     49 #include <sys/extent.h>
     50 #include <sys/device.h>
     51 #include <sys/kernel.h>
     52 #include <sys/malloc.h>
     53 
     54 #define _BUS_SPACE_PRIVATE
     55 #define _BUS_DMA_PRIVATE
     56 #include <machine/bus.h>
     57 
     58 #include <powerpc/spr.h>
     59 #include <powerpc/oea/hid.h>
     60 
     61 #include <dev/pci/pcivar.h>
     62 #include <dev/marvell/gtreg.h>
     63 #include <dev/marvell/gtvar.h>
     64 
     65 #ifdef DEBUG
     66 #include <sys/systm.h>	/* for Debugger() */
     67 #endif
     68 
     69 static int obio_cfprint(void *, const char *);
     70 static int obio_cfmatch(struct device *, struct cfdata *, void *);
     71 static int obio_cfsearch(struct device *, struct cfdata *, void *);
     72 static void obio_cfattach(struct device *, struct device *, void *);
     73 
     74 struct obio_softc {
     75 	struct device sc_dev;
     76 	bus_space_tag_t sc_memt;
     77 	bus_space_tag_t sc_gt_memt;
     78 	bus_space_tag_t sc_gt_memh;
     79 };
     80 
     81 CFATTACH_DECL(obio, sizeof(struct obio_softc),
     82     obio_cfmatch, obio_cfattach, NULL, NULL);
     83 
     84 extern struct cfdriver obio_cd;
     85 
     86 static const struct {
     87     bus_addr_t low_decode;
     88     bus_addr_t high_decode;
     89 } obio_info[5] = {
     90     { GT_CS0_Low_Decode, GT_CS0_High_Decode, },
     91     { GT_CS1_Low_Decode, GT_CS1_High_Decode, },
     92     { GT_CS2_Low_Decode, GT_CS2_High_Decode, },
     93     { GT_CS3_Low_Decode, GT_CS3_High_Decode, },
     94     { GT_BootCS_Low_Decode, GT_BootCS_High_Decode, },
     95 };
     96 
     97 extern bus_space_tag_t obio_bs_tags[5];
     98 
     99 int
    100 obio_cfprint(void *aux, const char *pnp)
    101 {
    102 	struct obio_attach_args *oa = aux;
    103 
    104 	if (pnp) {
    105 		aprint_normal("%s at %s", oa->oa_name, pnp);
    106 	}
    107 	aprint_normal(" offset %#x size %#x", oa->oa_offset, oa->oa_size);
    108 	if (oa->oa_irq != OBIO_UNK_IRQ)
    109 		aprint_normal(" irq %d", oa->oa_irq);
    110 
    111 	return (UNCONF);
    112 }
    113 
    114 
    115 int
    116 obio_cfsearch(struct device *parent, struct cfdata *cf, void *aux)
    117 {
    118 	struct obio_softc *sc = (struct obio_softc *) parent;
    119 	struct obio_attach_args oa;
    120 
    121 	oa.oa_name = cf->cf_name;
    122 	oa.oa_memt = sc->sc_memt;
    123 	oa.oa_offset = cf->obiocf_offset;
    124 	oa.oa_size = cf->obiocf_size;
    125 	oa.oa_irq = cf->obiocf_irq;
    126 
    127 	if (config_match(parent, cf, &oa) > 0)
    128 		config_attach(parent, cf, &oa, obio_cfprint);
    129 
    130 	return (0);
    131 }
    132 
    133 int
    134 obio_cfmatch(struct device *parent, struct cfdata *cf, void *aux)
    135 {
    136 	struct gt_softc * const gt = (struct gt_softc *)parent;
    137 	struct gt_attach_args * const ga = aux;
    138 
    139 	return GT_OBIOOK(gt, ga, &obio_cd);
    140 }
    141 
    142 void
    143 obio_cfattach(struct device *parent, struct device *self, void *aux)
    144 {
    145 	struct gt_softc * const gt = (struct gt_softc *)parent;
    146 	struct obio_softc *sc = (struct obio_softc *)self;
    147 	struct gt_attach_args *ga = aux;
    148 	uint32_t datal, datah;
    149 
    150 	GT_OBIOFOUND(gt, ga);
    151 
    152 	datal = bus_space_read_4(ga->ga_memt, ga->ga_memh,
    153 	    obio_info[ga->ga_unit].low_decode);
    154 	datah = bus_space_read_4(ga->ga_memt, ga->ga_memh,
    155 	    obio_info[ga->ga_unit].high_decode);
    156 
    157 	if (GT_LowAddr_GET(datal) > GT_HighAddr_GET(datah)) {
    158 		aprint_normal(": disabled\n");
    159 		return;
    160 	}
    161 
    162 	sc->sc_memt = obio_bs_tags[ga->ga_unit];
    163 	if (sc->sc_memt == NULL) {
    164 		aprint_normal(": unused\n");
    165 		return;
    166 	}
    167 
    168 	aprint_normal(": addr %#x-%#x, %s-endian\n",
    169 	    GT_LowAddr_GET(datal), GT_HighAddr_GET(datah),
    170 	    GT_PCISwap_GET(datal) == 1 ? "little" : "big");
    171 
    172         config_search(obio_cfsearch, &sc->sc_dev, NULL);
    173 }
    174 
    175