media-entity.h 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Media entity
  4. *
  5. * Copyright (C) 2010 Nokia Corporation
  6. *
  7. * Contacts: Laurent Pinchart <[email protected]>
  8. * Sakari Ailus <[email protected]>
  9. */
  10. #ifndef _MEDIA_ENTITY_H
  11. #define _MEDIA_ENTITY_H
  12. #include <linux/bitmap.h>
  13. #include <linux/bug.h>
  14. #include <linux/container_of.h>
  15. #include <linux/fwnode.h>
  16. #include <linux/list.h>
  17. #include <linux/media.h>
  18. #include <linux/minmax.h>
  19. #include <linux/types.h>
  20. /* Enums used internally at the media controller to represent graphs */
  21. /**
  22. * enum media_gobj_type - type of a graph object
  23. *
  24. * @MEDIA_GRAPH_ENTITY: Identify a media entity
  25. * @MEDIA_GRAPH_PAD: Identify a media pad
  26. * @MEDIA_GRAPH_LINK: Identify a media link
  27. * @MEDIA_GRAPH_INTF_DEVNODE: Identify a media Kernel API interface via
  28. * a device node
  29. */
  30. enum media_gobj_type {
  31. MEDIA_GRAPH_ENTITY,
  32. MEDIA_GRAPH_PAD,
  33. MEDIA_GRAPH_LINK,
  34. MEDIA_GRAPH_INTF_DEVNODE,
  35. };
  36. #define MEDIA_BITS_PER_TYPE 8
  37. #define MEDIA_BITS_PER_ID (32 - MEDIA_BITS_PER_TYPE)
  38. #define MEDIA_ID_MASK GENMASK_ULL(MEDIA_BITS_PER_ID - 1, 0)
  39. /* Structs to represent the objects that belong to a media graph */
  40. /**
  41. * struct media_gobj - Define a graph object.
  42. *
  43. * @mdev: Pointer to the struct &media_device that owns the object
  44. * @id: Non-zero object ID identifier. The ID should be unique
  45. * inside a media_device, as it is composed by
  46. * %MEDIA_BITS_PER_TYPE to store the type plus
  47. * %MEDIA_BITS_PER_ID to store the ID
  48. * @list: List entry stored in one of the per-type mdev object lists
  49. *
  50. * All objects on the media graph should have this struct embedded
  51. */
  52. struct media_gobj {
  53. struct media_device *mdev;
  54. u32 id;
  55. struct list_head list;
  56. };
  57. #define MEDIA_ENTITY_ENUM_MAX_DEPTH 16
  58. /**
  59. * struct media_entity_enum - An enumeration of media entities.
  60. *
  61. * @bmap: Bit map in which each bit represents one entity at struct
  62. * media_entity->internal_idx.
  63. * @idx_max: Number of bits in bmap
  64. */
  65. struct media_entity_enum {
  66. unsigned long *bmap;
  67. int idx_max;
  68. };
  69. /**
  70. * struct media_graph - Media graph traversal state
  71. *
  72. * @stack: Graph traversal stack; the stack contains information
  73. * on the path the media entities to be walked and the
  74. * links through which they were reached.
  75. * @stack.entity: pointer to &struct media_entity at the graph.
  76. * @stack.link: pointer to &struct list_head.
  77. * @ent_enum: Visited entities
  78. * @top: The top of the stack
  79. */
  80. struct media_graph {
  81. struct {
  82. struct media_entity *entity;
  83. struct list_head *link;
  84. } stack[MEDIA_ENTITY_ENUM_MAX_DEPTH];
  85. struct media_entity_enum ent_enum;
  86. int top;
  87. };
  88. /**
  89. * struct media_pipeline - Media pipeline related information
  90. *
  91. * @allocated: Media pipeline allocated and freed by the framework
  92. * @mdev: The media device the pipeline is part of
  93. * @pads: List of media_pipeline_pad
  94. * @start_count: Media pipeline start - stop count
  95. */
  96. struct media_pipeline {
  97. bool allocated;
  98. struct media_device *mdev;
  99. struct list_head pads;
  100. int start_count;
  101. };
  102. /**
  103. * struct media_pipeline_pad - A pad part of a media pipeline
  104. *
  105. * @list: Entry in the media_pad pads list
  106. * @pipe: The media_pipeline that the pad is part of
  107. * @pad: The media pad
  108. *
  109. * This structure associate a pad with a media pipeline. Instances of
  110. * media_pipeline_pad are created by media_pipeline_start() when it builds the
  111. * pipeline, and stored in the &media_pad.pads list. media_pipeline_stop()
  112. * removes the entries from the list and deletes them.
  113. */
  114. struct media_pipeline_pad {
  115. struct list_head list;
  116. struct media_pipeline *pipe;
  117. struct media_pad *pad;
  118. };
  119. /**
  120. * struct media_link - A link object part of a media graph.
  121. *
  122. * @graph_obj: Embedded structure containing the media object common data
  123. * @list: Linked list associated with an entity or an interface that
  124. * owns the link.
  125. * @gobj0: Part of a union. Used to get the pointer for the first
  126. * graph_object of the link.
  127. * @source: Part of a union. Used only if the first object (gobj0) is
  128. * a pad. In that case, it represents the source pad.
  129. * @intf: Part of a union. Used only if the first object (gobj0) is
  130. * an interface.
  131. * @gobj1: Part of a union. Used to get the pointer for the second
  132. * graph_object of the link.
  133. * @sink: Part of a union. Used only if the second object (gobj1) is
  134. * a pad. In that case, it represents the sink pad.
  135. * @entity: Part of a union. Used only if the second object (gobj1) is
  136. * an entity.
  137. * @reverse: Pointer to the link for the reverse direction of a pad to pad
  138. * link.
  139. * @flags: Link flags, as defined in uapi/media.h (MEDIA_LNK_FL_*)
  140. * @is_backlink: Indicate if the link is a backlink.
  141. */
  142. struct media_link {
  143. struct media_gobj graph_obj;
  144. struct list_head list;
  145. union {
  146. struct media_gobj *gobj0;
  147. struct media_pad *source;
  148. struct media_interface *intf;
  149. };
  150. union {
  151. struct media_gobj *gobj1;
  152. struct media_pad *sink;
  153. struct media_entity *entity;
  154. };
  155. struct media_link *reverse;
  156. unsigned long flags;
  157. bool is_backlink;
  158. };
  159. /**
  160. * enum media_pad_signal_type - type of the signal inside a media pad
  161. *
  162. * @PAD_SIGNAL_DEFAULT:
  163. * Default signal. Use this when all inputs or all outputs are
  164. * uniquely identified by the pad number.
  165. * @PAD_SIGNAL_ANALOG:
  166. * The pad contains an analog signal. It can be Radio Frequency,
  167. * Intermediate Frequency, a baseband signal or sub-carriers.
  168. * Tuner inputs, IF-PLL demodulators, composite and s-video signals
  169. * should use it.
  170. * @PAD_SIGNAL_DV:
  171. * Contains a digital video signal, with can be a bitstream of samples
  172. * taken from an analog TV video source. On such case, it usually
  173. * contains the VBI data on it.
  174. * @PAD_SIGNAL_AUDIO:
  175. * Contains an Intermediate Frequency analog signal from an audio
  176. * sub-carrier or an audio bitstream. IF signals are provided by tuners
  177. * and consumed by audio AM/FM decoders. Bitstream audio is provided by
  178. * an audio decoder.
  179. */
  180. enum media_pad_signal_type {
  181. PAD_SIGNAL_DEFAULT = 0,
  182. PAD_SIGNAL_ANALOG,
  183. PAD_SIGNAL_DV,
  184. PAD_SIGNAL_AUDIO,
  185. };
  186. /**
  187. * struct media_pad - A media pad graph object.
  188. *
  189. * @graph_obj: Embedded structure containing the media object common data
  190. * @entity: Entity this pad belongs to
  191. * @index: Pad index in the entity pads array, numbered from 0 to n
  192. * @sig_type: Type of the signal inside a media pad
  193. * @flags: Pad flags, as defined in
  194. * :ref:`include/uapi/linux/media.h <media_header>`
  195. * (seek for ``MEDIA_PAD_FL_*``)
  196. * @pipe: Pipeline this pad belongs to. Use media_entity_pipeline() to
  197. * access this field.
  198. */
  199. struct media_pad {
  200. struct media_gobj graph_obj; /* must be first field in struct */
  201. struct media_entity *entity;
  202. u16 index;
  203. enum media_pad_signal_type sig_type;
  204. unsigned long flags;
  205. /*
  206. * The fields below are private, and should only be accessed via
  207. * appropriate functions.
  208. */
  209. struct media_pipeline *pipe;
  210. };
  211. /**
  212. * struct media_entity_operations - Media entity operations
  213. * @get_fwnode_pad: Return the pad number based on a fwnode endpoint or
  214. * a negative value on error. This operation can be used
  215. * to map a fwnode to a media pad number. Optional.
  216. * @link_setup: Notify the entity of link changes. The operation can
  217. * return an error, in which case link setup will be
  218. * cancelled. Optional.
  219. * @link_validate: Return whether a link is valid from the entity point of
  220. * view. The media_pipeline_start() function
  221. * validates all links by calling this operation. Optional.
  222. * @has_pad_interdep: Return whether a two pads inside the entity are
  223. * interdependent. If two pads are interdependent they are
  224. * part of the same pipeline and enabling one of the pads
  225. * means that the other pad will become "locked" and
  226. * doesn't allow configuration changes. pad0 and pad1 are
  227. * guaranteed to not both be sinks or sources.
  228. * Optional: If the operation isn't implemented all pads
  229. * will be considered as interdependent.
  230. *
  231. * .. note::
  232. *
  233. * Those these callbacks are called with struct &media_device.graph_mutex
  234. * mutex held.
  235. */
  236. struct media_entity_operations {
  237. int (*get_fwnode_pad)(struct media_entity *entity,
  238. struct fwnode_endpoint *endpoint);
  239. int (*link_setup)(struct media_entity *entity,
  240. const struct media_pad *local,
  241. const struct media_pad *remote, u32 flags);
  242. int (*link_validate)(struct media_link *link);
  243. bool (*has_pad_interdep)(struct media_entity *entity, unsigned int pad0,
  244. unsigned int pad1);
  245. };
  246. /**
  247. * enum media_entity_type - Media entity type
  248. *
  249. * @MEDIA_ENTITY_TYPE_BASE:
  250. * The entity isn't embedded in another subsystem structure.
  251. * @MEDIA_ENTITY_TYPE_VIDEO_DEVICE:
  252. * The entity is embedded in a struct video_device instance.
  253. * @MEDIA_ENTITY_TYPE_V4L2_SUBDEV:
  254. * The entity is embedded in a struct v4l2_subdev instance.
  255. *
  256. * Media entity objects are often not instantiated directly, but the media
  257. * entity structure is inherited by (through embedding) other subsystem-specific
  258. * structures. The media entity type identifies the type of the subclass
  259. * structure that implements a media entity instance.
  260. *
  261. * This allows runtime type identification of media entities and safe casting to
  262. * the correct object type. For instance, a media entity structure instance
  263. * embedded in a v4l2_subdev structure instance will have the type
  264. * %MEDIA_ENTITY_TYPE_V4L2_SUBDEV and can safely be cast to a &v4l2_subdev
  265. * structure using the container_of() macro.
  266. */
  267. enum media_entity_type {
  268. MEDIA_ENTITY_TYPE_BASE,
  269. MEDIA_ENTITY_TYPE_VIDEO_DEVICE,
  270. MEDIA_ENTITY_TYPE_V4L2_SUBDEV,
  271. };
  272. /**
  273. * struct media_entity - A media entity graph object.
  274. *
  275. * @graph_obj: Embedded structure containing the media object common data.
  276. * @name: Entity name.
  277. * @obj_type: Type of the object that implements the media_entity.
  278. * @function: Entity main function, as defined in
  279. * :ref:`include/uapi/linux/media.h <media_header>`
  280. * (seek for ``MEDIA_ENT_F_*``)
  281. * @flags: Entity flags, as defined in
  282. * :ref:`include/uapi/linux/media.h <media_header>`
  283. * (seek for ``MEDIA_ENT_FL_*``)
  284. * @num_pads: Number of sink and source pads.
  285. * @num_links: Total number of links, forward and back, enabled and disabled.
  286. * @num_backlinks: Number of backlinks
  287. * @internal_idx: An unique internal entity specific number. The numbers are
  288. * re-used if entities are unregistered or registered again.
  289. * @pads: Pads array with the size defined by @num_pads.
  290. * @links: List of data links.
  291. * @ops: Entity operations.
  292. * @use_count: Use count for the entity.
  293. * @info: Union with devnode information. Kept just for backward
  294. * compatibility.
  295. * @info.dev: Contains device major and minor info.
  296. * @info.dev.major: device node major, if the device is a devnode.
  297. * @info.dev.minor: device node minor, if the device is a devnode.
  298. * @major: Devnode major number (zero if not applicable). Kept just
  299. * for backward compatibility.
  300. * @minor: Devnode minor number (zero if not applicable). Kept just
  301. * for backward compatibility.
  302. *
  303. * .. note::
  304. *
  305. * The @use_count reference count must never be negative, but is a signed
  306. * integer on purpose: a simple ``WARN_ON(<0)`` check can be used to detect
  307. * reference count bugs that would make it negative.
  308. */
  309. struct media_entity {
  310. struct media_gobj graph_obj; /* must be first field in struct */
  311. const char *name;
  312. enum media_entity_type obj_type;
  313. u32 function;
  314. unsigned long flags;
  315. u16 num_pads;
  316. u16 num_links;
  317. u16 num_backlinks;
  318. int internal_idx;
  319. struct media_pad *pads;
  320. struct list_head links;
  321. const struct media_entity_operations *ops;
  322. int use_count;
  323. union {
  324. struct {
  325. u32 major;
  326. u32 minor;
  327. } dev;
  328. } info;
  329. };
  330. /**
  331. * media_entity_for_each_pad - Iterate on all pads in an entity
  332. * @entity: The entity the pads belong to
  333. * @iter: The iterator pad
  334. *
  335. * Iterate on all pads in a media entity.
  336. */
  337. #define media_entity_for_each_pad(entity, iter) \
  338. for (iter = (entity)->pads; \
  339. iter < &(entity)->pads[(entity)->num_pads]; \
  340. ++iter)
  341. /**
  342. * struct media_interface - A media interface graph object.
  343. *
  344. * @graph_obj: embedded graph object
  345. * @links: List of links pointing to graph entities
  346. * @type: Type of the interface as defined in
  347. * :ref:`include/uapi/linux/media.h <media_header>`
  348. * (seek for ``MEDIA_INTF_T_*``)
  349. * @flags: Interface flags as defined in
  350. * :ref:`include/uapi/linux/media.h <media_header>`
  351. * (seek for ``MEDIA_INTF_FL_*``)
  352. *
  353. * .. note::
  354. *
  355. * Currently, no flags for &media_interface is defined.
  356. */
  357. struct media_interface {
  358. struct media_gobj graph_obj;
  359. struct list_head links;
  360. u32 type;
  361. u32 flags;
  362. };
  363. /**
  364. * struct media_intf_devnode - A media interface via a device node.
  365. *
  366. * @intf: embedded interface object
  367. * @major: Major number of a device node
  368. * @minor: Minor number of a device node
  369. */
  370. struct media_intf_devnode {
  371. struct media_interface intf;
  372. /* Should match the fields at media_v2_intf_devnode */
  373. u32 major;
  374. u32 minor;
  375. };
  376. /**
  377. * media_entity_id() - return the media entity graph object id
  378. *
  379. * @entity: pointer to &media_entity
  380. */
  381. static inline u32 media_entity_id(struct media_entity *entity)
  382. {
  383. return entity->graph_obj.id;
  384. }
  385. /**
  386. * media_type() - return the media object type
  387. *
  388. * @gobj: Pointer to the struct &media_gobj graph object
  389. */
  390. static inline enum media_gobj_type media_type(struct media_gobj *gobj)
  391. {
  392. return gobj->id >> MEDIA_BITS_PER_ID;
  393. }
  394. /**
  395. * media_id() - return the media object ID
  396. *
  397. * @gobj: Pointer to the struct &media_gobj graph object
  398. */
  399. static inline u32 media_id(struct media_gobj *gobj)
  400. {
  401. return gobj->id & MEDIA_ID_MASK;
  402. }
  403. /**
  404. * media_gobj_gen_id() - encapsulates type and ID on at the object ID
  405. *
  406. * @type: object type as define at enum &media_gobj_type.
  407. * @local_id: next ID, from struct &media_device.id.
  408. */
  409. static inline u32 media_gobj_gen_id(enum media_gobj_type type, u64 local_id)
  410. {
  411. u32 id;
  412. id = type << MEDIA_BITS_PER_ID;
  413. id |= local_id & MEDIA_ID_MASK;
  414. return id;
  415. }
  416. /**
  417. * is_media_entity_v4l2_video_device() - Check if the entity is a video_device
  418. * @entity: pointer to entity
  419. *
  420. * Return: %true if the entity is an instance of a video_device object and can
  421. * safely be cast to a struct video_device using the container_of() macro, or
  422. * %false otherwise.
  423. */
  424. static inline bool is_media_entity_v4l2_video_device(struct media_entity *entity)
  425. {
  426. return entity && entity->obj_type == MEDIA_ENTITY_TYPE_VIDEO_DEVICE;
  427. }
  428. /**
  429. * is_media_entity_v4l2_subdev() - Check if the entity is a v4l2_subdev
  430. * @entity: pointer to entity
  431. *
  432. * Return: %true if the entity is an instance of a &v4l2_subdev object and can
  433. * safely be cast to a struct &v4l2_subdev using the container_of() macro, or
  434. * %false otherwise.
  435. */
  436. static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity)
  437. {
  438. return entity && entity->obj_type == MEDIA_ENTITY_TYPE_V4L2_SUBDEV;
  439. }
  440. /**
  441. * media_entity_enum_init - Initialise an entity enumeration
  442. *
  443. * @ent_enum: Entity enumeration to be initialised
  444. * @mdev: The related media device
  445. *
  446. * Return: zero on success or a negative error code.
  447. */
  448. __must_check int media_entity_enum_init(struct media_entity_enum *ent_enum,
  449. struct media_device *mdev);
  450. /**
  451. * media_entity_enum_cleanup - Release resources of an entity enumeration
  452. *
  453. * @ent_enum: Entity enumeration to be released
  454. */
  455. void media_entity_enum_cleanup(struct media_entity_enum *ent_enum);
  456. /**
  457. * media_entity_enum_zero - Clear the entire enum
  458. *
  459. * @ent_enum: Entity enumeration to be cleared
  460. */
  461. static inline void media_entity_enum_zero(struct media_entity_enum *ent_enum)
  462. {
  463. bitmap_zero(ent_enum->bmap, ent_enum->idx_max);
  464. }
  465. /**
  466. * media_entity_enum_set - Mark a single entity in the enum
  467. *
  468. * @ent_enum: Entity enumeration
  469. * @entity: Entity to be marked
  470. */
  471. static inline void media_entity_enum_set(struct media_entity_enum *ent_enum,
  472. struct media_entity *entity)
  473. {
  474. if (WARN_ON(entity->internal_idx >= ent_enum->idx_max))
  475. return;
  476. __set_bit(entity->internal_idx, ent_enum->bmap);
  477. }
  478. /**
  479. * media_entity_enum_clear - Unmark a single entity in the enum
  480. *
  481. * @ent_enum: Entity enumeration
  482. * @entity: Entity to be unmarked
  483. */
  484. static inline void media_entity_enum_clear(struct media_entity_enum *ent_enum,
  485. struct media_entity *entity)
  486. {
  487. if (WARN_ON(entity->internal_idx >= ent_enum->idx_max))
  488. return;
  489. __clear_bit(entity->internal_idx, ent_enum->bmap);
  490. }
  491. /**
  492. * media_entity_enum_test - Test whether the entity is marked
  493. *
  494. * @ent_enum: Entity enumeration
  495. * @entity: Entity to be tested
  496. *
  497. * Returns %true if the entity was marked.
  498. */
  499. static inline bool media_entity_enum_test(struct media_entity_enum *ent_enum,
  500. struct media_entity *entity)
  501. {
  502. if (WARN_ON(entity->internal_idx >= ent_enum->idx_max))
  503. return true;
  504. return test_bit(entity->internal_idx, ent_enum->bmap);
  505. }
  506. /**
  507. * media_entity_enum_test_and_set - Test whether the entity is marked,
  508. * and mark it
  509. *
  510. * @ent_enum: Entity enumeration
  511. * @entity: Entity to be tested
  512. *
  513. * Returns %true if the entity was marked, and mark it before doing so.
  514. */
  515. static inline bool
  516. media_entity_enum_test_and_set(struct media_entity_enum *ent_enum,
  517. struct media_entity *entity)
  518. {
  519. if (WARN_ON(entity->internal_idx >= ent_enum->idx_max))
  520. return true;
  521. return __test_and_set_bit(entity->internal_idx, ent_enum->bmap);
  522. }
  523. /**
  524. * media_entity_enum_empty - Test whether the entire enum is empty
  525. *
  526. * @ent_enum: Entity enumeration
  527. *
  528. * Return: %true if the entity was empty.
  529. */
  530. static inline bool media_entity_enum_empty(struct media_entity_enum *ent_enum)
  531. {
  532. return bitmap_empty(ent_enum->bmap, ent_enum->idx_max);
  533. }
  534. /**
  535. * media_entity_enum_intersects - Test whether two enums intersect
  536. *
  537. * @ent_enum1: First entity enumeration
  538. * @ent_enum2: Second entity enumeration
  539. *
  540. * Return: %true if entity enumerations @ent_enum1 and @ent_enum2 intersect,
  541. * otherwise %false.
  542. */
  543. static inline bool media_entity_enum_intersects(
  544. struct media_entity_enum *ent_enum1,
  545. struct media_entity_enum *ent_enum2)
  546. {
  547. WARN_ON(ent_enum1->idx_max != ent_enum2->idx_max);
  548. return bitmap_intersects(ent_enum1->bmap, ent_enum2->bmap,
  549. min(ent_enum1->idx_max, ent_enum2->idx_max));
  550. }
  551. /**
  552. * gobj_to_entity - returns the struct &media_entity pointer from the
  553. * @gobj contained on it.
  554. *
  555. * @gobj: Pointer to the struct &media_gobj graph object
  556. */
  557. #define gobj_to_entity(gobj) \
  558. container_of(gobj, struct media_entity, graph_obj)
  559. /**
  560. * gobj_to_pad - returns the struct &media_pad pointer from the
  561. * @gobj contained on it.
  562. *
  563. * @gobj: Pointer to the struct &media_gobj graph object
  564. */
  565. #define gobj_to_pad(gobj) \
  566. container_of(gobj, struct media_pad, graph_obj)
  567. /**
  568. * gobj_to_link - returns the struct &media_link pointer from the
  569. * @gobj contained on it.
  570. *
  571. * @gobj: Pointer to the struct &media_gobj graph object
  572. */
  573. #define gobj_to_link(gobj) \
  574. container_of(gobj, struct media_link, graph_obj)
  575. /**
  576. * gobj_to_intf - returns the struct &media_interface pointer from the
  577. * @gobj contained on it.
  578. *
  579. * @gobj: Pointer to the struct &media_gobj graph object
  580. */
  581. #define gobj_to_intf(gobj) \
  582. container_of(gobj, struct media_interface, graph_obj)
  583. /**
  584. * intf_to_devnode - returns the struct media_intf_devnode pointer from the
  585. * @intf contained on it.
  586. *
  587. * @intf: Pointer to struct &media_intf_devnode
  588. */
  589. #define intf_to_devnode(intf) \
  590. container_of(intf, struct media_intf_devnode, intf)
  591. /**
  592. * media_gobj_create - Initialize a graph object
  593. *
  594. * @mdev: Pointer to the &media_device that contains the object
  595. * @type: Type of the object
  596. * @gobj: Pointer to the struct &media_gobj graph object
  597. *
  598. * This routine initializes the embedded struct &media_gobj inside a
  599. * media graph object. It is called automatically if ``media_*_create``
  600. * function calls are used. However, if the object (entity, link, pad,
  601. * interface) is embedded on some other object, this function should be
  602. * called before registering the object at the media controller.
  603. */
  604. void media_gobj_create(struct media_device *mdev,
  605. enum media_gobj_type type,
  606. struct media_gobj *gobj);
  607. /**
  608. * media_gobj_destroy - Stop using a graph object on a media device
  609. *
  610. * @gobj: Pointer to the struct &media_gobj graph object
  611. *
  612. * This should be called by all routines like media_device_unregister()
  613. * that remove/destroy media graph objects.
  614. */
  615. void media_gobj_destroy(struct media_gobj *gobj);
  616. /**
  617. * media_entity_pads_init() - Initialize the entity pads
  618. *
  619. * @entity: entity where the pads belong
  620. * @num_pads: total number of sink and source pads
  621. * @pads: Array of @num_pads pads.
  622. *
  623. * The pads array is managed by the entity driver and passed to
  624. * media_entity_pads_init() where its pointer will be stored in the
  625. * &media_entity structure.
  626. *
  627. * If no pads are needed, drivers could either directly fill
  628. * &media_entity->num_pads with 0 and &media_entity->pads with %NULL or call
  629. * this function that will do the same.
  630. *
  631. * As the number of pads is known in advance, the pads array is not allocated
  632. * dynamically but is managed by the entity driver. Most drivers will embed the
  633. * pads array in a driver-specific structure, avoiding dynamic allocation.
  634. *
  635. * Drivers must set the direction of every pad in the pads array before calling
  636. * media_entity_pads_init(). The function will initialize the other pads fields.
  637. */
  638. int media_entity_pads_init(struct media_entity *entity, u16 num_pads,
  639. struct media_pad *pads);
  640. /**
  641. * media_entity_cleanup() - free resources associated with an entity
  642. *
  643. * @entity: entity where the pads belong
  644. *
  645. * This function must be called during the cleanup phase after unregistering
  646. * the entity (currently, it does nothing).
  647. *
  648. * Calling media_entity_cleanup() on a media_entity whose memory has been
  649. * zeroed but that has not been initialized with media_entity_pad_init() is
  650. * valid and is a no-op.
  651. */
  652. #if IS_ENABLED(CONFIG_MEDIA_CONTROLLER)
  653. static inline void media_entity_cleanup(struct media_entity *entity) {}
  654. #else
  655. #define media_entity_cleanup(entity) do { } while (false)
  656. #endif
  657. /**
  658. * media_get_pad_index() - retrieves a pad index from an entity
  659. *
  660. * @entity: entity where the pads belong
  661. * @is_sink: true if the pad is a sink, false if it is a source
  662. * @sig_type: type of signal of the pad to be search
  663. *
  664. * This helper function finds the first pad index inside an entity that
  665. * satisfies both @is_sink and @sig_type conditions.
  666. *
  667. * Return:
  668. *
  669. * On success, return the pad number. If the pad was not found or the media
  670. * entity is a NULL pointer, return -EINVAL.
  671. */
  672. int media_get_pad_index(struct media_entity *entity, bool is_sink,
  673. enum media_pad_signal_type sig_type);
  674. /**
  675. * media_create_pad_link() - creates a link between two entities.
  676. *
  677. * @source: pointer to &media_entity of the source pad.
  678. * @source_pad: number of the source pad in the pads array
  679. * @sink: pointer to &media_entity of the sink pad.
  680. * @sink_pad: number of the sink pad in the pads array.
  681. * @flags: Link flags, as defined in
  682. * :ref:`include/uapi/linux/media.h <media_header>`
  683. * ( seek for ``MEDIA_LNK_FL_*``)
  684. *
  685. * Valid values for flags:
  686. *
  687. * %MEDIA_LNK_FL_ENABLED
  688. * Indicates that the link is enabled and can be used to transfer media data.
  689. * When two or more links target a sink pad, only one of them can be
  690. * enabled at a time.
  691. *
  692. * %MEDIA_LNK_FL_IMMUTABLE
  693. * Indicates that the link enabled state can't be modified at runtime. If
  694. * %MEDIA_LNK_FL_IMMUTABLE is set, then %MEDIA_LNK_FL_ENABLED must also be
  695. * set, since an immutable link is always enabled.
  696. *
  697. * .. note::
  698. *
  699. * Before calling this function, media_entity_pads_init() and
  700. * media_device_register_entity() should be called previously for both ends.
  701. */
  702. __must_check int media_create_pad_link(struct media_entity *source,
  703. u16 source_pad, struct media_entity *sink,
  704. u16 sink_pad, u32 flags);
  705. /**
  706. * media_create_pad_links() - creates a link between two entities.
  707. *
  708. * @mdev: Pointer to the media_device that contains the object
  709. * @source_function: Function of the source entities. Used only if @source is
  710. * NULL.
  711. * @source: pointer to &media_entity of the source pad. If NULL, it will use
  712. * all entities that matches the @sink_function.
  713. * @source_pad: number of the source pad in the pads array
  714. * @sink_function: Function of the sink entities. Used only if @sink is NULL.
  715. * @sink: pointer to &media_entity of the sink pad. If NULL, it will use
  716. * all entities that matches the @sink_function.
  717. * @sink_pad: number of the sink pad in the pads array.
  718. * @flags: Link flags, as defined in include/uapi/linux/media.h.
  719. * @allow_both_undefined: if %true, then both @source and @sink can be NULL.
  720. * In such case, it will create a crossbar between all entities that
  721. * matches @source_function to all entities that matches @sink_function.
  722. * If %false, it will return 0 and won't create any link if both @source
  723. * and @sink are NULL.
  724. *
  725. * Valid values for flags:
  726. *
  727. * A %MEDIA_LNK_FL_ENABLED flag indicates that the link is enabled and can be
  728. * used to transfer media data. If multiple links are created and this
  729. * flag is passed as an argument, only the first created link will have
  730. * this flag.
  731. *
  732. * A %MEDIA_LNK_FL_IMMUTABLE flag indicates that the link enabled state can't
  733. * be modified at runtime. If %MEDIA_LNK_FL_IMMUTABLE is set, then
  734. * %MEDIA_LNK_FL_ENABLED must also be set since an immutable link is
  735. * always enabled.
  736. *
  737. * It is common for some devices to have multiple source and/or sink entities
  738. * of the same type that should be linked. While media_create_pad_link()
  739. * creates link by link, this function is meant to allow 1:n, n:1 and even
  740. * cross-bar (n:n) links.
  741. *
  742. * .. note::
  743. *
  744. * Before calling this function, media_entity_pads_init() and
  745. * media_device_register_entity() should be called previously for the
  746. * entities to be linked.
  747. */
  748. int media_create_pad_links(const struct media_device *mdev,
  749. const u32 source_function,
  750. struct media_entity *source,
  751. const u16 source_pad,
  752. const u32 sink_function,
  753. struct media_entity *sink,
  754. const u16 sink_pad,
  755. u32 flags,
  756. const bool allow_both_undefined);
  757. void __media_entity_remove_links(struct media_entity *entity);
  758. /**
  759. * media_entity_remove_links() - remove all links associated with an entity
  760. *
  761. * @entity: pointer to &media_entity
  762. *
  763. * .. note::
  764. *
  765. * This is called automatically when an entity is unregistered via
  766. * media_device_register_entity().
  767. */
  768. void media_entity_remove_links(struct media_entity *entity);
  769. /**
  770. * __media_entity_setup_link - Configure a media link without locking
  771. * @link: The link being configured
  772. * @flags: Link configuration flags
  773. *
  774. * The bulk of link setup is handled by the two entities connected through the
  775. * link. This function notifies both entities of the link configuration change.
  776. *
  777. * If the link is immutable or if the current and new configuration are
  778. * identical, return immediately.
  779. *
  780. * The user is expected to hold link->source->parent->mutex. If not,
  781. * media_entity_setup_link() should be used instead.
  782. */
  783. int __media_entity_setup_link(struct media_link *link, u32 flags);
  784. /**
  785. * media_entity_setup_link() - changes the link flags properties in runtime
  786. *
  787. * @link: pointer to &media_link
  788. * @flags: the requested new link flags
  789. *
  790. * The only configurable property is the %MEDIA_LNK_FL_ENABLED link flag
  791. * to enable/disable a link. Links marked with the
  792. * %MEDIA_LNK_FL_IMMUTABLE link flag can not be enabled or disabled.
  793. *
  794. * When a link is enabled or disabled, the media framework calls the
  795. * link_setup operation for the two entities at the source and sink of the
  796. * link, in that order. If the second link_setup call fails, another
  797. * link_setup call is made on the first entity to restore the original link
  798. * flags.
  799. *
  800. * Media device drivers can be notified of link setup operations by setting the
  801. * &media_device.link_notify pointer to a callback function. If provided, the
  802. * notification callback will be called before enabling and after disabling
  803. * links.
  804. *
  805. * Entity drivers must implement the link_setup operation if any of their links
  806. * is non-immutable. The operation must either configure the hardware or store
  807. * the configuration information to be applied later.
  808. *
  809. * Link configuration must not have any side effect on other links. If an
  810. * enabled link at a sink pad prevents another link at the same pad from
  811. * being enabled, the link_setup operation must return %-EBUSY and can't
  812. * implicitly disable the first enabled link.
  813. *
  814. * .. note::
  815. *
  816. * The valid values of the flags for the link is the same as described
  817. * on media_create_pad_link(), for pad to pad links or the same as described
  818. * on media_create_intf_link(), for interface to entity links.
  819. */
  820. int media_entity_setup_link(struct media_link *link, u32 flags);
  821. /**
  822. * media_entity_find_link - Find a link between two pads
  823. * @source: Source pad
  824. * @sink: Sink pad
  825. *
  826. * Return: returns a pointer to the link between the two entities. If no
  827. * such link exists, return %NULL.
  828. */
  829. struct media_link *media_entity_find_link(struct media_pad *source,
  830. struct media_pad *sink);
  831. /**
  832. * media_pad_remote_pad_first - Find the first pad at the remote end of a link
  833. * @pad: Pad at the local end of the link
  834. *
  835. * Search for a remote pad connected to the given pad by iterating over all
  836. * links originating or terminating at that pad until an enabled link is found.
  837. *
  838. * Return: returns a pointer to the pad at the remote end of the first found
  839. * enabled link, or %NULL if no enabled link has been found.
  840. */
  841. struct media_pad *media_pad_remote_pad_first(const struct media_pad *pad);
  842. /**
  843. * media_pad_remote_pad_unique - Find a remote pad connected to a pad
  844. * @pad: The pad
  845. *
  846. * Search for and return a remote pad connected to @pad through an enabled
  847. * link. If multiple (or no) remote pads are found, an error is returned.
  848. *
  849. * The uniqueness constraint makes this helper function suitable for entities
  850. * that support a single active source at a time on a given pad.
  851. *
  852. * Return: A pointer to the remote pad, or one of the following error pointers
  853. * if an error occurs:
  854. *
  855. * * -ENOTUNIQ - Multiple links are enabled
  856. * * -ENOLINK - No connected pad found
  857. */
  858. struct media_pad *media_pad_remote_pad_unique(const struct media_pad *pad);
  859. /**
  860. * media_entity_remote_pad_unique - Find a remote pad connected to an entity
  861. * @entity: The entity
  862. * @type: The type of pad to find (MEDIA_PAD_FL_SINK or MEDIA_PAD_FL_SOURCE)
  863. *
  864. * Search for and return a remote pad of @type connected to @entity through an
  865. * enabled link. If multiple (or no) remote pads match these criteria, an error
  866. * is returned.
  867. *
  868. * The uniqueness constraint makes this helper function suitable for entities
  869. * that support a single active source or sink at a time.
  870. *
  871. * Return: A pointer to the remote pad, or one of the following error pointers
  872. * if an error occurs:
  873. *
  874. * * -ENOTUNIQ - Multiple links are enabled
  875. * * -ENOLINK - No connected pad found
  876. */
  877. struct media_pad *
  878. media_entity_remote_pad_unique(const struct media_entity *entity,
  879. unsigned int type);
  880. /**
  881. * media_entity_remote_source_pad_unique - Find a remote source pad connected to
  882. * an entity
  883. * @entity: The entity
  884. *
  885. * Search for and return a remote source pad connected to @entity through an
  886. * enabled link. If multiple (or no) remote pads match these criteria, an error
  887. * is returned.
  888. *
  889. * The uniqueness constraint makes this helper function suitable for entities
  890. * that support a single active source at a time.
  891. *
  892. * Return: A pointer to the remote pad, or one of the following error pointers
  893. * if an error occurs:
  894. *
  895. * * -ENOTUNIQ - Multiple links are enabled
  896. * * -ENOLINK - No connected pad found
  897. */
  898. static inline struct media_pad *
  899. media_entity_remote_source_pad_unique(const struct media_entity *entity)
  900. {
  901. return media_entity_remote_pad_unique(entity, MEDIA_PAD_FL_SOURCE);
  902. }
  903. /**
  904. * media_pad_is_streaming - Test if a pad is part of a streaming pipeline
  905. * @pad: The pad
  906. *
  907. * Return: True if the pad is part of a pipeline started with the
  908. * media_pipeline_start() function, false otherwise.
  909. */
  910. static inline bool media_pad_is_streaming(const struct media_pad *pad)
  911. {
  912. return pad->pipe;
  913. }
  914. /**
  915. * media_entity_is_streaming - Test if an entity is part of a streaming pipeline
  916. * @entity: The entity
  917. *
  918. * Return: True if the entity is part of a pipeline started with the
  919. * media_pipeline_start() function, false otherwise.
  920. */
  921. static inline bool media_entity_is_streaming(const struct media_entity *entity)
  922. {
  923. struct media_pad *pad;
  924. media_entity_for_each_pad(entity, pad) {
  925. if (media_pad_is_streaming(pad))
  926. return true;
  927. }
  928. return false;
  929. }
  930. /**
  931. * media_entity_pipeline - Get the media pipeline an entity is part of
  932. * @entity: The entity
  933. *
  934. * DEPRECATED: use media_pad_pipeline() instead.
  935. *
  936. * This function returns the media pipeline that an entity has been associated
  937. * with when constructing the pipeline with media_pipeline_start(). The pointer
  938. * remains valid until media_pipeline_stop() is called.
  939. *
  940. * In general, entities can be part of multiple pipelines, when carrying
  941. * multiple streams (either on different pads, or on the same pad using
  942. * multiplexed streams). This function is to be used only for entities that
  943. * do not support multiple pipelines.
  944. *
  945. * Return: The media_pipeline the entity is part of, or NULL if the entity is
  946. * not part of any pipeline.
  947. */
  948. struct media_pipeline *media_entity_pipeline(struct media_entity *entity);
  949. /**
  950. * media_pad_pipeline - Get the media pipeline a pad is part of
  951. * @pad: The pad
  952. *
  953. * This function returns the media pipeline that a pad has been associated
  954. * with when constructing the pipeline with media_pipeline_start(). The pointer
  955. * remains valid until media_pipeline_stop() is called.
  956. *
  957. * Return: The media_pipeline the pad is part of, or NULL if the pad is
  958. * not part of any pipeline.
  959. */
  960. struct media_pipeline *media_pad_pipeline(struct media_pad *pad);
  961. /**
  962. * media_entity_get_fwnode_pad - Get pad number from fwnode
  963. *
  964. * @entity: The entity
  965. * @fwnode: Pointer to the fwnode_handle which should be used to find the pad
  966. * @direction_flags: Expected direction of the pad, as defined in
  967. * :ref:`include/uapi/linux/media.h <media_header>`
  968. * (seek for ``MEDIA_PAD_FL_*``)
  969. *
  970. * This function can be used to resolve the media pad number from
  971. * a fwnode. This is useful for devices which use more complex
  972. * mappings of media pads.
  973. *
  974. * If the entity does not implement the get_fwnode_pad() operation
  975. * then this function searches the entity for the first pad that
  976. * matches the @direction_flags.
  977. *
  978. * Return: returns the pad number on success or a negative error code.
  979. */
  980. int media_entity_get_fwnode_pad(struct media_entity *entity,
  981. struct fwnode_handle *fwnode,
  982. unsigned long direction_flags);
  983. /**
  984. * media_graph_walk_init - Allocate resources used by graph walk.
  985. *
  986. * @graph: Media graph structure that will be used to walk the graph
  987. * @mdev: Pointer to the &media_device that contains the object
  988. *
  989. * The caller is required to hold the media_device graph_mutex during the graph
  990. * walk until the graph state is released.
  991. *
  992. * Returns zero on success or a negative error code otherwise.
  993. */
  994. __must_check int media_graph_walk_init(
  995. struct media_graph *graph, struct media_device *mdev);
  996. /**
  997. * media_graph_walk_cleanup - Release resources used by graph walk.
  998. *
  999. * @graph: Media graph structure that will be used to walk the graph
  1000. */
  1001. void media_graph_walk_cleanup(struct media_graph *graph);
  1002. /**
  1003. * media_graph_walk_start - Start walking the media graph at a
  1004. * given entity
  1005. *
  1006. * @graph: Media graph structure that will be used to walk the graph
  1007. * @entity: Starting entity
  1008. *
  1009. * Before using this function, media_graph_walk_init() must be
  1010. * used to allocate resources used for walking the graph. This
  1011. * function initializes the graph traversal structure to walk the
  1012. * entities graph starting at the given entity. The traversal
  1013. * structure must not be modified by the caller during graph
  1014. * traversal. After the graph walk, the resources must be released
  1015. * using media_graph_walk_cleanup().
  1016. */
  1017. void media_graph_walk_start(struct media_graph *graph,
  1018. struct media_entity *entity);
  1019. /**
  1020. * media_graph_walk_next - Get the next entity in the graph
  1021. * @graph: Media graph structure
  1022. *
  1023. * Perform a depth-first traversal of the given media entities graph.
  1024. *
  1025. * The graph structure must have been previously initialized with a call to
  1026. * media_graph_walk_start().
  1027. *
  1028. * Return: returns the next entity in the graph or %NULL if the whole graph
  1029. * have been traversed.
  1030. */
  1031. struct media_entity *media_graph_walk_next(struct media_graph *graph);
  1032. /**
  1033. * media_pipeline_start - Mark a pipeline as streaming
  1034. * @pad: Starting pad
  1035. * @pipe: Media pipeline to be assigned to all pads in the pipeline.
  1036. *
  1037. * Mark all pads connected to a given pad through enabled links, either
  1038. * directly or indirectly, as streaming. The given pipeline object is assigned
  1039. * to every pad in the pipeline and stored in the media_pad pipe field.
  1040. *
  1041. * Calls to this function can be nested, in which case the same number of
  1042. * media_pipeline_stop() calls will be required to stop streaming. The
  1043. * pipeline pointer must be identical for all nested calls to
  1044. * media_pipeline_start().
  1045. */
  1046. __must_check int media_pipeline_start(struct media_pad *pad,
  1047. struct media_pipeline *pipe);
  1048. /**
  1049. * __media_pipeline_start - Mark a pipeline as streaming
  1050. *
  1051. * @pad: Starting pad
  1052. * @pipe: Media pipeline to be assigned to all pads in the pipeline.
  1053. *
  1054. * ..note:: This is the non-locking version of media_pipeline_start()
  1055. */
  1056. __must_check int __media_pipeline_start(struct media_pad *pad,
  1057. struct media_pipeline *pipe);
  1058. /**
  1059. * media_pipeline_stop - Mark a pipeline as not streaming
  1060. * @pad: Starting pad
  1061. *
  1062. * Mark all pads connected to a given pads through enabled links, either
  1063. * directly or indirectly, as not streaming. The media_pad pipe field is
  1064. * reset to %NULL.
  1065. *
  1066. * If multiple calls to media_pipeline_start() have been made, the same
  1067. * number of calls to this function are required to mark the pipeline as not
  1068. * streaming.
  1069. */
  1070. void media_pipeline_stop(struct media_pad *pad);
  1071. /**
  1072. * __media_pipeline_stop - Mark a pipeline as not streaming
  1073. *
  1074. * @pad: Starting pad
  1075. *
  1076. * .. note:: This is the non-locking version of media_pipeline_stop()
  1077. */
  1078. void __media_pipeline_stop(struct media_pad *pad);
  1079. /**
  1080. * media_pipeline_alloc_start - Mark a pipeline as streaming
  1081. * @pad: Starting pad
  1082. *
  1083. * media_pipeline_alloc_start() is similar to media_pipeline_start() but instead
  1084. * of working on a given pipeline the function will use an existing pipeline if
  1085. * the pad is already part of a pipeline, or allocate a new pipeline.
  1086. *
  1087. * Calls to media_pipeline_alloc_start() must be matched with
  1088. * media_pipeline_stop().
  1089. */
  1090. __must_check int media_pipeline_alloc_start(struct media_pad *pad);
  1091. /**
  1092. * media_devnode_create() - creates and initializes a device node interface
  1093. *
  1094. * @mdev: pointer to struct &media_device
  1095. * @type: type of the interface, as given by
  1096. * :ref:`include/uapi/linux/media.h <media_header>`
  1097. * ( seek for ``MEDIA_INTF_T_*``) macros.
  1098. * @flags: Interface flags, as defined in
  1099. * :ref:`include/uapi/linux/media.h <media_header>`
  1100. * ( seek for ``MEDIA_INTF_FL_*``)
  1101. * @major: Device node major number.
  1102. * @minor: Device node minor number.
  1103. *
  1104. * Return: if succeeded, returns a pointer to the newly allocated
  1105. * &media_intf_devnode pointer.
  1106. *
  1107. * .. note::
  1108. *
  1109. * Currently, no flags for &media_interface is defined.
  1110. */
  1111. struct media_intf_devnode *
  1112. __must_check media_devnode_create(struct media_device *mdev,
  1113. u32 type, u32 flags,
  1114. u32 major, u32 minor);
  1115. /**
  1116. * media_devnode_remove() - removes a device node interface
  1117. *
  1118. * @devnode: pointer to &media_intf_devnode to be freed.
  1119. *
  1120. * When a device node interface is removed, all links to it are automatically
  1121. * removed.
  1122. */
  1123. void media_devnode_remove(struct media_intf_devnode *devnode);
  1124. /**
  1125. * media_create_intf_link() - creates a link between an entity and an interface
  1126. *
  1127. * @entity: pointer to %media_entity
  1128. * @intf: pointer to %media_interface
  1129. * @flags: Link flags, as defined in
  1130. * :ref:`include/uapi/linux/media.h <media_header>`
  1131. * ( seek for ``MEDIA_LNK_FL_*``)
  1132. *
  1133. *
  1134. * Valid values for flags:
  1135. *
  1136. * %MEDIA_LNK_FL_ENABLED
  1137. * Indicates that the interface is connected to the entity hardware.
  1138. * That's the default value for interfaces. An interface may be disabled if
  1139. * the hardware is busy due to the usage of some other interface that it is
  1140. * currently controlling the hardware.
  1141. *
  1142. * A typical example is an hybrid TV device that handle only one type of
  1143. * stream on a given time. So, when the digital TV is streaming,
  1144. * the V4L2 interfaces won't be enabled, as such device is not able to
  1145. * also stream analog TV or radio.
  1146. *
  1147. * .. note::
  1148. *
  1149. * Before calling this function, media_devnode_create() should be called for
  1150. * the interface and media_device_register_entity() should be called for the
  1151. * interface that will be part of the link.
  1152. */
  1153. struct media_link *
  1154. __must_check media_create_intf_link(struct media_entity *entity,
  1155. struct media_interface *intf,
  1156. u32 flags);
  1157. /**
  1158. * __media_remove_intf_link() - remove a single interface link
  1159. *
  1160. * @link: pointer to &media_link.
  1161. *
  1162. * .. note:: This is an unlocked version of media_remove_intf_link()
  1163. */
  1164. void __media_remove_intf_link(struct media_link *link);
  1165. /**
  1166. * media_remove_intf_link() - remove a single interface link
  1167. *
  1168. * @link: pointer to &media_link.
  1169. *
  1170. * .. note:: Prefer to use this one, instead of __media_remove_intf_link()
  1171. */
  1172. void media_remove_intf_link(struct media_link *link);
  1173. /**
  1174. * __media_remove_intf_links() - remove all links associated with an interface
  1175. *
  1176. * @intf: pointer to &media_interface
  1177. *
  1178. * .. note:: This is an unlocked version of media_remove_intf_links().
  1179. */
  1180. void __media_remove_intf_links(struct media_interface *intf);
  1181. /**
  1182. * media_remove_intf_links() - remove all links associated with an interface
  1183. *
  1184. * @intf: pointer to &media_interface
  1185. *
  1186. * .. note::
  1187. *
  1188. * #) This is called automatically when an entity is unregistered via
  1189. * media_device_register_entity() and by media_devnode_remove().
  1190. *
  1191. * #) Prefer to use this one, instead of __media_remove_intf_links().
  1192. */
  1193. void media_remove_intf_links(struct media_interface *intf);
  1194. /**
  1195. * media_entity_call - Calls a struct media_entity_operations operation on
  1196. * an entity
  1197. *
  1198. * @entity: entity where the @operation will be called
  1199. * @operation: type of the operation. Should be the name of a member of
  1200. * struct &media_entity_operations.
  1201. *
  1202. * This helper function will check if @operation is not %NULL. On such case,
  1203. * it will issue a call to @operation\(@entity, @args\).
  1204. */
  1205. #define media_entity_call(entity, operation, args...) \
  1206. (((entity)->ops && (entity)->ops->operation) ? \
  1207. (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD)
  1208. /**
  1209. * media_create_ancillary_link() - create an ancillary link between two
  1210. * instances of &media_entity
  1211. *
  1212. * @primary: pointer to the primary &media_entity
  1213. * @ancillary: pointer to the ancillary &media_entity
  1214. *
  1215. * Create an ancillary link between two entities, indicating that they
  1216. * represent two connected pieces of hardware that form a single logical unit.
  1217. * A typical example is a camera lens controller being linked to the sensor that
  1218. * it is supporting.
  1219. *
  1220. * The function sets both MEDIA_LNK_FL_ENABLED and MEDIA_LNK_FL_IMMUTABLE for
  1221. * the new link.
  1222. */
  1223. struct media_link *
  1224. media_create_ancillary_link(struct media_entity *primary,
  1225. struct media_entity *ancillary);
  1226. /**
  1227. * __media_entity_next_link() - Iterate through a &media_entity's links
  1228. *
  1229. * @entity: pointer to the &media_entity
  1230. * @link: pointer to a &media_link to hold the iterated values
  1231. * @link_type: one of the MEDIA_LNK_FL_LINK_TYPE flags
  1232. *
  1233. * Return the next link against an entity matching a specific link type. This
  1234. * allows iteration through an entity's links whilst guaranteeing all of the
  1235. * returned links are of the given type.
  1236. */
  1237. struct media_link *__media_entity_next_link(struct media_entity *entity,
  1238. struct media_link *link,
  1239. unsigned long link_type);
  1240. /**
  1241. * for_each_media_entity_data_link() - Iterate through an entity's data links
  1242. *
  1243. * @entity: pointer to the &media_entity
  1244. * @link: pointer to a &media_link to hold the iterated values
  1245. *
  1246. * Iterate over a &media_entity's data links
  1247. */
  1248. #define for_each_media_entity_data_link(entity, link) \
  1249. for (link = __media_entity_next_link(entity, NULL, \
  1250. MEDIA_LNK_FL_DATA_LINK); \
  1251. link; \
  1252. link = __media_entity_next_link(entity, link, \
  1253. MEDIA_LNK_FL_DATA_LINK))
  1254. #endif