From 88d723fb6176fbad31e4f4e199ce44b8008b2eac Mon Sep 17 00:00:00 2001 From: imp Date: Tue, 31 Jul 2001 06:12:01 +0000 Subject: Have pccardd always ask the kernel for the IRQ to use. The kernel will soon return the irq from the pcic bridge in cases where't that's appropriate. Note: I've had to disbale -I option for the moment. I've made it easy to reenable it for people that need it. MFC After: soon! --- usr.sbin/pccard/pccardd/cardd.c | 83 ++++++++++++++++++++++----------------- usr.sbin/pccard/pccardd/pccardd.c | 2 +- 2 files changed, 47 insertions(+), 38 deletions(-) (limited to 'usr.sbin/pccard/pccardd') diff --git a/usr.sbin/pccard/pccardd/cardd.c b/usr.sbin/pccard/pccardd/cardd.c index 10e3b2c..a5e5d75 100644 --- a/usr.sbin/pccard/pccardd/cardd.c +++ b/usr.sbin/pccard/pccardd/cardd.c @@ -41,7 +41,7 @@ static const char rcsid[] = #include #include "cardd.h" -static struct card_config *assign_driver(struct card *); +static struct card_config *assign_driver(struct slot *, struct card *); static int assign_io(struct slot *); static int setup_slot(struct slot *); static void card_inserted(struct slot *); @@ -361,7 +361,7 @@ escape: break; } } - if ((sp->config = assign_driver(cp)) == NULL) + if ((sp->config = assign_driver(sp, cp)) == NULL) return; if ((err = assign_io(sp))) { char *reason; @@ -474,10 +474,12 @@ read_ether_attr2(struct slot *sp) * First, see if an existing driver is already setup. */ static struct card_config * -assign_driver(struct card *cp) +assign_driver(struct slot *sp, struct card *cp) { struct driver *drvp; struct card_config *conf; + struct pccard_resource res; + int i; for (conf = cp->config; conf; conf = conf->next) if (conf->inuse == 0 && conf->driver->card == cp && @@ -515,35 +517,53 @@ assign_driver(struct card *cp) return (NULL); } /* Allocate a free IRQ if none has been specified */ + res.type = SYS_RES_IRQ; + res.size = 1; if (conf->irq == 0) { - struct pccard_resource res; - char name[128]; - int i, fd; - - sprintf(name, CARD_DEVICE, 0); /* XXX */ - fd = open(name, O_RDWR); - - res.type = SYS_RES_IRQ; - res.size = 1; for (i = 1; i < 16; i++) { + /* + * The foloowing code will properly implement sanpai's + * -I option. However, it will break everyone that + * I told to use this as a workaround for my pccard + * patches testing. + */ + if (!use_kern_irq && pool_irq[i]) { + conf->irq = i; + pool_irq[i] = 0; + break; + } res.min = i; res.max = i; - if (ioctl(fd, PIOCSRESOURCE, &res) < 0) { + if (ioctl(sp->fd, PIOCSRESOURCE, &res) < 0) { perror("ioctl (PIOCSRESOURCE)"); exit(1); } - if (pool_irq[i] - && (res.resource_addr == i || !use_kern_irq)) { - conf->irq = i; - pool_irq[i] = 0; - break; - } + if (res.resource_addr == ~0ul) + continue; + conf->irq = res.resource_addr; + pool_irq[conf->irq] = 0; + break; } - close(fd); if (conf->irq == 0) { logmsg("Failed to allocate IRQ for %s\n", cp->manuf); return (NULL); } + } else { + res.min = res.max = conf->irq; + if (ioctl(sp->fd, PIOCSRESOURCE, &res) < 0) { + perror("ioctl (PIOCSRESOURCE)"); + exit(1); + } + if (res.resource_addr == ~0ul) { + logmsg("Failed to verify IRQ for %s\n", cp->manuf); + return (NULL); + } + if (res.resource_addr != conf->irq) { + logmsg("Kernel changed irq from %d to %d for %s\n", + conf->irq, res.resource_addr, cp->manuf); + conf->irq = res.resource_addr; + } + } drvp->card = cp; drvp->config = conf; @@ -556,16 +576,12 @@ assign_driver(struct card *cp) * Auto select config index */ static struct cis_config * -assign_card_index(struct cis * cis) +assign_card_index(struct slot *sp, struct cis * cis) { struct cis_config *cp; struct cis_ioblk *cio; struct pccard_resource res; - char name[128]; - int i, fd; - - sprintf(name, CARD_DEVICE, 0); /* XXX */ - fd = open(name, O_RDWR); + int i; res.type = SYS_RES_IOPORT; for (cp = cis->conf; cp; cp = cp->next) { @@ -575,7 +591,7 @@ assign_card_index(struct cis * cis) res.size = cio->size; res.min = cio->addr; res.max = res.min + cio->size - 1; - if (ioctl(fd, PIOCSRESOURCE, &res) < 0) { + if (ioctl(sp->fd, PIOCSRESOURCE, &res) < 0) { perror("ioctl (PIOCSRESOURCE)"); exit(1); } @@ -585,11 +601,9 @@ assign_card_index(struct cis * cis) if (!bit_test(io_avail, i)) goto next; } - close(fd); return cp; /* found */ next: } - close(fd); return cis->def_config; } @@ -611,7 +625,7 @@ assign_io(struct slot *sp) sp->config->index = cisconf->id; break; case AUTO_INDEX: /* auto */ - cisconf = assign_card_index(cis); + cisconf = assign_card_index(sp, cis); sp->config->index = cisconf->id; break; default: /* normal, use index value */ @@ -739,12 +753,8 @@ memskip: } if (sio->addr == 0) { struct pccard_resource res; - char name[128]; - int i, j, fd; + int i, j; - sprintf(name, CARD_DEVICE, 0); /* XXX */ - fd = open(name, O_RDWR); - res.type = SYS_RES_IOPORT; res.size = sio->size; @@ -753,7 +763,7 @@ memskip: sio->size, sio->size); res.min = j; res.max = j + sio->size - 1; - if (ioctl(fd, PIOCSRESOURCE, &res) < 0) { + if (ioctl(sp->fd, PIOCSRESOURCE, &res) < 0) { perror("ioctl (PIOCSRESOURCE)"); exit(1); } @@ -765,7 +775,6 @@ memskip: } else { sio->addr = j; } - close(fd); } bit_nclear(io_avail, sio->addr, sio->addr + sio->size - 1); diff --git a/usr.sbin/pccard/pccardd/pccardd.c b/usr.sbin/pccard/pccardd/pccardd.c index ba70336..4bca2c4 100644 --- a/usr.sbin/pccard/pccardd/pccardd.c +++ b/usr.sbin/pccard/pccardd/pccardd.c @@ -171,7 +171,7 @@ main(int argc, char *argv[]) while ((count = getopt(argc, argv, COM_OPTS)) != -1) { switch (count) { case 'I': - use_kern_irq = 0; + /* use_kern_irq = 0; */ break; case 'd': setbuf(stdout, 0); -- cgit v1.1