FreeBSD/Linux Kernel Cross Reference
sys/dev/isa/daic_isa.c
1 /*-
2 * Copyright (c) 2002 The NetBSD Foundation, Inc.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to The NetBSD Foundation
6 * by Martin Husemann <martin@NetBSD.org>.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the NetBSD
19 * Foundation, Inc. and its contributors.
20 * 4. Neither the name of The NetBSD Foundation nor the names of its
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
25 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
28 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37 #include <sys/cdefs.h>
38 __KERNEL_RCSID(0, "$NetBSD: daic_isa.c,v 1.11 2003/12/04 13:57:30 keihan Exp $");
39
40 #include <sys/param.h>
41 #include <sys/errno.h>
42 #include <sys/syslog.h>
43 #include <sys/device.h>
44
45 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
46 #include <sys/callout.h>
47 #endif
48
49 #include <machine/cpu.h>
50 #include <machine/intr.h>
51 #include <machine/bus.h>
52
53 #include <sys/socket.h>
54 #include <net/if.h>
55 #include <dev/isa/isavar.h>
56 #include <netisdn/i4b_ioctl.h>
57 #include <netisdn/i4b_l3l4.h>
58 #include <dev/ic/daicvar.h>
59
60 /* driver state */
61 struct daic_isa_softc {
62 struct daic_softc sc_daic; /* MI driver state */
63 void *sc_ih; /* interrupt handler */
64 };
65
66 /* local functions */
67 #ifdef __BROKEN_INDIRECT_CONFIG
68 static int daic_isa_probe __P((struct device *, void *, void *));
69 #else
70 static int daic_isa_probe __P((struct device *, struct cfdata *, void *));
71 #endif
72 static void daic_isa_attach __P((struct device *, struct device *, void *));
73 static int daic_isa_intr __P((void *));
74
75 CFATTACH_DECL(daic_isa, sizeof(struct daic_isa_softc),
76 daic_isa_probe, daic_isa_attach, NULL, NULL);
77
78 static int
79 #ifdef __BROKEN_INDIRECT_CONFIG
80 daic_isa_probe(parent, match, aux)
81 #else
82 daic_isa_probe(parent, cf, aux)
83 #endif
84 struct device *parent;
85 #ifdef __BROKEN_INDIRECT_CONFIG
86 void *match;
87 #else
88 struct cfdata *cf;
89 #endif
90 void *aux;
91 {
92 struct isa_attach_args *ia = aux;
93 bus_space_tag_t memt = ia->ia_memt;
94 bus_space_handle_t memh;
95 int card, need_unmap = 0;
96
97 /* We need some controller memory to comunicate! */
98 if (ia->ia_iomem[0].ir_addr == 0 || ia->ia_iomem[0].ir_size == -1)
99 goto bad;
100
101 /* Map card RAM. */
102 ia->ia_iomem[0].ir_size = DAIC_ISA_MEMSIZE;
103 ia->ia_nio = 0;
104 ia->ia_ndrq = 0;
105 ia->ia_nirq = 1;
106 ia->ia_niomem = 1;
107 if (bus_space_map(memt, ia->ia_iomem[0].ir_addr, ia->ia_iomem[0].ir_size,
108 0, &memh))
109 goto bad;
110 need_unmap = 1;
111
112 /* MI check for card at this location */
113 card = daic_probe(memt, memh);
114 if (card < 0)
115 goto bad;
116 if (card == DAIC_TYPE_QUAD)
117 ia->ia_iomem[0].ir_size = DAIC_ISA_QUADSIZE;
118
119 bus_space_unmap(memt, memh, DAIC_ISA_MEMSIZE);
120 return 1;
121
122 bad:
123 /* unmap card RAM if already mapped */
124 if (need_unmap)
125 bus_space_unmap(memt, memh, DAIC_ISA_MEMSIZE);
126 return 0;
127 }
128
129 static void
130 daic_isa_attach(parent, self, aux)
131 struct device *parent, *self;
132 void *aux;
133 {
134 struct daic_isa_softc *sc = (void *)self;
135 struct isa_attach_args *ia = aux;
136 bus_space_tag_t memt = ia->ia_memt;
137 bus_space_handle_t memh;
138
139 /* Map card RAM. */
140 if (bus_space_map(memt, ia->ia_iomem[0].ir_addr, ia->ia_iomem[0].ir_size,
141 0, &memh))
142 return;
143
144 sc->sc_daic.sc_iot = memt;
145 sc->sc_daic.sc_ioh = memh;
146
147 /* MI initialization of card */
148 daic_attach(self, &sc->sc_daic);
149
150 sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq, IST_EDGE,
151 IPL_NET, daic_isa_intr, sc);
152 }
153
154 /*
155 * Controller interrupt.
156 */
157 static int
158 daic_isa_intr(arg)
159 void *arg;
160 {
161 struct daic_isa_softc *sc = arg;
162 return daic_intr(&sc->sc_daic);
163 }
Cache object: a0ed180922800dd427fb4f296934f0cf
|