From 333a6515344f5dc4ed0772b8fe252a2246f2e099 Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Mon, 25 Jan 2016 07:29:13 -0200 Subject: Revert "[media] Postpone the addition of MEDIA_IOC_G_TOPOLOGY" Enable MEDIA_IOC_G_TOPOLOGY ioctl for Kernel 4.6. This reverts commit be0270ec89e6b9b49de7e533dd1f3a89ad34d205. Signed-off-by: Mauro Carvalho Chehab --- drivers/media/media-device.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'drivers/media/media-device.c') diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c index 7dae0ac0f3ae..4d1c13de494b 100644 --- a/drivers/media/media-device.c +++ b/drivers/media/media-device.c @@ -234,7 +234,6 @@ static long media_device_setup_link(struct media_device *mdev, return ret; } -#if 0 /* Let's postpone it to Kernel 4.6 */ static long __media_device_get_topology(struct media_device *mdev, struct media_v2_topology *topo) { @@ -390,7 +389,6 @@ static long media_device_get_topology(struct media_device *mdev, return 0; } -#endif static long media_device_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) @@ -424,14 +422,13 @@ static long media_device_ioctl(struct file *filp, unsigned int cmd, mutex_unlock(&dev->graph_mutex); break; -#if 0 /* Let's postpone it to Kernel 4.6 */ case MEDIA_IOC_G_TOPOLOGY: mutex_lock(&dev->graph_mutex); ret = media_device_get_topology(dev, (struct media_v2_topology __user *)arg); mutex_unlock(&dev->graph_mutex); break; -#endif + default: ret = -ENOIOCTLCMD; } @@ -480,9 +477,7 @@ static long media_device_compat_ioctl(struct file *filp, unsigned int cmd, case MEDIA_IOC_DEVICE_INFO: case MEDIA_IOC_ENUM_ENTITIES: case MEDIA_IOC_SETUP_LINK: -#if 0 /* Let's postpone it to Kernel 4.6 */ case MEDIA_IOC_G_TOPOLOGY: -#endif return media_device_ioctl(filp, cmd, arg); case MEDIA_IOC_ENUM_LINKS32: -- cgit v1.2.3 From bb07bd6b6851120ac9b25bb315d62d9782d2c345 Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Thu, 11 Feb 2016 14:24:23 -0200 Subject: [media] allow overriding the driver name On USB drivers, the dev struct is usually filled with the USB device. That would mean that the name of the driver specified by media_device.dev.driver.name would be "usb", instead of the name of the actual driver that created the media entity. Add an optional field at the internal struct to allow drivers to override the driver name. Signed-off-by: Mauro Carvalho Chehab --- drivers/media/media-device.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'drivers/media/media-device.c') diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c index 4d1c13de494b..5ebb3cd31345 100644 --- a/drivers/media/media-device.c +++ b/drivers/media/media-device.c @@ -55,7 +55,11 @@ static int media_device_get_info(struct media_device *dev, memset(&info, 0, sizeof(info)); - strlcpy(info.driver, dev->dev->driver->name, sizeof(info.driver)); + if (dev->driver_name[0]) + strlcpy(info.driver, dev->driver_name, sizeof(info.driver)); + else + strlcpy(info.driver, dev->dev->driver->name, sizeof(info.driver)); + strlcpy(info.model, dev->model, sizeof(info.model)); strlcpy(info.serial, dev->serial, sizeof(info.serial)); strlcpy(info.bus_info, dev->bus_info, sizeof(info.bus_info)); -- cgit v1.2.3 From 41b44e35ba9b34e50a65c05ecf7642c07bd3e8aa Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Mon, 22 Feb 2016 11:42:04 -0300 Subject: [media] media-device: move PCI/USB helper functions from v4l2-mc Those ancillary functions could be called even when compiled without V4L2 support, as warned by ktest build robot: All errors (new ones prefixed by >>): >> ERROR: "__v4l2_mc_usb_media_device_init" [drivers/media/usb/dvb-usb/dvb-usb.ko] undefined! >> ERROR: "__v4l2_mc_usb_media_device_init" [drivers/media/usb/dvb-usb-v2/dvb_usb_v2.ko] undefined! >> ERROR: "__v4l2_mc_usb_media_device_init" [drivers/media/usb/au0828/au0828.ko] undefined! Also, there's nothing there that are specific to V4L2. So, move those ancillary functions to MC core. No functional changes. Just function rename. Signed-off-by: Mauro Carvalho Chehab --- drivers/media/media-device.c | 74 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'drivers/media/media-device.c') diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c index 5ebb3cd31345..fe376b6b5244 100644 --- a/drivers/media/media-device.c +++ b/drivers/media/media-device.c @@ -27,6 +27,8 @@ #include #include #include +#include +#include #include #include @@ -753,4 +755,76 @@ struct media_device *media_device_find_devres(struct device *dev) } EXPORT_SYMBOL_GPL(media_device_find_devres); +struct media_device *media_device_pci_init(struct pci_dev *pci_dev, + const char *name) +{ +#ifdef CONFIG_PCI + struct media_device *mdev; + + mdev = kzalloc(sizeof(*mdev), GFP_KERNEL); + if (!mdev) + return NULL; + + mdev->dev = &pci_dev->dev; + + if (name) + strlcpy(mdev->model, name, sizeof(mdev->model)); + else + strlcpy(mdev->model, pci_name(pci_dev), sizeof(mdev->model)); + + sprintf(mdev->bus_info, "PCI:%s", pci_name(pci_dev)); + + mdev->hw_revision = (pci_dev->subsystem_vendor << 16) + | pci_dev->subsystem_device; + + mdev->driver_version = LINUX_VERSION_CODE; + + media_device_init(mdev); + + return mdev; +#else + return NULL; +#endif +} +EXPORT_SYMBOL_GPL(media_device_pci_init); + +struct media_device *__media_device_usb_init(struct usb_device *udev, + const char *board_name, + const char *driver_name) +{ +#ifdef CONFIG_USB + struct media_device *mdev; + + mdev = kzalloc(sizeof(*mdev), GFP_KERNEL); + if (!mdev) + return NULL; + + mdev->dev = &udev->dev; + + if (driver_name) + strlcpy(mdev->driver_name, driver_name, + sizeof(mdev->driver_name)); + + if (board_name) + strlcpy(mdev->model, board_name, sizeof(mdev->model)); + else if (udev->product) + strlcpy(mdev->model, udev->product, sizeof(mdev->model)); + else + strlcpy(mdev->model, "unknown model", sizeof(mdev->model)); + if (udev->serial) + strlcpy(mdev->serial, udev->serial, sizeof(mdev->serial)); + usb_make_path(udev, mdev->bus_info, sizeof(mdev->bus_info)); + mdev->hw_revision = le16_to_cpu(udev->descriptor.bcdDevice); + mdev->driver_version = LINUX_VERSION_CODE; + + media_device_init(mdev); + + return mdev; +#else + return NULL; +#endif +} +EXPORT_SYMBOL_GPL(__media_device_usb_init); + + #endif /* CONFIG_MEDIA_CONTROLLER */ -- cgit v1.2.3 From 6cf5dad17e913fce1ccb0c38e199eff15b0f03cc Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Mon, 22 Feb 2016 12:10:49 -0300 Subject: [media] media_device: move allocation out of media_device_*_init Right now, media_device_pci_init and media_device_usb_init does media_device allocation internaly. That preents its usage when the media_device struct is embedded on some other structure. Move memory allocation outside it, to make it more generic. Signed-off-by: Mauro Carvalho Chehab --- drivers/media/media-device.c | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) (limited to 'drivers/media/media-device.c') diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c index fe376b6b5244..6613723f5eb8 100644 --- a/drivers/media/media-device.c +++ b/drivers/media/media-device.c @@ -755,16 +755,11 @@ struct media_device *media_device_find_devres(struct device *dev) } EXPORT_SYMBOL_GPL(media_device_find_devres); -struct media_device *media_device_pci_init(struct pci_dev *pci_dev, - const char *name) +void media_device_pci_init(struct media_device *mdev, + struct pci_dev *pci_dev, + const char *name) { #ifdef CONFIG_PCI - struct media_device *mdev; - - mdev = kzalloc(sizeof(*mdev), GFP_KERNEL); - if (!mdev) - return NULL; - mdev->dev = &pci_dev->dev; if (name) @@ -780,25 +775,16 @@ struct media_device *media_device_pci_init(struct pci_dev *pci_dev, mdev->driver_version = LINUX_VERSION_CODE; media_device_init(mdev); - - return mdev; -#else - return NULL; #endif } EXPORT_SYMBOL_GPL(media_device_pci_init); -struct media_device *__media_device_usb_init(struct usb_device *udev, - const char *board_name, - const char *driver_name) +void __media_device_usb_init(struct media_device *mdev, + struct usb_device *udev, + const char *board_name, + const char *driver_name) { #ifdef CONFIG_USB - struct media_device *mdev; - - mdev = kzalloc(sizeof(*mdev), GFP_KERNEL); - if (!mdev) - return NULL; - mdev->dev = &udev->dev; if (driver_name) @@ -818,10 +804,6 @@ struct media_device *__media_device_usb_init(struct usb_device *udev, mdev->driver_version = LINUX_VERSION_CODE; media_device_init(mdev); - - return mdev; -#else - return NULL; #endif } EXPORT_SYMBOL_GPL(__media_device_usb_init); -- cgit v1.2.3 From afcbdb55898b469606220fcb1868fc1bdd859675 Mon Sep 17 00:00:00 2001 From: Shuah Khan Date: Thu, 11 Feb 2016 21:41:21 -0200 Subject: [media] media: Media Controller register/unregister entity_notify API Add new interfaces to register and unregister entity_notify hook to media device. These interfaces allow drivers to add hooks to take appropriate actions when new entities get added to a shared media device. For example, au0828 bridge driver registers an entity_notify hook to create links as needed between media graph nodes. [mchehab@osg.samsung.com: simple comments should be /* and not /**] Signed-off-by: Shuah Khan Signed-off-by: Mauro Carvalho Chehab --- drivers/media/media-device.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'drivers/media/media-device.c') diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c index 6613723f5eb8..17cd349e485f 100644 --- a/drivers/media/media-device.c +++ b/drivers/media/media-device.c @@ -542,6 +542,7 @@ static void media_device_release(struct media_devnode *mdev) int __must_check media_device_register_entity(struct media_device *mdev, struct media_entity *entity) { + struct media_entity_notify *notify, *next; unsigned int i; int ret; @@ -581,6 +582,11 @@ int __must_check media_device_register_entity(struct media_device *mdev, media_gobj_create(mdev, MEDIA_GRAPH_PAD, &entity->pads[i].graph_obj); + /* invoke entity_notify callbacks */ + list_for_each_entry_safe(notify, next, &mdev->entity_notify, list) { + (notify)->notify(entity, notify->notify_data); + } + spin_unlock(&mdev->lock); return 0; @@ -614,6 +620,8 @@ static void __media_device_unregister_entity(struct media_entity *entity) /* Remove the entity */ media_gobj_destroy(&entity->graph_obj); + /* invoke entity_notify callbacks to handle entity removal?? */ + entity->graph_obj.mdev = NULL; } @@ -646,6 +654,7 @@ void media_device_init(struct media_device *mdev) INIT_LIST_HEAD(&mdev->interfaces); INIT_LIST_HEAD(&mdev->pads); INIT_LIST_HEAD(&mdev->links); + INIT_LIST_HEAD(&mdev->entity_notify); spin_lock_init(&mdev->lock); mutex_init(&mdev->graph_mutex); ida_init(&mdev->entity_internal_idx); @@ -691,11 +700,40 @@ int __must_check __media_device_register(struct media_device *mdev, } EXPORT_SYMBOL_GPL(__media_device_register); +int __must_check media_device_register_entity_notify(struct media_device *mdev, + struct media_entity_notify *nptr) +{ + spin_lock(&mdev->lock); + list_add_tail(&nptr->list, &mdev->entity_notify); + spin_unlock(&mdev->lock); + return 0; +} +EXPORT_SYMBOL_GPL(media_device_register_entity_notify); + +/* + * Note: Should be called with mdev->lock held. + */ +static void __media_device_unregister_entity_notify(struct media_device *mdev, + struct media_entity_notify *nptr) +{ + list_del(&nptr->list); +} + +void media_device_unregister_entity_notify(struct media_device *mdev, + struct media_entity_notify *nptr) +{ + spin_lock(&mdev->lock); + __media_device_unregister_entity_notify(mdev, nptr); + spin_unlock(&mdev->lock); +} +EXPORT_SYMBOL_GPL(media_device_unregister_entity_notify); + void media_device_unregister(struct media_device *mdev) { struct media_entity *entity; struct media_entity *next; struct media_interface *intf, *tmp_intf; + struct media_entity_notify *notify, *nextp; if (mdev == NULL) return; @@ -712,6 +750,10 @@ void media_device_unregister(struct media_device *mdev) list_for_each_entry_safe(entity, next, &mdev->entities, graph_obj.list) __media_device_unregister_entity(entity); + /* Remove all entity_notify callbacks from the media device */ + list_for_each_entry_safe(notify, nextp, &mdev->entity_notify, list) + __media_device_unregister_entity_notify(mdev, notify); + /* Remove all interfaces from the media device */ list_for_each_entry_safe(intf, tmp_intf, &mdev->interfaces, graph_obj.list) { -- cgit v1.2.3 From 0c426c472b5585ed6e59160359c979506d45ae49 Mon Sep 17 00:00:00 2001 From: Sakari Ailus Date: Sun, 21 Feb 2016 13:25:08 -0300 Subject: [media] media: Always keep a graph walk large enough around Re-create the graph walk object as needed in order to have one large enough available for all entities in the graph. This enumeration is used for pipeline power management in the future. [mchehab@osg.samsung.com: fix documentation bug: " warning: bad line: graph_mutex"] Signed-off-by: Sakari Ailus Signed-off-by: Mauro Carvalho Chehab --- drivers/media/media-device.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'drivers/media/media-device.c') diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c index 17cd349e485f..a2353ecab687 100644 --- a/drivers/media/media-device.c +++ b/drivers/media/media-device.c @@ -589,6 +589,26 @@ int __must_check media_device_register_entity(struct media_device *mdev, spin_unlock(&mdev->lock); + mutex_lock(&mdev->graph_mutex); + if (mdev->entity_internal_idx_max + >= mdev->pm_count_walk.ent_enum.idx_max) { + struct media_entity_graph new = { .top = 0 }; + + /* + * Initialise the new graph walk before cleaning up + * the old one in order not to spoil the graph walk + * object of the media device if graph walk init fails. + */ + ret = media_entity_graph_walk_init(&new, mdev); + if (ret) { + mutex_unlock(&mdev->graph_mutex); + return ret; + } + media_entity_graph_walk_cleanup(&mdev->pm_count_walk); + mdev->pm_count_walk = new; + } + mutex_unlock(&mdev->graph_mutex); + return 0; } EXPORT_SYMBOL_GPL(media_device_register_entity); @@ -667,6 +687,7 @@ void media_device_cleanup(struct media_device *mdev) { ida_destroy(&mdev->entity_internal_idx); mdev->entity_internal_idx_max = 0; + media_entity_graph_walk_cleanup(&mdev->pm_count_walk); mutex_destroy(&mdev->graph_mutex); } EXPORT_SYMBOL_GPL(media_device_cleanup); -- cgit v1.2.3 From 0629e991a25a9b56a70f9f0c327aad8ae1471dbf Mon Sep 17 00:00:00 2001 From: Sakari Ailus Date: Mon, 22 Feb 2016 17:47:04 -0300 Subject: [media] media: Move media_get_uptr() macro out of the media.h user space header The media_get_uptr() macro is mostly useful only for the IOCTL handling code in media-device.c so move it there. Signed-off-by: Sakari Ailus Acked-by: Laurent Pinchart Signed-off-by: Mauro Carvalho Chehab --- drivers/media/media-device.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'drivers/media/media-device.c') diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c index a2353ecab687..c89dfef0c4c5 100644 --- a/drivers/media/media-device.c +++ b/drivers/media/media-device.c @@ -40,6 +40,11 @@ * Userspace API */ +static inline void __user *media_get_uptr(__u64 arg) +{ + return (void __user *)(uintptr_t)arg; +} + static int media_device_open(struct file *filp) { return 0; -- cgit v1.2.3 From d37410c27299fab8c7f17041f71ca5c2046d1f6f Mon Sep 17 00:00:00 2001 From: Sakari Ailus Date: Mon, 22 Feb 2016 17:47:03 -0300 Subject: [media] media: Properly handle user pointers Mark pointers containing user pointers as such. Signed-off-by: Sakari Ailus Acked-by: Laurent Pinchart Signed-off-by: Mauro Carvalho Chehab --- drivers/media/media-device.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'drivers/media/media-device.c') diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c index c89dfef0c4c5..6ba6e8f982fc 100644 --- a/drivers/media/media-device.c +++ b/drivers/media/media-device.c @@ -252,10 +252,10 @@ static long __media_device_get_topology(struct media_device *mdev, struct media_interface *intf; struct media_pad *pad; struct media_link *link; - struct media_v2_entity kentity, *uentity; - struct media_v2_interface kintf, *uintf; - struct media_v2_pad kpad, *upad; - struct media_v2_link klink, *ulink; + struct media_v2_entity kentity, __user *uentity; + struct media_v2_interface kintf, __user *uintf; + struct media_v2_pad kpad, __user *upad; + struct media_v2_link klink, __user *ulink; unsigned int i; int ret = 0; -- cgit v1.2.3