[media] media: add a debug message to warn about gobj creation/removal
[deliverable/linux.git] / include / media / media-entity.h
CommitLineData
53e269c1
LP
1/*
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
5c7b25b9 26#include <linux/bitops.h>
0149a2e1 27#include <linux/kernel.h>
53e269c1 28#include <linux/list.h>
1651333b 29#include <linux/media.h>
53e269c1 30
ec6e4c95
MCC
31/* Enums used internally at the media controller to represent graphs */
32
33/**
34 * enum media_gobj_type - type of a graph object
35 *
bfab2aac 36 * @MEDIA_GRAPH_ENTITY: Identify a media entity
18710dc6 37 * @MEDIA_GRAPH_PAD: Identify a media pad
6b6a4278 38 * @MEDIA_GRAPH_LINK: Identify a media link
ec6e4c95
MCC
39 */
40enum media_gobj_type {
bfab2aac 41 MEDIA_GRAPH_ENTITY,
18710dc6 42 MEDIA_GRAPH_PAD,
6b6a4278 43 MEDIA_GRAPH_LINK,
ec6e4c95
MCC
44};
45
46#define MEDIA_BITS_PER_TYPE 8
47#define MEDIA_BITS_PER_LOCAL_ID (32 - MEDIA_BITS_PER_TYPE)
48#define MEDIA_LOCAL_ID_MASK GENMASK(MEDIA_BITS_PER_LOCAL_ID - 1, 0)
49
50/* Structs to represent the objects that belong to a media graph */
51
52/**
53 * struct media_gobj - Define a graph object.
54 *
55 * @id: Non-zero object ID identifier. The ID should be unique
56 * inside a media_device, as it is composed by
57 * MEDIA_BITS_PER_TYPE to store the type plus
58 * MEDIA_BITS_PER_LOCAL_ID to store a per-type ID
59 * (called as "local ID").
60 *
61 * All objects on the media graph should have this struct embedded
62 */
63struct media_gobj {
39a956c4 64 struct media_device *mdev;
ec6e4c95
MCC
65 u32 id;
66};
67
68
e02188c9
LP
69struct media_pipeline {
70};
71
53e269c1 72struct media_link {
6b6a4278 73 struct media_gobj graph_obj;
53e269c1
LP
74 struct media_pad *source; /* Source pad */
75 struct media_pad *sink; /* Sink pad */
76 struct media_link *reverse; /* Link in the reverse direction */
77 unsigned long flags; /* Link flags (MEDIA_LNK_FL_*) */
78};
79
80struct media_pad {
18710dc6 81 struct media_gobj graph_obj;
53e269c1
LP
82 struct media_entity *entity; /* Entity this pad belongs to */
83 u16 index; /* Pad index in the entity pads array */
84 unsigned long flags; /* Pad flags (MEDIA_PAD_FL_*) */
85};
86
5a5394be
LP
87/**
88 * struct media_entity_operations - Media entity operations
89 * @link_setup: Notify the entity of link changes. The operation can
90 * return an error, in which case link setup will be
91 * cancelled. Optional.
92 * @link_validate: Return whether a link is valid from the entity point of
93 * view. The media_entity_pipeline_start() function
94 * validates all links by calling this operation. Optional.
95 */
97548ed4
LP
96struct media_entity_operations {
97 int (*link_setup)(struct media_entity *entity,
98 const struct media_pad *local,
99 const struct media_pad *remote, u32 flags);
af88be38 100 int (*link_validate)(struct media_link *link);
97548ed4
LP
101};
102
53e269c1 103struct media_entity {
bfab2aac 104 struct media_gobj graph_obj;
53e269c1
LP
105 struct list_head list;
106 struct media_device *parent; /* Media device this entity belongs to*/
53e269c1
LP
107 const char *name; /* Entity name */
108 u32 type; /* Entity type (MEDIA_ENT_T_*) */
109 u32 revision; /* Entity revision, driver specific */
110 unsigned long flags; /* Entity flags (MEDIA_ENT_FL_*) */
111 u32 group_id; /* Entity group ID */
112
113 u16 num_pads; /* Number of sink and source pads */
114 u16 num_links; /* Number of existing links, both
115 * enabled and disabled */
116 u16 num_backlinks; /* Number of backlinks */
117 u16 max_links; /* Maximum number of links */
118
119 struct media_pad *pads; /* Pads array (num_pads elements) */
120 struct media_link *links; /* Links array (max_links elements)*/
121
97548ed4
LP
122 const struct media_entity_operations *ops; /* Entity operations */
123
503c3d82
LP
124 /* Reference counts must never be negative, but are signed integers on
125 * purpose: a simple WARN_ON(<0) check can be used to detect reference
126 * count bugs that would make them negative.
127 */
e02188c9 128 int stream_count; /* Stream count for the entity. */
503c3d82
LP
129 int use_count; /* Use count for the entity. */
130
e02188c9
LP
131 struct media_pipeline *pipe; /* Pipeline this entity belongs to. */
132
53e269c1
LP
133 union {
134 /* Node specifications */
135 struct {
136 u32 major;
137 u32 minor;
e31a0ba7 138 } dev;
53e269c1
LP
139
140 /* Sub-device specifications */
141 /* Nothing needed yet */
fa5034c6 142 } info;
53e269c1
LP
143};
144
145static inline u32 media_entity_type(struct media_entity *entity)
146{
147 return entity->type & MEDIA_ENT_TYPE_MASK;
148}
149
150static inline u32 media_entity_subtype(struct media_entity *entity)
151{
152 return entity->type & MEDIA_ENT_SUBTYPE_MASK;
153}
154
fa762394
MCC
155static inline u32 media_entity_id(struct media_entity *entity)
156{
bfab2aac 157 return entity->graph_obj.id;
fa762394
MCC
158}
159
ec6e4c95
MCC
160static inline enum media_gobj_type media_type(struct media_gobj *gobj)
161{
162 return gobj->id >> MEDIA_BITS_PER_LOCAL_ID;
163}
164
165static inline u32 media_localid(struct media_gobj *gobj)
166{
167 return gobj->id & MEDIA_LOCAL_ID_MASK;
168}
169
170static inline u32 media_gobj_gen_id(enum media_gobj_type type, u32 local_id)
171{
172 u32 id;
173
174 id = type << MEDIA_BITS_PER_LOCAL_ID;
175 id |= local_id & MEDIA_LOCAL_ID_MASK;
176
177 return id;
178}
179
a5ccc48a 180#define MEDIA_ENTITY_ENUM_MAX_DEPTH 16
5c7b25b9 181#define MEDIA_ENTITY_ENUM_MAX_ID 64
a5ccc48a 182
ef69ee1b
MCC
183/*
184 * The number of pads can't be bigger than the number of entities,
185 * as the worse-case scenario is to have one entity linked up to
186 * MEDIA_ENTITY_ENUM_MAX_ID - 1 entities.
187 */
188#define MEDIA_ENTITY_MAX_PADS (MEDIA_ENTITY_ENUM_MAX_ID - 1)
189
a5ccc48a
SA
190struct media_entity_graph {
191 struct {
192 struct media_entity *entity;
193 int link;
194 } stack[MEDIA_ENTITY_ENUM_MAX_DEPTH];
5c7b25b9
LP
195
196 DECLARE_BITMAP(entities, MEDIA_ENTITY_ENUM_MAX_ID);
a5ccc48a
SA
197 int top;
198};
199
ec6e4c95
MCC
200#define gobj_to_entity(gobj) \
201 container_of(gobj, struct media_entity, graph_obj)
202
39a956c4
MCC
203#define gobj_to_pad(gobj) \
204 container_of(gobj, struct media_pad, graph_obj)
205
206#define gobj_to_link(gobj) \
207 container_of(gobj, struct media_link, graph_obj)
208
ec6e4c95
MCC
209void media_gobj_init(struct media_device *mdev,
210 enum media_gobj_type type,
211 struct media_gobj *gobj);
212void media_gobj_remove(struct media_gobj *gobj);
213
53e269c1 214int media_entity_init(struct media_entity *entity, u16 num_pads,
18095107 215 struct media_pad *pads);
53e269c1 216void media_entity_cleanup(struct media_entity *entity);
e02188c9 217
53e269c1
LP
218int media_entity_create_link(struct media_entity *source, u16 source_pad,
219 struct media_entity *sink, u16 sink_pad, u32 flags);
7349cec1
SN
220void __media_entity_remove_links(struct media_entity *entity);
221void media_entity_remove_links(struct media_entity *entity);
222
97548ed4
LP
223int __media_entity_setup_link(struct media_link *link, u32 flags);
224int media_entity_setup_link(struct media_link *link, u32 flags);
225struct media_link *media_entity_find_link(struct media_pad *source,
226 struct media_pad *sink);
1bddf1b3 227struct media_pad *media_entity_remote_pad(struct media_pad *pad);
53e269c1 228
503c3d82
LP
229struct media_entity *media_entity_get(struct media_entity *entity);
230void media_entity_put(struct media_entity *entity);
231
a5ccc48a
SA
232void media_entity_graph_walk_start(struct media_entity_graph *graph,
233 struct media_entity *entity);
234struct media_entity *
235media_entity_graph_walk_next(struct media_entity_graph *graph);
af88be38
SA
236__must_check int media_entity_pipeline_start(struct media_entity *entity,
237 struct media_pipeline *pipe);
e02188c9 238void media_entity_pipeline_stop(struct media_entity *entity);
a5ccc48a 239
97548ed4
LP
240#define media_entity_call(entity, operation, args...) \
241 (((entity)->ops && (entity)->ops->operation) ? \
242 (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD)
243
53e269c1 244#endif
This page took 0.18916 seconds and 5 git commands to generate.