2005-01-06 01:43:34 +00:00
|
|
|
/*-
|
1995-11-05 04:42:50 +00:00
|
|
|
* EISA bus probe and attach routines
|
1995-04-23 08:55:43 +00:00
|
|
|
*
|
1996-01-29 03:13:23 +00:00
|
|
|
* Copyright (c) 1995, 1996 Justin T. Gibbs.
|
1995-11-05 04:42:50 +00:00
|
|
|
* All rights reserved.
|
1996-04-20 21:21:50 +00:00
|
|
|
*
|
1995-11-05 04:42:50 +00:00
|
|
|
* 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.
|
1996-04-20 21:21:50 +00:00
|
|
|
* 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.
|
1995-04-23 08:55:43 +00:00
|
|
|
*
|
|
|
|
*/
|
1997-03-13 18:04:05 +00:00
|
|
|
|
2003-08-24 17:55:58 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1997-03-13 18:04:05 +00:00
|
|
|
#include "opt_eisa.h"
|
|
|
|
|
1995-04-23 08:55:43 +00:00
|
|
|
#include <sys/param.h>
|
1995-11-05 04:42:50 +00:00
|
|
|
#include <sys/systm.h>
|
1999-04-18 15:50:35 +00:00
|
|
|
#include <sys/queue.h>
|
2003-04-29 13:36:06 +00:00
|
|
|
#include <sys/limits.h>
|
1995-11-05 04:42:50 +00:00
|
|
|
#include <sys/malloc.h>
|
1999-04-18 15:50:35 +00:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/bus.h>
|
1995-04-23 08:55:43 +00:00
|
|
|
|
1999-04-18 15:50:35 +00:00
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/resource.h>
|
|
|
|
#include <sys/rman.h>
|
1997-08-21 20:33:42 +00:00
|
|
|
|
2000-01-14 07:14:17 +00:00
|
|
|
#include <dev/eisa/eisaconf.h>
|
1995-11-29 17:40:47 +00:00
|
|
|
|
1999-04-18 15:50:35 +00:00
|
|
|
typedef struct resvaddr {
|
|
|
|
u_long addr; /* start address */
|
|
|
|
u_long size; /* size of reserved area */
|
|
|
|
int flags;
|
|
|
|
struct resource *res; /* resource manager handle */
|
2000-05-26 02:09:24 +00:00
|
|
|
LIST_ENTRY(resvaddr) links; /* List links */
|
1999-04-18 15:50:35 +00:00
|
|
|
} resvaddr_t;
|
|
|
|
|
2000-05-26 02:09:24 +00:00
|
|
|
LIST_HEAD(resvlist, resvaddr);
|
1999-04-18 15:50:35 +00:00
|
|
|
|
|
|
|
struct irq_node {
|
|
|
|
int irq_no;
|
1999-08-01 22:57:09 +00:00
|
|
|
int irq_trigger;
|
1999-04-18 15:50:35 +00:00
|
|
|
void *idesc;
|
2000-05-26 02:09:24 +00:00
|
|
|
TAILQ_ENTRY(irq_node) links;
|
1995-11-05 04:42:50 +00:00
|
|
|
};
|
1995-04-23 08:55:43 +00:00
|
|
|
|
2000-05-26 02:09:24 +00:00
|
|
|
TAILQ_HEAD(irqlist, irq_node);
|
1999-04-18 15:50:35 +00:00
|
|
|
|
|
|
|
struct eisa_ioconf {
|
|
|
|
int slot;
|
|
|
|
struct resvlist ioaddrs; /* list of reserved I/O ranges */
|
|
|
|
struct resvlist maddrs; /* list of reserved memory ranges */
|
|
|
|
struct irqlist irqs; /* list of reserved irqs */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* To be replaced by the "super device" generic device structure... */
|
|
|
|
struct eisa_device {
|
|
|
|
eisa_id_t id;
|
|
|
|
struct eisa_ioconf ioconf;
|
|
|
|
};
|
1995-11-10 01:32:12 +00:00
|
|
|
|
|
|
|
|
1999-07-30 13:54:00 +00:00
|
|
|
#define MAX_COL 79
|
1997-03-13 18:04:05 +00:00
|
|
|
#ifndef EISA_SLOTS
|
|
|
|
#define EISA_SLOTS 10 /* PCI clashes with higher ones.. fix later */
|
|
|
|
#endif
|
1996-12-14 18:07:17 +00:00
|
|
|
int num_eisa_slots = EISA_SLOTS;
|
2002-10-31 00:45:49 +00:00
|
|
|
TUNABLE_INT("hw.eisa_slots", &num_eisa_slots);
|
1999-04-18 15:50:35 +00:00
|
|
|
|
|
|
|
static devclass_t eisa_devclass;
|
|
|
|
|
2004-08-03 00:41:47 +00:00
|
|
|
static int eisa_probe_slot(int slot, eisa_id_t *eisa_id);
|
2005-08-01 07:09:15 +00:00
|
|
|
static struct irq_node *eisa_find_irq(struct eisa_device *e_dev, int rid);
|
|
|
|
static struct resvaddr *eisa_find_maddr(struct eisa_device *e_dev, int rid);
|
|
|
|
static struct resvaddr *eisa_find_ioaddr(struct eisa_device *e_dev, int rid);
|
1999-07-30 13:54:00 +00:00
|
|
|
|
1999-04-18 15:50:35 +00:00
|
|
|
static int
|
|
|
|
mainboard_probe(device_t dev)
|
|
|
|
{
|
|
|
|
char *idstring;
|
|
|
|
eisa_id_t id = eisa_get_id(dev);
|
|
|
|
|
|
|
|
if (eisa_get_slot(dev) != 0)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
idstring = (char *)malloc(8 + sizeof(" (System Board)") + 1,
|
2005-03-17 17:33:52 +00:00
|
|
|
M_DEVBUF, M_NOWAIT);
|
|
|
|
if (idstring == NULL)
|
1999-04-18 15:50:35 +00:00
|
|
|
panic("Eisa probe unable to malloc");
|
1999-07-11 13:42:37 +00:00
|
|
|
sprintf(idstring, "%c%c%c%03x%01x (System Board)",
|
2005-03-17 17:33:52 +00:00
|
|
|
EISA_MFCTR_CHAR0(id), EISA_MFCTR_CHAR1(id), EISA_MFCTR_CHAR2(id),
|
|
|
|
EISA_PRODUCT_ID(id), EISA_REVISION_ID(id));
|
1999-04-18 15:50:35 +00:00
|
|
|
device_set_desc(dev, idstring);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mainboard_attach(device_t dev)
|
|
|
|
{
|
1999-04-19 13:34:25 +00:00
|
|
|
return (0);
|
1999-04-18 15:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static device_method_t mainboard_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, mainboard_probe),
|
|
|
|
DEVMETHOD(device_attach, mainboard_attach),
|
|
|
|
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t mainboard_driver = {
|
|
|
|
"mainboard",
|
|
|
|
mainboard_methods,
|
|
|
|
1,
|
|
|
|
};
|
|
|
|
|
|
|
|
static devclass_t mainboard_devclass;
|
|
|
|
|
|
|
|
DRIVER_MODULE(mainboard, eisa, mainboard_driver, mainboard_devclass, 0, 0);
|
1996-01-29 03:13:23 +00:00
|
|
|
|
1995-04-23 08:55:43 +00:00
|
|
|
/*
|
|
|
|
** probe for EISA devices
|
|
|
|
*/
|
1999-04-18 15:50:35 +00:00
|
|
|
static int
|
|
|
|
eisa_probe(device_t dev)
|
1995-04-23 08:55:43 +00:00
|
|
|
{
|
2004-08-03 06:48:36 +00:00
|
|
|
int devices_found, slot;
|
1995-11-09 07:14:11 +00:00
|
|
|
struct eisa_device *e_dev;
|
1999-12-03 08:41:24 +00:00
|
|
|
device_t child;
|
1995-11-09 07:14:11 +00:00
|
|
|
eisa_id_t eisa_id;
|
|
|
|
|
1999-04-19 06:57:33 +00:00
|
|
|
device_set_desc(dev, "EISA bus");
|
|
|
|
|
2004-08-03 00:41:47 +00:00
|
|
|
devices_found = 0;
|
|
|
|
for (slot = 0; slot < num_eisa_slots; slot++) {
|
1995-11-09 07:14:11 +00:00
|
|
|
eisa_id = 0;
|
2004-08-03 06:48:36 +00:00
|
|
|
if (eisa_probe_slot(slot, &eisa_id)) {
|
2004-08-03 00:41:47 +00:00
|
|
|
/*
|
|
|
|
* If there's no card in the first slot (the
|
|
|
|
* mainboard), then the system doesn't have EISA.
|
|
|
|
* We abort the probe early in this case since
|
|
|
|
* continuing on causes a hang on some systems.
|
|
|
|
* Interestingly enough, the inb has been seen to
|
2005-03-17 17:36:07 +00:00
|
|
|
* cause the hang.
|
2004-08-03 00:41:47 +00:00
|
|
|
*/
|
|
|
|
if (slot == 0)
|
|
|
|
break;
|
|
|
|
continue;
|
1995-11-09 07:14:11 +00:00
|
|
|
}
|
|
|
|
|
1999-05-18 21:03:30 +00:00
|
|
|
devices_found++;
|
|
|
|
|
1995-11-09 07:14:11 +00:00
|
|
|
/* Prepare an eisa_device_node for this slot */
|
1999-04-18 15:50:35 +00:00
|
|
|
e_dev = (struct eisa_device *)malloc(sizeof(*e_dev),
|
2005-03-17 17:33:52 +00:00
|
|
|
M_DEVBUF, M_NOWAIT|M_ZERO);
|
1999-04-18 15:50:35 +00:00
|
|
|
if (!e_dev) {
|
1999-04-19 13:34:25 +00:00
|
|
|
device_printf(dev, "cannot malloc eisa_device");
|
1995-11-09 07:14:11 +00:00
|
|
|
break; /* Try to attach what we have already */
|
|
|
|
}
|
1996-01-29 03:13:23 +00:00
|
|
|
|
1995-11-09 07:14:11 +00:00
|
|
|
e_dev->id = eisa_id;
|
|
|
|
e_dev->ioconf.slot = slot;
|
1996-01-29 03:13:23 +00:00
|
|
|
|
|
|
|
/* Initialize our lists of reserved addresses */
|
|
|
|
LIST_INIT(&(e_dev->ioconf.ioaddrs));
|
|
|
|
LIST_INIT(&(e_dev->ioconf.maddrs));
|
1997-09-21 21:35:24 +00:00
|
|
|
TAILQ_INIT(&(e_dev->ioconf.irqs));
|
1996-01-29 03:13:23 +00:00
|
|
|
|
1999-12-03 08:41:24 +00:00
|
|
|
child = device_add_child(dev, NULL, -1);
|
|
|
|
device_set_ivars(child, e_dev);
|
1995-11-06 05:21:01 +00:00
|
|
|
}
|
|
|
|
|
1999-05-18 21:03:30 +00:00
|
|
|
/*
|
|
|
|
* EISA busses themselves are not easily detectable, the easiest way
|
|
|
|
* to tell if there is an eisa bus is if we found something - there
|
|
|
|
* should be a motherboard "card" there somewhere.
|
|
|
|
*/
|
2005-03-17 17:33:52 +00:00
|
|
|
return (devices_found ? 0 : ENXIO);
|
1999-04-18 15:50:35 +00:00
|
|
|
}
|
1995-11-06 05:21:01 +00:00
|
|
|
|
2004-08-03 00:41:47 +00:00
|
|
|
static int
|
|
|
|
eisa_probe_slot(int slot, eisa_id_t *eisa_id)
|
|
|
|
{
|
|
|
|
eisa_id_t probe_id;
|
2004-08-16 22:05:53 +00:00
|
|
|
int base, i, id_size;
|
2004-08-03 00:41:47 +00:00
|
|
|
|
|
|
|
probe_id = 0;
|
|
|
|
id_size = sizeof(probe_id);
|
|
|
|
base = 0x0c80 + (slot * 0x1000);
|
|
|
|
|
2004-08-16 22:05:53 +00:00
|
|
|
for (i = 0; i < id_size; i++)
|
2004-08-03 00:41:47 +00:00
|
|
|
probe_id |= inb(base + i) << ((id_size - i - 1) * CHAR_BIT);
|
|
|
|
|
|
|
|
/* If we found a card, return its EISA id. */
|
|
|
|
if ((probe_id & 0x80000000) == 0) {
|
|
|
|
*eisa_id = probe_id;
|
2004-08-16 22:05:53 +00:00
|
|
|
return (0);
|
2004-08-03 00:41:47 +00:00
|
|
|
}
|
|
|
|
|
2004-08-16 22:05:53 +00:00
|
|
|
return (ENXIO);
|
2004-08-03 00:41:47 +00:00
|
|
|
}
|
|
|
|
|
1999-07-11 13:42:37 +00:00
|
|
|
static void
|
|
|
|
eisa_probe_nomatch(device_t dev, device_t child)
|
|
|
|
{
|
|
|
|
u_int32_t eisa_id = eisa_get_id(child);
|
|
|
|
u_int8_t slot = eisa_get_slot(child);
|
|
|
|
|
2005-08-01 07:09:15 +00:00
|
|
|
device_printf(dev, "%c%c%c%03x%01x (0x%08x) at slot %d (no driver attached)\n",
|
2005-03-17 17:33:52 +00:00
|
|
|
EISA_MFCTR_CHAR0(eisa_id), EISA_MFCTR_CHAR1(eisa_id),
|
|
|
|
EISA_MFCTR_CHAR2(eisa_id), EISA_PRODUCT_ID(eisa_id),
|
|
|
|
EISA_REVISION_ID(eisa_id), eisa_id, slot);
|
1999-07-11 13:42:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-07-29 01:03:04 +00:00
|
|
|
static int
|
1999-04-18 15:50:35 +00:00
|
|
|
eisa_print_child(device_t dev, device_t child)
|
|
|
|
{
|
1999-07-30 13:54:00 +00:00
|
|
|
struct eisa_device * e_dev = device_get_ivars(child);
|
|
|
|
int rid;
|
1999-08-02 20:01:40 +00:00
|
|
|
struct irq_node * irq;
|
1999-07-30 13:54:00 +00:00
|
|
|
struct resvaddr * resv;
|
|
|
|
int retval = 0;
|
|
|
|
|
2005-08-01 07:09:15 +00:00
|
|
|
retval += bus_print_child_header(dev, child);
|
1999-07-30 13:54:00 +00:00
|
|
|
rid = 0;
|
|
|
|
while ((resv = eisa_find_ioaddr(e_dev, rid++))) {
|
2005-03-17 17:33:52 +00:00
|
|
|
if (resv->size == 1 || (resv->flags & RESVADDR_BITMASK))
|
2005-08-01 07:09:15 +00:00
|
|
|
retval += printf("%s%lx", rid == 1 ? " port 0x" : ",0x",
|
|
|
|
resv->addr);
|
2005-03-17 17:33:52 +00:00
|
|
|
else
|
2005-08-01 07:09:15 +00:00
|
|
|
retval += printf("%s%lx-0x%lx", rid == 1 ? " port 0x" :
|
|
|
|
",0x", resv->addr, resv->addr + resv->size - 1);
|
1999-07-30 13:54:00 +00:00
|
|
|
}
|
|
|
|
rid = 0;
|
|
|
|
while ((resv = eisa_find_maddr(e_dev, rid++))) {
|
2005-03-17 17:33:52 +00:00
|
|
|
if (resv->size == 1 || (resv->flags & RESVADDR_BITMASK))
|
2005-08-01 07:09:15 +00:00
|
|
|
retval += printf("%s%lx", rid == 1 ? " mem 0x" : ",0x",
|
|
|
|
resv->addr);
|
2005-03-17 17:33:52 +00:00
|
|
|
else
|
2005-08-01 07:09:15 +00:00
|
|
|
retval += printf("%s%lx-0x%lx", rid == 1 ? " mem 0x" :
|
|
|
|
",0x", resv->addr, resv->addr + resv->size - 1);
|
1999-07-30 13:54:00 +00:00
|
|
|
}
|
|
|
|
rid = 0;
|
2005-08-01 07:09:15 +00:00
|
|
|
while ((irq = eisa_find_irq(e_dev, rid++)) != NULL)
|
|
|
|
retval += printf(" irq %d (%s)", irq->irq_no,
|
|
|
|
irq->irq_trigger ? "level" : "edge");
|
|
|
|
retval += printf(" at slot %d on %s\n", eisa_get_slot(child),
|
|
|
|
device_get_nameunit(dev));
|
1999-07-29 01:03:04 +00:00
|
|
|
|
|
|
|
return (retval);
|
1999-04-18 15:50:35 +00:00
|
|
|
}
|
1995-11-06 05:21:01 +00:00
|
|
|
|
1999-08-01 22:57:09 +00:00
|
|
|
static struct irq_node *
|
1999-04-18 15:50:35 +00:00
|
|
|
eisa_find_irq(struct eisa_device *e_dev, int rid)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct irq_node *irq;
|
1995-11-05 04:42:50 +00:00
|
|
|
|
1999-04-18 15:50:35 +00:00
|
|
|
for (i = 0, irq = TAILQ_FIRST(&e_dev->ioconf.irqs);
|
2005-03-17 17:33:52 +00:00
|
|
|
i < rid && irq != NULL; i++, irq = TAILQ_NEXT(irq, links))
|
|
|
|
continue;
|
1999-04-18 15:50:35 +00:00
|
|
|
|
2005-03-17 17:33:52 +00:00
|
|
|
return (irq);
|
1999-04-18 15:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct resvaddr *
|
|
|
|
eisa_find_maddr(struct eisa_device *e_dev, int rid)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct resvaddr *resv;
|
|
|
|
|
|
|
|
for (i = 0, resv = LIST_FIRST(&e_dev->ioconf.maddrs);
|
2005-03-17 17:33:52 +00:00
|
|
|
i < rid && resv != NULL; i++, resv = LIST_NEXT(resv, links))
|
|
|
|
continue;
|
1999-04-18 15:50:35 +00:00
|
|
|
|
2005-03-17 17:33:52 +00:00
|
|
|
return (resv);
|
1999-04-18 15:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct resvaddr *
|
|
|
|
eisa_find_ioaddr(struct eisa_device *e_dev, int rid)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct resvaddr *resv;
|
|
|
|
|
|
|
|
for (i = 0, resv = LIST_FIRST(&e_dev->ioconf.ioaddrs);
|
2005-03-17 17:33:52 +00:00
|
|
|
i < rid && resv != NULL; i++, resv = LIST_NEXT(resv, links))
|
|
|
|
continue;
|
1999-04-18 15:50:35 +00:00
|
|
|
|
2005-03-17 17:33:52 +00:00
|
|
|
return (resv);
|
1999-04-18 15:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-06-11 17:06:58 +00:00
|
|
|
eisa_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
|
1999-04-18 15:50:35 +00:00
|
|
|
{
|
|
|
|
struct eisa_device *e_dev = device_get_ivars(child);
|
1999-08-01 22:57:09 +00:00
|
|
|
struct irq_node *irq;
|
1999-04-18 15:50:35 +00:00
|
|
|
|
|
|
|
switch (which) {
|
|
|
|
case EISA_IVAR_SLOT:
|
|
|
|
*result = e_dev->ioconf.slot;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EISA_IVAR_ID:
|
|
|
|
*result = e_dev->id;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EISA_IVAR_IRQ:
|
|
|
|
/* XXX only first irq */
|
2005-03-17 17:33:52 +00:00
|
|
|
if ((irq = eisa_find_irq(e_dev, 0)) != NULL)
|
1999-08-01 22:57:09 +00:00
|
|
|
*result = irq->irq_no;
|
2005-03-17 17:33:52 +00:00
|
|
|
else
|
1999-08-01 22:57:09 +00:00
|
|
|
*result = -1;
|
1999-04-18 15:50:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return (ENOENT);
|
1995-11-05 04:42:50 +00:00
|
|
|
}
|
1995-11-09 07:14:11 +00:00
|
|
|
|
1999-04-18 15:50:35 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
eisa_write_ivar(device_t dev, device_t child, int which, uintptr_t value)
|
|
|
|
{
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct resource *
|
|
|
|
eisa_alloc_resource(device_t dev, device_t child, int type, int *rid,
|
2005-03-17 17:33:52 +00:00
|
|
|
u_long start, u_long end, u_long count, u_int flags)
|
1999-04-18 15:50:35 +00:00
|
|
|
{
|
|
|
|
int isdefault;
|
|
|
|
struct eisa_device *e_dev = device_get_ivars(child);
|
|
|
|
struct resource *rv, **rvp = 0;
|
|
|
|
|
2005-03-17 17:33:52 +00:00
|
|
|
isdefault = (device_get_parent(child) == dev &&
|
|
|
|
start == 0UL && end == ~0UL && count == 1);
|
1999-04-18 15:50:35 +00:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case SYS_RES_IRQ:
|
|
|
|
if (isdefault) {
|
1999-08-01 22:57:09 +00:00
|
|
|
struct irq_node * irq = eisa_find_irq(e_dev, *rid);
|
|
|
|
if (irq == NULL)
|
2005-03-17 17:33:52 +00:00
|
|
|
return (NULL);
|
1999-08-01 22:57:09 +00:00
|
|
|
start = end = irq->irq_no;
|
1999-04-18 15:50:35 +00:00
|
|
|
count = 1;
|
2005-03-17 17:33:52 +00:00
|
|
|
if (irq->irq_trigger == EISA_TRIGGER_LEVEL)
|
1999-08-01 22:57:09 +00:00
|
|
|
flags |= RF_SHAREABLE;
|
2005-03-17 17:33:52 +00:00
|
|
|
else
|
1999-08-01 22:57:09 +00:00
|
|
|
flags &= ~RF_SHAREABLE;
|
1999-04-18 15:50:35 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SYS_RES_MEMORY:
|
|
|
|
if (isdefault) {
|
|
|
|
struct resvaddr *resv;
|
|
|
|
|
|
|
|
resv = eisa_find_maddr(e_dev, *rid);
|
2005-03-17 17:33:52 +00:00
|
|
|
if (resv == NULL)
|
|
|
|
return (NULL);
|
1999-04-18 15:50:35 +00:00
|
|
|
|
|
|
|
start = resv->addr;
|
1999-05-24 03:08:46 +00:00
|
|
|
end = resv->addr + (resv->size - 1);
|
1999-04-18 15:50:35 +00:00
|
|
|
count = resv->size;
|
|
|
|
rvp = &resv->res;
|
1995-11-09 07:14:11 +00:00
|
|
|
}
|
1999-04-18 15:50:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SYS_RES_IOPORT:
|
|
|
|
if (isdefault) {
|
|
|
|
struct resvaddr *resv;
|
|
|
|
|
|
|
|
resv = eisa_find_ioaddr(e_dev, *rid);
|
2005-03-17 17:33:52 +00:00
|
|
|
if (resv == NULL)
|
|
|
|
return (NULL);
|
1999-04-18 15:50:35 +00:00
|
|
|
|
|
|
|
start = resv->addr;
|
1999-05-24 03:08:46 +00:00
|
|
|
end = resv->addr + (resv->size - 1);
|
1999-04-18 15:50:35 +00:00
|
|
|
count = resv->size;
|
|
|
|
rvp = &resv->res;
|
1995-11-09 07:14:11 +00:00
|
|
|
}
|
1999-04-18 15:50:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
1995-11-05 04:42:50 +00:00
|
|
|
}
|
1999-04-18 15:50:35 +00:00
|
|
|
|
|
|
|
rv = BUS_ALLOC_RESOURCE(device_get_parent(dev), child,
|
2005-03-17 17:33:52 +00:00
|
|
|
type, rid, start, end, count, flags);
|
1999-04-18 15:50:35 +00:00
|
|
|
if (rvp)
|
|
|
|
*rvp = rv;
|
|
|
|
|
2005-03-17 17:33:52 +00:00
|
|
|
return (rv);
|
1995-11-05 04:42:50 +00:00
|
|
|
}
|
|
|
|
|
1999-04-18 15:50:35 +00:00
|
|
|
static int
|
|
|
|
eisa_release_resource(device_t dev, device_t child, int type, int rid,
|
|
|
|
struct resource *r)
|
1995-11-05 04:42:50 +00:00
|
|
|
{
|
1999-04-18 15:50:35 +00:00
|
|
|
int rv;
|
|
|
|
struct eisa_device *e_dev = device_get_ivars(child);
|
|
|
|
struct resvaddr *resv = 0;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case SYS_RES_IRQ:
|
1999-08-01 22:57:09 +00:00
|
|
|
if (eisa_find_irq(e_dev, rid) == NULL)
|
2005-03-17 17:33:52 +00:00
|
|
|
return (EINVAL);
|
1999-04-18 15:50:35 +00:00
|
|
|
break;
|
1995-11-09 07:14:11 +00:00
|
|
|
|
1999-04-18 15:50:35 +00:00
|
|
|
case SYS_RES_MEMORY:
|
|
|
|
if (device_get_parent(child) == dev)
|
|
|
|
resv = eisa_find_maddr(e_dev, rid);
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case SYS_RES_IOPORT:
|
|
|
|
if (device_get_parent(child) == dev)
|
|
|
|
resv = eisa_find_ioaddr(e_dev, rid);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return (ENOENT);
|
1995-11-06 05:21:01 +00:00
|
|
|
}
|
1995-11-09 07:14:11 +00:00
|
|
|
|
1999-04-18 15:50:35 +00:00
|
|
|
rv = BUS_RELEASE_RESOURCE(device_get_parent(dev), child, type, rid, r);
|
|
|
|
|
|
|
|
if (rv == 0) {
|
2005-03-17 17:33:52 +00:00
|
|
|
if (resv != NULL)
|
1999-04-18 15:50:35 +00:00
|
|
|
resv->res = 0;
|
1995-11-05 04:42:50 +00:00
|
|
|
}
|
1999-04-18 15:50:35 +00:00
|
|
|
|
2005-03-17 17:33:52 +00:00
|
|
|
return (rv);
|
1995-11-05 04:42:50 +00:00
|
|
|
}
|
|
|
|
|
2004-06-09 16:08:20 +00:00
|
|
|
static int
|
|
|
|
eisa_add_intr_m(device_t eisa, device_t dev, int irq, int trigger)
|
1995-11-05 04:42:50 +00:00
|
|
|
{
|
1999-04-18 15:50:35 +00:00
|
|
|
struct eisa_device *e_dev = device_get_ivars(dev);
|
1999-08-01 22:57:09 +00:00
|
|
|
struct irq_node *irq_info;
|
1997-09-21 21:35:24 +00:00
|
|
|
|
|
|
|
irq_info = (struct irq_node *)malloc(sizeof(*irq_info), M_DEVBUF,
|
|
|
|
M_NOWAIT);
|
|
|
|
if (irq_info == NULL)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
irq_info->irq_no = irq;
|
1999-08-01 22:57:09 +00:00
|
|
|
irq_info->irq_trigger = trigger;
|
1997-09-21 21:35:24 +00:00
|
|
|
irq_info->idesc = NULL;
|
|
|
|
TAILQ_INSERT_TAIL(&e_dev->ioconf.irqs, irq_info, links);
|
2005-03-17 17:33:52 +00:00
|
|
|
return (0);
|
1995-11-05 04:42:50 +00:00
|
|
|
}
|
|
|
|
|
1996-01-29 03:13:23 +00:00
|
|
|
static int
|
1999-05-06 22:17:26 +00:00
|
|
|
eisa_add_resvaddr(struct eisa_device *e_dev, struct resvlist *head, u_long base,
|
|
|
|
u_long size, int flags)
|
1996-01-29 03:13:23 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2001-02-04 13:13:25 +00:00
|
|
|
if (!LIST_FIRST(head)) {
|
1996-01-29 03:13:23 +00:00
|
|
|
LIST_INSERT_HEAD(head, reservation, links);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
resvaddr_t *node;
|
2001-02-04 13:13:25 +00:00
|
|
|
LIST_FOREACH(node, head, links) {
|
1996-01-29 03:13:23 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2001-02-04 13:13:25 +00:00
|
|
|
if (!LIST_NEXT(node, links)) {
|
1996-01-29 03:13:23 +00:00
|
|
|
LIST_INSERT_AFTER(node, reservation, links);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2004-06-09 16:08:20 +00:00
|
|
|
static int
|
|
|
|
eisa_add_mspace_m(device_t eisa, device_t dev, u_long mbase, u_long msize,
|
|
|
|
int flags)
|
1995-11-05 04:42:50 +00:00
|
|
|
{
|
1999-04-18 15:50:35 +00:00
|
|
|
struct eisa_device *e_dev = device_get_ivars(dev);
|
1999-05-06 22:17:26 +00:00
|
|
|
|
2005-03-17 17:33:52 +00:00
|
|
|
return (eisa_add_resvaddr(e_dev, &(e_dev->ioconf.maddrs), mbase, msize,
|
|
|
|
flags));
|
1995-11-05 04:42:50 +00:00
|
|
|
}
|
|
|
|
|
2004-06-09 16:08:20 +00:00
|
|
|
static int
|
|
|
|
eisa_add_iospace_m(device_t eisa, device_t dev, u_long iobase, u_long iosize,
|
|
|
|
int flags)
|
1995-11-05 04:42:50 +00:00
|
|
|
{
|
1999-04-18 15:50:35 +00:00
|
|
|
struct eisa_device *e_dev = device_get_ivars(dev);
|
1999-05-06 22:17:26 +00:00
|
|
|
|
2005-03-17 17:33:52 +00:00
|
|
|
return (eisa_add_resvaddr(e_dev, &(e_dev->ioconf.ioaddrs), iobase,
|
|
|
|
iosize, flags));
|
1996-01-29 03:13:23 +00:00
|
|
|
}
|
|
|
|
|
1999-04-18 15:50:35 +00:00
|
|
|
static device_method_t eisa_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, eisa_probe),
|
|
|
|
DEVMETHOD(device_attach, bus_generic_attach),
|
|
|
|
DEVMETHOD(device_shutdown, bus_generic_shutdown),
|
1999-06-22 09:44:00 +00:00
|
|
|
DEVMETHOD(device_suspend, bus_generic_suspend),
|
|
|
|
DEVMETHOD(device_resume, bus_generic_resume),
|
1999-04-18 15:50:35 +00:00
|
|
|
|
|
|
|
/* Bus interface */
|
|
|
|
DEVMETHOD(bus_print_child, eisa_print_child),
|
1999-07-11 13:42:37 +00:00
|
|
|
DEVMETHOD(bus_probe_nomatch, eisa_probe_nomatch),
|
1999-04-18 15:50:35 +00:00
|
|
|
DEVMETHOD(bus_read_ivar, eisa_read_ivar),
|
|
|
|
DEVMETHOD(bus_write_ivar, eisa_write_ivar),
|
|
|
|
DEVMETHOD(bus_alloc_resource, eisa_alloc_resource),
|
|
|
|
DEVMETHOD(bus_release_resource, eisa_release_resource),
|
|
|
|
DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
|
|
|
|
DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
|
|
|
|
DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
|
|
|
|
DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
|
|
|
|
|
2004-06-09 16:08:20 +00:00
|
|
|
/* EISA interface */
|
|
|
|
DEVMETHOD(eisa_add_intr, eisa_add_intr_m),
|
|
|
|
DEVMETHOD(eisa_add_iospace, eisa_add_iospace_m),
|
|
|
|
DEVMETHOD(eisa_add_mspace, eisa_add_mspace_m),
|
|
|
|
|
2011-11-22 21:28:20 +00:00
|
|
|
DEVMETHOD_END
|
1999-04-18 15:50:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t eisa_driver = {
|
|
|
|
"eisa",
|
|
|
|
eisa_methods,
|
|
|
|
1, /* no softc */
|
|
|
|
};
|
|
|
|
|
2001-02-09 16:33:53 +00:00
|
|
|
DRIVER_MODULE(eisa, eisab, eisa_driver, eisa_devclass, 0, 0);
|
2002-09-26 18:40:06 +00:00
|
|
|
DRIVER_MODULE(eisa, legacy, eisa_driver, eisa_devclass, 0, 0);
|