Writing Device Drivers: Tutorial 第一章 设备驱动程序的概念

编写设备驱动程序
本文介绍编写设备驱动程序的基础知识,包括驱动程序的概念、设计、数据结构分配等关键步骤。此外,还探讨了如何编写可移植的驱动程序以及注册中断处理程序的方法。

1. 设备驱动程序的概念

编写驱动程序之前,你要有一台运行UNIX的机器。你一定要熟悉一般的驱动概念,以及成功编写的驱动程序,您需要执行特定的任务。

这本书假定您了解以下概念:

a.设备驱动程序的目的
b.设备驱动程序的类型
c.单一的二进制模块
d.调用设备驱动程序
f.在UNIX上运行你的设备驱动程序

下面的章节审查编写设备驱动程序相关的任务。《编写设备驱动程序:教程》中详细讨论这些任务。


1.1 收集信息
编写设备驱动程序的第一个任务是收集有关主机系统的相关信息,在你将要写驱动的设备上。
例如,您需要:
a.指定主机系统的信息
b.确定用于编写驱动程序的标准
c.指定的特性,并描述该设备的使用情况
d.提供设备寄存器的描述
e.确定编写驱动程序的支持

1.2  设备驱动程序设计
收集关于主机系统和设备的信息后,你准备设计和开发设备驱动程序。你需要指定驱动器类型和驱动程序是否你正在写的是静态或动态配置到内核中。
在设计的驱动程序,还可以识别设备驱动程序入口点和描述的驱动状态。


1.3分配数据结构
数据结构是用于内核和设备驱动程序接口之间的信息传递机制。下表总结了数据结构,编写设备驱动程序中描述:
buf Describes arbitrary I/O.
bus Represents an instance of a bus entity to which other buses or controllers are logically attached.
cfg_attr_t Contains information for managing the loading and unloading of drivers.
cfg_subsys_attr_t Contains attribute information for drivers.
controller Contains members that store information about hardware resources and store data for communication between the kernel and the device driver.
controller_config Contains information needed to create a controller structure.
DEVGEOMST Stores disk device geometry.
devget Contains information about a device.
device Contains information that identifies the device. There is onedevice data structure for each device connected to the controller.
device_config Contains information needed to create a device structure.
device_info_t Is the top-level union that stores bus- and device-type information.
disklabel Stores disk device label information.
driver Defines driver entry points and other driver-specific information. You initialize this data structure in the device driver.
dsent Defines a device driver's entry points and other information.
handler_intr_info Contains interrupt handler information.
ihandler_t Contains information associated with device driver interrupt handling.
item_list Contains hardware platform-specific information.
lock Contains complex lock-specific information.
port Contains information about a port.
pt_tbl Stores a disk partition map.
sel_queue Defines a queue of select events.
sg_entry Contains bus address/byte count pairs.
slock Contains simple lock-specific information.
task Contains task-specific information.
thread Contains kernel threads-related information.
uio Describes I/O, either single vector or multiple vectors.
v1_bustype_info_t Stores bus information.
v1_device_info_t Is the top-level union that stores bus- and device-type information.
v1_devtype_info_t Stores device-type information.
v1_disk_dev_info_t Stores disk information.
v1_tape_dev_info_t Stores tape information.

当设计一个设备驱动程序,你必须决定那种技术将用于分配数据结构。一般来说,你可以使用的有两种技术:动态分配和静态分配。动态分配是推荐的方法,所有的新驱动,一些现有的驱动程序静态分配数据结构。如果你知道设备的最大数量是大于五或驱动程序使用了大量的数据结构,计划使用动态分配方法。分配的数据结构,可加载设备驱动程序,您还应该使用动态分配方法。


1.4  编写可移植的设备驱动程序
 只要有可能,设计您的设备驱动程序,以便它可以容纳不同的总线架构,不同的CPU架构,和多个CPU类型相同的架构内运作的外围设备。
你需要考虑以下几个问题,让您的驱动程序移植到CPU架构:


控制状态寄存器( CSR )访问

输入/输出(I / O )的复制操作

直接存储器存取(DMA)操作

64位与32位( C编译器的数据类型和位大小)

你需要考虑以下几个问题,以使您的驱动程序移植到总线架构:


总线特定的头文件

总线特定的常量名

实施探头接口总线有关的具体问题

实现从接口总线有关的具体问题

实施配置接口总线有关的具体问题

你必须考虑到这些问题,也如果您有ULTRIX的设备驱动程序要移植到数字UNIX 。请参阅<<编写设备驱动程序:教程>>;
讨论了数字UNIX移植一个ULTRIX设备驱动程序,您需要执行额外的任务。另外,移植的章节<<编写设备驱动程序:教程>>
为旧版本数字UNIX操作系统的当前版本与更新设备驱动程序有关的问题的讨论。虽然是二进制兼容现有的设备驱动程序与当前版本的数字UNIX ,你可能想在移植教程章节的建议,以使更改。


注意:
请参阅编写设备驱动程序:教程CSR的I / O访问接口的信息。这些介面可让您无需直接访问它的设备寄存器读取和写入设备的CSR地址。
这些接口中的每一个都需要一个I / O处理,总线配置代码传递给驾驶员的探头接口。

1.5 检查设备驱动程序工具包交付流程
当你准备写你的驱动程序,你可能要研究的设备驱动程序工具包交付过程,并创建一个适当的设备驱动程序开发环境。

<<编写设备驱动程序:教程>>介绍了设备驱动程序工具包交付过程,以及如何以静态和动态地配置到内核中的驱动程序。本教程介绍如何编写设备驱动程序的数字UNIX上运行的计算机系统。


1.6  注册设备中断处理程序的识别方法
Digital建议您实现所有新的设备驱动程序(可装载和静态)来调用处理程序接口和引用的处理程序特定的数据结构,登记他们的设备的中断处理程序。 (更多信息,请参阅编写设备驱动程序:教程)。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值