2022-05-26 18:32:13

by Pintu Kumar

[permalink] [raw]
Subject: Queries: Using ifdef CONFIG condition in dts files

Hi,

I have a generic question regarding conditional compilation options in
dts/dtsi files.
Our Kernel version is: 4.14
Let's say I have a Kernel config such as CONFIG_XYZ.
This driver uses a CMA reserved memory and its node is defined in a
mysoc.dtsi file.
Like:
#if defined(CONFIG_XYZ)
&reserved_mem {
xyz_region: xyz_region {
compatible = "shared-dma-pool";
reusable;
size = <0x600000>;
};
};
#endif

The problem is as follows:
a) The same kernel/dts source is shared across 2 product versions.
b) In one product we need to enable this CONFIG_XYZ but in another
product we need to disable it.
c) When we disable the CONFIG we wanted this dts node also to be
disabled together.
d) When we add "#if defined(CONFIG_XYZ)" check in the dtsi file, it
works if the CONFIG is disabled, but it does not work if CONFIG is
enabled (node is not getting created).
e) This mysoc.dtsi file is getting included in many other dts files,
so we cannot add a compilation check in Makefile. We will end up
renaming many files just to protect this one change.

Is there any other better way to handle this situation ?

I see that in latest kernel we have a conditional compilation added like this:
#ifdef SOC_HAS_USB2_CH2
https://elixir.bootlin.com/linux/latest/source/arch/arm64/boot/dts/renesas/salvator-common.dtsi#L1028

But the same is not recognized by the device tree compiler when using
kernel CONFIG_ check.

Is it the device-tree compiler issue which got fixed in the latest version ?
Or, is it because Kernel config cannot be shared with device-tree ?

Please let us know if there is any other opinion.


Thank you.

Regards,
Pintu


2022-05-28 00:58:51

by Pintu Kumar

[permalink] [raw]
Subject: Re: Queries: Using ifdef CONFIG condition in dts files

On Fri, 27 May 2022 at 15:34, Pintu Agarwal <[email protected]> wrote:
>
> Hi,
>
> On Thu, 26 May 2022 at 19:53, T.Michael Turney <[email protected]> wrote:
> >
> > Kernel developers correct me where I go astray, but this seems like the
> > CONFIG_XYZ value is not available in this file. This would explain why
> > the disable case works.
> >
> > At top of dtsi file are you #include <config.h> or whatever the correct
> > syntax is to see the CONFIG values?
>
> Thanks for your comments.
> No, I could not find any specific config,h to be included to make the
> CONFIG values visible to dts.
>

BTW, I tried another approach but this also doesn't work when CONFIG is enabled.
a) I have created a new header file such as myxyz.h and defined a new
macro with config check.
=> myxyz.h
+#ifdef CONFIG_XYZ
+#define XYZ_CMA
+#endif

b) Then I included the header file in my dtsi file and used ifdef with
the new macro.

#include "myxyz.h"

#ifdef CONFIG_XYZ
&reserved_mem {
xyz_region: xyz_region {
compatible = "shared-dma-pool";
reusable;
size = <0x600000>;
};
};
#endif

But unfortunately this approach also did not work when CONFIG is
enabled. So, when config enable/disable its same behavior.
However, if I put the #define in the dtsi file itself then it works as expected.


Thanks,
Pintu

2022-05-28 20:37:44

by Pintu Kumar

[permalink] [raw]
Subject: Re: Queries: Using ifdef CONFIG condition in dts files

Sorry, a small correction.

On Fri, 27 May 2022 at 17:06, Pintu Agarwal <[email protected]> wrote:
>
> On Fri, 27 May 2022 at 15:34, Pintu Agarwal <[email protected]> wrote:
> >
> > Hi,
> >
> > On Thu, 26 May 2022 at 19:53, T.Michael Turney <[email protected]> wrote:
> > >
> > > Kernel developers correct me where I go astray, but this seems like the
> > > CONFIG_XYZ value is not available in this file. This would explain why
> > > the disable case works.
> > >
> > > At top of dtsi file are you #include <config.h> or whatever the correct
> > > syntax is to see the CONFIG values?
> >
> > Thanks for your comments.
> > No, I could not find any specific config,h to be included to make the
> > CONFIG values visible to dts.
> >
>
> BTW, I tried another approach but this also doesn't work when CONFIG is enabled.
> a) I have created a new header file such as myxyz.h and defined a new
> macro with config check.
> => myxyz.h
> +#ifdef CONFIG_XYZ
> +#define XYZ_CMA
> +#endif
>
> b) Then I included the header file in my dtsi file and used ifdef with
> the new macro.
>
> #include "myxyz.h"
>
> #ifdef CONFIG_XYZ

#ifdef XYZ_CMA

> &reserved_mem {
> xyz_region: xyz_region {
> compatible = "shared-dma-pool";
> reusable;
> size = <0x600000>;
> };
> };
> #endif
>
> But unfortunately this approach also did not work when CONFIG is
> enabled. So, when config enable/disable its same behavior.
> However, if I put the #define in the dtsi file itself then it works as expected.
>
>
> Thanks,
> Pintu

2022-05-28 20:37:45

by Pintu Kumar

[permalink] [raw]
Subject: Re: Queries: Using ifdef CONFIG condition in dts files

Hi,

On Thu, 26 May 2022 at 19:53, T.Michael Turney <[email protected]> wrote:
>
> Kernel developers correct me where I go astray, but this seems like the
> CONFIG_XYZ value is not available in this file. This would explain why
> the disable case works.
>
> At top of dtsi file are you #include <config.h> or whatever the correct
> syntax is to see the CONFIG values?

Thanks for your comments.
No, I could not find any specific config,h to be included to make the
CONFIG values visible to dts.

Thanks,
Pintu

>
> On 5/26/2022 1:46 AM, Pintu Agarwal wrote:
> > Hi,
> >
> > I have a generic question regarding conditional compilation options in
> > dts/dtsi files.
> > Our Kernel version is: 4.14
> > Let's say I have a Kernel config such as CONFIG_XYZ.
> > This driver uses a CMA reserved memory and its node is defined in a
> > mysoc.dtsi file.
> > Like:
> > #if defined(CONFIG_XYZ)
> > &reserved_mem {
> > xyz_region: xyz_region {
> > compatible = "shared-dma-pool";
> > reusable;
> > size = <0x600000>;
> > };
> > };
> > #endif
> >
> > The problem is as follows:
> > a) The same kernel/dts source is shared across 2 product versions.
> > b) In one product we need to enable this CONFIG_XYZ but in another
> > product we need to disable it.
> > c) When we disable the CONFIG we wanted this dts node also to be
> > disabled together.
> > d) When we add "#if defined(CONFIG_XYZ)" check in the dtsi file, it
> > works if the CONFIG is disabled, but it does not work if CONFIG is
> > enabled (node is not getting created).
> > e) This mysoc.dtsi file is getting included in many other dts files,
> > so we cannot add a compilation check in Makefile. We will end up
> > renaming many files just to protect this one change.
> >
> > Is there any other better way to handle this situation ?
> >
> > I see that in latest kernel we have a conditional compilation added like this:
> > #ifdef SOC_HAS_USB2_CH2
> > https://elixir.bootlin.com/linux/latest/source/arch/arm64/boot/dts/renesas/salvator-common.dtsi#L1028
> >
> > But the same is not recognized by the device tree compiler when using
> > kernel CONFIG_ check.
> >
> > Is it the device-tree compiler issue which got fixed in the latest version ?
> > Or, is it because Kernel config cannot be shared with device-tree ?
> >
> > Please let us know if there is any other opinion.
> >
> >
> > Thank you.
> >
> > Regards,
> > Pintu