2 * Copyright (c) 2001 Cubical Solutions Ltd. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * capi/iavc/iavc_pci.c
26 * The AVM ISDN controllers' PCI bus attachment handling.
28 * $FreeBSD: src/sys/i4b/capi/iavc/iavc_pci.c,v 1.1.2.1 2001/08/10 14:08:34 obrien Exp $
29 * $DragonFly: src/sys/net/i4b/capi/iavc/iavc_pci.c,v 1.10 2006/12/22 23:44:55 swildner Exp $
32 #include <sys/param.h>
33 #include <sys/kernel.h>
34 #include <sys/systm.h>
36 #include <sys/socket.h>
40 #include <machine/clock.h>
45 #include <bus/pci/pcireg.h>
46 #include <bus/pci/pcivar.h>
49 #include <net/i4b/include/machine/i4b_debug.h>
50 #include <net/i4b/include/machine/i4b_ioctl.h>
51 #include <net/i4b/include/machine/i4b_trace.h>
53 #include "../../include/i4b_global.h"
54 #include "../../include/i4b_l3l4.h"
55 #include "../../include/i4b_mbuf.h"
62 #define PCI_AVM_VID 0x1244
63 #define PCI_AVMT1_DID 0x1200
64 #define PCI_AVMB1_DID 0x0700
66 /* PCI driver linkage */
68 static void iavc_pci_intr(iavc_softc_t *sc);
69 static int iavc_pci_probe(device_t dev);
70 static int iavc_pci_attach(device_t dev);
72 static device_method_t iavc_pci_methods[] =
74 DEVMETHOD(device_probe, iavc_pci_probe),
75 DEVMETHOD(device_attach, iavc_pci_attach),
79 static driver_t iavc_pci_driver =
86 static devclass_t iavc_pci_devclass;
88 DRIVER_MODULE(iavc, pci, iavc_pci_driver, iavc_pci_devclass, 0, 0);
90 /* Driver soft contexts */
92 iavc_softc_t iavc_sc[IAVC_MAXUNIT];
94 /*---------------------------------------------------------------------------*
96 *---------------------------------------------------------------------------*/
99 iavc_pci_probe(device_t dev)
101 u_int16_t did = pci_get_device(dev);
102 u_int16_t vid = pci_get_vendor(dev);
104 if ((vid == PCI_AVM_VID) && (did == PCI_AVMT1_DID)) {
105 device_set_desc(dev, "AVM T1 PCI");
106 } else if ((vid == PCI_AVM_VID) && (did == PCI_AVMB1_DID)) {
107 device_set_desc(dev, "AVM B1 PCI");
115 /*---------------------------------------------------------------------------*
117 *---------------------------------------------------------------------------*/
120 iavc_pci_attach(device_t dev)
122 struct iavc_softc *sc;
124 u_int16_t did = pci_get_device(dev);
125 int unit = device_get_unit(dev), ret;
128 /* check max unit range */
130 if (unit >= IAVC_MAXUNIT) {
131 kprintf("iavc%d: too many units\n", unit);
135 sc = iavc_find_sc(unit); /* get softc */
139 /* use the i/o mapped base address */
141 sc->sc_resources.io_rid[0] = 0x14;
143 if (!(sc->sc_resources.io_base[0] =
144 bus_alloc_resource(dev, SYS_RES_IOPORT,
145 &sc->sc_resources.io_rid[0],
146 0UL, ~0UL, 1, RF_ACTIVE))) {
147 kprintf("iavc%d: can't allocate io region\n", unit);
151 sc->sc_iobase = rman_get_start(sc->sc_resources.io_base[0]);
152 sc->sc_io_bt = rman_get_bustag(sc->sc_resources.io_base[0]);
153 sc->sc_io_bh = rman_get_bushandle(sc->sc_resources.io_base[0]);
155 /* use the memory mapped DMA controller */
157 sc->sc_resources.mem_rid = 0x10;
159 if (!(sc->sc_resources.mem =
160 bus_alloc_resource(dev, SYS_RES_MEMORY,
161 &sc->sc_resources.mem_rid,
162 0UL, ~0UL, 1, RF_ACTIVE))) {
163 kprintf("iavc%d: can't allocate memory region\n", unit);
167 sc->sc_membase = rman_get_start(sc->sc_resources.mem);
168 sc->sc_mem_bt = rman_get_bustag(sc->sc_resources.mem);
169 sc->sc_mem_bh = rman_get_bushandle(sc->sc_resources.mem);
171 /* do some detection */
177 if (did == PCI_AVMT1_DID) {
178 sc->sc_capi.card_type = CARD_TYPEC_AVM_T1_PCI;
179 sc->sc_capi.sc_nbch = 30;
183 kprintf("iavc%d: no card detected?\n", sc->sc_unit);
185 kprintf("iavc%d: black box not on\n", sc->sc_unit);
193 } else if (did == PCI_AVMB1_DID) {
194 sc->sc_capi.card_type = CARD_TYPEC_AVM_B1_PCI;
195 sc->sc_capi.sc_nbch = 2;
196 ret = b1dma_detect(sc);
200 kprintf("iavc%d: no card detected?\n", sc->sc_unit);
208 if (sc->sc_dma) b1dma_reset(sc);
210 if (sc->sc_t1) t1_reset(sc);
214 /* of course we need an interrupt */
216 sc->sc_resources.irq_rid = 0x00;
218 if(!(sc->sc_resources.irq =
219 bus_alloc_resource(dev, SYS_RES_IRQ,
220 &sc->sc_resources.irq_rid,
221 0UL, ~0UL, 1, RF_SHAREABLE|RF_ACTIVE))) {
222 kprintf("iavc%d: can't allocate irq\n",unit);
226 /* finalize our own context */
228 memset(&sc->sc_txq, 0, sizeof(struct ifqueue));
229 sc->sc_txq.ifq_maxlen = sc->sc_capi.sc_nbch * 4;
232 sc->sc_state = IAVC_DOWN;
233 sc->sc_blocked = FALSE;
235 /* setup capi link */
237 sc->sc_capi.load = iavc_load;
238 sc->sc_capi.reg_appl = iavc_register;
239 sc->sc_capi.rel_appl = iavc_release;
240 sc->sc_capi.send = iavc_send;
241 sc->sc_capi.ctx = (void*) sc;
243 if (capi_ll_attach(&sc->sc_capi)) {
244 kprintf("iavc%d: capi attach failed\n", unit);
248 /* setup the interrupt */
250 error = bus_setup_intr(dev, sc->sc_resources.irq, 0,
251 (void(*)(void*))iavc_pci_intr,
254 kprintf("iavc%d: irq setup failed\n", unit);
258 /* the board is now ready to be loaded */
263 /*---------------------------------------------------------------------------*
265 *---------------------------------------------------------------------------*/
268 iavc_pci_intr(struct iavc_softc *sc)
270 iavc_handle_intr(sc);