11 Jan, 2016

40 commits

  • Sometimes, it is desired to create 1:n and n:1 or even
    n:n links between different entities with the same
    function.

    This is actually needed to support DVB devices that
    have multiple frontends. While we could do a function
    like that internally at the DVB core, such function is
    generic enough to be at media-entity, and it could be
    useful on some other places.

    So, add such function.

    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • We should not remove the media_device until its last usage,
    or we may have use after free troubles.

    So, move the per-adapter media_device removal to happen at
    the end of the adapter removal code.

    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Several pure digital TV devices have a frontend with the tuner
    integrated on it. Add the RF connector when dvb_create_media_graph()
    is called on such devices.

    Tested with siano and dvb_usb_mxl111sf drivers.

    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Those functions are used only if CONFIG_MEDIA_CONTROLLER_DVB.
    Without that, if !CONFIG_MEDIA_CONTROLLER_DVB, it would produce
    two warnings:

    drivers/media/dvb-core/dvbdev.c:219:12: warning: 'dvb_create_tsout_entity' defined but not used [-Wunused-function]
    static int dvb_create_tsout_entity(struct dvb_device *dvbdev,
    ^
    drivers/media/dvb-core/dvbdev.c:264:12: warning: 'dvb_create_media_entity' defined but not used [-Wunused-function]
    static int dvb_create_media_entity(struct dvb_device *dvbdev,
    ^

    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Currently, v4l2_device_register() doesn't use the media_device
    struct. So, calling media_device_init() could be called either
    before or after v4l2_device_register().

    Yet, it is a good practice to initialize everything before calling
    the register functions. Also, the other drivers call
    media_device_init() before registering the V4L2 device.

    So, move the call for media_device_init() to happen earlier on
    exynos4-is and s3c-camif.

    This is just a cleanup patch.

    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • While we need to keep a u64 alignment to avoid compat32 issues,
    having the number of entities/pads/links/interfaces represented
    by an u64 is incoherent with the ID number, with is an u32.

    In order to make it coherent, change those quantities to u32.

    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • media_device_register_entity() is protected by a spin_lock.

    Calling ida_pre_get() with GFP_KERNEL may put it to sleep,
    with is a bad idea and causes this warning:

    [ 8812.397195] BUG: sleeping function called from invalid context at mm/slub.c:1287
    [ 8812.397203] in_atomic(): 1, irqs_disabled(): 0, pid: 15179, name: modprobe
    [ 8812.397207] INFO: lockdep is turned off.
    [ 8812.397213] CPU: 2 PID: 15179 Comm: modprobe Tainted: G B 4.4.0-rc2+ #41
    [ 8812.397218] Hardware name: /NUC5i7RYB, BIOS RYBDWi35.86A.0350.2015.0812.1722 08/12/2015
    [ 8812.397222] 0000000000000000 ffff880314c77268 ffffffff818f8ba7 ffff8803b17dde00
    [ 8812.397232] ffff880314c77290 ffffffff811c2ee5 ffff8803b17dde00 ffffffff8284dbc9
    [ 8812.397241] 0000000000000507 ffff880314c772d0 ffffffff811c30d5 0000000041b58ab3
    [ 8812.397250] Call Trace:
    [ 8812.397258] [] dump_stack+0x4b/0x64
    [ 8812.397265] [] ___might_sleep+0x245/0x3a0
    [ 8812.397270] [] __might_sleep+0x95/0x1a0
    [ 8812.397276] [] ? ida_pre_get+0x113/0x250
    [ 8812.397282] [] kmem_cache_alloc+0x197/0x250
    [ 8812.397288] [] ida_pre_get+0x113/0x250
    [ 8812.397293] [] ida_simple_get+0xa5/0x170
    [ 8812.397298] [] ? ida_pre_get+0x250/0x250
    [ 8812.397306] [] media_device_register_entity+0x171/0x420 [media]
    [ 8812.397318] [] v4l2_device_register_subdev+0x34f/0x640 [videodev]
    [ 8812.397324] [] v4l2_i2c_new_subdev_board+0x12a/0x250 [v4l2_common]
    [ 8812.397330] [] v4l2_i2c_new_subdev+0xd7/0x110 [v4l2_common]
    [ 8812.397337] [] ? v4l2_i2c_new_subdev_board+0x250/0x250 [v4l2_common]
    [ 8812.397347] [] au0828_card_analog_fe_setup+0x2e6/0x3f0 [au0828]
    [ 8812.397352] [] ? power_down+0xc4/0xc4
    [ 8812.397361] [] ? au0828_tuner_callback+0x160/0x160 [au0828]
    [ 8812.397370] [] au0828_card_setup+0x11f/0x340 [au0828]
    [ 8812.397378] [] ? au0828_card_analog_fe_setup+0x3f0/0x3f0 [au0828]
    [ 8812.397384] [] ? msleep+0x7b/0xc0
    [ 8812.397393] [] au0828_usb_probe+0x679/0xcf0 [au0828]
    [ 8812.397399] [] usb_probe_interface+0x45d/0x940
    [ 8812.397406] [] driver_probe_device+0x454/0xd90
    [ 8812.397411] [] ? driver_probe_device+0xd90/0xd90
    [ 8812.397417] [] ? driver_probe_device+0xd90/0xd90
    [ 8812.397422] [] __driver_attach+0x121/0x160
    [ 8812.397427] [] bus_for_each_dev+0x11f/0x1a0
    [ 8812.397433] [] ? subsys_dev_iter_exit+0x10/0x10
    [ 8812.397439] [] ? _raw_spin_unlock+0x27/0x40
    [ 8812.397445] [] driver_attach+0x3d/0x50
    [ 8812.397450] [] bus_add_driver+0x4c9/0x770
    [ 8812.397456] [] driver_register+0x18c/0x3b0
    [ 8812.397462] [] ? __raw_spin_lock_init+0x32/0x100
    [ 8812.397468] [] usb_register_driver+0x1f8/0x440
    [ 8812.397473] [] ? 0xffffffffa0208000
    [ 8812.397481] [] au0828_init+0xb7/0x1000 [au0828]
    [ 8812.397486] [] do_one_initcall+0x141/0x300
    [ 8812.397492] [] ? try_to_run_init_process+0x40/0x40
    [ 8812.397497] [] ? trace_hardirqs_on_caller+0x16/0x590
    [ 8812.397502] [] ? kasan_unpoison_shadow+0x36/0x50
    [ 8812.397507] [] ? kasan_unpoison_shadow+0x36/0x50
    [ 8812.397512] [] ? kasan_unpoison_shadow+0x36/0x50
    [ 8812.397517] [] ? __asan_register_globals+0x87/0xa0
    [ 8812.397524] [] do_init_module+0x1d0/0x5a4
    [ 8812.397530] [] load_module+0x6648/0x9d70
    [ 8812.397535] [] ? symbol_put_addr+0x50/0x50
    [ 8812.397546] [] ? module_frob_arch_sections+0x20/0x20
    [ 8812.397552] [] ? open_exec+0x50/0x50
    [ 8812.397559] [] ? ns_capable+0x5b/0xd0
    [ 8812.397565] [] SyS_finit_module+0x108/0x130
    [ 8812.397571] [] ? SyS_init_module+0x1f0/0x1f0
    [ 8812.397576] [] ? lockdep_sys_exit_thunk+0x12/0x14
    [ 8812.397582] [] entry_SYSCALL_64_fastpath+0x16/0x7a

    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • The DVB drivers may have 257 PADs. Get the next power of two
    that would accomodate that amount.

    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • There are two ancillary functions that are missing comments.

    While those are used only internally at media-entity.c,
    document them, for completeness.

    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Instead of using one u32 counter per type for object IDs, use
    just one counter. With such change, it makes sense to simplify
    the debug logs too.

    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Several parameters added by the media_ent_enum patches
    were declared with wrong argument names:
    include/media/media-device.h:333: warning: No description found for parameter 'entity_internal_idx_max'
    include/media/media-device.h:354: warning: No description found for parameter 'ent_enum'
    include/media/media-device.h:354: warning: Excess function parameter 'e' description in 'media_entity_enum_init'
    include/media/media-device.h:333: warning: No description found for parameter 'entity_internal_idx_max'
    include/media/media-device.h:354: warning: No description found for parameter 'ent_enum'
    include/media/media-device.h:354: warning: Excess function parameter 'e' description in 'media_entity_enum_init'
    include/media/media-entity.h:397: warning: No description found for parameter 'ent_enum'
    include/media/media-entity.h:397: warning: Excess function parameter 'e' description in 'media_entity_enum_zero'
    include/media/media-entity.h:409: warning: No description found for parameter 'ent_enum'
    include/media/media-entity.h:409: warning: Excess function parameter 'e' description in 'media_entity_enum_set'
    include/media/media-entity.h:424: warning: No description found for parameter 'ent_enum'
    include/media/media-entity.h:424: warning: Excess function parameter 'e' description in 'media_entity_enum_clear'
    include/media/media-entity.h:441: warning: No description found for parameter 'ent_enum'
    include/media/media-entity.h:441: warning: Excess function parameter 'e' description in 'media_entity_enum_test'
    include/media/media-entity.h:458: warning: No description found for parameter 'ent_enum'
    include/media/media-entity.h:458: warning: Excess function parameter 'e' description in 'media_entity_enum_test_and_set'
    include/media/media-entity.h:474: warning: No description found for parameter 'ent_enum'
    include/media/media-entity.h:474: warning: Excess function parameter 'e' description in 'media_entity_enum_empty'
    include/media/media-entity.h:474: warning: Excess function parameter 'entity' description in 'media_entity_enum_empty'
    include/media/media-entity.h:489: warning: No description found for parameter 'ent_enum1'
    include/media/media-entity.h:489: warning: No description found for parameter 'ent_enum2'
    include/media/media-entity.h:489: warning: Excess function parameter 'e' description in 'media_entity_enum_intersects'
    include/media/media-entity.h:489: warning: Excess function parameter 'f' description in 'media_entity_enum_intersects'

    Fix them.

    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • This function was added recently, but weren't documented.
    Add documentation for it.

    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Some exported functions were still documented at the .c file,
    instead of documenting at the .h one.

    Move the documentation to the right place, as we only use headers
    at media device-drivers.xml DocBook.

    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • This isn't really a part of any interface drivers are expected to use. In
    order to keep drivers from using it, hide it in media-entity.c. This was
    always an arbitrary number and should be removed in the long run.

    Signed-off-by: Sakari Ailus
    Signed-off-by: Mauro Carvalho Chehab

    Sakari Ailus
     
  • The bitmaps for entity enumerations used to be statically allocated. Now
    that the drivers have been converted to use the new interface which
    explicitly initialises the enum objects, drop the pre-allocated bitmaps.

    Signed-off-by: Sakari Ailus
    Signed-off-by: Mauro Carvalho Chehab

    Sakari Ailus
     
  • The media graph walk requires initialisation and cleanup soon. Update the
    users to perform the soon necessary API calls.

    Signed-off-by: Sakari Ailus
    Cc: Prabhakar Lad
    Signed-off-by: Mauro Carvalho Chehab

    Sakari Ailus
     
  • The media graph walk requires initialisation and cleanup soon. Update the
    users to perform the soon necessary API calls.

    Signed-off-by: Sakari Ailus
    Signed-off-by: Mauro Carvalho Chehab

    Sakari Ailus
     
  • Instead of using a bitmap directly in a driver, use the new media
    entity enumeration interface to perform the same.

    Signed-off-by: Sakari Ailus
    Signed-off-by: Mauro Carvalho Chehab

    Sakari Ailus
     
  • The same bug was present in the omap4iss driver as was in the omap3isp
    driver. The code got copied to the omap4iss driver while broken. Fix the
    omap4iss driver as well.

    Signed-off-by: Sakari Ailus
    Signed-off-by: Mauro Carvalho Chehab

    Sakari Ailus
     
  • Instead of using a bitmap directly in a driver, use the new media entity
    enumeration interface to perform the same.

    Signed-off-by: Sakari Ailus
    Signed-off-by: Mauro Carvalho Chehab

    Sakari Ailus
     
  • Instead of using a bitmap directly in a driver, use the new media entity
    enumeration interface to perform the same.

    Signed-off-by: Sakari Ailus
    Signed-off-by: Mauro Carvalho Chehab

    Sakari Ailus
     
  • Initialise a given graph walk object once, and then keep using it whilst
    the same pipeline is running. Once the pipeline is stopped, release the
    graph walk object.

    Signed-off-by: Sakari Ailus
    Signed-off-by: Mauro Carvalho Chehab

    Sakari Ailus
     
  • This will also mean that the necessary graph related data structures will
    be allocated dynamically, removing the need for maximum ID checks.

    Signed-off-by: Sakari Ailus
    Signed-off-by: Mauro Carvalho Chehab

    Sakari Ailus
     
  • The media graph walk requires initialisation and cleanup soon. Update the
    users to perform the soon necessary API calls.

    Signed-off-by: Sakari Ailus
    Signed-off-by: Mauro Carvalho Chehab

    Sakari Ailus
     
  • The media graph walk requires initialisation and cleanup soon. Update the
    users to perform the soon necessary API calls.

    Signed-off-by: Sakari Ailus
    Cc: Hyun Kwon
    Signed-off-by: Mauro Carvalho Chehab

    Sakari Ailus
     
  • The media graph walk requires initialisation and cleanup soon. Update the
    users to perform the soon necessary API calls.

    Signed-off-by: Sakari Ailus
    Cc: Javier Martinez Canillas
    Cc: Kamil Debski
    Cc: Sylwester Nawrocki
    Signed-off-by: Mauro Carvalho Chehab

    Sakari Ailus
     
  • The media graph walk requires initialisation and cleanup soon. Update the
    users to perform the soon necessary API calls.

    Signed-off-by: Sakari Ailus
    Signed-off-by: Mauro Carvalho Chehab

    Sakari Ailus
     
  • The media graph walk requires initialisation and cleanup soon. Update the
    users to perform the soon necessary API calls.

    Signed-off-by: Sakari Ailus
    Signed-off-by: Mauro Carvalho Chehab

    Sakari Ailus
     
  • Add media_entity_graph_walk_init() and media_entity_graph_walk_cleanup()
    functions in order to dynamically allocate memory for the graph. This is
    not done in media_entity_graph_walk_start() as there are situations where
    e.g. correct error handling, that itself may not fail, requires successful
    graph walk.

    Signed-off-by: Sakari Ailus
    Signed-off-by: Mauro Carvalho Chehab

    Sakari Ailus
     
  • The struct media_entity_graph was allocated in the stack, limiting the
    number of entities that could be reasonably allocated. Instead, move the
    struct to struct media_pipeline which is typically allocated using
    kmalloc() instead.

    The intent is to keep the enumeration around for later use for the
    duration of the streaming. As streaming is eventually stopped, an
    unfortunate memory allocation failure would prevent stopping the
    streaming. As no memory will need to be allocated, the problem is avoided
    altogether.

    Signed-off-by: Sakari Ailus
    Reviewed-by: Mauro Carvalho Chehab
    Signed-off-by: Mauro Carvalho Chehab

    Sakari Ailus
     
  • KernelDoc doesn't appear to handle anonymous structs defined inside
    another gracefully. As the struct is internal to the framework graph walk
    algorithm, detailed documentation isn't seen very important.

    Signed-off-by: Sakari Ailus
    Signed-off-by: Mauro Carvalho Chehab

    Sakari Ailus
     
  • It will be needed in struct media_pipeline shortly.

    Signed-off-by: Sakari Ailus
    Signed-off-by: Mauro Carvalho Chehab

    Sakari Ailus
     
  • This is useful in e.g. knowing whether certain operations have already
    been performed for an entity. The users include the framework itself (for
    graph walking) and a number of drivers.

    Signed-off-by: Sakari Ailus
    Signed-off-by: Mauro Carvalho Chehab

    Sakari Ailus
     
  • The internal index can be used internally by the framework in order to keep
    track of entities for a purpose or another. The internal index is constant
    while it's registered to a media device, but the same index may be re-used
    once the entity having that index is unregistered.

    Signed-off-by: Sakari Ailus
    Signed-off-by: Mauro Carvalho Chehab

    Sakari Ailus
     
  • We need to set "err = -ENOMEM" here.

    Fixes: 38b11f19667a ('[media] v4l2-core: create MC interfaces for devnodes')

    Signed-off-by: Dan Carpenter
    Signed-off-by: Mauro Carvalho Chehab

    Dan Carpenter
     
  • The copy_to/from_user() functions return the number of bytes *not*
    copied. They don't return error codes.

    Fixes: 4f6b3f363475 ('media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl')

    Signed-off-by: Dan Carpenter
    Signed-off-by: Mauro Carvalho Chehab

    Dan Carpenter
     
  • The G_TOPOLOGY ioctl is used to get a graph topology and since in the
    future a graph can be dynamically updated, there is a way to know the
    topology version so userspace can be aware that the graph has changed.

    The version 0 is reserved to indicate that the graph is static (i.e no
    graphs updates since the media device was registered).

    So, now that the media device initialization and registration has been
    split and the media device node is not exposed to user-space until all
    the entities have been registered and links created, it is safe to set
    a topology version 0 in media_device_register().

    Suggested-by: Laurent Pinchart
    Suggested-by: Mauro Carvalho Chehab
    Signed-off-by: Javier Martinez Canillas
    Signed-off-by: Mauro Carvalho Chehab

    Javier Martinez Canillas
     
  • Registering a V4L2 sub-device includes, among other things, registering
    the related media entity and calling the sub-device's registered op. Since
    patch "media: convert links from array to list", creating a link between
    two pads requires registering the entity first. If the registered() op
    involves link creation, the link list head will not be initialised before
    it is used.

    Resolve this by first registering the entity, then calling its
    registered() op.

    Signed-off-by: Sakari Ailus
    Signed-off-by: Mauro Carvalho Chehab

    Sakari Ailus
     
  • There are now two new warnings:

    drivers/media/usb/dvb-usb-v2/dvb_usb_core.c: In function 'dvb_usbv2_media_device_register':
    drivers/media/usb/dvb-usb-v2/dvb_usb_core.c:433:2: warning: ignoring return value of '__media_device_register', declared with attribute warn_unused_result [-Wunused-result]
    media_device_register(adap->dvb_adap.mdev);
    ^
    drivers/media/usb/dvb-usb/dvb-usb-dvb.c: In function 'dvb_usb_media_device_register':
    drivers/media/usb/dvb-usb/dvb-usb-dvb.c:128:2: warning: ignoring return value of '__media_device_register', declared with attribute warn_unused_result [-Wunused-result]
    media_device_register(adap->dvb_adap.mdev);
    ^

    Those are because the drivers are not properly checking if the
    media device init and register were succeeded.

    Fix it.

    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • The media device node is registered and so made visible to user-space
    before entities are registered and links created which means that the
    media graph obtained by user-space could be only partially enumerated
    if that happens too early before all the graph has been created.

    To avoid this race condition, split the media init and registration
    in separate functions and only register the media device node when
    all the pending subdevices have been registered, either explicitly
    by the driver or asynchronously using v4l2_async_register_subdev().

    The media_device_register() had a check for drivers not filling dev
    and model fields but all drivers in mainline set them and not doing
    it will be a driver bug so change the function return to void and
    add a BUG_ON() for dev being NULL instead.

    Also, add a media_device_cleanup() function that will destroy the
    graph_mutex that is initialized in media_device_init().

    [mchehab@osg.samsung.com: Fix compilation if !CONFIG_MEDIA_CONTROLLER
    and remove two warnings added by this changeset]
    Suggested-by: Sakari Ailus
    Signed-off-by: Javier Martinez Canillas
    Acked-by: Sakari Ailus
    Signed-off-by: Mauro Carvalho Chehab

    Javier Martinez Canillas