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