Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] media: Add link_validate() op to check links to the sink pad

The purpose of the link_validate() op is to allow an entity driver to ensure
that the properties of the pads at the both ends of the link are suitable
for starting the pipeline. link_validate is called on sink pads on active
links which belong to the active part of the graph.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>

authored by

Sakari Ailus and committed by
Mauro Carvalho Chehab
af88be38 440f0fad

+77 -4
+19
Documentation/media-framework.txt
··· 335 335 Calls to media_entity_pipeline_start() can be nested. The pipeline pointer must 336 336 be identical for all nested calls to the function. 337 337 338 + media_entity_pipeline_start() may return an error. In that case, it will 339 + clean up any the changes it did by itself. 340 + 338 341 When stopping the stream, drivers must notify the entities with 339 342 340 343 media_entity_pipeline_stop(struct media_entity *entity); ··· 354 351 changing entities configuration parameters) drivers can explicitly check the 355 352 media_entity stream_count field to find out if an entity is streaming. This 356 353 operation must be done with the media_device graph_mutex held. 354 + 355 + 356 + Link validation 357 + --------------- 358 + 359 + Link validation is performed by media_entity_pipeline_start() for any 360 + entity which has sink pads in the pipeline. The 361 + media_entity::link_validate() callback is used for that purpose. In 362 + link_validate() callback, entity driver should check that the properties of 363 + the source pad of the connected entity and its own sink pad match. It is up 364 + to the type of the entity (and in the end, the properties of the hardware) 365 + what matching actually means. 366 + 367 + Subsystems should facilitate link validation by providing subsystem specific 368 + helper functions to provide easy access for commonly needed information, and 369 + in the end provide a way to use driver-specific callbacks.
+55 -2
drivers/media/media-entity.c
··· 214 214 * pipeline pointer must be identical for all nested calls to 215 215 * media_entity_pipeline_start(). 216 216 */ 217 - void media_entity_pipeline_start(struct media_entity *entity, 218 - struct media_pipeline *pipe) 217 + __must_check int media_entity_pipeline_start(struct media_entity *entity, 218 + struct media_pipeline *pipe) 219 219 { 220 220 struct media_device *mdev = entity->parent; 221 221 struct media_entity_graph graph; 222 + struct media_entity *entity_err = entity; 223 + int ret; 222 224 223 225 mutex_lock(&mdev->graph_mutex); 224 226 225 227 media_entity_graph_walk_start(&graph, entity); 226 228 227 229 while ((entity = media_entity_graph_walk_next(&graph))) { 230 + unsigned int i; 231 + 228 232 entity->stream_count++; 229 233 WARN_ON(entity->pipe && entity->pipe != pipe); 230 234 entity->pipe = pipe; 235 + 236 + /* Already streaming --- no need to check. */ 237 + if (entity->stream_count > 1) 238 + continue; 239 + 240 + if (!entity->ops || !entity->ops->link_validate) 241 + continue; 242 + 243 + for (i = 0; i < entity->num_links; i++) { 244 + struct media_link *link = &entity->links[i]; 245 + 246 + /* Is this pad part of an enabled link? */ 247 + if (!(link->flags & MEDIA_LNK_FL_ENABLED)) 248 + continue; 249 + 250 + /* Are we the sink or not? */ 251 + if (link->sink->entity != entity) 252 + continue; 253 + 254 + ret = entity->ops->link_validate(link); 255 + if (ret < 0 && ret != -ENOIOCTLCMD) 256 + goto error; 257 + } 231 258 } 232 259 233 260 mutex_unlock(&mdev->graph_mutex); 261 + 262 + return 0; 263 + 264 + error: 265 + /* 266 + * Link validation on graph failed. We revert what we did and 267 + * return the error. 268 + */ 269 + media_entity_graph_walk_start(&graph, entity_err); 270 + 271 + while ((entity_err = media_entity_graph_walk_next(&graph))) { 272 + entity_err->stream_count--; 273 + if (entity_err->stream_count == 0) 274 + entity_err->pipe = NULL; 275 + 276 + /* 277 + * We haven't increased stream_count further than this 278 + * so we quit here. 279 + */ 280 + if (entity_err == entity) 281 + break; 282 + } 283 + 284 + mutex_unlock(&mdev->graph_mutex); 285 + 286 + return ret; 234 287 } 235 288 EXPORT_SYMBOL_GPL(media_entity_pipeline_start); 236 289
+3 -2
include/media/media-entity.h
··· 46 46 int (*link_setup)(struct media_entity *entity, 47 47 const struct media_pad *local, 48 48 const struct media_pad *remote, u32 flags); 49 + int (*link_validate)(struct media_link *link); 49 50 }; 50 51 51 52 struct media_entity { ··· 141 140 struct media_entity *entity); 142 141 struct media_entity * 143 142 media_entity_graph_walk_next(struct media_entity_graph *graph); 144 - void media_entity_pipeline_start(struct media_entity *entity, 145 - struct media_pipeline *pipe); 143 + __must_check int media_entity_pipeline_start(struct media_entity *entity, 144 + struct media_pipeline *pipe); 146 145 void media_entity_pipeline_stop(struct media_entity *entity); 147 146 148 147 #define media_entity_call(entity, operation, args...) \