Home | History | Annotate | Line # | Download | only in ofw
vlpci.c revision 1.9
      1  1.9  macallan /*	$NetBSD: vlpci.c,v 1.9 2019/01/03 18:28:21 macallan Exp $	*/
      2  1.1  jakllsch 
      3  1.1  jakllsch /*
      4  1.1  jakllsch  * Copyright (c) 2017 Jonathan A. Kollasch
      5  1.1  jakllsch  * All rights reserved.
      6  1.1  jakllsch  *
      7  1.1  jakllsch  * Redistribution and use in source and binary forms, with or without
      8  1.1  jakllsch  * modification, are permitted provided that the following conditions
      9  1.1  jakllsch  * are met:
     10  1.1  jakllsch  * 1. Redistributions of source code must retain the above copyright
     11  1.1  jakllsch  *    notice, this list of conditions and the following disclaimer.
     12  1.1  jakllsch  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  jakllsch  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  jakllsch  *    documentation and/or other materials provided with the distribution.
     15  1.1  jakllsch  *
     16  1.1  jakllsch  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     17  1.1  jakllsch  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  1.1  jakllsch  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  1.1  jakllsch  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
     20  1.1  jakllsch  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     21  1.1  jakllsch  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     22  1.1  jakllsch  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     23  1.1  jakllsch  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     24  1.1  jakllsch  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     25  1.1  jakllsch  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     26  1.1  jakllsch  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27  1.1  jakllsch  */
     28  1.1  jakllsch 
     29  1.1  jakllsch #include <sys/cdefs.h>
     30  1.9  macallan __KERNEL_RCSID(0, "$NetBSD: vlpci.c,v 1.9 2019/01/03 18:28:21 macallan Exp $");
     31  1.1  jakllsch 
     32  1.1  jakllsch #include "opt_pci.h"
     33  1.1  jakllsch #include "pci.h"
     34  1.1  jakllsch 
     35  1.1  jakllsch #include <sys/param.h>
     36  1.1  jakllsch #include <sys/bus.h>
     37  1.1  jakllsch #include <sys/device.h>
     38  1.1  jakllsch #include <sys/extent.h>
     39  1.1  jakllsch #include <sys/mutex.h>
     40  1.5  macallan #include <uvm/uvm.h>
     41  1.5  macallan #include <machine/pio.h>
     42  1.5  macallan #include <machine/pmap.h>
     43  1.5  macallan #include <machine/ofw.h>
     44  1.1  jakllsch 
     45  1.1  jakllsch #include <dev/isa/isavar.h>
     46  1.1  jakllsch 
     47  1.1  jakllsch #include <dev/ofw/openfirm.h>
     48  1.1  jakllsch 
     49  1.1  jakllsch #include <dev/pci/pcivar.h>
     50  1.1  jakllsch #include <dev/pci/pciconf.h>
     51  1.1  jakllsch #include <arm/pci_machdep.h>
     52  1.1  jakllsch 
     53  1.8      flxd #include <shark/ofw/vlpci.h>
     54  1.8      flxd 
     55  1.8      flxd #define VLPCI_ADDON_DEV_NO	6
     56  1.8      flxd #define VLPCI_IRQ		10
     57  1.8      flxd 
     58  1.8      flxd #define VLPCI_PCI_MEM_BASE	0x02000000
     59  1.8      flxd #define VLPCI_PCI_MEM_SZ	1048576
     60  1.8      flxd 
     61  1.8      flxd #define VLPCI_VL_MEM_BASE	0x08000000
     62  1.8      flxd #define VLPCI_VL_MEM_SZ		4194304
     63  1.8      flxd 
     64  1.1  jakllsch static int	vlpci_match(device_t, struct cfdata *, void *);
     65  1.1  jakllsch static void	vlpci_attach(device_t, device_t, void *);
     66  1.1  jakllsch 
     67  1.1  jakllsch static void	vlpci_pc_attach_hook(device_t, device_t,
     68  1.1  jakllsch     struct pcibus_attach_args *);
     69  1.1  jakllsch static int	vlpci_pc_bus_maxdevs(void *, int);
     70  1.1  jakllsch static pcitag_t	vlpci_pc_make_tag(void *, int, int, int);
     71  1.1  jakllsch static void	vlpci_pc_decompose_tag(void *, pcitag_t, int *, int *, int *);
     72  1.1  jakllsch static pcireg_t	vlpci_pc_conf_read(void *, pcitag_t, int);
     73  1.1  jakllsch static void	vlpci_pc_conf_write(void *, pcitag_t, int, pcireg_t);
     74  1.4  jakllsch 
     75  1.4  jakllsch static int	vlpci_pc_intr_map(const struct pci_attach_args *,
     76  1.4  jakllsch     pci_intr_handle_t *);
     77  1.4  jakllsch static const char * vlpci_pc_intr_string(void *, pci_intr_handle_t, char *,
     78  1.4  jakllsch     size_t);
     79  1.4  jakllsch static const struct evcnt * vlpci_pc_intr_evcnt(void *, pci_intr_handle_t);
     80  1.4  jakllsch static void *	vlpci_pc_intr_establish(void *, pci_intr_handle_t, int,
     81  1.9  macallan     int (*)(void *), void *, const char *);
     82  1.4  jakllsch static void 	vlpci_pc_intr_disestablish(void *, void *);
     83  1.4  jakllsch 
     84  1.1  jakllsch #ifdef __HAVE_PCI_CONF_HOOK
     85  1.1  jakllsch static int	vlpci_pc_conf_hook(void *, int, int, int, pcireg_t);
     86  1.1  jakllsch #endif
     87  1.1  jakllsch static void	vlpci_pc_conf_interrupt(void *, int, int, int, int, int *);
     88  1.1  jakllsch 
     89  1.1  jakllsch struct vlpci_softc {
     90  1.1  jakllsch 	device_t			sc_dev;
     91  1.1  jakllsch 	kmutex_t			sc_lock;
     92  1.1  jakllsch 	bus_space_handle_t		sc_conf_ioh;
     93  1.1  jakllsch 	bus_space_handle_t		sc_reg_ioh;
     94  1.1  jakllsch 	struct arm32_pci_chipset	sc_pc;
     95  1.1  jakllsch };
     96  1.1  jakllsch 
     97  1.1  jakllsch CFATTACH_DECL_NEW(vlpci, sizeof(struct vlpci_softc),
     98  1.1  jakllsch     vlpci_match, vlpci_attach, NULL, NULL);
     99  1.1  jakllsch 
    100  1.1  jakllsch static const char * const compat_strings[] = { "via,vt82c505", NULL };
    101  1.1  jakllsch 
    102  1.5  macallan vaddr_t vlpci_mem_vaddr = 0;
    103  1.5  macallan paddr_t vlpci_mem_paddr;
    104  1.5  macallan struct bus_space vlpci_memt;
    105  1.5  macallan 
    106  1.1  jakllsch static void
    107  1.1  jakllsch regwrite_1(struct vlpci_softc * const sc, uint8_t off, uint8_t val)
    108  1.1  jakllsch {
    109  1.7      flxd 
    110  1.1  jakllsch 	mutex_spin_enter(&sc->sc_lock);
    111  1.8      flxd 	bus_space_write_1(&isa_io_bs_tag, sc->sc_reg_ioh, VLPCI_INTREG_IDX_OFF,
    112  1.8      flxd 	    off);
    113  1.8      flxd 	bus_space_write_1(&isa_io_bs_tag, sc->sc_reg_ioh, VLPCI_INTREG_DATA_OFF,
    114  1.8      flxd 	    val);
    115  1.1  jakllsch 	mutex_spin_exit(&sc->sc_lock);
    116  1.1  jakllsch }
    117  1.1  jakllsch 
    118  1.5  macallan static uint8_t
    119  1.5  macallan regread_1(struct vlpci_softc * const sc, uint8_t off)
    120  1.5  macallan {
    121  1.5  macallan 	uint8_t reg;
    122  1.5  macallan 
    123  1.5  macallan 	mutex_spin_enter(&sc->sc_lock);
    124  1.8      flxd 	bus_space_write_1(&isa_io_bs_tag, sc->sc_reg_ioh, VLPCI_INTREG_IDX_OFF,
    125  1.8      flxd 	    off);
    126  1.8      flxd 	reg = bus_space_read_1(&isa_io_bs_tag, sc->sc_reg_ioh,
    127  1.8      flxd 	    VLPCI_INTREG_DATA_OFF);
    128  1.5  macallan 	mutex_spin_exit(&sc->sc_lock);
    129  1.5  macallan 	return reg;
    130  1.5  macallan }
    131  1.5  macallan 
    132  1.5  macallan static void
    133  1.5  macallan vlpci_dump_window(struct vlpci_softc *sc, int num)
    134  1.5  macallan {
    135  1.8      flxd 	int regaddr = VLPCI_PCI_WND_HIADDR_REG(num);
    136  1.5  macallan 	uint32_t addr, size;
    137  1.5  macallan 	uint8_t attr;
    138  1.5  macallan 
    139  1.5  macallan 	addr = regread_1(sc, regaddr) << 24;
    140  1.5  macallan 	addr |= regread_1(sc, regaddr + 1) << 16;
    141  1.5  macallan 	attr = regread_1(sc, regaddr + 2);
    142  1.8      flxd 	size = 0x00010000 << __SHIFTOUT(attr, VLPCI_PCI_WND_ATTR_SZ);
    143  1.7      flxd 	printf("memory window #%d at %08x size %08x flags %x\n", num, addr,
    144  1.7      flxd 	    size, attr);
    145  1.5  macallan }
    146  1.5  macallan 
    147  1.5  macallan static int
    148  1.7      flxd vlpci_map(void *t, bus_addr_t bpa, bus_size_t size, int cacheable,
    149  1.7      flxd     bus_space_handle_t *bshp)
    150  1.5  macallan {
    151  1.7      flxd 
    152  1.8      flxd 	*bshp = vlpci_mem_vaddr - VLPCI_PCI_MEM_BASE + bpa;
    153  1.7      flxd 	printf("%s: %08lx -> %08lx\n", __func__, bpa, *bshp);
    154  1.5  macallan 	return(0);
    155  1.5  macallan }
    156  1.5  macallan 
    157  1.5  macallan static paddr_t
    158  1.5  macallan vlpci_mmap(void *cookie, bus_addr_t addr, off_t off, int prot,
    159  1.5  macallan     int flags)
    160  1.5  macallan {
    161  1.5  macallan 	paddr_t ret;
    162  1.5  macallan 
    163  1.5  macallan 	ret = vlpci_mem_paddr + addr + off;
    164  1.5  macallan 
    165  1.7      flxd 	if (flags & BUS_SPACE_MAP_PREFETCHABLE)
    166  1.5  macallan 		return (arm_btop(ret) | ARM32_MMAP_WRITECOMBINE);
    167  1.7      flxd 	else
    168  1.7      flxd 		return arm_btop(ret);
    169  1.5  macallan }
    170  1.5  macallan 
    171  1.8      flxd static void
    172  1.8      flxd vlpci_steer_irq(struct vlpci_softc * const sc)
    173  1.8      flxd {
    174  1.8      flxd 	const unsigned int_ctl[] = {
    175  1.8      flxd 		VLPCI_INT_CTL_INTA, VLPCI_INT_CTL_INTB,
    176  1.8      flxd 		VLPCI_INT_CTL_INTC, VLPCI_INT_CTL_INTD
    177  1.8      flxd 	};
    178  1.8      flxd 	uint8_t val;
    179  1.8      flxd 
    180  1.8      flxd 	for (size_t i = 0; i < __arraycount(int_ctl); i++) {
    181  1.8      flxd 		val = regread_1(sc, VLPCI_INT_CTL_REG(int_ctl[i]));
    182  1.8      flxd 		val &= ~VLPCI_INT_CTL_INT2IRQ(int_ctl[i]);
    183  1.8      flxd 		val |= VLPCI_INT_CTL_ENA(int_ctl[i]);
    184  1.8      flxd 		val |= __SHIFTIN(VLPCI_INT_CTL_IRQ(VLPCI_IRQ),
    185  1.8      flxd 		    VLPCI_INT_CTL_INT2IRQ(int_ctl[i]));
    186  1.8      flxd 		regwrite_1(sc, VLPCI_INT_CTL_REG(int_ctl[i]), val);
    187  1.8      flxd 	}
    188  1.8      flxd }
    189  1.8      flxd 
    190  1.1  jakllsch static int
    191  1.1  jakllsch vlpci_match(device_t parent, struct cfdata *match, void *aux)
    192  1.1  jakllsch {
    193  1.1  jakllsch 	struct ofbus_attach_args * const oba = aux;
    194  1.1  jakllsch 
    195  1.1  jakllsch 	if (of_compatible(oba->oba_phandle, compat_strings) < 0)
    196  1.1  jakllsch 		return 0;
    197  1.1  jakllsch 
    198  1.2      flxd 	return 2;	/* beat generic ofbus */
    199  1.1  jakllsch }
    200  1.1  jakllsch 
    201  1.1  jakllsch static void
    202  1.1  jakllsch vlpci_attach(device_t parent, device_t self, void *aux)
    203  1.1  jakllsch {
    204  1.1  jakllsch 	struct vlpci_softc * const sc = device_private(self);
    205  1.1  jakllsch 	pci_chipset_tag_t const pc = &sc->sc_pc;
    206  1.1  jakllsch 	struct pcibus_attach_args pba;
    207  1.8      flxd 	pcitag_t tag;
    208  1.8      flxd 	pcireg_t cmd;
    209  1.1  jakllsch 
    210  1.1  jakllsch 	aprint_normal("\n");
    211  1.1  jakllsch 
    212  1.1  jakllsch 	sc->sc_dev = self;
    213  1.1  jakllsch 	mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_HIGH);
    214  1.1  jakllsch 	memset(&pba, 0, sizeof(pba));
    215  1.1  jakllsch 
    216  1.8      flxd 	if (bus_space_map(&isa_io_bs_tag, VLPCI_INTREG_BASE, VLPCI_INTREG_SZ,
    217  1.1  jakllsch 	    0, &sc->sc_reg_ioh) != 0) {
    218  1.8      flxd 		aprint_error_dev(self, "failed to map internal reg port\n");
    219  1.1  jakllsch 		return;
    220  1.1  jakllsch 	}
    221  1.8      flxd 	if (bus_space_map(&isa_io_bs_tag, VLPCI_CFGREG_BASE, VLPCI_CFGREG_SZ,
    222  1.1  jakllsch 	    0, &sc->sc_conf_ioh) != 0) {
    223  1.8      flxd 		aprint_error_dev(self, "failed to map configuration port\n");
    224  1.1  jakllsch 		return;
    225  1.1  jakllsch 	}
    226  1.1  jakllsch 
    227  1.1  jakllsch 	/* Enable VLB/PCI bridge */
    228  1.8      flxd 	regwrite_1(sc, VLPCI_MISC_1_REG, VLPCI_MISC_1_LOCAL_PIN |
    229  1.8      flxd 	    VLPCI_MISC_1_COMPAT_ISA_BOFF);
    230  1.8      flxd 	regwrite_1(sc, VLPCI_MISC_CTL_REG, __SHIFTIN(VLPCI_MISC_CTL_HIADDR_DIS,
    231  1.8      flxd 	    VLPCI_MISC_CTL_HIADDR) | VLPCI_MISC_CTL_IOCHCK_PIN);
    232  1.8      flxd 	regwrite_1(sc, VLPCI_CFG_MISC_CTL_REG,
    233  1.8      flxd 	    __SHIFTIN(VLPCI_CFG_MISC_CTL_INT_CTL_CONV,
    234  1.8      flxd 	    VLPCI_CFG_MISC_CTL_INT_CTL) | VLPCI_CFG_MISC_CTL_LREQI_LGNTO_PIN);
    235  1.8      flxd 	regwrite_1(sc, VLPCI_IRQ_MODE_REG, 0x00); /* don't do per-INTx conversions */
    236  1.8      flxd 	vlpci_steer_irq(sc);
    237  1.5  macallan 	/*
    238  1.5  macallan 	 * XXX
    239  1.5  macallan 	 * set memory size to 255MB, so the bridge knows which cycles go to RAM
    240  1.5  macallan 	 * shark's RAM is in the upper half of the lower 256MB, part of the
    241  1.5  macallan 	 * lower half is occupied by the graphics chip
    242  1.5  macallan 	 * ... or that's the theory. OF puts PCI BARS at 0x02000000 which
    243  1.5  macallan 	 * overlaps with when we do this and pci memory access doesn't work.
    244  1.5  macallan 	 */
    245  1.8      flxd 	regwrite_1(sc, VLPCI_OBD_MEM_SZ_REG, 1);
    246  1.5  macallan 
    247  1.8      flxd 	regwrite_1(sc, VLPCI_BUF_CTL_REG, VLPCI_BUF_CTL_PCI_DYN_ACC_DEC);
    248  1.8      flxd 	regwrite_1(sc, VLPCI_VL_TIM_REG, VLPCI_VL_TIM_OBD_MEM_1ST_DAT);
    249  1.8      flxd 	printf("reg 0x83 %02x\n", regread_1(sc, VLPCI_VL_TIM_REG));
    250  1.5  macallan 
    251  1.5  macallan #if 1
    252  1.5  macallan 	/* program window #0 to 0x08000000 */
    253  1.8      flxd 	regwrite_1(sc, VLPCI_PCI_WND_HIADDR_REG(VLPCI_PCI_WND_NO_1),
    254  1.8      flxd 	    VLPCI_PCI_WND_HIADDR_MEM(VLPCI_VL_MEM_BASE));
    255  1.8      flxd 	regwrite_1(sc, VLPCI_PCI_WND_LOADDR_REG(VLPCI_PCI_WND_NO_1),
    256  1.8      flxd 	    VLPCI_PCI_WND_LOADDR_MEM(VLPCI_VL_MEM_BASE));
    257  1.8      flxd 	regwrite_1(sc, VLPCI_PCI_WND_ATTR_REG(VLPCI_PCI_WND_NO_1),
    258  1.8      flxd 	    VLPCI_PCI_WND_ATTR_VL |
    259  1.8      flxd 	    __SHIFTIN(VLPCI_PCI_WND_ATTR_SZ_MEM(VLPCI_VL_MEM_SZ),
    260  1.8      flxd 	    VLPCI_PCI_WND_ATTR_SZ));
    261  1.5  macallan #else
    262  1.8      flxd 	regwrite_1(sc, VLPCI_PCI_WND_HIADDR_REG(VLPCI_PCI_WND_NO_1), 0x00);
    263  1.8      flxd 	regwrite_1(sc, VLPCI_PCI_WND_LOADDR_REG(VLPCI_PCI_WND_NO_1), 0x00);
    264  1.8      flxd 	regwrite_1(sc, VLPCI_PCI_WND_ATTR_REG(VLPCI_PCI_WND_NO_1), 0x00);
    265  1.5  macallan #endif
    266  1.1  jakllsch 
    267  1.8      flxd 	vlpci_mem_paddr = VLPCI_PCI_MEM_BASE;	/* get from OF! */
    268  1.7      flxd 
    269  1.5  macallan 	/*
    270  1.5  macallan 	 * we map in 1MB at 0x02000000, so program window #1 accordingly
    271  1.5  macallan 	 */
    272  1.8      flxd 	regwrite_1(sc, VLPCI_PCI_WND_HIADDR_REG(VLPCI_PCI_WND_NO_2),
    273  1.8      flxd 	    VLPCI_PCI_WND_HIADDR_MEM(vlpci_mem_paddr));
    274  1.8      flxd 	regwrite_1(sc, VLPCI_PCI_WND_LOADDR_REG(VLPCI_PCI_WND_NO_2),
    275  1.8      flxd 	    VLPCI_PCI_WND_LOADDR_MEM(vlpci_mem_paddr));
    276  1.8      flxd 	regwrite_1(sc, VLPCI_PCI_WND_ATTR_REG(VLPCI_PCI_WND_NO_2),
    277  1.8      flxd 	    VLPCI_PCI_WND_ATTR_PCI |
    278  1.8      flxd 	    __SHIFTIN(VLPCI_PCI_WND_ATTR_SZ_MEM(VLPCI_PCI_MEM_SZ),
    279  1.8      flxd 	    VLPCI_PCI_WND_ATTR_SZ));
    280  1.5  macallan 
    281  1.5  macallan 	/* now map in some of the memory space */
    282  1.5  macallan 	printf("vlpci_mem_vaddr %08lx\n", vlpci_mem_vaddr);
    283  1.5  macallan 	memcpy(&vlpci_memt, &isa_io_bs_tag, sizeof(struct bus_space));
    284  1.5  macallan 	vlpci_memt.bs_cookie = (void *)vlpci_mem_vaddr;
    285  1.5  macallan 	vlpci_memt.bs_map = vlpci_map;
    286  1.5  macallan 	vlpci_memt.bs_mmap = vlpci_mmap;
    287  1.7      flxd 
    288  1.1  jakllsch 	pc->pc_conf_v = sc;
    289  1.1  jakllsch 	pc->pc_attach_hook = vlpci_pc_attach_hook;
    290  1.1  jakllsch 	pc->pc_bus_maxdevs = vlpci_pc_bus_maxdevs;
    291  1.1  jakllsch 	pc->pc_make_tag = vlpci_pc_make_tag;
    292  1.1  jakllsch 	pc->pc_decompose_tag = vlpci_pc_decompose_tag;
    293  1.1  jakllsch 	pc->pc_conf_read = vlpci_pc_conf_read;
    294  1.1  jakllsch 	pc->pc_conf_write = vlpci_pc_conf_write;
    295  1.4  jakllsch 
    296  1.4  jakllsch 	pc->pc_intr_v = sc;
    297  1.4  jakllsch 	pc->pc_intr_map = vlpci_pc_intr_map;
    298  1.4  jakllsch 	pc->pc_intr_string = vlpci_pc_intr_string;
    299  1.4  jakllsch 	pc->pc_intr_evcnt = vlpci_pc_intr_evcnt;
    300  1.4  jakllsch 	pc->pc_intr_establish = vlpci_pc_intr_establish;
    301  1.4  jakllsch 	pc->pc_intr_disestablish = vlpci_pc_intr_disestablish;
    302  1.4  jakllsch 
    303  1.1  jakllsch #ifdef __HAVE_PCI_CONF_HOOK
    304  1.1  jakllsch 	pc->pc_conf_hook = vlpci_pc_conf_hook;
    305  1.1  jakllsch #endif
    306  1.1  jakllsch 	pc->pc_conf_interrupt = vlpci_pc_conf_interrupt;
    307  1.1  jakllsch 
    308  1.4  jakllsch 	/* try to assure IO space is enabled on the default device-function */
    309  1.8      flxd 	tag = vlpci_pc_make_tag(sc, 0, VLPCI_ADDON_DEV_NO, 0);
    310  1.8      flxd 	cmd = vlpci_pc_conf_read(sc, tag, PCI_COMMAND_STATUS_REG);
    311  1.8      flxd 	vlpci_pc_conf_write(sc, tag, PCI_COMMAND_STATUS_REG,
    312  1.8      flxd 	    cmd | PCI_COMMAND_IO_ENABLE);
    313  1.1  jakllsch 
    314  1.5  macallan 	pba.pba_flags = PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY;
    315  1.4  jakllsch 	pba.pba_iot = &isa_io_bs_tag;
    316  1.5  macallan 	pba.pba_memt = &vlpci_memt;
    317  1.5  macallan 	pba.pba_dmat = &isa_bus_dma_tag;
    318  1.1  jakllsch 	pba.pba_pc = &sc->sc_pc;
    319  1.1  jakllsch 	pba.pba_bus = 0;
    320  1.1  jakllsch 
    321  1.7      flxd 	printf("dma %lx %lx, %lx\n", isa_bus_dma_tag._ranges[0].dr_sysbase,
    322  1.7      flxd 	    isa_bus_dma_tag._ranges[0].dr_busbase,
    323  1.7      flxd 	    isa_bus_dma_tag._ranges[0].dr_len);
    324  1.5  macallan 
    325  1.8      flxd 	vlpci_dump_window(sc, VLPCI_PCI_WND_NO_1);
    326  1.8      flxd 	vlpci_dump_window(sc, VLPCI_PCI_WND_NO_2);
    327  1.8      flxd 	vlpci_dump_window(sc, VLPCI_PCI_WND_NO_3);
    328  1.5  macallan 
    329  1.1  jakllsch 	config_found_ia(self, "pcibus", &pba, pcibusprint);
    330  1.1  jakllsch }
    331  1.1  jakllsch 
    332  1.1  jakllsch static void
    333  1.1  jakllsch vlpci_pc_attach_hook(device_t parent, device_t self,
    334  1.1  jakllsch     struct pcibus_attach_args *pba)
    335  1.1  jakllsch {
    336  1.1  jakllsch }
    337  1.1  jakllsch 
    338  1.1  jakllsch static int
    339  1.1  jakllsch vlpci_pc_bus_maxdevs(void *v, int busno)
    340  1.1  jakllsch {
    341  1.7      flxd 
    342  1.1  jakllsch 	return busno == 0 ? 32 : 0;
    343  1.1  jakllsch }
    344  1.1  jakllsch 
    345  1.1  jakllsch static pcitag_t
    346  1.1  jakllsch vlpci_pc_make_tag(void *v, int b, int d, int f)
    347  1.1  jakllsch {
    348  1.7      flxd 
    349  1.1  jakllsch 	return (b << 16) | (d << 11) | (f << 8);
    350  1.1  jakllsch }
    351  1.1  jakllsch 
    352  1.1  jakllsch static void
    353  1.1  jakllsch vlpci_pc_decompose_tag(void *v, pcitag_t tag, int *bp, int *dp, int *fp)
    354  1.1  jakllsch {
    355  1.7      flxd 
    356  1.1  jakllsch 	if (bp)
    357  1.1  jakllsch 		*bp = (tag >> 16) & 0xff;
    358  1.1  jakllsch 	if (dp)
    359  1.1  jakllsch 		*dp = (tag >> 11) & 0x1f;
    360  1.1  jakllsch 	if (fp)
    361  1.1  jakllsch 		*fp = (tag >> 8) & 0x7;
    362  1.1  jakllsch }
    363  1.1  jakllsch 
    364  1.1  jakllsch static pcireg_t
    365  1.1  jakllsch vlpci_pc_conf_read(void *v, pcitag_t tag, int offset)
    366  1.1  jakllsch {
    367  1.1  jakllsch 	struct vlpci_softc * const sc = v;
    368  1.1  jakllsch 	pcireg_t ret;
    369  1.1  jakllsch 
    370  1.1  jakllsch 	KASSERT((offset & 3) == 0);
    371  1.3  jakllsch 
    372  1.3  jakllsch 	if (offset >= PCI_CONF_SIZE)
    373  1.3  jakllsch 		return 0xffffffff;
    374  1.1  jakllsch 
    375  1.1  jakllsch 	mutex_spin_enter(&sc->sc_lock);
    376  1.8      flxd 	bus_space_write_4(&isa_io_bs_tag, sc->sc_conf_ioh,
    377  1.8      flxd 	    VLPCI_CFGREG_ADDR_OFF, 0x80000000UL|tag|offset);
    378  1.8      flxd 	ret = bus_space_read_4(&isa_io_bs_tag, sc->sc_conf_ioh,
    379  1.8      flxd 	    VLPCI_CFGREG_DATA_OFF);
    380  1.1  jakllsch 	mutex_spin_exit(&sc->sc_lock);
    381  1.1  jakllsch 
    382  1.1  jakllsch #if 0
    383  1.1  jakllsch 	device_printf(sc->sc_dev, "%s tag %x offset %x ret %x\n",
    384  1.1  jakllsch 	    __func__, (unsigned int)tag, offset, ret);
    385  1.1  jakllsch #endif
    386  1.1  jakllsch 
    387  1.1  jakllsch 	return ret;
    388  1.1  jakllsch }
    389  1.1  jakllsch 
    390  1.1  jakllsch static void
    391  1.1  jakllsch vlpci_pc_conf_write(void *v, pcitag_t tag, int offset, pcireg_t val)
    392  1.1  jakllsch {
    393  1.1  jakllsch 	struct vlpci_softc * const sc = v;
    394  1.1  jakllsch 
    395  1.1  jakllsch 	KASSERT((offset & 3) == 0);
    396  1.3  jakllsch 
    397  1.3  jakllsch 	if (offset >= PCI_CONF_SIZE)
    398  1.3  jakllsch 		return;
    399  1.1  jakllsch 
    400  1.1  jakllsch #if 0
    401  1.1  jakllsch 	device_printf(sc->sc_dev, "%s tag %x offset %x val %x\n",
    402  1.1  jakllsch 	    __func__, (unsigned int)tag, offset, val);
    403  1.1  jakllsch #endif
    404  1.1  jakllsch 
    405  1.1  jakllsch 	mutex_spin_enter(&sc->sc_lock);
    406  1.8      flxd 	bus_space_write_4(&isa_io_bs_tag, sc->sc_conf_ioh,
    407  1.8      flxd 	    VLPCI_CFGREG_ADDR_OFF, 0x80000000UL|tag|offset);
    408  1.8      flxd 	bus_space_write_4(&isa_io_bs_tag, sc->sc_conf_ioh,
    409  1.8      flxd 	    VLPCI_CFGREG_DATA_OFF, val);
    410  1.1  jakllsch 	mutex_spin_exit(&sc->sc_lock);
    411  1.1  jakllsch }
    412  1.1  jakllsch 
    413  1.4  jakllsch static int
    414  1.4  jakllsch vlpci_pc_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ih)
    415  1.4  jakllsch {
    416  1.7      flxd 
    417  1.4  jakllsch 	switch (pa->pa_intrpin) {
    418  1.4  jakllsch 	default:
    419  1.4  jakllsch 	case 0:
    420  1.4  jakllsch 		return EINVAL;
    421  1.4  jakllsch 	case 1:
    422  1.4  jakllsch 	case 2:
    423  1.4  jakllsch 	case 3:
    424  1.4  jakllsch 	case 4:
    425  1.8      flxd 		*ih = VLPCI_IRQ;
    426  1.4  jakllsch 		return 0;
    427  1.4  jakllsch 	}
    428  1.4  jakllsch }
    429  1.4  jakllsch 
    430  1.4  jakllsch static const char *
    431  1.4  jakllsch vlpci_pc_intr_string(void *v, pci_intr_handle_t ih, char *buf, size_t len)
    432  1.4  jakllsch {
    433  1.4  jakllsch 
    434  1.4  jakllsch 	if (ih == PCI_INTERRUPT_PIN_NONE)
    435  1.4  jakllsch 		return NULL;
    436  1.9  macallan 	snprintf(buf, len, "irq %llu", ih);
    437  1.4  jakllsch 	return buf;
    438  1.4  jakllsch }
    439  1.4  jakllsch 
    440  1.4  jakllsch static const struct evcnt *
    441  1.4  jakllsch vlpci_pc_intr_evcnt(void *v, pci_intr_handle_t ih)
    442  1.4  jakllsch {
    443  1.7      flxd 
    444  1.4  jakllsch 	return NULL;
    445  1.4  jakllsch }
    446  1.4  jakllsch 
    447  1.4  jakllsch static void *
    448  1.4  jakllsch vlpci_pc_intr_establish(void *v, pci_intr_handle_t pih, int ipl,
    449  1.9  macallan     int (*callback)(void *), void *arg, const char *foo)
    450  1.4  jakllsch {
    451  1.7      flxd 
    452  1.4  jakllsch 	if (pih == 0)
    453  1.4  jakllsch 		return NULL;
    454  1.4  jakllsch 
    455  1.4  jakllsch 	return isa_intr_establish(NULL, pih, IST_LEVEL, ipl, callback, arg);
    456  1.4  jakllsch }
    457  1.4  jakllsch 
    458  1.4  jakllsch static void
    459  1.4  jakllsch vlpci_pc_intr_disestablish(void *v, void *w)
    460  1.4  jakllsch {
    461  1.6    martin 
    462  1.6    martin 	return isa_intr_disestablish(NULL, v);
    463  1.4  jakllsch }
    464  1.4  jakllsch 
    465  1.1  jakllsch #ifdef __HAVE_PCI_CONF_HOOK
    466  1.1  jakllsch static int
    467  1.1  jakllsch vlpci_pc_conf_hook(void *v, int b, int d, int f, pcireg_t id)
    468  1.1  jakllsch {
    469  1.7      flxd 
    470  1.5  macallan 	return PCI_CONF_DEFAULT /*& ~PCI_CONF_ENABLE_BM*/;
    471  1.1  jakllsch }
    472  1.1  jakllsch #endif
    473  1.1  jakllsch 
    474  1.1  jakllsch static void
    475  1.1  jakllsch vlpci_pc_conf_interrupt(void *v, int bus, int dev, int ipin, int swiz,
    476  1.1  jakllsch     int *ilinep)
    477  1.1  jakllsch {
    478  1.7      flxd 
    479  1.1  jakllsch 	*ilinep = 0xff; /* XXX */
    480  1.1  jakllsch }
    481