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> |
53e269c1 | 27 | #include <linux/list.h> |
1651333b | 28 | #include <linux/media.h> |
53e269c1 | 29 | |
e02188c9 LP |
30 | struct media_pipeline { |
31 | }; | |
32 | ||
53e269c1 LP |
33 | struct media_link { |
34 | struct media_pad *source; /* Source pad */ | |
35 | struct media_pad *sink; /* Sink pad */ | |
36 | struct media_link *reverse; /* Link in the reverse direction */ | |
37 | unsigned long flags; /* Link flags (MEDIA_LNK_FL_*) */ | |
38 | }; | |
39 | ||
40 | struct media_pad { | |
41 | struct media_entity *entity; /* Entity this pad belongs to */ | |
42 | u16 index; /* Pad index in the entity pads array */ | |
43 | unsigned long flags; /* Pad flags (MEDIA_PAD_FL_*) */ | |
44 | }; | |
45 | ||
97548ed4 LP |
46 | struct media_entity_operations { |
47 | int (*link_setup)(struct media_entity *entity, | |
48 | const struct media_pad *local, | |
49 | const struct media_pad *remote, u32 flags); | |
af88be38 | 50 | int (*link_validate)(struct media_link *link); |
97548ed4 LP |
51 | }; |
52 | ||
53e269c1 LP |
53 | struct media_entity { |
54 | struct list_head list; | |
55 | struct media_device *parent; /* Media device this entity belongs to*/ | |
56 | u32 id; /* Entity ID, unique in the parent media | |
57 | * device context */ | |
58 | const char *name; /* Entity name */ | |
59 | u32 type; /* Entity type (MEDIA_ENT_T_*) */ | |
60 | u32 revision; /* Entity revision, driver specific */ | |
61 | unsigned long flags; /* Entity flags (MEDIA_ENT_FL_*) */ | |
62 | u32 group_id; /* Entity group ID */ | |
63 | ||
64 | u16 num_pads; /* Number of sink and source pads */ | |
65 | u16 num_links; /* Number of existing links, both | |
66 | * enabled and disabled */ | |
67 | u16 num_backlinks; /* Number of backlinks */ | |
68 | u16 max_links; /* Maximum number of links */ | |
69 | ||
70 | struct media_pad *pads; /* Pads array (num_pads elements) */ | |
71 | struct media_link *links; /* Links array (max_links elements)*/ | |
72 | ||
97548ed4 LP |
73 | const struct media_entity_operations *ops; /* Entity operations */ |
74 | ||
503c3d82 LP |
75 | /* Reference counts must never be negative, but are signed integers on |
76 | * purpose: a simple WARN_ON(<0) check can be used to detect reference | |
77 | * count bugs that would make them negative. | |
78 | */ | |
e02188c9 | 79 | int stream_count; /* Stream count for the entity. */ |
503c3d82 LP |
80 | int use_count; /* Use count for the entity. */ |
81 | ||
e02188c9 LP |
82 | struct media_pipeline *pipe; /* Pipeline this entity belongs to. */ |
83 | ||
53e269c1 LP |
84 | union { |
85 | /* Node specifications */ | |
86 | struct { | |
87 | u32 major; | |
88 | u32 minor; | |
89 | } v4l; | |
90 | struct { | |
91 | u32 major; | |
92 | u32 minor; | |
93 | } fb; | |
94 | struct { | |
95 | u32 card; | |
96 | u32 device; | |
97 | u32 subdevice; | |
98 | } alsa; | |
99 | int dvb; | |
100 | ||
101 | /* Sub-device specifications */ | |
102 | /* Nothing needed yet */ | |
fa5034c6 | 103 | } info; |
53e269c1 LP |
104 | }; |
105 | ||
106 | static inline u32 media_entity_type(struct media_entity *entity) | |
107 | { | |
108 | return entity->type & MEDIA_ENT_TYPE_MASK; | |
109 | } | |
110 | ||
111 | static inline u32 media_entity_subtype(struct media_entity *entity) | |
112 | { | |
113 | return entity->type & MEDIA_ENT_SUBTYPE_MASK; | |
114 | } | |
115 | ||
a5ccc48a | 116 | #define MEDIA_ENTITY_ENUM_MAX_DEPTH 16 |
5c7b25b9 | 117 | #define MEDIA_ENTITY_ENUM_MAX_ID 64 |
a5ccc48a SA |
118 | |
119 | struct media_entity_graph { | |
120 | struct { | |
121 | struct media_entity *entity; | |
122 | int link; | |
123 | } stack[MEDIA_ENTITY_ENUM_MAX_DEPTH]; | |
5c7b25b9 LP |
124 | |
125 | DECLARE_BITMAP(entities, MEDIA_ENTITY_ENUM_MAX_ID); | |
a5ccc48a SA |
126 | int top; |
127 | }; | |
128 | ||
53e269c1 LP |
129 | int media_entity_init(struct media_entity *entity, u16 num_pads, |
130 | struct media_pad *pads, u16 extra_links); | |
131 | void media_entity_cleanup(struct media_entity *entity); | |
e02188c9 | 132 | |
53e269c1 LP |
133 | int media_entity_create_link(struct media_entity *source, u16 source_pad, |
134 | struct media_entity *sink, u16 sink_pad, u32 flags); | |
7349cec1 SN |
135 | void __media_entity_remove_links(struct media_entity *entity); |
136 | void media_entity_remove_links(struct media_entity *entity); | |
137 | ||
97548ed4 LP |
138 | int __media_entity_setup_link(struct media_link *link, u32 flags); |
139 | int media_entity_setup_link(struct media_link *link, u32 flags); | |
140 | struct media_link *media_entity_find_link(struct media_pad *source, | |
141 | struct media_pad *sink); | |
1bddf1b3 | 142 | struct media_pad *media_entity_remote_pad(struct media_pad *pad); |
53e269c1 | 143 | |
503c3d82 LP |
144 | struct media_entity *media_entity_get(struct media_entity *entity); |
145 | void media_entity_put(struct media_entity *entity); | |
146 | ||
a5ccc48a SA |
147 | void media_entity_graph_walk_start(struct media_entity_graph *graph, |
148 | struct media_entity *entity); | |
149 | struct media_entity * | |
150 | media_entity_graph_walk_next(struct media_entity_graph *graph); | |
af88be38 SA |
151 | __must_check int media_entity_pipeline_start(struct media_entity *entity, |
152 | struct media_pipeline *pipe); | |
e02188c9 | 153 | void media_entity_pipeline_stop(struct media_entity *entity); |
a5ccc48a | 154 | |
97548ed4 LP |
155 | #define media_entity_call(entity, operation, args...) \ |
156 | (((entity)->ops && (entity)->ops->operation) ? \ | |
157 | (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD) | |
158 | ||
53e269c1 | 159 | #endif |