Linux Remote Processor Subsystem development
 help / color / mirror / Atom feed
From: Ben Levinsky <ben.levinsky@xilinx.com>
To: <mathieu.poirier@linaro.org>, <arnaud.pouliquen@foss.st.com>,
	<bill.mills@linaro.com>, <tanmay.shah@amd.com>
Cc: <linux-remoteproc@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: [RFC PATCH 0/1] remoteproc: Enable getter for drivers that manage 2+ remotes
Date: Tue, 15 Nov 2022 07:37:52 -0800	[thread overview]
Message-ID: <20221115153753.2065803-1-ben.levinsky@xilinx.com> (raw)

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


             reply	other threads:[~2022-11-15 15:38 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-15 15:37 Ben Levinsky [this message]
2022-11-15 15:37 ` [RFC PATCH 1/1] remoteproc: Introduce rproc_get_by_id API Ben Levinsky
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

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=20221115153753.2065803-1-ben.levinsky@xilinx.com \
    --to=ben.levinsky@xilinx.com \
    --cc=arnaud.pouliquen@foss.st.com \
    --cc=bill.mills@linaro.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-remoteproc@vger.kernel.org \
    --cc=mathieu.poirier@linaro.org \
    --cc=tanmay.shah@amd.com \
    /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