[media] media-device: move media entity register/unregister functions
media entity register and unregister functions are called by media
device register/unregister. Move them to occur earlier, as we'll need
an unlocked version of media_device_entity_unregister() and we don't
want to add a function prototype without needing it.
[media] media-device: check before unregister if mdev was registered
Most media functions that unregister, check if the corresponding register
function succeed before. So these functions can safely be called even if a
registration was never made or the component as already been unregistered.
Add the same check to media_device_unregister() function for consistency.
This will also allow to split the media_device_register() function in an
initialization and registration functions without the need to change the
generic cleanup functions and error code paths for all the media drivers.
Suggested-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com> Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
[media] media-entity: cache media_device on object removal
As pointed by Dan, the commit f8fd4c61b5ae ("[media] media-entity:
protect object creation/removal using spin lock")' leads to the
following static checker warning:
In practice, I didn't see any troubles even with KASAN enabled. I guess
gcc optimizer internally cached the mdev reference, instead of getting
it twice. Yet, it is a very bad idea to rely on such optimization. So,
let's fix the code.
Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Changeset f8fd4c61b5ae ("[media] media-entity: protect object
creation/removal using spin lock") changed the object creation/removal
protection to spin lock, as this is what's used on media-device,
keeping the mutex reserved for graph traversal routines. However, it
also changed the link setup, by mistake.
This could cause troubles, as the link setup can affect the graph
traversal, and this is likely the reason for a mutex there.
So, revert media_entity_setup_link() to use mutex.
Sakari Ailus [Sun, 29 Nov 2015 19:20:02 +0000 (17:20 -0200)]
[media] media: Enforce single entity->pipe in a pipeline
If a different entity->pipe in a pipeline was encountered, a warning was
issued but the execution continued as if nothing had happened. Return an
error instead right there.
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
[media] DocBook: move data types to a separate section
As MEDIA_IOC_G_TOPOLOGY shares the data types already declared
for entities, pads and links, we should move those to a separate
part of the document, and use cross-references where needed.
So, move the following tables to a separate section at the
DocBook:
media-entity-type
media-entity-flag
media-pad-flag
media-link-flag
[media] DocBook: MC: add the concept of interfaces
The Media Controller next generation patches added a new graph
element type: interfaces. It also allows links between interfaces
and entities. Update the docbook to reflect that.
[media] media: move MEDIA_LNK_FL_INTERFACE_LINK logic to link creation
Instead of flagging an interface link as MEDIA_LNK_FL_INTERFACE_LINK
only when returning to userspace, do it at link creation time.
That would allow using such flag internally, and cleans up a
little bit the code for G_TOPOLOGY ioctl.
[mchehab@osg.samsung.com: folded with a fixup from Dan Carpenter,
replacing & by &&] Suggested-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Commit 86ee417578a2 ("[media] media: convert links from array to list")
had many changes that were automated using coccinelle but the semantic
patch was not smart enough to rely on operators precedence and avoid
using unnecessary enclosing parenthesis.
The uvc_mc_register_entities() function iterated over the entities three
times to initialize the entities, register the subdev for the ones whose
type was UVC_TT_STREAMING and to create the entities links.
But this can be simplied by merging the init and registration logic in a
single loop.
[media] uvcvideo: remove pads prefix from uvc_mc_create_pads_links()
The function uvc_mc_create_pads_links() creates entities links but the
"pads" prefix is redundant since the driver doesn't handle any other
kind of link, so it can be removed.
[media] v4l: vsp1: use else if instead of continue when creating links
The for loop in the vsp1_create_entities() function that create the links,
checks the entity type and call the proper link creation function but then
it uses continue to force the next iteration of the loop to take place and
skipping code in between that creates links for different entities types.
It is more readable and easier to understand if the if else constructs is
used instead of the continue statement.
[media] v4l: vsp1: remove pads prefix from *_create_pads_links()
The functions that create entities links are called *_create_pads_links()
but the "pads" prefix is redundant since the driver doesn't handle any
other kind of link so it can be removed.
[media] staging: omap4iss: remove pads prefix from *_create_pads_links()
The functions that create ISS internal and external entities links are
called *_create_pads_links() but the "pads" prefix is redundant since
the driver doesn't handle any other kind of link so it can be removed.
[media] omap3isp: consistently use v4l2_dev var in complete notifier
The isp_subdev_notifier_complete() complete callback defines a struct
v4l2_device *v4l2_dev to avoid needing two level of indirections to
access the V4L2 subdevs but the var is not always used when possible
as when calling v4l2_device_register_subdev_nodes().
So change that to consistently use the defined v4l2_dev pointer var.
Suggested-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
[media] omap3isp: rename single labels to just error
Commit bc36b30fe06b ("[media] omap3isp: separate links creation from
entities init") moved the link creation logic from the entities init
functions and so removed the error_link labels from the error paths.
But after that, some functions have a single error label so it makes
more sense to rename the label to just "error" in thi case.
[media] omap3isp: remove pads prefix from isp_create_pads_links()
The function that creates the links between ISP internal and external
entities is called isp_create_pads_links() but the "pads" prefix is
redundant since the driver doesn't handle any other kind of link so
it can just be removed.
While being there, fix the function's kernel-doc since is not using
a proper format.
[media] omap3isp: remove per ISP module link creation functions
The entities to video nodes links were created on separate functions for
each ISP module but since the only thing that these functions do is to
call media_create_pad_link(), there's no need for that indirection level
and all link creation logic can be just inlined in the caller function.
Also, since the only possible failure for the link creation is a memory
allocation, there is no need for error messages since the core already
reports a very verbose message in that case.
[media] media-entity.h: move kernel-doc tags from media-entity.c
Several additional functions are described at media-entity.c.
Moving them to the header file, to make the code cleaner and
to have all such macros at the same place.
[media] media_entity: rename media_obj functions to *_create *_destroy
Those media_obj_* functions are actually creating/destroying
media graph objects. So, rename them to better represent
what they're actually doing.
No functional changes.
This was created via this small shell script:
for i in $(git grep -l media_gobj_init); do sed s,media_gobj_init,media_gobj_create,g <$i >a && mv a $i; done
for i in $(git grep -l media_gobj_remove); do sed s,media_gobj_remove,media_gobj_destroy,g <$i >a && mv a $i; done
Suggested-by: Sakari Ailus <sakari.ailus@iki.fi> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
[media] media-device.h: Improve documentation and update it
Now that we moved the content of the media-framework.txt into
the kerneldoc documentation, move the per-function specific
documentation to the corresponding functions and clean it up.
It would be good if we had already the markdown kernel-doc
patches merged upstream, but, while we doesn't have it,
let's make it less ugly at device-drivers.xml.
[media] media-entity.h: convert media_entity_cleanup to inline
This function was used in the past to free the links
that were allocated by the media controller core.
However, this is not needed anymore. We should likely
get rid of the funcion on some function, but, for now,
let's just convert into an inlined function and let the
compiler to get rid of it.
[media] media framework: rename pads init function to media_entity_pads_init()
With the MC next gen rework, what's left for media_entity_init()
is to just initialize the PADs. However, certain devices, like
a FLASH led/light doesn't have any input or output PAD.
So, there's no reason why calling media_entity_init() would be
mandatory. Also, despite its name, what this function actually
does is to initialize the PADs data. So, rename it to
media_entity_pads_init() in order to reflect that.
The media entity actual init happens during entity register,
at media_device_register_entity(). We should move init of
num_links and num_backlinks to it.
[media] media-device: better name Kernelspace/Userspace links
The __media_device_enum_links() copies links definitions from
Kernelspace to userspace. It has to work with 3 structs that
handle with links. Better name them to:
link: Kernelspace internal link representation, of the
type media_link;
klink_desc: struct media_link_desc pointer to the
kernel memory where the data will be filled;
ulink_desc: struct media_link_desc pointer to the
memory where the data will be copied to
userspace.
[media] media-entity: init pads on entity init if was registered before
If an entity is registered with a media device before is initialized
with media_device_register_entity(), the number of pads won't be set
so media_device_register_entity() won't create pad objects and add
it to the media device pads list.
Do this at entity initialization time if the entity was registered
before so the graph is complete and correct regardless of the order
in which the entities are initialized and registered.
[media] media-device: use unsigned ints on some places
The entity->num_pads are defined as u16. So, better to use an
unsigned int, as this prevents additional warnings when W=2
(or W=1 on some architectures).
The "i" counter at __media_device_get_topology() is also a
monotonic counter that should never be below zero. So,
make it unsigned too.
Suggested-by: Sakari Ailus <sakari.ailus@iki.fi> Acked-by: Hans Verkuil <hans.verkuil@cisco.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
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 <sakari.ailus@iki.fi> Acked-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
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 <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
[media] media-device: export the entity function via new ioctl
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 <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
[media] v4l2 core: enable all interface links at init
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 <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
[media] media-device: supress backlinks at G_TOPOLOGY ioctl
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 <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
[media] dvbdev: returns error if graph object creation fails
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 <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
[media] media-entity: fix backlink removal on __media_entity_remove_link()
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.
[media] media: don't try to empty links list in media_entity_cleanup()
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@osg.samsung.com>
[media] au0828: postpone call to au0828_unregister_media_device()
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.
[media] dvbdev: enable all interface links at init
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 <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
[media] media-entity: protect object creation/removal using spin lock
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
[media] media_device: add a topology version field
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 <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
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 <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
[media] dvb: modify core to implement interfaces/entities at MC new gen
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 <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
[media] DocBook: update descriptions for the media controller entities
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.
This sensor driver is abusing MEDIA_ENT_T_V4L2_SUBDEV, creating
some subdevs with a non-existing type.
As this is a sensor driver, one of the entries is
MEDIA_ENT_T_CAM_SENSOR. The other one will be using
MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN, because the subdev is not
any of the already existing types.
[media] omap3/omap4/davinci: get rid of MEDIA_ENT_T_V4L2_SUBDEV abuse
On omap3/omap4/davinci drivers, MEDIA_ENT_T_V4L2_SUBDEV macro is
abused in order to "simplify" the pad checks.
Basically, it does a logical or of this macro, in order to check
for a local index and if the entity is either a subdev or not.
As we'll get rid of MEDIA_ENT_T_V4L2_SUBDEV macro, replace it by
2 << 16 where it occurs, and add a note saying that the code
there is actually a hack.
[media] media: use macros to check for V4L2 subdev entities
Instead of relying on media subtype, use the new macros to detect
if an entity is a subdev or an A/V DMA entity.
Please note that most drivers assume that there's just AV_DMA or
V4L2 subdevs. This is not true anymore, as we've added MC support
for DVB, and there are plans to add support for ALSA and FB/DRM
too.
Ok, on the current pipelines supported by those drivers, just V4L
stuff are there, but, assuming that some day a pipeline that also
works with other subsystems will ever added, it is better to add
explicit checks for the AV_DMA stuff.
[media] media: add macros to check if subdev or V4L2 DMA
As we'll be removing entity subtypes from the Kernel, we need
to provide a way for drivers and core to check if a given
entity is represented by a V4L2 subdev or if it is an V4L2
I/O entity (typically with DMA).
Drivers that create entities that don't belong to any defined subdev
category should use MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN.
Acked-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
[media] replace all occurrences of MEDIA_ENT_T_DEVNODE_DVB
Now that interfaces and entities are distinct, it makes no sense
of keeping something named as MEDIA_ENT_T_DEVNODE_DVB_foo.
Made via this script:
for i in $(git grep -l MEDIA_ENT_T|grep -v uapi/linux/media.h); do sed s,MEDIA_ENT_T_DEVNODE_DVB_,MEDIA_ENT_T_DVB_, <$i >a && mv a $i; done
for i in $(git grep -l MEDIA_ENT_T|grep -v uapi/linux/media.h); do sed s,MEDIA_ENT_T_DVB_DVR,MEDIA_ENT_T_DVB_TSOUT, <$i >a && mv a $i; done
for i in $(git grep -l MEDIA_ENT_T|grep -v uapi/linux/media.h); do sed s,MEDIA_ENT_T_DVB_FE,MEDIA_ENT_T_DVB_DEMOD, <$i >a && mv a $i; done
for i in $(git grep -l MEDIA_ENT_T|grep -v uapi/linux/media.h); do sed s,MEDIA_ENT_T_DVB_NET,MEDIA_ENT_T_DVB_DEMOD_NET_DECAP, <$i >a && mv a $i; done
Acked-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Now that the infrastruct for that is set, add support for
interfaces.
Please notice that we're missing two links:
DVB FE intf -> tuner
DVB demux intf -> dvr
Those should be added latter, after having the entire graph
set. With the current infrastructure, those should be added
at dvb_create_media_graph(), but it would also require some
extra core changes, to allow the function to enumerate the
interfaces.
Acked-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>