Userspace programs use libdrm to talk to the DRM subsystem.
libdrm provides a set of methods that use ioctl syscall to talk to DRM.
$ ls /dev/dri/
prints cardDRM = direct rendering manager. DRM manages multiple programs trying to access GPU hardware (before it was possible for one process to hijack it completely, DRM subsystem was introduced to resolve this). DRM core API consists of a generic API (which includes GEM and KMS) and a specific driver API. Vendors implement a DRM driver that registers to the DRM core, implements core parts of the DRM API and can also provide its own functions. Example driver. DRM core has two memory managers: TTM (translation table manager) and GEM (graphics execution manager). TTM can support both UMA and NUMA architectures but is more complex than GEM. Provides control over VRAM that a CPU won't be able to read/write. Vendor driver implementations will usually create a struct that wraps/implements TTM (example with Radeon). struct drm_global_reference contains a field called enum ttm_global_types global_type; .
Important parts of TTM are
buffer objects and graphics address remapping table (GART) which gives a GPU driver DMA to host system memory for texture, polygon meshes.
(note: GART system was later used for I/O virtualization with disk controllers, neat!)
scheduling and fences (for a GPU to tell userspace that some resource is no longer used).
struct drm_sched_[rq|fence|entity|job];
struct drm_gpu_scheduler;
Any linux device driver can implement the DMA buffer sharing API to share DMA buffers across devices. This was used to implement PRIME, a system for sharing framebuffers between DRM drivers of integrated and discrete graphics cards, thus allowing for GPU hotswapping. (two new ioctls: convert GEM handle to DMA-BUF handle, convert DMA-BUF handle to GEM handle). Further reading GEM is the graphics execution manager and was built in response to TTM complexity. It abstracts away NUMA complexity.
struct drm_gem_[create|open|close|flink] p;
int ret = ioctl (fd, DRM_IOCTL_GEM_[CREATE|OPEN|CLOSE|FLINK], &p);
NOTE: some TTM drivers will still implement GEM API e.g. Radeon.
KMS is the kernel mode-switch. It manages the display controller and the last step of the rendering pipeline. KMS sits on the die of the GPU and communicates with the monitor. If you want to change the resolution or refresh rate, these are the bits you change.
|