Linux USB subsystem-USB Bus Registry

Source: Internet
Author: User

Objective: To study USB in depth and take notes here. Welcome to the discussion.

[Linux 3.2] [Driver/USB/CORE/driver. C]

Definition: usb_bus_type

struct bus_type usb_bus_type = {.name ="usb",.match =usb_device_match,.uevent =usb_uevent,};

 

[Linux 3.2] [Driver/base/bus. C]

Function: bus_register (struct bus_type * Bus)

/** * bus_register - register a bus with the system. * @bus: bus. * * Once we have that, we registered the bus with the kobject * infrastructure, then register the children subsystems it has: * the devices and drivers that belong to the bus. */int bus_register(struct bus_type *bus){int retval;struct subsys_private *priv;priv = kzalloc(sizeof(struct subsys_private), GFP_KERNEL);if (!priv)return -ENOMEM;priv->bus = bus;bus->p = priv;BLOCKING_INIT_NOTIFIER_HEAD(&priv->bus_notifier);retval = kobject_set_name(&priv->subsys.kobj, "%s", bus->name);if (retval)goto out;priv->subsys.kobj.kset = bus_kset;priv->subsys.kobj.ktype = &bus_ktype;priv->drivers_autoprobe = 1;retval = kset_register(&priv->subsys);if (retval)goto out;retval = bus_create_file(bus, &bus_attr_uevent);if (retval)goto bus_uevent_fail;priv->devices_kset = kset_create_and_add("devices", NULL, &priv->subsys.kobj);if (!priv->devices_kset) {retval = -ENOMEM;goto bus_devices_fail;}priv->drivers_kset = kset_create_and_add("drivers", NULL, &priv->subsys.kobj);if (!priv->drivers_kset) {retval = -ENOMEM;goto bus_drivers_fail;}klist_init(&priv->klist_devices, klist_devices_get, klist_devices_put);klist_init(&priv->klist_drivers, NULL, NULL);retval = add_probe_files(bus);if (retval)goto bus_probe_files_fail;retval = bus_add_attrs(bus);if (retval)goto bus_attrs_fail;pr_debug("bus: '%s': registered\n", bus->name);return 0;bus_attrs_fail:remove_probe_files(bus);bus_probe_files_fail:kset_unregister(bus->p->drivers_kset);bus_drivers_fail:kset_unregister(bus->p->devices_kset);bus_devices_fail:bus_remove_file(bus, &bus_attr_uevent);bus_uevent_fail:kset_unregister(&bus->p->subsys);out:kfree(bus->p);bus->p = NULL;return retval;}EXPORT_SYMBOL_GPL(bus_register);

Bus_register is mainly used to handle Linux device models.

This function has the following functions:

1. Line 21: initialize a blocking notification chain.

2. Line 23 ~ 31: add the USB bus to the bus set and create a USB subdirectory under/sys/bus.

3. Line 35: Create a uevent attribute file under/sys/bus/USB.

4. Line 39 ~ 51: Create devices and drivers Subsets on the USB Bus subset and create directories at the same time.

5. Line 53 ~ 54: Initialize two linked lists: klist_devices and klist_drivers.

6. Line 56: add the drivers_probe and drivers_autoprobe attribute files of the bus. (Support for config_hotplug is required)

7. Line 60: add other property files of the bus. For USB, no.

After completing these steps, you can view the USB directory under/sys/bus,

You can see below the USB directory:

# Ls/sys/bus/USB

Devices drivers_autoprobe uevent drivers drivers_probe

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.