[RFC PATCH 26/28] media: mali-vpu: handle firmware event responses

From: Charvi Mehta

Date: Thu Nov 19 2026 - 10:41:22 EST


Add protocol definitions needed to parse firmware event responses.
Report corrupt and unsupported streams, and propagate unsupported-stream
events to the session as -EOPNOTSUPP. Ignore informational events that
require no session action.

Also retain sequence bit-depth and interlace information, and reject
interlaced or non-8-bit streams that aren't supported by the driver yet.

Signed-off-by: Charvi Mehta <charvi.mehta@xxxxxxx>
---
.../platform/arm/mali-vpu/mali-vpu-firmware.c | 44 ++++++++++
.../platform/arm/mali-vpu/mali-vpu-firmware.h | 13 +++
.../arm/mali-vpu/mali-vpu-protocol-def-v3.h | 87 +++++++++++++++++++
.../platform/arm/mali-vpu/mali-vpu-session.c | 19 ++++
4 files changed, 163 insertions(+)

diff --git a/drivers/media/platform/arm/mali-vpu/mali-vpu-firmware.c b/drivers/media/platform/arm/mali-vpu/mali-vpu-firmware.c
index 34d57b288a682..99d191b194bfe 100644
--- a/drivers/media/platform/arm/mali-vpu/mali-vpu-firmware.c
+++ b/drivers/media/platform/arm/mali-vpu/mali-vpu-firmware.c
@@ -1036,6 +1036,7 @@ int mali_vpu_fw_parse_msg(struct mali_vpu_fw *fw, struct mali_vpu_fw_msg *msg)
struct mve_response_frame_alloc_parameters alloc_params;
struct mve_response_sequence_parameters seq_params;
struct mve_buffer_param buffer_param;
+ struct mve_response_event event;
struct mve_response_error error;
} fw_msg = {};
size_t size = sizeof(fw_msg);
@@ -1149,6 +1150,9 @@ int mali_vpu_fw_parse_msg(struct mali_vpu_fw *fw, struct mali_vpu_fw_msg *msg)

msg->code = MALI_VPU_FW_CODE_SEQUENCE_PARAMS;
msg->data.seq_params.planar.buffers_min = fw_msg.seq_params.num_buffers_planar;
+ msg->data.seq_params.bitdepth.luma = fw_msg.seq_params.bitdepth_luma;
+ msg->data.seq_params.bitdepth.chroma = fw_msg.seq_params.bitdepth_chroma;
+ msg->data.seq_params.interlaced = fw_msg.seq_params.interlace;
break;
case MVE_RESPONSE_CODE_INPUT_FLUSHED:
msg->code = MALI_VPU_FW_CODE_INPUT_FLUSH;
@@ -1169,6 +1173,46 @@ int mali_vpu_fw_parse_msg(struct mali_vpu_fw *fw, struct mali_vpu_fw_msg *msg)
case MVE_BUFFER_CODE_PARAM:
ret = mali_vpu_convert_buffer_param(msg, &fw_msg.buffer_param, size);
break;
+ case MVE_RESPONSE_CODE_EVENT: {
+ size_t message_offset = offsetof(struct mve_response_event, event_data.message);
+ size_t message_size;
+
+ msg->code = MALI_VPU_FW_CODE_EVENT;
+
+ if (size < sizeof(fw_msg.event.event_code))
+ return -EPROTO;
+
+ switch (fw_msg.event.event_code) {
+ case MVE_EVENT_ERROR_STREAM_CORRUPT:
+ if (size <= message_offset)
+ return -EPROTO;
+
+ message_size = min(size - message_offset,
+ sizeof(fw_msg.event.event_data.message));
+
+ dev_warn_ratelimited(fw->dev,
+ "firmware reports corrupt stream: %.*s\n",
+ (int)message_size,
+ fw_msg.event.event_data.message);
+
+ break;
+ case MVE_EVENT_ERROR_STREAM_NOT_SUPPORTED:
+ if (size <= message_offset)
+ return -EPROTO;
+
+ message_size = min(size - message_offset,
+ sizeof(fw_msg.event.event_data.message));
+ dev_warn_ratelimited(fw->dev,
+ "firmware reports unsupported stream: %.*s\n",
+ (int)message_size,
+ fw_msg.event.event_data.message);
+ msg->code = MALI_VPU_FW_CODE_STREAM_NOT_SUPPORTED;
+ break;
+ default:
+ break;
+ }
+ break;
+ }
case MVE_RESPONSE_CODE_ERROR: {
size_t message_offset = offsetof(struct mve_response_error, message);
size_t message_size;
diff --git a/drivers/media/platform/arm/mali-vpu/mali-vpu-firmware.h b/drivers/media/platform/arm/mali-vpu/mali-vpu-firmware.h
index 6c46f23ac8638..d3928fdc9133f 100644
--- a/drivers/media/platform/arm/mali-vpu/mali-vpu-firmware.h
+++ b/drivers/media/platform/arm/mali-vpu/mali-vpu-firmware.h
@@ -86,13 +86,22 @@ struct mali_vpu_fw_set_option {

/**
* struct mali_vpu_fw_seq_param - Sequence parameters.
+ * @interlaced: Whether the decoded sequence is interlaced.
* @planar: Planar output-buffer requirements.
* @planar.buffers_min: Minimum number of planar buffers required.
+ * @bitdepth: Decoded luma and chroma bitdepths.
+ * @bitdepth.luma: Decoded luma bitdepth.
+ * @bitdepth.chroma: Decoded chroma bitdepth.
*/
struct mali_vpu_fw_seq_param {
+ bool interlaced;
struct {
u32 buffers_min;
} planar;
+ struct mali_vpu_fw_bitdepth {
+ u32 chroma;
+ u32 luma;
+ } bitdepth;
};

/**
@@ -146,6 +155,8 @@ struct mali_vpu_fw_error {
* @MALI_VPU_FW_CODE_ALLOC_PARAM: Firmware reported new frame allocation parameters.
* @MALI_VPU_FW_CODE_COLOR_DESC: Firmware reported colour-description metadata.
* @MALI_VPU_FW_CODE_DPB_HELD_FRAMES: Firmware reported the number of frames held in the DPB.
+ * @MALI_VPU_FW_CODE_STREAM_NOT_SUPPORTED: Firmware rejected the coded stream.
+ * @MALI_VPU_FW_CODE_EVENT: Firmware reported an informational event.
* @MALI_VPU_FW_CODE_UNKNOWN: Unrecognized firmware message.
* @MALI_VPU_FW_CODE_MAX: Sentinel marking the end of the message-code enum.
*/
@@ -168,6 +179,8 @@ enum mali_vpu_fw_code {
MALI_VPU_FW_CODE_ALLOC_PARAM, /* Driver <- Firmware. */
MALI_VPU_FW_CODE_COLOR_DESC, /* Driver <- Firmware. */
MALI_VPU_FW_CODE_DPB_HELD_FRAMES, /* Driver <- Firmware. */
+ MALI_VPU_FW_CODE_STREAM_NOT_SUPPORTED, /* Driver <- Firmware. */
+ MALI_VPU_FW_CODE_EVENT, /* Driver <- Firmware. */
MALI_VPU_FW_CODE_UNKNOWN, /* Driver <- Firmware. */
MALI_VPU_FW_CODE_MAX
};
diff --git a/drivers/media/platform/arm/mali-vpu/mali-vpu-protocol-def-v3.h b/drivers/media/platform/arm/mali-vpu/mali-vpu-protocol-def-v3.h
index 76dc7bf076c8f..3fe572b180d72 100644
--- a/drivers/media/platform/arm/mali-vpu/mali-vpu-protocol-def-v3.h
+++ b/drivers/media/platform/arm/mali-vpu/mali-vpu-protocol-def-v3.h
@@ -259,6 +259,8 @@ struct mve_msg_header {
#define MVE_RESPONSE_CODE_FRAME_ALLOC_PARAM (2014)
/* struct mve_response_sequence_parameters */
#define MVE_RESPONSE_CODE_SEQUENCE_PARAMETERS (2015)
+ /* struct mve_response_event (variable size) */
+ #define MVE_RESPONSE_CODE_EVENT (2016)
/* struct mve_response_set_option_fail */
#define MVE_RESPONSE_CODE_SET_OPTION_FAIL (2017)

@@ -440,6 +442,91 @@ struct mve_response_error {
char message[MVE_MAX_ERROR_MESSAGE_SIZE];
};

+/*
+ * Per-frame processing statistics emitted when firmware profiling is
+ * enabled.
+ */
+struct mve_event_processed {
+ u8 pic_format;
+ u8 qp;
+ u8 pad0;
+ u8 pad1;
+ u32 parse_start_time; /* Timestamp, absolute time */
+ u32 parse_end_time; /* Timestamp, absolute time */
+ u32 parse_idle_time; /* Waiting for in/out buffers or available RAM */
+ u32 pipe_start_time; /* Timestamp */
+ u32 pipe_end_time; /* Timestamp, end-start = process time. Idle time while in a frame
+ * is not measured.
+ */
+ u32 pipe_idle_time; /* Always 0 in decode, */
+ u32 parser_coreid; /* Core used to parse this frame */
+ u32 pipe_coreid; /* Core used to pipe this frame */
+ u32 bitstream_bits; /* Number of bitstream bits used for this frame. */
+ u32 intermediate_buffer_size; /* Size of intermediate (mbinfo/residuals) buffer after this
+ * frame was parsed.
+ */
+ u32 total_memory_allocated; /* after the frame was parsed. Including reference frames */
+ u32 bus_read_bytes; /* bus read bytes */
+ u32 bus_write_bytes; /* bus written bytes */
+ u32 afbc_bytes;
+ u32 slice0_end_time; /* Timestamp, absolute time */
+ u32 stream_start_time; /* Timestamp, absolute stream start time */
+ u32 stream_open_time; /* Timestamp, absolute stream open time */
+};
+
+/*
+ * Encoder reference-frame metadata emitted when reference-frame exposure
+ * is enabled.
+ */
+struct mve_event_ref_frame {
+ u32 ref_width; /* Width of display area in luma pixels */
+ u32 ref_height; /* Height of display area in luma pixels */
+ u32 ref_mb_width; /* Width in macroblocks */
+ u32 ref_mb_height; /* Height in macroblocks */
+ u32 ref_left_crop; /* Left crop in luma pixels */
+ u32 ref_top_crop; /* Top crop in luma pixels */
+ u32 ref_frame_size;
+ u32 ref_display_order;
+ u32 ref_addr;
+ u16 bit_width; /* bit width of the YUV either 8 or 10 */
+ u16 tiled_headers;
+};
+
+/*
+ * Trace-buffer allocations emitted by firmware build with event tracing
+ * enabled.
+ */
+struct mve_event_trace_buffers {
+ u16 reserved;
+ u8 num_cores;
+ u8 rasc_mask;
+ #define MVE_MAX_TRACE_BUFFERS 40
+ /* this array will contain one buffer per rasc in rasc_mask per num_core */
+ struct {
+ u32 rasc_addr; /* rasc address of the buffer */
+ u32 size; /* size of the buffer in bytes */
+ } buffers[MVE_MAX_TRACE_BUFFERS];
+};
+
+/*
+ * Firmware event response. Profiling and tracing events are informational,
+ * while stream-error events may require host action.
+ */
+struct mve_response_event {
+ u32 event_code;
+ #define MVE_EVENT_ERROR_STREAM_CORRUPT (1) /* message, text string */
+ #define MVE_EVENT_ERROR_STREAM_NOT_SUPPORTED (2) /* message, text string */
+ #define MVE_EVENT_PROCESSED (3) /* struct mve_event_processed */
+ #define MVE_EVENT_REF_FRAME (4) /* struct mve_event_ref_frame */
+ #define MVE_EVENT_TRACE_BUFFERS (5)
+ union {
+ struct mve_event_processed event_processed;
+ struct mve_event_ref_frame event_ref_frame;
+ struct mve_event_trace_buffers event_trace_buffers;
+ char message[MVE_MAX_ERROR_MESSAGE_SIZE];
+ } event_data;
+};
+
/*
* When a set-option succeeds, a confirmation message is
* sent, including the index-code for that particular option.
diff --git a/drivers/media/platform/arm/mali-vpu/mali-vpu-session.c b/drivers/media/platform/arm/mali-vpu/mali-vpu-session.c
index 411421e175e71..500d80788d0eb 100644
--- a/drivers/media/platform/arm/mali-vpu/mali-vpu-session.c
+++ b/drivers/media/platform/arm/mali-vpu/mali-vpu-session.c
@@ -584,6 +584,20 @@ static int mali_vpu_session_handle_fw_msg(struct mali_vpu_session *sess,
struct vb2_queue *dst_q;
u32 buffers_min;

+ if (fw_msg->data.seq_params.interlaced) {
+ dev_err(sess->vpu_dev->dev, "interlaced streams are not supported\n");
+ return -EOPNOTSUPP;
+ }
+
+ if (fw_msg->data.seq_params.bitdepth.luma != 8 ||
+ fw_msg->data.seq_params.bitdepth.chroma != 8) {
+ dev_err(sess->vpu_dev->dev,
+ "bitdepth luma=%u chroma=%u is not supported\n",
+ fw_msg->data.seq_params.bitdepth.luma,
+ fw_msg->data.seq_params.bitdepth.chroma);
+ return -EOPNOTSUPP;
+ }
+
buffers_min = fw_msg->data.seq_params.planar.buffers_min;
dst_q = v4l2_m2m_get_dst_vq(sess->m2m_ctx);

@@ -599,6 +613,11 @@ static int mali_vpu_session_handle_fw_msg(struct mali_vpu_session *sess,

return mali_vpu_session_fw_send_flush(sess, false);
}
+ case MALI_VPU_FW_CODE_STREAM_NOT_SUPPORTED:
+ return -EOPNOTSUPP;
+ case MALI_VPU_FW_CODE_EVENT:
+ /* No session action is required for informational events. */
+ return 0;
case MALI_VPU_FW_CODE_UNKNOWN:
case MALI_VPU_FW_CODE_MAX:
default:
--
2.43.0