Home | History | Annotate | Line # | Download | only in marvell
obio.c revision 1.12.2.1
      1  1.12.2.1  uebayasi /*	$NetBSD: obio.c,v 1.12.2.1 2010/04/30 14:43:28 uebayasi 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.3     lukem #include <sys/cdefs.h>
     41  1.12.2.1  uebayasi __KERNEL_RCSID(0, "$NetBSD: obio.c,v 1.12.2.1 2010/04/30 14:43:28 uebayasi Exp $");
     42       1.1      matt 
     43       1.1      matt #include "opt_marvell.h"
     44       1.1      matt 
     45       1.1      matt #include <sys/param.h>
     46       1.1      matt #include <sys/types.h>
     47       1.1      matt #include <sys/extent.h>
     48       1.1      matt #include <sys/device.h>
     49       1.1      matt #include <sys/kernel.h>
     50       1.1      matt #include <sys/malloc.h>
     51       1.1      matt 
     52       1.1      matt #include <dev/pci/pcivar.h>
     53       1.1      matt #include <dev/marvell/gtreg.h>
     54       1.1      matt #include <dev/marvell/gtvar.h>
     55  1.12.2.1  uebayasi #include <dev/marvell/gtdevbusvar.h>
     56  1.12.2.1  uebayasi #include <dev/marvell/marvellvar.h>
     57  1.12.2.1  uebayasi 
     58  1.12.2.1  uebayasi #include <prop/proplib.h>
     59       1.1      matt 
     60       1.1      matt #ifdef DEBUG
     61       1.1      matt #include <sys/systm.h>	/* for Debugger() */
     62       1.1      matt #endif
     63       1.1      matt 
     64       1.5  drochner #include "locators.h"
     65       1.5  drochner 
     66  1.12.2.1  uebayasi 
     67  1.12.2.1  uebayasi static int obio_match(device_t, cfdata_t, void *);
     68  1.12.2.1  uebayasi static void obio_attach(device_t, device_t, void *);
     69  1.12.2.1  uebayasi 
     70       1.1      matt static int obio_cfprint(void *, const char *);
     71  1.12.2.1  uebayasi static int obio_cfsearch(device_t, cfdata_t, const int *, void *);
     72  1.12.2.1  uebayasi 
     73       1.1      matt 
     74       1.1      matt struct obio_softc {
     75  1.12.2.1  uebayasi 	device_t sc_dev;
     76  1.12.2.1  uebayasi 	bus_space_tag_t sc_iot;
     77       1.1      matt };
     78       1.1      matt 
     79  1.12.2.1  uebayasi CFATTACH_DECL_NEW(obio, sizeof(struct obio_softc),
     80  1.12.2.1  uebayasi     obio_match, obio_attach, NULL, NULL);
     81       1.1      matt 
     82       1.1      matt 
     83  1.12.2.1  uebayasi /* ARGSUSED */
     84  1.12.2.1  uebayasi int
     85  1.12.2.1  uebayasi obio_match(device_t parent, cfdata_t cf, void *aux)
     86  1.12.2.1  uebayasi {
     87  1.12.2.1  uebayasi 	struct marvell_attach_args *mva = aux;
     88  1.12.2.1  uebayasi 
     89  1.12.2.1  uebayasi 	if (strcmp(mva->mva_name, cf->cf_name) != 0)
     90  1.12.2.1  uebayasi 		return 0;
     91  1.12.2.1  uebayasi 
     92  1.12.2.1  uebayasi #define NUM_OBIO	5
     93  1.12.2.1  uebayasi 	if (mva->mva_unit == GTCF_UNIT_DEFAULT ||
     94  1.12.2.1  uebayasi 	    mva->mva_unit > NUM_OBIO)
     95  1.12.2.1  uebayasi 		return 0;
     96  1.12.2.1  uebayasi 
     97  1.12.2.1  uebayasi 	return 1;
     98  1.12.2.1  uebayasi }
     99  1.12.2.1  uebayasi 
    100  1.12.2.1  uebayasi /* ARGSUSED */
    101  1.12.2.1  uebayasi void
    102  1.12.2.1  uebayasi obio_attach(device_t parent, device_t self, void *aux)
    103  1.12.2.1  uebayasi {
    104  1.12.2.1  uebayasi 	struct obio_softc *sc = device_private(self);
    105  1.12.2.1  uebayasi 	struct marvell_attach_args *mva = aux;
    106  1.12.2.1  uebayasi 	prop_data_t bst;
    107  1.12.2.1  uebayasi 	uint32_t datal, datah;
    108  1.12.2.1  uebayasi 
    109  1.12.2.1  uebayasi 	aprint_naive("\n");
    110  1.12.2.1  uebayasi 	aprint_normal(": Device Bus\n");
    111  1.12.2.1  uebayasi 
    112  1.12.2.1  uebayasi 	sc->sc_dev = self;
    113  1.12.2.1  uebayasi 
    114  1.12.2.1  uebayasi 	if (gt_devbus_addr(parent, mva->mva_unit, &datal, &datah)) {
    115  1.12.2.1  uebayasi 		aprint_error_dev(self, "unknown unit number %d\n",
    116  1.12.2.1  uebayasi 		    mva->mva_unit);
    117  1.12.2.1  uebayasi 		return;
    118  1.12.2.1  uebayasi 	}
    119  1.12.2.1  uebayasi 
    120  1.12.2.1  uebayasi 	if (GT_LowAddr_GET(datal) > GT_HighAddr_GET(datah)) {
    121  1.12.2.1  uebayasi 		aprint_normal_dev(self, "disabled\n");
    122  1.12.2.1  uebayasi 		return;
    123  1.12.2.1  uebayasi 	}
    124  1.12.2.1  uebayasi 
    125  1.12.2.1  uebayasi 	bst = prop_dictionary_get(device_properties(sc->sc_dev), "bus-tag");
    126  1.12.2.1  uebayasi 	if (bst != NULL) {
    127  1.12.2.1  uebayasi 		KASSERT(prop_object_type(bst) == PROP_TYPE_DATA);
    128  1.12.2.1  uebayasi 		KASSERT(prop_data_size(bst) == sizeof(bus_space_tag_t));
    129  1.12.2.1  uebayasi 		memcpy(&sc->sc_iot, prop_data_data_nocopy(bst),
    130  1.12.2.1  uebayasi 		    sizeof(bus_space_tag_t));
    131  1.12.2.1  uebayasi 	} else
    132  1.12.2.1  uebayasi 		sc->sc_iot = mva->mva_iot;
    133  1.12.2.1  uebayasi 	if (sc->sc_iot == NULL) {
    134  1.12.2.1  uebayasi 		aprint_normal_dev(self, "unused\n");
    135  1.12.2.1  uebayasi 		return;
    136  1.12.2.1  uebayasi 	}
    137  1.12.2.1  uebayasi 
    138  1.12.2.1  uebayasi 	aprint_normal_dev(self, "addr %#x-%#x\n",
    139  1.12.2.1  uebayasi 	    GT_LowAddr_GET(datal), GT_HighAddr_GET(datah));
    140  1.12.2.1  uebayasi 
    141  1.12.2.1  uebayasi         config_search_ia(obio_cfsearch, self, "obio", NULL);
    142  1.12.2.1  uebayasi }
    143       1.1      matt 
    144       1.1      matt 
    145       1.1      matt int
    146       1.1      matt obio_cfprint(void *aux, const char *pnp)
    147       1.1      matt {
    148       1.1      matt 	struct obio_attach_args *oa = aux;
    149       1.1      matt 
    150  1.12.2.1  uebayasi 	if (pnp)
    151       1.1      matt 		aprint_normal("%s at %s", oa->oa_name, pnp);
    152  1.12.2.1  uebayasi 	aprint_normal(" addr %#x size %#x", oa->oa_offset, oa->oa_size);
    153       1.5  drochner 	if (oa->oa_irq != OBIOCF_IRQ_DEFAULT)
    154       1.2      matt 		aprint_normal(" irq %d", oa->oa_irq);
    155       1.1      matt 
    156  1.12.2.1  uebayasi 	return UNCONF;
    157       1.1      matt }
    158       1.1      matt 
    159       1.1      matt 
    160  1.12.2.1  uebayasi /* ARGSUSED */
    161       1.1      matt int
    162  1.12.2.1  uebayasi obio_cfsearch(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
    163       1.1      matt {
    164  1.12.2.1  uebayasi 	struct obio_softc *sc = device_private(parent);
    165       1.1      matt 	struct obio_attach_args oa;
    166       1.1      matt 
    167       1.1      matt 	oa.oa_name = cf->cf_name;
    168  1.12.2.1  uebayasi 	oa.oa_memt = sc->sc_iot;
    169       1.5  drochner 	oa.oa_offset = cf->cf_loc[OBIOCF_OFFSET];
    170       1.5  drochner 	oa.oa_size = cf->cf_loc[OBIOCF_SIZE];
    171       1.5  drochner 	oa.oa_irq = cf->cf_loc[OBIOCF_IRQ];
    172       1.1      matt 
    173       1.1      matt 	if (config_match(parent, cf, &oa) > 0)
    174       1.1      matt 		config_attach(parent, cf, &oa, obio_cfprint);
    175       1.1      matt 
    176  1.12.2.1  uebayasi 	return 0;
    177       1.1      matt }
    178