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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
|
/*
* EISA bus probe and attach routines
*
* Copyright (c) 1995, 1996 Justin T. Gibbs.
* 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 immediately at the beginning of the file, without modification,
* this list of conditions, and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. 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.
*
* $Id: eisaconf.c,v 1.22 1996/09/06 23:06:57 phk Exp $
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/sysctl.h>
#include <sys/conf.h>
#include <sys/malloc.h>
#include <i386/eisa/eisaconf.h>
#include <i386/isa/icu.h> /* Hmmm. Interrupt stuff? */
struct eisa_device_node{
struct eisa_device dev;
struct eisa_device_node *next;
};
/*
* This should probably be a list of "struct device" once it exists.
* A struct device will incorperate ioconf and driver entry point data
* regardless of how its attached to the system (via unions) as well
* as more generic information that all device types should support (unit
* number, if its installed, etc).
*/
static struct eisa_device_node *eisa_dev_list;
static struct eisa_device_node **eisa_dev_list_tail = &eisa_dev_list;
static u_long eisa_unit;
static struct eisa_driver mainboard_drv = {
"eisa",
NULL,
NULL,
NULL,
&eisa_unit
};
/*
* Add the mainboard_drv to the eisa driver linkerset so that it is
* defined even if no EISA drivers are linked into the kernel.
*/
DATA_SET (eisadriver_set, mainboard_drv);
/*
* Local function declarations and static variables
*/
void eisa_reg_print __P((struct eisa_device *e_dev, char *string,
char *separator));
static int eisa_add_resvaddr __P((struct eisa_device *e_dev,
struct resvlist *head, u_long base,
u_long size, int flags));
static int eisa_reg_resvaddr __P((struct eisa_device *e_dev,
struct resvlist *head, resvaddr_t *resvaddr,
int *reg_count));
/*
* Keep some state about what we've printed so far
* to make probe output pretty.
*/
static struct {
int in_registration;/* reg_start has been called */
int num_interrupts;
int num_ioaddrs;
int num_maddrs;
int column; /* How much we have output so far. */
#define MAX_COL 80
} reg_state;
/*
** probe for EISA devices
*/
void
eisa_configure()
{
int i,slot;
char *id_string;
struct eisa_device_node *dev_node;
struct eisa_driver **e_drvp;
struct eisa_driver *e_drv;
struct eisa_device *e_dev;
int eisaBase = 0xc80;
eisa_id_t eisa_id;
e_drvp = (struct eisa_driver**)eisadriver_set.ls_items;
for (slot = 0; slot < EISA_SLOTS; eisaBase+=0x1000, slot++) {
int id_size = sizeof(eisa_id);
eisa_id = 0;
for( i = 0; i < id_size; i++ ) {
outb(eisaBase,0x80 + i); /*Some cards require priming*/
eisa_id |= inb(eisaBase+i) << ((id_size-i-1)*CHAR_BIT);
}
if (eisa_id & 0x80000000)
continue; /* no EISA card in slot */
/* Prepare an eisa_device_node for this slot */
dev_node = (struct eisa_device_node *)malloc(sizeof(*dev_node),
M_DEVBUF, M_NOWAIT);
if (!dev_node) {
printf("eisa0: cannot malloc eisa_device_node");
break; /* Try to attach what we have already */
}
bzero(dev_node, sizeof(*dev_node));
e_dev = &(dev_node->dev);
e_dev->id = eisa_id;
/*
* Add an EISA ID based descriptive name incase we don't
* have a driver for it. We do this now instead of after all
* probes because in the future, the eisa module will only
* be responsible for creating the list of devices in the system
* for the configuration manager to use.
*/
e_dev->full_name = (char *)malloc(8*sizeof(char),
M_DEVBUF, M_NOWAIT);
if (!e_dev->full_name) {
panic("Eisa probe unable to malloc");
}
sprintf(e_dev->full_name, "%c%c%c%x%x",
EISA_MFCTR_CHAR0(e_dev->id),
EISA_MFCTR_CHAR1(e_dev->id),
EISA_MFCTR_CHAR2(e_dev->id),
EISA_PRODUCT_ID(e_dev->id),
EISA_REVISION_ID(e_dev->id));
e_dev->ioconf.slot = slot;
/* Initialize our lists of reserved addresses */
LIST_INIT(&(e_dev->ioconf.ioaddrs));
LIST_INIT(&(e_dev->ioconf.maddrs));
*eisa_dev_list_tail = dev_node;
eisa_dev_list_tail = &dev_node->next;
}
dev_node = eisa_dev_list;
/*
* "Attach" the system board
*/
/* The first will be the motherboard in a true EISA system */
if (dev_node && (dev_node->dev.ioconf.slot == 0)) {
e_dev = &dev_node->dev;
e_dev->driver = &mainboard_drv;
e_dev->unit = (*e_dev->driver->unit)++;
id_string = e_dev->full_name;
e_dev->full_name = (char *)malloc(strlen(e_dev->full_name)
+ sizeof(" (System Board)")
+ 1, M_DEVBUF, M_NOWAIT);
if (!e_dev->full_name) {
panic("Eisa probe unable to malloc");
}
sprintf(e_dev->full_name, "%s (System Board)", id_string);
free(id_string, M_DEVBUF);
printf("%s%ld: <%s>\n",
e_dev->driver->name,
e_dev->unit,
e_dev->full_name);
/* Should set the iosize, but I don't have a spec handy */
printf("Probing for devices on the EISA bus\n");
dev_node = dev_node->next;
}
if (!eisa_dev_list) {
/*
* No devices.
*/
return;
}
/*
* See what devices we recognize.
*/
while((e_drv = *e_drvp++)) {
if (e_drv->probe)
(*e_drv->probe)();
}
/*
* Attach the devices we found in slot order
*/
for (; dev_node; dev_node=dev_node->next) {
e_dev = &dev_node->dev;
e_drv = e_dev->driver;
if (e_drv) {
/*
* Determine the proper unit number for this device.
* Here we should look in the device table generated
* by config to see if this type of device is enabled
* either generically or for this particular address
* as well as determine if a reserved unit number
* should be used. We should also ensure that the
* "next availible unit number" skips over "wired" unit
* numbers. This will be done after config is fixed or
* some other configuration method is chosen.
*/
e_dev->unit = (*e_drv->unit)++;
if ((*e_drv->attach)(e_dev) < 0) {
/* Ensure registration has ended */
reg_state.in_registration = 0;
printf("\n%s0:%d <%s> attach failed\n",
mainboard_drv.name,
e_dev->ioconf.slot,
e_dev->full_name);
continue;
}
/* Ensure registration has ended */
reg_state.in_registration = 0;
}
else {
/* Announce unattached device */
printf("%s0:%d <%s=0x%x> unknown device\n",
mainboard_drv.name,
e_dev->ioconf.slot,
e_dev->full_name,
e_dev->id);
}
}
}
struct eisa_device *
eisa_match_dev(e_dev, match_func)
struct eisa_device *e_dev;
char* (*match_func)(eisa_id_t);
{
struct eisa_device_node *e_node = eisa_dev_list;
if (e_dev) {
/* Start our search from the last successful match */
e_node = ((struct eisa_device_node *)e_dev)->next;
}
for(; e_node; e_node = e_node->next) {
char *result;
if (e_node->dev.driver) {
/* Already claimed */
continue;
}
result = (*match_func)(e_node->dev.id);
if (result) {
free(e_node->dev.full_name, M_DEVBUF);
e_node->dev.full_name = result;
return (&(e_node->dev));
}
}
return NULL;
}
/* Interrupt and I/O space registration facitlities */
void
eisa_reg_start(e_dev)
struct eisa_device *e_dev;
{
/*
* Announce the device.
*/
char *string;
reg_state.in_registration = 1;
reg_state.num_interrupts = 0;
reg_state.num_ioaddrs = 0;
reg_state.num_maddrs = 0;
reg_state.column = 0;
string = malloc(strlen(e_dev->full_name) + sizeof(" <>") + /*NULL*/1,
M_TEMP, M_NOWAIT);
if(!string) {
printf("eisa0: cannot malloc device description string\n");
return;
}
sprintf(string, " <%s>", e_dev->full_name);
eisa_reg_print(e_dev, string, /*separator=*/NULL);
free(string, M_TEMP);
}
/*
* Output registration information mindfull of screen wrap.
* Output an optional character separator before the string
* if the line does not wrap.
*/
void
eisa_reg_print(e_dev, string, separator)
struct eisa_device *e_dev;
char *string;
char *separator;
{
int len = strlen(string);
if(separator)
len++;
if(reg_state.column + len > MAX_COL) {
printf("\n");
reg_state.column = 0;
}
else if(separator) {
printf("%c", *separator);
reg_state.column++;
}
if(reg_state.column == 0)
reg_state.column += printf("%s%ld:%s",
e_dev->driver->name,
e_dev->unit,
string);
else
reg_state.column += printf("%s", string);
}
/* Interrupt and I/O space registration facitlities */
void
eisa_reg_end(e_dev)
struct eisa_device *e_dev;
{
if( reg_state.in_registration )
{
char string[25];
sprintf(string, " on %s0 slot %d",
mainboard_drv.name,
e_dev->ioconf.slot);
eisa_reg_print(e_dev, string, NULL);
printf("\n");
reg_state.in_registration = 0;
}
else
printf("eisa_reg_end called outside of a "
"registration session\n");
}
int
eisa_add_intr(e_dev, irq)
struct eisa_device *e_dev;
int irq;
{
e_dev->ioconf.irq |= 1ul << irq;
return 0;
}
int
eisa_reg_intr(e_dev, irq, func, arg, maskptr, shared)
struct eisa_device *e_dev;
int irq;
void (*func)(void *);
void *arg;
u_int *maskptr;
int shared;
{
int result;
int s;
char string[25];
char separator = ',';
#if NOT_YET
/*
* Punt on conflict detection for the moment.
* I want to develop a generic routine to do
* this for all device types.
*/
int checkthese = CC_IRQ;
if (haveseen_dev(dev, checkthese))
return 1;
#endif
if (reg_state.in_registration) {
s = splhigh();
/*
* This should really go to a routine that can optionally
* handle shared interrupts.
*/
result = register_intr(irq, /* isa irq */
0, /* deviced?? */
0, /* flags? */
(inthand2_t*) func, /* handler */
maskptr, /* mask pointer */
(int)arg); /* handler arg */
if (result) {
printf ("\neisa_reg_int: result=%d\n", result);
splx(s);
return (result);
};
update_intr_masks();
splx(s);
}
else
return EPERM;
e_dev->ioconf.irq |= 1ul << irq;
sprintf(string, " irq %d", irq);
eisa_reg_print(e_dev, string, reg_state.num_interrupts ?
&separator : NULL);
reg_state.num_interrupts++;
return (0);
}
int
eisa_release_intr(e_dev, irq, func)
struct eisa_device *e_dev;
int irq;
void (*func)(void *);
{
int result;
int s;
if (!(e_dev->ioconf.irq & (1ul << irq))) {
printf("%s%ld: Attempted to release an interrupt (%d) "
"it doesn't own\n", e_dev->driver->name,
e_dev->unit, irq);
return (-1);
}
s = splhigh();
INTRDIS ((1ul<<irq));
result = unregister_intr (irq, (inthand2_t*)func);
if (result)
printf ("eisa_release_intr: result=%d\n", result);
update_intr_masks();
splx(s);
return (result);
}
int
eisa_enable_intr(e_dev, irq)
struct eisa_device *e_dev;
int irq;
{
int s;
if (!(e_dev->ioconf.irq & (1ul << irq))) {
printf("%s%ld: Attempted to enable an interrupt (%d) "
"it doesn't own\n", e_dev->driver->name,
e_dev->unit, irq);
return (-1);
}
s = splhigh();
INTREN((1ul << irq));
splx(s);
return 0;
}
static int
eisa_add_resvaddr(e_dev, head, base, size, flags)
struct eisa_device *e_dev;
struct resvlist *head;
u_long base;
u_long size;
int flags;
{
resvaddr_t *reservation;
reservation = (resvaddr_t *)malloc(sizeof(resvaddr_t),
M_DEVBUF, M_NOWAIT);
if(!reservation)
return (ENOMEM);
reservation->addr = base;
reservation->size = size;
reservation->flags = flags;
if (!head->lh_first) {
LIST_INSERT_HEAD(head, reservation, links);
}
else {
resvaddr_t *node;
for(node = head->lh_first; node; node = node->links.le_next) {
if (node->addr > reservation->addr) {
/*
* List is sorted in increasing
* address order.
*/
LIST_INSERT_BEFORE(node, reservation, links);
break;
}
if (node->addr == reservation->addr) {
/*
* If the entry we want to add
* matches any already in here,
* fail.
*/
free(reservation, M_DEVBUF);
return (EEXIST);
}
if (!node->links.le_next) {
LIST_INSERT_AFTER(node, reservation, links);
break;
}
}
}
return (0);
}
int
eisa_add_mspace(e_dev, mbase, msize, flags)
struct eisa_device *e_dev;
u_long mbase;
u_long msize;
int flags;
{
return eisa_add_resvaddr(e_dev, &(e_dev->ioconf.maddrs), mbase, msize,
flags);
}
int
eisa_add_iospace(e_dev, iobase, iosize, flags)
struct eisa_device *e_dev;
u_long iobase;
u_long iosize;
int flags;
{
return eisa_add_resvaddr(e_dev, &(e_dev->ioconf.ioaddrs), iobase,
iosize, flags);
}
static int
eisa_reg_resvaddr(e_dev, head, resvaddr, reg_count)
struct eisa_device *e_dev;
struct resvlist *head;
resvaddr_t *resvaddr;
int *reg_count;
{
if (reg_state.in_registration) {
resvaddr_t *node;
/*
* Ensure that this resvaddr is actually in the devices'
* reservation list.
*/
for(node = head->lh_first; node;
node = node->links.le_next) {
if (node == resvaddr) {
char buf[35];
char separator = ',';
char *string = buf;
if (*reg_count == 0) {
/* First time */
string += sprintf(string, " at");
}
if (node->size == 1
|| (node->flags & RESVADDR_BITMASK))
sprintf(string, " 0x%lx", node->addr);
else
sprintf(string, " 0x%lx-0x%lx",
node->addr,
node->addr + node->size - 1);
eisa_reg_print(e_dev, buf,
*reg_count ? &separator : NULL);
(*reg_count)++;
return (0);
}
}
return (ENOENT);
}
return EPERM;
}
int
eisa_reg_mspace(e_dev, resvaddr)
struct eisa_device *e_dev;
resvaddr_t *resvaddr;
{
#ifdef NOT_YET
/*
* Punt on conflict detection for the moment.
* I want to develop a generic routine to do
* this for all device types.
*/
int checkthese = CC_MADDR;
if (haveseen_dev(dev, checkthese))
return -1;
#endif
return (eisa_reg_resvaddr(e_dev, &(e_dev->ioconf.maddrs), resvaddr,
&(reg_state.num_maddrs)));
}
int
eisa_reg_iospace(e_dev, resvaddr)
struct eisa_device *e_dev;
resvaddr_t *resvaddr;
{
#ifdef NOT_YET
/*
* Punt on conflict detection for the moment.
* I want to develop a generic routine to do
* this for all device types.
*/
int checkthese = CC_IOADDR;
if (haveseen_dev(dev, checkthese))
return -1;
#endif
return (eisa_reg_resvaddr(e_dev, &(e_dev->ioconf.ioaddrs), resvaddr,
&(reg_state.num_ioaddrs)));
}
int
eisa_registerdev(e_dev, driver)
struct eisa_device *e_dev;
struct eisa_driver *driver;
{
e_dev->driver = driver; /* Driver now owns this device */
return (0);
}
|