11 Jan, 2016

40 commits

  • We should not be creating device nodes at IRQ contexts. So,
    the only flags we'll be using will be GFP_KERNEL. Let's
    remove the gfp_flags, in order to make the interface simpler.

    If we ever need it, it would be easy to revert those changes.

    While here, remove an extra blank line.

    Suggested-by: Sakari Ailus
    Acked-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Indirect links are those whose interface indirectly controls
    other functions.

    There are two interfaces that have indirect controls at the DVB
    side:
    - the network interface, which also controls the demux;
    - the DVR interface which also controls the demux.

    One could argue that the frontend control to the tuner is indirect.
    Well, that's debatable. There's no way to create subdev interfaces
    for tuner and demod, as those devices are tightly coupled. So, it
    was decided that just one interface is the best to control both
    entities, and there's no plan (or easy way) to decouple both. So,
    the DVB frontend interface should link to both entities.

    Acked-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Cleanup the code a little bit by moving the routine that creates
    links between DVR and demux to the I/O entitis into a separate
    function.

    While here, fix the code to use strncmp() instead of strcmp().

    Acked-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Due to the rename, the documentation became outdated.

    Update it to reflect what's there at media.h.

    Acked-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Rename the userspace types from MEDIA_ENT_T_ to MEDIA_ENT_F_
    and add the backward compatibility bits.

    The changes at the .c files was generated by the following
    coccinelle script:

    @@
    @@
    -MEDIA_ENT_T_UNKNOWN
    +MEDIA_ENT_F_UNKNOWN
    @@
    @@
    -MEDIA_ENT_T_DVB_BASE
    +MEDIA_ENT_F_DVB_BASE
    @@
    @@
    -MEDIA_ENT_T_V4L2_BASE
    +MEDIA_ENT_F_V4L2_BASE
    @@
    @@
    -MEDIA_ENT_T_V4L2_SUBDEV_BASE
    +MEDIA_ENT_F_V4L2_SUBDEV_BASE
    @@
    @@
    -MEDIA_ENT_T_CONNECTOR_BASE
    +MEDIA_ENT_F_CONNECTOR_BASE
    @@
    @@
    -MEDIA_ENT_T_V4L2_VIDEO
    +MEDIA_ENT_F_IO_V4L
    @@
    @@
    -MEDIA_ENT_T_V4L2_VBI
    +MEDIA_ENT_F_IO_VBI
    @@
    @@
    -MEDIA_ENT_T_V4L2_SWRADIO
    +MEDIA_ENT_F_IO_SWRADIO
    @@
    @@
    -MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN
    +MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN
    @@
    @@
    -MEDIA_ENT_T_CONN_RF
    +MEDIA_ENT_F_CONN_RF
    @@
    @@
    -MEDIA_ENT_T_CONN_SVIDEO
    +MEDIA_ENT_F_CONN_SVIDEO
    @@
    @@
    -MEDIA_ENT_T_CONN_COMPOSITE
    +MEDIA_ENT_F_CONN_COMPOSITE
    @@
    @@
    -MEDIA_ENT_T_CONN_TEST
    +MEDIA_ENT_F_CONN_TEST
    @@
    @@
    -MEDIA_ENT_T_V4L2_SUBDEV_SENSOR
    +MEDIA_ENT_F_CAM_SENSOR
    @@
    @@
    -MEDIA_ENT_T_V4L2_SUBDEV_FLASH
    +MEDIA_ENT_F_FLASH
    @@
    @@
    -MEDIA_ENT_T_V4L2_SUBDEV_LENS
    +MEDIA_ENT_F_LENS
    @@
    @@
    -MEDIA_ENT_T_V4L2_SUBDEV_DECODER
    +MEDIA_ENT_F_ATV_DECODER
    @@
    @@
    -MEDIA_ENT_T_V4L2_SUBDEV_TUNER
    +MEDIA_ENT_F_TUNER
    @@
    @@
    -MEDIA_ENT_T_DVB_DEMOD
    +MEDIA_ENT_F_DTV_DEMOD
    @@
    @@
    -MEDIA_ENT_T_DVB_DEMUX
    +MEDIA_ENT_F_TS_DEMUX
    @@
    @@
    -MEDIA_ENT_T_DVB_TSOUT
    +MEDIA_ENT_F_IO_DTV
    @@
    @@
    -MEDIA_ENT_T_DVB_CA
    +MEDIA_ENT_F_DTV_CA
    @@
    @@
    -MEDIA_ENT_T_DVB_NET_DECAP
    +MEDIA_ENT_F_DTV_NET_DECAP

    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Now that entities have a main function, expose it via
    MEDIA_IOC_G_TOPOLOGY ioctl.

    Please notice that some entities may have secundary functions.
    Such use case will be addressed later, when we add support for the
    Media Controller properties.

    Acked-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Entities should have one or more functions. Calling it as a
    type proofed to not be correct, as an entity could eventually
    have more than one type.

    So, rename the field as function.

    Please notice that this patch doesn't extend support for
    multiple function entities. Such change will happen when
    we have real case drivers using it.

    No functional changes.

    Acked-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Drivers should check if media_create_pad_link() actually
    worked.

    Acked-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • If the graph creation fails, don't register the device.

    Acked-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • If the graph creation fails, don't register the device.

    Acked-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Drivers should check if interfaces and interface links were
    created. Add a must_check for them.

    Acked-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • If media controller is enabled and mdev is filled, it should
    ensure that the media graph will be properly initialized.

    Enforce that.

    Acked-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Interface links are normally enabled, meaning that the interfaces are
    bound to the entities. So, any ioctl send to the interface are reflected
    at the entities managed by the interface.

    However, when a device is used, other interfaces for the same hardware
    could be decoupled from the entities linked to them, because the
    hardware may have some parts busy.

    That's for example, what happens when an hybrid TV device is in use.
    If it is streaming analog TV or capturing signals from S-Video/Composite
    connectors, typically the digital part of the hardware can't be used and
    vice-versa.

    This is generally due to some internal hardware or firmware limitation,
    that it is not easily mapped via data pipelines.

    What the Kernel drivers do internally is that they decouple the hardware
    from the interface. So, all changes, if allowed, are done only at some
    interface cache, but not physically changed at the hardware.

    The usage is similar to the usage of the MEDIA_LNK_FL_ENABLED on data
    links. So, let's use the same flag to indicate if either the interface
    to entity link is bound/enabled or not.

    Acked-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Due to the graph traversal algorithm currently in usage, we
    need a copy of all data links. Those backlinks should not be
    send to userspace, as otherwise, all links there will be
    duplicated.

    Acked-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Now that connectors are entities, we need to represent the
    connector links.

    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Depending on the input, an au0828 may have a different
    number of connectors. add entities to represent them.

    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Add entities to represent the connectors that exists inside a
    hybrid TV device.

    Acked-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Only a few structs are documented on kernel-doc-nano format
    (the ones added by the MC next gen patches).

    Add a documentation for all structs, and ensure that they'll
    be producing the documentation at the Kernel's device driver
    DocBook.

    Acked-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • V4L2 device (and subdevice) nodes should create an interface, if the
    Media Controller support is enabled.

    Please notice that radio devices should not create an entity, as radio
    input/output is either via wires or via ALSA.

    Acked-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Right now, if something gets wrong at dvb_create_media_entity()
    or at dvb_create_media_graph(), the device will still be
    registered.

    Change the logic to properly handle it and free all media graph
    objects if something goes wrong at dvb_register_device().

    Also, change the logic at dvb_create_media_graph() to return
    an error code if something goes wrong. It is up to the
    caller to implement the right logic and to call
    dvb_unregister_device() to unregister the already-created
    objects.

    While here, add a missing logic to unregister the created
    interfaces.

    Acked-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • The logic is testing if num_links==0 at the wrong place. Due to
    that, a backlink may be kept without removal, causing KASAN
    to complain about usage after free during either entity or
    link removal.

    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • The media_entity_cleanup() function only cleans up the entity links list
    but this operation is already made in media_device_unregister_entity().

    In most cases this should be harmless (besides having duplicated code)
    since the links list would be empty so the iteration would not happen
    but the links list is initialized in media_device_register_entity() so
    if a driver fails to register an entity with a media device and clean up
    the entity in the error path, a NULL deference pointer error will happen.

    So don't try to empty the links list in media_entity_cleanup() since
    is either done already or haven't been initialized yet.

    Signed-off-by: Javier Martinez Canillas

    Javier Martinez Canillas
     
  • The DVB core needs to unregister the media device. So, we
    can't call au0828_unregister_media_device() before calling
    au0828_dvb_unregister(), otherwise the DVB MC free code
    (that will be implemented on the next patch) will fail.

    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Interface links are normally enabled, meaning that the interfaces are
    bound to the entities. So, any ioctl sent to the interface are reflected
    at the entities managed by the interface.

    However, when a device is in use, other interfaces for the same hardware
    could be decoupled from the entities linked to them, because the
    hardware may have some parts busy.

    That's for example, what happens when an hybrid TV device is in use.
    If it is streaming analog TV or capturing signals from S-Video/Composite
    connectors, typically the digital part of the hardware can't be used and
    vice-versa.

    This is generally due to some internal hardware or firmware limitation,
    that it is not easily mapped via data pipelines.

    What the Kernel drivers do internally is that they decouple the hardware
    from the interface. So, all changes, if allowed, are done only at some
    interface cache, but not physically changed at the hardware.

    The usage is similar to the usage of the MEDIA_LNK_FL_ENABLED on data
    links. So, let's use the same flag to indicate if either the interface
    to entity link is bound/enabled or not.

    Acked-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Tuners actually have at least one connector on its input.

    Add a PAD to connect it.

    Acked-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Some parts of the media controller are using mutexes while
    others are using spin locks in order to protect creation
    and removal of elements in the graph. That's wrong!

    Also, the V4L2 core can remove graph elements on non-interactive
    context:
    BUG: sleeping function called from invalid context at include/linux/sched.h:2776

    Fix it by always using spin locks for graph element addition/removal,
    just like entity creation/removal is protected at media-device.c

    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Just like what's done with entities, when the media controller is
    unregistered, release any interface and interface links that
    might still be there.

    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Interface links connected to an entity should be removed
    before the entity itself can be removed.

    Acked-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Add functions to explicitly unregister all entity links.
    This function is called automatically when an entity
    link is destroyed.

    Acked-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Add support for the new MEDIA_IOC_G_TOPOLOGY ioctl, according
    with the RFC for the MC next generation.

    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Every time a graph object is added or removed, the version
    of the topology changes. That's a requirement for the new
    MEDIA_IOC_G_TOPOLOGY, in order to allow userspace to know
    that the topology has changed after a previous call to it.

    Acked-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • The MC next gen API sends objects to userspace grouped by
    their types.

    In the case of pads and links, in order to improve performance
    and have a simpler code, the best is to store them also on
    separate linked lists at MC.

    If we don't do that, we would need this kind of interaction
    to send data to userspace (code is in structured english):

    for each entity:
    for each pad:
    store pads

    for each entity:
    for each link:
    store link

    for each interface:
    for each link:
    store link

    With would require one nested loop for pads and two nested
    loops for links. By using separate linked lists for them,
    just one loop would be enough.

    Acked-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Let's control the topology changes inside the graph_object. So, move the
    addition and removal of interfaces/entities from the mdev lists to
    media_gobj_init() and media_gobj_remove().

    The main reason is that mdev should have lists for all object types, as
    the new MC api will require to store objects in separate places.

    Acked-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Just like we do with entities, use a similar macro for the
    interfaces loop.

    Acked-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Add a new ioctl that will report the entire topology on
    one go.

    Acked-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Sometimes, it is important to see if the created pad is
    sink or source. Add info to track that.

    Acked-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • The Media Controller New Generation redefines the types for both
    interfaces and entities to be used on DVB. Make the needed
    changes at the DVB core for all interfaces, entities and
    data and interface links to appear in the graph.

    Acked-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Cleanup the media controller entities description:
    - remove MEDIA_ENT_T_DEVNODE and MEDIA_ENT_T_V4L2_SUBDEV entity
    types, as they don't mean anything;
    - add MEDIA_ENT_T_UNKNOWN with a proper description;
    - remove ALSA and FB entity types. Those should not be used, as
    the types are deprecated. We'll soon be adidng ALSA, but with
    a different entity namespace;
    - improve the description of some entities.

    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Put the legacy MEDIA_ENT_* macros under a #ifndef __KERNEL__,
    in order to be sure that none of those old symbols are used
    inside the Kernel.

    Acked-by: Laurent Pinchart
    Acked-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab
     
  • Don't use anymore the type/subtype entity data/macros
    inside the Kernel.

    Acked-by: Hans Verkuil
    Acked-by: Laurent Pinchart
    Signed-off-by: Mauro Carvalho Chehab

    Mauro Carvalho Chehab