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