Home | History | Annotate | Line # | Download | only in ofw
vlpci.c revision 1.13
      1  1.13   thorpej /*	$NetBSD: vlpci.c,v 1.13 2022/01/21 19:12:28 thorpej 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.13   thorpej __KERNEL_RCSID(0, "$NetBSD: vlpci.c,v 1.13 2022/01/21 19:12:28 thorpej 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.10   thorpej static const struct device_compatible_entry compat_data[] = {
    101  1.10   thorpej 	{ .compat = "via,vt82c505" },
    102  1.10   thorpej 	DEVICE_COMPAT_EOL
    103  1.10   thorpej };
    104   1.1  jakllsch 
    105   1.5  macallan vaddr_t vlpci_mem_vaddr = 0;
    106   1.5  macallan paddr_t vlpci_mem_paddr;
    107   1.5  macallan struct bus_space vlpci_memt;
    108   1.5  macallan 
    109   1.1  jakllsch static void
    110   1.1  jakllsch regwrite_1(struct vlpci_softc * const sc, uint8_t off, uint8_t val)
    111   1.1  jakllsch {
    112   1.7      flxd 
    113   1.1  jakllsch 	mutex_spin_enter(&sc->sc_lock);
    114   1.8      flxd 	bus_space_write_1(&isa_io_bs_tag, sc->sc_reg_ioh, VLPCI_INTREG_IDX_OFF,
    115   1.8      flxd 	    off);
    116   1.8      flxd 	bus_space_write_1(&isa_io_bs_tag, sc->sc_reg_ioh, VLPCI_INTREG_DATA_OFF,
    117   1.8      flxd 	    val);
    118   1.1  jakllsch 	mutex_spin_exit(&sc->sc_lock);
    119   1.1  jakllsch }
    120   1.1  jakllsch 
    121   1.5  macallan static uint8_t
    122   1.5  macallan regread_1(struct vlpci_softc * const sc, uint8_t off)
    123   1.5  macallan {
    124   1.5  macallan 	uint8_t reg;
    125   1.5  macallan 
    126   1.5  macallan 	mutex_spin_enter(&sc->sc_lock);
    127   1.8      flxd 	bus_space_write_1(&isa_io_bs_tag, sc->sc_reg_ioh, VLPCI_INTREG_IDX_OFF,
    128   1.8      flxd 	    off);
    129   1.8      flxd 	reg = bus_space_read_1(&isa_io_bs_tag, sc->sc_reg_ioh,
    130   1.8      flxd 	    VLPCI_INTREG_DATA_OFF);
    131   1.5  macallan 	mutex_spin_exit(&sc->sc_lock);
    132   1.5  macallan 	return reg;
    133   1.5  macallan }
    134   1.5  macallan 
    135   1.5  macallan static void
    136   1.5  macallan vlpci_dump_window(struct vlpci_softc *sc, int num)
    137   1.5  macallan {
    138   1.8      flxd 	int regaddr = VLPCI_PCI_WND_HIADDR_REG(num);
    139   1.5  macallan 	uint32_t addr, size;
    140   1.5  macallan 	uint8_t attr;
    141   1.5  macallan 
    142   1.5  macallan 	addr = regread_1(sc, regaddr) << 24;
    143   1.5  macallan 	addr |= regread_1(sc, regaddr + 1) << 16;
    144   1.5  macallan 	attr = regread_1(sc, regaddr + 2);
    145   1.8      flxd 	size = 0x00010000 << __SHIFTOUT(attr, VLPCI_PCI_WND_ATTR_SZ);
    146   1.7      flxd 	printf("memory window #%d at %08x size %08x flags %x\n", num, addr,
    147   1.7      flxd 	    size, attr);
    148   1.5  macallan }
    149   1.5  macallan 
    150   1.5  macallan static int
    151   1.7      flxd vlpci_map(void *t, bus_addr_t bpa, bus_size_t size, int cacheable,
    152   1.7      flxd     bus_space_handle_t *bshp)
    153   1.5  macallan {
    154   1.7      flxd 
    155   1.8      flxd 	*bshp = vlpci_mem_vaddr - VLPCI_PCI_MEM_BASE + bpa;
    156   1.7      flxd 	printf("%s: %08lx -> %08lx\n", __func__, bpa, *bshp);
    157   1.5  macallan 	return(0);
    158   1.5  macallan }
    159   1.5  macallan 
    160   1.5  macallan static paddr_t
    161   1.5  macallan vlpci_mmap(void *cookie, bus_addr_t addr, off_t off, int prot,
    162   1.5  macallan     int flags)
    163   1.5  macallan {
    164   1.5  macallan 	paddr_t ret;
    165   1.5  macallan 
    166   1.5  macallan 	ret = vlpci_mem_paddr + addr + off;
    167   1.5  macallan 
    168   1.7      flxd 	if (flags & BUS_SPACE_MAP_PREFETCHABLE)
    169   1.5  macallan 		return (arm_btop(ret) | ARM32_MMAP_WRITECOMBINE);
    170   1.7      flxd 	else
    171   1.7      flxd 		return arm_btop(ret);
    172   1.5  macallan }
    173   1.5  macallan 
    174   1.8      flxd static void
    175   1.8      flxd vlpci_steer_irq(struct vlpci_softc * const sc)
    176   1.8      flxd {
    177   1.8      flxd 	const unsigned int_ctl[] = {
    178   1.8      flxd 		VLPCI_INT_CTL_INTA, VLPCI_INT_CTL_INTB,
    179   1.8      flxd 		VLPCI_INT_CTL_INTC, VLPCI_INT_CTL_INTD
    180   1.8      flxd 	};
    181   1.8      flxd 	uint8_t val;
    182   1.8      flxd 
    183   1.8      flxd 	for (size_t i = 0; i < __arraycount(int_ctl); i++) {
    184   1.8      flxd 		val = regread_1(sc, VLPCI_INT_CTL_REG(int_ctl[i]));
    185   1.8      flxd 		val &= ~VLPCI_INT_CTL_INT2IRQ(int_ctl[i]);
    186   1.8      flxd 		val |= VLPCI_INT_CTL_ENA(int_ctl[i]);
    187   1.8      flxd 		val |= __SHIFTIN(VLPCI_INT_CTL_IRQ(VLPCI_IRQ),
    188   1.8      flxd 		    VLPCI_INT_CTL_INT2IRQ(int_ctl[i]));
    189   1.8      flxd 		regwrite_1(sc, VLPCI_INT_CTL_REG(int_ctl[i]), val);
    190   1.8      flxd 	}
    191   1.8      flxd }
    192   1.8      flxd 
    193   1.1  jakllsch static int
    194   1.1  jakllsch vlpci_match(device_t parent, struct cfdata *match, void *aux)
    195   1.1  jakllsch {
    196   1.1  jakllsch 	struct ofbus_attach_args * const oba = aux;
    197   1.1  jakllsch 
    198  1.10   thorpej 						/* beat generic ofbus */
    199  1.10   thorpej 	return of_compatible_match(oba->oba_phandle, compat_data) * 2;
    200   1.1  jakllsch }
    201   1.1  jakllsch 
    202   1.1  jakllsch static void
    203   1.1  jakllsch vlpci_attach(device_t parent, device_t self, void *aux)
    204   1.1  jakllsch {
    205  1.11   thorpej 	struct ofbus_attach_args * const oba = aux;
    206   1.1  jakllsch 	struct vlpci_softc * const sc = device_private(self);
    207   1.1  jakllsch 	pci_chipset_tag_t const pc = &sc->sc_pc;
    208   1.1  jakllsch 	struct pcibus_attach_args pba;
    209   1.8      flxd 	pcitag_t tag;
    210   1.8      flxd 	pcireg_t cmd;
    211   1.1  jakllsch 
    212   1.1  jakllsch 	aprint_normal("\n");
    213   1.1  jakllsch 
    214   1.1  jakllsch 	sc->sc_dev = self;
    215   1.1  jakllsch 	mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_HIGH);
    216   1.1  jakllsch 	memset(&pba, 0, sizeof(pba));
    217   1.1  jakllsch 
    218   1.8      flxd 	if (bus_space_map(&isa_io_bs_tag, VLPCI_INTREG_BASE, VLPCI_INTREG_SZ,
    219   1.1  jakllsch 	    0, &sc->sc_reg_ioh) != 0) {
    220   1.8      flxd 		aprint_error_dev(self, "failed to map internal reg port\n");
    221   1.1  jakllsch 		return;
    222   1.1  jakllsch 	}
    223   1.8      flxd 	if (bus_space_map(&isa_io_bs_tag, VLPCI_CFGREG_BASE, VLPCI_CFGREG_SZ,
    224   1.1  jakllsch 	    0, &sc->sc_conf_ioh) != 0) {
    225   1.8      flxd 		aprint_error_dev(self, "failed to map configuration port\n");
    226   1.1  jakllsch 		return;
    227   1.1  jakllsch 	}
    228   1.1  jakllsch 
    229   1.1  jakllsch 	/* Enable VLB/PCI bridge */
    230   1.8      flxd 	regwrite_1(sc, VLPCI_MISC_1_REG, VLPCI_MISC_1_LOCAL_PIN |
    231   1.8      flxd 	    VLPCI_MISC_1_COMPAT_ISA_BOFF);
    232   1.8      flxd 	regwrite_1(sc, VLPCI_MISC_CTL_REG, __SHIFTIN(VLPCI_MISC_CTL_HIADDR_DIS,
    233   1.8      flxd 	    VLPCI_MISC_CTL_HIADDR) | VLPCI_MISC_CTL_IOCHCK_PIN);
    234   1.8      flxd 	regwrite_1(sc, VLPCI_CFG_MISC_CTL_REG,
    235   1.8      flxd 	    __SHIFTIN(VLPCI_CFG_MISC_CTL_INT_CTL_CONV,
    236   1.8      flxd 	    VLPCI_CFG_MISC_CTL_INT_CTL) | VLPCI_CFG_MISC_CTL_LREQI_LGNTO_PIN);
    237   1.8      flxd 	regwrite_1(sc, VLPCI_IRQ_MODE_REG, 0x00); /* don't do per-INTx conversions */
    238   1.8      flxd 	vlpci_steer_irq(sc);
    239   1.5  macallan 	/*
    240   1.5  macallan 	 * XXX
    241   1.5  macallan 	 * set memory size to 255MB, so the bridge knows which cycles go to RAM
    242   1.5  macallan 	 * shark's RAM is in the upper half of the lower 256MB, part of the
    243   1.5  macallan 	 * lower half is occupied by the graphics chip
    244   1.5  macallan 	 * ... or that's the theory. OF puts PCI BARS at 0x02000000 which
    245   1.5  macallan 	 * overlaps with when we do this and pci memory access doesn't work.
    246   1.5  macallan 	 */
    247   1.8      flxd 	regwrite_1(sc, VLPCI_OBD_MEM_SZ_REG, 1);
    248   1.5  macallan 
    249   1.8      flxd 	regwrite_1(sc, VLPCI_BUF_CTL_REG, VLPCI_BUF_CTL_PCI_DYN_ACC_DEC);
    250   1.8      flxd 	regwrite_1(sc, VLPCI_VL_TIM_REG, VLPCI_VL_TIM_OBD_MEM_1ST_DAT);
    251   1.8      flxd 	printf("reg 0x83 %02x\n", regread_1(sc, VLPCI_VL_TIM_REG));
    252   1.5  macallan 
    253   1.5  macallan #if 1
    254   1.5  macallan 	/* program window #0 to 0x08000000 */
    255   1.8      flxd 	regwrite_1(sc, VLPCI_PCI_WND_HIADDR_REG(VLPCI_PCI_WND_NO_1),
    256   1.8      flxd 	    VLPCI_PCI_WND_HIADDR_MEM(VLPCI_VL_MEM_BASE));
    257   1.8      flxd 	regwrite_1(sc, VLPCI_PCI_WND_LOADDR_REG(VLPCI_PCI_WND_NO_1),
    258   1.8      flxd 	    VLPCI_PCI_WND_LOADDR_MEM(VLPCI_VL_MEM_BASE));
    259   1.8      flxd 	regwrite_1(sc, VLPCI_PCI_WND_ATTR_REG(VLPCI_PCI_WND_NO_1),
    260   1.8      flxd 	    VLPCI_PCI_WND_ATTR_VL |
    261   1.8      flxd 	    __SHIFTIN(VLPCI_PCI_WND_ATTR_SZ_MEM(VLPCI_VL_MEM_SZ),
    262   1.8      flxd 	    VLPCI_PCI_WND_ATTR_SZ));
    263   1.5  macallan #else
    264   1.8      flxd 	regwrite_1(sc, VLPCI_PCI_WND_HIADDR_REG(VLPCI_PCI_WND_NO_1), 0x00);
    265   1.8      flxd 	regwrite_1(sc, VLPCI_PCI_WND_LOADDR_REG(VLPCI_PCI_WND_NO_1), 0x00);
    266   1.8      flxd 	regwrite_1(sc, VLPCI_PCI_WND_ATTR_REG(VLPCI_PCI_WND_NO_1), 0x00);
    267   1.5  macallan #endif
    268   1.1  jakllsch 
    269   1.8      flxd 	vlpci_mem_paddr = VLPCI_PCI_MEM_BASE;	/* get from OF! */
    270   1.7      flxd 
    271   1.5  macallan 	/*
    272   1.5  macallan 	 * we map in 1MB at 0x02000000, so program window #1 accordingly
    273   1.5  macallan 	 */
    274   1.8      flxd 	regwrite_1(sc, VLPCI_PCI_WND_HIADDR_REG(VLPCI_PCI_WND_NO_2),
    275   1.8      flxd 	    VLPCI_PCI_WND_HIADDR_MEM(vlpci_mem_paddr));
    276   1.8      flxd 	regwrite_1(sc, VLPCI_PCI_WND_LOADDR_REG(VLPCI_PCI_WND_NO_2),
    277   1.8      flxd 	    VLPCI_PCI_WND_LOADDR_MEM(vlpci_mem_paddr));
    278   1.8      flxd 	regwrite_1(sc, VLPCI_PCI_WND_ATTR_REG(VLPCI_PCI_WND_NO_2),
    279   1.8      flxd 	    VLPCI_PCI_WND_ATTR_PCI |
    280   1.8      flxd 	    __SHIFTIN(VLPCI_PCI_WND_ATTR_SZ_MEM(VLPCI_PCI_MEM_SZ),
    281   1.8      flxd 	    VLPCI_PCI_WND_ATTR_SZ));
    282   1.5  macallan 
    283   1.5  macallan 	/* now map in some of the memory space */
    284   1.5  macallan 	printf("vlpci_mem_vaddr %08lx\n", vlpci_mem_vaddr);
    285   1.5  macallan 	memcpy(&vlpci_memt, &isa_io_bs_tag, sizeof(struct bus_space));
    286   1.5  macallan 	vlpci_memt.bs_cookie = (void *)vlpci_mem_vaddr;
    287   1.5  macallan 	vlpci_memt.bs_map = vlpci_map;
    288   1.5  macallan 	vlpci_memt.bs_mmap = vlpci_mmap;
    289   1.7      flxd 
    290   1.1  jakllsch 	pc->pc_conf_v = sc;
    291   1.1  jakllsch 	pc->pc_attach_hook = vlpci_pc_attach_hook;
    292   1.1  jakllsch 	pc->pc_bus_maxdevs = vlpci_pc_bus_maxdevs;
    293   1.1  jakllsch 	pc->pc_make_tag = vlpci_pc_make_tag;
    294   1.1  jakllsch 	pc->pc_decompose_tag = vlpci_pc_decompose_tag;
    295   1.1  jakllsch 	pc->pc_conf_read = vlpci_pc_conf_read;
    296   1.1  jakllsch 	pc->pc_conf_write = vlpci_pc_conf_write;
    297   1.4  jakllsch 
    298   1.4  jakllsch 	pc->pc_intr_v = sc;
    299   1.4  jakllsch 	pc->pc_intr_map = vlpci_pc_intr_map;
    300   1.4  jakllsch 	pc->pc_intr_string = vlpci_pc_intr_string;
    301   1.4  jakllsch 	pc->pc_intr_evcnt = vlpci_pc_intr_evcnt;
    302   1.4  jakllsch 	pc->pc_intr_establish = vlpci_pc_intr_establish;
    303   1.4  jakllsch 	pc->pc_intr_disestablish = vlpci_pc_intr_disestablish;
    304   1.4  jakllsch 
    305   1.1  jakllsch #ifdef __HAVE_PCI_CONF_HOOK
    306   1.1  jakllsch 	pc->pc_conf_hook = vlpci_pc_conf_hook;
    307   1.1  jakllsch #endif
    308   1.1  jakllsch 	pc->pc_conf_interrupt = vlpci_pc_conf_interrupt;
    309   1.1  jakllsch 
    310   1.4  jakllsch 	/* try to assure IO space is enabled on the default device-function */
    311   1.8      flxd 	tag = vlpci_pc_make_tag(sc, 0, VLPCI_ADDON_DEV_NO, 0);
    312   1.8      flxd 	cmd = vlpci_pc_conf_read(sc, tag, PCI_COMMAND_STATUS_REG);
    313   1.8      flxd 	vlpci_pc_conf_write(sc, tag, PCI_COMMAND_STATUS_REG,
    314   1.8      flxd 	    cmd | PCI_COMMAND_IO_ENABLE);
    315   1.1  jakllsch 
    316   1.5  macallan 	pba.pba_flags = PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY;
    317   1.4  jakllsch 	pba.pba_iot = &isa_io_bs_tag;
    318   1.5  macallan 	pba.pba_memt = &vlpci_memt;
    319   1.5  macallan 	pba.pba_dmat = &isa_bus_dma_tag;
    320   1.1  jakllsch 	pba.pba_pc = &sc->sc_pc;
    321   1.1  jakllsch 	pba.pba_bus = 0;
    322   1.1  jakllsch 
    323   1.7      flxd 	printf("dma %lx %lx, %lx\n", isa_bus_dma_tag._ranges[0].dr_sysbase,
    324   1.7      flxd 	    isa_bus_dma_tag._ranges[0].dr_busbase,
    325   1.7      flxd 	    isa_bus_dma_tag._ranges[0].dr_len);
    326   1.5  macallan 
    327   1.8      flxd 	vlpci_dump_window(sc, VLPCI_PCI_WND_NO_1);
    328   1.8      flxd 	vlpci_dump_window(sc, VLPCI_PCI_WND_NO_2);
    329   1.8      flxd 	vlpci_dump_window(sc, VLPCI_PCI_WND_NO_3);
    330   1.5  macallan 
    331  1.11   thorpej 	config_found(self, &pba, pcibusprint,
    332  1.13   thorpej 	    CFARGS(.devhandle = device_handle(self)));
    333   1.1  jakllsch }
    334   1.1  jakllsch 
    335   1.1  jakllsch static void
    336   1.1  jakllsch vlpci_pc_attach_hook(device_t parent, device_t self,
    337   1.1  jakllsch     struct pcibus_attach_args *pba)
    338   1.1  jakllsch {
    339   1.1  jakllsch }
    340   1.1  jakllsch 
    341   1.1  jakllsch static int
    342   1.1  jakllsch vlpci_pc_bus_maxdevs(void *v, int busno)
    343   1.1  jakllsch {
    344   1.7      flxd 
    345   1.1  jakllsch 	return busno == 0 ? 32 : 0;
    346   1.1  jakllsch }
    347   1.1  jakllsch 
    348   1.1  jakllsch static pcitag_t
    349   1.1  jakllsch vlpci_pc_make_tag(void *v, int b, int d, int f)
    350   1.1  jakllsch {
    351   1.7      flxd 
    352   1.1  jakllsch 	return (b << 16) | (d << 11) | (f << 8);
    353   1.1  jakllsch }
    354   1.1  jakllsch 
    355   1.1  jakllsch static void
    356   1.1  jakllsch vlpci_pc_decompose_tag(void *v, pcitag_t tag, int *bp, int *dp, int *fp)
    357   1.1  jakllsch {
    358   1.7      flxd 
    359   1.1  jakllsch 	if (bp)
    360   1.1  jakllsch 		*bp = (tag >> 16) & 0xff;
    361   1.1  jakllsch 	if (dp)
    362   1.1  jakllsch 		*dp = (tag >> 11) & 0x1f;
    363   1.1  jakllsch 	if (fp)
    364   1.1  jakllsch 		*fp = (tag >> 8) & 0x7;
    365   1.1  jakllsch }
    366   1.1  jakllsch 
    367   1.1  jakllsch static pcireg_t
    368   1.1  jakllsch vlpci_pc_conf_read(void *v, pcitag_t tag, int offset)
    369   1.1  jakllsch {
    370   1.1  jakllsch 	struct vlpci_softc * const sc = v;
    371   1.1  jakllsch 	pcireg_t ret;
    372   1.1  jakllsch 
    373   1.1  jakllsch 	KASSERT((offset & 3) == 0);
    374   1.3  jakllsch 
    375   1.3  jakllsch 	if (offset >= PCI_CONF_SIZE)
    376   1.3  jakllsch 		return 0xffffffff;
    377   1.1  jakllsch 
    378   1.1  jakllsch 	mutex_spin_enter(&sc->sc_lock);
    379   1.8      flxd 	bus_space_write_4(&isa_io_bs_tag, sc->sc_conf_ioh,
    380   1.8      flxd 	    VLPCI_CFGREG_ADDR_OFF, 0x80000000UL|tag|offset);
    381   1.8      flxd 	ret = bus_space_read_4(&isa_io_bs_tag, sc->sc_conf_ioh,
    382   1.8      flxd 	    VLPCI_CFGREG_DATA_OFF);
    383   1.1  jakllsch 	mutex_spin_exit(&sc->sc_lock);
    384   1.1  jakllsch 
    385   1.1  jakllsch #if 0
    386   1.1  jakllsch 	device_printf(sc->sc_dev, "%s tag %x offset %x ret %x\n",
    387   1.1  jakllsch 	    __func__, (unsigned int)tag, offset, ret);
    388   1.1  jakllsch #endif
    389   1.1  jakllsch 
    390   1.1  jakllsch 	return ret;
    391   1.1  jakllsch }
    392   1.1  jakllsch 
    393   1.1  jakllsch static void
    394   1.1  jakllsch vlpci_pc_conf_write(void *v, pcitag_t tag, int offset, pcireg_t val)
    395   1.1  jakllsch {
    396   1.1  jakllsch 	struct vlpci_softc * const sc = v;
    397   1.1  jakllsch 
    398   1.1  jakllsch 	KASSERT((offset & 3) == 0);
    399   1.3  jakllsch 
    400   1.3  jakllsch 	if (offset >= PCI_CONF_SIZE)
    401   1.3  jakllsch 		return;
    402   1.1  jakllsch 
    403   1.1  jakllsch #if 0
    404   1.1  jakllsch 	device_printf(sc->sc_dev, "%s tag %x offset %x val %x\n",
    405   1.1  jakllsch 	    __func__, (unsigned int)tag, offset, val);
    406   1.1  jakllsch #endif
    407   1.1  jakllsch 
    408   1.1  jakllsch 	mutex_spin_enter(&sc->sc_lock);
    409   1.8      flxd 	bus_space_write_4(&isa_io_bs_tag, sc->sc_conf_ioh,
    410   1.8      flxd 	    VLPCI_CFGREG_ADDR_OFF, 0x80000000UL|tag|offset);
    411   1.8      flxd 	bus_space_write_4(&isa_io_bs_tag, sc->sc_conf_ioh,
    412   1.8      flxd 	    VLPCI_CFGREG_DATA_OFF, val);
    413   1.1  jakllsch 	mutex_spin_exit(&sc->sc_lock);
    414   1.1  jakllsch }
    415   1.1  jakllsch 
    416   1.4  jakllsch static int
    417   1.4  jakllsch vlpci_pc_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ih)
    418   1.4  jakllsch {
    419   1.7      flxd 
    420   1.4  jakllsch 	switch (pa->pa_intrpin) {
    421   1.4  jakllsch 	default:
    422   1.4  jakllsch 	case 0:
    423   1.4  jakllsch 		return EINVAL;
    424   1.4  jakllsch 	case 1:
    425   1.4  jakllsch 	case 2:
    426   1.4  jakllsch 	case 3:
    427   1.4  jakllsch 	case 4:
    428   1.8      flxd 		*ih = VLPCI_IRQ;
    429   1.4  jakllsch 		return 0;
    430   1.4  jakllsch 	}
    431   1.4  jakllsch }
    432   1.4  jakllsch 
    433   1.4  jakllsch static const char *
    434   1.4  jakllsch vlpci_pc_intr_string(void *v, pci_intr_handle_t ih, char *buf, size_t len)
    435   1.4  jakllsch {
    436   1.4  jakllsch 
    437   1.4  jakllsch 	if (ih == PCI_INTERRUPT_PIN_NONE)
    438   1.4  jakllsch 		return NULL;
    439   1.9  macallan 	snprintf(buf, len, "irq %llu", ih);
    440   1.4  jakllsch 	return buf;
    441   1.4  jakllsch }
    442   1.4  jakllsch 
    443   1.4  jakllsch static const struct evcnt *
    444   1.4  jakllsch vlpci_pc_intr_evcnt(void *v, pci_intr_handle_t ih)
    445   1.4  jakllsch {
    446   1.7      flxd 
    447   1.4  jakllsch 	return NULL;
    448   1.4  jakllsch }
    449   1.4  jakllsch 
    450   1.4  jakllsch static void *
    451   1.4  jakllsch vlpci_pc_intr_establish(void *v, pci_intr_handle_t pih, int ipl,
    452   1.9  macallan     int (*callback)(void *), void *arg, const char *foo)
    453   1.4  jakllsch {
    454   1.7      flxd 
    455   1.4  jakllsch 	if (pih == 0)
    456   1.4  jakllsch 		return NULL;
    457   1.4  jakllsch 
    458   1.4  jakllsch 	return isa_intr_establish(NULL, pih, IST_LEVEL, ipl, callback, arg);
    459   1.4  jakllsch }
    460   1.4  jakllsch 
    461   1.4  jakllsch static void
    462   1.4  jakllsch vlpci_pc_intr_disestablish(void *v, void *w)
    463   1.4  jakllsch {
    464   1.6    martin 
    465   1.6    martin 	return isa_intr_disestablish(NULL, v);
    466   1.4  jakllsch }
    467   1.4  jakllsch 
    468   1.1  jakllsch #ifdef __HAVE_PCI_CONF_HOOK
    469   1.1  jakllsch static int
    470   1.1  jakllsch vlpci_pc_conf_hook(void *v, int b, int d, int f, pcireg_t id)
    471   1.1  jakllsch {
    472   1.7      flxd 
    473   1.5  macallan 	return PCI_CONF_DEFAULT /*& ~PCI_CONF_ENABLE_BM*/;
    474   1.1  jakllsch }
    475   1.1  jakllsch #endif
    476   1.1  jakllsch 
    477   1.1  jakllsch static void
    478   1.1  jakllsch vlpci_pc_conf_interrupt(void *v, int bus, int dev, int ipin, int swiz,
    479   1.1  jakllsch     int *ilinep)
    480   1.1  jakllsch {
    481   1.7      flxd 
    482   1.1  jakllsch 	*ilinep = 0xff; /* XXX */
    483   1.1  jakllsch }
    484