Introduction to the Framebuffer driver for Linux driver development

Source: Internet
Author: User

Framebuffer is a display device inside Linux. How to operate the LCD at the bottom of the drive to achieve graphical display.

1. What is Framebuffer?

(1) First consider how we operate the LCD in bare metal.

The SOC has an LCD controller, an LCD driver outside the SOC, an LCD driver connected to the LCD screen, a CPU inside the SOC, and an external DDR memory. These devices are all part of the LCD display.

What do we do with the bare metal? The LCD driver and the LCD controller are linked by a cable connection, which is an interface that is unique to the LCD. The LCD controller contains many registers related to LCD. Start the CPU set some registers inside the LCD controller, achieve in the DDR memory space to separate a piece of memory as video memory, this video memory and LCD set up a two-way mapping relationship between the CPU as long as the content will be displayed to the video memory to go on the line, The hardware automatically refreshes the content from the video memory to the LCD drive, and then the LCD driver operates the LCD screen to refresh the content to the LCD screen. So when programming, we don't have to tangle with LCD drivers and LCD screens, we program only the registers inside the LCD controller and the content to be displayed in memory. This is the process we operate in bare metal.

(2) What are the difficulties in operating the LCD under the OS?

In the bare metal we operate the LCD code is in a code, can be likened to a process, but under the operating system, the operation of the LCD code is not in a code, because it is divided into two parts of the driver and application. The kernel-driven part is part of the underlying hardware, the application is to let the LCD screen display the specific content of that part, so under the operating system, our task volume is divided into two points, It is not possible to initialize the controller and video memory setting for the LCD and refresh the content to the LCD screen, as in bare metal. Under the operating system, the first part is to set the controller to initialize some LCD, so that the mapping between the video memory and the LCD relationship, the first part of the work is done by the kernel driver, the driver only to do this part. The second part of the application is completed, will be specific to display the content into the video memory so that the hardware LCD driver automatically refresh the contents of the video memory into the drive and then the driver to let the LCD display relevant content, so the application part is to achieve the LCD screen specific display what. So the problem comes out, the difficulty is the application and drive how to cooperate between the problem.

Memory in bare metal we can use it wherever we want, so it's simple to build a map of the LCD and the part of the video memory in bare metal. But in the operating system, memory is strictly managed, you want to use the memory you need to apply to the kernel. This is also the difference between operating system and no operating system and the difficulty.

Kernel-driven part of the memory portion of the set to map to the actual physical address, the application layer will be displayed in the video memory, this part of the video memory will also be mapped to the real physical address, so the drive part of the memory space and the application layer of memory space need to map to the same physical address, This way, you will be correctly displayed on the screen when you lose data in the drive or in the application layer like video memory.

In order to solve the above problem, it is also the key reason of framebuffer birth.

(3) framebuffer frame buffer (FB), a frame of data is a screen of data. A frame of data in a string represents a data segment in which a frame of data represents a screen of data. FB from the programming point of view is the Linux kernel virtual out of a device, that is, the embodiment of FB in the kernel is the kernel with code to implement virtual out of an FB device, the device in the application space has a device file node, is generally/dev/fb0. Why is FB is a device, because we can operate a device like to open the operation of this file, but we have to know in the real world does not exist a real FB device. He was abstracted from the design of the Linux kernel, and he was abstracted out to replace the software facilities needed for the LCD display, the hardware and LCD display (for display software, such as a video card), which is called FB (Frambuffer).

(4) What is Framebuffer?

To sum up, FB is the Linux kernel to the system inside all the hardware and software, such as display related to the collection of these parts, the overall virtual out of a device FB, this device has a feature, that is, the application layer can provide a unified interface, this interface is standard, So the application layer to let the screen display some things, do not need to go to specific hardware features, such as your hardware LCD is how many bits, the resolution is how many of these features are not need to care about the application layer, the application layer only need to operate a unified interface, and do not need to care about these features can be done to do the display task. So FB is a good thing because he shields the application layer of some of the details of the drive layer. This is framebuffer.

We are learning the driver section in Framebuffer. Things like VGA interface and HDMI interface can also be related to framebuffer. Configuring some framebuffer content in the drive layer is also connected to the devices of these VGS interfaces and HDMI interfaces. So our analysis of the FB driver code can be used in various and FB-related devices are available. Like support HDMI and so on.

2, the use of framebuffer

Framebuffer provides a unified interface to the application layer, so the use of FB in the application layer is very simple, if you do not care about the internal implementation of FB, but simply use FB, then it is very simple. So it is very simple to use FB in the application layer.

(1) The application layer using Frambuffer, the first to open the corresponding device files, usually/DEV/FB0,FB after 0 is the serial number, there are several monitors then the system will be several serial numbers. This fb0 device file is a device file that FB drives open to the upper application layer. From the drive layer in fact, the FB device is also a typical character device (in the driver layer), and created a class, this class is/sys/class/graphics

, graphics is the meaning of graphic images, because FB automatically creates a class in the system, so a device file node (/dev/fb0) is created automatically. The first part of the use of our application layer is to open the device file.

(2) The second step is to obtain the device information (#include <linux/fb.h>), the application layer read and write, do not know the resolution of the LCD screen is how large. Different LCD devices His resolution is not the same, so when you are in the application layer to operate an LCD device, you must first know the LCD device information. The application itself is unable to know the future of its own program to run on which LCD, the application is unable to know the LCD device information, but the driver know the LCD device hardware specific information. Because the application layer does not know the specific parameters of the LCD hardware, the drive layer has opened some interfaces to the application to let the application know that the application can call these interfaces from the driver to learn the specific LCD hardware device information, so when the application of the first step to open the FB device, the second step is to obtain information about the LCD device. After acquiring the device information in the decision to buy the operation of this LCD device.

(3) Step three, mmap mapping. Because the application layer program is working on its own virtual address space, our driver is working in the kernel's address space. The driver has already applied for a piece of memory in the kernel, the memory space of the driver request is also a virtual address, this virtual address corresponds to a block of physical memory, so there is a physical memory address is occupied by video memory. So how do you get the application to bind its own virtual address space to the memory space of this physical memory address, and that is to call this mmap function to map the physical memory of the actual video to the virtual address space of the application's current process, At this time the current application read and write this virtual address space is actually mapped to the actual video memory corresponding to the physical address, and the physical memory corresponding to the location of the driver is set up in the drive to be bound to the LCD screen. So when the app operates this mmap mapped virtual address space, the corresponding screen changes.

If all two applications call mmap to establish a mapping between the virtual address space of the current process being applied and the physical address space of the video memory, then both a application and B application are like the virtual address space, as the virtual address space of the two applications is mapped to the same physical address. So on the screen there will be two applications to write the content overlay, after the write will overwrite the previous things. Just as we open the two software interface in the computer, the interface of the software that is opened before is overwritten by the screen of the software that opens. So it is possible for multiple processes to simultaneously operate the same LCD corresponding to the physical address space. Because the virtual address space is mapped to the physical address space of the video memory, it can be mapped more than one, and the virtual address space of multiple application tiers can be mapped to the same physical address at the same time. Mmap is a very important function.

(4) When the application layer uses MMAP, then the virtual address space in the current application layer will be mapped with the actual memory physical address, that is, a part of the virtual address space FB, I operate the FB virtual address space is actually operating the memory of the physical address space is actually operating the LCD screen. So the fourth step is to fill the content to the FB, is mmap out of the virtual address space, will be displayed on the screen.




This article from "Whylinux" blog, declined reprint!

Introduction to the Framebuffer driver for Linux driver development

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.