devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Frank Rowand <frowand.list@gmail.com>
To: Rob Herring <robh@kernel.org>
Cc: "Clément Léger" <clement.leger@bootlin.com>,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Lizhi Hou" <lizhi.hou@xilinx.com>,
	"Allan Nielsen" <allan.nielsen@microchip.com>,
	"Horatiu Vultur" <horatiu.vultur@microchip.com>,
	"Steen Hegelund" <steen.hegelund@microchip.com>,
	"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>
Subject: Re: [PATCH v3 1/2] of: create of_root if no dtb provided
Date: Wed, 1 Mar 2023 10:49:16 -0600	[thread overview]
Message-ID: <f26ffb41-f542-2809-9818-903947dd6eb4@gmail.com> (raw)
In-Reply-To: <20230301030003.GA263873-robh@kernel.org>

On 2/28/23 21:00, Rob Herring wrote:
> On Tue, Feb 28, 2023 at 08:05:58PM -0600, Frank Rowand wrote:
>> On 2/27/23 11:17, Rob Herring wrote:
>>> On Thu, Feb 23, 2023 at 3:34 PM Frank Rowand <frowand.list@gmail.com> wrote:
>>>>
>>>> When enabling CONFIG_OF on a platform where of_root is not populated by
>>>> firmware, we end up without a root node. In order to apply overlays and
>>>> create subnodes of the root node, we need one. Create this root node
>>>> by unflattening an empty builtin dtb.
>>>>
>>>> If firmware provides a flattened device tree (FDT) then the FDT is
>>>> unflattened via setup_arch().  Otherwise, setup_of() which is called
>>>> immediately after setup_arch(), and will create the default root node
>>>> if it does not exist.
>>>
>>> Why do we need a hook after setup_arch() rather than an initcall?
>>>
>>> Rob
>>
>> It might work as an initcall today.  Maybe not in the future as other
>> initcalls are added.
> 
> That's an argument for never using initcalls (not a bad one either). But 
> we have them and we have little reason not to use them. Also, it's 
> better to do things as late as possible I've found. The earlier you do 
> things, the more architecture specific stuff you hit. That's a big 
> reason for the remaining differences in FDT init across architectures. 
> Maybe after setup_arch is late enough. IDK.
> 
>> But my main stream of thinking is that before the patch "we know" that
>> the device tree data structure exists when setup_arch() returns.
>> Adding setup_of() immediately after setup_arch() retains that
>> guarantee, but one line later in start_kernel().
> 
> I get the logic. I'd just rather not add another hook between the DT 
> code and the core/arch code. Especially for this niche usecase.
> 
> We already have the secondary init when sysfs is up. Can't we just do 
> this there?

In general, I agree with your sentiments about an initcall being a preferred
solution.

But when I was looking at the suggested alternatives, I noticed one sticking
point.  The new setup_of() calls unflatten_device_tree(), which calls
unittest_unflatten_overlay_base().  The call to unittest_unflatten_overlay_base()
is deliberately very early in the boot, so that the memory allocator used
for this very small portion of the devicetree nodes created for unittest
is the same early boot allocator that is used to unflatten an FDT passed
to the kernel from a bootloader.

Digging through this led me to another issue.  I have not tested this patch
series on a user mode linux kernel (on my todo list...).  For user mode linux,
unittest_data_add() is called directly from the late initcall of_unittest().
So for user mode linux, unittest_data_add() will be called a second time - I
need to remove that second call and make sure unittest still works on user
mode linux.

> 
>> I could have instead put the call to setup_of() into each architectures'
>> setup_arch(), but that would just be duplicating the same code for each
>> architecture, which did not seem like a good choice.
> 

> Uhh, no!

Agreed, I guess I was too subtle with "did not seem like a good choice". :-)

> 
> Rob


  reply	other threads:[~2023-03-01 16:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-23 21:34 [PATCH v3 0/2] of: populate of_root_node if not set (alternate) Frank Rowand
2023-02-23 21:34 ` [PATCH v3 1/2] of: create of_root if no dtb provided Frank Rowand
2023-02-27 17:17   ` Rob Herring
2023-03-01  2:05     ` Frank Rowand
2023-03-01  3:00       ` Rob Herring
2023-03-01 16:49         ` Frank Rowand [this message]
2023-02-23 21:34 ` [PATCH v3 2/2] of: unittest: treat missing of_root as error instead of fixing up Frank Rowand
2023-02-23 21:39 ` [PATCH v3 0/2] of: populate of_root_node if not set (alternate) Frank Rowand
2023-02-27  9:31   ` Clément Léger

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=f26ffb41-f542-2809-9818-903947dd6eb4@gmail.com \
    --to=frowand.list@gmail.com \
    --cc=allan.nielsen@microchip.com \
    --cc=clement.leger@bootlin.com \
    --cc=devicetree@vger.kernel.org \
    --cc=horatiu.vultur@microchip.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizhi.hou@xilinx.com \
    --cc=robh@kernel.org \
    --cc=steen.hegelund@microchip.com \
    --cc=thomas.petazzoni@bootlin.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;
as well as URLs for NNTP newsgroup(s).