From b5f5469c0dc91ddca5406b9658ec8fd88b4a8f72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Ren=C3=A9?= <17342133+angelrenefm@users.noreply.github.com> Date: Fri, 13 Nov 2026 20:46:44 +0100 Subject: [PATCH 01/21] media: s5p-mfc: signal the parsed stream format with V4L2_EVENT_SOURCE_CHANGE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The stateful decoder interface (dev-decoder.rst, "Initialization") has the client learn the stream's coded format from V4L2_EVENT_SOURCE_CHANGE once the header is parsed; s5p-mfc only sent the event for a resolution change in the middle of a stream. Queue it when SEQ_DONE leaves the instance in HEAD_PARSED. Clients that do not subscribe to the event are not affected. Tested on a Pixel 7 (gs201, MFC v15.6) with the rest of this series: a small V4L2 stateful test client that waits for the event, FFmpeg's h264_v4l2m2m and GStreamer's v4l2h264dec all decode H.264 bit-exact against FFmpeg's software decoder. Not tested on any older MFC. Assisted-by: LLM Signed-off-by: Ángel René <17342133+angelrenefm@users.noreply.github.com> --- .../media/platform/samsung/s5p-mfc/s5p_mfc.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c index 32eb402d43..c88017371d 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c @@ -540,10 +540,24 @@ static void s5p_mfc_handle_seq_done(struct s5p_mfc_ctx *ctx, if (FW_HAS_E_MIN_SCRATCH_BUF(dev)) ctx->scratch_buf_size = s5p_mfc_hw_call(dev->mfc_ops, get_min_scratch_buf_size, dev); - if (ctx->img_width == 0 || ctx->img_height == 0) + if (ctx->img_width == 0 || ctx->img_height == 0) { ctx->state = MFCINST_ERROR; - else + } else { + static const struct v4l2_event ev_src_ch = { + .type = V4L2_EVENT_SOURCE_CHANGE, + .u.src_change.changes = + V4L2_EVENT_SRC_CH_RESOLUTION, + }; + ctx->state = MFCINST_HEAD_PARSED; + /* + * The stateful decoder interface (dev-decoder.rst, + * "Initialization"): the client learns the stream's + * format from this event, not by calling G_FMT on + * CAPTURE in a loop. + */ + v4l2_event_queue_fh(&ctx->fh, &ev_src_ch); + } if ((ctx->codec_mode == S5P_MFC_CODEC_H264_DEC || ctx->codec_mode == S5P_MFC_CODEC_H264_MVC_DEC) && From e03b8833b01f630b1c9f2264e7564218a527afd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Ren=C3=A9?= <17342133+angelrenefm@users.noreply.github.com> Date: Fri, 13 Nov 2026 21:06:11 +0100 Subject: [PATCH 02/21] media: s5p-mfc: round private buffer sizes up to whole pages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The preallocated-memory allocator marks b->size >> PAGE_SHIFT pages as used, so the tail of a buffer whose size is not a multiple of the page size is left free in the bitmap and can be handed out again. Today the 64 KiB alignment of every allocation hides it for the context buffers (30 KiB, 2 MiB), but not for a buffer that ends just past a 64 KiB boundary. Round the page count up on allocation and release alike. Assisted-by: LLM Signed-off-by: Ángel René <17342133+angelrenefm@users.noreply.github.com> --- drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr.c index b25ad2a371..5b078cc0d6 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr.c +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr.c @@ -35,7 +35,7 @@ int s5p_mfc_alloc_priv_buf(struct s5p_mfc_dev *dev, unsigned int mem_ctx, struct s5p_mfc_priv_buf *b) { unsigned int bits = dev->mem_size >> PAGE_SHIFT; - unsigned int count = b->size >> PAGE_SHIFT; + unsigned int count = DIV_ROUND_UP(b->size, PAGE_SIZE); unsigned int align = (SZ_64K >> PAGE_SHIFT) - 1; unsigned int start, offset; @@ -97,7 +97,7 @@ void s5p_mfc_release_priv_buf(struct s5p_mfc_dev *dev, { if (dev->mem_virt) { unsigned int start = (b->dma - dev->mem_base) >> PAGE_SHIFT; - unsigned int count = b->size >> PAGE_SHIFT; + unsigned int count = DIV_ROUND_UP(b->size, PAGE_SIZE); bitmap_clear(dev->mem_bitmap, start, count); } else { From 1b4dc7270842c30d5c88e2d11a754595f4aaf8e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Ren=C3=A9?= <17342133+angelrenefm@users.noreply.github.com> Date: Fri, 13 Nov 2026 21:06:23 +0100 Subject: [PATCH 03/21] dt-bindings: media: s5p-mfc: Add the Google GS201 MFC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Google GS201 SoC (Pixel 7) has an MFC v15.6 (MFC_VERSION reads 0x15060000). Like the Tesla FSD one it takes a single "mfc" clock and sits behind up to two System MMUs. On GS201 that clock is the ACPM firmware's MFC DVFS domain, which sets the voltage with the rate. Assisted-by: LLM Signed-off-by: Ángel René <17342133+angelrenefm@users.noreply.github.com> --- Documentation/devicetree/bindings/media/samsung,s5p-mfc.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/media/samsung,s5p-mfc.yaml b/Documentation/devicetree/bindings/media/samsung,s5p-mfc.yaml index b46cc78070..41f05d7ce4 100644 --- a/Documentation/devicetree/bindings/media/samsung,s5p-mfc.yaml +++ b/Documentation/devicetree/bindings/media/samsung,s5p-mfc.yaml @@ -18,6 +18,7 @@ properties: compatible: oneOf: - enum: + - google,gs201-mfc # Google GS201 (MFC v15) - samsung,exynos5433-mfc # Exynos5433 - samsung,mfc-v5 # Exynos4 - samsung,mfc-v6 # Exynos5 @@ -164,6 +165,7 @@ allOf: compatible: contains: enum: + - google,gs201-mfc - tesla,fsd-mfc then: properties: From ac6db1e3a55ed315f744943516780a389801e7a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Ren=C3=A9?= <17342133+angelrenefm@users.noreply.github.com> Date: Fri, 13 Nov 2026 21:06:50 +0100 Subject: [PATCH 04/21] media: s5p-mfc: Add support for the MFC v15 of Google GS201 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The GS201 MFC (IP version 0x15060000) keeps the v8+ register map used by v12, with these differences, measured on a Pixel 7 or taken from Google's exynos-mfc driver (kernel/google-modules/soc/gs, drivers/media/platform/exynos/mfc/) and its device tree (kernel/devices/google/gs201, dts/gs201-mfc.dtsi), both on branch android-gs-pantah-6.1-android16: - The non-secure firmware base is RISC_NONSECURE_BASE_ADDR (0x0068); 0x0054 is the secure one. - MFC_CLOCK_OFF is cleared before RISC_ON, and the firmware status bit (0xF0A4) is polled before SYS_INIT. MFC_VERSION (0xF028) is checked. - The firmware rejects any buffer placed below its own base (ERR_RET with error 0x33, measured). The firmware, the device and instance contexts and also the codec buffers therefore come from one preallocated 64 MiB region with a 32-bit DMA mask, firmware first. An optional "memory-region" makes the vb2 buffers come from the same pool; without it, buffers below the firmware base are reported with a warning. - A missing clock is tolerated: the node's clock is only the ACPM DVFS rate, and the MFC clock controller (CMU_MFC) is not described yet. - The encoder registers differ from v12's (0xF770/0xF774 clash with the decoder's) and nothing programs them yet, so only the decoder node is registered. The firmware is loaded as s5p-mfc-v15.fw; it is the stock mfc_fw.bin from the device's vendor partition, which each owner takes from their own OTA. The vendor driver always runs the decoder with dynamic DPB; that comes in the next patch. This patch was not run on its own: whether the v15 firmware still takes mainline's static DPB is not known. Tested on a Pixel 7 (panther) with the node applied as a runtime DT overlay on the "camera-pool" reserved region, together with the next patch. Not tested: the encoder, VP8/VP9/HEVC/MPEG-4 decode, the System MMU (left in bypass), runtime PM with a real clock, suspend/resume. Assisted-by: LLM Signed-off-by: Ángel René <17342133+angelrenefm@users.noreply.github.com> --- .../platform/samsung/s5p-mfc/regs-mfc-v15.h | 35 ++++++++++++ .../media/platform/samsung/s5p-mfc/s5p_mfc.c | 54 +++++++++++++++++++ .../platform/samsung/s5p-mfc/s5p_mfc_common.h | 14 +++-- .../platform/samsung/s5p-mfc/s5p_mfc_ctrl.c | 50 ++++++++++++++++- .../platform/samsung/s5p-mfc/s5p_mfc_dec.c | 32 ++++++++++- .../platform/samsung/s5p-mfc/s5p_mfc_opr.c | 13 +++++ .../platform/samsung/s5p-mfc/s5p_mfc_pm.c | 7 ++- 7 files changed, 195 insertions(+), 10 deletions(-) create mode 100644 drivers/media/platform/samsung/s5p-mfc/regs-mfc-v15.h diff --git a/drivers/media/platform/samsung/s5p-mfc/regs-mfc-v15.h b/drivers/media/platform/samsung/s5p-mfc/regs-mfc-v15.h new file mode 100644 index 0000000000..3a792de938 --- /dev/null +++ b/drivers/media/platform/samsung/s5p-mfc/regs-mfc-v15.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Register definition file for Samsung MFC V15.x Interface (FIMV) driver + * + * MFC v15.6 is found in the Google GS201 SoC. Its register map is the v8+ + * map used by v12; only the differences used by this driver are listed here. + */ + +#ifndef _REGS_MFC_V15_H +#define _REGS_MFC_V15_H + +#include +#include "regs-mfc-v12.h" + +/* Firmware base for the non-secure firmware; 0x0054 is the secure one */ +#define S5P_FIMV_RISC_NONSECURE_BASE_ADDR_V15 0x0068 +#define S5P_FIMV_MFC_VERSION_V15 0xF028 +#define S5P_FIMV_FW_STATUS_INFO_V15 0xF0A4 +#define S5P_FIMV_FW_STATUS_READY_V15 BIT(0) + +/* MFCv15 variant defines */ +#define MFC_VERSION_V15 0xF0 +#define MFC_HW_VERSION_V15 0x15060000 +#define MFC_NUM_PORTS_V15 1 +#define MAX_FW_SIZE_V15 (SZ_1M) +#define MAX_CPB_SIZE_V15 (7 * SZ_1M) + +/* + * The firmware rejects every buffer below its own base address, so the + * firmware and all the driver's private buffers share one region with the + * firmware at its start. + */ +#define MFC_MEM_SIZE_V15 (64 * SZ_1M) + +#endif /*_REGS_MFC_V15_H*/ diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c index c88017371d..b927fc0ac8 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c @@ -1233,10 +1233,28 @@ static int s5p_mfc_configure_common_memory(struct s5p_mfc_dev *mfc_dev) { struct device *dev = &mfc_dev->plat_dev->dev; unsigned long mem_size = SZ_4M; + int ret; if (IS_ENABLED(CONFIG_DMA_CMA) || exynos_is_iommu_available(dev)) mem_size = SZ_8M; + if (IS_MFCV15(mfc_dev)) { + /* + * The firmware sees physical addresses through 32-bit + * registers and rejects buffers below its own base, so all of + * the private buffers (codec buffers included) live in this + * region, after the firmware. An optional "memory-region" + * also serves the vb2 buffers from the same pool. + */ + mem_size = MFC_MEM_SIZE_V15; + ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)); + if (ret) + return ret; + ret = of_reserved_mem_device_init(dev); + if (ret && ret != -ENODEV) + return ret; + } + if (mfc_mem_size) mem_size = memparse(mfc_mem_size, NULL); @@ -1248,6 +1266,8 @@ static int s5p_mfc_configure_common_memory(struct s5p_mfc_dev *mfc_dev) &mfc_dev->mem_base, GFP_KERNEL); if (!mfc_dev->mem_virt) { bitmap_free(mfc_dev->mem_bitmap); + if (IS_MFCV15(mfc_dev)) + of_reserved_mem_device_release(dev); dev_err(dev, "failed to preallocate %ld MiB for the firmware and context buffers\n", (mem_size / SZ_1M)); return -ENOMEM; @@ -1288,6 +1308,8 @@ static void s5p_mfc_unconfigure_common_memory(struct s5p_mfc_dev *mfc_dev) mfc_dev->mem_base); bitmap_free(mfc_dev->mem_bitmap); vb2_dma_contig_clear_max_seg_size(dev); + if (IS_MFCV15(mfc_dev)) + of_reserved_mem_device_release(dev); } static int s5p_mfc_configure_dma_memory(struct s5p_mfc_dev *mfc_dev) @@ -1433,6 +1455,18 @@ static int s5p_mfc_probe(struct platform_device *pdev) v4l2_info(&dev->v4l2_dev, "decoder registered as /dev/video%d\n", dev->vfd_dec->num); + /* + * The v15 encoder's registers differ from v12's (0xF770/0xF774 clash + * with the decoder's) and nothing here programs them yet: no encoder + * node rather than one that hangs the firmware. + */ + if (IS_MFCV15(dev)) { + video_device_release(dev->vfd_enc); + dev->vfd_enc = NULL; + pr_debug("%s--\n", __func__); + return 0; + } + ret = video_register_device(dev->vfd_enc, VFL_TYPE_VIDEO, 0); if (ret) { v4l2_err(&dev->v4l2_dev, "Failed to register video device\n"); @@ -1719,6 +1753,23 @@ static struct s5p_mfc_variant mfc_drvdata_v12 = { .num_clocks = 1, }; +static const struct s5p_mfc_buf_size buf_size_v15 = { + .fw = MAX_FW_SIZE_V15, + .cpb = MAX_CPB_SIZE_V15, + .priv = &mfc_buf_size_v12, +}; + +static const struct s5p_mfc_variant mfc_drvdata_v15 = { + .version = MFC_VERSION_V15, + .version_bit = MFC_V15_BIT, + .port_num = MFC_NUM_PORTS_V15, + .buf_size = &buf_size_v15, + .fw_name[0] = "s5p-mfc-v15.fw", + .clk_names = {"mfc"}, + .num_clocks = 1, + .clocks_optional = true, +}; + static const struct of_device_id exynos_mfc_match[] = { { .compatible = "samsung,mfc-v5", @@ -1744,6 +1795,9 @@ static const struct of_device_id exynos_mfc_match[] = { }, { .compatible = "tesla,fsd-mfc", .data = &mfc_drvdata_v12, + }, { + .compatible = "google,gs201-mfc", + .data = &mfc_drvdata_v15, }, {}, }; diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_common.h b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_common.h index 58dc176808..a0192a79ab 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_common.h +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_common.h @@ -19,7 +19,7 @@ #include #include #include "regs-mfc.h" -#include "regs-mfc-v12.h" +#include "regs-mfc-v15.h" #define S5P_MFC_NAME "s5p-mfc" @@ -234,6 +234,7 @@ struct s5p_mfc_variant { const char *clk_names[MFC_MAX_CLOCKS]; int num_clocks; bool use_clock_gating; + bool clocks_optional; }; /** @@ -790,6 +791,7 @@ void s5p_mfc_cleanup_queue(struct list_head *lh, struct vb2_queue *vq); #define IS_MFCV8_PLUS(dev) ((dev)->variant->version >= 0x80) #define IS_MFCV10_PLUS(dev) ((dev)->variant->version >= 0xA0) #define IS_MFCV12(dev) ((dev)->variant->version >= 0xC0) +#define IS_MFCV15(dev) ((dev)->variant->version >= 0xF0) #define FW_HAS_E_MIN_SCRATCH_BUF(dev) (IS_MFCV10_PLUS(dev)) #define MFC_V5_BIT BIT(0) @@ -798,14 +800,16 @@ void s5p_mfc_cleanup_queue(struct list_head *lh, struct vb2_queue *vq); #define MFC_V8_BIT BIT(3) #define MFC_V10_BIT BIT(5) #define MFC_V12_BIT BIT(7) +#define MFC_V15_BIT BIT(8) #define MFC_V5PLUS_BITS (MFC_V5_BIT | MFC_V6_BIT | MFC_V7_BIT | \ - MFC_V8_BIT | MFC_V10_BIT | MFC_V12_BIT) + MFC_V8_BIT | MFC_V10_BIT | MFC_V12_BIT | \ + MFC_V15_BIT) #define MFC_V6PLUS_BITS (MFC_V6_BIT | MFC_V7_BIT | MFC_V8_BIT | \ - MFC_V10_BIT | MFC_V12_BIT) + MFC_V10_BIT | MFC_V12_BIT | MFC_V15_BIT) #define MFC_V7PLUS_BITS (MFC_V7_BIT | MFC_V8_BIT | MFC_V10_BIT | \ - MFC_V12_BIT) + MFC_V12_BIT | MFC_V15_BIT) -#define MFC_V10PLUS_BITS (MFC_V10_BIT | MFC_V12_BIT) +#define MFC_V10PLUS_BITS (MFC_V10_BIT | MFC_V12_BIT | MFC_V15_BIT) #endif /* S5P_MFC_COMMON_H_ */ diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_ctrl.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_ctrl.c index 625d77b2be..b722090701 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_ctrl.c +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_ctrl.c @@ -178,7 +178,13 @@ int s5p_mfc_reset(struct s5p_mfc_dev *dev) static inline void s5p_mfc_init_memctrl(struct s5p_mfc_dev *dev) { - if (IS_MFCV6_PLUS(dev)) { + if (IS_MFCV15(dev)) { + /* 0x0054 is the secure firmware base on MFCv15 */ + mfc_write(dev, dev->dma_base[BANK_L_CTX], + S5P_FIMV_RISC_NONSECURE_BASE_ADDR_V15); + mfc_debug(2, "Base Address : %pad\n", + &dev->dma_base[BANK_L_CTX]); + } else if (IS_MFCV6_PLUS(dev)) { mfc_write(dev, dev->dma_base[BANK_L_CTX], S5P_FIMV_RISC_BASE_ADDRESS_V6); mfc_debug(2, "Base Address : %pad\n", @@ -207,6 +213,34 @@ static inline void s5p_mfc_clear_cmds(struct s5p_mfc_dev *dev) } } +/* + * MFCv15: check that the IP is the one the driver knows and wait until the + * firmware accepts commands, as the vendor driver does before SYS_INIT. + */ +static int s5p_mfc_v15_check_fw(struct s5p_mfc_dev *dev) +{ + unsigned long timeout; + u32 ver; + + ver = mfc_read(dev, S5P_FIMV_MFC_VERSION_V15); + if (ver != MFC_HW_VERSION_V15) { + mfc_err("Unsupported MFC IP version 0x%08x (expected 0x%08x)\n", + ver, MFC_HW_VERSION_V15); + return -ENODEV; + } + + timeout = jiffies + msecs_to_jiffies(MFC_BW_TIMEOUT); + while (!(mfc_read(dev, S5P_FIMV_FW_STATUS_INFO_V15) & + S5P_FIMV_FW_STATUS_READY_V15)) { + if (time_after(jiffies, timeout)) { + mfc_err("Timeout waiting for the firmware status\n"); + return -EIO; + } + usleep_range(100, 200); + } + return 0; +} + /* Initialize hardware */ int s5p_mfc_init_hw(struct s5p_mfc_dev *dev) { @@ -235,6 +269,10 @@ int s5p_mfc_init_hw(struct s5p_mfc_dev *dev) s5p_mfc_clear_cmds(dev); /* 3. Release reset signal to the RISC */ s5p_mfc_clean_dev_int_flags(dev); + /* MFCv15 needs the clock ungated before the RISC starts */ + if (IS_MFCV15(dev)) + mfc_write(dev, 0x0, S5P_FIMV_MFC_CLOCK_OFF_V10); + if (IS_MFCV6_PLUS(dev)) { dev->risc_on = 1; mfc_write(dev, 0x1, S5P_FIMV_RISC_ON_V6); @@ -242,7 +280,7 @@ int s5p_mfc_init_hw(struct s5p_mfc_dev *dev) else mfc_write(dev, 0x3ff, S5P_FIMV_SW_RESET); - if (IS_MFCV10_PLUS(dev)) + if (IS_MFCV10_PLUS(dev) && !IS_MFCV15(dev)) mfc_write(dev, 0x0, S5P_FIMV_MFC_CLOCK_OFF_V10); mfc_debug(2, "Will now wait for completion of firmware transfer\n"); @@ -253,6 +291,14 @@ int s5p_mfc_init_hw(struct s5p_mfc_dev *dev) return -EIO; } s5p_mfc_clean_dev_int_flags(dev); + if (IS_MFCV15(dev)) { + ret = s5p_mfc_v15_check_fw(dev); + if (ret) { + s5p_mfc_reset(dev); + s5p_mfc_clock_off(dev); + return ret; + } + } /* 4. Initialize firmware */ ret = s5p_mfc_hw_call(dev->mfc_cmds, sys_init_cmd, dev); if (ret) { diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c index afd28beabf..8da765ebdf 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c @@ -61,14 +61,14 @@ static const struct s5p_mfc_fmt formats[] = { .codec_mode = S5P_MFC_CODEC_NONE, .type = MFC_FMT_RAW, .num_planes = 3, - .versions = MFC_V12_BIT, + .versions = MFC_V12_BIT | MFC_V15_BIT, }, { .fourcc = V4L2_PIX_FMT_YVU420M, .codec_mode = S5P_MFC_CODEC_NONE, .type = MFC_FMT_RAW, .num_planes = 3, - .versions = MFC_V12_BIT + .versions = MFC_V12_BIT | MFC_V15_BIT }, { .fourcc = V4L2_PIX_FMT_H264, @@ -1002,6 +1002,32 @@ static int s5p_mfc_queue_setup(struct vb2_queue *vq, return 0; } +/* + * MFCv15 firmware rejects any buffer below its own base address. The private + * buffers are allocated after it, but the vb2 buffers come from the generic + * DMA allocator and nothing guarantees their position unless the device has + * its own "memory-region". Warn so that a failure can be traced to this. + */ +static void s5p_mfc_check_buf_addr_v15(struct s5p_mfc_ctx *ctx, + struct vb2_buffer *vb, unsigned int planes) +{ + struct s5p_mfc_dev *dev = ctx->dev; + dma_addr_t addr; + unsigned int i; + + if (!IS_MFCV15(dev)) + return; + + for (i = 0; i < planes; i++) { + addr = vb2_dma_contig_plane_dma_addr(vb, i); + if (addr < dev->fw_buf.dma) + dev_warn(&dev->plat_dev->dev, + "%s buffer %u plane %u at %pad is below the firmware base %pad, the MFC will reject it\n", + V4L2_TYPE_IS_OUTPUT(vb->type) ? "OUTPUT" : "CAPTURE", + vb->index, i, &addr, &dev->fw_buf.dma); + } +} + static int s5p_mfc_buf_init(struct vb2_buffer *vb) { struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); @@ -1031,6 +1057,7 @@ static int s5p_mfc_buf_init(struct vb2_buffer *vb) return -EINVAL; } } + s5p_mfc_check_buf_addr_v15(ctx, vb, ctx->dst_fmt->num_planes); i = vb->index; ctx->dst_bufs[i].b = vbuf; ctx->dst_bufs[i].cookie.raw.luma = @@ -1054,6 +1081,7 @@ static int s5p_mfc_buf_init(struct vb2_buffer *vb) return -EINVAL; } + s5p_mfc_check_buf_addr_v15(ctx, vb, 1); i = vb->index; ctx->src_bufs[i].b = vbuf; ctx->src_bufs[i].cookie.stream = diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr.c index 5b078cc0d6..a576026776 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr.c +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr.c @@ -78,6 +78,13 @@ int s5p_mfc_alloc_generic_buf(struct s5p_mfc_dev *dev, unsigned int mem_ctx, { struct device *mem_dev = dev->mem_dev[mem_ctx]; + /* + * MFCv15 firmware rejects buffers below its base address, so the codec + * buffers come from the same region as the firmware. + */ + if (IS_MFCV15(dev)) + return s5p_mfc_alloc_priv_buf(dev, mem_ctx, b); + mfc_debug(3, "Allocating generic buf: %zu\n", b->size); b->ctx = mem_ctx; @@ -114,6 +121,12 @@ void s5p_mfc_release_generic_buf(struct s5p_mfc_dev *dev, struct s5p_mfc_priv_buf *b) { struct device *mem_dev = dev->mem_dev[b->ctx]; + + if (IS_MFCV15(dev)) { + if (b->virt) + s5p_mfc_release_priv_buf(dev, b); + return; + } dma_free_coherent(mem_dev, b->size, b->virt, b->dma); b->virt = NULL; b->dma = 0; diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_pm.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_pm.c index ae42414083..d60a04b5a7 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_pm.c +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_pm.c @@ -26,7 +26,12 @@ int s5p_mfc_init_pm(struct s5p_mfc_dev *dev) /* clock control */ for (i = 0; i < pm->num_clocks; i++) { - pm->clocks[i] = devm_clk_get(pm->device, pm->clk_names[i]); + if (dev->variant->clocks_optional) + pm->clocks[i] = devm_clk_get_optional(pm->device, + pm->clk_names[i]); + else + pm->clocks[i] = devm_clk_get(pm->device, + pm->clk_names[i]); if (IS_ERR(pm->clocks[i])) { /* additional clocks are optional */ if (i && PTR_ERR(pm->clocks[i]) == -ENOENT) { From 4e9f0640935cbb1f25fb7e6555d4b9801dafbabd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Ren=C3=A9?= <17342133+angelrenefm@users.noreply.github.com> Date: Fri, 13 Nov 2026 21:07:14 +0100 Subject: [PATCH 05/21] media: s5p-mfc: decode with dynamic DPB on MFC v15 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Google's exynos-mfc driver always sets DYNAMIC_DPB (bit 3 of D_INIT_BUFFER_OPTIONS) on v15 and gives the firmware one capture buffer per FRAME_START, through D_DYNAMIC_DPB_FLAG and D_AVAILABLE_DPB_FLAG; D_USED_DPB_FLAG then tells which buffers the firmware still holds as references or for display. Mainline programs every DPB address once at INIT_BUFFERS (static DPB). Do as the vendor driver on v15: skip the DPB addresses at INIT_BUFFERS, and before each frame pick a queued capture buffer that the firmware does not hold (mfc_search_for_dpb() in the vendor driver). If it holds all of them it frees one by displaying it, so any queued buffer may be given then. A frame is not started while no buffer can be given. Tested on a Pixel 7 (panther, MFC v15.6, firmware version 0x44250901), module built from this series on omamobile, node applied as a runtime DT overlay on the "camera-pool" reserved region: - H.264 320x240 Baseline (30 frames), 1920x1080 High (60 frames) and a hard 1920x1080 High stream (300 frames, ~20 Mbit/s): every frame bit-exact against FFmpeg's software decoder. - 1080p at ~70 fps with ~0.09 s of CPU time for the 300 frames, against 8.3 s of CPU time for FFmpeg's software decoder (8 threads). - Clients: a small V4L2 stateful test client, FFmpeg's h264_v4l2m2m (300/300 frames bit-exact with -fps_mode passthrough) and GStreamer's v4l2h264dec. Not tested: VP8/VP9/HEVC/MPEG-4 decode, interlaced or MVC streams, a resolution change in the middle of a stream, seeking (decoder stop and restart in the middle of a stream). Assisted-by: LLM Signed-off-by: Ángel René <17342133+angelrenefm@users.noreply.github.com> --- .../platform/samsung/s5p-mfc/regs-mfc-v15.h | 9 ++ .../media/platform/samsung/s5p-mfc/s5p_mfc.c | 4 + .../platform/samsung/s5p-mfc/s5p_mfc_common.h | 4 + .../platform/samsung/s5p-mfc/s5p_mfc_dec.c | 1 + .../platform/samsung/s5p-mfc/s5p_mfc_opr_v6.c | 84 ++++++++++++++++++- 5 files changed, 100 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/samsung/s5p-mfc/regs-mfc-v15.h b/drivers/media/platform/samsung/s5p-mfc/regs-mfc-v15.h index 3a792de938..4c4a8fe37a 100644 --- a/drivers/media/platform/samsung/s5p-mfc/regs-mfc-v15.h +++ b/drivers/media/platform/samsung/s5p-mfc/regs-mfc-v15.h @@ -18,6 +18,15 @@ #define S5P_FIMV_FW_STATUS_INFO_V15 0xF0A4 #define S5P_FIMV_FW_STATUS_READY_V15 BIT(0) +/* Dynamic DPB */ +#define S5P_FIMV_D_NAL_START_OPTIONS_V15 0xF5AC +#define S5P_FIMV_D_AVAILABLE_DPB_FLAG_UPPER_V15 0xF5B8 +#define S5P_FIMV_D_DYNAMIC_DPB_FLAG_UPPER_V15 0xF5D4 +#define S5P_FIMV_D_DYNAMIC_DPB_FLAG_LOWER_V15 0xF5D8 +#define S5P_FIMV_D_USED_DPB_FLAG_UPPER_V15 0xF720 +#define S5P_FIMV_D_USED_DPB_FLAG_LOWER_V15 0xF724 +#define S5P_FIMV_D_INIT_BUF_OPT_DYNAMIC_DPB_V15 BIT(3) + /* MFCv15 variant defines */ #define MFC_VERSION_V15 0xF0 #define MFC_HW_VERSION_V15 0x15060000 diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c index b927fc0ac8..94e75fc4d7 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c @@ -381,6 +381,9 @@ static void s5p_mfc_handle_frame(struct s5p_mfc_ctx *ctx, & S5P_FIMV_DEC_STATUS_DECODING_STATUS_MASK; dec_frame_status = s5p_mfc_hw_call(dev->mfc_ops, get_dec_status, dev) & S5P_FIMV_DEC_STATUS_DECODING_STATUS_MASK; + /* DPBs the firmware still holds (references or not yet displayed) */ + if (dev->dynamic_dpb) + ctx->dpb_used = readl(dev->mfc_regs->d_used_dpb_flag_lower); res_change = (s5p_mfc_hw_call(dev->mfc_ops, get_dspl_status, dev) & S5P_FIMV_DEC_STATUS_RESOLUTION_MASK) >> S5P_FIMV_DEC_STATUS_RESOLUTION_SHIFT; @@ -1358,6 +1361,7 @@ static int s5p_mfc_probe(struct platform_device *pdev) dev_err(&pdev->dev, "Failed to get device MFC hardware variant information\n"); return -ENOENT; } + dev->dynamic_dpb = IS_MFCV15(dev); dev->regs_base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(dev->regs_base)) diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_common.h b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_common.h index a0192a79ab..98ab487bd9 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_common.h +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_common.h @@ -301,6 +301,7 @@ struct s5p_mfc_priv_buf { * @fw_get_done: flag set when request_firmware() is complete and * copied into fw_buf * @risc_on: flag indicates RISC is on or off + * @dynamic_dpb: decoder hands one DPB to the firmware per frame (MFCv15) * */ struct s5p_mfc_dev { @@ -348,6 +349,7 @@ struct s5p_mfc_dev { enum s5p_mfc_fw_ver fw_ver; bool fw_get_done; bool risc_on; /* indicates if RISC is on or off */ + bool dynamic_dpb; }; /* @@ -592,6 +594,7 @@ struct s5p_mfc_codec_ops { * @dst_bufs_cnt: number of allocated destination buffers * @sequence: counter for the sequence number for v4l2 * @dec_dst_flag: flags for buffers queued in the hardware + * @dpb_used: DPBs still held by the firmware (dynamic DPB, MFCv15) * @dec_src_buf_size: size of the buffer for source buffers in decoding * @codec_mode: number of codec mode used by MFC hw * @slice_interface: slice interface flag @@ -685,6 +688,7 @@ struct s5p_mfc_ctx { unsigned int sequence; unsigned long dec_dst_flag; + unsigned long dpb_used; size_t dec_src_buf_size; /* Control values */ diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c index 8da765ebdf..6d7f093b49 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c @@ -1134,6 +1134,7 @@ static void s5p_mfc_stop_streaming(struct vb2_queue *q) ctx->dst_queue_cnt = 0; ctx->dpb_flush_flag = 1; ctx->dec_dst_flag = 0; + ctx->dpb_used = 0; if (IS_MFCV6_PLUS(dev) && (ctx->state == MFCINST_RUNNING)) { ctx->state = MFCINST_FLUSH; set_work_bit_irqsave(ctx); diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr_v6.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr_v6.c index 98f8292b31..770e3e8617 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr_v6.c +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr_v6.c @@ -654,7 +654,18 @@ static int s5p_mfc_set_dec_frame_buffer_v6(struct s5p_mfc_ctx *ctx) mfc_debug(2, "Frame size: %d ch: %d mv: %d\n", frame_size, frame_size_ch, frame_size_mv); - for (i = 0; i < ctx->total_dpb_count; i++) { + /* + * Dynamic DPB: the DPB addresses are given one per frame at + * FRAME_START (s5p_mfc_set_dynamic_dpb_v15()), not here. + */ + if (dev->dynamic_dpb) { + writel(readl(mfc_regs->d_init_buffer_options) | + S5P_FIMV_D_INIT_BUF_OPT_DYNAMIC_DPB_V15, + mfc_regs->d_init_buffer_options); + ctx->dpb_used = 0; + } + + for (i = 0; !dev->dynamic_dpb && i < ctx->total_dpb_count; i++) { /* Bank2 */ mfc_debug(2, "Luma %d: %zx\n", i, ctx->dst_bufs[i].cookie.raw.luma); @@ -1826,6 +1837,57 @@ static inline void s5p_mfc_set_flush(struct s5p_mfc_ctx *ctx, int flush) } } +/* + * Dynamic DPB (MFCv15): pick a capture buffer queued in the driver that the + * firmware does not hold any more, as the vendor driver does + * (mfc_search_for_dpb()). If the firmware holds all of them it releases one + * by displaying it, so any queued buffer may be given then. + */ +static struct s5p_mfc_buf *s5p_mfc_search_dynamic_dpb_v15(struct s5p_mfc_ctx *ctx) +{ + struct s5p_mfc_buf *buf; + + list_for_each_entry(buf, &ctx->dst_queue, list) + if (!(ctx->dpb_used & BIT(buf->b->vb2_buf.index))) + return buf; + + if (!list_empty(&ctx->dst_queue) && + hweight_long(ctx->dpb_used) >= ctx->total_dpb_count) + return list_first_entry(&ctx->dst_queue, struct s5p_mfc_buf, + list); + return NULL; +} + +static void s5p_mfc_set_dynamic_dpb_v15(struct s5p_mfc_ctx *ctx) +{ + struct s5p_mfc_dev *dev = ctx->dev; + const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs; + struct s5p_mfc_buf *buf; + u32 set = 0; + int i; + + buf = s5p_mfc_search_dynamic_dpb_v15(ctx); + if (buf) { + i = buf->b->vb2_buf.index; + set = BIT(i); + writel(buf->cookie.raw.luma, mfc_regs->d_first_plane_dpb + i * 4); + writel(buf->cookie.raw.chroma, + mfc_regs->d_second_plane_dpb + i * 4); + if (ctx->dst_fmt->fourcc == V4L2_PIX_FMT_YUV420M || + ctx->dst_fmt->fourcc == V4L2_PIX_FMT_YVU420M) + writel(buf->cookie.raw.chroma_1, + mfc_regs->d_third_plane_dpb + i * 4); + mfc_debug(2, "Dynamic DPB %d: %zx (used %#lx)\n", i, + buf->cookie.raw.luma, ctx->dpb_used); + } + + writel(0, mfc_regs->d_nal_start_options); + writel(set, mfc_regs->d_dynamic_dpb_flag_lower); + writel(0, mfc_regs->d_dynamic_dpb_flag_upper); + writel(set, mfc_regs->d_available_dpb_flag_lower); + writel(0, mfc_regs->d_available_dpb_flag_upper); +} + /* Decode a single frame */ static int s5p_mfc_decode_one_frame_v6(struct s5p_mfc_ctx *ctx, enum s5p_mfc_decode_arg last_frame) @@ -1833,7 +1895,10 @@ static int s5p_mfc_decode_one_frame_v6(struct s5p_mfc_ctx *ctx, struct s5p_mfc_dev *dev = ctx->dev; const struct s5p_mfc_regs *mfc_regs = dev->mfc_regs; - writel(ctx->dec_dst_flag, mfc_regs->d_available_dpb_flag_lower); + if (dev->dynamic_dpb) + s5p_mfc_set_dynamic_dpb_v15(ctx); + else + writel(ctx->dec_dst_flag, mfc_regs->d_available_dpb_flag_lower); writel(ctx->slice_interface & 0x1, mfc_regs->d_slice_if_enable); writel(ctx->inst_no, mfc_regs->instance_id); @@ -1969,6 +2034,10 @@ static inline int s5p_mfc_run_dec_frame(struct s5p_mfc_ctx *ctx) mfc_debug(2, "No src buffers.\n"); return -EAGAIN; } + if (dev->dynamic_dpb && !s5p_mfc_search_dynamic_dpb_v15(ctx)) { + mfc_debug(2, "No free DPB (used %#lx).\n", ctx->dpb_used); + return -EAGAIN; + } /* Get the next source buffer */ temp_vb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list); temp_vb->flags |= MFC_BUF_FLAG_USED; @@ -2656,6 +2725,17 @@ const struct s5p_mfc_regs *s5p_mfc_init_regs_v6_plus(struct s5p_mfc_dev *dev) R(e_hevc_lf_tc_offset_div2, S5P_FIMV_E_HEVC_LF_TC_OFFSET_DIV2_V10); R(e_hevc_nal_control, S5P_FIMV_E_HEVC_NAL_CONTROL_V10); + if (!IS_MFCV15(dev)) + goto done; + + /* Dynamic DPB registers of MFC v15 */ + R(d_nal_start_options, S5P_FIMV_D_NAL_START_OPTIONS_V15); + R(d_available_dpb_flag_upper, S5P_FIMV_D_AVAILABLE_DPB_FLAG_UPPER_V15); + R(d_dynamic_dpb_flag_upper, S5P_FIMV_D_DYNAMIC_DPB_FLAG_UPPER_V15); + R(d_dynamic_dpb_flag_lower, S5P_FIMV_D_DYNAMIC_DPB_FLAG_LOWER_V15); + R(d_used_dpb_flag_upper, S5P_FIMV_D_USED_DPB_FLAG_UPPER_V15); + R(d_used_dpb_flag_lower, S5P_FIMV_D_USED_DPB_FLAG_LOWER_V15); + done: return &mfc_regs; #undef S5P_MFC_REG_ADDR From 5ab72dd419e12ea223d4b0c4b95a8f1b1d31e374 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Ren=C3=A9?= <17342133+angelrenefm@users.noreply.github.com> Date: Sun, 15 Nov 2026 13:51:03 +0100 Subject: [PATCH 06/21] arm64: dts: exynos: google: gs201: Add the MFC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Describe the gs201 MFC (v15.6), disabled, from Google's MFC-0 node (kernel/devices/google/gs201, dts/gs201-mfc.dtsi, branch android-gs-pantah-6.1-android16): registers at 0x1c8d0000, GIC SPI 504 level high. Its "mfc" clock is the ACPM firmware's MFC DVFS domain, so that s5p-mfc can raise the rate while it decodes instead of running at the 100 MHz the bootloader leaves; ACPM sets the voltage with it. The two System MMUs in front of it are not described: they stay in bypass, so the MFC sees physical addresses through 32-bit registers, and a board that enables it gives it memory below 4 GiB through memory-region. No power domain and no CMU_MFC gates either: CMU_MFC is not described yet, and the gs201 boards boot with clk_ignore_unused and pd_ignore_unused, which leave them on as the bootloader set them. The node's comment names the CMU_TOP gate that depends on that flag. Assisted-by: LLM Signed-off-by: Ángel René <17342133+angelrenefm@users.noreply.github.com> --- arch/arm64/boot/dts/exynos/google/gs201.dtsi | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/arch/arm64/boot/dts/exynos/google/gs201.dtsi b/arch/arm64/boot/dts/exynos/google/gs201.dtsi index 4f804ecbb4..11f0d479e5 100644 --- a/arch/arm64/boot/dts/exynos/google/gs201.dtsi +++ b/arch/arm64/boot/dts/exynos/google/gs201.dtsi @@ -2013,6 +2013,26 @@ }; }; + /* + * MFC v15.6 video codec. Its two System MMUs (0x1c870000, + * 0x1c8a0000) are left in bypass and CMU_MFC is not described + * yet, so the firmware and its buffers need memory below 4 GiB + * from the board's memory-region, and the block runs on the + * power domain the bootloader leaves on. Its rate (and voltage) + * is the ACPM firmware's MFC DVFS domain. CMU_TOP's + * gout_cmu_mfc_mfc gate feeds the block too and stays on only + * because the boards boot with clk_ignore_unused: without that + * flag the first register access would hit an unclocked block. + */ + mfc: video-codec@1c8d0000 { + compatible = "google,gs201-mfc"; + reg = <0x1c8d0000 0x10000>; + interrupts = ; + clocks = <&acpm_ipc GS201_CLK_ACPM_DVFS_MFC>; + clock-names = "mfc"; + status = "disabled"; + }; + gpu: gpu@28000000 { compatible = "google,gs201-mali", "arm,mali-valhall-csf"; reg = <0x28000000 0x480000>; From b174e510ce1e46da1da4387f411a3f26e4628dc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Ren=C3=A9?= <17342133+angelrenefm@users.noreply.github.com> Date: Sat, 14 Nov 2026 00:57:49 +0100 Subject: [PATCH 07/21] media: s5p-mfc: let dynamic DPB clients queue more capture buffers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The CAPTURE queue is capped at the minimum the stream needs plus MFC_MAX_EXTRA_DPB (5). That fits a fixed DPB, which the firmware takes whole at INIT_BUFFERS. With dynamic DPB (MFC v15) the firmware only holds the frames it still references or has not shown yet, and every other buffer the client keeps, a player's display queue among them, comes out of those five. mpv 0.41 on the Pixel 7 shows the problem: with its default gpu-next output it keeps more decoded frames queued than the five spare ones, the decoder runs out of free buffers after the first frame and the picture freezes. With dynamic DPB, cap the queue at MFC_MAX_BUFFERS (32) only, the driver's own limit for any queue; FFmpeg's h264_v4l2m2m asks for 20 by default. vb2 already falls back to fewer buffers when the memory runs short. Assisted-by: LLM Signed-off-by: Ángel René <17342133+angelrenefm@users.noreply.github.com> --- drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c index 6d7f093b49..653f7efa68 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c @@ -966,7 +966,8 @@ static int s5p_mfc_queue_setup(struct vb2_queue *vq, /* Setup buffer count */ if (*buf_count < ctx->pb_count) *buf_count = ctx->pb_count; - if (*buf_count > ctx->pb_count + MFC_MAX_EXTRA_DPB) + if (!dev->dynamic_dpb && + *buf_count > ctx->pb_count + MFC_MAX_EXTRA_DPB) *buf_count = ctx->pb_count + MFC_MAX_EXTRA_DPB; if (*buf_count > MFC_MAX_BUFFERS) *buf_count = MFC_MAX_BUFFERS; From 2889c50918121f35c4e6bf1f136c5d71ea3c14c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Ren=C3=A9?= <17342133+angelrenefm@users.noreply.github.com> Date: Sat, 14 Nov 2026 01:13:26 +0100 Subject: [PATCH 08/21] media: s5p-mfc: offer only H.264 decode on MFC v15 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On the Pixel 7's MFC v15.6 only H.264 has been made to work. The firmware refuses to open an instance for MPEG-1, MPEG-2, MPEG-4, H.263, VP8 and VP9 (OPEN_INSTANCE returns error 0x35, then REQBUFS fails with EIO), and HEVC opens but every frame comes back with a decode error. Each was tried with FFmpeg's *_v4l2m2m decoder on a short clip. Advertising them anyway breaks playback: GStreamer ranks its V4L2 decoders above the software ones, picks v4l2vp9dec for a VP9 file, and the pipeline fails instead of falling back to vp9dec. Leave every compressed format but H.264 out of the v15 list, H.264 MVC included, which wasn't tried. Assisted-by: LLM Signed-off-by: Ángel René <17342133+angelrenefm@users.noreply.github.com> --- .../platform/samsung/s5p-mfc/s5p_mfc_dec.c | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c index 653f7efa68..d26bafe4d7 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c @@ -84,7 +84,7 @@ static const struct s5p_mfc_fmt formats[] = { .codec_mode = S5P_MFC_CODEC_H264_MVC_DEC, .type = MFC_FMT_DEC, .num_planes = 1, - .versions = MFC_V6PLUS_BITS, + .versions = (MFC_V6PLUS_BITS & ~MFC_V15_BIT), .flags = V4L2_FMT_FLAG_DYN_RESOLUTION | V4L2_FMT_FLAG_CONTINUOUS_BYTESTREAM, }, @@ -93,7 +93,7 @@ static const struct s5p_mfc_fmt formats[] = { .codec_mode = S5P_MFC_CODEC_H263_DEC, .type = MFC_FMT_DEC, .num_planes = 1, - .versions = MFC_V5PLUS_BITS, + .versions = (MFC_V5PLUS_BITS & ~MFC_V15_BIT), .flags = V4L2_FMT_FLAG_DYN_RESOLUTION, }, { @@ -101,7 +101,7 @@ static const struct s5p_mfc_fmt formats[] = { .codec_mode = S5P_MFC_CODEC_MPEG2_DEC, .type = MFC_FMT_DEC, .num_planes = 1, - .versions = MFC_V5PLUS_BITS, + .versions = (MFC_V5PLUS_BITS & ~MFC_V15_BIT), .flags = V4L2_FMT_FLAG_DYN_RESOLUTION | V4L2_FMT_FLAG_CONTINUOUS_BYTESTREAM, }, @@ -110,7 +110,7 @@ static const struct s5p_mfc_fmt formats[] = { .codec_mode = S5P_MFC_CODEC_MPEG2_DEC, .type = MFC_FMT_DEC, .num_planes = 1, - .versions = MFC_V5PLUS_BITS, + .versions = (MFC_V5PLUS_BITS & ~MFC_V15_BIT), .flags = V4L2_FMT_FLAG_DYN_RESOLUTION | V4L2_FMT_FLAG_CONTINUOUS_BYTESTREAM, }, @@ -119,7 +119,7 @@ static const struct s5p_mfc_fmt formats[] = { .codec_mode = S5P_MFC_CODEC_MPEG4_DEC, .type = MFC_FMT_DEC, .num_planes = 1, - .versions = MFC_V5PLUS_BITS, + .versions = (MFC_V5PLUS_BITS & ~MFC_V15_BIT), .flags = V4L2_FMT_FLAG_DYN_RESOLUTION | V4L2_FMT_FLAG_CONTINUOUS_BYTESTREAM, }, @@ -128,7 +128,7 @@ static const struct s5p_mfc_fmt formats[] = { .codec_mode = S5P_MFC_CODEC_MPEG4_DEC, .type = MFC_FMT_DEC, .num_planes = 1, - .versions = MFC_V5PLUS_BITS, + .versions = (MFC_V5PLUS_BITS & ~MFC_V15_BIT), .flags = V4L2_FMT_FLAG_DYN_RESOLUTION, }, { @@ -136,7 +136,7 @@ static const struct s5p_mfc_fmt formats[] = { .codec_mode = S5P_MFC_CODEC_VC1_DEC, .type = MFC_FMT_DEC, .num_planes = 1, - .versions = MFC_V5PLUS_BITS, + .versions = (MFC_V5PLUS_BITS & ~MFC_V15_BIT), .flags = V4L2_FMT_FLAG_DYN_RESOLUTION, }, { @@ -144,7 +144,7 @@ static const struct s5p_mfc_fmt formats[] = { .codec_mode = S5P_MFC_CODEC_VC1RCV_DEC, .type = MFC_FMT_DEC, .num_planes = 1, - .versions = MFC_V5PLUS_BITS, + .versions = (MFC_V5PLUS_BITS & ~MFC_V15_BIT), .flags = V4L2_FMT_FLAG_DYN_RESOLUTION, }, { @@ -152,7 +152,7 @@ static const struct s5p_mfc_fmt formats[] = { .codec_mode = S5P_MFC_CODEC_VP8_DEC, .type = MFC_FMT_DEC, .num_planes = 1, - .versions = MFC_V6PLUS_BITS, + .versions = (MFC_V6PLUS_BITS & ~MFC_V15_BIT), .flags = V4L2_FMT_FLAG_DYN_RESOLUTION, }, { @@ -160,7 +160,7 @@ static const struct s5p_mfc_fmt formats[] = { .codec_mode = S5P_FIMV_CODEC_HEVC_DEC, .type = MFC_FMT_DEC, .num_planes = 1, - .versions = MFC_V10PLUS_BITS, + .versions = (MFC_V10PLUS_BITS & ~MFC_V15_BIT), .flags = V4L2_FMT_FLAG_DYN_RESOLUTION | V4L2_FMT_FLAG_CONTINUOUS_BYTESTREAM, }, @@ -169,7 +169,7 @@ static const struct s5p_mfc_fmt formats[] = { .codec_mode = S5P_FIMV_CODEC_VP9_DEC, .type = MFC_FMT_DEC, .num_planes = 1, - .versions = MFC_V10PLUS_BITS, + .versions = (MFC_V10PLUS_BITS & ~MFC_V15_BIT), .flags = V4L2_FMT_FLAG_DYN_RESOLUTION, }, }; From c2411138ebe78f533aa5dfc42535bbd0bb2d0716 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Ren=C3=A9?= <17342133+angelrenefm@users.noreply.github.com> Date: Sat, 14 Nov 2026 11:43:52 +0100 Subject: [PATCH 09/21] media: s5p-mfc: report the clamped OUTPUT buffer size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit S_FMT on the OUTPUT queue caps the bitstream buffer at the variant's CPB size, but hands the application back the size it asked for. The buffers then come out smaller than the format says. GStreamer asks for width * height for a 4K H.264 stream (8294400 bytes), the MFC v15 caps it at 7 MiB, and v4l2h264dec gives up with "buffer size 7340032 is smaller then negotiated size 8294400" and "Failed to allocate required memory". Return the clamped size, as the default branch already does. On the Pixel 7 a 3840x2160 High profile clip then decodes in full and its frames match FFmpeg's software decoder bit for bit. Assisted-by: LLM Signed-off-by: Ángel René <17342133+angelrenefm@users.noreply.github.com> --- drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c index d26bafe4d7..cfc1694e72 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c @@ -476,6 +476,7 @@ static int vidioc_s_fmt(struct file *file, void *priv, struct v4l2_format *f) ctx->dec_src_buf_size = buf_size->cpb; else ctx->dec_src_buf_size = pix_mp->plane_fmt[0].sizeimage; + pix_mp->plane_fmt[0].sizeimage = ctx->dec_src_buf_size; pix_mp->plane_fmt[0].bytesperline = 0; ctx->state = MFCINST_INIT; ret = 0; From e47e9332478388fad5c636ba60c12cf84d8d5a05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Ren=C3=A9?= <17342133+angelrenefm@users.noreply.github.com> Date: Sat, 14 Nov 2026 12:33:53 +0100 Subject: [PATCH 10/21] media: s5p-mfc: report the coded format flags in ENUM_FMT MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The decoder's format table sets V4L2_FMT_FLAG_DYN_RESOLUTION and V4L2_FMT_FLAG_CONTINUOUS_BYTESTREAM on the coded formats, but vidioc_enum_fmt() only copies the fourcc, so applications never see them. GStreamer's v4l2 decoders read DYN_RESOLUTION to know that the driver sends V4L2_EVENT_SOURCE_CHANGE once the header is parsed. Without it, v4l2h264dec sets up the CAPTURE queue on its own, then takes that first event for a resolution change in the middle of the stream. It stays marked as draining, and the next flush (a seek) throws the CAPTURE pool away and asks for a new one. Copy the flags. Assisted-by: LLM Signed-off-by: Ángel René <17342133+angelrenefm@users.noreply.github.com> --- drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c index cfc1694e72..e151b5a397 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c @@ -327,6 +327,7 @@ static int vidioc_enum_fmt(struct file *file, struct v4l2_fmtdesc *f, if (i == ARRAY_SIZE(formats)) return -EINVAL; f->pixelformat = formats[i].fourcc; + f->flags = formats[i].flags; return 0; } From 8e7f03b0bfcba08344308a8ee6bdbc7b8466899f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Ren=C3=A9?= <17342133+angelrenefm@users.noreply.github.com> Date: Sat, 14 Nov 2026 12:33:54 +0100 Subject: [PATCH 11/21] media: s5p-mfc: don't lose the FRAME_DONE that stop_streaming waits for MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a queue is stopped while the context's frame is being decoded, stop_streaming() sets MFCINST_ABORT and waits for FRAME_DONE. The interrupt handler of that frame wakes the context up, releases the hardware and calls try_run, which picks the same context again because its work bit is still set. try_run clears the context's interrupt flags before finding nothing to run in MFCINST_ABORT, so the waiter finds no FRAME_DONE and the STREAMOFF stalls for the full two second timeout, logging "Interrupt (ctx->int_type:0, command:13) timed out". Clear the work bit together with setting MFCINST_ABORT. On the Pixel 7 every seek in GStreamer took two seconds and logged that timeout; with this, three runs of two seeks each logged none and resumed at once. Assisted-by: LLM Signed-off-by: Ángel René <17342133+angelrenefm@users.noreply.github.com> --- drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c index e151b5a397..3d10dcccf9 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c @@ -1125,6 +1125,14 @@ static void s5p_mfc_stop_streaming(struct vb2_queue *q) ctx->state == MFCINST_RUNNING) && dev->curr_ctx == ctx->num && dev->hw_lock) { ctx->state = MFCINST_ABORT; + /* + * Take the context off the run queue. Otherwise the interrupt + * handler of the frame being decoded picks it again in + * try_run, which clears the context's interrupt flags before + * finding nothing to run in MFCINST_ABORT, and the wait below + * misses that FRAME_DONE and times out. + */ + clear_work_bit(ctx); spin_unlock_irqrestore(&dev->irqlock, flags); s5p_mfc_wait_for_done_ctx(ctx, S5P_MFC_R2H_CMD_FRAME_DONE_RET, 0); From 2cbf7aab253ab5cac4942183ab9cbb24c852e2e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Ren=C3=A9?= <17342133+angelrenefm@users.noreply.github.com> Date: Sat, 14 Nov 2026 13:47:52 +0100 Subject: [PATCH 12/21] media: s5p-mfc: raise the MFC clock while it is in use on MFC v15 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The bootloader leaves the Pixel 7's MFC at 100 MHz. Decoding only, that gives about 22 fps for 3840x2160 H.264 and 64 fps for 1080p, so 4K cannot play in real time. On gs201 the MFC rate is a DVFS domain of the ACPM firmware, which sets the voltage along with it. Let a variant name the rate to ask of its first clock while the MFC is powered on, and put the previous rate back at power off. MFC v15 asks for 666 MHz, the top of Google's gs201 mfc_freqs table. On the Pixel 7, with the clock below in the device tree: the rate reads 666 MHz while decoding and 100 MHz again afterwards; decoding only, the 4K clip runs at about 70 fps and the 1080p one at about 280 fps; the 4K clip plays on screen through glimagesink at 30 fps with no frame dropped (44 shown and 72 dropped before); and the 300 4K frames and the 1800 frames of a 60 s 1080p clip match FFmpeg's software decoder bit for bit. Assisted-by: LLM Signed-off-by: Ángel René <17342133+angelrenefm@users.noreply.github.com> --- .../media/platform/samsung/s5p-mfc/s5p_mfc.c | 2 ++ .../platform/samsung/s5p-mfc/s5p_mfc_common.h | 2 ++ .../platform/samsung/s5p-mfc/s5p_mfc_pm.c | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c index 94e75fc4d7..296723d721 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c @@ -1772,6 +1772,8 @@ static const struct s5p_mfc_variant mfc_drvdata_v15 = { .clk_names = {"mfc"}, .num_clocks = 1, .clocks_optional = true, + /* The top MFC rate of Google's gs201 tables (mfc_freqs) */ + .active_clk_rate = 666000000, }; static const struct of_device_id exynos_mfc_match[] = { diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_common.h b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_common.h index 98ab487bd9..a10cc406c4 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_common.h +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_common.h @@ -199,6 +199,7 @@ struct s5p_mfc_pm { struct clk *clocks[MFC_MAX_CLOCKS]; int num_clocks; bool use_clock_gating; + unsigned long idle_clk_rate; struct device *device; }; @@ -235,6 +236,7 @@ struct s5p_mfc_variant { int num_clocks; bool use_clock_gating; bool clocks_optional; + unsigned long active_clk_rate; }; /** diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_pm.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_pm.c index d60a04b5a7..47107b16c2 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_pm.c +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_pm.c @@ -84,6 +84,20 @@ int s5p_mfc_power_on(struct s5p_mfc_dev *dev) } } + /* + * Run at the variant's rate while the MFC is in use. The bootloader + * leaves the GS201 MFC at 100 MHz, a quarter of what 4K needs. + */ + if (dev->variant->active_clk_rate && dev->pm.clocks[0]) { + dev->pm.idle_clk_rate = clk_get_rate(dev->pm.clocks[0]); + ret = clk_set_rate(dev->pm.clocks[0], + dev->variant->active_clk_rate); + if (ret) + mfc_err("Failed to set the MFC clock to %lu Hz: %d\n", + dev->variant->active_clk_rate, ret); + ret = 0; + } + /* prepare for software clock gating */ clk_disable(dev->pm.clock_gate); @@ -102,6 +116,11 @@ int s5p_mfc_power_off(struct s5p_mfc_dev *dev) /* finish software clock gating */ clk_enable(dev->pm.clock_gate); + if (dev->pm.idle_clk_rate) { + clk_set_rate(dev->pm.clocks[0], dev->pm.idle_clk_rate); + dev->pm.idle_clk_rate = 0; + } + for (i = 0; i < dev->pm.num_clocks; i++) clk_disable_unprepare(dev->pm.clocks[i]); From 8bdfda16af81e13814b5e4ddbda2214325c5a4ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Ren=C3=A9?= <17342133+angelrenefm@users.noreply.github.com> Date: Sat, 14 Nov 2026 14:37:20 +0100 Subject: [PATCH 13/21] media: s5p-mfc: let the CAPTURE format be set while OUTPUT streams MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The decoder's S_FMT returns EBUSY when either queue is streaming. The stateful decoder interface (dev-decoder.rst, "Capture Setup") has the client set the CAPTURE format after the source change event, while the OUTPUT queue keeps streaming, and Chromium's V4L2 decoder does exactly that: its S_FMT on CAPTURE failed with "vidioc_s_fmt queue busy" and it gave up on the stream. Only refuse a format change on the queue that is streaming. Assisted-by: LLM Signed-off-by: Ángel René <17342133+angelrenefm@users.noreply.github.com> --- drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c index 3d10dcccf9..31ddaf0745 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c @@ -453,7 +453,13 @@ static int vidioc_s_fmt(struct file *file, void *priv, struct v4l2_format *f) pix_mp = &f->fmt.pix_mp; if (ret) return ret; - if (vb2_is_streaming(&ctx->vq_src) || vb2_is_streaming(&ctx->vq_dst)) { + /* + * Each queue's format is fixed only while that queue streams: the + * stateful decoder interface has the client set the CAPTURE format + * after the source change event, with OUTPUT still streaming. + */ + if (vb2_is_streaming(f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ? + &ctx->vq_dst : &ctx->vq_src)) { v4l2_err(&dev->v4l2_dev, "%s queue busy\n", __func__); ret = -EBUSY; goto out; From d944a4812196c93d0ce61b84b33d8157de0abffa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Ren=C3=A9?= <17342133+angelrenefm@users.noreply.github.com> Date: Sat, 14 Nov 2026 14:37:31 +0100 Subject: [PATCH 14/21] media: s5p-mfc: set the DPB plane sizes for every frame on MFC v15 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With dynamic DPB the plane sizes and strides are only written at INIT_BUFFERS. Under Chromium's V4L2 decoder the first frame decodes, but at the second one those registers read back as 0 and the firmware fails it with error 57, INSUFFICIENT_DPB_SIZE (the name in Google's exynos-mfc driver). The same stream through GStreamer never shows it. Write the sizes and strides again before every frame, next to the frame's DPB addresses. Assisted-by: LLM Signed-off-by: Ángel René <17342133+angelrenefm@users.noreply.github.com> --- .../platform/samsung/s5p-mfc/s5p_mfc_opr_v6.c | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr_v6.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr_v6.c index 770e3e8617..27bc562002 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr_v6.c +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr_v6.c @@ -603,6 +603,15 @@ static int s5p_mfc_set_dec_stream_buffer_v6(struct s5p_mfc_ctx *ctx, return 0; } +/* DPB plane sizes */ +static void s5p_mfc_set_dec_dpb_size(struct s5p_mfc_ctx *ctx) +{ + const struct s5p_mfc_regs *mfc_regs = ctx->dev->mfc_regs; + + writel(ctx->luma_size, mfc_regs->d_first_plane_dpb_size); + writel(ctx->chroma_size, mfc_regs->d_second_plane_dpb_size); +} + /* Set decoding frame buffer */ static int s5p_mfc_set_dec_frame_buffer_v6(struct s5p_mfc_ctx *ctx) { @@ -622,8 +631,7 @@ static int s5p_mfc_set_dec_frame_buffer_v6(struct s5p_mfc_ctx *ctx) mfc_debug(2, "Setting display delay to %d\n", ctx->display_delay); writel(ctx->total_dpb_count, mfc_regs->d_num_dpb); - writel(ctx->luma_size, mfc_regs->d_first_plane_dpb_size); - writel(ctx->chroma_size, mfc_regs->d_second_plane_dpb_size); + s5p_mfc_set_dec_dpb_size(ctx); if (ctx->dst_fmt->fourcc == V4L2_PIX_FMT_YUV420M || ctx->dst_fmt->fourcc == V4L2_PIX_FMT_YVU420M) writel(ctx->chroma_size_1, mfc_regs->d_third_plane_dpb_size); @@ -1866,6 +1874,21 @@ static void s5p_mfc_set_dynamic_dpb_v15(struct s5p_mfc_ctx *ctx) u32 set = 0; int i; + /* + * The plane sizes and strides set at INIT_BUFFERS don't always last + * until the next frame (under Chromium they read back as 0 at the + * second one), and the firmware then fails the frame with + * INSUFFICIENT_DPB_SIZE. Set them again for every frame. + */ + s5p_mfc_set_dec_dpb_size(ctx); + writel(ctx->stride[0], mfc_regs->d_first_plane_dpb_stride_size); + writel(ctx->stride[1], mfc_regs->d_second_plane_dpb_stride_size); + if (ctx->dst_fmt->fourcc == V4L2_PIX_FMT_YUV420M || + ctx->dst_fmt->fourcc == V4L2_PIX_FMT_YVU420M) { + writel(ctx->chroma_size_1, mfc_regs->d_third_plane_dpb_size); + writel(ctx->stride[2], mfc_regs->d_third_plane_dpb_stride_size); + } + buf = s5p_mfc_search_dynamic_dpb_v15(ctx); if (buf) { i = buf->b->vb2_buf.index; From 0ee10babf3d3414659dbacd443ea3611cb427481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Ren=C3=A9?= <17342133+angelrenefm@users.noreply.github.com> Date: Sat, 14 Nov 2026 14:37:43 +0100 Subject: [PATCH 15/21] media: s5p-mfc: decode to single-buffer NV12 on MFC v15 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The decoder only offers multi-planar formats (NV12M and friends), each plane in a buffer of its own. Chromium's V4L2 decoder renders NV12 in one buffer without a copy; for NM12 it sets up an image processor first, and on the Pixel 7 it got no further than that. Offer V4L2_PIX_FMT_NV12 on MFC v15, laid out as V4L2 has it: a 64 byte aligned stride, as Google's NV12N, and the chroma right after the luma's bytesperline * height. The MFC is given the luma address and the chroma one inside the same buffer. The firmware still wants its 64 bytes after each plane (it reports 2089024 and 1044544 bytes as the least for 1920x1088, and fails frames with INSUFFICIENT_DPB_SIZE below that), so the plane sizes it is told include them, and the buffer ends 64 bytes after the chroma. Work the sizes out again when the CAPTURE format changes after the header was parsed, as Chromium does, and count the CAPTURE planes with mem_planes rather than comp_planes. On the Pixel 7, with this format only offered: GStreamer's v4l2h264dec decodes a 20 s and a 60 s 1080p clip (2400 frames) to the same frames as avdec_h264. With all formats offered, GStreamer keeps NV12M and its 2700 frames still match; Chromium 156 (AcceleratedVideoDecoder enabled) plays a 1080p30 clip at 30 fps with no frame dropped and spends 6.8 s of CPU time per 10 s of video, against 9.9 s decoding in software. Assisted-by: LLM Signed-off-by: Ángel René <17342133+angelrenefm@users.noreply.github.com> --- .../media/platform/samsung/s5p-mfc/s5p_mfc.c | 4 +++ .../platform/samsung/s5p-mfc/s5p_mfc_common.h | 3 ++ .../platform/samsung/s5p-mfc/s5p_mfc_dec.c | 33 ++++++++++++++++--- .../platform/samsung/s5p-mfc/s5p_mfc_opr_v6.c | 33 ++++++++++++++++--- 4 files changed, 65 insertions(+), 8 deletions(-) diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c index 296723d721..821a1af6d3 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c @@ -356,6 +356,10 @@ static void s5p_mfc_handle_frame_new(struct s5p_mfc_ctx *ctx, unsigned int err) ctx->luma_size); vb2_set_plane_payload(&dst_buf->b->vb2_buf, 1, ctx->chroma_size); + /* NV12 in one buffer: plane 0 holds the whole frame */ + if (ctx->dst_fmt->num_planes == 1) + vb2_set_plane_payload(&dst_buf->b->vb2_buf, 0, + s5p_mfc_dec_nv12_size(ctx)); clear_bit(dst_buf->b->vb2_buf.index, &ctx->dec_dst_flag); diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_common.h b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_common.h index a10cc406c4..8abf5104e0 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_common.h +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_common.h @@ -226,6 +226,9 @@ struct s5p_mfc_buf_size { const void *priv; }; +struct s5p_mfc_ctx; +size_t s5p_mfc_dec_nv12_size(const struct s5p_mfc_ctx *ctx); + struct s5p_mfc_variant { unsigned int version; unsigned int port_num; diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c index 31ddaf0745..f37347e398 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c @@ -70,6 +70,13 @@ static const struct s5p_mfc_fmt formats[] = { .num_planes = 3, .versions = MFC_V12_BIT | MFC_V15_BIT }, + { + .fourcc = V4L2_PIX_FMT_NV12, + .codec_mode = S5P_FIMV_CODEC_NONE, + .type = MFC_FMT_RAW, + .num_planes = 1, + .versions = MFC_V15_BIT, + }, { .fourcc = V4L2_PIX_FMT_H264, .codec_mode = S5P_MFC_CODEC_H264_DEC, @@ -378,6 +385,9 @@ static int vidioc_g_fmt(struct file *file, void *priv, struct v4l2_format *f) pix_mp->plane_fmt[0].sizeimage = ctx->luma_size; pix_mp->plane_fmt[1].bytesperline = ctx->stride[1]; pix_mp->plane_fmt[1].sizeimage = ctx->chroma_size; + /* NV12 in one buffer: the chroma follows the luma */ + if (ctx->dst_fmt->num_planes == 1) + pix_mp->plane_fmt[0].sizeimage = s5p_mfc_dec_nv12_size(ctx); if (ctx->dst_fmt->fourcc == V4L2_PIX_FMT_YUV420M || ctx->dst_fmt->fourcc == V4L2_PIX_FMT_YVU420M) { pix_mp->plane_fmt[2].bytesperline = ctx->stride[2]; @@ -467,6 +477,13 @@ static int vidioc_s_fmt(struct file *file, void *priv, struct v4l2_format *f) if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { /* dst_fmt is validated by call to vidioc_try_fmt */ ctx->dst_fmt = find_format(f, MFC_FMT_RAW); + /* + * After the header was parsed the plane sizes were worked out + * for the old format; NV12 in one buffer lays them out + * differently, so work them out again. + */ + if (ctx->state == MFCINST_HEAD_PARSED) + s5p_mfc_hw_call(dev->mfc_ops, dec_calc_dpb_size, ctx); ret = 0; goto out; } else if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { @@ -969,7 +986,7 @@ static int s5p_mfc_queue_setup(struct vb2_queue *vq, mfc_err("invalid format\n"); return -EINVAL; } - *plane_count = format->comp_planes; + *plane_count = format->mem_planes; /* Setup buffer count */ if (*buf_count < ctx->pb_count) @@ -990,6 +1007,8 @@ static int s5p_mfc_queue_setup(struct vb2_queue *vq, vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { psize[0] = ctx->luma_size; psize[1] = ctx->chroma_size; + if (ctx->dst_fmt->num_planes == 1) + psize[0] = s5p_mfc_dec_nv12_size(ctx); if (ctx->dst_fmt->fourcc == V4L2_PIX_FMT_YUV420M || ctx->dst_fmt->fourcc == V4L2_PIX_FMT_YVU420M) psize[2] = ctx->chroma_size_1; @@ -1054,8 +1073,10 @@ static int s5p_mfc_buf_init(struct vb2_buffer *vb) return -EINVAL; } } - if (vb2_plane_size(vb, 0) < ctx->luma_size || - vb2_plane_size(vb, 1) < ctx->chroma_size) { + if (ctx->dst_fmt->num_planes == 1 ? + vb2_plane_size(vb, 0) < s5p_mfc_dec_nv12_size(ctx) : + vb2_plane_size(vb, 0) < ctx->luma_size || + vb2_plane_size(vb, 1) < ctx->chroma_size) { mfc_err("Plane buffer (CAPTURE) is too small\n"); return -EINVAL; } @@ -1071,7 +1092,11 @@ static int s5p_mfc_buf_init(struct vb2_buffer *vb) ctx->dst_bufs[i].b = vbuf; ctx->dst_bufs[i].cookie.raw.luma = vb2_dma_contig_plane_dma_addr(vb, 0); - ctx->dst_bufs[i].cookie.raw.chroma = + if (ctx->dst_fmt->num_planes == 1) + ctx->dst_bufs[i].cookie.raw.chroma = + ctx->dst_bufs[i].cookie.raw.luma + ctx->luma_size; + else + ctx->dst_bufs[i].cookie.raw.chroma = vb2_dma_contig_plane_dma_addr(vb, 1); if (ctx->dst_fmt->fourcc == V4L2_PIX_FMT_YUV420M || ctx->dst_fmt->fourcc == V4L2_PIX_FMT_YVU420M) { diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr_v6.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr_v6.c index 27bc562002..3f1e6e694f 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr_v6.c +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr_v6.c @@ -483,6 +483,12 @@ static int calc_plane(int width, int height) (mbY * S5P_FIMV_NUM_PIXELS_IN_MB_ROW_V6); } +/* Bytes of a one-buffer NV12 frame: both planes and the firmware's margin */ +size_t s5p_mfc_dec_nv12_size(const struct s5p_mfc_ctx *ctx) +{ + return ctx->luma_size + ctx->chroma_size + S5P_FIMV_D_ALIGN_PLANE_SIZE_V8; +} + static void s5p_mfc_dec_calc_dpb_size_v6(struct s5p_mfc_ctx *ctx) { struct s5p_mfc_dev *dev = ctx->dev; @@ -494,6 +500,18 @@ static void s5p_mfc_dec_calc_dpb_size_v6(struct s5p_mfc_ctx *ctx) ctx->img_height, ctx->buf_width, ctx->buf_height); switch (ctx->dst_fmt->fourcc) { + case V4L2_PIX_FMT_NV12: + /* + * One buffer, laid out as V4L2 NV12: the chroma starts right + * after the luma's bytesperline * height, so no padding goes + * between the planes (as Google's NV12N: 64 byte stride, + * height aligned to 16). + */ + ctx->stride[0] = ALIGN(ctx->img_width, 64); + ctx->stride[1] = ctx->stride[0]; + ctx->luma_size = ctx->stride[0] * ctx->buf_height; + ctx->chroma_size = ctx->stride[1] * ctx->buf_height / 2; + break; case V4L2_PIX_FMT_NV12M: case V4L2_PIX_FMT_NV21M: ctx->stride[0] = ALIGN(ctx->img_width, S5P_FIMV_NV12MT_HALIGN_V6); @@ -512,7 +530,7 @@ static void s5p_mfc_dec_calc_dpb_size_v6(struct s5p_mfc_ctx *ctx) break; } - if (IS_MFCV8_PLUS(ctx->dev)) { + if (IS_MFCV8_PLUS(ctx->dev) && ctx->dst_fmt->num_planes > 1) { /* MFCv8 needs additional 64 bytes for luma,chroma dpb*/ ctx->luma_size += S5P_FIMV_D_ALIGN_PLANE_SIZE_V8; ctx->chroma_size += S5P_FIMV_D_ALIGN_PLANE_SIZE_V8; @@ -603,13 +621,20 @@ static int s5p_mfc_set_dec_stream_buffer_v6(struct s5p_mfc_ctx *ctx, return 0; } -/* DPB plane sizes */ +/* + * DPB plane sizes. For NV12 in one buffer the firmware still wants its 64 + * bytes after each plane: the chroma starts right after the luma, as V4L2 + * NV12 has it, so the luma's margin is the chroma's first bytes, and the + * buffer ends with the chroma's margin. + */ static void s5p_mfc_set_dec_dpb_size(struct s5p_mfc_ctx *ctx) { const struct s5p_mfc_regs *mfc_regs = ctx->dev->mfc_regs; + unsigned int pad = ctx->dst_fmt->num_planes == 1 ? + S5P_FIMV_D_ALIGN_PLANE_SIZE_V8 : 0; - writel(ctx->luma_size, mfc_regs->d_first_plane_dpb_size); - writel(ctx->chroma_size, mfc_regs->d_second_plane_dpb_size); + writel(ctx->luma_size + pad, mfc_regs->d_first_plane_dpb_size); + writel(ctx->chroma_size + pad, mfc_regs->d_second_plane_dpb_size); } /* Set decoding frame buffer */ From f4722ab6076b085f18b4fe1647709351536ab03f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Ren=C3=A9?= <17342133+angelrenefm@users.noreply.github.com> Date: Sat, 14 Nov 2026 15:25:58 +0100 Subject: [PATCH 16/21] media: s5p-mfc: enumerate the coded frame sizes on MFC v15 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The decoder has no VIDIOC_ENUM_FRAMESIZES. Chromium's V4L2 decoder then assumes it handles up to 1920x1088, and decodes anything larger in software: a 3840x2160 H.264 clip played with the MFC left at its idle clock. Report a stepwise range up to 4096x2304, H.264 level 5.2's largest frame, on MFC v15. On the Pixel 7, Chromium then decodes that 4K clip on the MFC: no frame dropped over the 10 s, seeks included. Assisted-by: LLM Signed-off-by: Ángel René <17342133+angelrenefm@users.noreply.github.com> --- .../platform/samsung/s5p-mfc/s5p_mfc_dec.c | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c index f37347e398..d99efc15e5 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c @@ -350,6 +350,36 @@ static int vidioc_enum_fmt_vid_out(struct file *file, void *priv, return vidioc_enum_fmt(file, f, true); } +/* + * Coded sizes on MFC v15: up to H.264 level 5.2's largest frame. Without + * this, Chromium assumes 1920x1088 and decodes anything bigger in software. + */ +static int vidioc_enum_framesizes(struct file *file, void *priv, + struct v4l2_frmsizeenum *fsize) +{ + struct s5p_mfc_dev *dev = video_drvdata(file); + const struct s5p_mfc_fmt *fmt; + struct v4l2_format f = { + .type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, + .fmt.pix_mp.pixelformat = fsize->pixel_format, + }; + + if (!IS_MFCV15(dev) || fsize->index) + return -EINVAL; + fmt = find_format(&f, MFC_FMT_DEC); + if (!fmt || !(dev->variant->version_bit & fmt->versions)) + return -EINVAL; + + fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE; + fsize->stepwise.min_width = 32; + fsize->stepwise.max_width = 4096; + fsize->stepwise.step_width = 2; + fsize->stepwise.min_height = 32; + fsize->stepwise.max_height = 2304; + fsize->stepwise.step_height = 2; + return 0; +} + /* Get format */ static int vidioc_g_fmt(struct file *file, void *priv, struct v4l2_format *f) { @@ -938,6 +968,7 @@ static const struct v4l2_ioctl_ops s5p_mfc_dec_ioctl_ops = { .vidioc_querycap = vidioc_querycap, .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, .vidioc_enum_fmt_vid_out = vidioc_enum_fmt_vid_out, + .vidioc_enum_framesizes = vidioc_enum_framesizes, .vidioc_g_fmt_vid_cap_mplane = vidioc_g_fmt, .vidioc_g_fmt_vid_out_mplane = vidioc_g_fmt, .vidioc_try_fmt_vid_cap_mplane = vidioc_try_fmt, From 16d34cfa17f20cde2d362e6a1815607b9b42a624 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Ren=C3=A9?= <17342133+angelrenefm@users.noreply.github.com> Date: Sat, 14 Nov 2026 16:03:30 +0100 Subject: [PATCH 17/21] media: s5p-mfc: give MFC v15 the context buffer sizes of Google's driver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MFC v15 reused v12's instance context sizes, among them 30 KiB for the decoders other than H.264 and HEVC. Google's exynos-mfc driver for gs201 gives those 60 KiB, and 50 KiB to the HEVC and other encoders. With 30 KiB the firmware refuses to open an MPEG-2, VP8 or VP9 instance (OPEN_INSTANCE returns error 0x35). Use Google's sizes on v15. On the Pixel 7 those instances then open. Assisted-by: LLM Signed-off-by: Ángel René <17342133+angelrenefm@users.noreply.github.com> --- .../media/platform/samsung/s5p-mfc/regs-mfc-v15.h | 3 +++ drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/samsung/s5p-mfc/regs-mfc-v15.h b/drivers/media/platform/samsung/s5p-mfc/regs-mfc-v15.h index 4c4a8fe37a..84d756a3fa 100644 --- a/drivers/media/platform/samsung/s5p-mfc/regs-mfc-v15.h +++ b/drivers/media/platform/samsung/s5p-mfc/regs-mfc-v15.h @@ -33,6 +33,9 @@ #define MFC_NUM_PORTS_V15 1 #define MAX_FW_SIZE_V15 (SZ_1M) #define MAX_CPB_SIZE_V15 (7 * SZ_1M) +#define MFC_OTHER_DEC_CTX_BUF_SIZE_V15 (60 * SZ_1K) +#define MFC_HEVC_ENC_CTX_BUF_SIZE_V15 (50 * SZ_1K) +#define MFC_OTHER_ENC_CTX_BUF_SIZE_V15 (50 * SZ_1K) /* * The firmware rejects every buffer below its own base address, so the diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c index 821a1af6d3..bccf911120 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c @@ -1761,10 +1761,20 @@ static struct s5p_mfc_variant mfc_drvdata_v12 = { .num_clocks = 1, }; +/* Google's gs201 sizes (mfc_ctx_buf_size in its exynos-mfc driver) */ +static const struct s5p_mfc_buf_size_v6 mfc_buf_size_v15 = { + .dev_ctx = MFC_CTX_BUF_SIZE_V12, + .h264_dec_ctx = MFC_H264_DEC_CTX_BUF_SIZE_V12, + .other_dec_ctx = MFC_OTHER_DEC_CTX_BUF_SIZE_V15, + .h264_enc_ctx = MFC_H264_ENC_CTX_BUF_SIZE_V12, + .hevc_enc_ctx = MFC_HEVC_ENC_CTX_BUF_SIZE_V15, + .other_enc_ctx = MFC_OTHER_ENC_CTX_BUF_SIZE_V15, +}; + static const struct s5p_mfc_buf_size buf_size_v15 = { .fw = MAX_FW_SIZE_V15, .cpb = MAX_CPB_SIZE_V15, - .priv = &mfc_buf_size_v12, + .priv = &mfc_buf_size_v15, }; static const struct s5p_mfc_variant mfc_drvdata_v15 = { From de0537dd9f2db19531b98836f40b65ee33638928 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Ren=C3=A9?= <17342133+angelrenefm@users.noreply.github.com> Date: Sat, 14 Nov 2026 16:03:30 +0100 Subject: [PATCH 18/21] media: s5p-mfc: keep the frame that came with the header on MFC v15 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After the header is parsed, the driver only checks for H.264 whether the header's buffer holds more than the header, and treats the buffer as used up for every other codec. That buffer usually carries the first picture too: the first HEVC IRAP picture, and in VP8 and VP9 the header is the key frame itself. Dropping it, the firmware fails every HEVC frame with error 190 (SYNC_POINT_NOT_RECEIVED in Google's exynos-mfc driver) and every VP8/VP9 frame with error 34 (NO_KEY_FRAME). Check the consumed bytes for every codec on MFC v15. On the Pixel 7, HEVC, VP8 and VP9 clips then decode to the same frames as FFmpeg's and GStreamer's software decoders. Assisted-by: LLM Signed-off-by: Ángel René <17342133+angelrenefm@users.noreply.github.com> --- drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c index bccf911120..d3ac63b53b 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c @@ -566,8 +566,15 @@ static void s5p_mfc_handle_seq_done(struct s5p_mfc_ctx *ctx, v4l2_event_queue_fh(&ctx->fh, &ev_src_ch); } + /* + * The buffer the header came in may hold the first frame too. + * Keep it for decoding unless the header used it up: on MFC + * v15 for every codec, as the first HEVC IRAP picture and the + * first VP8/VP9 key frame share the header's buffer. + */ if ((ctx->codec_mode == S5P_MFC_CODEC_H264_DEC || - ctx->codec_mode == S5P_MFC_CODEC_H264_MVC_DEC) && + ctx->codec_mode == S5P_MFC_CODEC_H264_MVC_DEC || + IS_MFCV15(dev)) && !list_empty(&ctx->src_queue)) { struct s5p_mfc_buf *src_buf; From e030455bdbe035a4f3471c97288ed7c882888fcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Ren=C3=A9?= <17342133+angelrenefm@users.noreply.github.com> Date: Sat, 14 Nov 2026 16:03:31 +0100 Subject: [PATCH 19/21] media: s5p-mfc: offer VP8, VP9 and HEVC decode on MFC v15 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With the two previous commits these decode on the Pixel 7. Through FFmpeg's *_v4l2m2m decoders and through GStreamer's v4l2vp8dec, v4l2vp9dec and v4l2h265dec, every frame matches the software decoders (FFmpeg's, vp8dec, vp9dec, avdec_h265): VP9 1920x1080, 450 frames; VP9 3840x2160 (libvpx), 90 frames VP8 1280x720, 450 frames HEVC 1920x1080, 450 frames; HEVC 1920x1080 (x265), 90 frames Chromium 156 decodes the 1080p VP9 clip on the MFC with no frame dropped. MPEG-1/2/4, H.263, VC-1 and H.264 MVC stay off: MPEG-2 and H.263 decode with differences that were not checked further, and MPEG-4 fails to allocate its CAPTURE buffers. Assisted-by: LLM Signed-off-by: Ángel René <17342133+angelrenefm@users.noreply.github.com> --- drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c index d99efc15e5..beb6bc32ec 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c @@ -159,7 +159,7 @@ static const struct s5p_mfc_fmt formats[] = { .codec_mode = S5P_MFC_CODEC_VP8_DEC, .type = MFC_FMT_DEC, .num_planes = 1, - .versions = (MFC_V6PLUS_BITS & ~MFC_V15_BIT), + .versions = MFC_V6PLUS_BITS, .flags = V4L2_FMT_FLAG_DYN_RESOLUTION, }, { @@ -167,7 +167,7 @@ static const struct s5p_mfc_fmt formats[] = { .codec_mode = S5P_FIMV_CODEC_HEVC_DEC, .type = MFC_FMT_DEC, .num_planes = 1, - .versions = (MFC_V10PLUS_BITS & ~MFC_V15_BIT), + .versions = MFC_V10PLUS_BITS, .flags = V4L2_FMT_FLAG_DYN_RESOLUTION | V4L2_FMT_FLAG_CONTINUOUS_BYTESTREAM, }, @@ -176,7 +176,7 @@ static const struct s5p_mfc_fmt formats[] = { .codec_mode = S5P_FIMV_CODEC_VP9_DEC, .type = MFC_FMT_DEC, .num_planes = 1, - .versions = (MFC_V10PLUS_BITS & ~MFC_V15_BIT), + .versions = MFC_V10PLUS_BITS, .flags = V4L2_FMT_FLAG_DYN_RESOLUTION, }, }; From 47386c9467dad3b3c5d102f86d0a4cff1327c4de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Ren=C3=A9?= <17342133+angelrenefm@users.noreply.github.com> Date: Sat, 14 Nov 2026 19:47:24 +0100 Subject: [PATCH 20/21] media: s5p-mfc: leave capture buffers for display with dynamic DPB MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With dynamic DPB the firmware may keep its whole minimum DPB as references at once. A client that allocates only that minimum plus one or two buffers then has almost none left to display while the next frame decodes. Chromium allocates the driver's minimum plus 2: for a 3840x2160 VP9 clip on the Pixel 7 (minimum 10) it decoded at about 24 fps and dropped 131 of 468 frames at 30 fps. Give such clients at least four buffers more than the minimum. With it Chromium drops 4 of 582 frames of the same clip (looping, the drops are at the loop points), and H.264 3840x2160 still drops none. GStreamer's output stays bit-exact against vp9dec and avdec_h264 at 3840x2160. Assisted-by: LLM Signed-off-by: Ángel René <17342133+angelrenefm@users.noreply.github.com> --- drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c index beb6bc32ec..b7615ba8d0 100644 --- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c +++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c @@ -1022,6 +1022,12 @@ static int s5p_mfc_queue_setup(struct vb2_queue *vq, /* Setup buffer count */ if (*buf_count < ctx->pb_count) *buf_count = ctx->pb_count; + /* + * With dynamic DPB the firmware can hold all of its minimum + * at once; leave some for the client to display. + */ + if (dev->dynamic_dpb && *buf_count < ctx->pb_count + 4) + *buf_count = ctx->pb_count + 4; if (!dev->dynamic_dpb && *buf_count > ctx->pb_count + MFC_MAX_EXTRA_DPB) *buf_count = ctx->pb_count + MFC_MAX_EXTRA_DPB; From da2c0333c82b2e6df08cf5a0b6d86d86a905e40e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Ren=C3=A9?= <17342133+angelrenefm@users.noreply.github.com> Date: Sun, 15 Nov 2026 13:51:15 +0100 Subject: [PATCH 21/21] arm64: dts: exynos: google: gs201-panther: Give the MFC its memory pool MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Give panther's MFC its own reusable shared-dma-pool of 256 MiB below 4 GiB, and leave the node disabled. The driver takes its 64 MiB for the firmware, contexts and codec buffers from the pool, firmware first, and vb2 serves the OUTPUT and CAPTURE buffers from the rest. The firmware rejects any buffer below its own base, which a single pool rules out. 256 MiB is what a 4K stream needs: a 3840x2160 frame in single-buffer NV12 is 12.4 MiB in one block, and with 128 MiB next to the firmware GStreamer got no frame at all out of a 4K clip. The pool is reusable, so its pages serve movable allocations while nothing is decoded. The node stays disabled until its two System MMUs are described: in bypass, Google's closed firmware parsing untrusted video can reach all memory below 4 GiB. An overlay in omarchy-mobile (device/panther) enables it for owners who want hardware video. Tested on a Pixel 7 booting a DTB with this node and pool enabled, the driver built from this series as a module and the firmware taken from the phone's own OTA. The pool is reserved below 4 GiB and the driver probes from it on its own. H.264, HEVC, VP8 and VP9 decode bit-exact against FFmpeg's and GStreamer's software decoders (1080p and 4K), and Chromium plays 1080p and 4K H.264 and VP9 on the MFC. Assisted-by: LLM Signed-off-by: Ángel René <17342133+angelrenefm@users.noreply.github.com> --- .../boot/dts/exynos/google/gs201-panther.dts | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/arch/arm64/boot/dts/exynos/google/gs201-panther.dts b/arch/arm64/boot/dts/exynos/google/gs201-panther.dts index 25594305a5..9986f4a90b 100644 --- a/arch/arm64/boot/dts/exynos/google/gs201-panther.dts +++ b/arch/arm64/boot/dts/exynos/google/gs201-panther.dts @@ -125,6 +125,24 @@ reg = <0x0 0xfac00000 (1080 * 2400 * 4)>; no-map; }; + + /* + * MFC firmware, contexts and frames. The MFC takes 32-bit + * addresses, its System MMU is in bypass and the firmware + * rejects any buffer below its own base, so they all come from + * one contiguous pool below 4 GiB, firmware first. Reusable, + * so the pages serve movable allocations while no video is + * decoded. 256 MiB holds the firmware and a 4K stream decoded + * to single-buffer NV12. + */ + mfc_pool: mfc-pool { + compatible = "shared-dma-pool"; + reusable; + size = <0x10000000>; + /* read with the root's #address-cells (2), not #size-cells */ + alignment = <0x0 0x200000>; + alloc-ranges = <0x0 0x80000000 0x80000000>; + }; }; }; @@ -246,6 +264,16 @@ status = "okay"; }; +/* + * Left disabled until its two System MMUs are described: in bypass, the + * closed firmware parsing untrusted video can reach all memory below + * 4 GiB. omarchy-mobile's device/panther overlay enables it for owners who + * want hardware video. + */ +&mfc { + memory-region = <&mfc_pool>; +}; + &usbdrd31_phy { status = "okay"; };