Linux内核4.14版本——drm框架分析(5)——plane分析
创始人
2024-05-28 18:32:47
0

目录

1. struct drm_plane结构体

1.1 uint32_t possible_crtcs

1.2 uint32_t *format_types

1.3 unsigned int format_count

1.4  uint64_t *modifiers

1.5 unsigned int modifier_count

1.6  struct drm_crtc *crtc

1.7 struct drm_framebuffer *fb

1.8 struct drm_framebuffer *old_fb

1.9 struct drm_plane_state *state

2. API

2.1 drm_universal_plane_init

3. func

3.1 struct drm_plane_funcs

3.2 struct drm_plane_helper_funcs


      本文主要介绍plane的一些知识。

1. struct drm_plane结构体

/*** struct drm_plane - central DRM plane control structure* @dev: DRM device this plane belongs to* @head: for list management* @name: human readable name, can be overwritten by the driver* @base: base mode object* @possible_crtcs: pipes this plane can be bound to* @format_types: array of formats supported by this plane* @format_count: number of formats supported* @format_default: driver hasn't supplied supported formats for the plane* @crtc: currently bound CRTC* @fb: currently bound fb* @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by* 	drm_mode_set_config_internal() to implement correct refcounting.* @funcs: helper functions* @properties: property tracking for this plane* @type: type of plane (overlay, primary, cursor)* @zpos_property: zpos property for this plane* @rotation_property: rotation property for this plane* @helper_private: mid-layer private data*/
struct drm_plane {struct drm_device *dev;struct list_head head;char *name;/*** @mutex:** Protects modeset plane state, together with the &drm_crtc.mutex of* CRTC this plane is linked to (when active, getting activated or* getting disabled).** For atomic drivers specifically this protects @state.*/struct drm_modeset_lock mutex;struct drm_mode_object base;uint32_t possible_crtcs;uint32_t *format_types;unsigned int format_count;bool format_default;uint64_t *modifiers;unsigned int modifier_count;struct drm_crtc *crtc;struct drm_framebuffer *fb;struct drm_framebuffer *old_fb;const struct drm_plane_funcs *funcs;struct drm_object_properties properties;enum drm_plane_type type;/*** @index: Position inside the mode_config.list, can be used as an array* index. It is invariant over the lifetime of the plane.*/unsigned index;const struct drm_plane_helper_funcs *helper_private;/*** @state:** Current atomic state for this plane.** This is protected by @mutex. Note that nonblocking atomic commits* access the current plane state without taking locks. Either by going* through the &struct drm_atomic_state pointers, see* for_each_plane_in_state(), for_each_oldnew_plane_in_state(),* for_each_old_plane_in_state() and for_each_new_plane_in_state(). Or* through careful ordering of atomic commit operations as implemented* in the atomic helpers, see &struct drm_crtc_commit.*/struct drm_plane_state *state;struct drm_property *zpos_property;struct drm_property *rotation_property;
};

1.1 uint32_t possible_crtcs

        改plane绑定的crtc。

1.2 uint32_t *format_types

        plane支持的fb像素format类型数组, format类型如DRM_FORMAT_ARGB8888

1.3 unsigned int format_count

        plane支持的fb像素format类型数组大小

1.4  uint64_t *modifiers

        modifier数组,其存放的值DRM_FORMAT_MOD_LINEAR/DRM_FORMAT_MOD_X_TILED等

1.5 unsigned int modifier_count

        modifier数组大小

1.6  struct drm_crtc *crtc

        no-atomic drivers用来标识当前绑定的crtc。 对于atomic driver,该值应该为null并使用 &drm_plane_state.crtc替代

1.7 struct drm_framebuffer *fb

        no-atomic drivers用来标识当前绑定的fb。 对于atomic driver,该值应该为null并使用 &drm_plane_state.fb替代

1.8 struct drm_framebuffer *old_fb

       对于non-atomic drivers, old_fb用于在modeset操作时跟踪老的fb atomic drivers下,该值为Null

1.9 struct drm_plane_state *state

        表示plane的各种状态,如其绑定的crtc/fb等,用于atomic操作

2. API

2.1 drm_universal_plane_init

int drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane,uint32_t possible_crtcs,const struct drm_plane_funcs *funcs,const uint32_t *formats, unsigned int format_count,const uint64_t *format_modifiers,enum drm_plane_type type,const char *name, ...)
{struct drm_mode_config *config = &dev->mode_config;unsigned int format_modifier_count = 0;int ret;ret = drm_mode_object_add(dev, &plane->base, DRM_MODE_OBJECT_PLANE);  // (1)if (ret)return ret;drm_modeset_lock_init(&plane->mutex);plane->base.properties = &plane->properties;                  // (2)plane->dev = dev;plane->funcs = funcs;plane->format_types = kmalloc_array(format_count, sizeof(uint32_t),GFP_KERNEL);if (!plane->format_types) {DRM_DEBUG_KMS("out of memory when allocating plane\n");drm_mode_object_unregister(dev, &plane->base);return -ENOMEM;}/** First driver to need more than 64 formats needs to fix this. Each* format is encoded as a bit and the current code only supports a u64.*/if (WARN_ON(format_count > 64))return -EINVAL;if (format_modifiers) {const uint64_t *temp_modifiers = format_modifiers;while (*temp_modifiers++ != DRM_FORMAT_MOD_INVALID)format_modifier_count++;}if (format_modifier_count)config->allow_fb_modifiers = true;plane->modifier_count = format_modifier_count;plane->modifiers = kmalloc_array(format_modifier_count,sizeof(format_modifiers[0]),GFP_KERNEL);if (format_modifier_count && !plane->modifiers) {DRM_DEBUG_KMS("out of memory when allocating plane\n");kfree(plane->format_types);drm_mode_object_unregister(dev, &plane->base);return -ENOMEM;}if (name) {va_list ap;va_start(ap, name);plane->name = kvasprintf(GFP_KERNEL, name, ap);va_end(ap);} else {plane->name = kasprintf(GFP_KERNEL, "plane-%d",drm_num_planes(dev));}if (!plane->name) {kfree(plane->format_types);kfree(plane->modifiers);drm_mode_object_unregister(dev, &plane->base);return -ENOMEM;}memcpy(plane->format_types, formats, format_count * sizeof(uint32_t));plane->format_count = format_count;memcpy(plane->modifiers, format_modifiers,format_modifier_count * sizeof(format_modifiers[0]));plane->possible_crtcs = possible_crtcs;plane->type = type;list_add_tail(&plane->head, &config->plane_list);plane->index = config->num_total_plane++;if (plane->type == DRM_PLANE_TYPE_OVERLAY)config->num_overlay_plane++;drm_object_attach_property(&plane->base,config->plane_type_property,plane->type);if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {              // (3)drm_object_attach_property(&plane->base, config->prop_fb_id, 0);drm_object_attach_property(&plane->base, config->prop_in_fence_fd, -1);drm_object_attach_property(&plane->base, config->prop_crtc_id, 0);drm_object_attach_property(&plane->base, config->prop_crtc_x, 0);drm_object_attach_property(&plane->base, config->prop_crtc_y, 0);drm_object_attach_property(&plane->base, config->prop_crtc_w, 0);drm_object_attach_property(&plane->base, config->prop_crtc_h, 0);drm_object_attach_property(&plane->base, config->prop_src_x, 0);drm_object_attach_property(&plane->base, config->prop_src_y, 0);drm_object_attach_property(&plane->base, config->prop_src_w, 0);drm_object_attach_property(&plane->base, config->prop_src_h, 0);}if (config->allow_fb_modifiers)create_in_format_blob(dev, plane);return 0;
}

        (1)创建一个类型为DRM_MODE_OBJECT_PLANE的结构体。

        (2~3)得到properties,并设置。

3. func

3.1 struct drm_plane_funcs

/*** struct drm_plane_funcs - driver plane control functions*/
struct drm_plane_funcs {/*使能配置plane的crtc和framebuffer.src_x/src_y/src_w/src_h指定fb的源区域*crtc_x/crtc_y/crtc_w/crtc_h指定其显示在crtc上的目标区域*atomic操作使用drm_atomic_helper_update_plane实现*/int (*update_plane)(struct drm_plane *plane,struct drm_crtc *crtc, struct drm_framebuffer *fb,int crtc_x, int crtc_y,unsigned int crtc_w, unsigned int crtc_h,uint32_t src_x, uint32_t src_y,uint32_t src_w, uint32_t src_h,struct drm_modeset_acquire_ctx *ctx);/*DRM_IOCTL_MODE_SETPLANE IOCTL调用时,fb id参数,如果为0,就会调用该接口*关闭plane, atomic modeset使用drm_atomic_helper_disable_plane()实现该hook*/int (*disable_plane)(struct drm_plane *plane,struct drm_modeset_acquire_ctx *ctx);//该接口仅在driver卸载的时候通过drm_mode_config_cleanup()调用来清空plane资源void (*destroy)(struct drm_plane *plane);/*reset plane的软硬件状态, 通过drm_mode_config_reset接口调用*atomic drivers 使用drm_atomic_helper_plane_reset()实现该hook*/void (*reset)(struct drm_plane *plane);/*设置属性的legacy入口, atomic drivers不使用*/int (*set_property)(struct drm_plane *plane,struct drm_property *property, uint64_t val);/*复制plane state, atomic driver必须要有该接口*drm_atomic_get_plane_state会调用到该hook*/struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);//销毁plane statevoid (*atomic_destroy_state)(struct drm_plane *plane,struct drm_plane_state *state);/*设置驱动自定义的属性, 通过drm_atomic_plane_set_property调用*/int (*atomic_set_property)(struct drm_plane *plane,struct drm_plane_state *state,struct drm_property *property,uint64_t val);//获取驱动自定义的属性, 通过drm_atomic_plane_get_property调用int (*atomic_get_property)(struct drm_plane *plane,const struct drm_plane_state *state,struct drm_property *property,uint64_t *val);//drm_dev_register接口调用后,调用该hook注册额外的用户接口int (*late_register)(struct drm_plane *plane);//drm_dev_unregister()前调用,unregister用户空间接口void (*early_unregister)(struct drm_plane *plane);//打印plane state, drm_atomic_plane_print_state()会调用void (*atomic_print_state)(struct drm_printer *p,const struct drm_plane_state *state);//检查format和modifier是否有效bool (*format_mod_supported)(struct drm_plane *plane, uint32_t format,uint64_t modifier);
};

3.2 struct drm_plane_helper_funcs

 
struct drm_plane_helper_funcs {//准备fb,主要包括设置fb fence,  映射fb虚拟地址等int (*prepare_fb)(struct drm_plane *plane,struct drm_plane_state *new_state);//和prepare_fb是相反的操作,比如解除fb虚拟地址的映射void (*cleanup_fb)(struct drm_plane *plane,struct drm_plane_state *old_state);//可选的检查plane属性的约束项int (*atomic_check)(struct drm_plane *plane,struct drm_atomic_state *state);/*更新plane的属性状态到软硬件中, 这个接口才是真正更新参数*/void (*atomic_update)(struct drm_plane *plane,struct drm_atomic_state *state);//disable plane 非必需,不做介绍void (*atomic_disable)(struct drm_plane *plane,struct drm_atomic_state *state);//异步检查 后续了解int (*atomic_async_check)(struct drm_plane *plane,struct drm_atomic_state *state);//异步更新,后续了解void (*atomic_async_update)(struct drm_plane *plane,struct drm_atomic_state *state);
};

相关内容

热门资讯

苹果系统安卓爱思助手,系统兼容... 你有没有发现,手机的世界里,苹果系统和安卓系统就像是一对欢喜冤家,总是各有各的粉丝,各有各的拥趸。而...
安卓系统占用很大内存,揭秘内存... 手机里的安卓系统是不是让你感觉内存不够用,就像你的房间堆满了杂物,总是找不到地方放新东西?别急,今天...
安卓系统p30,安卓系统下的摄... 你有没有发现,最近安卓系统P30在手机圈里可是火得一塌糊涂呢!这不,我就来给你好好扒一扒这款手机的那...
siri被安卓系统进入了,智能... 你知道吗?最近科技圈可是炸开了锅,因为一个大家伙——Siri,竟然悄悄地溜进了安卓系统!这可不是什么...
最强挂机系统和安卓区别,揭秘安... 亲爱的读者,你是否曾在游戏中遇到过这样的困扰:一边想要享受游戏带来的乐趣,一边又不想放弃手中的零食或...
安卓系统为什么设系统盘,保障稳... 你有没有想过,为什么安卓系统里会有一个叫做“系统盘”的东西呢?这可不是随便设置的,背后可是有大学问的...
王者怎么加安卓系统的,轻松提升... 你有没有想过,你的手机里那款超酷的王者荣耀,怎么才能让它更好地在你的安卓系统上运行呢?别急,今天就来...
安卓手机系统怎么开热点,共享网... 你有没有想过,当你身处一个没有Wi-Fi信号的地方,而你的安卓手机里却存满了精彩视频和游戏时,是不是...
安卓系统11的平板电脑,性能升... 你有没有发现,最近平板电脑市场又热闹起来了?没错,安卓系统11的新一代平板电脑正在悄悄地走进我们的生...
安卓手机系统创始人,安卓手机系... 你有没有想过,那些陪伴我们每天生活的安卓手机,它们的灵魂是谁赋予的呢?没错,就是那位神秘而又传奇的安...
安卓11系统速度提升,体验再升... 你知道吗?最近安卓系统又升级啦!这次可是直接跳到了安卓11,听说速度提升了不少呢!是不是很心动?那就...
安卓5.1原生系统设置apk,... 你有没有想过,你的安卓手机里那些看似普通的设置,其实隐藏着不少小秘密呢?今天,就让我带你一探究竟,揭...
手机安卓系统玩音游,畅享指尖音... 你有没有发现,现在手机上的游戏种类越来越丰富,尤其是音游,简直让人爱不释手!今天,就让我来给你详细介...
安卓系统与win10,系统融合... 你有没有想过,为什么你的手机里装的是安卓系统,而电脑上却是Windows 10呢?这两种操作系统,就...
苹果系统王者安卓系统可以登吗,... 你有没有想过,为什么苹果系统的手机那么受欢迎,而安卓系统的手机却也能在市场上占有一席之地呢?今天,咱...
安卓系统怎么重制系统还原,安卓... 手机用久了是不是感觉卡得要命,想给它来个大变身?别急,今天就来教你怎么给安卓手机重置系统,让它焕然一...
安卓9系统怎样应用分身,轻松实... 你有没有发现,手机里的APP越来越多,有时候一个APP里还要处理好多任务,分身功能简直就是救星啊!今...
获取安卓系统的ip地址,轻松获... 你有没有想过,你的安卓手机里隐藏着一个神秘的IP地址?没错,就是那个能让你在网络世界里找到自己的小秘...
LG彩电安卓系统升级,畅享智能... 你家的LG彩电是不是最近有点儿“闹别扭”,屏幕上时不时地跳出个升级提示?别急,今天就来给你详细说说这...
阴阳师安卓苹果系统,安卓与苹果... 亲爱的玩家们,你是否曾在深夜里,手握手机,沉浸在阴阳师的神秘世界?今天,就让我带你一起探索这款风靡全...