?? showpci.c
字號(hào):
#include <linux/config.h>#include <linux/module.h>#include <linux/pci.h>#include <linux/list.h>#include <linux/fs.h>#include <linux/string.h>unsigned short vendor = 0;unsigned short device = 0;unsigned short class = 0;unsigned short detail = 0;static void print_resource( struct resource *res ){ if( res->name && res->flags ) { //printk( "<1>name: %s\n", res->name ); printk( "<1> flags : 0x%08x ", (unsigned int)res->flags ); if( res->flags & IORESOURCE_UNSET ) printk( "UNSET " ); if( res->flags & IORESOURCE_AUTO ) printk( "AUTO " ); if( res->flags & IORESOURCE_BUSY ) printk( "BUSY " ); if( res->flags & IORESOURCE_PREFETCH ) printk( "PREFETCH " ); if( res->flags & IORESOURCE_READONLY ) printk( "READONLY " ); if( res->flags & IORESOURCE_CACHEABLE ) printk( "CACHE " ); if( res->flags & IORESOURCE_RANGELENGTH ) printk( "RANGELENGTH " ); if( res->flags & IORESOURCE_SHADOWABLE ) printk( "SHADOW " ); if( res->flags & IORESOURCE_BUS_HAS_VGA ) printk( "BUS_HAS_VGA " ); if( res->flags & IORESOURCE_IO ) printk( "IO " ); if( res->flags & IORESOURCE_MEM ) { printk( "MEM [ISA: " ); if(res->flags &IORESOURCE_MEM_WRITEABLE ) printk( "WRITE " ); if(res->flags &IORESOURCE_MEM_CACHEABLE ) printk( "CACHE " ); if(res->flags &IORESOURCE_MEM_RANGELENGTH ) printk( "RANGE " ); if(res->flags &IORESOURCE_MEM_TYPE_MASK ) printk( "TYPEMASK " ); if(res->flags &IORESOURCE_MEM_8BIT ) printk( "8BIT " ); if(res->flags &IORESOURCE_MEM_16BIT ) printk( "16BIT " ); if(res->flags &IORESOURCE_MEM_8AND16BIT ) printk( "8AND16BIT " ); if(res->flags &IORESOURCE_MEM_SHADOWABLE ) printk( "SHADOW " ); if(res->flags &IORESOURCE_MEM_EXPANSIONROM ) printk( "EXPANSIONROM " ); printk( "] " ); } if( res->flags & IORESOURCE_IRQ ) { printk( "IRQ [ISA:" ); if(res->flags &IORESOURCE_IRQ_HIGHEDGE ) printk( "HIGHEDGE " ); if(res->flags &IORESOURCE_IRQ_LOWEDGE ) printk( "LOWEDGE " ); if(res->flags &IORESOURCE_IRQ_HIGHLEVEL ) printk( "HIGHLEVEL " ); if(res->flags &IORESOURCE_IRQ_LOWLEVEL ) printk( "LOWLEVEL " ); printk( "] " ); } if( res->flags & IORESOURCE_DMA ) { printk( "DMA [ISA:" ); if(res->flags &IORESOURCE_DMA_TYPE_MASK ) printk( "TYPEMASK " ); if(res->flags &IORESOURCE_DMA_8BIT ) printk( "8BIT " ); if(res->flags &IORESOURCE_DMA_8AND16BIT ) printk( "8AND16BIT " ); if(res->flags &IORESOURCE_DMA_16BIT ) printk( "16BIT " ); if(res->flags &IORESOURCE_DMA_MASTER ) printk( "MASTER " ); if(res->flags &IORESOURCE_DMA_BYTE ) printk( "BYTE " ); if(res->flags &IORESOURCE_DMA_WORD ) printk( "WORD " ); if(res->flags &IORESOURCE_DMA_SPEED_MASK ) printk( "SPEEDMASK " ); if(res->flags &IORESOURCE_DMA_COMPATIBLE ) printk( "COMPIT " ); if(res->flags &IORESOURCE_DMA_TYPEA ) printk( "TYPEA " ); if(res->flags &IORESOURCE_DMA_TYPEB ) printk( "TYPEB " ); if(res->flags &IORESOURCE_DMA_TYPEF ) printk( "TYPEF " ); printk( "] " ); } printk( "\n" ); printk( "<1> range : 0x%08x--0x%08x\n", (unsigned int)res->start, (unsigned int)res->end ); }}static void printmsg( struct pci_dev *dev ) { if( detail ) { printk( "<1>name : %s\n", dev->name ); printk( "<1>slot name : %s\n", dev->slot_name ); printk( "<1>slot : %d, func: %d\n", PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn) ); printk( "<1>vendor : 0x%04x, sub: 0x%04x\n", dev->vendor, dev->subsystem_vendor ); printk( "<1>device : 0x%04x, sub: 0x%04x\n", dev->device, dev->subsystem_device ); printk( "<1>class : 0x%04x, prog: 0x%02x\n", (unsigned short)(dev->class>>8), (unsigned char)dev->class ); printk( "<1>irq : %d\n", dev->irq ); printk( "<1>hdr type : %d", dev->hdr_type&0x7f ); if( dev->hdr_type&0x80 ) printk( " (Multi Func)\n" ); else printk( " (Singl Func)\n" ); int i; printk( "<1>resource :\n" ); for( i=0; i<DEVICE_COUNT_RESOURCE; i++ ) { print_resource( &dev->resource[i] ); } for( i=0; i<DEVICE_COUNT_DMA; i++ ) { print_resource( &dev->dma_resource[i] ); } for( i=0; i<DEVICE_COUNT_IRQ; i++ ) { print_resource( &dev->irq_resource[i] ); } printk( "\n" ); } else { printk( "<1>name : %s\n", dev->name ); printk( "<1>value : 0x%04x | 0x%04x | 0x%04x | 0x%02x | 0x%02x\n", dev->vendor, dev->device, (unsigned short)(dev->class>>8), dev->irq, PCI_SLOT( dev->devfn ) ); printk( "<1> : vendor | device | class | irq | slot\n" ); printk( "\n" ); }}static int __init showpci_init( void ){ struct pci_dev *dev = NULL; int count = 0; struct list_head *n = pci_devices.next; while( n!=&pci_devices ) { dev = pci_dev_g( n ); n = n->next; if( !vendor && !device && !class ) { printmsg( dev ); count ++; continue; } if( !vendor && !device && class ) { if( class==(unsigned short)((dev->class>>16)&0x0f) ) { printmsg( dev ); count ++; } continue; } if( !vendor && device && !class ) { if( device==dev->device ) { printmsg( dev ); count ++; } continue; } if( !vendor && device && class ) { if( device==dev->device && class==(unsigned short)((dev->class>>16)&0x0f) ) { printmsg( dev ); count ++; } continue; } if( vendor && !device && !class ) { if( vendor==dev->vendor ) { printmsg( dev ); count ++; } continue; } if( vendor && !device && class ) { if( vendor==dev->vendor && class==(unsigned short)((dev->class>>16)&0x0f)) { printmsg( dev ); count ++; } continue; } if( vendor && device && !class ) { if( vendor==dev->vendor && device==dev->device) { printmsg( dev ); count ++; } continue; } if( vendor && device && class ) { if( vendor==dev->vendor && device==dev->device && class==(unsigned short)((dev->class>>16)&0x0f) ) { printmsg( dev ); count ++; } continue; } } printk( "<1>device count: %d\n\n", count ); return 0;}static void __exit showpci_exit( void ){}module_init (showpci_init);module_exit (showpci_exit);MODULE_LICENSE( "GPL" );MODULE_AUTHOR( "enLinux" );MODULE_PARM( vendor, "i" );MODULE_PARM( device, "i" );MODULE_PARM( class, "i" );MODULE_PARM( detail, "i" );
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -