Linux DRM(二) --Xorg/DRM

article/2025/10/25 3:56:40
  • 了解xorg

1.前言

  GUI作为人机交互的一种方式,通过其承载的大量信息提高了信息交流的效率。这里我们不介绍鼠标、键盘等输入设备,只介绍输出显示这一子模块。生活中大家最常见的图形化界面估计就是图像化界面的桌面环境,即窗口系统。

  窗口系统一般都具备以下基本功能:

  • 通过WIMO(Window-视窗、Icon-图标、Menu-选单、Pointer-指标)4个基本元素来实现人机交互;
  • 上述的4个基本元素都能通过第三方的程序来扩展(也就是安装新程序);

  在实现方式上,大部分Linux下的窗口系统都是通过X来响应不同的交互请求及输出到显示器上。因此,整个应用层的GUI结构如下:
在这里插入图片描述
  因此,在应用层面上,GUI系统的核心部分是X,X的总体功能一句话描述如下:通过指定的协议接受本地或远程的鼠标、键盘需求,并切输出相应的窗口画面到显示设备上。细分来讲,X主要由以下4个组件构成:

  • X server:负责软硬件的管理,将输入的软硬件事件通过一定协议转发给X client,将输出的图形绘制在屏幕上。包括键盘、鼠标、手写板、显示器 (monitor) 、屏幕分辨率与色彩深度、显卡 (包含驱动程序) 与显示的字体等等,都是 X Server 管理的。
  • X client:每个需要涉及到GUI的App,可以实例化为一个X client,X client主要是响应X server分发下来的事件,通过处理后,将待绘制的图像回传给X Server;
  • X window manager:X window manager作为一个特殊的X client,主要负责为X server管理多个X client(一个具体的例子就是对虚拟桌面的管理),起着视窗管理员的角色。常见的X window manager如下:
    • GNOME (GNU Network Object Model Environment);
    • KDE (K Desktop Enviroment)
    • TWM (Tab Window Manager)
    • XFCE (XForms Common Environment)
    • Display manager: 提供登陆许可环境以获得X Window的控制;

1.1.The X Window configuration file

  In the early days of X, configuring a display meant having extensive knowledge of the display’s capabilities and the ability to express information about not only resolution, but also horizontal and vertical sync values, color depth, and so on. Since the advent of the Video Electronics Standards Association (VESA) and the Display Data Channel (DDC) protocols that allow a display to communicate these capabilities to a graphics card and thus to a computer, configuration has become much more automatic. This is fortunate as we now expect to be able to take our notebook anywhere and just plug in an available external monitor or projector.

  Configuring your mouse, trackball, or keyboard has also become more automatic. Generally, you just plug in the device, often through a USB connection and it works.

  However, as with most things in Linux, there is an underlying configuration mechanism that you can use. In fact, the Xorg implementation of X obtains configuration information from several sources. The main configuration file is xorg.conf, along with files included from the xorg.conf.d directory. These are usually located in /etc/X11. Additional configuration can come from command-line options, environment variables, auto-detection, and fallback defaults.

  Xorg uses a configuration file called xorg.conf and files ending in the suffix .conf from the directory xorg.conf.d for its initial setup. The xorg.conf configuration file is searched for in the following places when the server is started as a normal user:

/etc/X11/<cmdline>
/usr/etc/X11/<cmdline>
/etc/X11/$XORGCONFIG
/usr/etc/X11/$XORGCONFIG
/etc/X11/xorg.conf
/etc/xorg.conf
/usr/etc/X11/xorg.conf.<hostname>
/usr/etc/X11/xorg.conf
/usr/lib/X11/xorg.conf.<hostname>
/usr/lib/X11/xorg.conf

  The xorg.conf configuration file and the files in the xorg.conf.d directory are organized into sections which may be specified in any order. The general section format is shown in Listing 1.

Listing 1. Section layout in xorg.confSection  "SectionName"SectionEntry...EndSection

  You can include the following sections:

Files – File pathnames
ServerFlags – Server flags
Module – Dynamic module loading
Extensions – Extension enabling
InputDevice – Input device description
InputClass – Input class description
OutputClass – Output class description
Device – Graphics device description
VideoAdaptor – Xv video adaptor description
Monitor – Monitor description
Modes – Video modes descriptions
Screen – Screen configuration
ServerLayout – Overall layout
DRI – DRI-specific configuration
Vendor – Vendor-specific configuration

Note:
  Read the man or info pages for xorg.conf to find out more about the various sections of the files. Man pages for Xserver and Xorg provide additional information. (man xorg.conf)

  The X server supports two configuration directories.

  • The /usr/share/X11/xorg.conf.d/ provides separate configuration files from vendors or third-party packages; changes to files in this directory may be overwritten by settings specified in the /etc/X11/xorg.conf file.
  • The /etc/X11/xorg.conf.d/ directory stores user-specific configuration.

Note:
  大部分Xorg的配置文件存储在 /etc/X11/xorg.conf.d/。 每个文件的名字都是独一无二的并且以.conf为扩展名。 Xorg配置目录中的文件名会按字母顺序读取。例如,10-evdev.conf会在20-synaptics.conf之前被读取; a-evdev.conf 会在b-synaptics.conf之前被读取…… 此目录中的文件不需要编号,但是如果编号,那么会帮助他们有组织化。组织化有助于调试错误的配置文件。
uos@uos-PC:/usr/share/X11/xorg.conf.d$ ls
10-amdgpu.conf 10-quirks.conf 10-radeon.conf 10-zxgpu.conf 40-libinput.conf 70-wacom.conf

  The directory /usr/lib/xorg/modules/ contains X server modules that can be loaded dynamically at runtime. By default, only some modules in /usr/lib/xorg/modules/ are automatically loaded by the X server.

uos@uos-PC:/usr/lib/xorg/modules/drivers$ ls -l
总用量 3380
-rw-r--r-- 1 root root  160896 112 17:09 amdgpu_drv.so
-rw-r--r-- 1 root root   14504 112 17:09 ati_drv.so
-rw-r--r-- 1 root root   27648 112 17:09 fbdev_drv.so
-rw-r--r-- 1 root root 1702440 112 17:09 intel_drv.so
-rw-r--r-- 1 root root  111168 112 17:09 modesetting_drv.so
-rw-r--r-- 1 root root  225416 112 17:09 nouveau_drv.so
-rw-r--r-- 1 root root  514368 112 17:09 radeon_drv.so
-rw-r--r-- 1 root root   31784 112 17:09 vesa_drv.so
-rw-r--r-- 1 root root  170296 112 17:09 vmware_drv.so
-rw-r--r-- 1 root root  481616 112 17:09 zx_drv.so

1.2.Section

  The xorg.conf and xorg.conf.d files are composed of a number of sections which may be present in any order, or omitted to use default configuration values. Each section has the form:

Section "SectionName"
SectionEntry
...
EndSection

The section names are:

Files File pathnames
ServerFlags Server flags
Module Dynamic module loading
Extensions Extension enabling
InputDevice Input device description
InputClass Input class description
Device Graphics device description
VideoAdaptor Xv video adaptor description
Monitor Monitor description
Modes Video modes descriptions
Screen Screen configuration
ServerLayout Overall layout
DRI DRI−specific configuration
Vendor Vendor−specific configuration

1.2.1.DEVICE SECTION

  The config file may have multiple Device sections. There must be at least one, for the video card being used.

  Device sections have the following format:

Section "Device"
Identifier "name"
Driver "driver"
entries
...
EndSection

  The Identifier and Driver entries are required in all Device sections. All other entries are optional.

  • The Identifier entry specifies the unique name for this graphics device.

  • The Driver entry specifies the name of the driver to use for this graphics device.

    When using the loadable server, the driver module “driver” will be loaded for each active Device section. A Device section is considered active if it is referenced by an active Screen section.

1.2.2.OUTPUTCLASS SECTION

  The config file may have multiple OutputClass sections. These sections are optional and are used to provide configuration for a class of output devices as they are automatically added. An output device can match more than one OutputClass section. Each class can override settings from a previous class, so it is best to arrange the sections with the most generic matches first.

  OutputClass sections have the following format:

Section "OutputClass"Identifier  "name"entries...
EndSection

  The Identifier entry is required in all OutputClass sections. All other entries are optional.The Identifier entry specifies the unique name for this output class. The Driver entry specifies the name of the driver to use for this output device. After all classes have been examined, the “outputdriver” module from the first Driver entry will be enabled when using the loadable server.

Note: What’s the difference between xorg’s OutputClass and Device sections?

  The main difference is that Device sections are used for static configuration (e.g. “here’s the configuration for a specific piece of hardware”) while the *Class sections are used for dynamic configuration (e.g. "here’s the configuration for any device that has these properties).

https://www.reddit.com/r/linuxquestions/comments/iaz692/whats_the_difference_between_xorgs_outputclass/

1.3.生成xorg.conf

  • 进入 multi-user.target
[root@localhost ~]# systemctl get-default
graphical.target//若需要設定預設的操作界面,例如將原本的圖形界面改為文字界面的操作方式時,可以使用如下的方式來處理:
[root@localhost ~]# systemctl set-default multi-user.target
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to/usr/lib/systemd/system/multi-user.target.
  • 然后执行: Xorg -configure,可以生成 xorg.conf 模板:
    执行后会在 /root/ 生成 xorg.conf.new 文件,然后你可以将它复制到 /etc/X11/xorg.conf。

Note:
$ systemctl get-default # 查看启动时的默认 Target
$ sudo systemctl set-default multi-user.target # 设置启动时的默认 Target
$ sudo systemctl isolate multi-user.target # 切换到后面接的模式

2.Linux GUI子系统构成及工作流程

  从应用层深入到内核中去。暂不考虑在linux下的GUI,我们知道,单纯的显示图片的话,整个数据流的走向是这样的:
在这里插入图片描述

  即按照一定时序时序,将图像信息从内存中输出到显示接口上。若在生成Frame buffer里面的图像数据时不仅通过软件memory处理,还用到了硬件加速的话,数据流则变为如下:

在这里插入图片描述
  其中accelerate logic就是显卡部分(若是SOC的片内GPU模块,则是通过片内高速总线进行数据交互的,若若是独立显卡,一般是通过pci-e高速串行接口进行数据传输的)。把这个数据流走向放入Linux中,数据流和控制流都需要和用户层进行交互,也就是说,Linux下,必须得有相关的软件驱动给用户层提供相应的API。这也就是DRM(Direct Rendering Manager)和KMS(Kernel Mode Setting)的角色。

  Linux提供由DRM+KMS构成的DRI(Direct Rendering Infrastructure)中:

  • DRM主要负责负责数据流,即通过软件或硬件,生成目标图像,存储在framebuffer中;
  • KMS主要负责控制流,即针对外置LCD以及指定的显示模式设置,将生成好了的frame数据信息送到响应display port上(VGA、HDMI等);

  Kernel将这两大快的基本API抽出来封装成libdrm供X使用,整个应用层+kernel相关的GUI结构如下图:

在这里插入图片描述

3.Direct Rendering 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 such as configuring the mode setting of the display. DRM was first developed as the kernel-space component of the X Server Direct Rendering Infrastructure,[1] 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 3D rendering and video decoding, as well as GPGPU computing.1.DRM - Direct Rendering Manager

  DRM是一个内核级的设备驱动,既可以编译到内核中也可以作为标准模块进行加载。DRM最初是在FreeBSD中出现的,后来被移植到Linux系统中,并成为Linux系统的标准部分。

  DRM是Linux目前主流的图形显示框架,相比FB架构,DRM更能适应当前日益更新的显示硬件。比如FB原生不支持多层合成,不支持VSYNC,不支持DMA-BUF,不支持异步更新,不支持fence机制等等,而这些功能DRM原生都支持。同时DRM可以统一管理GPU和Display驱动,使得软件架构更为统一,方便管理和维护。

  DRM从模块上划分,可以简单分为3部分:libdrm、KMS、GEM。
在这里插入图片描述

  • libdrm
    对底层接口进行封装,向上层提供通用的API接口,主要是对各种IOCTL接口进行封装。

  • KMS
    Kernel Mode Setting,所谓Mode setting,其实说白了就两件事:更新画面和设置显示参数。
    更新画面:显示buffer的切换,多图层的合成方式,以及每个图层的显示位置。
    设置显示参数:包括分辨率、刷新率、电源状态(休眠唤醒)等。

  • GEM
    Graphic Execution Manager,主要负责显示buffer的分配和释放,也是GPU唯一用到DRM的地方

3.1.基本元素

  DRM框架涉及到的元素很多,大致如下:

  • KMS:CRTC,ENCODER,CONNECTOR,PLANE,FB,VBLANK,property
  • GEM:DUMB、PRIME、fence
    在这里插入图片描述
    在这里插入图片描述

3.2.接口介绍

  connector–>encoder–>crtc–>framebuffer的顺序倒过来介绍:

3.2.1.Connector

  Connector是和显示器连接的物理接口,常见的有VGA/HDMI/DVI/DP等。以HDMI为例,HDMI的接口信号主要由以下几组信号组成:

  • 1组TMDS clock:差分时钟用于同步信号驱动;
  • 3组TMDS data:查分数据传输视频信号;
  • 1组I2C:用于EDID的获取;
  • 1组音频总线;

注:EDID全称是Extended Display Identification Data(扩展显示标识数据),目的是让视频信号输出设备输出前获取到存储在显示器内部的相关参数,如支持的分辨率、帧率、图像格式:RGB等,因此,整个输出的控制参数是由以下几个部分综合决定的:
1.通过connector读出的显示器支持的参数;
2.内核静态配置或devicetree传入的参数;
3.用户空间输入的参数

  HDMI类型的connector的任务就是输出显示器解码芯片所需的信号时序(主要是TMDS clock以及TMDS data)。

3.2.2.Encoder

  Encoder就是将一定格式的图像信号(如RGB、YUV等)编码成connector需要输出的信号。以HDMI为例,帧/行同步/显示内容都是通过TMDS data的串行总线输出的,那么并行的时序按照HDMI的标准编码为串行顺序则是Encoder的任务。

3.2.3.CRTC

  CRTC的任务是从Framebuffer中读出待显示的图像,并按照相应的格式输出给Encoder。

3.2.4.Planes

  Plane其实就是图层,实际输出的图像往往由多个图层叠加而成,比如主图层,显示光标的图层,其中有些图层由硬件加速模块生成,本例中不涉及,因此所有plane的相关操作都由软件实现,不涉及到任何硬件结构。

3.2.5.Framebuffer

  Framebuffer对应着存储空间中的图像数据,此处对应硬件为DDR。

在这里插入图片描述

refer to

  • https://www.x.org/wiki/
  • https://wiki.gentoo.org/wiki/Xorg/Guide/zh-cn
  • https://developer.ibm.com/tutorials/l-lpic1-106-1/
  • https://zhuanlan.zhihu.com/p/59784377
  • https://zhuanlan.zhihu.com/p/60504398
  • https://en.wikipedia.org/wiki/Direct_Rendering_Manager
  • https://dri.freedesktop.org/docs/drm/gpu/index.html
  • https://www.jianshu.com/p/50405e326127
  • https://blog.csdn.net/hexiaolong2009/article/details/83720940
  • https://docs.freebsd.org/en_US.ISO8859-1/books/handbook/x-config.html
  • https://www.x.org/releases/current/doc/man/man5/xorg.conf.5.xhtml
  • https://web.mit.edu/rhel-doc/5/RHEL-5-manual/Deployment_Guide-en-US/s1-x-server-configuration.html

http://chatgpt.dhexx.cn/article/wmU659Zp.shtml

相关文章

Linux DRM 理解

本文从如下几个部分介绍 1. DRM 概念介绍2. 对比HW结构分析3. code分析 1. DRM 概念介绍 DRM 是Direct Render Manager的缩写&#xff1a; Linux 显示子系统结构框架 向上提供标准API给到应用使用管理GPU和Display模块 相较于原来的framebuffer结构&#xff0c;DRM将更多的硬…

直接渲染管理器(Direct Rendering Manager, DRM)

这是一篇来至于wiki的译文&#xff0c;希望对学习DRM的同学有帮助。 目录 概述 软件架构 API DRM-Master and DRM-Auth 图形执行管理器&#xff08;Graphics Execution Manager&#xff09; Translation Table Maps DMA Buffer共享和PRIME KMS&#xff08;Kernel Mode…

java drm_DRM系统工作原理

一、系统工作原理DRM技术是一项加强对音频、视频数字化产品内容版权保护的技术,其基本的工作原理是将音频、视频等文件进行加密编码处理,再建立一个证书授权服务中心;当用户使用这些加密文件时,应用软件会根据其包含在头文件中的有关属性自动链接到相应的站点(证书授权服务…

drm oracle,近距离接触RAC DRM

drm 是Oracle rac中独有的动态资源管理操作&#xff0c; 我们听了很多关于DRM的理论&#xff0c; 但是你是否亲眼见证过DRM, 今天我们就来看一下&#xff1a; SQL> select * from v$version; BANNER ---------------------------------------------------------------------…

菜鸟修炼笔记-音视频开发基础知识-drm简介

音视频开发基础知识-drm简介 前言一。DRM的基础概念1. DRM是什么&#xff1f;2. DRM的组成2.1 libdrm2.2 GEM2.3 KMS 二。KMS各个元素详解1. plane1.1 定义&#xff1a;1.2 类型1.3 功能1.4 使用&#xff1a;1.5 注意&#xff1a; 2. property2.1 定义和作用&#xff1a;2.2 常…

CSS字体的font-family属性和@font-face使用方法

CSS字体的font-family属性&#xff1a; font-family属性一共有5个字体系列&#xff0c;分别是&#xff1a; sans-serif&#xff1a; 包括没有衬线的字体&#xff0c;与serif相比&#xff0c;通常认为sans-serif在计算机屏幕上更容易识别。 serif&#xff1a; 包括有衬线的字…

前端漂亮的字体 font-family

今天在看UI图的时候看到这种字体&#xff0c;给大家分享分享&#xff0c;直接上图 图一 利用字体系列font-family div{font-size: .7rem;color: #ffeb7b;/* 黄色 */font-family: electronicFont; /* 这是重点&#xff01;&#xff01;&#xff01; */ }图二 利用文字阴影text-…

【CSS】font-family的相关字体设置

大家都知道&#xff0c;在不同操作系统、不同游览器里面默认显示的字体是不一样的&#xff0c;并且相同字体在不同操作系统里面渲染的效果也不尽相同&#xff0c;那么如何设置字体显示效果会比较好呢&#xff1f;下面我们逐步的分析一下&#xff1a; 一、字体基础知识 css 中…

Web 字体 font-family 浅谈

前言 最近研究各大网站的font-family字体设置&#xff0c;发现每个网站的默认值都不相同&#xff0c;甚至一些大网站也犯了很明显的错误&#xff0c;说明字体还是有很大学问的&#xff0c;值的我们好好研究。 不同的操作系统、不同浏览器下内嵌的默认字体是不同的&#xff0c;错…

font-faimly字体大全

清 font-size:100px 为例 font-family:“Arial”,“Microsoft YaHei”,“黑体”,“宋体”,sans-serif; font-family:Tahoma,Helvetica,Arial,‘宋体’,sans-serif; font-family: ‘Microsoft YaHei’,arial,tahoma,\5b8b\4f53,sans-serif; font-family:Tahoma,Helvetica,A…

html字体设置font-family

<div ><p style"font-family:STHeiti">1.华文黑体:STHeiti</p><p style"font-family:STKaiti">2.华文楷体&#xff1a;STKaiti</p><p style"font-family:STSong">3.华文宋体&#xff1a;STSong</p>&l…

html常用font-family设置字体样式

<table border"1" cellpadding"0" cellspacing"0" ><tr><td><h3 style"font-family: 黑体;">黑体&#xff1a;SimHei</h3></td><td><h3 style"font-family: 华文黑体;">华…

font-family、font-style、font-weight、font-variant的区别「In CSS」

学习 CSS&#xff0c;看文档的时候总是对 font 的属性搞不清楚或者总是搞混。 这里总结一下这四个经常搞混的&#xff08;特别是前面两个&#xff09;。 font-family 这个属性指的是字体&#xff0c;比如说汉字中常说的行书与草书。 这个属性的值可以有多个&#xff0c;因为…

FontFamily 看这里就够了

TextView中字体设置 typeface 一、配置设置 代码方式设置 fontFamily 文字如何实现加粗、斜体&#xff1f; 三者之间的关系 自定义字体 参考&#xff1a; TextView中字体设置 textView中有三个属性可以设置字体 textStyle&#xff1a;设置样式fontFamily&#xff1…

WPF—WrapPanel布局

WrapPanel布局面板将各个控件从左至右按照行或列的顺序罗列&#xff0c;当长度或高度不够是就会自动调整进行换行&#xff0c;后续排序按照从上至下或从右至左的顺序进行。 Orientation——根据内容自动换行。当 Horizontal选项看上去类似于Windows资源管理器的缩略图视图&…

WrapPanel

WrapPanel将子元素自左向右逐个地排列, 若一个水平行中放不下,就排在下一行。面板的方向可以是水平或垂直的 <Window x:Class"Panel布局.WrapPanelxaml"xmlns"http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x"http://schemas.…

WPF中5种内建面板Canvas、StackPanel、WrapPanel、DockPanel、Grid分析

https://blog.csdn.net/weixin_43437202/article/details/88292620 Canvas、StackPanel、WrapPanel、DockPanel和Grid是WPF中主要的5种内建面板&#xff0c;这些面板类都位于System.Windows.Controls命名空间下。 主要布局特点简述 Grid 按行列排列内容&#xff0c;如果没有特…

WPF 改进 WrapPanel 右侧填充

WPF 改进 WrapPanel 右侧填充 本文经原作者授权以原创方式二次分享&#xff0c;欢迎转载、分享。 WPF 改进 WrapPanel 右边缘填充 作者&#xff1a;陈-林-赵-魏|驚鏵 原文链接[1]&#xff1a;https://www.cnblogs.com/wandia/p/17084881.html 目的&#xff1a;改进下WrapPanel,…

WrapPanel 实现虚拟化

WrapPanel 实现虚拟化 控件名&#xff1a;VirtualizingWrapPanel 作者&#xff1a;WPFDevelopersOrg 原文链接&#xff1a; https://github.com/WPFDevelopersOrg/WPFDevelopers 框架使用大于等于.NET40&#xff1b;Visual Studio 2022;项目使用 MIT 开源许可协议&#xff1…

对wpf 的入门记录总结----面板控件Canvas、WrapPanel、StackPanel、DockPanel

面板是WPF裡其中一個很重要的控件。 面板扮演著裝載其他控件的容器的角色&#xff0c;同時也控制著頁面和視窗的佈局。 由於一個視窗只允許一個子控件&#xff0c;因此面板經常會被使用於分隔空間&#xff0c;這樣每個空間就會有一個控件或者面板。 wpf支持6种面板&#xff1…