Linux上PCI―E驱动设计

摘 要:当前基于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 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;Driver   PCI—Express 简称PCI—E,是一种完全不同于PCI、具有高速串行点对点双通道高带宽传输模式的全新总线规范,所连接的设备分配独享通道带宽,不共享总线带宽,支持端对端的可靠性传输。

PCI—E在软件层面上兼容的PCI技术和设备,支持PCI设备和内存模组的初始化,也就是说驱动程序操作系统完全兼容。

1 PCI设备驱动关系   PCI设备通常由一组参数唯一地标识,它们被vendorID,deviceID和class nodes所标识,即设备厂商,型号等,这些参数保存在 pci_device_id结构中。

每个PCI设备都会被分配一个pci_dev变量

所有的PCI驱动程序都必须定义一个pci_driver结构变量,在该变量中包含了这个PCI驱动程序所提供的不同功能的函数,同时,在这个结构中也包含了一个device_driver结构这个结构定义了PCI子系统与PCI设备之间的接口。

在注册PCI驱动程序时,这个结构将被初始化,同时这个 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 [] __initdata ={   {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 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 ={/ * 设备模块信息 */   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_driver);   }   module_init( example_init_module);/* 加载驱动程序模块入口 */   module_exit( example_cleanup_module);/* 卸载驱动程序模块入口 */。

12 次访问