Linux Device Drivers Article 1: Device Drivers and linux Article 1

Source: Internet
Author: User

Linux Device Drivers Article 1: Device Drivers and linux Article 1

First, we know that the driver is part of the kernel. So what role does the driver play in the kernel?

The role of device drivers in the kernel: they are independent "black boxes" that allow a specific hardware to respond to a well-defined internal programming interface, these interfaces completely hide the device's work details. (To put it bluntly, in addition to providing specific external interfaces for the driver, any implementation details are invisible to the application .) User operations are performed through a set of standardized calls that are independent of specific drivers. The task of the driver is to map these standardized calls to the device-specific operations of the actual hardware.

When writing drivers, programmers should pay special attention to the following concept: When writing kernel code that accesses hardware, do not impose any specific policies on users. In my understanding, the driver is only responsible for implementing the most basic hardware functions. Generally, no matter who uses the hardware or how it is used.

Drivers without policies include some typical features: synchronous and asynchronous operations are supported, the driver can be opened multiple times, and the hardware features are fully utilized, and software layers that are not used to "simplify tasks" or provide policies.

The driver is a software layer between the application and the actual hardware. The same hardware may provide different functions for different drivers. The actual driver design requires a balance between many factors to consider. In general, the driver design mainly considers the following three factors: provide users with as many options as possible, the time required to write the driver, and keep the program as simple as possible without causing errors.

After learning about the role of the driver in the kernel, we can also briefly understand other modules contained in the kernel. Kernel functions are generally divided into process management, memory management, file system, device control, and network functions. Operating system principles the operating system principles are divided into: processor management, process management, file management, storage management, device management, network and communication management, user interface, processor management is actually process management. Because processor allocation and execution are all based on processes. Storage Management refers to memory management.

Further, there are NICs, video cards, sound cards, and other peripherals on the computer, and external USB flash drives, printers, and so on. Are there any categories of devices? Obviously, according to the interface of the device, we can know that there are usb devices, serial devices, pci devices, spi devices, i2c devices, and so on. What are the differences in Linux kernel? The following describes a classification of all devices in linux and describes the simple differences between them.

Categories of devices and modules in linux:

Character device:A character device is a device that can be accessed like a byte stream (similar to a file). It has a character device driver to implement this feature. The character device driver must at least implement open, close, read, and write system calls. Character devices can be accessed through file system nodes. The only difference between these device files and common files is that the accesses to common files can be moved before and after, most character devices are a data channel that can only be accessed sequentially. A character device is a byte stream device. its access to the device can only be sequential access by byte, but not random access. The character device does not request a buffer zone, all access requests are executed in order. But in fact, some advanced character devices can also read a piece of data at a specified position.

Block device:Block devices are also accessed through device nodes. Block devices can accommodate file systems. In most unix systems, Block devices can transmit only one or more complete blocks at a time during I/O operations, each block contains 512 bytes (or a higher power byte of 2 ). In linux, applications can read and write Block devices like character devices, allowing any multibyte data to be transmitted at a time. Therefore, the difference between Block devices and character devices lies only in the way in which data is managed within the kernel, that is, the software interfaces between the kernel and the driver. These differences are transparent to users. In the kernel, block drivers have completely different interfaces than character drivers. A storage device is generally a block device. A block device has a Request Buffer and supports random access without having to access data in order. For example, you can first access the subsequent data, then, it is impossible for character devices to access the previous data. Disk devices in Linux are Block devices. Although there are block device nodes in Linux, applications generally access Block devices through the file system and its high-speed cache, instead of reading and writing data on Block devices directly through device nodes.

Network device:Different from character devices and Block devices, a network device is packet-oriented rather than stream-oriented. It does not support random access or request buffer. Because it is not a stream-oriented device, it is difficult to map network interfaces to nodes in the file system. The communication between the kernel and the driver of the network device is completely different from the communication between the kernel and characters and the block driver. The kernel calls a set of functions related to data packet transmission instead of read and write. The Network Interface does not have the same device number as the character device and block device. It has only one unique name, such as eth0 and eth1, and does not need to correspond to the device file node.

In summary, the differences between character devices and Block devices are as follows: 1. Character devices are stream-oriented, and the minimum access unit is byte. Block devices are block-oriented, the minimum access unit is 512 bytes or a higher power of 2. 2. Character devices can only access data in bytes, while Block devices can access data randomly. 3. Block devices can accommodate file systems. In the form of access, character devices can be accessed through device nodes, while Block devices can also be accessed through device nodes, however, data is generally accessed through a file system.

The network device does not have any device node because the network device is packet oriented and it is difficult to implement File read/write functions such as read and write. Therefore, the implementation of the driver is different from that of character devices and Block devices.

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.