pcidump.c
上传用户:wudi5211
上传日期:2010-01-21
资源大小:607k
文件大小:7k
- /*
- * pcidump.c -- a tool to decode /proc/pcidata
- *
- * $Id: pcidump.c,v 1.3 2001/02/10 01:30:29 rubini Exp $
- *
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <errno.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <linux/pci.h>
- #include <asm/page.h>
- #include <linux/version.h>
- /* A structure to declare how data is decoded */
- struct pcidump_info {
- int offset; /* the data item to retrieve */
- unsigned long bitmask;
- int bool; /* true or false */
- char *string;
- };
- #define ONEBYTE 0xFF
- #define TWOBYTES 0xFFFF
- #define FOURBYTES 0xFFFFFFFF
- struct pcidump_info dumpinfo[] = {
- {0, 0, 0, "tCompulsory registers:n"},
- {PCI_VENDOR_ID, TWOBYTES, 0, "Vendor id: %04xn"},
- {PCI_DEVICE_ID, TWOBYTES, 0, "Device id: %04xn"},
- {PCI_COMMAND, PCI_COMMAND_IO, 1, "I/O space enabled: %cn"},
- {PCI_COMMAND, PCI_COMMAND_MEMORY, 1, "Memory enabled: %cn"},
- {PCI_COMMAND, PCI_COMMAND_MASTER, 1, "Master enabled: %cn"},
- {PCI_COMMAND, PCI_COMMAND_SPECIAL, 1, "Special command enabled: %cn"},
- {PCI_COMMAND, PCI_COMMAND_INVALIDATE, 1, "Write-invalidate enabled: %cn"},
- {PCI_COMMAND, PCI_COMMAND_VGA_PALETTE, 1, "Palette-snoop enabled: %cn"},
- {PCI_COMMAND, PCI_COMMAND_PARITY, 1, "Parity enabled: %cn"},
- {PCI_COMMAND, PCI_COMMAND_WAIT, 1, "Wait-cycle enabled: %cn"},
- {PCI_COMMAND, PCI_COMMAND_SERR, 1, "System-error enabled: %cn"},
- {PCI_COMMAND, PCI_COMMAND_FAST_BACK, 1, "Fast-back-to-back enabled: %cn"},
- {PCI_STATUS, PCI_STATUS_66MHZ, 1, "Can do 66MHz: %cn"},
- {PCI_STATUS, PCI_STATUS_UDF, 1, "Supports User Defined Features: %cn"},
- {PCI_STATUS, PCI_STATUS_FAST_BACK, 1, "Fast-back-to-back capable: %cn"},
- {PCI_STATUS, PCI_STATUS_PARITY, 1, "Data Parity Reported: %cn"},
- {PCI_STATUS, PCI_STATUS_DEVSEL_MASK, 0, "Device Select Timing bits are %xn"},
- {PCI_STATUS, PCI_STATUS_SIG_TARGET_ABORT,1, "Signalled abort as target: %cn"},
- {PCI_STATUS, PCI_STATUS_REC_TARGET_ABORT, 1, "Received abort from target: %cn"},
- {PCI_STATUS, PCI_STATUS_REC_MASTER_ABORT, 1, "Aborted transaction as master: %cn"},
- {PCI_STATUS, PCI_STATUS_SIG_SYSTEM_ERROR, 1, "Did send a system error: %cn"},
- {PCI_STATUS, PCI_STATUS_DETECTED_PARITY, 1, "Detected a parity error: %cn"},
- {PCI_REVISION_ID, ONEBYTE, 0, "Revision id (decimal): %in"},
- {PCI_CLASS_PROG, ONEBYTE, 0, "Programmer Interface: %02xn"},
- {PCI_CLASS_DEVICE, TWOBYTES, 0, "Class of device: %04xn"},
- {PCI_HEADER_TYPE, 0x7f, 0, "Header type: %02xn"},
- {PCI_HEADER_TYPE, 0x80, 1, "Multi function device: %cn"},
- {0, 0, 0, "tOptional registers:n"},
- {PCI_CACHE_LINE_SIZE, ONEBYTE, 0, "Cache line size (decimal): %in"},
- {PCI_LATENCY_TIMER, ONEBYTE, 0, "Latency timer (decimal): %in"},
- {PCI_BIST, PCI_BIST_CAPABLE, 1, "Is Built-In-Self-Test available: %cn"},
- {PCI_BIST, PCI_BIST_CODE_MASK, 1, "Did Built-In-Self-Test fail: %cn"},
- {PCI_BASE_ADDRESS_0, PCI_BASE_ADDRESS_MEM_MASK, 0, "Base Address 0: %08xn"},
- {PCI_BASE_ADDRESS_0, PCI_BASE_ADDRESS_SPACE, 1, "Base Address 0 Is I/O: %cn"},
- {PCI_BASE_ADDRESS_0, PCI_BASE_ADDRESS_MEM_TYPE_64, 1, "Base Address 0 is 64-bits: %cn"},
- {PCI_BASE_ADDRESS_0, PCI_BASE_ADDRESS_MEM_TYPE_1M, 1, "Base Address 0 is below-1M: %cn"},
- {PCI_BASE_ADDRESS_0, PCI_BASE_ADDRESS_MEM_PREFETCH, 1, "Base Address 0 is prefetchable: %cn"},
- {PCI_BASE_ADDRESS_1, PCI_BASE_ADDRESS_MEM_MASK, 0, "Base Address 1: %08xn"},
- {PCI_BASE_ADDRESS_1, PCI_BASE_ADDRESS_SPACE, 1, "Base Address 1 Is I/O: %cn"},
- {PCI_BASE_ADDRESS_1, PCI_BASE_ADDRESS_MEM_TYPE_64, 1, "Base Address 1 is 64-bits: %cn"},
- {PCI_BASE_ADDRESS_1, PCI_BASE_ADDRESS_MEM_TYPE_1M, 1, "Base Address 1 is below-1M: %cn"},
- {PCI_BASE_ADDRESS_1, PCI_BASE_ADDRESS_MEM_PREFETCH, 1, "Base Address 1 is prefetchable: %cn"},
- #if 0
- #define PCI_BASE_ADDRESS_2 0x18 /* 32 bits */
- #define PCI_BASE_ADDRESS_3 0x1c /* 32 bits */
- #define PCI_BASE_ADDRESS_4 0x20 /* 32 bits */
- #define PCI_BASE_ADDRESS_5 0x24 /* 32 bits */
- #define PCI_CARDBUS_CIS 0x28
- #endif
- {PCI_SUBSYSTEM_ID, TWOBYTES, 0, "Subsystem id: %04xn"},
- {PCI_SUBSYSTEM_VENDOR_ID, TWOBYTES, 0, "Subsystem vendor: %04xn"},
- {PCI_ROM_ADDRESS, ~0x7FF, 0, "Rom address: %08xn"},
- {PCI_ROM_ADDRESS, PCI_ROM_ADDRESS_ENABLE, 1, "Rom is enabled: %cn"},
- {PCI_INTERRUPT_PIN, ONEBYTE, 1, "Does generate interrupts: %cn"},
- {PCI_INTERRUPT_LINE, ONEBYTE, 0, "Interrupt line (decimal): %in"},
- {PCI_INTERRUPT_PIN, ONEBYTE, 0, "Interrupt pin (decimal): %in"},
- {PCI_MIN_GNT, ONEBYTE, 0, "Min bus grant time (decimal): %in"},
- {PCI_MAX_LAT, ONEBYTE, 0, "Max bus latency acceptable (decimal): %in"},
- {0x00, 0, 0, NULL}
- };
- unsigned char buffer[PAGE_SIZE];
- int main(int argc, char **argv)
- {
- int fd, len;
- char *fname="/proc/pcidata";
-
- unsigned char *curr, *end;
- if (argc > 2 || (argc == 2 && argv[1][0] == '-')) {
- fprintf(stderr,"%s: Usage: "%s <filename>"n"
- "tfilename should embed binary pci configuration datan"
- "tif filename is missing, %s is usedn",
- argv[0], argv[0], fname);
- exit(1);
- }
- if (argc>1) {
- fname = argv[1];
- }
- fd=open(fname, O_RDONLY);
- if (fd<0) {
- fprintf(stderr,"%s: %s: %sn", argv[0], fname, strerror(errno));
- exit(1);
- }
- switch (len=read(fd,buffer,PAGE_SIZE)) {
- case 0:
- fprintf(stderr,"%s: %s: no datan", argv[0], fname);
- exit(1);
- case -1:
- fprintf(stderr,"%s: %s: %sn", argv[0], fname, strerror(errno));
- exit(1);
- default: break;
- }
- if (len < 256) {
- buffer[len]=' ';
- fprintf(stderr," %s: %s: %sn", argv[0], fname, buffer);
- exit(1);
- }
- if (len % 256) {
- fprintf(stderr," %s: %s: incorrect data size: %in",
- argv[0], fname, len);
- exit(1);
- }
- for (end = buffer+len, curr = buffer; curr < end; curr += 256) {
- struct pcidump_info *ptr;
- unsigned int datum;
- for (ptr = dumpinfo; ptr->string; ptr++) {
- /*
- * Perform a little-endian read of the item
- */
- datum = curr[ptr->offset]
- | (curr[ptr->offset+1]<<8)
- | (curr[ptr->offset+2]<<16)
- | (curr[ptr->offset+3]<<24);
- datum &= ptr->bitmask;
- printf(ptr->string, ptr->bool ? (datum ? 'y' : 'n') : datum);
- }
- printf("n");
- }
- return 0;
- }