// gcc -c pcitest.c -Wall -Wstrict-prototypes -O #define MODULE #define __KERNEL__ #include #if defined(CONFIG_MODVERSIONS) && !defined(MODVERSIONS) # define MODVERSIONS #endif #ifdef MODVERSIONS # include #endif #include #include #include #include #undef L24 //#define L24 static int vendorid=0x8086; // 適宜 static int deviceid=0x1229; #if LINUX_VERSION_CODE > 0x20115 MODULE_PARM(vendorid, "i"); MODULE_PARM(deviceid, "i"); #endif int init_module(void) { int i,j; struct pci_dev *pdev=NULL; for(i=0;;i++) { pdev=pci_find_device(vendorid,deviceid,pdev); if(!pdev) break; // これ以上ドライバ見つからず printk("pcitest: found device(%04X,%04X,%d) on" " Bus:%d Device:%d Function:%d\n", vendorid,deviceid,i, pdev->bus->number,pdev->devfn>>3,pdev->devfn&0x7); for(j=0;j<6;j++) { #ifdef L24 unsigned long start=pci_resource_start(pdev,j); unsigned long flags=pci_resource_flags(pdev,j); if(flags & IORESOURCE_IO) { printk("pcitest: found base(%d) I/O address: " "%04lX\n",j,start); } if(flags & IORESOURCE_MEM) { printk("pcitest: found base(%d) Mem address: " "%08lX\n",j,start); } #else unsigned long baseaddr=pdev->base_address[j]; if((baseaddr&PCI_BASE_ADDRESS_SPACE)== PCI_BASE_ADDRESS_SPACE_IO) { printk("pcitest: found base(%d) I/O address: ",j); printk("%04lX\n",baseaddr&PCI_BASE_ADDRESS_IO_MASK); } else { printk("pcitest: found base(%d) Mem address: ",j); printk("%08lX\n",baseaddr&PCI_BASE_ADDRESS_MEM_MASK); } #endif } printk("pcitest: found IRQ %d\n",pdev->irq); } if(i==0) { printk("There is no device vendor:%04X device:%04X\n", vendorid,deviceid); } return 1; // insmod がこけるように } void cleanup_module(void) { }