打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
struct class 和 struct class_device
设备类struct class是一个设备的高级视图,它抽象出低级的实现细节。例如,驱动可以见到一个SCSI磁盘或者一个ATA磁盘,在类的级别,他们都是磁盘,类允许用户空间基于它们作什么来使用设备,而不是它们如何被连接或者它们如何工作。
struct class{
    const char *name;   //类名称
    struct module *owner;   //对应模块
    struct subsystem subsys;   //对应的subsystem;
    struct list_head children;   //class_device链表
    struct list_head  interfaces;   //class_interface链表
    struct semaphore  sem;   //用于同步的信号锁
    struct class_attribute *class_attrs;   //类属性
    int (*uevent)(struct class_device *dev,char **envp,int num_envp,
                  char *buffer,int buffer_size);   //事件
    void (*release)(struct class_device *dev);   //释放类设备
    void (*class_release)(struct class *class);    //释放类
}

 

调用函数:

int class_register(struct class *cls); 

用于注册
void class_unregister(struct class *cls);

用于注销


      class可以看成是一个容器,容器总包含了很多的class_device,每个都对应着一个具体的逻辑设备,并通过成员变量dev关联一个物理设备。定义为:
struct class_device
{
    struct list_head node;

    struct kobject  kobj;   //内嵌的kobject,用于计数

    struct class   *class;   //所属的类;

    dev_t   devt;   //dev_t设备号

    struct class_device_attribute  *devt_attr;

    struct class_device_attribute  uevent_attr;

    struct device  *dev;   //如果存在,创建到/sys/devices相应入口的符号链接

    void *class_data;   //私有数据

    struct class_device  *parent;   //父设备

    void (*release)(struct class_device *dev);   //释放对应类实际设备的方法

    int(*uevent)(struct class_device *dev,char **envp,
                int num_envp,char *buffer,int buffer_size);

    char class_id[BUS_IO_SIZE];  //类标志
}

调用函数:

int class_device_register(struct class_device *class_dev); 

用于注册
void class_device_unregister(struct class_device *class_dev);

用于注销

 

相关结构体

struct class_interface
{
    struct list_head node;  
    struct class *class;   //所属的class
    int (*add)(struct class_device *,struct class_interface *);  //设备加入时触发
    void (*remove)(struct class_device *,struct class_interface *);//设备移出时触发
}

调用函数:
int class_interface_register(struct class_interface *class_intf);

用于注册
void class_interface_unregister(struct class_interface *class_intf);
用于注销

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
设备模型(总线、设备、驱动程序和类)
linux设备模型详解 2( 转 )
Linux设备驱动程序学习(17)-USB 驱动程序(二)
linux usb 设备驱动和接口驱动
Linux设备模型(8)_platform设备
linux设备模型之led子系统
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服