How does the bottom of the computer access the video card?

Source: Internet
Author: User

In fact, you can think of the graphics card as another machine. So the way to control another machine is to write instructions and data into its memory. To a piece of memory to write things in a few ways, 1, with the CPU to do, then is to use Mmio (memory Mapped IO) to the ' memory ' map to the CPU address space, and then read and write, 2, with the DMA controller to do, which has the system comes with the DMA controller or video card band, Either way, you can think of the DMA controller once again as another machine, then it is to write instructions to the DMA controller to help you pass something to the video memory, the transmission of these things is the graphics card to execute the command and data. Memory controller on the video card, the original AGP when called Gart, now do not know what name, and the SOC also has a similar concept, but most of the SOC has only one memory controller, so do not divide between memory and RAM.

Think of the graphics card as another machine. It has to work, nothing more than "program storage" principle, after power-up, from the specific memory (video) address to refer to, and then execute the instructions. The work logic of the graphics card is much simpler than the CPU, it is generally from a ring buffer constantly take instructions, and then execute, the CPU will continue to the ring buffer to fill instructions.

Many times the same action can be used MMIO or DMA, such as Flip framebuffer. Just get the flip Framebuffer's instructions correctly to the ring buffer. But Mmio need CPU participation, when big data, disrupt CPU GPU parallelism, can not be scratched.

The driver is actually around this thing to do, Vista before, the driver of the graphics card is all kernel mode execution, because only kernel mode to access the physical address, but kernel mode the disadvantage is that once there is a problem, the system crashes, and kernel Mode has many limitations, such as the lack of C-Library support, floating-point arithmetic is difficult, the cost is very large and so on. So after Vista, the graphics driver is divided into two parts, KMD is responsible for the need to access the physical address of the action, and other things to UMD to do, including API support and so on. So a 3D program executes the process like this, app generate command, call D3D RUNTIME,D3D Runtime call driver UMD, driver UMD system call driver KMD, K md Send command to ring buffer, graphic card exeute.

As for the graphics card driver to complete what part, this is called HAL (Hardware abstraction layer), that is, HAL is provided by the manufacturer, the above is the operating system, above the HAL layer, all operations are unified, such as drawing a point, draw a line, Driver to correspond to a specific chip to generate real commands, such as drawing points, need to 0x9 instructions, the absolute coordinates of the address 0x12345678 (for example). Microsoft tube is wide, UMD, KMD have HAL layer, meaning even if kmd you can not write, unified as far as possible unified, such as CPU GPU external fence read-write synchronization mechanism is Microsoft Unified.

Stream processor that is, those processors can execute a lot of instructions, rather than a few fixed functions, such as the original I put several matrix multiplication into an operation (such as the T&l unit), now I take this operation is removed, changed to more basic instructions, for example, take the matrix element, add multiply, so more flexible. But you have to bother to combine these instructions, and the combination of these commands has a tall name, shader. As for why it is called shader, more and more long, do not say.

*************************************************************************************************************** ************************************

There must be some qualification before you answer this question. Because there are many kinds of video cards, there are many kinds of platform for graphics card, can not generalize. My answer is based on Intel's own Gen display core unit (i.e., HD 4000 on the market) under the Intel x86 platform. Most of the operating systems take Linux as an example.

>>> Q1. How does the graphics driver control the graphics card, that is, using those instructions to control the video card, through the port?

The current graphics driver is not simply a standalone drive module, but a collection of several drive modules. Both user-and kernel-state drivers are available. Take the Linux desktop system as an example, according to the module partition, the kernel drive has drm/i915 module, the user driver includes libdrm, xorg DDX and dix,3d Libgl, video LIBVA and so on, each user state driver may depend on each other, cooperate with each other, the function is different. Confined to the space cannot be described. If according to the function divides, probably divides into 5 categories, display, the three-dimensional, the video, as well as General Purpose Computing Universal Computation. Display is about how to show content, such as resolution AH, refresh rate Ah, multi-screen display AH. It is now used very little, the basic point is to draw a line acceleration, fast memory copy (that is, a DMA). The complexity of the 2D, the basic thing is now 3D dry. 3D involves a lot of computer graphics knowledge, my short board, I will not say more. Video refers to hardware-accelerated audio codec. Universal computing is the support for Opencl,opencv,cuda these frameworks.

Back to the question, drive how to control the video card.
First, the operation of the hardware action is sensitive action, generally only the kernel has permissions. Individual situations are handled by the user, but register mappings are created through the kernel.
The most important thing to understand about drivers is that registers are the only way for software to control hardware. So you ask how to control the graphics card, the answer is to read and write the card provided by the Register.
Through what, read and write? As far as I know, the current graphics driver is basically not read and written in the form of inefficient port IO. This is now done by Mmio the kernel address space of the register map, and then using the Memory access instruction (the general C-language assignment statement) to access it. Refer to "Kernel memory mapping, MMIO" for details.

>>>q2.2. DirectX or OpenGL or Cuda or OpenCL how to find the graphics driver, the graphics driver is not to provide them with the implementation of the interface, if so, then DirectX and OpenGL and Cuda and OpenCL needs the graphics card driver provides the interface is what, this document where Load it up? If not, then how does DirectX, OpenGL, CL, Cuda control the graphics card?

I'm just trying to answer this question for OpenGL and OPENCL implementations on Linux.
A. How do I find a driver? First of all, let's make it clear what the driver is, for OpenGL, There is a user-State library called libgl.so, this is the OpenGL user-state driver (also known as the library, but will be dependent on another hardware-related dynamic library, this is a narrower driver), directly to the application to provide APIs. Similarly, OpenCL, there is also a libcl.so. These so files rely on lower-level user-driven drivers as support (in Linux, graphics-related drivers are generally a general-purpose tier-driven. So file provides the API, and then a platform-dependent. So file is provided for the corresponding hardware support. For example, Libva.so provides video acceleration api,i965_video_drv.so is his back end, providing the Intel platform corresponding to LIBVA hardware acceleration implementation). Here's a big picture for you:
It can be seen that the top-level user driver relies heavily on a number of device-related drivers and finally goes back to the LIBDRM layer, which is the kernel and user-state critical. Usually here, the program that wants to use the video card will open a/DEV/DRI/CARD0 device node, which is created by the graphics card kernel driver. Of course, this open action is not done directly by the application, usually using some abundance functions, such as Drmopenbyname, Drmopenbybusid. There will also be some query operations, query the name of the board or bus ID. Then call the corresponding auxiliary function to open the device node. Once opened, he can use the features of the graphics card according to the DRI specification. All of this is regulated in Linux, called DRI (Direct Rendering Infrastructure).
All of these picture documents can be found on the DRI wiki on the page dri wiki on direct Rendering Infrastructure and FreeDesktop
Graphics drivers are complex, and there are design reasons and historical reasons.
B. With regard to the definition of the interface, the source code can be found in the link I provided above. This set is normative and has an agreement.
C.opengl, OpenCL, or libva the need for graphics cards to provide bitmap operations, general purpose computing, or codec service drivers, generally in two ways to operate the video card. The first is the IOCTL mechanism that is provided with DRM, which is called by the system. Such operations typically include the application to release memory objects, map memory objects, perform GPU instructions, and so on. The other is that the user-state driver translates the user's API semantics into a set of GPU instructions and then releases the instructions to the GPU with the help of the kernel driver (the first to execute the GPU instructions). The specifics are not much to say, these can be obtained by reading the source code.

>>>q4. Does the video card (or other device) have access to memory? Memory address mapping principle is what, why b8000h to C7FFFH is the memory address, to this address space after writing data, is directly through the bus to write the memory, or still write in memory, video card to memory read, if directly write to the video, will appear delay and wait?

A.. can access memory. If you can't access it, where does that show come from? You in the hard disk of a piece, always can not put yourself in the video card decoding rendering it?
B. Graphics card accesses memory, 3 main ways.
The first kind is framebuffer. The CPU has a piece of memory called Framebuffer, which is put on display, the graphics card has a part called Display controller will scan the memory, and then display the content on the screen. As for the specific how to configure the successful, Long story, here is not elaborate.
The second type, DMA. DMA, understand? Is the hardware device directly from within the data access, of course, the software must be configured first, this is the work of graphics driver. In the graphics card driver, DMA also has a special name called Blit.
The third type, memory sharing. Intel's platform, video memory and memory are essentially main memories. The difference is that the CPU needs the MMU mapping, and the GPU-required MMU called the GTT map. So the method of sharing memory is very simple, the same physical page is filled in the MMU page table, also fill in the GTT page. Specific details and principles, according to the basis of each person, need to look at different documents ...
C. Why is that fixed address? The name of this address is called aperture space, which is to map the memory to a contiguous physical space. Why to map, just for the video card can continuously access a section of the address. Because memory is paged, hardware often requires sequential pages. In fact, there is a more important reason is to solve the problem called tiling about the graphics memory storage situation and different memory inconsistencies (this is too professional for the average person).
The starting address of this address is platform-dependent, and the PC platform is typically partitioned by the firmware (BIOS flow) to plan the bus address space for the graphics card. The size of the address range can also be specified or configured in the firmware.
In addition, there is a class of address is also fixed high-level partition called stolen memory, this is the x86 platform, is to steal a piece of physical memory specifically for the most basic graphics output use, such as terminal character display, framebuffer. The start address is also the firmware decision, and the size has a default value can also be configured.
D. Just now, Intel's video memory is a thing. As for the independent graphics card with independent memory platform to answer your question is this: any visit is through the bus, the direct write is also through the bus write, copy is also through the bus copy; sometimes you need to write to the temporary memory and then copy it to the target area for many reasons, the write operation through the PCI bus has a delay, Everyone has it written. The bus is the resources that each device shares, need the mechanism such as arbitration, must wait for certain sometimes.

>>>q5. Which books are available from the above knowledge?

Intel Graphics for Linux * from here, look at the teenager. This kind of too professional knowledge, not recommended in the General Experience Exchange platform for help, it is difficult to get accurate answers. What you need is an accurate answer to these questions. Otherwise it would be more complicated to have a problem that was not easy to understand.

References

http://www.zhihu.com/question/20722310

How does the bottom of the computer access the video card?

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.