Linux device drivers (i)

Source: Internet
Author: User

---restore content starts---

Linux device drivers

One, the role of device-driven

The most popular explanation for device drivers is " Drive hardware Device Actions ". Drive and the underlying hardware directly to deal with, according to the specific work of the hardware device, read and write device registers, the completion of the device polling (polling (Polling) is a CPU decision how to provide peripheral equipment services, also known as "programmed output in" (programmed I/O). The concept of polling is that the CPU timed to ask, in sequence asked each peripheral device whether it needs its services, that is, to give services, after the end of the service to ask the next perimeter, and then continue to cycle), interrupt processing, DMA communication, physical memory to virtual mapping, etc., finally let the communication equipment can send and receive data , so that the display device can display text and pictures, so that the storage device can record files and data.

This shows that the device driver acts as a link between the hardware and the application software, which allows the application software to invoke the Application programming interface (API) of the system software so that the hardware can complete the required work.

Device drivers can be divided into non-operating system device drivers and operating system-driven devices.

1, device driver without operating system

Not every computer system is bound to run the operating system, and in many cases the operating system does not have to exist. For a single function, control is not complex system, such as ASIC internal, bus card machine, etc., do not need multi-task scheduling, file system, memory management and other complex functions, with a single mission architecture can well support their work. The detection of a device interrupt in an infinite loop or the polling of a device is a typical architecture of the software in this system, as in the following code:

Typical architecture for single-tasking software

intMainintargcChar*avgv[]) {   while(1)    {        if(serialint==1)       //There is a serial interrupt{processserialint ();//Handle serial InterruptSerialint=0;//Interrupt Flag Variable Clear 0     }    if(keyint==1)     //There are key interrupts{processkeyint ();//Handling Key InterruptsKeyint=0;//Interrupt Flag scalar Clear 0} status=checkxxx (); Switch(status) {...}  . . .     } }    

2, device driver with operating system

What happens to device drivers when the OS is included in the system?

First of all, no operating system is device-driven hardware operation is still essential, without this part, the drive is impossible to deal with hardware.

Second, we also need to integrate the drive into the kernel. In order to achieve this fusion, the interface of the operating system kernel must be designed in the drive of all the devices, the interface is stipulated by the operating system, the structure of a class of devices is consistent, independent of the specific equipment.

Thus, when the operating system is present, the driver becomes the bridge connecting the hardware and the kernel. The existence of the operating system is bound to require the device driver to add more code and functionality, the single "Drive Hardware Device action" into the operating system and hardware interaction module, he external to the operating system API, no longer give application software engineer directly interface.

Then we have to ask, with the operating system, the driver becomes complex, then what does the operating system do?

First, a complex software system needs to handle multiple concurrent tasks, without operating systems, and it is difficult to accomplish multitasking.

Second, the operating system provides us with a memory management mechanism. A typical example is that, for most processors with MMU, Windows,linux and other operating systems allow each process to access 4G of memory independently.

In short, the operating system is designed to facilitate the upper-level application by making trouble with the driver. When the drivers are designed according to the device-independent interface given by the operating system, the application will be able to access the various devices using a unified system invocation interface.

As a Linux enthusiast, you are welcome to communicate with each other.

Linux device drivers (i)

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.