diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/media/media-device.h | 469 | ||||
-rw-r--r-- | include/media/media-devnode.h | 54 | ||||
-rw-r--r-- | include/media/media-entity.h | 904 | ||||
-rw-r--r-- | include/media/tuner.h | 8 | ||||
-rw-r--r-- | include/media/v4l2-dev.h | 1 | ||||
-rw-r--r-- | include/uapi/linux/media.h | 228 |
6 files changed, 1581 insertions, 83 deletions
diff --git a/include/media/media-device.h b/include/media/media-device.h index 6e6db78f1ee2..d3855898c3fc 100644 --- a/include/media/media-device.h +++ b/include/media/media-device.h | |||
@@ -30,6 +30,238 @@ | |||
30 | #include <media/media-devnode.h> | 30 | #include <media/media-devnode.h> |
31 | #include <media/media-entity.h> | 31 | #include <media/media-entity.h> |
32 | 32 | ||
33 | /** | ||
34 | * DOC: Media Controller | ||
35 | * | ||
36 | * The media controller userspace API is documented in DocBook format in | ||
37 | * Documentation/DocBook/media/v4l/media-controller.xml. This document focus | ||
38 | * on the kernel-side implementation of the media framework. | ||
39 | * | ||
40 | * * Abstract media device model: | ||
41 | * | ||
42 | * Discovering a device internal topology, and configuring it at runtime, is one | ||
43 | * of the goals of the media framework. To achieve this, hardware devices are | ||
44 | * modelled as an oriented graph of building blocks called entities connected | ||
45 | * through pads. | ||
46 | * | ||
47 | * An entity is a basic media hardware building block. It can correspond to | ||
48 | * a large variety of logical blocks such as physical hardware devices | ||
49 | * (CMOS sensor for instance), logical hardware devices (a building block | ||
50 | * in a System-on-Chip image processing pipeline), DMA channels or physical | ||
51 | * connectors. | ||
52 | * | ||
53 | * A pad is a connection endpoint through which an entity can interact with | ||
54 | * other entities. Data (not restricted to video) produced by an entity | ||
55 | * flows from the entity's output to one or more entity inputs. Pads should | ||
56 | * not be confused with physical pins at chip boundaries. | ||
57 | * | ||
58 | * A link is a point-to-point oriented connection between two pads, either | ||
59 | * on the same entity or on different entities. Data flows from a source | ||
60 | * pad to a sink pad. | ||
61 | * | ||
62 | * | ||
63 | * * Media device: | ||
64 | * | ||
65 | * A media device is represented by a struct &media_device instance, defined in | ||
66 | * include/media/media-device.h. Allocation of the structure is handled by the | ||
67 | * media device driver, usually by embedding the &media_device instance in a | ||
68 | * larger driver-specific structure. | ||
69 | * | ||
70 | * Drivers register media device instances by calling | ||
71 | * __media_device_register() via the macro media_device_register() | ||
72 | * and unregistered by calling | ||
73 | * media_device_unregister(). | ||
74 | * | ||
75 | * * Entities, pads and links: | ||
76 | * | ||
77 | * - Entities | ||
78 | * | ||
79 | * Entities are represented by a struct &media_entity instance, defined in | ||
80 | * include/media/media-entity.h. The structure is usually embedded into a | ||
81 | * higher-level structure, such as a v4l2_subdev or video_device instance, | ||
82 | * although drivers can allocate entities directly. | ||
83 | * | ||
84 | * Drivers initialize entity pads by calling | ||
85 | * media_entity_pads_init(). | ||
86 | * | ||
87 | * Drivers register entities with a media device by calling | ||
88 | * media_device_register_entity() | ||
89 | * and unregistred by calling | ||
90 | * media_device_unregister_entity(). | ||
91 | * | ||
92 | * - Interfaces | ||
93 | * | ||
94 | * Interfaces are represented by a struct &media_interface instance, defined in | ||
95 | * include/media/media-entity.h. Currently, only one type of interface is | ||
96 | * defined: a device node. Such interfaces are represented by a struct | ||
97 | * &media_intf_devnode. | ||
98 | * | ||
99 | * Drivers initialize and create device node interfaces by calling | ||
100 | * media_devnode_create() | ||
101 | * and remove them by calling: | ||
102 | * media_devnode_remove(). | ||
103 | * | ||
104 | * - Pads | ||
105 | * | ||
106 | * Pads are represented by a struct &media_pad instance, defined in | ||
107 | * include/media/media-entity.h. Each entity stores its pads in a pads array | ||
108 | * managed by the entity driver. Drivers usually embed the array in a | ||
109 | * driver-specific structure. | ||
110 | * | ||
111 | * Pads are identified by their entity and their 0-based index in the pads | ||
112 | * array. | ||
113 | * Both information are stored in the &media_pad structure, making the | ||
114 | * &media_pad pointer the canonical way to store and pass link references. | ||
115 | * | ||
116 | * Pads have flags that describe the pad capabilities and state. | ||
117 | * | ||
118 | * %MEDIA_PAD_FL_SINK indicates that the pad supports sinking data. | ||
119 | * %MEDIA_PAD_FL_SOURCE indicates that the pad supports sourcing data. | ||
120 | * | ||
121 | * NOTE: One and only one of %MEDIA_PAD_FL_SINK and %MEDIA_PAD_FL_SOURCE must | ||
122 | * be set for each pad. | ||
123 | * | ||
124 | * - Links | ||
125 | * | ||
126 | * Links are represented by a struct &media_link instance, defined in | ||
127 | * include/media/media-entity.h. There are two types of links: | ||
128 | * | ||
129 | * 1. pad to pad links: | ||
130 | * | ||
131 | * Associate two entities via their PADs. Each entity has a list that points | ||
132 | * to all links originating at or targeting any of its pads. | ||
133 | * A given link is thus stored twice, once in the source entity and once in | ||
134 | * the target entity. | ||
135 | * | ||
136 | * Drivers create pad to pad links by calling: | ||
137 | * media_create_pad_link() and remove with media_entity_remove_links(). | ||
138 | * | ||
139 | * 2. interface to entity links: | ||
140 | * | ||
141 | * Associate one interface to a Link. | ||
142 | * | ||
143 | * Drivers create interface to entity links by calling: | ||
144 | * media_create_intf_link() and remove with media_remove_intf_links(). | ||
145 | * | ||
146 | * NOTE: | ||
147 | * | ||
148 | * Links can only be created after having both ends already created. | ||
149 | * | ||
150 | * Links have flags that describe the link capabilities and state. The | ||
151 | * valid values are described at media_create_pad_link() and | ||
152 | * media_create_intf_link(). | ||
153 | * | ||
154 | * Graph traversal: | ||
155 | * | ||
156 | * The media framework provides APIs to iterate over entities in a graph. | ||
157 | * | ||
158 | * To iterate over all entities belonging to a media device, drivers can use | ||
159 | * the media_device_for_each_entity macro, defined in | ||
160 | * include/media/media-device.h. | ||
161 | * | ||
162 | * struct media_entity *entity; | ||
163 | * | ||
164 | * media_device_for_each_entity(entity, mdev) { | ||
165 | * // entity will point to each entity in turn | ||
166 | * ... | ||
167 | * } | ||
168 | * | ||
169 | * Drivers might also need to iterate over all entities in a graph that can be | ||
170 | * reached only through enabled links starting at a given entity. The media | ||
171 | * framework provides a depth-first graph traversal API for that purpose. | ||
172 | * | ||
173 | * Note that graphs with cycles (whether directed or undirected) are *NOT* | ||
174 | * supported by the graph traversal API. To prevent infinite loops, the graph | ||
175 | * traversal code limits the maximum depth to MEDIA_ENTITY_ENUM_MAX_DEPTH, | ||
176 | * currently defined as 16. | ||
177 | * | ||
178 | * Drivers initiate a graph traversal by calling | ||
179 | * media_entity_graph_walk_start() | ||
180 | * | ||
181 | * The graph structure, provided by the caller, is initialized to start graph | ||
182 | * traversal at the given entity. | ||
183 | * | ||
184 | * Drivers can then retrieve the next entity by calling | ||
185 | * media_entity_graph_walk_next() | ||
186 | * | ||
187 | * When the graph traversal is complete the function will return NULL. | ||
188 | * | ||
189 | * Graph traversal can be interrupted at any moment. No cleanup function call | ||
190 | * is required and the graph structure can be freed normally. | ||
191 | * | ||
192 | * Helper functions can be used to find a link between two given pads, or a pad | ||
193 | * connected to another pad through an enabled link | ||
194 | * media_entity_find_link() and media_entity_remote_pad() | ||
195 | * | ||
196 | * Use count and power handling: | ||
197 | * | ||
198 | * Due to the wide differences between drivers regarding power management | ||
199 | * needs, the media controller does not implement power management. However, | ||
200 | * the &media_entity structure includes a use_count field that media drivers | ||
201 | * can use to track the number of users of every entity for power management | ||
202 | * needs. | ||
203 | * | ||
204 | * The &media_entity.@use_count field is owned by media drivers and must not be | ||
205 | * touched by entity drivers. Access to the field must be protected by the | ||
206 | * &media_device.@graph_mutex lock. | ||
207 | * | ||
208 | * Links setup: | ||
209 | * | ||
210 | * Link properties can be modified at runtime by calling | ||
211 | * media_entity_setup_link() | ||
212 | * | ||
213 | * Pipelines and media streams: | ||
214 | * | ||
215 | * When starting streaming, drivers must notify all entities in the pipeline to | ||
216 | * prevent link states from being modified during streaming by calling | ||
217 | * media_entity_pipeline_start(). | ||
218 | * | ||
219 | * The function will mark all entities connected to the given entity through | ||
220 | * enabled links, either directly or indirectly, as streaming. | ||
221 | * | ||
222 | * The &media_pipeline instance pointed to by the pipe argument will be stored | ||
223 | * in every entity in the pipeline. Drivers should embed the &media_pipeline | ||
224 | * structure in higher-level pipeline structures and can then access the | ||
225 | * pipeline through the &media_entity pipe field. | ||
226 | * | ||
227 | * Calls to media_entity_pipeline_start() can be nested. The pipeline pointer | ||
228 | * must be identical for all nested calls to the function. | ||
229 | * | ||
230 | * media_entity_pipeline_start() may return an error. In that case, it will | ||
231 | * clean up any of the changes it did by itself. | ||
232 | * | ||
233 | * When stopping the stream, drivers must notify the entities with | ||
234 | * media_entity_pipeline_stop(). | ||
235 | * | ||
236 | * If multiple calls to media_entity_pipeline_start() have been made the same | ||
237 | * number of media_entity_pipeline_stop() calls are required to stop streaming. | ||
238 | * The &media_entity pipe field is reset to NULL on the last nested stop call. | ||
239 | * | ||
240 | * Link configuration will fail with -%EBUSY by default if either end of the | ||
241 | * link is a streaming entity. Links that can be modified while streaming must | ||
242 | * be marked with the %MEDIA_LNK_FL_DYNAMIC flag. | ||
243 | * | ||
244 | * If other operations need to be disallowed on streaming entities (such as | ||
245 | * changing entities configuration parameters) drivers can explicitly check the | ||
246 | * media_entity stream_count field to find out if an entity is streaming. This | ||
247 | * operation must be done with the media_device graph_mutex held. | ||
248 | * | ||
249 | * Link validation: | ||
250 | * | ||
251 | * Link validation is performed by media_entity_pipeline_start() for any | ||
252 | * entity which has sink pads in the pipeline. The | ||
253 | * &media_entity.@link_validate() callback is used for that purpose. In | ||
254 | * @link_validate() callback, entity driver should check that the properties of | ||
255 | * the source pad of the connected entity and its own sink pad match. It is up | ||
256 | * to the type of the entity (and in the end, the properties of the hardware) | ||
257 | * what matching actually means. | ||
258 | * | ||
259 | * Subsystems should facilitate link validation by providing subsystem specific | ||
260 | * helper functions to provide easy access for commonly needed information, and | ||
261 | * in the end provide a way to use driver-specific callbacks. | ||
262 | */ | ||
263 | |||
264 | struct ida; | ||
33 | struct device; | 265 | struct device; |
34 | 266 | ||
35 | /** | 267 | /** |
@@ -41,8 +273,16 @@ struct device; | |||
41 | * @bus_info: Unique and stable device location identifier | 273 | * @bus_info: Unique and stable device location identifier |
42 | * @hw_revision: Hardware device revision | 274 | * @hw_revision: Hardware device revision |
43 | * @driver_version: Device driver version | 275 | * @driver_version: Device driver version |
44 | * @entity_id: ID of the next entity to be registered | 276 | * @topology_version: Monotonic counter for storing the version of the graph |
277 | * topology. Should be incremented each time the topology changes. | ||
278 | * @id: Unique ID used on the last registered graph object | ||
279 | * @entity_internal_idx: Unique internal entity ID used by the graph traversal | ||
280 | * algorithms | ||
281 | * @entity_internal_idx_max: Allocated internal entity indices | ||
45 | * @entities: List of registered entities | 282 | * @entities: List of registered entities |
283 | * @interfaces: List of registered interfaces | ||
284 | * @pads: List of registered pads | ||
285 | * @links: List of registered links | ||
46 | * @lock: Entities list lock | 286 | * @lock: Entities list lock |
47 | * @graph_mutex: Entities graph operation lock | 287 | * @graph_mutex: Entities graph operation lock |
48 | * @link_notify: Link state change notification callback | 288 | * @link_notify: Link state change notification callback |
@@ -68,10 +308,18 @@ struct media_device { | |||
68 | u32 hw_revision; | 308 | u32 hw_revision; |
69 | u32 driver_version; | 309 | u32 driver_version; |
70 | 310 | ||
71 | u32 entity_id; | 311 | u32 topology_version; |
312 | |||
313 | u32 id; | ||
314 | struct ida entity_internal_idx; | ||
315 | int entity_internal_idx_max; | ||
316 | |||
72 | struct list_head entities; | 317 | struct list_head entities; |
318 | struct list_head interfaces; | ||
319 | struct list_head pads; | ||
320 | struct list_head links; | ||
73 | 321 | ||
74 | /* Protects the entities list */ | 322 | /* Protects the graph objects creation/removal */ |
75 | spinlock_t lock; | 323 | spinlock_t lock; |
76 | /* Serializes graph operations. */ | 324 | /* Serializes graph operations. */ |
77 | struct mutex graph_mutex; | 325 | struct mutex graph_mutex; |
@@ -80,6 +328,8 @@ struct media_device { | |||
80 | unsigned int notification); | 328 | unsigned int notification); |
81 | }; | 329 | }; |
82 | 330 | ||
331 | #ifdef CONFIG_MEDIA_CONTROLLER | ||
332 | |||
83 | /* Supported link_notify @notification values. */ | 333 | /* Supported link_notify @notification values. */ |
84 | #define MEDIA_DEV_NOTIFY_PRE_LINK_CH 0 | 334 | #define MEDIA_DEV_NOTIFY_PRE_LINK_CH 0 |
85 | #define MEDIA_DEV_NOTIFY_POST_LINK_CH 1 | 335 | #define MEDIA_DEV_NOTIFY_POST_LINK_CH 1 |
@@ -87,17 +337,228 @@ struct media_device { | |||
87 | /* media_devnode to media_device */ | 337 | /* media_devnode to media_device */ |
88 | #define to_media_device(node) container_of(node, struct media_device, devnode) | 338 | #define to_media_device(node) container_of(node, struct media_device, devnode) |
89 | 339 | ||
340 | /** | ||
341 | * media_entity_enum_init - Initialise an entity enumeration | ||
342 | * | ||
343 | * @ent_enum: Entity enumeration to be initialised | ||
344 | * @mdev: The related media device | ||
345 | * | ||
346 | * Returns zero on success or a negative error code. | ||
347 | */ | ||
348 | static inline __must_check int media_entity_enum_init( | ||
349 | struct media_entity_enum *ent_enum, struct media_device *mdev) | ||
350 | { | ||
351 | return __media_entity_enum_init(ent_enum, | ||
352 | mdev->entity_internal_idx_max + 1); | ||
353 | } | ||
354 | |||
355 | /** | ||
356 | * media_device_init() - Initializes a media device element | ||
357 | * | ||
358 | * @mdev: pointer to struct &media_device | ||
359 | * | ||
360 | * This function initializes the media device prior to its registration. | ||
361 | * The media device initialization and registration is split in two functions | ||
362 | * to avoid race conditions and make the media device available to user-space | ||
363 | * before the media graph has been completed. | ||
364 | * | ||
365 | * So drivers need to first initialize the media device, register any entity | ||
366 | * within the media device, create pad to pad links and then finally register | ||
367 | * the media device by calling media_device_register() as a final step. | ||
368 | */ | ||
369 | void media_device_init(struct media_device *mdev); | ||
370 | |||
371 | /** | ||
372 | * media_device_cleanup() - Cleanups a media device element | ||
373 | * | ||
374 | * @mdev: pointer to struct &media_device | ||
375 | * | ||
376 | * This function that will destroy the graph_mutex that is | ||
377 | * initialized in media_device_init(). | ||
378 | */ | ||
379 | void media_device_cleanup(struct media_device *mdev); | ||
380 | |||
381 | /** | ||
382 | * __media_device_register() - Registers a media device element | ||
383 | * | ||
384 | * @mdev: pointer to struct &media_device | ||
385 | * @owner: should be filled with %THIS_MODULE | ||
386 | * | ||
387 | * Users, should, instead, call the media_device_register() macro. | ||
388 | * | ||
389 | * The caller is responsible for initializing the media_device structure before | ||
390 | * registration. The following fields must be set: | ||
391 | * | ||
392 | * - dev must point to the parent device (usually a &pci_dev, &usb_interface or | ||
393 | * &platform_device instance). | ||
394 | * | ||
395 | * - model must be filled with the device model name as a NUL-terminated UTF-8 | ||
396 | * string. The device/model revision must not be stored in this field. | ||
397 | * | ||
398 | * The following fields are optional: | ||
399 | * | ||
400 | * - serial is a unique serial number stored as a NUL-terminated ASCII string. | ||
401 | * The field is big enough to store a GUID in text form. If the hardware | ||
402 | * doesn't provide a unique serial number this field must be left empty. | ||
403 | * | ||
404 | * - bus_info represents the location of the device in the system as a | ||
405 | * NUL-terminated ASCII string. For PCI/PCIe devices bus_info must be set to | ||
406 | * "PCI:" (or "PCIe:") followed by the value of pci_name(). For USB devices, | ||
407 | * the usb_make_path() function must be used. This field is used by | ||
408 | * applications to distinguish between otherwise identical devices that don't | ||
409 | * provide a serial number. | ||
410 | * | ||
411 | * - hw_revision is the hardware device revision in a driver-specific format. | ||
412 | * When possible the revision should be formatted with the KERNEL_VERSION | ||
413 | * macro. | ||
414 | * | ||
415 | * - driver_version is formatted with the KERNEL_VERSION macro. The version | ||
416 | * minor must be incremented when new features are added to the userspace API | ||
417 | * without breaking binary compatibility. The version major must be | ||
418 | * incremented when binary compatibility is broken. | ||
419 | * | ||
420 | * Notes: | ||
421 | * | ||
422 | * Upon successful registration a character device named media[0-9]+ is created. | ||
423 | * The device major and minor numbers are dynamic. The model name is exported as | ||
424 | * a sysfs attribute. | ||
425 | * | ||
426 | * Unregistering a media device that hasn't been registered is *NOT* safe. | ||
427 | * | ||
428 | * Return: returns zero on success or a negative error code. | ||
429 | */ | ||
90 | int __must_check __media_device_register(struct media_device *mdev, | 430 | int __must_check __media_device_register(struct media_device *mdev, |
91 | struct module *owner); | 431 | struct module *owner); |
92 | #define media_device_register(mdev) __media_device_register(mdev, THIS_MODULE) | 432 | #define media_device_register(mdev) __media_device_register(mdev, THIS_MODULE) |
433 | |||
434 | /** | ||
435 | * __media_device_unregister() - Unegisters a media device element | ||
436 | * | ||
437 | * @mdev: pointer to struct &media_device | ||
438 | * | ||
439 | * | ||
440 | * It is safe to call this function on an unregistered (but initialised) | ||
441 | * media device. | ||
442 | */ | ||
93 | void media_device_unregister(struct media_device *mdev); | 443 | void media_device_unregister(struct media_device *mdev); |
94 | 444 | ||
445 | /** | ||
446 | * media_device_register_entity() - registers a media entity inside a | ||
447 | * previously registered media device. | ||
448 | * | ||
449 | * @mdev: pointer to struct &media_device | ||
450 | * @entity: pointer to struct &media_entity to be registered | ||
451 | * | ||
452 | * Entities are identified by a unique positive integer ID. The media | ||
453 | * controller framework will such ID automatically. IDs are not guaranteed | ||
454 | * to be contiguous, and the ID number can change on newer Kernel versions. | ||
455 | * So, neither the driver nor userspace should hardcode ID numbers to refer | ||
456 | * to the entities, but, instead, use the framework to find the ID, when | ||
457 | * needed. | ||
458 | * | ||
459 | * The media_entity name, type and flags fields should be initialized before | ||
460 | * calling media_device_register_entity(). Entities embedded in higher-level | ||
461 | * standard structures can have some of those fields set by the higher-level | ||
462 | * framework. | ||
463 | * | ||
464 | * If the device has pads, media_entity_pads_init() should be called before | ||
465 | * this function. Otherwise, the &media_entity.@pad and &media_entity.@num_pads | ||
466 | * should be zeroed before calling this function. | ||
467 | * | ||
468 | * Entities have flags that describe the entity capabilities and state: | ||
469 | * | ||
470 | * %MEDIA_ENT_FL_DEFAULT indicates the default entity for a given type. | ||
471 | * This can be used to report the default audio and video devices or the | ||
472 | * default camera sensor. | ||
473 | * | ||
474 | * NOTE: Drivers should set the entity function before calling this function. | ||
475 | * Please notice that the values %MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN and | ||
476 | * %MEDIA_ENT_F_UNKNOWN should not be used by the drivers. | ||
477 | */ | ||
95 | int __must_check media_device_register_entity(struct media_device *mdev, | 478 | int __must_check media_device_register_entity(struct media_device *mdev, |
96 | struct media_entity *entity); | 479 | struct media_entity *entity); |
480 | |||
481 | /* | ||
482 | * media_device_unregister_entity() - unregisters a media entity. | ||
483 | * | ||
484 | * @entity: pointer to struct &media_entity to be unregistered | ||
485 | * | ||
486 | * All links associated with the entity and all PADs are automatically | ||
487 | * unregistered from the media_device when this function is called. | ||
488 | * | ||
489 | * Unregistering an entity will not change the IDs of the other entities and | ||
490 | * the previoully used ID will never be reused for a newly registered entities. | ||
491 | * | ||
492 | * When a media device is unregistered, all its entities are unregistered | ||
493 | * automatically. No manual entities unregistration is then required. | ||
494 | * | ||
495 | * Note: the media_entity instance itself must be freed explicitly by | ||
496 | * the driver if required. | ||
497 | */ | ||
97 | void media_device_unregister_entity(struct media_entity *entity); | 498 | void media_device_unregister_entity(struct media_entity *entity); |
98 | 499 | ||
500 | /** | ||
501 | * media_device_get_devres() - get media device as device resource | ||
502 | * creates if one doesn't exist | ||
503 | * | ||
504 | * @dev: pointer to struct &device. | ||
505 | * | ||
506 | * Sometimes, the media controller &media_device needs to be shared by more | ||
507 | * than one driver. This function adds support for that, by dynamically | ||
508 | * allocating the &media_device and allowing it to be obtained from the | ||
509 | * struct &device associated with the common device where all sub-device | ||
510 | * components belong. So, for example, on an USB device with multiple | ||
511 | * interfaces, each interface may be handled by a separate per-interface | ||
512 | * drivers. While each interface have its own &device, they all share a | ||
513 | * common &device associated with the hole USB device. | ||
514 | */ | ||
515 | struct media_device *media_device_get_devres(struct device *dev); | ||
516 | |||
517 | /** | ||
518 | * media_device_find_devres() - find media device as device resource | ||
519 | * | ||
520 | * @dev: pointer to struct &device. | ||
521 | */ | ||
522 | struct media_device *media_device_find_devres(struct device *dev); | ||
523 | |||
99 | /* Iterate over all entities. */ | 524 | /* Iterate over all entities. */ |
100 | #define media_device_for_each_entity(entity, mdev) \ | 525 | #define media_device_for_each_entity(entity, mdev) \ |
101 | list_for_each_entry(entity, &(mdev)->entities, list) | 526 | list_for_each_entry(entity, &(mdev)->entities, graph_obj.list) |
527 | |||
528 | /* Iterate over all interfaces. */ | ||
529 | #define media_device_for_each_intf(intf, mdev) \ | ||
530 | list_for_each_entry(intf, &(mdev)->interfaces, graph_obj.list) | ||
531 | |||
532 | /* Iterate over all pads. */ | ||
533 | #define media_device_for_each_pad(pad, mdev) \ | ||
534 | list_for_each_entry(pad, &(mdev)->pads, graph_obj.list) | ||
102 | 535 | ||
536 | /* Iterate over all links. */ | ||
537 | #define media_device_for_each_link(link, mdev) \ | ||
538 | list_for_each_entry(link, &(mdev)->links, graph_obj.list) | ||
539 | #else | ||
540 | static inline int media_device_register(struct media_device *mdev) | ||
541 | { | ||
542 | return 0; | ||
543 | } | ||
544 | static inline void media_device_unregister(struct media_device *mdev) | ||
545 | { | ||
546 | } | ||
547 | static inline int media_device_register_entity(struct media_device *mdev, | ||
548 | struct media_entity *entity) | ||
549 | { | ||
550 | return 0; | ||
551 | } | ||
552 | static inline void media_device_unregister_entity(struct media_entity *entity) | ||
553 | { | ||
554 | } | ||
555 | static inline struct media_device *media_device_get_devres(struct device *dev) | ||
556 | { | ||
557 | return NULL; | ||
558 | } | ||
559 | static inline struct media_device *media_device_find_devres(struct device *dev) | ||
560 | { | ||
561 | return NULL; | ||
562 | } | ||
563 | #endif /* CONFIG_MEDIA_CONTROLLER */ | ||
103 | #endif | 564 | #endif |
diff --git a/include/media/media-devnode.h b/include/media/media-devnode.h index 17ddae32060d..fe42f08e72bd 100644 --- a/include/media/media-devnode.h +++ b/include/media/media-devnode.h | |||
@@ -40,6 +40,20 @@ | |||
40 | */ | 40 | */ |
41 | #define MEDIA_FLAG_REGISTERED 0 | 41 | #define MEDIA_FLAG_REGISTERED 0 |
42 | 42 | ||
43 | /** | ||
44 | * struct media_file_operations - Media device file operations | ||
45 | * | ||
46 | * @owner: should be filled with %THIS_MODULE | ||
47 | * @read: pointer to the function that implements read() syscall | ||
48 | * @write: pointer to the function that implements write() syscall | ||
49 | * @poll: pointer to the function that implements poll() syscall | ||
50 | * @ioctl: pointer to the function that implements ioctl() syscall | ||
51 | * @compat_ioctl: pointer to the function that will handle 32 bits userspace | ||
52 | * calls to the the ioctl() syscall on a Kernel compiled with 64 bits. | ||
53 | * @open: pointer to the function that implements open() syscall | ||
54 | * @release: pointer to the function that will release the resources allocated | ||
55 | * by the @open function. | ||
56 | */ | ||
43 | struct media_file_operations { | 57 | struct media_file_operations { |
44 | struct module *owner; | 58 | struct module *owner; |
45 | ssize_t (*read) (struct file *, char __user *, size_t, loff_t *); | 59 | ssize_t (*read) (struct file *, char __user *, size_t, loff_t *); |
@@ -53,7 +67,7 @@ struct media_file_operations { | |||
53 | 67 | ||
54 | /** | 68 | /** |
55 | * struct media_devnode - Media device node | 69 | * struct media_devnode - Media device node |
56 | * @fops: pointer to struct media_file_operations with media device ops | 70 | * @fops: pointer to struct &media_file_operations with media device ops |
57 | * @dev: struct device pointer for the media controller device | 71 | * @dev: struct device pointer for the media controller device |
58 | * @cdev: struct cdev pointer character device | 72 | * @cdev: struct cdev pointer character device |
59 | * @parent: parent device | 73 | * @parent: parent device |
@@ -86,15 +100,53 @@ struct media_devnode { | |||
86 | /* dev to media_devnode */ | 100 | /* dev to media_devnode */ |
87 | #define to_media_devnode(cd) container_of(cd, struct media_devnode, dev) | 101 | #define to_media_devnode(cd) container_of(cd, struct media_devnode, dev) |
88 | 102 | ||
103 | /** | ||
104 | * media_devnode_register - register a media device node | ||
105 | * | ||
106 | * @mdev: media device node structure we want to register | ||
107 | * @owner: should be filled with %THIS_MODULE | ||
108 | * | ||
109 | * The registration code assigns minor numbers and registers the new device node | ||
110 | * with the kernel. An error is returned if no free minor number can be found, | ||
111 | * or if the registration of the device node fails. | ||
112 | * | ||
113 | * Zero is returned on success. | ||
114 | * | ||
115 | * Note that if the media_devnode_register call fails, the release() callback of | ||
116 | * the media_devnode structure is *not* called, so the caller is responsible for | ||
117 | * freeing any data. | ||
118 | */ | ||
89 | int __must_check media_devnode_register(struct media_devnode *mdev, | 119 | int __must_check media_devnode_register(struct media_devnode *mdev, |
90 | struct module *owner); | 120 | struct module *owner); |
121 | |||
122 | /** | ||
123 | * media_devnode_unregister - unregister a media device node | ||
124 | * @mdev: the device node to unregister | ||
125 | * | ||
126 | * This unregisters the passed device. Future open calls will be met with | ||
127 | * errors. | ||
128 | * | ||
129 | * This function can safely be called if the device node has never been | ||
130 | * registered or has already been unregistered. | ||
131 | */ | ||
91 | void media_devnode_unregister(struct media_devnode *mdev); | 132 | void media_devnode_unregister(struct media_devnode *mdev); |
92 | 133 | ||
134 | /** | ||
135 | * media_devnode_data - returns a pointer to the &media_devnode | ||
136 | * | ||
137 | * @filp: pointer to struct &file | ||
138 | */ | ||
93 | static inline struct media_devnode *media_devnode_data(struct file *filp) | 139 | static inline struct media_devnode *media_devnode_data(struct file *filp) |
94 | { | 140 | { |
95 | return filp->private_data; | 141 | return filp->private_data; |
96 | } | 142 | } |
97 | 143 | ||
144 | /** | ||
145 | * media_devnode_is_registered - returns true if &media_devnode is registered; | ||
146 | * false otherwise. | ||
147 | * | ||
148 | * @mdev: pointer to struct &media_devnode. | ||
149 | */ | ||
98 | static inline int media_devnode_is_registered(struct media_devnode *mdev) | 150 | static inline int media_devnode_is_registered(struct media_devnode *mdev) |
99 | { | 151 | { |
100 | return test_bit(MEDIA_FLAG_REGISTERED, &mdev->flags); | 152 | return test_bit(MEDIA_FLAG_REGISTERED, &mdev->flags); |
diff --git a/include/media/media-entity.h b/include/media/media-entity.h index 197f93799753..fe485d367985 100644 --- a/include/media/media-entity.h +++ b/include/media/media-entity.h | |||
@@ -23,25 +23,151 @@ | |||
23 | #ifndef _MEDIA_ENTITY_H | 23 | #ifndef _MEDIA_ENTITY_H |
24 | #define _MEDIA_ENTITY_H | 24 | #define _MEDIA_ENTITY_H |
25 | 25 | ||
26 | #include <linux/bitops.h> | 26 | #include <linux/bitmap.h> |
27 | #include <linux/kernel.h> | 27 | #include <linux/kernel.h> |
28 | #include <linux/list.h> | 28 | #include <linux/list.h> |
29 | #include <linux/media.h> | 29 | #include <linux/media.h> |
30 | 30 | ||
31 | /* Enums used internally at the media controller to represent graphs */ | ||
32 | |||
33 | /** | ||
34 | * enum media_gobj_type - type of a graph object | ||
35 | * | ||
36 | * @MEDIA_GRAPH_ENTITY: Identify a media entity | ||
37 | * @MEDIA_GRAPH_PAD: Identify a media pad | ||
38 | * @MEDIA_GRAPH_LINK: Identify a media link | ||
39 | * @MEDIA_GRAPH_INTF_DEVNODE: Identify a media Kernel API interface via | ||
40 | * a device node | ||
41 | */ | ||
42 | enum media_gobj_type { | ||
43 | MEDIA_GRAPH_ENTITY, | ||
44 | MEDIA_GRAPH_PAD, | ||
45 | MEDIA_GRAPH_LINK, | ||
46 | MEDIA_GRAPH_INTF_DEVNODE, | ||
47 | }; | ||
48 | |||
49 | #define MEDIA_BITS_PER_TYPE 8 | ||
50 | #define MEDIA_BITS_PER_ID (32 - MEDIA_BITS_PER_TYPE) | ||
51 | #define MEDIA_ID_MASK GENMASK_ULL(MEDIA_BITS_PER_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 | * @mdev: Pointer to the struct media_device that owns the object | ||
59 | * @id: Non-zero object ID identifier. The ID should be unique | ||
60 | * inside a media_device, as it is composed by | ||
61 | * %MEDIA_BITS_PER_TYPE to store the type plus | ||
62 | * %MEDIA_BITS_PER_ID to store the ID | ||
63 | * @list: List entry stored in one of the per-type mdev object lists | ||
64 | * | ||
65 | * All objects on the media graph should have this struct embedded | ||
66 | */ | ||
67 | struct media_gobj { | ||
68 | struct media_device *mdev; | ||
69 | u32 id; | ||
70 | struct list_head list; | ||
71 | }; | ||
72 | |||
73 | #define MEDIA_ENTITY_ENUM_MAX_DEPTH 16 | ||
74 | |||
75 | /** | ||
76 | * struct media_entity_enum - An enumeration of media entities. | ||
77 | * | ||
78 | * @bmap: Bit map in which each bit represents one entity at struct | ||
79 | * media_entity->internal_idx. | ||
80 | * @idx_max: Number of bits in bmap | ||
81 | */ | ||
82 | struct media_entity_enum { | ||
83 | unsigned long *bmap; | ||
84 | int idx_max; | ||
85 | }; | ||
86 | |||
87 | /** | ||
88 | * struct media_entity_graph - Media graph traversal state | ||
89 | * | ||
90 | * @stack: Graph traversal stack; the stack contains information | ||
91 | * on the path the media entities to be walked and the | ||
92 | * links through which they were reached. | ||
93 | * @ent_enum: Visited entities | ||
94 | * @top: The top of the stack | ||
95 | */ | ||
96 | struct media_entity_graph { | ||
97 | struct { | ||
98 | struct media_entity *entity; | ||
99 | struct list_head *link; | ||
100 | } stack[MEDIA_ENTITY_ENUM_MAX_DEPTH]; | ||
101 | |||
102 | struct media_entity_enum ent_enum; | ||
103 | int top; | ||
104 | }; | ||
105 | |||
106 | /* | ||
107 | * struct media_pipeline - Media pipeline related information | ||
108 | * | ||
109 | * @streaming_count: Streaming start count - streaming stop count | ||
110 | * @graph: Media graph walk during pipeline start / stop | ||
111 | */ | ||
31 | struct media_pipeline { | 112 | struct media_pipeline { |
113 | int streaming_count; | ||
114 | struct media_entity_graph graph; | ||
32 | }; | 115 | }; |
33 | 116 | ||
117 | /** | ||
118 | * struct media_link - A link object part of a media graph. | ||
119 | * | ||
120 | * @graph_obj: Embedded structure containing the media object common data | ||
121 | * @list: Linked list associated with an entity or an interface that | ||
122 | * owns the link. | ||
123 | * @gobj0: Part of a union. Used to get the pointer for the first | ||
124 | * graph_object of the link. | ||
125 | * @source: Part of a union. Used only if the first object (gobj0) is | ||
126 | * a pad. In that case, it represents the source pad. | ||
127 | * @intf: Part of a union. Used only if the first object (gobj0) is | ||
128 | * an interface. | ||
129 | * @gobj1: Part of a union. Used to get the pointer for the second | ||
130 | * graph_object of the link. | ||
131 | * @source: Part of a union. Used only if the second object (gobj1) is | ||
132 | * a pad. In that case, it represents the sink pad. | ||
133 | * @entity: Part of a union. Used only if the second object (gobj1) is | ||
134 | * an entity. | ||
135 | * @reverse: Pointer to the link for the reverse direction of a pad to pad | ||
136 | * link. | ||
137 | * @flags: Link flags, as defined in uapi/media.h (MEDIA_LNK_FL_*) | ||
138 | * @is_backlink: Indicate if the link is a backlink. | ||
139 | */ | ||
34 | struct media_link { | 140 | struct media_link { |
35 | struct media_pad *source; /* Source pad */ | 141 | struct media_gobj graph_obj; |
36 | struct media_pad *sink; /* Sink pad */ | 142 | struct list_head list; |
37 | struct media_link *reverse; /* Link in the reverse direction */ | 143 | union { |
38 | unsigned long flags; /* Link flags (MEDIA_LNK_FL_*) */ | 144 | struct media_gobj *gobj0; |
145 | struct media_pad *source; | ||
146 | struct media_interface *intf; | ||
147 | }; | ||
148 | union { | ||
149 | struct media_gobj *gobj1; | ||
150 | struct media_pad *sink; | ||
151 | struct media_entity *entity; | ||
152 | }; | ||
153 | struct media_link *reverse; | ||
154 | unsigned long flags; | ||
155 | bool is_backlink; | ||
39 | }; | 156 | }; |
40 | 157 | ||
158 | /** | ||
159 | * struct media_pad - A media pad graph object. | ||
160 | * | ||
161 | * @graph_obj: Embedded structure containing the media object common data | ||
162 | * @entity: Entity this pad belongs to | ||
163 | * @index: Pad index in the entity pads array, numbered from 0 to n | ||
164 | * @flags: Pad flags, as defined in uapi/media.h (MEDIA_PAD_FL_*) | ||
165 | */ | ||
41 | struct media_pad { | 166 | struct media_pad { |
42 | struct media_entity *entity; /* Entity this pad belongs to */ | 167 | struct media_gobj graph_obj; /* must be first field in struct */ |
43 | u16 index; /* Pad index in the entity pads array */ | 168 | struct media_entity *entity; |
44 | unsigned long flags; /* Pad flags (MEDIA_PAD_FL_*) */ | 169 | u16 index; |
170 | unsigned long flags; | ||
45 | }; | 171 | }; |
46 | 172 | ||
47 | /** | 173 | /** |
@@ -60,105 +186,763 @@ struct media_entity_operations { | |||
60 | int (*link_validate)(struct media_link *link); | 186 | int (*link_validate)(struct media_link *link); |
61 | }; | 187 | }; |
62 | 188 | ||
189 | /** | ||
190 | * struct media_entity - A media entity graph object. | ||
191 | * | ||
192 | * @graph_obj: Embedded structure containing the media object common data. | ||
193 | * @name: Entity name. | ||
194 | * @function: Entity main function, as defined in uapi/media.h | ||
195 | * (MEDIA_ENT_F_*) | ||
196 | * @flags: Entity flags, as defined in uapi/media.h (MEDIA_ENT_FL_*) | ||
197 | * @num_pads: Number of sink and source pads. | ||
198 | * @num_links: Total number of links, forward and back, enabled and disabled. | ||
199 | * @num_backlinks: Number of backlinks | ||
200 | * @internal_idx: An unique internal entity specific number. The numbers are | ||
201 | * re-used if entities are unregistered or registered again. | ||
202 | * @pads: Pads array with the size defined by @num_pads. | ||
203 | * @links: List of data links. | ||
204 | * @ops: Entity operations. | ||
205 | * @stream_count: Stream count for the entity. | ||
206 | * @use_count: Use count for the entity. | ||
207 | * @pipe: Pipeline this entity belongs to. | ||
208 | * @info: Union with devnode information. Kept just for backward | ||
209 | * compatibility. | ||
210 | * @major: Devnode major number (zero if not applicable). Kept just | ||
211 | * for backward compatibility. | ||
212 | * @minor: Devnode minor number (zero if not applicable). Kept just | ||
213 | * for backward compatibility. | ||
214 | * | ||
215 | * NOTE: @stream_count and @use_count reference counts must never be | ||
216 | * negative, but are signed integers on purpose: a simple WARN_ON(<0) check | ||
217 | * can be used to detect reference count bugs that would make them negative. | ||
218 | */ | ||
63 | struct media_entity { | 219 | struct media_entity { |
64 | struct list_head list; | 220 | struct media_gobj graph_obj; /* must be first field in struct */ |
65 | struct media_device *parent; /* Media device this entity belongs to*/ | 221 | const char *name; |
66 | u32 id; /* Entity ID, unique in the parent media | 222 | u32 function; |
67 | * device context */ | 223 | unsigned long flags; |
68 | const char *name; /* Entity name */ | 224 | |
69 | u32 type; /* Entity type (MEDIA_ENT_T_*) */ | 225 | u16 num_pads; |
70 | u32 revision; /* Entity revision, driver specific */ | 226 | u16 num_links; |
71 | unsigned long flags; /* Entity flags (MEDIA_ENT_FL_*) */ | 227 | u16 num_backlinks; |
72 | u32 group_id; /* Entity group ID */ | 228 | int internal_idx; |
73 | 229 | ||
74 | u16 num_pads; /* Number of sink and source pads */ | 230 | struct media_pad *pads; |
75 | u16 num_links; /* Number of existing links, both | 231 | struct list_head links; |
76 | * enabled and disabled */ | 232 | |
77 | u16 num_backlinks; /* Number of backlinks */ | 233 | const struct media_entity_operations *ops; |
78 | u16 max_links; /* Maximum number of links */ | ||
79 | |||
80 | struct media_pad *pads; /* Pads array (num_pads elements) */ | ||
81 | struct media_link *links; /* Links array (max_links elements)*/ | ||
82 | |||
83 | const struct media_entity_operations *ops; /* Entity operations */ | ||
84 | 234 | ||
85 | /* Reference counts must never be negative, but are signed integers on | 235 | /* 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 | 236 | * purpose: a simple WARN_ON(<0) check can be used to detect reference |
87 | * count bugs that would make them negative. | 237 | * count bugs that would make them negative. |
88 | */ | 238 | */ |
89 | int stream_count; /* Stream count for the entity. */ | 239 | int stream_count; |
90 | int use_count; /* Use count for the entity. */ | 240 | int use_count; |
91 | 241 | ||
92 | struct media_pipeline *pipe; /* Pipeline this entity belongs to. */ | 242 | struct media_pipeline *pipe; |
93 | 243 | ||
94 | union { | 244 | union { |
95 | /* Node specifications */ | ||
96 | struct { | 245 | struct { |
97 | u32 major; | 246 | u32 major; |
98 | u32 minor; | 247 | u32 minor; |
99 | } dev; | 248 | } dev; |
100 | |||
101 | /* Sub-device specifications */ | ||
102 | /* Nothing needed yet */ | ||
103 | } info; | 249 | } info; |
104 | }; | 250 | }; |
105 | 251 | ||
106 | static inline u32 media_entity_type(struct media_entity *entity) | 252 | /** |
253 | * struct media_interface - A media interface graph object. | ||
254 | * | ||
255 | * @graph_obj: embedded graph object | ||
256 | * @links: List of links pointing to graph entities | ||
257 | * @type: Type of the interface as defined in the | ||
258 | * uapi/media/media.h header, e. g. | ||
259 | * MEDIA_INTF_T_* | ||
260 | * @flags: Interface flags as defined in uapi/media/media.h | ||
261 | */ | ||
262 | struct media_interface { | ||
263 | struct media_gobj graph_obj; | ||
264 | struct list_head links; | ||
265 | u32 type; | ||
266 | u32 flags; | ||
267 | }; | ||
268 | |||
269 | /** | ||
270 | * struct media_intf_devnode - A media interface via a device node. | ||
271 | * | ||
272 | * @intf: embedded interface object | ||
273 | * @major: Major number of a device node | ||
274 | * @minor: Minor number of a device node | ||
275 | */ | ||
276 | struct media_intf_devnode { | ||
277 | struct media_interface intf; | ||
278 | |||
279 | /* Should match the fields at media_v2_intf_devnode */ | ||
280 | u32 major; | ||
281 | u32 minor; | ||
282 | }; | ||
283 | |||
284 | /** | ||
285 | * media_entity_id() - return the media entity graph object id | ||
286 | * | ||
287 | * @entity: pointer to entity | ||
288 | */ | ||
289 | static inline u32 media_entity_id(struct media_entity *entity) | ||
107 | { | 290 | { |
108 | return entity->type & MEDIA_ENT_TYPE_MASK; | 291 | return entity->graph_obj.id; |
109 | } | 292 | } |
110 | 293 | ||
111 | static inline u32 media_entity_subtype(struct media_entity *entity) | 294 | /** |
295 | * media_type() - return the media object type | ||
296 | * | ||
297 | * @gobj: pointer to the media graph object | ||
298 | */ | ||
299 | static inline enum media_gobj_type media_type(struct media_gobj *gobj) | ||
112 | { | 300 | { |
113 | return entity->type & MEDIA_ENT_SUBTYPE_MASK; | 301 | return gobj->id >> MEDIA_BITS_PER_ID; |
114 | } | 302 | } |
115 | 303 | ||
116 | #define MEDIA_ENTITY_ENUM_MAX_DEPTH 16 | 304 | /** |
117 | #define MEDIA_ENTITY_ENUM_MAX_ID 64 | 305 | * media_id() - return the media object ID |
306 | * | ||
307 | * @gobj: pointer to the media graph object | ||
308 | */ | ||
309 | static inline u32 media_id(struct media_gobj *gobj) | ||
310 | { | ||
311 | return gobj->id & MEDIA_ID_MASK; | ||
312 | } | ||
118 | 313 | ||
119 | /* | 314 | /** |
120 | * The number of pads can't be bigger than the number of entities, | 315 | * media_gobj_gen_id() - encapsulates type and ID on at the object ID |
121 | * as the worse-case scenario is to have one entity linked up to | 316 | * |
122 | * MEDIA_ENTITY_ENUM_MAX_ID - 1 entities. | 317 | * @type: object type as define at enum &media_gobj_type. |
318 | * @local_id: next ID, from struct &media_device.@id. | ||
123 | */ | 319 | */ |
124 | #define MEDIA_ENTITY_MAX_PADS (MEDIA_ENTITY_ENUM_MAX_ID - 1) | 320 | static inline u32 media_gobj_gen_id(enum media_gobj_type type, u64 local_id) |
321 | { | ||
322 | u32 id; | ||
125 | 323 | ||
126 | struct media_entity_graph { | 324 | id = type << MEDIA_BITS_PER_ID; |
127 | struct { | 325 | id |= local_id & MEDIA_ID_MASK; |
128 | struct media_entity *entity; | ||
129 | int link; | ||
130 | } stack[MEDIA_ENTITY_ENUM_MAX_DEPTH]; | ||
131 | 326 | ||
132 | DECLARE_BITMAP(entities, MEDIA_ENTITY_ENUM_MAX_ID); | 327 | return id; |
133 | int top; | 328 | } |
134 | }; | 329 | |
330 | /** | ||
331 | * is_media_entity_v4l2_io() - identify if the entity main function | ||
332 | * is a V4L2 I/O | ||
333 | * | ||
334 | * @entity: pointer to entity | ||
335 | * | ||
336 | * Return: true if the entity main function is one of the V4L2 I/O types | ||
337 | * (video, VBI or SDR radio); false otherwise. | ||
338 | */ | ||
339 | static inline bool is_media_entity_v4l2_io(struct media_entity *entity) | ||
340 | { | ||
341 | if (!entity) | ||
342 | return false; | ||
343 | |||
344 | switch (entity->function) { | ||
345 | case MEDIA_ENT_F_IO_V4L: | ||
346 | case MEDIA_ENT_F_IO_VBI: | ||
347 | case MEDIA_ENT_F_IO_SWRADIO: | ||
348 | return true; | ||
349 | default: | ||
350 | return false; | ||
351 | } | ||
352 | } | ||
353 | |||
354 | /** | ||
355 | * is_media_entity_v4l2_subdev - return true if the entity main function is | ||
356 | * associated with the V4L2 API subdev usage | ||
357 | * | ||
358 | * @entity: pointer to entity | ||
359 | * | ||
360 | * This is an ancillary function used by subdev-based V4L2 drivers. | ||
361 | * It checks if the entity function is one of functions used by a V4L2 subdev, | ||
362 | * e. g. camera-relatef functions, analog TV decoder, TV tuner, V4L2 DSPs. | ||
363 | */ | ||
364 | static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity) | ||
365 | { | ||
366 | if (!entity) | ||
367 | return false; | ||
368 | |||
369 | switch (entity->function) { | ||
370 | case MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN: | ||
371 | case MEDIA_ENT_F_CAM_SENSOR: | ||
372 | case MEDIA_ENT_F_FLASH: | ||
373 | case MEDIA_ENT_F_LENS: | ||
374 | case MEDIA_ENT_F_ATV_DECODER: | ||
375 | case MEDIA_ENT_F_TUNER: | ||
376 | return true; | ||
377 | |||
378 | default: | ||
379 | return false; | ||
380 | } | ||
381 | } | ||
382 | |||
383 | /** | ||
384 | * __media_entity_enum_init - Initialise an entity enumeration | ||
385 | * | ||
386 | * @ent_enum: Entity enumeration to be initialised | ||
387 | * @idx_max: Maximum number of entities in the enumeration | ||
388 | * | ||
389 | * Return: Returns zero on success or a negative error code. | ||
390 | */ | ||
391 | __must_check int __media_entity_enum_init(struct media_entity_enum *ent_enum, | ||
392 | int idx_max); | ||
393 | |||
394 | /** | ||
395 | * media_entity_enum_cleanup - Release resources of an entity enumeration | ||
396 | * | ||
397 | * @ent_enum: Entity enumeration to be released | ||
398 | */ | ||
399 | void media_entity_enum_cleanup(struct media_entity_enum *ent_enum); | ||
400 | |||
401 | /** | ||
402 | * media_entity_enum_zero - Clear the entire enum | ||
403 | * | ||
404 | * @ent_enum: Entity enumeration to be cleared | ||
405 | */ | ||
406 | static inline void media_entity_enum_zero(struct media_entity_enum *ent_enum) | ||
407 | { | ||
408 | bitmap_zero(ent_enum->bmap, ent_enum->idx_max); | ||
409 | } | ||
410 | |||
411 | /** | ||
412 | * media_entity_enum_set - Mark a single entity in the enum | ||
413 | * | ||
414 | * @ent_enum: Entity enumeration | ||
415 | * @entity: Entity to be marked | ||
416 | */ | ||
417 | static inline void media_entity_enum_set(struct media_entity_enum *ent_enum, | ||
418 | struct media_entity *entity) | ||
419 | { | ||
420 | if (WARN_ON(entity->internal_idx >= ent_enum->idx_max)) | ||
421 | return; | ||
422 | |||
423 | __set_bit(entity->internal_idx, ent_enum->bmap); | ||
424 | } | ||
425 | |||
426 | /** | ||
427 | * media_entity_enum_clear - Unmark a single entity in the enum | ||
428 | * | ||
429 | * @ent_enum: Entity enumeration | ||
430 | * @entity: Entity to be unmarked | ||
431 | */ | ||
432 | static inline void media_entity_enum_clear(struct media_entity_enum *ent_enum, | ||
433 | struct media_entity *entity) | ||
434 | { | ||
435 | if (WARN_ON(entity->internal_idx >= ent_enum->idx_max)) | ||
436 | return; | ||
135 | 437 | ||
136 | int media_entity_init(struct media_entity *entity, u16 num_pads, | 438 | __clear_bit(entity->internal_idx, ent_enum->bmap); |
137 | struct media_pad *pads, u16 extra_links); | 439 | } |
138 | void media_entity_cleanup(struct media_entity *entity); | 440 | |
441 | /** | ||
442 | * media_entity_enum_test - Test whether the entity is marked | ||
443 | * | ||
444 | * @ent_enum: Entity enumeration | ||
445 | * @entity: Entity to be tested | ||
446 | * | ||
447 | * Returns true if the entity was marked. | ||
448 | */ | ||
449 | static inline bool media_entity_enum_test(struct media_entity_enum *ent_enum, | ||
450 | struct media_entity *entity) | ||
451 | { | ||
452 | if (WARN_ON(entity->internal_idx >= ent_enum->idx_max)) | ||
453 | return true; | ||
454 | |||
455 | return test_bit(entity->internal_idx, ent_enum->bmap); | ||
456 | } | ||
457 | |||
458 | /** | ||
459 | * media_entity_enum_test - Test whether the entity is marked, and mark it | ||
460 | * | ||
461 | * @ent_enum: Entity enumeration | ||
462 | * @entity: Entity to be tested | ||
463 | * | ||
464 | * Returns true if the entity was marked, and mark it before doing so. | ||
465 | */ | ||
466 | static inline bool | ||
467 | media_entity_enum_test_and_set(struct media_entity_enum *ent_enum, | ||
468 | struct media_entity *entity) | ||
469 | { | ||
470 | if (WARN_ON(entity->internal_idx >= ent_enum->idx_max)) | ||
471 | return true; | ||
472 | |||
473 | return __test_and_set_bit(entity->internal_idx, ent_enum->bmap); | ||
474 | } | ||
475 | |||
476 | /** | ||
477 | * media_entity_enum_empty - Test whether the entire enum is empty | ||
478 | * | ||
479 | * @ent_enum: Entity enumeration | ||
480 | * | ||
481 | * Returns true if the entity was marked. | ||
482 | */ | ||
483 | static inline bool media_entity_enum_empty(struct media_entity_enum *ent_enum) | ||
484 | { | ||
485 | return bitmap_empty(ent_enum->bmap, ent_enum->idx_max); | ||
486 | } | ||
487 | |||
488 | /** | ||
489 | * media_entity_enum_intersects - Test whether two enums intersect | ||
490 | * | ||
491 | * @ent_enum1: First entity enumeration | ||
492 | * @ent_enum2: Second entity enumeration | ||
493 | * | ||
494 | * Returns true if entity enumerations e and f intersect, otherwise false. | ||
495 | */ | ||
496 | static inline bool media_entity_enum_intersects( | ||
497 | struct media_entity_enum *ent_enum1, | ||
498 | struct media_entity_enum *ent_enum2) | ||
499 | { | ||
500 | WARN_ON(ent_enum1->idx_max != ent_enum2->idx_max); | ||
501 | |||
502 | return bitmap_intersects(ent_enum1->bmap, ent_enum2->bmap, | ||
503 | min(ent_enum1->idx_max, ent_enum2->idx_max)); | ||
504 | } | ||
505 | |||
506 | #define gobj_to_entity(gobj) \ | ||
507 | container_of(gobj, struct media_entity, graph_obj) | ||
508 | |||
509 | #define gobj_to_pad(gobj) \ | ||
510 | container_of(gobj, struct media_pad, graph_obj) | ||
511 | |||
512 | #define gobj_to_link(gobj) \ | ||
513 | container_of(gobj, struct media_link, graph_obj) | ||
514 | |||
515 | #define gobj_to_link(gobj) \ | ||
516 | container_of(gobj, struct media_link, graph_obj) | ||
517 | |||
518 | #define gobj_to_pad(gobj) \ | ||
519 | container_of(gobj, struct media_pad, graph_obj) | ||
520 | |||
521 | #define gobj_to_intf(gobj) \ | ||
522 | container_of(gobj, struct media_interface, graph_obj) | ||
523 | |||
524 | #define intf_to_devnode(intf) \ | ||
525 | container_of(intf, struct media_intf_devnode, intf) | ||
526 | |||
527 | /** | ||
528 | * media_gobj_create - Initialize a graph object | ||
529 | * | ||
530 | * @mdev: Pointer to the media_device that contains the object | ||
531 | * @type: Type of the object | ||
532 | * @gobj: Pointer to the graph object | ||
533 | * | ||
534 | * This routine initializes the embedded struct media_gobj inside a | ||
535 | * media graph object. It is called automatically if media_*_create() | ||
536 | * calls are used. However, if the object (entity, link, pad, interface) | ||
537 | * is embedded on some other object, this function should be called before | ||
538 | * registering the object at the media controller. | ||
539 | */ | ||
540 | void media_gobj_create(struct media_device *mdev, | ||
541 | enum media_gobj_type type, | ||
542 | struct media_gobj *gobj); | ||
543 | |||
544 | /** | ||
545 | * media_gobj_destroy - Stop using a graph object on a media device | ||
546 | * | ||
547 | * @gobj: Pointer to the graph object | ||
548 | * | ||
549 | * This should be called by all routines like media_device_unregister() | ||
550 | * that remove/destroy media graph objects. | ||
551 | */ | ||
552 | void media_gobj_destroy(struct media_gobj *gobj); | ||
553 | |||
554 | /** | ||
555 | * media_entity_pads_init() - Initialize the entity pads | ||
556 | * | ||
557 | * @entity: entity where the pads belong | ||
558 | * @num_pads: total number of sink and source pads | ||
559 | * @pads: Array of @num_pads pads. | ||
560 | * | ||
561 | * The pads array is managed by the entity driver and passed to | ||
562 | * media_entity_pads_init() where its pointer will be stored in the entity | ||
563 | * structure. | ||
564 | * | ||
565 | * If no pads are needed, drivers could either directly fill | ||
566 | * &media_entity->@num_pads with 0 and &media_entity->@pads with NULL or call | ||
567 | * this function that will do the same. | ||
568 | * | ||
569 | * As the number of pads is known in advance, the pads array is not allocated | ||
570 | * dynamically but is managed by the entity driver. Most drivers will embed the | ||
571 | * pads array in a driver-specific structure, avoiding dynamic allocation. | ||
572 | * | ||
573 | * Drivers must set the direction of every pad in the pads array before calling | ||
574 | * media_entity_pads_init(). The function will initialize the other pads fields. | ||
575 | */ | ||
576 | int media_entity_pads_init(struct media_entity *entity, u16 num_pads, | ||
577 | struct media_pad *pads); | ||
578 | |||
579 | /** | ||
580 | * media_entity_cleanup() - free resources associated with an entity | ||
581 | * | ||
582 | * @entity: entity where the pads belong | ||
583 | * | ||
584 | * This function must be called during the cleanup phase after unregistering | ||
585 | * the entity (currently, it does nothing). | ||
586 | */ | ||
587 | static inline void media_entity_cleanup(struct media_entity *entity) {}; | ||
588 | |||
589 | /** | ||
590 | * media_create_pad_link() - creates a link between two entities. | ||
591 | * | ||
592 | * @source: pointer to &media_entity of the source pad. | ||
593 | * @source_pad: number of the source pad in the pads array | ||
594 | * @sink: pointer to &media_entity of the sink pad. | ||
595 | * @sink_pad: number of the sink pad in the pads array. | ||
596 | * @flags: Link flags, as defined in include/uapi/linux/media.h. | ||
597 | * | ||
598 | * Valid values for flags: | ||
599 | * A %MEDIA_LNK_FL_ENABLED flag indicates that the link is enabled and can be | ||
600 | * used to transfer media data. When two or more links target a sink pad, | ||
601 | * only one of them can be enabled at a time. | ||
602 | * | ||
603 | * A %MEDIA_LNK_FL_IMMUTABLE flag indicates that the link enabled state can't | ||
604 | * be modified at runtime. If %MEDIA_LNK_FL_IMMUTABLE is set, then | ||
605 | * %MEDIA_LNK_FL_ENABLED must also be set since an immutable link is | ||
606 | * always enabled. | ||
607 | * | ||
608 | * NOTE: | ||
609 | * | ||
610 | * Before calling this function, media_entity_pads_init() and | ||
611 | * media_device_register_entity() should be called previously for both ends. | ||
612 | */ | ||
613 | __must_check int media_create_pad_link(struct media_entity *source, | ||
614 | u16 source_pad, struct media_entity *sink, | ||
615 | u16 sink_pad, u32 flags); | ||
616 | |||
617 | /** | ||
618 | * media_create_pad_links() - creates a link between two entities. | ||
619 | * | ||
620 | * @mdev: Pointer to the media_device that contains the object | ||
621 | * @source_function: Function of the source entities. Used only if @source is | ||
622 | * NULL. | ||
623 | * @source: pointer to &media_entity of the source pad. If NULL, it will use | ||
624 | * all entities that matches the @sink_function. | ||
625 | * @source_pad: number of the source pad in the pads array | ||
626 | * @sink_function: Function of the sink entities. Used only if @sink is NULL. | ||
627 | * @sink: pointer to &media_entity of the sink pad. If NULL, it will use | ||
628 | * all entities that matches the @sink_function. | ||
629 | * @sink_pad: number of the sink pad in the pads array. | ||
630 | * @flags: Link flags, as defined in include/uapi/linux/media.h. | ||
631 | * @allow_both_undefined: if true, then both @source and @sink can be NULL. | ||
632 | * In such case, it will create a crossbar between all entities that | ||
633 | * matches @source_function to all entities that matches @sink_function. | ||
634 | * If false, it will return 0 and won't create any link if both @source | ||
635 | * and @sink are NULL. | ||
636 | * | ||
637 | * Valid values for flags: | ||
638 | * A %MEDIA_LNK_FL_ENABLED flag indicates that the link is enabled and can be | ||
639 | * used to transfer media data. If multiple links are created and this | ||
640 | * flag is passed as an argument, only the first created link will have | ||
641 | * this flag. | ||
642 | * | ||
643 | * A %MEDIA_LNK_FL_IMMUTABLE flag indicates that the link enabled state can't | ||
644 | * be modified at runtime. If %MEDIA_LNK_FL_IMMUTABLE is set, then | ||
645 | * %MEDIA_LNK_FL_ENABLED must also be set since an immutable link is | ||
646 | * always enabled. | ||
647 | * | ||
648 | * It is common for some devices to have multiple source and/or sink entities | ||
649 | * of the same type that should be linked. While media_create_pad_link() | ||
650 | * creates link by link, this function is meant to allow 1:n, n:1 and even | ||
651 | * cross-bar (n:n) links. | ||
652 | * | ||
653 | * NOTE: Before calling this function, media_entity_pads_init() and | ||
654 | * media_device_register_entity() should be called previously for the entities | ||
655 | * to be linked. | ||
656 | */ | ||
657 | int media_create_pad_links(const struct media_device *mdev, | ||
658 | const u32 source_function, | ||
659 | struct media_entity *source, | ||
660 | const u16 source_pad, | ||
661 | const u32 sink_function, | ||
662 | struct media_entity *sink, | ||
663 | const u16 sink_pad, | ||
664 | u32 flags, | ||
665 | const bool allow_both_undefined); | ||
139 | 666 | ||
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); | 667 | void __media_entity_remove_links(struct media_entity *entity); |
668 | |||
669 | /** | ||
670 | * media_entity_remove_links() - remove all links associated with an entity | ||
671 | * | ||
672 | * @entity: pointer to &media_entity | ||
673 | * | ||
674 | * Note: this is called automatically when an entity is unregistered via | ||
675 | * media_device_register_entity(). | ||
676 | */ | ||
143 | void media_entity_remove_links(struct media_entity *entity); | 677 | void media_entity_remove_links(struct media_entity *entity); |
144 | 678 | ||
679 | /** | ||
680 | * __media_entity_setup_link - Configure a media link without locking | ||
681 | * @link: The link being configured | ||
682 | * @flags: Link configuration flags | ||
683 | * | ||
684 | * The bulk of link setup is handled by the two entities connected through the | ||
685 | * link. This function notifies both entities of the link configuration change. | ||
686 | * | ||
687 | * If the link is immutable or if the current and new configuration are | ||
688 | * identical, return immediately. | ||
689 | * | ||
690 | * The user is expected to hold link->source->parent->mutex. If not, | ||
691 | * media_entity_setup_link() should be used instead. | ||
692 | */ | ||
145 | int __media_entity_setup_link(struct media_link *link, u32 flags); | 693 | int __media_entity_setup_link(struct media_link *link, u32 flags); |
694 | |||
695 | /** | ||
696 | * media_entity_setup_link() - changes the link flags properties in runtime | ||
697 | * | ||
698 | * @link: pointer to &media_link | ||
699 | * @flags: the requested new link flags | ||
700 | * | ||
701 | * The only configurable property is the %MEDIA_LNK_FL_ENABLED link flag | ||
702 | * flag to enable/disable a link. Links marked with the | ||
703 | * %MEDIA_LNK_FL_IMMUTABLE link flag can not be enabled or disabled. | ||
704 | * | ||
705 | * When a link is enabled or disabled, the media framework calls the | ||
706 | * link_setup operation for the two entities at the source and sink of the | ||
707 | * link, in that order. If the second link_setup call fails, another | ||
708 | * link_setup call is made on the first entity to restore the original link | ||
709 | * flags. | ||
710 | * | ||
711 | * Media device drivers can be notified of link setup operations by setting the | ||
712 | * media_device::link_notify pointer to a callback function. If provided, the | ||
713 | * notification callback will be called before enabling and after disabling | ||
714 | * links. | ||
715 | * | ||
716 | * Entity drivers must implement the link_setup operation if any of their links | ||
717 | * is non-immutable. The operation must either configure the hardware or store | ||
718 | * the configuration information to be applied later. | ||
719 | * | ||
720 | * Link configuration must not have any side effect on other links. If an | ||
721 | * enabled link at a sink pad prevents another link at the same pad from | ||
722 | * being enabled, the link_setup operation must return -EBUSY and can't | ||
723 | * implicitly disable the first enabled link. | ||
724 | * | ||
725 | * NOTE: the valid values of the flags for the link is the same as described | ||
726 | * on media_create_pad_link(), for pad to pad links or the same as described | ||
727 | * on media_create_intf_link(), for interface to entity links. | ||
728 | */ | ||
146 | int media_entity_setup_link(struct media_link *link, u32 flags); | 729 | int media_entity_setup_link(struct media_link *link, u32 flags); |
730 | |||
731 | /** | ||
732 | * media_entity_find_link - Find a link between two pads | ||
733 | * @source: Source pad | ||
734 | * @sink: Sink pad | ||
735 | * | ||
736 | * Return a pointer to the link between the two entities. If no such link | ||
737 | * exists, return NULL. | ||
738 | */ | ||
147 | struct media_link *media_entity_find_link(struct media_pad *source, | 739 | struct media_link *media_entity_find_link(struct media_pad *source, |
148 | struct media_pad *sink); | 740 | struct media_pad *sink); |
741 | |||
742 | /** | ||
743 | * media_entity_remote_pad - Find the pad at the remote end of a link | ||
744 | * @pad: Pad at the local end of the link | ||
745 | * | ||
746 | * Search for a remote pad connected to the given pad by iterating over all | ||
747 | * links originating or terminating at that pad until an enabled link is found. | ||
748 | * | ||
749 | * Return a pointer to the pad at the remote end of the first found enabled | ||
750 | * link, or NULL if no enabled link has been found. | ||
751 | */ | ||
149 | struct media_pad *media_entity_remote_pad(struct media_pad *pad); | 752 | struct media_pad *media_entity_remote_pad(struct media_pad *pad); |
150 | 753 | ||
754 | /** | ||
755 | * media_entity_get - Get a reference to the parent module | ||
756 | * | ||
757 | * @entity: The entity | ||
758 | * | ||
759 | * Get a reference to the parent media device module. | ||
760 | * | ||
761 | * The function will return immediately if @entity is NULL. | ||
762 | * | ||
763 | * Return a pointer to the entity on success or NULL on failure. | ||
764 | */ | ||
151 | struct media_entity *media_entity_get(struct media_entity *entity); | 765 | struct media_entity *media_entity_get(struct media_entity *entity); |
766 | |||
767 | __must_check int media_entity_graph_walk_init( | ||
768 | struct media_entity_graph *graph, struct media_device *mdev); | ||
769 | |||
770 | /** | ||
771 | * media_entity_graph_walk_cleanup - Release resources used by graph walk. | ||
772 | * | ||
773 | * @graph: Media graph structure that will be used to walk the graph | ||
774 | */ | ||
775 | void media_entity_graph_walk_cleanup(struct media_entity_graph *graph); | ||
776 | |||
777 | /** | ||
778 | * media_entity_put - Release the reference to the parent module | ||
779 | * | ||
780 | * @entity: The entity | ||
781 | * | ||
782 | * Release the reference count acquired by media_entity_get(). | ||
783 | * | ||
784 | * The function will return immediately if @entity is NULL. | ||
785 | */ | ||
152 | void media_entity_put(struct media_entity *entity); | 786 | void media_entity_put(struct media_entity *entity); |
153 | 787 | ||
788 | /** | ||
789 | * media_entity_graph_walk_start - Start walking the media graph at a given entity | ||
790 | * @graph: Media graph structure that will be used to walk the graph | ||
791 | * @entity: Starting entity | ||
792 | * | ||
793 | * Before using this function, media_entity_graph_walk_init() must be | ||
794 | * used to allocate resources used for walking the graph. This | ||
795 | * function initializes the graph traversal structure to walk the | ||
796 | * entities graph starting at the given entity. The traversal | ||
797 | * structure must not be modified by the caller during graph | ||
798 | * traversal. After the graph walk, the resources must be released | ||
799 | * using media_entity_graph_walk_cleanup(). | ||
800 | */ | ||
154 | void media_entity_graph_walk_start(struct media_entity_graph *graph, | 801 | void media_entity_graph_walk_start(struct media_entity_graph *graph, |
155 | struct media_entity *entity); | 802 | struct media_entity *entity); |
803 | |||
804 | /** | ||
805 | * media_entity_graph_walk_next - Get the next entity in the graph | ||
806 | * @graph: Media graph structure | ||
807 | * | ||
808 | * Perform a depth-first traversal of the given media entities graph. | ||
809 | * | ||
810 | * The graph structure must have been previously initialized with a call to | ||
811 | * media_entity_graph_walk_start(). | ||
812 | * | ||
813 | * Return the next entity in the graph or NULL if the whole graph have been | ||
814 | * traversed. | ||
815 | */ | ||
156 | struct media_entity * | 816 | struct media_entity * |
157 | media_entity_graph_walk_next(struct media_entity_graph *graph); | 817 | media_entity_graph_walk_next(struct media_entity_graph *graph); |
818 | |||
819 | /** | ||
820 | * media_entity_pipeline_start - Mark a pipeline as streaming | ||
821 | * @entity: Starting entity | ||
822 | * @pipe: Media pipeline to be assigned to all entities in the pipeline. | ||
823 | * | ||
824 | * Mark all entities connected to a given entity through enabled links, either | ||
825 | * directly or indirectly, as streaming. The given pipeline object is assigned to | ||
826 | * every entity in the pipeline and stored in the media_entity pipe field. | ||
827 | * | ||
828 | * Calls to this function can be nested, in which case the same number of | ||
829 | * media_entity_pipeline_stop() calls will be required to stop streaming. The | ||
830 | * pipeline pointer must be identical for all nested calls to | ||
831 | * media_entity_pipeline_start(). | ||
832 | */ | ||
158 | __must_check int media_entity_pipeline_start(struct media_entity *entity, | 833 | __must_check int media_entity_pipeline_start(struct media_entity *entity, |
159 | struct media_pipeline *pipe); | 834 | struct media_pipeline *pipe); |
835 | |||
836 | /** | ||
837 | * media_entity_pipeline_stop - Mark a pipeline as not streaming | ||
838 | * @entity: Starting entity | ||
839 | * | ||
840 | * Mark all entities connected to a given entity through enabled links, either | ||
841 | * directly or indirectly, as not streaming. The media_entity pipe field is | ||
842 | * reset to NULL. | ||
843 | * | ||
844 | * If multiple calls to media_entity_pipeline_start() have been made, the same | ||
845 | * number of calls to this function are required to mark the pipeline as not | ||
846 | * streaming. | ||
847 | */ | ||
160 | void media_entity_pipeline_stop(struct media_entity *entity); | 848 | void media_entity_pipeline_stop(struct media_entity *entity); |
161 | 849 | ||
850 | /** | ||
851 | * media_devnode_create() - creates and initializes a device node interface | ||
852 | * | ||
853 | * @mdev: pointer to struct &media_device | ||
854 | * @type: type of the interface, as given by MEDIA_INTF_T_* macros | ||
855 | * as defined in the uapi/media/media.h header. | ||
856 | * @flags: Interface flags as defined in uapi/media/media.h. | ||
857 | * @major: Device node major number. | ||
858 | * @minor: Device node minor number. | ||
859 | * | ||
860 | * Return: if succeeded, returns a pointer to the newly allocated | ||
861 | * &media_intf_devnode pointer. | ||
862 | */ | ||
863 | struct media_intf_devnode * | ||
864 | __must_check media_devnode_create(struct media_device *mdev, | ||
865 | u32 type, u32 flags, | ||
866 | u32 major, u32 minor); | ||
867 | /** | ||
868 | * media_devnode_remove() - removes a device node interface | ||
869 | * | ||
870 | * @devnode: pointer to &media_intf_devnode to be freed. | ||
871 | * | ||
872 | * When a device node interface is removed, all links to it are automatically | ||
873 | * removed. | ||
874 | */ | ||
875 | void media_devnode_remove(struct media_intf_devnode *devnode); | ||
876 | struct media_link * | ||
877 | |||
878 | /** | ||
879 | * media_create_intf_link() - creates a link between an entity and an interface | ||
880 | * | ||
881 | * @entity: pointer to %media_entity | ||
882 | * @intf: pointer to %media_interface | ||
883 | * @flags: Link flags, as defined in include/uapi/linux/media.h. | ||
884 | * | ||
885 | * | ||
886 | * Valid values for flags: | ||
887 | * The %MEDIA_LNK_FL_ENABLED flag indicates that the interface is connected to | ||
888 | * the entity hardware. That's the default value for interfaces. An | ||
889 | * interface may be disabled if the hardware is busy due to the usage | ||
890 | * of some other interface that it is currently controlling the hardware. | ||
891 | * A typical example is an hybrid TV device that handle only one type of | ||
892 | * stream on a given time. So, when the digital TV is streaming, | ||
893 | * the V4L2 interfaces won't be enabled, as such device is not able to | ||
894 | * also stream analog TV or radio. | ||
895 | * | ||
896 | * Note: | ||
897 | * | ||
898 | * Before calling this function, media_devnode_create() should be called for | ||
899 | * the interface and media_device_register_entity() should be called for the | ||
900 | * interface that will be part of the link. | ||
901 | */ | ||
902 | __must_check media_create_intf_link(struct media_entity *entity, | ||
903 | struct media_interface *intf, | ||
904 | u32 flags); | ||
905 | /** | ||
906 | * __media_remove_intf_link() - remove a single interface link | ||
907 | * | ||
908 | * @link: pointer to &media_link. | ||
909 | * | ||
910 | * Note: this is an unlocked version of media_remove_intf_link() | ||
911 | */ | ||
912 | void __media_remove_intf_link(struct media_link *link); | ||
913 | |||
914 | /** | ||
915 | * media_remove_intf_link() - remove a single interface link | ||
916 | * | ||
917 | * @link: pointer to &media_link. | ||
918 | * | ||
919 | * Note: prefer to use this one, instead of __media_remove_intf_link() | ||
920 | */ | ||
921 | void media_remove_intf_link(struct media_link *link); | ||
922 | |||
923 | /** | ||
924 | * __media_remove_intf_links() - remove all links associated with an interface | ||
925 | * | ||
926 | * @intf: pointer to &media_interface | ||
927 | * | ||
928 | * Note: this is an unlocked version of media_remove_intf_links(). | ||
929 | */ | ||
930 | void __media_remove_intf_links(struct media_interface *intf); | ||
931 | |||
932 | /** | ||
933 | * media_remove_intf_links() - remove all links associated with an interface | ||
934 | * | ||
935 | * @intf: pointer to &media_interface | ||
936 | * | ||
937 | * Notes: | ||
938 | * | ||
939 | * this is called automatically when an entity is unregistered via | ||
940 | * media_device_register_entity() and by media_devnode_remove(). | ||
941 | * | ||
942 | * Prefer to use this one, instead of __media_remove_intf_links(). | ||
943 | */ | ||
944 | void media_remove_intf_links(struct media_interface *intf); | ||
945 | |||
162 | #define media_entity_call(entity, operation, args...) \ | 946 | #define media_entity_call(entity, operation, args...) \ |
163 | (((entity)->ops && (entity)->ops->operation) ? \ | 947 | (((entity)->ops && (entity)->ops->operation) ? \ |
164 | (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD) | 948 | (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD) |
diff --git a/include/media/tuner.h b/include/media/tuner.h index 486b6a54363b..e5321fda5489 100644 --- a/include/media/tuner.h +++ b/include/media/tuner.h | |||
@@ -21,6 +21,14 @@ | |||
21 | 21 | ||
22 | #include <linux/videodev2.h> | 22 | #include <linux/videodev2.h> |
23 | 23 | ||
24 | /* Tuner PADs */ | ||
25 | /* FIXME: is this the right place for it? */ | ||
26 | enum tuner_pad_index { | ||
27 | TUNER_PAD_RF_INPUT, | ||
28 | TUNER_PAD_IF_OUTPUT, | ||
29 | TUNER_NUM_PADS | ||
30 | }; | ||
31 | |||
24 | #define ADDR_UNSET (255) | 32 | #define ADDR_UNSET (255) |
25 | 33 | ||
26 | #define TUNER_TEMIC_PAL 0 /* 4002 FH5 (3X 7756, 9483) */ | 34 | #define TUNER_TEMIC_PAL 0 /* 4002 FH5 (3X 7756, 9483) */ |
diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h index acbcd2f5fe7f..eeabf20e87a6 100644 --- a/include/media/v4l2-dev.h +++ b/include/media/v4l2-dev.h | |||
@@ -86,6 +86,7 @@ struct video_device | |||
86 | { | 86 | { |
87 | #if defined(CONFIG_MEDIA_CONTROLLER) | 87 | #if defined(CONFIG_MEDIA_CONTROLLER) |
88 | struct media_entity entity; | 88 | struct media_entity entity; |
89 | struct media_intf_devnode *intf_devnode; | ||
89 | #endif | 90 | #endif |
90 | /* device ops */ | 91 | /* device ops */ |
91 | const struct v4l2_file_operations *fops; | 92 | const struct v4l2_file_operations *fops; |
diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h index 4e816be3de39..1e3c8cb43bd7 100644 --- a/include/uapi/linux/media.h +++ b/include/uapi/linux/media.h | |||
@@ -23,6 +23,9 @@ | |||
23 | #ifndef __LINUX_MEDIA_H | 23 | #ifndef __LINUX_MEDIA_H |
24 | #define __LINUX_MEDIA_H | 24 | #define __LINUX_MEDIA_H |
25 | 25 | ||
26 | #ifndef __KERNEL__ | ||
27 | #include <stdint.h> | ||
28 | #endif | ||
26 | #include <linux/ioctl.h> | 29 | #include <linux/ioctl.h> |
27 | #include <linux/types.h> | 30 | #include <linux/types.h> |
28 | #include <linux/version.h> | 31 | #include <linux/version.h> |
@@ -42,33 +45,107 @@ struct media_device_info { | |||
42 | 45 | ||
43 | #define MEDIA_ENT_ID_FLAG_NEXT (1 << 31) | 46 | #define MEDIA_ENT_ID_FLAG_NEXT (1 << 31) |
44 | 47 | ||
48 | /* | ||
49 | * Initial value to be used when a new entity is created | ||
50 | * Drivers should change it to something useful | ||
51 | */ | ||
52 | #define MEDIA_ENT_F_UNKNOWN 0x00000000 | ||
53 | |||
54 | /* | ||
55 | * Base number ranges for entity functions | ||
56 | * | ||
57 | * NOTE: those ranges and entity function number are phased just to | ||
58 | * make it easier to maintain this file. Userspace should not rely on | ||
59 | * the ranges to identify a group of function types, as newer | ||
60 | * functions can be added with any name within the full u32 range. | ||
61 | */ | ||
62 | #define MEDIA_ENT_F_BASE 0x00000000 | ||
63 | #define MEDIA_ENT_F_OLD_BASE 0x00010000 | ||
64 | #define MEDIA_ENT_F_OLD_SUBDEV_BASE 0x00020000 | ||
65 | |||
66 | /* | ||
67 | * DVB entities | ||
68 | */ | ||
69 | #define MEDIA_ENT_F_DTV_DEMOD (MEDIA_ENT_F_BASE + 1) | ||
70 | #define MEDIA_ENT_F_TS_DEMUX (MEDIA_ENT_F_BASE + 2) | ||
71 | #define MEDIA_ENT_F_DTV_CA (MEDIA_ENT_F_BASE + 3) | ||
72 | #define MEDIA_ENT_F_DTV_NET_DECAP (MEDIA_ENT_F_BASE + 4) | ||
73 | |||
74 | /* | ||
75 | * Connectors | ||
76 | */ | ||
77 | /* It is a responsibility of the entity drivers to add connectors and links */ | ||
78 | #define MEDIA_ENT_F_CONN_RF (MEDIA_ENT_F_BASE + 21) | ||
79 | #define MEDIA_ENT_F_CONN_SVIDEO (MEDIA_ENT_F_BASE + 22) | ||
80 | #define MEDIA_ENT_F_CONN_COMPOSITE (MEDIA_ENT_F_BASE + 23) | ||
81 | /* For internal test signal generators and other debug connectors */ | ||
82 | #define MEDIA_ENT_F_CONN_TEST (MEDIA_ENT_F_BASE + 24) | ||
83 | |||
84 | /* | ||
85 | * I/O entities | ||
86 | */ | ||
87 | #define MEDIA_ENT_F_IO_DTV (MEDIA_ENT_F_BASE + 31) | ||
88 | #define MEDIA_ENT_F_IO_VBI (MEDIA_ENT_F_BASE + 32) | ||
89 | #define MEDIA_ENT_F_IO_SWRADIO (MEDIA_ENT_F_BASE + 33) | ||
90 | |||
91 | /* | ||
92 | * Don't touch on those. The ranges MEDIA_ENT_F_OLD_BASE and | ||
93 | * MEDIA_ENT_F_OLD_SUBDEV_BASE are kept to keep backward compatibility | ||
94 | * with the legacy v1 API.The number range is out of range by purpose: | ||
95 | * several previously reserved numbers got excluded from this range. | ||
96 | * | ||
97 | * Subdevs are initialized with MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN, | ||
98 | * in order to preserve backward compatibility. | ||
99 | * Drivers must change to the proper subdev type before | ||
100 | * registering the entity. | ||
101 | */ | ||
102 | |||
103 | #define MEDIA_ENT_F_IO_V4L (MEDIA_ENT_F_OLD_BASE + 1) | ||
104 | |||
105 | #define MEDIA_ENT_F_CAM_SENSOR (MEDIA_ENT_F_OLD_SUBDEV_BASE + 1) | ||
106 | #define MEDIA_ENT_F_FLASH (MEDIA_ENT_F_OLD_SUBDEV_BASE + 2) | ||
107 | #define MEDIA_ENT_F_LENS (MEDIA_ENT_F_OLD_SUBDEV_BASE + 3) | ||
108 | #define MEDIA_ENT_F_ATV_DECODER (MEDIA_ENT_F_OLD_SUBDEV_BASE + 4) | ||
109 | /* | ||
110 | * It is a responsibility of the entity drivers to add connectors and links | ||
111 | * for the tuner entities. | ||
112 | */ | ||
113 | #define MEDIA_ENT_F_TUNER (MEDIA_ENT_F_OLD_SUBDEV_BASE + 5) | ||
114 | |||
115 | #define MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN MEDIA_ENT_F_OLD_SUBDEV_BASE | ||
116 | |||
117 | #ifndef __KERNEL__ | ||
118 | |||
119 | /* | ||
120 | * Legacy symbols used to avoid userspace compilation breakages | ||
121 | * | ||
122 | * Those symbols map the entity function into types and should be | ||
123 | * used only on legacy programs for legacy hardware. Don't rely | ||
124 | * on those for MEDIA_IOC_G_TOPOLOGY. | ||
125 | */ | ||
45 | #define MEDIA_ENT_TYPE_SHIFT 16 | 126 | #define MEDIA_ENT_TYPE_SHIFT 16 |
46 | #define MEDIA_ENT_TYPE_MASK 0x00ff0000 | 127 | #define MEDIA_ENT_TYPE_MASK 0x00ff0000 |
47 | #define MEDIA_ENT_SUBTYPE_MASK 0x0000ffff | 128 | #define MEDIA_ENT_SUBTYPE_MASK 0x0000ffff |
48 | 129 | ||
49 | #define MEDIA_ENT_T_DEVNODE (1 << MEDIA_ENT_TYPE_SHIFT) | 130 | #define MEDIA_ENT_T_DEVNODE MEDIA_ENT_F_OLD_BASE |
50 | #define MEDIA_ENT_T_DEVNODE_V4L (MEDIA_ENT_T_DEVNODE + 1) | 131 | #define MEDIA_ENT_T_DEVNODE_V4L MEDIA_ENT_F_IO_V4L |
51 | #define MEDIA_ENT_T_DEVNODE_FB (MEDIA_ENT_T_DEVNODE + 2) | 132 | #define MEDIA_ENT_T_DEVNODE_FB (MEDIA_ENT_T_DEVNODE + 2) |
52 | #define MEDIA_ENT_T_DEVNODE_ALSA (MEDIA_ENT_T_DEVNODE + 3) | 133 | #define MEDIA_ENT_T_DEVNODE_ALSA (MEDIA_ENT_T_DEVNODE + 3) |
53 | #define MEDIA_ENT_T_DEVNODE_DVB_FE (MEDIA_ENT_T_DEVNODE + 4) | 134 | #define MEDIA_ENT_T_DEVNODE_DVB (MEDIA_ENT_T_DEVNODE + 4) |
54 | #define MEDIA_ENT_T_DEVNODE_DVB_DEMUX (MEDIA_ENT_T_DEVNODE + 5) | ||
55 | #define MEDIA_ENT_T_DEVNODE_DVB_DVR (MEDIA_ENT_T_DEVNODE + 6) | ||
56 | #define MEDIA_ENT_T_DEVNODE_DVB_CA (MEDIA_ENT_T_DEVNODE + 7) | ||
57 | #define MEDIA_ENT_T_DEVNODE_DVB_NET (MEDIA_ENT_T_DEVNODE + 8) | ||
58 | |||
59 | /* Legacy symbol. Use it to avoid userspace compilation breakages */ | ||
60 | #define MEDIA_ENT_T_DEVNODE_DVB MEDIA_ENT_T_DEVNODE_DVB_FE | ||
61 | |||
62 | #define MEDIA_ENT_T_V4L2_SUBDEV (2 << MEDIA_ENT_TYPE_SHIFT) | ||
63 | #define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR (MEDIA_ENT_T_V4L2_SUBDEV + 1) | ||
64 | #define MEDIA_ENT_T_V4L2_SUBDEV_FLASH (MEDIA_ENT_T_V4L2_SUBDEV + 2) | ||
65 | #define MEDIA_ENT_T_V4L2_SUBDEV_LENS (MEDIA_ENT_T_V4L2_SUBDEV + 3) | ||
66 | /* A converter of analogue video to its digital representation. */ | ||
67 | #define MEDIA_ENT_T_V4L2_SUBDEV_DECODER (MEDIA_ENT_T_V4L2_SUBDEV + 4) | ||
68 | 135 | ||
69 | #define MEDIA_ENT_T_V4L2_SUBDEV_TUNER (MEDIA_ENT_T_V4L2_SUBDEV + 5) | 136 | #define MEDIA_ENT_T_UNKNOWN MEDIA_ENT_F_UNKNOWN |
137 | #define MEDIA_ENT_T_V4L2_VIDEO MEDIA_ENT_F_IO_V4L | ||
138 | #define MEDIA_ENT_T_V4L2_SUBDEV MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN | ||
139 | #define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR MEDIA_ENT_F_CAM_SENSOR | ||
140 | #define MEDIA_ENT_T_V4L2_SUBDEV_FLASH MEDIA_ENT_F_FLASH | ||
141 | #define MEDIA_ENT_T_V4L2_SUBDEV_LENS MEDIA_ENT_F_LENS | ||
142 | #define MEDIA_ENT_T_V4L2_SUBDEV_DECODER MEDIA_ENT_F_ATV_DECODER | ||
143 | #define MEDIA_ENT_T_V4L2_SUBDEV_TUNER MEDIA_ENT_F_TUNER | ||
144 | #endif | ||
70 | 145 | ||
146 | /* Entity flags */ | ||
71 | #define MEDIA_ENT_FL_DEFAULT (1 << 0) | 147 | #define MEDIA_ENT_FL_DEFAULT (1 << 0) |
148 | #define MEDIA_ENT_FL_CONNECTOR (1 << 1) | ||
72 | 149 | ||
73 | struct media_entity_desc { | 150 | struct media_entity_desc { |
74 | __u32 id; | 151 | __u32 id; |
@@ -151,6 +228,10 @@ struct media_pad_desc { | |||
151 | #define MEDIA_LNK_FL_IMMUTABLE (1 << 1) | 228 | #define MEDIA_LNK_FL_IMMUTABLE (1 << 1) |
152 | #define MEDIA_LNK_FL_DYNAMIC (1 << 2) | 229 | #define MEDIA_LNK_FL_DYNAMIC (1 << 2) |
153 | 230 | ||
231 | #define MEDIA_LNK_FL_LINK_TYPE (0xf << 28) | ||
232 | # define MEDIA_LNK_FL_DATA_LINK (0 << 28) | ||
233 | # define MEDIA_LNK_FL_INTERFACE_LINK (1 << 28) | ||
234 | |||
154 | struct media_link_desc { | 235 | struct media_link_desc { |
155 | struct media_pad_desc source; | 236 | struct media_pad_desc source; |
156 | struct media_pad_desc sink; | 237 | struct media_pad_desc sink; |
@@ -167,9 +248,120 @@ struct media_links_enum { | |||
167 | __u32 reserved[4]; | 248 | __u32 reserved[4]; |
168 | }; | 249 | }; |
169 | 250 | ||
251 | /* Interface type ranges */ | ||
252 | |||
253 | #define MEDIA_INTF_T_DVB_BASE 0x00000100 | ||
254 | #define MEDIA_INTF_T_V4L_BASE 0x00000200 | ||
255 | |||
256 | /* Interface types */ | ||
257 | |||
258 | #define MEDIA_INTF_T_DVB_FE (MEDIA_INTF_T_DVB_BASE) | ||
259 | #define MEDIA_INTF_T_DVB_DEMUX (MEDIA_INTF_T_DVB_BASE + 1) | ||
260 | #define MEDIA_INTF_T_DVB_DVR (MEDIA_INTF_T_DVB_BASE + 2) | ||
261 | #define MEDIA_INTF_T_DVB_CA (MEDIA_INTF_T_DVB_BASE + 3) | ||
262 | #define MEDIA_INTF_T_DVB_NET (MEDIA_INTF_T_DVB_BASE + 4) | ||
263 | |||
264 | #define MEDIA_INTF_T_V4L_VIDEO (MEDIA_INTF_T_V4L_BASE) | ||
265 | #define MEDIA_INTF_T_V4L_VBI (MEDIA_INTF_T_V4L_BASE + 1) | ||
266 | #define MEDIA_INTF_T_V4L_RADIO (MEDIA_INTF_T_V4L_BASE + 2) | ||
267 | #define MEDIA_INTF_T_V4L_SUBDEV (MEDIA_INTF_T_V4L_BASE + 3) | ||
268 | #define MEDIA_INTF_T_V4L_SWRADIO (MEDIA_INTF_T_V4L_BASE + 4) | ||
269 | |||
270 | /* | ||
271 | * MC next gen API definitions | ||
272 | * | ||
273 | * NOTE: The declarations below are close to the MC RFC for the Media | ||
274 | * Controller, the next generation. Yet, there are a few adjustments | ||
275 | * to do, as we want to be able to have a functional API before | ||
276 | * the MC properties change. Those will be properly marked below. | ||
277 | * Please also notice that I removed "num_pads", "num_links", | ||
278 | * from the proposal, as a proper userspace application will likely | ||
279 | * use lists for pads/links, just as we intend to do in Kernelspace. | ||
280 | * The API definition should be freed from fields that are bound to | ||
281 | * some specific data structure. | ||
282 | * | ||
283 | * FIXME: Currently, I opted to name the new types as "media_v2", as this | ||
284 | * won't cause any conflict with the Kernelspace namespace, nor with | ||
285 | * the previous kAPI media_*_desc namespace. This can be changed | ||
286 | * later, before the adding this API upstream. | ||
287 | */ | ||
288 | |||
289 | #if 0 /* Let's postpone it to Kernel 4.6 */ | ||
290 | struct media_v2_entity { | ||
291 | __u32 id; | ||
292 | char name[64]; /* FIXME: move to a property? (RFC says so) */ | ||
293 | __u32 function; /* Main function of the entity */ | ||
294 | __u16 reserved[12]; | ||
295 | }; | ||
296 | |||
297 | /* Should match the specific fields at media_intf_devnode */ | ||
298 | struct media_v2_intf_devnode { | ||
299 | __u32 major; | ||
300 | __u32 minor; | ||
301 | }; | ||
302 | |||
303 | struct media_v2_interface { | ||
304 | __u32 id; | ||
305 | __u32 intf_type; | ||
306 | __u32 flags; | ||
307 | __u32 reserved[9]; | ||
308 | |||
309 | union { | ||
310 | struct media_v2_intf_devnode devnode; | ||
311 | __u32 raw[16]; | ||
312 | }; | ||
313 | }; | ||
314 | |||
315 | struct media_v2_pad { | ||
316 | __u32 id; | ||
317 | __u32 entity_id; | ||
318 | __u32 flags; | ||
319 | __u16 reserved[9]; | ||
320 | }; | ||
321 | |||
322 | struct media_v2_link { | ||
323 | __u32 id; | ||
324 | __u32 source_id; | ||
325 | __u32 sink_id; | ||
326 | __u32 flags; | ||
327 | __u32 reserved[5]; | ||
328 | }; | ||
329 | |||
330 | struct media_v2_topology { | ||
331 | __u64 topology_version; | ||
332 | |||
333 | __u32 num_entities; | ||
334 | __u32 reserved1; | ||
335 | __u64 ptr_entities; | ||
336 | |||
337 | __u32 num_interfaces; | ||
338 | __u32 reserved2; | ||
339 | __u64 ptr_interfaces; | ||
340 | |||
341 | __u32 num_pads; | ||
342 | __u32 reserved3; | ||
343 | __u64 ptr_pads; | ||
344 | |||
345 | __u32 num_links; | ||
346 | __u32 reserved4; | ||
347 | __u64 ptr_links; | ||
348 | }; | ||
349 | |||
350 | static inline void __user *media_get_uptr(__u64 arg) | ||
351 | { | ||
352 | return (void __user *)(uintptr_t)arg; | ||
353 | } | ||
354 | #endif | ||
355 | |||
356 | /* ioctls */ | ||
357 | |||
170 | #define MEDIA_IOC_DEVICE_INFO _IOWR('|', 0x00, struct media_device_info) | 358 | #define MEDIA_IOC_DEVICE_INFO _IOWR('|', 0x00, struct media_device_info) |
171 | #define MEDIA_IOC_ENUM_ENTITIES _IOWR('|', 0x01, struct media_entity_desc) | 359 | #define MEDIA_IOC_ENUM_ENTITIES _IOWR('|', 0x01, struct media_entity_desc) |
172 | #define MEDIA_IOC_ENUM_LINKS _IOWR('|', 0x02, struct media_links_enum) | 360 | #define MEDIA_IOC_ENUM_LINKS _IOWR('|', 0x02, struct media_links_enum) |
173 | #define MEDIA_IOC_SETUP_LINK _IOWR('|', 0x03, struct media_link_desc) | 361 | #define MEDIA_IOC_SETUP_LINK _IOWR('|', 0x03, struct media_link_desc) |
174 | 362 | ||
363 | #if 0 /* Let's postpone it to Kernel 4.6 */ | ||
364 | #define MEDIA_IOC_G_TOPOLOGY _IOWR('|', 0x04, struct media_v2_topology) | ||
365 | #endif | ||
366 | |||
175 | #endif /* __LINUX_MEDIA_H */ | 367 | #endif /* __LINUX_MEDIA_H */ |