| 
		    
		    
                    
   其中使用的pci_find_slot()函数定义为: 
 
    
        
            struct pci_dev *pci_find_slot (unsigned int bus, unsigned int devfn) {  struct pci_dev *pptr = kmalloc(sizeof(*pptr), GFP_KERNEL);  int index = 0;  unsigned short vendor;  int ret;
   if (!pptr) return NULL;  pptr->index = index; /* 0 */  ret = pcibios_read_config_word(bus, devfn, PCI_VENDOR_ID, &vendor);  if (ret /* == PCIBIOS_DEVICE_NOT_FOUND or whatever error */ || vendor==0xffff || vendor==0x0000) {   kfree(pptr); return NULL;  }  printk("ok (%i, %i %x)\n", bus, devfn, vendor);  /* fill other fields */  pptr->bus = bus;  pptr->devfn = devfn;  pcibios_read_config_word(pptr->bus, pptr->devfn,PCI_VENDOR_ID, &pptr->vendor);  pcibios_read_config_word(pptr->bus, pptr->devfn,PCI_DEVICE_ID, &pptr->device);  return pptr; } | 
         
    
 
  (3)根据设备的配置信息申请I/O空间及IRQ资源; 
  (4)注册设备。
    USB设备的驱动主要处理probe(探测)、disconnect(断开)函数及usb_device_id(设备信息)数据结构,如: 
 
    
        
            static struct usb_device_id sample_id_table[] = {  {   USB_INTERFACE_INFO(3, 1, 1), driver_info: (unsigned long)"keyboard"  } ,  {   USB_INTERFACE_INFO(3, 1, 2), driver_info: (unsigned long)"mouse"  }  ,  {   0, /* no more matches */  } };
  static struct usb_driver sample_usb_driver = {  name: "sample", probe: sample_probe, disconnect: sample_disconnect, id_table:  sample_id_table, }; | 
         
    
 
  当一个USB 设备从系统拔掉后,设备驱动程序的disconnect 函数会自动被调用,在执行了disconnect 函数后,所有为USB 设备分配的数据结构,内存空间都会被释放: 
 
    
        
            static void sample_disconnect(struct usb_device *udev, void *clientdata) {  /* the clientdata is the sample_device we passed originally */  struct sample_device *sample = clientdata;
   /* remove the URB, remove the input device, free memory */  usb_unlink_urb(&sample->urb);  kfree(sample);  printk(KERN_INFO "sample: USB %s disconnected\n", sample->name);
   /*  * here you might MOD_DEC_USE_COUNT, but only if you increment  * the count in sample_probe() below  */  return; } | 
         
    
 
  当驱动程序向子系统注册后,插入一个新的USB设备后总是要自动进入probe函数。驱动程序会为这个新加入系统的设备向内部的数据结构建立一个新的实例。通常情况下,probe 函数执行一些功能来检测新加入的USB 设备硬件中的生产厂商和产品定义以及设备所属的类或子类定义是否与驱动程序相符,若相符,再比较接口的数目与本驱动程序支持设备的接口数目是否相符。一般在probe 函数中也会解析USB 设备的说明,从而确认新加入的USB 设备会使用这个驱动程序: 
		    
                       
		      
		      
		   |