I am an EHCI (2) routine for Linux.

Source: Internet
Author: User

Zi Yue: give cards according to the routine. Indeed, there are routines for everything, and for a girl, it is better to spend money on a day before a month. Playing mahjong has a way to play mahjong. You can eat less, touch less, play less, and make a fortune. There are Starcraft routines and Linux routines. The story of Liu Tao's sister once again tells us that age is not a problem, height is not a distance, and CAI is enough.

Let's take a look at what happened after modprobe EHCI-HCD. EHCI-HCd is a driver. I don't know if you remember that I talked about the device model in sysfs. There are two important linked lists hanging on the bus. One is the device linked list, and the other is the driver linked list.

Every time we register a driver from a bus, the procedure is as follows:

Driver_register (struct device_driver * DRV)-> bus_add_driver ()-> driver_attach ()->

Bus_for_each_dev (DRV-> bus, null, DRV, _ driver_attach );

Bus_for_each_dev traverses all the devices on the bus and runs _ driver_attach () to check whether the driver can be associated with a device.

_ Driver_attach ()

-> Driver_probe_device ()

-> DRV-> bus-> match (Dev, DRV), // call the match function of the bus to check that the device and driver do not match. If it matches,

Continue to execute really_probe ().

-> Really_probe ()

-> Driver-> probe (). (If bus-> probe is not empty, call bus-> probe)

Every time we add a hardware to a bus, the procedure is as follows:

Device_add ()

// There are many operations in device_add: kobject. Register sysfs to form the code of the hardware hiberarchy structure.

If you forget it, refer to "I'm sysfs" first"

-> Bus_attach_device ()-> device_attach ()-> bus_for_each_drv ()

Bus_for_each_drv is similar to bus_for_each_dev. it traverses all the drivers on the bus and executes _ device_attach () once to check whether the device can be associated with a registered driver.

_ Device_attach ()

-> Driver_probe_device () // the same as above

To sum up, registering a driver for a certain bus is to first link the driver to the bus driver chain table and search for it from the device Chain List of the bus, check whether there are any devices that you can associate. Find probe and bind the two. On the contrary, the same applies to devices.

Okay, let's take a look at the things after modprobe EHCI-HCD. Everything starts from now on,

Module_init (ehci_hcd_init );

After removing unnecessary pre-compiled code, ehci_hcd_init is as follows:

Static int _ init ehci_hcd_init (void)
...{
Int retval = 0;

Pr_debug ("% s: block sizes: QH % ZD QTd % zd itd % ZD sitd % ZD ",
Hcd_name,
Sizeof (struct ehci_qh), sizeof (struct ehci_qtd ),
Sizeof (struct ehci_itd), sizeof (struct ehci_sitd ));

Retval = pci_register_driver (& pci_driver );
If (retval <0 )...{
Return retval;
}
If (retval <0 )...{
Platform_driver_unregister (& platform_driver );
Pci_unregister_driver (& pci_driver );
Return retval;
}
}

Pci_driver is a macro, # define pci_driver ehci_pci_driver.

Static struct pci_driver ehci_pci_driver = ...{
. Name = (char *) hcd_name,
. Id_table = pci_ids,

. Probe = usb_hcd_pci_probe,
. Remove = usb_hcd_pci_remove,

# Ifdef config_pm
. Suspend = usb_hcd_pci_suspend,
. Resume = usb_hcd_pci_resume,
# Endif
. Shutdown = usb_hcd_pci_shutdown,
};

Ehci_hcd_init calls pci_register_driver (), which is _ pci_register_driver ().

Int _ pci_register_driver (struct pci_driver * DRV, struct module * owner,
Const char * mod_name)
...{
Int error;

/** // * Initialize common driver fields */
DRV-> driver. Name = DRV-> name;
DRV-> driver. Bus = & pci_bus_type;
DRV-> driver. Owner = owner;
DRV-> driver. mod_name = mod_name;
DRV-> driver. kobj. ktype = & pci_driver_kobj_type;

Spin_lock_init (& DRV-> dynids. Lock );
Init_list_head (& DRV-> dynids. List );

/** // * Register with core */
Error = driver_register (& DRV-> driver );
If (error)
Return Error;

Error = pci_create_newid_file (DRV );
If (error)
Driver_unregister (& DRV-> driver );

Return Error;
}
Driver_register (struct device_driver * DRV) is a routine of Linux. Let's look at the match and probe functions of the PCI bus.

 

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/fudan_abc/archive/2008/01/09/2032635.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.