Design of PCI driver based on Linux platform

Source: Internet
Author: User
Article title: PCI device driver design based on Linux platform. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Chapter 1 Linux device management overview
1.1 Device Category
In Linux, device management has its own characteristics: abstract all hardware devices, making operations on hardware devices very similar to those on files by computer users, you can enable, disable, read, and write devices through standard system calls that are exactly the same as operating files.
Linux classifies all hardware devices into three types:
Character device:
Character devices can be read and written directly without buffering. Users can access character devices as they access files. character device drivers are responsible for these access operations. Drivers usually implement open, close, read, and write system calls. The keyboard and mouse are typical examples of character devices. The file system node can access character devices, such as/dev/tty1 and/dev/lp1. A significant difference between character devices and common file systems is that common files can be read and written back and forth. most character devices are only data channels and can only read and write in sequence. Of course, such a character device also exists, which looks like a data zone and can read data back and forth.
Block device:
A block device is the host of a file system, such as a hard disk, optical drive, or a soft Drive. In most Unix systems, block devices can only be viewed as multiple blocks for access. a block is usually 1 kB of data. Linux allows users to read block devices like character devices-any number of bytes can be transferred at a time. Block devices and character devices differ only in the internal management of the kernel. Therefore, software interfaces between the kernel and driver are different. Like Character devices, each block device reads and writes data through a file system node. the differences between them are transparent to users. The interfaces of the block device driver and kernel are the same as those of the character device driver. it also communicates with the kernel through a traditional block-oriented interface, however, this interface is invisible to users.
Network device:
The biggest difference between a network device and a character device and a block device is that the network device does not have a corresponding device file. Nic is a typical example.
The NIC writes the data sent to the remote computer system to a communication line, and loads the packets received from the remote system into the kernel memory. In Unix systems, a computer assigns a different symbol name to each Nic, such as eth0 and eth1. However, this name does not have a device file or an index node.
Because the file system is not used, the system administrator must establish a connection between the device name and network address. Therefore, data communication between applications and network interfaces is not based on standard system calls such as read () and write () of related files, but based on socket () and bind () listen (), accept (), connect () system call, these system calls operate on the network address.
1.2 Primary device number and secondary device number
In traditional device management, apart from the device type (character device or block device), the kernel also needs a pair of parameters called The Master and secondary device numbers to uniquely identify a device. The primary device ID identifies the driver corresponding to the device. the kernel uses the primary device ID to match the device with the corresponding driver. The device number is only used by the device driver, and is not used by other parts of the kernel. A driver can control several devices. the device number can be distinguished by different devices using the same driver.
All devices must have corresponding special files under the appropriate directory (usually under the/dev directory), so that both the character device and the block device can complete the system call through file operations. The device file is a special file, which can be indicated by "c" in the first column output by the command "ls-l". it indicates that they are character nodes; the first column of block devices is "B ". After the "ls-l" command is executed, you can see two numbers (separated by commas) before the latest modification date of the device file entry, which usually shows the length of the regular file. The two numbers are the master and secondary device numbers of the corresponding device. The following lists some devices on my system. their main device numbers are 10, 14, 29, 41, and 68, respectively, the device numbers are 3, 4, 20, 7, 0, 1, and 2.
  
  
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.