📄 lspnp.c
字号:
/*====================================================================== A utility for dumping resource information for PnP devices lspnp.c 1.8 2002/02/13 05:45:01 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. Usage: lspnp [-b] [-v[v]] [device #]======================================================================*/#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <fcntl.h>#include <string.h>#include <endian.h>#include <ctype.h>#include <asm/types.h>#include <linux/pnp_resource.h>static int verbose = 0, boot = 0;static struct { __u8 base; char * name;} base_type[] = { { 1, "mass storage device" }, { 2, "network interface controller" }, { 3, "display controller" }, { 4, "multimedia controller" }, { 5, "memory controller" }, { 6, "bridge controller" }, { 7, "communications device" }, { 8, "system peripheral" }, { 9, "input device" }, { 10, "service processor" }};#define NBASE (sizeof(base_type)/sizeof(base_type[0]))static struct { __u8 base, sub; char * name;} sub_type[] = { { 1, 0, "SCSI" }, { 1, 1, "IDE" }, { 1, 2, "floppy" }, { 1, 3, "IPI" }, { 2, 0, "ethernet" }, { 2, 1, "token ring" }, { 2, 2, "FDDI" }, { 3, 0, "VGA" }, { 3, 1, "SVGA" }, { 3, 2, "XGA" }, { 4, 0, "video" }, { 4, 1, "audio" }, { 5, 0, "RAM" }, { 5, 1, "flash" }, { 6, 0, "host processor" }, { 6, 1, "ISA" }, { 6, 2, "EISA" }, { 6, 3, "MicroChannel" }, { 6, 4, "PCI" }, { 6, 5, "PCMCIA" }, { 6, 6, "VME" }, { 7, 0, "RS-232" }, { 7, 1, "AT parallel port" }, { 8, 0, "programmable interrupt controller" }, { 8, 1, "DMA controller" }, { 8, 2, "system timer" }, { 8, 3, "real time clock" }, { 8, 4, "L2 cache" }, { 8, 5, "NVRAM" }, { 8, 6, "power management" }, { 8, 7, "CMOS" }, { 8, 8, "operator panel" }, { 9, 0, "keyboard" }, { 9, 1, "digitizer" }, { 9, 2, "mouse" }, { 9, 3, "tablet" }, { 10, 0, "general memory" }};#define NSUB (sizeof(sub_type)/sizeof(sub_type[0]))static struct eisa_id { char id[8]; char * name; struct eisa_id * next;} *eisa_id = NULL;#define swap16(n) ((((n)&0x00ff)<<8) | (((n)&0xff00)>>8))#define swap32(n) \ ((((n)&0xff000000)>>24) | (((n)&0x00ff0000)>>8) | \ (((n)&0x0000ff00)<<8) | (((n)&0x000000ff)<<24))#if (__BYTE_ORDER == _BIG_ENDIAN)#define flip16(n) swap16(n)#define flip32(n) swap32(n)#else#define flip16(n) (n)#define flip32(n) (n)#endif/*====================================================================*/#define HEX(id,a) hex[((id)>>a) & 15]#define CHAR(id,a) (0x40 + (((id)>>a) & 31))static char *eisa_str(__u32 id){ const char *hex = "0123456789abcdef"; static char str[8]; id = swap32(id); str[0] = CHAR(id, 26); str[1] = CHAR(id, 21); str[2] = CHAR(id,16); str[3] = HEX(id, 12); str[4] = HEX(id, 8); str[5] = HEX(id, 4); str[6] = HEX(id, 0); str[7] = '\0'; return str;}static void load_ids(void){ char s[133], *t; int n; struct eisa_id *id; FILE *f = fopen("/usr/share/pnp.ids", "r"); if (f == NULL) return; while (fgets(s, sizeof(s), f)) { if ((strlen(s) < 9) || !(isupper(s[0]) && isupper(s[1]) && isupper(s[2]) && isxdigit(s[3]) && isxdigit(s[4]) && isxdigit(s[5]) && isxdigit(s[6]))) continue; id = malloc(sizeof(struct eisa_id)); strncpy(id->id, s, 7); for (n = 3; n < 7; n++) id->id[n] = tolower(id->id[n]); id->id[7] = '\0'; s[strlen(s)-1] = '\0'; for (t = s+7; isspace(*t); t++) ; id->name = strdup(t); id->next = eisa_id; eisa_id = id; } fclose(f);}static void dump_flags(int flags){ printf(" flags:"); if (!flags) printf(" none"); if (flags & 0x0001) printf(" [no disable]"); if (flags & 0x0002) printf(" [no config]"); if (flags & 0x0004) printf(" [output]"); if (flags & 0x0008) printf(" [input]"); if (flags & 0x0010) printf(" [bootable]"); if (flags & 0x0020) printf(" [dock]"); if (flags & 0x0040) printf(" [removable]"); if ((flags & 0x0180) == 0x0000) printf(" [static]"); if ((flags & 0x0180) == 0x0080) printf(" [dynamic]"); if ((flags & 0x0180) == 0x0180) printf(" [dynamic only]"); printf("\n");}static void dump_class(int t1, int t2){ int i; for (i = 0; i < NBASE; i++) if (t1 == base_type[i].base) break; printf("%s: ", (i < NBASE) ? base_type[i].name : "reserved"); for (i = 0; i < NSUB; i++) if ((t1 == sub_type[i].base) && (t2 == sub_type[i].sub)) break; printf("%s", (i < NSUB) ? sub_type[i].name : "other");}/* Small resource tags*/static void dump_version(union pnp_small_resource *r){ printf("\tPnP version %d.%d, vendor version %d.%d\n", r->version.pnp>>4, r->version.pnp & 0x0f, r->version.vendor>>4, r->version.vendor & 0x0f);}static void dump_ldid(union pnp_small_resource *r, int sz){ printf("\tlogical ID %s", eisa_str(r->ldid.id)); if (verbose > 1) { if (r->ldid.flag0 & PNP_RES_LDID_BOOT) printf(" [boot]"); } printf("\n");}static void dump_gdid(union pnp_small_resource *r){ struct eisa_id *eid; char *eis = eisa_str(r->gdid.id); printf("\t%s", eis); for (eid = eisa_id; eid; eid = eid->next) if (strcmp(eis, eid->id) == 0) break; if (eid) printf(" %s\n", eid->name); else printf("\n");}static void dump_irq(union pnp_small_resource *r, int sz){ int mask = flip16(r->irq.mask); printf("\tirq "); if (!mask) { printf("disabled"); } else if (mask & (mask-1)) { printf("mask 0x%04x", mask); } else { printf("%d", ffs(mask)-1); } if (verbose > 1) { if (sz == 3) { if (r->irq.info & PNP_RES_IRQ_HIGH_EDGE) printf(" [high edge]"); if (r->irq.info & PNP_RES_IRQ_LOW_EDGE) printf(" [low edge]"); if (r->irq.info & PNP_RES_IRQ_HIGH_LEVEL) printf(" [high level]"); if (r->irq.info & PNP_RES_IRQ_LOW_LEVEL) printf(" [low level]"); } else { printf(" [high edge]"); } } printf("\n");}static void dump_dma(union pnp_small_resource *r){ int mask = r->dma.mask; printf("\tdma "); if (!mask) { printf("disabled"); } else if (mask & (mask-1)) { printf("mask 0x%04x", mask); } else { printf("%d", ffs(mask)-1); } if (verbose > 1) { switch (r->dma.info & PNP_RES_DMA_WIDTH_MASK) { case PNP_RES_DMA_WIDTH_8: printf(" [8 bit]"); break; case PNP_RES_DMA_WIDTH_8_16: printf(" [8/16 bit]"); break; case PNP_RES_DMA_WIDTH_16: printf(" [16 bit]"); break; } if (r->dma.info & PNP_RES_DMA_BUSMASTER) printf(" [master]");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -