关闭

Linux---device_driver驱动理论详解

发表于:2013-12-27 10:47

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:kokodudu    来源:51Testing软件测试网采编

  驱动程序的描述结构体
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 */
#if defined(CONFIG_OF)
const struct of_device_id *of_match_table;
#endif
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;
};
  设备驱动注册
  driver_register(struct device_driver *drv);
  设备驱动注销
  driver_unregister(struct device_driver *drv);
  驱动属性描述结构体
struct driver_attribute {
struct attribute attr;
ssize_t (*show)(struct device_driver *driver, char *buf);//读取时调用的函数
ssize_t (*store)(struct device_driver *driver, const char *buf,
size_t count);//写入的时候 调用的函数
};
  但是属性文件的创建都是使用下面的这个宏来创建
#define DRIVER_ATTR(_name, _mode, _show, _store)\////////注意参数的意义:
struct driver_attribute driver_attr_##_name =  \//根据 宏的第一个参数 来创建名为driver_attr_name的属性文件
__ATTR(_name, _mode, _show, _store)//
  创建属性文件的函数
  driver_create_file(struct device_driver *driver,const struct driver_attribute *attr);//注意参数 第一个是 自己的定义驱动结构体,第二个是驱动属性文件
31/3123>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号