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 11/16] media: mc: Add .detect() to media_entity_operations
Date: Wed, 18 Nov 2026 13:43:55 +0100 [thread overview]
Message-ID: <20261118-v4l2-sensor-detect-v2-11-1bb1a445b556@kernel.org> (raw)
In-Reply-To: <20261118-v4l2-sensor-detect-v2-0-1bb1a445b556@kernel.org>
When mc.fault_tolerance = true, media drivers can probe without the
underlying hardware being physically connected.
In that case, The media controller core needs to be able to retrieve
the driver state in order to update the topology.
Add a new, optional, media_entity_operation named .detect().
To support fault tolerance, drivers must be modified and do the
following when media_fault_tolerance_enabled() = true:
* Probe must succeed even when the underlying hardware is not present
* Probe must set initial entity connections status if disconnected
* The .detect() operation must be implemented
* .enable_streams() must query hardware for presence and must fail when
it's not detected. Can be done using the media_entity_detect_or_fail()
helper.
Note: this is based on the .detect() helpers from DRM connectors.
Signed-off-by: Mattijs Korpershoek <mkorpershoek@kernel.org>
---
drivers/media/mc/mc-device.c | 11 +++++++++++
drivers/media/mc/mc-entity.c | 22 ++++++++++++++++++++++
include/media/media-device.h | 10 ++++++++++
include/media/media-entity.h | 24 ++++++++++++++++++++++++
4 files changed, 67 insertions(+)
diff --git a/drivers/media/mc/mc-device.c b/drivers/media/mc/mc-device.c
index 71cdf079c8a8..9151a47887a7 100644
--- a/drivers/media/mc/mc-device.c
+++ b/drivers/media/mc/mc-device.c
@@ -14,6 +14,7 @@
#include <linux/idr.h>
#include <linux/ioctl.h>
#include <linux/media.h>
+#include <linux/module.h>
#include <linux/slab.h>
#include <linux/types.h>
#include <linux/pci.h>
@@ -27,6 +28,16 @@
#include <media/media-fh.h>
#include <media/media-request.h>
+static bool fault_tolerance;
+module_param(fault_tolerance, bool, 0444);
+MODULE_PARM_DESC(fault_tolerance, "Enable fault-tolerant support");
+
+bool media_fault_tolerance_enabled(void)
+{
+ return fault_tolerance;
+}
+EXPORT_SYMBOL_GPL(media_fault_tolerance_enabled);
+
#ifdef CONFIG_MEDIA_CONTROLLER
/*
diff --git a/drivers/media/mc/mc-entity.c b/drivers/media/mc/mc-entity.c
index c152d3a61d51..2b5fc5d1b0a4 100644
--- a/drivers/media/mc/mc-entity.c
+++ b/drivers/media/mc/mc-entity.c
@@ -1559,6 +1559,28 @@ void media_entity_set_status(struct media_entity *entity, u32 status)
}
EXPORT_SYMBOL_GPL(media_entity_set_status);
+int media_entity_detect_or_fail(struct media_entity *entity)
+{
+ int ret;
+
+ if (!media_fault_tolerance_enabled())
+ return 0;
+
+ ret = media_entity_call(entity, detect);
+ if (ret == -ENOIOCTLCMD)
+ return 0;
+ if (ret < 0)
+ return ret;
+
+ media_entity_set_status(entity, ret);
+
+ if (ret == MEDIA_ENT_STATUS_DISCONNECTED)
+ return -ENOLINK;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(media_entity_detect_or_fail);
+
struct media_pipeline *media_pad_pipeline(struct media_pad *pad)
{
return pad->pipe;
diff --git a/include/media/media-device.h b/include/media/media-device.h
index 3ef277309d59..9a0f38914354 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -204,6 +204,16 @@ struct media_device {
/* We don't need to include usb.h here */
struct usb_device;
+/**
+ * media_fault_tolerance_enabled - Check if media fault tolerance is enabled
+ *
+ * Returns true when the mc.fault_tolerance module parameter is set.
+ * Drivers should call this to decide whether to enable fault-tolerant
+ * behavior (e.g. probing without the underlying hardware being
+ * physically connected).
+ */
+bool media_fault_tolerance_enabled(void);
+
#ifdef CONFIG_MEDIA_CONTROLLER
/* Supported link_notify @notification values. */
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 1ec62793fc76..4d66f9823c9d 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -269,6 +269,12 @@ struct media_pad {
* media_entity_has_pad_interdep().
* Optional: If the operation isn't implemented all pads
* will be considered as interdependent.
+ * @detect: Query whether the entity's hardware is physically
+ * connected and reachable. Must not modify entity state.
+ * Returns a %MEDIA_ENT_STATUS_* value on success, or
+ * a negative error code on failure.
+ * Optional: If the operation isn't implemented the
+ * entity will be considered as connected
*
* .. note::
*
@@ -284,6 +290,7 @@ struct media_entity_operations {
int (*link_validate)(struct media_link *link);
bool (*has_pad_interdep)(struct media_entity *entity, unsigned int pad0,
unsigned int pad1);
+ int (*detect)(struct media_entity *entity);
};
/**
@@ -1042,6 +1049,23 @@ void __media_entity_set_status(struct media_entity *entity, u32 status);
*/
void media_entity_set_status(struct media_entity *entity, u32 status);
+/**
+ * media_entity_detect_or_fail - Detect entity hardware and fail if disconnected
+ * @entity: The entity
+ *
+ * Call the entity's &media_entity_operations.detect() operation to probe
+ * the hardware. If the entity is disconnected, the entity status is updated
+ * and a %MEDIA_EVENT_ENTITY_STATUS_CHANGE event is queued.
+ *
+ * Intended to be called by drivers at the beginning of their
+ * &v4l2_subdev_pad_ops.enable_streams() callback
+ *
+ * Return: 0 if the entity is connected or does not implement .detect(),
+ * -ENOLINK if the entity is disconnected, or a negative error code on
+ * failure.
+ */
+int media_entity_detect_or_fail(struct media_entity *entity);
+
/**
* media_entity_pipeline - Get the media pipeline an entity is part of
* @entity: The entity
--
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 ` Mattijs Korpershoek [this message]
2026-11-18 12:43 ` [PATCH RFC v2 12/16] media: mc: Add MEDIA_IOC_G_ENTITY_STATUS ioctl Mattijs Korpershoek
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-11-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®