English Chinese (Simplified) (zh_CN)
PC Card PC Card
This chapter will talk about the FreeBSD mechanisms for writing a device driver for a PC Card or CardBus device. However, at present it just documents how to add a new device to an existing pccard driver. 本章将讨论FreeBSD为编写PC Card或CardBus设备的驱动程序而提供的机制。 但目前本文只记录了如何向现有的pccard驱动程序中添加驱动程序。
Adding a Device 添加设备
Device drivers know what devices they support. There is a table of supported devices in the kernel that drivers use to attach to a device. 向所支持的pccard设备列表中添加新设备的步骤已经与系统在FreeBSD 4 中使用的方法不同了。在以前的版本中,需要编辑 <filename>/etc</filename>中的一个文件来列出设备。从FreeBSD 5.0开始, 设备驱动程序知道它们支持什么设备。现在内核中有一个受支持设备的表, 驱动程序用它来连接设备。
Overview 总览
The first section of the file contains the vendor IDs. Please keep this list sorted in numeric order. Also, please coordinate changes to this file because we share it with NetBSD to help facilitate a common clearing house for this information. For example, here are the first few vendor IDs: 文件的第一节包含供货商ID。请保持列表按数字排序。此外,为了 能有一个通用清晰的保存地来方便地保存这些信息,我们与NetBSD共享此 文件,因此请协调对此文件的任何更改。例如:
The second section of the file contains the products. As shown in this example, the format is similar to the vendor lines: 文件的第二节包含产品. 如你在下面例子中看到的:
The final section contains the entries for those cards that must be identified by string entries. This section's format is a little different from the generic section: 最后一节包含那些必须用字符串匹配的卡。这一节的格式与通用 节的格式有点不同:
Sample Probe Routine 探测例程样例
To understand how to add a device to the list of supported devices, one must understand the probe and/or match routines that many drivers have. It is complicated a little in FreeBSD 5.x because there is a compatibility layer for OLDCARD present as well. Since only the window-dressing is different, an idealized version will be presented here. 要懂得如何向所支持的设备列表中添加设备,就必须懂得很多驱动程序 都有的探测和/或匹配例程。由于也为老卡提供了一个兼容层,这在 FreeBSD 5.x中有一点复杂。由于只是window-dressing不同,这儿给出了 一个理想化的版本。
Putting it All Together 将它合在一起
Since we first want to prefer the numeric option, first try to construct an entry based on that. The above card has been slightly fictionalized for the purpose of this example. The vendor is BUFFALO, which we see already has an entry: 由于我们首先想优先使用数字选项,因此首先尝试创建基于此的条目。 为了示例,上面的卡已经被稍稍虚构化了。我们看到的供货商为BUFFALO, 它已经有一个条目了:
But there is no entry for this particular card. Instead we find: 这样我们就可以了。为这个卡查找一个条目,但我们没有发现。但我们 发现:
Once these steps are complete, the card can be added to the driver. That is a simple operation of adding one line: 目前,需要一个手动步骤来 重新产生<filename>pccarddevs.h</filename>,用来将这些标识符转换 到客户驱动程序。你在驱动程序中使用它们之前必须完成下面步骤:
Submitting a New Device 提交新设备