Home | History | Annotate | Line # | Download | only in dev
admpci.c revision 1.3
      1  1.3    matt /* $NetBSD: admpci.c,v 1.3 2010/12/20 00:25:38 matt Exp $ */
      2  1.1  dyoung 
      3  1.1  dyoung /*-
      4  1.1  dyoung  * Copyright (c) 2007 David Young.  All rights reserved.
      5  1.1  dyoung  *
      6  1.1  dyoung  * Redistribution and use in source and binary forms, with or
      7  1.1  dyoung  * without modification, are permitted provided that the following
      8  1.1  dyoung  * conditions are met:
      9  1.1  dyoung  * 1. Redistributions of source code must retain the above copyright
     10  1.1  dyoung  *    notice, this list of conditions and the following disclaimer.
     11  1.1  dyoung  * 2. Redistributions in binary form must reproduce the above
     12  1.1  dyoung  *    copyright notice, this list of conditions and the following
     13  1.1  dyoung  *    disclaimer in the documentation and/or other materials provided
     14  1.1  dyoung  *    with the distribution.
     15  1.1  dyoung  *
     16  1.1  dyoung  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
     17  1.1  dyoung  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     18  1.1  dyoung  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
     19  1.1  dyoung  * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR
     20  1.1  dyoung  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
     21  1.1  dyoung  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     22  1.1  dyoung  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
     23  1.1  dyoung  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24  1.1  dyoung  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
     25  1.1  dyoung  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     26  1.1  dyoung  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
     27  1.1  dyoung  * OF SUCH DAMAGE.
     28  1.1  dyoung  */
     29  1.1  dyoung /*-
     30  1.1  dyoung  * Copyright (c) 2006 Itronix Inc.
     31  1.1  dyoung  * All rights reserved.
     32  1.1  dyoung  *
     33  1.1  dyoung  * Written by Garrett D'Amore for Itronix Inc.
     34  1.1  dyoung  *
     35  1.1  dyoung  * Redistribution and use in source and binary forms, with or without
     36  1.1  dyoung  * modification, are permitted provided that the following conditions
     37  1.1  dyoung  * are met:
     38  1.1  dyoung  * 1. Redistributions of source code must retain the above copyright
     39  1.1  dyoung  *    notice, this list of conditions and the following disclaimer.
     40  1.1  dyoung  * 2. Redistributions in binary form must reproduce the above copyright
     41  1.1  dyoung  *    notice, this list of conditions and the following disclaimer in the
     42  1.1  dyoung  *    documentation and/or other materials provided with the distribution.
     43  1.1  dyoung  * 3. The name of Itronix Inc. may not be used to endorse
     44  1.1  dyoung  *    or promote products derived from this software without specific
     45  1.1  dyoung  *    prior written permission.
     46  1.1  dyoung  *
     47  1.1  dyoung  * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
     48  1.1  dyoung  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     49  1.1  dyoung  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     50  1.1  dyoung  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
     51  1.1  dyoung  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     52  1.1  dyoung  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     53  1.1  dyoung  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     54  1.1  dyoung  * ON ANY THEORY OF LIABILITY, WHETHER IN
     55  1.1  dyoung  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     56  1.1  dyoung  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     57  1.1  dyoung  * POSSIBILITY OF SUCH DAMAGE.
     58  1.1  dyoung  */
     59  1.1  dyoung 
     60  1.1  dyoung #include "opt_pci.h"
     61  1.1  dyoung #include "pci.h"
     62  1.1  dyoung 
     63  1.1  dyoung #include <sys/cdefs.h>
     64  1.3    matt __KERNEL_RCSID(0, "$NetBSD: admpci.c,v 1.3 2010/12/20 00:25:38 matt Exp $");
     65  1.1  dyoung 
     66  1.1  dyoung #include <sys/types.h>
     67  1.1  dyoung #include <sys/param.h>
     68  1.1  dyoung #include <sys/time.h>
     69  1.1  dyoung #include <sys/systm.h>
     70  1.1  dyoung #include <sys/errno.h>
     71  1.1  dyoung #include <sys/device.h>
     72  1.1  dyoung #include <sys/malloc.h>
     73  1.1  dyoung #include <sys/extent.h>
     74  1.1  dyoung 
     75  1.1  dyoung #include <uvm/uvm_extern.h>
     76  1.1  dyoung 
     77  1.1  dyoung #include <machine/bus.h>
     78  1.1  dyoung #include <machine/cpu.h>
     79  1.1  dyoung #include <machine/pte.h>
     80  1.1  dyoung 
     81  1.1  dyoung #include <dev/pci/pcivar.h>
     82  1.1  dyoung #include <dev/pci/pcireg.h>
     83  1.1  dyoung #include <dev/pci/pciconf.h>
     84  1.1  dyoung 
     85  1.1  dyoung #ifdef	PCI_NETBSD_CONFIGURE
     86  1.1  dyoung #include <mips/cache.h>
     87  1.1  dyoung #endif
     88  1.1  dyoung 
     89  1.1  dyoung #include <mips/adm5120/include/adm5120_mainbusvar.h>
     90  1.1  dyoung #include <mips/adm5120/include/adm5120reg.h>
     91  1.1  dyoung #include <mips/adm5120/include/adm5120var.h>
     92  1.1  dyoung 
     93  1.1  dyoung #ifdef ADMPCI_DEBUG
     94  1.1  dyoung int admpci_debug = 1;
     95  1.1  dyoung #define	ADMPCI_DPRINTF(__fmt, ...)		\
     96  1.1  dyoung do {						\
     97  1.1  dyoung 	if (admpci_debug)			\
     98  1.1  dyoung 		printf((__fmt), __VA_ARGS__);	\
     99  1.1  dyoung } while (/*CONSTCOND*/0)
    100  1.1  dyoung #else /* !ADMPCI_DEBUG */
    101  1.1  dyoung #define	ADMPCI_DPRINTF(__fmt, ...)	do { } while (/*CONSTCOND*/0)
    102  1.1  dyoung #endif /* ADMPCI_DEBUG */
    103  1.1  dyoung 
    104  1.1  dyoung #define	ADMPCI_TAG_BUS_MASK		__BITS(23, 16)
    105  1.1  dyoung /* Bit 11 is reserved.  It selects the AHB-PCI bridge.  Let device 0
    106  1.1  dyoung  * be the bridge.  For all other device numbers, let bit[11] == 0.
    107  1.1  dyoung  */
    108  1.1  dyoung #define	ADMPCI_TAG_DEVICE_MASK		__BITS(15, 11)
    109  1.1  dyoung #define	ADMPCI_TAG_DEVICE_SUBMASK	__BITS(15, 12)
    110  1.1  dyoung #define	ADMPCI_TAG_DEVICE_BRIDGE	__BIT(11)
    111  1.1  dyoung #define	ADMPCI_TAG_FUNCTION_MASK	__BITS(10, 8)
    112  1.1  dyoung #define	ADMPCI_TAG_REGISTER_MASK	__BITS(7, 0)
    113  1.1  dyoung 
    114  1.1  dyoung #define	ADMPCI_MAX_DEVICE
    115  1.1  dyoung 
    116  1.1  dyoung struct admpci_softc {
    117  1.1  dyoung 	struct device			sc_dev;
    118  1.1  dyoung 	struct mips_pci_chipset		sc_pc;
    119  1.1  dyoung 
    120  1.1  dyoung 	bus_space_tag_t			sc_memt;
    121  1.1  dyoung 	bus_space_tag_t			sc_iot;
    122  1.1  dyoung 
    123  1.1  dyoung 	bus_space_tag_t			sc_conft;
    124  1.1  dyoung 	bus_space_handle_t		sc_addrh;
    125  1.1  dyoung 	bus_space_handle_t		sc_datah;
    126  1.1  dyoung };
    127  1.1  dyoung 
    128  1.1  dyoung int		admpcimatch(struct device *, struct cfdata *, void *);
    129  1.1  dyoung void		admpciattach(struct device *, struct device *, void *);
    130  1.1  dyoung 
    131  1.1  dyoung #if NPCI > 0
    132  1.1  dyoung static void admpci_attach_hook(struct device *, struct device *,
    133  1.1  dyoung     struct pcibus_attach_args *);
    134  1.1  dyoung static int admpci_bus_maxdevs(void *, int);
    135  1.1  dyoung static pcitag_t admpci_make_tag(void *, int, int, int);
    136  1.1  dyoung static void admpci_decompose_tag(void *, pcitag_t, int *, int *, int *);
    137  1.1  dyoung static pcireg_t admpci_conf_read(void *, pcitag_t, int);
    138  1.1  dyoung static void admpci_conf_write(void *, pcitag_t, int, pcireg_t);
    139  1.1  dyoung static const char *admpci_intr_string(void *, pci_intr_handle_t);
    140  1.1  dyoung static void admpci_conf_interrupt(void *, int, int, int, int, int *);
    141  1.1  dyoung static void *admpci_intr_establish(void *, pci_intr_handle_t, int,
    142  1.1  dyoung     int (*)(void *), void *);
    143  1.1  dyoung static void admpci_intr_disestablish(void *, void *);
    144  1.1  dyoung static int admpci_intr_map(struct pci_attach_args *, pci_intr_handle_t *);
    145  1.1  dyoung 
    146  1.1  dyoung #ifdef	PCI_NETBSD_CONFIGURE
    147  1.1  dyoung static struct extent	*io_ex = NULL;
    148  1.1  dyoung static struct extent	*mem_ex = NULL;
    149  1.1  dyoung #endif	/* PCI_NETBSD_CONFIGURE */
    150  1.1  dyoung 
    151  1.1  dyoung #endif	/* NPCI > 0 */
    152  1.1  dyoung 
    153  1.1  dyoung CFATTACH_DECL(admpci, sizeof(struct admpci_softc),
    154  1.1  dyoung     admpcimatch, admpciattach, NULL, NULL);
    155  1.1  dyoung 
    156  1.1  dyoung int admpci_found = 0;
    157  1.1  dyoung 
    158  1.1  dyoung /*
    159  1.1  dyoung  * Physical PCI addresses are 36-bits long, so we need to have
    160  1.1  dyoung  * adequate storage space for them.
    161  1.1  dyoung  */
    162  1.1  dyoung #if NPCI > 0
    163  1.1  dyoung #if !defined(_MIPS_PADDR_T_64BIT) && !defined(_LP64)
    164  1.1  dyoung #error	"admpci requires 64 bit paddr_t!"
    165  1.1  dyoung #endif
    166  1.1  dyoung #endif
    167  1.1  dyoung 
    168  1.1  dyoung int
    169  1.1  dyoung admpcimatch(struct device *parent, struct cfdata *match, void *aux)
    170  1.1  dyoung {
    171  1.1  dyoung 	struct mainbus_attach_args *ma = (struct mainbus_attach_args *)aux;
    172  1.1  dyoung 
    173  1.1  dyoung 	return !admpci_found && strcmp(ma->ma_name, "admpci") == 0;
    174  1.1  dyoung }
    175  1.1  dyoung 
    176  1.1  dyoung void
    177  1.1  dyoung admpciattach(struct device *parent, struct device *self, void *aux)
    178  1.1  dyoung {
    179  1.1  dyoung 	struct adm5120_config		*admc = &adm5120_configuration;
    180  1.1  dyoung 	struct admpci_softc		*sc = (struct admpci_softc *)self;
    181  1.1  dyoung 	struct mainbus_attach_args	*ma = (struct mainbus_attach_args *)aux;
    182  1.1  dyoung #if NPCI > 0
    183  1.1  dyoung 	u_long				result;
    184  1.1  dyoung 	pcitag_t			tag;
    185  1.1  dyoung 	struct pcibus_attach_args	pba;
    186  1.1  dyoung #endif
    187  1.1  dyoung 
    188  1.1  dyoung 	admpci_found = 1;
    189  1.1  dyoung 
    190  1.1  dyoung 	sc->sc_conft = ma->ma_obiot;
    191  1.1  dyoung 	if (bus_space_map(sc->sc_conft, ADM5120_BASE_PCI_CONFDATA, 4, 0,
    192  1.1  dyoung 		&sc->sc_datah) != 0) {
    193  1.1  dyoung 		printf(
    194  1.1  dyoung 		    "\n%s: unable to map PCI Configuration Data register\n",
    195  1.1  dyoung 		    device_xname(&sc->sc_dev));
    196  1.1  dyoung 		return;
    197  1.1  dyoung 	}
    198  1.1  dyoung 	if (bus_space_map(sc->sc_conft, ADM5120_BASE_PCI_CONFADDR, 4, 0,
    199  1.1  dyoung 		&sc->sc_addrh) != 0) {
    200  1.1  dyoung 		printf(
    201  1.1  dyoung 		    "\n%s: unable to map PCI Configuration Address register\n",
    202  1.1  dyoung 		    device_xname(&sc->sc_dev));
    203  1.1  dyoung 		return;
    204  1.1  dyoung 	}
    205  1.1  dyoung 
    206  1.3    matt 	printf(": ADM5120 Host-PCI Bridge, data %"PRIxBUSADDR
    207  1.3    matt 	    " addr %"PRIxBUSADDR", sc %p\n",
    208  1.1  dyoung 	    sc->sc_datah, sc->sc_addrh, (void *)sc);
    209  1.1  dyoung 
    210  1.1  dyoung #if NPCI > 0
    211  1.1  dyoung 	sc->sc_memt = &admc->pcimem_space;
    212  1.1  dyoung 	sc->sc_iot = &admc->pciio_space;
    213  1.1  dyoung 
    214  1.1  dyoung 	sc->sc_pc.pc_conf_v = sc;
    215  1.1  dyoung 	sc->sc_pc.pc_attach_hook = admpci_attach_hook;
    216  1.1  dyoung 	sc->sc_pc.pc_bus_maxdevs = admpci_bus_maxdevs;
    217  1.1  dyoung 	sc->sc_pc.pc_make_tag = admpci_make_tag;
    218  1.1  dyoung 	sc->sc_pc.pc_decompose_tag = admpci_decompose_tag;
    219  1.1  dyoung 	sc->sc_pc.pc_conf_read = admpci_conf_read;
    220  1.1  dyoung 	sc->sc_pc.pc_conf_write = admpci_conf_write;
    221  1.1  dyoung 
    222  1.1  dyoung 	sc->sc_pc.pc_intr_v = sc;
    223  1.1  dyoung 	sc->sc_pc.pc_intr_map = admpci_intr_map;
    224  1.1  dyoung 	sc->sc_pc.pc_intr_string = admpci_intr_string;
    225  1.1  dyoung 	sc->sc_pc.pc_intr_establish = admpci_intr_establish;
    226  1.1  dyoung 	sc->sc_pc.pc_intr_disestablish = admpci_intr_disestablish;
    227  1.1  dyoung 	sc->sc_pc.pc_conf_interrupt = admpci_conf_interrupt;
    228  1.1  dyoung 
    229  1.1  dyoung 	tag = pci_make_tag(&sc->sc_pc, 0, 0, 0);
    230  1.1  dyoung 	ADMPCI_DPRINTF("%s: BAR 0x10 0x%08x\n", __func__,
    231  1.1  dyoung 	    pci_conf_read(&sc->sc_pc, tag, PCI_MAPREG_START));
    232  1.1  dyoung 
    233  1.1  dyoung #ifdef PCI_NETBSD_CONFIGURE
    234  1.1  dyoung 	mem_ex = extent_create("pcimem",
    235  1.1  dyoung 	    ADM5120_BOTTOM, ADM5120_TOP,
    236  1.1  dyoung 	    M_DEVBUF, NULL, 0, EX_WAITOK);
    237  1.1  dyoung 	(void)extent_alloc_subregion(mem_ex,
    238  1.1  dyoung 	    ADM5120_BASE_SRAM1, ADM5120_BASE_PCI_MEM - 1,
    239  1.1  dyoung 	    ADM5120_BASE_PCI_MEM - ADM5120_BASE_SRAM1,
    240  1.1  dyoung 	    ADM5120_BASE_PCI_MEM - ADM5120_BASE_SRAM1,
    241  1.1  dyoung 	    0, EX_WAITOK, &result);
    242  1.1  dyoung 	(void)extent_alloc_subregion(mem_ex,
    243  1.1  dyoung 	    ADM5120_BASE_PCI_IO, ADM5120_TOP,
    244  1.1  dyoung 	    ADM5120_TOP - ADM5120_BASE_PCI_IO + 1,
    245  1.1  dyoung 	    ADM5120_TOP - ADM5120_BASE_PCI_IO + 1,
    246  1.1  dyoung 	    0, EX_WAITOK, &result);
    247  1.1  dyoung 
    248  1.1  dyoung 	io_ex = extent_create("pciio",
    249  1.1  dyoung 	    ADM5120_BASE_PCI_IO, ADM5120_BASE_PCI_CONFADDR - 1,
    250  1.1  dyoung 	    M_DEVBUF, NULL, 0, EX_WAITOK);
    251  1.1  dyoung 
    252  1.1  dyoung 	pci_configure_bus(&sc->sc_pc,
    253  1.1  dyoung 	    io_ex, mem_ex, NULL, 0, mips_dcache_align);
    254  1.1  dyoung 	extent_destroy(mem_ex);
    255  1.1  dyoung 	extent_destroy(io_ex);
    256  1.1  dyoung #endif
    257  1.1  dyoung 
    258  1.1  dyoung 	pba.pba_iot = sc->sc_iot;
    259  1.1  dyoung 	pba.pba_memt = sc->sc_memt;
    260  1.1  dyoung 	/* XXX: review dma tag logic */
    261  1.1  dyoung 	pba.pba_dmat = ma->ma_dmat;
    262  1.1  dyoung 	pba.pba_dmat64 = NULL;
    263  1.1  dyoung 	pba.pba_pc = &sc->sc_pc;
    264  1.1  dyoung 	pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
    265  1.1  dyoung 	pba.pba_bus = 0;
    266  1.1  dyoung 	pba.pba_bridgetag = NULL;
    267  1.1  dyoung 
    268  1.1  dyoung 	config_found_ia(self, "pcibus", &pba, pcibusprint);
    269  1.1  dyoung #endif	/* NPCI > 0 */
    270  1.1  dyoung }
    271  1.1  dyoung 
    272  1.1  dyoung #if NPCI > 0
    273  1.1  dyoung 
    274  1.1  dyoung void
    275  1.1  dyoung admpci_attach_hook(struct device *parent, struct device *self,
    276  1.1  dyoung     struct pcibus_attach_args *pba)
    277  1.1  dyoung {
    278  1.1  dyoung }
    279  1.1  dyoung 
    280  1.1  dyoung /* There are at most four devices on bus 0.  The ADM5120 has
    281  1.1  dyoung  * request/grant lines for 3 PCI devices: 1, 2, and 3.  The host
    282  1.1  dyoung  * bridge is device 0.
    283  1.1  dyoung  */
    284  1.1  dyoung int
    285  1.1  dyoung admpci_bus_maxdevs(void *v, int bus)
    286  1.1  dyoung {
    287  1.1  dyoung 	if (bus == 0)
    288  1.1  dyoung 		return 4;
    289  1.1  dyoung 
    290  1.1  dyoung 	return 1 + __SHIFTOUT_MASK(ADMPCI_TAG_DEVICE_MASK);
    291  1.1  dyoung }
    292  1.1  dyoung 
    293  1.1  dyoung pcitag_t
    294  1.1  dyoung admpci_make_tag(void *v, int bus, int device, int function)
    295  1.1  dyoung {
    296  1.1  dyoung 	if (bus > __SHIFTOUT_MASK(ADMPCI_TAG_BUS_MASK) ||
    297  1.1  dyoung 	    device > __SHIFTOUT_MASK(ADMPCI_TAG_DEVICE_MASK) ||
    298  1.1  dyoung 	    function > __SHIFTOUT_MASK(ADMPCI_TAG_FUNCTION_MASK))
    299  1.1  dyoung 		panic("%s: bad request", __func__);
    300  1.1  dyoung 
    301  1.1  dyoung 	return __SHIFTIN(bus, ADMPCI_TAG_BUS_MASK) |
    302  1.1  dyoung 	       __SHIFTIN(device, ADMPCI_TAG_DEVICE_MASK) |
    303  1.1  dyoung 	       __SHIFTIN(function, ADMPCI_TAG_FUNCTION_MASK);
    304  1.1  dyoung }
    305  1.1  dyoung 
    306  1.1  dyoung void
    307  1.1  dyoung admpci_decompose_tag(void *v, pcitag_t tag, int *b, int *d, int *f)
    308  1.1  dyoung {
    309  1.1  dyoung 	int bus, device, function;
    310  1.1  dyoung 
    311  1.1  dyoung 	bus = __SHIFTOUT(tag, ADMPCI_TAG_BUS_MASK);
    312  1.1  dyoung 	device = __SHIFTOUT(tag, ADMPCI_TAG_DEVICE_MASK);
    313  1.1  dyoung 	function = __SHIFTOUT(tag, ADMPCI_TAG_FUNCTION_MASK);
    314  1.1  dyoung 
    315  1.1  dyoung 	if (b != NULL)
    316  1.1  dyoung 		*b = bus;
    317  1.1  dyoung 	if (d != NULL)
    318  1.1  dyoung 		*d = device;
    319  1.1  dyoung 	if (f != NULL)
    320  1.1  dyoung 		*f = function;
    321  1.1  dyoung }
    322  1.1  dyoung 
    323  1.1  dyoung static int
    324  1.1  dyoung admpci_tag_to_addr(void *v, pcitag_t tag, int reg, bus_addr_t *addrp)
    325  1.1  dyoung {
    326  1.1  dyoung 	int bus, device, function;
    327  1.1  dyoung 
    328  1.1  dyoung 	KASSERT(addrp != NULL);
    329  1.1  dyoung 	/* panics if tag is not well-formed */
    330  1.1  dyoung 	admpci_decompose_tag(v, tag, &bus, &device, &function);
    331  1.1  dyoung 	if (reg > __SHIFTOUT_MASK(ADMPCI_TAG_REGISTER_MASK))
    332  1.1  dyoung 		panic("%s: bad register", __func__);
    333  1.1  dyoung 
    334  1.1  dyoung 	*addrp = 0x80000000 | tag | __SHIFTIN(reg, ADMPCI_TAG_REGISTER_MASK);
    335  1.1  dyoung 
    336  1.1  dyoung 	return 0;
    337  1.1  dyoung }
    338  1.1  dyoung 
    339  1.1  dyoung static pcireg_t
    340  1.1  dyoung admpci_conf_read(void *v, pcitag_t tag, int reg)
    341  1.1  dyoung {
    342  1.1  dyoung 	int s;
    343  1.1  dyoung 	struct admpci_softc *sc = (struct admpci_softc *)v;
    344  1.1  dyoung 	uint32_t data;
    345  1.1  dyoung 	bus_addr_t addr;
    346  1.1  dyoung 
    347  1.1  dyoung 	ADMPCI_DPRINTF("%s: sc %p tag %lx reg %d\n", __func__, (void *)sc, tag,
    348  1.1  dyoung 	    reg);
    349  1.1  dyoung 
    350  1.1  dyoung 	if (admpci_tag_to_addr(v, tag, reg, &addr) == -1)
    351  1.1  dyoung 		return 0xffffffff;
    352  1.1  dyoung 
    353  1.1  dyoung 	ADMPCI_DPRINTF("%s: sc_addrh %lx sc_datah %lx addr %lx\n", __func__,
    354  1.1  dyoung 	    sc->sc_addrh, sc->sc_datah, addr);
    355  1.1  dyoung 
    356  1.1  dyoung 	s = splhigh();
    357  1.1  dyoung 	bus_space_write_4(sc->sc_conft, sc->sc_addrh, 0, addr);
    358  1.1  dyoung 	data = bus_space_read_4(sc->sc_conft, sc->sc_datah, 0);
    359  1.1  dyoung 	splx(s);
    360  1.1  dyoung 
    361  1.1  dyoung 	ADMPCI_DPRINTF("%s: read 0x%" PRIx32 "\n", __func__, data);
    362  1.1  dyoung 	return data;
    363  1.1  dyoung }
    364  1.1  dyoung 
    365  1.1  dyoung void
    366  1.1  dyoung admpci_conf_write(void *v, pcitag_t tag, int reg, pcireg_t data)
    367  1.1  dyoung {
    368  1.1  dyoung 	int s;
    369  1.1  dyoung 	struct admpci_softc	*sc = (struct admpci_softc *)v;
    370  1.1  dyoung 	bus_addr_t addr;
    371  1.1  dyoung 
    372  1.1  dyoung 	ADMPCI_DPRINTF("%s: sc %p tag %lx reg %d\n", __func__, (void *)sc, tag,
    373  1.1  dyoung 	    reg);
    374  1.1  dyoung 
    375  1.1  dyoung 	if (admpci_tag_to_addr(v, tag, reg, &addr) == -1)
    376  1.1  dyoung 		return;
    377  1.1  dyoung 
    378  1.1  dyoung 	ADMPCI_DPRINTF("%s: sc_addrh %lx sc_datah %lx addr %lx\n", __func__,
    379  1.1  dyoung 	    sc->sc_addrh, sc->sc_datah, addr);
    380  1.1  dyoung 
    381  1.1  dyoung 	s = splhigh();
    382  1.1  dyoung 	bus_space_write_4(sc->sc_conft, sc->sc_addrh, 0, addr);
    383  1.1  dyoung 	bus_space_write_4(sc->sc_conft, sc->sc_datah, 0, data);
    384  1.1  dyoung 	splx(s);
    385  1.1  dyoung }
    386  1.1  dyoung 
    387  1.1  dyoung const char *
    388  1.1  dyoung admpci_intr_string(void *v, pci_intr_handle_t ih)
    389  1.1  dyoung {
    390  1.1  dyoung 	static char name[16];
    391  1.1  dyoung 
    392  1.1  dyoung 	(void)snprintf(name, sizeof(name), "irq %u", (unsigned)ih);
    393  1.1  dyoung 	return name;
    394  1.1  dyoung }
    395  1.1  dyoung 
    396  1.1  dyoung void *
    397  1.1  dyoung admpci_intr_establish(void *v, pci_intr_handle_t ih, int ipl,
    398  1.1  dyoung     int (*handler)(void *), void *arg)
    399  1.1  dyoung {
    400  1.1  dyoung 	return adm5120_intr_establish(ih, ipl, handler, arg);
    401  1.1  dyoung }
    402  1.1  dyoung 
    403  1.1  dyoung void
    404  1.1  dyoung admpci_intr_disestablish(void *v, void *cookie)
    405  1.1  dyoung {
    406  1.1  dyoung 	adm5120_intr_disestablish(cookie);
    407  1.1  dyoung }
    408  1.1  dyoung 
    409  1.1  dyoung void
    410  1.1  dyoung admpci_conf_interrupt(void *v, int bus, int dev, int ipin, int swiz, int *iline)
    411  1.1  dyoung {
    412  1.1  dyoung 	/*
    413  1.1  dyoung 	 * We let the machdep_pci_intr_map take care of IRQ routing.
    414  1.1  dyoung 	 * On some platforms the BIOS may have handled this properly,
    415  1.1  dyoung 	 * on others it might not have.  For now we avoid clobbering
    416  1.1  dyoung 	 * the settings establishsed by the BIOS, so that they will be
    417  1.1  dyoung 	 * there if the platform logic is confident that it can rely
    418  1.1  dyoung 	 * on them.
    419  1.1  dyoung 	 */
    420  1.1  dyoung }
    421  1.1  dyoung 
    422  1.1  dyoung /*
    423  1.1  dyoung  * Map the bus 0 device numbers 1, 2, and 3 to IRQ 6, 7, and 8,
    424  1.1  dyoung  * respectively.
    425  1.1  dyoung  *
    426  1.1  dyoung  * XXX How to handle bridges?
    427  1.1  dyoung  */
    428  1.1  dyoung static int
    429  1.1  dyoung admpci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    430  1.1  dyoung {
    431  1.1  dyoung 	int bus, device, function;
    432  1.1  dyoung 
    433  1.1  dyoung 	admpci_decompose_tag(pa->pa_pc->pc_conf_v, pa->pa_tag,
    434  1.1  dyoung 	    &bus, &device, &function);
    435  1.1  dyoung 
    436  1.1  dyoung 	if (bus != 0 || device > 3)
    437  1.1  dyoung 		return -1;
    438  1.1  dyoung 
    439  1.1  dyoung 	*ihp = (device - 1) + 6;
    440  1.1  dyoung 
    441  1.1  dyoung 	return 0;
    442  1.1  dyoung }
    443  1.1  dyoung #endif
    444