[PATCH RFC v2 10/16] media: media.h: Add entity connection status

From: Mattijs Korpershoek

Date: Wed Nov 18 2026 - 07:44:39 EST


Some elements in the media graph (such as camera sensors) can be
physically disconnected/reconnected. Drivers may still probe in that
case to have a complete media graph.

Add a new entity field, named status, which reflects the connection
status of that particular entity.

This field is retrieved by userspace via the MEDIA_IOC_G_TOPOLOGY and
can be updated from drivers via media_entity_set_status().

When a status is not initialized, it's set to zero (STATUS_CONNECTED).
This matches older media graphs were all entities are always connected.

Signed-off-by: Mattijs Korpershoek <mkorpershoek@xxxxxxxxxx>
---
drivers/media/mc/mc-device.c | 1 +
drivers/media/mc/mc-entity.c | 29 +++++++++++++++++++++++++++++
include/media/media-entity.h | 20 ++++++++++++++++++++
include/uapi/linux/media.h | 6 +++++-
4 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/drivers/media/mc/mc-device.c b/drivers/media/mc/mc-device.c
index 82f5676afbc0..71cdf079c8a8 100644
--- a/drivers/media/mc/mc-device.c
+++ b/drivers/media/mc/mc-device.c
@@ -307,6 +307,7 @@ static long media_device_get_topology(struct media_device *mdev,
kentity.id = entity->graph_obj.id;
kentity.function = entity->function;
kentity.flags = entity->flags;
+ kentity.status = entity->status;
strscpy(kentity.name, entity->name,
sizeof(kentity.name));

diff --git a/drivers/media/mc/mc-entity.c b/drivers/media/mc/mc-entity.c
index 7938f785e2e3..c152d3a61d51 100644
--- a/drivers/media/mc/mc-entity.c
+++ b/drivers/media/mc/mc-entity.c
@@ -1530,6 +1530,35 @@ struct media_pipeline *media_entity_pipeline(struct media_entity *entity)
}
EXPORT_SYMBOL_GPL(media_entity_pipeline);

+void __media_entity_set_status(struct media_entity *entity, u32 status)
+{
+ struct media_device *mdev = entity->graph_obj.mdev;
+
+ /* Do nothing if the entity is not registered. */
+ if (mdev == NULL)
+ return;
+
+ lockdep_assert_held(&mdev->graph_mutex);
+
+ if (entity->status != status)
+ entity->status = status;
+}
+EXPORT_SYMBOL_GPL(__media_entity_set_status);
+
+void media_entity_set_status(struct media_entity *entity, u32 status)
+{
+ struct media_device *mdev = entity->graph_obj.mdev;
+
+ /* Do nothing if the entity is not registered. */
+ if (mdev == NULL)
+ return;
+
+ mutex_lock(&mdev->graph_mutex);
+ __media_entity_set_status(entity, status);
+ mutex_unlock(&mdev->graph_mutex);
+}
+EXPORT_SYMBOL_GPL(media_entity_set_status);
+
struct media_pipeline *media_pad_pipeline(struct media_pad *pad)
{
return pad->pipe;
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index fa393e840669..1ec62793fc76 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -325,6 +325,10 @@ enum media_entity_type {
* @flags: Entity flags, as defined in
* :ref:`include/uapi/linux/media.h <media_header>`
* (seek for ``MEDIA_ENT_FL_*``)
+ * @status: Entity connection status, as defined in
+ * :ref:`include/uapi/linux/media.h <media_header>`
+ * (seek for ``MEDIA_ENT_STATUS_*``).
+ * Access with media_entity_set_status()
* @num_pads: Number of sink and source pads.
* @num_links: Total number of links, forward and back, enabled and disabled.
* @num_backlinks: Number of backlinks
@@ -352,6 +356,7 @@ struct media_entity {
enum media_entity_type obj_type;
u32 function;
unsigned long flags;
+ u32 status;

u16 num_pads;
u16 num_links;
@@ -1022,6 +1027,21 @@ static inline bool media_entity_is_streaming(const struct media_entity *entity)
return false;
}

+void __media_entity_set_status(struct media_entity *entity, u32 status);
+
+/**
+ * media_entity_set_status - Set the connection status of an entity
+ * @entity: The entity
+ * @status: The new status (%MEDIA_ENT_STATUS_CONNECTED or
+ * %MEDIA_ENT_STATUS_DISCONNECTED)
+ *
+ * Update the entity's connection status.
+ *
+ * The entity must be registered with a media device. To set the initial
+ * status before registration, assign entity->status directly.
+ */
+void media_entity_set_status(struct media_entity *entity, u32 status);
+
/**
* media_entity_pipeline - Get the media pipeline an entity is part of
* @entity: The entity
diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index b5275acad87f..ab1dea809879 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -302,12 +302,16 @@ struct media_links_enum {
#define MEDIA_V2_ENTITY_HAS_FLAGS(media_version) \
((media_version) >= ((4U << 16) | (19U << 8) | 0U))

+#define MEDIA_ENT_STATUS_CONNECTED 0
+#define MEDIA_ENT_STATUS_DISCONNECTED 1
+
struct media_v2_entity {
__u32 id;
char name[64];
__u32 function; /* Main function of the entity */
__u32 flags;
- __u32 reserved[5];
+ __u32 status;
+ __u32 reserved[4];
} __attribute__ ((packed));

/* Should match the specific fields at media_intf_devnode */

--
2.56.0