1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
|
/*
* Copyright (c) 2000 Jonathan Lemon
* Copyright (c) 1999 by Matthew N. Dodd <winter@jurai.net>
* All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer,
* without modification, immediately at the beginning of the file.
* 2. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/bio.h>
#include <sys/devicestat.h>
#include <sys/disk.h>
#include <machine/bus_pio.h>
#include <machine/bus.h>
#include <machine/resource.h>
#include <sys/rman.h>
#include <dev/ida/idavar.h>
#include <dev/ida/idareg.h>
#include <dev/eisa/eisaconf.h>
#define IDA_EISA_IOPORT_START 0x0c88
#define IDA_EISA_IOPORT_LEN 0x0017
#define IDA_EISA_IRQ_REG 0x0cc0
#define IDA_EISA_IRQ_MASK 0xf0
#define IDA_EISA_IRQ_15 0x80
#define IDA_EISA_IRQ_14 0x40
#define IDA_EISA_IRQ_11 0x10
#define IDA_EISA_IRQ_10 0x20
static int
ida_v1_fifo_full(struct ida_softc *ida)
{
u_int8_t status;
status = ida_inb(ida, R_EISA_SYSTEM_DOORBELL);
return ((status & EISA_CHANNEL_CLEAR) == 0);
}
static void
ida_v1_submit(struct ida_softc *ida, struct ida_qcb *qcb)
{
u_int16_t size;
/*
* On these cards, this location is actually for control flags.
* Set them to zero and pass in structure size via an I/O port.
*/
size = qcb->hwqcb->hdr.size << 2;
qcb->hwqcb->hdr.size = 0;
ida_outb(ida, R_EISA_SYSTEM_DOORBELL, EISA_CHANNEL_CLEAR);
ida_outl(ida, R_EISA_LIST_ADDR, qcb->hwqcb_busaddr);
ida_outw(ida, R_EISA_LIST_LEN, size);
ida_outb(ida, R_EISA_LOCAL_DOORBELL, EISA_CHANNEL_BUSY);
}
static bus_addr_t
ida_v1_done(struct ida_softc *ida)
{
struct ida_hardware_qcb *hwqcb;
bus_addr_t completed;
u_int8_t status;
if ((ida_inb(ida, R_EISA_SYSTEM_DOORBELL) & EISA_CHANNEL_BUSY) == 0)
return (0);
ida_outb(ida, R_EISA_SYSTEM_DOORBELL, EISA_CHANNEL_BUSY);
completed = ida_inl(ida, R_EISA_COMPLETE_ADDR);
status = ida_inb(ida, R_EISA_LIST_STATUS);
ida_outb(ida, R_EISA_LOCAL_DOORBELL, EISA_CHANNEL_CLEAR);
if (completed != 0) {
hwqcb = (struct ida_hardware_qcb *)
((bus_addr_t)ida->hwqcbs +
((completed & ~3) - ida->hwqcb_busaddr));
hwqcb->req.error = status;
}
return (completed);
}
static int
ida_v1_int_pending(struct ida_softc *ida)
{
return (ida_inb(ida, R_EISA_SYSTEM_DOORBELL) & EISA_CHANNEL_BUSY);
}
static void
ida_v1_int_enable(struct ida_softc *ida, int enable)
{
if (enable) {
ida_outb(ida, R_EISA_SYSTEM_DOORBELL, ~EISA_CHANNEL_CLEAR);
ida_outb(ida, R_EISA_LOCAL_DOORBELL, EISA_CHANNEL_BUSY);
ida_outb(ida, R_EISA_INT_MASK, INT_ENABLE);
ida_outb(ida, R_EISA_SYSTEM_MASK, INT_ENABLE);
ida->flags |= IDA_INTERRUPTS;
} else {
ida_outb(ida, R_EISA_SYSTEM_MASK, INT_DISABLE);
ida->flags &= ~IDA_INTERRUPTS;
}
}
static int
ida_v2_fifo_full(struct ida_softc *ida)
{
return (ida_inl(ida, R_CMD_FIFO) == 0);
}
static void
ida_v2_submit(struct ida_softc *ida, struct ida_qcb *qcb)
{
ida_outl(ida, R_CMD_FIFO, qcb->hwqcb_busaddr);
}
static bus_addr_t
ida_v2_done(struct ida_softc *ida)
{
return (ida_inl(ida, R_DONE_FIFO));
}
static int
ida_v2_int_pending(struct ida_softc *ida)
{
return (ida_inl(ida, R_INT_PENDING));
}
static void
ida_v2_int_enable(struct ida_softc *ida, int enable)
{
if (enable)
ida->flags |= IDA_INTERRUPTS;
else
ida->flags &= ~IDA_INTERRUPTS;
ida_outl(ida, R_INT_MASK, enable ? INT_ENABLE : INT_DISABLE);
}
static struct ida_access ida_v1_access = {
ida_v1_fifo_full,
ida_v1_submit,
ida_v1_done,
ida_v1_int_pending,
ida_v1_int_enable,
};
static struct ida_access ida_v2_access = {
ida_v2_fifo_full,
ida_v2_submit,
ida_v2_done,
ida_v2_int_pending,
ida_v2_int_enable,
};
static struct ida_board board_id[] = {
{ 0x0e114001, "Compaq IDA controller",
&ida_v1_access, 0 },
{ 0x0e114002, "Compaq IDA-2 controller",
&ida_v1_access, 0 },
{ 0x0e114010, "Compaq IAES controller",
&ida_v1_access, 0 },
{ 0x0e114020, "Compaq SMART array controller",
&ida_v1_access, 0 },
{ 0x0e114030, "Compaq SMART-2/E array controller",
&ida_v2_access, 0 },
{ 0, "", 0, 0 }
};
static struct ida_board *ida_eisa_match(eisa_id_t);
static int ida_eisa_probe(device_t);
static int ida_eisa_attach(device_t);
static device_method_t ida_eisa_methods[] = {
DEVMETHOD(device_probe, ida_eisa_probe),
DEVMETHOD(device_attach, ida_eisa_attach),
DEVMETHOD(device_detach, ida_detach),
{ 0, 0 }
};
static driver_t ida_eisa_driver = {
"ida",
ida_eisa_methods,
sizeof(struct ida_softc)
};
static devclass_t ida_devclass;
static struct ida_board *
ida_eisa_match(eisa_id_t id)
{
int i;
for (i = 0; board_id[i].board; i++)
if (board_id[i].board == id)
return (&board_id[i]);
return (NULL);
}
static int
ida_eisa_probe(device_t dev)
{
struct ida_board *board;
u_int32_t io_base;
u_int irq = 0;
board = ida_eisa_match(eisa_get_id(dev));
if (board == NULL)
return (ENXIO);
device_set_desc(dev, board->desc);
io_base = (eisa_get_slot(dev) * EISA_SLOT_SIZE);
switch (IDA_EISA_IRQ_MASK & (inb(IDA_EISA_IRQ_REG + io_base))) {
case IDA_EISA_IRQ_15:
irq = 15;
break;
case IDA_EISA_IRQ_14:
irq = 14;
break;
case IDA_EISA_IRQ_11:
irq = 11;
break;
case IDA_EISA_IRQ_10:
irq = 10;
break;
default:
device_printf(dev, "slot %d, illegal irq setting.\n",
eisa_get_slot(dev));
return (ENXIO);
}
eisa_add_iospace(dev, (io_base + IDA_EISA_IOPORT_START),
IDA_EISA_IOPORT_LEN, RESVADDR_NONE);
eisa_add_intr(dev, irq, EISA_TRIGGER_LEVEL); /* XXX ??? */
return (0);
}
static int
ida_eisa_attach(device_t dev)
{
struct ida_softc *ida;
struct ida_board *board;
int error;
int rid;
ida = device_get_softc(dev);
ida->dev = dev;
board = ida_eisa_match(eisa_get_id(dev));
ida->cmd = *board->accessor;
ida->flags = board->flags;
ida->regs_res_type = SYS_RES_IOPORT;
ida->regs_res_id = 0;
ida->regs = bus_alloc_resource(dev, ida->regs_res_type,
&ida->regs_res_id, 0, ~0, 1, RF_ACTIVE);
if (ida->regs == NULL) {
device_printf(dev, "can't allocate register resources\n");
return (ENOMEM);
}
error = bus_dma_tag_create(
/* parent */ NULL,
/* alignment */ 0,
/* boundary */ 0,
/* lowaddr */ BUS_SPACE_MAXADDR_32BIT,
/* highaddr */ BUS_SPACE_MAXADDR,
/* filter */ NULL,
/* filterarg */ NULL,
/* maxsize */ MAXBSIZE,
/* nsegments */ IDA_NSEG,
/* maxsegsize */ BUS_SPACE_MAXSIZE_32BIT,
/* flags */ BUS_DMA_ALLOCNOW,
&ida->parent_dmat);
if (error != 0) {
device_printf(dev, "can't allocate DMA tag\n");
ida_free(ida);
return (ENOMEM);
}
rid = 0;
ida->irq_res_type = SYS_RES_IRQ;
ida->irq = bus_alloc_resource(dev, ida->irq_res_type, &rid,
0, ~0, 1, RF_ACTIVE | RF_SHAREABLE);
if (ida->irq == NULL) {
ida_free(ida);
return (ENOMEM);
}
error = bus_setup_intr(dev, ida->irq, INTR_TYPE_BIO | INTR_ENTROPY,
ida_intr, ida, &ida->ih);
if (error) {
device_printf(dev, "can't setup interrupt\n");
ida_free(ida);
return (ENOMEM);
}
error = ida_init(ida);
if (error) {
ida_free(ida);
return (error);
}
ida_attach(ida);
ida->flags |= IDA_ATTACHED;
return (0);
}
DRIVER_MODULE(ida, eisa, ida_eisa_driver, ida_devclass, 0, 0);
|