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.2 2003/06/17 04:28:39 dillon Exp $
36 #if (NIAVC > 0) && (NI4BCAPI > 0) && (NPCI > 0)
38 #include <sys/param.h>
39 #include <sys/kernel.h>
40 #include <sys/systm.h>
42 #include <sys/socket.h>
45 #include <machine/clock.h>
47 #include <machine/bus.h>
48 #include <machine/resource.h>
54 #include <pci/pcireg.h>
55 #include <pci/pcivar.h>
57 #include <machine/i4b_debug.h>
58 #include <machine/i4b_ioctl.h>
59 #include <machine/i4b_trace.h>
61 #include <i4b/include/i4b_global.h>
62 #include <i4b/include/i4b_l3l4.h>
63 #include <i4b/include/i4b_mbuf.h>
65 #include <i4b/capi/capi.h>
67 #include <i4b/capi/iavc/iavc.h>
71 #define PCI_AVM_VID 0x1244
72 #define PCI_AVMT1_DID 0x1200
73 #define PCI_AVMB1_DID 0x0700
75 /* PCI driver linkage */
77 static void iavc_pci_intr(iavc_softc_t *sc);
78 static int iavc_pci_probe(device_t dev);
79 static int iavc_pci_attach(device_t dev);
81 static device_method_t iavc_pci_methods[] =
83 DEVMETHOD(device_probe, iavc_pci_probe),
84 DEVMETHOD(device_attach, iavc_pci_attach),
88 static driver_t iavc_pci_driver =
95 static devclass_t iavc_pci_devclass;
97 DRIVER_MODULE(iavc, pci, iavc_pci_driver, iavc_pci_devclass, 0, 0);
99 /* Driver soft contexts */
101 iavc_softc_t iavc_sc[IAVC_MAXUNIT];
103 /*---------------------------------------------------------------------------*
105 *---------------------------------------------------------------------------*/
108 iavc_pci_probe(device_t dev)
110 u_int16_t did = pci_get_device(dev);
111 u_int16_t vid = pci_get_vendor(dev);
113 if ((vid == PCI_AVM_VID) && (did == PCI_AVMT1_DID)) {
114 device_set_desc(dev, "AVM T1 PCI");
115 } else if ((vid == PCI_AVM_VID) && (did == PCI_AVMB1_DID)) {
116 device_set_desc(dev, "AVM B1 PCI");
124 /*---------------------------------------------------------------------------*
126 *---------------------------------------------------------------------------*/
129 iavc_pci_attach(device_t dev)
131 struct iavc_softc *sc;
133 u_int16_t did = pci_get_device(dev);
134 int unit = device_get_unit(dev), ret;
136 /* check max unit range */
138 if (unit >= IAVC_MAXUNIT) {
139 printf("iavc%d: too many units\n", unit);
143 sc = iavc_find_sc(unit); /* get softc */
147 /* use the i/o mapped base address */
149 sc->sc_resources.io_rid[0] = 0x14;
151 if (!(sc->sc_resources.io_base[0] =
152 bus_alloc_resource(dev, SYS_RES_IOPORT,
153 &sc->sc_resources.io_rid[0],
154 0UL, ~0UL, 1, RF_ACTIVE))) {
155 printf("iavc%d: can't allocate io region\n", unit);
159 sc->sc_iobase = rman_get_start(sc->sc_resources.io_base[0]);
160 sc->sc_io_bt = rman_get_bustag(sc->sc_resources.io_base[0]);
161 sc->sc_io_bh = rman_get_bushandle(sc->sc_resources.io_base[0]);
163 /* use the memory mapped DMA controller */
165 sc->sc_resources.mem_rid = 0x10;
167 if (!(sc->sc_resources.mem =
168 bus_alloc_resource(dev, SYS_RES_MEMORY,
169 &sc->sc_resources.mem_rid,
170 0UL, ~0UL, 1, RF_ACTIVE))) {
171 printf("iavc%d: can't allocate memory region\n", unit);
175 sc->sc_membase = rman_get_start(sc->sc_resources.mem);
176 sc->sc_mem_bt = rman_get_bustag(sc->sc_resources.mem);
177 sc->sc_mem_bh = rman_get_bushandle(sc->sc_resources.mem);
179 /* do some detection */
185 if (did == PCI_AVMT1_DID) {
186 sc->sc_capi.card_type = CARD_TYPEC_AVM_T1_PCI;
187 sc->sc_capi.sc_nbch = 30;
191 printf("iavc%d: no card detected?\n", sc->sc_unit);
193 printf("iavc%d: black box not on\n", sc->sc_unit);
201 } else if (did == PCI_AVMB1_DID) {
202 sc->sc_capi.card_type = CARD_TYPEC_AVM_B1_PCI;
203 sc->sc_capi.sc_nbch = 2;
204 ret = b1dma_detect(sc);
208 printf("iavc%d: no card detected?\n", sc->sc_unit);
216 if (sc->sc_dma) b1dma_reset(sc);
218 if (sc->sc_t1) t1_reset(sc);
222 /* of course we need an interrupt */
224 sc->sc_resources.irq_rid = 0x00;
226 if(!(sc->sc_resources.irq =
227 bus_alloc_resource(dev, SYS_RES_IRQ,
228 &sc->sc_resources.irq_rid,
229 0UL, ~0UL, 1, RF_SHAREABLE|RF_ACTIVE))) {
230 printf("iavc%d: can't allocate irq\n",unit);
234 /* finalize our own context */
236 memset(&sc->sc_txq, 0, sizeof(struct ifqueue));
237 sc->sc_txq.ifq_maxlen = sc->sc_capi.sc_nbch * 4;
239 #if defined (__FreeBSD__) && __FreeBSD__ > 4
240 mtx_init(&sc->sc_txq.ifq_mtx, "i4b_ivac_pci", MTX_DEF);
244 sc->sc_state = IAVC_DOWN;
245 sc->sc_blocked = FALSE;
247 /* setup capi link */
249 sc->sc_capi.load = iavc_load;
250 sc->sc_capi.reg_appl = iavc_register;
251 sc->sc_capi.rel_appl = iavc_release;
252 sc->sc_capi.send = iavc_send;
253 sc->sc_capi.ctx = (void*) sc;
255 if (capi_ll_attach(&sc->sc_capi)) {
256 printf("iavc%d: capi attach failed\n", unit);
260 /* setup the interrupt */
262 if(bus_setup_intr(dev, sc->sc_resources.irq, INTR_TYPE_NET,
263 (void(*)(void*))iavc_pci_intr,
265 printf("iavc%d: irq setup failed\n", unit);
269 /* the board is now ready to be loaded */
274 /*---------------------------------------------------------------------------*
276 *---------------------------------------------------------------------------*/
279 iavc_pci_intr(struct iavc_softc *sc)
281 iavc_handle_intr(sc);