Linux设备驱动编程模型之设备篇
Linux设备驱动编程模型之设备篇
设备驱动程序模型建立在几个基本数据结构上,这些结构描述了总线、设备、设备驱动、属性以及他们之间的关系。我们首先认识一下这些数据结构。一、数据结构
设备表述符
[cpp]- struct device {
- struct device *parent;/*指向父设备的指针*/
- /*该字段用于管理device和其他device结构,一起device
- 与其他结构之间的关系*/
- struct device_private *p;
- struct kobject kobj;/*内嵌的kobject结构*/
- const char *init_name; /* initial name of the device */
- struct device_type *type;
- struct semaphore sem; /* semaphore to synchronize calls to
- * its driver.
- */
- struct bus_type *bus;/*指向所连接总线的指针*/ /* type of bus device is on */
- struct device_driver *driver;/*指向控制设备驱动程序的指针*//* which driver has allocated this
- device */
- void *platform_data;/*指向遗留设备驱动程序的私有数据的指针*//* Platform specific data, device
- core doesn't touch it */
- struct dev_pm_info power;
- #ifdef CONFIG_NUMA
- int numa_node; /* NUMA node this device is close to */
- #endif
- u64 *dma_mask; /* dma mask (if dma'able device) */
- u64 coherent_dma_mask;/* Like dma_mask, but for
- alloc_coherent mappings as
- not all hardware supports
- 64 bit addresses for consistent
- allocations such descriptors. */
- struct device_dma_parameters *dma_parms;
- struct list_head dma_pools;/*www.bkjia.com聚集的DMA缓冲池链表的首部*//* dma pools (if dma'ble) */
- struct dma_coherent_mem *dma_mem;/*指向设备所使用的一致性DMA存储器描述符的指针*//* internal for coherent mem
- override */
- /* arch specific additions */
- struct dev_archdata archdata;
- dev_t devt; /* dev_t, creates the sysfs "dev" */
- spinlock_t devres_lock;
- struct list_head devres_head;
- struct klist_node knode_class;
- struct class *class;
- const struct attribute_group **groups; /* optional groups */
- void (*release)(struct device *dev);/*释放设备描述符的回调函数*/
- };
Bus描述符
[cpp]- struct bus_type {
- const char *name;/*总线类型名称*/
- /*指向对象的指针,该对象包含总线属性和用于导出此属性到sysfs文件系统的方法*/
- struct bus_attribute *bus_attrs;
- /*指向对象的指针,该对象包含设备属性和用于导出此属性sysfs文件系统的方法*/
- struct device_attribute *dev_attrs;
- /*指向对象的指针,该对象包含设备驱动程序属性和用于导出此属性到sysfs文件
- 的方法*/
- struct driver_attribute *drv_attrs;
- /*检验给定的设备驱动程序是否支持特定设备的方法www.bkjia.com*/
- int (*match)(struct device *dev, struct device_driver *drv);
- /**/
- int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
- int (*probe)(struct device *dev);
- int (*remove)(struct device *dev);
- void (*shutdown)(struct device *dev);
- int (*suspend)(struct device *dev, pm_message_t state);
- int (*resume)(struct device *dev);
- const struct dev_pm_ops *pm;
- struct bus_type_private *p;
- };
设备驱动
[cpp]- /*设备驱动程序模型中的每个驱动程序*/
- struct device_driver {
- const char *name;/*设备驱动程序的名称*/
- struct bus_type *bus;/*指向总线描述符的指针,总线连接所支持的设备*/
- struct module *owner;/*标识实现设备程序的模块,如果有的话*/
- const char *mod_name; /* used for built-in modules */
- bool suppress_bind_attrs; /* disables bind/unbind via sysfs */
- int (*probe) (struct device *dev);/*探测设备的方法(检验设备驱动程序是否可以控制该设备)*/
- int (*remove) (struct device *dev);/*移走设备时所调用的方法*/
- void (*shutdown) (struct device *dev);/*设备断电时所调用的方法*/
- int (*suspend) (struct device *dev, pm_message_t state);/*设备置于低功率状态时所调用的方法*/
- int (*resume) (struct device *dev);/*设备恢复正常状态时所调用的方法*/
- const struct attribute_group **groups;
- const struct dev_pm_ops *pm;
- struct driver_private *p;
- };
类描述符
[cpp]- /*
- * device classes
- */
- struct class {
- const char *name;
- struct module *owner;
- struct class_attribute *class_attrs;
- struct device_attribute *dev_attrs;
- struct kobject *dev_kobj;
- int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env);
- char *(*devnode)(struct device *dev, mode_t *mode);
- void (*class_release)(struct class *class);
- void (*dev_release)(struct device *dev);
- int (*suspend)(struct device *dev, pm_message_t state);
- int (*resume)(struct device *dev);
- const struct dev_pm_ops *pm;
- struct class_private *p;
- };
|
评论暂时关闭