Direct Rendering Manager

From Wikipedia, the free encyclopedia
Jump to: navigation, search
Direct Rendering Manager
Original author(s) kernel.org & freedesktop.org
Developer(s) kernel.org & freedesktop.org
Written in C
Type
License
Website dri.freedesktop.org/wiki/DRM
The Linux API is composed out of the System Call Interface of the Linux kernel, the GNU C Library (by GNU), libcgroup,[1] libdrm, libalsa and libevedv[2] (by freedesktop.org).

The Direct Rendering Manager (DRM) is a subsystem of the Linux kernel responsible for interfacing with GPUs of modern video cards. DRM exposes an API that user space programs can use to send commands and data to the GPU, and perform operations like configuring the mode setting of the display. DRM was first developed as the kernel space component of the the X Server's Direct Rendering Infrastructure,[3] but since then it has been used by other graphic stack alternatives like Wayland.

The Direct Rendering Manager can be compiled into the Linux kernel or loaded via the standard module interface.

Overview[edit]

The Linux Kernel already had an API called fbdev allowing to manage the framebuffer of a graphics adapter, but it couldn't be used to handle the needs of modern 3D accelerated GPU based video cards. These type of cards usually require setting and managing a command queue in the memory of the card (Video RAM) to dispatch commands to the GPU, and also they need a proper management of the buffers and free space of the Video RAM itself.[4] Initially own user space programs (like the X Server) directly managed these resources, but these programs usually acted as if they were the only ones with access to the card's resources. When two or more programs tried to control the same video card at the same time, and set its resources each one in its own way, most times they ended catastrophically.[4]

Access to video card without DRM
Without DRM
Access to video card with DRM
With DRM
DRM allows multiple programs concurrently access to the 3D video card avoiding collisions

When the Direct Render Manager was first created, the purpose was that multiple programs that would use the resources of the video card cooperate through it. The DRM has exclusive access to the video card's resources, and it's responsible for initializing and maintaining the command queue, the VRAM and any other hardware resource of the GPU. The programs that want to use a GPU send their requests to DRM, which acts as an arbitrator and takes care to avoid possible conflicts.

Since then, the scope of DRM has been expanded over the years to cover more functionality previously handled by user space programs, like framebuffer managing and mode setting, memory sharing objects and memory synchronization.[5][6] These expansions had carried its own specific names, like Graphics Execution Manager (GEM) or Kernel Mode-Setting (KMS), and are often called by these names when referring specifically to its functionality. But they are really parts of the whole kernel DRM subsystem.

Software architecture[edit]

A process using the Direct Rendering Manager of the Linux Kernel to access a 3D accelerated graphics card

The Direct Rendering Manager resides in kernel space, so the user space programs must use kernel system calls to request its services. However, DRM doesn't define its own customized system calls. Instead, it follows the Unix principle "everything is a file" to expose the GPUs through the filesystem name space using device files under the /dev hierarchy. Each GPU detected by DRM is referred as a DRM device, and a device file /dev/dri/cardX (where X is a correlative number) is created to interface with the device.[7][8] The user space programs that want to talk to the GPU must open the file and use ioctl calls to communicate with DRM. Different ioctls correspond to different functions of the DRM API.

A library called libdrm was created to facilitate the interface of user space applications with the DRM subsystem. This library is merely a wrapper that provides a function written in C for every ioctl of the DRM API, as well as constants, structures and other helper elements.[9] The use of libdrm not only avoids exposing the kernel interface directly to the user space applications, but presents the usual advantages of reusing and sharing code between programs.

  • The DRM provides synchronized access to the graphics hardware via the use of an optimized two-tiered lock.
  • The DRM enforces the DRI security policy for access to the graphics hardware by only allowing authenticated X11 clients access to restricted regions of memory.
  • The DRM provides a generic DMA engine, complete with multiple queues and the ability to detect the need for an OpenGL context switch.
  • The DRM is extensible via the use of small device-specific modules that rely extensively on the API exported by the DRM module.

It consists of two in-kernel drivers: a generic drm driver, and another which has specific support for the GPUs. This pair of drivers allows a userspace client direct access to the video hardware. The entire DRI system enables hardware accelerated 3D rendering, video decoding as well as GPGPU.

AGP, PCIe and other graphics cards contain an IOMMU called Graphics address remapping table (GART) which can be used to map various pages of system memory into the GPU's address space. The result is that, at any time, an arbitrary (scattered) subset of the system's RAM pages are accessible to the GPU.[10]

Linux kernel version 3.11, which was released on 2013-09-02, included major changes to the direct rendering manager.[11]

API[edit]

The DRM core exports several interfaces to user-space applications, generally intended to be used through corresponding libdrm wrapper functions. In addition, drivers export device-specific interfaces for use by user-space drivers & device-aware applications through ioctls and sysfs files. External interfaces include: memory mapping, context management, DMA operations, AGP management, vblank control, fence management, memory management, and output management.

KMS driver (Kernel mode setting)[edit]

The KMS driver is the component which is solely responsible for the mode setting. It is the device driver for a display controller, and it can be distinguished from the device driver of a rendering accelerator. Due to the fact that dies of modern the GPU found on graphics cards for desktop computers integrate "processing logic", "display controller" and "hardware video acceleration" SIP cores, non-technical people don't distinguish between these three very different components. SoCs on the other hand, regularly mix SIP from different developers, and e.g. ARM's Mali SIP does not feature a display controller. For historical reasons, the DRM and the KMS of the Linux kernel were amalgamated into one component. They were split in 2013 for technical reasons.[12]

The video Embedded Linux Conference 2013 – Anatomy of an Embedded KMS driver on YouTube explains what a KMS driver is.

DRM/i915 obtained support for MIPI Display Serial Interface (DSI) for Linux kernel 3.16.[13]

Multi-monitor[edit]

Support for a multi-monitor set-up is of course an ability of the display controller. For example, AMD's display controllers since the Radeon HD 5000 Series, are advertised with the brand "AMD Eyefinity". This new capability of the hardware is supported by AMD's proprietary driver. Whether it is also supported by the KMS driver, this section will tell soon.

Render nodes[edit]

In version 3.12 an (experimental) implementation of render nodes were merged into the Direct Rendering Manager.[14][15][16][17]

A render node is a character device that exposes a GPU's off-screen rendering and GPGPU capabilities to unprivileged programs, without exposing any display manipulation access. This is the first step in of an effort to decouple the kernel's interfaces for GPUs and display controllers from the obsolete notion of a graphics card.[12] Coincidentally, unprivileged off-screen rendering is presumed by both Wayland and Mir display protocols — only the compositor is entitled to send its output to a display, and rendering on behalf of client programs is outside the scope of these protocols.

Universal plane[edit]

Patches for universal plane were submitted by Intel's Matthew. D. Roper in May 2014. The idea behind universal plane is to expose all types of hardware planes to userspace via one consistent Kernel–user space API.[18] Universal plane brings framebuffers (primary planes), overlays (secondary planes) and cursors (cursor planes) together under the same API. No more type specific ioctls, but common ioctls shared by them all.[19]

Universal plane prepares the way for Atomic mode setting and nuclear pageflip.

Hardware support[edit]

All hardware mentioned in the article free and open-source graphics device driver has drm code.[20]

As of August 2013, the kernel component of the freedreno driver mainly authored by Rob Clark for Qualcomm's Adreno GPU family, called MSM driver, has been accepted into mainline, and has been available since Linux kernel 3.12.[21][22]

In Linux kernel 3.13

  • DRM support for Marvell's ARMADA 510 display subsystem.[23]

See also[edit]

References[edit]

  1. ^ "ControlGroupInterface". freedesktop.org. 
  2. ^ "libevdev". freedesktop.org. 
  3. ^ "Linux kernel/drivers/gpu/drm/README.drm". kernel.org. Retrieved 2014-02-26. 
  4. ^ a b White, Thomas. "How DRI and DRM Work". Retrieved 22 July 2014. 
  5. ^ Corbet, Jonathan. "Memory management for graphics processors". LWN.Net. Retrieved 23 July 2014. 
  6. ^ Packard, Keith; Anholt, Eric. "The Graphics Execution Manager". LWN.Net. Retrieved 23 July 2014. 
  7. ^ Kitching, Simon. "DRM and KMS kernel modules". Retrieved 23 July 2014. 
  8. ^ Herrmann, David. "Splitting DRM and KMS device nodes". Retrieved 23 July 2014. 
  9. ^ "libdrm README". Retrieved 23 July 2014. 
  10. ^ "Memory management for graphics processors". LWN.net. 2007-11-06. Retrieved 2014-06-25. 
  11. ^ "DRM changes in Linux Kernel 3.11 are huge". Phoronix. 2013-06-30. Retrieved 2014-06-25. 
  12. ^ a b "Splitting DRM and KMS nodes". David Herrmann. 2013-09-01. 
  13. ^ "Neat drm/i915 stuff for 3.16". 2014-06-10. 
  14. ^ "drm: implement experimental render nodes". 
  15. ^ "drm/i915: Support render nodes". 
  16. ^ "drm/radeon: Support render nodes". 
  17. ^ "drm/nouveau: Support render nodes". 
  18. ^ "Universal plane support". 2014-05-07. 
  19. ^ "From pre-history to beyond the global thermonuclear war". 2014-06-05. 
  20. ^ "/drivers/gpu/drm". kernel.org. 
  21. ^ "Merge the MSM driver from Rob Clark". freedesktop.org. 2013-08-28. Retrieved 2014-06-25. 
  22. ^ "drm/msm for Linux kernel 3.13". freedesktop.org. 2013-10-20. 
  23. ^ "Armada DRM support for Linux kernel 3.13". 

External links[edit]