Mauro Carvalho Chehab | d26a5d4 | 2016-07-17 07:20:06 -0300 | [diff] [blame^] | 1 | ========== |
| 2 | Media core |
| 3 | ========== |
| 4 | |
| 5 | Video2Linux devices |
| 6 | ------------------- |
| 7 | |
| 8 | .. kernel-doc:: include/media/tuner.h |
| 9 | |
| 10 | .. kernel-doc:: include/media/tuner-types.h |
| 11 | |
| 12 | .. kernel-doc:: include/media/tveeprom.h |
| 13 | |
| 14 | .. kernel-doc:: include/media/v4l2-async.h |
| 15 | |
| 16 | .. kernel-doc:: include/media/v4l2-ctrls.h |
| 17 | |
| 18 | .. kernel-doc:: include/media/v4l2-dv-timings.h |
| 19 | |
| 20 | .. kernel-doc:: include/media/v4l2-event.h |
| 21 | |
| 22 | .. kernel-doc:: include/media/v4l2-flash-led-class.h |
| 23 | |
| 24 | .. kernel-doc:: include/media/v4l2-mc.h |
| 25 | |
| 26 | .. kernel-doc:: include/media/v4l2-mediabus.h |
| 27 | |
| 28 | .. kernel-doc:: include/media/v4l2-mem2mem.h |
| 29 | |
| 30 | .. kernel-doc:: include/media/v4l2-of.h |
| 31 | |
| 32 | .. kernel-doc:: include/media/v4l2-rect.h |
| 33 | |
| 34 | .. kernel-doc:: include/media/v4l2-subdev.h |
| 35 | |
| 36 | .. kernel-doc:: include/media/videobuf2-core.h |
| 37 | |
| 38 | .. kernel-doc:: include/media/videobuf2-v4l2.h |
| 39 | |
| 40 | .. kernel-doc:: include/media/videobuf2-memops.h |
| 41 | |
| 42 | |
| 43 | Digital TV (DVB) devices |
| 44 | ------------------------ |
| 45 | |
| 46 | Digital TV Common functions |
| 47 | --------------------------- |
| 48 | |
| 49 | .. kernel-doc:: drivers/media/dvb-core/dvb_math.h |
| 50 | |
| 51 | .. kernel-doc:: drivers/media/dvb-core/dvb_ringbuffer.h |
| 52 | |
| 53 | .. kernel-doc:: drivers/media/dvb-core/dvbdev.h |
| 54 | |
| 55 | |
| 56 | Digital TV Frontend kABI |
| 57 | ------------------------ |
| 58 | |
| 59 | Digital TV Frontend |
| 60 | ~~~~~~~~~~~~~~~~~~~ |
| 61 | |
| 62 | The Digital TV Frontend kABI defines a driver-internal interface for |
| 63 | registering low-level, hardware specific driver to a hardware independent |
| 64 | frontend layer. It is only of interest for Digital TV device driver writers. |
| 65 | The header file for this API is named dvb_frontend.h and located in |
| 66 | drivers/media/dvb-core. |
| 67 | |
| 68 | Before using the Digital TV frontend core, the bridge driver should attach |
| 69 | the frontend demod, tuner and SEC devices and call dvb_register_frontend(), |
| 70 | in order to register the new frontend at the subsystem. At device |
| 71 | detach/removal, the bridge driver should call dvb_unregister_frontend() to |
| 72 | remove the frontend from the core and then dvb_frontend_detach() to free the |
| 73 | memory allocated by the frontend drivers. |
| 74 | |
| 75 | The drivers should also call dvb_frontend_suspend() as part of their |
| 76 | handler for the &device_driver.suspend(), and dvb_frontend_resume() as |
| 77 | part of their handler for &device_driver.resume(). |
| 78 | |
| 79 | few other optional functions are provided to handle some special cases. |
| 80 | |
| 81 | .. kernel-doc:: drivers/media/dvb-core/dvb_frontend.h |
| 82 | |
| 83 | |
| 84 | Digital TV Demux kABI |
| 85 | --------------------- |
| 86 | |
| 87 | Digital TV Demux |
| 88 | ~~~~~~~~~~~~~~~~ |
| 89 | |
| 90 | The Kernel Digital TV Demux kABI defines a driver-internal interface for |
| 91 | registering low-level, hardware specific driver to a hardware independent |
| 92 | demux layer. It is only of interest for Digital TV device driver writers. |
| 93 | The header file for this kABI is named demux.h and located in |
| 94 | drivers/media/dvb-core. |
| 95 | |
| 96 | The demux kABI should be implemented for each demux in the system. It is |
| 97 | used to select the TS source of a demux and to manage the demux resources. |
| 98 | When the demux client allocates a resource via the demux kABI, it receives |
| 99 | a pointer to the kABI of that resource. |
| 100 | |
| 101 | Each demux receives its TS input from a DVB front-end or from memory, as |
| 102 | set via this demux kABI. In a system with more than one front-end, the kABI |
| 103 | can be used to select one of the DVB front-ends as a TS source for a demux, |
| 104 | unless this is fixed in the HW platform. |
| 105 | |
| 106 | The demux kABI only controls front-ends regarding to their connections with |
| 107 | demuxes; the kABI used to set the other front-end parameters, such as |
| 108 | tuning, are devined via the Digital TV Frontend kABI. |
| 109 | |
| 110 | The functions that implement the abstract interface demux should be defined |
| 111 | static or module private and registered to the Demux core for external |
| 112 | access. It is not necessary to implement every function in the struct |
| 113 | &dmx_demux. For example, a demux interface might support Section filtering, |
| 114 | but not PES filtering. The kABI client is expected to check the value of any |
| 115 | function pointer before calling the function: the value of NULL means |
| 116 | that the function is not available. |
| 117 | |
| 118 | Whenever the functions of the demux API modify shared data, the |
| 119 | possibilities of lost update and race condition problems should be |
| 120 | addressed, e.g. by protecting parts of code with mutexes. |
| 121 | |
| 122 | Note that functions called from a bottom half context must not sleep. |
| 123 | Even a simple memory allocation without using %GFP_ATOMIC can result in a |
| 124 | kernel thread being put to sleep if swapping is needed. For example, the |
| 125 | Linux Kernel calls the functions of a network device interface from a |
| 126 | bottom half context. Thus, if a demux kABI function is called from network |
| 127 | device code, the function must not sleep. |
| 128 | |
| 129 | |
| 130 | |
| 131 | Demux Callback API |
| 132 | ------------------ |
| 133 | |
| 134 | Demux Callback |
| 135 | ~~~~~~~~~~~~~~ |
| 136 | |
| 137 | This kernel-space API comprises the callback functions that deliver filtered |
| 138 | data to the demux client. Unlike the other DVB kABIs, these functions are |
| 139 | provided by the client and called from the demux code. |
| 140 | |
| 141 | The function pointers of this abstract interface are not packed into a |
| 142 | structure as in the other demux APIs, because the callback functions are |
| 143 | registered and used independent of each other. As an example, it is possible |
| 144 | for the API client to provide several callback functions for receiving TS |
| 145 | packets and no callbacks for PES packets or sections. |
| 146 | |
| 147 | The functions that implement the callback API need not be re-entrant: when |
| 148 | a demux driver calls one of these functions, the driver is not allowed to |
| 149 | call the function again before the original call returns. If a callback is |
| 150 | triggered by a hardware interrupt, it is recommended to use the Linux |
| 151 | bottom half mechanism or start a tasklet instead of making the callback |
| 152 | function call directly from a hardware interrupt. |
| 153 | |
| 154 | This mechanism is implemented by dmx_ts_cb() and dmx_section_cb() |
| 155 | callbacks. |
| 156 | |
| 157 | |
| 158 | .. kernel-doc:: drivers/media/dvb-core/demux.h |
| 159 | |
| 160 | |
| 161 | Digital TV Conditional Access kABI |
| 162 | ---------------------------------- |
| 163 | |
| 164 | .. kernel-doc:: drivers/media/dvb-core/dvb_ca_en50221.h |
| 165 | |
| 166 | |
| 167 | Remote Controller devices |
| 168 | ------------------------- |
| 169 | |
| 170 | .. kernel-doc:: include/media/rc-core.h |
| 171 | |
| 172 | .. kernel-doc:: include/media/lirc_dev.h |
| 173 | |
| 174 | |
| 175 | Media Controller devices |
| 176 | ------------------------ |
| 177 | |
| 178 | Media Controller |
| 179 | ~~~~~~~~~~~~~~~~ |
| 180 | |
| 181 | |
| 182 | The media controller userspace API is documented in DocBook format in |
| 183 | Documentation/DocBook/media/v4l/media-controller.xml. This document focus |
| 184 | on the kernel-side implementation of the media framework. |
| 185 | |
| 186 | * Abstract media device model: |
| 187 | |
| 188 | Discovering a device internal topology, and configuring it at runtime, is one |
| 189 | of the goals of the media framework. To achieve this, hardware devices are |
| 190 | modelled as an oriented graph of building blocks called entities connected |
| 191 | through pads. |
| 192 | |
| 193 | An entity is a basic media hardware building block. It can correspond to |
| 194 | a large variety of logical blocks such as physical hardware devices |
| 195 | (CMOS sensor for instance), logical hardware devices (a building block |
| 196 | in a System-on-Chip image processing pipeline), DMA channels or physical |
| 197 | connectors. |
| 198 | |
| 199 | A pad is a connection endpoint through which an entity can interact with |
| 200 | other entities. Data (not restricted to video) produced by an entity |
| 201 | flows from the entity's output to one or more entity inputs. Pads should |
| 202 | not be confused with physical pins at chip boundaries. |
| 203 | |
| 204 | A link is a point-to-point oriented connection between two pads, either |
| 205 | on the same entity or on different entities. Data flows from a source |
| 206 | pad to a sink pad. |
| 207 | |
| 208 | |
| 209 | * Media device: |
| 210 | |
| 211 | A media device is represented by a struct &media_device instance, defined in |
| 212 | include/media/media-device.h. Allocation of the structure is handled by the |
| 213 | media device driver, usually by embedding the &media_device instance in a |
| 214 | larger driver-specific structure. |
| 215 | |
| 216 | Drivers register media device instances by calling |
| 217 | __media_device_register() via the macro media_device_register() |
| 218 | and unregistered by calling |
| 219 | media_device_unregister(). |
| 220 | |
| 221 | * Entities, pads and links: |
| 222 | |
| 223 | - Entities |
| 224 | |
| 225 | Entities are represented by a struct &media_entity instance, defined in |
| 226 | include/media/media-entity.h. The structure is usually embedded into a |
| 227 | higher-level structure, such as a v4l2_subdev or video_device instance, |
| 228 | although drivers can allocate entities directly. |
| 229 | |
| 230 | Drivers initialize entity pads by calling |
| 231 | media_entity_pads_init(). |
| 232 | |
| 233 | Drivers register entities with a media device by calling |
| 234 | media_device_register_entity() |
| 235 | and unregistred by calling |
| 236 | media_device_unregister_entity(). |
| 237 | |
| 238 | - Interfaces |
| 239 | |
| 240 | Interfaces are represented by a struct &media_interface instance, defined in |
| 241 | include/media/media-entity.h. Currently, only one type of interface is |
| 242 | defined: a device node. Such interfaces are represented by a struct |
| 243 | &media_intf_devnode. |
| 244 | |
| 245 | Drivers initialize and create device node interfaces by calling |
| 246 | media_devnode_create() |
| 247 | and remove them by calling: |
| 248 | media_devnode_remove(). |
| 249 | |
| 250 | - Pads |
| 251 | |
| 252 | Pads are represented by a struct &media_pad instance, defined in |
| 253 | include/media/media-entity.h. Each entity stores its pads in a pads array |
| 254 | managed by the entity driver. Drivers usually embed the array in a |
| 255 | driver-specific structure. |
| 256 | |
| 257 | Pads are identified by their entity and their 0-based index in the pads |
| 258 | array. |
| 259 | Both information are stored in the &media_pad structure, making the |
| 260 | &media_pad pointer the canonical way to store and pass link references. |
| 261 | |
| 262 | Pads have flags that describe the pad capabilities and state. |
| 263 | |
| 264 | %MEDIA_PAD_FL_SINK indicates that the pad supports sinking data. |
| 265 | %MEDIA_PAD_FL_SOURCE indicates that the pad supports sourcing data. |
| 266 | |
| 267 | NOTE: One and only one of %MEDIA_PAD_FL_SINK and %MEDIA_PAD_FL_SOURCE must |
| 268 | be set for each pad. |
| 269 | |
| 270 | - Links |
| 271 | |
| 272 | Links are represented by a struct &media_link instance, defined in |
| 273 | include/media/media-entity.h. There are two types of links: |
| 274 | |
| 275 | 1. pad to pad links: |
| 276 | |
| 277 | Associate two entities via their PADs. Each entity has a list that points |
| 278 | to all links originating at or targeting any of its pads. |
| 279 | A given link is thus stored twice, once in the source entity and once in |
| 280 | the target entity. |
| 281 | |
| 282 | Drivers create pad to pad links by calling: |
| 283 | media_create_pad_link() and remove with media_entity_remove_links(). |
| 284 | |
| 285 | 2. interface to entity links: |
| 286 | |
| 287 | Associate one interface to a Link. |
| 288 | |
| 289 | Drivers create interface to entity links by calling: |
| 290 | media_create_intf_link() and remove with media_remove_intf_links(). |
| 291 | |
| 292 | NOTE: |
| 293 | |
| 294 | Links can only be created after having both ends already created. |
| 295 | |
| 296 | Links have flags that describe the link capabilities and state. The |
| 297 | valid values are described at media_create_pad_link() and |
| 298 | media_create_intf_link(). |
| 299 | |
| 300 | Graph traversal: |
| 301 | |
| 302 | The media framework provides APIs to iterate over entities in a graph. |
| 303 | |
| 304 | To iterate over all entities belonging to a media device, drivers can use |
| 305 | the media_device_for_each_entity macro, defined in |
| 306 | include/media/media-device.h. |
| 307 | |
| 308 | struct media_entity *entity; |
| 309 | |
| 310 | media_device_for_each_entity(entity, mdev) { |
| 311 | // entity will point to each entity in turn |
| 312 | ... |
| 313 | } |
| 314 | |
| 315 | Drivers might also need to iterate over all entities in a graph that can be |
| 316 | reached only through enabled links starting at a given entity. The media |
| 317 | framework provides a depth-first graph traversal API for that purpose. |
| 318 | |
| 319 | Note that graphs with cycles (whether directed or undirected) are *NOT* |
| 320 | supported by the graph traversal API. To prevent infinite loops, the graph |
| 321 | traversal code limits the maximum depth to MEDIA_ENTITY_ENUM_MAX_DEPTH, |
| 322 | currently defined as 16. |
| 323 | |
| 324 | Drivers initiate a graph traversal by calling |
| 325 | media_entity_graph_walk_start() |
| 326 | |
| 327 | The graph structure, provided by the caller, is initialized to start graph |
| 328 | traversal at the given entity. |
| 329 | |
| 330 | Drivers can then retrieve the next entity by calling |
| 331 | media_entity_graph_walk_next() |
| 332 | |
| 333 | When the graph traversal is complete the function will return NULL. |
| 334 | |
| 335 | Graph traversal can be interrupted at any moment. No cleanup function call |
| 336 | is required and the graph structure can be freed normally. |
| 337 | |
| 338 | Helper functions can be used to find a link between two given pads, or a pad |
| 339 | connected to another pad through an enabled link |
| 340 | media_entity_find_link() and media_entity_remote_pad() |
| 341 | |
| 342 | Use count and power handling: |
| 343 | |
| 344 | Due to the wide differences between drivers regarding power management |
| 345 | needs, the media controller does not implement power management. However, |
| 346 | the &media_entity structure includes a use_count field that media drivers |
| 347 | can use to track the number of users of every entity for power management |
| 348 | needs. |
| 349 | |
| 350 | The &media_entity.@use_count field is owned by media drivers and must not be |
| 351 | touched by entity drivers. Access to the field must be protected by the |
| 352 | &media_device.@graph_mutex lock. |
| 353 | |
| 354 | Links setup: |
| 355 | |
| 356 | Link properties can be modified at runtime by calling |
| 357 | media_entity_setup_link() |
| 358 | |
| 359 | Pipelines and media streams: |
| 360 | |
| 361 | When starting streaming, drivers must notify all entities in the pipeline to |
| 362 | prevent link states from being modified during streaming by calling |
| 363 | media_entity_pipeline_start(). |
| 364 | |
| 365 | The function will mark all entities connected to the given entity through |
| 366 | enabled links, either directly or indirectly, as streaming. |
| 367 | |
| 368 | The &media_pipeline instance pointed to by the pipe argument will be stored |
| 369 | in every entity in the pipeline. Drivers should embed the &media_pipeline |
| 370 | structure in higher-level pipeline structures and can then access the |
| 371 | pipeline through the &media_entity pipe field. |
| 372 | |
| 373 | Calls to media_entity_pipeline_start() can be nested. The pipeline pointer |
| 374 | must be identical for all nested calls to the function. |
| 375 | |
| 376 | media_entity_pipeline_start() may return an error. In that case, it will |
| 377 | clean up any of the changes it did by itself. |
| 378 | |
| 379 | When stopping the stream, drivers must notify the entities with |
| 380 | media_entity_pipeline_stop(). |
| 381 | |
| 382 | If multiple calls to media_entity_pipeline_start() have been made the same |
| 383 | number of media_entity_pipeline_stop() calls are required to stop streaming. |
| 384 | The &media_entity pipe field is reset to NULL on the last nested stop call. |
| 385 | |
| 386 | Link configuration will fail with -%EBUSY by default if either end of the |
| 387 | link is a streaming entity. Links that can be modified while streaming must |
| 388 | be marked with the %MEDIA_LNK_FL_DYNAMIC flag. |
| 389 | |
| 390 | If other operations need to be disallowed on streaming entities (such as |
| 391 | changing entities configuration parameters) drivers can explicitly check the |
| 392 | media_entity stream_count field to find out if an entity is streaming. This |
| 393 | operation must be done with the media_device graph_mutex held. |
| 394 | |
| 395 | Link validation: |
| 396 | |
| 397 | Link validation is performed by media_entity_pipeline_start() for any |
| 398 | entity which has sink pads in the pipeline. The |
| 399 | &media_entity.@link_validate() callback is used for that purpose. In |
| 400 | @link_validate() callback, entity driver should check that the properties of |
| 401 | the source pad of the connected entity and its own sink pad match. It is up |
| 402 | to the type of the entity (and in the end, the properties of the hardware) |
| 403 | what matching actually means. |
| 404 | |
| 405 | Subsystems should facilitate link validation by providing subsystem specific |
| 406 | helper functions to provide easy access for commonly needed information, and |
| 407 | in the end provide a way to use driver-specific callbacks. |
| 408 | |
| 409 | .. kernel-doc:: include/media/media-device.h |
| 410 | |
| 411 | .. kernel-doc:: include/media/media-devnode.h |
| 412 | |
| 413 | .. kernel-doc:: include/media/media-entity.h |
| 414 | |