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);
};

相关内容

热门资讯

安卓系统能跑win吗,探索跨平... 你有没有想过,你的安卓手机里能不能装上Windows系统呢?这听起来是不是有点像科幻电影里的情节?别...
安卓车载系统蓝牙设置,畅享智能... 你有没有发现,现在开车的时候,手机和车载系统之间的互动越来越频繁了呢?这不,今天就来给你详细说说安卓...
奥利奥安卓系统,探索新一代智能... 你有没有想过,一块小小的奥利奥饼干竟然能和强大的安卓系统扯上关系?没错,今天就要来聊聊这个跨界组合,...
微信使用安卓系统,功能解析与操... 你有没有发现,现在用微信的人越来越多了呢?尤其是安卓系统的用户,简直就像潮水一样涌来。今天,就让我带...
体验最新原生安卓系统,极致体验... 你有没有想过,手机系统就像是我们生活的调味品,有时候换一种口味,生活都会变得有趣起来呢?最近,我体验...
安卓系统能玩原神,尽享奇幻冒险... 你有没有想过,在安卓系统上也能畅玩《原神》这样的热门游戏呢?没错,就是那个画面精美、角色丰富、玩法多...
安卓写手机银行系统,基于安卓平... 你有没有想过,手机银行系统在我们日常生活中扮演了多么重要的角色呢?每天刷刷手机,就能轻松管理账户,转...
僵尸之夜恐怖安卓系统,揭秘恐怖... 僵尸之夜,恐怖安卓系统来袭!想象一个寂静的夜晚,你正沉浸在美梦中,突然,一阵诡异的铃声打破了夜的宁静...
谷歌框架和安卓系统,构建智能移... 你有没有想过,为什么你的手机那么聪明,能帮你找到路线,还能帮你拍出美美的照片呢?这都要归功于一个超级...
安卓系统和oppo系统哪个流畅... 你有没有想过,手机系统哪个更流畅呢?安卓系统和OPPO系统,这两个名字听起来就让人心动。今天,咱们就...
安卓怎么用微软系统,利用微软系... 你是不是也和我一样,对安卓手机上的微软系统充满了好奇?想象那熟悉的Windows界面在你的安卓手机上...
安卓系统如何安装nfc,安卓系... 你有没有想过,用手机刷公交卡、支付账单,是不是比掏出钱包来得酷炫多了?这就得归功于NFC技术啦!今天...
ios系统可以转安卓,跨平台应... 你有没有想过,你的iPhone手机里的那些宝贝应用,能不能搬到安卓手机上继续使用呢?没错,今天就要来...
iOSapp移植到安卓系统,i... 你有没有想过,那些在iOS上让你爱不释手的app,是不是也能在安卓系统上大放异彩呢?今天,就让我带你...
现在安卓随便换系统,探索个性化... 你知道吗?现在安卓手机换系统简直就像换衣服一样简单!没错,就是那种随时随地、随心所欲的感觉。今天,就...
安卓系统安装按钮灰色,探究原因... 最近发现了一个让人头疼的小问题,那就是安卓手机的安装按钮突然变成了灰色,这可真是让人摸不着头脑。你知...
安卓7.1.1操作系统,系统特... 你知道吗?最近我在手机上发现了一个超级酷的新玩意儿——安卓7.1.1操作系统!这可不是什么小打小闹的...
安卓os系统怎么设置,并使用`... 你有没有发现,你的安卓手机有时候就像一个不听话的小孩子,有时候设置起来真是让人头疼呢?别急,今天就来...
安卓降低系统版本5.1,探索安... 你知道吗?最近安卓系统又来了一次大动作,竟然把系统版本给降到了5.1!这可真是让人有点摸不着头脑,不...
解放安卓系统被保护,解放安卓系... 你有没有想过,你的安卓手机其实可以更加自由地呼吸呢?是的,你没听错,我说的就是解放安卓系统被保护的束...