总线、设备、驱动,也就是 bus、device、driver

总线、设备、驱动,也就是 bus、device、driver,

在 include/linux/device.h 中定义

struct bus_type {
53 const char * name;
54 struct module * owner;
55
56 struct kset subsys;
57 struct kset drivers;
58 struct kset devices;

struct klist klist_devices;
60 struct klist klist_drivers;
61
62 struct blocking_notifier_head bus_notifier;
63
64 struct bus_attribute * bus_attrs;
65 struct device_attribute * dev_attrs;
66 struct driver_attribute * drv_attrs;
67 struct bus_attribute drivers_autoprobe_attr;
68 struct bus_attribute drivers_probe_attr;
69
70 int (*match)(struct device * dev, struct device_driver * drv);
71 int (*uevent)(struct device *dev, char **envp,
72 int num_envp, char *buffer, int buffer_size);
73 int (*probe)(struct device * dev);
74 int (*remove)(struct device * dev);
75 void (*shutdown)(struct device * dev);
76
77 int (*suspend)(struct device * dev, pm_message_t state);
78 int (*suspend_late)(struct device * dev, pm_message_t state);
79 int (*resume_early)(struct device * dev);
80 int (*resume)(struct device * dev);
81
82 unsigned int drivers_autoprobe:1;
83 };


124 struct device_driver {
125 const char * name;
126 struct bus_type * bus;
127
128 struct kobject kobj;
129 struct klist klist_devices;
130 struct klist_node knode_bus;
131
132 struct module * owner;
133 const char * mod_name; /* used for built-in modules */
134 struct module_kobject * mkobj;
135
136 int (*probe) (struct device * dev);
137 int (*remove) (struct device * dev);
138 void (*shutdown) (struct device * dev);
139 int (*suspend) (struct device * dev, pm_message_t state);
140 int (*resume) (struct device * dev);
141 };


410 struct device {
411 struct klist klist_children;
412 struct klist_node knode_parent; /* node in sibling list */
413 struct klist_node knode_driver;
414 struct klist_node knode_bus;
415 struct device *parent;
416
417 struct kobject kobj;
418 char bus_id[BUS_ID_SIZE]; /* position on parent bus */
419 struct device_type *type;
420 unsigned is_registered:1;
421 unsigned uevent_suppress:1;
422 struct device_attribute uevent_attr;
423 struct device_attribute *devt_attr;
424
425 struct semaphore sem; /* semaphore to synchronize calls to
426 * its driver.
427 */

struct bus_type * bus; /* type of bus device is on */
430 struct device_driver *driver; /* which driver has allocated this
431 device */
432 void *driver_data; /* data private to the driver */
433 void *platform_data; /* Platform specific data, device
434 core doesn't touch it */
435 struct dev_pm_info power;
436
437 #ifdef CONFIG_NUMA
438 int numa_node; /* NUMA node this device is close to */
439 #endif
440 u64 *dma_mask; /* dma mask (if dma'able device) */
441 u64 coherent_dma_mask;/* Like dma_mask, but for
442 alloc_coherent mappings as
443 not all hardware supports
444 64 bit addresses for consistent
445 allocations such descriptors. */
446
447 struct list_head dma_pools; /* dma pools (if dma'ble) */
448
449 struct dma_coherent_mem *dma_mem; /* internal for coherent mem
450 override */
451 /* arch specific additions */
452 struct dev_archdata archdata;
453
454 spinlock_t devres_lock;
455 struct list_head devres_head;
456
457 /* class_device migration path */
458 struct list_head node;
459 struct class *class;
460 dev_t devt; /* dev_t, creates the sysfs "dev" */
461 struct attribute_group **groups; /* optional groups */
462
463 void (*release)(struct device * dev);
464 };

struct bus_type 中有成员 struct kset
drivers 和 struct kset devices,同时 struct device 中有两个成员 struct bus_type * bus 和 struct
device_driver *driver,struct device_driver 中有两个成员 struct bus_type * bus 和 struct klist
klist_devices。先不说什么是 klist、kset,光从成员的名字看,它们就是一个完美的三角关系。

 struct device 中的 bus 表示这个设备连到哪个总线上,driver 表示这个设备的
驱动是什么。struct device_driver 中的 bus 表示这个驱动属于哪个总线,klist_devices 表示这个
驱动都支持哪些设备,因为这里 device 是复数,又是 list,更因为一个驱动可以支持多个设备,
而一个设备只能绑定一个驱动。当然,struct bus_type 中的 drivers 和 devices 分别表示了这个总
线拥有哪些设备和哪些驱动。

猜你喜欢

转载自blog.csdn.net/qq_34040053/article/details/88549430
今日推荐