diff options
Diffstat (limited to 'usr.sbin/pccard/pccardc')
-rw-r--r-- | usr.sbin/pccard/pccardc/Makefile | 37 | ||||
-rw-r--r-- | usr.sbin/pccard/pccardc/dumpcis.c | 79 | ||||
-rw-r--r-- | usr.sbin/pccard/pccardc/enabler.c | 144 | ||||
-rw-r--r-- | usr.sbin/pccard/pccardc/pccardc.c | 59 | ||||
-rw-r--r-- | usr.sbin/pccard/pccardc/pccardmem.c | 38 | ||||
-rw-r--r-- | usr.sbin/pccard/pccardc/printcis.c | 711 | ||||
-rw-r--r-- | usr.sbin/pccard/pccardc/rdmap.c | 71 | ||||
-rw-r--r-- | usr.sbin/pccard/pccardc/rdreg.c | 48 | ||||
-rw-r--r-- | usr.sbin/pccard/pccardc/wrattr.c | 46 | ||||
-rw-r--r-- | usr.sbin/pccard/pccardc/wrreg.c | 39 |
10 files changed, 1272 insertions, 0 deletions
diff --git a/usr.sbin/pccard/pccardc/Makefile b/usr.sbin/pccard/pccardc/Makefile new file mode 100644 index 0000000..078fb4b --- /dev/null +++ b/usr.sbin/pccard/pccardc/Makefile @@ -0,0 +1,37 @@ +# +# Makefile pccardc +# +# $Id$ +# +.PATH: ${.CURDIR}/../pccardd +PROG= pccardc +SRCS= pccardc.c \ + dumpcis.c readcis.c printcis.c \ + enabler.c \ + pccardmem.c \ + rdmap.c \ + rdreg.c \ + wrattr.c \ + wrreg.c + +CFLAGS+= -I. -I${.CURDIR}/../pccardd + +.include <bsd.prog.mk> + +## +## Makefile for PCMCIA card programs. +## +# +#PROGS = rdmap rdreg wrreg pccardmem wrattr enabler +# +#enabler: enabler.c +# cc $(CFLAGS) -o enabler enabler.c +# +#rdmap: rdmap.c +# cc $(CFLAGS) -o rdmap rdmap.c +# +#rdreg: rdreg.c +# cc $(CFLAGS) -o rdreg rdreg.c +# +#wrreg: wrreg.c +# cc $(CFLAGS) -o wrreg wrreg.c diff --git a/usr.sbin/pccard/pccardc/dumpcis.c b/usr.sbin/pccard/pccardc/dumpcis.c new file mode 100644 index 0000000..eacf73a --- /dev/null +++ b/usr.sbin/pccard/pccardc/dumpcis.c @@ -0,0 +1,79 @@ +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include <string.h> +#include <sys/ioctl.h> + +#include <pccard/card.h> +#include <pccard/cis.h> +#include "readcis.h" + +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); +} +scan(slot) +int slot; +{ +int fd, i; +char name[64]; +struct cis *cp; +struct slotstate st; + + sprintf(name, "/dev/card%d", slot); + fd = open(name, 0); + if (fd < 0) + return; + nocards++; + ioctl(fd, PIOCGSTATE, &st); + if (st.state == filled) + { + cp = readcis(fd); + if (cp) + { + printf("Configuration data for card in slot %d\n", + slot); + dumpcis(cp); + freecis(cp); + } + } +} +dump(p, sz) +unsigned char *p; +int sz; +{ +int ad = 0, i; + while (sz > 0) + { + printf("%03x: ", ad); + for (i = 0; i < ((sz < 16) ? sz : 16); i++) + printf(" %02x", p[i]); + printf("\n"); + sz -= 16; + p += 16; + ad += 16; + } +} +void * +xmalloc(int sz) +{ +void *p; + + sz = (sz + 7) & ~7; + p = malloc(sz); + if (p) + bzero(p, sz); + else + { + perror("malloc"); + exit(1); + } + return(p); +} diff --git a/usr.sbin/pccard/pccardc/enabler.c b/usr.sbin/pccard/pccardc/enabler.c new file mode 100644 index 0000000..c96b853 --- /dev/null +++ b/usr.sbin/pccard/pccardc/enabler.c @@ -0,0 +1,144 @@ +/* + * Enabler for PCCARD. Used for testing drivers etc. + * Options: + * enabler slot driver [ -m card addr size ] [ -i iobase ] [ -q irq ] + */ +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include <string.h> +#include <sys/ioctl.h> + +#include <pccard/card.h> +#include <pccard/cis.h> + +void usage(); + +int +enabler_main(argc, argv) +int argc; +char *argv[]; +{ +struct drv_desc drv; +struct mem_desc mem; +struct io_desc io; +int fd, err, slot, i, card_addr; +char name[32]; +char *p; + + bzero(&drv, sizeof(drv)); + if (argc < 3) + usage("arg count"); + slot = atoi(argv[1]); + if (slot < 0 || slot >= MAXSLOT) + usage("Illegal slot number"); + p = argv[2]; + while (*p && (*p < '0' || *p > '9')) + p++; + if (*p == 0) + usage("No unit on device name"); + drv.unit = atoi(p); + *p = 0; + strcpy(drv.name, argv[2]); + argv += 3; + argc -= 3; + while (argc > 1) + { + if (strcmp(argv[0], "-m")==0) + { + if (argc < 4) + usage("Memory argument error"); + if (sscanf(argv[1], "%x", &card_addr)!=1) + usage("Bad card address"); + if (sscanf(argv[2], "%x", &drv.mem)!=1) + usage("Bad memory address"); + if (sscanf(argv[3], "%d", &i)!=1) + usage("Bad memory size"); + drv.memsize = i * 1024; + argc -= 2; + argv += 2; + } + else if (strcmp(argv[0], "-f")==0) + { + if (sscanf(argv[1], "%x", &drv.flags)!=1) + usage("Bad driver flags"); + } + else if (strcmp(argv[0], "-a")==0) + { + if (sscanf(argv[1], "%x", &drv.iobase)!=1) + usage("Bad I/O address"); + } + else if (strcmp(argv[0], "-i")==0) + { + if (sscanf(argv[1], "%d", &i)!=1 || + i < 1 || i > 15) + usage("Illegal IRQ"); + drv.irqmask = 1 << i; + } + argc -= 2; + argv += 2; + } + 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", + drv.name, drv.unit, drv.mem, drv.memsize, drv.iobase, + drv.irqmask, drv.flags); + sprintf(name, "/dev/card%d", slot); + fd = open(name, 2); + if (fd < 0) + { + perror(name); + exit(1); + } +/* + * Map the memory and I/O contexts. + */ + if (drv.mem) + { + mem.window = 0; + mem.flags = MDF_ACTIVE|MDF_16BITS; + mem.start = (caddr_t)drv.mem; + mem.size = drv.memsize; + mem.card = card_addr; + if (ioctl(fd, PIOCSMEM, &mem)) + { + perror("Set memory context"); + exit(1); + } + } + if (drv.iobase) + { + io.window = 0; + io.flags = IODF_ACTIVE|IODF_CS16; + io.start = drv.iobase; + io.size = 32; /* Blah... */ + if (ioctl(fd, PIOCSIO, &io)) + { + perror("Set I/O context"); + exit(1); + } + } + if (ioctl(fd, PIOCSDRV, &drv)) + perror("set driver"); + close(fd); +} +/* + * usage - print usage and exit + */ +void +usage(msg) +char *msg; +{ + fprintf(stderr, "enabler: %s\n", msg); + fprintf(stderr, +"Usage: enabler slot driver [ -m addr size ] [ -a iobase ] [ -i irq ]\n"); + fprintf(stderr, +" -m card addr size : Card address (hex), host address (hex) & size (Kb)\n"); + fprintf(stderr, +" -a iobase : I/O port address (hex)\n"); + fprintf(stderr, +" -i irq : Interrupt request number (1-15)\n"); + fprintf(stderr, +" Example: enabler 0 ed0 -m 2000 d4000 16 -a 300 -i 3\n"); + exit(1); +} diff --git a/usr.sbin/pccard/pccardc/pccardc.c b/usr.sbin/pccard/pccardc/pccardc.c new file mode 100644 index 0000000..e789be2 --- /dev/null +++ b/usr.sbin/pccard/pccardc/pccardc.c @@ -0,0 +1,59 @@ +#include <stdio.h> +#include <stdlib.h> + +typedef int (*main_t)(int , char **); + +#define DECL(foo) int foo(int, char**); +DECL(dumpcis_main); +DECL(enabler_main); +DECL(help_main); +DECL(pccardmem_main); +DECL(rdmap_main); +DECL(rdreg_main); +DECL(wrattr_main); +DECL(wrreg_main); + +struct { + char *name; + main_t func; + char *help; +} subcommands[] = { + +{ "dumpcis", dumpcis_main, "Prints CIS for all cards"}, +{ "enabler", enabler_main, "Device driver enabler"}, +{ "help", help_main, "Prints command summary"}, +{ "pccardmem", pccardmem_main, "Allocate memory for pccard driver"}, +{ "rdmap", rdmap_main, "Read pcic mappings"}, +{ "rdreg", rdreg_main, "Read pcic register"}, +{ "wrattr", wrattr_main, "Write byte to attribute memory"}, +{ "wrreg", wrreg_main, "Write pcic register"}, +{0, 0} +}; + +int +main(int argc, char **argv) +{ + int i; + for(i=0; argc > 1 && subcommands[i].name; i++) { + if (!strcmp(argv[1],subcommands[i].name)) { + argv[1] = argv[0]; + return (*subcommands[i].func)(argc-1,argv+1); + } + } + if (argc > 1) + fprintf(stderr,"Unknown Subcommand.\n"); + return help_main(argc,argv); +} + +int +help_main(int argc, char **argv) +{ + int i; + fprintf(stderr,"Usage:\n"); + fprintf(stderr,"\t%s <subcommand> <arg> ...\n",argv[0]); + fprintf(stderr,"Subcommands:\n"); + for(i=0; subcommands[i].name; i++) + fprintf(stderr,"\t%s\n\t\t%s\n", + subcommands[i].name, subcommands[i].help); + return 1; +} diff --git a/usr.sbin/pccard/pccardc/pccardmem.c b/usr.sbin/pccard/pccardc/pccardmem.c new file mode 100644 index 0000000..3c75f13 --- /dev/null +++ b/usr.sbin/pccard/pccardc/pccardmem.c @@ -0,0 +1,38 @@ +#include <stdio.h> +#include <sys/types.h> +#include <sys/ioctl.h> + +#include <pccard/card.h> +int +pccardmem_main(argc, argv) +int argc; +char *argv[]; +{ +int addr = 0; +int fd; + + if (argc > 2) + { + fprintf(stderr, "usage: %s [ memory-address ]\n", argv[0]); + exit(1); + } + fd = open("/dev/card0", 0); + if (fd < 0) + { + perror("/dev/card0"); + exit(1); + } + if (argc == 2) + { + if (sscanf(argv[1], "%x", &addr) != 1) + { + fprintf(stderr, "arg error\n"); + exit(1); + } + } + if (ioctl(fd, PIOCRWMEM, &addr)) + perror("ioctl"); + else + printf("PCCARD Memory address set to 0x%x\n", addr); + exit(0); +} diff --git a/usr.sbin/pccard/pccardc/printcis.c b/usr.sbin/pccard/pccardc/printcis.c new file mode 100644 index 0000000..2ee3ca0 --- /dev/null +++ b/usr.sbin/pccard/pccardc/printcis.c @@ -0,0 +1,711 @@ +/* set tab=4 + * dump CIS tuples. + */ +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include <string.h> +#include <sys/ioctl.h> + +#include <pccard/card.h> +#include <pccard/cis.h> + +#include "readcis.h" + +int dump_pwr_desc(unsigned char *); +void print_ext_speed(unsigned char, int); + +void +dumpcis(struct cis *cp) +{ +struct tuple *tp; +struct tuple_list *tl; +int count = 0, sz, ad, i; +unsigned char *p; + + for (tl = cp->tlist; tl; tl = tl->next) + for (tp = tl->tuples; tp; tp = tp->next) + { + printf("Tuple #%d, code = 0x%x (%s), length = %d\n", + ++count, tp->code, tuple_name(tp->code), tp->length); + p = tp->data; + sz = tp->length; + ad = 0; + while (sz > 0) + { + printf(" %03x: ", ad); + for (i = 0; i < ((sz < 16) ? sz : 16); i++) + printf(" %02x", p[i]); + printf("\n"); + sz -= 16; + p += 16; + ad += 16; + } + switch(tp->code) + { + default: + break; + case CIS_MEM_COMMON: /* 0x01 */ + dump_device_desc(tp->data, tp->length, "Common"); + break; + case CIS_CHECKSUM: /* 0x10 */ + if (tp->length == 5) + { + printf("\tChecksum from offset %d, length %d, value is 0x%x\n", + (short)((tp->data[1] << 8) | tp->data[0]), + (tp->data[3] << 8) | tp->data[2], + tp->data[4]); + } + else + printf("\tIllegal length for checksum!\n"); + break; + case CIS_LONGLINK_A: /* 0x11 */ + printf("\tLong link to attribute memory, address 0x%x\n", + (tp->data[3] << 24) | + (tp->data[2] << 16) | + (tp->data[1] << 8) | + tp->data[0]); + break; + case CIS_LONGLINK_C: /* 0x12 */ + printf("\tLong link to common memory, address 0x%x\n", + (tp->data[3] << 24) | + (tp->data[2] << 16) | + (tp->data[1] << 8) | + tp->data[0]); + break; + break; + case CIS_INFO_V1: /* 0x15 */ + dump_info_v1(tp->data, tp->length); + break; + case CIS_ALTSTR: /* 0x16 */ + break; + case CIS_MEM_ATTR: /* 0x17 */ + dump_device_desc(tp->data, tp->length, "Attribute"); + break; + case CIS_JEDEC_C: /* 0x18 */ + break; + case CIS_JEDEC_A: /* 0x19 */ + break; + case CIS_CONF_MAP: /* 0x1A */ + dump_config_map(tp); + break; + case CIS_CONFIG: /* 0x1B */ + dump_cis_config(tp); + break; + case CIS_DEVICE_OC: /* 0x1C */ + dump_other_cond(tp->data); + break; + case CIS_DEVICE_OA: /* 0x1D */ + dump_other_cond(tp->data); + break; + case CIS_DEVICEGEO: /* 0x1E */ + break; + case CIS_DEVICEGEO_A: /* 0x1F */ + break; + case CIS_MANUF_ID: /* 0x20 */ + printf("\tPCMCIA ID = 0x%x, OEM ID = 0x%x\n", + (tp->data[1] << 8) | tp->data[0], + (tp->data[3] << 8) | tp->data[2]); + break; + case CIS_FUNC_ID: /* 0x21 */ + switch(tp->data[0]) + { + default: + printf("\tUnknown function"); + break; + case 0: + printf("\tMultifunction card"); + break; + case 1: + printf("\tMemory card"); + break; + case 2: + printf("\tSerial port/modem"); + break; + case 3: + printf("\tParallel port"); + break; + case 4: + printf("\tFixed disk card"); + break; + case 5: + printf("\tVideo adapter"); + break; + case 6: + printf("\tNetwork/LAN adapter"); + break; + case 7: + printf("\tAIMS"); + break; + } + printf("%s%s\n", (tp->data[1] & 1) ? " - POST initialize" : "", + (tp->data[1] & 2) ? " - Card has ROM" : ""); + break; + case CIS_FUNC_EXT: /* 0x22 */ + dump_func_ext(tp->data, tp->length); + break; + case CIS_VERS_2: /* 0x40 */ + break; + } + } +} +/* + * Dump configuration map tuple. + */ +dump_config_map(struct tuple *tp) +{ +unsigned char *p, x; +int rlen, mlen; +int i; +union { + unsigned long l; + unsigned char b[4]; + }u; + + rlen = (tp->data[0] & 3)+1; + mlen = ((tp->data[0] >> 2) & 3)+1; + u.l = 0; + 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", + rlen, u.l, tp->data[1]); + if (mlen) + printf("\tRegisters: "); + for (i = 0; i < mlen; i++, p++) + { + for (x = 0x1; x; x <<= 1) + printf("%c", x & *p ? 'X' : '-'); + printf(" "); + } + printf("\n"); +} +/* + * Dump a config entry. + */ +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, + *p & 0x40 ? "(default)" : ""); + if (*p & 0x80) + { + p++; + printf("\tInterface byte = 0x%x ", *p); + switch (*p & 0xF) + { + default: + printf("(reserved)"); + break; + case 0: + printf("(memory)"); + break; + case 1: + printf("(I/O)"); + break; + case 4: + case 5: + case 6: + case 7: + case 8: + printf("(custom)"); + break; + } + c = ' '; + if (*p & 0x10) + { + printf(" BVD1/2 active"); + c = ','; + } + if (*p & 0x20) + { + printf("%c card WP active", c); /* Write protect */ + c = ','; + } + if (*p & 0x40) + { + printf("%c +RDY/-BSY active", c); + c = ','; + } + if (*p & 0x80) + printf("%c wait signal supported", c); + printf("\n"); + } + p++; + feat = *p++; + switch(feat & 3) + { + case 0: + break; + case 1: + printf("\tVcc pwr:\n"); + p += dump_pwr_desc(p); + break; + case 2: + printf("\tVcc pwr:\n"); + p += dump_pwr_desc(p); + printf("\tVpp pwr:\n"); + p += dump_pwr_desc(p); + break; + case 3: + printf("\tVcc pwr:\n"); + p += dump_pwr_desc(p); + printf("\tVpp1 pwr:\n"); + p += dump_pwr_desc(p); + printf("\tVpp2 pwr:\n"); + p += dump_pwr_desc(p); + break; + } + if (feat & 0x4) + { + i = *p & 3; + j = (*p >> 2) & 7; + p++; + if (i != 3) + { + printf("\tWait scale "); + print_ext_speed(*p, i); + while (*p & 0x80) + p++; + printf("\n"); + } + if (j != 7) + { + printf("\tRDY/BSY scale "); + print_ext_speed(*p, j); + while (*p & 0x80) + p++; + printf("\n"); + } + } + if (feat & 0x8) + { + if (*p & 0x1F) + printf("\tCard decodes %d address lines", *p & 0x1F); + else + printf("\tCard provides address decode"); + switch((*p >> 5) & 3) + { + case 0: + break; + case 1: + printf(", 8 Bit I/O only"); + break; + case 2: + printf(", limited 8/16 Bit I/O"); + break; + case 3: + printf(", full 8/16 Bit I/O"); + break; + } + printf("\n"); + if (*p & 0x80) + { + p++; + c = *p++; + for (i = 0; i <= (c & 0xF); i++) + { + printf("\t\tI/O address # %d: ", i + 1); + switch ((c >> 4) & 3) + { + case 0: + break; + case 1: + printf("block start = 0x%x", *p++); + break; + case 2: + printf("block start = 0x%x", (p[1] << 8) | *p); + p += 2; + break; + case 3: + printf("block start = 0x%x", + (p[3] << 24) | (p[2] << 16) | + (p[1] << 8) | *p); + p += 4; + break; + } + switch ((c >> 6) & 3) + { + case 0: + break; + case 1: + printf(" block length = 0x%x", *p++ + 1); + break; + case 2: + printf(" block length = 0x%x", ((p[1] << 8) | *p)+1); + p += 2; + break; + case 3: + printf(" block length = 0x%x", + ((p[3] << 24) | (p[2] << 16) | + (p[1] << 8) | *p) + 1); + p += 4; + break; + } + printf("\n"); + } + } + } +/* + * IRQ descriptor + */ + if (feat & 0x10) + { + printf("\t\tIRQ modes:"); + c = ' '; + if (*p & 0x20) + { + printf(" Level"); + c = ','; + } + if (*p & 0x40) + { + printf("%c Pulse", c); + c = ','; + } + if (*p & 0x80) + printf("%c Shared", c); + printf("\n"); + if (*p & 0x10) + { + i = p[0] | (p[1] << 8); + printf("\t\tIRQs: "); + if (*p & 1) + printf(" NMI"); + if (*p & 0x2) + printf(" IOCK"); + if (*p & 0x4) + printf(" BERR"); + if (*p & 0x8) + printf(" VEND"); + for ( j = 0; j < 16; j++) + if (i & (1 << j)) + printf(" %d", j); + printf("\n"); + p += 3; + } + else + { + printf("\t\tIRQ level = %d\n", *p & 0xF); + p++; + } + } + switch((feat >> 5) & 3) + { + case 0: + break; + case 1: + printf("\tMemory space length = 0x%x\n", (p[1] << 8) | p[0]); + p += 2; + break; + case 2: + printf("\tMemory space address = 0x%x, length = 0x%x\n", + (p[3] << 8) | p[2], + (p[1] << 8) | p[0]); + p += 4; + break; +/* + * Memory descriptors. + */ + case 3: + c = *p++; + for (i = 0; i <= (c & 7); i++) + { + printf("\tMemory descriptor %d\n\t\t", i+1); + switch ((c >> 3) & 3) + { + case 0: + break; + case 1: + printf(" blk length = 0x%x00", *p++); + break; + case 2: + printf(" blk length = 0x%x00", (p[1] << 8) | *p); + p += 2; + break; + case 3: + printf(" blk length = 0x%x00", + (p[3] << 24) | (p[2] << 16) | + (p[1] << 8) | *p); + p += 4; + break; + } + switch ((c >> 5) & 3) + { + case 0: + break; + case 1: + printf(" card addr = 0x%x00", *p++); + break; + case 2: + printf(" card addr = 0x%x00", (p[1] << 8) | *p); + p += 2; + break; + case 3: + printf(" card addr = 0x%x00", + (p[3] << 24) | (p[2] << 16) | + (p[1] << 8) | *p); + p += 4; + break; + } + if (c & 0x80) + switch ((c >> 5) & 3) + { + case 0: + break; + case 1: + printf(" host addr = 0x%x00", *p++); + break; + case 2: + printf(" host addr = 0x%x00", (p[1] << 8) | *p); + p += 2; + break; + case 3: + printf(" host addr = 0x%x00", + (p[3] << 24) | (p[2] << 16) | + (p[1] << 8) | *p); + p += 4; + break; + } + printf("\n"); + } + break; + } + if (feat & 0x80) + { + printf("\tMax twin cards = %d\n", *p & 7); + printf("\tMisc attr:"); + if (*p & 0x8) + printf(" (Audio-BVD2)"); + if (*p & 0x10) + printf(" (Read-only)"); + if (*p & 0x20) + printf(" (Power down supported)"); + if (*p & 0x80) + { + printf(" (Ext byte = 0x%x)", p[1]); + p++; + } + printf("\n"); + p++; + } +} +/* + * dump_other_cond - Dump other conditions. + */ +dump_other_cond(unsigned char *p) +{ + if (p[0]) + { + printf("\t"); + if (p[0] & 1) + printf("(MWAIT)"); + if (p[0] & 2) + printf(" (3V card)"); + if (p[0] & 0x80) + printf(" (Extension bytes follow)"); + printf("\n"); + } +} +/* + * Dump power descriptor. + */ +int +dump_pwr_desc(unsigned char *p) +{ +int len = 1, i; +unsigned char mask; +char **expp; +static char *pname[] = + { "Nominal operating supply voltage", + "Minimum operating supply voltage", + "Maximum operating supply voltage", + "Continuous supply current", + "Max current average over 1 second", + "Max current average over 10 ms", + "Power down supply current", + "Reserved" + }; +static char *vexp[] = + { "10uV", "100uV", "1mV", "10mV", "100mV", "1V", "10V", "100V" }; +static char *cexp[] = + { "10nA", "1uA", "10uA", "100uA", "1mA", "10mA", "100mA", "1A" }; +static char *mant[] = + { "1", "1.2", "1.3", "1.5", "2", "2.5", "3", "3.5", "4", "4.5", + "5", "5.5", "6", "7", "8", "9" }; + + mask = *p++; + expp = vexp; + for (i = 0; i < 8; i++) + if (mask & (1 << i)) + { + len++; + if (i >= 3) + expp = cexp; + printf("\t\t%s: ", pname[i]); + printf("%s x %s", + mant[(*p >> 3) & 0xF], + expp[*p & 7]); + while (*p & 0x80) + { + len++; + p++; + printf(", ext = 0x%x", *p); + } + printf("\n"); + p++; + } + return(len); +} + +dump_device_desc(unsigned char *p, int len, char *type) +{ +static char *un_name[] = + { "512b", "2Kb", "8Kb", "32Kb", + "128Kb", "512Kb", "2Mb", "reserved"}; +static char *speed[] = + { "No speed", "250nS", "200nS", "150nS", + "100nS", "Reserved", "Reserved" }; +static char *dev[] = + { "No device", "Mask ROM", "OTPROM", "UV EPROM", + "EEPROM", "FLASH EEPROM", "SRAM", "DRAM", + "Reserved", "Reserved", "Reserved", "Reserved", + "Reserved", "Function specific", "Extended", + "Reserved" }; +int count = 0; + + while (*p != 0xFF && len > 0) + { + unsigned char x; + + x = *p++; + len -= 2; + if (count++ == 0) + printf("\t%s memory device information:\n", type); + printf("\t\tDevice number %d, type %s, WPS = %s\n", + count, dev[x >> 4], (x & 0x8) ? "ON" : "OFF"); + if ((x & 7) == 7) + { + len--; + if (*p) + { + printf("\t\t"); + print_ext_speed(*p, 0); + while (*p & 0x80) + { + p++; + len--; + } + } + p++; + } + else + printf("\t\tSpeed = %s", speed[x & 7]); + printf(", Memory block size = %s, %d units\n", + un_name[*p & 7], (*p >> 3) + 1); + p++; + } +} +/* + * Print version info + */ +dump_info_v1(unsigned char *p, int len) +{ + printf("\tVersion = %d.%d", p[0], p[1]); + p += 2; + printf(", Manuf = [%s],", p); + while (*p++) + ; + printf("card vers = [%s]\n", p); + while (*p++) + ; + printf("\tAddit. info = [%s]", p); + while (*p++) + ; + printf(",[%s]\n", p); +} +/* + * dump functional extension tuple. + */ +dump_func_ext(unsigned char *p, int len) +{ + if (len == 0) + return; + switch(p[0]) + { + case 0: + case 8: + case 10: + if (len != 4) + { + printf("\tWrong length for serial extension\n"); + return; + } + printf("\tSerial interface extension:\n"); + switch(p[1] & 0x1F) + { + default: + printf("\t\tUnkn device"); + break; + case 0: + printf("\t\t8250 UART"); + break; + case 1: + printf("\t\t16450 UART"); + break; + case 2: + printf("\t\t16550 UART"); + break; + } + printf(", Parity - %s%s%s%s", + (p[2] & 1) ? "Space," : "", + (p[2] & 2) ? "Mark," : "", + (p[2] & 4) ? "Odd," : "", + (p[2] & 8) ? "Even," : ""); + printf("\n"); + break; + case 1: + case 5: + case 6: + case 7: + printf("\tModem interface capabilities:\n"); + break; + case 2: + printf("\tData modem services available:\n"); + break; + case 9: + printf("\tFax/modem services available:\n"); + break; + case 4: + printf("\tVoice services available:\n"); + break; + } +} +/* + * print_ext_speed - Print extended speed. + */ +void +print_ext_speed(unsigned char x, int scale) +{ +static char *mant[] = + { "Reserved", "1.0", "1.2", "1.3", "1.5", "2.0", "2.5", "3.0", + "3.5", "4.0", "4.5", "5.0", "5.5", "6.0", "7.0", "8.0" }; +static char *exp[] = + { "1 ns", "10 ns", "100 ns", "1 us", "10 us", "100 us", + "1 ms", "10 ms" }; +static char *scale_name[] = + { "None", "10", "100", "1,000", "10,000", "100,000", + "1,000,000", "10,000,000" }; + + printf("Speed = %s x %s", mant[(x >> 3) & 0xF], exp[x & 7]); + if (scale) + printf(", scaled by %s", scale_name[scale & 7]); +} diff --git a/usr.sbin/pccard/pccardc/rdmap.c b/usr.sbin/pccard/pccardc/rdmap.c new file mode 100644 index 0000000..bfcce1f --- /dev/null +++ b/usr.sbin/pccard/pccardc/rdmap.c @@ -0,0 +1,71 @@ +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include <string.h> +#include <sys/ioctl.h> + +#include <pccard/card.h> +#include <pccard/cis.h> + +int +rdmap_main(argc, argv) +int argc; +char *argv[]; +{ +int node, mask; +struct card *cp; + + for (node = 0; node < 8; node++) + scan(node); + exit(0); +} +static scan(slot) +int slot; +{ +int fd, mask; +char blk[1024]; +char name[64]; +struct slotstate st; + + sprintf(name, "/dev/card%d", slot); + fd = open(name, 0); + if (fd < 0) + return; + ioctl(fd, PIOCGSTATE, &st); +/* + if (st.state == filled) + */ + { + dump_mem(fd, st.maxmem); + dump_io(fd, st.maxio); + } + 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; +{ +struct io_desc io; +int i; + + 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); + } +} diff --git a/usr.sbin/pccard/pccardc/rdreg.c b/usr.sbin/pccard/pccardc/rdreg.c new file mode 100644 index 0000000..c278ae5 --- /dev/null +++ b/usr.sbin/pccard/pccardc/rdreg.c @@ -0,0 +1,48 @@ +#include <stdio.h> +#include <sys/types.h> +#include <sys/ioctl.h> + +#include <pccard/card.h> +int +rdreg_main(argc, argv) +int argc; +char *argv[]; +{ + if (argc != 2) + { + dumpslot(0); + dumpslot(1); + } + else + dumpslot(atoi(argv[1])); +} +dumpslot(sl) +int sl; +{ +char name[64]; +int fd; +struct pcic_reg r; + + sprintf(name, "/dev/card%d", sl); + fd = open(name, 2); + if (fd < 0) + { + perror(name); + return; + } + printf("Registers for slot %d\n", sl); + for (r.reg = 0; r.reg < 0x40; r.reg++) + { + if (ioctl(fd, PIOCGREG, &r)) + { + perror("ioctl"); + break; + } + if ((r.reg % 16)==0) + printf("%02x:", r.reg); + printf(" %02x", r.value); + if ((r.reg % 16)==15) + printf("\n"); + } + close(fd); +} diff --git a/usr.sbin/pccard/pccardc/wrattr.c b/usr.sbin/pccard/pccardc/wrattr.c new file mode 100644 index 0000000..d8e980f --- /dev/null +++ b/usr.sbin/pccard/pccardc/wrattr.c @@ -0,0 +1,46 @@ +#include <stdio.h> +#include <sys/types.h> +#include <sys/ioctl.h> + +#include <pccard/card.h> + +int +wrattr_main(argc, argv) +int argc; +char *argv[]; +{ +int reg,value; +char name[64], c; +int fd; +off_t offs; + + if (argc != 4) + { + fprintf(stderr, "usage: wrmem slot offs value\n"); + exit(1); + } + sprintf(name, "/dev/card%d", atoi(argv[1])); + fd = open(name, 2); + if (fd < 0) + { + perror(name); + exit(1); + } + reg = MDF_ATTR; + if (ioctl(fd, PIOCRWFLAG, ®)) + { + perror("ioctl (PIOCRWFLAG)"); + exit(1); + } + if (sscanf(argv[2], "%x", ®) != 1 || + sscanf(argv[3], "%x", &value) != 1) + { + fprintf(stderr, "arg error\n"); + exit(1); + } + offs = reg; + c = value; + lseek(fd, offs, SEEK_SET); + if (write(fd, &c, 1) != 1) + perror(name); +} diff --git a/usr.sbin/pccard/pccardc/wrreg.c b/usr.sbin/pccard/pccardc/wrreg.c new file mode 100644 index 0000000..88a54ba --- /dev/null +++ b/usr.sbin/pccard/pccardc/wrreg.c @@ -0,0 +1,39 @@ +#include <stdio.h> +#include <sys/types.h> +#include <sys/ioctl.h> + +#include <pccard/card.h> + +int +wrreg_main(argc, argv) +int argc; +char *argv[]; +{ +int reg,value; +char name[64]; +int fd; +struct pcic_reg r; + + if (argc != 4) + { + fprintf(stderr, "usage: wrreg slot reg value\n"); + exit(1); + } + sprintf(name, "/dev/card%d", atoi(argv[1])); + fd = open(name, 2); + if (fd < 0) + { + perror(name); + exit(1); + } + if (sscanf(argv[2], "%x", ®) != 1 || + sscanf(argv[3], "%x", &value) != 1) + { + fprintf(stderr, "arg error\n"); + exit(1); + } + r.reg = reg; + r.value = value; + if (ioctl(fd, PIOCSREG, &r)) + perror("ioctl"); +} |