当前位置: 首页 > news >正文

DRM全解析 —— ADD_FB2(3)

接前一篇文章:DRM全解析 —— ADD_FB2(2)

本文参考以下博文:

DRM驱动(四)之ADD_FB

特此致谢!

上一回围绕libdrm与DRM在Linux内核中的接口:

DRM_IOCTL_DEF(DRM_IOCTL_MODE_ADDFB2, drm_mode_addfb2_ioctl, 0),

进行了相关宏的展开。本文开始对于drm_mode_addfb2_ioctl函数进行详解。drm_mode_addfb2_ioctl函数在drivers/gpu/drm/drm_framebuffer.c中,代码如下:

int drm_mode_addfb2_ioctl(struct drm_device *dev,void *data, struct drm_file *file_priv)
{
#ifdef __BIG_ENDIANif (!dev->mode_config.quirk_addfb_prefer_host_byte_order) {/** Drivers must set the* quirk_addfb_prefer_host_byte_order quirk to make* the drm_mode_addfb() compat code work correctly on* bigendian machines.** If they don't they interpret pixel_format values* incorrectly for bug compatibility, which in turn* implies the ADDFB2 ioctl does not work correctly* then.  So block it to make userspace fallback to* ADDFB.*/drm_dbg_kms(dev, "addfb2 broken on bigendian");return -EOPNOTSUPP;}
#endifreturn drm_mode_addfb2(dev, data, file_priv);
}

drm_mode_addfb2_ioctl函数只是一层简单封装,实际的工作交给了drm_mode_addfb2函数。它就在上边,代码如下:

/*** drm_mode_addfb2 - add an FB to the graphics configuration* @dev: drm device for the ioctl* @data: data pointer for the ioctl* @file_priv: drm file for the ioctl call** Add a new FB to the specified CRTC, given a user request with format. This is* the 2nd version of the addfb ioctl, which supports multi-planar framebuffers* and uses fourcc codes as pixel format specifiers.** Called by the user via ioctl.** Returns:* Zero on success, negative errno on failure.*/
int drm_mode_addfb2(struct drm_device *dev,void *data, struct drm_file *file_priv)
{struct drm_mode_fb_cmd2 *r = data;struct drm_framebuffer *fb;if (!drm_core_check_feature(dev, DRIVER_MODESET))return -EOPNOTSUPP;fb = drm_internal_framebuffer_create(dev, r, file_priv);if (IS_ERR(fb))return PTR_ERR(fb);drm_dbg_kms(dev, "[FB:%d]\n", fb->base.id);r->fb_id = fb->base.id;/* Transfer ownership to the filp for reaping on close */mutex_lock(&file_priv->fbs_lock);list_add(&fb->filp_head, &file_priv->fbs);mutex_unlock(&file_priv->fbs_lock);return 0;
}

实际上前文DRM全解析 —— ADD_FB(2)中曾给出drm_mode_addfb函数的代码:

/*** drm_mode_addfb - add an FB to the graphics configuration* @dev: drm device for the ioctl* @or: pointer to request structure* @file_priv: drm file** Add a new FB to the specified CRTC, given a user request. This is the* original addfb ioctl which only supported RGB formats.** Called by the user via ioctl, or by an in-kernel client.** Returns:* Zero on success, negative errno on failure.*/
int drm_mode_addfb(struct drm_device *dev, struct drm_mode_fb_cmd *or,struct drm_file *file_priv)
{struct drm_mode_fb_cmd2 r = {};int ret;if (!drm_core_check_feature(dev, DRIVER_MODESET))return -EOPNOTSUPP;r.pixel_format = drm_driver_legacy_fb_format(dev, or->bpp, or->depth);if (r.pixel_format == DRM_FORMAT_INVALID) {drm_dbg_kms(dev, "bad {bpp:%d, depth:%d}\n", or->bpp, or->depth);return -EINVAL;}/* convert to new format and call new ioctl */r.fb_id = or->fb_id;r.width = or->width;r.height = or->height;r.pitches[0] = or->pitch;r.handles[0] = or->handle;ret = drm_mode_addfb2(dev, &r, file_priv);if (ret)return ret;or->fb_id = r.fb_id;return 0;
}

从这里就能看出,drm_mode_addfb()实际上也是调用了drm_mode_addfb2(),这俩本质上是一回事。只是drm_mode_addfb函数中多了一些预准备和预处理。

drm_mode_fb_cmd2结构在本系列第一篇文章中已经介绍过了,为了便于理解,再次给出其代码,在include/drm/drm_mode.h中,如下:

struct drm_mode_fb_cmd2 {__u32 fb_id;__u32 width;__u32 height;__u32 pixel_format; /* fourcc code from drm_fourcc.h */__u32 flags; /* see above flags *//** In case of planar formats, this ioctl allows up to 4* buffer objects with offsets and pitches per plane.* The pitch and offset order is dictated by the fourcc,* e.g. NV12 (https://fourcc.org/yuv.php#NV12) is described as:**   YUV 4:2:0 image with a plane of 8 bit Y samples*   followed by an interleaved U/V plane containing*   8 bit 2x2 subsampled colour difference samples.** So it would consist of Y as offsets[0] and UV as* offsets[1].  Note that offsets[0] will generally* be 0 (but this is not required).** To accommodate tiled, compressed, etc formats, a* modifier can be specified.  The default value of zero* indicates "native" format as specified by the fourcc.* Vendor specific modifier token.  Note that even though* it looks like we have a modifier per-plane, we in fact* do not. The modifier for each plane must be identical.* Thus all combinations of different data layouts for* multi plane formats must be enumerated as separate* modifiers.*/__u32 handles[4];__u32 pitches[4]; /* pitch for each plane */__u32 offsets[4]; /* offset of each plane */__u64 modifier[4]; /* ie, tiling, compress */
};

struct drm_framebuffer 当然是在include/drm/drm_framebuffer.h中定义,代码如下:

/*** struct drm_framebuffer - frame buffer object** Note that the fb is refcounted for the benefit of driver internals,* for example some hw, disabling a CRTC/plane is asynchronous, and* scanout does not actually complete until the next vblank.  So some* cleanup (like releasing the reference(s) on the backing GEM bo(s))* should be deferred.  In cases like this, the driver would like to* hold a ref to the fb even though it has already been removed from* userspace perspective. See drm_framebuffer_get() and* drm_framebuffer_put().** The refcount is stored inside the mode object @base.*/
struct drm_framebuffer {/*** @dev: DRM device this framebuffer belongs to*/struct drm_device *dev;/*** @head: Place on the &drm_mode_config.fb_list, access protected by* &drm_mode_config.fb_lock.*/struct list_head head;/*** @base: base modeset object structure, contains the reference count.*/struct drm_mode_object base;/*** @comm: Name of the process allocating the fb, used for fb dumping.*/char comm[TASK_COMM_LEN];/*** @format: framebuffer format information*/const struct drm_format_info *format;/*** @funcs: framebuffer vfunc table*/const struct drm_framebuffer_funcs *funcs;/*** @pitches: Line stride per buffer. For userspace created object this* is copied from drm_mode_fb_cmd2.*/unsigned int pitches[DRM_FORMAT_MAX_PLANES];/*** @offsets: Offset from buffer start to the actual pixel data in bytes,* per buffer. For userspace created object this is copied from* drm_mode_fb_cmd2.** Note that this is a linear offset and does not take into account* tiling or buffer layout per @modifier. It is meant to be used when* the actual pixel data for this framebuffer plane starts at an offset,* e.g. when multiple planes are allocated within the same backing* storage buffer object. For tiled layouts this generally means its* @offsets must at least be tile-size aligned, but hardware often has* stricter requirements.** This should not be used to specifiy x/y pixel offsets into the buffer* data (even for linear buffers). Specifying an x/y pixel offset is* instead done through the source rectangle in &struct drm_plane_state.*/unsigned int offsets[DRM_FORMAT_MAX_PLANES];/*** @modifier: Data layout modifier. This is used to describe* tiling, or also special layouts (like compression) of auxiliary* buffers. For userspace created object this is copied from* drm_mode_fb_cmd2.*/uint64_t modifier;/*** @width: Logical width of the visible area of the framebuffer, in* pixels.*/unsigned int width;/*** @height: Logical height of the visible area of the framebuffer, in* pixels.*/unsigned int height;/*** @flags: Framebuffer flags like DRM_MODE_FB_INTERLACED or* DRM_MODE_FB_MODIFIERS.*/int flags;/*** @hot_x: X coordinate of the cursor hotspot. Used by the legacy cursor* IOCTL when the driver supports cursor through a DRM_PLANE_TYPE_CURSOR* universal plane.*/int hot_x;/*** @hot_y: Y coordinate of the cursor hotspot. Used by the legacy cursor* IOCTL when the driver supports cursor through a DRM_PLANE_TYPE_CURSOR* universal plane.*/int hot_y;/*** @filp_head: Placed on &drm_file.fbs, protected by &drm_file.fbs_lock.*/struct list_head filp_head;/*** @obj: GEM objects backing the framebuffer, one per plane (optional).** This is used by the GEM framebuffer helpers, see e.g.* drm_gem_fb_create().*/struct drm_gem_object *obj[DRM_FORMAT_MAX_PLANES];
};

了解了相关的结构体定义之后,可以开始对于drm_mode_addfb2函数的正式解析了。请看下回。

相关文章:

DRM全解析 —— ADD_FB2(3)

接前一篇文章:DRM全解析 —— ADD_FB2(2) 本文参考以下博文: DRM驱动(四)之ADD_FB 特此致谢! 上一回围绕libdrm与DRM在Linux内核中的接口: DRM_IOCTL_DEF(DRM_IOCTL_MODE_ADDFB2,…...

【Java】SpringMVC ResponseBodyAdvice详解

目录 1. ResponseBodyAdvice 2. supports方法 3. beforeBodyWrite方法 4. 实践 1. ResponseBodyAdvice Spring MVC的ResponseBodyAdvice是Spring 4.1版本中引入的一个接口,它允许在Controller控制器中ResponseBody修饰的方法或ResponseEntity执行之后&#xff…...

python常见面试题五

解释 Python 中的列表推导式 (list comprehension)。 答:列表推导式是一种创建新列表的简洁方式。它可以在一行代码中通过对一个可迭代对象应用表达式和条件来生成新的列表。 解释 Python 中的时间复杂度和空间复杂度。 答:时间复杂度衡量算法运行时间的…...

SpringBoot结合Vue.js+axios框架实现增删改查功能+网页端实时显示数据库数据(包括删除多条数据)

本文适用对象:已有基础的同学,知道基础的SpringBoot配置和Vue操作。 在此基础上本文实现基于SpringBoot和Vue.js基础上的增删改查和数据回显、刷新等。 一、实时显示数据库数据 实现步骤: 第1步:编写动态请求响应类&#xff1a…...

曙光亮相工博会,发布首款国产高端工业实时仿真计算系统

9月19日-23日,中科曙光亮相第23届中国国际工业博览会,并受邀于主论坛发表主题演讲,在工业权威会议上展示曙光领先的工业数字化技术与实践成果。展会期间,曙光重磅发布首款国产工业实时仿真计算系统,并展出多项工业数字…...

「大数据-2.0」安装Hadoop和部署HDFS集群

目录 一、下载Hadoop安装包 二、安装Hadoop 0. 安装Hadoop前的必要准备 1. 以root用户登录主节点虚拟机 2. 上传Hadoop安装包到主节点 3. 解压缩安装包到/export/server/目录中 4. 构建软链接 三、部署HDFS集群 0. 集群部署规划 1. 进入hadoop安装包内 2 进入etc目录下的hadoop…...

文档在线预览word、pdf、excel文件转html以实现文档在线预览

目录 一、前言 1、aspose2 、poi pdfbox3 spire二、将文件转换成html字符串 1、将word文件转成html字符串 1.1 使用aspose1.2 使用poi1.3 使用spire2、将pdf文件转成html字符串 2.1 使用aspose2.2 使用 poi pbfbox2.3 使用spire3、将excel文件转成html字符串 3.1 使用aspose…...

FFmpeg视音频分离器----向雷神学习

雷神博客地址:https://blog.csdn.net/leixiaohua1020/article/details/39767055 本程序可以将封装格式中的视频码流数据和音频码流数据分离出来。 在该例子中, 将FLV的文件分离得到H.264视频码流文件和MP3 音频码流文件。 注意: 这个是简化版…...

CentOS 8开启bbr

CentOS 8 默认内核版本为 4.18.x,内核版本高于4.9 就可以直接开启 BBR,所以CentOS 8 启用BBR非常简单不需要再去升级内核。 开启bbr echo "net.core.default_qdiscfq" >> /etc/sysctl.conf echo "net.ipv4.tcp_congestion_contro…...

Redis的安装与基本使用

文章目录 Linux 环境下安装Redis下载Redis 安装包解压安装包安装Redis进入redis安装包下编译并且安装到指定目录下 启动redis配置远程访问找到Redis.config文件 Windows 环境下安装Redis说明官方提供方式安装或启用WSL2在WSL(Ubuntu)上安装Redis启动Redi…...

2014 款金旅牌小型客车 发动机怠速抖动、加速无力

故障现象 一辆2014款金旅牌小型客车,搭载JM491Q-ME发动机,累计行驶里程约为20万km。车主反映,最近该车发动机怠速抖动、加速无力,且经常缺少冷却液。 故障诊断 根据车主描述的故障现象,初步判断该车气缸垫损坏&#…...

R语言逻辑回归、决策树、随机森林、神经网络预测患者心脏病数据混淆矩阵可视化...

全文链接:https://tecdat.cn/?p33760 众所周知,心脏疾病是目前全球最主要的死因。开发一个能够预测患者心脏疾病存在的计算系统将显著降低死亡率并大幅降低医疗保健成本。机器学习在全球许多领域中被广泛应用,尤其在医疗行业中越来越受欢迎。机器学习可…...

网站被劫持了怎么办

网站被劫持了怎么办 建议新建一个index.html文件,文件中只写几个数字,上传到网站根目录,然后访问网站域名,看看是不是正常,从而可以确定是程序问题还是域名被劫持的问题。 如果是域名被劫持,你可以登录你的…...

【面试题精讲】Java包装类缓存机制

有的时候博客内容会有变动,首发博客是最新的,其他博客地址可能会未同步,认准https://blog.zysicyj.top 首发博客地址[1] 面试题手册[2] 系列文章地址[3] 1. 什么是 Java 包装类缓存机制? Java 中的包装类(Wrapper Class)是为了将…...

网络相关知识

0 socket SOCK_DGRAM #无连接UDP SOCK_STREAM #面向连接TCP 1 UDP 1.1 检测UDP yum install -y nc 使用netcat测试连通性 服务器端启动 UDP 30003 端口 ​ nc -l -u 30003 客户端连接服务器的30003端口(假设服务的IP地址是119.23.67.12) ​nc -u 119…...

商品冷启动推荐综述

About Me: LuckBoyPhd/Resume (github.com) (1)一种基于三部图网络的协同过滤算法 推荐系统是电子商务领域最重要的技术之一,而协同过滤算法又是推荐系统用得最广泛的.提出了一种基于加权三部图网络的协同过滤算法,用户、产品及标签都被考虑到算法中,并且研究了标签结点的度对…...

GEO生信数据挖掘(二)下载基因芯片平台文件及注释

检索到目标数据集后,开始数据挖掘,本文以阿尔兹海默症数据集GSE1297为例 目录 下载平台文件 1.AnnotGPL参数改为TRUE,联网下载芯片平台的soft文件。(国内网速奇慢经常中断) 2.手工去GEO官网下载 转换芯片探针ID为gene name 拓…...

淘宝电商必备的大数据应用

在日常生活中,大家总能听到“大数据”“人工智能”的说法。现在的大数据技术应用,从大到巨大科学研究、社会信息审查、搜索引擎,小到社交联结、餐厅推荐等等,已经渗透到我们生活中的方方面面。到底大数据在电商行业可以怎么用&…...

Docker版部署RocketMQ开启ACL验证

一、拉取镜像 docker pull apache/rocketmq:latest 二、准备挂载目录 mkdir /usr/local/rocketmq/data mkdir /usr/local/rocketmq/conf 三、运行 docker run \ -d \ -p 9876:9876 \ -v /usr/local/rocketmq/data/logs:/home/rocketmq/logs \ -v /usr/local/rocketmq/data…...

【RabbitMQ实战】04 RabbitMQ的基本概念:Exchange,Queue,Channel等

一、简介 Message Queue的需求由来已久,80年代最早在金融交易中,高盛等公司采用Teknekron公司的产品,当时的Message queuing软件叫做:the information bus(TIB)。 TIB被电信和通讯公司采用,路透…...

网络编程(Modbus进阶)

思维导图 Modbus RTU(先学一点理论) 概念 Modbus RTU 是工业自动化领域 最广泛应用的串行通信协议,由 Modicon 公司(现施耐德电气)于 1979 年推出。它以 高效率、强健性、易实现的特点成为工业控制系统的通信标准。 包…...

基于大模型的 UI 自动化系统

基于大模型的 UI 自动化系统 下面是一个完整的 Python 系统,利用大模型实现智能 UI 自动化,结合计算机视觉和自然语言处理技术,实现"看屏操作"的能力。 系统架构设计 #mermaid-svg-2gn2GRvh5WCP2ktF {font-family:"trebuchet ms",verdana,arial,sans-…...

Redis相关知识总结(缓存雪崩,缓存穿透,缓存击穿,Redis实现分布式锁,如何保持数据库和缓存一致)

文章目录 1.什么是Redis?2.为什么要使用redis作为mysql的缓存?3.什么是缓存雪崩、缓存穿透、缓存击穿?3.1缓存雪崩3.1.1 大量缓存同时过期3.1.2 Redis宕机 3.2 缓存击穿3.3 缓存穿透3.4 总结 4. 数据库和缓存如何保持一致性5. Redis实现分布式…...

解决Ubuntu22.04 VMware失败的问题 ubuntu入门之二十八

现象1 打开VMware失败 Ubuntu升级之后打开VMware上报需要安装vmmon和vmnet,点击确认后如下提示 最终上报fail 解决方法 内核升级导致,需要在新内核下重新下载编译安装 查看版本 $ vmware -v VMware Workstation 17.5.1 build-23298084$ lsb_release…...

线程与协程

1. 线程与协程 1.1. “函数调用级别”的切换、上下文切换 1. 函数调用级别的切换 “函数调用级别的切换”是指:像函数调用/返回一样轻量地完成任务切换。 举例说明: 当你在程序中写一个函数调用: funcA() 然后 funcA 执行完后返回&…...

Cilium动手实验室: 精通之旅---20.Isovalent Enterprise for Cilium: Zero Trust Visibility

Cilium动手实验室: 精通之旅---20.Isovalent Enterprise for Cilium: Zero Trust Visibility 1. 实验室环境1.1 实验室环境1.2 小测试 2. The Endor System2.1 部署应用2.2 检查现有策略 3. Cilium 策略实体3.1 创建 allow-all 网络策略3.2 在 Hubble CLI 中验证网络策略源3.3 …...

质量体系的重要

质量体系是为确保产品、服务或过程质量满足规定要求,由相互关联的要素构成的有机整体。其核心内容可归纳为以下五个方面: 🏛️ 一、组织架构与职责 质量体系明确组织内各部门、岗位的职责与权限,形成层级清晰的管理网络&#xf…...

Qwen3-Embedding-0.6B深度解析:多语言语义检索的轻量级利器

第一章 引言:语义表示的新时代挑战与Qwen3的破局之路 1.1 文本嵌入的核心价值与技术演进 在人工智能领域,文本嵌入技术如同连接自然语言与机器理解的“神经突触”——它将人类语言转化为计算机可计算的语义向量,支撑着搜索引擎、推荐系统、…...

EtherNet/IP转DeviceNet协议网关详解

一,设备主要功能 疆鸿智能JH-DVN-EIP本产品是自主研发的一款EtherNet/IP从站功能的通讯网关。该产品主要功能是连接DeviceNet总线和EtherNet/IP网络,本网关连接到EtherNet/IP总线中做为从站使用,连接到DeviceNet总线中做为从站使用。 在自动…...

在鸿蒙HarmonyOS 5中使用DevEco Studio实现录音机应用

1. 项目配置与权限设置 1.1 配置module.json5 {"module": {"requestPermissions": [{"name": "ohos.permission.MICROPHONE","reason": "录音需要麦克风权限"},{"name": "ohos.permission.WRITE…...