]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - sys/dev/dpt/dpt_isa.c
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / sys / dev / dpt / dpt_isa.c
1 /*-
2  * Copyright (c) 2000 Matthew N. Dodd <winter@jurai.net>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  */
27
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
30
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/kernel.h>
34 #include <sys/module.h>
35 #include <sys/bus.h>
36
37 #include <machine/bus.h>
38 #include <machine/resource.h>
39 #include <sys/rman.h>
40
41 #include <isa/isavar.h>
42
43 #include <cam/scsi/scsi_all.h>
44
45 #include <dev/dpt/dpt.h>
46
47 #ifdef notyet
48 static void     dpt_isa_identify        (driver_t *, device_t);
49 #endif
50 static int      dpt_isa_probe           (device_t);
51 static int      dpt_isa_attach          (device_t);
52 static int      dpt_isa_detach          (device_t);
53
54 static int      dpt_isa_valid_irq       (int);
55 static int      dpt_isa_valid_ioport    (int);
56
57 static int
58 dpt_isa_valid_irq (int irq)
59 {
60         switch (irq) {
61                 case 11:
62                 case 12:
63                 case 14:
64                 case 15:
65                         return (0);
66                 default:
67                         return (1);
68         };
69         return (1);
70 }
71
72 static int
73 dpt_isa_valid_ioport (int ioport)
74 {
75         switch (ioport) {
76                 case 0x170:
77                 case 0x1f0:
78                 case 0x230:
79                 case 0x330:
80                         return (0);
81                 default:
82                         return (1);
83         };
84         return (1);
85 }
86
87 #ifdef notyet
88 static void
89 dpt_isa_identify (driver_t *driver, device_t parent)
90 {
91         device_t        child;
92         dpt_conf_t *    conf;
93         int             isa_bases[] = { 0x1f0, 0x170, 0x330, 0x230, 0 };
94         int             i;
95
96         for (i = 0; isa_bases[i]; i++) {
97                 conf = dpt_pio_get_conf(isa_bases[i]);
98                 if (!conf) {
99                         if (bootverbose)
100                                 device_printf(parent, "dpt: dpt_pio_get_conf(%x) failed.\n",
101                                         isa_bases[i]);
102                         continue;
103                 }
104
105                 child = BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, "dpt", -1);
106                 if (child == 0) {
107                         device_printf(parent, "dpt: BUS_ADD_CHILD() failed!\n");
108                         continue;
109                 }
110                 device_set_driver(child, driver);
111                 bus_set_resource(child, SYS_RES_IOPORT, 0, isa_bases[i], 0x9);
112         }
113         return;
114 }
115 #endif
116
117 static int
118 dpt_isa_probe (device_t dev)
119 {
120         dpt_conf_t *    conf;
121         u_int32_t       io_base;
122
123         /* No pnp support */
124         if (isa_get_vendorid(dev))
125                 return (ENXIO);
126
127         if ((io_base = bus_get_resource_start(dev, SYS_RES_IOPORT, 0)) == 0)
128                 return (ENXIO);
129
130         if (dpt_isa_valid_ioport(io_base))
131                 ;
132
133         conf = dpt_pio_get_conf(io_base);
134         if (!conf) {
135                 printf("dpt: dpt_pio_get_conf() failed.\n");
136                 return (ENXIO);
137         }
138
139         if (dpt_isa_valid_irq(conf->IRQ))
140                 ;
141
142         device_set_desc(dev, "ISA DPT SCSI controller");
143         bus_set_resource(dev, SYS_RES_IRQ, 0, conf->IRQ, 1);
144         bus_set_resource(dev, SYS_RES_DRQ, 0, ((8 - conf->DMA_channel) & 7), 1);
145
146         return 0;
147 }
148
149 static int
150 dpt_isa_attach (device_t dev)
151 {
152         dpt_softc_t *   dpt;
153         int             s;
154         int             error = 0;
155
156         dpt = device_get_softc(dev);
157         dpt->dev = dev;
158
159         dpt->io_rid = 0;
160         dpt->io_type = SYS_RES_IOPORT;
161         dpt->irq_rid = 0;
162
163         error = dpt_alloc_resources(dev);
164         if (error) {
165                 goto bad;
166         }
167
168         dpt->drq_rid = 0;
169         dpt->drq_res = bus_alloc_resource_any(dev, SYS_RES_DRQ, &dpt->drq_rid,
170                                         RF_ACTIVE);
171         if (!dpt->drq_res) {
172                 device_printf(dev, "No DRQ!\n");
173                 error = ENOMEM;
174                 goto bad;
175         }
176         isa_dma_acquire(rman_get_start(dpt->drq_res));
177         isa_dmacascade(rman_get_start(dpt->drq_res));
178
179         dpt_alloc(dev);
180
181         /* Allocate a dmatag representing the capabilities of this attachment */
182         if (bus_dma_tag_create( /* parent    */ NULL,
183                                 /* alignemnt */ 1,
184                                 /* boundary  */ 0,
185                                 /* lowaddr   */ BUS_SPACE_MAXADDR_32BIT,
186                                 /* highaddr  */ BUS_SPACE_MAXADDR,
187                                 /* filter    */ NULL,
188                                 /* filterarg */ NULL,
189                                 /* maxsize   */ BUS_SPACE_MAXSIZE_32BIT,
190                                 /* nsegments */ ~0,
191                                 /* maxsegsz  */ BUS_SPACE_MAXSIZE_32BIT,
192                                 /* flags     */ 0,
193                                 /* lockfunc  */ busdma_lock_mutex,
194                                 /* lockarg   */ &Giant,
195                                 &dpt->parent_dmat) != 0) {
196                 error = ENXIO;
197                 goto bad;
198         }
199
200         s = splcam();
201
202         if (dpt_init(dpt) != 0) {
203                 splx(s);
204                 error = ENXIO;
205                 goto bad;
206         }
207
208         /* Register with the XPT */
209         dpt_attach(dpt);
210
211         splx(s);
212
213         if (bus_setup_intr(dev, dpt->irq_res, INTR_TYPE_CAM | INTR_ENTROPY,
214                            dpt_intr, dpt, &dpt->ih)) {
215                 device_printf(dev, "Unable to register interrupt handler\n");
216                 error = ENXIO;
217                 goto bad;
218         }
219
220         return (error);
221
222  bad:
223         if (dpt->drq_res) {
224                 isa_dma_release(rman_get_start(dpt->drq_res));
225         }
226
227         dpt_release_resources(dev);
228
229         if (dpt)
230                 dpt_free(dpt);
231
232         return (error);
233 }
234
235 static int
236 dpt_isa_detach (device_t dev)
237 {
238         dpt_softc_t *   dpt;
239         int             dma;
240         int             error;
241
242         dpt = device_get_softc(dev);
243
244         dma = rman_get_start(dpt->drq_res);
245         error = dpt_detach(dev);
246         isa_dma_release(dma);
247
248         return (error);
249 }
250
251
252 static device_method_t dpt_isa_methods[] = {
253         /* Device interface */
254 #ifdef notyet
255         DEVMETHOD(device_identify,      dpt_isa_identify),
256 #endif
257         DEVMETHOD(device_probe,         dpt_isa_probe),
258         DEVMETHOD(device_attach,        dpt_isa_attach),
259         DEVMETHOD(device_detach,        dpt_isa_detach),
260
261         { 0, 0 }
262 };
263
264 static driver_t dpt_isa_driver = {
265         "dpt",
266         dpt_isa_methods,
267         sizeof(dpt_softc_t),
268 };
269
270 DRIVER_MODULE(dpt, isa, dpt_isa_driver, dpt_devclass, 0, 0);
271 MODULE_DEPEND(dpt, isa, 1, 1, 1);
272 MODULE_DEPEND(dpt, cam, 1, 1, 1);