Linux Device driver notes (i) a brief introduction to device drivers

Source: Internet
Author: User

<: The role of device drivers

From one point of view, the role of a device driver is to provide a mechanism, not a policy.

When writing drivers, the program ape should pay particular attention to the following basic concept: When writing kernel code to access hardware, do not impose any specific policy on the user. Because different users have different needs, the driver should handle the problem of how to make the hardware available. And the problem of how to use hardware is left to the upper application.

look at the driver from a point of view. It can also be seen as a software layer between the application and the actual device .

In general, the driver program design is mainly to consider the following three factors: provide users with as many options as possible, write the driver to take the time and try to keep the program simple and not error-ridden.

< two;: Kernel function partitioning

UNIX systems Support multi-process concurrent execution. Each process requests system resources. The kernel handles all of these requests and, depending on the completion of the kernel tasks, divides the kernel functionality into the following sections, for example:

1. Process management: Responsible for creating and ecstasy processes. and deal with the connections between them and the outside world. The kernel process management activity is the abstraction of multiple processes on a single or multiple CPUs.

2. Memory Management: Memory is one of the main resources of a computer, and the strategy used to manage memory is a key factor in determining system performance.

3. File system: The kernel constructs a structured file system on hardware that has no structure. and file abstraction is widely used throughout the system.

4. Device control: Almost every system operation will eventually be mapped to a physical device.

5. Network functions: Network functions must also be managed by the operating system, the system is responsible for the application and network interface between the transmission of packets, and according to the operation of network activity control program. Other than that. All Routing and address resolution issues are handled by the kernel.

Loadable Modules: Linux has a very good feature: the features provided by the kernel can be extended at execution time. Code that can be added to the kernel at execution time is called a "module."

The Linux kernel supports several types of modules. Contains, but is not limited to, device drivers.

Each module consists of the target code, which can be used to connect the module to the executing kernel using the INSMOD program, or to remove the connection using the Rmmod program.

< three;: Classification of equipment and modules

The Linux system divides the device into three basic types: a character device, a block device, and a network interface.

1. Character device: Character device drivers typically implement at least open, close, read, and write system calls. Character devices are able to access through file system nodes.

The only difference between these device files and normal files is that access to ordinary files can be moved back and forth to the location of the interview. Most character devices are a data channel that can only be interviewed sequentially.

2. Block devices: Similar to character devices, block devices are also visited through the file system node under the/dev folder.

The file system can be accommodated on a block device. The difference between a block device and a character device is only the way the kernel manages data internally, which is the software interface between the kernel and the driver. And these differences are transparent to the user.

In the kernel, the block driver has a completely different interface than the character driver.

3. Network interface: The network interface is driven by the network subsystem in the kernel. Responsible for sending and receiving packets. But it does not need to know how each transaction maps to the actual transmitted packets. The network driver does not need to know the information about each connection, it simply processes the packet.

The communication between the kernel and the network device driver is completely different from the communication between the kernel and the character and the block driver, and the kernel calls a set of functions related to packet transport rather than read, write, and so on.

In addition to device drivers. Some of the other functions in the kernel are also modular. such as file systems.

A file system type determines how data is organized on a block device to represent the tree in which folders and files are formed. The file system is not a device driver, because there is no actual physical device associated with such a way of organizing information. Instead, the file system type is a software driver. It maps the underlying data structure to a high-level data structure. Determines how long the file name can be and what information is stored in the folder item, and so on.

< four;: Security issues

1. All security checks in the system are carried out by the kernel code, assuming that the kernel has a security vulnerability, the entire system will have a security vulnerability. When executing the officially published kernel, only the superuser or the intruder who became Superuser could use privileged code.

2. Driver writers should try to avoid implementing security policies in code.

Security policy issues are best implemented under the control of the system administrator, at the top level of the kernel. Driver writers should also avoid introducing security flaws for their own reasons.

3. Whatever input you get from the user process is only available after the kernel has been rigorously verified. Also be careful with uninitialized memory: whatever memory is obtained from the kernel. Must be cleared 0 or otherwise initialized before being supplied to the user process or device. Otherwise, information disclosure can occur.

4. The software obtained from third parties should be used with care, especially when it is related to the kernel, because the source code is open and everyone can change and compile it again.

The 5.Linux kernel can also be compiled to not support module mode. This enables the closure of any module-related security vulnerabilities. It is possible to disable the transfer of kernel modules after system startup through the power mechanism.

< five;: Version number

1. First, each software package in a Linux system has its own release number, and there is often a dependency between them.

Almost all distributions now come with a package manager that agrees to upgrade the package after verifying that it satisfies the dependencies between the packages. If you encounter any issue related to the version number, you can refer to the kernel source file documentation/changes to resolve.

2. For the kernel, the even numbered kernel version number is the stable version number used for the official release. And the odd numbered version number

is a snapshot of the development process.

< six;: License Terms

Linux follows the GNU General Public License (GPL), and the GPL agrees that no one may disclose or even sell products protected under the GPL, provided that the recipient of the product obtains the source code and has the same rights.

If you want to read the original license, you can find it in the copying file in the top-level folder of the system's kernel source tree.

Linux Device driver notes (i) a brief introduction to device drivers

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.