免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4668 | 回复: 2
打印 上一主题 下一主题

Introduction to device drivers and device nodes [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-02-21 01:33 |只看该作者 |倒序浏览
Introduction to device drivers and device nodes

This section provides an overview of the way in which peripheral components use the Unix Input/Output (I/O) subsystem.

Physical devices, such as disk drives and modems, have a varied command interface and command interpretation. For this reason the Unix operating system defines a standard method of I/O that is used on any type of device that is attached to the system. As we discussed earlier in the course, for the Unix operating system "everything is a file", so devices have special files.

Adding hardware to a Unix system is essentially a two part problem. The first is a hardware problem; "How do I attach this to the system?" and the second is a software problem "How do I make use of this new hardware from my application?"

Hardware connectivity
To connect new hardware to Unix systems, the architecture of the Unix system must be considered. Most Unix systems are manufactured with standard interfaces, such as a serial port, a parallel port and an external SCSI bus. These allow many peripherals to be installed without adding additional hardware (or software). However, some peripherals devices will require the addition of an interface card or a controller.

Interface cards are manufactured for specific bus types. Therefore, when preparing to purchase them, it is good to know the type of bus that is supported by the target Unix system.

Here are the I/O bus types supported by each vendor's workstations. More specific information about the bus type and other hardware options is distributed by the vendors.

Sun Microsystems- SparcStations   SBUS, MBUS, and XDBUS
Silicon Graphics- Indy           GIO
Silicon Graphics- Indigo2,Onyx   GIO and EISA
Silicon Graphics- Challenge      HIO and VME64
Hewlett-Packard 9000 series-    EISA
Intel-based systems (Linux)     ISA, EISA, VESA Local Bus,PCIDigital Equipment Corp.-         PCI, TurboChannel

For more optional information about hardware please refer to this Introduction to PC Hardware article which reviews computer hardware in a general way. Contact Unix system vendors for more specific information about hardware support.

Most systems have a keyboard, mouse and video (framebuffer) interface, but these are not commonly used to add peripherals to the system and will not be considered standard. Some systems have built-in audio and video jacks available but most do not; we will not be covering audio and video peripherals at this time.

Standard Unix system interfaces:

SparcStations have 2 serial ports for connecting a modem, a printer or an ASCII terminal, a single parallel port for connecting printers, an external micro SCSI connector for connecting disk drives, or removable media drives and a 10BaseT Ethernet port.
HP 9000 Series systems have 2 serial ports, a single parallel port, an external micro SCSI connector and an AUI Ethernet port.
SGI Indys have 2 serial ports, a single parallel port, a external micro SCSI connector and both a 10BaseT and AUI Ethernet port.
Intel (Linux) systems are very diverse; there is no standard. Most commonly you will find 2 serial ports, a single parallel port, an IDE hard disk controller and a 10BaseT Ethernet port.

Software connectivity

A device driver is required as the first step in connecting with a new hardware device.

The device driver is the software that operates the controller. This software must be available to the kernel if you wish to use the device. The device drivers must match the device that you wish to use.

When a program attempts to access a device, via the device file, the kernel looks up the appropriate information in its tables, and transfers control to the device driver. The device driver then performs the access request for the device and returns control back to the kernel.

For more recommend information on device drivers review the following reference.
Linux Kernel Hackers Guide

Basics of device drivers

There are two main types of devices and therefore device nodes, character and block.

A block device is one that stores information in fixed size blocks. Common block sizes are between 128 bytes and 1k bytes. Each block may be read independently of the others, so the device allows random access to each block.

Character devices deliver or accept a stream of characters (bytes) without regard to any other structure. Some character devices are keyboards and terminals.

Character devices are read from and written to with the functions: mydev_read() and mydev_write(). The read() and write() calls do not return until the operation has been completed. By contrast, block devices do not implement the read() and write() functions; instead they have a strategy function. The strategy function is used to both read and write blocks to the device.

Common device file naming conventions

In order for the operating system to recognize the hardware device, the device must have a software name, usually referred to as a device special file or device node. The node number on the special file connects it to a specific device driver in the Unix kernel. A device node is created with the command mknod

The device nodes are stored in or have links to the /dev directory. When the ls -l command is used to list these files, their major and minor numbers are displayed. The major number instructs the kernel to call the device specific code associated with the device, and the minor number is passed by the kernel to the device driver to further control the action of the device driver.

Special File Names
The standard devices for each system and a semi-standard names. For example, in Unix systems:

/dev/tty*       terminals
/dev/fd*        floppy disk
/dev/mt*        magnetic tape
/dev/st*        streaming tape
/dev/mouse      mouse


A block device can be accessed through an associated "raw" device special file. This allows diagnostics and checks to be performed on the data the device is offering. For example here are a block and character device special file under HP-UX.


brw-r-----   1 root     sys       31 0x002000 Apr  4 08:23 /dev/dsk/c0t2d0
crw-r-----   1 root     sys      188 0x002000 Apr  4 08:23 /dev/rdsk/c0t2d0

Examples of device special files for disk drives for common Unix systems are:


SunOS 4.x - /dev/{r}sdAP
SunOS 5.x - /dev/{r}dsk/cCtAd0sS
IRIX 5.3 - /dev/{r}dsk/dksCdA{sS|vh|vol}
HPUX 10.X - /dev/{r}dsk/cCtAd0{sS}
Digital Unix - /dev/{r}rzNP
Linux - /dev/sdLK
Where: A = SCSI address,
       C = SCSI Controller number,
       K = DOS primary/extended partition,
       L = drive letter "a" through "h",
       N = 8 * controller # + SCSI address,
       P = BSD-style partition: (a,b,c,d,e,f,g),
       S = System V-style slice (0,1,2,3,4,5,6).

[Note: Linux device names  and partitioning is quite different
       from other flavors of Unix. Partition 0, or no partition
       number, refers to the whole drive.
       Partitions 1-4 are DOS primary partitions, while partitions
       5-8 are extended DOS partitions.]



--------------------------------------------------------------------------------

论坛徽章:
0
2 [报告]
发表于 2003-02-21 08:32 |只看该作者

Introduction to device drivers and device nodes

谁给翻译一下就更好~~~

论坛徽章:
0
3 [报告]
发表于 2003-02-21 09:12 |只看该作者

Introduction to device drivers and device nodes

搞小型机的,肯定会看懂吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP