bf93c90e921882339f9842391a1833a935eaecfa
[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 u32 id;
65 };
66
67
68 struct media_pipeline {
69 };
70
71 struct media_link {
72 struct media_gobj graph_obj;
73 struct media_pad *source; /* Source pad */
74 struct media_pad *sink; /* Sink pad */
75 struct media_link *reverse; /* Link in the reverse direction */
76 unsigned long flags; /* Link flags (MEDIA_LNK_FL_*) */
77 };
78
79 struct media_pad {
80 struct media_gobj graph_obj;
81 struct media_entity *entity; /* Entity this pad belongs to */
82 u16 index; /* Pad index in the entity pads array */
83 unsigned long flags; /* Pad flags (MEDIA_PAD_FL_*) */
84 };
85
86 /**
87 * struct media_entity_operations - Media entity operations
88 * @link_setup: Notify the entity of link changes. The operation can
89 * return an error, in which case link setup will be
90 * cancelled. Optional.
91 * @link_validate: Return whether a link is valid from the entity point of
92 * view. The media_entity_pipeline_start() function
93 * validates all links by calling this operation. Optional.
94 */
95 struct media_entity_operations {
96 int (*link_setup)(struct media_entity *entity,
97 const struct media_pad *local,
98 const struct media_pad *remote, u32 flags);
99 int (*link_validate)(struct media_link *link);
100 };
101
102 struct media_entity {
103 struct media_gobj graph_obj;
104 struct list_head list;
105 struct media_device *parent; /* Media device this entity belongs to*/
106 const char *name; /* Entity name */
107 u32 type; /* Entity type (MEDIA_ENT_T_*) */
108 u32 revision; /* Entity revision, driver specific */
109 unsigned long flags; /* Entity flags (MEDIA_ENT_FL_*) */
110 u32 group_id; /* Entity group ID */
111
112 u16 num_pads; /* Number of sink and source pads */
113 u16 num_links; /* Number of existing links, both
114 * enabled and disabled */
115 u16 num_backlinks; /* Number of backlinks */
116 u16 max_links; /* Maximum number of links */
117
118 struct media_pad *pads; /* Pads array (num_pads elements) */
119 struct media_link *links; /* Links array (max_links elements)*/
120
121 const struct media_entity_operations *ops; /* Entity operations */
122
123 /* Reference counts must never be negative, but are signed integers on
124 * purpose: a simple WARN_ON(<0) check can be used to detect reference
125 * count bugs that would make them negative.
126 */
127 int stream_count; /* Stream count for the entity. */
128 int use_count; /* Use count for the entity. */
129
130 struct media_pipeline *pipe; /* Pipeline this entity belongs to. */
131
132 union {
133 /* Node specifications */
134 struct {
135 u32 major;
136 u32 minor;
137 } dev;
138
139 /* Sub-device specifications */
140 /* Nothing needed yet */
141 } info;
142 };
143
144 static inline u32 media_entity_type(struct media_entity *entity)
145 {
146 return entity->type & MEDIA_ENT_TYPE_MASK;
147 }
148
149 static inline u32 media_entity_subtype(struct media_entity *entity)
150 {
151 return entity->type & MEDIA_ENT_SUBTYPE_MASK;
152 }
153
154 static inline u32 media_entity_id(struct media_entity *entity)
155 {
156 return entity->graph_obj.id;
157 }
158
159 static inline enum media_gobj_type media_type(struct media_gobj *gobj)
160 {
161 return gobj->id >> MEDIA_BITS_PER_LOCAL_ID;
162 }
163
164 static inline u32 media_localid(struct media_gobj *gobj)
165 {
166 return gobj->id & MEDIA_LOCAL_ID_MASK;
167 }
168
169 static inline u32 media_gobj_gen_id(enum media_gobj_type type, u32 local_id)
170 {
171 u32 id;
172
173 id = type << MEDIA_BITS_PER_LOCAL_ID;
174 id |= local_id & MEDIA_LOCAL_ID_MASK;
175
176 return id;
177 }
178
179 #define MEDIA_ENTITY_ENUM_MAX_DEPTH 16
180 #define MEDIA_ENTITY_ENUM_MAX_ID 64
181
182 /*
183 * The number of pads can't be bigger than the number of entities,
184 * as the worse-case scenario is to have one entity linked up to
185 * MEDIA_ENTITY_ENUM_MAX_ID - 1 entities.
186 */
187 #define MEDIA_ENTITY_MAX_PADS (MEDIA_ENTITY_ENUM_MAX_ID - 1)
188
189 struct media_entity_graph {
190 struct {
191 struct media_entity *entity;
192 int link;
193 } stack[MEDIA_ENTITY_ENUM_MAX_DEPTH];
194
195 DECLARE_BITMAP(entities, MEDIA_ENTITY_ENUM_MAX_ID);
196 int top;
197 };
198
199 #define gobj_to_entity(gobj) \
200 container_of(gobj, struct media_entity, graph_obj)
201
202 void media_gobj_init(struct media_device *mdev,
203 enum media_gobj_type type,
204 struct media_gobj *gobj);
205 void media_gobj_remove(struct media_gobj *gobj);
206
207 int media_entity_init(struct media_entity *entity, u16 num_pads,
208 struct media_pad *pads);
209 void media_entity_cleanup(struct media_entity *entity);
210
211 int media_entity_create_link(struct media_entity *source, u16 source_pad,
212 struct media_entity *sink, u16 sink_pad, u32 flags);
213 void __media_entity_remove_links(struct media_entity *entity);
214 void media_entity_remove_links(struct media_entity *entity);
215
216 int __media_entity_setup_link(struct media_link *link, u32 flags);
217 int media_entity_setup_link(struct media_link *link, u32 flags);
218 struct media_link *media_entity_find_link(struct media_pad *source,
219 struct media_pad *sink);
220 struct media_pad *media_entity_remote_pad(struct media_pad *pad);
221
222 struct media_entity *media_entity_get(struct media_entity *entity);
223 void media_entity_put(struct media_entity *entity);
224
225 void media_entity_graph_walk_start(struct media_entity_graph *graph,
226 struct media_entity *entity);
227 struct media_entity *
228 media_entity_graph_walk_next(struct media_entity_graph *graph);
229 __must_check int media_entity_pipeline_start(struct media_entity *entity,
230 struct media_pipeline *pipe);
231 void media_entity_pipeline_stop(struct media_entity *entity);
232
233 #define media_entity_call(entity, operation, args...) \
234 (((entity)->ops && (entity)->ops->operation) ? \
235 (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD)
236
237 #endif
This page took 0.037112 seconds and 4 git commands to generate.