All of lore.kernel.org
 help / color / mirror / Atom feed
From: Herve Codina <herve.codina@bootlin.com>
To: Ayush Singh <ayush@beagleboard.org>
Cc: Jason Kridner <jkridner@beagleboard.org>,
	d-gole@ti.com, Deepak Khatri <lorforlinux@beagleboard.org>,
	Robert Nelson <robertcnelson@beagleboard.org>,
	nenad.marinkovic@mikroe.com, Andrew Davis <afd@ti.com>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Robert Nelson <robertcnelson@gmail.com>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>, Arnd Bergmann <arnd@arndb.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Saravana Kannan <saravanak@google.com>,
	David Gibson <david@gibson.dropbear.id.au>,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	Luca Ceresoli <luca.ceresoli@bootlin.com>,
	devicetree-spec@vger.kernel.org
Subject: Re: [RFC] Adding export-symbols to specification
Date: Wed, 12 Feb 2025 11:47:50 +0100	[thread overview]
Message-ID: <20250212114750.6a0ad842@bootlin.com> (raw)
In-Reply-To: <20250205103204.100f4b8c@bootlin.com>

Hi Rob, David,

The export-symbols topic is a blocking point on my side to provide the
support for addon board hot-plugged on connector [0].

Can you provide some feedback on this topic in order for us (me and Ayush)
to move forward.

Best regards,
Hervé

[0]: https://lore.kernel.org/all/20241209151830.95723-1-herve.codina@bootlin.com/


On Wed, 5 Feb 2025 10:32:04 +0100
Herve Codina <herve.codina@bootlin.com> wrote:

> Hi Ayush,
> 
> On Wed, 5 Feb 2025 01:53:54 +0530
> Ayush Singh <ayush@beagleboard.org> wrote:
> 
> > On 2/5/25 00:51, Herve Codina wrote:
> >   
> > > On Tue, 4 Feb 2025 22:54:52 +0530
> > > Ayush Singh <ayush@beagleboard.org> wrote:
> > >    
> > >>> You have perfectly summarized the export-symbols goal and the benefit of
> > >>> this new feature.
> > >>>
> > >>> I am waiting for feedback from other people. I hope we will move forward
> > >>> on this topic and unblock several users (me included) stuck on this real
> > >>> issue.
> > >>>
> > >>> Thanks a lot!
> > >>>
> > >>> Best regards,
> > >>> Hervé    
> > >> While working on a Patch series to the specification itself, I realized
> > >> that I was missing some edge cases, so wanted to discuss those:
> > >>
> > >> # Scope
> > >>
> > >> Should export-symbols only be used to resolve the properties in parent,
> > >> or should all other children (and their decedents) use the
> > >> `export-symbols` for resolving phandles and path references?
> > >>
> > >> For example, should the following work:
> > >>
> > >>
> > >> parent {
> > >>
> > >>     sibling {
> > >>
> > >>         led = <&gpio 0 GPIO_ACTIVE_HIGH>
> > >>
> > >>     };
> > >>
> > >>
> > >>     export-symbols {
> > >>
> > >>         gpio = <&my_gpio1>;
> > >>
> > >>     };
> > >>
> > >> };
> > >>
> > >>
> > >> This would also mean that bottoms up lookup needs to take place for all
> > >> `export-symbols` that might be present in path to root, before using top
> > >> level `__symbols__` or `/aliases`.    
> > > I restricted the use of export-symbols node when an overlay is applied 
> > > at a node
> > > which contains an export-symbols sub-node.
> > >
> > > In your example, If you apply an overlay at parent node, your 
> > > export-symbols
> > > is used but if you apply an overlay at sibling node, your 
> > > export-symbols is
> > > not used.
> > >
> > > Of course if your overlay applied at parent node looks like the following:
> > >
> > > __overlay__ {
> > > sibling {
> > > prop = <&gpio>;
> > > };
> > > };
> > >
> > > &gpio will be resolved using your export-symbols. __overlay__ is applied
> > > at parent -> visible in the overlay.
> > >
> > > If the base device-tree looks like this:
> > > parent {
> > > sibling {
> > > export-symbols {
> > > gpio = <&my_gpio1>;
> > > };
> > > };
> > > };
> > >
> > > The same overlay applied at parent will failed.
> > > Indeed, no export-symbols is available at parent node and so the
> > > gpio symbols used by the overlay will not be resolved even
> > > if an export-symbols exists in the sibling node.
> > > To see this export-symbols from the overlay, the overlay has to be applied
> > > at sibling node and not parent node.    
> > 
> > Yes, but adding export-symbols to specification would mean defining the 
> > behavior in base devicetree as well.
> > 
> > 
> > ```
> > 
> > \ {
> > 
> >      parent {
> > 
> >          export-symbols {
> > 
> >              gpio = <&main_gpio0>;
> > 
> >          };
> > 
> >      };
> > 
> > };
> > 
> > 
> > &parent {
> > 
> >      led = <&gpio 0 GPIO_ACTIVE_HIGH>
> > 
> > };
> > 
> > ```
> >   
> 
> In this example, we can consider that 'led = <&gpio 0 GPIO_ACTIVE_HIGH>' is
> applied to the parent node (&parent).
> 
> Suppose:
>  \ {
>       node-one {
> 	  export-symbols {
> 		gpio = <&main_gpio0>;
>           };
>  
> 	  node-two {
>           	export-symbols {
>               		gpio = <&main_gpio1>;
>           	};
> 	  };
>       };
>  };
> 
> &node-one {  <--- Applied to node-one
> 	my-gpio = <&gpio>;   <--- &main_gpio0 from node-one.export-symbols
> };
> 
> &node-one { <--- Applied to node-one
> 	node-two {
> 		my-gpio = <&gpio>;   <--- &main_gpio0 from node-one.export-symbols
> 	};
> };
> 
> &node-two { <--- Applied to node-two
> 	my-gpio = <&gpio>;   <--- &main_gpio1 from node-two.export-symbols
> };
> 
> Suppose this other base DT
> \ {
> 	node-one {
> 		export-symbols {
> 			gpio = <&main_gpio0>;
> 		};
> 		my-gpio = <&gpio>;  <--- Not allowed as there is no notion of
> 				         fragment applied. my-gpio was not
> 					 "applied" but already present in the
> 					 node description
> 	};
>  };
> 
> Two questions:
> - Does it make sense ?
> - Is it easily implementable ?
> 
> > 
> > It might not make sense to add it to devicetree specification if the 
> > node does not function in normal devicetree context.
> >   
> > >>
> > >> # Export symbols phandles
> > >>
> > >> Can export symbols reference each other? For example is the following 
> > >> valid:
> > >>
> > >>
> > >> parent {
> > >>
> > >>     export-symbols {
> > >>
> > >>         shadow_gpio = <&my_gpio1>;
> > >>
> > >>         gpio = <&shadow_gpio>;
> > >>
> > >>     };
> > >>
> > >> };    
> > > For sure, not planned.
> > >
> > > Also, maybe I missed something but I am not sure you can have a
> > > phandle referencing a property.
> > >
> > > In your example, shadow_gpio is a property, even if we add a label
> > > to this property i.e.
> > > label_shadow_gpio: shadow_gpio = <&my_gpio1>;
> > >
> > > How can we set:
> > > gpio = <&label_shadow_gpio>;    
> > 
> > Well, technically, all phandles actually just reference a property since 
> > they are resolved using the properties defined in `__symbols__` node or 
> > `/aliases`. So it is pretty simple to add the functionality described above.  
> 
> I think in __symbols__ we have labels not phandles.
> At runtime, in the end, a phandles are numbers.
> 
>   some-node {
> 	phandle = <0x12>;
>   };
> 
>   other-node {
> 	ref-to-some-node = <0x12>; <--- It references a node which has phandle == 0x12
>   };
> 
> >   
> > > Best regards,
> > > Hervé
> > >    
> > 
> > 
> > I have been thinking about some alternative approaches as well, and 
> > something that sounds nice is `/ephimeral-symbols`. Let me explain what 
> > I mean:
> > 
> > `/ephemeral-symbols` can be a global node whose properties have a single 
> > phandle as value. For example:
> > 
> > 
> > / {
> >      ephemeral-symbols {
> >        connector1 = <&connector1>;
> >        gpio = <&my_gpio1>;
> >      };
> > };
> > 
> > 
> > This node will take precedence over `__symbols__` and will be used for 
> > symbol resolution. However, it will never be present in the compiled 
> > devicetree blob.
> > 
> > In case of base devicetree, it can be used to generate symbols for 
> > specific nodes:
> > 
> > 
> > / {
> >      connector1 {
> >          prop = "1";
> >      };
> > 
> >      ephemeral-symbols {
> >          connector1 = <&connector1>;
> >      };
> > };
> > 
> > 
> > Will compile to:
> > 
> > 
> > / {
> > 
> >      connector1 {
> >          prop = "1";
> >      };
> > 
> >      __symbols__ {
> >          connector1 = "/connector1";
> >      };
> > 
> > };
> > 
> > 
> > In case of addon board overlay setup, it can be used in a similar way to 
> > the __symbols__ proposal by Andrew [0].
> > 
> > 
> > So you have the base devicetree:
> > 
> > 
> > / {
> > 
> >      connector1 {
> >      };
> > 
> >      connector2 {
> >      };
> > 
> >      ephemeral-symbols {
> >          connector1 = <&connector1>;
> >      };
> > };
> > 
> > 
> > adapter overlay:
> > 
> > 
> > /dts-v1/;
> > /plugin/;
> > 
> > &{/} {
> >      ephemeral-symbols {
> >          ABC_CONNECTOR = <&connector1>;
> >      };
> > };
> > 
> > 
> > addon board overlay:
> > 
> > 
> > /dts-v1/;
> > /plugin/;
> > 
> > 
> > &ABC_CONNECTOR {
> > 
> >      prop = "val";
> > 
> > };
> > 
> > 
> > Which will end up resolving to:
> > 
> > 
> > / {
> > 
> >      connector1 {
> >          prop = "val";
> >      };
> > 
> >      connector2 {
> >      };
> > 
> >      __symbols__ {
> >          connector1 = "/connector1";
> >          connector2 = "/connector2";
> >      };
> > 
> > };  
> 
> You need 2 overlays and you need to have both overlay applied in an atomic
> way.
> 
> adapter-connector1.dtso then addon.dtso
> 
> You should avoid this kind of non atomic flow:
>   adapter-connector1.dtso
>   adapter-connector2.dtso  <--- ABC_CONNECTOR changed
>   addon.dtso <--- ABC_CONNECTOR from adapter-connector2.dtso: Ok
>   addon.dtso <-- ABC_CONNECTOR is no more from adapter-connector1.dtso
> 
> I really wanted to avoid this extra complexity (runtime and maintenance)
> involving two overlays.
> 
> With epheral-symbols, you need to use ABC_CONNECTOR as a reference and not
> a phandle. I mean:
> in the overlay:
>   &ABC_CONNECTOR {   <--- Use a reference: ok
>       some-thing;
>   };
> 
>   node {
>     phandle-to-connector = <&ABC_CONNECTOR>; <--- Use as phandle: ko
>   };
> 
> To use a phandle, you need to have a phandle = <0x??> property set in the node
> the phandle is pointing to. In your base dt:
> > / {
> > 
> >      connector1 {
> >      };
> > 
> >      connector2 {
> >      };
> > 
> >      ephemeral-symbols {
> >          connector1 = <&connector1>;
> >      };
> > };  
> 
> connector2 will not have its phandle property set unless you
>   - set a label and use that label in a phandle reference in your base DT.
> or
>   - set a label and compile with -@ flag
> 
> On my use case, my connector node is not referenced by a phandle in my
> base DT, except export-symbols.
> I really don't need and don't want to export all possible symbols of my
> base DT (I don't use -@ option).
> 
> An other rule we try to follow on our side (me and Luca) is:
> Overlays are supposed to add or remove descriptions of new or removed
> hardwares and so overlays add or remove nodes and not properties in
> existing node (which means modify existing hardware).
> 
> > 
> > 
> > It does seem like it avoids the pitfalls of [0] (no global __symbols__ 
> > polluting and chaining is fine since we do not need to resize devicetree 
> > to resolve path references). But it might have some other flaws I am 
> > missing right now.  
> 
> I don't think we pollute the global __symbols__ with export-symbols
> solution :)
> 
> Related to implementation details (resizing devicetree), my turn :)
> 
> At runtime the implementation constraint is that adding a property in an
> already existing node leads to a memory leak and so adding connector2 in
> __symbols__ node at runtime is an issue.
> 
> Best regards,
> Hervé



-- 
Hervé Codina, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

  reply	other threads:[~2025-02-12 10:48 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-27 13:45 [RFC] Adding export-symbols to specification Ayush Singh
2025-01-27 15:20 ` Herve Codina
2025-02-04 17:24   ` Ayush Singh
2025-02-04 19:21     ` Herve Codina
2025-02-04 20:23       ` Ayush Singh
2025-02-05  9:32         ` Herve Codina
2025-02-12 10:47           ` Herve Codina [this message]
2025-02-12 11:02           ` Ayush Singh
2025-01-30 16:47 ` Quentin Schulz
2025-01-30 18:07   ` Herve Codina
2025-01-30 19:01     ` Ayush Singh

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=20250212114750.6a0ad842@bootlin.com \
    --to=herve.codina@bootlin.com \
    --cc=afd@ti.com \
    --cc=arnd@arndb.de \
    --cc=ayush@beagleboard.org \
    --cc=conor+dt@kernel.org \
    --cc=d-gole@ti.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=devicetree-spec@vger.kernel.org \
    --cc=geert@linux-m68k.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jkridner@beagleboard.org \
    --cc=krzk+dt@kernel.org \
    --cc=lorforlinux@beagleboard.org \
    --cc=luca.ceresoli@bootlin.com \
    --cc=nenad.marinkovic@mikroe.com \
    --cc=robertcnelson@beagleboard.org \
    --cc=robertcnelson@gmail.com \
    --cc=robh@kernel.org \
    --cc=saravanak@google.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 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.