Home | History | Annotate | Line # | Download | only in marvell
mvpex.c revision 1.14
      1  1.14  knakahar /*	$NetBSD: mvpex.c,v 1.14 2015/07/28 01:57:55 knakahara Exp $	*/
      2   1.1  kiyohara /*
      3   1.1  kiyohara  * Copyright (c) 2008 KIYOHARA Takashi
      4   1.1  kiyohara  * All rights reserved.
      5   1.1  kiyohara  *
      6   1.1  kiyohara  * Redistribution and use in source and binary forms, with or without
      7   1.1  kiyohara  * modification, are permitted provided that the following conditions
      8   1.1  kiyohara  * are met:
      9   1.1  kiyohara  * 1. Redistributions of source code must retain the above copyright
     10   1.1  kiyohara  *    notice, this list of conditions and the following disclaimer.
     11   1.1  kiyohara  * 2. Redistributions in binary form must reproduce the above copyright
     12   1.1  kiyohara  *    notice, this list of conditions and the following disclaimer in the
     13   1.1  kiyohara  *    documentation and/or other materials provided with the distribution.
     14   1.1  kiyohara  *
     15   1.1  kiyohara  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     16   1.1  kiyohara  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     17   1.1  kiyohara  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     18   1.1  kiyohara  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     19   1.1  kiyohara  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     20   1.1  kiyohara  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     21   1.1  kiyohara  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22   1.1  kiyohara  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     23   1.1  kiyohara  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     24   1.1  kiyohara  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25   1.1  kiyohara  * POSSIBILITY OF SUCH DAMAGE.
     26   1.1  kiyohara  */
     27   1.1  kiyohara 
     28   1.1  kiyohara #include <sys/cdefs.h>
     29  1.14  knakahar __KERNEL_RCSID(0, "$NetBSD: mvpex.c,v 1.14 2015/07/28 01:57:55 knakahara Exp $");
     30   1.1  kiyohara 
     31   1.1  kiyohara #include "opt_pci.h"
     32   1.1  kiyohara #include "pci.h"
     33   1.1  kiyohara 
     34   1.1  kiyohara #include <sys/param.h>
     35   1.1  kiyohara #include <sys/bus.h>
     36   1.1  kiyohara #include <sys/device.h>
     37   1.1  kiyohara #include <sys/errno.h>
     38   1.1  kiyohara #include <sys/extent.h>
     39   1.1  kiyohara #include <sys/evcnt.h>
     40   1.1  kiyohara #include <sys/malloc.h>
     41   1.1  kiyohara #include <sys/systm.h>
     42   1.1  kiyohara 
     43   1.1  kiyohara #include <prop/proplib.h>
     44   1.1  kiyohara 
     45   1.1  kiyohara #include <dev/pci/pcivar.h>
     46   1.1  kiyohara #include <dev/pci/pcireg.h>
     47   1.1  kiyohara #include <dev/pci/pciconf.h>
     48   1.1  kiyohara 
     49   1.1  kiyohara #include <dev/marvell/mvpexreg.h>
     50   1.1  kiyohara #include <dev/marvell/mvpexvar.h>
     51   1.1  kiyohara #include <dev/marvell/marvellreg.h>
     52   1.1  kiyohara #include <dev/marvell/marvellvar.h>
     53   1.1  kiyohara 
     54   1.1  kiyohara #include <machine/pci_machdep.h>
     55   1.1  kiyohara 
     56   1.1  kiyohara #include "locators.h"
     57   1.1  kiyohara 
     58   1.1  kiyohara 
     59   1.1  kiyohara static int mvpex_match(device_t, struct cfdata *, void *);
     60   1.1  kiyohara static void mvpex_attach(device_t, device_t, void *);
     61   1.1  kiyohara 
     62   1.1  kiyohara static int mvpex_intr(void *);
     63   1.1  kiyohara 
     64   1.9  kiyohara static void mvpex_init(struct mvpex_softc *, enum marvell_tags *);
     65   1.1  kiyohara #if 0	/* shall move to pchb(4)? */
     66   1.1  kiyohara static void mvpex_barinit(struct mvpex_softc *);
     67   1.1  kiyohara static int mvpex_wininit(struct mvpex_softc *, int, int, int, int, uint32_t *,
     68   1.1  kiyohara 			 uint32_t *);
     69   1.1  kiyohara #else
     70   1.9  kiyohara static void mvpex_wininit(struct mvpex_softc *, enum marvell_tags *);
     71   1.1  kiyohara #endif
     72   1.1  kiyohara #if NPCI > 0
     73   1.1  kiyohara static void mvpex_pci_config(struct mvpex_softc *, bus_space_tag_t,
     74   1.1  kiyohara 			     bus_space_tag_t, bus_dma_tag_t, pci_chipset_tag_t,
     75   1.1  kiyohara 			     u_long, u_long, u_long, u_long, int);
     76   1.1  kiyohara #endif
     77   1.1  kiyohara 
     78   1.9  kiyohara enum marvell_tags *mvpex_bar2_tags;
     79   1.9  kiyohara 
     80   1.1  kiyohara CFATTACH_DECL_NEW(mvpex_gt, sizeof(struct mvpex_softc),
     81   1.1  kiyohara     mvpex_match, mvpex_attach, NULL, NULL);
     82   1.1  kiyohara CFATTACH_DECL_NEW(mvpex_mbus, sizeof(struct mvpex_softc),
     83   1.1  kiyohara     mvpex_match, mvpex_attach, NULL, NULL);
     84   1.1  kiyohara 
     85   1.1  kiyohara 
     86   1.1  kiyohara /* ARGSUSED */
     87   1.1  kiyohara static int
     88   1.1  kiyohara mvpex_match(device_t parent, struct cfdata *match, void *aux)
     89   1.1  kiyohara {
     90   1.1  kiyohara 	struct marvell_attach_args *mva = aux;
     91   1.1  kiyohara 
     92   1.2  kiyohara 	if (strcmp(mva->mva_name, match->cf_name) != 0)
     93   1.1  kiyohara 		return 0;
     94   1.1  kiyohara 	if (mva->mva_offset == MVA_OFFSET_DEFAULT ||
     95   1.1  kiyohara 	    mva->mva_irq == MVA_IRQ_DEFAULT)
     96   1.1  kiyohara 		return 0;
     97   1.1  kiyohara 
     98   1.1  kiyohara 	mva->mva_size = MVPEX_SIZE;
     99   1.1  kiyohara 	return 1;
    100   1.1  kiyohara }
    101   1.1  kiyohara 
    102   1.1  kiyohara /* ARGSUSED */
    103   1.1  kiyohara static void
    104   1.1  kiyohara mvpex_attach(device_t parent, device_t self, void *aux)
    105   1.1  kiyohara {
    106   1.1  kiyohara 	struct mvpex_softc *sc = device_private(self);
    107   1.1  kiyohara 	struct marvell_attach_args *mva = aux;
    108   1.1  kiyohara #if NPCI > 0
    109   1.1  kiyohara 	prop_dictionary_t dict = device_properties(self);
    110   1.1  kiyohara 	prop_object_t pc, iot, memt;
    111   1.1  kiyohara 	pci_chipset_tag_t mvpex_chipset;
    112   1.1  kiyohara 	bus_space_tag_t mvpex_io_bs_tag, mvpex_mem_bs_tag;
    113   1.1  kiyohara 	uint64_t iostart = 0, ioend = 0, memstart = 0, memend = 0;
    114   1.3  jakllsch 	uint32_t cl_size = 0;
    115   1.1  kiyohara 	int i;
    116   1.1  kiyohara #endif
    117   1.1  kiyohara 
    118   1.1  kiyohara 	aprint_normal(": Marvell PCI Express Interface\n");
    119   1.1  kiyohara 	aprint_naive("\n");
    120   1.1  kiyohara 
    121   1.1  kiyohara #if NPCI > 0
    122   1.1  kiyohara 	iot = prop_dictionary_get(dict, "io-bus-tag");
    123   1.1  kiyohara 	if (iot == NULL) {
    124   1.1  kiyohara 		aprint_error_dev(self, "no io-bus-tag property\n");
    125   1.1  kiyohara 		return;
    126   1.1  kiyohara 	}
    127   1.1  kiyohara 	KASSERT(prop_object_type(iot) == PROP_TYPE_DATA);
    128   1.1  kiyohara 	mvpex_io_bs_tag = __UNCONST(prop_data_data_nocopy(iot));
    129   1.1  kiyohara 	memt = prop_dictionary_get(dict, "mem-bus-tag");
    130   1.1  kiyohara 	if (memt == NULL) {
    131   1.1  kiyohara 		aprint_error_dev(self, "no mem-bus-tag property\n");
    132   1.1  kiyohara 		return;
    133   1.1  kiyohara 	}
    134   1.1  kiyohara 	KASSERT(prop_object_type(memt) == PROP_TYPE_DATA);
    135   1.1  kiyohara 	mvpex_mem_bs_tag = __UNCONST(prop_data_data_nocopy(memt));
    136   1.1  kiyohara 	pc = prop_dictionary_get(dict, "pci-chipset");
    137   1.1  kiyohara 	if (pc == NULL) {
    138   1.1  kiyohara 		aprint_error_dev(self, "no pci-chipset property\n");
    139   1.1  kiyohara 		return;
    140   1.1  kiyohara 	}
    141   1.1  kiyohara 	KASSERT(prop_object_type(pc) == PROP_TYPE_DATA);
    142   1.1  kiyohara 	mvpex_chipset = __UNCONST(prop_data_data_nocopy(pc));
    143   1.1  kiyohara #ifdef PCI_NETBSD_CONFIGURE
    144   1.1  kiyohara 	if (!prop_dictionary_get_uint64(dict, "iostart", &iostart)) {
    145   1.1  kiyohara 		aprint_error_dev(self, "no iostart property\n");
    146   1.1  kiyohara 		return;
    147   1.1  kiyohara 	}
    148   1.1  kiyohara 	if (!prop_dictionary_get_uint64(dict, "ioend", &ioend)) {
    149   1.1  kiyohara 		aprint_error_dev(self, "no ioend property\n");
    150   1.1  kiyohara 		return;
    151   1.1  kiyohara 	}
    152   1.1  kiyohara 	if (!prop_dictionary_get_uint64(dict, "memstart", &memstart)) {
    153   1.1  kiyohara 		aprint_error_dev(self, "no memstart property\n");
    154   1.1  kiyohara 		return;
    155   1.1  kiyohara 	}
    156   1.1  kiyohara 	if (!prop_dictionary_get_uint64(dict, "memend", &memend)) {
    157   1.1  kiyohara 		aprint_error_dev(self, "no memend property\n");
    158   1.1  kiyohara 		return;
    159   1.1  kiyohara 	}
    160   1.1  kiyohara 	if (!prop_dictionary_get_uint32(dict, "cache-line-size", &cl_size)) {
    161   1.1  kiyohara 		aprint_error_dev(self, "no cache-line-size property\n");
    162   1.1  kiyohara 		return;
    163   1.1  kiyohara 	}
    164   1.1  kiyohara #endif
    165   1.1  kiyohara #endif
    166   1.1  kiyohara 
    167   1.1  kiyohara 	sc->sc_dev = self;
    168   1.1  kiyohara 	sc->sc_model = mva->mva_model;
    169   1.1  kiyohara 	sc->sc_rev = mva->mva_revision;
    170   1.1  kiyohara 	sc->sc_offset = mva->mva_offset;
    171   1.1  kiyohara 	sc->sc_iot = mva->mva_iot;
    172   1.1  kiyohara 
    173   1.1  kiyohara 	/* Map I/O registers for mvpex */
    174   1.1  kiyohara 	if (bus_space_subregion(mva->mva_iot, mva->mva_ioh, mva->mva_offset,
    175   1.1  kiyohara 	    mva->mva_size, &sc->sc_ioh)) {
    176   1.1  kiyohara 		aprint_error_dev(self, "can't map registers\n");
    177   1.1  kiyohara 		return;
    178   1.1  kiyohara 	}
    179   1.9  kiyohara 	mvpex_init(sc, mva->mva_tags);
    180   1.1  kiyohara 
    181   1.1  kiyohara 	/* XXX: looks seem good to specify level IPL_VM. */
    182   1.1  kiyohara 	marvell_intr_establish(mva->mva_irq, IPL_VM, mvpex_intr, sc);
    183   1.1  kiyohara 
    184   1.1  kiyohara #if NPCI > 0
    185   1.1  kiyohara 	for (i = 0; i < PCI_INTERRUPT_PIN_MAX; i++) {
    186   1.1  kiyohara 		sc->sc_intrtab[i].intr_pin = PCI_INTERRUPT_PIN_A + i;
    187   1.1  kiyohara 		sc->sc_intrtab[i].intr_refcnt = 0;
    188   1.1  kiyohara 		LIST_INIT(&sc->sc_intrtab[i].intr_list);
    189   1.1  kiyohara 	}
    190   1.1  kiyohara 
    191   1.1  kiyohara 	mvpex_pci_config(sc, mvpex_io_bs_tag, mvpex_mem_bs_tag, mva->mva_dmat,
    192   1.1  kiyohara 	    mvpex_chipset, iostart, ioend, memstart, memend, cl_size);
    193   1.1  kiyohara #endif
    194   1.1  kiyohara }
    195   1.1  kiyohara 
    196   1.1  kiyohara static int
    197   1.1  kiyohara mvpex_intr(void *arg)
    198   1.1  kiyohara {
    199   1.1  kiyohara 	struct mvpex_softc *sc = (struct mvpex_softc *)arg;
    200   1.1  kiyohara 	struct mvpex_intrhand *ih;
    201   1.1  kiyohara 	struct mvpex_intrtab *intrtab;
    202   1.1  kiyohara 	uint32_t ic, im;
    203   1.1  kiyohara 	int handled = 0, pin, rv, i, s;
    204   1.1  kiyohara 
    205   1.1  kiyohara 	for (;;) {
    206   1.1  kiyohara 		ic = bus_space_read_4(sc->sc_iot, sc->sc_ioh, MVPEX_IC);
    207   1.1  kiyohara 		im = bus_space_read_4(sc->sc_iot, sc->sc_ioh, MVPEX_IM);
    208   1.1  kiyohara 		ic &= im;
    209   1.1  kiyohara 
    210   1.1  kiyohara 		if (!ic)
    211   1.1  kiyohara 			break;
    212   1.1  kiyohara 
    213   1.1  kiyohara 		for (i = 0, pin = PCI_INTERRUPT_PIN_A;
    214   1.1  kiyohara 		    i < PCI_INTERRUPT_PIN_MAX; pin++, i++) {
    215   1.1  kiyohara 			if ((ic & MVPEX_I_PIN(pin)) == 0)
    216   1.1  kiyohara 				continue;
    217   1.1  kiyohara 
    218   1.1  kiyohara 			intrtab = &sc->sc_intrtab[i];
    219   1.1  kiyohara 			LIST_FOREACH(ih, &intrtab->intr_list, ih_q) {
    220   1.1  kiyohara 				s = _splraise(ih->ih_type);
    221   1.1  kiyohara 				rv = (*ih->ih_func)(ih->ih_arg);
    222   1.1  kiyohara 				splx(s);
    223   1.1  kiyohara 				if (rv) {
    224   1.1  kiyohara 					ih->ih_evcnt.ev_count++;
    225   1.1  kiyohara 					handled++;
    226   1.1  kiyohara 				}
    227   1.1  kiyohara 			}
    228   1.1  kiyohara 			bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVPEX_IC,
    229   1.1  kiyohara 			    ~MVPEX_I_PIN(pin));
    230   1.1  kiyohara 		}
    231   1.1  kiyohara 	}
    232   1.1  kiyohara 
    233   1.1  kiyohara 	return handled;
    234   1.1  kiyohara }
    235   1.1  kiyohara 
    236   1.1  kiyohara 
    237   1.1  kiyohara static void
    238   1.9  kiyohara mvpex_init(struct mvpex_softc *sc, enum marvell_tags *tags)
    239   1.1  kiyohara {
    240   1.1  kiyohara 	uint32_t reg;
    241   1.1  kiyohara 	int window;
    242   1.1  kiyohara 
    243   1.1  kiyohara 	/*
    244   1.1  kiyohara 	 * First implement Guideline (GL# PCI Express-2) Wrong Default Value
    245   1.1  kiyohara 	 * to Transmitter Output Current (TXAMP) Relevant for: 88F5181-A1/B0/B1
    246   1.1  kiyohara 	 * and 88F5281-B0
    247   1.1  kiyohara 	 */
    248   1.1  kiyohara 						/* Write the read command */
    249   1.1  kiyohara 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, 0x1b00, 0x80820000);
    250   1.1  kiyohara 	reg = bus_space_read_4(sc->sc_iot, sc->sc_ioh, 0x1b00);
    251   1.1  kiyohara 	/* Prepare new data for write */
    252   1.1  kiyohara 	reg &= ~0x7;		/* Clear bits [2:0] */
    253   1.1  kiyohara 	reg |= 0x4;		/* Set the new value */
    254   1.1  kiyohara 	reg &= ~0x80000000;	/* Set "write" command */
    255   1.1  kiyohara 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, 0x1b00, reg);
    256   1.1  kiyohara 
    257   1.1  kiyohara 	for (window = 0; window < MVPEX_NWINDOW; window++)
    258   1.1  kiyohara 		bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVPEX_WC(window), 0);
    259   1.1  kiyohara 
    260   1.1  kiyohara #if 0	/* shall move to pchb(4)? */
    261   1.1  kiyohara 	mvpex_barinit(sc);
    262   1.1  kiyohara #else
    263   1.9  kiyohara 	mvpex_wininit(sc, tags);
    264   1.1  kiyohara #endif
    265   1.1  kiyohara 
    266   1.1  kiyohara 	/* Clear Interrupt Cause and Mask registers */
    267   1.1  kiyohara 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVPEX_IC, 0);
    268   1.1  kiyohara 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVPEX_IM, 0);
    269   1.1  kiyohara 
    270   1.1  kiyohara 	/* now wait 60 ns to be sure the link is valid (spec compliant) */
    271   1.1  kiyohara 	delay(1);
    272   1.1  kiyohara }
    273   1.1  kiyohara 
    274   1.1  kiyohara #if 0
    275   1.1  kiyohara static int
    276   1.1  kiyohara mvpex_wininit(struct mvpex_softc *sc, int window, int tbegin, int tend,
    277   1.1  kiyohara 	      int barmap, uint32_t *barbase, uint32_t *barsize)
    278   1.1  kiyohara {
    279   1.1  kiyohara 	uint32_t target, attr, base, size;
    280   1.1  kiyohara 	int targetid;
    281   1.1  kiyohara 
    282   1.1  kiyohara 	for (targetid = tbegin; targetid <= tend && window < MVPEX_NWINDOW;
    283   1.1  kiyohara 	    targetid++) {
    284   1.1  kiyohara 		if (orion_target(targetid, &target, &attr, &base, &size) == -1)
    285   1.1  kiyohara 			continue;
    286   1.1  kiyohara 		if (size == 0)
    287   1.1  kiyohara 			continue;
    288   1.1  kiyohara 
    289   1.1  kiyohara 		if (base < *barbase)
    290   1.1  kiyohara 			*barbase = base;
    291   1.1  kiyohara 		*barsize += size;
    292   1.1  kiyohara 
    293   1.1  kiyohara 		bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVPEX_WC(window),
    294   1.1  kiyohara 		    MVPEX_WC_WINEN		|
    295   1.1  kiyohara 		    barmap			|
    296   1.1  kiyohara 		    MVPEX_WC_TARGET(target)	|
    297   1.1  kiyohara 		    MVPEX_WC_ATTR(attr)		|
    298   1.1  kiyohara 		    MVPEX_WC_SIZE(size));
    299   1.1  kiyohara 		bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVPEX_WB(window),
    300   1.1  kiyohara 		    MVPEX_WB_BASE(base));
    301   1.1  kiyohara 		bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVPEX_WR(window), 0);
    302   1.1  kiyohara 		window++;
    303   1.1  kiyohara 	}
    304   1.1  kiyohara 
    305   1.1  kiyohara 	return window;
    306   1.1  kiyohara }
    307   1.1  kiyohara 
    308   1.1  kiyohara /* shall move to pchb(4)? */
    309   1.1  kiyohara static void
    310   1.1  kiyohara mvpex_barinit(struct mvpex_softc *sc)
    311   1.1  kiyohara {
    312   1.1  kiyohara 	const uint32_t barflag =
    313   1.1  kiyohara 	    PCI_MAPREG_MEM_PREFETCHABLE_MASK | PCI_MAPREG_MEM_TYPE_64BIT;
    314   1.1  kiyohara 	uint32_t base, size;
    315   1.1  kiyohara 	int window = 0;
    316   1.1  kiyohara 
    317   1.1  kiyohara 	marvell_winparams_by_tag(device_parent(sc->sc_dev),
    318   1.1  kiyohara 	    ORION_TARGETID_INTERNALREG, NULL, NULL, &base, &size);
    319   1.1  kiyohara 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVPEX_BAR0INTERNAL,
    320   1.1  kiyohara 	    barflag | (base & MVPEX_BAR0INTERNAL_MASK));
    321   1.1  kiyohara 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVPEX_BAR0INTERNALH, 0);
    322   1.1  kiyohara 
    323   1.1  kiyohara 	base = size = 0;
    324   1.1  kiyohara 	window = mvpex_wininit(sc, window, ORION_TARGETID_SDRAM_CS0,
    325   1.1  kiyohara 	    ORION_TARGETID_SDRAM_CS3, MVPEX_WC_BARMAP_BAR1, &base, &size);
    326   1.1  kiyohara 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVPEX_BAR1,
    327   1.1  kiyohara 	    barflag | (base & MVPEX_BAR_MASK));
    328   1.1  kiyohara 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVPEX_BAR1H, 0);
    329   1.1  kiyohara 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVPEX_BAR1C,
    330   1.1  kiyohara 	    MVPEX_BARC_BARSIZE(size) | MVPEX_BARC_BAREN);
    331   1.1  kiyohara 
    332   1.1  kiyohara #if 0
    333   1.1  kiyohara 	base = size = 0;
    334   1.1  kiyohara 	if (sc->sc_model == MARVELL_ORION_1_88F1181)
    335   1.1  kiyohara 		window = mvpex_wininit(sc, window, ORION_TARGETID_FLASH_CS,
    336   1.1  kiyohara 		    ORION_TARGETID_DEVICE_BOOTCS,
    337   1.1  kiyohara 		    MVPEX_WC_BARMAP_BAR2, &base, &size);
    338   1.1  kiyohara 	else {
    339   1.1  kiyohara 		window = mvpex_wininit(sc, window,
    340   1.1  kiyohara 		    ORION_TARGETID_DEVICE_CS0, ORION_TARGETID_DEVICE_CS2,
    341   1.1  kiyohara 		    MVPEX_WC_BARMAP_BAR2, &base, &size);
    342   1.1  kiyohara 		window = mvpex_wininit(sc, window,
    343   1.1  kiyohara 		    ORION_TARGETID_DEVICE_BOOTCS, ORION_TARGETID_DEVICE_BOOTCS,
    344   1.1  kiyohara 		    MVPEX_WC_BARMAP_BAR2, &base, &size);
    345   1.1  kiyohara 	}
    346   1.1  kiyohara 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVPEX_BAR2,
    347   1.1  kiyohara 	    barflag | (base & MVPEX_BAR_MASK));
    348   1.1  kiyohara 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVPEX_BAR2H, 0);
    349   1.1  kiyohara 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVPEX_BAR2C,
    350   1.1  kiyohara 	    MVPEX_BARC_BARSIZE(size) | MVPEX_BARC_BAREN);
    351   1.1  kiyohara #else
    352   1.1  kiyohara 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVPEX_BAR2C, 0);
    353   1.1  kiyohara #endif
    354   1.1  kiyohara }
    355   1.1  kiyohara #else
    356   1.1  kiyohara static void
    357   1.9  kiyohara mvpex_wininit(struct mvpex_softc *sc, enum marvell_tags *tags)
    358   1.1  kiyohara {
    359   1.1  kiyohara 	device_t pdev = device_parent(sc->sc_dev);
    360   1.1  kiyohara 	uint64_t base;
    361   1.9  kiyohara 	uint32_t size, bar;
    362   1.9  kiyohara 	int target, attr, window, rv, i, j;
    363   1.1  kiyohara 
    364   1.1  kiyohara 	for (window = 0, i = 0;
    365   1.9  kiyohara 	    tags[i] != MARVELL_TAG_UNDEFINED && window < MVPEX_NWINDOW; i++) {
    366   1.9  kiyohara 		rv = marvell_winparams_by_tag(pdev, tags[i],
    367   1.1  kiyohara 		    &target, &attr, &base, &size);
    368   1.1  kiyohara 		if (rv != 0 || size == 0)
    369   1.1  kiyohara 			continue;
    370   1.1  kiyohara 
    371   1.1  kiyohara 		if (base > 0xffffffffULL) {
    372   1.1  kiyohara 			aprint_error_dev(sc->sc_dev,
    373   1.1  kiyohara 			    "tag %d address 0x%llx not support\n",
    374   1.9  kiyohara 			    tags[i], base);
    375   1.1  kiyohara 			continue;
    376   1.1  kiyohara 		}
    377   1.1  kiyohara 
    378   1.9  kiyohara 		bar = MVPEX_WC_BARMAP_BAR1;
    379   1.9  kiyohara 		if (mvpex_bar2_tags != NULL)
    380   1.9  kiyohara 			for (j = 0; mvpex_bar2_tags[j] != MARVELL_TAG_UNDEFINED;
    381   1.9  kiyohara 			    j++) {
    382   1.9  kiyohara 				if (mvpex_bar2_tags[j] != tags[i])
    383   1.9  kiyohara 					continue;
    384   1.9  kiyohara 				bar = MVPEX_WC_BARMAP_BAR2;
    385   1.9  kiyohara 				break;
    386   1.9  kiyohara 			}
    387   1.9  kiyohara 
    388   1.1  kiyohara 		bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVPEX_WC(window),
    389   1.1  kiyohara 		    MVPEX_WC_WINEN		|
    390   1.9  kiyohara 		    bar				|
    391   1.1  kiyohara 		    MVPEX_WC_TARGET(target)	|
    392   1.1  kiyohara 		    MVPEX_WC_ATTR(attr)		|
    393   1.1  kiyohara 		    MVPEX_WC_SIZE(size));
    394   1.1  kiyohara 		bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVPEX_WB(window),
    395   1.1  kiyohara 		    MVPEX_WB_BASE(base));
    396   1.1  kiyohara 		bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVPEX_WR(window), 0);
    397   1.1  kiyohara 		window++;
    398   1.1  kiyohara 	}
    399   1.1  kiyohara 	for ( ; window < MVPEX_NWINDOW; window++)
    400   1.1  kiyohara 		bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVPEX_WC(window), 0);
    401   1.1  kiyohara }
    402   1.1  kiyohara #endif
    403   1.1  kiyohara 
    404   1.1  kiyohara #if NPCI > 0
    405   1.1  kiyohara static void
    406   1.1  kiyohara mvpex_pci_config(struct mvpex_softc *sc, bus_space_tag_t iot,
    407   1.1  kiyohara 		 bus_space_tag_t memt, bus_dma_tag_t dmat, pci_chipset_tag_t pc,
    408   1.1  kiyohara 		 u_long iostart, u_long ioend, u_long memstart, u_long memend,
    409   1.1  kiyohara 		 int cacheline_size)
    410   1.1  kiyohara {
    411   1.1  kiyohara 	struct pcibus_attach_args pba;
    412   1.1  kiyohara #ifdef PCI_NETBSD_CONFIGURE
    413   1.1  kiyohara 	struct extent *ioext = NULL, *memext = NULL;
    414   1.1  kiyohara #endif
    415   1.1  kiyohara 	uint32_t stat;
    416   1.1  kiyohara 
    417   1.1  kiyohara 	stat = bus_space_read_4(sc->sc_iot, sc->sc_ioh, MVPEX_STAT);
    418   1.1  kiyohara 
    419   1.1  kiyohara #ifdef PCI_NETBSD_CONFIGURE
    420   1.6      para 	ioext = extent_create("pexio", iostart, ioend, NULL, 0, EX_NOWAIT);
    421   1.6      para 	memext = extent_create("pexmem", memstart, memend, NULL, 0, EX_NOWAIT);
    422   1.1  kiyohara 	if (ioext != NULL && memext != NULL)
    423   1.1  kiyohara 		pci_configure_bus(pc, ioext, memext, NULL,
    424   1.1  kiyohara 		    MVPEX_STAT_PEXBUSNUM(stat), cacheline_size);
    425   1.1  kiyohara         else
    426   1.1  kiyohara 		aprint_error_dev(sc->sc_dev, "can't create extent %s%s%s\n",
    427   1.1  kiyohara 		    ioext == NULL ? "io" : "",
    428   1.1  kiyohara 		    ioext == NULL && memext == NULL ? " and " : "",
    429   1.1  kiyohara 		    memext == NULL ? "mem" : "");
    430   1.1  kiyohara 	if (ioext != NULL)
    431   1.1  kiyohara 		extent_destroy(ioext);
    432   1.1  kiyohara 	if (memext != NULL)
    433   1.1  kiyohara 		extent_destroy(memext);
    434   1.1  kiyohara #endif
    435   1.1  kiyohara 
    436   1.1  kiyohara 	pba.pba_iot = iot;
    437   1.1  kiyohara 	pba.pba_memt = memt;
    438   1.1  kiyohara 	pba.pba_dmat = dmat;
    439   1.1  kiyohara 	pba.pba_dmat64 = NULL;
    440   1.1  kiyohara 	pba.pba_pc = pc;
    441   1.5    dyoung 	pba.pba_flags = PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY;
    442   1.1  kiyohara 	pba.pba_bus = MVPEX_STAT_PEXBUSNUM(stat);
    443   1.1  kiyohara 	pba.pba_bridgetag = NULL;
    444   1.1  kiyohara 	config_found_ia(sc->sc_dev, "pcibus", &pba, NULL);
    445   1.1  kiyohara }
    446   1.1  kiyohara 
    447   1.1  kiyohara 
    448   1.1  kiyohara /*
    449   1.1  kiyohara  * PCI-Express CPU dependent code
    450   1.1  kiyohara  */
    451   1.1  kiyohara 
    452   1.1  kiyohara /* ARGSUSED */
    453   1.1  kiyohara void
    454   1.1  kiyohara mvpex_attach_hook(device_t parent, device_t self,
    455   1.1  kiyohara 		  struct pcibus_attach_args *pba)
    456   1.1  kiyohara {
    457   1.1  kiyohara 
    458   1.1  kiyohara 	/* Nothing */
    459   1.1  kiyohara }
    460   1.1  kiyohara 
    461   1.1  kiyohara /*
    462   1.1  kiyohara  * Bit map for configuration register:
    463   1.1  kiyohara  *   [31]    ConfigEn
    464   1.1  kiyohara  *   [30:28] Reserved
    465   1.1  kiyohara  *   [27:24] ExtRegNum (PCI Express only)
    466   1.1  kiyohara  *   [23:16] BusNum
    467   1.1  kiyohara  *   [15:11] DevNum
    468   1.1  kiyohara  *   [10: 8] FunctNum
    469   1.1  kiyohara  *   [ 7: 2] RegNum
    470   1.1  kiyohara  *   [ 1: 0] reserved
    471   1.1  kiyohara  */
    472   1.1  kiyohara 
    473   1.1  kiyohara /* ARGSUSED */
    474   1.1  kiyohara int
    475   1.1  kiyohara mvpex_bus_maxdevs(void *v, int busno)
    476   1.1  kiyohara {
    477   1.1  kiyohara 
    478   1.1  kiyohara 	return 32;	/* 32 device/bus */
    479   1.1  kiyohara }
    480   1.1  kiyohara 
    481   1.1  kiyohara /* ARGSUSED */
    482   1.1  kiyohara pcitag_t
    483   1.1  kiyohara mvpex_make_tag(void *v, int bus, int dev, int func)
    484   1.1  kiyohara {
    485   1.1  kiyohara 
    486   1.1  kiyohara 	return (bus << 16) | (dev << 11) | (func << 8);
    487   1.1  kiyohara }
    488   1.1  kiyohara 
    489   1.1  kiyohara /* ARGSUSED */
    490   1.1  kiyohara void
    491   1.1  kiyohara mvpex_decompose_tag(void *v, pcitag_t tag, int *bp, int *dp, int *fp)
    492   1.1  kiyohara {
    493   1.1  kiyohara 
    494   1.1  kiyohara 	if (bp != NULL)
    495   1.1  kiyohara 		*bp = (tag >> 16) & 0xff;
    496   1.1  kiyohara 	if (dp != NULL)
    497   1.1  kiyohara 		*dp = (tag >> 11) & 0x1f;
    498   1.1  kiyohara 	if (fp != NULL)
    499   1.1  kiyohara 		*fp = (tag >> 8) & 0x07;
    500   1.1  kiyohara }
    501   1.1  kiyohara 
    502   1.1  kiyohara pcireg_t
    503   1.1  kiyohara mvpex_conf_read(void *v, pcitag_t tag, int reg)
    504   1.1  kiyohara {
    505   1.1  kiyohara 	struct mvpex_softc *sc = v;
    506   1.1  kiyohara 	pcireg_t addr, pci_cs;
    507   1.1  kiyohara 	uint32_t stat;
    508   1.1  kiyohara 	int bus, dev, func, pexbus, pexdev;
    509   1.1  kiyohara 
    510   1.1  kiyohara 	mvpex_decompose_tag(v, tag, &bus, &dev, &func);
    511   1.1  kiyohara 
    512   1.1  kiyohara 	stat = bus_space_read_4(sc->sc_iot, sc->sc_ioh, MVPEX_STAT);
    513   1.1  kiyohara 	pexbus = MVPEX_STAT_PEXBUSNUM(stat);
    514   1.1  kiyohara 	pexdev = MVPEX_STAT_PEXDEVNUM(stat);
    515   1.1  kiyohara 	if (bus != pexbus || dev != pexdev)
    516   1.1  kiyohara 		if (stat & MVPEX_STAT_DLDOWN)
    517   1.1  kiyohara 			return -1;
    518   1.1  kiyohara 
    519   1.1  kiyohara 	if (bus == pexbus) {
    520   1.1  kiyohara 		if (pexdev == 0) {
    521   1.1  kiyohara 			if (dev != 1 && dev != pexdev)
    522   1.1  kiyohara 				return -1;
    523   1.1  kiyohara 		} else {
    524   1.1  kiyohara 			if (dev != 0 && dev != pexdev)
    525   1.1  kiyohara 				return -1;
    526   1.1  kiyohara 		}
    527   1.1  kiyohara 		if (func != 0)
    528   1.1  kiyohara 			return -1;
    529   1.1  kiyohara 	}
    530   1.1  kiyohara 
    531   1.1  kiyohara 	addr = ((reg & 0xf00) << 24)  | tag | (reg & 0xfc);
    532   1.1  kiyohara 
    533   1.1  kiyohara 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVPEX_CA,
    534   1.1  kiyohara 	    addr | MVPEX_CA_CONFIGEN);
    535   1.1  kiyohara 	if ((addr | MVPEX_CA_CONFIGEN) !=
    536   1.1  kiyohara 	    bus_space_read_4(sc->sc_iot, sc->sc_ioh, MVPEX_CA))
    537   1.1  kiyohara 		return -1;
    538   1.1  kiyohara 
    539   1.1  kiyohara 	pci_cs = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
    540   1.1  kiyohara 	    PCI_COMMAND_STATUS_REG);
    541   1.1  kiyohara 	bus_space_write_4(sc->sc_iot, sc->sc_ioh,
    542   1.1  kiyohara 	    PCI_COMMAND_STATUS_REG, pci_cs | PCI_STATUS_MASTER_ABORT);
    543   1.1  kiyohara 
    544   1.1  kiyohara 	return bus_space_read_4(sc->sc_iot, sc->sc_ioh, MVPEX_CD);
    545   1.1  kiyohara }
    546   1.1  kiyohara 
    547   1.1  kiyohara void
    548   1.1  kiyohara mvpex_conf_write(void *v, pcitag_t tag, int reg, pcireg_t data)
    549   1.1  kiyohara {
    550   1.1  kiyohara 	struct mvpex_softc *sc = v;
    551   1.1  kiyohara 	pcireg_t addr;
    552   1.1  kiyohara 	uint32_t stat;
    553   1.1  kiyohara 	int bus, dev, func, pexbus, pexdev;
    554   1.1  kiyohara 
    555   1.1  kiyohara 	mvpex_decompose_tag(v, tag, &bus, &dev, &func);
    556   1.1  kiyohara 
    557   1.1  kiyohara 	stat = bus_space_read_4(sc->sc_iot, sc->sc_ioh, MVPEX_STAT);
    558   1.1  kiyohara 	pexbus = MVPEX_STAT_PEXBUSNUM(stat);
    559   1.1  kiyohara 	pexdev = MVPEX_STAT_PEXDEVNUM(stat);
    560   1.1  kiyohara 	if (bus != pexbus || dev != pexdev)
    561   1.1  kiyohara 		if (stat & MVPEX_STAT_DLDOWN)
    562   1.1  kiyohara 			return;
    563   1.1  kiyohara 
    564   1.1  kiyohara 	if (bus == pexbus) {
    565   1.1  kiyohara 		if (pexdev == 0) {
    566   1.1  kiyohara 			if (dev != 1 && dev != pexdev)
    567   1.1  kiyohara 				return;
    568   1.1  kiyohara 		} else {
    569   1.1  kiyohara 			if (dev != 0 && dev != pexdev)
    570   1.1  kiyohara 				return;
    571   1.1  kiyohara 		}
    572   1.1  kiyohara 		if (func != 0)
    573   1.1  kiyohara 			return;
    574   1.1  kiyohara 	}
    575   1.1  kiyohara 
    576   1.1  kiyohara 	addr = ((reg & 0xf00) << 24)  | tag | (reg & 0xfc);
    577   1.1  kiyohara 
    578   1.1  kiyohara 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVPEX_CA,
    579   1.1  kiyohara 	    addr | MVPEX_CA_CONFIGEN);
    580   1.1  kiyohara 	if ((addr | MVPEX_CA_CONFIGEN) !=
    581   1.1  kiyohara 	    bus_space_read_4(sc->sc_iot, sc->sc_ioh, MVPEX_CA))
    582   1.1  kiyohara 		return;
    583   1.1  kiyohara 
    584   1.1  kiyohara 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVPEX_CD, data);
    585   1.1  kiyohara }
    586   1.1  kiyohara 
    587   1.1  kiyohara /* ARGSUSED */
    588   1.1  kiyohara int
    589   1.7      matt mvpex_conf_hook(void *v, int bus, int dev, int func, pcireg_t id)
    590   1.1  kiyohara {
    591   1.1  kiyohara 
    592   1.1  kiyohara 	if (bus == 0 && dev == 0)	/* don't configure GT */
    593   1.1  kiyohara 		return 0;
    594   1.1  kiyohara 
    595   1.8   rkujawa 	/*
    596   1.8   rkujawa 	 * Do not configure PCI Express root complex on MV78460 - avoid
    597   1.8   rkujawa 	 * setting up IO and memory windows.
    598   1.8   rkujawa 	 * XXX: should also avoid that other Aramadas.
    599   1.8   rkujawa 	 */
    600   1.8   rkujawa 	else if ((dev == 0) && (PCI_PRODUCT(id) == MARVELL_ARMADAXP_MV78460))
    601   1.8   rkujawa 		return 0;
    602   1.8   rkujawa 
    603   1.1  kiyohara 	return PCI_CONF_DEFAULT;
    604   1.1  kiyohara }
    605   1.1  kiyohara 
    606   1.1  kiyohara int
    607   1.4    dyoung mvpex_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    608   1.1  kiyohara {
    609   1.1  kiyohara 
    610   1.1  kiyohara 	switch (pa->pa_intrpin) {
    611   1.1  kiyohara 	case PCI_INTERRUPT_PIN_A:
    612   1.1  kiyohara 	case PCI_INTERRUPT_PIN_B:
    613   1.1  kiyohara 	case PCI_INTERRUPT_PIN_C:
    614   1.1  kiyohara 	case PCI_INTERRUPT_PIN_D:
    615   1.1  kiyohara 		*ihp = pa->pa_intrpin;
    616   1.1  kiyohara 		return 0;
    617   1.1  kiyohara 	}
    618   1.1  kiyohara 	return -1;
    619   1.1  kiyohara }
    620   1.1  kiyohara 
    621   1.1  kiyohara /* ARGSUSED */
    622   1.1  kiyohara const char *
    623  1.11     htodd mvpex_intr_string(void *v, pci_intr_handle_t pin, char *buf, size_t len)
    624   1.1  kiyohara {
    625   1.1  kiyohara 	switch (pin) {
    626   1.1  kiyohara 	case PCI_INTERRUPT_PIN_A:
    627   1.1  kiyohara 	case PCI_INTERRUPT_PIN_B:
    628   1.1  kiyohara 	case PCI_INTERRUPT_PIN_C:
    629   1.1  kiyohara 	case PCI_INTERRUPT_PIN_D:
    630   1.1  kiyohara 		break;
    631   1.1  kiyohara 
    632   1.1  kiyohara 	default:
    633   1.1  kiyohara 		return NULL;
    634   1.1  kiyohara 	}
    635  1.10  christos 	snprintf(buf, len, "interrupt pin INT%c#", (char)('A' - 1 + pin));
    636   1.1  kiyohara 
    637  1.10  christos 	return buf;
    638   1.1  kiyohara }
    639   1.1  kiyohara 
    640   1.1  kiyohara /* ARGSUSED */
    641   1.1  kiyohara const struct evcnt *
    642   1.1  kiyohara mvpex_intr_evcnt(void *v, pci_intr_handle_t pin)
    643   1.1  kiyohara {
    644   1.1  kiyohara 
    645   1.1  kiyohara 	return NULL;
    646   1.1  kiyohara }
    647   1.1  kiyohara 
    648   1.1  kiyohara /*
    649   1.1  kiyohara  * XXXX: Shall these functions use mutex(9) instead of spl(9)?
    650   1.1  kiyohara  *       MV78200 and MV64360 and after supports SMP.
    651   1.1  kiyohara  */
    652   1.1  kiyohara 
    653   1.1  kiyohara /* ARGSUSED */
    654   1.1  kiyohara void *
    655   1.1  kiyohara mvpex_intr_establish(void *v, pci_intr_handle_t pin, int ipl,
    656   1.1  kiyohara 		     int (*intrhand)(void *), void *intrarg)
    657   1.1  kiyohara {
    658   1.1  kiyohara 	struct mvpex_softc *sc = (struct mvpex_softc *)v;
    659   1.1  kiyohara 	struct mvpex_intrtab *intrtab;
    660   1.1  kiyohara 	struct mvpex_intrhand *pexih;
    661   1.1  kiyohara 	uint32_t mask;
    662   1.1  kiyohara 	int ih = pin - 1, s;
    663   1.1  kiyohara 
    664   1.1  kiyohara 	intrtab = &sc->sc_intrtab[ih];
    665   1.1  kiyohara 
    666   1.1  kiyohara 	KASSERT(pin == intrtab->intr_pin);
    667   1.1  kiyohara 
    668   1.1  kiyohara 	pexih = malloc(sizeof(*pexih), M_DEVBUF, M_NOWAIT);
    669   1.1  kiyohara 	if (pexih == NULL)
    670   1.1  kiyohara 		return NULL;
    671   1.1  kiyohara 
    672   1.1  kiyohara 	pexih->ih_func = intrhand;
    673   1.1  kiyohara 	pexih->ih_arg = intrarg;
    674   1.1  kiyohara 	pexih->ih_type = ipl;
    675   1.1  kiyohara 	pexih->ih_intrtab = intrtab;
    676  1.13  knakahar 	mvpex_intr_string(v, pin, pexih->ih_evname, sizeof(pexih->ih_evname));
    677   1.1  kiyohara 	evcnt_attach_dynamic(&pexih->ih_evcnt, EVCNT_TYPE_INTR, NULL, "mvpex",
    678  1.13  knakahar 	    pexih->ih_evname);
    679   1.1  kiyohara 
    680   1.1  kiyohara 	s = splhigh();
    681   1.1  kiyohara 
    682   1.1  kiyohara 	/* First, link it into the tables. */
    683   1.1  kiyohara 	LIST_INSERT_HEAD(&intrtab->intr_list, pexih, ih_q);
    684   1.1  kiyohara 
    685   1.1  kiyohara 	/* Now enable it. */
    686   1.1  kiyohara 	if (intrtab->intr_refcnt++ == 0) {
    687   1.1  kiyohara 		mask = bus_space_read_4(sc->sc_iot, sc->sc_ioh, MVPEX_IM);
    688   1.1  kiyohara 		mask |= MVPEX_I_PIN(intrtab->intr_pin);
    689   1.1  kiyohara 		bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVPEX_IM, mask);
    690   1.1  kiyohara 	}
    691   1.1  kiyohara 
    692   1.1  kiyohara 	splx(s);
    693   1.1  kiyohara 
    694   1.1  kiyohara 	return pexih;
    695   1.1  kiyohara }
    696   1.1  kiyohara 
    697   1.1  kiyohara void
    698   1.1  kiyohara mvpex_intr_disestablish(void *v, void *ih)
    699   1.1  kiyohara {
    700   1.1  kiyohara 	struct mvpex_softc *sc = (struct mvpex_softc *)v;
    701   1.1  kiyohara 	struct mvpex_intrtab *intrtab;
    702   1.1  kiyohara 	struct mvpex_intrhand *pexih = ih;
    703   1.1  kiyohara 	uint32_t mask;
    704   1.1  kiyohara 	int s;
    705   1.1  kiyohara 
    706  1.14  knakahar 	evcnt_detach(&pexih->ih_evcnt);
    707  1.14  knakahar 
    708   1.1  kiyohara 	intrtab = pexih->ih_intrtab;
    709   1.1  kiyohara 
    710   1.1  kiyohara 	s = splhigh();
    711   1.1  kiyohara 
    712   1.1  kiyohara 	/*
    713   1.1  kiyohara 	 * First, remove it from the table.
    714   1.1  kiyohara 	 */
    715   1.1  kiyohara 	LIST_REMOVE(pexih, ih_q);
    716   1.1  kiyohara 
    717   1.1  kiyohara 	/* Now, disable it, if there is nothing remaining on the list. */
    718   1.1  kiyohara 	if (intrtab->intr_refcnt-- == 1) {
    719   1.1  kiyohara 		mask = bus_space_read_4(sc->sc_iot, sc->sc_ioh, MVPEX_IM);
    720   1.1  kiyohara 		mask &= ~MVPEX_I_PIN(intrtab->intr_pin);
    721   1.1  kiyohara 		bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVPEX_IM, mask);
    722   1.1  kiyohara 	}
    723   1.1  kiyohara 	splx(s);
    724   1.1  kiyohara 
    725   1.1  kiyohara 	free(pexih, M_DEVBUF);
    726   1.1  kiyohara }
    727   1.1  kiyohara #endif	/* NPCI > 0 */
    728