Index: sys/pccard/cardinfo.h =================================================================== RCS file: /home/ncvs/src/sys/pccard/cardinfo.h,v retrieving revision 1.16 diff -u -u -r1.16 cardinfo.h --- sys/pccard/cardinfo.h 2000/01/16 06:44:44 1.16 +++ sys/pccard/cardinfo.h 2000/10/02 05:29:45 @@ -28,7 +28,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* $FreeBSD: src/sys/pccard/cardinfo.h,v 1.16 2000/01/16 06:44:44 hosokawa Exp $ */ +/* $FreeBSD: src/sys/pccard/cardinfo.h,v 1.16.2.1 2000/08/26 15:49:48 ume Exp $ */ #ifndef _PCCARD_CARDINFO_H_ #define _PCCARD_CARDINFO_H_ @@ -49,6 +49,7 @@ #define PIOCSPOW _IOW('P', 9, struct power) /* Set power structure */ #define PIOCSVIR _IOW('P', 10, int) /* Virtual insert/remove */ #define PIOCSBEEP _IOW('P', 11, int) /* Select Beep */ +#define PIOCSRESOURCE _IOWR('P', 12, struct pccard_resource) /* get resource info */ /* * Debug codes. */ @@ -58,7 +59,7 @@ /* * Slot states for PIOCGSTATE */ -enum cardstate { noslot, empty, suspend, filled }; +enum cardstate { noslot, empty, suspend, filled, inactive }; /* * Descriptor structure for memory map. @@ -135,6 +136,18 @@ int vcc; int vpp; }; + +/* + * Th PC-Card resource IOC_GET_RESOURCE_RANGE + */ +struct pccard_resource { + int type; + u_long size; + u_long min; + u_long max; + u_long resource_addr; +}; + /* * Other system limits Index: sys/pccard/pccard.c =================================================================== RCS file: /home/ncvs/src/sys/pccard/pccard.c,v retrieving revision 1.106.2.1 diff -u -u -r1.106.2.1 pccard.c --- sys/pccard/pccard.c 2000/05/23 03:56:58 1.106.2.1 +++ sys/pccard/pccard.c 2000/10/02 05:29:46 @@ -28,7 +28,7 @@ * (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: src/sys/pccard/pccard.c,v 1.106.2.1 2000/05/23 03:56:58 imp Exp $ + * $FreeBSD: src/sys/pccard/pccard.c,v 1.106.2.2 2000/08/26 15:49:48 ume Exp $ */ #include "opt_pcic.h" @@ -318,7 +318,7 @@ * The slot and devices are disabled, but the * data structures are not unlinked. */ - if (slt->state == filled) { + if (slt->state == filled || slt->state == inactive) { slt->state = empty; disable_slot_to(slt); } @@ -460,7 +460,12 @@ struct slot *slt = pccard_slots[minor(dev)]; struct mem_desc *mp; struct io_desc *ip; + struct pccard_resource *pr; + struct resource *r; + device_t pcicdev; int s, err; + int rid = 1; + int i; int pwval; if (slt == 0 && cmd != PIOCRWMEM) @@ -597,15 +602,48 @@ if (!pwval) { if (slt->state != filled) return EINVAL; + pccard_event(slt, card_removed); + slt->state = inactive; } else { - if (slt->state != empty) + if (slt->state != empty && slt->state != inactive) return EINVAL; + pccard_event(slt, card_inserted); } - pccard_event(slt, pwval == 0 ? card_removed : card_inserted); break; case PIOCSBEEP: if (pccard_beep_select(*(int *)data)) { return EINVAL; + } + break; + case PIOCSRESOURCE: + pr = (struct pccard_resource *)data; + pr->resource_addr = ~0ul; + /* + * pccard_devclass does not have soft_c + * so we use pcic_devclass + */ + pcicdev = devclass_get_device(pcic_devclass, 0); + switch(pr->type) { + default: + return EINVAL; + case SYS_RES_IOPORT: + case SYS_RES_MEMORY: + case SYS_RES_IRQ: + for (i = pr->min; i + pr->size - 1 <= pr->max; i++) { + /* already allocated to pcic? */ + if (bus_get_resource_start(pcicdev, pr->type, 0) == i) + continue; + err = bus_set_resource(pcicdev, pr->type, rid, i, pr->size); + if (!err) { + r = bus_alloc_resource(pcicdev, pr->type, &rid, 0ul, ~0ul, pr->size, 0); + if (r) { + pr->resource_addr = (u_long)rman_get_start(r); + bus_release_resource(pcicdev, pr->type, rid, r); + break; + } + } + } + break; } break; } Index: sys/pccard/pcic.h =================================================================== RCS file: /home/ncvs/src/sys/pccard/pcic.h,v retrieving revision 1.5.2.1 diff -u -u -r1.5.2.1 pcic.h --- sys/pccard/pcic.h 2000/05/23 03:56:59 1.5.2.1 +++ sys/pccard/pcic.h 2000/10/02 05:29:46 @@ -27,7 +27,7 @@ * (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: src/sys/pccard/pcic.h,v 1.5.2.1 2000/05/23 03:56:59 imp Exp $ + * $FreeBSD: src/sys/pccard/pcic.h,v 1.5.2.2 2000/08/03 01:08:04 peter Exp $ */ #define PCIC_RF_IODF_WS (0x01 << 16) @@ -41,3 +41,4 @@ #define PCIC_RF_MDF_WS1 (0x08 << 16) #define PCIC_RF_MDF_ATTR (0x10 << 16) #define PCIC_RF_MDF_WP (0x20 << 16) +extern devclass_t pcic_devclass; Index: usr.sbin/pccard/pccardd/Makefile =================================================================== RCS file: /home/ncvs/src/usr.sbin/pccard/pccardd/Makefile,v retrieving revision 1.4 retrieving revision 1.4.6.1 diff -u -u -r1.4 -r1.4.6.1 --- usr.sbin/pccard/pccardd/Makefile 1998/02/27 08:19:23 1.4 +++ usr.sbin/pccard/pccardd/Makefile 2000/08/26 15:49:48 1.4.6.1 @@ -1,7 +1,8 @@ # Makefile for pccardd +# $FreeBSD: src/usr.sbin/pccard/pccardd/Makefile,v 1.4.6.1 2000/08/26 15:49:48 ume Exp $ PROG= pccardd -SRCS= pccardd.c cardd.c file.c util.c readcis.c printcis.c +SRCS= pccardd.c cardd.c file.c util.c readcis.c printcis.c server.c MAN8= pccardd.8 MAN5= pccard.conf.5 DPADD= ${LIBUTIL} Index: usr.sbin/pccard/pccardd/cardd.c =================================================================== RCS file: /home/ncvs/src/usr.sbin/pccard/pccardd/cardd.c,v retrieving revision 1.46.2.4 diff -u -u -r1.46.2.4 cardd.c --- usr.sbin/pccard/pccardd/cardd.c 2000/07/18 04:59:39 1.46.2.4 +++ usr.sbin/pccard/pccardd/cardd.c 2000/10/02 05:29:54 @@ -26,7 +26,7 @@ #ifndef lint static const char rcsid[] = - "$FreeBSD: src/usr.sbin/pccard/pccardd/cardd.c,v 1.46.2.4 2000/07/18 04:59:39 imp Exp $"; + "$FreeBSD: src/usr.sbin/pccard/pccardd/cardd.c,v 1.46.2.6 2000/09/17 15:17:07 sanpei Exp $"; #endif /* not lint */ #include @@ -37,6 +37,7 @@ #include #include #include +#include #include #include "cardd.h" @@ -49,6 +50,8 @@ static void read_ether(struct slot *); static void read_ether_attr2(struct slot *sp); +struct slot *slots; + /* * Dump configuration file data. */ @@ -105,7 +108,7 @@ { char name[128]; int i, fd; - struct slot *slots, *sp; + struct slot *sp; slots = NULL; for (i = 0; i < MAXSLOT; i++) { @@ -158,6 +161,7 @@ } switch (state.state) { case empty: + case inactive: case noslot: /* Debounce potentially incorrectly reported removals */ if (state.laststate == filled || state.laststate == suspend) @@ -173,6 +177,8 @@ /* ignored */ break; } + sp->state = state.state; + stat_changed(sp); } /* @@ -481,13 +487,29 @@ } /* Allocate a free IRQ if none has been specified */ if (conf->irq == 0) { - int i; - for (i = 1; i < 16; i++) - if (pool_irq[i]) { + struct pccard_resource resource; + char name[128]; + int i, fd; + + sprintf(name, CARD_DEVICE, 0); /* XXX */ + fd = open(name, O_RDWR); + + resource.type = SYS_RES_IRQ; + resource.size = 1; + for (i = 1; i < 16; i++) { + resource.min = i; + resource.max = i; + if (ioctl(fd, PIOCSRESOURCE, &resource) < 0) { + perror("ioctl (PIOCSRESOURCE)"); + exit(1); + } + if (pool_irq[i] && resource.resource_addr == i) { conf->irq = i; pool_irq[i] = 0; break; } + } + close(fd); if (conf->irq == 0) { logmsg("Failed to allocate IRQ for %s\n", cp->manuf); return (NULL); @@ -508,19 +530,36 @@ { struct cis_config *cp; struct cis_ioblk *cio; - int i; + struct pccard_resource resource; + char name[128]; + int i, fd; + sprintf(name, CARD_DEVICE, 0); /* XXX */ + fd = open(name, O_RDWR); + + resource.type = SYS_RES_IOPORT; for (cp = cis->conf; cp; cp = cp->next) { if (!cp->iospace || !cp->io) continue; for (cio = cp->io; cio; cio = cio->next) { + resource.size = cio->size; + resource.min = cio->addr; + resource.max = resource.min + cio->size - 1; + if (ioctl(fd, PIOCSRESOURCE, &resource) < 0) { + perror("ioctl (PIOCSRESOURCE)"); + exit(1); + } + if (resource.resource_addr != cio->addr) + goto next; for (i = cio->addr; i < cio->addr + cio->size - 1; i++) if (!bit_test(io_avail, i)) goto next; } + close(fd); return cp; /* found */ next: } + close(fd); return cis->def_config; } @@ -627,7 +666,7 @@ cio = cp->io; sio = &(sp->io); xmax = 1; - if (cio) + if (iosize == 0 && cio) xmax = cisconf->io_blks; for (x = 0; x < xmax; x++) { if (iosize) { @@ -644,12 +683,34 @@ sio->size = 1 << cp->io_addr; } if (sio->addr == 0) { - int i = bit_fns(io_avail, IOPORTS, - sio->size, sio->size); - if (i < 0) { + 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 - 1; + if (ioctl(fd, PIOCSRESOURCE, &res) < 0) { + perror("ioctl (PIOCSRESOURCE)"); + exit(1); + } + if (res.resource_addr == j) + break; + } + if (j < 0) { return (-1); + } else { + sio->addr = j; } - sio->addr = i; + close(fd); } bit_nclear(io_avail, sio->addr, sio->addr + sio->size - 1); Index: usr.sbin/pccard/pccardd/cardd.h =================================================================== RCS file: /home/ncvs/src/usr.sbin/pccard/pccardd/cardd.h,v retrieving revision 1.18.2.3 diff -u -u -r1.18.2.3 cardd.h --- usr.sbin/pccard/pccardd/cardd.h 2000/07/18 04:59:39 1.18.2.3 +++ usr.sbin/pccard/pccardd/cardd.h 2000/10/02 05:29:54 @@ -23,7 +23,7 @@ * (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: src/usr.sbin/pccard/pccardd/cardd.h,v 1.18.2.3 2000/07/18 04:59:39 imp Exp $ + * $FreeBSD: src/usr.sbin/pccard/pccardd/cardd.h,v 1.18.2.4 2000/08/26 15:49:48 ume Exp $ * * Common include file for PCMCIA daemon */ @@ -139,6 +139,9 @@ #define AFLAGS (IO_ASSIGNED | MEM_ASSIGNED | IRQ_ASSIGNED) #define CFLAGS (EADDR_CONFIGED | WL_CONFIGED) +EXTERN struct slot *slots, *current_slot; +EXTERN int slen; + EXTERN struct allocblk *pool_ioblks; /* I/O blocks in the pool */ EXTERN struct allocblk *pool_mem; /* Memory in the pool */ EXTERN int pool_irq[16]; /* IRQ allocations */ @@ -160,7 +163,7 @@ /* 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 *, ...); @@ -170,8 +173,13 @@ void reset_slot(struct slot *); void *xmalloc(int); -/* file.c */ +/* file.c functions */ void readfile(char *); + +/* server.c functions */ +void set_socket(int); +void stat_changed(struct slot *); +void process_client(void); #define IOPORTS 0x400 #define MEMUNIT 0x1000 Index: usr.sbin/pccard/pccardd/file.c =================================================================== RCS file: /home/ncvs/src/usr.sbin/pccard/pccardd/file.c,v retrieving revision 1.24.2.4 diff -u -u -r1.24.2.4 file.c --- usr.sbin/pccard/pccardd/file.c 2000/07/18 04:59:39 1.24.2.4 +++ usr.sbin/pccard/pccardd/file.c 2000/10/02 05:29:56 @@ -64,6 +64,7 @@ "include", /* 14 */ "function", /* 15 */ "logstr", /* 16 */ + "ignirq", /* 17 */ 0 }; @@ -83,6 +84,7 @@ #define KWD_INCLUDE 14 #define KWD_FUNCTION 15 #define KWD_LOGSTR 16 +#define KWD_IGNIRQ 17 /* for keyword compatibility with PAO/plain FreeBSD */ static struct { @@ -342,6 +344,12 @@ bzero(pool_irq, sizeof(pool_irq)); while ((i = irq_tok(0)) > 0) pool_irq[i] = 1; + pusht = 1; + break; + case KWD_IGNIRQ: + /* ignored irqs */ + while ((i = irq_tok(0)) > 0) + pool_irq[i] = 0; pusht = 1; break; case KWD_MEMORY: Index: usr.sbin/pccard/pccardd/pccard.conf.5 =================================================================== RCS file: /home/ncvs/src/usr.sbin/pccard/pccardd/pccard.conf.5,v retrieving revision 1.12.2.4 diff -u -u -r1.12.2.4 pccard.conf.5 --- usr.sbin/pccard/pccardd/pccard.conf.5 2000/07/18 18:29:27 1.12.2.4 +++ usr.sbin/pccard/pccardd/pccard.conf.5 2000/10/02 05:29:56 @@ -23,7 +23,7 @@ .\" (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: src/usr.sbin/pccard/pccardd/pccard.conf.5,v 1.12.2.4 2000/07/18 18:29:27 imp Exp $ +.\" $FreeBSD: src/usr.sbin/pccard/pccardd/pccard.conf.5,v 1.12.2.5 2000/09/15 19:19:28 iwasaki Exp $ .\" .Dd November 2, 1994 .Dt PCCARD.CONF 5 @@ -61,7 +61,7 @@ which contains the default resource pool settings and pccard identifiers database. The user specific configuration can be specified in -.Pa /etc/rc.conf +.Pa /etc/pccard.conf when the user wishes to override these defaults and/or add additional entries. .Pp @@ -133,11 +133,17 @@ .Dl io Ar start - end ... .Dl memory Ar address size ... .Dl irq Ar irq-number ... +.Dl ignirq Ar irq-number ... .Pp Each of the statements define I/O, memory or IRQ blocks that can be used to allocate to drivers when they are initialized. .Pp +"ignirq" prohibits +.Xr pccardd 8 +to use +.Ar irq-number . +.Pp The syntax of the debuglevel parameter: .Pp .Dl debuglevel Ar level @@ -266,7 +272,8 @@ # Pool parameters. # io 0x280 - 0x2F0 0x300 - 0x360 -irq 5 6 8 9 10 15 +#irq 5 6 8 9 10 15 +ignirq 3 11 memory 0xd4000 96k memory 0xc4000 32k # Index: usr.sbin/pccard/pccardd/pccardd.c =================================================================== RCS file: /home/ncvs/src/usr.sbin/pccard/pccardd/pccardd.c,v retrieving revision 1.6.2.2 diff -u -u -r1.6.2.2 pccardd.c --- usr.sbin/pccard/pccardd/pccardd.c 2000/06/29 08:23:26 1.6.2.2 +++ usr.sbin/pccard/pccardd/pccardd.c 2000/10/02 05:29:57 @@ -26,7 +26,7 @@ #ifndef lint static const char rcsid[] = - "$FreeBSD: src/usr.sbin/pccard/pccardd/pccardd.c,v 1.6.2.2 2000/06/29 08:23:26 roberto Exp $"; + "$FreeBSD: src/usr.sbin/pccard/pccardd/pccardd.c,v 1.6.2.3 2000/08/26 15:49:48 ume Exp $"; #endif /* not lint */ #include @@ -35,12 +35,22 @@ #include #include #include +#include +#include +#include #define EXTERN #include "cardd.h" char *config_file = "/etc/defaults/pccard.conf"; static char *pid_file = "/var/run/pccardd.pid"; +/* + * pathname of UNIX-domain socket + */ +static char *socket_name = "/var/tmp/.pccardd"; +static char *sock = 0; +static int server_sock; + /* SIGHUP signal handler */ static void restart(void) @@ -49,6 +59,7 @@ bitstr_t bit_decl(mem_inuse, MEMBLKS); int irq_inuse[16]; int i; + struct sockaddr_un sun; bit_nclear(io_inuse, 0, IOPORTS-1); bit_nclear(mem_inuse, 0, MEMBLKS-1); @@ -98,6 +109,22 @@ pool_irq[i] = 0; } } + close(server_sock); + if ((server_sock = socket(PF_LOCAL, SOCK_DGRAM, 0)) < 0) + die("socket failed"); + bzero(&sun, sizeof(sun)); + sun.sun_family = AF_UNIX; + if (sock) { + socket_name = sock; + } + strcpy(sun.sun_path, socket_name); + slen = SUN_LEN(&sun); + (void)unlink(socket_name); + if (bind(server_sock, (struct sockaddr *) & sun, slen) < 0) + die("bind failed"); + chown(socket_name, 0, 5); /* XXX - root.operator */ + chmod(socket_name, 0660); + set_socket(server_sock); } /* SIGTERM/SIGINT signal handler */ @@ -127,18 +154,20 @@ int main(int argc, char *argv[]) { - struct slot *slots, *sp; + struct slot *sp; int count, dodebug = 0; int delay = 0; int irq_arg[16]; int irq_specified = 0; int i; + struct sockaddr_un sun; +#define COM_OPTS ":dvf:s:i:z" bzero(irq_arg, sizeof(irq_arg)); debug_level = 0; pccard_init_sleep = 5000000; cards = last_card = 0; - while ((count = getopt(argc, argv, ":dvf:i:z")) != -1) { + while ((count = getopt(argc, argv, COM_OPTS)) != -1) { switch (count) { case 'd': setbuf(stdout, 0); @@ -160,6 +189,9 @@ irq_arg[i] = 1; irq_specified = 1; break; + case 's': + sock = optarg; + break; case 'z': delay = 1; break; @@ -180,6 +212,17 @@ /* Mem allocation done in MEMUNIT units. */ mem_avail = bit_alloc(MEMBLKS); mem_init = bit_alloc(MEMBLKS); + + /* + * initially all irqs are unused, + * and then set used irq by ignirq in readfile, + * or set free irqs by irq in readfile + * or set free irqs by -i option. + * And also check free irq by PIOCSRESOURCE ioctl. + */ + for (i = 1; i < 16; i++) + pool_irq[i] = 1; + readfile(config_file); if (irq_specified) { bcopy(irq_arg, pool_irq, sizeof(irq_arg)); @@ -200,23 +243,44 @@ logmsg("pccardd started", NULL); write_pid(); + if ((server_sock = socket(PF_LOCAL, SOCK_DGRAM, 0)) < 0) + die("socket failed"); + bzero(&sun, sizeof(sun)); + sun.sun_family = AF_UNIX; + if (sock) { + socket_name = sock; + } + strcpy(sun.sun_path, socket_name); + slen = SUN_LEN(&sun); + (void)unlink(socket_name); + if (bind(server_sock, (struct sockaddr *) & sun, slen) < 0) + die("bind failed"); + chown(socket_name, 0, 5); /* XXX - root.operator */ + chmod(socket_name, 0660); + set_socket(server_sock); + (void)signal(SIGINT, dodebug ? term : SIG_IGN); (void)signal(SIGTERM, term); (void)signal(SIGHUP, (void (*)(int))restart); for (;;) { - fd_set mask; - FD_ZERO(&mask); + fd_set rmask, emask; + FD_ZERO(&emask); + FD_ZERO(&rmask); for (sp = slots; sp; sp = sp->next) - FD_SET(sp->fd, &mask); - count = select(32, 0, 0, &mask, 0); + FD_SET(sp->fd, &emask); + FD_SET(server_sock, &rmask); + count = select(32, &rmask, 0, &emask, 0); if (count == -1) { logerr("select"); continue; } - if (count) + if (count) { for (sp = slots; sp; sp = sp->next) - if (FD_ISSET(sp->fd, &mask)) + if (FD_ISSET(sp->fd, &emask)) slot_change(sp); + if (FD_ISSET(server_sock, &rmask)) + process_client(); + } } } Index: usr.sbin/pccard/pccardd/server.c =================================================================== RCS file: server.c diff -N server.c --- /dev/null Sun Oct 1 22:26:12 2000 +++ /tmp/cvsBDunO74842 Sun Oct 1 22:29:57 2000 @@ -0,0 +1,187 @@ +/* + * pccardd UNIX-domain socket interface + * Copyright (C) 1996 by Tatsumi Hosokawa + * + * $Id: server.c,v 1.3 1999/02/07 08:02:44 kuriyama Exp $ + */ + +#ifndef lint +static const char rcsid[] = + "$FreeBSD: src/usr.sbin/pccard/pccardd/server.c,v 1.2.2.1 2000/08/26 15:49:48 ume Exp $"; +#endif /* not lint */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "cardd.h" + +static void +cardnum(char *buf) +{ + int i = 0; + struct slot *sp; + + for (sp = slots; sp; sp = sp->next) + i++; + if (i > MAXSLOT) + i = MAXSLOT; + sprintf(buf, "%2d", i); +} + +static struct slot * +find_slot(int slot) +{ + struct slot *sp; + + /* Search the list until we find the slot or get to the end */ + for (sp = slots; sp && sp->slot != slot; sp = sp->next) + continue; + + return ( sp ); +} + +static void +cardname(char *buf, int slot) +{ + struct slot *sp; + char *manuf, *vers, *drv, *stat; + + /* Look for the slot */ + if ( (sp = find_slot(slot)) == NULL) + return; + + /* Fill in the information in the buff */ + if (sp->cis) { + + manuf = sp->cis->manuf; + vers = sp->cis->vers; + if (sp->config && sp->config->driver && + sp->config->driver->name) + drv = sp->config->driver->name; + else + drv = ""; + } else + manuf = vers = drv = ""; + + switch (sp->state) { + case empty: + stat = "0"; + break; + case filled: + stat = "1"; + break; + case inactive: + stat = "2"; + break; + default: + stat = "9"; + } + sprintf(buf, "%d~%s~%s~%s~%s", slot, manuf, vers, drv, stat); +} + +static void +cardpwr(int slot, int pwon) +{ + struct slot *sp; + + /* Look for the slot */ + if ( (sp = find_slot(slot)) == NULL) + return; + + if (ioctl(sp->fd, PIOCSVIR, &pwon) < 0) + logerr("invaild arguments for cardpwr"); +} + +static int sock = 0; +static int slen = 0; +static struct sockaddr_un sun; + +void +set_socket(int s) +{ + sock = s; +} + +void +stat_changed(struct slot *sp) +{ + int len; + char buf[512]; + + if (!slen) + return; + + cardname(buf, sp->slot); + len = strlen(buf); + if (sendto(sock, buf, len, 0, (struct sockaddr *) & sun, slen) != len) { + logerr("sendto failed"); + slen = 0; + } +} + +void +process_client(void) +{ + char buf[512], obuf[512]; + int len; + int snum; + + if (!sock) + return; + slen = sizeof(sun); + len = recvfrom(sock, buf, sizeof(buf), + 0, (struct sockaddr *)&sun, &slen); + if (len < 0) + logerr("recvfrom failed"); + buf[len] = '\0'; + obuf[0] = '\0'; + switch (buf[0]) { /* Protocol implementation */ + case 'S': /* How many slots? */ + cardnum(obuf); + break; + case 'N': /* Card name request */ + sscanf(buf + 1, "%d", &snum); + if (snum >= 0 && snum <= MAXSLOT) + cardname(obuf, snum); + else + logerr("Illegal slot requests for N command"); + break; + case 'P': /* Virtual insertion request */ + sscanf(buf + 1, "%d", &snum); + if (snum >= 0 && snum <= MAXSLOT) { + logmsg("slot %d: spring has come", snum); + cardpwr(snum, 1); + } else + logerr("Illegal slot requests for P command"); + break; + case 'Q': /* Virtual removal request */ + sscanf(buf + 1, "%d", &snum); + if (snum >= 0 && snum <= MAXSLOT) { + logmsg("slot %d: hibernation", snum); + cardpwr(snum, 0); + } else + logerr("Illegal slot requests for Q command"); + break; + default: + logerr("Unknown control message from socket"); + break; + } + len = strlen(obuf); + if (len) { + if (sendto(sock, obuf, len, 0, (struct sockaddr *)&sun, slen) + != len) { + logerr("sendto failed"); + slen = 0; + } + } else if (sendto(sock, 0, 0, 0, (struct sockaddr *)&sun, slen) + != len) { + logerr("sendto failed"); + slen = 0; + } +} Index: usr.sbin/pccard/pccardd/util.c =================================================================== RCS file: /home/ncvs/src/usr.sbin/pccard/pccardd/util.c,v retrieving revision 1.13.2.2 diff -u -u -r1.13.2.2 util.c --- usr.sbin/pccard/pccardd/util.c 2000/07/18 18:29:27 1.13.2.2 +++ usr.sbin/pccard/pccardd/util.c 2000/10/02 05:29:57 @@ -150,12 +150,12 @@ * 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 @@ { 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);