diff --git a/usr.sbin/pccard/pccardc/dumpcis.c b/usr.sbin/pccard/pccardc/dumpcis.c index eacf73a1d80c..51ce026a18cc 100644 --- a/usr.sbin/pccard/pccardc/dumpcis.c +++ b/usr.sbin/pccard/pccardc/dumpcis.c @@ -1,6 +1,10 @@ +/* + * $Id$ + */ #include #include #include +#include #include #include @@ -10,19 +14,11 @@ int nocards; -int -dumpcis_main(int argc, char **argv) -{ -int node; - - for (node = 0; node < 8; node++) - scan(node); - printf("%d slots found\n", nocards); -} +void scan(slot) int slot; { -int fd, i; +int fd; char name[64]; struct cis *cp; struct slotstate st; @@ -45,6 +41,8 @@ struct slotstate st; } } } + +void dump(p, sz) unsigned char *p; int sz; @@ -77,3 +75,14 @@ void *p; } return(p); } + +int +dumpcis_main(int argc, char **argv) +{ +int node; + + for (node = 0; node < 8; node++) + scan(node); + printf("%d slots found\n", nocards); + return 0; +} diff --git a/usr.sbin/pccard/pccardc/enabler.c b/usr.sbin/pccard/pccardc/enabler.c index c96b853d76a1..56f17302b80b 100644 --- a/usr.sbin/pccard/pccardc/enabler.c +++ b/usr.sbin/pccard/pccardc/enabler.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -22,7 +23,7 @@ char *argv[]; struct drv_desc drv; struct mem_desc mem; struct io_desc io; -int fd, err, slot, i, card_addr; +int fd, slot, i, card_addr; char name[32]; char *p; @@ -50,7 +51,7 @@ char *p; usage("Memory argument error"); if (sscanf(argv[1], "%x", &card_addr)!=1) usage("Bad card address"); - if (sscanf(argv[2], "%x", &drv.mem)!=1) + if (sscanf(argv[2], "%lx", &drv.mem)!=1) usage("Bad memory address"); if (sscanf(argv[3], "%d", &i)!=1) usage("Bad memory size"); @@ -80,7 +81,7 @@ char *p; } if (argc) usage("no parameter for argument"); - printf("drv %s%d, mem 0x%x, size %d, io %d, irq 0x%x, flags 0x%x\n", + printf("drv %s%d, mem 0x%lx, size %d, io %d, irq 0x%x, flags 0x%x\n", drv.name, drv.unit, drv.mem, drv.memsize, drv.iobase, drv.irqmask, drv.flags); sprintf(name, "/dev/card%d", slot); @@ -121,6 +122,7 @@ char *p; if (ioctl(fd, PIOCSDRV, &drv)) perror("set driver"); close(fd); + return 0; } /* * usage - print usage and exit diff --git a/usr.sbin/pccard/pccardc/pccardmem.c b/usr.sbin/pccard/pccardc/pccardmem.c index 3c75f1303fbe..9ab239cd1dd3 100644 --- a/usr.sbin/pccard/pccardc/pccardmem.c +++ b/usr.sbin/pccard/pccardc/pccardmem.c @@ -1,4 +1,5 @@ #include +#include #include #include diff --git a/usr.sbin/pccard/pccardc/printcis.c b/usr.sbin/pccard/pccardc/printcis.c index 2ee3ca063543..4d2cd951996e 100644 --- a/usr.sbin/pccard/pccardc/printcis.c +++ b/usr.sbin/pccard/pccardc/printcis.c @@ -12,8 +12,14 @@ #include "readcis.h" -int dump_pwr_desc(unsigned char *); -void print_ext_speed(unsigned char, int); +int dump_pwr_desc(unsigned char *); +void print_ext_speed(unsigned char, int); +void dump_device_desc(unsigned char *p, int len, char *type); +void dump_info_v1(unsigned char *p, int len); +void dump_config_map(struct tuple *tp); +void dump_cis_config(struct tuple *tp); +void dump_other_cond(unsigned char *p); +void dump_func_ext(unsigned char *p, int len); void dumpcis(struct cis *cp) @@ -152,6 +158,7 @@ unsigned char *p; /* * Dump configuration map tuple. */ +void dump_config_map(struct tuple *tp) { unsigned char *p, x; @@ -168,7 +175,7 @@ union { p = tp->data + 2; for (i = 0 ; i < rlen; i++) u.b[i] = *p++; - printf("\tReg len = %d, config register addr = 0x%x, last config = 0x%x\n", + printf("\tReg len = %d, config register addr = 0x%lx, last config = 0x%x\n", rlen, u.l, tp->data[1]); if (mlen) printf("\tRegisters: "); @@ -183,15 +190,12 @@ union { /* * Dump a config entry. */ +void dump_cis_config(struct tuple *tp) { unsigned char *p, feat; int i, j; char c; -union { - unsigned long l; - unsigned char b[4]; - }u; p = tp->data; printf("\tConfig index = 0x%x%s\n", *p & 0x3F, @@ -501,6 +505,7 @@ union { /* * dump_other_cond - Dump other conditions. */ +void dump_other_cond(unsigned char *p) { if (p[0]) @@ -566,6 +571,7 @@ static char *mant[] = return(len); } +void dump_device_desc(unsigned char *p, int len, char *type) { static char *un_name[] = @@ -617,6 +623,7 @@ int count = 0; /* * Print version info */ +void dump_info_v1(unsigned char *p, int len) { printf("\tVersion = %d.%d", p[0], p[1]); @@ -635,6 +642,7 @@ dump_info_v1(unsigned char *p, int len) /* * dump functional extension tuple. */ +void dump_func_ext(unsigned char *p, int len) { if (len == 0) diff --git a/usr.sbin/pccard/pccardc/rdmap.c b/usr.sbin/pccard/pccardc/rdmap.c index bfcce1fb0ef8..77ff3c7771fa 100644 --- a/usr.sbin/pccard/pccardc/rdmap.c +++ b/usr.sbin/pccard/pccardc/rdmap.c @@ -2,28 +2,49 @@ #include #include #include +#include #include #include #include -int -rdmap_main(argc, argv) -int argc; -char *argv[]; +void +dump_io(fd, nio) +int fd, nio; { -int node, mask; -struct card *cp; +struct io_desc io; +int i; - for (node = 0; node < 8; node++) - scan(node); - exit(0); + for (i = 0; i < nio; i++) + { + io.window = i; + ioctl(fd, PIOCGIO, &io); +printf("I/O %d: flags 0x%03x port 0x%3x size %d bytes\n", + io.window, io.flags, io.start, io.size); + } } -static scan(slot) + +void +dump_mem(fd, nmem) +int fd, nmem; +{ +struct mem_desc mem; +int i; + + for (i = 0; i < nmem; i++) + { + mem.window = i; + ioctl(fd, PIOCGMEM, &mem); +printf("Mem %d: flags 0x%03x host %p card %04lx size %d bytes\n", + mem.window, mem.flags, mem.start, mem.card, mem.size); + } +} + +static void +scan(slot) int slot; { -int fd, mask; -char blk[1024]; +int fd; char name[64]; struct slotstate st; @@ -41,31 +62,15 @@ struct slotstate st; } close(fd); } -dump_mem(fd, nmem) -int fd, nmem; -{ -struct mem_desc mem; -int i; - for (i = 0; i < nmem; i++) - { - mem.window = i; - ioctl(fd, PIOCGMEM, &mem); -printf("Mem %d: flags 0x%03x host 0x%6x card %04x size %d bytes\n", - mem.window, mem.flags, mem.start, mem.card, mem.size); - } -} -dump_io(fd, nio) -int fd, nio; +int +rdmap_main(argc, argv) +int argc; +char *argv[]; { -struct io_desc io; -int i; +int node; - for (i = 0; i < nio; i++) - { - io.window = i; - ioctl(fd, PIOCGIO, &io); -printf("I/O %d: flags 0x%03x port 0x%3x size %d bytes\n", - io.window, io.flags, io.start, io.size); - } + for (node = 0; node < 8; node++) + scan(node); + exit(0); } diff --git a/usr.sbin/pccard/pccardc/rdreg.c b/usr.sbin/pccard/pccardc/rdreg.c index c278ae529c96..8bf0ccd9ed4e 100644 --- a/usr.sbin/pccard/pccardc/rdreg.c +++ b/usr.sbin/pccard/pccardc/rdreg.c @@ -1,21 +1,12 @@ #include +#include +#include +#include #include #include #include -int -rdreg_main(argc, argv) -int argc; -char *argv[]; -{ - if (argc != 2) - { - dumpslot(0); - dumpslot(1); - } - else - dumpslot(atoi(argv[1])); -} +void dumpslot(sl) int sl; { @@ -46,3 +37,18 @@ struct pcic_reg r; } close(fd); } +int +rdreg_main(argc, argv) +int argc; +char *argv[]; +{ + if (argc != 2) + { + dumpslot(0); + dumpslot(1); + } + else + dumpslot(atoi(argv[1])); + return 0; +} + diff --git a/usr.sbin/pccard/pccardc/wrattr.c b/usr.sbin/pccard/pccardc/wrattr.c index d8e980fab731..597411950e97 100644 --- a/usr.sbin/pccard/pccardc/wrattr.c +++ b/usr.sbin/pccard/pccardc/wrattr.c @@ -1,4 +1,7 @@ #include +#include +#include +#include #include #include @@ -43,4 +46,5 @@ off_t offs; lseek(fd, offs, SEEK_SET); if (write(fd, &c, 1) != 1) perror(name); + return 0; } diff --git a/usr.sbin/pccard/pccardc/wrreg.c b/usr.sbin/pccard/pccardc/wrreg.c index 88a54ba4924a..42bdd7d574f2 100644 --- a/usr.sbin/pccard/pccardc/wrreg.c +++ b/usr.sbin/pccard/pccardc/wrreg.c @@ -1,4 +1,7 @@ #include +#include +#include +#include #include #include @@ -36,4 +39,5 @@ struct pcic_reg r; r.value = value; if (ioctl(fd, PIOCSREG, &r)) perror("ioctl"); + return 0; } diff --git a/usr.sbin/pccard/pccardd/cardd.c b/usr.sbin/pccard/pccardd/cardd.c index ce97520b010e..ecebdaa84510 100644 --- a/usr.sbin/pccard/pccardd/cardd.c +++ b/usr.sbin/pccard/pccardd/cardd.c @@ -6,8 +6,10 @@ #include #include #include +#include #include #include +#include #include #include #include "cardd.h" @@ -24,14 +26,16 @@ void readslots(); void slot_change(struct slot *); void card_removed(struct slot *); void card_inserted(struct slot *); +int assign_io(struct slot *sp); /* * mainline code for cardd */ +int main(int argc, char *argv[]) { struct slot *sp; -int mask, count, debug = 0, err = 0; +int count, debug = 0; int verbose = 0; extern char *optarg; extern int optind, optopt; @@ -82,11 +86,13 @@ extern int optind, optopt; die("No PC-CARD slots"); for (;;) { - mask = 0; + fd_set mask; + FD_ZERO(&mask); for (sp = slots; sp; sp = sp->next) - mask |= sp->mask; + FD_SET(sp->fd,&mask); printf("Doing select\n"); count = select(32, 0, 0, &mask, 0); +printf("select=%d\n",count); if (count == -1) { perror("Select"); @@ -94,7 +100,7 @@ printf("Doing select\n"); } if (count) for (sp = slots; sp; sp = sp->next) - if (mask & sp->mask) + if (FD_ISSET(sp->fd,&mask)) slot_change(sp); } } @@ -104,8 +110,6 @@ printf("Doing select\n"); void dump_config_file() { -struct driver *drvp; -struct device *devp; struct card *cp; struct card_config *confp; @@ -172,7 +176,6 @@ struct slot *sp; printf("opened %s\n",name); sp = xmalloc(sizeof(*sp)); sp->fd = fd; - sp->mask = 1 << fd; sp->name = newstr(name); sp->slot = i; sp->state = empty; @@ -253,7 +256,6 @@ HERE(); void card_removed(struct slot *sp) { -struct driver *drvp; struct card *cp; HERE(); @@ -265,7 +267,7 @@ HERE(); sp->config->driver->inuse = 0; } HERE(); - if (cp = sp->card) + if ((cp = sp->card) != 0) execute(cp->remove); HERE(); sp->cis = 0; @@ -339,7 +341,7 @@ struct card *cp; void read_ether(struct slot *sp) { -unsigned char net_addr[12], *p; +unsigned char net_addr[12]; lseek(sp->fd, (off_t)sp->card->ether, SEEK_SET); if (read(sp->fd, net_addr, sizeof(net_addr)) != sizeof(net_addr)) @@ -582,7 +584,6 @@ setup_slot(struct slot *sp) struct mem_desc mem; struct io_desc io; struct drv_desc drv; -struct allocblk *ap; struct driver *drvp = sp->config->driver; char c; off_t offs; diff --git a/usr.sbin/pccard/pccardd/cardd.h b/usr.sbin/pccard/pccardd/cardd.h index 88561f5e3691..4700d150f728 100644 --- a/usr.sbin/pccard/pccardd/cardd.h +++ b/usr.sbin/pccard/pccardd/cardd.h @@ -119,6 +119,8 @@ void logerr(char *); void reset_slot(struct slot *); void execute(struct cmd *); unsigned long alloc_memory(int size); +int bit_fns(bitstr_t *nm, int nbits, int count); +void readfile(char *name); #define IOPORTS 0x400 #define MEMUNIT 0x1000 diff --git a/usr.sbin/pccard/pccardd/file.c b/usr.sbin/pccard/pccardd/file.c index 769fafc7c9bc..5841b120886b 100644 --- a/usr.sbin/pccard/pccardd/file.c +++ b/usr.sbin/pccard/pccardd/file.c @@ -49,14 +49,17 @@ int irq_tok(int); void setflags(struct flags *, int *); struct driver *new_driver(char *); +void addcmd(struct cmd **cp); +void parse_card(); + /* * Read a file and parse the pcmcia configuration data. * After parsing, verify the links. */ +void readfile(char *name) { struct card *cp; -struct driver *drvp; in = fopen(name, "r"); if (in == 0) @@ -76,7 +79,6 @@ void parsefile() { int i; -char *s; struct allocblk *bp; pushc = 0; @@ -94,7 +96,7 @@ struct allocblk *bp; * reserved I/O blocks */ case 1: - while (bp = ioblk_tok(0)) + while ((bp = ioblk_tok(0)) != 0) { if (bp->size == 0 || bp->addr == 0) { @@ -119,7 +121,7 @@ struct allocblk *bp; * reserved memory blocks. */ case 3: - while (bp = memblk_tok(0)) + while ((bp = memblk_tok(0)) != 0) { if (bp->size == 0 || bp->addr == 0) { @@ -152,6 +154,7 @@ struct allocblk *bp; /* * Parse a card definition. */ +void parse_card() { char *man, *vers; @@ -626,6 +629,7 @@ int set = 1; * addcmd - Append the command line to the list of * commands. */ +void addcmd(struct cmd **cp) { char *s = getline(); @@ -698,7 +702,7 @@ int num_tok() { char *s = next_tok(), c; -int val=0, base, term=0; +int val=0, base; base = 10; c = *s++; @@ -752,7 +756,7 @@ int val=0, base, term=0; return(-1); break; } - } while (c = *s++); + } while ((c = *s++) != 0); return(val); } char *_next_tok(); diff --git a/usr.sbin/pccard/pccardd/readcis.c b/usr.sbin/pccard/pccardd/readcis.c index 880a4aa44b69..b25f0eeddb84 100644 --- a/usr.sbin/pccard/pccardd/readcis.c +++ b/usr.sbin/pccard/pccardd/readcis.c @@ -15,41 +15,45 @@ static int read_attr(int fd, char *bp, int len); struct tuple_list *read_one_tuplelist(int, int, off_t); int ck_linktarget(int, off_t, int); +void cis_info(struct cis *cp, unsigned char *p, int len); +void device_desc(unsigned char *p, int len, struct dev_mem *dp); +void config_map(struct cis *cp, unsigned char *p, int len); +void cis_config(struct cis *cp, unsigned char *p, int len); struct tuple_info tuple_info[] = { - "Null tuple", 0x00, 0, - "Common memory descriptor", 0x01, 255, - "Checksum", 0x10, 5, - "Long link to attribute memory", 0x11, 4, - "Long link to common memory", 0x12, 4, - "Link target", 0x13, 3, - "No link", 0x14, 0, - "Version 1 info", 0x15, 255, - "Alternate language string", 0x16, 255, - "Attribute memory descriptor", 0x17, 255, - "JEDEC descr for common memory", 0x18, 255, - "JEDEC descr for attribute memory", 0x19, 255, - "Configuration map", 0x1A, 255, - "Configuration entry", 0x1B, 255, - "Other conditions for common memory", 0x1C, 255, - "Other conditions for attribute memory", 0x1D, 255, - "Geometry info for common memory", 0x1E, 255, - "Geometry info for attribute memory", 0x1F, 255, - "Manufacturer ID", 0x20, 4, - "Functional ID", 0x21, 255, - "Functional EXT", 0x22, 255, - "Software interleave", 0x23, 2, - "Version 2 Info", 0x40, 255, - "Data format", 0x41, 255, - "Geometry", 0x42, 4, - "Byte order", 0x43, 2, - "Card init date", 0x44, 4, - "Battery replacement", 0x45, 4, - "Organisation", 0x46, 255, - "Terminator", 0xFF, 255, - 0, 0, 0 - }; + { "Null tuple", 0x00, 0 }, + { "Common memory descriptor", 0x01, 255 }, + { "Checksum", 0x10, 5 }, + { "Long link to attribute memory", 0x11, 4 }, + { "Long link to common memory", 0x12, 4 }, + { "Link target", 0x13, 3 }, + { "No link", 0x14, 0 }, + { "Version 1 info", 0x15, 255 }, + { "Alternate language string", 0x16, 255 }, + { "Attribute memory descriptor", 0x17, 255 }, + { "JEDEC descr for common memory", 0x18, 255 }, + { "JEDEC descr for attribute memory", 0x19, 255 }, + { "Configuration map", 0x1A, 255 }, + { "Configuration entry", 0x1B, 255 }, + { "Other conditions for common memory", 0x1C, 255 }, + { "Other conditions for attribute memory", 0x1D, 255 }, + { "Geometry info for common memory", 0x1E, 255 }, + { "Geometry info for attribute memory", 0x1F, 255 }, + { "Manufacturer ID", 0x20, 4 }, + { "Functional ID", 0x21, 255 }, + { "Functional EXT", 0x22, 255 }, + { "Software interleave", 0x23, 2 }, + { "Version 2 Info", 0x40, 255 }, + { "Data format", 0x41, 255 }, + { "Geometry", 0x42, 4 }, + { "Byte order", 0x43, 2 }, + { "Card init date", 0x44, 4 }, + { "Battery replacement", 0x45, 4 }, + { "Organisation", 0x46, 255 }, + { "Terminator", 0xFF, 255 }, + { 0, 0, 0 } + }; /* * After reading the tuples, decode the relevant ones. @@ -106,10 +110,10 @@ struct cis_config *conf; struct tuple *tp; struct tuple_list *tl; - while (tl = cp->tlist) + while ((tl = cp->tlist) != 0) { cp->tlist = tl->next; - while (tp = tl->tuples) + while ((tp = tl->tuples) != 0) { tl->tuples = tp->next; if (tp->data) @@ -117,15 +121,15 @@ struct tuple_list *tl; } } - while (conf = cp->conf) + while ((conf = cp->conf) != 0) { cp->conf = conf->next; - while (io = conf->io) + while ((io = conf->io) != 0) { conf->io = io->next; free(io); } - while (mem = conf->mem) + while ((mem = conf->mem) != 0) { conf->mem = mem->next; free(mem); @@ -137,6 +141,7 @@ struct tuple_list *tl; /* * Fills in CIS version data. */ +void cis_info(struct cis *cp, unsigned char *p, int len) { cp->maj_v = *p++; @@ -155,10 +160,8 @@ cis_info(struct cis *cp, unsigned char *p, int len) /* * device_desc - decode device descriptor. */ -device_desc(p, len, dp) -unsigned char *p; -int len; -struct dev_mem *dp; +void +device_desc(unsigned char *p, int len, struct dev_mem *dp) { while (len > 0 && *p != 0xFF) { @@ -179,10 +182,8 @@ struct dev_mem *dp; /* * configuration map of card control register. */ -config_map(cp, p, len) -struct cis *cp; -unsigned char *p; -int len; +void +config_map(struct cis *cp, unsigned char *p, int len) { unsigned char *p1; int i; @@ -202,12 +203,10 @@ union { /* * CIS config entry - Decode and build configuration entry. */ -cis_config(cp, p, len) -struct cis *cp; -unsigned char *p; -int len; +void +cis_config(struct cis *cp, unsigned char *p, int len) { -int blks, x; +int x; int i, j; union { unsigned long l; @@ -216,9 +215,10 @@ union { struct cis_config *conf, *last; struct cis_memblk *mem; unsigned char feat; +struct cis_memblk *lastmem = 0; conf = xmalloc(sizeof(*conf)); - if (last = cp->conf) + if ((last = cp->conf) !=0) { while (last->next) last = last->next; @@ -351,14 +351,12 @@ unsigned char feat; conf->memwins = CIS_MEM_WINS(x); for (i = 0; i < conf->memwins; i++) { - struct cis_memblk *last; - mem = xmalloc(sizeof(*mem)); if (i == 0) conf->mem = mem; else - last->next = mem; - last = mem; + lastmem->next = mem; + lastmem = mem; u.l = 0; for (j = 0 ; j < CIS_MEM_LENSZ(x); j++) u.b[j] = *p++; @@ -465,10 +463,10 @@ off_t offs; struct tuple_list * read_one_tuplelist(int fd, int flags, off_t offs) { -struct tuple *tp, *last_tp, *first = 0; +struct tuple *tp, *last_tp = 0; struct tuple_list *tl; struct tuple_info *tinfo; -int i, total = 0; +int total = 0; unsigned char code, length; /* @@ -567,7 +565,7 @@ struct tuple_list *tl; struct tuple *tp; for (tl = sp->tlist; tl; tl = tl->next) - if (tp = find_tuple_in_list(tl, code)) + if ((tp = find_tuple_in_list(tl, code)) != 0) return(tp); return(0); } diff --git a/usr.sbin/pccard/pccardd/util.c b/usr.sbin/pccard/pccardd/util.c index 6abacaa0042e..68379e9c1391 100644 --- a/usr.sbin/pccard/pccardd/util.c +++ b/usr.sbin/pccard/pccardd/util.c @@ -4,6 +4,8 @@ #include #include #include +#include +#include #include #include #include @@ -107,7 +109,6 @@ int i; void reset_slot(struct slot *sp) { -struct card *cp = sp->card; char c; off_t offs; struct mem_desc mem; @@ -155,7 +156,7 @@ char *p, *cp, *lp; lp = cmdp->line; if (*lp == 0) continue; - while (p = strchr(lp, '$')) + while ((p = strchr(lp, '$')) != 0) { /* * copy over preceding string. @@ -199,7 +200,7 @@ char *p, *cp, *lp; /* * No more replacements. Copy rest of string. */ - while (*cp++ = *lp++) + while ((*cp++ = *lp++) != 0) ; #ifdef DEBUG fprintf(stderr, "Executing [%s]\n", cmd);