Compile the device driver of the Linux operating system

Source: Internet
Author: User
Compile the C Operating System Device Driver-Linux general technology-Linux programming and kernel information. The following is a detailed description. 1.1 Linux Device Driver categories

Linux device drivers account for a large proportion of the Linux kernel source code. The source code length is increasing, mainly because of the increase in the driver program. During the continuous upgrade of the Linux kernel, the driver structure is still relatively stable. In the changes from 2.0.xx to 2.2.xx, the compilation of the driver has made some changes, but only a small amount of work is required from the 2.0.xx driver to the 2.2.xx porting. Linux devices include character devices, block devices, and net work devices. Character devices are devices that do not cache data during access. Block devices have caches to support reading and writing, and block devices must be able to access random devices. Character devices do not have this requirement. Typical Character devices include the mouse, keyboard, and serial port. Block equipment mainly includes hard disk equipment, CD-ROM and so on. A file system must be installed on a block device to enter the operating system. Network devices are specially processed in Linux. Linux's network system is mainly based on BSD unix socket mechanism. A special data structure (sk_buff) is defined between the system and the driver for data transmission. The system supports the caching of sent and received data, provides traffic control mechanisms, and supports multiple protocols.

   1.2 compile some basic concepts of the driver

No matter what the operating system driver is, there are some general concepts. The support provided by the operating system to the driver is also similar. The following describes some basic requirements for network device drivers.

   1.2.1 sending and receiving

This is the most basic function of a network device. A network card does nothing more than sending and receiving. Therefore, the driver should tell the system where the sending function is. The system will call your sending program when there is data to be sent. In addition, the driver directly controls the hardware, so the network hardware receives the data first, that is, the driver, it processes the raw data and sends it to the system. Here, the operating system must provide two mechanisms: one is to find the sending function of the driver, and the other is to send the received data to the system.

   1.2.2 interruption

Interruptions play an important role in modern computer structures. The operating system must provide the driver's ability to respond to interruptions. Generally, an interrupt handler is registered in the system. The operating system calls the processing program of the driver when the hardware is interrupted. Linux supports interrupt sharing, that is, multiple devices share one interrupt.

   1.2.3 clock

Clock is used in many places when implementing the driver. For example, timeout processing in some protocols and hardware polling without interruption mechanisms. The operating system should provide a timing mechanism for the driver. Generally, it refers to the clock function that is called back for registration after the reservation. In the network driver, if the hardware is not interrupted, the timer can provide poll to access the hardware. Or timeout retransmission required for some protocols.

   Ii. network device drivers in Linux

2.1 Structure of the Network Driver


All Linux network drivers follow common interfaces. The object-oriented method is used in the design. A device is an object (device structure) with its own data and methods. The first parameter when a device method is called is the device object itself. In this way, you can access your own data (similar to this reference during object-oriented programming ).

The most basic methods for a network device are initialization, sending, and receiving.
CODE :----------------------------------------
| Deliver packets | receive packets queue |


| (Dev_queue_xmit () | them (netif_rx () |
----------------------------------------
|/
/|
-------------------------------------------------------
| Methods and variables (initialize, open, close, hard_xmit, |
| Interrupt handler, config, resources, status...) |
-------------------------------------------------------
|/
/|
---------------------------------------
| Send to hardware | CE from hardware |
---------------------------------------
|/
/|
-----------------------------------------------------
| Hardware media |
-----------------------------------------------------
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.