of: MSI: Simplify irqdomain lookup
[linux/fpc-iii.git] / include / media / media-entity.h
blob197f9379975395dd259defbeb92bf0a5eccd2e86
1 /*
2 * Media entity
4 * Copyright (C) 2010 Nokia Corporation
6 * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
7 * Sakari Ailus <sakari.ailus@iki.fi>
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.
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.
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
23 #ifndef _MEDIA_ENTITY_H
24 #define _MEDIA_ENTITY_H
26 #include <linux/bitops.h>
27 #include <linux/kernel.h>
28 #include <linux/list.h>
29 #include <linux/media.h>
31 struct media_pipeline {
34 struct media_link {
35 struct media_pad *source; /* Source pad */
36 struct media_pad *sink; /* Sink pad */
37 struct media_link *reverse; /* Link in the reverse direction */
38 unsigned long flags; /* Link flags (MEDIA_LNK_FL_*) */
41 struct media_pad {
42 struct media_entity *entity; /* Entity this pad belongs to */
43 u16 index; /* Pad index in the entity pads array */
44 unsigned long flags; /* Pad flags (MEDIA_PAD_FL_*) */
47 /**
48 * struct media_entity_operations - Media entity operations
49 * @link_setup: Notify the entity of link changes. The operation can
50 * return an error, in which case link setup will be
51 * cancelled. Optional.
52 * @link_validate: Return whether a link is valid from the entity point of
53 * view. The media_entity_pipeline_start() function
54 * validates all links by calling this operation. Optional.
56 struct media_entity_operations {
57 int (*link_setup)(struct media_entity *entity,
58 const struct media_pad *local,
59 const struct media_pad *remote, u32 flags);
60 int (*link_validate)(struct media_link *link);
63 struct media_entity {
64 struct list_head list;
65 struct media_device *parent; /* Media device this entity belongs to*/
66 u32 id; /* Entity ID, unique in the parent media
67 * device context */
68 const char *name; /* Entity name */
69 u32 type; /* Entity type (MEDIA_ENT_T_*) */
70 u32 revision; /* Entity revision, driver specific */
71 unsigned long flags; /* Entity flags (MEDIA_ENT_FL_*) */
72 u32 group_id; /* Entity group ID */
74 u16 num_pads; /* Number of sink and source pads */
75 u16 num_links; /* Number of existing links, both
76 * enabled and disabled */
77 u16 num_backlinks; /* Number of backlinks */
78 u16 max_links; /* Maximum number of links */
80 struct media_pad *pads; /* Pads array (num_pads elements) */
81 struct media_link *links; /* Links array (max_links elements)*/
83 const struct media_entity_operations *ops; /* Entity operations */
85 /* Reference counts must never be negative, but are signed integers on
86 * purpose: a simple WARN_ON(<0) check can be used to detect reference
87 * count bugs that would make them negative.
89 int stream_count; /* Stream count for the entity. */
90 int use_count; /* Use count for the entity. */
92 struct media_pipeline *pipe; /* Pipeline this entity belongs to. */
94 union {
95 /* Node specifications */
96 struct {
97 u32 major;
98 u32 minor;
99 } dev;
101 /* Sub-device specifications */
102 /* Nothing needed yet */
103 } info;
106 static inline u32 media_entity_type(struct media_entity *entity)
108 return entity->type & MEDIA_ENT_TYPE_MASK;
111 static inline u32 media_entity_subtype(struct media_entity *entity)
113 return entity->type & MEDIA_ENT_SUBTYPE_MASK;
116 #define MEDIA_ENTITY_ENUM_MAX_DEPTH 16
117 #define MEDIA_ENTITY_ENUM_MAX_ID 64
120 * The number of pads can't be bigger than the number of entities,
121 * as the worse-case scenario is to have one entity linked up to
122 * MEDIA_ENTITY_ENUM_MAX_ID - 1 entities.
124 #define MEDIA_ENTITY_MAX_PADS (MEDIA_ENTITY_ENUM_MAX_ID - 1)
126 struct media_entity_graph {
127 struct {
128 struct media_entity *entity;
129 int link;
130 } stack[MEDIA_ENTITY_ENUM_MAX_DEPTH];
132 DECLARE_BITMAP(entities, MEDIA_ENTITY_ENUM_MAX_ID);
133 int top;
136 int media_entity_init(struct media_entity *entity, u16 num_pads,
137 struct media_pad *pads, u16 extra_links);
138 void media_entity_cleanup(struct media_entity *entity);
140 int media_entity_create_link(struct media_entity *source, u16 source_pad,
141 struct media_entity *sink, u16 sink_pad, u32 flags);
142 void __media_entity_remove_links(struct media_entity *entity);
143 void media_entity_remove_links(struct media_entity *entity);
145 int __media_entity_setup_link(struct media_link *link, u32 flags);
146 int media_entity_setup_link(struct media_link *link, u32 flags);
147 struct media_link *media_entity_find_link(struct media_pad *source,
148 struct media_pad *sink);
149 struct media_pad *media_entity_remote_pad(struct media_pad *pad);
151 struct media_entity *media_entity_get(struct media_entity *entity);
152 void media_entity_put(struct media_entity *entity);
154 void media_entity_graph_walk_start(struct media_entity_graph *graph,
155 struct media_entity *entity);
156 struct media_entity *
157 media_entity_graph_walk_next(struct media_entity_graph *graph);
158 __must_check int media_entity_pipeline_start(struct media_entity *entity,
159 struct media_pipeline *pipe);
160 void media_entity_pipeline_stop(struct media_entity *entity);
162 #define media_entity_call(entity, operation, args...) \
163 (((entity)->ops && (entity)->ops->operation) ? \
164 (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD)
166 #endif