diff --git a/usr.sbin/pccard/pccardd/cardd.c b/usr.sbin/pccard/pccardd/cardd.c index 6514c8a1c81b..5d4f4e390dfc 100644 --- a/usr.sbin/pccard/pccardd/cardd.c +++ b/usr.sbin/pccard/pccardd/cardd.c @@ -491,7 +491,7 @@ assign_driver(struct card *cp) char name[128]; int i, fd; - sprintf(name, CARD_DEVICE, 0); /* XXX sanpei */ + sprintf(name, CARD_DEVICE, 0); /* XXX */ fd = open(name, O_RDWR); resource.type = SYS_RES_IRQ; @@ -534,7 +534,7 @@ assign_card_index(struct cis * cis) char name[128]; int i, fd; - sprintf(name, CARD_DEVICE, 0); /* XXX sanpei */ + sprintf(name, CARD_DEVICE, 0); /* XXX */ fd = open(name, O_RDWR); resource.type = SYS_RES_IOPORT; @@ -683,12 +683,34 @@ assign_io(struct slot *sp) sio->size = 1 << cp->io_addr; } if (sio->addr == 0) { - int i = bit_fns(io_avail, IOPORTS, - sio->size, sio->size); - if (i < 0) { - return (-1); + struct pccard_resource res; + char name[128]; + int i, j, fd; + + sprintf(name, CARD_DEVICE, 0); /* XXX */ + fd = open(name, O_RDWR); + + res.type = SYS_RES_IOPORT; + res.size = sio->size; + + for (i = 0; i < IOPORTS; i++) { + j = bit_fns(io_avail, IOPORTS, i, + sio->size, sio->size); + res.min = j; + res.max = j + sio->size ; + if (ioctl(fd, PIOCSRESOURCE, &res) < 0) { + perror("ioctl (PIOCSRESOURCE)"); + exit(1); + } + if (res.resource_addr == j) + break; } - sio->addr = i; + if (j < 0) { + return (-1); + } else { + sio->addr = j; + } + close(fd); } bit_nclear(io_avail, sio->addr, sio->addr + sio->size - 1); diff --git a/usr.sbin/pccard/pccardd/cardd.h b/usr.sbin/pccard/pccardd/cardd.h index 726a82b9e5b6..f225d4f16420 100644 --- a/usr.sbin/pccard/pccardd/cardd.h +++ b/usr.sbin/pccard/pccardd/cardd.h @@ -163,7 +163,7 @@ void slot_change(struct slot *); /* util.c functions */ unsigned long alloc_memory(int); -int bit_fns(bitstr_t *, int, int, int); +int bit_fns(bitstr_t *, int, int, int, int); void die(char *); void execute(struct cmd *, struct slot *); void logmsg(const char *, ...); diff --git a/usr.sbin/pccard/pccardd/util.c b/usr.sbin/pccard/pccardd/util.c index aa443641b0e4..951d66a48a98 100644 --- a/usr.sbin/pccard/pccardd/util.c +++ b/usr.sbin/pccard/pccardd/util.c @@ -150,12 +150,12 @@ newstr(char *p) * least count number. */ int -bit_fns(bitstr_t *nm, int nbits, int count, int step) +bit_fns(bitstr_t *nm, int nbits, int min, int count, int step) { int i, j; int found = 0; - for (i = 0; i < nbits; i += step) + for (i = min; i < nbits; i += step) for (j = i, found = 0; j < nbits; j++) if (bit_test(nm, j)) { if (++found == count) @@ -173,7 +173,7 @@ alloc_memory(int size) { int i; - i = bit_fns(mem_avail, MEMBLKS, size / MEMUNIT + (size % MEMUNIT != 0), 1); + i = bit_fns(mem_avail, MEMBLKS, 0, size / MEMUNIT + (size % MEMUNIT != 0), 1); if (i < 0) return (0); bit_nclear(mem_avail, i, i + size / MEMUNIT + (size % MEMUNIT != 0) - 1);