From: Detlev Casanova <detlev.casanova@collabora.com>
To: Mauro Carvalho Chehab <mchehab@kernel.org>,
Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>,
Heiko Stuebner <heiko@sntech.de>,
Hans Verkuil <hverkuil+cisco@kernel.org>,
Jonas Karlman <jonas@kwiboo.se>,
Nicolas Dufresne <nicolas.dufresne@collabora.com>
Cc: "Sven Püschel" <s.pueschel@pengutronix.de>,
kernel@collabora.com, linux-media@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v2 4/5] media: rkvdec: Split into core and master platform drivers
Date: Mon, 30 Nov 2026 10:53:18 -0500 [thread overview]
Message-ID: <DHzDE1dLRbaR-tn1tg9ZoQ@collabora.com> (raw)
In-Reply-To: <c0e155b0a64e193572f33d13d58b2492ceafa601.camel@collabora.com>
Hello !
On Thursday, 19 November 2026 12:58:37 EST Nicolas Dufresne wrote:
> Hi,
>
> Le lundi 10 août 2026 à 11:22 -0400, Detlev Casanova a écrit :
> > Prepare the driver for multi-core support by restructuring around the
> > component framework, based on what rga does.
>
> Add a blank between paragraph.
>
> > This commit only adds the plumbing and does not yet enable more
> > than a single core to run (Each additionnal core adding will return
> > -EBUSY).
> >
[...]
> > diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.c
> > b/drivers/media/platform/rockchip/rkvdec/rkvdec-rcb.c index
> > 191f78278c01..44df5b6df80c 100644
[...]
> > @@ -77,12 +76,13 @@ void rkvdec_free_rcb(struct rkvdec_ctx *ctx)
> >
> > case RKVDEC_ALLOC_SRAM:
> > virt_addr = (unsigned long)cfg-
>rcb_bufs[i].cpu;
> >
> > - if (dev->iommu_domain)
> > - iommu_unmap(dev->iommu_domain,
virt_addr, rcb_size);
> > - gen_pool_free(dev->sram_pool, virt_addr,
rcb_size);
> > + if (iommu_get_domain_for_dev(core->dev))
> > +
iommu_unmap(iommu_get_domain_for_dev(core->dev),
> > + virt_addr,
rcb_size);
>
> Also, see
> https://lore.kernel.org/all/70ed0df5a04b11d8dcfe41d91e86fc28dedcb132.camel@c
> ollabora.com/ where I suggest to port to dma api. I mean, its not like the
> page table of SRAM is going to move, but I also don't see why we have to
> use iommu_map/unmap(), so if not, better clean that up now.
I'll add a separate commit to fix this and to be backported to stable versions.
> > + gen_pool_free(core->sram_pool, virt_addr,
rcb_size);
> >
> > break;
> >
> > case RKVDEC_ALLOC_DMA:
> > - dma_free_coherent(dev->dev,
> > + dma_free_coherent(rkvdec->main_core->dev,
> >
> > rcb_size,
> > cfg-
>rcb_bufs[i].cpu,
> > cfg-
>rcb_bufs[i].dma);
[...]
> > diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec.c
> > b/drivers/media/platform/rockchip/rkvdec/rkvdec.c index
> > db2731af06cf..d3b13132b751 100644
> > --- a/drivers/media/platform/rockchip/rkvdec/rkvdec.c
> > +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec.c
> > @@ -11,12 +11,14 @@
> >
> > #include <linux/hw_bitfield.h>
> > #include <linux/clk.h>
> >
> > +#include <linux/component.h>
> >
> > #include <linux/genalloc.h>
> > #include <linux/interrupt.h>
> > #include <linux/iommu.h>
> > #include <linux/module.h>
> > #include <linux/of.h>
> > #include <linux/of_device.h>
> >
> > +#include <linux/of_platform.h>
> >
> > #include <linux/platform_device.h>
> > #include <linux/pm.h>
> > #include <linux/pm_runtime.h>
> >
> > @@ -652,14 +654,11 @@ static int rkvdec_enum_framesizes(struct file *file,
> > void *priv,>
> > static int rkvdec_querycap(struct file *file, void *priv,
> >
> > struct v4l2_capability *cap)
> >
> > {
> >
> > - struct rkvdec_dev *rkvdec = video_drvdata(file);
> >
> > struct video_device *vdev = video_devdata(file);
> >
> > - strscpy(cap->driver, rkvdec->dev->driver->name,
> > - sizeof(cap->driver));
> > + strscpy(cap->driver, "rkvdec", sizeof(cap->driver));
> >
> > strscpy(cap->card, vdev->name, sizeof(cap->card));
> >
> > - snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
> > - rkvdec->dev->driver->name);
> > + snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:rkvdec");
> >
> > return 0;
> >
> > }
> >
> > @@ -1026,8 +1025,6 @@ static void rkvdec_stop_streaming(struct vb2_queue
> > *q)>
> > if (desc->ops->stop)
> >
> > desc->ops->stop(ctx);
> >
> > -
> > - rkvdec_free_rcb(ctx);
> >
> > }
> >
> > rkvdec_queue_cleanup(q, VB2_BUF_STATE_ERROR);
> >
> > @@ -1062,26 +1059,28 @@ static const struct media_device_ops
> > rkvdec_media_ops = {>
> > };
> >
> > static void rkvdec_job_finish_no_pm(struct rkvdec_ctx *ctx,
> >
> > - enum vb2_buffer_state result)
> > + enum vb2_buffer_state result)
> >
> > {
> >
> > + struct v4l2_m2m_ctx *m2m_ctx = ctx->fh.m2m_ctx;
> > + struct v4l2_m2m_dev *m2m_dev = m2m_ctx->m2m_dev;
> > +
> >
> > if (ctx->coded_fmt_desc->ops->done) {
> >
> > struct vb2_v4l2_buffer *src_buf, *dst_buf;
> >
> > - src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
> > - dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
> > + src_buf = v4l2_m2m_next_src_buf(m2m_ctx);
> > + dst_buf = v4l2_m2m_next_dst_buf(m2m_ctx);
> >
> > ctx->coded_fmt_desc->ops->done(ctx, src_buf, dst_buf,
result);
> >
> > }
> >
> > - v4l2_m2m_buf_done_and_job_finish(ctx->dev->m2m_dev, ctx-
>fh.m2m_ctx,
> > - result);
> > + v4l2_m2m_buf_done_and_job_finish(m2m_dev, m2m_ctx, result);
> >
> > }
> >
> > static void rkvdec_job_finish(struct rkvdec_ctx *ctx,
> >
> > - enum vb2_buffer_state result)
> > + enum vb2_buffer_state result)
> >
> > {
> >
> > - struct rkvdec_dev *rkvdec = ctx->dev;
> > + pm_runtime_mark_last_busy(ctx->core->dev);
> > + pm_runtime_put_autosuspend(ctx->core->dev);
>
> Since we modify its default domain, so basically call into the core0 iommu,
> should be also make sure core0 is up, or does the iommu driver handles it
> independently?
From what I checked, when the domain table stored in ram is written on its
devices, the function checks if the device is powered on before writing or
just skips it. (See rk_iommu_zap_iova())
When the device comes back on, the domain table is written on it from RAM.
> p.s. didn't take the time to check the DT here
>
> > - pm_runtime_put_autosuspend(rkvdec->dev);
> >
> > rkvdec_job_finish_no_pm(ctx, result);
> >
> > }
> >
> > @@ -1112,14 +1111,14 @@ void rkvdec_run_postamble(struct rkvdec_ctx *ctx,
> > struct rkvdec_run *run)>
> > void rkvdec_quirks_disable_qos(struct rkvdec_ctx *ctx)
> > {
> >
> > - struct rkvdec_dev *rkvdec = ctx->dev;
> > + struct rkvdec_core *core = ctx->core;
> >
> > u32 reg;
> >
> > /* Set undocumented swreg_block_gating_e field */
> >
> > - reg = readl(rkvdec->regs + RKVDEC_REG_QOS_CTRL);
> > + reg = readl(core->regs + RKVDEC_REG_QOS_CTRL);
> >
> > reg &= GENMASK(31, 16);
> > reg |= 0xEFFF;
> >
> > - writel(reg, rkvdec->regs + RKVDEC_REG_QOS_CTRL);
> > + writel(reg, core->regs + RKVDEC_REG_QOS_CTRL);
> >
> > }
> >
> > void rkvdec_memcpy_toio(void __iomem *dst, void *src, size_t len)
> >
> > @@ -1131,40 +1130,42 @@ void rkvdec_memcpy_toio(void __iomem *dst, void
> > *src, size_t len)>
> > #endif
> > }
> >
> > -void rkvdec_schedule_watchdog(struct rkvdec_dev *rkvdec, u32
> > timeout_threshold) +void rkvdec_schedule_watchdog(struct rkvdec_core
> > *core, u32 timeout_threshold)>
> > {
> >
> > /* Set watchdog at 2 times the hardware timeout threshold */
> > u32 watchdog_time;
> >
> > - unsigned long axi_rate = clk_get_rate(rkvdec->axi_clk);
> > + unsigned long axi_rate = clk_get_rate(core->axi_clk);
> >
> > if (axi_rate)
> >
> > watchdog_time = 2 * div_u64(1000 *
(u64)timeout_threshold, axi_rate);
> >
> > else
> >
> > watchdog_time = 2000;
> >
> > - schedule_delayed_work(&rkvdec->watchdog_work,
> > msecs_to_jiffies(watchdog_time));
> > + schedule_delayed_work(&core->watchdog_work,
> > msecs_to_jiffies(watchdog_time));>
> > }
> >
> > static void rkvdec_device_run(void *priv)
> > {
> >
> > struct rkvdec_ctx *ctx = priv;
> >
> > - struct rkvdec_dev *rkvdec = ctx->dev;
> >
> > const struct rkvdec_coded_fmt_desc *desc = ctx->coded_fmt_desc;
> > int ret;
> >
> > if (WARN_ON(!desc))
> >
> > return;
> >
> > - ret = pm_runtime_resume_and_get(rkvdec->dev);
> > + ctx->core = ctx->dev->main_core;
> > + ctx->core->curr_ctx = ctx;
> > +
> > + ret = pm_runtime_resume_and_get(ctx->core->dev);
> >
> > if (ret < 0) {
> >
> > rkvdec_job_finish_no_pm(ctx, VB2_BUF_STATE_ERROR);
> > return;
> >
> > }
> >
> > if (!rkvdec_rcb_buf_validate_size(ctx)) {
> >
> > - rkvdec_free_rcb(ctx);
> > + rkvdec_free_rcb(ctx->dev, ctx->core);
> >
> > - ret = rkvdec_allocate_rcb(ctx,
> > + ret = rkvdec_allocate_rcb(ctx->dev, ctx->core,
> >
> > ctx-
>decoded_fmt.fmt.pix_mp.width,
> > ctx-
>decoded_fmt.fmt.pix_mp.height,
> > ctx->dev->variant-
>rcb_sizes,
> >
> > @@ -1340,10 +1341,11 @@ static const struct v4l2_file_operations
> > rkvdec_fops = {>
> > static int rkvdec_v4l2_init(struct rkvdec_dev *rkvdec)
> > {
> >
> > int ret;
> >
> > + struct device *dev = rkvdec->main_core->dev;
> >
> > - ret = v4l2_device_register(rkvdec->dev, &rkvdec->v4l2_dev);
> > + ret = v4l2_device_register(dev, &rkvdec->v4l2_dev);
> >
> > if (ret) {
> >
> > - dev_err(rkvdec->dev, "Failed to register V4L2
device\n");
> > + dev_err(dev, "Failed to register V4L2 device\n");
> >
> > return ret;
> >
> > }
> >
> > @@ -1354,7 +1356,7 @@ static int rkvdec_v4l2_init(struct rkvdec_dev
> > *rkvdec)>
> > goto err_unregister_v4l2;
> >
> > }
> >
> > - rkvdec->mdev.dev = rkvdec->dev;
> > + rkvdec->mdev.dev = dev;
> >
> > strscpy(rkvdec->mdev.model, "rkvdec", sizeof(rkvdec->mdev.model));
> > strscpy(rkvdec->mdev.bus_info, "platform:rkvdec",
> >
> > sizeof(rkvdec->mdev.bus_info));
> >
> > @@ -1420,9 +1422,9 @@ static void rkvdec_v4l2_cleanup(struct rkvdec_dev
> > *rkvdec)>
> > v4l2_device_unregister(&rkvdec->v4l2_dev);
> >
> > }
> >
> > -static void rkvdec_iommu_restore(struct rkvdec_dev *rkvdec)
> > +static void rkvdec_iommu_restore(struct rkvdec_core *core)
> >
> > {
> >
> > - if (rkvdec->empty_domain) {
> > + if (core->empty_domain) {
> >
> > /*
> >
> > * To rewrite mapping into the attached IOMMU core,
attach a new empty
> > domain that * will program an empty table, then detach
it to restore
> > the default domain and>
> > @@ -1430,29 +1432,29 @@ static void rkvdec_iommu_restore(struct rkvdec_dev
> > *rkvdec)>
> > * This is safely done in this interrupt handler to
make sure no memory
> > get mapped * through the IOMMU while the empty domain
is attached.
> > */
> >
> > - iommu_attach_device(rkvdec->empty_domain, rkvdec->dev);
> > - iommu_detach_device(rkvdec->empty_domain, rkvdec->dev);
> > + iommu_attach_device(core->empty_domain, core->dev);
> > + iommu_detach_device(core->empty_domain, core->dev);
>
> On second core, that will restore the second core default domain, which is
> also empty. At least for the second core, you have to explicitly attach the
> main core default domain. It should be possible to just attach the empty
> domain, attach the main core default domain regardless.
Yes, but this commit only separate cores/master devices. It still will only
use the first core only (extra cores will not be in the list of cores). The
next commit takes care of multi core support.
> nit: Remember this is a hack, we should plan on having a call or ops into
> the rkiommu driver to signal that we (or the IP) operated a soft reset.
> > }
> >
> > }
> >
> > static irqreturn_t rk3399_irq_handler(struct rkvdec_ctx *ctx)
> > {
> >
> > - struct rkvdec_dev *rkvdec = ctx->dev;
> > + struct rkvdec_core *core = ctx->core;
> >
> > enum vb2_buffer_state state;
> > u32 status;
> >
> > - status = readl(rkvdec->regs + RKVDEC_REG_INTERRUPT);
> > - writel(0, rkvdec->regs + RKVDEC_REG_INTERRUPT);
> > + status = readl(core->regs + RKVDEC_REG_INTERRUPT);
> > + writel(0, core->regs + RKVDEC_REG_INTERRUPT);
> >
> > if (status & RKVDEC_RDY_STA) {
> >
> > state = VB2_BUF_STATE_DONE;
> >
> > } else {
> >
> > state = VB2_BUF_STATE_ERROR;
> > if (status & RKVDEC_SOFTRESET_RDY)
> >
> > - rkvdec_iommu_restore(rkvdec);
> > + rkvdec_iommu_restore(core);
> >
> > }
> >
> > - if (cancel_delayed_work(&rkvdec->watchdog_work))
> > + if (cancel_delayed_work(&core->watchdog_work))
> >
> > rkvdec_job_finish(ctx, state);
> >
> > return IRQ_HANDLED;
> >
> > @@ -1460,12 +1462,12 @@ static irqreturn_t rk3399_irq_handler(struct
> > rkvdec_ctx *ctx)>
> > static irqreturn_t vdpu381_irq_handler(struct rkvdec_ctx *ctx)
> > {
> >
> > - struct rkvdec_dev *rkvdec = ctx->dev;
> > + struct rkvdec_core *core = ctx->core;
> >
> > enum vb2_buffer_state state;
> > u32 status;
> >
> > - status = readl(rkvdec->regs + VDPU381_REG_STA_INT);
> > - writel(0, rkvdec->regs + VDPU381_REG_STA_INT);
> > + status = readl(core->regs + VDPU381_REG_STA_INT);
> > + writel(0, core->regs + VDPU381_REG_STA_INT);
> >
> > if (status & VDPU381_STA_INT_DEC_RDY_STA) {
> >
> > state = VB2_BUF_STATE_DONE;
> >
> > @@ -1474,10 +1476,10 @@ static irqreturn_t vdpu381_irq_handler(struct
> > rkvdec_ctx *ctx)>
> > if (status & (VDPU381_STA_INT_SOFTRESET_RDY |
> >
> > VDPU381_STA_INT_TIMEOUT |
> > VDPU381_STA_INT_ERROR))
> >
> > - rkvdec_iommu_restore(rkvdec);
> > + rkvdec_iommu_restore(core);
> >
> > }
> >
> > - if (cancel_delayed_work(&rkvdec->watchdog_work))
> > + if (cancel_delayed_work(&core->watchdog_work))
> >
> > rkvdec_job_finish(ctx, state);
> >
> > return IRQ_HANDLED;
> >
> > @@ -1485,24 +1487,24 @@ static irqreturn_t vdpu381_irq_handler(struct
> > rkvdec_ctx *ctx)>
> > static irqreturn_t vdpu383_irq_handler(struct rkvdec_ctx *ctx)
> > {
> >
> > - struct rkvdec_dev *rkvdec = ctx->dev;
> > + struct rkvdec_core *core = ctx->core;
> >
> > enum vb2_buffer_state state;
> > u32 status;
> >
> > - status = readl(rkvdec->link + VDPU383_LINK_STA_INT);
> > - writel(FIELD_PREP_WM16(VDPU383_STA_INT_ALL, 0), rkvdec->link +
> > VDPU383_LINK_STA_INT); + status = readl(core->link +
> > VDPU383_LINK_STA_INT);
> > + writel(FIELD_PREP_WM16(VDPU383_STA_INT_ALL, 0), core->link +
> > VDPU383_LINK_STA_INT);>
> > /* On vdpu383, the interrupts must be disabled */
> > writel(FIELD_PREP_WM16(VDPU383_INT_EN_IRQ |
VDPU383_INT_EN_LINE_IRQ, 0),
> >
> > - rkvdec->link + VDPU383_LINK_INT_EN);
> > + core->link + VDPU383_LINK_INT_EN);
> >
> > if (status & VDPU383_STA_INT_DEC_RDY_STA) {
> >
> > state = VB2_BUF_STATE_DONE;
> >
> > } else {
> >
> > state = VB2_BUF_STATE_ERROR;
> >
> > - rkvdec_iommu_restore(rkvdec);
> > + rkvdec_iommu_restore(core);
> >
> > }
> >
> > - if (cancel_delayed_work(&rkvdec->watchdog_work))
> > + if (cancel_delayed_work(&core->watchdog_work))
> >
> > rkvdec_job_finish(ctx, state);
> >
> > return IRQ_HANDLED;
> >
> > @@ -1510,11 +1512,14 @@ static irqreturn_t vdpu383_irq_handler(struct
> > rkvdec_ctx *ctx)>
> > static irqreturn_t rkvdec_irq_handler(int irq, void *priv)
> > {
> >
> > - struct rkvdec_dev *rkvdec = priv;
> > - struct rkvdec_ctx *ctx = v4l2_m2m_get_curr_priv(rkvdec->m2m_dev);
> > - const struct rkvdec_variant *variant = rkvdec->variant;
> > + irqreturn_t ret;
> > + struct rkvdec_core *core = priv;
> > + struct rkvdec_ctx *ctx = core->curr_ctx;
> > + const struct rkvdec_variant *variant = ctx->dev->variant;
> > +
> > + ret = variant->ops->irq_handler(ctx);
> >
> > - return variant->ops->irq_handler(ctx);
> > + return ret;
> >
> > }
> >
> > /*
> >
> > @@ -1591,62 +1596,19 @@ static void vdpu383_flatten_matrices(u8 *output,
> > const u8 *input, int matrices,>
> > static void rkvdec_watchdog_func(struct work_struct *work)
> > {
> >
> > - struct rkvdec_dev *rkvdec;
> > + struct rkvdec_core *core;
> >
> > struct rkvdec_ctx *ctx;
> >
> > - rkvdec = container_of(to_delayed_work(work), struct rkvdec_dev,
> > + core = container_of(to_delayed_work(work), struct rkvdec_core,
> >
> > watchdog_work);
> >
> > - ctx = v4l2_m2m_get_curr_priv(rkvdec->m2m_dev);
> > + ctx = core->curr_ctx;
> >
> > if (ctx) {
> >
> > - dev_err(rkvdec->dev, "Frame processing timed out!\n");
> > - writel(RKVDEC_IRQ_DIS, rkvdec->regs +
RKVDEC_REG_INTERRUPT);
> > + dev_err(core->dev, "Frame processing timed out!\n");
> > + writel(RKVDEC_IRQ_DIS, core->regs +
RKVDEC_REG_INTERRUPT);
> >
> > rkvdec_job_finish(ctx, VB2_BUF_STATE_ERROR);
> >
> > }
> >
> > }
> >
> > -/*
> > - * Some SoCs, like RK3588 have multiple identical VDPU cores, but the
> > - * kernel is currently missing support for multi-core handling. Exposing
> > - * separate devices for each core to userspace is bad, since that does
> > - * not allow scheduling tasks properly (and creates ABI). With this
> > workaround - * the driver will only probe for the first core and early
> > exit for the other - * cores. Once the driver gains multi-core support,
> > the same technique - * for detecting the first core can be used to
> > cluster all cores together. - */
> > -static int rkvdec_disable_multicore(struct rkvdec_dev *rkvdec)
> > -{
> > - struct device_node *node = NULL;
> > - const char *compatible;
> > - bool is_first_core;
> > - int ret;
> > -
> > - /* Intentionally ignores the fallback strings */
> > - ret = of_property_read_string(rkvdec->dev->of_node, "compatible",
> > &compatible); - if (ret)
> > - return ret;
> > -
> > - /* The first compatible and available node found is considered the
main
> > core */ - do {
> > - node = of_find_compatible_node(node, NULL, compatible);
> > - if (of_device_is_available(node))
> > - break;
> > - } while (node);
> > -
> > - if (!node)
> > - return -EINVAL;
> > -
> > - is_first_core = (rkvdec->dev->of_node == node);
> > -
> > - of_node_put(node);
> > -
> > - if (!is_first_core) {
> > - dev_info(rkvdec->dev, "missing multi-core support,
ignoring this
> > instance\n"); - return -ENODEV;
> > - }
> > -
> > - return 0;
> > -}
> > -
> >
> > static const struct rkvdec_variant_ops rk3399_variant_ops = {
> >
> > .irq_handler = rk3399_irq_handler,
> > .colmv_size = rkvdec_colmv_size,
> >
> > @@ -1757,49 +1719,75 @@ static const struct of_device_id of_rkvdec_match[]
> > = {>
> > };
> > MODULE_DEVICE_TABLE(of, of_rkvdec_match);
> >
> > -static int rkvdec_probe(struct platform_device *pdev)
> > +static int rkvdec_core_bind(struct device *dev, struct device *master,
> > void *data) +{
> > + struct platform_device *pdev = to_platform_device(dev);
> > + struct rkvdec_core *core = platform_get_drvdata(pdev);
> > + struct rkvdec_dev *rkvdec = data;
> > +
> > + if (rkvdec->main_core)
> > + return dev_err_probe(dev, -EBUSY,
> > + "rkvdec already has a bound
core\n");
> > +
> > + rkvdec->main_core = core;
> > +
> > + dev_info(dev, "Registered core\n");
> > +
> > + return 0;
> > +}
> > +
> > +static const struct component_ops rkvdec_core_ops = {
> > + .bind = rkvdec_core_bind,
> > +};
> > +
> > +static int rkvdec_core_probe(struct platform_device *pdev)
> >
> > {
> >
> > const struct rkvdec_variant *variant;
> >
> > - struct rkvdec_dev *rkvdec;
> > + struct rkvdec_core *core;
> >
> > int ret, irq;
> >
> > + if (!pdev->dev.of_node)
> > + return -ENODEV;
> > +
> >
> > variant = of_device_get_match_data(&pdev->dev);
> > if (!variant)
> >
> > - return -EINVAL;
> > + return dev_err_probe(&pdev->dev, -ENODEV, "failed to
get match
> > data\n");
> >
> > - rkvdec = devm_kzalloc(&pdev->dev, sizeof(*rkvdec), GFP_KERNEL);
> > - if (!rkvdec)
> > + core = devm_kzalloc(&pdev->dev, sizeof(*core), GFP_KERNEL);
> > + if (!core)
> >
> > return -ENOMEM;
> >
> > - platform_set_drvdata(pdev, rkvdec);
> > - rkvdec->dev = &pdev->dev;
> > - rkvdec->variant = variant;
> > - mutex_init(&rkvdec->vdev_lock);
> > - INIT_DELAYED_WORK(&rkvdec->watchdog_work, rkvdec_watchdog_func);
> > -
> > - ret = rkvdec_disable_multicore(rkvdec);
> > - if (ret)
> > - return ret;
> > + core->dev = &pdev->dev;
> > + INIT_DELAYED_WORK(&core->watchdog_work, rkvdec_watchdog_func);
> >
> > - ret = devm_clk_bulk_get_all_enabled(&pdev->dev, &rkvdec->clocks);
> > + ret = devm_clk_bulk_get_all_enabled(&pdev->dev, &core->clocks);
>
> Just a note, we'll have a conflict here, someone noted that PM runtime
> should enable the clock instead, there is a small fix that might be picked
> before this one. Just rebase if that happens.
I'll rebase before sending the next version
> > if (ret < 0)
> >
> > return ret;
> >
> > + core->num_clocks = ret;
> >
> > - rkvdec->num_clocks = ret;
> > - rkvdec->axi_clk = devm_clk_get(&pdev->dev, "axi");
> > + core->axi_clk = devm_clk_get(&pdev->dev, "axi");
> >
> > - if (rkvdec->variant->has_single_reg_region) {
> > - rkvdec->regs = devm_platform_ioremap_resource(pdev, 0);
> > - if (IS_ERR(rkvdec->regs))
> > - return PTR_ERR(rkvdec->regs);
> > + if (variant->has_single_reg_region) {
> > + core->regs = devm_platform_ioremap_resource(pdev, 0);
> > + if (IS_ERR(core->regs))
> > + return PTR_ERR(core->regs);
> >
> > } else {
> >
> > - rkvdec->regs =
devm_platform_ioremap_resource_byname(pdev, "function");
> > - if (IS_ERR(rkvdec->regs))
> > - return PTR_ERR(rkvdec->regs);
> > + core->regs =
devm_platform_ioremap_resource_byname(pdev, "function");
> > + if (IS_ERR(core->regs))
> > + return PTR_ERR(core->regs);
> > +
> > + core->link =
devm_platform_ioremap_resource_byname(pdev, "link");
> > + if (IS_ERR(core->link))
> > + return PTR_ERR(core->link);
> > + }
> > +
> > + if (iommu_get_domain_for_dev(&pdev->dev)) {
> > + core->empty_domain = iommu_paging_domain_alloc(core-
>dev);
> >
> > - rkvdec->link =
devm_platform_ioremap_resource_byname(pdev, "link");
> > - if (IS_ERR(rkvdec->link))
> > - return PTR_ERR(rkvdec->link);
> > + if (IS_ERR(core->empty_domain)) {
> > + dev_warn(core->dev, "cannot alloc new empty
domain\n");
> > + core->empty_domain = NULL;
> > + }
> >
> > }
> >
> > ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
> >
> > @@ -1816,32 +1804,26 @@ static int rkvdec_probe(struct platform_device
> > *pdev)>
> > ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
> >
> > rkvdec_irq_handler,
IRQF_ONESHOT,
> >
> > - dev_name(&pdev->dev),
rkvdec);
> > + dev_name(&pdev->dev),
core);
> >
> > if (ret) {
> >
> > - dev_err(&pdev->dev, "Could not request vdec IRQ\n");
> > + dev_err(&pdev->dev, "Could not request core IRQ\n");
> >
> > return ret;
> >
> > }
> >
> > - rkvdec->sram_pool = of_gen_pool_get(pdev->dev.of_node, "sram", 0);
> > - if (!rkvdec->sram_pool && rkvdec->variant->num_rcb_sizes > 0)
> > + core->sram_pool = of_gen_pool_get(pdev->dev.of_node, "sram", 0);
> > + if (!core->sram_pool && variant->num_rcb_sizes > 0)
> >
> > dev_info(&pdev->dev, "No sram node, RCB will be stored
in RAM\n");
> >
> > pm_runtime_set_autosuspend_delay(&pdev->dev, 100);
> > pm_runtime_use_autosuspend(&pdev->dev);
> > pm_runtime_enable(&pdev->dev);
> >
> > - ret = rkvdec_v4l2_init(rkvdec);
> > - if (ret)
> > - goto err_disable_runtime_pm;
> > + platform_set_drvdata(pdev, core);
> >
> > - rkvdec->iommu_domain = iommu_get_domain_for_dev(&pdev->dev);
> > - if (rkvdec->iommu_domain) {
> > - rkvdec->empty_domain =
iommu_paging_domain_alloc(rkvdec->dev);
> > -
> > - if (IS_ERR(rkvdec->empty_domain)) {
> > - rkvdec->empty_domain = NULL;
> > - dev_warn(rkvdec->dev, "cannot alloc new
empty domain\n");
> > - }
> > + ret = component_add(&pdev->dev, &rkvdec_core_ops);
> > + if (ret < 0) {
> > + dev_err(&pdev->dev, "failed to register component:
%d\n", ret);
> > + goto err_disable_runtime_pm;
> >
> > }
> >
> > return 0;
> >
> > @@ -1849,60 +1831,254 @@ static int rkvdec_probe(struct platform_device
> > *pdev)>
> > err_disable_runtime_pm:
> > pm_runtime_dont_use_autosuspend(&pdev->dev);
> > pm_runtime_disable(&pdev->dev);
> >
> > -
> > - if (rkvdec->sram_pool)
> > - gen_pool_destroy(rkvdec->sram_pool);
> > + if (core->empty_domain)
> > + iommu_domain_free(core->empty_domain);
> >
> > return ret;
> >
> > }
> >
> > -static void rkvdec_remove(struct platform_device *pdev)
> > +static void rkvdec_core_remove(struct platform_device *pdev)
> >
> > {
> >
> > - struct rkvdec_dev *rkvdec = platform_get_drvdata(pdev);
> > + struct rkvdec_core *core = platform_get_drvdata(pdev);
> >
> > - cancel_delayed_work_sync(&rkvdec->watchdog_work);
> > + component_del(&pdev->dev, &rkvdec_core_ops);
> >
> > - rkvdec_v4l2_cleanup(rkvdec);
> > - pm_runtime_disable(&pdev->dev);
> >
> > pm_runtime_dont_use_autosuspend(&pdev->dev);
> >
> > + pm_runtime_disable(&pdev->dev);
> >
> > - if (rkvdec->empty_domain)
> > - iommu_domain_free(rkvdec->empty_domain);
> > + if (core->empty_domain)
> > + iommu_domain_free(core->empty_domain);
> >
> > }
> >
> > #ifdef CONFIG_PM
> >
> > -static int rkvdec_runtime_resume(struct device *dev)
> > +static int rkvdec_core_runtime_resume(struct device *dev)
> >
> > {
> >
> > - struct rkvdec_dev *rkvdec = dev_get_drvdata(dev);
> > + struct rkvdec_core *core = dev_get_drvdata(dev);
> >
> > - return clk_bulk_prepare_enable(rkvdec->num_clocks, rkvdec-
>clocks);
> > + return clk_bulk_prepare_enable(core->num_clocks, core->clocks);
> >
> > }
> >
> > -static int rkvdec_runtime_suspend(struct device *dev)
> > +static int rkvdec_core_runtime_suspend(struct device *dev)
> >
> > {
> >
> > - struct rkvdec_dev *rkvdec = dev_get_drvdata(dev);
> > + struct rkvdec_core *core = dev_get_drvdata(dev);
> > +
> > + clk_bulk_disable_unprepare(core->num_clocks, core->clocks);
> >
> > - clk_bulk_disable_unprepare(rkvdec->num_clocks, rkvdec->clocks);
> >
> > return 0;
> >
> > }
> > #endif
> >
> > -static const struct dev_pm_ops rkvdec_pm_ops = {
> > +static const struct dev_pm_ops rkvdec_core_pm_ops = {
> >
> > SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
> >
> > pm_runtime_force_resume)
> >
> > - SET_RUNTIME_PM_OPS(rkvdec_runtime_suspend, rkvdec_runtime_resume,
NULL)
> > + SET_RUNTIME_PM_OPS(rkvdec_core_runtime_suspend,
> > + rkvdec_core_runtime_resume, NULL)
> > +};
> > +
> > +static struct platform_driver rkvdec_core_pdrv = {
> > + .probe = rkvdec_core_probe,
> > + .remove = rkvdec_core_remove,
> > + .driver = {
> > + .name = "rkvdec-core",
> > + .of_match_table = of_rkvdec_match,
> > + .pm = &rkvdec_core_pm_ops,
> > + },
> > +};
> > +
> > +static int rkvdec_bind(struct device *dev)
> > +{
> > + struct rkvdec_dev *rkvdec = dev_get_drvdata(dev);
> > + int ret;
> > +
> > + ret = component_bind_all(dev, rkvdec);
> > + if (ret) {
> > + dev_err(dev, "component bind failed\n");
> > + return ret;
> > + }
> > +
> > + ret = rkvdec_v4l2_init(rkvdec);
> > + if (ret)
> > + goto err_unbind;
> > +
> > + return 0;
> > +
> > +err_unbind:
> > + component_unbind_all(dev, NULL);
> > + return ret;
> > +}
> > +
> > +static void rkvdec_unbind(struct device *dev)
> > +{
> > + struct rkvdec_dev *rkvdec = dev_get_drvdata(dev);
> > +
> > + cancel_delayed_work_sync(&rkvdec->main_core->watchdog_work);
> > +
> > + rkvdec_v4l2_cleanup(rkvdec);
> > +
> > + rkvdec_free_rcb(rkvdec, rkvdec->main_core);
> > +
> > + component_unbind_all(dev, NULL);
> > +}
> > +
> > +static const struct component_master_ops rkvdec_master_ops = {
> > + .bind = rkvdec_bind,
> > + .unbind = rkvdec_unbind,
> >
> > };
> >
> > -static struct platform_driver rkvdec_driver = {
> > +static int rkvdec_probe(struct platform_device *pdev)
> > +{
> > + const struct of_device_id *match_desc = pdev->dev.platform_data;
> > + struct device *dev = &pdev->dev;
> > + struct component_match *match = NULL;
> > + struct device_node *core_node;
> > + struct rkvdec_dev *rkvdec;
> > +
> > + if (!match_desc)
> > + return dev_err_probe(dev, -ENODEV, "missing platform
data\n");
> > +
> > + for_each_compatible_node(core_node, NULL, match_desc->compatible)
{
> > + if (!of_device_is_available(core_node))
> > + continue;
> > +
> > + of_node_get(core_node);
> > + component_match_add_release(dev, &match,
component_release_of,
> > +
component_compare_of, core_node);
> > + }
> > +
> > + if (!match)
> > + return dev_err_probe(dev, -ENODEV,
> > + "no matching available
component devices found\n");
> > +
> > + rkvdec = devm_kzalloc(dev, sizeof(*rkvdec), GFP_KERNEL);
> > + if (!rkvdec)
> > + return -ENOMEM;
> > +
> > + rkvdec->variant = match_desc->data;
> > + if (!rkvdec->variant)
> > + return dev_err_probe(dev, -ENODEV, "failed to get match
data\n");
> > +
> > + mutex_init(&rkvdec->vdev_lock);
> > +
> > + dev_set_drvdata(dev, rkvdec);
> > +
> > + return component_master_add_with_match(dev, &rkvdec_master_ops,
match);
> > +}
> > +
> > +static void rkvdec_remove(struct platform_device *pdev)
> > +{
> > + component_master_del(&pdev->dev, &rkvdec_master_ops);
> > +}
> > +
> > +static struct platform_driver rkvdec_pdrv = {
> >
> > .probe = rkvdec_probe,
> > .remove = rkvdec_remove,
> > .driver = {
> >
> > - .name = "rkvdec",
> > - .of_match_table = of_rkvdec_match,
> > - .pm = &rkvdec_pm_ops,
> > + .name = "rkvdec",
> >
> > },
> >
> > };
> >
> > -module_platform_driver(rkvdec_driver);
> > +
> > +static bool rkvdec_of_has_available_node(const char *compat)
> > +{
> > + struct device_node *node;
> > +
> > + for_each_compatible_node(node, NULL, compat) {
> > + if (of_device_is_available(node)) {
> > + of_node_put(node);
> > + return true;
> > + }
> > + }
> > +
> > + return false;
> > +}
> > +
> > +static int rkvdec_create_platform_device(struct platform_device **ppdev,
> > + const struct
of_device_id *match)
> > +{
> > + struct platform_device *pdev;
> > + int ret;
> > +
> > + pdev = platform_device_alloc(match->compatible,
PLATFORM_DEVID_NONE);
> > + if (!pdev)
> > + return -ENOMEM;
> > +
> > + ret = platform_device_add_data(pdev, match, sizeof(*match));
> > + if (ret)
> > + goto free_platform_device;
> > +
> > + ret = platform_device_add(pdev);
> > + if (ret)
> > + goto free_platform_device;
> > +
> > + ret = device_driver_attach(&rkvdec_pdrv.driver, &pdev->dev);
> > + if (ret)
> > + goto del_platform_device;
> > +
> > + *ppdev = pdev;
> > +
> > + return 0;
> > +
> > +del_platform_device:
> > + platform_device_del(pdev);
> > +free_platform_device:
> > + platform_device_put(pdev);
> > + return ret;
> > +}
> > +
> > +static struct platform_device *master_pdevs[ARRAY_SIZE(of_rkvdec_match) -
> > 1]; +
> > +static int __init rkvdec_init(void)
> > +{
> > + unsigned int i;
> > + int ret;
> > +
> > + ret = platform_driver_register(&rkvdec_core_pdrv);
> > + if (ret)
> > + return ret;
> > +
> > + ret = platform_driver_register(&rkvdec_pdrv);
> > + if (ret)
> > + goto unregister_core_driver;
> > +
> > + for (i = 0; i < ARRAY_SIZE(master_pdevs); i++) {
> > + if (!
rkvdec_of_has_available_node(of_rkvdec_match[i].compatible))
> > + continue;
> > +
> > + ret = rkvdec_create_platform_device(&master_pdevs[i],
> > +
&of_rkvdec_match[i]);
> > + if (ret)
> > + goto unregister_platform_devices;
> > + }
> > +
> > + return 0;
> > +
> > +unregister_platform_devices:
> > + for (i = 0; i < ARRAY_SIZE(master_pdevs); i++) {
> > + if (master_pdevs[i]) {
> > + platform_device_unregister(master_pdevs[i]);
> > + master_pdevs[i] = NULL;
> > + }
> > + }
> > + platform_driver_unregister(&rkvdec_pdrv);
> > +unregister_core_driver:
> > + platform_driver_unregister(&rkvdec_core_pdrv);
> > + return ret;
> > +}
> > +module_init(rkvdec_init);
> > +
> > +static void __exit rkvdec_exit(void)
> > +{
> > + unsigned int i;
> > +
> > + for (i = 0; i < ARRAY_SIZE(master_pdevs); i++) {
> > + if (master_pdevs[i]) {
> > + platform_device_unregister(master_pdevs[i]);
> > + master_pdevs[i] = NULL;
> > + }
> > + }
> > + platform_driver_unregister(&rkvdec_pdrv);
> > + platform_driver_unregister(&rkvdec_core_pdrv);
> > +}
> > +module_exit(rkvdec_exit);
> >
> > MODULE_AUTHOR("Boris Brezillon <boris.brezillon@collabora.com>");
> > MODULE_DESCRIPTION("Rockchip Video Decoder driver");
> >
> > diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec.h
> > b/drivers/media/platform/rockchip/rkvdec/rkvdec.h index
> > a24be6638b6b..36eadcfcabdb 100644
> > --- a/drivers/media/platform/rockchip/rkvdec/rkvdec.h
> > +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec.h
> > @@ -125,23 +125,28 @@ struct rkvdec_coded_fmt_desc {
> >
> > u32 subsystem_flags;
> >
> > };
> >
> > -struct rkvdec_dev {
> > - struct v4l2_device v4l2_dev;
> > - struct media_device mdev;
> > - struct video_device vdev;
> > - struct v4l2_m2m_dev *m2m_dev;
> > +struct rkvdec_core {
> >
> > struct device *dev;
> > struct clk_bulk_data *clocks;
> > unsigned int num_clocks;
> > struct clk *axi_clk;
> > void __iomem *regs;
> > void __iomem *link;
> >
> > - struct mutex vdev_lock; /* serializes ioctls */
> >
> > struct delayed_work watchdog_work;
> > struct gen_pool *sram_pool;
> >
> > - struct iommu_domain *iommu_domain;
> >
> > struct iommu_domain *empty_domain;
> >
> > + struct rkvdec_rcb_config *rcb_config;
> > + struct rkvdec_ctx *curr_ctx;
> > +};
> > +
> > +struct rkvdec_dev {
> > + struct v4l2_device v4l2_dev;
> > + struct media_device mdev;
> > + struct video_device vdev;
> > + struct v4l2_m2m_dev *m2m_dev;
> > + struct mutex vdev_lock; /* serializes ioctls */
> >
> > const struct rkvdec_variant *variant;
> >
> > + struct rkvdec_core *main_core;
> >
> > };
> >
> > struct rkvdec_ctx {
> >
> > @@ -152,8 +157,8 @@ struct rkvdec_ctx {
> >
> > struct v4l2_ctrl_handler ctrl_hdl;
> > struct rkvdec_dev *dev;
> > enum rkvdec_image_fmt image_fmt;
> >
> > - struct rkvdec_rcb_config *rcb_config;
> >
> > u32 colmv_offset;
> >
> > + struct rkvdec_core *core;
> >
> > void *priv;
> > u8 has_sps_st_rps: 1;
> > u8 has_sps_lt_rps: 1;
> >
> > @@ -179,7 +184,7 @@ struct rkvdec_aux_buf {
> >
> > void rkvdec_run_preamble(struct rkvdec_ctx *ctx, struct rkvdec_run *run);
> > void rkvdec_run_postamble(struct rkvdec_ctx *ctx, struct rkvdec_run
> > *run);
> > void rkvdec_memcpy_toio(void __iomem *dst, void *src, size_t len);
> >
> > -void rkvdec_schedule_watchdog(struct rkvdec_dev *rkvdec, u32
> > timeout_threshold); +void rkvdec_schedule_watchdog(struct rkvdec_core
> > *core, u32 timeout_threshold);>
> > void rkvdec_quirks_disable_qos(struct rkvdec_ctx *ctx);
>
> So not that much, yet the iommu restore hack seems broken now at first
> sight.
I don't agree for this commit.
> Nicolas
next prev parent reply other threads:[~2026-11-30 15:54 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-10 15:22 [PATCH v2 0/5] media: rkvdec: Enable multi-core support Detlev Casanova
2026-08-10 15:22 ` [PATCH v2 1/5] media: rkvdec: Keep RCB to the correct size Detlev Casanova
2026-11-19 17:33 ` Nicolas Dufresne
2026-08-10 15:22 ` [PATCH v2 2/5] media: rkvdec: Remove unused need_reset Detlev Casanova
2026-11-19 17:35 ` Nicolas Dufresne
2026-11-27 18:42 ` Detlev Casanova
2026-08-10 15:22 ` [PATCH v2 3/5] v4l2: export v4l2_m2m_set_max_parallel_jobs Detlev Casanova
2026-11-19 17:36 ` Nicolas Dufresne
2026-11-27 18:44 ` Detlev Casanova
2026-08-10 15:22 ` [PATCH v2 4/5] media: rkvdec: Split into core and master platform drivers Detlev Casanova
2026-11-19 17:58 ` Nicolas Dufresne
2026-11-30 15:53 ` Detlev Casanova [this message]
2026-08-10 15:22 ` [PATCH v2 5/5] media: rkvdec: Add multicore support Detlev Casanova
2026-11-19 18:08 ` Nicolas Dufresne
2026-11-13 12:39 ` [PATCH v2 0/5] media: rkvdec: Enable multi-core support Lukas Splavec
2026-11-14 4:50 ` Arun Iyengar
2026-11-14 5:01 ` Arun Iyengar
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=DHzDE1dLRbaR-tn1tg9ZoQ@collabora.com \
--to=detlev.casanova@collabora.com \
--cc=ezequiel@vanguardiasur.com.ar \
--cc=heiko@sntech.de \
--cc=hverkuil+cisco@kernel.org \
--cc=jonas@kwiboo.se \
--cc=kernel@collabora.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=mchehab@kernel.org \
--cc=nicolas.dufresne@collabora.com \
--cc=s.pueschel@pengutronix.de \
/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®