* Preprocessor arithmetic in dtsi files (base + offset)
@ 2015-11-26 13:16 Mason
[not found] ` <56570620.3070106-GANU6spQydw@public.gmane.org>
0 siblings, 1 reply; 7+ messages in thread
From: Mason @ 2015-11-26 13:16 UTC (permalink / raw)
To: Linux ARM, DT
Cc: Mark Rutland, Pawel Moll, Rob Herring, Arnd Bergmann,
Sebastian Frias
Hello,
In the device tree for my ARM platform, I have several nodes with
addresses within the SCU block:
scu: scu@20000000 {
compatible = "arm,cortex-a9-scu";
reg = <0x20000000 0x100>;
gic: interrupt-controller@20001000 {
compatible = "arm,cortex-a9-gic";
reg = <0x20001000 0x1000>, <0x20000100 0x0100>;
twd-timer@20000600 {
compatible = "arm,cortex-a9-twd-timer";
reg = <0x20000600 0x10>;
Can I use preprocessor arithmetic to abstract the base address,
as would be done in C?
#define SCU_BASE 0x20000000
scu: scu@XXX {
compatible = "arm,cortex-a9-scu";
reg = <SCU_BASE 0x100>;
gic: interrupt-controller@XXX {
compatible = "arm,cortex-a9-gic";
reg = <SCU_BASE+0x1000 0x1000>, <SCU_BASE+0x100 0x0100>;
twd-timer@XXX {
compatible = "arm,cortex-a9-twd-timer";
reg = <SCU_BASE+0x600 0x10>;
Are the @XXX important? Can they be removed altogether?
Regards.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 7+ messages in thread[parent not found: <56570620.3070106-GANU6spQydw@public.gmane.org>]
* Re: Preprocessor arithmetic in dtsi files (base + offset) [not found] ` <56570620.3070106-GANU6spQydw@public.gmane.org> @ 2015-11-26 13:52 ` Mark Rutland 2015-11-26 13:59 ` Russell King - ARM Linux 1 sibling, 0 replies; 7+ messages in thread From: Mark Rutland @ 2015-11-26 13:52 UTC (permalink / raw) To: Mason Cc: Linux ARM, DT, Pawel Moll, Rob Herring, Arnd Bergmann, Sebastian Frias On Thu, Nov 26, 2015 at 02:16:16PM +0100, Mason wrote: > Hello, > > In the device tree for my ARM platform, I have several nodes with > addresses within the SCU block: > > scu: scu@20000000 { > compatible = "arm,cortex-a9-scu"; > reg = <0x20000000 0x100>; > > gic: interrupt-controller@20001000 { > compatible = "arm,cortex-a9-gic"; > reg = <0x20001000 0x1000>, <0x20000100 0x0100>; > > twd-timer@20000600 { > compatible = "arm,cortex-a9-twd-timer"; > reg = <0x20000600 0x10>; > > Can I use preprocessor arithmetic to abstract the base address, > as would be done in C? > > #define SCU_BASE 0x20000000 > > scu: scu@XXX { > compatible = "arm,cortex-a9-scu"; > reg = <SCU_BASE 0x100>; > > gic: interrupt-controller@XXX { > compatible = "arm,cortex-a9-gic"; > reg = <SCU_BASE+0x1000 0x1000>, <SCU_BASE+0x100 0x0100>; The pre-processor would only do substitution, not arithmetic. So the '+' would flow all the way to DTC. DTC does have some basic integer expression support (see [1]), but it looks like it can only work at the cell level, so generally it needs to be avoided (in case #address-cells >1, for example). So generally I think that such arithmetic should be avoided. > twd-timer@XXX { > compatible = "arm,cortex-a9-twd-timer"; > reg = <SCU_BASE+0x600 0x10>; > > Are the @XXX important? Can they be removed altogether? The bit after the @ is called the unit-address. It's meant to be there (matching the base address of the first reg entry) to disambiguate nodes and make it simple to figure out where a node lives in the physical address space. They should stay. Thanks, Mark. [1] https://git.kernel.org/cgit/linux/kernel/git/jdl/dtc.git/commit/?id=5f0c3b2d6235dec65fff1628a97f45e21680b36d -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Preprocessor arithmetic in dtsi files (base + offset) [not found] ` <56570620.3070106-GANU6spQydw@public.gmane.org> 2015-11-26 13:52 ` Mark Rutland @ 2015-11-26 13:59 ` Russell King - ARM Linux [not found] ` <20151126135957.GC8644-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org> 1 sibling, 1 reply; 7+ messages in thread From: Russell King - ARM Linux @ 2015-11-26 13:59 UTC (permalink / raw) To: Mason Cc: Linux ARM, DT, Mark Rutland, Arnd Bergmann, Pawel Moll, Sebastian Frias On Thu, Nov 26, 2015 at 02:16:16PM +0100, Mason wrote: > #define SCU_BASE 0x20000000 > > scu: scu@XXX { > compatible = "arm,cortex-a9-scu"; > reg = <SCU_BASE 0x100>; > > gic: interrupt-controller@XXX { > compatible = "arm,cortex-a9-gic"; > reg = <SCU_BASE+0x1000 0x1000>, <SCU_BASE+0x100 0x0100>; You don't get preprocessor arithmetic here. What you get is this passed to DTC: reg = <0x20000000+0x1000 0x1000>... The only time the preprocessor does arithmetic is when it needs to evaluate an expression, eg, in an #if statement. The @XXX are part of the requirements from ePAPR, and are required to be conformant with the spec. -- FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up according to speedtest.net. -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <20151126135957.GC8644-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org>]
* Re: Preprocessor arithmetic in dtsi files (base + offset) [not found] ` <20151126135957.GC8644-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org> @ 2015-11-26 14:44 ` Mason [not found] ` <56571ACC.9080306-GANU6spQydw@public.gmane.org> 0 siblings, 1 reply; 7+ messages in thread From: Mason @ 2015-11-26 14:44 UTC (permalink / raw) To: Russell King - ARM Linux Cc: Linux ARM, DT, Mark Rutland, Arnd Bergmann, Pawel Moll, Sebastian Frias On 26/11/2015 14:59, Russell King - ARM Linux wrote: > On Thu, Nov 26, 2015 at 02:16:16PM +0100, Mason wrote: >> #define SCU_BASE 0x20000000 >> >> scu: scu@XXX { >> compatible = "arm,cortex-a9-scu"; >> reg = <SCU_BASE 0x100>; >> >> gic: interrupt-controller@XXX { >> compatible = "arm,cortex-a9-gic"; >> reg = <SCU_BASE+0x1000 0x1000>, <SCU_BASE+0x100 0x0100>; > > You don't get preprocessor arithmetic here. What you get is this passed > to DTC: > > reg = <0x20000000+0x1000 0x1000>... > > The only time the preprocessor does arithmetic is when it needs to > evaluate an expression, eg, in an #if statement. Doh! Brain malfunction. No arithmetic indeed. Working with the preprocessor would have to involve token-pasting. #define SCU_BASE(OFFSET) 2000##OFFSET #define SCU_BASEX(OFFSET) 0x2000##OFFSET gic: interrupt-controller@SCU_BASE(1000) { reg = <SCU_BASEX(1000) 0x1000>, <SCU_BASEX(0100) 0x0100>; }; My very own abomination! Regards. -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <56571ACC.9080306-GANU6spQydw@public.gmane.org>]
* Re: Preprocessor arithmetic in dtsi files (base + offset) [not found] ` <56571ACC.9080306-GANU6spQydw@public.gmane.org> @ 2015-11-26 16:23 ` Geert Uytterhoeven [not found] ` <CAMuHMdX9JRRURMxmNFcKOkzeO1B5Nmnk+XnOpgcLsPbiG4CfSA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 7+ messages in thread From: Geert Uytterhoeven @ 2015-11-26 16:23 UTC (permalink / raw) To: Mason Cc: Russell King - ARM Linux, Linux ARM, DT, Mark Rutland, Arnd Bergmann, Pawel Moll, Sebastian Frias On Thu, Nov 26, 2015 at 3:44 PM, Mason <slash.tmp-GANU6spQydw@public.gmane.org> wrote: > On 26/11/2015 14:59, Russell King - ARM Linux wrote: >> On Thu, Nov 26, 2015 at 02:16:16PM +0100, Mason wrote: >>> #define SCU_BASE 0x20000000 >>> >>> scu: scu@XXX { >>> compatible = "arm,cortex-a9-scu"; >>> reg = <SCU_BASE 0x100>; >>> >>> gic: interrupt-controller@XXX { >>> compatible = "arm,cortex-a9-gic"; >>> reg = <SCU_BASE+0x1000 0x1000>, <SCU_BASE+0x100 0x0100>; >> >> You don't get preprocessor arithmetic here. What you get is this passed >> to DTC: >> >> reg = <0x20000000+0x1000 0x1000>... >> >> The only time the preprocessor does arithmetic is when it needs to >> evaluate an expression, eg, in an #if statement. > > Doh! Brain malfunction. No arithmetic indeed. > Working with the preprocessor would have to involve token-pasting. > > #define SCU_BASE(OFFSET) 2000##OFFSET > #define SCU_BASEX(OFFSET) 0x2000##OFFSET > > gic: interrupt-controller@SCU_BASE(1000) { > reg = <SCU_BASEX(1000) 0x1000>, <SCU_BASEX(0100) 0x0100>; > }; > > My very own abomination! Yeah! ;-) I guess this would work, too? scu_container@20000000 { compatible = "simple-bus"; ranges = <0x0 0x20000000 0x10000>; #address-cells = <1>; #size-cells = <1>; scu: scu@0 { compatible = "arm,cortex-a9-scu"; reg = <0x0000 0x100>; gic: interrupt-controller@1000 { compatible = "arm,cortex-a9-gic"; reg = <0x1000 0x1000>, <0x0100 0x0100>; twd-timer@0600 { compatible = "arm,cortex-a9-twd-timer"; reg = <0x0600 0x10>; }; No more explicit arithmetic needed, just substitue "20000000". Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <CAMuHMdX9JRRURMxmNFcKOkzeO1B5Nmnk+XnOpgcLsPbiG4CfSA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: Preprocessor arithmetic in dtsi files (base + offset) [not found] ` <CAMuHMdX9JRRURMxmNFcKOkzeO1B5Nmnk+XnOpgcLsPbiG4CfSA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2015-11-26 17:51 ` Robin Murphy 2015-12-02 22:14 ` Mason 1 sibling, 0 replies; 7+ messages in thread From: Robin Murphy @ 2015-11-26 17:51 UTC (permalink / raw) To: Geert Uytterhoeven, Mason Cc: Mark Rutland, DT, Russell King - ARM Linux, Arnd Bergmann, Pawel Moll, Sebastian Frias, Linux ARM On 26/11/15 16:23, Geert Uytterhoeven wrote: [...] > I guess this would work, too? > > scu_container@20000000 { > compatible = "simple-bus"; > > ranges = <0x0 0x20000000 0x10000>; > #address-cells = <1>; > #size-cells = <1>; > > scu: scu@0 { > compatible = "arm,cortex-a9-scu"; > reg = <0x0000 0x100>; > > gic: interrupt-controller@1000 { > compatible = "arm,cortex-a9-gic"; > reg = <0x1000 0x1000>, <0x0100 0x0100>; > > twd-timer@0600 { > compatible = "arm,cortex-a9-twd-timer"; > reg = <0x0600 0x10>; > }; > > No more explicit arithmetic needed, just substitue "20000000". Which, funnily enough, ends up looking an awful lot like the definition in the hardware documentation[1] too ;) Robin. [1]:http://infocenter.arm.com/help/topic/com.arm.doc.ddi0407i/CACCJFCJ.html > Gr{oetje,eeting}s, > > Geert > > -- > Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org > > In personal conversations with technical people, I call myself a hacker. But > when I'm talking to journalists I just say "programmer" or something like that. > -- Linus Torvalds > > _______________________________________________ > linux-arm-kernel mailing list > linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel > -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Preprocessor arithmetic in dtsi files (base + offset) [not found] ` <CAMuHMdX9JRRURMxmNFcKOkzeO1B5Nmnk+XnOpgcLsPbiG4CfSA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2015-11-26 17:51 ` Robin Murphy @ 2015-12-02 22:14 ` Mason 1 sibling, 0 replies; 7+ messages in thread From: Mason @ 2015-12-02 22:14 UTC (permalink / raw) To: Geert Uytterhoeven Cc: Russell King - ARM Linux, Linux ARM, DT, Mark Rutland, Arnd Bergmann, Pawel Moll, Sebastian Frias On 26/11/2015 17:23, Geert Uytterhoeven wrote: > I guess this would work, too? > > scu_container@20000000 { > compatible = "simple-bus"; > > ranges = <0x0 0x20000000 0x10000>; > #address-cells = <1>; > #size-cells = <1>; > > scu: scu@0 { > compatible = "arm,cortex-a9-scu"; > reg = <0x0000 0x100>; > > gic: interrupt-controller@1000 { > compatible = "arm,cortex-a9-gic"; > reg = <0x1000 0x1000>, <0x0100 0x0100>; > > twd-timer@0600 { > compatible = "arm,cortex-a9-twd-timer"; > reg = <0x0600 0x10>; > }; > > No more explicit arithmetic needed, just substitute "20000000". I like it! Only one address to change in the next chip. Minimizes the risk of missing something. (I see that armada did something similar, but they also grouped unrelated stuff. And bcm5301x did exactly what you suggested.) Wondering if there are macro definitions for the intra-SCU offsets? So I could have symbolic names, such as twd-timer@0600 { reg = <TWD_OFFSET 0x10> Didn't see anything appropriate in include and arch/arm. Should I include my own definitions at the top of the dtsi? Regards. -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2015-12-02 22:14 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-26 13:16 Preprocessor arithmetic in dtsi files (base + offset) Mason
[not found] ` <56570620.3070106-GANU6spQydw@public.gmane.org>
2015-11-26 13:52 ` Mark Rutland
2015-11-26 13:59 ` Russell King - ARM Linux
[not found] ` <20151126135957.GC8644-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org>
2015-11-26 14:44 ` Mason
[not found] ` <56571ACC.9080306-GANU6spQydw@public.gmane.org>
2015-11-26 16:23 ` Geert Uytterhoeven
[not found] ` <CAMuHMdX9JRRURMxmNFcKOkzeO1B5Nmnk+XnOpgcLsPbiG4CfSA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-11-26 17:51 ` Robin Murphy
2015-12-02 22:14 ` Mason
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).