[media] replace all occurrences of MEDIA_ENT_T_DEVNODE_DVB
[linux-block.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
27e543fa
MCC
39 * @MEDIA_GRAPH_INTF_DEVNODE: Identify a media Kernel API interface via
40 * a device node
ec6e4c95
MCC
41 */
42enum media_gobj_type {
bfab2aac 43 MEDIA_GRAPH_ENTITY,
18710dc6 44 MEDIA_GRAPH_PAD,
6b6a4278 45 MEDIA_GRAPH_LINK,
27e543fa 46 MEDIA_GRAPH_INTF_DEVNODE,
ec6e4c95
MCC
47};
48
49#define MEDIA_BITS_PER_TYPE 8
50#define MEDIA_BITS_PER_LOCAL_ID (32 - MEDIA_BITS_PER_TYPE)
51#define MEDIA_LOCAL_ID_MASK GENMASK(MEDIA_BITS_PER_LOCAL_ID - 1, 0)
52
53/* Structs to represent the objects that belong to a media graph */
54
55/**
56 * struct media_gobj - Define a graph object.
57 *
58 * @id: Non-zero object ID identifier. The ID should be unique
59 * inside a media_device, as it is composed by
60 * MEDIA_BITS_PER_TYPE to store the type plus
61 * MEDIA_BITS_PER_LOCAL_ID to store a per-type ID
62 * (called as "local ID").
63 *
64 * All objects on the media graph should have this struct embedded
65 */
66struct media_gobj {
39a956c4 67 struct media_device *mdev;
ec6e4c95
MCC
68 u32 id;
69};
70
71
e02188c9
LP
72struct media_pipeline {
73};
74
53e269c1 75struct media_link {
6b6a4278 76 struct media_gobj graph_obj;
57208e5e 77 struct list_head list;
4b8a3c08
MCC
78 union {
79 struct media_gobj *gobj0;
80 struct media_pad *source;
86e26620 81 struct media_interface *intf;
4b8a3c08
MCC
82 };
83 union {
84 struct media_gobj *gobj1;
85 struct media_pad *sink;
86e26620 86 struct media_entity *entity;
4b8a3c08 87 };
53e269c1
LP
88 struct media_link *reverse; /* Link in the reverse direction */
89 unsigned long flags; /* Link flags (MEDIA_LNK_FL_*) */
90};
91
92struct media_pad {
4b8a3c08 93 struct media_gobj graph_obj; /* must be first field in struct */
53e269c1
LP
94 struct media_entity *entity; /* Entity this pad belongs to */
95 u16 index; /* Pad index in the entity pads array */
96 unsigned long flags; /* Pad flags (MEDIA_PAD_FL_*) */
97};
98
5a5394be
LP
99/**
100 * struct media_entity_operations - Media entity operations
101 * @link_setup: Notify the entity of link changes. The operation can
102 * return an error, in which case link setup will be
103 * cancelled. Optional.
104 * @link_validate: Return whether a link is valid from the entity point of
105 * view. The media_entity_pipeline_start() function
106 * validates all links by calling this operation. Optional.
107 */
97548ed4
LP
108struct media_entity_operations {
109 int (*link_setup)(struct media_entity *entity,
110 const struct media_pad *local,
111 const struct media_pad *remote, u32 flags);
af88be38 112 int (*link_validate)(struct media_link *link);
97548ed4
LP
113};
114
53e269c1 115struct media_entity {
4b8a3c08 116 struct media_gobj graph_obj; /* must be first field in struct */
53e269c1 117 struct list_head list;
53e269c1
LP
118 const char *name; /* Entity name */
119 u32 type; /* Entity type (MEDIA_ENT_T_*) */
120 u32 revision; /* Entity revision, driver specific */
121 unsigned long flags; /* Entity flags (MEDIA_ENT_FL_*) */
122 u32 group_id; /* Entity group ID */
123
124 u16 num_pads; /* Number of sink and source pads */
125 u16 num_links; /* Number of existing links, both
126 * enabled and disabled */
127 u16 num_backlinks; /* Number of backlinks */
53e269c1 128
57208e5e 129 struct media_pad *pads; /* Pads array (num_pads objects) */
4b8a3c08 130 struct list_head links; /* Pad-to-pad links list */
53e269c1 131
97548ed4
LP
132 const struct media_entity_operations *ops; /* Entity operations */
133
503c3d82
LP
134 /* Reference counts must never be negative, but are signed integers on
135 * purpose: a simple WARN_ON(<0) check can be used to detect reference
136 * count bugs that would make them negative.
137 */
e02188c9 138 int stream_count; /* Stream count for the entity. */
503c3d82
LP
139 int use_count; /* Use count for the entity. */
140
e02188c9
LP
141 struct media_pipeline *pipe; /* Pipeline this entity belongs to. */
142
53e269c1
LP
143 union {
144 /* Node specifications */
145 struct {
146 u32 major;
147 u32 minor;
e31a0ba7 148 } dev;
53e269c1
LP
149
150 /* Sub-device specifications */
151 /* Nothing needed yet */
fa5034c6 152 } info;
53e269c1
LP
153};
154
27e543fa
MCC
155/**
156 * struct media_intf_devnode - Define a Kernel API interface
157 *
158 * @graph_obj: embedded graph object
57cf79b7
MCC
159 * @list: Linked list used to find other interfaces that belong
160 * to the same media controller
86e26620 161 * @links: List of links pointing to graph entities
27e543fa
MCC
162 * @type: Type of the interface as defined at the
163 * uapi/media/media.h header, e. g.
164 * MEDIA_INTF_T_*
165 * @flags: Interface flags as defined at uapi/media/media.h
166 */
167struct media_interface {
168 struct media_gobj graph_obj;
57cf79b7 169 struct list_head list;
86e26620 170 struct list_head links;
27e543fa
MCC
171 u32 type;
172 u32 flags;
173};
174
175/**
176 * struct media_intf_devnode - Define a Kernel API interface via a device node
177 *
178 * @intf: embedded interface object
179 * @major: Major number of a device node
180 * @minor: Minor number of a device node
181 */
182struct media_intf_devnode {
183 struct media_interface intf;
184 u32 major;
185 u32 minor;
186};
187
53e269c1
LP
188static inline u32 media_entity_type(struct media_entity *entity)
189{
190 return entity->type & MEDIA_ENT_TYPE_MASK;
191}
192
193static inline u32 media_entity_subtype(struct media_entity *entity)
194{
195 return entity->type & MEDIA_ENT_SUBTYPE_MASK;
196}
197
fa762394
MCC
198static inline u32 media_entity_id(struct media_entity *entity)
199{
bfab2aac 200 return entity->graph_obj.id;
fa762394
MCC
201}
202
ec6e4c95
MCC
203static inline enum media_gobj_type media_type(struct media_gobj *gobj)
204{
205 return gobj->id >> MEDIA_BITS_PER_LOCAL_ID;
206}
207
208static inline u32 media_localid(struct media_gobj *gobj)
209{
210 return gobj->id & MEDIA_LOCAL_ID_MASK;
211}
212
213static inline u32 media_gobj_gen_id(enum media_gobj_type type, u32 local_id)
214{
215 u32 id;
216
217 id = type << MEDIA_BITS_PER_LOCAL_ID;
218 id |= local_id & MEDIA_LOCAL_ID_MASK;
219
220 return id;
221}
222
a5ccc48a 223#define MEDIA_ENTITY_ENUM_MAX_DEPTH 16
5c7b25b9 224#define MEDIA_ENTITY_ENUM_MAX_ID 64
a5ccc48a 225
ef69ee1b
MCC
226/*
227 * The number of pads can't be bigger than the number of entities,
228 * as the worse-case scenario is to have one entity linked up to
229 * MEDIA_ENTITY_ENUM_MAX_ID - 1 entities.
230 */
231#define MEDIA_ENTITY_MAX_PADS (MEDIA_ENTITY_ENUM_MAX_ID - 1)
232
a5ccc48a
SA
233struct media_entity_graph {
234 struct {
235 struct media_entity *entity;
57208e5e 236 struct list_head *link;
a5ccc48a 237 } stack[MEDIA_ENTITY_ENUM_MAX_DEPTH];
5c7b25b9
LP
238
239 DECLARE_BITMAP(entities, MEDIA_ENTITY_ENUM_MAX_ID);
a5ccc48a
SA
240 int top;
241};
242
ec6e4c95
MCC
243#define gobj_to_entity(gobj) \
244 container_of(gobj, struct media_entity, graph_obj)
245
39a956c4
MCC
246#define gobj_to_pad(gobj) \
247 container_of(gobj, struct media_pad, graph_obj)
248
249#define gobj_to_link(gobj) \
250 container_of(gobj, struct media_link, graph_obj)
251
27e543fa
MCC
252#define gobj_to_link(gobj) \
253 container_of(gobj, struct media_link, graph_obj)
254
255#define gobj_to_pad(gobj) \
256 container_of(gobj, struct media_pad, graph_obj)
257
258#define gobj_to_intf(gobj) \
259 container_of(gobj, struct media_interface, graph_obj)
260
261#define intf_to_devnode(intf) \
262 container_of(intf, struct media_intf_devnode, intf)
263
ec6e4c95
MCC
264void media_gobj_init(struct media_device *mdev,
265 enum media_gobj_type type,
266 struct media_gobj *gobj);
267void media_gobj_remove(struct media_gobj *gobj);
268
53e269c1 269int media_entity_init(struct media_entity *entity, u16 num_pads,
57208e5e 270 struct media_pad *pads);
53e269c1 271void media_entity_cleanup(struct media_entity *entity);
e02188c9 272
8df00a15 273int media_create_pad_link(struct media_entity *source, u16 source_pad,
53e269c1 274 struct media_entity *sink, u16 sink_pad, u32 flags);
7349cec1
SN
275void __media_entity_remove_links(struct media_entity *entity);
276void media_entity_remove_links(struct media_entity *entity);
277
97548ed4
LP
278int __media_entity_setup_link(struct media_link *link, u32 flags);
279int media_entity_setup_link(struct media_link *link, u32 flags);
280struct media_link *media_entity_find_link(struct media_pad *source,
281 struct media_pad *sink);
1bddf1b3 282struct media_pad *media_entity_remote_pad(struct media_pad *pad);
53e269c1 283
503c3d82
LP
284struct media_entity *media_entity_get(struct media_entity *entity);
285void media_entity_put(struct media_entity *entity);
286
a5ccc48a
SA
287void media_entity_graph_walk_start(struct media_entity_graph *graph,
288 struct media_entity *entity);
289struct media_entity *
290media_entity_graph_walk_next(struct media_entity_graph *graph);
af88be38
SA
291__must_check int media_entity_pipeline_start(struct media_entity *entity,
292 struct media_pipeline *pipe);
e02188c9 293void media_entity_pipeline_stop(struct media_entity *entity);
a5ccc48a 294
27e543fa
MCC
295struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
296 u32 type, u32 flags,
297 u32 major, u32 minor,
298 gfp_t gfp_flags);
299void media_devnode_remove(struct media_intf_devnode *devnode);
86e26620
MCC
300struct media_link *media_create_intf_link(struct media_entity *entity,
301 struct media_interface *intf,
302 u32 flags);
303void media_remove_intf_link(struct media_link *link);
304
97548ed4
LP
305#define media_entity_call(entity, operation, args...) \
306 (((entity)->ops && (entity)->ops->operation) ? \
307 (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD)
308
53e269c1 309#endif