linux2.6设备文件系统
2015-03-27 18:51
344 查看
Linux2.6内核设备模型
Linux2.6内核设备模型组件
系统中的任一设备在设备,模型中都由一个device对象描述,其对应的数据结构struct
device定义如下:
struct device
{
struct klist klist_children; //设备列表中的孩子结点
struct klist_node knode_parent; //兄弟节点
struct klist_node knode_driver; //驱动节点
struct klist_node knode_bus; //总线节点
struct device *parent; //指向父设备
struct kobject kobj; //内嵌一个kobject对象
char bus_id[BUS_ID_SIZE]; //总线上的位置
struct device_attribute uevent_attr;
struct semaphore sem ;
struct bus_type *bus ; //总线
struct device_driver *driver ; //使用的驱动
void *driver_data; //驱动私有数据
void *platform_data; //平台特定的数据
void *firmware_data; //固件特定的数据(如ACPI、BIOS数据)
struct dev_pm_info power;
u64 *dma_mask; //DMA掩码
u64 coherent_dma_mask;
struct list_head dma_pools; //DMA缓冲区
struct dma_coherent_mem *dma_mem;
void (*release)(struct device * dev); //释放设备方法
};
device结构体用于描述设备相关的信息设备之间的层次关系,以及设备与总线、驱动的关系。
内核提供了相应的函数用于操作device对象。其中,device_register()函数将一个新的device对象插入设备模型,并自动在/sys/device下创建一个对应的目录。device_unregister()完成相反的操作,注销设备对象。get_device()和put_device()分别增加与减少设备对象的引用计数。通常device结构体不单独使用,而是包含在更大的结构体中,比如描述PCI设备的struct
pci_dev,其中的dev域就是一个device对象。
系统中的每个驱动程序由一个device_driver对象描述,对应的数据结构的定义如下:
struct device_driver
{
const char *name; //设备驱动程序的名称
struct bus_type *bus; //总线
struct completion unload;
struct kobject kobj; //内嵌的kobject对象
struct klist klist_devices;
struct klist_node knode_bus;
struct module *owner;
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);
};
与device结构体类似,device_driver对象依靠内嵌的kobject对象实现引用计数管理和层次结构组织。内核提供类似的函数用于操作device_driver对象。如get_driver()增加引用计数,driver_register()用于向设备模型插入新的driver对象,同时在sysfs文件系统中创建对应的目录。device_driver()结构体还包括几个函数,用于处理探测、移除和电源管理事件。
系统中总线由struct bus_type描述,其定义如下:
struct bus_type
{
const char *name; //总线类型的名称
struct subsystem subsys; //与总线相关的subsystem
struct kset drivers; //所有与该总线相关的驱动程序集合
struct kset devices; //所有挂接在总线上的设备集合
struct klist klist_devices;
struct klist klist_drivers;
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,char **envp,int num_envp,char *buffer,int buffer_size);
int (*probe)
(struct device *dev) ;
int (*remove) (struct device *dev) ;
int (*shutdown) (struct device *dev) ;
int (*suspend) (struct device *dev,pm_message_t
state);
int (*resume) (struct device *dev) ;
};
每个bus_type对象都内嵌一个subsystem对象,bus_subsys对象管理系统中所有总线类型的subsystem对象。每个bus_type对象都对应/sys/bus目录下的一个子目录,如PCI总线类型对应于/sys/bus/pci。在每个这样的目录下都存在两个子目录:device和drivers(分别对应于bus_type结构中的devices和drivers域)。其中,devices子目录描述连接在该总线上的所有设备,而drivers目录则描述与该总线关联的所有驱动程序。与device_driver对象类似,bus_type结构还包括几个函数处理热插拔、即插即拔和电源管理事件的函数。
系统中的设备类型由struct class描述,表述某一类设备。所有的class对象都属于class_subsys子系统,对应于sysfs文件系统中的/sys/class目录,如下所示: http://blog.sina.com.cn/s/blog_682686610100w5wf.html
相关文章推荐
- linux2.6内核文件系统与设备模型
- Linux-2.6设备模型与sysfs文件系统
- inotify -- Linux 2.6 内核中的文件系统变化通知机制
- 嵌入式Linux2.6 根文件系统制作
- inotify -- Linux 2.6 内核中的文件系统变化通知机制
- inotify -- Linux 2.6 内核中的文件系统变化通知机制
- inotify -- Linux 2.6 内核中的文件系统变化通知机制
- linux文件系统之loop环设备--新建一个文件系统并挂载
- linux文件系统的系统分析--(十六)sysfs和设备模型--从platform和rtc来感受设备模型
- inotify -- Linux 2.6 内核中的文件系统变化通知机制
- inotify -- Linux 2.6 内核中的文件系统变化通知机制
- Linux设备驱动开发详解-Note(9) --- Linux 文件系统与设备文件系统(1)
- Linux设备驱动开发详解-Note(10)--- Linux 文件系统与设备文件系统(2)
- Monit - Linux系统进程、文件、目录和设备的监测软件
- linux下,在挂载设备之前,查看设备的文件系统类型
- 基于Linux2.6的YAFFS文件系统移植
- inotify -- Linux 2.6 内核中的文件系统变化通知机制
- inotify -- Linux 2.6 内核中的文件系统变化通知机制
- 2.6 使用Linux文件系统
- 文件系统管理 之 在Linux系统中存储设备的两种表示方法