/*
* Copyright (c) 1999
* Matthias Drochner. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* Driver for the Bit3/SBS PCI-VME adapter Model 2706.
* Uses the common Tundra Universe code.
*/
int b3_2706_dmamem_alloc(void *, vme_size_t,
vme_am_t, vme_datasize_t, vme_swap_t,
bus_dma_segment_t *, int, int *, int);
void b3_2706_dmamem_free(void *, bus_dma_segment_t *, int);
struct b3_2706_vmemaprescs {
int wnd;
unsigned long pcibase, maplen;
bus_space_handle_t handle;
u_int32_t len;
};
struct b3_2706_vmeintrhand {
TAILQ_ENTRY(b3_2706_vmeintrhand) ih_next;
int (*ih_fun)(void*);
void *ih_arg;
int ih_level;
int ih_vector;
int ih_prior;
u_long ih_count;
};
/*
* The adapter consists of a DEC PCI-PCI-bridge with two
* PCI devices behind it: A Tundra Universe as device 4 and
* some FPGA with glue logics as device 8.
* As long as the autoconf code doesn't provide more support
* for dependent devices, we have to duplicate a part of the
* "ppb" functions here.
*/
static int
b3_2706_match(device_t parent, cfdata_t match, void *aux)
{
struct pci_attach_args *pa = aux;
pci_chipset_tag_t pc = pa->pa_pc;
int secbus;
pcitag_t tag;
pcireg_t id;
if ((PCI_VENDOR(pa->pa_id) != PCI_VENDOR_DEC)
|| (PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_DEC_21152))
return (0);
secbus = PCI_BRIDGE_BUS_NUM_SECONDARY(pci_conf_read(pc, pa->pa_tag,
PCI_BRIDGE_BUS_REG));
if (secbus == 0) {
printf("b3_2706_match: ppb not configured\n");
return (0);
}
tag = pci_make_tag(pc, secbus, 4, 0);
id = pci_conf_read(pc, tag, PCI_ID_REG);
if ((PCI_VENDOR(id) != PCI_VENDOR_NEWBRIDGE)
|| (PCI_PRODUCT(id) != PCI_PRODUCT_NEWBRIDGE_CA91CX42)) {
#ifdef DEBUG
printf("b3_2706_match: no tundra\n");
#endif
return (0);
}
tag = pci_make_tag(pc, secbus, 8, 0);
id = pci_conf_read(pc, tag, PCI_ID_REG);
if ((PCI_VENDOR(id) != PCI_VENDOR_BIT3)
|| (PCI_PRODUCT(id) != PCI_PRODUCT_BIT3_PCIVME2706)) {
#ifdef DEBUG
printf("b3_2706_match: no bit3 chip\n");
#endif
return (0);
}
/*
* don't waste KVM - the byteswap register is aliased in
* a 512k window, we need it only once
*/
tag = pci_make_tag(pc, secbus, 8, 0);
sc->swapt = pa->pa_memt;
if (pci_mapreg_info(pc, tag, 0x10,
PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT,
&swappbase, 0, 0) ||
bus_space_map(sc->swapt, swappbase, 4, 0, &sc->swaph)) {
aprint_error_dev(self, "can't map byteswap register\n");
return;
}
/*
* Set up cycle specific byteswap mode.
* XXX Readback yields "all-ones" for me, and it doesn't seem
* to matter what I write into the register - the data don't
* get swapped. Adapter fault or documentation bug?
*/
bus_space_write_4(sc->swapt, sc->swaph, 0, 0x00000490);
/* VME space is mapped as needed */
sc->vmet = pa->pa_memt;
if (pci_mapreg_info(pc, tag, 0x14,
PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT,
&sc->vmepbase, 0, 0)) {
aprint_error_dev(self, "VME range not assigned\n");
return;
}
#ifdef BIT3DEBUG
aprint_debug_dev(self, "VME window @%lx\n",
(long)sc->vmepbase);
#endif
for (ih = sc->intrhdls.tqh_first; ih;
ih = ih->ih_next.tqe_next) {
if ((ih->ih_level == level) &&
((ih->ih_vector == -1) ||
(ih->ih_vector == vector))) {
int s, res;
/*
* We should raise the interrupt level
* to ih->ih_prior here. How to do this
* machine-independently?
* To be safe, raise to the maximum.
*/
s = splhigh();
found |= (res = (*(ih->ih_fun))(ih->ih_arg));
splx(s);
if (res)
ih->ih_count++;
if (res == 1)
break;
}
}
if (!found)
sc->strayintrs++;
}
int
b3_2706_dmamap_create(void *vsc, vme_size_t len, vme_am_t am,
vme_datasize_t datasize, vme_swap_t swap, int nsegs, vme_size_t segsz,
vme_addr_t bound, int flags, bus_dmamap_t *mapp)
{
return (EINVAL);
}