Home | History | Annotate | Line # | Download | only in gemini
gemini_pci.c revision 1.6
      1  1.6  cliff /*	$NetBSD: gemini_pci.c,v 1.6 2008/11/20 20:23:05 cliff Exp $	*/
      2  1.1   matt 
      3  1.1   matt /* adapted from:
      4  1.1   matt  *	NetBSD: i80312_pci.c,v 1.9 2005/12/11 12:16:51 christos Exp
      5  1.1   matt  */
      6  1.1   matt 
      7  1.1   matt /*
      8  1.1   matt  * Copyright (c) 2001 Wasabi Systems, Inc.
      9  1.1   matt  * All rights reserved.
     10  1.1   matt  *
     11  1.1   matt  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
     12  1.1   matt  *
     13  1.1   matt  * Redistribution and use in source and binary forms, with or without
     14  1.1   matt  * modification, are permitted provided that the following conditions
     15  1.1   matt  * are met:
     16  1.1   matt  * 1. Redistributions of source code must retain the above copyright
     17  1.1   matt  *    notice, this list of conditions and the following disclaimer.
     18  1.1   matt  * 2. Redistributions in binary form must reproduce the above copyright
     19  1.1   matt  *    notice, this list of conditions and the following disclaimer in the
     20  1.1   matt  *    documentation and/or other materials provided with the distribution.
     21  1.1   matt  * 3. All advertising materials mentioning features or use of this software
     22  1.1   matt  *    must display the following acknowledgement:
     23  1.1   matt  *	This product includes software developed for the NetBSD Project by
     24  1.1   matt  *	Wasabi Systems, Inc.
     25  1.1   matt  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     26  1.1   matt  *    or promote products derived from this software without specific prior
     27  1.1   matt  *    written permission.
     28  1.1   matt  *
     29  1.1   matt  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     30  1.1   matt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     31  1.1   matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     32  1.1   matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     33  1.1   matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     34  1.1   matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     35  1.1   matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     36  1.1   matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     37  1.1   matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     38  1.1   matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     39  1.1   matt  * POSSIBILITY OF SUCH DAMAGE.
     40  1.1   matt  */
     41  1.1   matt 
     42  1.1   matt /*
     43  1.1   matt  * PCI configuration support for i80312 Companion I/O chip.
     44  1.1   matt  */
     45  1.1   matt 
     46  1.1   matt #include <sys/cdefs.h>
     47  1.6  cliff __KERNEL_RCSID(0, "$NetBSD: gemini_pci.c,v 1.6 2008/11/20 20:23:05 cliff Exp $");
     48  1.1   matt 
     49  1.1   matt #include <sys/cdefs.h>
     50  1.1   matt 
     51  1.1   matt #include <sys/param.h>
     52  1.1   matt #include <sys/systm.h>
     53  1.1   matt #include <sys/device.h>
     54  1.1   matt #include <sys/extent.h>
     55  1.1   matt #include <sys/malloc.h>
     56  1.1   matt 
     57  1.1   matt #include <uvm/uvm_extern.h>
     58  1.1   matt 
     59  1.1   matt #include <machine/bus.h>
     60  1.1   matt #include <machine/intr.h>
     61  1.1   matt 
     62  1.1   matt #include <arm/pic/picvar.h>
     63  1.1   matt 
     64  1.1   matt #include <arm/gemini/gemini_reg.h>
     65  1.1   matt #include <arm/gemini/gemini_pcivar.h>
     66  1.1   matt #include <arm/gemini/gemini_obiovar.h>
     67  1.1   matt 
     68  1.1   matt #include <dev/pci/pcivar.h>
     69  1.1   matt #include <dev/pci/pcidevs.h>
     70  1.1   matt #include <dev/pci/pciconf.h>
     71  1.1   matt 
     72  1.1   matt #include <machine/pci_machdep.h>
     73  1.1   matt 
     74  1.3  cliff #include "opt_gemini.h"
     75  1.1   matt #include "opt_pci.h"
     76  1.1   matt #include "pci.h"
     77  1.1   matt 
     78  1.1   matt void		gemini_pci_attach_hook(struct device *, struct device *,
     79  1.1   matt 		    struct pcibus_attach_args *);
     80  1.1   matt int		gemini_pci_bus_maxdevs(void *, int);
     81  1.1   matt pcitag_t	gemini_pci_make_tag(void *, int, int, int);
     82  1.1   matt void		gemini_pci_decompose_tag(void *, pcitag_t, int *, int *,
     83  1.1   matt 		    int *);
     84  1.1   matt pcireg_t	gemini_pci_conf_read(void *, pcitag_t, int);
     85  1.1   matt void		gemini_pci_conf_write(void *, pcitag_t, int, pcireg_t);
     86  1.1   matt int		gemini_pci_conf_hook(pci_chipset_tag_t, int, int, int,
     87  1.1   matt 		    pcireg_t);
     88  1.1   matt 
     89  1.1   matt int		gemini_pci_intr_map(struct pci_attach_args *,
     90  1.1   matt 		    pci_intr_handle_t *);
     91  1.1   matt const char	*gemini_pci_intr_string(void *, pci_intr_handle_t);
     92  1.1   matt const struct evcnt *gemini_pci_intr_evcnt(void *, pci_intr_handle_t);
     93  1.1   matt void		*gemini_pci_intr_establish(void *, pci_intr_handle_t,
     94  1.1   matt 		    int, int (*)(void *), void *);
     95  1.1   matt void		gemini_pci_intr_disestablish(void *, void *);
     96  1.1   matt int		gemini_pci_intr_handler(void *v);
     97  1.1   matt 
     98  1.1   matt #define	PCI_CONF_LOCK(s)	(s) = disable_interrupts(I32_bit)
     99  1.1   matt #define	PCI_CONF_UNLOCK(s)	restore_interrupts((s))
    100  1.1   matt 
    101  1.1   matt int gemini_pci_debug=0;
    102  1.1   matt 
    103  1.1   matt struct gemini_pci_intrq {
    104  1.1   matt 	SIMPLEQ_ENTRY(gemini_pci_intrq) iq_q;
    105  1.1   matt 	int (*iq_func)(void *);
    106  1.1   matt 	void *iq_arg;
    107  1.1   matt 	void *iq_ih;
    108  1.1   matt };
    109  1.1   matt 
    110  1.1   matt static SIMPLEQ_HEAD(, gemini_pci_intrq) gemini_pci_intrq =
    111  1.1   matt 	SIMPLEQ_HEAD_INITIALIZER(gemini_pci_intrq);
    112  1.1   matt 
    113  1.1   matt static inline int
    114  1.1   matt gemini_pci_intrq_empty(void)
    115  1.1   matt {
    116  1.1   matt 	return SIMPLEQ_EMPTY(&gemini_pci_intrq);
    117  1.1   matt }
    118  1.1   matt 
    119  1.1   matt static inline void *
    120  1.1   matt gemini_pci_intrq_insert(void *ih, int (*func)(void *), void *arg)
    121  1.1   matt {
    122  1.1   matt 	struct gemini_pci_intrq *iqp;
    123  1.1   matt 
    124  1.1   matt         iqp = malloc(sizeof(*iqp), M_DEVBUF, M_NOWAIT|M_ZERO);
    125  1.1   matt         if (iqp == NULL) {
    126  1.1   matt 		printf("gemini_pci_intrq_insert: malloc failed\n");
    127  1.1   matt 		return NULL;
    128  1.1   matt 	}
    129  1.1   matt 
    130  1.1   matt         iqp->iq_func = func;
    131  1.1   matt         iqp->iq_arg = arg;
    132  1.1   matt         iqp->iq_ih = ih;
    133  1.1   matt         SIMPLEQ_INSERT_TAIL(&gemini_pci_intrq, iqp, iq_q);
    134  1.1   matt 
    135  1.1   matt 	return (void *)iqp;
    136  1.1   matt }
    137  1.1   matt 
    138  1.1   matt static inline void
    139  1.1   matt gemini_pci_intrq_remove(void *cookie)
    140  1.1   matt {
    141  1.1   matt 	struct gemini_pci_intrq *iqp;
    142  1.1   matt 
    143  1.1   matt 	SIMPLEQ_FOREACH(iqp, &gemini_pci_intrq, iq_q) {
    144  1.1   matt 		if ((void *)iqp == cookie) {
    145  1.1   matt 			SIMPLEQ_REMOVE(&gemini_pci_intrq,
    146  1.1   matt 				iqp, gemini_pci_intrq, iq_q);
    147  1.1   matt 			free(iqp, M_DEVBUF);
    148  1.1   matt 			return;
    149  1.1   matt 		}
    150  1.1   matt 	}
    151  1.1   matt }
    152  1.1   matt 
    153  1.1   matt static inline int
    154  1.1   matt gemini_pci_intrq_dispatch(void)
    155  1.1   matt {
    156  1.1   matt 	struct gemini_pci_intrq *iqp;
    157  1.1   matt 
    158  1.1   matt 	SIMPLEQ_FOREACH(iqp, &gemini_pci_intrq, iq_q) {
    159  1.1   matt 		(*iqp->iq_func)(iqp->iq_arg);
    160  1.1   matt 	}
    161  1.1   matt 
    162  1.1   matt 	return 1;
    163  1.1   matt }
    164  1.1   matt 
    165  1.1   matt void
    166  1.1   matt gemini_pci_init(pci_chipset_tag_t pc, void *cookie)
    167  1.1   matt {
    168  1.1   matt #if NPCI > 0 && defined(PCI_NETBSD_CONFIGURE)
    169  1.1   matt 	struct obio_softc *sc = cookie;
    170  1.1   matt 	struct extent *ioext, *memext;
    171  1.1   matt #endif
    172  1.1   matt 
    173  1.1   matt 	pc->pc_conf_v = cookie;
    174  1.1   matt 	pc->pc_attach_hook = gemini_pci_attach_hook;
    175  1.1   matt 	pc->pc_bus_maxdevs = gemini_pci_bus_maxdevs;
    176  1.1   matt 	pc->pc_make_tag = gemini_pci_make_tag;
    177  1.1   matt 	pc->pc_decompose_tag = gemini_pci_decompose_tag;
    178  1.1   matt 	pc->pc_conf_read = gemini_pci_conf_read;
    179  1.1   matt 	pc->pc_conf_write = gemini_pci_conf_write;
    180  1.1   matt 
    181  1.1   matt 	pc->pc_intr_v = cookie;
    182  1.1   matt 	pc->pc_intr_map = gemini_pci_intr_map;
    183  1.1   matt 	pc->pc_intr_string = gemini_pci_intr_string;
    184  1.1   matt 	pc->pc_intr_evcnt = gemini_pci_intr_evcnt;
    185  1.1   matt 	pc->pc_intr_establish = gemini_pci_intr_establish;
    186  1.1   matt 	pc->pc_intr_disestablish = gemini_pci_intr_disestablish;
    187  1.1   matt 
    188  1.1   matt 	pc->pc_conf_hook = gemini_pci_conf_hook;
    189  1.1   matt 
    190  1.1   matt 	/*
    191  1.1   matt 	 * initialize copy of CFG_CMD
    192  1.1   matt 	 */
    193  1.1   matt 	sc->sc_pci_chipset.pc_cfg_cmd =
    194  1.1   matt 		gemini_pci_conf_read(sc, 0, GEMINI_PCI_CFG_CMD);
    195  1.1   matt 
    196  1.1   matt #if NPCI > 0 && defined(PCI_NETBSD_CONFIGURE)
    197  1.1   matt 	/*
    198  1.1   matt 	 * Configure the PCI bus.
    199  1.1   matt 	 *
    200  1.1   matt 	 * XXX We need to revisit this.  We only configure the Secondary
    201  1.1   matt 	 * bus (and its children).  The bus configure code needs changes
    202  1.1   matt 	 * to support how the busses are arranged on this chip.  We also
    203  1.1   matt 	 * need to only configure devices in the private device space on
    204  1.1   matt 	 * the Secondary bus.
    205  1.1   matt 	 */
    206  1.1   matt 
    207  1.1   matt 	aprint_normal("%s: configuring Secondary PCI bus\n",
    208  1.6  cliff 		device_xname(sc->sc_dev));
    209  1.1   matt 
    210  1.1   matt 	/*
    211  1.2  cliff 	 * XXX PCI IO addr should be inherited ?
    212  1.1   matt 	 */
    213  1.1   matt 	ioext  = extent_create("pciio",
    214  1.1   matt 		GEMINI_PCIIO_BASE,
    215  1.1   matt 		GEMINI_PCIIO_BASE + GEMINI_PCIIO_SIZE - 1,
    216  1.1   matt 		M_DEVBUF, NULL, 0, EX_NOWAIT);
    217  1.1   matt 
    218  1.1   matt 	/*
    219  1.1   matt 	 * XXX PCI mem addr should be inherited ?
    220  1.1   matt 	 */
    221  1.1   matt 	memext = extent_create("pcimem",
    222  1.1   matt 		GEMINI_PCIMEM_BASE,
    223  1.1   matt 		GEMINI_PCIMEM_BASE + GEMINI_PCIMEM_SIZE - 1,
    224  1.1   matt 		M_DEVBUF, NULL, 0, EX_NOWAIT);
    225  1.1   matt 
    226  1.1   matt 	pci_configure_bus(pc, ioext, memext, NULL, 0, arm_dcache_align);
    227  1.1   matt 
    228  1.4  cliff 	gemini_pci_conf_write(sc, 0, GEMINI_PCI_CFG_REG_MEM1,
    229  1.5  cliff 		PCI_CFG_REG_MEM_BASE((GEMINI_DRAM_BASE + (GEMINI_BUSBASE * 1024 * 1024)))
    230  1.5  cliff 		| gemini_pci_cfg_reg_mem_size(MEMSIZE * 1024 * 1024));
    231  1.1   matt 
    232  1.1   matt 	extent_destroy(ioext);
    233  1.1   matt 	extent_destroy(memext);
    234  1.1   matt #endif
    235  1.1   matt }
    236  1.1   matt 
    237  1.1   matt void
    238  1.1   matt pci_conf_interrupt(pci_chipset_tag_t pc, int a, int b, int c, int d, int *p)
    239  1.1   matt {
    240  1.1   matt }
    241  1.1   matt 
    242  1.1   matt int
    243  1.1   matt gemini_pci_conf_hook(pci_chipset_tag_t pc, int bus, int device, int function, pcireg_t id)
    244  1.1   matt {
    245  1.1   matt 	int rv;
    246  1.1   matt 
    247  1.1   matt 	rv = PCI_CONF_ALL;
    248  1.1   matt 
    249  1.1   matt 	return rv;
    250  1.1   matt }
    251  1.1   matt 
    252  1.1   matt void
    253  1.1   matt gemini_pci_attach_hook(struct device *parent, struct device *self,
    254  1.1   matt 	struct pcibus_attach_args *pba)
    255  1.1   matt {
    256  1.1   matt 	/* Nothing to do. */
    257  1.1   matt }
    258  1.1   matt 
    259  1.1   matt int
    260  1.1   matt gemini_pci_bus_maxdevs(void *v, int busno)
    261  1.1   matt {
    262  1.1   matt 	return (32);
    263  1.1   matt }
    264  1.1   matt 
    265  1.1   matt pcitag_t
    266  1.1   matt gemini_pci_make_tag(void *v, int b, int d, int f)
    267  1.1   matt {
    268  1.1   matt 	return ((b << 16) | (d << 11) | (f << 8));
    269  1.1   matt }
    270  1.1   matt 
    271  1.1   matt void
    272  1.1   matt gemini_pci_decompose_tag(void *v, pcitag_t tag, int *bp, int *dp, int *fp)
    273  1.1   matt {
    274  1.1   matt 	if (bp != NULL)
    275  1.1   matt 		*bp = (tag >> 16) & 0xff;
    276  1.1   matt 	if (dp != NULL)
    277  1.1   matt 		*dp = (tag >> 11) & 0x1f;
    278  1.1   matt 	if (fp != NULL)
    279  1.1   matt 		*fp = (tag >> 8) & 0x7;
    280  1.1   matt }
    281  1.1   matt 
    282  1.1   matt struct pciconf_state {
    283  1.1   matt 	uint32_t ps_addr_val;
    284  1.1   matt 	int ps_b, ps_d, ps_f;
    285  1.1   matt };
    286  1.1   matt 
    287  1.1   matt static int
    288  1.1   matt gemini_pci_conf_setup(struct obio_softc *sc, pcitag_t tag, int offset,
    289  1.1   matt 	struct pciconf_state *ps)
    290  1.1   matt {
    291  1.1   matt 	gemini_pci_decompose_tag(sc, tag, &ps->ps_b, &ps->ps_d, &ps->ps_f);
    292  1.1   matt 
    293  1.1   matt 	ps->ps_addr_val =
    294  1.1   matt 		  PCI_CFG_CMD_ENB
    295  1.1   matt 		| PCI_CFG_CMD_BUSn(ps->ps_b)
    296  1.1   matt 		| PCI_CFG_CMD_DEVn(ps->ps_d)
    297  1.1   matt 		| PCI_CFG_CMD_FUNCn(ps->ps_f)
    298  1.1   matt 		| PCI_CFG_CMD_REGn(offset);
    299  1.1   matt 
    300  1.1   matt 	return (0);
    301  1.1   matt }
    302  1.1   matt 
    303  1.1   matt pcireg_t
    304  1.1   matt gemini_pci_conf_read(void *v, pcitag_t tag, int offset)
    305  1.1   matt {
    306  1.1   matt 	struct obio_softc *sc = v;
    307  1.1   matt 	struct pciconf_state ps;
    308  1.1   matt 	vaddr_t va;
    309  1.1   matt 	pcireg_t rv;
    310  1.1   matt 	u_int s;
    311  1.1   matt 
    312  1.1   matt 	if (gemini_pci_conf_setup(sc, tag, offset, &ps))
    313  1.1   matt 		return ((pcireg_t) -1);
    314  1.1   matt 
    315  1.1   matt 	PCI_CONF_LOCK(s);
    316  1.1   matt 
    317  1.1   matt 	if (sc->sc_pci_chipset.pc_cfg_cmd != ps.ps_addr_val) {
    318  1.1   matt 		sc->sc_pci_chipset.pc_cfg_cmd = ps.ps_addr_val;
    319  1.1   matt 		bus_space_write_4(sc->sc_iot, sc->sc_pcicfg_ioh,
    320  1.1   matt 			GEMINI_PCI_CFG_CMD, ps.ps_addr_val);
    321  1.1   matt 	}
    322  1.1   matt 
    323  1.1   matt 	va = (vaddr_t) bus_space_vaddr(sc->sc_iot, sc->sc_pcicfg_ioh);
    324  1.1   matt 	if (badaddr_read((void *) (va + GEMINI_PCI_CFG_DATA), sizeof(rv), &rv)) {
    325  1.1   matt 		/*
    326  1.1   matt 		 * XXX Clear the Master Abort
    327  1.1   matt 		 */
    328  1.1   matt #if 1
    329  1.1   matt 		printf("conf_read: %d/%d/%d bad address\n",
    330  1.1   matt 			ps.ps_b, ps.ps_d, ps.ps_f);
    331  1.1   matt #endif
    332  1.1   matt 		rv = (pcireg_t) -1;
    333  1.1   matt 	}
    334  1.1   matt 
    335  1.1   matt 	PCI_CONF_UNLOCK(s);
    336  1.1   matt 
    337  1.1   matt 	if (gemini_pci_debug) {
    338  1.1   matt 		printf("conf_read: tag %#lx, %d/%d/%d, ps_addr_val %#x, rv %#x\n",
    339  1.1   matt 			tag, ps.ps_b, ps.ps_d, ps.ps_f, ps.ps_addr_val, rv);
    340  1.1   matt 		Debugger();
    341  1.1   matt 	}
    342  1.1   matt 
    343  1.1   matt 	return (rv);
    344  1.1   matt }
    345  1.1   matt 
    346  1.1   matt void
    347  1.1   matt gemini_pci_conf_write(void *v, pcitag_t tag, int offset, pcireg_t val)
    348  1.1   matt {
    349  1.1   matt 	struct obio_softc *sc = v;
    350  1.1   matt 	struct pciconf_state ps;
    351  1.1   matt 	u_int s;
    352  1.1   matt 
    353  1.1   matt 	if (gemini_pci_conf_setup(sc, tag, offset, &ps))
    354  1.1   matt 		return;
    355  1.1   matt 
    356  1.1   matt 	PCI_CONF_LOCK(s);
    357  1.1   matt 
    358  1.1   matt 	if (sc->sc_pci_chipset.pc_cfg_cmd != ps.ps_addr_val) {
    359  1.1   matt 		sc->sc_pci_chipset.pc_cfg_cmd = ps.ps_addr_val;
    360  1.1   matt 		bus_space_write_4(sc->sc_iot, sc->sc_pcicfg_ioh,
    361  1.1   matt 			GEMINI_PCI_CFG_CMD, ps.ps_addr_val);
    362  1.1   matt 	}
    363  1.1   matt 
    364  1.1   matt 	bus_space_write_4(sc->sc_iot, sc->sc_pcicfg_ioh,
    365  1.1   matt 		GEMINI_PCI_CFG_DATA, val);
    366  1.1   matt 
    367  1.1   matt 	PCI_CONF_UNLOCK(s);
    368  1.1   matt }
    369  1.1   matt 
    370  1.1   matt int
    371  1.1   matt gemini_pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    372  1.1   matt {
    373  1.1   matt 	int irq;
    374  1.1   matt 
    375  1.1   matt 	irq = 8;
    376  1.1   matt 
    377  1.1   matt 	*ihp = irq;
    378  1.1   matt 	return 0;
    379  1.1   matt }
    380  1.1   matt 
    381  1.1   matt const char *
    382  1.1   matt gemini_pci_intr_string(void *v, pci_intr_handle_t ih)
    383  1.1   matt {
    384  1.1   matt 	const char *name = "pci";
    385  1.1   matt 
    386  1.1   matt 	return (name);
    387  1.1   matt }
    388  1.1   matt 
    389  1.1   matt const struct evcnt *
    390  1.1   matt gemini_pci_intr_evcnt(void *v, pci_intr_handle_t ih)
    391  1.1   matt {
    392  1.1   matt 	return NULL;
    393  1.1   matt }
    394  1.1   matt 
    395  1.1   matt void *
    396  1.1   matt gemini_pci_intr_establish(void *v, pci_intr_handle_t pci_ih, int ipl,
    397  1.1   matt 	int (*func)(void *), void *arg)
    398  1.1   matt {
    399  1.1   matt 	pcireg_t r;
    400  1.1   matt 	void *ih=NULL;
    401  1.1   matt 	int irq;
    402  1.1   matt 	void *cookie;
    403  1.1   matt 
    404  1.1   matt 	irq = (int)pci_ih;
    405  1.1   matt 
    406  1.1   matt 	r = gemini_pci_conf_read(v, 0, GEMINI_PCI_CFG_REG_CTL2);
    407  1.1   matt 	r |= CFG_REG_CTL2_INTMASK_INT_ABCD;
    408  1.1   matt 	gemini_pci_conf_write(v, 0, GEMINI_PCI_CFG_REG_CTL2, r);
    409  1.1   matt 
    410  1.1   matt 	if (gemini_pci_intrq_empty())
    411  1.1   matt 		ih = intr_establish(irq, ipl, IST_LEVEL_HIGH,
    412  1.1   matt 			gemini_pci_intr_handler, v);
    413  1.1   matt 
    414  1.1   matt 	cookie = gemini_pci_intrq_insert(ih, func, arg);
    415  1.1   matt 	if (cookie == NULL) {
    416  1.1   matt 		if (gemini_pci_intrq_empty())
    417  1.1   matt 			intr_disestablish(ih);
    418  1.1   matt 	}
    419  1.1   matt 
    420  1.1   matt 	return cookie;
    421  1.1   matt }
    422  1.1   matt 
    423  1.1   matt void
    424  1.1   matt gemini_pci_intr_disestablish(void *v, void *cookie)
    425  1.1   matt {
    426  1.1   matt 	pcireg_t r;
    427  1.1   matt 	struct gemini_pci_intrq *iqp = (struct gemini_pci_intrq *)cookie;;
    428  1.1   matt 	void *ih = iqp->iq_ih;
    429  1.1   matt 
    430  1.1   matt 	gemini_pci_intrq_remove(cookie);
    431  1.1   matt 	if (gemini_pci_intrq_empty()) {
    432  1.1   matt 		r = gemini_pci_conf_read(v, 0, GEMINI_PCI_CFG_REG_CTL2);
    433  1.1   matt 		r &= ~CFG_REG_CTL2_INTMASK_INT_ABCD;
    434  1.1   matt 		gemini_pci_conf_write(v, 0, GEMINI_PCI_CFG_REG_CTL2, r);
    435  1.1   matt 		intr_disestablish(ih);
    436  1.1   matt 	}
    437  1.1   matt }
    438  1.1   matt 
    439  1.1   matt int
    440  1.1   matt gemini_pci_intr_handler(void *v)
    441  1.1   matt {
    442  1.1   matt 	pcireg_t r;
    443  1.1   matt 	int rv;
    444  1.1   matt 
    445  1.1   matt 	/*
    446  1.1   matt 	 * dispatch PCI device interrupt handlers
    447  1.1   matt 	 */
    448  1.1   matt 	rv = gemini_pci_intrq_dispatch();
    449  1.1   matt 
    450  1.1   matt 	/*
    451  1.1   matt 	 * ack Gemini PCI interrupts
    452  1.1   matt 	 */
    453  1.1   matt 	r = gemini_pci_conf_read(v, 0, GEMINI_PCI_CFG_REG_CTL2);
    454  1.1   matt 	gemini_pci_conf_write(v, 0, GEMINI_PCI_CFG_REG_CTL2, r);
    455  1.1   matt 
    456  1.1   matt 	return rv;
    457  1.1   matt }
    458  1.1   matt 
    459