From: Arnaud POULIQUEN <arnaud.pouliquen@foss.st.com>
To: Rob Herring <robh@kernel.org>
Cc: Saravana Kannan <saravanak@google.com>,
Bjorn Andersson <andersson@kernel.org>,
Mathieu Poirier <mathieu.poirier@linaro.org>,
"Shawn Guo" <shawnguo@kernel.org>,
Sascha Hauer <s.hauer@pengutronix.de>,
"Pengutronix Kernel Team" <kernel@pengutronix.de>,
Fabio Estevam <festevam@gmail.com>,
Patrice Chotard <patrice.chotard@foss.st.com>,
Maxime Coquelin <mcoquelin.stm32@gmail.com>,
Alexandre Torgue <alexandre.torgue@foss.st.com>,
<devicetree@vger.kernel.org>, <imx@lists.linux.dev>,
<linux-arm-msm@vger.kernel.org>,
<linux-remoteproc@vger.kernel.org>,
<linux-kernel@vger.kernel.org>,
<linux-stm32@st-md-mailman.stormreply.com>,
<linux-arm-kernel@lists.infradead.org>
Subject: Re: [Linux-stm32] [PATCH 3/3] remoteproc: Use of_reserved_mem_region_* functions for "memory-region"
Date: Fri, 21 Mar 2025 09:22:30 +0100 [thread overview]
Message-ID: <4eddc37b-5164-453a-9b7f-c4331a7d6243@foss.st.com> (raw)
In-Reply-To: <CAL_JsqJZkEpx26=ro_y8hHA2x1Zm6z_SFOQHjQ-WzUa-gy+s0w@mail.gmail.com>
On 3/20/25 19:02, Rob Herring wrote:
> On Thu, Mar 20, 2025 at 4:23 AM Arnaud POULIQUEN
> <arnaud.pouliquen@foss.st.com> wrote:
>>
>>
>>
>> On 3/20/25 00:04, Rob Herring wrote:
>>> On Wed, Mar 19, 2025 at 10:26 AM Arnaud POULIQUEN
>>> <arnaud.pouliquen@foss.st.com> wrote:
>>>>
>>>> Hello Rob,
>>>>
>>>> On 3/18/25 00:24, Rob Herring (Arm) wrote:
>>>>> Use the newly added of_reserved_mem_region_to_resource() and
>>>>> of_reserved_mem_region_count() functions to handle "memory-region"
>>>>> properties.
>>>>>
>>>>> The error handling is a bit different in some cases. Often
>>>>> "memory-region" is optional, so failed lookup is not an error. But then
>>>>> an error in of_reserved_mem_lookup() is treated as an error. However,
>>>>> that distinction is not really important. Either the region is available
>>>>> and usable or it is not. So now, it is just
>>>>> of_reserved_mem_region_to_resource() which is checked for an error.
>>>>>
>>>>> Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
>>>>> ---
>>>>> For v6.16
>>>>>
>>>
>>> [...]
>>>
>>>>> diff --git a/drivers/remoteproc/stm32_rproc.c b/drivers/remoteproc/stm32_rproc.c
>>>>> index b02b36a3f515..9d2bd8904c49 100644
>>>>> --- a/drivers/remoteproc/stm32_rproc.c
>>>>> +++ b/drivers/remoteproc/stm32_rproc.c
>>>>> @@ -213,52 +213,46 @@ static int stm32_rproc_prepare(struct rproc *rproc)
>>>>> {
>>>>> struct device *dev = rproc->dev.parent;
>>>>> struct device_node *np = dev->of_node;
>>>>> - struct of_phandle_iterator it;
>>>>> struct rproc_mem_entry *mem;
>>>>> - struct reserved_mem *rmem;
>>>>> u64 da;
>>>>> - int index = 0;
>>>>> + int index = 0, mr = 0;
>>>>>
>>>>> /* Register associated reserved memory regions */
>>>>> - of_phandle_iterator_init(&it, np, "memory-region", NULL, 0);
>>>>> - while (of_phandle_iterator_next(&it) == 0) {
>>>>> - rmem = of_reserved_mem_lookup(it.node);
>>>>> - if (!rmem) {
>>>>> - of_node_put(it.node);
>>>>> - dev_err(dev, "unable to acquire memory-region\n");
>>>>> - return -EINVAL;
>>>>> - }
>>>>> + while (1) {
>>>>> + struct resource res;
>>>>> + int ret;
>>>>> +
>>>>> + ret = of_reserved_mem_region_to_resource(np, mr++, &res);
>>>>> + if (ret)
>>>>> + return 0;
>>>>>
>>>>> - if (stm32_rproc_pa_to_da(rproc, rmem->base, &da) < 0) {
>>>>> - of_node_put(it.node);
>>>>> - dev_err(dev, "memory region not valid %pa\n",
>>>>> - &rmem->base);
>>>>> + if (stm32_rproc_pa_to_da(rproc, res.start, &da) < 0) {
>>>>> + dev_err(dev, "memory region not valid %pR\n", &res);
>>>>> return -EINVAL;
>>>>> }
>>>>>
>>>>> /* No need to map vdev buffer */
>>>>> - if (strcmp(it.node->name, "vdev0buffer")) {
>>>>> + if (strcmp(res.name, "vdev0buffer")) {
>>>>
>>>> I tested your patches
>>>
>>> Thank you.
>>>
>>>> The update introduces a regression here. The strcmp function never returns 0.
>>>> Indeed, it.node->name stores the memory region label "vdev0buffer," while
>>>> res.name stores the memory region name "vdev0buffer@10042000."
>>>>
>>>> Several remoteproc drivers may face the same issue as they embed similar code.
>>>
>>> Indeed. I confused myself because node 'name' is without the
>>> unit-address, but this is using the full name. I've replaced the
>>> strcmp's with strstarts() to address this. I've updated my branch with
>>> the changes.
>>
>> This is not enough as the remoteproc core function rproc_find_carveout_by_name()
>> also compares the memory names. With the following additional fix, it is working
>> on my STM32MP15-DK board.
>>
>> @@ -309,11 +309,11 @@ rproc_find_carveout_by_name(struct rproc *rproc, const
>> char *name, ...)
>> vsnprintf(_name, sizeof(_name), name, args);
>> va_end(args);
>>
>> list_for_each_entry(carveout, &rproc->carveouts, node) {
>> /* Compare carveout and requested names */
>> - if (!strcmp(carveout->name, _name)) {
>> + if (strstarts(carveout->name, _name)) {
>> mem = carveout;
>> break;
>> }
>> }
>>
>> I just wonder if would not be more suitable to address this using the
>> "memory-region-names" field.
>
> That would be better as you shouldn't really care what a provider node
> name is where-as "memory-region-names" is meaningful to the driver.
>
>>
>> The drawback is that we would break compatibility with legacy boards...
>
> So not an option.
>
> I think I'll have to fix this within the reserved mem code storing the
> name or do something like the diff below. I'd like to avoid the
> former. Using the original device_node.name is also problematic
> because I want to get rid of it. We redundantly store the node name
> with and without the unit-address. There's a lot of places like this
> one where we hand out the pointer with no lifetime.
>
> diff --git a/drivers/remoteproc/stm32_rproc.c b/drivers/remoteproc/stm32_rproc.c
> index 1e949694d365..cdee87c6ffe0 100644
> --- a/drivers/remoteproc/stm32_rproc.c
> +++ b/drivers/remoteproc/stm32_rproc.c
> @@ -239,7 +239,7 @@ static int stm32_rproc_prepare(struct rproc *rproc)
> resource_size(&res), da,
> stm32_rproc_mem_alloc,
> stm32_rproc_mem_release,
> - res.name);
> + "%.*s",
> strchrnul(res.name, '@') - res.name, res.name);
>
> if (mem)
> rproc_coredump_add_segment(rproc, da,
> @@ -249,7 +249,7 @@ static int stm32_rproc_prepare(struct rproc *rproc)
> mem = rproc_of_resm_mem_entry_init(dev, index,
> resource_size(&res),
> res.start,
> - res.name);
> + "vdev0buffer");
> }
>
> if (!mem) {
That's work on my side.
Could we have an OF helper to retrieve the name from the full name?
Thanks,
Arnaud
next prev parent reply other threads:[~2025-03-21 8:27 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-17 23:24 [PATCH 0/3] of: Common "memory-region" parsing Rob Herring (Arm)
2025-03-17 23:24 ` [PATCH 1/3] of: reserved_mem: Add functions to parse "memory-region" Rob Herring (Arm)
2025-03-18 8:54 ` Daniel Baluta
2025-03-18 11:12 ` Jonathan Cameron
2025-03-17 23:24 ` [PATCH 2/3] of: Simplify of_dma_set_restricted_buffer() to use of_for_each_phandle() Rob Herring (Arm)
2025-03-26 6:44 ` Chen-Yu Tsai
2025-03-26 18:52 ` Rob Herring
2025-03-27 4:32 ` Chen-Yu Tsai
2025-03-17 23:24 ` [PATCH 3/3] remoteproc: Use of_reserved_mem_region_* functions for "memory-region" Rob Herring (Arm)
2025-03-18 8:57 ` Daniel Baluta
2025-03-18 10:48 ` neil.armstrong
2025-03-19 15:23 ` [Linux-stm32] " Arnaud POULIQUEN
2025-03-19 23:04 ` Rob Herring
2025-03-20 9:21 ` Arnaud POULIQUEN
2025-03-20 9:37 ` Arnaud POULIQUEN
2025-03-20 18:02 ` Rob Herring
2025-03-21 8:22 ` Arnaud POULIQUEN [this message]
2025-03-21 13:14 ` Rob Herring
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=4eddc37b-5164-453a-9b7f-c4331a7d6243@foss.st.com \
--to=arnaud.pouliquen@foss.st.com \
--cc=alexandre.torgue@foss.st.com \
--cc=andersson@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=festevam@gmail.com \
--cc=imx@lists.linux.dev \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=mathieu.poirier@linaro.org \
--cc=mcoquelin.stm32@gmail.com \
--cc=patrice.chotard@foss.st.com \
--cc=robh@kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=saravanak@google.com \
--cc=shawnguo@kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).