Underlying Linux Driver Model 2: Upper-layer containers

Source: Internet
Author: User

1) Bus
In the system, the bus is described by struct bus_type and defined:
Struct bus_type {
Char * Name; Name of the Bus Type
Struct subsystem subsys; the subsystem associated with the bus
Struct kset drivers; a collection of all drivers related to the bus
Struct kset devices; a collection of all devices attached to the bus
Struct bus attribute * bus_attrs; bus attribute
Struct device attribute * dev_attrs; device attribute
Struct driver attribute * drv_attrs; driver attributes
INT (* match) (struct device * Dev, struct device_driver * DRV );
INT (* hotplug) (struct device * Dev, char ** envp, int num_envp, char * buffer, int buffer_size );
INT (* suspend) (struct device * Dev, u32 State );
INT (* resume) (struct device * Dev );
};
Each bus_type object is embedded with a subsystem object. Each bus_type object corresponds to a sub-directory under the/sys/bus directory. For example, the PCI bus type corresponds to/sys/bus/PCI. Each directory contains two subdirectories: devices and drivers (corresponding to the devices and drivers fields in the bus type structure ). The devices subdirectory describes all devices connected to the bus, and the DRIVERS directory describes all drivers associated with the bus. Similar to the device_driver object, the bus_type structure also contains several functions (such as match () and hotplug () to handle hot swapping, Plug and Play, and power management events.

2) Device
Any device in the system is described by a device object in the device model. The corresponding data structure is struct device.
Defined:
Struct device {
Struct list_head g_list;
Struct list_head node;
Struct list_head bus_list;
Struct list_head driver_list;
Struct list_head children;
Struct device * parent;
Struct kobject kobj;
Char bus_id [bus_id_size];
Struct bus_type * bus;
Struct device_driver * driver;
Void * driver_data;
/* Several fields omitted */
};
G_list mounts the device object to the global device linked list. All Device objects are contained in devices subsys and organized into hierarchies. The node field connects the object to the linked list of its brother object, while the bus list organizes devices connected to the same bus into a linked list, the driver list organizes all devices managed by the same driver into a linked list. In addition, the children field points to the sub-object linked list header of the device object, and the parent field points to the parent object. The device object is also embedded with a kobject object, which is used to reference counting management and implement the device hierarchy. The driver domain points to the driver object that manages the device, while the driver data is the data provided to the driver. The bus field describes the type of the bus that the device is connected.

The kernel provides functions to operate Device objects. The device_register () function inserts a new device object into the device model and automatically creates a corresponding directory under/sys/devices. Device_unregister () to cancel the device object. Get_device () and put_device () increase and decrease the reference count of the device object respectively. Generally, the device structure is not used independently, but included in a larger structure as a sub-structure. For example, struct pci_dev describing the PCI device and ldd_dev. the dev field is a device object.

§ 3) Driver
Each driver in the system is described by a device_driver object. The corresponding data structure is defined:
Struct device_driver {
Char * Name; Name of the device driver
Struct bus_type * bus; type of the bus to which the driver is attached
Struct kobject kobj; embedded kobject object
Struct list_head devices; device linked list header managed by the driver
INT (* probe) (struct device * Dev); points to the device detection function to detect whether the device can be managed by the driver.
INT (* remove) (struct device * Dev); function used to delete a device
/* Some fields omitted */
};
Similar to the device structure, the device_driver object relies on the embedded kobject object to implement reference counting management and hierarchical organization. The kernel provides similar functions to operate the device_driver object, such as get_driver () to increase the reference count, and driver_register () to insert a new driver object to the device model, create a directory in the sysfs file system. The device_driver () structure also includes several functions for hot plugging, plug-and-play, and power management events.

 

 

You may be very upset about the column data structure you just listed. It doesn't matter. You will understand the following example.

Http://blog.csdn.net/fudan_abc/archive/2007/09/01/1768315.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.