The Direct Rendering Manager (DRM) is a subsystem of the
Linux kernel
The Linux kernel is a free and open-source, monolithic, modular, multitasking, Unix-like operating system kernel. It was originally authored in 1991 by Linus Torvalds for his i386-based PC, and it was soon adopted as the kernel for the GNU ope ...
responsible for interfacing with
GPUs
A graphics processing unit (GPU) is a specialized electronic circuit designed to manipulate and alter memory to accelerate the creation of images in a frame buffer intended for output to a display device. GPUs are used in embedded systems, mobil ...
of modern
video cards
A graphics card (also called a video card, display card, graphics adapter, VGA card/VGA, video adapter, display adapter, or mistakenly GPU) is an expansion card which generates a feed of output images to a display device, such as a computer mo ...
. DRM exposes an
API
An application programming interface (API) is a way for two or more computer programs to communicate with each other. It is a type of software interface, offering a service to other pieces of software. A document or standard that describes how ...
that
user-space
A modern computer operating system usually segregates virtual memory into user space and kernel space. Primarily, this separation serves to provide memory protection and hardware protection from malicious or errant software behaviour.
Kernel ...
programs can use to send commands and data to the GPU and perform operations such as configuring the
mode setting
Mode setting is a software operation that activates a display mode (screen resolution, color depth, and refresh rate) for a computer's display controller by using VESA BIOS Extensions or UEFI Graphics extensions (on more modern computers).
The d ...
of the display. DRM was first developed as the
kernel-space
A modern computer operating system usually segregates virtual memory into user space and kernel space. Primarily, this separation serves to provide memory protection and hardware protection from malicious or errant software behaviour.
Kernel ...
component of the
X Server Direct Rendering Infrastructure
The Direct Rendering Infrastructure (DRI) is the framework comprising the modern Linux graphics stack which allows unprivileged user-space programs to issue commands to graphics hardware without conflicting with other programs. The main use ...
, but since then it has been used by other graphic stack alternatives such as
Wayland.
User-space programs can use the DRM API to command the GPU to do
hardware-accelerated
Hardware acceleration is the use of computer hardware designed to perform specific functions more efficiently when compared to software running on a general-purpose central processing unit (CPU). Any transformation of data that can be calcul ...
3D rendering
3D rendering is the 3D computer graphics process of converting 3D modeling, 3D models into 2D computer graphics, 2D images on a computer. 3D renders may include photorealistic rendering, photorealistic effects or non-photorealistic rendering, no ...
and
video decoding
A video decoder is an electronic circuit, often contained within a single integrated circuit chip, that converts base-band analog video signals to digital video. Video decoders commonly allow programmable control over video characteristics such ...
, as well as
GPGPU computing.
Overview
The
Linux kernel
The Linux kernel is a free and open-source, monolithic, modular, multitasking, Unix-like operating system kernel. It was originally authored in 1991 by Linus Torvalds for his i386-based PC, and it was soon adopted as the kernel for the GNU ope ...
already had an
API
An application programming interface (API) is a way for two or more computer programs to communicate with each other. It is a type of software interface, offering a service to other pieces of software. A document or standard that describes how ...
called
fbdev, used to manage the
framebuffer
A framebuffer (frame buffer, or sometimes framestore) is a portion of random-access memory (RAM) containing a bitmap that drives a video display. It is a memory buffer containing data representing all the pixels in a complete video frame. Modern ...
of a
graphics adapter
A graphics card (also called a video card, display card, graphics adapter, VGA card/VGA, video adapter, display adapter, or mistakenly GPU) is an expansion card which generates a feed of output images to a display device, such as a computer moni ...
, but it couldn't be used to handle the needs of modern 3D-accelerated
GPU
A graphics processing unit (GPU) is a specialized electronic circuit designed to manipulate and alter memory to accelerate the creation of images in a frame buffer intended for output to a display device. GPUs are used in embedded systems, mobi ...
-based video hardware. These devices usually require setting and managing a command queue in
their own memory to dispatch commands to the GPU and also require management of buffers and free space within that memory. Initially, user-space programs (such as the
X Server) directly managed these resources, but they usually acted as if they were the only ones with access to them. When two or more programs tried to control the same hardware at the same time, and set its resources each one in its own way, most times they ended catastrophically.
The Direct Rendering Manager was created to allow multiple programs to use video hardware resources cooperatively. The DRM gets exclusive access to the GPU and is responsible for initializing and maintaining the command queue, memory, and any other hardware resource. Programs wishing to use the GPU send requests to DRM, which acts as an arbitrator and takes care to avoid possible conflicts.
The scope of DRM has been expanded over the years to cover more functionality previously handled by user-space programs, such as framebuffer managing and
mode setting
Mode setting is a software operation that activates a display mode (screen resolution, color depth, and refresh rate) for a computer's display controller by using VESA BIOS Extensions or UEFI Graphics extensions (on more modern computers).
The d ...
, memory-sharing objects and memory synchronization. Some of these expansions were given specific names, such as
Graphics Execution Manager
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 ...
(GEM) or
kernel mode-setting
Mode setting is a software operation that activates a display mode (screen resolution, color depth, and refresh rate) for a computer's display controller by using VESA BIOS Extensions or UEFI Graphics extensions (on more modern computers).
The d ...
(KMS), and the terminology prevails when the functionality they provide is specifically alluded. But they are really parts of the whole kernel DRM subsystem.
The trend to include two GPUs in a computer—a discrete GPU and an integrated one—led to new problems such as
GPU switching
GPU switching is a mechanism used on computers with multiple graphic controllers. This mechanism allows the user to either maximize the graphic performance or prolong battery life by switching between the graphic cards. It is mostly used on gaming ...
that also needed to be solved at the DRM layer. In order to match the
Nvidia Optimus
Nvidia Optimus is a computer GPU switching technology created by Nvidia which, depending on the resource load generated by client software applications, will seamlessly switch between two graphics adapters within a computer system in order to prov ...
technology, DRM was provided with GPU offloading abilities, called PRIME.
Software architecture
![High level Overview of DRM](https://upload.wikimedia.org/wikipedia/commons/6/62/High_level_Overview_of_DRM.svg)
The Direct Rendering Manager resides in
kernel space
A modern computer operating system usually segregates virtual memory into user space and kernel space. Primarily, this separation serves to provide memory protection and hardware protection from malicious or errant software behaviour.
Kernel ...
, so user-space programs must use kernel
system call
In computing, a system call (commonly abbreviated to syscall) is the programmatic way in which a computer program requests a service from the operating system on which it is executed. This may include hardware-related services (for example, acc ...
s to request its services. However, DRM doesn't define its own customized system calls. Instead, it follows the
Unix
Unix (; trademarked as UNIX) is a family of multitasking, multiuser computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, and ot ...
principle of "
everything is a file
Everything is a file is an idea that Unix, and its derivatives handle input/output to and from resources such as documents, hard-drives, modems, keyboards, printers and even some inter-process and network communications as simple streams of byte ...
" to expose the
GPU
A graphics processing unit (GPU) is a specialized electronic circuit designed to manipulate and alter memory to accelerate the creation of images in a frame buffer intended for output to a display device. GPUs are used in embedded systems, mobi ...
s through the filesystem name space, using
device file
In Unix-like operating systems, a device file or special file is an interface to a device driver that appears in a file system as if it were an ordinary file. There are also special files in DOS, OS/2, and Windows. These special files allow a ...
s under the
/dev
hierarchy. Each GPU detected by DRM is referred to as a ''DRM device'', and a device file
/dev/dri/card''X''
(where ''X'' is a sequential number) is created to interface with it. User-space programs that want to talk to the GPU must
open
Open or OPEN may refer to:
Music
* Open (band), Australian pop/rock band
* The Open (band), English indie rock band
* ''Open'' (Blues Image album), 1969
* ''Open'' (Gotthard album), 1999
* ''Open'' (Cowboy Junkies album), 2001
* ''Open'' (YF ...
this file and use
ioctl
In computing, ioctl (an abbreviation of input/output control) is a system call for device-specific input/output operations and other operations which cannot be expressed by regular system calls. It takes a parameter specifying a request code; th ...
calls to communicate with DRM. Different ioctls correspond to different functions of the DRM
API
An application programming interface (API) is a way for two or more computer programs to communicate with each other. It is a type of software interface, offering a service to other pieces of software. A document or standard that describes how ...
.
A
library
A library is a collection of materials, books or media that are accessible for use and not just for display purposes. A library provides physical (hard copies) or digital access (soft copies) materials, and may be a physical location or a vir ...
called ''libdrm'' was created to facilitate the interface of user-space programs with the DRM subsystem. This library is merely a
wrapper that provides a
function
Function or functionality may refer to:
Computing
* Function key, a type of key on computer keyboards
* Function model, a structured representation of processes in a system
* Function object or functor or functionoid, a concept of object-oriente ...
written in
C for every ioctl of the DRM API, as well as constants, structures and other helper elements. The use of libdrm not only avoids exposing the kernel interface directly to applications, but presents the usual advantages of
reusing
Reuse is the action or practice of using an item, whether for its original purpose (conventional reuse) or to fulfill a different function ( creative reuse or repurposing). It should be distinguished from recycling, which is the breaking down of u ...
and sharing code between programs.
![DRM architecture](https://upload.wikimedia.org/wikipedia/commons/3/3d/DRM_architecture.svg)
DRM consists of two parts: a generic "DRM core" and a specific one ("DRM driver") for each type of supported hardware. DRM core provides the basic framework where different DRM drivers can register and also provides to user space a minimal set of ioctls with common, hardware-independent functionality. A DRM driver, on the other hand, implements the hardware-dependent part of the API, specific to the type of GPU it supports; it should provide the implementation of the remaining ioctls not covered by DRM core, but it may also extend the API, offering additional ioctls with extra functionality only available on such hardware. When a specific DRM driver provides an enhanced API, user-space libdrm is also extended by an extra library libdrm-''driver'' that can be used by user space to interface with the additional ioctls.
API
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 and device-aware applications through
ioctl
In computing, ioctl (an abbreviation of input/output control) is a system call for device-specific input/output operations and other operations which cannot be expressed by regular system calls. It takes a parameter specifying a request code; th ...
s and
sysfs
sysfs is a pseudo file system provided by the Linux kernel that exports information about various kernel subsystems, hardware devices, and associated device drivers from the kernel's device model to user space through virtual files. In addition ...
files. External interfaces include: memory mapping, context management,
DMA operations,
AGP management,
vblank control, fence management, memory management, and output management.
DRM-Master and DRM-Auth
There are several operations (ioctls) in the DRM API that either for security purposes or for concurrency issues must be restricted to be used by a single user-space process per device. To implement this restriction, DRM limits such ioctls to be only invoked by the process considered the "master" of a DRM device, usually called ''DRM-Master''. Only one of all processes that have the device node
/dev/dri/card''X''
opened will have its
file handle
In Unix and Unix-like computer operating systems, a file descriptor (FD, less frequently fildes) is a process-unique identifier ( handle) for a file or other input/output resource, such as a pipe or network socket.
File descriptors typically hav ...
marked as master, specifically the first calling the ioctl. Any attempt to use one of these restricted ioctls without being the DRM-Master will return an error. A process can also give up its master role—and let another process acquire it—by calling the ioctl.
The
X Server—or any other
display server
In computing, a windowing system (or window system) is software that manages separately different parts of display screens. It is a type of graphical user interface (GUI) which implements the WIMP (windows, icons, menus, pointer) paradigm for ...
—is commonly the process that acquires the DRM-Master status in every DRM device it manages, usually when it opens the corresponding device node during its startup, and keeps these privileges for the entire graphical session until it finishes or dies.
For the remaining user-space processes there is another way to gain the privilege to invoke some restricted operations on the DRM device called ''DRM-Auth''. It is basically a method of authentication against the DRM device, in order to prove to it that the process has the DRM-Master's approval to get such privileges. The procedure consists of:
* The client gets a unique token—a 32-bit integer—from the DRM device using the ioctl and passes it to the DRM-Master process by whatever means (normally some sort of
IPC; for example, in
DRI2
The Direct Rendering Infrastructure (DRI) is the framework comprising the modern Linux graphics stack which allows unprivileged user-space programs to issue commands to graphics hardware without conflicting with other programs. The main use ...
there is a request that any X client can send to the X Server.)
* The DRM-Master process, in turn, sends back the token to the DRM device by invoking the ioctl.
* The device grants special rights to the process file handle whose auth token matches the received token from the DRM-Master.
Graphics Execution Manager
Due to the increasing size of
video memory
Dynamic random-access memory (dynamic RAM or DRAM) is a type of random-access semiconductor memory that stores each bit of data in a memory cell, usually consisting of a tiny capacitor and a transistor, both typically based on metal-oxide ...
and the growing complexity of graphics APIs such as
OpenGL
OpenGL (Open Graphics Library) is a cross-language, cross-platform application programming interface (API) for rendering 2D and 3D vector graphics. The API is typically used to interact with a graphics processing unit (GPU), to achieve hardwa ...
, the strategy of reinitializing the graphics card state at each
context switch
In computing, a context switch is the process of storing the state of a process or thread, so that it can be restored and resume execution at a later point, and then restoring a different, previously saved, state. This allows multiple processes ...
was too expensive, performance-wise. Also, modern
Linux desktop
Besides the Linux distributions designed for general-purpose use on desktops and servers, distributions may be specialized for different purposes including computer architecture support, embedded systems, stability, security, localization to a spec ...
s needed an optimal way to share off-screen buffers with the
compositing manager. These requirements led to the development of new methods to manage graphics
buffers inside the kernel. The ''Graphics Execution Manager'' (GEM) emerged as one of these methods.
GEM provides an API with explicit
memory management
Memory management is a form of resource management applied to computer memory. The essential requirement of memory management is to provide ways to dynamically allocate portions of memory to programs at their request, and free it for reuse when ...
primitives. Through GEM, a user-space program can create, handle and destroy memory objects living in the GPU video memory. These objects, called "GEM objects", are persistent from the user-space program's perspective and don't need to be reloaded every time the program regains control of the GPU. When a user-space program needs a chunk of video memory (to store a
framebuffer
A framebuffer (frame buffer, or sometimes framestore) is a portion of random-access memory (RAM) containing a bitmap that drives a video display. It is a memory buffer containing data representing all the pixels in a complete video frame. Modern ...
,
texture
Texture may refer to:
Science and technology
* Surface texture, the texture means smoothness, roughness, or bumpiness of the surface of an object
* Texture (roads), road surface characteristics with waves shorter than road roughness
* Texture (c ...
or any other data required by the GPU), it requests the allocation to the DRM driver using the GEM API. The DRM driver keeps track of the used video memory and is able to comply with the request if there is free memory available, returning a "handle" to user space to further refer the allocated memory in coming operations. GEM API also provides operations to populate the buffer and to release it when it is not needed anymore. Memory from unreleased GEM handles gets recovered when the user-space process closes the DRM device
file descriptor
In Unix and Unix-like computer operating systems, a file descriptor (FD, less frequently fildes) is a process-unique identifier (handle) for a file or other input/output resource, such as a pipe or network socket.
File descriptors typically have ...
—intentionally or because it terminates.
GEM also allows two or more user-space
processes using the same DRM device (hence the same DRM driver) to share a GEM object. GEM handles are local 32-bit integers unique to a process but repeatable in other processes, therefore not suitable for sharing. What is needed is a global namespace, and GEM provides one through the use of global handles called ''GEM names''. A GEM name refers to one, and only one, GEM object created within the same DRM device by the same DRM driver, by using a unique 32-bit
integer
An integer is the number zero (), a positive natural number (, , , etc.) or a negative integer with a minus sign (−1, −2, −3, etc.). The negative numbers are the additive inverses of the corresponding positive numbers. In the language ...
. GEM provides an operation ''flink'' to obtain a GEM name from a GEM handle. The process can then pass this GEM name (32-bit integer) to another process using any
IPC mechanism available. The GEM name can be used by the recipient process to obtain a local GEM handle pointing to the original GEM object.
Unfortunately, the use of GEM names to share buffers is not secure. A malicious third-party process accessing the same DRM device could try to guess the GEM name of a buffer shared by other two processes, simply by probing 32-bit integers. Once a GEM name is found, its contents can be accessed and modified, violating the
confidentiality and integrity of the information of the buffer. This drawback was overcome later by the introduction of
DMA-BUF support into DRM, as DMA-BUF represents buffers in userspace as file descriptors, which
may be shared securely.
Another important task for any video-memory management system besides managing the video-memory space is handling the memory synchronization between the GPU and the CPU. Current
memory architecture
Memory architecture describes the methods used to implement electronic computer data storage in a manner that is a combination of the fastest, most reliable, most durable, and least expensive way to store and retrieve information. Depending on the ...
s are very complex and usually involve various levels of
caches for the system memory and sometimes for the video memory too. Therefore, video-memory managers should also handle the
cache coherence
In computer architecture, cache coherence is the uniformity of shared resource data that ends up stored in multiple local caches. When clients in a system maintain caches of a common memory resource, problems may arise with incoherent data, whi ...
to ensure the data shared between CPU and GPU is consistent. This means that often video-memory management internals are highly dependent on hardware details of the GPU and memory architecture, and thus driver-specific.
GEM was initially developed by
Intel
Intel Corporation is an American multinational corporation and technology company headquartered in Santa Clara, California. It is the world's largest semiconductor chip manufacturer by revenue, and is one of the developers of the x86 seri ...
engineers to provide a video-memory manager for its i915 driver. The
Intel GMA 9xx family are
integrated GPUs with a Uniform Memory Architecture (UMA), where the GPU and CPU share the physical memory, and there is not a dedicated VRAM. GEM defines "memory domains" for memory synchronization, and while these memory domains are GPU-independent, they are specifically designed with an UMA memory architecture in mind, making them less suitable for other memory architectures like those with a separate VRAM. For this reason, other DRM drivers have decided to expose to user-space programs the GEM API, but internally they implemented a different memory manager better suited for their particular hardware and memory architecture.
The GEM API also provides ioctls for control of the execution flow (command buffers), but they are Intel-specific, to be used with Intel i915 and later GPUs. No other DRM driver has attempted to implement any part of the GEM API beyond the memory-management specific ioctls.
Translation Table Maps
''Translation Table Maps'' (TTM) is the name of the generic memory manager for GPUs that was developed before GEM. It was specifically designed to manage the different types of memory that a GPU might access, including dedicated
Video RAM
Dual-ported video RAM, or VRAM, is a dual-ported variant of dynamic RAM (DRAM), which was once commonly used to store the framebuffer in graphics adapters. Note that most computers and game consoles do not use this form of memory, and dual-porte ...
(commonly installed in the video card) and
system memory accessible through an
I/O memory management unit called the
Graphics Address Remapping Table
The graphics address remapping table (GART), also known as the graphics aperture remapping table, or graphics translation table (GTT), is an I/O memory management unit (IOMMU) used by Accelerated Graphics Port (AGP) and PCI Express (PCIe) graphics ...
(GART). TTM should also handle the portions of the video RAM that are not directly addressable by the CPU and do it with the best possible performance, considering that user-space graphics applications typically work with large amounts of video data. Another important matter was to maintain the consistency between the different memories and caches involved.
The main concept of TTM are the "buffer objects", regions of video memory that at some point must be addressable by the GPU. When a user-space graphics application wants access to a certain buffer object (usually to fill it with content), TTM may require relocating it to a type of memory addressable by the CPU. Further relocations—or GART mapping operations—could happen when the GPU needs access to a buffer object but it isn't in the GPU's address space yet. Each of these relocation operations must handle any related data and cache-coherency issues.
Another important TTM concept is ''
fences
A fence is a barrier enclosing or bordering a field, yard, etc., usually made of posts and wire or wood, used to prevent entrance, to confine, or to mark a boundary.
Fence or fences may also refer to:
Entertainment Music
* Fences (band), an Amer ...
''. Fences are essentially a mechanism to manage concurrency between the CPU and the GPU. A fence tracks when a buffer object is no longer used by the GPU, generally to notify any user-space process with access to it.
The fact that TTM tried to manage all kind of memory architectures, including those with and without a dedicated VRAM, in a suitable way, and to provide every conceivable feature in a memory manager for use with any type of hardware, led to an overly complex solution with an API far larger than needed. Some DRM developers thought that it wouldn't fit well with any specific driver, especially the API. When GEM emerged as a simpler memory manager, its API was preferred over the TTM one. But some driver developers considered that the approach taken by TTM was more suitable for discrete video cards with dedicated video memory and IOMMUs, so they decided to use TTM internally, while exposing their buffer objects as GEM objects and thus supporting the GEM API. Examples of current drivers using TTM as an internal memory manager but providing a GEM API are the radeon driver for AMD video cards and the
nouveau
A ''nouveau'' ( ), or ''vin (de) primeur'', is a wine which may be sold in the same year in which it was harvested.
The most widely exported ''nouveau'' wine is French wine Beaujolais ''nouveau'' which is released on the third Thursday of N ...
driver for NVIDIA video cards.
DMA Buffer Sharing and PRIME
The ''DMA Buffer Sharing API'' (often abbreviated as DMA-BUF) is a
Linux kernel
The Linux kernel is a free and open-source, monolithic, modular, multitasking, Unix-like operating system kernel. It was originally authored in 1991 by Linus Torvalds for his i386-based PC, and it was soon adopted as the kernel for the GNU ope ...
internal
API
An application programming interface (API) is a way for two or more computer programs to communicate with each other. It is a type of software interface, offering a service to other pieces of software. A document or standard that describes how ...
designed to provide a generic mechanism to share
DMA buffers across multiple devices, possibly managed by different types of device drivers. For example, a
Video4Linux
Video4Linux (V4L for short) is a collection of device drivers and an API for supporting realtime video capture on Linux systems. It supports many USB webcams, TV tuners, and related devices, standardizing their output, so programmers can easily ...
device and a graphics adapter device could share buffers through DMA-BUF to achieve
zero-copy
"Zero-copy" describes computer operations in which the CPU does not perform the task of copying data from one memory area to another or in which unnecessary data copies are avoided. This is frequently used to save CPU cycles and memory bandwid ...
of the data of a video stream produced by the first and consumed by the latter. Any Linux
device driver
In computing, a device driver is a computer program that operates or controls a particular type of device that is attached to a computer or automaton. A driver provides a software interface to hardware devices, enabling operating systems and ot ...
can implement this API as exporter, as user (consumer) or both.
This feature was exploited for the first time in DRM to implement PRIME, a solution for
GPU offloading that uses DMA-BUF to share the resulting framebuffers between the DRM drivers of the discrete and the integrated GPU. An important feature of DMA-BUF is that a shared buffer is presented to user space as a
file descriptor
In Unix and Unix-like computer operating systems, a file descriptor (FD, less frequently fildes) is a process-unique identifier (handle) for a file or other input/output resource, such as a pipe or network socket.
File descriptors typically have ...
. For the development of PRIME two new ioctls were added to the DRM API, one to convert a local GEM handle to a DMA-BUF file descriptor and another for the exact opposite operation.
These two new ioctls were later reused as a way to fix the inherent unsafety of GEM buffer sharing. Unlike GEM names, file descriptors can not be guessed (they are not a global namespace), and Unix operating systems provide a safe way to pass them through a
Unix domain socket
A Unix domain socket aka UDS or IPC socket ( inter-process communication socket) is a data communications endpoint for exchanging data between processes executing on the same host operating system. It is also referred to by its address family AF_U ...
using the SCM_RIGHTS semantics. A process that wants to share a GEM object with another process can convert its local GEM handle to a DMA-BUF file descriptor and pass it to the recipient, which in turn can get its own GEM handle from the received file descriptor. This method is used by
DRI3 to share buffers between the client and the X Server and also by
Wayland.
Kernel Mode Setting
![Linux kernel and daemons with exclusive access](https://upload.wikimedia.org/wikipedia/commons/4/44/Linux_kernel_and_daemons_with_exclusive_access.svg)
In order to work properly, a video card or graphics adapter must set a ''
mode
Mode ( la, modus meaning "manner, tune, measure, due measure, rhythm, melody") may refer to:
Arts and entertainment
* '' MO''D''E (magazine)'', a defunct U.S. women's fashion magazine
* ''Mode'' magazine, a fictional fashion magazine which is ...
''—a combination of
screen resolution
The display resolution or display modes of a digital television, computer monitor or display device is the number of distinct pixels in each dimension that can be displayed. It can be an ambiguous term especially as the displayed resolution is ...
,
color depth
Color depth or colour depth (see spelling differences), also known as bit depth, is either the number of bits used to indicate the color of a single pixel, or the number of bits used for each color component of a single pixel. When referring to ...
and
refresh rate
The refresh rate (or "vertical refresh rate", "vertical scan rate", terminology originating with the cathode ray tubes) is the number of times per second that a raster-based display device displays a new image. This is independent from frame rate ...
—that is within the range of values supported by itself and the attached
display screen. This operation is called
mode-setting
Mode setting is a software operation that activates a display mode (screen resolution, color depth, and refresh rate) for a computer's display controller by using VESA BIOS Extensions or UEFI Graphics extensions (on more modern computers).
The d ...
, and it usually requires raw access to the graphics hardware—i.e. the ability to write to certain registers of the video card
display controller
A video display controller or VDC (also called a display engine or display interface) is an integrated circuit which is the main component in a video-signal generator, a device responsible for the production of a TV video signal in a computing ...
. A mode-setting operation must be performed before starting to use the
framebuffer
A framebuffer (frame buffer, or sometimes framestore) is a portion of random-access memory (RAM) containing a bitmap that drives a video display. It is a memory buffer containing data representing all the pixels in a complete video frame. Modern ...
, and also when the mode is required to change by an application or the user.
In early days, the user space programs that wanted to use the graphical framebuffer were also responsible for providing the mode-setting operations, and therefore they needed to run with privileged access to the video hardware. In Unix-type operating systems, the
X Server was the most prominent example, and its mode-setting implementation lived in the
DDX driver for each specific type of video card. This approach, later referred as ''User space Mode-Setting'' or UMS, poses several issues. It not only breaks the isolation that operating systems should provide between programs and hardware, raising both stability and security concerns, but also could leave the graphics hardware in an inconsistent state if two or more user space programs try to do the mode-setting at the same time. To avoid these conflicts, the X Server became in practice the only user space program that performed mode-setting operations; the remainder user space programs relied on the X Server to set the appropriate mode and to handle any other operation involving mode-setting. Initially the mode-setting was performed exclusively during the X Server startup process, but later the X Server gained the ability to do it while running. The XFree86-VidModeExtension extension was introduced in
XFree86
XFree86 is an implementation of the X Window System. It was originally written for Unix-like operating systems on IBM PC compatibles and was available for many other operating systems and platforms. It is free and open source software under the X ...
3.1.2 to let any X client request
modeline (resolution) changes to the X Server. VidMode extension was later superseded by the more generic
XRandR
X.Org Server is the free and open-source implementation of the X Window System display server stewarded by the X.Org Foundation.
Implementations of the client-side X Window System protocol exist in the form of ''X11 libraries'', which serve ...
extension.
However, this was not the only code doing mode-setting in a
Linux
Linux ( or ) is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically packaged as a Linux distribution, which ...
system. During the system booting process, the Linux kernel must set a minimal
text mode
Text mode is a computer display mode in which content is internally represented on a computer screen in terms of characters rather than individual pixels. Typically, the screen consists of a uniform rectangular grid of ''character cells'', each ...
for the
virtual console
A virtual console (VC) – also known as a virtual terminal (VT) – is a conceptual combination of the keyboard and display for a computer user interface. It is a feature of some Unix-like operating systems such as Linux, BSD, illumos, Unix ...
(based on the standard modes defined by
VESA BIOS extensions). Also the
Linux kernel framebuffer driver contained mode-setting code to configure framebuffer devices. To avoid mode-setting conflicts, the
XFree86 Server—and later the
X.Org Server
X.Org Server is the free and open-source implementation of the X Window System display server stewarded by the X.Org Foundation.
Implementations of the client-side X Window System protocol exist in the form of ''X11 libraries'', which serve a ...
—handled the case when the user switched from the graphical environment to a text
virtual console
A virtual console (VC) – also known as a virtual terminal (VT) – is a conceptual combination of the keyboard and display for a computer user interface. It is a feature of some Unix-like operating systems such as Linux, BSD, illumos, Unix ...
by saving its mode-setting state, and restoring it when the user switched back to X. This process caused an annoying flicker in the transition, and also can fail, leading to a corrupted or unusable output display.
The user space mode setting approach also caused other issues:
* The
suspend/resume process has to rely on user space tools to restore the previous mode. One single failure or crash of one of these programs could leave the system without a working display due to a modeset misconfiguration, and therefore unusable.
* It was also impossible for the kernel to show error or debug messages when the screen was in a graphics mode—for example when X was running—since the only modes the kernel knew about were the VESA BIOS standard text modes.
* A more pressing issue was the proliferation of graphical applications bypassing the X Server and the emergence of other graphics stack alternatives to X, extending the duplication of mode-setting code across the system even further.
To address these problems, the mode-setting code was moved to a single place inside the kernel, specifically to the existing DRM module. Then, every process—including the X Server—should be able to command the kernel to perform mode-setting operations, and the kernel would ensure that concurrent operations don't result in an inconsistent state. The new kernel API and code added to the DRM module to perform these mode-setting operations was called ''Kernel Mode-Setting'' (KMS).
Kernel Mode-Setting provides several benefits. The most immediate is of course the removal of duplicate mode-setting code, from both the kernel (Linux console, fbdev) and user space (X Server DDX drivers). KMS also makes it easier to write alternative graphics systems, which now don't need to implement their own mode-setting code. By providing centralized mode management, KMS solves the flickering issues while changing between console and X, and also between different instances of X (fast user switching). Since it is available in the kernel, it can also be used at the beginning of the boot process, saving flickering due to mode changes in these early stages.
The fact that KMS is part of the kernel allows it to use resources only available at kernel space such as
interrupts
In digital computers, an interrupt (sometimes referred to as a trap) is a request for the processor to ''interrupt'' currently executing code (when permitted), so that the event can be processed in a timely manner. If the request is accepted, ...
. For example, the mode recovery after a suspend/resume process simplifies a lot by being managed by the kernel itself, and incidentally improves security (no more user space tools requiring root permissions). The kernel also allows the
hotplug
Hot swapping is the replacement or addition of components to a computer system without stopping, shutting down, or rebooting the system; hot plugging describes the addition of components only. Components which have such functionality are said ...
of new display devices easily, solving a longstanding problem. Mode-setting is also closely related to memory management—since framebuffers are basically memory buffers—so a tight integration with the graphics memory manager is highly recommended. That's the main reason why the kernel mode-setting code was incorporated into DRM and not as a separate subsystem.
To avoid breaking backwards compatibility of the DRM API, Kernel Mode-Setting is provided as an additional ''driver feature'' of certain DRM drivers. Any DRM driver can choose to provide the flag when it registers with the DRM core to indicate that supports the KMS API. Those drivers that implement Kernel Mode-Setting are often called ''KMS drivers'' as a way to differentiate them from the legacy—without KMS—DRM drivers.
KMS has been adopted to such an extent that certain drivers which lack 3D acceleration (or for which the hardware vendor doesn't want to expose or implement it) nevertheless implement the KMS API without the rest of the DRM API.
KMS device model
KMS models and manages the output devices as a series of abstract hardware blocks commonly found on the display output pipeline of a
display controller
A video display controller or VDC (also called a display engine or display interface) is an integrated circuit which is the main component in a video-signal generator, a device responsible for the production of a TV video signal in a computing ...
. These blocks are:
* CRTCs: each CRTC (from
CRT Controller) represents a scanout engine of the display controller, pointing to a ''scanout buffer'' (
framebuffer
A framebuffer (frame buffer, or sometimes framestore) is a portion of random-access memory (RAM) containing a bitmap that drives a video display. It is a memory buffer containing data representing all the pixels in a complete video frame. Modern ...
). The purpose of a CRTC is to read the pixel data currently in the scanout buffer and generate from it the
video mode timing signal with the help of a
PLL circuit. The number of CRTCs available determines how many independent output devices the hardware can handle at the same time, so in order to use ''
multi-head'' configurations at least one CRTC per display device is required. Two—or more—CRTCs can also work in ''clone mode'' if they scan out from the same framebuffer to send the same image to several output devices.
* Connectors: a connector represents where the display controller sends the video signal from a scanout operation to be displayed. Usually, the KMS concept of a connector corresponds to a physical connector (
VGA
Video Graphics Array (VGA) is a video display controller and accompanying de facto graphics standard, first introduced with the IBM PS/2 line of computers in 1987, which became ubiquitous in the PC industry within three years. The term can no ...
,
DVI
Digital Visual Interface (DVI) is a video display interface developed by the Digital Display Working Group (DDWG). The digital interface is used to connect a video source, such as a video display controller, to a display device, such as a comp ...
,
FPD-Link
Flat Panel Display Link, more commonly referred to as FPD-Link, is the original high-speed digital video interface created in 1996 by National Semiconductor (now within Texas Instruments). It is a free and open standard for connecting the output ...
,
HDMI
High-Definition Multimedia Interface (HDMI) is a proprietary audio/video interface for transmitting uncompressed video data and compressed or uncompressed digital audio data from an HDMI-compliant source device, such as a display controller, ...
,
DisplayPort
DisplayPort (DP) is a digital display interface developed by a consortium of PC and chip manufacturers and standardized by the Video Electronics Standards Association (VESA). It is primarily used to connect a video source to a display device su ...
,
S-Video
S-Video (also known as separate video, Y/C, and erroneously Super-Video ) is an analog video signal format that carries standard-definition video, typically at 525 lines or 625 lines. It encodes video luma and chrominance on two separate channe ...
, ...) in the hardware where an output device (
monitor
Monitor or monitor may refer to:
Places
* Monitor, Alberta
* Monitor, Indiana, town in the United States
* Monitor, Kentucky
* Monitor, Oregon, unincorporated community in the United States
* Monitor, Washington
* Monitor, Logan County, West ...
,
laptop
A laptop, laptop computer, or notebook computer is a small, portable personal computer (PC) with a screen and alphanumeric keyboard. Laptops typically have a clam shell form factor with the screen mounted on the inside of the upper li ...
panel, ...) is permanently or can temporarily be attached. Information related to the current physically attached output device—such as connection status,
EDID Extended Display Identification Data (EDID) and Enhanced EDID (E-EDID) are metadata formats for display devices to describe their capabilities to a video source (e.g. graphics card or set-top box). The data format is defined by a standard published ...
data,
DPMS status or supported video modes—is also stored within the connector.
* Encoders: the display controller must encode the video mode timing signal from the CRTC using a format suitable for the intended connector. An encoder represents the hardware block able to do one of these encodings. Examples of encodings—for digital outputs—are
TMDS
Transition-minimized differential signaling (TMDS), a technology for transmitting high-speed serial data, is used by the DVI and HDMI video interfaces, as well as by other digital communication interfaces.
The transmitter incorporates an advan ...
and
LVDS
Low-voltage differential signaling (LVDS), also known as TIA/EIA-644, is a technical standard that specifies electrical characteristics of a differential, serial signaling standard. LVDS operates at low power and can run at very high speeds ...
; for analog outputs such as
VGA
Video Graphics Array (VGA) is a video display controller and accompanying de facto graphics standard, first introduced with the IBM PS/2 line of computers in 1987, which became ubiquitous in the PC industry within three years. The term can no ...
and TV out, specific
DAC blocks are generally used. A connector can only receive the signal from one encoder at a time, and each type of connector only supports some encodings. There also might be additional physical restrictions by which not every CRTC is connected to every available encoder, limiting the possible combinations of CRTC-encoder-connector.
* Planes: a plane is not a hardware block but a memory object containing a buffer from which a scanout engine (a CRTC) is fed. The plane that holds the
framebuffer
A framebuffer (frame buffer, or sometimes framestore) is a portion of random-access memory (RAM) containing a bitmap that drives a video display. It is a memory buffer containing data representing all the pixels in a complete video frame. Modern ...
is called the ''primary plane'', and each CRTC must have one associated, since it's the source for the CRTC to determine the video mode—display resolution (width and height), pixel size, pixel format, refresh rate, etc. A CRTC might have also ''cursor planes'' associated to it if the display controller supports hardware cursor overlays, or ''secondary planes'' if it's able to scan out from additional
hardware overlay
In computing, hardware overlay, a type of video overlay, provides a method of rendering an image to a display screen with a dedicated memory buffer inside computer video hardware. The technique aims to improve the display of a fast-moving video im ...
s and compose or blend "on the fly" the final image sent to the output device.
Atomic Display
In recent years there has been an ongoing effort to bring
atomicity to some regular operations pertaining the KMS API, specifically to the
mode setting
Mode setting is a software operation that activates a display mode (screen resolution, color depth, and refresh rate) for a computer's display controller by using VESA BIOS Extensions or UEFI Graphics extensions (on more modern computers).
The d ...
and
page flipping
In computer science, multiple buffering is the use of more than one buffer to hold a block of data, so that a "reader" will see a complete (though perhaps old) version of the data, rather than a partially updated version of the data being create ...
operations. This enhanced KMS API is what is called ''Atomic Display'' (formerly known as ''atomic mode-setting'' and ''atomic'' or ''nuclear pageflip'').
The purpose of the ''atomic mode-setting'' is to ensure a correct change of mode in complex configurations with multiple restrictions, by avoiding intermediate steps which could lead to an inconsistent or invalid video state; it also avoids risky video states when a failed mode-setting process has to be undone ("rollback"). Atomic mode-setting allows to know beforehand if certain specific mode configuration is appropriate, by providing mode testing capabilities. When an atomic mode is tested and its validity confirmed, it can be applied with a single indivisible (atomic)
commit operation. Both test and commit operations are provided by the same new
ioctl
In computing, ioctl (an abbreviation of input/output control) is a system call for device-specific input/output operations and other operations which cannot be expressed by regular system calls. It takes a parameter specifying a request code; th ...
with different flags.
''Atomic page flip'' on the other hand allows to update multiple planes on the same output (for instance the primary plane, the cursor plane and maybe some overlays or secondary planes) all synchronized within the same
VBLANK interval, ensuring a proper display without tearing. This requirement is especially relevant to mobile and embedded display controllers, that tend to use multiple planes/overlays to save power.
The new atomic API is built upon the old KMS API. It uses the same model and objects (CRTCs, encoders, connectors, planes, ...), but with an increasing number of object properties that can be modified. The atomic procedure is based on changing the relevant properties to build the state that we want to test or commit. The properties we want to modify depend on whether we want to do a mode-setting (mostly CRTCs, encoders and connectors properties) or page flipping (usually planes properties). The ioctl is the same for both cases, the difference being the list of properties passed with each one.
Render nodes
In the original DRM API, the DRM device
/dev/dri/card''X''
is used for both privileged (modesetting, other display control) and non-privileged (rendering,
GPGPU
General-purpose computing on graphics processing units (GPGPU, or less often GPGP) is the use of a graphics processing unit (GPU), which typically handles computation only for computer graphics, to perform computation in applications traditiona ...
compute) operations. For security reasons, opening the associated DRM device file requires special privileges "equivalent to root-privileges". This leads to an architecture where only some reliable user space programs (the X server, a graphical compositor, ...) have full access to the DRM API, including the privileged parts like the modeset API. Other user space applications that want to render or make GPGPU computations should be granted by the owner of the DRM device ("DRM Master") through the use of a special authentication interface. Then the authenticated applications can render or make computations using a restricted version of the DRM API without privileged operations. This design imposes a severe constraint: there must always be a running graphics server (the X Server, a Wayland compositor, ...) acting as DRM-Master of a DRM device so that other user space programs can be granted the use of the device, even in cases not involving any graphics display like GPGPU computations.
The "render nodes" concept tries to solve these scenarios by splitting the DRM user space API into two interfaces – one privileged and one non-privileged – and using separate device files (or "nodes") for each one. For every GPU found, its corresponding DRM driver—if it supports the render nodes feature—creates a device file
/dev/dri/renderD''X''
, called the ''render node'', in addition to the primary node
/dev/dri/card''X''
. Clients that use a direct rendering model and applications that want to take advantage of the computing facilities of a GPU, can do it without requiring additional privileges by simply opening any existing render node and dispatching GPU operations using the limited subset of the DRM API supported by those nodes—provided they have
file system permissions
Most file systems include attributes of files and directories that control the ability of users to read, change, navigate, and execute the contents of the file system. In some cases, menu options or functions may be made visible or hidden depending ...
to open the device file. Display servers, compositors and any other program that requires the modeset API or any other privileged operation must open the standard primary node that grants access to the full DRM API and use it as usual. Render nodes explicitly disallow the GEM ''flink'' operation to prevent buffer sharing using insecure GEM global names; only PRIME (DMA-BUF)
file descriptor
In Unix and Unix-like computer operating systems, a file descriptor (FD, less frequently fildes) is a process-unique identifier (handle) for a file or other input/output resource, such as a pipe or network socket.
File descriptors typically have ...
s can be used to share buffers with another client, including the graphics server.
Hardware support
![Linux AMD graphics stack](https://upload.wikimedia.org/wikipedia/commons/f/ff/Linux_AMD_graphics_stack.svg)
The Linux DRM subsystem includes
free and open-source
Free and open-source software (FOSS) is a term used to refer to groups of software consisting of both free software and open-source software where anyone is freely licensed to use, copy, study, and change the software in any way, and the source ...
drivers to support hardware from the 3 main manufacturers of GPUs for desktop computers (AMD, NVIDIA and Intel), as well as from a growing number of mobile GPU and
System on a chip
A system on a chip or system-on-chip (SoC ; pl. ''SoCs'' ) is an integrated circuit that integrates most or all components of a computer or other electronic system. These components almost always include a central processing unit (CPU), memory ...
(SoC) integrators. The quality of each driver varies highly, depending on the degree of cooperation by the manufacturer and other matters.
There is also a number of drivers for old, obsolete hardware detailed in the next table for historical purposes. Some of them still remain in the kernel code, but most have been already removed.
Development
The Direct Rendering Manager is developed within the
Linux kernel
The Linux kernel is a free and open-source, monolithic, modular, multitasking, Unix-like operating system kernel. It was originally authored in 1991 by Linus Torvalds for his i386-based PC, and it was soon adopted as the kernel for the GNU ope ...
, and its
source code
In computing, source code, or simply code, is any collection of code, with or without comments, written using a human-readable programming language, usually as plain text. The source code of a program is specially designed to facilitate the wo ...
resides in the
/drivers/gpu/drm
directory of the Linux source code. The subsystem maintainer is Dave Airlie, with other maintainers taking care of specific drivers. As usual in the Linux kernel development, DRM submaintainers and contributors send their
patches with new features and
bug fixes to the main DRM maintainer which integrates them into its own Linux
repository
Repository may refer to:
Archives and online databases
* Content repository, a database with an associated set of data management tools, allowing application-independent access to the content
* Disciplinary repository (or subject repository), an ...
. The DRM maintainer in turn submits all of these patches that are ready to be mainlined to
Linus Torvalds
Linus Benedict Torvalds ( , ; born 28 December 1969) is a Finnish software engineer who is the creator and, historically, the lead developer of the Linux kernel, used by Linux distributions and other operating systems such as Android. He also c ...
whenever a new Linux version is going to be released. Torvalds, as top maintainer of the whole kernel, holds the last word on whether a patch is suitable or not for inclusion in the kernel.
For historical reasons, the source code of the libdrm library is maintained under the umbrella of the
Mesa
A mesa is an isolated, flat-topped elevation, ridge or hill, which is bounded from all sides by steep escarpments and stands distinctly above a surrounding plain. Mesas characteristically consist of flat-lying soft sedimentary rocks capped by ...
project.
History
In 1999, while developing
DRI for
XFree86
XFree86 is an implementation of the X Window System. It was originally written for Unix-like operating systems on IBM PC compatibles and was available for many other operating systems and platforms. It is free and open source software under the X ...
, Precision Insight created the first version of DRM for the
3dfx
3dfx Interactive was an American technology company headquartered in San Jose, California, founded in 1994, that specialized in the manufacturing of 3D graphics processing units, and later, video cards. It was a pioneer in the field from the l ...
video cards, as a
Linux kernel
The Linux kernel is a free and open-source, monolithic, modular, multitasking, Unix-like operating system kernel. It was originally authored in 1991 by Linus Torvalds for his i386-based PC, and it was soon adopted as the kernel for the GNU ope ...
patch
Patch or Patches may refer to:
Arts, entertainment and media
* Patch Johnson, a fictional character from ''Days of Our Lives''
* Patch (''My Little Pony''), a toy
* "Patches" (Dickey Lee song), 1962
* "Patches" (Chairmen of the Board song) ...
included within the
Mesa
A mesa is an isolated, flat-topped elevation, ridge or hill, which is bounded from all sides by steep escarpments and stands distinctly above a surrounding plain. Mesas characteristically consist of flat-lying soft sedimentary rocks capped by ...
source code. Later that year, the DRM code was mainlined in Linux kernel 2.3.18 under the
/drivers/char/drm/
directory for
character device
In Unix-like operating systems, a device file or special file is an interface to a device driver that appears in a file system as if it were an ordinary file. There are also special files in DOS, OS/2, and Windows. These special files allow an ...
s. During the following years the number of supported video cards grew. When Linux 2.4.0 was released in January 2001 there was already support for Creative Labs GMX 2000, Intel i810, Matrox G200/G400 and ATI Rage 128, in addition to 3dfx Voodoo3 cards, and that list expanded during the 2.4.x series, with drivers for
ATI Radeon
Radeon () is a brand of computer products, including graphics processing units, random-access memory, RAM disk software, and solid-state drives, produced by Radeon Technologies Group, a division of AMD. The brand was launched in 2000 by ATI Tech ...
cards, some SiS video cards and Intel 830M and subsequent integrated GPUs.
The split of DRM into two components, DRM core and DRM driver, called ''DRM core/personality split'' was done during the second half of 2004, and merged into kernel version 2.6.11. This split allowed multiple DRM drivers for multiple devices to work simultaneously, opening the way to multi-GPU support.
The idea of putting all the video mode setting code in one place inside the kernel had been acknowledged for years, but the graphics card manufacturers had argued that the only way to do the mode-setting was to use the routines provided by themselves and contained in the
Video BIOS
Video BIOS is the BIOS of a graphics card in a (usually IBM PC-derived) computer. It initializes the graphics card at the computer's boot time. It also implements INT 10h interrupt and VESA BIOS Extensions (VBE) for basic text and videomode output ...
of each graphics card. Such code had to be executed using x86
real mode
Real mode, also called real address mode, is an operating mode of all x86-compatible CPUs. The mode gets its name from the fact that addresses in real mode always correspond to real locations in memory. Real mode is characterized by a 20-bit seg ...
, which prevented it from being invoked by a kernel running in
protected mode
In computing, protected mode, also called protected virtual address mode, is an operational mode of x86-compatible central processing units (CPUs). It allows system software to use features such as virtual memory, paging and safe multi-tasking d ...
. The situation changed when Luc Verhaegen and other developers found a way to do the mode-setting natively instead of BIOS-based, showing that it was possible to do it using normal kernel code and laying the groundwork for what would become ''Kernel Mode Setting''. In May 2007 Jesse Barnes (
Intel
Intel Corporation is an American multinational corporation and technology company headquartered in Santa Clara, California. It is the world's largest semiconductor chip manufacturer by revenue, and is one of the developers of the x86 seri ...
) published the first proposal for a ''drm-modesetting'' API and a working native implementation of mode-setting for Intel GPUs within the i915 DRM driver. In December 2007 Jerome Glisse started to add the native mode-setting code for ATI cards to the radeon DRM driver. Work on both the API and drivers continued during 2008, but got delayed by the necessity of a memory manager also in kernel space to handle the framebuffers.
In October 2008 the Linux kernel 2.6.27 brought a major
source code
In computing, source code, or simply code, is any collection of code, with or without comments, written using a human-readable programming language, usually as plain text. The source code of a program is specially designed to facilitate the wo ...
reorganization, prior to some significant upcoming changes. The DRM source code tree was moved to its own source directory
/drivers/gpu/drm/
and the different drivers were moved into their own subdirectories. Headers were also moved into a new
/include/drm
directory.
The increasing complexity of video memory management led to several approaches to solving this issue. The first attempt was the ''Translation Table Maps'' (TTM) memory manager, developed by Thomas Hellstrom (
Tungsten Graphics) in collaboration with Emma Anholt (Intel) and Dave Airlie (
Red Hat
Red Hat, Inc. is an American software company that provides open source software products to enterprises. Founded in 1993, Red Hat has its corporate headquarters in Raleigh, North Carolina, with other offices worldwide.
Red Hat has become ass ...
). TTM was proposed for inclusion into mainline kernel 2.6.25 in November 2007, and again in May 2008, but was ditched in favor of a new approach called ''Graphics Execution Manager'' (GEM). GEM was first developed by Keith Packard and Emma Anholt from Intel as simpler solution for memory management for their i915 driver. GEM was well received and merged into the Linux kernel version 2.6.28 released in December 2008. Meanwhile, TTM had to wait until September 2009 to be finally merged into Linux 2.6.31 as a requirement of the new Radeon KMS DRM driver.
With memory management in place to handle buffer objects, DRM developers could finally add to the kernel the already finished API and code to do
mode setting
Mode setting is a software operation that activates a display mode (screen resolution, color depth, and refresh rate) for a computer's display controller by using VESA BIOS Extensions or UEFI Graphics extensions (on more modern computers).
The d ...
. This expanded API is what is called ''Kernel Mode-setting'' (KMS) and the drivers which implement it are often referred to as ''KMS drivers''. In March 2009, KMS was merged into the Linux kernel version 2.6.29, along with KMS support for the i915 driver. The KMS API have been exposed to user space programs since libdrm 2.4.3. The userspace
X.Org DDX driver for Intel graphics cards was also the first to use the new GEM and KMS APIs. KMS support for the radeon DRM driver was added to Linux 2.6.31 release of September 2009. The new radeon KMS driver used the TTM memory manager but exposed GEM-compatible interfaces and ioctls instead of TTM ones.
Since 2006 the
nouveau project had been developing a
free software
Free software or libre software is computer software distributed under terms that allow users to run the software for any purpose as well as to study, change, and distribute it and any adapted versions. Free software is a matter of liberty, no ...
DRM driver for
NVIDIA
Nvidia CorporationOfficially written as NVIDIA and stylized in its logo as VIDIA with the lowercase "n" the same height as the uppercase "VIDIA"; formerly stylized as VIDIA with a large italicized lowercase "n" on products from the mid 1990s to ...
GPUs outside of the official Linux kernel. In 2010 the nouveau source code was merged into Linux 2.6.33 as an experimental driver. At the time of merging, the driver had been already converted to KMS, and behind the GEM API it used TTM as its memory manager.
The new KMS API—including the GEM API—was a big milestone in the development of DRM, but it didn't stop the API for being enhanced in the following years. KMS gained support for
page flips in conjunction with asynchronous
VBLANK notifications in Linux 2.6.33—only for the i915 driver, radeon and nouveau added it later during Linux 2.6.38 release. The new page flip interface was added to libdrm 2.4.17. In early 2011, during the Linux 2.6.39 release cycle, the so-called ''dumb buffers''—a hardware-independent non-accelerated way to handle simple buffers suitable for use as framebuffers—were added to the KMS API. The goal was to reduce the complexity of applications such as
Plymouth
Plymouth () is a port city and unitary authority in South West England. It is located on the south coast of Devon, approximately south-west of Exeter and south-west of London. It is bordered by Cornwall to the west and south-west.
Plymouth ...
that don't need to use special accelerated operations provided by driver-specific ioctls. The feature was exposed by libdrm from version 2.4.25 onwards. Later that year it also gained a new main type of objects, called ''planes''. Planes were developed to represent hardware overlays supported by the scanout engine. Plane support was merged into Linux 3.3. and libdrm 2.4.30. Another concept added to the API—during Linux 3.5 and libdrm 2.4.36 releases—were ''generic object properties'', a method to add generic values to any KMS object. Properties are specially useful to set special behaviour or features to objects such as CRTCs and planes.
An early proof of concept to provide GPU offloading between DRM drivers was developed by Dave Airlie in 2010. Since Airlie was trying to mimic the
NVIDIA Optimus
Nvidia Optimus is a computer GPU switching technology created by Nvidia which, depending on the resource load generated by client software applications, will seamlessly switch between two graphics adapters within a computer system in order to prov ...
technology, he decided to name it "PRIME". Airlie resumed his work on PRIME in late 2011, but based on the new
DMA-BUF buffer sharing mechanism introduced by Linux kernel 3.3. The basic DMA-BUF PRIME infrastructure was finished in March 2012 and merged into the Linux 3.4 release, as well as into libdrm 2.4.34. Later during the Linux 3.5 release, several DRM drivers implemented PRIME support, including i915 for Intel cards, radeon for AMD cards and nouveau for NVIDIA cards.
In recent years, the DRM API has incrementally expanded with new and improved features. In 2013, as part of
GSoC, David Herrmann developed the multiple ''render nodes'' feature. His code was added to the Linux kernel version 3.12 as an experimental feature supported by i915, radeon and nouveau drivers, and enabled by default since Linux 3.17. In 2014 Matt Roper (Intel) developed the ''universal planes'' (or ''unified planes'') concept by which framebuffers (''primary planes''), overlays (''secondary planes'') and cursors (''cursor planes'') are all treated as a single type of object with an unified API. Universal planes support provides a more consistent DRM API with fewer, more generic
ioctl
In computing, ioctl (an abbreviation of input/output control) is a system call for device-specific input/output operations and other operations which cannot be expressed by regular system calls. It takes a parameter specifying a request code; th ...
s. In order to maintain the API
backwards compatible, the feature is exposed by DRM core as an additional capability that a DRM driver can provide. Universal plane support debuted in Linux 3.15 and libdrm 2.4.55. Several drivers, such as the Intel i915, have already implemented it.
The most recent DRM API enhancement is the ''atomic mode-setting'' API, which brings
atomicity to the mode-setting and page flipping operations on a DRM device. The idea of an atomic API for mode-setting was first proposed in early 2012. Ville Syrjälä (Intel) took over the task of designing and implementing such atomic API. Based on his work, Rob Clark (
Texas Instruments
Texas Instruments Incorporated (TI) is an American technology company headquartered in Dallas, Texas, that designs and manufactures semiconductors and various integrated circuits, which it sells to electronics designers and manufacturers globall ...
) took a similar approach aiming to implement atomic page flips. Later in 2013 both proposed features were reunited in a single one using a single ioctl for both tasks. Since it was a requirement, the feature had to wait for the support of universal planes to be merged in mid-2014. During the second half of 2014 the atomic code was greatly enhanced by Daniel Vetter (Intel) and other DRM developers in order to facilitate the transition for the existing KMS drivers to the new atomic framework. All of this work was finally merged into Linux 3.19 and Linux 4.0 releases, and enabled by default since Linux 4.2. libdrm exposed the new atomic API since version 2.4.62. Multiple drivers have already been converted to the new atomic API. By 2018 ten new DRM drivers based on this new atomic model had been added to the Linux kernel.
Adoption
The Direct Rendering Manager kernel subsystem was initially developed to be used with the new
Direct Rendering Infrastructure
The Direct Rendering Infrastructure (DRI) is the framework comprising the modern Linux graphics stack which allows unprivileged user-space programs to issue commands to graphics hardware without conflicting with other programs. The main use ...
of the
XFree86
XFree86 is an implementation of the X Window System. It was originally written for Unix-like operating systems on IBM PC compatibles and was available for many other operating systems and platforms. It is free and open source software under the X ...
4.0 display server, later inherited by its successor, the
X.Org Server
X.Org Server is the free and open-source implementation of the X Window System display server stewarded by the X.Org Foundation.
Implementations of the client-side X Window System protocol exist in the form of ''X11 libraries'', which serve a ...
. Therefore, the main users of DRM were DRI clients that link to the hardware-accelerated
OpenGL
OpenGL (Open Graphics Library) is a cross-language, cross-platform application programming interface (API) for rendering 2D and 3D vector graphics. The API is typically used to interact with a graphics processing unit (GPU), to achieve hardwa ...
implementation that lives in the
Mesa 3D
Mesa, also called Mesa3D and The Mesa 3D Graphics Library, is an open source implementation of OpenGL, Vulkan, and other graphics API specifications. Mesa translates these specifications to vendor-specific graphics hardware drivers.
Its most ...
library, as well as the X Server itself. Nowadays DRM is also used by several
Wayland compositors
Wayland may refer to:
Computers
* Wayland (display server protocol), a graphical display system for Unix-like computers
Fiction
* Jace Wayland, a character in the ''Mortal Instruments'' book series
* Wayland (''Star Wars''), a planet in the ''S ...
, including
Weston
Weston may refer to:
Places Australia
* Weston, Australian Capital Territory, a suburb of Canberra
* Weston, New South Wales
* Weston Creek, a residential district of Canberra
* Weston Park, Canberra, a park
Canada
* Weston, Nova Scotia
* ...
reference compositor.
kmscon
Kmscon is a virtual console that runs in userspace and intends to replace the Linux console, a terminal built into the Linux kernel. Kmscon uses the KMS driver for its output, it is Multiseat configuration, multiseat-capable, and supports intern ...
is a virtual console implementation that runs in user space using DRM KMS facilities.
In 2015, version 358.09 (beta) of the proprietary
Nvidia GeForce driver
GeForce is a brand of graphics processing units (GPUs) designed by Nvidia. As of the GeForce 40 series, there have been eighteen iterations of the design. The first GeForce products were discrete GPUs designed for add-on graphics boards, inten ...
received support for the DRM mode-setting interface implemented as a new kernel blob called
nvidia-modeset.ko
. This new driver component works in conjunction with the
nvidia.ko
kernel module to program the display engine (i.e. display controller) of the GPU.
See also
*
Direct Rendering Infrastructure
The Direct Rendering Infrastructure (DRI) is the framework comprising the modern Linux graphics stack which allows unprivileged user-space programs to issue commands to graphics hardware without conflicting with other programs. The main use ...
*
Free and open-source graphics device driver
A free and open-source graphics device driver is a software stack which controls computer-graphics hardware and supports graphics-rendering application programming interfaces (APIs) and is released under a free and open-source software license ...
*
Linux framebuffer
The Linux framebuffer (fbdev) is a linux subsystem used to show graphics on a computer monitor, typically on the system console.
It was designed as a hardware-independent API to give user space software access to the framebuffer (the part of ...
References
External links
DRM home page''Linux GPU Driver Developer's Guide''(formerly ''Linux DRM Developer's Guide'')
*
{{Freedesktop.org
Direct Rendering Infrastructure
Interfaces of the Linux kernel
Linux kernel features