Start_kernel rest_init (); kernel_thread (kernel_init, null, clone_fs | kernel); kernel (); driver_init (); void _ init driver_init (void) {/* These are the core pieces */devices_init (); indicates buses_init () in the/sys/devices/sys/dev/sys/block/sys/Char directory (); /sys/busclasses_init ();/sys/classfirmware_init ();/sys/firmwarehypervisor_init ();/* These are also core pieces, Must come after the * core pieces. */platform_bus_init (); system_bus_init (); cpu_dev_init (); memory_dev_init ();} platform Bus Device Driver: struct bus_type platform_bus_type = {. name = "Platform ",. dev_attrs = platform_dev_attrs ,. match = platform_match ,. uevent = platform_uevent ,. PM = platform_pm_ops_ptr,}; int _ init platform_bus_init (void) {int error; early_platform_cleanup (); error = device_register (& platform_bus); If (Er Ror) Return Error; error = bus_register (& platform_bus_type); // If (error) device_unregister (& platform_bus); Return Error;} USB Bus Device Driver: USB bus matching function static int usb_device_match (struct device * Dev, struct device_driver * DRV) {/* devices and interfaces are handled separately */If (is_usb_device (Dev )) {/* interface drivers never match devices */If (! Is_usb_device_driver (DRV) return 0;/* todo: add real matching code */return 1;} else {struct usb_interface * INTF; struct usb_driver * usb_drv; const struct usb_device_id * ID; /* device drivers never match interfaces */If (is_usb_device_driver (DRV) return 0; INTF = to_usb_interface (Dev); usb_drv = to_usb_driver (DRV); Id = usb_match_id (INTF, usb_drv-> id_table); If (ID) return 1; id = usb_match_dynamic_id (INTF, Usb_drv); If (ID) return 1;} return 0;} struct bus_type usb_bus_type = {. name = "USB ",. match = usb_device_match ,. uevent = usb_uevent,}; static const struct file_operations usb_fops = {. owner = this_module ,. open = usb_open,}; USB hub driver. Therefore, you can directly use the USB hub device in most cases. The system has completed device and driverstatic struct usb_driver hub_driver = {. name = "Hub ",. probe = hub_probe ,. disconnect = hub_disconnect ,. suspend = hub_suspend ,. resume = Hu B _resume ,. reset_resume = hub_reset_resume ,. pre_reset = hub_pre_reset ,. post_reset = hub_post_reset ,. IOCTL = hub_ioctl ,. id_table = hub_id_table ,. supports_autosuspend = 1,}; subsys_initcall (usb_init); retval = bus_register (& usb_bus_type); // USB Bus registration priv-> devices_kset = require ("devices", null, & amp; priv-& gt; subsys. kobj); // create devicespriv-> drivers_kset = kset_create_and_add ("drivers", null, & pr under/sys/bus/USB IV-> subsys. kobj); // create driversklist_init (& priv-> klist_devices, devices, klist_devices_put) under/sys/bus/USB; initialize the devices linked list klist_init (& priv-> klist_drivers, null, null); initialize the driver linked list retval = logging (& usb_bus_type, & usb_bus_nb); retval = usb_host_init (); retval = usb_major_init (); // register the character device error = logging (usb_major, "USB", & usb_fops); // view 180 USB under CAT/proc/devices, master device No. 180 retv Al = usb_register (& usbfs_driver); retval = usb_devi_init (); retval = usbfs_init (); retval = usb_hub_init (); usb_register (& hub_driver) // set the hub. add hub_driver in C to the drive chain list under the USB Bus new_driver-> drvwrap. driver. bus = & usb_bus_type; // specify the type of the added DRIVER: & usb_bus_type; retval = driver_register (& new_driver-> drvwrap. driver); ret = bus_add_driver (DRV); driver_find (DRV-> name, DRV-> Bus); ret = bus_add_driver (DRV); error = drive R_attach (DRV); bus_for_each_dev (DRV-> bus, null, DRV, _ driver_attach);} driver_match_device (DRV, Dev) // call the match on the bus, check whether the driver and device match driver_probe_device (DRV, Dev); really_probe (Dev, DRV); If (Dev-> bus-> probe) {ret = Dev-> bus-> probe (Dev); // use probeif (RET) goto probe_failed first;} else if (DRV-> probe) {ret = DRV-> probe (Dev); // call the hub. if (RET) goto probe_failed;} static int hub_probe (struct USB _ Interface * INTF, const struct usb_device_id * ID) hub_configure (hub, endpoint) pipe = usb_rcvintpipe (hdev, endpoint-> bendpointaddress); maxp = usb_maxpacket (hdev, pipe, usb_pipeout (PIPE); hub-> urb = usb_alloc_urb (0, gfp_kernel); usb_fill_int_urb (hub-> urb, hdev, pipe, * hub-> buffer, maxp, hub_irq, hub, endpoint-> binterval); hub-> urb-> transfer_dma = hub-> buffer_dma; hub-> urb-> transfer_flags | = urb_no_transfe R_dma_map; hub_activate (hub, hub_init); static declare_wait_queue_head (khubd_wait); // defines the waiting queue khubd_task = kthread_run (hub_thread, null, "khubd "); // enable the hub_thread wait_event_freezable (khubd_wait ,! List_empty (& hub_event_list) | kthread_should_stop (); // adds the current process to the waiting queue, where the process stops, let's take a look at Void wake (struct usb_device * hdev) Static void kick_khubd (struct usb_hub * hub) wake_up (& khubd_wait); // wake up the hub_thread hub_events (); hub_port_connect_change (hub, I, portstatus, portchange); udev = usb_alloc_dev (hdev, hdev-> bus, port1); // allocate a struct usb_device choose_address (udev ); // select the USB device address hub_p Ort_init dev_info (& udev-> Dev, "% S % s speed % susb device using % s and address % d \ n", (udev-> config )? "Reset": "new", speed, type, udev-> bus-> controller-> driver-> name, devnum ); hub_set_address // tell the selected address to the USB device retval = usb_get_device_descriptor (udev, 8); // obtain the device descriptor retval = usb_get_device_descriptor (udev, usb_dt_device_size );; // obtain the device descriptor status again = usb_new_device (udev); announce_device (udev); show_string (udev, "product", udev-> product); show_string (udev, "manufacturer ", udev-> manufacturer); show_string (Udev, "serialnumber", udev-> serial); err = device_add (& udev-> Dev); error = bus_add_device (Dev );; // Add the USB device to the device list under the USB Bus bus_attach_device (Dev); ret = device_attach (Dev); ret = bus_for_each_drv (Dev-> bus, null, Dev, _ device_attach); // call _ device_attach to determine whether the device and driver match driver_match_device (DRV, Dev) return DRV-> bus-> match? DRV-> bus-> match (Dev, DRV): 1; driver_probe_device (DRV, Dev); ret = really_probe (Dev, DRV); DRV-> probe (Dev ); // once matched, the driver's probe function will be called to describe the USB hub structure struct usb_hub {struct device * intfdev;/* The "interface" device */struct usb_device * hdev; struct krefkref; struct urb * urb;/* For interrupt polling pipe * // * buffer for urb... with extra space in case of babble */Char (* buffer) [8]; dma_addr_tbuffer_dma;/* DMA Address for buffer */Union {struct usb_hub_statushub; struct usb_port_statusport;} * status;/* buffer for status reports */struct mutexstatus_mutex;/* for the status buffer */interror; /* last reported Error */intnerrors;/* track consecutive errors */struct list_headevent_list;/* hubs w/data or errs ready */unsigned longevent_bits [1]; /* status change bitmask */unsigned longchange_bits [1];/* ports wit H logical connectstatus change */unsigned longbusy_bits [1];/* ports being reset orresumed */# If usb_maxchildren> 31/* 8 * sizeof (unsigned long) -1 */# error event_bits [] is too short! # Endifstruct usb_hub_descriptor * descriptor;/* class descriptor */struct usb_tttt;/* transaction translator */break;/* Current for each child */unsignedlimited_power: 1; Limit: 1; unsigneddisconnected: 1; unsignedhas_indicators: 1; u8indicator [usb_maxchildren]; struct delayed_workleds; struct delayed_workinit_work ;};