blob: 0c003d8174937ba47afa097d6a54b4fb8adce31d [file] [log] [blame]
Laurent Pinchart53e269c2009-12-09 08:40:00 -03001/*
2 * Media entity
3 *
4 * Copyright (C) 2010 Nokia Corporation
5 *
6 * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
7 * Sakari Ailus <sakari.ailus@iki.fi>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#ifndef _MEDIA_ENTITY_H
24#define _MEDIA_ENTITY_H
25
Laurent Pinchart5c7b25b2013-06-07 12:45:11 -030026#include <linux/bitops.h>
Sakari Ailus0149a2e2013-12-13 08:58:37 -030027#include <linux/kernel.h>
Laurent Pinchart53e269c2009-12-09 08:40:00 -030028#include <linux/list.h>
Laurent Pinchart16513332009-12-09 08:40:01 -030029#include <linux/media.h>
Laurent Pinchart53e269c2009-12-09 08:40:00 -030030
Laurent Pincharte02188c2010-08-25 09:00:41 -030031struct media_pipeline {
32};
33
Laurent Pinchart53e269c2009-12-09 08:40:00 -030034struct media_link {
35 struct media_pad *source; /* Source pad */
36 struct media_pad *sink; /* Sink pad */
37 struct media_link *reverse; /* Link in the reverse direction */
38 unsigned long flags; /* Link flags (MEDIA_LNK_FL_*) */
39};
40
41struct media_pad {
42 struct media_entity *entity; /* Entity this pad belongs to */
43 u16 index; /* Pad index in the entity pads array */
44 unsigned long flags; /* Pad flags (MEDIA_PAD_FL_*) */
45};
46
Laurent Pinchart5a5394b2014-03-26 00:01:44 -030047/**
48 * struct media_entity_operations - Media entity operations
49 * @link_setup: Notify the entity of link changes. The operation can
50 * return an error, in which case link setup will be
51 * cancelled. Optional.
52 * @link_validate: Return whether a link is valid from the entity point of
53 * view. The media_entity_pipeline_start() function
54 * validates all links by calling this operation. Optional.
55 */
Laurent Pinchart97548ed2009-12-09 08:40:03 -030056struct media_entity_operations {
57 int (*link_setup)(struct media_entity *entity,
58 const struct media_pad *local,
59 const struct media_pad *remote, u32 flags);
Sakari Ailusaf88be32012-01-11 06:25:15 -030060 int (*link_validate)(struct media_link *link);
Laurent Pinchart97548ed2009-12-09 08:40:03 -030061};
62
Laurent Pinchart53e269c2009-12-09 08:40:00 -030063struct media_entity {
64 struct list_head list;
65 struct media_device *parent; /* Media device this entity belongs to*/
66 u32 id; /* Entity ID, unique in the parent media
67 * device context */
68 const char *name; /* Entity name */
69 u32 type; /* Entity type (MEDIA_ENT_T_*) */
70 u32 revision; /* Entity revision, driver specific */
71 unsigned long flags; /* Entity flags (MEDIA_ENT_FL_*) */
72 u32 group_id; /* Entity group ID */
73
74 u16 num_pads; /* Number of sink and source pads */
75 u16 num_links; /* Number of existing links, both
76 * enabled and disabled */
77 u16 num_backlinks; /* Number of backlinks */
78 u16 max_links; /* Maximum number of links */
79
80 struct media_pad *pads; /* Pads array (num_pads elements) */
81 struct media_link *links; /* Links array (max_links elements)*/
82
Laurent Pinchart97548ed2009-12-09 08:40:03 -030083 const struct media_entity_operations *ops; /* Entity operations */
84
Laurent Pinchart503c3d822010-03-07 15:04:59 -030085 /* Reference counts must never be negative, but are signed integers on
86 * purpose: a simple WARN_ON(<0) check can be used to detect reference
87 * count bugs that would make them negative.
88 */
Laurent Pincharte02188c2010-08-25 09:00:41 -030089 int stream_count; /* Stream count for the entity. */
Laurent Pinchart503c3d822010-03-07 15:04:59 -030090 int use_count; /* Use count for the entity. */
91
Laurent Pincharte02188c2010-08-25 09:00:41 -030092 struct media_pipeline *pipe; /* Pipeline this entity belongs to. */
93
Laurent Pinchart53e269c2009-12-09 08:40:00 -030094 union {
95 /* Node specifications */
96 struct {
97 u32 major;
98 u32 minor;
Mauro Carvalho Chehabe31a0ba2015-01-02 12:18:23 -030099 } dev;
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300100
101 /* Sub-device specifications */
102 /* Nothing needed yet */
Clemens Ladischfa5034c2011-11-05 18:42:01 -0300103 } info;
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300104};
105
106static inline u32 media_entity_type(struct media_entity *entity)
107{
108 return entity->type & MEDIA_ENT_TYPE_MASK;
109}
110
111static inline u32 media_entity_subtype(struct media_entity *entity)
112{
113 return entity->type & MEDIA_ENT_SUBTYPE_MASK;
114}
115
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300116#define MEDIA_ENTITY_ENUM_MAX_DEPTH 16
Laurent Pinchart5c7b25b2013-06-07 12:45:11 -0300117#define MEDIA_ENTITY_ENUM_MAX_ID 64
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300118
119struct media_entity_graph {
120 struct {
121 struct media_entity *entity;
122 int link;
123 } stack[MEDIA_ENTITY_ENUM_MAX_DEPTH];
Laurent Pinchart5c7b25b2013-06-07 12:45:11 -0300124
125 DECLARE_BITMAP(entities, MEDIA_ENTITY_ENUM_MAX_ID);
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300126 int top;
127};
128
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300129int media_entity_init(struct media_entity *entity, u16 num_pads,
130 struct media_pad *pads, u16 extra_links);
131void media_entity_cleanup(struct media_entity *entity);
Laurent Pincharte02188c2010-08-25 09:00:41 -0300132
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300133int media_entity_create_link(struct media_entity *source, u16 source_pad,
134 struct media_entity *sink, u16 sink_pad, u32 flags);
Sylwester Nawrocki7349cec2013-05-09 08:29:32 -0300135void __media_entity_remove_links(struct media_entity *entity);
136void media_entity_remove_links(struct media_entity *entity);
137
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300138int __media_entity_setup_link(struct media_link *link, u32 flags);
139int media_entity_setup_link(struct media_link *link, u32 flags);
140struct media_link *media_entity_find_link(struct media_pad *source,
141 struct media_pad *sink);
Andrzej Hajda1bddf1b2013-06-03 05:16:13 -0300142struct media_pad *media_entity_remote_pad(struct media_pad *pad);
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300143
Laurent Pinchart503c3d822010-03-07 15:04:59 -0300144struct media_entity *media_entity_get(struct media_entity *entity);
145void media_entity_put(struct media_entity *entity);
146
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300147void media_entity_graph_walk_start(struct media_entity_graph *graph,
148 struct media_entity *entity);
149struct media_entity *
150media_entity_graph_walk_next(struct media_entity_graph *graph);
Sakari Ailusaf88be32012-01-11 06:25:15 -0300151__must_check int media_entity_pipeline_start(struct media_entity *entity,
152 struct media_pipeline *pipe);
Laurent Pincharte02188c2010-08-25 09:00:41 -0300153void media_entity_pipeline_stop(struct media_entity *entity);
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300154
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300155#define media_entity_call(entity, operation, args...) \
156 (((entity)->ops && (entity)->ops->operation) ? \
157 (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD)
158
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300159#endif