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