Chinaunix首页 | 论坛 | 博客
  • 博客访问: 381195
  • 博文数量: 87
  • 博客积分: 983
  • 博客等级: 准尉
  • 技术积分: 685
  • 用 户 组: 普通用户
  • 注册时间: 2012-06-25 07:20
文章分类

全部博文(87)

文章存档

2016年(1)

2015年(3)

2014年(55)

2013年(13)

2012年(15)

分类: LINUX

2012-09-21 11:19:44

int class_create_file(struct class *cls, const struct class_attribute *attr)
{  //create an attribute file for an object.
     error = sysfs_create_file(&cls->p->class_subsys.kobj,
                               &attr->attr);
    ...
}
 
static int add_class_attrs(struct class *cls)
{
    ...
    error = class_create_file(cls, &cls->class_attrs[i]);
    ...
}
 
int __class_register(struct class *cls, struct lock_class_key *key)
{  //
    struct class_private *cp;
    klist_init(&cp->class_devices, klist_class_dev_get, klist_class_dev_put);
    INIT_LIST_HEAD(&cp->class_interfaces);
    kset_init(&cp->class_dirs);
    __mutex_init(&cp->class_mutex, "struct class mutex", key);
    error = kobject_set_name(&cp->class_subsys.kobj, "%s", cls->name);
    ...
    cp->class_subsys.kobj.ktype = &class_ktype;
    cp->class = cls;
    cls->p = cp;
    error = kset_register(&cp->class_subsys);
    error = add_class_attrs(class_get(cls));
    ...
}
 
struct class *__class_create(struct module *owner, const char *name,
        struct lock_class_key *key)
{
    struct class *cls;
    cls = kzalloc(sizeof(*cls), GFP_KERNEL);
    ...
    cls->name = name;
    cls->owner = owner;
    cls->class_release = class_create_release;
    retval = __class_register(cls, key);
    ...
}
 
 
 
void class_dev_iter_init(struct class_dev_iter *iter, struct class *class,
                         struct device *start, const struct device_type *type)
{
    klist_iter_init_node(&class->p->class_devices, &iter->ki, start_knode);
}
 
struct device *class_dev_iter_next(struct class_dev_iter *iter)
{
    while (1) {
        knode = klist_next(&iter->ki);
        if (!knode)
        return NULL;
       dev = container_of(knode, struct device, knode_class);
       if (!iter->type || iter->type == dev->type)
       return dev;
   }
}
 
int class_for_each_device(struct class *class, struct device *start,
                       void *data, int (*fn)(struct device *, void *))
{
    class_dev_iter_init(&iter, class, start, NULL);
    while ((dev = class_dev_iter_next(&iter))){
        ....
    }
}
 
struct device *class_find_device(struct class *class, struct device *start,
     void *data,
     int (*match)(struct device *, void *))
{
    class_dev_iter_init(&iter, class, start, NULL);
    while ((dev = class_dev_iter_next(&iter)){
        ...
    }
}
 
int class_interface_register(struct class_interface *class_intf){
    parent = class_get(class_intf->class);
    mutex_lock(&parent->p->class_mutex);
    list_add_tail(&class_intf->node, &parent->p->class_interfaces);
    ...
     class_dev_iter_init(&iter, parent, NULL, NULL);
     while ((dev = class_dev_iter_next(&iter))){...}
}
阅读(1284) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~