From: Mattijs Korpershoek <mkorpershoek@kernel.org>
To: Hans Verkuil <hverkuil+cisco@kernel.org>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Kieran Bingham <kieran.bingham@ideasonboard.com>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Andy Walls <awalls@md.metrocast.net>,
Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Mattijs Korpershoek <mkorpershoek@kernel.org>,
Nicolas Dufresne <nicolas.dufres@collabora.com>,
Hans de Goede <hansg@kernel.org>,
Michael Riesch <michael.riesch@collabora.com>,
Dave Stevenson <dave.stevenson@raspberrypi.com>,
Maxime Ripard <mripard@kernel.org>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org
Subject: [PATCH RFC v2 12/16] media: mc: Add MEDIA_IOC_G_ENTITY_STATUS ioctl
Date: Wed, 18 Nov 2026 13:43:56 +0100 [thread overview]
Message-ID: <20261118-v4l2-sensor-detect-v2-12-1bb1a445b556@kernel.org> (raw)
In-Reply-To: <20261118-v4l2-sensor-detect-v2-0-1bb1a445b556@kernel.org>
Userspace can get an entity's connection status using 'media-ctl -p'.
This calls MEDIA_IOC_G_TOPOLOGY which will also provide the entity
status.
However, that status is from the cache. When fault tolerance is enabled,
the status can be only be updated in 2 ways:
1. During driver probe
2. When a stream is started
Add MEDIA_IOC_G_ENTITY_STATUS which allows userspace to get the hardware
state at any given time.
This can be useful for diagnostics, for example.
Calling MEDIA_IOC_G_ENTITY_STATUS will also update the topology's cached
value.
Signed-off-by: Mattijs Korpershoek <mkorpershoek@kernel.org>
---
.../userspace-api/media/mediactl/media-funcs.rst | 1 +
.../media/mediactl/media-ioc-g-entity-status.rst | 92 ++++++++++++++++++++++
drivers/media/mc/mc-device.c | 23 ++++++
include/uapi/linux/media.h | 7 ++
4 files changed, 123 insertions(+)
diff --git a/Documentation/userspace-api/media/mediactl/media-funcs.rst b/Documentation/userspace-api/media/mediactl/media-funcs.rst
index a9ce38b7144f..54150179227c 100644
--- a/Documentation/userspace-api/media/mediactl/media-funcs.rst
+++ b/Documentation/userspace-api/media/mediactl/media-funcs.rst
@@ -21,6 +21,7 @@ Function Reference
media-ioc-request-alloc
media-ioc-subscribe-event
media-ioc-dqevent
+ media-ioc-g-entity-status
request-func-close
request-func-ioctl
request-func-poll
diff --git a/Documentation/userspace-api/media/mediactl/media-ioc-g-entity-status.rst b/Documentation/userspace-api/media/mediactl/media-ioc-g-entity-status.rst
new file mode 100644
index 000000000000..ee108428c0bb
--- /dev/null
+++ b/Documentation/userspace-api/media/mediactl/media-ioc-g-entity-status.rst
@@ -0,0 +1,92 @@
+.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
+.. c:namespace:: MC
+
+.. _media_ioc_g_entity_status:
+
+*********************************
+ioctl MEDIA_IOC_G_ENTITY_STATUS
+*********************************
+
+Name
+====
+
+MEDIA_IOC_G_ENTITY_STATUS - Get the connection status of an entity
+
+Synopsis
+========
+
+.. c:macro:: MEDIA_IOC_G_ENTITY_STATUS
+
+``int ioctl(int fd, MEDIA_IOC_G_ENTITY_STATUS, struct media_entity_status *argp)``
+
+Arguments
+=========
+
+``fd``
+ File descriptor returned by :c:func:`open()`.
+
+``argp``
+ Pointer to struct :c:type:`media_entity_status`.
+
+Description
+===========
+
+To query the connection status of a given entity, applications set the
+``id`` field of a struct :c:type:`media_entity_status` and call the ioctl.
+The driver fills the rest of the structure or returns an
+EINVAL error code when the ``id`` is invalid.
+
+If the entity does not implement detection, the driver sets
+the ``status`` field to ``MEDIA_ENT_STATUS_CONNECTED``.
+
+If the entity supports detection, the driver reads the hardware state at call time
+and sets the ``status`` field accordingly.
+
+.. c:type:: media_entity_status
+
+.. tabularcolumns:: |p{1.5cm}|p{3.0cm}|p{12.0cm}|
+
+.. flat-table:: struct media_entity_status
+ :header-rows: 0
+ :stub-columns: 0
+ :widths: 1 2 8
+
+ * - __u32
+ - ``id``
+ - Entity ID, set by the application.
+
+ * - __u32
+ - ``status``
+ - Entity connection status, see :ref:`media-entity-status`.
+
+ * - __u32
+ - ``reserved``\ [6]
+ - Reserved for future extensions. Drivers and applications must set
+ the array to zero.
+
+.. tabularcolumns:: |p{5.5cm}|p{1.0cm}|p{10.0cm}|
+
+.. _media-entity-status:
+
+.. flat-table:: Entity Status
+ :header-rows: 0
+ :stub-columns: 0
+ :widths: 3 1 4
+
+ * - ``MEDIA_ENT_STATUS_CONNECTED``
+ - 0
+ - The entity hardware is connected and reachable.
+
+ * - ``MEDIA_ENT_STATUS_DISCONNECTED``
+ - 1
+ - The entity hardware is not connected or not reachable.
+
+Return Value
+============
+
+On success 0 is returned, on error -1 and the ``errno`` variable is set
+appropriately. The generic error codes are described at the
+:ref:`Generic Error Codes <gen-errors>` chapter.
+
+EINVAL
+ The ``id`` references a non-existing entity.
diff --git a/drivers/media/mc/mc-device.c b/drivers/media/mc/mc-device.c
index 9151a47887a7..6f5b2daa1177 100644
--- a/drivers/media/mc/mc-device.c
+++ b/drivers/media/mc/mc-device.c
@@ -501,6 +501,28 @@ struct media_ioctl_info {
long (*arg_to_user)(void __user *uarg, void *karg, unsigned int cmd);
};
+static long media_device_get_entity_status(struct media_device *mdev,
+ struct file *file, void *arg)
+{
+ struct media_entity_status *estatus = arg;
+ struct media_entity *entity;
+ int ret;
+
+ entity = find_entity(mdev, estatus->id);
+ if (!entity)
+ return -EINVAL;
+
+ ret = media_entity_call(entity, detect);
+ if (ret >= 0)
+ __media_entity_set_status(entity, ret);
+
+ memset(estatus->reserved, 0, sizeof(estatus->reserved));
+ estatus->id = media_entity_id(entity);
+ estatus->status = entity->status;
+
+ return 0;
+}
+
static const struct media_ioctl_info ioctl_info[] = {
MEDIA_IOC(DEVICE_INFO, media_device_get_info, MEDIA_IOC_FL_GRAPH_MUTEX),
MEDIA_IOC(ENUM_ENTITIES, media_device_enum_entities, MEDIA_IOC_FL_GRAPH_MUTEX),
@@ -511,6 +533,7 @@ static const struct media_ioctl_info ioctl_info[] = {
MEDIA_IOC(DQEVENT, media_device_event_dequeue, 0),
MEDIA_IOC(SUBSCRIBE_EVENT, media_device_event_subscribe, 0),
MEDIA_IOC(UNSUBSCRIBE_EVENT, media_device_event_unsubscribe, 0),
+ MEDIA_IOC(G_ENTITY_STATUS, media_device_get_entity_status, MEDIA_IOC_FL_GRAPH_MUTEX),
};
static long media_device_ioctl(struct file *filp, unsigned int cmd,
diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index ab1dea809879..9f9ced3fb0e0 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -377,6 +377,12 @@ struct media_v2_topology {
__u64 ptr_links;
} __attribute__ ((packed));
+struct media_entity_status {
+ __u32 id;
+ __u32 status;
+ __u32 reserved[6];
+} __attribute__ ((packed));
+
#define MEDIA_EVENT_ALL 0
#define MEDIA_EVENT_ENTITY_REGISTRATION 1
@@ -416,6 +422,7 @@ struct media_event_subscription {
#define MEDIA_IOC_SUBSCRIBE_EVENT _IOWR ('|', 0x06, struct media_event_subscription)
#define MEDIA_IOC_UNSUBSCRIBE_EVENT _IOWR ('|', 0x07, struct media_event_subscription)
#define MEDIA_IOC_DQEVENT _IOWR('|', 0x08, struct media_event)
+#define MEDIA_IOC_G_ENTITY_STATUS _IOWR('|', 0x09, struct media_entity_status)
/*
* These ioctls are called on the request file descriptor as returned
--
2.56.0
next prev parent reply other threads:[~2026-11-18 12:44 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 12:43 [PATCH RFC v2 00/16] media: Fault-Tolerant V4L2 Mattijs Korpershoek
2026-11-18 12:43 ` [PATCH RFC v2 01/16] media: mc: Add struct media_device_fh pointer to media device IOCTL op Mattijs Korpershoek
2026-11-18 12:43 ` [PATCH RFC v2 02/16] media: mc: Add per-file-handle data support Mattijs Korpershoek
2026-11-18 12:43 ` [PATCH RFC v2 03/16] v4l: event: Separate event related information from struct v4l2_fh Mattijs Korpershoek
2026-11-18 12:43 ` [PATCH RFC v2 04/16] v4l: event: Rework data structures for separating events and V4L2 Mattijs Korpershoek
2026-11-18 12:43 ` [PATCH RFC v2 05/16] v4l: event: Split the event framework into generic and V4L2 bits Mattijs Korpershoek
2026-11-18 12:43 ` [PATCH RFC v2 06/16] media: mc: Maintain a list of open file handles in a media device Mattijs Korpershoek
2026-11-18 12:43 ` [PATCH RFC v2 07/16] media: mc: Add MEDIA_IOC_DQEVENT Mattijs Korpershoek
2026-11-18 12:43 ` [PATCH RFC v2 08/16] media: mc: Add MEDIA_EVENT_ENTITY_REGISTRATION Mattijs Korpershoek
2026-11-18 12:43 ` [PATCH RFC v2 09/16] Documentation: media: Add Media controller event documentation Mattijs Korpershoek
2026-11-18 12:43 ` [PATCH RFC v2 10/16] media: media.h: Add entity connection status Mattijs Korpershoek
2026-11-18 12:43 ` [PATCH RFC v2 11/16] media: mc: Add .detect() to media_entity_operations Mattijs Korpershoek
2026-11-18 12:43 ` Mattijs Korpershoek [this message]
2026-11-18 12:43 ` [PATCH RFC v2 13/16] media: mc: Add MEDIA_EVENT_ENTITY_STATUS_CHANGE event Mattijs Korpershoek
2026-11-18 12:43 ` [PATCH RFC v2 14/16] media: mc: Add detect polling helpers for drivers Mattijs Korpershoek
2026-11-18 12:43 ` [PATCH RFC v2 15/16] media: imx219: Allow driver probe with missing sensor Mattijs Korpershoek
2026-11-18 12:44 ` [PATCH RFC v2 16/16] media: imx219: Implement .detect() sensor operation Mattijs Korpershoek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261118-v4l2-sensor-detect-v2-12-1bb1a445b556@kernel.org \
--to=mkorpershoek@kernel.org \
--cc=awalls@md.metrocast.net \
--cc=dave.stevenson@raspberrypi.com \
--cc=gustavoars@kernel.org \
--cc=hansg@kernel.org \
--cc=hverkuil+cisco@kernel.org \
--cc=kees@kernel.org \
--cc=kieran.bingham@ideasonboard.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=michael.riesch@collabora.com \
--cc=mripard@kernel.org \
--cc=nicolas.dufres@collabora.com \
--cc=sakari.ailus@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®