[media] media: add a debug message to warn about gobj creation/removal
[deliverable/linux.git] / include / media / media-entity.h
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
26 #include <linux/bitops.h>
27 #include <linux/kernel.h>
28 #include <linux/list.h>
29 #include <linux/media.h>
30
31 /* Enums used internally at the media controller to represent graphs */
32
33 /**
34 * enum media_gobj_type - type of a graph object
35 *
36 * @MEDIA_GRAPH_ENTITY: Identify a media entity
37 * @MEDIA_GRAPH_PAD: Identify a media pad
38 * @MEDIA_GRAPH_LINK: Identify a media link
39 */
40 enum media_gobj_type {
41 MEDIA_GRAPH_ENTITY,
42 MEDIA_GRAPH_PAD,
43 MEDIA_GRAPH_LINK,
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 */
63 struct media_gobj {
64 struct media_device *mdev;
65 u32 id;
66 };
67
68
69 struct media_pipeline {
70 };
71
72 struct media_link {
73 struct media_gobj graph_obj;
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
80 struct media_pad {
81 struct media_gobj graph_obj;
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
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 */
96 struct 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);
100 int (*link_validate)(struct media_link *link);
101 };
102
103 struct media_entity {
104 struct media_gobj graph_obj;
105 struct list_head list;
106 struct media_device *parent; /* Media device this entity belongs to*/
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
122 const struct media_entity_operations *ops; /* Entity operations */
123
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 */
128 int stream_count; /* Stream count for the entity. */
129 int use_count; /* Use count for the entity. */
130
131 struct media_pipeline *pipe; /* Pipeline this entity belongs to. */
132
133 union {
134 /* Node specifications */
135 struct {
136 u32 major;
137 u32 minor;
138 } dev;
139
140 /* Sub-device specifications */
141 /* Nothing needed yet */
142 } info;
143 };
144
145 static inline u32 media_entity_type(struct media_entity *entity)
146 {
147 return entity->type & MEDIA_ENT_TYPE_MASK;
148 }
149
150 static inline u32 media_entity_subtype(struct media_entity *entity)
151 {
152 return entity->type & MEDIA_ENT_SUBTYPE_MASK;
153 }
154
155 static inline u32 media_entity_id(struct media_entity *entity)
156 {
157 return entity->graph_obj.id;
158 }
159
160 static inline enum media_gobj_type media_type(struct media_gobj *gobj)
161 {
162 return gobj->id >> MEDIA_BITS_PER_LOCAL_ID;
163 }
164
165 static inline u32 media_localid(struct media_gobj *gobj)
166 {
167 return gobj->id & MEDIA_LOCAL_ID_MASK;
168 }
169
170 static 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
180 #define MEDIA_ENTITY_ENUM_MAX_DEPTH 16
181 #define MEDIA_ENTITY_ENUM_MAX_ID 64
182
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
190 struct media_entity_graph {
191 struct {
192 struct media_entity *entity;
193 int link;
194 } stack[MEDIA_ENTITY_ENUM_MAX_DEPTH];
195
196 DECLARE_BITMAP(entities, MEDIA_ENTITY_ENUM_MAX_ID);
197 int top;
198 };
199
200 #define gobj_to_entity(gobj) \
201 container_of(gobj, struct media_entity, graph_obj)
202
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
209 void media_gobj_init(struct media_device *mdev,
210 enum media_gobj_type type,
211 struct media_gobj *gobj);
212 void media_gobj_remove(struct media_gobj *gobj);
213
214 int media_entity_init(struct media_entity *entity, u16 num_pads,
215 struct media_pad *pads);
216 void media_entity_cleanup(struct media_entity *entity);
217
218 int media_entity_create_link(struct media_entity *source, u16 source_pad,
219 struct media_entity *sink, u16 sink_pad, u32 flags);
220 void __media_entity_remove_links(struct media_entity *entity);
221 void media_entity_remove_links(struct media_entity *entity);
222
223 int __media_entity_setup_link(struct media_link *link, u32 flags);
224 int media_entity_setup_link(struct media_link *link, u32 flags);
225 struct media_link *media_entity_find_link(struct media_pad *source,
226 struct media_pad *sink);
227 struct media_pad *media_entity_remote_pad(struct media_pad *pad);
228
229 struct media_entity *media_entity_get(struct media_entity *entity);
230 void media_entity_put(struct media_entity *entity);
231
232 void media_entity_graph_walk_start(struct media_entity_graph *graph,
233 struct media_entity *entity);
234 struct media_entity *
235 media_entity_graph_walk_next(struct media_entity_graph *graph);
236 __must_check int media_entity_pipeline_start(struct media_entity *entity,
237 struct media_pipeline *pipe);
238 void media_entity_pipeline_stop(struct media_entity *entity);
239
240 #define media_entity_call(entity, operation, args...) \
241 (((entity)->ops && (entity)->ops->operation) ? \
242 (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD)
243
244 #endif
This page took 0.043474 seconds and 5 git commands to generate.