{"id":219904,"date":"2021-06-15T09:36:21","date_gmt":"2021-06-15T01:36:21","guid":{"rendered":"https:\/\/gulass.cn\/?p=219904"},"modified":"2021-06-02T09:36:59","modified_gmt":"2021-06-02T01:36:59","slug":"linux-drm","status":"publish","type":"post","link":"https:\/\/gulass.cn\/linux-drm.html","title":{"rendered":"Linux drm\u663e\u793a\u7cfb\u7edf\u7684\u4e24\u79cd\u65b9\u6848"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u627e\u4e86\u51e0\u7bc7\u548cdrm\u4e0d\u9519\u7684\u6587\u7ae0\u5206\u4eab\u7ed9\u5927\u5bb6\uff0cLinux\u662f\u4e00\u4e2a\u6a21\u5757\u5316\u975e\u5e38\u660e\u663e\u7684\u7cfb\u7edf\uff0c\u6bcf\u4e2a\u5b50\u7cfb\u7edf\u53c8\u4f1a\u6709\u5c5e\u4e8e\u81ea\u5df1\u7684\u4e00\u4e9b\u7279\u6027\uff0c\u5b66\u4e60\u7684\u65f6\u5019\uff0c\u6700\u597d\u4e5f\u662f\u5206\u7c7b\u5b66\u4e60\u6bd4\u8f83\u597d\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u662f\u56de\u7b54\u4e00\u4f4d\u540c\u5b66\u7684\u63d0\u95ee\uff0c\u5f53\u7136\u4e5f\u662f\u505a\u4e00\u6b21\u603b\u7ed3\uff0c\u6211\u76f8\u4fe1\u5173\u6ce8\u6211\u53f7\u7684\u5f88\u591a\u4eba\u4e5f\u6709\u505aLCD\u76f8\u5173\u7684\u9a71\u52a8\u6216\u8005\u7cfb\u7edf\u5f00\u53d1\uff0c\u5373\u4f7f\u4e0d\u662f\u4e13\u95e8\u505aLCD\uff0c\u4f46\u662f\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u4e5f\u96be\u514d\u4f1a\u9047\u5230\u8fd9\u6837\u6216\u8005\u90a3\u6837\u7684\u95ee\u9898\u3002
\n\"\"
\n\u6240\u4ee5\u627e\u4e86\u51e0\u7bc7\u548cdrm\u4e0d\u9519\u7684\u6587\u7ae0\u5206\u4eab\u7ed9\u5927\u5bb6\uff0cLinux\u662f\u4e00\u4e2a\u6a21\u5757\u5316\u975e\u5e38\u660e\u663e\u7684\u7cfb\u7edf\uff0c\u6bcf\u4e2a\u5b50\u7cfb\u7edf\u53c8\u4f1a\u6709\u5c5e\u4e8e\u81ea\u5df1\u7684\u4e00\u4e9b\u7279\u6027\uff0c\u5b66\u4e60\u7684\u65f6\u5019\uff0c\u6700\u597d\u4e5f\u662f\u5206\u7c7b\u5b66\u4e60\u6bd4\u8f83\u597d\u3002<\/p>\n

Linux \u7684 2 \u79cd\u663e\u793a\u65b9\u6848
\n\u5305\u62ec\uff1a
\nFBDEV: Framebuffer Device
\nDRM\/KMS: Direct Rendering Manager \/ Kernel Mode Setting<\/p>\n

\u5b83\u4eec\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/strong><\/div>\n
FBDEV\uff1a<\/strong><\/span><\/div>\n

\u4f20\u7edf\u7684\u663e\u793a\u6846\u67b6;
\n \u7b80\u5355\uff0c\u4f46\u662f\u53ea\u80fd\u63d0\u4f9b\u6700\u57fa\u7840\u7684\u663e\u793a\u529f\u80fd;
\n \u65e0\u6cd5\u6ee1\u8db3\u5f53\u524d\u4e0a\u5c42\u5e94\u7528\u548c\u5e95\u5c42\u786c\u4ef6\u7684\u663e\u793a\u9700\u6c42;<\/p>\n

DRM\/KMS\uff1a<\/strong><\/span><\/div>\n

\u76ee\u524d\u4e3b\u6d41\u7684\u663e\u793a\u65b9\u6848;
\n \u4e3a\u4e86\u9002\u5e94\u5f53\u524d\u65e5\u76ca\u66f4\u65b0\u7684\u663e\u793a\u786c\u4ef6;
\n \u8f6f\u4ef6\u4e0a\u80fd\u652f\u6301\u66f4\u591a\u9ad8\u7ea7\u7684\u63a7\u5236\u548c\u7279\u6027;<\/p>\n

\u7b80\u5355\u7684\u8bf4\u5c31\u662fFBDEV\u5df2\u7ecf\u4e0d\u6ee1\u8db3\u65f6\u4ee3\u7684\u53d1\u5c55\u9700\u8981\uff0c\u7136\u540e\u5c31\u51fa\u73b0\u4e86DRM\u8fd9\u4e2a\u4e1c\u897f\uff0cDRM\uff0c\u82f1\u6587\u5168\u79f0 Direct Rendering Manager, \u5373 \u76f4\u63a5\u6e32\u67d3\u7ba1\u7406\u5668\u3002\u5b83\u662f\u4e3a\u4e86\u89e3\u51b3\u591a\u4e2a\u7a0b\u5e8f\u5bf9 Video Card \u8d44\u6e90\u7684\u534f\u540c\u4f7f\u7528\u95ee\u9898\u800c\u4ea7\u751f\u7684\u3002\u5b83\u5411\u7528\u6237\u7a7a\u95f4\u63d0\u4f9b\u4e86\u4e00\u7ec4 API\uff0c\u7528\u4ee5\u8bbf\u95ee\u64cd\u7eb5 GPU\u3002<\/p>\n

DRM\u662f\u4e00\u4e2a\u5185\u6838\u7ea7\u7684\u8bbe\u5907\u9a71\u52a8\uff0c\u53ef\u4ee5\u7f16\u8bd1\u5230\u5185\u6838\u4e2d\u4e5f\u53ef\u4ee5\u4f5c\u4e3a\u6807\u51c6\u6a21\u5757\u8fdb\u884c\u52a0\u8f7d\u3002DRM\u6700\u521d\u662f\u5728FreeBSD\u4e2d\u51fa\u73b0\u7684\uff0c\u540e\u6765\u88ab\u79fb\u690d\u5230Linux\u7cfb\u7edf\u4e2d\uff0c\u5e76\u6210\u4e3aLinux\u7cfb\u7edf\u7684\u6807\u51c6\u90e8\u5206\u3002<\/p>\n

DRM\u53ef\u4ee5\u76f4\u63a5\u8bbf\u95eeDRM clients\u7684\u786c\u4ef6\u3002DRM\u9a71\u52a8\u7528\u6765\u5904\u7406DMA\uff0c\u5185\u5b58\u7ba1\u7406\uff0c\u8d44\u6e90\u9501\u4ee5\u53ca\u5b89\u5168\u786c\u4ef6\u8bbf\u95ee\u3002\u4e3a\u4e86\u540c\u65f6\u652f\u6301\u591a\u4e2a3D\u5e94\u7528\uff0c3D\u56fe\u5f62\u5361\u786c\u4ef6\u5fc5\u987b\u4f5c\u4e3a\u4e00\u4e2a\u5171\u4eab\u8d44\u6e90\uff0c\u56e0\u6b64\u9700\u8981\u9501\u6765\u63d0\u4f9b\u4e92\u65a5\u8bbf\u95ee\u3002DMA\u4f20\u8f93\u548cAGP\u63a5\u53e3\u7528\u6765\u53d1\u9001\u56fe\u5f62\u64cd\u4f5c\u7684buffers\u5230\u663e\u5361\u786c\u4ef6\uff0c\u56e0\u6b64\u8981\u9632\u6b62\u5ba2\u6237\u7aef\u8d8a\u6743\u8bbf\u95ee\u663e\u5361\u786c\u4ef6\u3002<\/p>\n

Linux DRM\u5c42\u7528\u6765\u652f\u6301\u90a3\u4e9b\u590d\u6742\u7684\u663e\u5361\u8bbe\u5907\uff0c\u8fd9\u4e9b\u663e\u5361\u8bbe\u5907\u901a\u5e38\u90fd\u5305\u542b\u53ef\u7f16\u7a0b\u7684\u6d41\u6c34\u7ebf\uff0c\u975e\u5e38\u9002\u54083D\u56fe\u50cf\u52a0\u901f\u3002\u5185\u6838\u4e2d\u7684DRM\u5c42\uff0c\u4f7f\u5f97\u8fd9\u4e9b\u663e\u5361\u9a71\u52a8\u5728\u8fdb\u884c\u5185\u5b58\u7ba1\u7406\uff0c\u4e2d\u65ad\u5904\u7406\u548cDMA\u64cd\u4f5c\u4e2d\u53d8\u5f97\u66f4\u5bb9\u6613\uff0c\u5e76\u4e14\u53ef\u4ee5\u4e3a\u4e0a\u5c42\u5e94\u7528\u63d0\u4f9b\u7edf\u4e00\u7684\u63a5\u53e3\u3002<\/p>\n

FBDEV\u7684\u6d4b\u8bd5\u7a0b\u5e8f <\/p>\n

\r\n\/*  \r\n * Copyright (C) 2011 The Android Open Source Project  \r\n *  \r\n * Licensed under the Apache License, Version 2.0 (the \"License\");  \r\n * you may not use this file except in compliance with the License.  \r\n * You may obtain a copy of the License at  \r\n *  \r\n *      http:\/\/www.apache.org\/licenses\/LICENSE-2.0  \r\n *  \r\n * Unless required by applicable law or agreed to in writing, software  \r\n * distributed under the License is distributed on an \"AS IS\" BASIS,  \r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  \r\n * See the License for the specific language governing permissions and  \r\n * limitations under the License.  \r\n *\/  \r\n#include   \r\n#include   \r\n#include   \r\n#include   \r\n#include   \r\n#include   \r\n#include   \r\n#include   \r\n#ifndef FBIO_WAITFORVSYNC  \r\n#define FBIO_WAITFORVSYNC   _IOW('F', 0x20, __u32)  \r\n#endif  \r\nint main(int argc, char** argv) {  \r\n    int fd = open(\"\/dev\/graphics\/fb0\", O_RDWR);  \r\n    if (fd >= 0) {  \r\n        do {  \r\n            uint32_t crt = 0;  \r\n           int err = ioctl(fd, FBIO_WAITFORVSYNC, &crt);  \r\n           if (err < 0) {  \r\n               printf(\"FBIO_WAITFORVSYNC error: %s\\n\", strerror(errno));  \r\n               break;  \r\n           }  \r\n        } while(1);  \r\n        close(fd);  \r\n    }  \r\n    return 0;  \r\n} \r\n<\/pre>\n

DRM\u5e94\u7528\u6d4b\u8bd5\u7a0b\u5e8f<\/p>\n

 \r\nint main(int argc, char **argv)  \r\n{  \r\n int fd;  \r\n drmModeConnector *conn;  \r\n drmModeRes *res;  \r\n uint32_t conn_id;  \r\n uint32_t crtc_id;   \r\n    \/\/ 1. \u6253\u5f00\u8bbe\u5907  \r\n fd = open(\"\/dev\/dri\/card0\", O_RDWR | O_CLOEXEC);  \r\n    \/\/ 2. \u83b7\u5f97 crtc \u548c connector \u7684 id  \r\n res = drmModeGetResources(fd);  \r\n crtc_id = res->crtcs[0];  \r\n conn_id = res->connectors[0];  \r\n    \/\/ 3. \u83b7\u5f97 connector  \r\n conn = drmModeGetConnector(fd, conn_id);  \r\n buf.width = conn->modes[0].hdisplay;  \r\n buf.height = conn->modes[0].vdisplay;  \r\n    \/\/ 4. \u521b\u5efa framebuffer  \r\n modeset_create_fb(fd, &buf);  \r\n    \/\/ 5. Sets a CRTC configuration\uff0c\u8fd9\u4e4b\u540e\u5c31\u4f1a\u5f00\u59cb\u5728 crtc0 + connector0 pipeline \u4e0a\u8fdb\u884c\u4ee5 mode0 \u8f93\u51fa\u663e\u793a  \r\n drmModeSetCrtc(fd, crtc_id, buf.fb_id, 0, 0, &conn_id, 1, &conn->modes[0]);  \r\n getchar();  \r\n \/\/ 6. cleanup  \r\n ...  \r\n return 0;  \r\n}\r\n<\/pre>\n

DRM \u76f8\u5173\u7684\u9a71\u52a8\u5f88\u590d\u6742\uff0c\u6211\u5e76\u4e0d\u6562\u73ed\u95e8\u5f04\u65a7\uff0c\u5982\u679c\u5927\u5bb6\u53ea\u662f\u60f3\u4e86\u89e3\u4e2a\u5927\u6982\uff0c\u6211\u89c9\u5f97\u4e0a\u9762\u7684\u6587\u7ae0\u5e94\u8be5\u80fd\u591f\u6ee1\u8db3\u4f60\u4eec\u7684\u9700\u6c42\uff0c\u4f46\u662f\u5982\u679c\u4f60\u4eec\u662f\u4e13\u95e8\u505aLCD\u7684\uff0c\u53ef\u4ee5\u627e\u5230\u4e00\u4e9b\u66f4\u4f18\u79c0\u7684\u8d44\u6e90\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u662f\u56de\u7b54\u4e00\u4f4d\u540c\u5b66\u7684\u63d0\u95ee\uff0c\u5f53\u7136\u4e5f\u662f\u505a\u4e00\u6b21\u603b\u7ed3\uff0c\u6211\u76f8\u4fe1\u5173\u6ce8\u6211\u53f7\u7684\u5f88\u591a\u4eba\u4e5f\u6709\u505aLCD\u76f8\u5173\u7684\u9a71\u52a8\u6216\u8005\u7cfb\u7edf\u5f00\u53d1 […]<\/p>\n","protected":false},"author":1898,"featured_media":219907,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[696],"class_list":["post-219904","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread","tag-linux-drm"],"acf":[],"_links":{"self":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/219904","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/users\/1898"}],"replies":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/comments?post=219904"}],"version-history":[{"count":2,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/219904\/revisions"}],"predecessor-version":[{"id":219908,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/219904\/revisions\/219908"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media\/219907"}],"wp:attachment":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media?parent=219904"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/categories?post=219904"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/tags?post=219904"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}