]>
Commit | Line | Data |
---|---|---|
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 | */ |
40 | enum 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 | */ | |
63 | struct media_gobj { | |
39a956c4 | 64 | struct media_device *mdev; |
ec6e4c95 MCC |
65 | u32 id; |
66 | }; | |
67 | ||
68 | ||
e02188c9 LP |
69 | struct media_pipeline { |
70 | }; | |
71 | ||
53e269c1 | 72 | struct 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 | ||
80 | struct 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 |
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); | |
af88be38 | 100 | int (*link_validate)(struct media_link *link); |
97548ed4 LP |
101 | }; |
102 | ||
53e269c1 | 103 | struct media_entity { |
bfab2aac | 104 | struct media_gobj graph_obj; |
53e269c1 | 105 | struct list_head list; |
53e269c1 LP |
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 | ||
97548ed4 LP |
121 | const struct media_entity_operations *ops; /* Entity operations */ |
122 | ||
503c3d82 LP |
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 | */ | |
e02188c9 | 127 | int stream_count; /* Stream count for the entity. */ |
503c3d82 LP |
128 | int use_count; /* Use count for the entity. */ |
129 | ||
e02188c9 LP |
130 | struct media_pipeline *pipe; /* Pipeline this entity belongs to. */ |
131 | ||
53e269c1 LP |
132 | union { |
133 | /* Node specifications */ | |
134 | struct { | |
135 | u32 major; | |
136 | u32 minor; | |
e31a0ba7 | 137 | } dev; |
53e269c1 LP |
138 | |
139 | /* Sub-device specifications */ | |
140 | /* Nothing needed yet */ | |
fa5034c6 | 141 | } info; |
53e269c1 LP |
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 | ||
fa762394 MCC |
154 | static inline u32 media_entity_id(struct media_entity *entity) |
155 | { | |
bfab2aac | 156 | return entity->graph_obj.id; |
fa762394 MCC |
157 | } |
158 | ||
ec6e4c95 MCC |
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 | ||
a5ccc48a | 179 | #define MEDIA_ENTITY_ENUM_MAX_DEPTH 16 |
5c7b25b9 | 180 | #define MEDIA_ENTITY_ENUM_MAX_ID 64 |
a5ccc48a | 181 | |
ef69ee1b MCC |
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 | ||
a5ccc48a SA |
189 | struct media_entity_graph { |
190 | struct { | |
191 | struct media_entity *entity; | |
192 | int link; | |
193 | } stack[MEDIA_ENTITY_ENUM_MAX_DEPTH]; | |
5c7b25b9 LP |
194 | |
195 | DECLARE_BITMAP(entities, MEDIA_ENTITY_ENUM_MAX_ID); | |
a5ccc48a SA |
196 | int top; |
197 | }; | |
198 | ||
ec6e4c95 MCC |
199 | #define gobj_to_entity(gobj) \ |
200 | container_of(gobj, struct media_entity, graph_obj) | |
201 | ||
39a956c4 MCC |
202 | #define gobj_to_pad(gobj) \ |
203 | container_of(gobj, struct media_pad, graph_obj) | |
204 | ||
205 | #define gobj_to_link(gobj) \ | |
206 | container_of(gobj, struct media_link, graph_obj) | |
207 | ||
ec6e4c95 MCC |
208 | void media_gobj_init(struct media_device *mdev, |
209 | enum media_gobj_type type, | |
210 | struct media_gobj *gobj); | |
211 | void media_gobj_remove(struct media_gobj *gobj); | |
212 | ||
53e269c1 | 213 | int media_entity_init(struct media_entity *entity, u16 num_pads, |
18095107 | 214 | struct media_pad *pads); |
53e269c1 | 215 | void media_entity_cleanup(struct media_entity *entity); |
e02188c9 | 216 | |
8df00a15 | 217 | int media_create_pad_link(struct media_entity *source, u16 source_pad, |
53e269c1 | 218 | struct media_entity *sink, u16 sink_pad, u32 flags); |
7349cec1 SN |
219 | void __media_entity_remove_links(struct media_entity *entity); |
220 | void media_entity_remove_links(struct media_entity *entity); | |
221 | ||
97548ed4 LP |
222 | int __media_entity_setup_link(struct media_link *link, u32 flags); |
223 | int media_entity_setup_link(struct media_link *link, u32 flags); | |
224 | struct media_link *media_entity_find_link(struct media_pad *source, | |
225 | struct media_pad *sink); | |
1bddf1b3 | 226 | struct media_pad *media_entity_remote_pad(struct media_pad *pad); |
53e269c1 | 227 | |
503c3d82 LP |
228 | struct media_entity *media_entity_get(struct media_entity *entity); |
229 | void media_entity_put(struct media_entity *entity); | |
230 | ||
a5ccc48a SA |
231 | void media_entity_graph_walk_start(struct media_entity_graph *graph, |
232 | struct media_entity *entity); | |
233 | struct media_entity * | |
234 | media_entity_graph_walk_next(struct media_entity_graph *graph); | |
af88be38 SA |
235 | __must_check int media_entity_pipeline_start(struct media_entity *entity, |
236 | struct media_pipeline *pipe); | |
e02188c9 | 237 | void media_entity_pipeline_stop(struct media_entity *entity); |
a5ccc48a | 238 | |
97548ed4 LP |
239 | #define media_entity_call(entity, operation, args...) \ |
240 | (((entity)->ops && (entity)->ops->operation) ? \ | |
241 | (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD) | |
242 | ||
53e269c1 | 243 | #endif |