Home | History | Annotate | Line # | Download | only in pci
btvmeii.c revision 1.3.2.1
      1  1.3.2.1   thorpej /* $NetBSD: btvmeii.c,v 1.3.2.1 2002/01/10 19:56:27 thorpej Exp $ */
      2      1.1  drochner 
      3      1.1  drochner /*
      4      1.1  drochner  * Copyright (c) 1999
      5      1.1  drochner  * 	Matthias Drochner.  All rights reserved.
      6      1.1  drochner  *
      7      1.1  drochner  * Redistribution and use in source and binary forms, with or without
      8      1.1  drochner  * modification, are permitted provided that the following conditions
      9      1.1  drochner  * are met:
     10      1.1  drochner  * 1. Redistributions of source code must retain the above copyright
     11      1.1  drochner  *    notice, this list of conditions, and the following disclaimer.
     12      1.1  drochner  * 2. Redistributions in binary form must reproduce the above copyright
     13      1.1  drochner  *    notice, this list of conditions and the following disclaimer in the
     14      1.1  drochner  *    documentation and/or other materials provided with the distribution.
     15      1.1  drochner  *
     16      1.1  drochner  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     17      1.1  drochner  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18      1.1  drochner  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19      1.1  drochner  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     20      1.1  drochner  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21      1.1  drochner  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22      1.1  drochner  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23      1.1  drochner  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24      1.1  drochner  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25      1.1  drochner  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26      1.1  drochner  * SUCH DAMAGE.
     27      1.1  drochner  */
     28      1.1  drochner 
     29      1.1  drochner /*
     30      1.1  drochner  * Driver for the Bit3/SBS PCI-VME adapter Model 2706.
     31      1.1  drochner  * Uses the common Tundra Universe code.
     32      1.1  drochner  */
     33  1.3.2.1   thorpej 
     34  1.3.2.1   thorpej #include <sys/cdefs.h>
     35  1.3.2.1   thorpej __KERNEL_RCSID(0, "$NetBSD: btvmeii.c,v 1.3.2.1 2002/01/10 19:56:27 thorpej Exp $");
     36      1.1  drochner 
     37      1.1  drochner #include <sys/param.h>
     38      1.1  drochner #include <sys/systm.h>
     39      1.1  drochner #include <sys/device.h>
     40      1.1  drochner 
     41      1.1  drochner #include <dev/pci/pcireg.h>
     42      1.1  drochner #include <dev/pci/pcivar.h>
     43      1.1  drochner #include <dev/pci/pcidevs.h>
     44      1.1  drochner 
     45      1.1  drochner #include <machine/bus.h>
     46      1.1  drochner #include <sys/malloc.h>
     47      1.1  drochner #include <sys/extent.h>
     48      1.1  drochner 
     49      1.1  drochner #include <dev/pci/ppbreg.h>
     50      1.1  drochner 
     51      1.1  drochner #include <dev/vme/vmereg.h>
     52      1.1  drochner #include <dev/vme/vmevar.h>
     53      1.1  drochner 
     54      1.1  drochner #include <dev/pci/universe_pci_var.h>
     55      1.1  drochner 
     56      1.1  drochner static int b3_2706_match __P((struct device *, struct cfdata *, void *));
     57      1.1  drochner static void b3_2706_attach __P((struct device *, struct device *, void *));
     58      1.1  drochner 
     59      1.1  drochner /* exported via tag structs */
     60      1.1  drochner int b3_2706_map_vme __P((void *, vme_addr_t, vme_size_t,
     61      1.1  drochner 		      vme_am_t, vme_datasize_t, vme_swap_t,
     62      1.1  drochner 		      bus_space_tag_t *, bus_space_handle_t *, vme_mapresc_t*));
     63      1.1  drochner void b3_2706_unmap_vme __P((void *, vme_mapresc_t));
     64      1.1  drochner 
     65      1.1  drochner int b3_2706_vme_probe __P((void *, vme_addr_t, vme_size_t, vme_am_t,
     66      1.1  drochner 			vme_datasize_t,
     67      1.1  drochner 			int (*)(void *, bus_space_tag_t, bus_space_handle_t),
     68      1.1  drochner 			void *));
     69      1.1  drochner 
     70      1.1  drochner int b3_2706_map_vmeint __P((void *, int, int, vme_intr_handle_t *));
     71      1.1  drochner void *b3_2706_establish_vmeint __P((void *, vme_intr_handle_t, int,
     72      1.1  drochner 				 int (*)(void *), void *));
     73      1.1  drochner void b3_2706_disestablish_vmeint __P((void *, void *));
     74      1.2  drochner void b3_2706_vmeint __P((void *, int, int));
     75      1.1  drochner 
     76      1.1  drochner int b3_2706_dmamap_create __P((void *, vme_size_t,
     77      1.1  drochner 			    vme_am_t, vme_datasize_t, vme_swap_t,
     78      1.1  drochner 			    int, vme_size_t, vme_addr_t,
     79      1.1  drochner 			    int, bus_dmamap_t *));
     80      1.1  drochner void b3_2706_dmamap_destroy __P((void *, bus_dmamap_t));
     81      1.1  drochner 
     82      1.1  drochner int b3_2706_dmamem_alloc __P((void *, vme_size_t,
     83      1.1  drochner 			      vme_am_t, vme_datasize_t, vme_swap_t,
     84      1.1  drochner 			      bus_dma_segment_t *, int, int *, int));
     85      1.1  drochner void b3_2706_dmamem_free __P((void *, bus_dma_segment_t *, int));
     86      1.1  drochner 
     87      1.1  drochner struct b3_2706_vmemaprescs {
     88      1.1  drochner 	int wnd;
     89      1.1  drochner 	unsigned long pcibase, maplen;
     90      1.1  drochner 	bus_space_handle_t handle;
     91      1.1  drochner 	u_int32_t len;
     92      1.1  drochner };
     93      1.1  drochner 
     94      1.2  drochner struct b3_2706_vmeintrhand {
     95      1.2  drochner 	TAILQ_ENTRY(b3_2706_vmeintrhand) ih_next;
     96      1.2  drochner 	int (*ih_fun) __P((void*));
     97      1.2  drochner 	void *ih_arg;
     98      1.2  drochner 	int ih_level;
     99      1.2  drochner 	int ih_vector;
    100      1.2  drochner 	int ih_prior;
    101      1.2  drochner 	u_long ih_count;
    102      1.2  drochner };
    103      1.2  drochner 
    104      1.1  drochner struct b3_2706_softc {
    105      1.1  drochner 	struct device sc_dev;
    106      1.1  drochner 	struct univ_pci_data univdata;
    107      1.1  drochner 	bus_space_tag_t swapt, vmet;
    108      1.1  drochner 	bus_space_handle_t swaph;
    109      1.1  drochner 	bus_addr_t vmepbase;
    110      1.1  drochner 
    111      1.1  drochner 	int windowused[8];
    112      1.1  drochner 	struct b3_2706_vmemaprescs vmemaprescs[8];
    113      1.1  drochner 	struct extent *vmeext;
    114      1.1  drochner 	char vmemap[EXTENT_FIXED_STORAGE_SIZE(8)];
    115      1.1  drochner 
    116      1.1  drochner 	struct vme_chipset_tag sc_vct;
    117      1.2  drochner 
    118      1.2  drochner 	/* list of VME interrupt handlers */
    119      1.2  drochner 	TAILQ_HEAD(, b3_2706_vmeintrhand) intrhdls;
    120      1.2  drochner 	int strayintrs;
    121      1.1  drochner };
    122      1.1  drochner 
    123      1.1  drochner struct cfattach btvmeii_ca = {
    124      1.1  drochner 	sizeof(struct b3_2706_softc), b3_2706_match, b3_2706_attach,
    125      1.1  drochner #if 0
    126      1.1  drochner 	b3_2706_detach
    127      1.1  drochner #endif
    128      1.1  drochner };
    129      1.1  drochner 
    130      1.1  drochner /*
    131      1.1  drochner  * The adapter consists of a DEC PCI-PCI-bridge with two
    132      1.1  drochner  * PCI devices behind it: A Tundra Universe as device 4 and
    133      1.1  drochner  * some FPGA with glue logics as device 8.
    134      1.1  drochner  * As long as the autoconf code doesn't provide more support
    135      1.1  drochner  * for dependant devices, we have to duplicate a part of the
    136      1.1  drochner  * "ppb" functions here.
    137      1.1  drochner  */
    138      1.1  drochner 
    139      1.1  drochner static int
    140      1.1  drochner b3_2706_match(parent, match, aux)
    141      1.1  drochner 	struct device *parent;
    142      1.1  drochner 	struct cfdata *match;
    143      1.1  drochner 	void *aux;
    144      1.1  drochner {
    145      1.1  drochner 	struct pci_attach_args *pa = aux;
    146      1.1  drochner 	pci_chipset_tag_t pc = pa->pa_pc;
    147      1.1  drochner 	int secbus;
    148      1.1  drochner 	pcitag_t tag;
    149      1.1  drochner 	pcireg_t id;
    150      1.1  drochner 
    151      1.1  drochner 	if ((PCI_VENDOR(pa->pa_id) != PCI_VENDOR_DEC)
    152      1.1  drochner 	    || (PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_DEC_21152))
    153      1.1  drochner 		return (0);
    154      1.1  drochner 
    155      1.1  drochner 	secbus = PPB_BUSINFO_SECONDARY(pci_conf_read(pc, pa->pa_tag,
    156      1.1  drochner 						     PPB_REG_BUSINFO));
    157      1.1  drochner 	if (secbus == 0) {
    158      1.1  drochner 		printf("b3_2706_match: ppb not configured\n");
    159      1.1  drochner 		return (0);
    160      1.1  drochner 	}
    161      1.1  drochner 
    162      1.1  drochner 	tag = pci_make_tag(pc, secbus, 4, 0);
    163      1.1  drochner 	id = pci_conf_read(pc, tag, PCI_ID_REG);
    164      1.1  drochner 
    165      1.1  drochner 	if ((PCI_VENDOR(id) != PCI_VENDOR_NEWBRIDGE)
    166      1.1  drochner 	    || (PCI_PRODUCT(id) != PCI_PRODUCT_NEWBRIDGE_CA91CX42)) {
    167      1.1  drochner #ifdef DEBUG
    168      1.1  drochner 		printf("b3_2706_match: no tundra\n");
    169      1.1  drochner #endif
    170      1.1  drochner 		return (0);
    171      1.1  drochner 	}
    172      1.1  drochner 
    173      1.1  drochner 	tag = pci_make_tag(pc, secbus, 8, 0);
    174      1.1  drochner 	id = pci_conf_read(pc, tag, PCI_ID_REG);
    175      1.1  drochner 
    176      1.1  drochner 	if ((PCI_VENDOR(id) != PCI_VENDOR_BIT3)
    177      1.1  drochner 	    || (PCI_PRODUCT(id) != PCI_PRODUCT_BIT3_PCIVME2706)) {
    178      1.1  drochner #ifdef DEBUG
    179      1.1  drochner 		printf("b3_2706_match: no bit3 chip\n");
    180      1.1  drochner #endif
    181      1.1  drochner 		return (0);
    182      1.1  drochner 	}
    183      1.1  drochner 
    184      1.1  drochner 	return (5); /* beat "ppb" */
    185      1.1  drochner }
    186      1.1  drochner 
    187      1.1  drochner static void
    188      1.1  drochner b3_2706_attach(parent, self, aux)
    189      1.1  drochner 	struct device *parent, *self;
    190      1.1  drochner 	void *aux;
    191      1.1  drochner {
    192      1.1  drochner 	struct b3_2706_softc *sc = (struct b3_2706_softc *)self;
    193      1.1  drochner 	struct pci_attach_args *pa = aux;
    194      1.1  drochner 	pci_chipset_tag_t pc = pa->pa_pc;
    195      1.1  drochner 	struct pci_attach_args aa;
    196      1.1  drochner 	int secbus;
    197      1.1  drochner 	pcireg_t intr;
    198      1.1  drochner 	pcitag_t tag;
    199      1.1  drochner 	bus_addr_t swappbase;
    200      1.1  drochner 	int i;
    201      1.1  drochner 
    202      1.1  drochner 	struct vmebus_attach_args vaa;
    203      1.1  drochner 
    204      1.1  drochner 	printf("\n");
    205      1.1  drochner 
    206      1.1  drochner 	secbus = PPB_BUSINFO_SECONDARY(pci_conf_read(pc, pa->pa_tag,
    207      1.1  drochner 						     PPB_REG_BUSINFO));
    208      1.1  drochner 
    209      1.3   thorpej 	memcpy(&aa, pa, sizeof(struct pci_attach_args));
    210      1.1  drochner 	aa.pa_device = 4;
    211      1.1  drochner 	aa.pa_function = 0;
    212      1.1  drochner 	aa.pa_tag = pci_make_tag(pc, secbus, 4, 0);
    213      1.1  drochner 	aa.pa_intrswiz += 4;
    214      1.1  drochner 	intr = pci_conf_read(pc, aa.pa_tag, PCI_INTERRUPT_REG);
    215      1.1  drochner 	/*
    216      1.1  drochner 	 * swizzle it based on the number of
    217      1.1  drochner 	 * busses we're behind and our device
    218      1.1  drochner 	 * number.
    219      1.1  drochner 	 */
    220      1.1  drochner 	aa.pa_intrpin =	((1 + aa.pa_intrswiz - 1) % 4) + 1;
    221      1.1  drochner 	aa.pa_intrline = PCI_INTERRUPT_LINE(intr);
    222      1.1  drochner 
    223      1.2  drochner 	if (univ_pci_attach(&sc->univdata, &aa, self->dv_xname,
    224      1.2  drochner 			    b3_2706_vmeint, sc)) {
    225      1.1  drochner 		printf("%s: error initializing universe chip\n",
    226      1.1  drochner 		       self->dv_xname);
    227      1.1  drochner 		return;
    228      1.1  drochner 	}
    229      1.1  drochner 
    230      1.2  drochner 	/*
    231      1.2  drochner 	 * don't waste KVM - the byteswap register is aliased in
    232      1.2  drochner 	 * a 512k window, we need it only once
    233      1.2  drochner 	 */
    234      1.1  drochner 	tag = pci_make_tag(pc, secbus, 8, 0);
    235      1.1  drochner 	sc->swapt = pa->pa_memt;
    236      1.1  drochner 	if (pci_mapreg_info(pc, tag, 0x10,
    237      1.1  drochner 			    PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT,
    238      1.1  drochner 			    &swappbase, 0, 0) ||
    239      1.1  drochner 	    bus_space_map(sc->swapt, swappbase, 4, 0, &sc->swaph)) {
    240      1.1  drochner 		printf("%s: can't map byteswap register\n", self->dv_xname);
    241      1.1  drochner 		return;
    242      1.1  drochner 	}
    243      1.2  drochner 	/*
    244      1.2  drochner 	 * Set up cycle specific byteswap mode.
    245      1.2  drochner 	 * XXX Readback yields "all-ones" for me, and it doesn't seem
    246      1.2  drochner 	 * to matter what I write into the register - the data don't
    247      1.2  drochner 	 * get swapped. Adapter fault or documentation bug?
    248      1.2  drochner 	 */
    249      1.2  drochner 	bus_space_write_4(sc->swapt, sc->swaph, 0, 0x00000490);
    250      1.2  drochner 
    251      1.2  drochner 	/* VME space is mapped as needed */
    252      1.1  drochner 	sc->vmet = pa->pa_memt;
    253      1.1  drochner 	if (pci_mapreg_info(pc, tag, 0x14,
    254      1.1  drochner 			    PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT,
    255      1.1  drochner 			    &sc->vmepbase, 0, 0)) {
    256      1.1  drochner 		printf("%s: VME range not assigned\n", self->dv_xname);
    257      1.1  drochner 		return;
    258      1.1  drochner 	}
    259      1.2  drochner #ifdef BIT3DEBUG
    260      1.1  drochner 	printf("%s: VME window @%lx\n", self->dv_xname, (long)sc->vmepbase);
    261      1.2  drochner #endif
    262      1.1  drochner 
    263      1.1  drochner 	for (i = 0; i < 8; i++) {
    264      1.1  drochner 		sc->windowused[i] = 0;
    265      1.1  drochner 	}
    266      1.1  drochner 	sc->vmeext = extent_create("pcivme", sc->vmepbase,
    267      1.1  drochner 				   sc->vmepbase + 32*1024*1024 - 1, M_DEVBUF,
    268      1.1  drochner 				   sc->vmemap, sizeof(sc->vmemap),
    269      1.1  drochner 				   EX_NOCOALESCE);
    270      1.1  drochner 
    271      1.1  drochner 	sc->sc_vct.cookie = self;
    272      1.1  drochner 	sc->sc_vct.vct_probe = b3_2706_vme_probe;
    273      1.1  drochner 	sc->sc_vct.vct_map = b3_2706_map_vme;
    274      1.1  drochner 	sc->sc_vct.vct_unmap = b3_2706_unmap_vme;
    275      1.1  drochner 	sc->sc_vct.vct_int_map = b3_2706_map_vmeint;
    276      1.1  drochner 	sc->sc_vct.vct_int_establish = b3_2706_establish_vmeint;
    277      1.1  drochner 	sc->sc_vct.vct_int_disestablish = b3_2706_disestablish_vmeint;
    278      1.1  drochner 	sc->sc_vct.vct_dmamap_create = b3_2706_dmamap_create;
    279      1.1  drochner 	sc->sc_vct.vct_dmamap_destroy = b3_2706_dmamap_destroy;
    280      1.1  drochner 	sc->sc_vct.vct_dmamem_alloc = b3_2706_dmamem_alloc;
    281      1.1  drochner 	sc->sc_vct.vct_dmamem_free = b3_2706_dmamem_free;
    282      1.1  drochner 
    283      1.1  drochner 	vaa.va_vct = &(sc->sc_vct);
    284      1.1  drochner 	vaa.va_bdt = pa->pa_dmat; /* XXX */
    285      1.2  drochner 	vaa.va_slaveconfig = 0; /* XXX CSR window? */
    286      1.1  drochner 
    287      1.1  drochner 	config_found(self, &vaa, 0);
    288      1.1  drochner }
    289      1.1  drochner 
    290      1.1  drochner #define sc ((struct b3_2706_softc*)vsc)
    291      1.1  drochner 
    292      1.1  drochner int
    293      1.1  drochner b3_2706_map_vme(vsc, vmeaddr, len, am, datasizes, swap, tag, handle, resc)
    294      1.1  drochner 	void *vsc;
    295      1.1  drochner 	vme_addr_t vmeaddr;
    296      1.1  drochner 	vme_size_t len;
    297      1.1  drochner 	vme_am_t am;
    298      1.1  drochner 	vme_datasize_t datasizes;
    299      1.1  drochner 	vme_swap_t swap;
    300      1.1  drochner 	bus_space_tag_t *tag;
    301      1.1  drochner 	bus_space_handle_t *handle;
    302      1.1  drochner 	vme_mapresc_t *resc;
    303      1.1  drochner {
    304      1.1  drochner 	int idx, i, wnd, res;
    305      1.1  drochner 	unsigned long boundary, maplen, pcibase;
    306      1.1  drochner 	vme_addr_t vmebase, vmeend;
    307      1.1  drochner 	static int windoworder[8] = {1, 2, 3, 5, 6, 7, 0, 4};
    308      1.1  drochner 
    309      1.1  drochner 	/* prefer windows with fine granularity for small mappings */
    310      1.1  drochner 	wnd = -1;
    311      1.1  drochner 	if (len <= 32*1024)
    312      1.1  drochner 		idx = 6;
    313      1.1  drochner 	else
    314      1.1  drochner 		idx = 0;
    315      1.1  drochner 	for (i = 0; i < 8; i++) {
    316      1.1  drochner 		if (!sc->windowused[windoworder[idx]]) {
    317      1.1  drochner 			wnd = windoworder[idx];
    318      1.1  drochner 			sc->windowused[wnd] = 1;
    319      1.1  drochner 			break;
    320      1.1  drochner 		}
    321      1.1  drochner 		idx = (idx + 1) % 8;
    322      1.1  drochner 	}
    323      1.1  drochner 	if (wnd == -1)
    324      1.1  drochner 		return (ENOSPC);
    325      1.1  drochner 
    326      1.1  drochner 	boundary = (wnd & 3) ? 64*1024 : 4*1024;
    327      1.1  drochner 
    328      1.1  drochner 	/* first mapped address */
    329      1.1  drochner 	vmebase = vmeaddr & ~(boundary - 1);
    330      1.1  drochner 	/* base of last mapped page */
    331      1.1  drochner 	vmeend = (vmeaddr + len - 1) & ~(boundary - 1);
    332      1.1  drochner 	/* bytes in outgoing window required */
    333      1.1  drochner 	maplen = vmeend - vmebase + boundary;
    334      1.1  drochner 
    335      1.2  drochner 	if (extent_alloc(sc->vmeext, maplen, boundary, 0, EX_FAST, &pcibase)) {
    336      1.2  drochner 		sc->windowused[wnd] = 0;
    337      1.1  drochner 		return (ENOMEM);
    338      1.2  drochner 	}
    339      1.1  drochner 
    340      1.1  drochner 	res = univ_pci_mapvme(&sc->univdata, wnd, vmebase, maplen,
    341      1.1  drochner 			      am, datasizes, pcibase);
    342      1.1  drochner 	if (res) {
    343      1.1  drochner 		extent_free(sc->vmeext, pcibase, maplen, 0);
    344      1.2  drochner 		sc->windowused[wnd] = 0;
    345      1.1  drochner 		return (res);
    346      1.1  drochner 	}
    347      1.1  drochner 
    348      1.1  drochner 	res = bus_space_map(sc->vmet, pcibase + (vmeaddr - vmebase), len,
    349      1.1  drochner 			    0, handle);
    350      1.1  drochner 	if (res) {
    351      1.1  drochner 		univ_pci_unmapvme(&sc->univdata, wnd);
    352      1.1  drochner 		extent_free(sc->vmeext, pcibase, maplen, 0);
    353      1.2  drochner 		sc->windowused[wnd] = 0;
    354      1.1  drochner 		return (res);
    355      1.1  drochner 	}
    356      1.1  drochner 
    357      1.1  drochner 	*tag = sc->vmet;
    358      1.1  drochner 
    359      1.1  drochner 	/*
    360      1.1  drochner 	 * save all data needed for later unmapping
    361      1.1  drochner 	 */
    362      1.1  drochner 	sc->vmemaprescs[wnd].wnd = wnd;
    363      1.1  drochner 	sc->vmemaprescs[wnd].pcibase = pcibase;
    364      1.1  drochner 	sc->vmemaprescs[wnd].maplen = maplen;
    365      1.1  drochner 	sc->vmemaprescs[wnd].handle = *handle;
    366      1.1  drochner 	sc->vmemaprescs[wnd].len = len;
    367      1.1  drochner 	*resc = &sc->vmemaprescs[wnd];
    368      1.1  drochner 	return (0);
    369      1.1  drochner }
    370      1.1  drochner 
    371      1.1  drochner void
    372      1.1  drochner b3_2706_unmap_vme(vsc, resc)
    373      1.1  drochner 	void *vsc;
    374      1.1  drochner 	vme_mapresc_t resc;
    375      1.1  drochner {
    376      1.1  drochner 	struct b3_2706_vmemaprescs *r = resc;
    377      1.1  drochner 
    378      1.1  drochner 	bus_space_unmap(sc->vmet, r->handle, r->len);
    379      1.1  drochner 	extent_free(sc->vmeext, r->pcibase, r->maplen, 0);
    380      1.1  drochner 
    381      1.1  drochner 	if (!sc->windowused[r->wnd])
    382      1.1  drochner 		panic("b3_2706_unmap_vme: bad window");
    383      1.1  drochner 	univ_pci_unmapvme(&sc->univdata, r->wnd);
    384      1.1  drochner 	sc->windowused[r->wnd] = 0;
    385      1.1  drochner }
    386      1.1  drochner 
    387      1.1  drochner int
    388      1.1  drochner b3_2706_vme_probe(vsc, addr, len, am, datasize, callback, cbarg)
    389      1.1  drochner 	void *vsc;
    390      1.1  drochner 	vme_addr_t addr;
    391      1.1  drochner 	vme_size_t len;
    392      1.1  drochner 	vme_am_t am;
    393      1.1  drochner 	vme_datasize_t datasize;
    394      1.1  drochner 	int (*callback) __P((void *, bus_space_tag_t, bus_space_handle_t));
    395      1.1  drochner 	void *cbarg;
    396      1.1  drochner {
    397      1.2  drochner 	bus_space_tag_t tag;
    398      1.2  drochner 	bus_space_handle_t handle;
    399      1.2  drochner 	vme_mapresc_t resc;
    400      1.2  drochner 	int res, i;
    401      1.2  drochner 	volatile u_int32_t dummy;
    402      1.2  drochner 
    403      1.2  drochner 	res = b3_2706_map_vme(vsc, addr, len, am, datasize, 0,
    404      1.2  drochner 			      &tag, &handle, &resc);
    405      1.2  drochner 	if (res)
    406      1.2  drochner 		return (res);
    407      1.2  drochner 
    408      1.2  drochner 	if (univ_pci_vmebuserr(&sc->univdata, 1))
    409      1.2  drochner 		printf("b3_2706_vme_badaddr: TA bit not clean - reset\n");
    410      1.2  drochner 
    411      1.2  drochner 	if (callback)
    412      1.2  drochner 		res = (*callback)(cbarg, tag, handle);
    413      1.2  drochner 	else {
    414      1.2  drochner 		for (i = 0; i < len;) {
    415      1.2  drochner 			switch (datasize) {
    416      1.2  drochner 			    case VME_D8:
    417      1.2  drochner 				dummy = bus_space_read_1(tag, handle, i);
    418      1.2  drochner 				i++;
    419      1.2  drochner 				break;
    420      1.2  drochner 			    case VME_D16:
    421      1.2  drochner 				dummy = bus_space_read_2(tag, handle, i);
    422      1.2  drochner 				i += 2;
    423      1.2  drochner 				break;
    424      1.2  drochner 			    case VME_D32:
    425      1.2  drochner 				dummy = bus_space_read_4(tag, handle, i);
    426      1.2  drochner 				i += 4;
    427      1.2  drochner 				break;
    428      1.2  drochner 			    default:
    429      1.2  drochner 				panic("b3_2706_vme_probe: invalid datasize %x",
    430      1.2  drochner 				      datasize);
    431      1.2  drochner 			}
    432      1.2  drochner 		}
    433      1.2  drochner 	}
    434      1.2  drochner 
    435      1.2  drochner 	if (univ_pci_vmebuserr(&sc->univdata, 0)) {
    436      1.2  drochner #ifdef BIT3DEBUG
    437      1.2  drochner 		printf("b3_2706_vme_badaddr: caught TA\n");
    438      1.2  drochner #endif
    439      1.2  drochner 		univ_pci_vmebuserr(&sc->univdata, 1);
    440      1.2  drochner 		res = EIO;
    441      1.2  drochner 	}
    442      1.2  drochner 
    443      1.2  drochner 	b3_2706_unmap_vme(vsc, resc);
    444      1.2  drochner 	return (res);
    445      1.1  drochner }
    446      1.1  drochner 
    447      1.1  drochner int
    448      1.1  drochner b3_2706_map_vmeint(vsc, level, vector, handlep)
    449      1.1  drochner 	void *vsc;
    450      1.1  drochner 	int level, vector;
    451      1.1  drochner 	vme_intr_handle_t *handlep;
    452      1.1  drochner {
    453      1.2  drochner 
    454      1.2  drochner 	*handlep = (void *)(long)((level << 8) | vector); /* XXX */
    455      1.2  drochner 	return (0);
    456      1.1  drochner }
    457      1.1  drochner 
    458      1.1  drochner void *
    459      1.1  drochner b3_2706_establish_vmeint(vsc, handle, prior, func, arg)
    460      1.1  drochner 	void *vsc;
    461      1.1  drochner 	vme_intr_handle_t handle;
    462      1.1  drochner 	int prior;
    463      1.1  drochner 	int (*func) __P((void *));
    464      1.1  drochner 	void *arg;
    465      1.1  drochner {
    466      1.2  drochner 	struct b3_2706_vmeintrhand *ih;
    467      1.2  drochner 	long lv;
    468      1.2  drochner 	int s;
    469      1.2  drochner 	extern int cold;
    470      1.2  drochner 
    471      1.2  drochner 	/* no point in sleeping unless someone can free memory. */
    472      1.2  drochner 	ih = malloc(sizeof *ih, M_DEVBUF, cold ? M_NOWAIT : M_WAITOK);
    473      1.2  drochner 	if (ih == NULL)
    474      1.2  drochner 		panic("b3_2706_map_vmeint: can't malloc handler info");
    475      1.2  drochner 
    476      1.2  drochner 	lv = (long)handle; /* XXX */
    477      1.2  drochner 
    478      1.2  drochner 	ih->ih_fun = func;
    479      1.2  drochner 	ih->ih_arg = arg;
    480      1.2  drochner 	ih->ih_level = lv >> 8;
    481      1.2  drochner 	ih->ih_vector = lv & 0xff;
    482      1.2  drochner 	ih->ih_prior = prior;
    483      1.2  drochner 	ih->ih_count = 0;
    484      1.2  drochner 
    485      1.2  drochner 	s = splhigh();
    486      1.2  drochner 	TAILQ_INSERT_TAIL(&(sc->intrhdls), ih, ih_next);
    487      1.2  drochner 	splx(s);
    488      1.2  drochner 
    489      1.2  drochner 	return (ih);
    490      1.1  drochner }
    491      1.1  drochner 
    492      1.1  drochner void
    493      1.1  drochner b3_2706_disestablish_vmeint(vsc, cookie)
    494      1.1  drochner 	void *vsc;
    495      1.1  drochner 	void *cookie;
    496      1.1  drochner {
    497      1.2  drochner 	struct b3_2706_vmeintrhand *ih = cookie;
    498      1.2  drochner 	int s;
    499      1.2  drochner 
    500      1.2  drochner 	if (!ih) {
    501      1.2  drochner 		printf("b3_2706_unmap_vmeint: NULL arg\n");
    502      1.2  drochner 		return;
    503      1.2  drochner 	}
    504      1.2  drochner 
    505      1.2  drochner 	s = splhigh();
    506      1.2  drochner 	TAILQ_REMOVE(&(sc->intrhdls), ih, ih_next);
    507      1.2  drochner 	splx(s);
    508      1.2  drochner 
    509      1.2  drochner 	free(ih, M_DEVBUF);
    510      1.2  drochner }
    511      1.2  drochner 
    512      1.2  drochner void
    513      1.2  drochner b3_2706_vmeint(vsc, level, vector)
    514      1.2  drochner 	void *vsc;
    515      1.2  drochner 	int level, vector;
    516      1.2  drochner {
    517      1.2  drochner 	struct b3_2706_vmeintrhand *ih;
    518      1.2  drochner 	int found;
    519      1.2  drochner 
    520      1.2  drochner #ifdef BIT3DEBUG
    521      1.2  drochner 	printf("b3_2706_vmeint: VME IRQ %d, vec %x\n", level, vector);
    522      1.2  drochner #endif
    523      1.2  drochner 	found = 0;
    524      1.2  drochner 
    525      1.2  drochner 	for (ih = sc->intrhdls.tqh_first; ih;
    526      1.2  drochner 	     ih = ih->ih_next.tqe_next) {
    527      1.2  drochner 		if ((ih->ih_level == level) &&
    528      1.2  drochner 		    ((ih->ih_vector == -1) ||
    529      1.2  drochner 		     (ih->ih_vector == vector))) {
    530      1.2  drochner 			int s, res;
    531      1.2  drochner 			/*
    532      1.2  drochner 			 * We should raise the interrupt level
    533      1.2  drochner 			 * to ih->ih_prior here. How to do this
    534      1.2  drochner 			 * machine-independantly?
    535      1.2  drochner 			 * To be safe, raise to the maximum.
    536      1.2  drochner 			 */
    537      1.2  drochner 			s = splhigh();
    538      1.2  drochner 			found |= (res = (*(ih->ih_fun))(ih->ih_arg));
    539      1.2  drochner 			splx(s);
    540      1.2  drochner 			if (res)
    541      1.2  drochner 				ih->ih_count++;
    542      1.2  drochner 			if (res == 1)
    543      1.2  drochner 				break;
    544      1.2  drochner 		}
    545      1.2  drochner 	}
    546      1.2  drochner 	if (!found)
    547      1.2  drochner 		sc->strayintrs++;
    548      1.1  drochner }
    549      1.1  drochner 
    550      1.1  drochner int
    551      1.1  drochner b3_2706_dmamap_create(vsc, len, am, datasize, swap,
    552      1.1  drochner 		      nsegs, segsz, bound,
    553      1.1  drochner 		      flags, mapp)
    554      1.1  drochner 	void *vsc;
    555      1.1  drochner 	vme_size_t len;
    556      1.1  drochner 	vme_am_t am;
    557      1.1  drochner 	vme_datasize_t datasize;
    558      1.1  drochner 	vme_swap_t swap;
    559      1.1  drochner 	int nsegs;
    560      1.1  drochner 	vme_size_t segsz;
    561      1.1  drochner 	vme_addr_t bound;
    562      1.1  drochner 	int flags;
    563      1.1  drochner 	bus_dmamap_t *mapp;
    564      1.1  drochner {
    565      1.1  drochner 	return (EINVAL);
    566      1.1  drochner }
    567      1.1  drochner 
    568      1.1  drochner void
    569      1.1  drochner b3_2706_dmamap_destroy(vsc, map)
    570      1.1  drochner 	void *vsc;
    571      1.1  drochner 	bus_dmamap_t map;
    572      1.1  drochner {
    573      1.1  drochner }
    574      1.1  drochner 
    575      1.1  drochner int
    576      1.1  drochner b3_2706_dmamem_alloc(vsc, len, am, datasizes, swap, segs, nsegs, rsegs, flags)
    577      1.1  drochner 	void *vsc;
    578      1.1  drochner 	vme_size_t len;
    579      1.1  drochner 	vme_am_t am;
    580      1.1  drochner 	vme_datasize_t datasizes;
    581      1.1  drochner 	vme_swap_t swap;
    582      1.1  drochner 	bus_dma_segment_t *segs;
    583      1.1  drochner 	int nsegs;
    584      1.1  drochner 	int *rsegs;
    585      1.1  drochner 	int flags;
    586      1.1  drochner {
    587      1.1  drochner 	return (EINVAL);
    588      1.1  drochner }
    589      1.1  drochner 
    590      1.1  drochner void
    591      1.1  drochner b3_2706_dmamem_free(vsc, segs, nsegs)
    592      1.1  drochner 	void *vsc;
    593      1.1  drochner 	bus_dma_segment_t *segs;
    594      1.1  drochner 	int nsegs;
    595      1.1  drochner {
    596      1.1  drochner }
    597      1.1  drochner 
    598      1.1  drochner #undef sc
    599