驱动模型
2015-11-21 18:09
375 查看
驱动模型:
为了方便维护设备和驱动,内核抽象出三个类:
总线 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)
相关文章推荐
- Linux下的proc目录详解
- c语言俄罗斯方块
- 基于 platform 总线的设备驱动编写模式:
- RAC DATAGUARD primary listener
- Asp.net中实现同一用户名不能同时登录(单点登录)
- Socket套接字
- php cli模式和浏览器访问下加载php.ini文件的注意事项[架构篇]
- setInterval和setTimeout
- gdb调试SAPI方式的php
- HDU 2795 Billboard【线段树】单点查找更新
- CCF真题--数字排序
- Windows Server 2008R2 取消屏幕自动锁定
- Android 窗口添加机制系列2-Dialog,PopupWindow,Toast
- saltstack 测试
- 【Android】仿QQ功能点击通知栏返回应用,非启动一个新Activity
- 泡在网上的日子
- 转: 关于android 机型适配的问题
- 罗网统计:软件系统升级公告
- CCF真题--图像旋转
- 最新版SDWebImage的使用