整理一篇Linux drm显示系统的文章

系统 Linux
找了几篇和drm不错的文章分享给大家,Linux是一个模块化非常明显的系统,每个子系统又会有属于自己的一些特性,学习的时候,最好也是分类学习比较好。

[[402874]]

这篇文章主要是回答一位同学的提问,当然也是做一次总结,我相信关注我号的很多人也有做LCD相关的驱动或者系统开发,即使不是专门做LCD,但是在开发过程中也难免会遇到这样或者那样的问题。

所以找了几篇和drm不错的文章分享给大家,Linux是一个模块化非常明显的系统,每个子系统又会有属于自己的一些特性,学习的时候,最好也是分类学习比较好。

Linux 的 2 种显示方案

包括:

  •  FBDEV: Framebuffer Device
  •  DRM/KMS: Direct Rendering Manager / Kernel Mode Setting

它们有什么区别?

  •  FBDEV:
    •  传统的显示框架;
    •  简单,但是只能提供最基础的显示功能;
    •  无法满足当前上层应用和底层硬件的显示需求;
  •  DRM/KMS:
    •  目前主流的显示方案;
    •  为了适应当前日益更新的显示硬件;
    •  软件上能支持更多高级的控制和特性;

简单的说就是FBDEV已经不满足时代的发展需要,然后就出现了DRM这个东西,DRM,英文全称 Direct Rendering Manager, 即 直接渲染管理器。它是为了解决多个程序对 Video Card 资源的协同使用问题而产生的。它向用户空间提供了一组 API,用以访问操纵 GPU。

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

DRM可以直接访问DRM clients的硬件。DRM驱动用来处理DMA,内存管理,资源锁以及安全硬件访问。为了同时支持多个3D应用,3D图形卡硬件必须作为一个共享资源,因此需要锁来提供互斥访问。DMA传输和AGP接口用来发送图形操作的buffers到显卡硬件,因此要防止客户端越权访问显卡硬件。

Linux DRM层用来支持那些复杂的显卡设备,这些显卡设备通常都包含可编程的流水线,非常适合3D图像加速。内核中的DRM层,使得这些显卡驱动在进行内存管理,中断处理和DMA操作中变得更容易,并且可以为上层应用提供统一的接口。

FBDEV的测试程序 

  1. /*  
  2.  * Copyright (C) 2011 The Android Open Source Project  
  3.  *  
  4.  * Licensed under the Apache License, Version 2.0 (the "License");  
  5.  * you may not use this file except in compliance with the License.  
  6.  * You may obtain a copy of the License at  
  7.  *  
  8.  *      http://www.apache.org/licenses/LICENSE-2.0  
  9.  *  
  10.  * Unless required by applicable law or agreed to in writing, software  
  11.  * distributed under the License is distributed on an "AS IS" BASIS,  
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
  13.  * See the License for the specific language governing permissions and  
  14.  * limitations under the License.  
  15.  */  
  16. #include <stdint.h>  
  17. #include <sys/types.h>  
  18. #include <fcntl.h>  
  19. #include <sys/ioctl.h>  
  20. #include <linux/fb.h>  
  21. #include <errno.h>  
  22. #include <string.h>  
  23. #include <stdio.h>  
  24. #ifndef FBIO_WAITFORVSYNC  
  25. #define FBIO_WAITFORVSYNC   _IOW('F', 0x20, __u32)  
  26. #endif  
  27. int main(int argc, char** argv) {  
  28.     int fd = open("/dev/graphics/fb0", O_RDWR);  
  29.     if (fd >= 0) {  
  30.         do {  
  31.             uint32_t crt = 0 
  32.            int err = ioctl(fd, FBIO_WAITFORVSYNC, &crt);  
  33.            if (err < 0) {  
  34.                printf("FBIO_WAITFORVSYNC error: %s\n", strerror(errno));  
  35.                break;  
  36.            }  
  37.         } while(1);  
  38.         close(fd);  
  39.     }  
  40.     return 0;  

DRM应用测试程序 

  1. int main(int argc, char **argv)  
  2.  
  3.  int fd;  
  4.  drmModeConnector *conn;  
  5.  drmModeRes *res;  
  6.  uint32_t conn_id;  
  7.  uint32_t crtc_id;   
  8.     // 1. 打开设备  
  9.  fd = open("/dev/dri/card0", O_RDWR | O_CLOEXEC);  
  10.     // 2. 获得 crtc 和 connector 的 id  
  11.  res = drmModeGetResources(fd);  
  12.  crtc_id = res->crtcs[0];  
  13.  conn_id = res->connectors[0];  
  14.     // 3. 获得 connector  
  15.  conn = drmModeGetConnector(fd, conn_id);  
  16.  buf.width = conn->modes[0].hdisplay;  
  17.  buf.height = conn->modes[0].vdisplay;  
  18.     // 4. 创建 framebuffer  
  19.  modeset_create_fb(fd, &buf);  
  20.     // 5. Sets a CRTC configuration,这之后就会开始在 crtc0 + connector0 pipeline 上进行以 mode0 输出显示  
  21.  drmModeSetCrtc(fd, crtc_id, buf.fb_id, 0, 0, &conn_id, 1, &conn->modes[0]);  
  22.  getchar();  
  23.  // 6. cleanup  
  24.  ...  
  25.  return 0;  

DRM 相关的驱动很复杂,我并不敢班门弄斧,如果大家只是想了解个大概,我觉得上面的文章应该能够满足你们的需求,但是如果你们是专门做LCD的,可以找到一些更优秀的资源。 

 

责任编辑:庞桂玉 来源: 良许Linux
相关推荐

2019-11-25 09:46:32

Linux操作系统管理

2019-11-07 11:08:16

Linux操作系统目录

2020-10-09 08:15:11

JsBridge

2019-12-13 16:19:15

戴尔

2023-05-12 08:19:12

Netty程序框架

2022-02-21 09:44:45

Git开源分布式

2019-04-17 15:16:00

Sparkshuffle算法

2021-06-30 00:20:12

Hangfire.NET平台

2021-01-28 08:55:48

Elasticsear数据库数据存储

2021-04-09 08:40:51

网络保险网络安全网络风险

2017-09-05 08:52:37

Git程序员命令

2011-07-12 13:35:04

程序员

2019-12-06 09:16:23

Linux 开源操作系统

2022-08-03 08:17:00

Redis事务内存

2017-06-27 14:15:22

LinuxShellsed

2021-01-29 18:41:16

JavaScript函数语法

2021-07-01 10:01:16

JavaLinkedList集合

2020-11-10 10:48:10

JavaScript属性对象

2021-02-02 18:39:05

JavaScript

2020-10-22 08:25:22

JavaScript运作原理
点赞
收藏

51CTO技术栈公众号