Home | History | Annotate | Line # | Download | only in vr
vrpciu.c revision 1.14
      1 /*	$NetBSD: vrpciu.c,v 1.14 2003/07/15 02:29:36 lukem Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2001 Enami Tsugutomo.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  */
     28 
     29 #include <sys/cdefs.h>
     30 __KERNEL_RCSID(0, "$NetBSD: vrpciu.c,v 1.14 2003/07/15 02:29:36 lukem Exp $");
     31 
     32 #include <sys/param.h>
     33 #include <sys/systm.h>
     34 #include <sys/device.h>
     35 
     36 #include <machine/bus.h>
     37 #include <machine/bus_space_hpcmips.h>
     38 #include <machine/bus_dma_hpcmips.h>
     39 #include <machine/config_hook.h>
     40 #include <machine/platid.h>
     41 #include <machine/platid_mask.h>
     42 
     43 #include <dev/pci/pcivar.h>
     44 #include <dev/pci/pcidevs.h>
     45 #include <dev/pci/pciidereg.h>
     46 
     47 #include <hpcmips/vr/icureg.h>
     48 #include <hpcmips/vr/vripif.h>
     49 #include <hpcmips/vr/vrpciureg.h>
     50 
     51 #include "pci.h"
     52 
     53 #ifdef DEBUG
     54 #define	DPRINTF(args)	printf args
     55 #else
     56 #define	DPRINTF(args)
     57 #endif
     58 
     59 struct vrpciu_softc {
     60 	struct device sc_dev;
     61 
     62 	vrip_chipset_tag_t sc_vc;
     63 	bus_space_tag_t sc_iot;
     64 	bus_space_handle_t sc_ioh;
     65 	void *sc_ih;
     66 
     67 	struct vrc4173bcu_softc *sc_bcu; /* vrc4173bcu */
     68 
     69 	struct hpcmips_pci_chipset sc_pc;
     70 };
     71 
     72 static void	vrpciu_write(struct vrpciu_softc *, int, u_int32_t);
     73 static u_int32_t
     74 		vrpciu_read(struct vrpciu_softc *, int);
     75 #ifdef DEBUG
     76 static void	vrpciu_write_2(struct vrpciu_softc *, int, u_int16_t)
     77 	__attribute__((unused));
     78 static u_int16_t
     79 		vrpciu_read_2(struct vrpciu_softc *, int);
     80 #endif
     81 static int	vrpciu_match(struct device *, struct cfdata *, void *);
     82 static void	vrpciu_attach(struct device *, struct device *, void *);
     83 #if NPCI > 0
     84 static int	vrpciu_print(void *, const char *);
     85 #endif
     86 static int	vrpciu_intr(void *);
     87 static void	vrpciu_attach_hook(struct device *, struct device *,
     88 		    struct pcibus_attach_args *);
     89 static int	vrpciu_bus_maxdevs(pci_chipset_tag_t, int);
     90 static int	vrpciu_bus_devorder(pci_chipset_tag_t, int, char *);
     91 static pcitag_t	vrpciu_make_tag(pci_chipset_tag_t, int, int, int);
     92 static void	vrpciu_decompose_tag(pci_chipset_tag_t, pcitag_t, int *, int *,
     93 		    int *);
     94 static pcireg_t	vrpciu_conf_read(pci_chipset_tag_t, pcitag_t, int);
     95 static void	vrpciu_conf_write(pci_chipset_tag_t, pcitag_t, int, pcireg_t);
     96 static int	vrpciu_intr_map(struct pci_attach_args *, pci_intr_handle_t *);
     97 static const char *vrpciu_intr_string(pci_chipset_tag_t, pci_intr_handle_t);
     98 static const struct evcnt *vrpciu_intr_evcnt(pci_chipset_tag_t,
     99 		    pci_intr_handle_t);
    100 static void	*vrpciu_intr_establish(pci_chipset_tag_t, pci_intr_handle_t,
    101 		    int, int (*)(void *), void *);
    102 static void	vrpciu_intr_disestablish(pci_chipset_tag_t, void *);
    103 
    104 CFATTACH_DECL(vrpciu, sizeof(struct vrpciu_softc),
    105     vrpciu_match, vrpciu_attach, NULL, NULL);
    106 
    107 static void
    108 vrpciu_write(struct vrpciu_softc *sc, int offset, u_int32_t val)
    109 {
    110 
    111 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, offset, val);
    112 }
    113 
    114 static u_int32_t
    115 vrpciu_read(struct vrpciu_softc *sc, int offset)
    116 {
    117 
    118 	return (bus_space_read_4(sc->sc_iot, sc->sc_ioh, offset));
    119 }
    120 
    121 #ifdef DEBUG
    122 static void
    123 vrpciu_write_2(struct vrpciu_softc *sc, int offset, u_int16_t val)
    124 {
    125 
    126 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, offset, val);
    127 }
    128 
    129 static u_int16_t
    130 vrpciu_read_2(struct vrpciu_softc *sc, int offset)
    131 {
    132 
    133 	return (bus_space_read_2(sc->sc_iot, sc->sc_ioh, offset));
    134 }
    135 #endif
    136 
    137 static int
    138 vrpciu_match(struct device *parent, struct cfdata *match, void *aux)
    139 {
    140 
    141 	return (1);
    142 }
    143 
    144 static void
    145 vrpciu_attach(struct device *parent, struct device *self, void *aux)
    146 {
    147 	struct vrpciu_softc *sc = (struct vrpciu_softc *)self;
    148 	pci_chipset_tag_t pc = &sc->sc_pc;
    149 	struct vrip_attach_args *va = aux;
    150 #if defined(DEBUG) || NPCI > 0
    151 	u_int32_t reg;
    152 #endif
    153 #if NPCI > 0
    154 	struct bus_space_tag_hpcmips *iot;
    155 	char tmpbuf[16];
    156 	struct pcibus_attach_args pba;
    157 #endif
    158 
    159 	sc->sc_vc = va->va_vc;
    160 	sc->sc_iot = va->va_iot;
    161 	if (bus_space_map(sc->sc_iot, va->va_addr, va->va_size, 0,
    162 	    &sc->sc_ioh)) {
    163 		printf(": couldn't map io space\n");
    164 		return;
    165 	}
    166 
    167 	sc->sc_ih = vrip_intr_establish(va->va_vc, va->va_unit, 0, IPL_TTY,
    168 	    vrpciu_intr, sc);
    169 	if (sc->sc_ih == NULL) {
    170 		printf(": couldn't establish interrupt\n");
    171 		return;
    172 	}
    173 
    174 	/* Enable level 2 interrupt */
    175 	vrip_intr_setmask2(va->va_vc, sc->sc_ih, PCIINT_INT0, 1);
    176 
    177 	printf("\n");
    178 
    179 #ifdef DEBUG
    180 #define	DUMP_MAW(sc, name, reg) do {					\
    181 	printf("%s: %s =\t0x%08x\n", (sc)->sc_dev.dv_xname,		\
    182 	    (name), (reg));						\
    183 	printf("%s:\tIBA/MASK =\t0x%08x/0x%08x (0x%08x - 0x%08x)\n",	\
    184 	    (sc)->sc_dev.dv_xname,					\
    185 	    reg & VRPCIU_MAW_IBAMASK, VRPCIU_MAW_ADDRMASK(reg),		\
    186 	    VRPCIU_MAW_ADDR(reg),					\
    187 	    VRPCIU_MAW_ADDR(reg) + VRPCIU_MAW_SIZE(reg));		\
    188 	printf("%s:\tWINEN =\t0x%08x\n", (sc)->sc_dev.dv_xname,		\
    189 	    reg & VRPCIU_MAW_WINEN);					\
    190 	printf("%s:\tPCIADR =\t0x%08x\n", (sc)->sc_dev.dv_xname,	\
    191 	    VRPCIU_MAW_PCIADDR(reg));					\
    192 } while (0)
    193 #define	DUMP_TAW(sc, name, reg) do {				\
    194 	printf("%s: %s =\t\t0x%08x\n", (sc)->sc_dev.dv_xname,	\
    195 	    (name), (reg));					\
    196 	printf("%s:\tMASK =\t0x%08x\n", (sc)->sc_dev.dv_xname,	\
    197 	    VRPCIU_TAW_ADDRMASK(reg));				\
    198 	printf("%s:\tWINEN =\t0x%08x\n", (sc)->sc_dev.dv_xname,	\
    199 	    reg & VRPCIU_TAW_WINEN);				\
    200 	printf("%s:\tIBA =\t0x%08x\n", (sc)->sc_dev.dv_xname,	\
    201 	    VRPCIU_TAW_IBA(reg));				\
    202 } while (0)
    203 	reg = vrpciu_read(sc, VRPCIU_MMAW1REG);
    204 	DUMP_MAW(sc, "MMAW1", reg);
    205 	reg = vrpciu_read(sc, VRPCIU_MMAW2REG);
    206 	DUMP_MAW(sc, "MMAW2", reg);
    207 	reg = vrpciu_read(sc, VRPCIU_TAW1REG);
    208 	DUMP_TAW(sc, "TAW1", reg);
    209 	reg = vrpciu_read(sc, VRPCIU_TAW2REG);
    210 	DUMP_TAW(sc, "TAW2", reg);
    211 	reg = vrpciu_read(sc, VRPCIU_MIOAWREG);
    212 	DUMP_MAW(sc, "MIOAW", reg);
    213 	printf("%s: BUSERRAD =\t0x%08x\n", sc->sc_dev.dv_xname,
    214 	    vrpciu_read(sc, VRPCIU_BUSERRADREG));
    215 	printf("%s: INTCNTSTA =\t0x%08x\n", sc->sc_dev.dv_xname,
    216 	    vrpciu_read(sc, VRPCIU_INTCNTSTAREG));
    217 	printf("%s: EXACC =\t0x%08x\n", sc->sc_dev.dv_xname,
    218 	    vrpciu_read(sc, VRPCIU_EXACCREG));
    219 	printf("%s: RECONT =\t0x%08x\n", sc->sc_dev.dv_xname,
    220 	    vrpciu_read(sc, VRPCIU_RECONTREG));
    221 	printf("%s: PCIEN =\t0x%08x\n", sc->sc_dev.dv_xname,
    222 	    vrpciu_read(sc, VRPCIU_ENREG));
    223 	printf("%s: CLOCKSEL =\t0x%08x\n", sc->sc_dev.dv_xname,
    224 	    vrpciu_read(sc, VRPCIU_CLKSELREG));
    225 	printf("%s: TRDYV =\t0x%08x\n", sc->sc_dev.dv_xname,
    226 	    vrpciu_read(sc, VRPCIU_TRDYVREG));
    227 	printf("%s: CLKRUN =\t0x%08x\n", sc->sc_dev.dv_xname,
    228 	    vrpciu_read_2(sc, VRPCIU_CLKRUNREG));
    229 	printf("%s: IDREG =\t0x%08x\n", sc->sc_dev.dv_xname,
    230 	    vrpciu_read(sc, VRPCIU_CONF_BASE + PCI_ID_REG));
    231 	reg = vrpciu_read(sc, VRPCIU_CONF_BASE + PCI_COMMAND_STATUS_REG);
    232 	printf("%s: CSR =\t\t0x%08x\n", sc->sc_dev.dv_xname, reg);
    233 	vrpciu_write(sc, VRPCIU_CONF_BASE + PCI_COMMAND_STATUS_REG, reg);
    234 	printf("%s: CSR =\t\t0x%08x\n", sc->sc_dev.dv_xname,
    235 	    vrpciu_read(sc, VRPCIU_CONF_BASE + PCI_COMMAND_STATUS_REG));
    236 	printf("%s: CLASS =\t0x%08x\n", sc->sc_dev.dv_xname,
    237 	    vrpciu_read(sc, VRPCIU_CONF_BASE + PCI_CLASS_REG));
    238 	printf("%s: BHLC =\t\t0x%08x\n", sc->sc_dev.dv_xname,
    239 	    vrpciu_read(sc, VRPCIU_CONF_BASE + PCI_BHLC_REG));
    240 	printf("%s: MAIL =\t\t0x%08x\n", sc->sc_dev.dv_xname,
    241 	    vrpciu_read(sc, VRPCIU_CONF_BASE + VRPCIU_CONF_MAILREG));
    242 	printf("%s: MBA1 =\t\t0x%08x\n", sc->sc_dev.dv_xname,
    243 	    vrpciu_read(sc, VRPCIU_CONF_BASE + VRPCIU_CONF_MBA1REG));
    244 	printf("%s: MBA2 =\t\t0x%08x\n", sc->sc_dev.dv_xname,
    245 	    vrpciu_read(sc, VRPCIU_CONF_BASE + VRPCIU_CONF_MBA2REG));
    246 	printf("%s: INTR =\t\t0x%08x\n", sc->sc_dev.dv_xname,
    247 	    vrpciu_read(sc, VRPCIU_CONF_BASE + PCI_INTERRUPT_REG));
    248 #if 0
    249 	vrpciu_write(sc, VRPCIU_CONF_BASE + PCI_INTERRUPT_REG,
    250 	    vrpciu_read(sc, VRPCIU_CONF_BASE + PCI_INTERRUPT_REG) | 0x01);
    251 	printf("%s: INTR =\t\t0x%08x\n", sc->sc_dev.dv_xname,
    252 	    vrpciu_read(sc, VRPCIU_CONF_BASE + PCI_INTERRUPT_REG));
    253 #endif
    254 #endif
    255 
    256 	pc->pc_dev = &sc->sc_dev;
    257 	pc->pc_attach_hook = vrpciu_attach_hook;
    258 	pc->pc_bus_maxdevs = vrpciu_bus_maxdevs;
    259 	pc->pc_bus_devorder = vrpciu_bus_devorder;
    260 	pc->pc_make_tag = vrpciu_make_tag;
    261 	pc->pc_decompose_tag = vrpciu_decompose_tag;
    262 	pc->pc_conf_read = vrpciu_conf_read;
    263 	pc->pc_conf_write = vrpciu_conf_write;
    264 	pc->pc_intr_map = vrpciu_intr_map;
    265 	pc->pc_intr_string = vrpciu_intr_string;
    266 	pc->pc_intr_evcnt = vrpciu_intr_evcnt;
    267 	pc->pc_intr_establish = vrpciu_intr_establish;
    268 	pc->pc_intr_disestablish = vrpciu_intr_disestablish;
    269 
    270 #if 0
    271 	{
    272 		int i;
    273 
    274 		for (i = 0; i < 8; i++)
    275 			printf("%s: ID_REG(0, 0, %d) = 0x%08x\n",
    276 			    sc->sc_dev.dv_xname, i,
    277 			    pci_conf_read(pc, pci_make_tag(pc, 0, 0, i),
    278 				PCI_ID_REG));
    279 	}
    280 #endif
    281 
    282 #if NPCI > 0
    283 	memset(&pba, 0, sizeof(pba));
    284 	pba.pba_busname = "pci";
    285 
    286 	/* For now, just inherit window mappings set by WinCE.  XXX. */
    287 
    288 	iot = hpcmips_alloc_bus_space_tag();
    289 	reg = vrpciu_read(sc, VRPCIU_MIOAWREG);
    290 	snprintf(tmpbuf, sizeof(tmpbuf), "%s/iot",
    291 	    sc->sc_dev.dv_xname);
    292 	hpcmips_init_bus_space(iot, (struct bus_space_tag_hpcmips *)sc->sc_iot,
    293 	    tmpbuf, VRPCIU_MAW_ADDR(reg), VRPCIU_MAW_SIZE(reg));
    294 	pba.pba_iot = &iot->bst;
    295 
    296 	/*
    297 	 * Just use system bus space tag.  It works since WinCE maps
    298 	 * PCI bus space at same offset.  But this isn't right thing
    299 	 * of course.  XXX.
    300 	 */
    301 	pba.pba_memt = sc->sc_iot;
    302 	pba.pba_dmat = &hpcmips_default_bus_dma_tag.bdt;
    303 	pba.pba_dmat64 = NULL;
    304 	pba.pba_bus = 0;
    305 	pba.pba_bridgetag = NULL;
    306 
    307 	if (platid_match(&platid, &platid_mask_MACH_LASER5_L_BOARD)) {
    308 		/*
    309 		 * fix PCI device configration for L-Router.
    310 		 */
    311 		/* change IDE controller to native mode */
    312 		reg = pci_conf_read(pc, pci_make_tag(pc, 0, 16, 0),
    313 				    PCI_CLASS_REG);
    314 		reg |= PCIIDE_INTERFACE_PCI(0) << PCI_INTERFACE_SHIFT;
    315 		reg |= PCIIDE_INTERFACE_PCI(1) << PCI_INTERFACE_SHIFT;
    316 		pci_conf_write(pc, pci_make_tag(pc, 0, 16, 0), PCI_CLASS_REG,
    317 			       reg);
    318 		/* fix broken BAR setting of fxp0, fxp1 */
    319 		pci_conf_write(pc, pci_make_tag(pc, 0, 0, 0), PCI_MAPREG_START,
    320 			       0x11100000);
    321 		pci_conf_write(pc, pci_make_tag(pc, 0, 1, 0), PCI_MAPREG_START,
    322 			       0x11200000);
    323 	}
    324 
    325 	pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED |
    326 	    PCI_FLAGS_MRL_OKAY;
    327 	pba.pba_pc = pc;
    328 
    329 	config_found(self, &pba, vrpciu_print);
    330 #endif
    331 }
    332 
    333 #if NPCI > 0
    334 static int
    335 vrpciu_print(void *aux, const char *pnp)
    336 {
    337 	struct pcibus_attach_args *pba = aux;
    338 
    339 	if (pnp != NULL)
    340 		aprint_normal("%s at %s", pba->pba_busname, pnp);
    341 	else
    342 		aprint_normal(" bus %d", pba->pba_bus);
    343 
    344 	return (UNCONF);
    345 }
    346 #endif
    347 
    348 /*
    349  * Handle PCI error interrupts.
    350  */
    351 int
    352 vrpciu_intr(void *arg)
    353 {
    354 	struct vrpciu_softc *sc = (struct vrpciu_softc *)arg;
    355 	u_int32_t isr, baddr;
    356 
    357 	isr = vrpciu_read(sc, VRPCIU_INTCNTSTAREG);
    358 	baddr = vrpciu_read(sc, VRPCIU_BUSERRADREG);
    359 	printf("%s: status=0x%08x  bad addr=0x%08x\n",
    360 	    sc->sc_dev.dv_xname, isr, baddr);
    361 	return ((isr & 0x0f) ? 1 : 0);
    362 }
    363 
    364 void
    365 vrpciu_attach_hook(struct device *parent, struct device *self,
    366     struct pcibus_attach_args *pba)
    367 {
    368 
    369 	return;
    370 }
    371 
    372 int
    373 vrpciu_bus_maxdevs(pci_chipset_tag_t pc, int busno)
    374 {
    375 
    376 	return (32);
    377 }
    378 
    379 int
    380 vrpciu_bus_devorder(pci_chipset_tag_t pc, int busno, char *devs)
    381 {
    382 	int i, dev;
    383 	char priorities[32];
    384 	static pcireg_t ids[] = {
    385 		/* these devices should be attached first */
    386 		PCI_ID_CODE(PCI_VENDOR_NEC, PCI_PRODUCT_NEC_VRC4173_BCU),
    387 	};
    388 
    389 	/* scan PCI devices and check the id table */
    390 	memset(priorities, 0, sizeof(priorities));
    391 	for (dev = 0; dev < 32; dev++) {
    392 		pcireg_t id;
    393 		id = pci_conf_read(pc, pci_make_tag(pc, 0, dev, 0),PCI_ID_REG);
    394 		for (i = 0; i < sizeof(ids)/sizeof(*ids); i++)
    395 			if (id == ids[i])
    396 				priorities[dev] = 1;
    397 	}
    398 
    399 	/* fill order array */
    400 	for (i = 1; 0 <= i; i--)
    401 		for (dev = 0; dev < 32; dev++)
    402 			if (priorities[dev] == i)
    403 				*devs++ = dev;
    404 
    405 	return (32);
    406 }
    407 
    408 pcitag_t
    409 vrpciu_make_tag(pci_chipset_tag_t pc, int bus, int device, int function)
    410 {
    411 
    412 	return ((bus << 16) | (device << 11) | (function << 8));
    413 }
    414 
    415 void
    416 vrpciu_decompose_tag(pci_chipset_tag_t pc, pcitag_t tag, int *bp, int *dp,
    417     int *fp)
    418 {
    419 
    420 	if (bp != NULL)
    421 		*bp = (tag >> 16) & 0xff;
    422 	if (dp != NULL)
    423 		*dp = (tag >> 11) & 0x1f;
    424 	if (fp != NULL)
    425 		*fp = (tag >> 8) & 0x07;
    426 }
    427 
    428 pcireg_t
    429 vrpciu_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int reg)
    430 {
    431 	struct vrpciu_softc *sc = (struct vrpciu_softc *)pc->pc_dev;
    432 	u_int32_t val;
    433 	int bus, device, function;
    434 
    435 	pci_decompose_tag(pc, tag, &bus, &device, &function);
    436 	if (bus == 0) {
    437 		if (device > 21)
    438 			return ((pcitag_t)-1);
    439 		tag = (1 << (device + 11)) | (function << 8); /* Type 0 */
    440 	} else
    441 		tag |= VRPCIU_CONF_TYPE1;
    442 
    443 	vrpciu_write(sc, VRPCIU_CONFAREG, tag | reg);
    444 	val = vrpciu_read(sc, VRPCIU_CONFDREG);
    445 #if 0
    446 	printf("%s: conf_read: tag = 0x%08x, reg = 0x%x, val = 0x%08x\n",
    447 	    sc->sc_dev.dv_xname, (u_int32_t)tag, reg, val);
    448 #endif
    449 	return (val);
    450 }
    451 
    452 void
    453 vrpciu_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int reg,
    454     pcireg_t data)
    455 {
    456 	struct vrpciu_softc *sc = (struct vrpciu_softc *)pc->pc_dev;
    457 	int bus, device, function;
    458 
    459 #if 0
    460 	printf("%s: conf_write: tag = 0x%08x, reg = 0x%x, val = 0x%08x\n",
    461 	    sc->sc_dev.dv_xname, (u_int32_t)tag, reg, (u_int32_t)data);
    462 #endif
    463 	vrpciu_decompose_tag(pc, tag, &bus, &device, &function);
    464 	if (bus == 0) {
    465 		if (device > 21)
    466 			return;
    467 		tag = (1 << (device + 11)) | (function << 8); /* Type 0 */
    468 	} else
    469 		tag |= VRPCIU_CONF_TYPE1;
    470 
    471 	vrpciu_write(sc, VRPCIU_CONFAREG, tag | reg);
    472 	vrpciu_write(sc, VRPCIU_CONFDREG, data);
    473 }
    474 
    475 int
    476 vrpciu_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    477 {
    478 	pci_chipset_tag_t pc = pa->pa_pc;
    479 	pcitag_t intrtag = pa->pa_intrtag;
    480 	int bus, dev, func;
    481 #ifdef DEBUG
    482 	int line = pa->pa_intrline;
    483 	int pin = pa->pa_intrpin;
    484 #endif
    485 
    486 	pci_decompose_tag(pc, intrtag, &bus, &dev, &func);
    487 	DPRINTF(("%s(%d, %d, %d): line = %d, pin = %d\n", pc->pc_dev->dv_xname,
    488 	    bus, dev, func, line, pin));
    489 
    490 	*ihp = CONFIG_HOOK_PCIINTR_ID(bus, dev, func);
    491 
    492 	return (0);
    493 }
    494 
    495 const char *
    496 vrpciu_intr_string(pci_chipset_tag_t pc, pci_intr_handle_t ih)
    497 {
    498 	static char irqstr[sizeof("pciintr") + 16];
    499 
    500 	snprintf(irqstr, sizeof(irqstr), "pciintr %d:%d:%d",
    501 	    CONFIG_HOOK_PCIINTR_BUS((int)ih),
    502 	    CONFIG_HOOK_PCIINTR_DEVICE((int)ih),
    503 	    CONFIG_HOOK_PCIINTR_FUNCTION((int)ih));
    504 
    505 	return (irqstr);
    506 }
    507 
    508 const struct evcnt *
    509 vrpciu_intr_evcnt(pci_chipset_tag_t pc, pci_intr_handle_t ih)
    510 {
    511 
    512 	/* XXX for now, no evcnt parent reported */
    513 
    514 	return (NULL);
    515 }
    516 
    517 void *
    518 vrpciu_intr_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih, int level,
    519     int (*func)(void *), void *arg)
    520 {
    521 
    522 	if (ih == -1)
    523 		return (NULL);
    524 	DPRINTF(("vrpciu_intr_establish: %lx\n", ih));
    525 
    526 	return (config_hook(CONFIG_HOOK_PCIINTR, ih, CONFIG_HOOK_EXCLUSIVE,
    527 	    (int (*)(void *, int, long, void *))func, arg));
    528 }
    529 
    530 void
    531 vrpciu_intr_disestablish(pci_chipset_tag_t pc, void *cookie)
    532 {
    533 
    534 	DPRINTF(("vrpciu_intr_disestablish: %p\n", cookie));
    535 	config_unhook(cookie);
    536 }
    537