]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - sys/dev/dpt/dpt_eisa.c
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / sys / dev / dpt / dpt_eisa.c
1 /*-
2  * Copyright (c) 1997, 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 "opt_eisa.h"
32
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
36 #include <sys/module.h>
37 #include <sys/lock.h>
38 #include <sys/mutex.h>
39 #include <sys/bus.h>
40
41 #include <machine/bus.h>
42 #include <machine/resource.h>
43 #include <sys/rman.h>
44
45 #include <dev/eisa/eisaconf.h>
46
47 #include <cam/scsi/scsi_all.h>
48
49 #include <dev/dpt/dpt.h>
50
51 #define DPT_EISA_IOSIZE                 0x9
52 #define DPT_EISA_SLOT_OFFSET            0x0c00
53 #define DPT_EISA_EATA_REG_OFFSET        0x0088
54
55 #define DPT_EISA_DPT2402        0x12142402      /* DPT PM2012A/9X       */
56 #define DPT_EISA_DPTA401        0x1214A401      /* DPT PM2012B/9X       */
57 #define DPT_EISA_DPTA402        0x1214A402      /* DPT PM2012B2/9X      */
58 #define DPT_EISA_DPTA410        0x1214A410      /* DPT PM2x22A/9X       */
59 #define DPT_EISA_DPTA411        0x1214A411      /* DPT Spectre          */
60 #define DPT_EISA_DPTA412        0x1214A412      /* DPT PM2021A/9X       */
61 #define DPT_EISA_DPTA420        0x1214A420      /* DPT Smart Cache IV (PM2042) */
62 #define DPT_EISA_DPTA501        0x1214A501      /* DPT PM2012B1/9X"     */
63 #define DPT_EISA_DPTA502        0x1214A502      /* DPT PM2012Bx/9X      */
64 #define DPT_EISA_DPTA701        0x1214A701      /* DPT PM2011B1/9X      */
65 #define DPT_EISA_DPTBC01        0x1214BC01      /* DPT PM3011/7X ESDI   */ 
66 #define DPT_EISA_DPT8200        0x12148200      /* NEC EATA SCSI        */
67 #define DPT_EISA_DPT2408        0x12142408      /* ATT EATA SCSI        */
68
69 /* Function Prototypes */
70
71 static const char *     dpt_eisa_match  (eisa_id_t);
72 static int              dpt_eisa_probe  (device_t);
73 static int              dpt_eisa_attach (device_t);
74
75 static int
76 dpt_eisa_probe (device_t dev)
77 {
78         const char *    desc;
79         u_int32_t       io_base;
80         dpt_conf_t *    conf;
81
82         desc = dpt_eisa_match(eisa_get_id(dev));
83         if (!desc)
84                 return (ENXIO);
85         device_set_desc(dev, desc);
86
87         io_base = (eisa_get_slot(dev) * EISA_SLOT_SIZE) +
88                 DPT_EISA_SLOT_OFFSET +
89                 DPT_EISA_EATA_REG_OFFSET;
90
91         conf = dpt_pio_get_conf(io_base);
92         if (!conf) {
93                 printf("dpt: dpt_pio_get_conf() failed.\n");
94                 return (ENXIO);
95         }
96
97         eisa_add_iospace(dev, io_base, DPT_EISA_IOSIZE, RESVADDR_NONE);
98         eisa_add_intr(dev, conf->IRQ,
99                       (conf->IRQ_TR ? EISA_TRIGGER_LEVEL : EISA_TRIGGER_EDGE));
100
101         return 0;
102 }
103
104 static int
105 dpt_eisa_attach (device_t dev)
106 {
107         dpt_softc_t *   dpt;
108         int             s;
109         int             error = 0;
110
111         dpt = device_get_softc(dev);
112         dpt->dev = dev;
113
114         dpt->io_rid = 0;
115         dpt->io_type = SYS_RES_IOPORT;
116         dpt->irq_rid = 0;
117
118         error = dpt_alloc_resources(dev);
119         if (error) {
120                 goto bad;
121         }
122
123         dpt_alloc(dev);
124
125         /* Allocate a dmatag representing the capabilities of this attachment */
126         /* XXX Should be a child of the EISA bus dma tag */
127         if (bus_dma_tag_create( /* parent    */ NULL,
128                                 /* alignemnt */ 1,
129                                 /* boundary  */ 0,
130                                 /* lowaddr   */ BUS_SPACE_MAXADDR_32BIT,
131                                 /* highaddr  */ BUS_SPACE_MAXADDR,
132                                 /* filter    */ NULL,
133                                 /* filterarg */ NULL,
134                                 /* maxsize   */ BUS_SPACE_MAXSIZE_32BIT,
135                                 /* nsegments */ ~0,
136                                 /* maxsegsz  */ BUS_SPACE_MAXSIZE_32BIT,
137                                 /* flags     */ 0,
138                                 /* lockfunc  */ busdma_lock_mutex,
139                                 /* lockarg   */ &Giant,
140                                 &dpt->parent_dmat) != 0) {
141                 error = ENXIO;
142                 goto bad;
143         }
144
145         s = splcam();
146
147         if (dpt_init(dpt) != 0) {
148                 splx(s);
149                 error = ENXIO;
150                 goto bad;
151         }
152
153         /* Register with the XPT */
154         dpt_attach(dpt);
155
156         splx(s);
157
158         if (bus_setup_intr(dev, dpt->irq_res, INTR_TYPE_CAM | INTR_ENTROPY,
159                            NULL, dpt_intr, dpt, &dpt->ih)) {
160                 device_printf(dev, "Unable to register interrupt handler\n");
161                 error = ENXIO;
162                 goto bad;
163         }
164
165         return (error);
166
167  bad:
168         dpt_release_resources(dev);
169
170         dpt_free(dpt);
171
172         return (error);
173 }
174
175 static const char       *
176 dpt_eisa_match(type)
177         eisa_id_t       type;
178 {
179         switch (type) {
180                 case DPT_EISA_DPT2402:
181                 case DPT_EISA_DPTA401:
182                 case DPT_EISA_DPTA402:
183                 case DPT_EISA_DPTA410:
184                 case DPT_EISA_DPTA411:
185                 case DPT_EISA_DPTA412:
186                 case DPT_EISA_DPTA420:
187                 case DPT_EISA_DPTA501:
188                 case DPT_EISA_DPTA502:
189                 case DPT_EISA_DPTA701:
190                 case DPT_EISA_DPTBC01:
191                 case DPT_EISA_DPT8200:
192                 case DPT_EISA_DPT2408:
193                         return ("DPT SCSI Host Bus Adapter");
194                         break;
195                 default:
196                         break;
197         }
198         
199         return (NULL);
200 }
201
202 static device_method_t dpt_eisa_methods[] = {
203         /* Device interface */
204         DEVMETHOD(device_probe,         dpt_eisa_probe),
205         DEVMETHOD(device_attach,        dpt_eisa_attach),
206         DEVMETHOD(device_detach,        dpt_detach),
207
208         { 0, 0 }
209 };
210
211 static driver_t dpt_eisa_driver = {
212         "dpt",
213         dpt_eisa_methods,
214         sizeof(dpt_softc_t),
215 };
216
217 DRIVER_MODULE(dpt, eisa, dpt_eisa_driver, dpt_devclass, 0, 0);
218 MODULE_DEPEND(dpt, eisa, 1, 1, 1);
219 MODULE_DEPEND(dpt, cam, 1, 1, 1);