Re: [RFC/PATCH v4 08/11] media: Links setup

2010-09-16 Thread Laurent Pinchart
Hi Hans,

On Monday 06 September 2010 19:09:20 Hans Verkuil wrote:
 On Wednesday, September 01, 2010 16:08:29 Laurent Pinchart wrote:
  On Saturday 28 August 2010 13:14:18 Hans Verkuil wrote:
   On Friday, August 20, 2010 17:29:10 Laurent Pinchart wrote:
  [snip]
  
+/**
+ * media_entity_remote_pad - Locate the pad at the remote end of a
link + * @entity: Local entity
+ * @pad: Pad at the local end of the link
+ *
+ * Search for a remote pad connected to the given pad by iterating
over all
+ * links originating or terminating at that pad until an active link
is found.
+ *
+ * Return a pointer to the pad at the remote end of the first found
active link,
+ * or NULL if no active link has been found.
+ */
+struct media_pad *media_entity_remote_pad(struct media_pad *pad)
+{
+   unsigned int i;
+
+   for (i = 0; i  pad-entity-num_links; i++) {
+   struct media_link *link = pad-entity-links[i];
+
+   if (!(link-flags  MEDIA_LINK_FLAG_ACTIVE))
+   continue;
+
+   if (link-source == pad)
+   return link-sink;
+
+   if (link-sink == pad)
+   return link-source;
+   }
+
+   return NULL;
+
+}
   
   Why is this needed? Esp. since there can be multiple active remote pads
   if you have multiple active outgoing links. Something this function
   doesn't deal with.
  
  The function is meant to be used when only one of the links can be
  active. It's most useful to find the entity connected to a given input
  pad, as input pads can't be connected by multiple simultaneously active
  links.
 
 In that case I would rename it media_entity_remote_source to match the use
 case (and only look for remote sources).

OK, I'll rename the function.

 Alternatively you could add an index for the nth active link, then it would
 be truly generic.
 
 Right now the function either does too much or too little :-)

-- 
Regards,

Laurent Pinchart
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC/PATCH v4 08/11] media: Links setup

2010-09-16 Thread Laurent Pinchart
Hi Mauro,

On Thursday 09 September 2010 03:14:44 Mauro Carvalho Chehab wrote:
 Em 20-08-2010 12:29, Laurent Pinchart escreveu:
  Create the following ioctl and implement it at the media device level to
  setup links.
  
  - MEDIA_IOC_SETUP_LINK: Modify the properties of a given link
  
  The only property that can currently be modified is the ACTIVE link flag
  to activate/deactivate a link. Links marked with the IMMUTABLE link flag
  can not be activated or deactivated.
  
  Activating and deactivating a link has effects on entities' use count.
  Those changes are automatically propagated through the graph.
 
 You need to address here the release() call: if the userspace application
 dies or just exits, the device should be set into a sane state, e. g.
 devices powered on should be turned off,

That's already handled, as media_entity_put() is called in the vdev and subdev 
release() functions.

 and links activated by the application should be de-activated.

I don't think that's required. When an application exits with a video device 
node open, we don't reset all controls and formats. Power needs to be turned 
off and resources need to be released on exit, but configuration doesn't need 
to be reset.

-- 
Regards,

Laurent Pinchart
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC/PATCH v4 08/11] media: Links setup

2010-09-08 Thread Mauro Carvalho Chehab
Em 20-08-2010 12:29, Laurent Pinchart escreveu:
 Create the following ioctl and implement it at the media device level to
 setup links.
 
 - MEDIA_IOC_SETUP_LINK: Modify the properties of a given link
 
 The only property that can currently be modified is the ACTIVE link flag
 to activate/deactivate a link. Links marked with the IMMUTABLE link flag
 can not be activated or deactivated.
 
 Activating and deactivating a link has effects on entities' use count.
 Those changes are automatically propagated through the graph.

You need to address here the release() call: if the userspace application
dies or just exits, the device should be set into a sane state, e. g. devices
powered on should be turned off, and links activated by the application
should be de-activated.

 
 Signed-off-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
 Signed-off-by: Stanimir Varbanov svarba...@mm-sol.com
 Signed-off-by: Sakari Ailus sakari.ai...@maxwell.research.nokia.com
 ---
  Documentation/media-framework.txt |   81 ++-
  drivers/media/media-device.c  |   45 
  drivers/media/media-entity.c  |  208 
 +
  include/linux/media.h |1 +
  include/media/media-entity.h  |8 ++
  5 files changed, 340 insertions(+), 3 deletions(-)
 
 diff --git a/Documentation/media-framework.txt 
 b/Documentation/media-framework.txt
 index 74a137d..7894ef3 100644
 --- a/Documentation/media-framework.txt
 +++ b/Documentation/media-framework.txt
 @@ -278,6 +278,16 @@ When the graph traversal is complete the function will 
 return NULL.
  Graph traversal can be interrupted at any moment. No cleanup function call is
  required and the graph structure can be freed normally.
  
 +Helper functions can be used to find a link between two given pads, or a pad
 +connected to another pad through an active link
 +
 + media_entity_find_link(struct media_pad *source,
 +struct media_pad *sink);
 +
 + media_entity_remote_pad(struct media_pad *pad);
 +
 +Refer to the kerneldoc documentation for more information.
 +
  
  Reference counting and power handling
  -
 @@ -316,6 +326,46 @@ is allowed to fail when turning power on, in which case 
 the media_entity_get
  function will return NULL.
  
  
 +Links setup
 +---
 +
 +Link properties can be modified at runtime by calling
 +
 + media_entity_setup_link(struct media_link *link, u32 flags);
 +
 +The flags argument contains the requested new link flags.
 +
 +The only configurable property is the ACTIVE link flag to activate/deactivate
 +a link. Links marked with the IMMUTABLE link flag can not be activated or
 +deactivated.
 +
 +When a link is activated or deactivated, the media framework calls the
 +link_setup operation for the two entities at the source and sink of the link,
 +in that order. If the second link_setup call fails, another link_setup call 
 is
 +made on the first entity to restore the original link flags.
 +
 +Entity drivers must implement the link_setup operation if any of their links
 +is non-immutable. The operation must either configure the hardware or store
 +the configuration information to be applied later.
 +
 +Link activation must not have any side effect on other links. If an active
 +link at a sink pad prevents another link at the same pad from being
 +deactivated, the link_setup operation must return -EBUSY and can't implicitly
 +deactivate the first active link.
 +
 +Activating and deactivating a link has effects on entities' reference counts.
 +When two sub-graphs are connected, the reference count of each of them is
 +incremented by the total reference count of all node entities in the other
 +sub-graph. When two sub-graphs are disconnected, the reverse operation is
 +performed. In both cases the set_power operations are called accordingly,
 +ensuring that the link_setup calls are made with power active on the source
 +and sink entities.
 +
 +In other words, activating or deactivating a link propagates reference count
 +changes through the graph, and the final state is identical to what it would
 +have been if the link had been active or inactive from the start.
 +
 +
  Userspace application API
  -
  
 @@ -439,9 +489,6 @@ Valid entity flags are
  
   ioctl(int fd, int request, struct media_links_enum *argp);
  
 -Only forward links that originate at one of the entity's source pads are
 -returned during the enumeration process.
 -
  To enumerate pads and/or links for a given entity, applications set the 
 entity
  field of a media_links_enum structure and initialize the media_pad_desc and
  media_link_desc structure arrays pointed by the pads and links fields. They 
 then
 @@ -457,6 +504,9 @@ information about the entity's outbound links. The array 
 must have enough room
  to store all the entity's outbound links. The number of outbound links can be
  retrieved with the 

Re: [RFC/PATCH v4 08/11] media: Links setup

2010-09-06 Thread Hans Verkuil
On Wednesday, September 01, 2010 16:08:29 Laurent Pinchart wrote:
 Hi Hans,
 
 On Saturday 28 August 2010 13:14:18 Hans Verkuil wrote:
  On Friday, August 20, 2010 17:29:10 Laurent Pinchart wrote:
 
 [snip]
 
   +/**
   + * media_entity_remote_pad - Locate the pad at the remote end of a link
   + * @entity: Local entity
   + * @pad: Pad at the local end of the link
   + *
   + * Search for a remote pad connected to the given pad by iterating over
   all
   + * links originating or terminating at that pad until an active link is
   found.
   + *
   + * Return a pointer to the pad at the remote end of the first found
   active link,
   + * or NULL if no active link has been found.
   + */
   +struct media_pad *media_entity_remote_pad(struct media_pad *pad)
   +{
   + unsigned int i;
   +
   + for (i = 0; i  pad-entity-num_links; i++) {
   + struct media_link *link = pad-entity-links[i];
   +
   + if (!(link-flags  MEDIA_LINK_FLAG_ACTIVE))
   + continue;
   +
   + if (link-source == pad)
   + return link-sink;
   +
   + if (link-sink == pad)
   + return link-source;
   + }
   +
   + return NULL;
   +
   +}
  
  Why is this needed? Esp. since there can be multiple active remote pads if
  you have multiple active outgoing links. Something this function doesn't
  deal with.
 
 The function is meant to be used when only one of the links can be active. 
 It's most useful to find the entity connected to a given input pad, as input 
 pads can't be connected by multiple simultaneously active links.

In that case I would rename it media_entity_remote_source to match the use
case (and only look for remote sources).

Alternatively you could add an index for the nth active link, then it would
be truly generic.

Right now the function either does too much or too little :-)

Regards,

Hans


-- 
Hans Verkuil - video4linux developer - sponsored by TANDBERG, part of Cisco
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC/PATCH v4 08/11] media: Links setup

2010-09-01 Thread Laurent Pinchart
Hi Hans,

On Saturday 28 August 2010 13:14:18 Hans Verkuil wrote:
 On Friday, August 20, 2010 17:29:10 Laurent Pinchart wrote:

[snip]

  +/**
  + * media_entity_remote_pad - Locate the pad at the remote end of a link
  + * @entity: Local entity
  + * @pad: Pad at the local end of the link
  + *
  + * Search for a remote pad connected to the given pad by iterating over
  all
  + * links originating or terminating at that pad until an active link is
  found.
  + *
  + * Return a pointer to the pad at the remote end of the first found
  active link,
  + * or NULL if no active link has been found.
  + */
  +struct media_pad *media_entity_remote_pad(struct media_pad *pad)
  +{
  +   unsigned int i;
  +
  +   for (i = 0; i  pad-entity-num_links; i++) {
  +   struct media_link *link = pad-entity-links[i];
  +
  +   if (!(link-flags  MEDIA_LINK_FLAG_ACTIVE))
  +   continue;
  +
  +   if (link-source == pad)
  +   return link-sink;
  +
  +   if (link-sink == pad)
  +   return link-source;
  +   }
  +
  +   return NULL;
  +
  +}
 
 Why is this needed? Esp. since there can be multiple active remote pads if
 you have multiple active outgoing links. Something this function doesn't
 deal with.

The function is meant to be used when only one of the links can be active. 
It's most useful to find the entity connected to a given input pad, as input 
pads can't be connected by multiple simultaneously active links.

[snip]

 This patch made me wonder about something else: how is power management
 handled for immutable links? They are by definition active, so they should
 be powered on automatically as well. I'm not sure whether that happens
 right now.

Links are not powered, entities are. Whether a link is immutable or not 
doesn't make much of a difference, it will just always be considered as 
active.

-- 
Regards,

Laurent Pinchart
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC/PATCH v4 08/11] media: Links setup

2010-08-28 Thread Hans Verkuil
On Friday, August 20, 2010 17:29:10 Laurent Pinchart wrote:
 Create the following ioctl and implement it at the media device level to
 setup links.
 
 - MEDIA_IOC_SETUP_LINK: Modify the properties of a given link
 
 The only property that can currently be modified is the ACTIVE link flag
 to activate/deactivate a link. Links marked with the IMMUTABLE link flag
 can not be activated or deactivated.
 
 Activating and deactivating a link has effects on entities' use count.
 Those changes are automatically propagated through the graph.
 
 Signed-off-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
 Signed-off-by: Stanimir Varbanov svarba...@mm-sol.com
 Signed-off-by: Sakari Ailus sakari.ai...@maxwell.research.nokia.com
 ---
  Documentation/media-framework.txt |   81 ++-
  drivers/media/media-device.c  |   45 
  drivers/media/media-entity.c  |  208 
 +
  include/linux/media.h |1 +
  include/media/media-entity.h  |8 ++
  5 files changed, 340 insertions(+), 3 deletions(-)
 
 diff --git a/Documentation/media-framework.txt 
 b/Documentation/media-framework.txt
 index 74a137d..7894ef3 100644
 --- a/Documentation/media-framework.txt
 +++ b/Documentation/media-framework.txt
 @@ -278,6 +278,16 @@ When the graph traversal is complete the function will 
 return NULL.
  Graph traversal can be interrupted at any moment. No cleanup function call is
  required and the graph structure can be freed normally.
  
 +Helper functions can be used to find a link between two given pads, or a pad
 +connected to another pad through an active link
 +
 + media_entity_find_link(struct media_pad *source,
 +struct media_pad *sink);
 +
 + media_entity_remote_pad(struct media_pad *pad);
 +
 +Refer to the kerneldoc documentation for more information.
 +
  
  Reference counting and power handling
  -
 @@ -316,6 +326,46 @@ is allowed to fail when turning power on, in which case 
 the media_entity_get
  function will return NULL.
  
  
 +Links setup
 +---
 +
 +Link properties can be modified at runtime by calling
 +
 + media_entity_setup_link(struct media_link *link, u32 flags);
 +
 +The flags argument contains the requested new link flags.
 +
 +The only configurable property is the ACTIVE link flag to activate/deactivate
 +a link. Links marked with the IMMUTABLE link flag can not be activated or
 +deactivated.
 +
 +When a link is activated or deactivated, the media framework calls the
 +link_setup operation for the two entities at the source and sink of the link,
 +in that order. If the second link_setup call fails, another link_setup call 
 is
 +made on the first entity to restore the original link flags.
 +
 +Entity drivers must implement the link_setup operation if any of their links
 +is non-immutable. The operation must either configure the hardware or store
 +the configuration information to be applied later.
 +
 +Link activation must not have any side effect on other links. If an active
 +link at a sink pad prevents another link at the same pad from being
 +deactivated, the link_setup operation must return -EBUSY and can't implicitly
 +deactivate the first active link.
 +
 +Activating and deactivating a link has effects on entities' reference counts.
 +When two sub-graphs are connected, the reference count of each of them is
 +incremented by the total reference count of all node entities in the other
 +sub-graph. When two sub-graphs are disconnected, the reverse operation is
 +performed. In both cases the set_power operations are called accordingly,
 +ensuring that the link_setup calls are made with power active on the source
 +and sink entities.
 +
 +In other words, activating or deactivating a link propagates reference count
 +changes through the graph, and the final state is identical to what it would
 +have been if the link had been active or inactive from the start.
 +
 +
  Userspace application API
  -
  
 @@ -439,9 +489,6 @@ Valid entity flags are
  
   ioctl(int fd, int request, struct media_links_enum *argp);
  
 -Only forward links that originate at one of the entity's source pads are
 -returned during the enumeration process.
 -
  To enumerate pads and/or links for a given entity, applications set the 
 entity
  field of a media_links_enum structure and initialize the media_pad_desc and
  media_link_desc structure arrays pointed by the pads and links fields. They 
 then
 @@ -457,6 +504,9 @@ information about the entity's outbound links. The array 
 must have enough room
  to store all the entity's outbound links. The number of outbound links can be
  retrieved with the MEDIA_IOC_ENUM_ENTITIES ioctl.
  
 +Only outbound (forward) links that originate at one of the entity's source
 +pads are returned during the enumeration process.
 +
  The media_pad_desc, media_link_desc and media_links_enum structures are 
 defined
  as
  
 

[RFC/PATCH v4 08/11] media: Links setup

2010-08-20 Thread Laurent Pinchart
Create the following ioctl and implement it at the media device level to
setup links.

- MEDIA_IOC_SETUP_LINK: Modify the properties of a given link

The only property that can currently be modified is the ACTIVE link flag
to activate/deactivate a link. Links marked with the IMMUTABLE link flag
can not be activated or deactivated.

Activating and deactivating a link has effects on entities' use count.
Those changes are automatically propagated through the graph.

Signed-off-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Signed-off-by: Stanimir Varbanov svarba...@mm-sol.com
Signed-off-by: Sakari Ailus sakari.ai...@maxwell.research.nokia.com
---
 Documentation/media-framework.txt |   81 ++-
 drivers/media/media-device.c  |   45 
 drivers/media/media-entity.c  |  208 +
 include/linux/media.h |1 +
 include/media/media-entity.h  |8 ++
 5 files changed, 340 insertions(+), 3 deletions(-)

diff --git a/Documentation/media-framework.txt 
b/Documentation/media-framework.txt
index 74a137d..7894ef3 100644
--- a/Documentation/media-framework.txt
+++ b/Documentation/media-framework.txt
@@ -278,6 +278,16 @@ When the graph traversal is complete the function will 
return NULL.
 Graph traversal can be interrupted at any moment. No cleanup function call is
 required and the graph structure can be freed normally.
 
+Helper functions can be used to find a link between two given pads, or a pad
+connected to another pad through an active link
+
+   media_entity_find_link(struct media_pad *source,
+  struct media_pad *sink);
+
+   media_entity_remote_pad(struct media_pad *pad);
+
+Refer to the kerneldoc documentation for more information.
+
 
 Reference counting and power handling
 -
@@ -316,6 +326,46 @@ is allowed to fail when turning power on, in which case 
the media_entity_get
 function will return NULL.
 
 
+Links setup
+---
+
+Link properties can be modified at runtime by calling
+
+   media_entity_setup_link(struct media_link *link, u32 flags);
+
+The flags argument contains the requested new link flags.
+
+The only configurable property is the ACTIVE link flag to activate/deactivate
+a link. Links marked with the IMMUTABLE link flag can not be activated or
+deactivated.
+
+When a link is activated or deactivated, the media framework calls the
+link_setup operation for the two entities at the source and sink of the link,
+in that order. If the second link_setup call fails, another link_setup call is
+made on the first entity to restore the original link flags.
+
+Entity drivers must implement the link_setup operation if any of their links
+is non-immutable. The operation must either configure the hardware or store
+the configuration information to be applied later.
+
+Link activation must not have any side effect on other links. If an active
+link at a sink pad prevents another link at the same pad from being
+deactivated, the link_setup operation must return -EBUSY and can't implicitly
+deactivate the first active link.
+
+Activating and deactivating a link has effects on entities' reference counts.
+When two sub-graphs are connected, the reference count of each of them is
+incremented by the total reference count of all node entities in the other
+sub-graph. When two sub-graphs are disconnected, the reverse operation is
+performed. In both cases the set_power operations are called accordingly,
+ensuring that the link_setup calls are made with power active on the source
+and sink entities.
+
+In other words, activating or deactivating a link propagates reference count
+changes through the graph, and the final state is identical to what it would
+have been if the link had been active or inactive from the start.
+
+
 Userspace application API
 -
 
@@ -439,9 +489,6 @@ Valid entity flags are
 
ioctl(int fd, int request, struct media_links_enum *argp);
 
-Only forward links that originate at one of the entity's source pads are
-returned during the enumeration process.
-
 To enumerate pads and/or links for a given entity, applications set the entity
 field of a media_links_enum structure and initialize the media_pad_desc and
 media_link_desc structure arrays pointed by the pads and links fields. They 
then
@@ -457,6 +504,9 @@ information about the entity's outbound links. The array 
must have enough room
 to store all the entity's outbound links. The number of outbound links can be
 retrieved with the MEDIA_IOC_ENUM_ENTITIES ioctl.
 
+Only outbound (forward) links that originate at one of the entity's source
+pads are returned during the enumeration process.
+
 The media_pad_desc, media_link_desc and media_links_enum structures are defined
 as
 
@@ -497,3 +547,28 @@ struct media_pad_desc  *pads   Pointer to a pads array 
allocated by the
application. Ignored if NULL.
 struct