media-entity.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * Media entity
  3. *
  4. * Copyright (C) 2010 Nokia Corporation
  5. *
  6. * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  7. * Sakari Ailus <sakari.ailus@iki.fi>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #ifndef _MEDIA_ENTITY_H
  23. #define _MEDIA_ENTITY_H
  24. #include <linux/bitops.h>
  25. #include <linux/kernel.h>
  26. #include <linux/list.h>
  27. #include <linux/media.h>
  28. struct media_pipeline {
  29. };
  30. struct media_link {
  31. struct media_pad *source; /* Source pad */
  32. struct media_pad *sink; /* Sink pad */
  33. struct media_link *reverse; /* Link in the reverse direction */
  34. unsigned long flags; /* Link flags (MEDIA_LNK_FL_*) */
  35. };
  36. struct media_pad {
  37. struct media_entity *entity; /* Entity this pad belongs to */
  38. u16 index; /* Pad index in the entity pads array */
  39. unsigned long flags; /* Pad flags (MEDIA_PAD_FL_*) */
  40. };
  41. /**
  42. * struct media_entity_operations - Media entity operations
  43. * @link_setup: Notify the entity of link changes. The operation can
  44. * return an error, in which case link setup will be
  45. * cancelled. Optional.
  46. * @link_validate: Return whether a link is valid from the entity point of
  47. * view. The media_entity_pipeline_start() function
  48. * validates all links by calling this operation. Optional.
  49. */
  50. struct media_entity_operations {
  51. int (*link_setup)(struct media_entity *entity,
  52. const struct media_pad *local,
  53. const struct media_pad *remote, u32 flags);
  54. int (*link_validate)(struct media_link *link);
  55. };
  56. struct media_entity {
  57. struct list_head list;
  58. struct media_device *parent; /* Media device this entity belongs to*/
  59. u32 id; /* Entity ID, unique in the parent media
  60. * device context */
  61. const char *name; /* Entity name */
  62. u32 type; /* Entity type (MEDIA_ENT_T_*) */
  63. u32 revision; /* Entity revision, driver specific */
  64. unsigned long flags; /* Entity flags (MEDIA_ENT_FL_*) */
  65. u32 group_id; /* Entity group ID */
  66. u16 num_pads; /* Number of sink and source pads */
  67. u16 num_links; /* Number of existing links, both
  68. * enabled and disabled */
  69. u16 num_backlinks; /* Number of backlinks */
  70. u16 max_links; /* Maximum number of links */
  71. struct media_pad *pads; /* Pads array (num_pads elements) */
  72. struct media_link *links; /* Links array (max_links elements)*/
  73. const struct media_entity_operations *ops; /* Entity operations */
  74. /* Reference counts must never be negative, but are signed integers on
  75. * purpose: a simple WARN_ON(<0) check can be used to detect reference
  76. * count bugs that would make them negative.
  77. */
  78. int stream_count; /* Stream count for the entity. */
  79. int use_count; /* Use count for the entity. */
  80. struct media_pipeline *pipe; /* Pipeline this entity belongs to. */
  81. union {
  82. /* Node specifications */
  83. struct {
  84. u32 major;
  85. u32 minor;
  86. } dev;
  87. /* Sub-device specifications */
  88. /* Nothing needed yet */
  89. } info;
  90. };
  91. static inline u32 media_entity_type(struct media_entity *entity)
  92. {
  93. return entity->type & MEDIA_ENT_TYPE_MASK;
  94. }
  95. static inline u32 media_entity_subtype(struct media_entity *entity)
  96. {
  97. return entity->type & MEDIA_ENT_SUBTYPE_MASK;
  98. }
  99. #define MEDIA_ENTITY_ENUM_MAX_DEPTH 16
  100. #define MEDIA_ENTITY_ENUM_MAX_ID 64
  101. struct media_entity_graph {
  102. struct {
  103. struct media_entity *entity;
  104. int link;
  105. } stack[MEDIA_ENTITY_ENUM_MAX_DEPTH];
  106. DECLARE_BITMAP(entities, MEDIA_ENTITY_ENUM_MAX_ID);
  107. int top;
  108. };
  109. int media_entity_init(struct media_entity *entity, u16 num_pads,
  110. struct media_pad *pads, u16 extra_links);
  111. void media_entity_cleanup(struct media_entity *entity);
  112. int media_entity_create_link(struct media_entity *source, u16 source_pad,
  113. struct media_entity *sink, u16 sink_pad, u32 flags);
  114. void __media_entity_remove_links(struct media_entity *entity);
  115. void media_entity_remove_links(struct media_entity *entity);
  116. int __media_entity_setup_link(struct media_link *link, u32 flags);
  117. int media_entity_setup_link(struct media_link *link, u32 flags);
  118. struct media_link *media_entity_find_link(struct media_pad *source,
  119. struct media_pad *sink);
  120. struct media_pad *media_entity_remote_pad(struct media_pad *pad);
  121. struct media_entity *media_entity_get(struct media_entity *entity);
  122. void media_entity_put(struct media_entity *entity);
  123. void media_entity_graph_walk_start(struct media_entity_graph *graph,
  124. struct media_entity *entity);
  125. struct media_entity *
  126. media_entity_graph_walk_next(struct media_entity_graph *graph);
  127. __must_check int media_entity_pipeline_start(struct media_entity *entity,
  128. struct media_pipeline *pipe);
  129. void media_entity_pipeline_stop(struct media_entity *entity);
  130. #define media_entity_call(entity, operation, args...) \
  131. (((entity)->ops && (entity)->ops->operation) ? \
  132. (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD)
  133. #endif