📄 dump_cis.c
字号:
/*====================================================================== PC Card CIS dump utility dump_cis.c 1.63 2001/11/30 23:10:17 The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. The initial developer of the original code is David A. Hinds <dahinds@users.sourceforge.net>. Portions created by David A. Hinds are Copyright (C) 1999 David A. Hinds. All Rights Reserved. Alternatively, the contents of this file may be used under the terms of the GNU General Public License version 2 (the "GPL"), in which case the provisions of the GPL are applicable instead of the above. If you wish to allow the use of your version of this file only under the terms of the GPL and not to allow others to use your version of this file under the MPL, indicate your decision by deleting the provisions above and replace them with the notice and other provisions required by the GPL. If you do not delete the provisions above, a recipient may use your version of this file under either the MPL or the GPL. ======================================================================*/#include <sys/types.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <fcntl.h>#include <errno.h>#include <sys/time.h>#include <sys/ioctl.h>#include <sys/stat.h>#include <pcmcia/cs_types.h>#include <pcmcia/cs.h>#include <pcmcia/cistpl.h>#include <pcmcia/ds.h>static int verbose = 0;static char indent[10] = " ";/*====================================================================*/static int major = 0;static int lookup_dev(char *name){ FILE *f; int n; char s[32], t[32]; f = fopen("/proc/devices", "r"); if (f == NULL) return -1; while (fgets(s, 32, f) != NULL) { if (sscanf(s, "%d %s", &n, t) == 2) if (strcmp(name, t) == 0) break; } fclose(f); if (strcmp(name, t) == 0) return n; else return -1;}/*====================================================================*/static int open_sock(int sock){ static char *paths[] = { "/var/lib/pcmcia", "/var/run", "/dev", "/tmp", NULL }; int fd; char **p, fn[64]; dev_t dev = (major<<8) + sock; for (p = paths; *p; p++) { sprintf(fn, "%s/dc%d", *p, getpid()); if (mknod(fn, (S_IFCHR|S_IREAD|S_IWRITE), dev) == 0) { fd = open(fn, O_RDONLY); unlink(fn); if (fd >= 0) return fd; if (errno == ENODEV) break; } } return -1;} /* open_sock *//*====================================================================*/static void print_tuple(tuple_parse_t *tup){ int i; printf("%soffset 0x%2.2x, tuple 0x%2.2x, link 0x%2.2x\n", indent, tup->tuple.CISOffset, tup->tuple.TupleCode, tup->tuple.TupleLink); for (i = 0; i < tup->tuple.TupleDataLen; i++) { if ((i % 16) == 0) printf("%s ", indent); printf("%2.2x ", (u_char)tup->data[i]); if ((i % 16) == 15) putchar('\n'); } if ((i % 16) != 0) putchar('\n');}/*====================================================================*/static void print_funcid(cistpl_funcid_t *fn){ printf("%sfuncid ", indent); switch (fn->func) { case CISTPL_FUNCID_MULTI: printf("multi_function"); break; case CISTPL_FUNCID_MEMORY: printf("memory_card"); break; case CISTPL_FUNCID_SERIAL: printf("serial_port"); break; case CISTPL_FUNCID_PARALLEL: printf("parallel_port"); break; case CISTPL_FUNCID_FIXED: printf("fixed_disk"); break; case CISTPL_FUNCID_VIDEO: printf("video_adapter"); break; case CISTPL_FUNCID_NETWORK: printf("network_adapter"); break; case CISTPL_FUNCID_AIMS: printf("aims_card"); break; case CISTPL_FUNCID_SCSI: printf("scsi_adapter"); break; default: printf("unknown"); break; } if (fn->sysinit & CISTPL_SYSINIT_POST) printf(" [post]"); if (fn->sysinit & CISTPL_SYSINIT_ROM) printf(" [rom]"); putchar('\n');}/*====================================================================*/static void print_size(u_int size){ if (size < 1024) printf("%ub", size); else if (size < 1024*1024) printf("%ukb", size/1024); else printf("%umb", size/(1024*1024));}static void print_unit(u_int v, char *unit, char tag){ int n; for (n = 0; (v % 1000) == 0; n++) v /= 1000; printf("%u", v); if (n < strlen(unit)) putchar(unit[n]); putchar(tag);}static void print_time(u_int tm, u_long scale){ print_unit(tm * scale, "num", 's');}static void print_volt(u_int vi){ print_unit(vi * 10, "um", 'V');} static void print_current(u_int ii){ print_unit(ii / 10, "um", 'A');}static void print_speed(u_int b){ if (b < 1000) printf("%u bits/sec", b); else if (b < 1000000) printf("%u kb/sec", b/1000); else printf("%u mb/sec", b/1000000);}/*====================================================================*/static const char *dtype[] = { "NULL", "ROM", "OTPROM", "EPROM", "EEPROM", "FLASH", "SRAM", "DRAM", "rsvd", "rsvd", "rsvd", "rsvd", "rsvd", "fn_specific", "extended", "rsvd"};static void print_device(cistpl_device_t *dev){ int i; for (i = 0; i < dev->ndev; i++) { printf("%s %s ", indent, dtype[dev->dev[i].type]); printf("%uns, ", dev->dev[i].speed); print_size(dev->dev[i].size); putchar('\n'); } if (dev->ndev == 0) printf("%s no_info\n", indent);}/*====================================================================*/static void print_power(char *tag, cistpl_power_t *power){ int i, n; for (i = n = 0; i < 8; i++) if (power->present & (1<<i)) n++; i = 0; printf("%s %s", indent, tag); if (power->present & (1<<CISTPL_POWER_VNOM)) { printf(" Vnom "); i++; print_volt(power->param[CISTPL_POWER_VNOM]); } if (power->present & (1<<CISTPL_POWER_VMIN)) { printf(" Vmin "); i++; print_volt(power->param[CISTPL_POWER_VMIN]); } if (power->present & (1<<CISTPL_POWER_VMAX)) { printf(" Vmax "); i++; print_volt(power->param[CISTPL_POWER_VMAX]); } if (power->present & (1<<CISTPL_POWER_ISTATIC)) { printf(" Istatic "); i++; print_current(power->param[CISTPL_POWER_ISTATIC]); } if (power->present & (1<<CISTPL_POWER_IAVG)) { if (++i == 5) printf("\n%s ", indent); printf(" Iavg "); print_current(power->param[CISTPL_POWER_IAVG]); } if (power->present & (1<<CISTPL_POWER_IPEAK)) { if (++i == 5) printf("\n%s ", indent); printf(" Ipeak "); print_current(power->param[CISTPL_POWER_IPEAK]); } if (power->present & (1<<CISTPL_POWER_IDOWN)) { if (++i == 5) printf("\n%s ", indent); printf(" Idown "); print_current(power->param[CISTPL_POWER_IDOWN]); } if (power->flags & CISTPL_POWER_HIGHZ_OK) { if (++i == 5) printf("\n%s ", indent); printf(" [highz OK]"); } if (power->flags & CISTPL_POWER_HIGHZ_REQ) { printf(" [highz]"); } putchar('\n');}/*====================================================================*/static void print_cftable_entry(cistpl_cftable_entry_t *entry){ int i; printf("%scftable_entry 0x%2.2x%s\n", indent, entry->index, (entry->flags & CISTPL_CFTABLE_DEFAULT) ? " [default]" : ""); if (entry->flags & ~CISTPL_CFTABLE_DEFAULT) { printf("%s ", indent); if (entry->flags & CISTPL_CFTABLE_BVDS) printf(" [bvd]"); if (entry->flags & CISTPL_CFTABLE_WP) printf(" [wp]"); if (entry->flags & CISTPL_CFTABLE_RDYBSY) printf(" [rdybsy]"); if (entry->flags & CISTPL_CFTABLE_MWAIT) printf(" [mwait]"); if (entry->flags & CISTPL_CFTABLE_AUDIO) printf(" [audio]"); if (entry->flags & CISTPL_CFTABLE_READONLY) printf(" [readonly]"); if (entry->flags & CISTPL_CFTABLE_PWRDOWN) printf(" [pwrdown]"); putchar('\n'); } if (entry->vcc.present) print_power("Vcc", &entry->vcc); if (entry->vpp1.present) print_power("Vpp1", &entry->vpp1); if (entry->vpp2.present) print_power("Vpp2", &entry->vpp2); if ((entry->timing.wait != 0) || (entry->timing.ready != 0) || (entry->timing.reserved != 0)) { printf("%s timing", indent); if (entry->timing.wait != 0) { printf(" wait "); print_time(entry->timing.wait, entry->timing.waitscale); } if (entry->timing.ready != 0) { printf(" ready "); print_time(entry->timing.ready, entry->timing.rdyscale); } if (entry->timing.reserved != 0) { printf(" reserved "); print_time(entry->timing.reserved, entry->timing.rsvscale); } putchar('\n'); } if (entry->io.nwin) { cistpl_io_t *io = &entry->io; printf("%s io", indent); for (i = 0; i < io->nwin; i++) { if (i) putchar(','); printf(" 0x%4.4x-0x%4.4x", io->win[i].base, io->win[i].base+io->win[i].len-1); } printf(" [lines=%d]", io->flags & CISTPL_IO_LINES_MASK); if (io->flags & CISTPL_IO_8BIT) printf(" [8bit]"); if (io->flags & CISTPL_IO_16BIT) printf(" [16bit]"); if (io->flags & CISTPL_IO_RANGE) printf(" [range]"); putchar('\n'); } if (entry->irq.IRQInfo1) { printf("%s irq ", indent); if (entry->irq.IRQInfo1 & IRQ_INFO2_VALID) printf("mask 0x%04x", entry->irq.IRQInfo2); else printf("%u", entry->irq.IRQInfo1 & IRQ_MASK); if (entry->irq.IRQInfo1 & IRQ_LEVEL_ID) printf(" [level]"); if (entry->irq.IRQInfo1 & IRQ_PULSE_ID) printf(" [pulse]"); if (entry->irq.IRQInfo1 & IRQ_SHARE_ID) printf(" [shared]"); putchar('\n'); } if (entry->mem.nwin) { cistpl_mem_t *mem = &entry->mem; printf("%s memory", indent); for (i = 0; i < mem->nwin; i++) { if (i) putchar(','); printf(" 0x%4.4x-0x%4.4x @ 0x%4.4x", mem->win[i].card_addr, mem->win[i].card_addr + mem->win[i].len-1, mem->win[i].host_addr); } putchar('\n'); } if (verbose && entry->subtuples) printf("%s %d bytes in subtuples\n", indent, entry->subtuples); }/*====================================================================*/static void print_cftable_entry_cb(cistpl_cftable_entry_cb_t *entry)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -