linux设备模型之总线,设备,驱动模型
2015-11-23 10:36
721 查看
驱动模型:
为了方便维护设备和驱动,内核抽象出三个类:
总线 struct bus_type;
设备 struct device;
驱动 struct device_driver;
这里的总线是抽象的该念总线,逻辑层面的,只是为了管理匹配
向内核注册并和总线关联的设备和驱动的,匹配规则决定于总线。
--------------------------------------------------------------------------------
struct bus_type {
const char *name; //总线的名字,注册成功后会见于/sys/bus/
const char *dev_name;
struct device *dev_root;
struct bus_attribute *bus_attrs;
struct device_attribute *dev_attrs;
struct driver_attribute *drv_attrs;
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 iommu_ops *iommu_ops;
struct subsys_private *p;
};
int (*match)(struct device *dev, struct device_driver *drv); //匹配规则
匹配规则由编写驱动者自己定义。但是匹配成功必须返回1,否则返回0;
总线的注册:
bus_register(struct bus_type *bus);
bus_unregister(struct bus_type *bus);
--------------------------------------------------------------------------------
设备:
struct device {
struct device *parent;
struct device_private *p;
struct kobject kobj;
const char *init_name; /* initial name of the device */ //设备的名字
// /sys/bus/xx/devices
const struct device_type *type;
struct mutex mutex; /* mutex 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;
struct dev_pm_domain *pm_domain;
#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; /* dma pools (if dma'ble) */
struct dma_coherent_mem *dma_mem; /* internal for coherent mem
override */
#ifdef CONFIG_CMA
struct cma *cma_area; /* contiguous memory area for dma
allocations */
#endif
/* arch specific additions */
struct dev_archdata archdata;
struct device_node *of_node; /* associated device tree node */
dev_t devt; /* dev_t, creates the sysfs "dev" */
u32 id; /* device instance */
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);
};
设备的注册及移除:
device_register(struct device *dev);
device_unregister(struct device *dev);
---------------------------------------------------------------------------------------
驱动:
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 */
const struct of_device_id *of_match_table;
int (*probe) (struct device *dev); //匹配成功,内核自动调用probe
int (*remove) (struct device *dev); //移除驱动时会自动调用remove
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;
};
驱动的注册及移除:
int driver_register(struct device_driver *drv)
int driver_unregister(struct device_driver *drv)
为了方便维护设备和驱动,内核抽象出三个类:
总线 struct bus_type;
设备 struct device;
驱动 struct device_driver;
这里的总线是抽象的该念总线,逻辑层面的,只是为了管理匹配
向内核注册并和总线关联的设备和驱动的,匹配规则决定于总线。
--------------------------------------------------------------------------------
struct bus_type {
const char *name; //总线的名字,注册成功后会见于/sys/bus/
const char *dev_name;
struct device *dev_root;
struct bus_attribute *bus_attrs;
struct device_attribute *dev_attrs;
struct driver_attribute *drv_attrs;
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 iommu_ops *iommu_ops;
struct subsys_private *p;
};
int (*match)(struct device *dev, struct device_driver *drv); //匹配规则
匹配规则由编写驱动者自己定义。但是匹配成功必须返回1,否则返回0;
总线的注册:
bus_register(struct bus_type *bus);
bus_unregister(struct bus_type *bus);
--------------------------------------------------------------------------------
设备:
struct device {
struct device *parent;
struct device_private *p;
struct kobject kobj;
const char *init_name; /* initial name of the device */ //设备的名字
// /sys/bus/xx/devices
const struct device_type *type;
struct mutex mutex; /* mutex 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;
struct dev_pm_domain *pm_domain;
#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; /* dma pools (if dma'ble) */
struct dma_coherent_mem *dma_mem; /* internal for coherent mem
override */
#ifdef CONFIG_CMA
struct cma *cma_area; /* contiguous memory area for dma
allocations */
#endif
/* arch specific additions */
struct dev_archdata archdata;
struct device_node *of_node; /* associated device tree node */
dev_t devt; /* dev_t, creates the sysfs "dev" */
u32 id; /* device instance */
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);
};
设备的注册及移除:
device_register(struct device *dev);
device_unregister(struct device *dev);
---------------------------------------------------------------------------------------
驱动:
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 */
const struct of_device_id *of_match_table;
int (*probe) (struct device *dev); //匹配成功,内核自动调用probe
int (*remove) (struct device *dev); //移除驱动时会自动调用remove
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;
};
驱动的注册及移除:
int driver_register(struct device_driver *drv)
int driver_unregister(struct device_driver *drv)
相关文章推荐
- Netlink技术-在Linux 下用户空间与内核空间数据交换的方式
- linux查找文件
- Linux下chkconfig命令详解
- 扩展Linux虚拟机硬盘、分区一例
- 个人linux简单笔记,随时更新
- ubuntu14.04中的搜狗输入法安装
- Linux Ctrl+Z的使用方法
- linux消息列队
- btrfs-snapper 实现Linux 文件系统快照回滚
- 信息安全系统设计基础实验一:Linux开发环境的配置和使用
- linux可变参数 va_arg
- Weblogic在Linux下启动特别慢及进入控制台慢的解决方法
- Linux统计文件行数
- [TZ]内存与IO访问(2)--Linux地址映射
- linux dirname指令
- Linux basename指令
- 基于busybox-1.23.2(stable)版本制作arm-linux使用根文件系统
- Linux find 命令使用小技巧一则
- linux下的find命令
- linux下alias命令详解