linux总线对象bus_type
2016-05-29 17:33
302 查看
linux总线对象bus_type
struct bus_type { const char *name; //总线名字 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 bus_type_private *p; //管理总线上的设备与驱动 }; struct bus_type_private { struct kset subsys; //总线的kset struct kset *drivers_kset; //驱动对象的kset struct kset *devices_kset; //设备对象的kset struct klist klist_devices; struct klist klist_drivers; struct blocking_notifier_head bus_notifier; unsigned int drivers_autoprobe:1; struct bus_type *bus; }; //注册总线 /base/bus.c int __init buses_init(void) { bus_kset = kset_create_and_add("bus", &bus_uevent_ops, NULL); if (!bus_kset) return -ENOMEM; return 0; } int bus_register(struct bus_type *bus) { priv = kzalloc(sizeof(struct bus_type_private), GFP_KERNEL); priv->subsys.kobj.kset = bus_kset; priv->subsys.kobj.ktype = &bus_ktype; //kobject_type retval = kobject_set_name(&priv->subsys.kobj, "%s", bus->name); retval = kset_register(&priv->subsys); //注册subsys的kset retval = bus_create_file(bus, &bus_attr_uevent); //创建 sysbus 的 attr priv->devices_kset = kset_create_and_add("devices", NULL, //创建subsys的kset的driver &priv-subsys.kobj priv->drivers_kset = kset_create_and_add("drivers", NULL, //创建subsys的kset的device &priv->subsys.kobj); } 举例:操作总线属性 //操作属性文件 static BUS_ATTR(uevent, S_IWUSR, NULL, bus_uevent_store); #define BUS_ATTR(_name, _mode, _show, _store) \ struct bus_attribute bus_attr_##_name = __ATTR(_name, _mode, _show, _store) 举例: int bus_register(struct bus_type *bus) { retval = bus_create_file(bus, &bus_attr_uevent); retval = add_probe_files(bus); retval = bus_create_file(bus, &bus_attr_drivers_probe); retval = bus_create_file(bus, &bus_attr_drivers_autoprobe); } static BUS_ATTR(drivers_autoprobe, S_IWUSR | S_IRUGO, show_drivers_autoprobe, store_drivers_autoprobe); #define BUS_ATTR(_name, _mode, _show, _store) \ struct bus_attribute bus_attr_##_name = __ATTR(_name, _mode, _show, _store) static ssize_t show_drivers_autoprobe(struct bus_type *bus, char *buf) { return sprintf(buf, "%d\n", bus->p->drivers_autoprobe); } static ssize_t store_drivers_autoprobe(struct bus_type *bus, const char *buf, size_t count) { if (buf[0] == '0') bus->p->drivers_autoprobe = 0; else bus->p->drivers_autoprobe = 1; return count; } //应用空间修改attr文件的值 [root@EmbedSky i2c]# cat drivers_autoprobe 1 [root@EmbedSky i2c]# echo 0 > drivers_autoprobe [root@EmbedSky i2c]# cat drivers_autoprobe 0
相关文章推荐
- Linux下查看文件和文件夹大小
- Linux中常用的查询指令(which、whereis、find、locatae)
- CentOs中mysql的安装与配置
- CentOS,Ubuntu,Gentoo,Freebsd,RedHat,Debian的区别及选择
- Linux 常用命令积累
- Unix & Linux笔记(16)
- [置顶] linux系统工程师修改打开文件数限制代码教程。服务器运维技术
- Centos sudo添加用户
- 安装虚拟机报错:Could not get vmci driver version: 参数错误. You have an incorrect version of driver "vmci.sys".
- [置顶] 修改linux操作系统的时间可以使用date指令 运维系统工程师必会技术
- Linux下1号进程的前世(kernel_init)今生(init进程)----Linux进程的管理与调度(六)
- CentOS-6.5-x86 安装 jdk-7u79-linux-i586.rpm
- linux字符设备驱动
- Go程序在Linux作为后台应用daemon运行
- 回顾linux系统编程学习过程
- Linux信号
- C语言下的FILE指针与Linux的文件描述符
- linux 的简单应用
- Unix & Linux笔记(15)
- centos6.5二进制安装mysql