




下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、 linux上pcie驱动设计 摘 要:当前基于linux内核的操作系统应用越来越广泛,开发基于linux的设备驱动程序,具有很强的实用性和可移植性。本文简单介绍linux系统上pci-e设备驱动的框架以及重要的数据结构。关键词:linux;pci-e;pci;驱动abstract:at present,the operating system based on linux kernel is used more and more widely. it is very practical and portable to develop the
2、 device driver based on linux. this article briefly introduces the framework and the important data structure of pci-e device driver on linux system .key word: linux;pci-e;pci;driverpci-express 简称pci-e,是一种完全不同于pci、具有高速串行点对点双通道高带宽传输模式的全新总线规范,所连接的设备分配独享通道带宽,不共享总线带宽,支持端对端的可靠性传输。pci-e在软件层面上兼容的pci技术和设备,支
3、持pci设备和内存模组的初始化,也就是说驱动程序、操作系统完全兼容。1 pci设备与驱动关系pci设备通常由一组参数唯一地标识,它们被vendorid,deviceid和class nodes所标识,即设备厂商,型号等,这些参数保存在 pci_device_id结构中。每个pci设备都会被分配一个pci_dev变量。所有的pci驱动程序都必须定义一个pci_driver结构变量,在该变量中包含了这个pci驱动程序所提供的不同功能的函数,同时,在这个结构中也包含了一个device_driver结构,这个结构定义了pci子系统与pci设备之间的接口。在注册pci驱动程序时,这个结构将被初始化,同时
4、这个 pci_driver变量会被链接到pci_bus_type中的驱动链上去。在pci_driver中有一个成员struct pci_device_id *id_table,它列出了这个设备驱动程序所能够处理的所有pci设备的id值。2 基本框架在用模块方式实现pci设备驱动程序时,通常至少要实现以下几个部分:初始化设备模块、设备打开模块、数据读写和控制模块、中断处理模块、设备释放模块、设备卸载模块。下面给出一个典型的pci设备驱动程序的基本框架,从中不难体会到这几个关键模块是如何组织起来的。staticstruct pci_device_id example_pci_tbl _initda
5、ta =pci_vendor_id_example,pci_device_id_example,pci_any_id,pci_any_id,0,0, example,0,;struct example_pci /* 對特定pci设备进行描述的数据结构 */unsigned int magic;struct example_pci *next;/* 使用链表保存所有同类的pci设备 */* . */staticvoid example_interrupt(int irq,void*dev_id,struct pt_regs *regs)/* 中断处理模块 */* . */staticstruct
6、 file_operations example_fops = /* 设备文件操作接口 */owner: this_module,/* demo_fops所属的设备模块 */read: example_read,/* 读设备操作*/write: example_write,/* 写设备操作*/ioctl: example_ioctl,/* 控制设备操作*/open: example_open,/* 打开设备操作*/elease: example_release /* 释放设备操作*/* . */;staticstruct pci_driver example_pci_driver =/ * 设
7、备模块信息 */name: example_module_name,/* 设备模块名称 */id_table: example_pci_tbl,/* 能够驱动的设备列表 */probe: example_probe,/* 查找并初始化设备 */remove: example_remove /* 卸载设备模块 */* . */;staticint _init example_init_module (void)/* . */staticvoid _exit example_cleanup_module (void)pci_unregister_driver(&demo_pci_drive
8、r);module_init( example_init_module);/* 加载驱动程序模块入口 */module_exit( example_cleanup_module);/* 卸载驱动程序模块入口 */3 主要数据结构上面这段代码给出了一个典型的pci设备驱动程序的框架,是一种相对固定的模式。主要用了几个重要的数据结构。struct pci_device_id _u32 vendor, device;/* vendor and device id or pci_any_id*/_u32 subvendor, subdevice;/* subsystem id's o
9、r pci_any_id */_u32 class, class_mask;/* (class,subclass,prog-if) triplet */kernel_ulong_t driver_data;/* data private to the driver */;vendorid:标识硬件制造商,是一个16位的寄存器。deviceid:设备id,由制造商选择,也是一个16位的寄存器。class:每个外部设备属于某个类(class),也是一个16位的寄存器。struct pci_driver struct list_head node;char*name;conststruct pci_
10、device_id *id_table;/* must be non-null for probe to be called */int(*probe)(struct pci_dev *dev,conststruct pci_device_id *id);/* new device inserted */void(*remove)(struct pci_dev *dev);/* device removed */* . */;struct pci_driver它的作用并不仅仅是识别设备的id_table结构,还包括了检测设备的函数probe()和卸载设备的函数remove(),struct p
11、ci_dev struct list_head bus_list;/* node in per-bus list */struct pci_bus *bus;/* bus this device is on */struct pci_bus *subordinate;/* bus this device bridges to */void*sysdata;/* hook for sys-specific extension */struct proc_dir_entry *procent;/* device entry in /proc/bus/pci */struct pci_slot *slot;/* physical slot this device is in */unsignedint devfn;/* encoded device & function index */unsignedshort vendor;unsignedshort device;/* . */;它詳细描述了一个pci设备几乎所有的硬件信息,包括厂商id、设备id、各种资源等。4 结束语linux pci设备驱动实际包括linux pci设备驱动和具体设备本身驱动
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 高效谷物分级与包装生产线行业跨境出海战略研究报告
- 抗肿瘤多靶点药物企业制定与实施新质生产力战略研究报告
- 二年级组工作总结
- 公寓租赁合同模板
- 电脑维护服务合同范本
- 上海市微型计算机商品买卖合同
- 定金合同范文
- 2025-2030中国年龄相关性黄斑变性药物行业市场现状供需分析及投资评估规划分析研究报告
- 2025-2030中国干式涡旋真空泵行业市场发展趋势与前景展望战略研究报告
- 2025-2030中国布针两用铗行业市场现状供需分析及投资评估规划分析研究报告
- 2025年阜阳幼儿师范高等专科学校单招职业技能考试题库学生专用
- 2025年安徽工业经济职业技术学院单招职业适应性测试题库附答案
- 中国急性缺血性卒中诊治指南(2023)解读
- 2025湖北市政建设集团有限公司管理岗位公开竞聘14人笔试参考题库附带答案详解
- 3.13跨学科主题活动-在线学习小能手 课件 川教版(2024)三年级下册信息科技
- 矿产勘探数据分析-深度研究
- 人教版三年级下册语文《古诗三首(元日)》练习题(含答案)
- 2025年北京控股集团有限公司招聘笔试参考题库含答案解析
- 小学学生一日常规管理
- 基于代际互动视角的农村老年家庭数字反哺机制研究
- 2024年07月江苏银行招考笔试历年参考题库附带答案详解
评论
0/150
提交评论