Why should we introduce the platform driver in Linux?

Source: Internet
Author: User

Linux simple character driver is very simple. You only need to map the physical address during initialization, register a fileopenration operation set, and then implement the operation set just like writing a bare metal program.

Question 1: Why do I need to map physical addresses to virtual addresses? Because MMU memory management is introduced, users can only operate on virtual addresses.

Question 2: Why does MMU not allow users to directly operate on physical addresses?

Because memory management is very complex, it is mainly for security considerations. Assume that driver a uses a physical address 0x20000000 for the operation, and driver B just uses this physical address. What should I do in this situation? Note: At this time, no error will be reported, and unexpected events may occur. In this case, you can avoid using a virtual address. If the physical address is used by an existing user, the kernel will remind the user that the ing fails. You can select another physical address ing. Baidu's result: First, security. Second, convenient. Third, unified and universal. Fourth, convenient management. Fifth, ease of application...

However, you can hardly see such a simple driver in the Linux kernel. Almost all the drivers in the kernel are platform drivers (unless you write them yourself)

Question 3: Why is it difficult to introduce a platform driver in linux to increase the development difficulty of the driver?
The answer is: ease of transplantation.

For example, from your home to Beijing. If you know the terrain, you can go anywhere to Beijing. But now we want everyone to go from your home to Beijing. Most people may not go. What should we do at this time? Of course you can take them away, but we are talking about everyone. At this time, we can build a highway from your home to Beijing, and then all the people (including those who do not recognize the road, will not drive) you only need to follow certain rules to wait for a car on the side of the road. The car will take you to Beijing.

Disadvantages: you must first build a road from your home to Beijing, and then ask some experienced drivers.

Advantage: everyone had to learn the road recognition skills to go to Beijing, now you only need to know the information of some cars and follow certain rules next to the road (you only need to know which car you are taking, then tell the driver where you are ).

1. Building a road is like building a platform bus. Experienced drivers are like the original equipment manufacturers of various devices.

2. All people say they want to be tablets, mobile phones... Various system product manufacturers.

3. "Which car to take, tell the driver where to go" means that we need to tell the kernel what hardware resources are used by different chips when porting the driver.

Analysis: build a platform bus, which Linux has helped you with, a variety of complicated drivers (various Nic chips, sensor chips ...) The original device vendor helps you implement hardware-independent drivers. (Of course, do not admire these people, because these people only write one type of driver, that is, the NIC manufacturer they specifically write the NIC driver, writing only one driver from scratch is not very difficult)

Now, the most difficult part is to help us with the Linux kernel and the original device manufacturers. We only need to tell the driver the hardware resources we use when porting the driver.

Summary: As linux kernels become increasingly complicated, Linux has introduced platform drivers since 2.6. In fact, it is necessary to divide development into multiple units to take advantage of embedded systems.

The Platform driver and platform device mainly have four important structures. Struct platform_driver, struct platform_device, struct device_driver, and struct device.





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.