本网站(662p.com)打包出售,且带程序代码数据,662p.com域名,程序内核采用TP框架开发,需要联系扣扣:2360248666 /wx:lianweikj
精品域名一口价出售:1y1m.com(350元) ,6b7b.com(400元) , 5k5j.com(380元) , yayj.com(1800元), jiongzhun.com(1000元) , niuzen.com(2800元) , zennei.com(5000元)
需要联系扣扣:2360248666 /wx:lianweikj
整理一篇Linux drm显示系统的文章
phpren · 193浏览 · 发布于2021-06-01 +关注

这篇文章主要是回答一位同学的提问,当然也是做一次总结,我相信关注我号的很多人也有做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的,可以找到一些更优秀的资源。


相关推荐

将Fedora 29升级到Fedora 30

吴振华 · 702浏览 · 2019-05-14 22:00:02
使用Nginx反向代理到go-fastdfs

iamitnan · 724浏览 · 2019-05-23 13:42:00
利用VLC搭建组播流服务器

追忆似水年华 · 2691浏览 · 2019-06-14 11:27:06
用Bash脚本监控Linux上的内存使用情况

吴振华 · 972浏览 · 2019-06-24 11:27:02
加载中

0评论

评论
我从小喜欢编程,一直在学习中,从未停止,未来也是如此!
小鸟云服务器
扫码进入手机网页