Index: pccardc/printcis.c =================================================================== RCS file: /home/ncvs/src/usr.sbin/pccard/pccardc/printcis.c,v retrieving revision 1.11 diff -u -r1.11 printcis.c --- pccardc/printcis.c 1999/08/28 01:17:33 1.11 +++ pccardc/printcis.c 2000/05/31 18:31:59 @@ -29,6 +29,12 @@ "$FreeBSD: src/usr.sbin/pccard/pccardc/printcis.c,v 1.11 1999/08/28 01:17:33 peter Exp $"; #endif /* not lint */ +/* + * Code cleanup, bug-fix and extension + * by Tatsumi Hosokawa + */ + +#include #include #include #include @@ -40,14 +46,20 @@ #include "readcis.h" -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); +static void dump_config_map(struct tuple *tp); +static void dump_cis_config(struct tuple *tp); +static void dump_other_cond(u_char *p, int len); +static void dump_device_desc(u_char *p, int len, char *type); +static void dump_info_v1(u_char *p, int len); +static void dump_longlink_mfc(u_char *p, int len); +static void dump_bar(u_char *p, int len); +static void dump_device_geo(u_char *p, int len); +static void dump_func_id(u_char *p); +static void dump_serial_ext(u_char *p, int len); +static void dump_disk_ext(u_char *p, int len); +static void dump_network_ext(u_char *p, int len); +static void dump_info_v2(u_char *p, int len); +static void dump_org(u_char *p, int len); void dumpcis(struct cis *cp) @@ -55,7 +67,8 @@ struct tuple *tp; struct tuple_list *tl; int count = 0, sz, ad, i; - unsigned char *p; + u_char *p; + int func = 0; for (tl = cp->tlist; tl; tl = tl->next) for (tp = tl->tuples; tp; tp = tp->next) { @@ -79,30 +92,32 @@ case CIS_MEM_COMMON: /* 0x01 */ dump_device_desc(tp->data, tp->length, "Common"); break; + case CIS_CONF_MAP_CB: /* 0x04 */ + dump_config_map(tp); + break; + case CIS_CONFIG_CB: /* 0x05 */ + dump_cis_config(tp); + break; + case CIS_LONGLINK_MFC: /* 0x06 */ + dump_longlink_mfc(tp->data, tp->length); + break; + case CIS_BAR: /* 0x07 */ + dump_bar(tp->data, tp->length); + 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"); + printf("\tChecksum from offset %d, length %d, value is 0x%x\n", + tpl16(tp->data), + tpl16(tp->data + 2), + tp->data[4]); 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]); + tpl32(tp->data)); 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; + tpl32(tp->data)); + break; case CIS_INFO_V1: /* 0x15 */ dump_info_v1(tp->data, tp->length); break; @@ -112,7 +127,6 @@ 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 */ @@ -122,111 +136,387 @@ 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); + dump_other_cond(tp->data, tp->length); break; case CIS_DEVICEGEO: /* 0x1E */ - break; case CIS_DEVICEGEO_A: /* 0x1F */ + dump_device_geo(tp->data, tp->length); 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]); + tpl16(tp->data), + tpl16(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; + func = tp->data[0]; + dump_func_id(tp->data); + break; + case CIS_FUNC_EXT: /* 0x22 */ + switch (func) { case 2: - printf("\tSerial port/modem"); - break; - case 3: - printf("\tParallel port"); + dump_serial_ext(tp->data, tp->length); break; case 4: - printf("\tFixed disk card"); + dump_disk_ext(tp->data, tp->length); break; - case 5: - printf("\tVideo adapter"); - break; case 6: - printf("\tNetwork/LAN adapter"); - break; - case 7: - printf("\tAIMS"); + dump_network_ext(tp->data, tp->length); 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 */ + dump_info_v2(tp->data, tp->length); + break; + case CIS_ORG: /* 0x46 */ + dump_org(tp->data, tp->length); break; } } } /* - * Dump configuration map tuple. + * CIS_CONF_MAP : Dump configuration map tuple. + * CIS_CONF_MAP_CB: Dump configuration map for CardBus */ -void +static void dump_config_map(struct tuple *tp) { - unsigned char *p, x; - int rlen, mlen; + u_char *p = tp->data, x; + int rlen, mlen = 0; 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%lx, last config = 0x%x\n", - rlen, u.l, tp->data[1]); - if (mlen) + + rlen = (p[0] & 3) + 1; + if (tp->code == CIS_CONF_MAP) + mlen = ((p[0] >> 2) & 3) + 1; + if (tp->length < rlen + mlen + 2) { + printf("\tWrong length for configuration map tuple\n"); + return; + } + printf("\tReg len = %d, config register addr = 0x%x, last config = 0x%x\n", + rlen, parse_num(rlen | 0x10, p + 2, &p, 0), p[1]); + if (mlen) { printf("\tRegisters: "); - for (i = 0; i < mlen; i++, p++) { - for (x = 0x1; x; x <<= 1) - printf("%c", x & *p ? 'X' : '-'); - printf(" "); + for (i = 0; i < mlen; i++, p++) { + for (x = 0x1; x; x <<= 1) + printf("%c", x & *p ? 'X' : '-'); + putchar(' '); + } + } + i = tp->length - (rlen + mlen + 2); + if (i) { + if (!mlen) + putchar('\t'); + printf("%d bytes in subtuples", i); } - printf("\n"); + if (mlen || i) + putchar('\n'); } /* - * Dump a config entry. + * Dump power descriptor. + * call from dump_cis_config() */ -void +static int +print_pwr_desc(u_char *p) +{ + int len = 1, i; + u_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); +} + +/* + * print_ext_speed - Print extended speed. + * call from dump_cis_config(), dump_device_desc() + */ +static void +print_ext_speed(u_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]); +} + +/* + * Print variable length value. + * call from print_io_map(), print_mem_map() + */ +static int +print_num(int sz, char *fmt, u_char *p, int ofs) +{ + switch (sz) { + case 0: + case 0x10: + return 0; + case 1: + case 0x11: + printf(fmt, *p + ofs); + return 1; + case 2: + case 0x12: + printf(fmt, tpl16(p) + ofs); + return 2; + case 0x13: + printf(fmt, tpl24(p) + ofs); + return 3; + case 3: + case 0x14: + printf(fmt, tpl32(p) + ofs); + return 4; + } + errx(1, "print_num(0x%x): Illegal arguments", sz); +/*NOTREACHED*/ +} + +/* + * Print I/O mapping sub-tuple. + * call from dump_cis_config() + */ +static u_char * +print_io_map(u_char *p, u_char *q) +{ + int i, j; + u_char c; + + if (q <= p) + goto err; + if (CIS_IO_ADDR(*p)) /* I/O address line */ + printf("\tCard decodes %d address lines", + CIS_IO_ADDR(*p)); + else + printf("\tCard provides address decode"); + + /* 8/16 bit I/O */ + switch (*p & (CIS_IO_8BIT | CIS_IO_16BIT)) { + case CIS_IO_8BIT: + printf(", 8 Bit I/O only"); + break; + case CIS_IO_16BIT: + printf(", limited 8/16 Bit I/O"); + break; + case (CIS_IO_8BIT | CIS_IO_16BIT): + printf(", full 8/16 Bit I/O"); + break; + } + putchar('\n'); + + /* I/O block sub-tuple exist */ + if (*p++ & CIS_IO_RANGE) { + if (q <= p) + goto err; + c = *p++; + /* calculate byte length */ + j = CIS_IO_ADSZ(c) + CIS_IO_BLKSZ(c); + if (CIS_IO_ADSZ(c) == 3) + j++; + if (CIS_IO_BLKSZ(c) == 3) + j++; + /* number of I/O block sub-tuples */ + for (i = 0; i <= CIS_IO_BLKS(c); i++) { + if (q - p < j) + goto err; + printf("\t\tI/O address # %d: ", i + 1); + /* start block address */ + p += print_num(CIS_IO_ADSZ(c), + "block start = 0x%x", p, 0); + /* block size */ + p += print_num(CIS_IO_BLKSZ(c), + " block length = 0x%x", p, 1); + putchar('\n'); + } + } + return p; + + err: /* warning */ + printf("\tWrong length for I/O mapping sub-tuple\n"); + return p; +} + +/* + * Print IRQ sub-tuple. + * call from dump_cis_config() + */ +static u_char * +print_irq_map(u_char *p, u_char *q) +{ + int i, j; + u_char c; + + if (q <= p) + goto err; + printf("\t\tIRQ modes:"); + c = ' '; + if (*p & CIS_IRQ_LEVEL) { /* Level triggered interrupts */ + printf(" Level"); + c = ','; + } + if (*p & CIS_IRQ_PULSE) { /* Pulse triggered requests */ + printf("%c Pulse", c); + c = ','; + } + if (*p & CIS_IRQ_SHARING) /* Interrupt sharing */ + printf("%c Shared", c); + putchar('\n'); + + /* IRQ mask values exist */ + if (*p & CIS_IRQ_MASK) { + if (q - p < 3) + goto err; + i = tpl16(p + 1); /* IRQ mask */ + 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); + putchar('\n'); + p += 3; + } else { + printf("\t\tIRQ level = %d\n", CIS_IRQ_IRQN(*p)); + p++; + } + return p; + + err: /* warning */ + printf("\tWrong length for IRQ sub-tuple\n"); + return p; +} + +/* + * Print memory map sub-tuple. + * call from dump_cis_config() + */ +static u_char * +print_mem_map(u_char feat, u_char *p, u_char *q) +{ + int i, j; + u_char c; + + switch (CIS_FEAT_MEMORY(feat)) { + + case CIS_FEAT_MEM_NONE: /* No memory block */ + break; + case CIS_FEAT_MEM_LEN: /* Specify memory length */ + if (q - p < 2) + goto err; + printf("\tMemory space length = 0x%x\n", tpl16(p)); + p += 2; + break; + case CIS_FEAT_MEM_ADDR: /* Memory address and length */ + if (q - p < 4) + goto err; + printf("\tMemory space address = 0x%x, length = 0x%x\n", + tpl16(p + 2), tpl16(p)); + p += 4; + break; + case CIS_FEAT_MEM_WIN: /* Memory descriptors. */ + if (q <= p) + goto err; + c = *p++; + /* calculate byte length */ + j = CIS_MEM_LENSZ(c) + CIS_MEM_ADDRSZ(c); + if (c & CIS_MEM_HOST) + j += CIS_MEM_ADDRSZ(c); + /* number of memory block */ + for (i = 0; i < CIS_MEM_WINS(c); i++) { + if (q - p < j) + goto err; + printf("\tMemory descriptor %d\n\t\t", i + 1); + /* memory length */ + p += print_num(CIS_MEM_LENSZ(c) | 0x10, + " blk length = 0x%x00", p, 0); + /* card address */ + p += print_num(CIS_MEM_ADDRSZ(c) | 0x10, + " card addr = 0x%x00", p, 0); + if (c & CIS_MEM_HOST) /* Host address value exist */ + p += print_num(CIS_MEM_ADDRSZ(c) | 0x10, + " host addr = 0x%x00", p, 0); + putchar('\n'); + } + break; + } + return p; + + err: /* warning */ + printf("\tWrong length for memory mapping sub-tuple\n"); + return p; +} + +/* + * CIS_CONFIG : Dump a config entry. + * CIS_CONFIG_CB: Dump a configuration entry for CardBus + */ +static void dump_cis_config(struct tuple *tp) { - unsigned char *p, feat; + u_char *p, *q, feat; int i, j; char c; p = tp->data; + q = p + tp->length; printf("\tConfig index = 0x%x%s\n", *p & 0x3F, - *p & 0x40 ? "(default)" : ""); - if (*p & 0x80) { + *p & 0x40 ? "(default)" : ""); + + /* Interface byte exists */ + if (tp->code == CIS_CONFIG && (*p & 0x80)) { p++; printf("\tInterface byte = 0x%x ", *p); - switch (*p & 0xF) { + switch (*p & 0xF) { /* Interface type */ default: printf("(reserved)"); break; @@ -245,265 +535,150 @@ break; } c = ' '; - if (*p & 0x10) { + if (*p & 0x10) { /* Battery voltage detect */ printf(" BVD1/2 active"); c = ','; } - if (*p & 0x20) { + if (*p & 0x20) { /* Write protect active */ printf("%c card WP active", c); /* Write protect */ c = ','; } - if (*p & 0x40) { + if (*p & 0x40) { /* RdyBsy active bit */ printf("%c +RDY/-BSY active", c); c = ','; } - if (*p & 0x80) + if (*p & 0x80) /* Wait signal required */ printf("%c wait signal supported", c); printf("\n"); } + + /* features byte */ p++; feat = *p++; - switch (CIS_FEAT_POWER(feat)) { + + /* Power structure sub-tuple */ + switch (CIS_FEAT_POWER(feat)) { /* Power sub-tuple(s) exists */ case 0: break; case 1: printf("\tVcc pwr:\n"); - p += dump_pwr_desc(p); + p += print_pwr_desc(p); break; case 2: printf("\tVcc pwr:\n"); - p += dump_pwr_desc(p); + p += print_pwr_desc(p); printf("\tVpp pwr:\n"); - p += dump_pwr_desc(p); + p += print_pwr_desc(p); break; case 3: printf("\tVcc pwr:\n"); - p += dump_pwr_desc(p); + p += print_pwr_desc(p); printf("\tVpp1 pwr:\n"); - p += dump_pwr_desc(p); + p += print_pwr_desc(p); printf("\tVpp2 pwr:\n"); - p += dump_pwr_desc(p); + p += print_pwr_desc(p); break; } - if (feat & CIS_FEAT_TIMING) { - i = CIS_WAIT_SCALE(*p); - j = CIS_READY_SCALE(*p); - p++; - if (i != 3) { + + /* Timing sub-tuple */ + if (tp->code == CIS_CONFIG && + (feat & CIS_FEAT_TIMING)) { /* Timing sub-tuple exists */ + i = *p++; + j = CIS_WAIT_SCALE(i); + if (j != 3) { printf("\tWait scale "); - print_ext_speed(*p, i); - while (*p & 0x80) - p++; + print_ext_speed(*p++, j); printf("\n"); } + j = CIS_READY_SCALE(i); if (j != 7) { printf("\tRDY/BSY scale "); - print_ext_speed(*p, j); - while (*p & 0x80) - p++; + print_ext_speed(*p++, j); printf("\n"); } - } - if (feat & CIS_FEAT_I_O) { - if (CIS_IO_ADDR(*p)) - printf("\tCard decodes %d address lines", - CIS_IO_ADDR(*p)); - else - printf("\tCard provides address decode"); - switch (CIS_MEM_ADDRSZ(*p)) { - 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; + j = CIS_RESERVED_SCALE(i); + if (j != 7) { + printf("\tExternal scale "); + print_ext_speed(*p++, j); + printf("\n"); } - printf("\n"); - if (*p & CIS_IO_RANGE) { + } + + /* I/O mapping sub-tuple */ + if (feat & CIS_FEAT_I_O) { /* I/O space sub-tuple exists */ + if (tp->code == CIS_CONFIG) + p = print_io_map(p, q); + else { /* CIS_CONFIG_CB */ + printf("\tI/O base:"); + for (i = 0; i < 8; i++) + if (*p & (1 << i)) + printf(" %d", i); + putchar('\n'); p++; - c = *p++; - for (i = 0; i <= CIS_IO_BLKS(c); i++) { - printf("\t\tI/O address # %d: ", i + 1); - switch (CIS_IO_ADSZ(c)) { - 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 (CIS_IO_BLKSZ(c)) { - 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 & CIS_FEAT_IRQ) { - printf("\t\tIRQ modes:"); - c = ' '; - if (*p & CIS_IRQ_LEVEL) { - printf(" Level"); - c = ','; - } - if (*p & CIS_IRQ_PULSE) { - printf("%c Pulse", c); - c = ','; - } - if (*p & CIS_IRQ_SHARING) - printf("%c Shared", c); - printf("\n"); - if (*p & CIS_IRQ_MASK) { - 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", CIS_IRQ_IRQN(*p)); + /* IRQ descriptor sub-tuple */ + if (feat & CIS_FEAT_IRQ) /* IRQ sub-tuple exists */ + p = print_irq_map(p, q); + + /* Memory map sub-tuple */ + if (CIS_FEAT_MEMORY(feat)) { /* Memory space sub-tuple(s) exists */ + if (tp->code == CIS_CONFIG) + p = print_mem_map(feat, p, q); + else { /* CIS_CONFIG_CB */ + printf("\tMemory base:"); + for (i = 0; i < 8; i++) + if (*p & (1 << i)) + printf(" %d", i); + putchar('\n'); p++; } } - switch (CIS_FEAT_MEMORY(feat)) { - 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 (CIS_MEM_LENSZ(c)) { - 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 (CIS_MEM_ADDRSZ(c)) { - 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; + /* Misc sub-tuple */ + if (feat & CIS_FEAT_MISC) { /* Miscellaneous sub-tuple exists */ + if (tp->code == CIS_CONFIG) { + printf("\tMax twin cards = %d\n", *p & 7); + printf("\tMisc attr:%s%s%s", + (*p & 8) ? " (Audio-BVD2)" : "", + (*p & 0x10) ? " (Read-only)" : "", + (*p & 0x20) ? " (Power down supported)" : ""); + if (*p++ & 0x80) { + printf(" (Ext byte = 0x%x)", *p); + p++; } - if (c & CIS_MEM_HOST) - 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"); + putchar('\n'); } - break; - } - if (feat & CIS_FEAT_MISC) { - 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++; + else { /* CIS_CONFIG_CB */ + printf("\tMisc attr:"); + printf("%s%s%s%s%s%s%s", + (*p & 1) ? " (Master)" : "", + (*p & 2) ? " (Invalidate)" : "", + (*p & 4) ? " (VGA palette)" : "", + (*p & 8) ? " (Parity)" : "", + (*p & 0x10) ? " (Wait)" : "", + (*p & 0x20) ? " (Serr)" : "", + (*p & 0x40) ? " (Fast back)" : ""); + if (*p++ & 0x80) { + printf("%s%s", + (*p & 1) ? " (Binary audio)" : "", + (*p & 2) ? " (pwm audio)" : ""); + p++; + } + putchar('\n'); } - printf("\n"); - p++; } } /* - * dump_other_cond - Dump other conditions. + * CIS_DEVICE_OC, CIS_DEVICE_OA: + * Dump other conditions for common/attribute memory */ -void -dump_other_cond(unsigned char *p) +static void +dump_other_cond(u_char *p, int len) { - if (p[0]) { + if (p[0] && len > 0) { printf("\t"); if (p[0] & 1) printf("(MWAIT)"); @@ -516,57 +691,12 @@ } /* - * Dump power descriptor. + * CIS_MEM_COMMON, CIS_MEM_ATTR: + * Common / Attribute memory descripter */ -int -dump_pwr_desc(unsigned char *p) +static void +dump_device_desc(u_char *p, int len, char *type) { - 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); -} - -void -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[] = @@ -581,7 +711,7 @@ int count = 0; while (*p != 0xFF && len > 0) { - unsigned char x; + u_char x; x = *p++; len -= 2; @@ -593,7 +723,7 @@ len--; if (*p) { printf("\t\t"); - print_ext_speed(*p, 0); + print_ext_speed(*p++, 0); while (*p & 0x80) { p++; len--; @@ -609,45 +739,86 @@ } /* - * Print version info + * CIS_INFO_V1: Print version-1 info */ -void -dump_info_v1(unsigned char *p, int len) +static void +dump_info_v1(u_char *p, int len) { + if (len < 2) { + printf("\tWrong length for version-1 info tuple\n"); + return; + } printf("\tVersion = %d.%d", p[0], p[1]); p += 2; - printf(", Manuf = [%s],", p); - while (*p++); - printf("card vers = [%s]\n", p); - while (*p++); - if (*p == 0xff) + len -= 2; + if (len > 1 && *p != 0xff) { + printf(", Manuf = [%s]", p); + while (*p++ && --len > 0); + } + if (len > 1 && *p != 0xff) { + printf(", card vers = [%s]", p); + while (*p++ && --len > 0); + } else { + printf("\n\tWrong length for version-1 info tuple\n"); return; - printf("\tAddit. info = [%s]", p); - while (*p++); - while (*p != 0xff) { - printf(",[%s]", p); - while (*p++); + } + putchar('\n'); + if (len > 1 && *p != 0xff) { + printf("\tAddit. info = [%.*s]", len, p); + while (*p++ && --len > 0); + if (len > 1 && *p != 0xff) + printf(",[%.*s]", len, p); + putchar('\n'); } - printf("\n"); } /* - * dump functional extension tuple. + * CIS_FUNC_ID: Functional ID */ -void -dump_func_ext(unsigned char *p, int len) +static void +dump_func_id(u_char *p) +{ + static char *id[] = { + "Multifunction card", + "Memory card", + "Serial port/modem", + "Parallel port", + "Fixed disk card", + "Video adapter", + "Network/LAN adapter", + "AIMS", + "SCSI card", + "Security" + }; + + printf("\t%s%s%s\n", + (*p <= 9) ? id[*p] : "Unknown function", + (p[1] & 1) ? " - POST initialize" : "", + (p[1] & 2) ? " - Card has ROM" : ""); +} + +/* + * CIS_FUNC_EXT: Dump functional extension tuple. + * (Serial port/modem) + */ +static void +dump_serial_ext(u_char *p, int len) { - if (len == 0) + static char *type[] = { + "", "Modem", "Data", "Fax", "Voice", "Data modem", + "Fax/modem", "Voice", " (Data)", " (Fax)", " (Voice)" + }; + + if (len < 1) 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"); + case 0: /* Serial */ + case 8: /* Data */ + case 9: /* Fax */ + case 10: /* Voice */ + printf("\tSerial interface extension:%s\n", type[*p]); + if (len < 4) + goto err; switch (p[1] & 0x1F) { default: printf("\t\tUnkn device"); @@ -662,48 +833,275 @@ 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"); + printf(", Parity - %s%s%s%s\n", + (p[2] & 1) ? "Space," : "", + (p[2] & 2) ? "Mark," : "", + (p[2] & 4) ? "Odd," : "", + (p[2] & 8) ? "Even" : ""); + printf("\t\tData bit - %s%s%s%s Stop bit - %s%s%s\n", + (p[3] & 1) ? "5bit," : "", + (p[3] & 2) ? "6bit," : "", + (p[3] & 4) ? "7bit," : "", + (p[3] & 8) ? "8bit," : "", + (p[3] & 0x10) ? "1bit," : "", + (p[3] & 0x20) ? "1.5bit," : "", + (p[3] & 0x40) ? "2bit" : ""); break; - case 1: - case 5: - case 6: - case 7: - printf("\tModem interface capabilities:\n"); + case 1: /* Serial */ + case 5: /* Data */ + case 6: /* Fax */ + case 7: /* Voice */ + printf("\t%s interface capabilities:\n", type[*p]); + if (len < 9) + goto err; break; - case 2: + case 2: /* Data */ printf("\tData modem services available:\n"); break; - case 9: - printf("\tFax/modem services available:\n"); + case 0x13: /* Fax1 */ + case 0x23: /* Fax2 */ + case 0x33: /* Fax3 */ + printf("\tFax%d/modem services available:\n", *p >> 4); break; - case 4: + case 0x84: /* Voice */ printf("\tVoice services available:\n"); break; + err: /* warning */ + printf("\tWrong length for serial extension tuple\n"); + return; } } /* - * print_ext_speed - Print extended speed. + * CIS_FUNC_EXT: Dump functional extension tuple. + * (Fixed disk card) */ -void -print_ext_speed(unsigned char x, int scale) +static void +dump_disk_ext(u_char *p, int len) { - 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"}; + if (len < 1) + return; + switch (p[0]) { + case 1: /* IDE interface */ + if (len < 2) + goto err; + printf("\tDisk interface: %s\n", + (p[1] & 1) ? "IDE" : "Undefined"); + break; + case 2: /* Master */ + case 3: /* Slave */ + if (len < 3) + goto err; + printf("\tDisk features: %s, %s%s\n", + (p[1] & 0x04) ? "Silicon" : "Rotating", + (p[1] & 0x08) ? "Unique, " : "", + (p[1] & 0x10) ? "Dual" : "Single"); + if (p[2] & 0x7f) + printf("\t\t%s%s%s%s%s%s%s\n", + (p[2] & 0x01) ? "Sleep, " : "", + (p[2] & 0x02) ? "Standby, " : "", + (p[2] & 0x04) ? "Idle, " : "", + (p[2] & 0x08) ? "Low power, " : "", + (p[2] & 0x10) ? "Reg inhibit, " : "", + (p[2] & 0x20) ? "Index, " : "", + (p[2] & 0x40) ? "Iois16" : ""); + break; + err: /* warning */ + printf("\tWrong length for fixed disk extension tuple\n"); + return; + } +} - printf("Speed = %s x %s", mant[(x >> 3) & 0xF], exp[x & 7]); - if (scale) - printf(", scaled by %s", scale_name[scale & 7]); +static void +print_speed(u_int i) +{ + if (i < 1000) + printf("%u bits/sec", i); + else if (i < 1000000) + printf("%u kb/sec", i / 1000); + else + printf("%u Mb/sec", i / 1000000); +} + +/* + * CIS_FUNC_EXT: Dump functional extension tuple. + * (Network/LAN adapter) + */ +static void +dump_network_ext(u_char *p, int len) +{ + static const char *tech[] = { + "Undefined", "ARCnet", "Ethernet", "Token ring", + "Localtalk", "FDDI/CDDI", "ATM", "Wireless" + }; + static const char *media[] = { + "Undefined", "UTP", "STP", "Thin coax", + "THICK coax", "Fiber", "900 MHz", "2.4 GHz", + "5.4 GHz", "Diffuse Infrared", "Point to point Infrared" + }; + u_int i = 0; + + if (len < 1) + return; + switch (p[0]) { + case 1: /* Network technology */ + if (len < 2) + goto err; + printf("\tNetwork technology: %s\n", tech[p[1] & 7]); + break; + case 2: /* Network speed */ + if (len < 5) + goto err; + printf("\tNetwork speed: "); + print_speed(tpl32(p + 1)); + putchar('\n'); + break; + case 3: /* Network media */ + if (len < 2) + goto err; + if (p[1] <= 10) + i = p[1]; + printf("\tNetwork media: %s\n", media[i]); + break; + case 4: /* Node ID */ + if (len <= 2 || len < p[1] + 2) + goto err; + printf("\tNetwork node ID:"); + for (i = 0; i < p[1]; i++) + printf(" %02x", p[i + 2]); + putchar('\n'); + break; + case 5: /* Connecter type */ + if (len < 2) + goto err; + printf("\tNetwork connector: %s connector standard\n", + (p[1] == 0) ? "open" : "closed"); + break; + err: /* warning */ + printf("\tWrong length for network extension tuple\n"); + return; + } +} + +/* + * CIS_LONGLINK_MFC: Long link to next chain for Multi function card + */ +static void +dump_longlink_mfc(u_char *p, int len) +{ + u_int i, n = *p++; + + --len; + for (i = 0; i < n; i++) { + if (len < 5) { + printf("\tWrong length for long link MFC tuple\n"); + return; + } + printf("\tFunction %d: %s memory, address 0x%x\n", + i, (*p ? "common" : "attribute"), tpl32(p + 1)); + p += 5; + len -= 5; + } +} + +/* + * CIS_DEVICEGEO, CIS_DEVICEGEO_A: + * Geometry info for common/attribute memory + */ +static void +dump_device_geo(u_char *p, int len) +{ + while (len >= 6) { + printf("\twidth = %d, erase = 0x%x, read = 0x%x, write = 0x%x\n" + "\t\tpartition = 0x%x, interleave = 0x%x\n", + p[0], 1 << (p[1] - 1), + 1 << (p[2] - 1), 1 << (p[3] - 1), + 1 << (p[4] - 1), 1 << (p[5] - 1)); + len -= 6; + } +} + +/* + * CIS_INFO_V2: Print version-2 info + */ +static void +dump_info_v2(u_char *p, int len) +{ + if (len < 9) { + printf("\tWrong length for version-2 info tuple\n"); + return; + } + printf("\tVersion = 0x%x, compliance = 0x%x, dindex = 0x%x\n", + p[0], p[1], tpl16(p + 2)); + printf("\tVspec8 = 0x%x, vspec9 = 0x%x, nhdr = %d\n", + p[6], p[7], p[8]); + p += 9; + len -= 9; + if (len <= 1 || *p == 0xff) + return; + printf("\tVendor = [%.*s]", len, p); + while (*p++ && --len > 0); + if (len > 1 && *p != 0xff) + printf(", info = [%.*s]", len, p); + putchar('\n'); +} + +/* + * CIS_ORG: Organization + */ +static void +dump_org(u_char *p, int len) +{ + if (len < 1) { + printf("\tWrong length for organization tuple\n"); + return; + } + switch (*p) { + case 0: + printf("\tFilesystem"); + break; + case 1: + printf("\tApp specific"); + break; + case 2: + printf("\tCode"); + break; + default: + if (*p < 0x80) + printf("\tReserved"); + else + printf("\tVendor specific"); + break; + } + printf(" [%.*s]\n", len - 1, p + 1); +} + +static void +print_size(u_int i) +{ + if (i < 1024) + printf("%ubits", i); + else if (i < 1024*1024) + printf("%ukb", i / 1024); + else + printf("%uMb", i / (1024*1024)); +} + +/* + * CIS_BAR: Base address register for CardBus + */ +static void +dump_bar(u_char *p, int len) +{ + if (len < 6) { + printf("\tWrong length for BAR tuple\n"); + return; + } + printf("\tBAR %d: size = ", *p & 7); + print_size(tpl32(p + 2)); + printf(", %s%s%s%s\n", + (*p & 0x10) ? "I/O" : "Memory", + (*p & 0x20) ? ", Prefetch" : "", + (*p & 0x40) ? ", Cacheable" : "", + (*p & 0x80) ? ", <1Mb" : ""); } Index: pccardd/cardd.c =================================================================== RCS file: /home/ncvs/src/usr.sbin/pccard/pccardd/cardd.c,v retrieving revision 1.46.2.2 diff -u -r1.46.2.2 cardd.c --- pccardd/cardd.c 2000/05/09 22:04:31 1.46.2.2 +++ pccardd/cardd.c 2000/05/31 18:31:59 @@ -36,6 +36,7 @@ #include #include #include +#include #include #include "cardd.h" @@ -206,6 +207,48 @@ pool_irq[sp->irq] = 1; } +/* CIS string comparison */ + +#define REGCOMP_FLAGS (REG_EXTENDED | REG_NOSUB) +#define REGEXEC_FLAGS (0) + +static int +cis_strcmp(char *db, char *cis) +{ + int res, err; + char buf[256]; + regex_t rx; + char * p; + size_t n; + + if (!db || !cis) { + return -1; + } + n = strlen(db); + if (n > 2 && db[0] == '/' && db[n-1] == '/') { + /* matching by regex */ + db++; + } else { + /* otherwise, matching by strncmp() */ + return strncmp(db, cis, n); + } + p = xmalloc(n); + strncpy(p + 1, db, n-2); + *p = '^'; + db = p; + if ((err = regcomp(&rx, p, REGCOMP_FLAGS))) { + regerror(err, &rx, buf, sizeof buf); + logmsg("Warning: REGEX error for\"%s\" -- %s\n", p, buf); + regfree(&rx); + free(p); + return -1; + } + res = regexec(&rx, cis, 0, NULL, REGEXEC_FLAGS); + regfree(&rx); + free(p); + return res; +} + /* * card_inserted - Card has been inserted; * - Read the CIS @@ -235,13 +278,25 @@ for (cp = cards; cp; cp = cp->next) { switch (cp->deftype) { case DT_VERS: - if (strncmp(cp->manuf, sp->cis->manuf, CIS_MAXSTR) == 0 && - strncmp(cp->version, sp->cis->vers, CIS_MAXSTR) == 0) { + if (cis_strcmp(cp->manuf, sp->cis->manuf) == 0 && + cis_strcmp(cp->version, sp->cis->vers) == 0) { + if (cp->add_info1 != NULL && + cis_strcmp(cp->add_info1, sp->cis->add_info1) != 0) { + break; + } + if (cp->add_info2 != NULL && + cis_strcmp(cp->add_info2, sp->cis->add_info2) != 0) { + break; + } + logmsg("Card \"%s\"(\"%s\") " - "matched \"%s\" (\"%s\") ", - sp->cis->manuf, sp->cis->vers, - cp->manuf, cp->version - ); + "[%s] [%s] " + "matched \"%s\" (\"%s\") " + "[%s] [%s] ", + sp->cis->manuf, sp->cis->vers, + sp->cis->add_info1, sp->cis->add_info2, + cp->manuf, cp->version, + cp->add_info1, cp->add_info2); goto escape; } break; @@ -271,6 +326,13 @@ sp->cis->manuf, sp->cis->vers); return; } + if (sp->cis->lan_nid && sp->cis->lan_nid[0] == sizeof(sp->eaddr)) { + bcopy(sp->cis->lan_nid + 1, sp->eaddr, sizeof(sp->eaddr)); + sp->flags |= EADDR_CONFIGED; + } else { + bzero(sp->eaddr, sizeof(sp->eaddr)); + } + if (cp->ether) { struct ether *e = 0; e = cp->ether; @@ -311,7 +373,9 @@ read_ether(struct slot *sp) { unsigned char net_addr[12]; + int flags = MDF_ATTR; /* attribute memory */ + ioctl(sp->fd, PIOCRWFLAG, &flags); lseek(sp->fd, (off_t)sp->card->ether->value, SEEK_SET); if (read(sp->fd, net_addr, sizeof(net_addr)) != sizeof(net_addr)) { logerr("read err on net addr"); @@ -326,6 +390,7 @@ logmsg("Ether=%02x:%02x:%02x:%02x:%02x:%02x\n", sp->eaddr[0], sp->eaddr[1], sp->eaddr[2], sp->eaddr[3], sp->eaddr[4], sp->eaddr[5]); + sp->flags |= EADDR_CONFIGED; } /* @@ -494,7 +559,9 @@ * Found a matching configuration. Now look at the I/O, memory and IRQ * to create the desired parameters. Look at memory first. */ - if (cisconf->memspace || (defconf && defconf->memspace)) { + if (!(strncmp(sp->config->driver->name, "ed", 2) == 0 + && (sp->config->flags & 0x10)) + && (cisconf->memspace || (defconf && defconf->memspace))) { struct cis_memblk *mp; mp = cisconf->mem; @@ -528,6 +595,9 @@ if (cisconf->iospace || (defconf && defconf->iospace) || sp->card->iosize) { struct cis_config *cp; + struct cis_ioblk *cio; + struct allocblk *sio; + int x, xmax; int iosize; cp = cisconf; @@ -551,49 +621,61 @@ * If no address (but a length) is available, allocate * from the pool. */ - if (iosize) { - sp->io.addr = 0; - sp->io.size = iosize; - } - else if (cp->io) { - sp->io.addr = cp->io->addr; - sp->io.size = cp->io->size; - } else { - /* - * No I/O block, assume the address lines - * decode gives the size. - */ - sp->io.size = 1 << cp->io_addr; - } - if (sp->io.addr == 0) { - int i = bit_fns(io_avail, IOPORTS, sp->io.size); - - if (i < 0) - return (-1); - sp->io.addr = i; - } - bit_nclear(io_avail, sp->io.addr, - sp->io.addr + sp->io.size - 1); - sp->flags |= IO_ASSIGNED; - - /* Set up the size to take into account the decode lines. */ - sp->io.cardaddr = cp->io_addr; - switch (cp->io_bus) { - case 0: - break; - case 1: - sp->io.flags = IODF_WS; - break; - case 2: - sp->io.flags = IODF_WS | IODF_CS16; - break; - case 3: - sp->io.flags = IODF_WS | IODF_CS16 | IODF_16BIT; - break; - } - if (debug_level > 0) { - logmsg("Using I/O addr 0x%x, size %d\n", - sp->io.addr, sp->io.size); + cio = cp->io; + sio = &(sp->io); + xmax = 1; + if (cio) + xmax = cisconf->io_blks; + for (x = 0; x < xmax; x++) { + if (iosize) { + sio->addr = 0; + sio->size = iosize; + } else if (cio) { + sio->addr = cio->addr; + sio->size = cio->size; + } else { + /* + * No I/O block, assume the address lines + * decode gives the size. + */ + 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); + } + sio->addr = i; + } + bit_nclear(io_avail, sio->addr, + sio->addr + sio->size - 1); + sp->flags |= IO_ASSIGNED; + + /* Set up the size to take into account the decode lines. */ + sio->cardaddr = cp->io_addr; + switch (cp->io_bus) { + case 0: + break; + case 1: + sio->flags = IODF_WS; + break; + case 2: + sio->flags = IODF_WS | IODF_CS16; + break; + case 3: + sio->flags = IODF_WS | IODF_CS16 | IODF_16BIT; + break; + } + if (debug_level > 0) { + logmsg("Using I/O addr 0x%x, size %d\n", + sio->addr, sio->size); + } + if (cio && cio->next) { + sio->next = xmalloc(sizeof(*sio)); + sio = sio->next; + cio = cio->next; + } } } sp->irq = sp->config->irq; @@ -612,10 +694,12 @@ struct io_desc io; struct dev_desc drv; struct driver *drvp = sp->config->driver; + struct allocblk *sio; char *p; char c; off_t offs; int rw_flags; + int iowin; memset(&io, 0, sizeof io); memset(&drv, 0, sizeof drv); @@ -665,11 +749,14 @@ return (0); } } - io.window = 0; if (sp->flags & IO_ASSIGNED) { - io.flags = sp->io.flags; - io.start = sp->io.addr; - io.size = sp->io.size; + for (iowin = 0, sio = &(sp->io); iowin <= 1; iowin++) { + io.window = iowin; + if (sio->size) { + io.flags = sio->flags; + io.start = sio->addr; + io.size = sio->size; + } #if 0 io.start = sp->io.addr & ~((1 << sp->io.cardaddr) - 1); io.size = 1 << sp->io.cardaddr; @@ -688,6 +775,21 @@ logerr("ioctl (PIOCSIO)"); return (0); } + if (ioctl(sp->fd, PIOCGIO, &io)) + { + logerr("ioctl (PIOCGIO)"); + return(0); + } + if (io.start != sio->addr){ + logmsg("I/O base address changed from 0x%x to 0x%x\n", + sio->addr, io.start); + sio->addr = io.start; + } + if (sio->next) + sio = sio->next; + else + break; + } } strcpy(drv.name, drvp->kernel); drv.unit = drvp->unit; Index: pccardd/cardd.h =================================================================== RCS file: /home/ncvs/src/usr.sbin/pccard/pccardd/cardd.h,v retrieving revision 1.18.2.1 diff -u -r1.18.2.1 cardd.h --- pccardd/cardd.h 2000/04/15 10:56:20 1.18.2.1 +++ pccardd/cardd.h 2000/05/31 18:31:59 @@ -67,6 +67,8 @@ struct card *next; char *manuf; char *version; + char *add_info1; + char *add_info2; u_char func_id; int deftype; struct ether *ether; /* For net cards, ether at offset */ @@ -157,7 +159,7 @@ /* util.c functions */ unsigned long alloc_memory(int); -int bit_fns(bitstr_t *, int, int); +int bit_fns(bitstr_t *, int, int, int); void die(char *); void execute(struct cmd *, struct slot *); void logmsg(const char *, ...); Index: pccardd/file.c =================================================================== RCS file: /home/ncvs/src/usr.sbin/pccard/pccardd/file.c,v retrieving revision 1.24.2.1 diff -u -r1.24.2.1 file.c --- pccardd/file.c 2000/04/15 10:56:20 1.24.2.1 +++ pccardd/file.c 2000/05/31 18:31:59 @@ -123,10 +123,14 @@ struct cmd *cmdp, *cmd_next; /* free characters */ - if (cp->manuf[0] != NULL) + if (cp->manuf != NULL) free(cp->manuf); - if (cp->version[0] != NULL) + if (cp->version != NULL) free(cp->version); + if (cp->add_info1 != NULL) + free(cp->add_info1); + if (cp->add_info2 != NULL) + free(cp->add_info2); /* free structures */ for (etherp = cp->ether; etherp; etherp = ether_next) { @@ -395,6 +399,7 @@ parse_card(int deftype) { char *man, *vers, *tmp; + char *add_info; unsigned char index_type; struct card *cp; int i, iosize; @@ -408,13 +413,30 @@ case DT_VERS: man = newstr(next_tok()); vers = newstr(next_tok()); + add_info = newstr(next_tok()); + if (keyword(add_info)) { + pusht = 1; + free(add_info); + cp->add_info1 = NULL; + cp->add_info2 = NULL; + } else { + cp->add_info1 = add_info; + add_info = newstr(next_tok()); + if (keyword(add_info)) { + pusht = 1; + free(add_info); + cp->add_info2 = NULL; + } else { + cp->add_info2 = add_info; + } + } cp->manuf = man; cp->version = vers; cp->func_id = 0; break; case DT_FUNC: - cp->manuf = ""; - cp->version = ""; + cp->manuf = NULL; + cp->version = NULL; cp->func_id = (u_char) func_tok(); break; default: Index: pccardd/pccard.conf.5 =================================================================== RCS file: /home/ncvs/src/usr.sbin/pccard/pccardd/pccard.conf.5,v retrieving revision 1.12.2.1 diff -u -r1.12.2.1 pccard.conf.5 --- pccardd/pccard.conf.5 2000/04/15 10:56:21 1.12.2.1 +++ pccardd/pccard.conf.5 2000/05/31 18:31:59 @@ -141,7 +141,7 @@ .Ss "Card Identifiers" The syntax for card identifiers is: .Pp -.Dl card Ar manufacturer version +.Dl card Ar manufacturer version [ add_info1 [ add_info2 ]] .Dl config Ar index driver interrupt [ flags ] .Dl ether Ar offset .Dl insert Ar command @@ -155,8 +155,14 @@ lines. The .Em card -parameters are the Manufacturer name and card version that +parameters are the Manufacturer name, card version and +additional information add_info1, add_info2 that is used to match the values from the card's CIS memory. +These parameter can be described in extended regular expression +.Xr regex 3 +if the string is enclosed by '/' like "/.*/". +Each of the expressions is evaluated with a character '^' at top. +.Pp The .Em config parameters select the particular card's configuration index Index: pccardd/readcis.c =================================================================== RCS file: /home/ncvs/src/usr.sbin/pccard/pccardd/readcis.c,v retrieving revision 1.17.2.1 diff -u -r1.17.2.1 readcis.c --- pccardd/readcis.c 2000/04/15 10:56:21 1.17.2.1 +++ pccardd/readcis.c 2000/05/31 18:31:59 @@ -29,6 +29,11 @@ "$FreeBSD: src/usr.sbin/pccard/pccardd/readcis.c,v 1.17.2.1 2000/04/15 10:56:21 iwasaki Exp $"; #endif /* not lint */ +/* + * Code cleanup, bug-fix and extension + * by Tatsumi Hosokawa + */ + #include #include #include @@ -41,6 +46,10 @@ #include "readcis.h" +#ifdef RATOCLAN +static int rex5588 = 0; +#endif + static int read_attr(int, char *, int); static int ck_linktarget(int, off_t, int); static void cis_info(struct cis *, unsigned char *, int); @@ -48,6 +57,7 @@ static void config_map(struct cis *, unsigned char *, int); static void cis_config(struct cis *, unsigned char *, int); static void cis_func_id(struct cis *, unsigned char *, int); +static void cis_network_ext(struct cis *, unsigned char *, int); static struct tuple_list *read_one_tuplelist(int, int, off_t); static struct tuple_list *read_tuples(int); static struct tuple *find_tuple_in_list(struct tuple_list *, unsigned char); @@ -56,6 +66,12 @@ static struct tuple_info tuple_info[] = { {"Null tuple", 0x00, 0}, {"Common memory descriptor", 0x01, 255}, + {"Long link to next chain for CardBus", 0x02, 255}, + {"Indirect access", 0x03, 255}, + {"Configuration map for CardBus", 0x04, 255}, + {"Configuration entry for CardBus", 0x05, 255}, + {"Long link to next chain for MFC", 0x06, 255}, + {"Base address register for CardBus", 0x07, 6}, {"Checksum", 0x10, 5}, {"Long link to attribute memory", 0x11, 4}, {"Long link to common memory", 0x12, 4}, @@ -73,7 +89,7 @@ {"Geometry info for common memory", 0x1E, 255}, {"Geometry info for attribute memory", 0x1F, 255}, {"Manufacturer ID", 0x20, 4}, - {"Functional ID", 0x21, 255}, + {"Functional ID", 0x21, 2}, {"Functional EXT", 0x22, 255}, {"Software interleave", 0x23, 2}, {"Version 2 Info", 0x40, 255}, @@ -82,8 +98,8 @@ {"Byte order", 0x43, 2}, {"Card init date", 0x44, 4}, {"Battery replacement", 0x45, 4}, - {"Organisation", 0x46, 255}, - {"Terminator", 0xFF, 255}, + {"Organization", 0x46, 255}, + {"Terminator", 0xFF, 0}, {0, 0, 0} }; @@ -104,7 +120,7 @@ for (tl = cp->tlist; tl; tl = tl->next) for (tp = tl->tuples; tp; tp = tp->next) { -#if 0 +#if DEBUG printf("tuple code = 0x%02x, data is\n", tp->code); dump(tp->data, tp->length); #endif @@ -124,10 +140,13 @@ case CIS_CONFIG: /* 0x1B */ cis_config(cp, tp->data, tp->length); break; - case CIS_FUNC_ID: /* 0x21 */ + case CIS_FUNC_ID: /* 0x21 */ cis_func_id(cp, tp->data, tp->length); break; - + case CIS_FUNC_EXT: /* 0x22 */ + if (cp->func_id1 == 6) /* LAN adaptor */ + cis_network_ext(cp, tp->data, tp->length); + break; } } return (cp); @@ -175,19 +194,45 @@ static void cis_info(struct cis *cp, unsigned char *p, int len) { - *cp->manuf = *cp->vers = *cp->add_info1 = *cp->add_info2 = '\0'; cp->maj_v = *p++; cp->min_v = *p++; - strncpy(cp->manuf, p, CIS_MAXSTR - 1); - while (*p++); - strncpy(cp->vers, p, CIS_MAXSTR - 1); - while (*p++); - strncpy(cp->add_info1, p, CIS_MAXSTR - 1); - while (*p++); - strncpy(cp->add_info2, p, CIS_MAXSTR - 1); + len -= 2; + if (cp->manuf) { + free(cp->manuf); + cp->manuf = NULL; + } + if (len > 1 && *p != 0xff) { + cp->manuf = strdup(p); + while (*p++ && --len > 0); + } + if (cp->vers) { + free(cp->vers); + cp->vers = NULL; + } + if (len > 1 && *p != 0xff) { + cp->vers = strdup(p); + while (*p++ && --len > 0); + } else { + cp->vers = strdup("?"); + } + if (cp->add_info1) { + free(cp->add_info1); + cp->add_info1 = NULL; + } + if (len > 1 && *p != 0xff) { + cp->add_info1 = strdup(p); + while (*p++ && --len > 0); + } + if (cp->add_info2) { + free(cp->add_info2); + cp->add_info2 = NULL; + } + if (len > 1 && *p != 0xff) + cp->add_info2 = strdup(p); } + /* - * Fills in CIS function ID. + * Fills in CIS function ID. */ static void cis_func_id(struct cis *cp, unsigned char *p, int len) @@ -196,6 +241,88 @@ cp->func_id2 = *p++; } +static void +cis_network_ext(struct cis *cp, unsigned char *p, int len) +{ + int i; + + switch (p[0]) { + case 4: /* Node ID */ + if (len <= 2 || len < p[1] + 2) + return; + + if (cp->lan_nid) + free(cp->lan_nid); + cp->lan_nid = xmalloc(p[1]); + + for (i = 0; i <= p[1]; i++) + cp->lan_nid[i] = p[i + 1]; + break; + } +} + +/* + * "FUJITSU LAN Card (FMV-J182)" has broken CIS + */ +static int +fmvj182_check(unsigned char *p) +{ + char manuf[BUFSIZ], vers[BUFSIZ]; + + p++; /* major version */ + p++; /* minor version */ + strncpy(manuf, p, sizeof(manuf) - 1); + while (*p++); + strncpy(vers, p, sizeof(vers) - 1); + if (!strcmp(manuf, "FUJITSU") && !strcmp(vers, "LAN Card(FMV-J182)")) + return 1; + else + return 0; +} + +#ifdef RATOCLAN +/* + * "RATOC LAN Card (REX-5588)" has broken CIS + */ +static int +rex5588_check(unsigned char *p) +{ + char manuf[BUFSIZ], vers[BUFSIZ]; + + p++; /* major version */ + p++; /* minor version */ + strncpy(manuf, p, sizeof(manuf) - 1); + while (*p++); + strncpy(vers, p, sizeof(manuf) - 1); + if (!strcmp(manuf, "PCMCIA LAN MBH10304 ES")) + return 1; + else + return 0; +} +#endif + +#ifdef HSSYNTH +/* + * Broken CIS for "HITACHI MICROCOMPUTER SYSTEM LTD." "MSSHVPC02" + */ +static int +hss_check(unsigned char *p) +{ + char manuf[BUFSIZ], vers[BUFSIZ]; + + p++; /* major version */ + p++; /* minor version */ + strncpy(manuf, p, sizeof(manuf) - 1); + while (*p++); + strncpy(vers, p, sizeof(vers) - 1); + if (!strcmp(manuf, "HITACHI MICROCOMPUTER SYSTEMS LTD.") + && !strcmp(vers, "MSSHVPC02")) + return 1; + else + return 0; +} +#endif /* HSSYNTH */ + /* * device_desc - decode device descriptor. */ @@ -209,7 +336,7 @@ dp->speed = *p & 7; p++; if (*p != 0xFF) { - dp->addr = *p >> 3; + dp->addr = (*p >> 3) & 0xF; dp->units = *p & 7; } p++; @@ -224,22 +351,51 @@ config_map(struct cis *cp, unsigned char *p, int len) { unsigned char *p1; - int i; - union { - unsigned long l; - unsigned char b[4]; - } u; + int rlen = (*p & 3) + 1; p1 = p + 1; cp->last_config = *p1++ & 0x3F; - u.l = 0; - for (i = 0; i <= (*p & 3); i++) - u.b[i] = *p1++; - cp->reg_addr = u.l; + cp->reg_addr = parse_num(rlen | 0x10, p1, &p1, 0); cp->ccrs = *p1; } /* + * Parse variable length value. + */ +u_int +parse_num(int sz, u_char *p, u_char **q, int ofs) +{ + u_int num = 0; + + switch (sz) { + case 0: + case 0x10: + break; + case 1: + case 0x11: + num = (*p++) + ofs; + break; + case 2: + case 0x12: + num = tpl16(p) + ofs; + p += 2; + break; + case 0x13: + num = tpl24(p) + ofs; + p += 3; + break; + case 3: + case 0x14: + num = tpl32(p) + ofs; + p += 4; + break; + } + if (q) + *q = p; + return num; +} + +/* * CIS config entry - Decode and build configuration entry. */ static void @@ -247,14 +403,8 @@ { int x; int i, j; - union { - unsigned long l; - unsigned char b[4]; - } u; 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) != 0) { @@ -263,12 +413,16 @@ last->next = conf; } else cp->conf = conf; - conf->id = *p & 0x3F; - if (*p & 0x40) + conf->id = *p & 0x3F; /* Config index */ +#ifdef RATOCLAN + if (rex5588 && conf->id >= 0x08 && conf->id <= 0x1d) + conf->id |= 0x20; +#endif + if (*p & 0x40) /* Default flag */ cp->def_config = conf; if (*p++ & 0x80) - p++; - feat = *p++; + p++; /* Interface byte skip */ + feat = *p++; /* Features byte */ for (i = 0; i < CIS_FEAT_POWER(feat); i++) { unsigned char parms = *p++; @@ -292,59 +446,22 @@ if (CIS_IO_RANGE & *p) conf->io_blks = CIS_IO_BLKS(p[1]) + 1; conf->io_addr = CIS_IO_ADDR(*p); - conf->io_bus = (*p >> 5) & 3; + conf->io_bus = (*p >> 5) & 3; /* CIS_IO_8BIT | CIS_IO_16BIT */ if (*p++ & CIS_IO_RANGE) { - struct cis_ioblk *io, *last = 0; + struct cis_ioblk *io; + struct cis_ioblk *last_io = NULL; + i = CIS_IO_ADSZ(*p); j = CIS_IO_BLKSZ(*p++); for (x = 0; x < conf->io_blks; x++) { io = xmalloc(sizeof(*io)); - if (last) - last->next = io; + if (last_io) + last_io->next = io; else conf->io = io; - last = io; - u.l = 0; - switch (i) { - case 0: - break; - case 1: - u.b[0] = *p++; - break; - case 2: - u.b[0] = *p++; - u.b[1] = *p++; - break; - case 3: - u.b[0] = *p++; - u.b[1] = *p++; - u.b[2] = *p++; - u.b[3] = *p++; - break; - } - io->addr = u.l; - u.l = 0; - switch (j) { - case 0: - break; - case 1: - u.b[0] = *p++; - u.l++; - break; - case 2: - u.b[0] = *p++; - u.b[1] = *p++; - u.l++; - break; - case 3: - u.b[0] = *p++; - u.b[1] = *p++; - u.b[2] = *p++; - u.b[3] = *p++; - u.l++; - break; - } - io->size = u.l; + last_io = io; + io->addr = parse_num(i, p, &p, 0); + io->size = parse_num(j, p, &p, 1); } } } @@ -353,7 +470,7 @@ conf->irqlevel = *p & 0xF; conf->irq_flags = *p & 0xF0; if (*p++ & CIS_IRQ_MASK) { - conf->irq_mask = (p[1] << 8) | p[0]; + conf->irq_mask = tpl16(p); p += 2; } } @@ -363,43 +480,39 @@ case 1: conf->memspace = 1; conf->mem = xmalloc(sizeof(*conf->mem)); - conf->mem->length = ((p[1] << 8) | p[0]) << 8; + conf->mem->length = tpl16(p) << 8; break; case 2: conf->memspace = 1; conf->mem = xmalloc(sizeof(*conf->mem)); - conf->mem->length = ((p[1] << 8) | p[0]) << 8; - conf->mem->address = ((p[3] << 8) | p[2]) << 8; + conf->mem->length = tpl16(p) << 8; + conf->mem->address = tpl16(p + 2) << 8; break; - case 3: + case 3: { + struct cis_memblk *mem; + struct cis_memblk *last_mem = NULL; + conf->memspace = 1; x = *p++; conf->memwins = CIS_MEM_WINS(x); for (i = 0; i < conf->memwins; i++) { mem = xmalloc(sizeof(*mem)); - if (i == 0) - conf->mem = mem; + if (last_mem) + last_mem->next = mem; else - lastmem->next = mem; - lastmem = mem; - u.l = 0; - for (j = 0; j < CIS_MEM_LENSZ(x); j++) - u.b[j] = *p++; - mem->length = u.l << 8; - u.l = 0; - for (j = 0; j < CIS_MEM_ADDRSZ(x); j++) - u.b[j] = *p++; - mem->address = u.l << 8; + conf->mem = mem; + last_mem = mem; + mem->length = parse_num(CIS_MEM_LENSZ(x) | 0x10, p, &p, 0) << 8; + mem->address = parse_num(CIS_MEM_ADDRSZ(x) | 0x10, p, &p, 0) << 8; if (x & CIS_MEM_HOST) { - u.l = 0; - for (j = 0; j < CIS_MEM_ADDRSZ(x); j++) - u.b[j] = *p++; - mem->host_address = u.l << 8; + mem->host_address = parse_num(CIS_MEM_ADDRSZ(x) | 0x10, + p, &p, 0) << 8; } } break; + } } - if (feat & 0x80) { + if (feat & CIS_FEAT_MISC) { conf->misc_valid = 1; conf->misc = *p++; } @@ -443,12 +556,9 @@ tp = find_tuple_in_list(last_tl, CIS_LONGLINK_C); } if (tp && tp->length == 4) { - offs = tp->data[0] | - (tp->data[1] << 8) | - (tp->data[2] << 16) | - (tp->data[3] << 24); + offs = tpl32(tp->data); #ifdef DEBUG - printf("Checking long link at %ld (%s memory)\n", + printf("Checking long link at %qd (%s memory)\n", offs, flag ? "Attribute" : "Common"); #endif /* If a link was found, read the tuple list from it. */ @@ -468,7 +578,7 @@ if (find_tuple_in_list(tlist, CIS_NOLINK) == 0 && tlist->next == 0 && ck_linktarget(fd, (off_t) 0, 0)) { #ifdef DEBUG - printf("Reading long link at %ld (%s memory)\n", + printf("Reading long link at %qd (%s memory)\n", offs, flag ? "Attribute" : "Common"); #endif tlist->next = read_one_tuplelist(fd, 0, (off_t) 0); @@ -487,6 +597,10 @@ struct tuple_info *tinfo; int total = 0; unsigned char code, length; + int fmvj182 = 0; +#ifdef HSSYNTH + int hss = 0; +#endif /* HSSYNTH */ /* Check to see if this memory has already been scanned. */ for (tl = tlist; tl; tl = tl->next) @@ -507,11 +621,17 @@ continue; tp = xmalloc(sizeof(*tp)); tp->code = code; - if (read_attr(fd, &length, 1) != 1) { - warn("CIS len read"); - break; + if (code == CIS_END) + length = 0; + else { + if (read_attr(fd, &length, 1) != 1) { + warn("CIS len read"); + break; + } + total++; + if (fmvj182 && (code == 0x1b) && (length == 25)) + length = 31; } - total++; tp->length = length; #ifdef DEBUG printf("Tuple code = 0x%x, len = %d\n", code, length); @@ -534,11 +654,23 @@ * or the length is illegal. */ tinfo = get_tuple_info(code); - if (tinfo == 0 || (tinfo->length != 255 && tinfo->length != length)) { + if (code == CIS_INFO_V1) { + /* Hack for broken CIS of FMV-J182 Ethernet card */ + fmvj182 = fmvj182_check(tp->data); +#ifdef RATOCLAN + /* Hack for RATOC LAN card */ + rex5588 = rex5588_check(tp->data); +#endif /* RATOCLAN */ +#ifdef HSSYNTH + /* Hack for Hitachi Speech Synthesis card */ + hss = hss_check(tp->data); +#endif /* HSSYNTH */ + } + if (tinfo == NULL || (tinfo->length != 255 && tinfo->length > length)) { printf("code %s ignored\n", tuple_name(code)); tp->code = CIS_NULL; } - if (tl->tuples == 0) + if (tl->tuples == NULL) tl->tuples = tp; else last_tp->next = tp; Index: pccardd/readcis.h =================================================================== RCS file: /home/ncvs/src/usr.sbin/pccard/pccardd/readcis.h,v retrieving revision 1.11.2.1 diff -u -r1.11.2.1 readcis.h --- pccardd/readcis.h 2000/04/15 10:56:22 1.11.2.1 +++ pccardd/readcis.h 2000/05/31 18:31:59 @@ -26,7 +26,6 @@ * $FreeBSD: src/usr.sbin/pccard/pccardd/readcis.h,v 1.11.2.1 2000/04/15 10:56:22 iwasaki Exp $ */ -#define CIS_MAXSTR 254 struct tuple { struct tuple *next; unsigned char code; @@ -111,10 +110,10 @@ */ struct cis { struct tuple_list *tlist; - char manuf[CIS_MAXSTR]; - char vers[CIS_MAXSTR]; - char add_info1[CIS_MAXSTR]; - char add_info2[CIS_MAXSTR]; + char *manuf; + char *vers; + char *add_info1; + char *add_info2; unsigned char maj_v, min_v; unsigned char last_config; unsigned char ccrs; @@ -124,11 +123,21 @@ struct dev_mem common_mem; struct cis_config *def_config; struct cis_config *conf; + unsigned char *lan_nid; }; +#define tpl32(tp) ((*((tp) + 3) << 24) | \ + (*((tp) + 2) << 16) | \ + (*((tp) + 1) << 8) | *(tp)) +#define tpl24(tp) ((*((tp) + 2) << 16) | \ + (*((tp) + 1) << 8) | *(tp)) +#define tpl16(tp) ((*((tp) + 1) << 8) | *(tp)) + void *xmalloc(int); +void dump(unsigned char *, int); void dumpcis(struct cis *); void freecis(struct cis *); struct cis *readcis(int); char *tuple_name(unsigned char); +u_int parse_num(int, u_char *, u_char **, int); Index: pccardd/util.c =================================================================== RCS file: /home/ncvs/src/usr.sbin/pccard/pccardd/util.c,v retrieving revision 1.13 diff -u -r1.13 util.c --- pccardd/util.c 1999/08/28 01:17:37 1.13 +++ pccardd/util.c 2000/05/31 18:31:59 @@ -150,17 +150,18 @@ * least count number. */ int -bit_fns(bitstr_t *nm, int nbits, int count) +bit_fns(bitstr_t *nm, int nbits, int count, int step) { - int i; + int i, j; int found = 0; - for (i = 0; i < nbits; i++) - if (bit_test(nm, i)) { - if (++found == count) - return (i - count + 1); - } else - found = 0; + for (i = 0; i < nbits; i += step) + for (j = i, found = 0; j < nbits; j++) + if (bit_test(nm, j)) { + if (++found == count) + return i; + } else + break; return (-1); } @@ -172,10 +173,10 @@ { int i; - i = bit_fns(mem_avail, MEMBLKS, size / MEMUNIT); + i = bit_fns(mem_avail, MEMBLKS, size / MEMUNIT + (size % MEMUNIT != 0), 1); if (i < 0) return (0); - bit_nclear(mem_avail, i, size / MEMUNIT); + bit_nclear(mem_avail, i, i + size / MEMUNIT + (size % MEMUNIT != 0) - 1); return (BIT2MEM(i)); }