Home | History | Annotate | Line # | Download | only in marvell
gtpci.c revision 1.21.4.1
      1  1.21.4.1   rmind /*	$NetBSD: gtpci.c,v 1.21.4.1 2010/05/30 05:17:29 rmind Exp $	*/
      2       1.1    matt /*
      3  1.21.4.1   rmind  * Copyright (c) 2008, 2009 KIYOHARA Takashi
      4       1.1    matt  * All rights reserved.
      5       1.1    matt  *
      6       1.1    matt  * Redistribution and use in source and binary forms, with or without
      7       1.1    matt  * modification, are permitted provided that the following conditions
      8       1.1    matt  * are met:
      9       1.1    matt  * 1. Redistributions of source code must retain the above copyright
     10       1.1    matt  *    notice, this list of conditions and the following disclaimer.
     11       1.1    matt  * 2. Redistributions in binary form must reproduce the above copyright
     12       1.1    matt  *    notice, this list of conditions and the following disclaimer in the
     13       1.1    matt  *    documentation and/or other materials provided with the distribution.
     14       1.1    matt  *
     15  1.21.4.1   rmind  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     16  1.21.4.1   rmind  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     17  1.21.4.1   rmind  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     18  1.21.4.1   rmind  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     19  1.21.4.1   rmind  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     20  1.21.4.1   rmind  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     21  1.21.4.1   rmind  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22  1.21.4.1   rmind  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     23  1.21.4.1   rmind  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     24  1.21.4.1   rmind  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25       1.1    matt  * POSSIBILITY OF SUCH DAMAGE.
     26       1.1    matt  */
     27      1.10   lukem 
     28      1.10   lukem #include <sys/cdefs.h>
     29  1.21.4.1   rmind __KERNEL_RCSID(0, "$NetBSD: gtpci.c,v 1.21.4.1 2010/05/30 05:17:29 rmind Exp $");
     30  1.21.4.1   rmind 
     31  1.21.4.1   rmind #include "opt_pci.h"
     32  1.21.4.1   rmind #include "pci.h"
     33       1.1    matt 
     34       1.1    matt #include <sys/param.h>
     35  1.21.4.1   rmind #include <sys/bus.h>
     36       1.1    matt #include <sys/device.h>
     37  1.21.4.1   rmind #include <sys/errno.h>
     38       1.1    matt #include <sys/extent.h>
     39  1.21.4.1   rmind #include <sys/gpio.h>
     40       1.1    matt #include <sys/malloc.h>
     41       1.1    matt 
     42  1.21.4.1   rmind #include <prop/proplib.h>
     43       1.1    matt 
     44       1.1    matt #include <dev/pci/pcireg.h>
     45       1.1    matt #include <dev/pci/pcivar.h>
     46       1.1    matt #include <dev/pci/pciconf.h>
     47  1.21.4.1   rmind 
     48       1.1    matt #include <dev/marvell/gtpcireg.h>
     49       1.1    matt #include <dev/marvell/gtpcivar.h>
     50  1.21.4.1   rmind #include <dev/marvell/marvellreg.h>
     51  1.21.4.1   rmind #include <dev/marvell/marvellvar.h>
     52       1.1    matt 
     53  1.21.4.1   rmind #include <machine/pci_machdep.h>
     54       1.1    matt 
     55  1.21.4.1   rmind #include "locators.h"
     56       1.5    matt 
     57       1.1    matt 
     58  1.21.4.1   rmind #define GTPCI_READ(sc, r) \
     59  1.21.4.1   rmind 	bus_space_read_4((sc)->sc_iot, (sc)->sc_ioh, r((sc)->sc_unit))
     60  1.21.4.1   rmind #define GTPCI_WRITE(sc, r, v) \
     61  1.21.4.1   rmind 	bus_space_write_4((sc)->sc_iot, (sc)->sc_ioh, r((sc)->sc_unit), (v))
     62  1.21.4.1   rmind #define GTPCI_WRITE_AC(sc, r, n, v) \
     63  1.21.4.1   rmind     bus_space_write_4((sc)->sc_iot, (sc)->sc_ioh, r((sc)->sc_unit, (n)), (v))
     64       1.1    matt 
     65       1.1    matt 
     66  1.21.4.1   rmind static int gtpci_match(device_t, struct cfdata *, void *);
     67      1.21  cegger static void gtpci_attach(device_t, device_t, void *);
     68       1.1    matt 
     69  1.21.4.1   rmind static void gtpci_init(struct gtpci_softc *);
     70  1.21.4.1   rmind static void gtpci_barinit(struct gtpci_softc *);
     71  1.21.4.1   rmind static void gtpci_protinit(struct gtpci_softc *);
     72  1.21.4.1   rmind #if NPCI > 0
     73  1.21.4.1   rmind static void gtpci_pci_config(struct gtpci_softc *, bus_space_tag_t,
     74  1.21.4.1   rmind 			     bus_space_tag_t, bus_dma_tag_t, pci_chipset_tag_t,
     75  1.21.4.1   rmind 			     u_long, u_long, u_long, u_long, int);
     76  1.21.4.1   rmind #endif
     77       1.1    matt 
     78       1.1    matt 
     79  1.21.4.1   rmind CFATTACH_DECL_NEW(gtpci_gt, sizeof(struct gtpci_softc),
     80  1.21.4.1   rmind     gtpci_match, gtpci_attach, NULL, NULL);
     81  1.21.4.1   rmind CFATTACH_DECL_NEW(gtpci_mbus, sizeof(struct gtpci_softc),
     82  1.21.4.1   rmind     gtpci_match, gtpci_attach, NULL, NULL);
     83       1.6    matt 
     84  1.21.4.1   rmind 
     85  1.21.4.1   rmind /* ARGSUSED */
     86  1.21.4.1   rmind static int
     87  1.21.4.1   rmind gtpci_match(device_t parent, struct cfdata *match, void *aux)
     88       1.1    matt {
     89  1.21.4.1   rmind 	struct marvell_attach_args *mva = aux;
     90       1.1    matt 
     91  1.21.4.1   rmind 	if (strcmp(mva->mva_name, match->cf_name) != 0)
     92  1.21.4.1   rmind 		return 0;
     93       1.1    matt 
     94  1.21.4.1   rmind 	switch (mva->mva_model) {
     95  1.21.4.1   rmind 	case MARVELL_DISCOVERY:
     96  1.21.4.1   rmind 	case MARVELL_DISCOVERY_II:
     97  1.21.4.1   rmind 	case MARVELL_DISCOVERY_III:
     98  1.21.4.1   rmind #if 0	/* XXXXX */
     99  1.21.4.1   rmind 	case MARVELL_DISCOVERY_LT:
    100  1.21.4.1   rmind 	case MARVELL_DISCOVERY_V:
    101  1.21.4.1   rmind 	case MARVELL_DISCOVERY_VI:
    102  1.21.4.1   rmind #endif
    103  1.21.4.1   rmind 		if (mva->mva_unit == GTCF_UNIT_DEFAULT ||
    104  1.21.4.1   rmind 		    mva->mva_offset != GTCF_OFFSET_DEFAULT)
    105  1.21.4.1   rmind 			return 0;
    106  1.21.4.1   rmind 		break;
    107      1.12   perry 
    108  1.21.4.1   rmind 	case MARVELL_ORION_1_88F5180N:
    109  1.21.4.1   rmind 	case MARVELL_ORION_1_88F5181:
    110  1.21.4.1   rmind 	case MARVELL_ORION_1_88F5182:
    111  1.21.4.1   rmind 	case MARVELL_ORION_2_88F5281:
    112  1.21.4.1   rmind 	case MARVELL_ORION_1_88W8660:
    113  1.21.4.1   rmind 		if (mva->mva_offset == GTCF_OFFSET_DEFAULT)
    114  1.21.4.1   rmind 			return 0;
    115  1.21.4.1   rmind 		mva->mva_unit = 0;	/* unit 0 only */
    116  1.21.4.1   rmind 		break;
    117       1.1    matt 
    118  1.21.4.1   rmind 	default:
    119  1.21.4.1   rmind 		return 0;
    120  1.21.4.1   rmind 	}
    121       1.1    matt 
    122  1.21.4.1   rmind 	mva->mva_size = GTPCI_SIZE;
    123  1.21.4.1   rmind 	return 1;
    124       1.1    matt }
    125       1.1    matt 
    126  1.21.4.1   rmind /* ARGSUSED */
    127  1.21.4.1   rmind static void
    128      1.21  cegger gtpci_attach(device_t parent, device_t self, void *aux)
    129       1.1    matt {
    130  1.21.4.1   rmind 	struct gtpci_softc *sc = device_private(self);
    131  1.21.4.1   rmind 	struct marvell_attach_args *mva = aux;
    132  1.21.4.1   rmind #if NPCI > 0
    133  1.21.4.1   rmind 	prop_dictionary_t dict = device_properties(self);
    134  1.21.4.1   rmind 	prop_object_t pc, iot, memt;
    135  1.21.4.1   rmind 	prop_array_t int2gpp;
    136  1.21.4.1   rmind 	prop_object_t gpp;
    137  1.21.4.1   rmind 	pci_chipset_tag_t gtpci_chipset;
    138  1.21.4.1   rmind 	bus_space_tag_t gtpci_io_bs_tag, gtpci_mem_bs_tag;
    139  1.21.4.1   rmind 	uint64_t iostart = 0, ioend = 0, memstart = 0, memend = 0;
    140  1.21.4.1   rmind 	int cl_size = 0, intr;
    141  1.21.4.1   rmind #endif
    142       1.1    matt 
    143  1.21.4.1   rmind 	aprint_normal(": Marvell PCI Interface\n");
    144  1.21.4.1   rmind 	aprint_naive("\n");
    145  1.21.4.1   rmind 
    146  1.21.4.1   rmind #if NPCI > 0
    147  1.21.4.1   rmind 	iot = prop_dictionary_get(dict, "io-bus-tag");
    148  1.21.4.1   rmind 	if (iot == NULL)
    149  1.21.4.1   rmind 		aprint_error_dev(self, "no io-bus-tag property\n");
    150  1.21.4.1   rmind 	KASSERT(prop_object_type(iot) == PROP_TYPE_DATA);
    151  1.21.4.1   rmind 	gtpci_io_bs_tag = __UNCONST(prop_data_data_nocopy(iot));
    152  1.21.4.1   rmind 	memt = prop_dictionary_get(dict, "mem-bus-tag");
    153  1.21.4.1   rmind 	if (memt == NULL)
    154  1.21.4.1   rmind 		aprint_error_dev(self, "no mem-bus-tag property\n");
    155  1.21.4.1   rmind 	KASSERT(prop_object_type(memt) == PROP_TYPE_DATA);
    156  1.21.4.1   rmind 	gtpci_mem_bs_tag = __UNCONST(prop_data_data_nocopy(memt));
    157  1.21.4.1   rmind 	pc = prop_dictionary_get(dict, "pci-chipset");
    158  1.21.4.1   rmind 	if (pc == NULL) {
    159  1.21.4.1   rmind 		aprint_error_dev(self, "no pci-chipset property\n");
    160  1.21.4.1   rmind 		return;
    161  1.21.4.1   rmind 	}
    162  1.21.4.1   rmind 	KASSERT(prop_object_type(pc) == PROP_TYPE_DATA);
    163  1.21.4.1   rmind 	gtpci_chipset = __UNCONST(prop_data_data_nocopy(pc));
    164  1.21.4.1   rmind #ifdef PCI_NETBSD_CONFIGURE
    165  1.21.4.1   rmind 	if (!prop_dictionary_get_uint64(dict, "iostart", &iostart)) {
    166  1.21.4.1   rmind 		aprint_error_dev(self, "no iostart property\n");
    167  1.21.4.1   rmind 		return;
    168  1.21.4.1   rmind 	}
    169  1.21.4.1   rmind 	if (!prop_dictionary_get_uint64(dict, "ioend", &ioend)) {
    170  1.21.4.1   rmind 		aprint_error_dev(self, "no ioend property\n");
    171  1.21.4.1   rmind 		return;
    172  1.21.4.1   rmind 	}
    173  1.21.4.1   rmind 	if (!prop_dictionary_get_uint64(dict, "memstart", &memstart)) {
    174  1.21.4.1   rmind 		aprint_error_dev(self, "no memstart property\n");
    175       1.2    matt 		return;
    176       1.2    matt 	}
    177  1.21.4.1   rmind 	if (!prop_dictionary_get_uint64(dict, "memend", &memend)) {
    178  1.21.4.1   rmind 		aprint_error_dev(self, "no memend property\n");
    179  1.21.4.1   rmind 		return;
    180  1.21.4.1   rmind 	}
    181  1.21.4.1   rmind 	if (!prop_dictionary_get_uint32(dict, "cache-line-size", &cl_size)) {
    182  1.21.4.1   rmind 		aprint_error_dev(self, "no cache-line-size property\n");
    183  1.21.4.1   rmind 		return;
    184  1.21.4.1   rmind 	}
    185  1.21.4.1   rmind #endif
    186  1.21.4.1   rmind #endif
    187       1.2    matt 
    188  1.21.4.1   rmind 	sc->sc_dev = self;
    189  1.21.4.1   rmind 	sc->sc_model = mva->mva_model;
    190  1.21.4.1   rmind 	sc->sc_rev = mva->mva_revision;
    191  1.21.4.1   rmind 	sc->sc_unit = mva->mva_unit;
    192  1.21.4.1   rmind 	sc->sc_iot = mva->mva_iot;
    193  1.21.4.1   rmind 	if (bus_space_subregion(mva->mva_iot, mva->mva_ioh,
    194  1.21.4.1   rmind 	    (mva->mva_offset != GTCF_OFFSET_DEFAULT) ? mva->mva_offset : 0,
    195  1.21.4.1   rmind 	    mva->mva_size, &sc->sc_ioh)) {
    196  1.21.4.1   rmind 		aprint_error_dev(self, "can't map registers\n");
    197  1.21.4.1   rmind 		return;
    198  1.21.4.1   rmind 	}
    199  1.21.4.1   rmind 	sc->sc_pc = gtpci_chipset;
    200  1.21.4.1   rmind 	gtpci_init(sc);
    201       1.2    matt 
    202  1.21.4.1   rmind #if NPCI > 0
    203  1.21.4.1   rmind 	int2gpp = prop_dictionary_get(dict, "int2gpp");
    204  1.21.4.1   rmind 	if (int2gpp != NULL) {
    205  1.21.4.1   rmind 		if (prop_object_type(int2gpp) != PROP_TYPE_ARRAY) {
    206  1.21.4.1   rmind 			aprint_error_dev(self, "int2gpp not an array\n");
    207  1.21.4.1   rmind 			return;
    208  1.21.4.1   rmind 		}
    209  1.21.4.1   rmind 		aprint_normal_dev(self, "use intrrupt pin:");
    210  1.21.4.1   rmind 		for (intr = PCI_INTERRUPT_PIN_A;
    211  1.21.4.1   rmind 		    intr <= PCI_INTERRUPT_PIN_D &&
    212  1.21.4.1   rmind 					intr < prop_array_count(int2gpp);
    213  1.21.4.1   rmind 		    intr++) {
    214  1.21.4.1   rmind 			gpp = prop_array_get(int2gpp, intr);
    215  1.21.4.1   rmind 			if (prop_object_type(gpp) != PROP_TYPE_NUMBER) {
    216  1.21.4.1   rmind 				aprint_error_dev(self,
    217  1.21.4.1   rmind 				    "int2gpp[%d] not an number\n", intr);
    218  1.21.4.1   rmind 				return;
    219  1.21.4.1   rmind 			}
    220  1.21.4.1   rmind 			aprint_normal(" %d",
    221  1.21.4.1   rmind 			    (int)prop_number_integer_value(gpp));
    222  1.21.4.1   rmind 		}
    223  1.21.4.1   rmind 		aprint_normal("\n");
    224  1.21.4.1   rmind 	}
    225       1.1    matt 
    226  1.21.4.1   rmind 	gtpci_pci_config(sc, gtpci_io_bs_tag, gtpci_mem_bs_tag, mva->mva_dmat,
    227  1.21.4.1   rmind 	    gtpci_chipset, iostart, ioend, memstart, memend, cl_size);
    228  1.21.4.1   rmind #endif
    229  1.21.4.1   rmind }
    230       1.1    matt 
    231  1.21.4.1   rmind static void
    232  1.21.4.1   rmind gtpci_init(struct gtpci_softc *sc)
    233  1.21.4.1   rmind {
    234  1.21.4.1   rmind 	uint32_t reg;
    235       1.1    matt 
    236  1.21.4.1   rmind 	/* First, all disable.  Also WA CQ 4382 (bit15 must set 1)*/
    237  1.21.4.1   rmind 	GTPCI_WRITE(sc, GTPCI_BARE, GTPCI_BARE_ALLDISABLE | (1 << 15));
    238       1.1    matt 
    239  1.21.4.1   rmind 	/* Enable Internal Arbiter */
    240  1.21.4.1   rmind 	reg = GTPCI_READ(sc, GTPCI_AC);
    241  1.21.4.1   rmind 	reg |= GTPCI_AC_EN;
    242  1.21.4.1   rmind 	GTPCI_WRITE(sc, GTPCI_AC, reg);
    243  1.21.4.1   rmind 
    244  1.21.4.1   rmind 	gtpci_barinit(sc);
    245  1.21.4.1   rmind 	gtpci_protinit(sc);
    246  1.21.4.1   rmind 
    247  1.21.4.1   rmind 	reg = GTPCI_READ(sc, GTPCI_ADC);
    248  1.21.4.1   rmind 	reg |= GTPCI_ADC_REMAPWRDIS;
    249  1.21.4.1   rmind 	GTPCI_WRITE(sc, GTPCI_ADC, reg);
    250  1.21.4.1   rmind 
    251  1.21.4.1   rmind 	/* enable CPU-2-PCI ordering */
    252  1.21.4.1   rmind 	reg = GTPCI_READ(sc, GTPCI_C);
    253  1.21.4.1   rmind 	reg |= GTPCI_C_CPU2PCIORDERING;
    254  1.21.4.1   rmind 	GTPCI_WRITE(sc, GTPCI_C, reg);
    255  1.21.4.1   rmind }
    256  1.21.4.1   rmind 
    257  1.21.4.1   rmind static void
    258  1.21.4.1   rmind gtpci_barinit(struct gtpci_softc *sc)
    259  1.21.4.1   rmind {
    260  1.21.4.1   rmind 	static const struct {
    261  1.21.4.1   rmind 		int tag;
    262  1.21.4.1   rmind 		int bars[2];	/* BAR Size registers */
    263  1.21.4.1   rmind 		int bare;	/* Bits of Base Address Registers Enable */
    264  1.21.4.1   rmind 		int func;
    265  1.21.4.1   rmind 		int balow;
    266  1.21.4.1   rmind 		int bahigh;
    267  1.21.4.1   rmind 	} maps[] = {
    268  1.21.4.1   rmind 		{ MARVELL_TAG_SDRAM_CS0,
    269  1.21.4.1   rmind 		  { GTPCI_CS0BARS(0),	GTPCI_CS0BARS(1) },
    270  1.21.4.1   rmind 		  GTPCI_BARE_CS0EN,	0, 0x10, 0x14 },
    271  1.21.4.1   rmind 		{ MARVELL_TAG_SDRAM_CS1,
    272  1.21.4.1   rmind 		  { GTPCI_CS1BARS(0),	GTPCI_CS1BARS(1) },
    273  1.21.4.1   rmind 		  GTPCI_BARE_CS1EN,	0, 0x18, 0x1c },
    274  1.21.4.1   rmind 		{ MARVELL_TAG_SDRAM_CS2,
    275  1.21.4.1   rmind 		  { GTPCI_CS2BARS(0),	GTPCI_CS2BARS(1) },
    276  1.21.4.1   rmind 		  GTPCI_BARE_CS2EN,	1, 0x10, 0x14 },
    277  1.21.4.1   rmind 		{ MARVELL_TAG_SDRAM_CS3,
    278  1.21.4.1   rmind 		  { GTPCI_CS3BARS(0),	GTPCI_CS3BARS(1) },
    279  1.21.4.1   rmind 		  GTPCI_BARE_CS3EN,	1, 0x18, 0x1c },
    280  1.21.4.1   rmind #if 0
    281  1.21.4.1   rmind 		{ ORION_TARGETID_INTERNALREG,
    282  1.21.4.1   rmind 		  { -1,			-1 },
    283  1.21.4.1   rmind 		  GTPCI_BARE_INTMEMEN,	0, 0x20, 0x24 },
    284  1.21.4.1   rmind 
    285  1.21.4.1   rmind 		{ ORION_TARGETID_DEVICE_CS0,
    286  1.21.4.1   rmind 		  { GTPCI_DCS0BARS(0),	GTPCI_DCS0BARS(1) },
    287  1.21.4.1   rmind 		  GTPCI_BARE_DEVCS0EN,	2, 0x10, 0x14 },
    288  1.21.4.1   rmind 		{ ORION_TARGETID_DEVICE_CS1,
    289  1.21.4.1   rmind 		  { GTPCI_DCS1BARS(0),	GTPCI_DCS1BARS(1) },
    290  1.21.4.1   rmind 		  GTPCI_BARE_DEVCS1EN,	2, 0x18, 0x1c },
    291  1.21.4.1   rmind 		{ ORION_TARGETID_DEVICE_CS2,
    292  1.21.4.1   rmind 		  { GTPCI_DCS2BARS(0),	GTPCI_DCS2BARS(1) },
    293  1.21.4.1   rmind 		  GTPCI_BARE_DEVCS2EN,	2, 0x20, 0x24 },
    294  1.21.4.1   rmind 		{ ORION_TARGETID_DEVICE_BOOTCS,
    295  1.21.4.1   rmind 		  { GTPCI_BCSBARS(0),	GTPCI_BCSBARS(1) },
    296  1.21.4.1   rmind 		  GTPCI_BARE_BOOTCSEN,	3, 0x18, 0x1c },
    297  1.21.4.1   rmind 		{ P2P Mem0 BAR,
    298  1.21.4.1   rmind 		  { GTPCI_P2PM0BARS(0),	GTPCI_P2PM0BARS(1) },
    299  1.21.4.1   rmind 		  GTPCI_BARE_P2PMEM0EN,	4, 0x10, 0x14 },
    300  1.21.4.1   rmind 		{ P2P I/O BAR,
    301  1.21.4.1   rmind 		  { GTPCI_P2PIOBARS(0),	GTPCI_P2PIOBARS(1) },
    302  1.21.4.1   rmind 		  GTPCI_BARE_P2PIO0EN,	4, 0x20, 0x24 },
    303  1.21.4.1   rmind 		{ Expansion ROM BAR,
    304  1.21.4.1   rmind 		  { GTPCI_EROMBARS(0),	GTPCI_EROMBARS(1) },
    305  1.21.4.1   rmind 		  0,				},
    306  1.21.4.1   rmind #endif
    307       1.1    matt 
    308  1.21.4.1   rmind 		{ MARVELL_TAG_UNDEFINED,
    309  1.21.4.1   rmind 		  { -1,			-1 },
    310  1.21.4.1   rmind 		  -1,				-1, 0x00, 0x00 },
    311  1.21.4.1   rmind 	};
    312  1.21.4.1   rmind 	device_t pdev = device_parent(sc->sc_dev);
    313  1.21.4.1   rmind 	uint64_t base;
    314  1.21.4.1   rmind 	uint32_t p2pc, size, bare;
    315  1.21.4.1   rmind 	int map, bus, dev, rv;
    316  1.21.4.1   rmind 
    317  1.21.4.1   rmind 	p2pc = GTPCI_READ(sc, GTPCI_P2PC);
    318  1.21.4.1   rmind 	bus = GTPCI_P2PC_BUSNUMBER(p2pc);
    319  1.21.4.1   rmind 	dev = GTPCI_P2PC_DEVNUM(p2pc);
    320  1.21.4.1   rmind 
    321  1.21.4.1   rmind 	bare = GTPCI_BARE_ALLDISABLE;
    322  1.21.4.1   rmind 	for (map = 0; maps[map].tag != MARVELL_TAG_UNDEFINED; map++) {
    323  1.21.4.1   rmind 		rv = marvell_winparams_by_tag(pdev, maps[map].tag, NULL, NULL,
    324  1.21.4.1   rmind 		    &base, &size);
    325  1.21.4.1   rmind 		if (rv != 0 || size == 0)
    326  1.21.4.1   rmind 			continue;
    327  1.21.4.1   rmind 
    328  1.21.4.1   rmind 		if (maps[map].bars[sc->sc_unit] != -1)
    329  1.21.4.1   rmind 			bus_space_write_4(sc->sc_iot, sc->sc_ioh,
    330  1.21.4.1   rmind 			    maps[map].bars[sc->sc_unit], GTPCI_BARSIZE(size));
    331  1.21.4.1   rmind 		bare &= ~maps[map].bare;
    332  1.21.4.1   rmind 
    333  1.21.4.1   rmind #if 0	/* shall move to pchb(4)? */
    334  1.21.4.1   rmind 		if (maps[map].func != -1) {
    335  1.21.4.1   rmind 			pcitag_t tag;
    336  1.21.4.1   rmind 			pcireg_t reg;
    337  1.21.4.1   rmind 
    338  1.21.4.1   rmind 			tag = gtpci_make_tag(NULL, bus, dev, maps[map].func);
    339  1.21.4.1   rmind 			reg = gtpci_conf_read(sc, tag, maps[map].balow);
    340  1.21.4.1   rmind 			reg &= ~GTPCI_BARLOW_MASK;
    341  1.21.4.1   rmind 			reg |= GTPCI_BARLOW_BASE(base);
    342  1.21.4.1   rmind 			gtpci_conf_write(sc, tag, maps[map].balow, reg);
    343  1.21.4.1   rmind 			reg = gtpci_conf_read(sc, tag, maps[map].bahigh);
    344  1.21.4.1   rmind 			reg = (base >> 16) >> 16;
    345  1.21.4.1   rmind 			gtpci_conf_write(sc, tag, maps[map].bahigh, reg);
    346       1.6    matt 		}
    347  1.21.4.1   rmind #endif
    348       1.9     scw 	}
    349  1.21.4.1   rmind 	GTPCI_WRITE(sc, GTPCI_BARE, bare);
    350       1.5    matt }
    351       1.5    matt 
    352  1.21.4.1   rmind static void
    353  1.21.4.1   rmind gtpci_protinit(struct gtpci_softc *sc)
    354       1.1    matt {
    355  1.21.4.1   rmind 	enum {
    356  1.21.4.1   rmind 		gt64260 = 0,
    357  1.21.4.1   rmind 		mv64360,
    358  1.21.4.1   rmind 		soc,
    359  1.21.4.1   rmind 	};
    360  1.21.4.1   rmind 	const struct gtpci_prot {
    361  1.21.4.1   rmind 		uint32_t acbl_flags;
    362  1.21.4.1   rmind 		uint32_t acbl_base_rshift;
    363  1.21.4.1   rmind 		uint32_t acs_flags;
    364  1.21.4.1   rmind 		uint32_t acs_size_rshift;
    365  1.21.4.1   rmind 	} gtpci_prots[] = {
    366  1.21.4.1   rmind 		{	/* GT64260 */
    367  1.21.4.1   rmind #if 0
    368  1.21.4.1   rmind 			GTPCI_GT64260_ACBL_PCISWAP_NOSWAP	|
    369  1.21.4.1   rmind 			GTPCI_GT64260_ACBL_WBURST_4_QW		|
    370  1.21.4.1   rmind 			GTPCI_GT64260_ACBL_RDMULPREFETCH	|
    371  1.21.4.1   rmind 			GTPCI_GT64260_ACBL_RDLINEPREFETCH	|
    372  1.21.4.1   rmind 			GTPCI_GT64260_ACBL_RDPREFETCH		|
    373  1.21.4.1   rmind 			GTPCI_GT64260_ACBL_DREADEN,
    374  1.21.4.1   rmind #else
    375  1.21.4.1   rmind 			GTPCI_GT64260_ACBL_PCISWAP_NOSWAP	|
    376  1.21.4.1   rmind 			GTPCI_GT64260_ACBL_WBURST_8_QW		|
    377  1.21.4.1   rmind 			GTPCI_GT64260_ACBL_RDMULPREFETCH	|
    378  1.21.4.1   rmind 			GTPCI_GT64260_ACBL_RDLINEPREFETCH	|
    379  1.21.4.1   rmind 			GTPCI_GT64260_ACBL_RDPREFETCH		|
    380  1.21.4.1   rmind 			GTPCI_GT64260_ACBL_PREFETCHEN,
    381       1.5    matt #endif
    382  1.21.4.1   rmind 			20,
    383  1.21.4.1   rmind 			0,
    384  1.21.4.1   rmind 			20
    385  1.21.4.1   rmind 		},
    386  1.21.4.1   rmind 		{	/* MV64360 and after */
    387  1.21.4.1   rmind 			GTPCI_ACBL_RDSIZE_256BYTE	|
    388  1.21.4.1   rmind 			GTPCI_ACBL_RDMBURST_128BYTE	|
    389  1.21.4.1   rmind 			GTPCI_ACBL_PCISWAP_NOSWAP	|
    390  1.21.4.1   rmind 			GTPCI_ACBL_SNOOP_NONE		|
    391  1.21.4.1   rmind 			GTPCI_ACBL_EN,
    392  1.21.4.1   rmind 			0,
    393  1.21.4.1   rmind 			0,
    394  1.21.4.1   rmind 			0
    395  1.21.4.1   rmind 		},
    396  1.21.4.1   rmind 		{	/* Orion */
    397  1.21.4.1   rmind 			GTPCI_ACBL_RDSIZE_256BYTE	|
    398  1.21.4.1   rmind 			GTPCI_ACBL_RDMBURST_128BYTE	|
    399  1.21.4.1   rmind 			GTPCI_ACBL_PCISWAP_BYTESWAP,
    400  1.21.4.1   rmind 			0,
    401  1.21.4.1   rmind 			GTPCI_ACS_WRMBURST_128BYTE,
    402  1.21.4.1   rmind 			0
    403  1.21.4.1   rmind 		},
    404  1.21.4.1   rmind 	};
    405  1.21.4.1   rmind 	const uint32_t prot_tags[] = {
    406  1.21.4.1   rmind 		MARVELL_TAG_SDRAM_CS0,
    407  1.21.4.1   rmind 		MARVELL_TAG_SDRAM_CS1,
    408  1.21.4.1   rmind 		MARVELL_TAG_SDRAM_CS2,
    409  1.21.4.1   rmind 		MARVELL_TAG_SDRAM_CS3,
    410  1.21.4.1   rmind 		MARVELL_TAG_UNDEFINED
    411  1.21.4.1   rmind 	};
    412  1.21.4.1   rmind 	device_t pdev = device_parent(sc->sc_dev);
    413  1.21.4.1   rmind 	uint64_t acbase, base;
    414  1.21.4.1   rmind 	uint32_t acsize, size;
    415  1.21.4.1   rmind 	int acbl_base_rshift, acbl_flags, acs_size_rshift, acs_flags;
    416  1.21.4.1   rmind 	int prot, rv, p, t;
    417  1.21.4.1   rmind 
    418  1.21.4.1   rmind 	switch (sc->sc_model) {
    419  1.21.4.1   rmind 	case MARVELL_DISCOVERY:
    420  1.21.4.1   rmind 		p = gt64260;
    421  1.21.4.1   rmind 		break;
    422       1.1    matt 
    423  1.21.4.1   rmind 	case MARVELL_DISCOVERY_II:
    424  1.21.4.1   rmind 	case MARVELL_DISCOVERY_III:
    425       1.3    matt #if 0
    426  1.21.4.1   rmind 	case MARVELL_DISCOVERY_LT:
    427  1.21.4.1   rmind 	case MARVELL_DISCOVERY_V:
    428  1.21.4.1   rmind 	case MARVELL_DISCOVERY_VI:
    429       1.3    matt #endif
    430  1.21.4.1   rmind 		p = mv64360;
    431  1.21.4.1   rmind 		break;
    432       1.1    matt 
    433  1.21.4.1   rmind 	default:
    434  1.21.4.1   rmind 		p = soc;
    435  1.21.4.1   rmind 		break;
    436  1.21.4.1   rmind 	}
    437  1.21.4.1   rmind 	acbl_base_rshift = gtpci_prots[p].acbl_base_rshift;
    438  1.21.4.1   rmind 	acbl_flags = gtpci_prots[p].acbl_flags;
    439  1.21.4.1   rmind 	acs_size_rshift = gtpci_prots[p].acs_size_rshift;
    440  1.21.4.1   rmind 	acs_flags = gtpci_prots[p].acs_flags;
    441  1.21.4.1   rmind 
    442  1.21.4.1   rmind 	t = 0;
    443  1.21.4.1   rmind 	for (prot = 0; prot < GTPCI_NPCIAC; prot++) {
    444  1.21.4.1   rmind 		acbase = acsize = 0;
    445  1.21.4.1   rmind 
    446  1.21.4.1   rmind 		for ( ; prot_tags[t] != MARVELL_TAG_UNDEFINED; t++) {
    447  1.21.4.1   rmind 			rv = marvell_winparams_by_tag(pdev, prot_tags[t],
    448  1.21.4.1   rmind 			    NULL, NULL, &base, &size);
    449  1.21.4.1   rmind 			if (rv != 0 || size == 0)
    450  1.21.4.1   rmind 				continue;
    451  1.21.4.1   rmind 
    452  1.21.4.1   rmind 			if (acsize == 0 || base + size == acbase)
    453  1.21.4.1   rmind 				acbase = base;
    454  1.21.4.1   rmind 			else if (acbase + acsize != base)
    455  1.21.4.1   rmind 				break;
    456  1.21.4.1   rmind 			acsize += size;
    457       1.6    matt 		}
    458       1.6    matt 
    459  1.21.4.1   rmind 		if (acsize != 0) {
    460  1.21.4.1   rmind 			GTPCI_WRITE_AC(sc, GTPCI_ACBL, prot,
    461  1.21.4.1   rmind 			    ((acbase & 0xffffffff) >> acbl_base_rshift) |
    462  1.21.4.1   rmind 			   					 acbl_flags);
    463  1.21.4.1   rmind 			GTPCI_WRITE_AC(sc, GTPCI_ACBH, prot,
    464  1.21.4.1   rmind 			    (acbase >> 32) & 0xffffffff);
    465  1.21.4.1   rmind 			GTPCI_WRITE_AC(sc, GTPCI_ACS, prot,
    466  1.21.4.1   rmind 			    ((acsize - 1) >> acs_size_rshift) | acs_flags);
    467  1.21.4.1   rmind 		} else {
    468  1.21.4.1   rmind 			GTPCI_WRITE_AC(sc, GTPCI_ACBL, prot, 0);
    469  1.21.4.1   rmind 			GTPCI_WRITE_AC(sc, GTPCI_ACBH, prot, 0);
    470  1.21.4.1   rmind 			GTPCI_WRITE_AC(sc, GTPCI_ACS, prot, 0);
    471       1.6    matt 		}
    472       1.6    matt 	}
    473  1.21.4.1   rmind 	return;
    474       1.1    matt }
    475       1.1    matt 
    476  1.21.4.1   rmind #if NPCI > 0
    477  1.21.4.1   rmind static void
    478  1.21.4.1   rmind gtpci_pci_config(struct gtpci_softc *sc, bus_space_tag_t iot,
    479  1.21.4.1   rmind 		 bus_space_tag_t memt, bus_dma_tag_t dmat, pci_chipset_tag_t pc,
    480  1.21.4.1   rmind 		 u_long iostart, u_long ioend, u_long memstart, u_long memend,
    481  1.21.4.1   rmind 		 int cacheline_size)
    482       1.1    matt {
    483  1.21.4.1   rmind 	struct pcibus_attach_args pba;
    484  1.21.4.1   rmind #ifdef PCI_NETBSD_CONFIGURE
    485  1.21.4.1   rmind 	struct extent *ioext = NULL, *memext = NULL;
    486  1.21.4.1   rmind #endif
    487  1.21.4.1   rmind 	uint32_t p2pc, command;
    488       1.1    matt 
    489  1.21.4.1   rmind 	p2pc = GTPCI_READ(sc, GTPCI_P2PC);
    490       1.1    matt 
    491  1.21.4.1   rmind #ifdef PCI_NETBSD_CONFIGURE
    492  1.21.4.1   rmind 	ioext = extent_create("pciio", iostart, ioend, M_DEVBUF, NULL, 0,
    493  1.21.4.1   rmind 	    EX_NOWAIT);
    494  1.21.4.1   rmind 	memext = extent_create("pcimem", memstart, memend, M_DEVBUF, NULL, 0,
    495  1.21.4.1   rmind 	    EX_NOWAIT);
    496  1.21.4.1   rmind 	if (ioext != NULL && memext != NULL)
    497  1.21.4.1   rmind 		pci_configure_bus(pc, ioext, memext, NULL,
    498  1.21.4.1   rmind 		    GTPCI_P2PC_BUSNUMBER(p2pc), cacheline_size);
    499  1.21.4.1   rmind 	else
    500  1.21.4.1   rmind 		aprint_error_dev(sc->sc_dev, "can't create extent %s%s%s\n",
    501  1.21.4.1   rmind 		    ioext == NULL ? "io" : "",
    502  1.21.4.1   rmind 		    ioext == NULL && memext == NULL ? " and " : "",
    503  1.21.4.1   rmind 		    memext == NULL ? "mem" : "");
    504  1.21.4.1   rmind 	if (ioext != NULL)
    505  1.21.4.1   rmind 		extent_destroy(ioext);
    506  1.21.4.1   rmind 	if (memext != NULL)
    507  1.21.4.1   rmind 		extent_destroy(memext);
    508       1.1    matt #endif
    509  1.21.4.1   rmind 
    510  1.21.4.1   rmind 	pba.pba_iot = iot;
    511  1.21.4.1   rmind 	pba.pba_memt = memt;
    512  1.21.4.1   rmind 	pba.pba_dmat = dmat;
    513  1.21.4.1   rmind 	pba.pba_dmat64 = NULL;
    514  1.21.4.1   rmind 	pba.pba_pc = pc;
    515  1.21.4.1   rmind 	if (iot == NULL || memt == NULL) {
    516  1.21.4.1   rmind 		pba.pba_flags = 0;
    517  1.21.4.1   rmind 		aprint_error_dev(sc->sc_dev, "");
    518  1.21.4.1   rmind 		if (iot == NULL)
    519  1.21.4.1   rmind 			aprint_error("io ");
    520  1.21.4.1   rmind 		else
    521  1.21.4.1   rmind 			pba.pba_flags |= PCI_FLAGS_IO_ENABLED;
    522  1.21.4.1   rmind 		if (iot == NULL && memt == NULL)
    523  1.21.4.1   rmind 			aprint_error("and ");
    524  1.21.4.1   rmind 		if (memt == NULL)
    525  1.21.4.1   rmind 			aprint_error("mem");
    526  1.21.4.1   rmind 		else
    527  1.21.4.1   rmind 			pba.pba_flags |= PCI_FLAGS_MEM_ENABLED;
    528  1.21.4.1   rmind 		aprint_error(" access disabled\n");
    529  1.21.4.1   rmind 	} else
    530  1.21.4.1   rmind 		pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
    531  1.21.4.1   rmind 	command = GTPCI_READ(sc, GTPCI_C);
    532  1.21.4.1   rmind 	if (command & GTPCI_C_MRDMUL)
    533  1.21.4.1   rmind 		pba.pba_flags |= PCI_FLAGS_MRM_OKAY;
    534  1.21.4.1   rmind 	if (command & GTPCI_C_MRDLINE)
    535  1.21.4.1   rmind 		pba.pba_flags |= PCI_FLAGS_MRL_OKAY;
    536  1.21.4.1   rmind 	pba.pba_flags |= PCI_FLAGS_MWI_OKAY;
    537  1.21.4.1   rmind 	pba.pba_bus = GTPCI_P2PC_BUSNUMBER(p2pc);
    538  1.21.4.1   rmind 	pba.pba_bridgetag = NULL;
    539  1.21.4.1   rmind 	config_found_ia(sc->sc_dev, "pcibus", &pba, NULL);
    540       1.1    matt }
    541       1.1    matt 
    542       1.1    matt 
    543  1.21.4.1   rmind /*
    544  1.21.4.1   rmind  * Dependent code of PCI Interface of Marvell
    545  1.21.4.1   rmind  */
    546  1.21.4.1   rmind 
    547  1.21.4.1   rmind /* ARGSUSED */
    548       1.1    matt void
    549  1.21.4.1   rmind gtpci_attach_hook(device_t parent, device_t self,
    550  1.21.4.1   rmind 		  struct pcibus_attach_args *pba)
    551       1.1    matt {
    552  1.21.4.1   rmind 
    553  1.21.4.1   rmind 	/* Nothing */
    554       1.1    matt }
    555       1.1    matt 
    556       1.1    matt /*
    557  1.21.4.1   rmind  * Bit map for configuration register:
    558  1.21.4.1   rmind  *   [31]    ConfigEn
    559  1.21.4.1   rmind  *   [30:24] Reserved
    560  1.21.4.1   rmind  *   [23:16] BusNum
    561  1.21.4.1   rmind  *   [15:11] DevNum
    562  1.21.4.1   rmind  *   [10: 8] FunctNum
    563  1.21.4.1   rmind  *   [ 7: 2] RegNum
    564  1.21.4.1   rmind  *   [ 1: 0] reserved
    565       1.1    matt  */
    566  1.21.4.1   rmind 
    567  1.21.4.1   rmind /* ARGSUSED */
    568       1.1    matt int
    569  1.21.4.1   rmind gtpci_bus_maxdevs(void *v, int busno)
    570       1.1    matt {
    571  1.21.4.1   rmind 
    572  1.21.4.1   rmind 	return 32;	/* 32 device/bus */
    573       1.1    matt }
    574       1.1    matt 
    575  1.21.4.1   rmind /* ARGSUSED */
    576       1.1    matt pcitag_t
    577  1.21.4.1   rmind gtpci_make_tag(void *v, int bus, int dev, int func)
    578       1.1    matt {
    579  1.21.4.1   rmind 
    580  1.21.4.1   rmind #if DIAGNOSTIC
    581  1.21.4.1   rmind 	if (bus >= 256 || dev >= 32 || func >= 8)
    582  1.21.4.1   rmind 		panic("pci_make_tag: bad request");
    583  1.21.4.1   rmind #endif
    584  1.21.4.1   rmind 
    585  1.21.4.1   rmind 	return (bus << 16) | (dev << 11) | (func << 8);
    586       1.1    matt }
    587       1.1    matt 
    588  1.21.4.1   rmind /* ARGSUSED */
    589       1.1    matt void
    590  1.21.4.1   rmind gtpci_decompose_tag(void *v, pcitag_t tag, int *bp, int *dp, int *fp)
    591       1.1    matt {
    592  1.21.4.1   rmind 
    593       1.1    matt 	if (bp != NULL)
    594  1.21.4.1   rmind 		*bp = (tag >> 16) & 0xff;
    595       1.1    matt 	if (dp != NULL)
    596  1.21.4.1   rmind 		*dp = (tag >> 11) & 0x1f;
    597       1.1    matt 	if (fp != NULL)
    598  1.21.4.1   rmind 		*fp = (tag >> 8) & 0x07;
    599       1.1    matt }
    600       1.1    matt 
    601       1.1    matt pcireg_t
    602  1.21.4.1   rmind gtpci_conf_read(void *v, pcitag_t tag, int reg)
    603       1.1    matt {
    604  1.21.4.1   rmind 	struct gtpci_softc *sc = v;
    605  1.21.4.1   rmind 	const pcireg_t addr = tag | reg;
    606  1.21.4.1   rmind 
    607  1.21.4.1   rmind 	GTPCI_WRITE(sc, GTPCI_CA, addr | GTPCI_CA_CONFIGEN);
    608  1.21.4.1   rmind 	if ((addr | GTPCI_CA_CONFIGEN) != GTPCI_READ(sc, GTPCI_CA))
    609  1.21.4.1   rmind 		return -1;
    610  1.21.4.1   rmind 
    611  1.21.4.1   rmind 	return GTPCI_READ(sc, GTPCI_CD);
    612       1.1    matt }
    613       1.1    matt 
    614       1.1    matt void
    615  1.21.4.1   rmind gtpci_conf_write(void *v, pcitag_t tag, int reg, pcireg_t data)
    616       1.1    matt {
    617  1.21.4.1   rmind 	struct gtpci_softc *sc = v;
    618  1.21.4.1   rmind 	pcireg_t addr = tag | (reg & 0xfc);
    619       1.1    matt 
    620  1.21.4.1   rmind 	GTPCI_WRITE(sc, GTPCI_CA, addr | GTPCI_CA_CONFIGEN);
    621  1.21.4.1   rmind 	if ((addr | GTPCI_CA_CONFIGEN) != GTPCI_READ(sc, GTPCI_CA))
    622  1.21.4.1   rmind 		return;
    623       1.1    matt 
    624  1.21.4.1   rmind 	GTPCI_WRITE(sc, GTPCI_CD, data);
    625       1.1    matt }
    626       1.1    matt 
    627  1.21.4.1   rmind /* ARGSUSED */
    628  1.21.4.1   rmind int
    629  1.21.4.1   rmind gtpci_conf_hook(pci_chipset_tag_t pc, int bus, int dev, int func, pcireg_t id)
    630       1.1    matt {
    631  1.21.4.1   rmind 	/* Oops, We have two PCI buses. */
    632  1.21.4.1   rmind 	if (dev == 0 &&
    633  1.21.4.1   rmind 	    PCI_VENDOR(id) == PCI_VENDOR_MARVELL) {
    634  1.21.4.1   rmind 		switch (PCI_PRODUCT(id)) {
    635  1.21.4.1   rmind 		case MARVELL_DISCOVERY:
    636  1.21.4.1   rmind 		case MARVELL_DISCOVERY_II:
    637  1.21.4.1   rmind 		case MARVELL_DISCOVERY_III:
    638  1.21.4.1   rmind #if 0
    639  1.21.4.1   rmind 		case MARVELL_DISCOVERY_LT:
    640  1.21.4.1   rmind 		case MARVELL_DISCOVERY_V:
    641  1.21.4.1   rmind 		case MARVELL_DISCOVERY_VI:
    642  1.21.4.1   rmind #endif
    643  1.21.4.1   rmind 		case MARVELL_ORION_1_88F5180N:
    644  1.21.4.1   rmind 		case MARVELL_ORION_1_88F5181:
    645  1.21.4.1   rmind 		case MARVELL_ORION_1_88F5182:
    646  1.21.4.1   rmind 		case MARVELL_ORION_2_88F5281:
    647  1.21.4.1   rmind 		case MARVELL_ORION_1_88W8660:
    648  1.21.4.1   rmind 			/* Don't configure us. */
    649  1.21.4.1   rmind 			return 0;
    650  1.21.4.1   rmind 		}
    651  1.21.4.1   rmind 	}
    652       1.1    matt 
    653  1.21.4.1   rmind 	return PCI_CONF_DEFAULT;
    654       1.1    matt }
    655  1.21.4.1   rmind #endif	/* NPCI > 0 */
    656