All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 0/1] remoteproc: Enable getter for drivers that manage 2+ remotes
@ 2022-11-15 15:37 Ben Levinsky
  2022-11-15 15:37 ` [RFC PATCH 1/1] remoteproc: Introduce rproc_get_by_id API Ben Levinsky
  0 siblings, 1 reply; 13+ messages in thread
From: Ben Levinsky @ 2022-11-15 15:37 UTC (permalink / raw)
  To: mathieu.poirier, arnaud.pouliquen, bill.mills, tanmay.shah
  Cc: linux-remoteproc, linux-kernel

This RFC is to show the following
(a) a use case for a new remoteproc API rproc_get_by_id()
(b) patch for the new API rproc_get_by_id() 

For context there exist multiple drivers in remoteproc that manage more than
one remote processor. For these drivers, calls to rproc_get_by_phandle()
are not sufficient as the check at
https://github.com/torvalds/linux/blob/master/drivers/remoteproc/remoteproc_core.c#L2111
will not work. This is because for r->dev.parent, r->dev's parent is 
expected to be the platform device that corresponds to the platform-probe()
call but instead is the child and this child does not have the driver field
set.

An example to show this issue is as follows:

If a remoteproc driver has the following DTS binding:

/{
	remoteproc_cluster {
		compatible = "soc,remoteproc-cluster";

		core0: core0 {
			memory-region;
			sram;
		};

		core1: core1 {
			memory-region;
			sram;
		}
	};
};

And in the corresponding driver the platform-probe() is as follows:

static int cluster_platform_probe(struct platform_device *pdev)
{
	struct device_node *np = dev_of_node(dev);
	struct device *dev = &pdev->dev;
	struct platform_device *cpdev;
	struct device *child_dev;
	struct rproc *rp;

	for_each_available_child_of_node(np, child) {
		cpdev = of_find_device_by_node(child);
		child_dev = &cpdev->dev;

		rp = rproc_alloc(cdev, dev_name(cdev), dummy_ops, NULL,
				 sizeof(struct dummy_ops));
	}

	return 0;
}


After the rproc call is done and when another driver tries to access this
rproc structure via a rproc_get_by_phandle(), the aforementioned check of
r->dev.parent->driver will be NULL.

To account for a remoteproc driver that manages multiple remote processors,
I have provided an API rproc_get_by_id() that enables getting rp
given a phandle to the core in question with a DT binding and usage of the API.

Sample binding:

/{
	platform_driver_sample {
		compatible = "custom_platform";
		rproc = <&core1>;
	};
};

Sample usage:

static int custom_platform_probe(struct platform_device *pdev)
{
	struct rproc *rp;
	struct device_node *node;

	node = of_parse_phandle(pdev->dev.of_node, "rproc", 0);

	/* Here get rproc 1, as its index should be 1 */
	rp = rproc_get_by_id(node->phandle, 1);

	return 0;
}
	
If we want further specification of getting the correct remoteproc ID,
this can be inferred from the pdev->dev child's device child node and
its dev->init_name field as this is set in rproc_alloc() as follows:

	dev_set_name(&rproc->dev, "remoteproc%d", rproc->index);

We can then parse the pdev->dev child device as follows:

	int index;

	sscanf(dev_name(dev), "remoteproc%d", &index);

Additionally I have provided the implementation for the API in
the subsequent patch.

Ben Levinsky (1):
  remoteproc: Introduce rproc_get_by_id API

 drivers/remoteproc/remoteproc_core.c | 64 +++++++++++++++++++++++++++-
 include/linux/remoteproc.h           |  1 +
 2 files changed, 64 insertions(+), 1 deletion(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-12-14 20:29 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-15 15:37 [RFC PATCH 0/1] remoteproc: Enable getter for drivers that manage 2+ remotes Ben Levinsky
2022-11-15 15:37 ` [RFC PATCH 1/1] remoteproc: Introduce rproc_get_by_id API Ben Levinsky
2022-11-17 13:55   ` kernel test robot
2022-11-17 20:09   ` kernel test robot
2022-11-25 18:05   ` Mathieu Poirier
2022-11-30 21:39     ` Levinsky, Ben
2022-12-02 17:00       ` Mathieu Poirier
     [not found]         ` <ba21b0e5-80e2-d976-1bf3-98a91825086b@amd.com>
2022-12-08 19:05           ` Mathieu Poirier
2022-12-09 19:01             ` Ben Levinsky
2022-12-13 21:53               ` Mathieu Poirier
2022-12-13 22:21                 ` Mathieu Poirier
     [not found]                   ` <D93BFC0C-F90C-413E-899F-9CF5C6FB794A@amd.com>
2022-12-14 17:17                     ` Ben Levinsky
2022-12-14 20:17                       ` Mathieu Poirier

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.