Linux device drivers (i) Introduction to device drivers

Source: Internet
Author: User

    • Mechanism or policy:

Drive provides a mechanism (what), rather than providing a strategy (how);

    • Kernel function Partitioning:

Depending on the completion of the task, the kernel can be divided into the following parts:

1. Process Management

Responsible for the creation and destruction of processes, and to handle the connection between them and the external (input and output). The communication between different processes is the basic function of the whole system, so it is processed by the kernel.

In addition, the scheduler that controls how the process shares the CPU is also part of the process management.

In summary, kernel process management 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.

The kernel creates a virtual address space for each process on a limited number of available resources.

Different parts of the kernel use a set of function calls, such as Malloc/free, and other complex functions when interacting with the memory management subsystem.

3. File system

Each Unix object can be viewed as a file.

The kernel constructs a structured file system on hardware that has no structure.

Linux supports a variety of file system types, essentially different ways of organizing data on physical media.

4. Device Control

Almost every system operation will eventually be mapped to a physical device. In addition to the processor, memory, and a limited number of other objects, all device control operations are done by the associated code with the controlled device, which is the driver.

The kernel must embed the appropriate driver for each peripheral in the system.

5. Network functions

Network functionality must be managed by the operating system, because most network operations are not related to a specific process: incoming packets are asynchronous times. Before a process processes these packets, it must collect, identify, and distribute the packets. The system is responsible for passing packets between the application and the network interface and pointing to the network activity Control program.

In addition, routing and address resolution are handled by the kernel.

    • Loadable Modules

The features provided by the Linux kernel can be extended at run time, that is, when the system is up and running, we can add or remove functionality from the kernel to the kernel.

Code that can be added to the kernel at run time is called a "module."

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

Each module consists of target code that is not connected to a complete executable program.

Add Module--insmod Remove Module--rmmod

    • Classification of equipment and modules

Linux divides devices into three categories: character devices, block devices, network devices.

1. Character Device:

A character device is a device that can be accessed like a byte stream, and is implemented by a character device driver.

Character device drivers typically require at least the implementation of open,close,read,write system calls.

The character device can be accessed through the file system node in the/dev directory.

The only difference between a character device and a normal file is that access to normal files can be moved back and forth, while most character devices are a data channel that can be accessed sequentially.

2. Block Device:

Block devices are similar to character devices and are accessed through file system nodes in the/dev directory.

The file system can be accommodated on a block device.

Linux allows applications to read and write block devices like character devices, allowing arbitrary multibyte data to be passed at once.

The difference between a block device and a character device is that only the kernel's internal data is managed, that is, the software interface between the kernel and the driver, and these differences are transparent to the user. In the kernel, character drivers and block drivers have completely different interfaces.

3. Network interface

Network transactions are formed through network interfaces.

Typically, an interface is a hardware device, but it can also be a purely software device, such as a loopback interface.

The network interface is driven by the network subsystem in the kernel and is responsible for sending and receiving packets, but it does not need to know how each of the XV maps to the actual transmitted packets.

Because it is not a stream-oriented device, it is difficult to map a network interface to a file system node. Unix still assigns them a unique name (such as Eth0), but the name does not exist in the file system for the corresponding node.

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 device driver, and the kernel calls a set of functions related to packet transport rather than read,write.

Linux device drivers (i) Introduction to device drivers

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: 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.