Memory-to-memory media controller topology
Subsystems (2)
cover Memory-to-memory media controller topology
As discussed on IRC, memory-to-memory need to be modeled properly in order to be supported by the media controller framework, and thus to support the Request API.
The topology looks like this:
Device topology
- entity 1: source (1 pad, 1 link)
type Node subtype V4L flags 0
pad0: Source
<- "proc":0 [ENABLED,IMMUTABLE]
- entity 3: proc (2 pads, 2 links)
type Node subtype Unknown flags 0 pad0: Source -> "source":0 [ENABLED,IMMUTABLE] pad1: Sink <- "sink":0 [ENABLED,IMMUTABLE]
- entity 6: sink (1 pad, 1 link)
type Node subtype V4L flags 0
pad0: Sink
-> "proc":1 [ENABLED,IMMUTABLE]
The first commit introduces a register/unregister API, that creates/destroys all the entities and pads needed, and links them.
The second commit uses this API to support the vim2m driver.
Ezequiel Garcia (1):
media: add helpers for memory-to-memory media controller
Hans Verkuil (1):
vim2m: add media device
drivers/media/platform/vim2m.c | 41 +++++- drivers/media/v4l2-core/v4l2-dev.c | 13 +- drivers/media/v4l2-core/v4l2-mem2mem.c | 176 +++++++++++++++++++++++++ include/media/v4l2-mem2mem.h | 5 + include/uapi/linux/media.h | 3 + 5 files changed, 229 insertions(+), 9 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/2 media: add helpers for memory-to-memory media controller
A memory-to-memory pipeline device consists in three
entities: two DMA engine and one video processing entities. The DMA engine entities are linked to a V4L interface.
This commit add a new v4l2_m2m_{un}register_media_controller API to register this topology.
For instance, a typical mem2mem device topology would look like this:
Device topology
- entity 1: source (1 pad, 1 link)
type Node subtype V4L flags 0
pad0: Source
<- "proc":0 [ENABLED,IMMUTABLE]
- entity 3: proc (2 pads, 2 links)
type Node subtype Unknown flags 0 pad0: Source -> "source":0 [ENABLED,IMMUTABLE] pad1: Sink <- "sink":0 [ENABLED,IMMUTABLE]
- entity 6: sink (1 pad, 1 link)
type Node subtype V4L flags 0
pad0: Sink
-> "proc":1 [ENABLED,IMMUTABLE]
--- drivers/media/v4l2-core/v4l2-dev.c | 13 +- drivers/media/v4l2-core/v4l2-mem2mem.c | 176 +++++++++++++++++++++++++ include/media/v4l2-mem2mem.h | 5 + include/uapi/linux/media.h | 3 + 4 files changed, 192 insertions(+), 5 deletions(-)
drivers/media/v4l2-core/v4l2-dev.c +8 -5
@@ -202,7 +202,7 @@ static void v4l2_device_release(struct device *cd)mutex_unlock (&videodev_lock);#if defined(CONFIG_MEDIA_CONTROLLER ) -if (v4l2_dev->mdev) { +if (v4l2_dev->mdev && vdev->vfl_dir !=VFL_DIR_M2M ) {/* Remove interfaces and interface links */ media_devnode_remove (vdev->intf_devnode);if (vdev->entity.function !=MEDIA_ENT_F_UNKNOWN )
@@ -733,19 +733,22 @@ static void determine_valid_ioctls(struct video_device *vdev) BASE_VIDIOC_PRIVATE); } -static int video_register_media_controller (struct video_device *vdev,int type) +static int video_register_media_controller (struct video_device *vdev) {#if defined(CONFIG_MEDIA_CONTROLLER )u32 intf_type;int ret; -if (!vdev->v4l2_dev->mdev) +/* Memory-to-memory devices are more complex and use +* their own function to register its mc entities. +*/ +if (!vdev->v4l2_dev->mdev || vdev->vfl_dir ==VFL_DIR_M2M )return 0 ; vdev->entity.obj_type =MEDIA_ENTITY_TYPE_VIDEO_DEVICE ; vdev->entity.function =MEDIA_ENT_F_UNKNOWN ; -switch (type) { +switch (vdev->vfl_type) {case VFL_TYPE_GRABBER : intf_type =MEDIA_INTF_T_V4L_VIDEO ; vdev->entity.function =MEDIA_ENT_F_IO_V4L ;
@@ -993,7 +996,7 @@ int __video_register_device(struct video_device *vdev,v4l2_device_get (vdev->v4l2_dev);/* Part 5: Register the entity. */ - ret =video_register_media_controller (vdev, type); + ret =video_register_media_controller (vdev);/* Part 6: Activate this minor. The char device can now be used. */ set_bit (V4L2_FL_REGISTERED , &vdev->flags);
drivers/media/v4l2-core/v4l2-mem2mem.c +176 -0
203 lines not on this page · raw message
include/media/v4l2-mem2mem.h +5 -0
@@ -53,6 +53,7 @@ struct v4l2_m2m_ops {void (*unlock)(void *priv); }; +struct video_device ;struct v4l2_m2m_dev ;/**
@@ -328,6 +329,10 @@ int v4l2_m2m_mmap(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,*/ struct v4l2_m2m_dev *v4l2_m2m_init (const struct v4l2_m2m_ops *m2m_ops); +void v4l2_m2m_unregister_media_controller (struct v4l2_m2m_dev *m2m_dev); +int v4l2_m2m_register_media_controller (struct v4l2_m2m_dev *m2m_dev, +struct video_device *vdev,int function); +/** * v4l2_m2m_release() - cleans up and frees a m2m_dev structure *
include/uapi/linux/media.h +3 -0
@@ -132,6 +132,9 @@ struct media_device_info {#define MEDIA_ENT_F_PROC_VIDEO_LUT (MEDIA_ENT_F_BASE + 0x4004)#define MEDIA_ENT_F_PROC_VIDEO_SCALER (MEDIA_ENT_F_BASE + 0x4005)#define MEDIA_ENT_F_PROC_VIDEO_STATISTICS (MEDIA_ENT_F_BASE + 0x4006) +#define MEDIA_ENT_F_PROC_VIDEO_DECODER (MEDIA_ENT_F_BASE + 0x4007) +#define MEDIA_ENT_F_PROC_VIDEO_ENCODER (MEDIA_ENT_F_BASE + 0x4008) +#define MEDIA_ENT_F_PROC_VIDEO_DEINTERLACER (MEDIA_ENT_F_BASE + 0x4009)/* * Switch and bridge entity functions
Signature · 1 line
2.17.1
PATCH 2/2 vim2m: add media device
In reply to Ezequiel GarciaFrom: Hans Verkuil <[email protected]>
Request API requires a media node. Add one to the vim2m driver so we can use requests with it.
--- drivers/media/platform/vim2m.c | 41 ++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-)
drivers/media/platform/vim2m.c +37 -4
@@ -140,6 +140,9 @@ static struct vim2m_fmt *find_format(struct v4l2_format *f)struct vim2m_dev {struct v4l2_device v4l2_dev;struct video_device vfd; +#ifdef CONFIG_MEDIA_CONTROLLER +struct media_device mdev; +#endif atomic_t num_inst;struct mutex dev_mutex;
@@ -1016,7 +1019,7 @@ static int vim2m_probe(struct platform_device *pdev) ret =video_register_device (vfd,VFL_TYPE_GRABBER ,0 );if (ret) {v4l2_err (&dev->v4l2_dev,"Failed to register video device\n" ); - goto unreg_dev; + goto unreg_v4l2; }video_set_drvdata (vfd, dev);
@@ -1031,15 +1034,39 @@ static int vim2m_probe(struct platform_device *pdev)if (IS_ERR (dev->m2m_dev)) {v4l2_err (&dev->v4l2_dev,"Failed to init mem2mem device\n" ); ret =PTR_ERR (dev->m2m_dev); - goto err_m2m; + goto unreg_dev; + } + +#ifdef CONFIG_MEDIA_CONTROLLER + dev->mdev.dev = &pdev->dev; +strlcpy (dev->mdev.model,"vim2m" ,sizeof (dev->mdev.model)); +media_device_init (&dev->mdev); + dev->v4l2_dev.mdev = &dev->mdev; + + ret =v4l2_m2m_register_media_controller (dev->m2m_dev, + vfd,MEDIA_ENT_F_PROC_VIDEO_SCALER ); +if (ret) { +v4l2_err (&dev->v4l2_dev,"Failed to init mem2mem media controller\n" ); + goto unreg_m2m; } + ret =media_device_register (&dev->mdev); +if (ret) { +v4l2_err (&dev->v4l2_dev,"Failed to register mem2mem media device\n" ); + goto unreg_m2m_mc; + } +#endif return 0 ; -err_m2m: +#ifdef CONFIG_MEDIA_CONTROLLER +unreg_m2m_mc: +v4l2_m2m_unregister_media_controller (dev->m2m_dev); +unreg_m2m:v4l2_m2m_release (dev->m2m_dev); -video_unregister_device (&dev->vfd); +#endif unreg_dev: +video_unregister_device (&dev->vfd); +unreg_v4l2:v4l2_device_unregister (&dev->v4l2_dev);return ret;
@@ -1050,6 +1077,12 @@ static int vim2m_remove(struct platform_device *pdev)struct vim2m_dev *dev =platform_get_drvdata (pdev);v4l2_info (&dev->v4l2_dev,"Removing " MEM2MEM_NAME ); + +#ifdef CONFIG_MEDIA_CONTROLLER +media_device_unregister (&dev->mdev); +v4l2_m2m_unregister_media_controller (dev->m2m_dev); +media_device_cleanup (&dev->mdev); +#endif v4l2_m2m_release (dev->m2m_dev);del_timer_sync (&dev->timer);video_unregister_device (&dev->vfd);
Signature · 1 line
2.17.1
kbuild test robot
build botRe: [PATCH 1/2] media: add helpers for memory-to-memory media controller
In reply to Ezequiel GarciaI love your patch! Yet something to improve:
Hi Ezequiel,
I love your patch! Yet something to improve:
[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on v4.18-rc1 next-20180620]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Ezequiel-Garcia/media-add-helpers-for-memory-to-memory-media-controller/20180621-050216 base: git://linuxtv.org/media_tree.git master config: x86_64-randconfig-x012-201824 (attached as .config) compiler: gcc-7 (Debian 7.3.0-16) 7.3.0 reproduce: # save the attached .config to linux build tree make ARCH=x86_64
All errors (new ones prefixed by >>):
drivers/media/v4l2-core/v4l2-mem2mem.c: In function 'v4l2_m2m_unregister_media_controller':
>> drivers/media/v4l2-core/v4l2-mem2mem.c:624:34: error: 'struct v4l2_m2m_dev' has no member named 'intf_devnode'
media_remove_intf_links(&m2m_dev->intf_devnode->intf);
^~
drivers/media/v4l2-core/v4l2-mem2mem.c:625:30: error: 'struct v4l2_m2m_dev' has no member named 'intf_devnode'
media_devnode_remove(m2m_dev->intf_devnode);
^~
>> drivers/media/v4l2-core/v4l2-mem2mem.c:627:35: error: 'struct v4l2_m2m_dev' has no member named 'source'
media_entity_remove_links(m2m_dev->source);
^~
>> drivers/media/v4l2-core/v4l2-mem2mem.c:628:36: error: 'struct v4l2_m2m_dev' has no member named 'sink'
media_entity_remove_links(&m2m_dev->sink);
^~
>> drivers/media/v4l2-core/v4l2-mem2mem.c:629:36: error: 'struct v4l2_m2m_dev' has no member named 'proc'
media_entity_remove_links(&m2m_dev->proc);
^~
drivers/media/v4l2-core/v4l2-mem2mem.c:630:40: error: 'struct v4l2_m2m_dev' has no member named 'source'
media_device_unregister_entity(m2m_dev->source);
^~
drivers/media/v4l2-core/v4l2-mem2mem.c:631:41: error: 'struct v4l2_m2m_dev' has no member named 'sink'
media_device_unregister_entity(&m2m_dev->sink);
^~
drivers/media/v4l2-core/v4l2-mem2mem.c:632:41: error: 'struct v4l2_m2m_dev' has no member named 'proc'
media_device_unregister_entity(&m2m_dev->proc);
^~vim +624 drivers/media/v4l2-core/v4l2-mem2mem.c
621
622 void v4l2_m2m_unregister_media_controller(struct v4l2_m2m_dev *m2m_dev)
623 {
> 624 media_remove_intf_links(&m2m_dev->intf_devnode->intf); > 625 media_devnode_remove(m2m_dev->intf_devnode); 626 > 627 media_entity_remove_links(m2m_dev->source); > 628 media_entity_remove_links(&m2m_dev->sink); > 629 media_entity_remove_links(&m2m_dev->proc);
630 media_device_unregister_entity(m2m_dev->source);
631 media_device_unregister_entity(&m2m_dev->sink);
632 media_device_unregister_entity(&m2m_dev->proc);
633 }
634 EXPORT_SYMBOL_GPL(v4l2_m2m_unregister_media_controller);
635
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Quoted 19 lines · Ezequiel Garcia
As discussed on IRC, memory-to-memory need to be modeled properly in order to be supported by the media controller framework, and thus to support the Request API.
The topology looks like this:
Device topology
- entity 1: source (1 pad, 1 link)
type Node subtype V4L flags 0
pad0: Source
<- "proc":0 [ENABLED,IMMUTABLE]- entity 3: proc (2 pads, 2 links)
type Node subtype Unknown flags 0 pad0: Source -> "source":0 [ENABLED,IMMUTABLE] pad1: Sink <- "sink":0 [ENABLED,IMMUTABLE]
Quoted 8 lines
- entity 6: sink (1 pad, 1 link)
type Node subtype V4L flags 0
pad0: Sink
-> "proc":1 [ENABLED,IMMUTABLE]The first commit introduces a register/unregister API, that creates/destroys all the entities and pads needed, and links them.
Can you add the output of v4l2-compliance -m /dev/mediaX here as well?
Thanks!
Hans
Quoted 16 lines
The second commit uses this API to support the vim2m driver.
Ezequiel Garcia (1):
media: add helpers for memory-to-memory media controllerHans Verkuil (1):
vim2m: add media devicedrivers/media/platform/vim2m.c | 41 +++++- drivers/media/v4l2-core/v4l2-dev.c | 13 +- drivers/media/v4l2-core/v4l2-mem2mem.c | 176 +++++++++++++++++++++++++ include/media/v4l2-mem2mem.h | 5 + include/uapi/linux/media.h | 3 + 5 files changed, 229 insertions(+), 9 deletions(-)
Quoted 25 lines · Hans Verkuil
Quoted 24 lines · Ezequiel Garcia
As discussed on IRC, memory-to-memory need to be modeled properly in order to be supported by the media controller framework, and thus to support the Request API.
The topology looks like this:
Device topology
- entity 1: source (1 pad, 1 link)
type Node subtype V4L flags 0
pad0: Source
<- "proc":0 [ENABLED,IMMUTABLE]- entity 3: proc (2 pads, 2 links)
type Node subtype Unknown flags 0 pad0: Source -> "source":0 [ENABLED,IMMUTABLE] pad1: Sink <- "sink":0 [ENABLED,IMMUTABLE]- entity 6: sink (1 pad, 1 link)
type Node subtype V4L flags 0
pad0: Sink
-> "proc":1 [ENABLED,IMMUTABLE]
Quoted 7 lines
Quoted 3 lines
The first commit introduces a register/unregister API, that creates/destroys all the entities and pads needed, and links them.
Can you add the output of v4l2-compliance -m
/dev/mediaXhere as well?
Let me post a new version of the patch, with some minor changes, including the output of the v4l2-compliance tool.
Thanks,
Eze