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