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