微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 总线设备驱动模型总结

总线设备驱动模型总结

时间:12-01 来源:互联网 点击:

while(length >

wait->

spin_lock_irqsave(&q->

if (list_empty(&wait->

spin_unlock_irqrestore(&q->

set_mb(current->

list_add(&new->task_list, &head->

wait->将相关的文件属性添加给总线类型,同时也必须检查返回值是否正确*/

int __must_check bus_create_file(struct bus_type *,struct bus_attribute *);

/*总线类型文件属性删除函数,将两者之间的关联性切断*/

void bus_remove_file(struct bus_type *, struct bus_attribute *);

最后需要将总线设备添加到系统中,主要采用设备注册函数;

设备注册函数:

int __must_check device_register(struct device *dev);

设备释放函数:

void device_unregister(struct device *dev);

2、设备

设备的实现主要是依靠struct device函数实现的,设备的实现主要是对结构体的填充。实现相应的函数即可。

struct device {

/*父设备,通常就是总线设备,这也是为什么需要将总线作为设备添加的原因*/

struct device *parent;

struct device_private *p;

struct kobject kobj;

/*init_name是新添加的,替代了原来的bus_id,但是init_name不能直接被读写操作*/

const char *init_name; /* initial name of the device */

struct device_type *type;

struct semaphore sem; /* semaphore 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 *driver_data; /* data private to the driver */

void *platform_data; /* Platform specific data, device

core doesnt touch it */

struct dev_pm_info power;

#ifdef CONFIG_NUMA

int numa_node; /* NUMA node this device is close to */

#endif

u64 *dma_mask; /* dma mask (if dmaable 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 dmable) */

struct dma_coherent_mem *dma_mem; /* internal for coherent mem

override */

/* arch specific additions */

struct dev_archdata archdata;

dev_t devt; /* dev_t, creates the sysfs "dev" */

spinlock_t devres_lock;

struct list_head devres_head;

struct klist_node knode_class;

struct class *class;

struct attribute_group **groups; /* optional groups */

/*必须实现的release函数*/

void (*release)(struct device *dev);

};

/*由于init_name 不能直接读写,只能通过*dev_name来读写设备名*/

static inline const char *dev_name(const struct device *dev)

{

return kobject_name(&dev->kobj);

}

/*实现对设备名的设置*/

int dev_set_name(struct device *dev, const char *name, ...)

__attribute__((format(printf, 2, 3)));

/*设备文件属性结构体,必须注意的改变点*/

struct device_attribute {

/*属性值*/

struct attribute attr;

/*设备属性读函数,必须注意是三个参数,不再是两个参数*/

ssize_t (*show)(struct device *dev, struct device_attribute *attr,char *buf);

/*设备属性写操作,必须注意是四个参数,不是三个参数*/

ssize_t (*store)(struct device *dev, struct device_attribute *attr,const char *buf, size_t count);

};

/*设备属性宏定义,主要用来实现设备文件属性*/

#define DEVICE_ATTR(_name, _mode, _show, _store)

struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store)

/*创建设备文件属性函数,必须检查返回值*/

int __must_check device_create_file(struct device *device,struct device_attribute *entry);

/*删除设备文件属性函数*/

void device_remove_file(struct device *dev,struct device_attribute *attr);

/*设备注册函数,必须检查返回值*/

int __must_check device_register(struct device *dev);

/*设备释放函数*/

void d

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top