mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nicolas Dufresne <nicolas@ndufresne.ca>
To: "Sven Püschel" <s.pueschel@pengutronix.de>,
	"Jacob Chen" <jacob-chen@iotwrt.com>,
	"Ezequiel Garcia" <ezequiel@vanguardiasur.com.ar>,
	"Mauro Carvalho Chehab" <mchehab@kernel.org>,
	"Heiko Stuebner" <heiko@sntech.de>,
	"Philipp Zabel" <p.zabel@pengutronix.de>
Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org,
	 linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,  kernel@pengutronix.de,
	Detlev Casanova <detlev.casanova@collabora.com>,
	 Michael Tretter <m.tretter@pengutronix.de>,
	Guangshuo Li <lgs201920130244@gmail.com>
Subject: Re: [PATCH v2 11/17] media: rockchip: rga: use components to manage multiple cores
Date: Tue, 24 Nov 2026 16:29:20 -0500	[thread overview]
Message-ID: <42e8fa9d09b2f773b4b46fd95e3b499163d81267.camel@ndufresne.ca> (raw)
In-Reply-To: <20260916-spu-rga3multicore-v2-11-23aa2cb74e61@pengutronix.de>

[-- Attachment #1: Type: text/plain, Size: 11429 bytes --]

Le mercredi 16 septembre 2026 à 17:09 +0200, Sven Püschel a écrit :
> Use component helpers to manage multiple cores and aggregate them into a
> central master device. This gives us a dedicated master device and
> ensures that all cores (components) are properly set up before creating
> the video device.
> 
> This commit only sets up a basic component device. Instead of the
> rga_disable_multicore function only the first core is added to the
> master device. To avoid the secondary core creating an additional video
> device the whole core probe implementation is moved to the bind method,
> which is only called when the core is bound to a master device.
> 
> As we use devres (devm_*) functions for resource cleanup in the probe,
> it is technically incorrect to use them in a component bind function.
> It'll be properly split out again in the follow-up commits to avoid
> having one big migration commit.
> 
> The implementation is based on the etnaviv gpu driver, which also groups
> multiple gpu cores under a single etnaviv master device.
> 
> Signed-off-by: Sven Püschel <s.pueschel@pengutronix.de>
> 
> ---
> v2
> - clarify that devres in component bind functions is technically
>   incorrect and only done to keep the commits split up
> - use dev_err_probe instead of dev_err + return for a failed
>   component_add
> - remove if (!match) check in rga_probe, as it's only called when we
>   have found at least one dt entry (and sashiko pointed out that it's
>   an err ptr)
> - add platform_device_id table to avoid a manual binding
> ---
>  drivers/media/platform/rockchip/rga/rga.c | 263 ++++++++++++++++++++++++------
>  1 file changed, 209 insertions(+), 54 deletions(-)
> 
> diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/platform/rockchip/rga/rga.c
> index bcfc19d29af74..367df0ee7b02f 100644
> --- a/drivers/media/platform/rockchip/rga/rga.c
> +++ b/drivers/media/platform/rockchip/rga/rga.c
> @@ -5,6 +5,7 @@
>   */
>  
>  #include <linux/clk.h>
> +#include <linux/component.h>
>  #include <linux/debugfs.h>
>  #include <linux/delay.h>
>  #include <linux/fs.h>
> @@ -737,51 +738,9 @@ static int rga_parse_dt(struct rga_core *core)
>  	return 0;
>  }
>  
> -/*
> - * Some SoCs, like RK3588 have multiple identical RGA3 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 main core can be used to cluster all cores together.
> - */
> -static int rga_disable_multicore(struct device *dev)
> -{
> -	struct device_node *node = NULL;
> -	const char *compatible;
> -	bool is_main_core;
> -	int ret;
> -
> -	/* Intentionally ignores the fallback strings */
> -	ret = of_property_read_string(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_main_core = (dev->of_node == node);
> -
> -	of_node_put(node);
> -
> -	if (!is_main_core) {
> -		dev_info(dev, "missing multi-core support, ignoring this instance\n");
> -		return -ENODEV;
> -	}
> -
> -	return 0;
> -}
> -
> -static int rga_probe(struct platform_device *pdev)
> +static int rga_core_bind(struct device *dev, struct device *master, void *data)
>  {
> +	struct platform_device *pdev = to_platform_device(dev);
>  	struct rockchip_rga *rga;
>  	struct rga_core *core;
>  	struct video_device *vfd;
> @@ -791,10 +750,6 @@ static int rga_probe(struct platform_device *pdev)
>  	if (!pdev->dev.of_node)
>  		return -ENODEV;
>  
> -	ret = rga_disable_multicore(&pdev->dev);
> -	if (ret)
> -		return ret;
> -
>  	rga = devm_kzalloc(&pdev->dev, sizeof(*rga) + 1 * sizeof(*rga->cores), GFP_KERNEL);
>  	if (!rga)
>  		return -ENOMEM;
> @@ -900,9 +855,10 @@ static int rga_probe(struct platform_device *pdev)
>  	return ret;
>  }
>  
> -static void rga_remove(struct platform_device *pdev)
> +static void rga_core_unbind(struct device *dev, struct device *master,
> +			    void *data)
>  {
> -	struct rga_core *core = platform_get_drvdata(pdev);
> +	struct rga_core *core = dev_get_drvdata(dev);
>  	struct rockchip_rga *rga = core->rga;
>  
>  	v4l2_info(&rga->v4l2_dev, "Removing\n");
> @@ -912,6 +868,27 @@ static void rga_remove(struct platform_device *pdev)
>  	v4l2_device_unregister(&rga->v4l2_dev);
>  }
>  
> +static const struct component_ops rga_core_ops = {
> +	.bind = rga_core_bind,
> +	.unbind = rga_core_unbind,
> +};
> +
> +static int rga_core_probe(struct platform_device *pdev)
> +{
> +	int ret = 0;
> +
> +	ret = component_add(&pdev->dev, &rga_core_ops);
> +	if (ret < 0)
> +		return dev_err_probe(&pdev->dev, ret, "failed to register component\n");
> +
> +	return 0;
> +}
> +
> +static void rga_core_remove(struct platform_device *pdev)
> +{
> +	component_del(&pdev->dev, &rga_core_ops);
> +}
> +
>  static int __maybe_unused rga_runtime_suspend(struct device *dev)
>  {
>  	struct rga_core *core = dev_get_drvdata(dev);
> @@ -928,11 +905,12 @@ static int __maybe_unused rga_runtime_resume(struct device *dev)
>  	return clk_bulk_prepare_enable(core->num_clks, core->clks);
>  }
>  
> -static const struct dev_pm_ops rga_pm = {
> +static const struct dev_pm_ops rga_core_pm = {
>  	SET_RUNTIME_PM_OPS(rga_runtime_suspend,
>  			   rga_runtime_resume, NULL)
>  };
>  
> +/* add new compatibles also to the rga_ids struct */
>  static const struct of_device_id rockchip_rga_match[] = {
>  	{
>  		.compatible = "rockchip,rk3288-rga",
> @@ -951,17 +929,194 @@ static const struct of_device_id rockchip_rga_match[] = {
>  
>  MODULE_DEVICE_TABLE(of, rockchip_rga_match);
>  
> +static struct platform_driver rga_core_pdrv = {
> +	.probe = rga_core_probe,
> +	.remove = rga_core_remove,
> +	.driver = {
> +		.name = RGA_NAME "-core",
> +		.pm = &rga_core_pm,
> +		.of_match_table = rockchip_rga_match,
> +	},
> +};
> +
> +static int rga_bind(struct device *dev)
> +{
> +	int ret;
> +
> +	ret = component_bind_all(dev, NULL);
> +	if (ret) {
> +		dev_err(dev, "component bind failed\n");
> +		return ret;
> +	}
> +
> +	return 0;
> +}
> +
> +static void rga_unbind(struct device *dev)
> +{
> +	component_unbind_all(dev, NULL);
> +}
> +
> +struct component_master_ops rga_master_ops = {
> +	.bind = rga_bind,
> +	.unbind = rga_unbind,
> +};
> +
> +static int rga_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;
> +
> +	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);

I believe sashiko strange report will go away with the added missing return.

Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>

> +
> +		/*
> +		 * As multi core is not implemented yet,
> +		 * break out of the loop to only have one core per rockchip_rga struct.
> +		 * Also put the node, which otherwise would've been done by the loop iteration.
> +		 */
> +		of_node_put(core_node);
> +		break;
> +	}
> +
> +	return component_master_add_with_match(dev, &rga_master_ops, match);
> +}
> +
> +static void rga_remove(struct platform_device *pdev)
> +{
> +	component_master_del(&pdev->dev, &rga_master_ops);
> +}
> +
> +/*
> + * Keep in sync with the compatible names of rockchip_rga_match, as we name the
> + * virtual component master platform device (allocating the /dev/video device)
> + * based on the compatible value.
> + */
> +static struct platform_device_id rga_ids[] = {
> +	{
> +		.name = "rockchip,rk3288-rga",
> +	},
> +	{
> +		.name = "rockchip,rk3399-rga",
> +	},
> +	{
> +		.name = "rockchip,rk3588-rga3",
> +	},
> +	{},
> +};
> +
>  static struct platform_driver rga_pdrv = {
>  	.probe = rga_probe,
>  	.remove = rga_remove,
>  	.driver = {
>  		.name = RGA_NAME,
> -		.pm = &rga_pm,
> -		.of_match_table = rockchip_rga_match,
>  	},
> +	.id_table = rga_ids,
>  };
>  
> -module_platform_driver(rga_pdrv);
> +static bool rga_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 rga_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;
> +
> +	*ppdev = pdev;
> +
> +	return 0;
> +
> +free_platform_device:
> +	platform_device_put(pdev);
> +	return ret;
> +}
> +
> +static struct platform_device *master_pdevs[ARRAY_SIZE(rockchip_rga_match) - 1];
> +
> +static int __init rga_init(void)
> +{
> +	int ret;
> +	unsigned int i;
> +
> +	ret = platform_driver_register(&rga_core_pdrv);
> +	if (ret != 0)
> +		return ret;
> +
> +	ret = platform_driver_register(&rga_pdrv);
> +	if (ret != 0)
> +		goto unregister_core_driver;
> +
> +	for (i = 0; i < ARRAY_SIZE(master_pdevs); i++) {
> +		if (!rga_of_has_available_node(
> +			    rockchip_rga_match[i].compatible))
> +			continue;
> +
> +		ret = rga_create_platform_device(&master_pdevs[i],
> +						 &rockchip_rga_match[i]);
> +		if (ret)
> +			goto unregister_platform_devices;
> +	}
> +
> +	return 0;
> +
> +unregister_platform_devices:
> +	for (i = 0; i < ARRAY_SIZE(master_pdevs); i++) {
> +		platform_device_unregister(master_pdevs[i]);
> +		master_pdevs[i] = NULL;
> +	}
> +	platform_driver_unregister(&rga_pdrv);
> +unregister_core_driver:
> +	platform_driver_unregister(&rga_core_pdrv);
> +	return ret;
> +}
> +module_init(rga_init);
> +
> +static void __exit rga_exit(void)
> +{
> +	unsigned int i;
> +
> +	for (i = 0; i < ARRAY_SIZE(master_pdevs); i++) {
> +		platform_device_unregister(master_pdevs[i]);
> +		master_pdevs[i] = NULL;
> +	}
> +	platform_driver_unregister(&rga_pdrv);
> +	platform_driver_unregister(&rga_core_pdrv);
> +}
> +module_exit(rga_exit);
>  
>  MODULE_AUTHOR("Jacob Chen <jacob-chen@iotwrt.com>");
>  MODULE_DESCRIPTION("Rockchip Raster 2d Graphic Acceleration Unit");

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  reply	other threads:[~2026-11-24 21:29 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16 15:09 [PATCH v2 00/17] media: rockchip: rga: Add multi-core support Sven Püschel
2026-09-16 15:09 ` [PATCH v2 01/17] media: rockchip: rga: zero cmdbuf in shared code Sven Püschel
2026-11-24 20:44   ` Nicolas Dufresne
2026-09-16 15:09 ` [PATCH v2 02/17] media: rockchip: rga: add comment about pixel alignment for YUV formats Sven Püschel
2026-11-24 20:45   ` Nicolas Dufresne
2026-09-16 15:09 ` [PATCH v2 03/17] media: rockchip: rga: move early return into if condition in vidioc_enum_fmt Sven Püschel
2026-11-24 20:46   ` Nicolas Dufresne
2026-09-16 15:09 ` [PATCH v2 04/17] media: rockchip: rga: removed unused regmap member Sven Püschel
2026-11-24 20:46   ` Nicolas Dufresne
2026-09-16 15:09 ` [PATCH v2 05/17] media: rockchip: rga: use devres version of pm_runtime_enable Sven Püschel
2026-11-24 20:51   ` Nicolas Dufresne
2026-09-16 15:09 ` [PATCH v2 06/17] media: v4l2-mem2mem: drop curr_ctx member from v4l2_m2m_dev struct Sven Püschel
2026-11-24 20:55   ` Nicolas Dufresne
2026-09-16 15:09 ` [PATCH v2 07/17] media: v4l2-mem2mem: support running multiple jobs in parallel Sven Püschel
2026-11-24 21:12   ` Nicolas Dufresne
2026-09-16 15:09 ` [PATCH v2 08/17] media: rockchip: rga: move power handling to device_run Sven Püschel
2026-11-24 21:14   ` Nicolas Dufresne
2026-09-16 15:09 ` [PATCH v2 09/17] media: rockchip: rga: adjust get_version to return the version Sven Püschel
2026-11-24 21:15   ` Nicolas Dufresne
2026-09-16 15:09 ` [PATCH v2 10/17] media: rockchip: rga: add rga_core structure Sven Püschel
2026-11-24 21:16   ` Nicolas Dufresne
2026-09-16 15:09 ` [PATCH v2 11/17] media: rockchip: rga: use components to manage multiple cores Sven Püschel
2026-11-24 21:29   ` Nicolas Dufresne [this message]
2026-09-16 15:09 ` [PATCH v2 12/17] media: rockchip: rga: move rockchip_rga allocation to master probe Sven Püschel
2026-11-24 21:30   ` Nicolas Dufresne
2026-09-16 15:09 ` [PATCH v2 13/17] media: rockchip: rga: move core initialization from bind to probe Sven Püschel
2026-11-24 21:35   ` Nicolas Dufresne
2026-09-16 15:09 ` [PATCH v2 14/17] media: rockchip: rga: move video device to the master Sven Püschel
2026-11-24 21:38   ` Nicolas Dufresne
2026-09-16 15:09 ` [PATCH v2 15/17] media: rockchip: rga: bind all cores " Sven Püschel
2026-11-24 21:43   ` Nicolas Dufresne
2026-09-16 15:09 ` [PATCH v2 16/17] media: rockchip: rga: put all cores into first core iommu domain Sven Püschel
2026-11-24 21:50   ` Nicolas Dufresne
2026-09-16 15:09 ` [PATCH v2 17/17] media: rockchip: rga: schedule jobs to multiple cores Sven Püschel
2026-11-24 21:52   ` Nicolas Dufresne
2026-11-14  4:50 ` [PATCH v2 00/17] media: rockchip: rga: Add multi-core support 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=42e8fa9d09b2f773b4b46fd95e3b499163d81267.camel@ndufresne.ca \
    --to=nicolas@ndufresne.ca \
    --cc=detlev.casanova@collabora.com \
    --cc=ezequiel@vanguardiasur.com.ar \
    --cc=heiko@sntech.de \
    --cc=jacob-chen@iotwrt.com \
    --cc=kernel@pengutronix.de \
    --cc=lgs201920130244@gmail.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=m.tretter@pengutronix.de \
    --cc=mchehab@kernel.org \
    --cc=p.zabel@pengutronix.de \
    --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®