As video hardware pipelines become increasingly complex and configurable, the current hardware description through v4l2 subdevices reaches its limits. In addition to enumerating and configuring subdevices, video camera drivers need a way to discover and modify at runtime how those subdevices are connected. This is done through new elements called entities, pads and links. An entity is a basic media hardware building block. It can correspond to a large variety of logical blocks such as physical hardware devices (CMOS sensor for instance), logical hardware devices (a building block in a System-on-Chip image processing pipeline), DMA channels or physical connectors. A pad is a connection endpoint through which an entity can interact with other entities. Data (not restricted to video) produced by an entity flows from the entity's output to one or more entity inputs. Pads should not be confused with physical pins at chip boundaries. A link is a point-to-point oriented connection between two pads, either on the same entity or on different entities. Data flows from a source pad to a sink pad. Links are stored in the source entity. To make backwards graph walk faster, a copy of all links is also stored in the sink entity. The copy is known as a backlink and is only used to help graph traversal. The entity API is made of three functions: - media_entity_init() initializes an entity. The caller must provide an array of pads as well as an estimated number of links. The links array is allocated dynamically and will be reallocated if it grows beyond the initial estimate. - media_entity_cleanup() frees resources allocated for an entity. It must be called during the cleanup phase after unregistering the entity and before freeing it. - media_entity_create_link() creates a link between two entities. An entry in the link array of each entity is allocated and stores pointers to source and sink pads. When a media device is unregistered, all its entities are unregistered automatically. The code is based on Hans Verkuil <hverkuil@xs4all.nl> initial work. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi> Acked-by: Hans Verkuil <hverkuil@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>tirimbino
parent
176fb0d108
commit
53e269c102
@ -0,0 +1,147 @@ |
||||
/*
|
||||
* Media entity |
||||
* |
||||
* Copyright (C) 2010 Nokia Corporation |
||||
* |
||||
* Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com> |
||||
* Sakari Ailus <sakari.ailus@iki.fi> |
||||
* |
||||
* This program is free software; you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License version 2 as |
||||
* published by the Free Software Foundation. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program; if not, write to the Free Software |
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||||
*/ |
||||
|
||||
#include <linux/module.h> |
||||
#include <linux/slab.h> |
||||
#include <media/media-entity.h> |
||||
|
||||
/**
|
||||
* media_entity_init - Initialize a media entity |
||||
* |
||||
* @num_pads: Total number of sink and source pads. |
||||
* @extra_links: Initial estimate of the number of extra links. |
||||
* @pads: Array of 'num_pads' pads. |
||||
* |
||||
* The total number of pads is an intrinsic property of entities known by the |
||||
* entity driver, while the total number of links depends on hardware design |
||||
* and is an extrinsic property unknown to the entity driver. However, in most |
||||
* use cases the entity driver can guess the number of links which can safely |
||||
* be assumed to be equal to or larger than the number of pads. |
||||
* |
||||
* For those reasons the links array can be preallocated based on the entity |
||||
* driver guess and will be reallocated later if extra links need to be |
||||
* created. |
||||
* |
||||
* This function allocates a links array with enough space to hold at least |
||||
* 'num_pads' + 'extra_links' elements. The media_entity::max_links field will |
||||
* be set to the number of allocated elements. |
||||
* |
||||
* The pads array is managed by the entity driver and passed to |
||||
* media_entity_init() where its pointer will be stored in the entity structure. |
||||
*/ |
||||
int |
||||
media_entity_init(struct media_entity *entity, u16 num_pads, |
||||
struct media_pad *pads, u16 extra_links) |
||||
{ |
||||
struct media_link *links; |
||||
unsigned int max_links = num_pads + extra_links; |
||||
unsigned int i; |
||||
|
||||
links = kzalloc(max_links * sizeof(links[0]), GFP_KERNEL); |
||||
if (links == NULL) |
||||
return -ENOMEM; |
||||
|
||||
entity->group_id = 0; |
||||
entity->max_links = max_links; |
||||
entity->num_links = 0; |
||||
entity->num_backlinks = 0; |
||||
entity->num_pads = num_pads; |
||||
entity->pads = pads; |
||||
entity->links = links; |
||||
|
||||
for (i = 0; i < num_pads; i++) { |
||||
pads[i].entity = entity; |
||||
pads[i].index = i; |
||||
} |
||||
|
||||
return 0; |
||||
} |
||||
EXPORT_SYMBOL_GPL(media_entity_init); |
||||
|
||||
void |
||||
media_entity_cleanup(struct media_entity *entity) |
||||
{ |
||||
kfree(entity->links); |
||||
} |
||||
EXPORT_SYMBOL_GPL(media_entity_cleanup); |
||||
|
||||
static struct media_link *media_entity_add_link(struct media_entity *entity) |
||||
{ |
||||
if (entity->num_links >= entity->max_links) { |
||||
struct media_link *links = entity->links; |
||||
unsigned int max_links = entity->max_links + 2; |
||||
unsigned int i; |
||||
|
||||
links = krealloc(links, max_links * sizeof(*links), GFP_KERNEL); |
||||
if (links == NULL) |
||||
return NULL; |
||||
|
||||
for (i = 0; i < entity->num_links; i++) |
||||
links[i].reverse->reverse = &links[i]; |
||||
|
||||
entity->max_links = max_links; |
||||
entity->links = links; |
||||
} |
||||
|
||||
return &entity->links[entity->num_links++]; |
||||
} |
||||
|
||||
int |
||||
media_entity_create_link(struct media_entity *source, u16 source_pad, |
||||
struct media_entity *sink, u16 sink_pad, u32 flags) |
||||
{ |
||||
struct media_link *link; |
||||
struct media_link *backlink; |
||||
|
||||
BUG_ON(source == NULL || sink == NULL); |
||||
BUG_ON(source_pad >= source->num_pads); |
||||
BUG_ON(sink_pad >= sink->num_pads); |
||||
|
||||
link = media_entity_add_link(source); |
||||
if (link == NULL) |
||||
return -ENOMEM; |
||||
|
||||
link->source = &source->pads[source_pad]; |
||||
link->sink = &sink->pads[sink_pad]; |
||||
link->flags = flags; |
||||
|
||||
/* Create the backlink. Backlinks are used to help graph traversal and
|
||||
* are not reported to userspace. |
||||
*/ |
||||
backlink = media_entity_add_link(sink); |
||||
if (backlink == NULL) { |
||||
source->num_links--; |
||||
return -ENOMEM; |
||||
} |
||||
|
||||
backlink->source = &source->pads[source_pad]; |
||||
backlink->sink = &sink->pads[sink_pad]; |
||||
backlink->flags = flags; |
||||
|
||||
link->reverse = backlink; |
||||
backlink->reverse = link; |
||||
|
||||
sink->num_backlinks++; |
||||
|
||||
return 0; |
||||
} |
||||
EXPORT_SYMBOL_GPL(media_entity_create_link); |
@ -0,0 +1,122 @@ |
||||
/*
|
||||
* Media entity |
||||
* |
||||
* Copyright (C) 2010 Nokia Corporation |
||||
* |
||||
* Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com> |
||||
* Sakari Ailus <sakari.ailus@iki.fi> |
||||
* |
||||
* This program is free software; you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License version 2 as |
||||
* published by the Free Software Foundation. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program; if not, write to the Free Software |
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||||
*/ |
||||
|
||||
#ifndef _MEDIA_ENTITY_H |
||||
#define _MEDIA_ENTITY_H |
||||
|
||||
#include <linux/list.h> |
||||
|
||||
#define MEDIA_ENT_TYPE_SHIFT 16 |
||||
#define MEDIA_ENT_TYPE_MASK 0x00ff0000 |
||||
#define MEDIA_ENT_SUBTYPE_MASK 0x0000ffff |
||||
|
||||
#define MEDIA_ENT_T_DEVNODE (1 << MEDIA_ENT_TYPE_SHIFT) |
||||
#define MEDIA_ENT_T_DEVNODE_V4L (MEDIA_ENT_T_DEVNODE + 1) |
||||
#define MEDIA_ENT_T_DEVNODE_FB (MEDIA_ENT_T_DEVNODE + 2) |
||||
#define MEDIA_ENT_T_DEVNODE_ALSA (MEDIA_ENT_T_DEVNODE + 3) |
||||
#define MEDIA_ENT_T_DEVNODE_DVB (MEDIA_ENT_T_DEVNODE + 4) |
||||
|
||||
#define MEDIA_ENT_T_V4L2_SUBDEV (2 << MEDIA_ENT_TYPE_SHIFT) |
||||
#define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR (MEDIA_ENT_T_V4L2_SUBDEV + 1) |
||||
#define MEDIA_ENT_T_V4L2_SUBDEV_FLASH (MEDIA_ENT_T_V4L2_SUBDEV + 2) |
||||
#define MEDIA_ENT_T_V4L2_SUBDEV_LENS (MEDIA_ENT_T_V4L2_SUBDEV + 3) |
||||
|
||||
#define MEDIA_ENT_FL_DEFAULT (1 << 0) |
||||
|
||||
#define MEDIA_LNK_FL_ENABLED (1 << 0) |
||||
#define MEDIA_LNK_FL_IMMUTABLE (1 << 1) |
||||
|
||||
#define MEDIA_PAD_FL_SINK (1 << 0) |
||||
#define MEDIA_PAD_FL_SOURCE (1 << 1) |
||||
|
||||
struct media_link { |
||||
struct media_pad *source; /* Source pad */ |
||||
struct media_pad *sink; /* Sink pad */ |
||||
struct media_link *reverse; /* Link in the reverse direction */ |
||||
unsigned long flags; /* Link flags (MEDIA_LNK_FL_*) */ |
||||
}; |
||||
|
||||
struct media_pad { |
||||
struct media_entity *entity; /* Entity this pad belongs to */ |
||||
u16 index; /* Pad index in the entity pads array */ |
||||
unsigned long flags; /* Pad flags (MEDIA_PAD_FL_*) */ |
||||
}; |
||||
|
||||
struct media_entity { |
||||
struct list_head list; |
||||
struct media_device *parent; /* Media device this entity belongs to*/ |
||||
u32 id; /* Entity ID, unique in the parent media
|
||||
* device context */ |
||||
const char *name; /* Entity name */ |
||||
u32 type; /* Entity type (MEDIA_ENT_T_*) */ |
||||
u32 revision; /* Entity revision, driver specific */ |
||||
unsigned long flags; /* Entity flags (MEDIA_ENT_FL_*) */ |
||||
u32 group_id; /* Entity group ID */ |
||||
|
||||
u16 num_pads; /* Number of sink and source pads */ |
||||
u16 num_links; /* Number of existing links, both
|
||||
* enabled and disabled */ |
||||
u16 num_backlinks; /* Number of backlinks */ |
||||
u16 max_links; /* Maximum number of links */ |
||||
|
||||
struct media_pad *pads; /* Pads array (num_pads elements) */ |
||||
struct media_link *links; /* Links array (max_links elements)*/ |
||||
|
||||
union { |
||||
/* Node specifications */ |
||||
struct { |
||||
u32 major; |
||||
u32 minor; |
||||
} v4l; |
||||
struct { |
||||
u32 major; |
||||
u32 minor; |
||||
} fb; |
||||
struct { |
||||
u32 card; |
||||
u32 device; |
||||
u32 subdevice; |
||||
} alsa; |
||||
int dvb; |
||||
|
||||
/* Sub-device specifications */ |
||||
/* Nothing needed yet */ |
||||
}; |
||||
}; |
||||
|
||||
static inline u32 media_entity_type(struct media_entity *entity) |
||||
{ |
||||
return entity->type & MEDIA_ENT_TYPE_MASK; |
||||
} |
||||
|
||||
static inline u32 media_entity_subtype(struct media_entity *entity) |
||||
{ |
||||
return entity->type & MEDIA_ENT_SUBTYPE_MASK; |
||||
} |
||||
|
||||
int media_entity_init(struct media_entity *entity, u16 num_pads, |
||||
struct media_pad *pads, u16 extra_links); |
||||
void media_entity_cleanup(struct media_entity *entity); |
||||
int media_entity_create_link(struct media_entity *source, u16 source_pad, |
||||
struct media_entity *sink, u16 sink_pad, u32 flags); |
||||
|
||||
#endif |
Loading…
Reference in new issue