linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2 Create empty OF root 0/1] XRT Alveo driver infrastructure overview
@ 2022-02-16  5:00 Lizhi Hou
  2022-02-16  5:00 ` [PATCH V2 Create empty OF root 1/1] of: create empty of root Lizhi Hou
  0 siblings, 1 reply; 4+ messages in thread
From: Lizhi Hou @ 2022-02-16  5:00 UTC (permalink / raw)
  To: devicetree, robh
  Cc: Lizhi Hou, linux-kernel, yilun.xu, maxz, sonal.santan, yliu,
	michal.simek, stefanos, trix, mdf, dwmw2

Hello,

This patch is to create an empty device tree if there is not one. For the use
case that hardware like Xilinx Alveo PCIe accelerator uses flattened device
tree to describe apertures in its PCIe BARs, a base tree with nodes for the
device needs to be created if there is not one. Then the flattened device tree
overlay from the device can be applied to the base tree. Please refer the
previous discussions with device tree maintainer:
    https://lore.kernel.org/lkml/CAL_JsqJfyRymB=VxLuQqLpep+Q1Eie48dobv9sC5OizDz0d2DQ@mail.gmail.com/

This patch is the first step creates empty OF root node if the arch does not
have device tree created. I will post a follow on patch series to add PCIe
interface for the creation of device tree node for a PCIe device. This will
enable a PCIe device driver to apply an overlay under a PCIe device tree node.
Please refer previous discussions with FPGA maintainer:
    https://lore.kernel.org/lkml/20220105225013.1567871-1-lizhi.hou@xilinx.com/

We would like to use this infrastructure to describe and bind platform drivers
for HW IPs in Alveo PCIe accelerator device.

Lizhi Hou (1):
  of: create empty of root

 drivers/of/Kconfig         |  5 ++++
 drivers/of/Makefile        |  1 +
 drivers/of/of_empty_root.c | 51 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 57 insertions(+)
 create mode 100644 drivers/of/of_empty_root.c

-- 
2.27.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH V2 Create empty OF root 1/1] of: create empty of root
  2022-02-16  5:00 [PATCH V2 Create empty OF root 0/1] XRT Alveo driver infrastructure overview Lizhi Hou
@ 2022-02-16  5:00 ` Lizhi Hou
  2022-05-17  3:22   ` Frank Rowand
  0 siblings, 1 reply; 4+ messages in thread
From: Lizhi Hou @ 2022-02-16  5:00 UTC (permalink / raw)
  To: devicetree, robh
  Cc: Lizhi Hou, linux-kernel, yilun.xu, maxz, sonal.santan, yliu,
	michal.simek, stefanos, trix, mdf, dwmw2, Max Zhen

Xilinx Alveo PCIe accelerator cards use flattened device tree to describe
describe apertures in its PCIe BARs. Each device tree node represents an
aperture and each aperture is an hardware unit which requires a driver.
The product detail:
    https://www.xilinx.com/products/boards-and-kits/alveo.html

Thus a base device tree is required. Then the Alveo card driver can load
its flattened device tree and overlay it to the base tree. However device
tree does not always exist. To resolve this, add OF_EMPTY_ROOT config.
When it is selected and there is not a device tree, create an empty device
tree root node.

Signed-off-by: Sonal Santan <sonal.santan@xilinx.com>
Signed-off-by: Max Zhen <max.zhen@xilinx.com>
Signed-off-by: Lizhi Hou <lizhi.hou@xilinx.com>
---
 drivers/of/Kconfig         |  5 ++++
 drivers/of/Makefile        |  1 +
 drivers/of/of_empty_root.c | 51 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 57 insertions(+)
 create mode 100644 drivers/of/of_empty_root.c

diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index 80b5fd44ab1c..452d2316b47b 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -94,4 +94,9 @@ config OF_DMA_DEFAULT_COHERENT
 	# arches should select this if DMA is coherent by default for OF devices
 	bool
 
+config OF_EMPTY_ROOT
+	# driver which requires at least the empty base device tree to
+	# overlay its own device nodes should select this.
+	bool
+
 endif # OF
diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index e0360a44306e..c65364f32935 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -12,6 +12,7 @@ obj-$(CONFIG_OF_RESERVED_MEM) += of_reserved_mem.o
 obj-$(CONFIG_OF_RESOLVE)  += resolver.o
 obj-$(CONFIG_OF_OVERLAY) += overlay.o
 obj-$(CONFIG_OF_NUMA) += of_numa.o
+obj-$(CONFIG_OF_EMPTY_ROOT) += of_empty_root.o
 
 ifdef CONFIG_KEXEC_FILE
 ifdef CONFIG_OF_FLATTREE
diff --git a/drivers/of/of_empty_root.c b/drivers/of/of_empty_root.c
new file mode 100644
index 000000000000..5c429c7a27bd
--- /dev/null
+++ b/drivers/of/of_empty_root.c
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2022 Xilinx, Inc.
+ */
+
+#include <linux/of.h>
+#include <linux/slab.h>
+
+#include "of_private.h"
+
+static int __init of_root_init(void)
+{
+	struct property *prop = NULL;
+	struct device_node *node;
+	__be32 *val = NULL;
+
+	if (of_root)
+		return 0;
+
+	pr_info("Create empty OF root node\n");
+	node = kzalloc(sizeof(*node), GFP_KERNEL);
+	if (!node)
+		return -ENOMEM;
+	of_node_init(node);
+	node->full_name = "/";
+
+	prop = kcalloc(2, sizeof(*prop), GFP_KERNEL);
+	if (!prop)
+		return -ENOMEM;
+
+	val = kzalloc(sizeof(*val), GFP_KERNEL);
+	if (!val)
+		return -ENOMEM;
+	*val = cpu_to_be32(sizeof(void *) / sizeof(u32));
+
+	prop->name = "#address-cells";
+	prop->value = val;
+	prop->length = sizeof(u32);
+	of_add_property(node, prop);
+	prop++;
+	prop->name = "#size-cells";
+	prop->value = val;
+	prop->length = sizeof(u32);
+	of_add_property(node, prop);
+	of_root = node;
+	for_each_of_allnodes(node)
+		__of_attach_node_sysfs(node);
+
+	return 0;
+}
+pure_initcall(of_root_init);
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH V2 Create empty OF root 1/1] of: create empty of root
  2022-02-16  5:00 ` [PATCH V2 Create empty OF root 1/1] of: create empty of root Lizhi Hou
@ 2022-05-17  3:22   ` Frank Rowand
  2022-05-18  5:02     ` Lizhi Hou
  0 siblings, 1 reply; 4+ messages in thread
From: Frank Rowand @ 2022-05-17  3:22 UTC (permalink / raw)
  To: Lizhi Hou, devicetree, robh
  Cc: linux-kernel, yilun.xu, maxz, sonal.santan, yliu, michal.simek,
	stefanos, trix, mdf, dwmw2, Max Zhen

On 2/16/22 23:00, Lizhi Hou wrote:
> Xilinx Alveo PCIe accelerator cards use flattened device tree to describe
> describe apertures in its PCIe BARs. Each device tree node represents an
> aperture and each aperture is an hardware unit which requires a driver.
> The product detail:
>     https://www.xilinx.com/products/boards-and-kits/alveo.html
> 
> Thus a base device tree is required. Then the Alveo card driver can load
> its flattened device tree and overlay it to the base tree. However device
> tree does not always exist. To resolve this, add OF_EMPTY_ROOT config.
> When it is selected and there is not a device tree, create an empty device
> tree root node.
> 

Please run scripts/get_maintainer on your patches to see who to put in
the distribution list.

I recently stumbled across this patch series and the previous related
patch series (currently up to
"[PATCH V3 XRT Alveo Infrastructure 0/8] XRT Alveo driver infrastructure overview")
when I noticed it in an email archive.

A similar need of creating an of_root if otherwise empty is being discussed
in the thread "[PATCH 0/3] add dynamic PCI device of_node creation for overlay"
at https://lore.kernel.org/r/20220427094502.456111-1-clement.leger@bootlin.com

-Frank

> Signed-off-by: Sonal Santan <sonal.santan@xilinx.com>
> Signed-off-by: Max Zhen <max.zhen@xilinx.com>
> Signed-off-by: Lizhi Hou <lizhi.hou@xilinx.com>
> ---
>  drivers/of/Kconfig         |  5 ++++
>  drivers/of/Makefile        |  1 +
>  drivers/of/of_empty_root.c | 51 ++++++++++++++++++++++++++++++++++++++
>  3 files changed, 57 insertions(+)
>  create mode 100644 drivers/of/of_empty_root.c
> 
> diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
> index 80b5fd44ab1c..452d2316b47b 100644
> --- a/drivers/of/Kconfig
> +++ b/drivers/of/Kconfig
> @@ -94,4 +94,9 @@ config OF_DMA_DEFAULT_COHERENT
>  	# arches should select this if DMA is coherent by default for OF devices
>  	bool
>  
> +config OF_EMPTY_ROOT
> +	# driver which requires at least the empty base device tree to
> +	# overlay its own device nodes should select this.
> +	bool
> +
>  endif # OF
> diff --git a/drivers/of/Makefile b/drivers/of/Makefile
> index e0360a44306e..c65364f32935 100644
> --- a/drivers/of/Makefile
> +++ b/drivers/of/Makefile
> @@ -12,6 +12,7 @@ obj-$(CONFIG_OF_RESERVED_MEM) += of_reserved_mem.o
>  obj-$(CONFIG_OF_RESOLVE)  += resolver.o
>  obj-$(CONFIG_OF_OVERLAY) += overlay.o
>  obj-$(CONFIG_OF_NUMA) += of_numa.o
> +obj-$(CONFIG_OF_EMPTY_ROOT) += of_empty_root.o
>  
>  ifdef CONFIG_KEXEC_FILE
>  ifdef CONFIG_OF_FLATTREE
> diff --git a/drivers/of/of_empty_root.c b/drivers/of/of_empty_root.c
> new file mode 100644
> index 000000000000..5c429c7a27bd
> --- /dev/null
> +++ b/drivers/of/of_empty_root.c
> @@ -0,0 +1,51 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (C) 2022 Xilinx, Inc.
> + */
> +
> +#include <linux/of.h>
> +#include <linux/slab.h>
> +
> +#include "of_private.h"
> +
> +static int __init of_root_init(void)
> +{
> +	struct property *prop = NULL;
> +	struct device_node *node;
> +	__be32 *val = NULL;
> +
> +	if (of_root)
> +		return 0;
> +
> +	pr_info("Create empty OF root node\n");
> +	node = kzalloc(sizeof(*node), GFP_KERNEL);
> +	if (!node)
> +		return -ENOMEM;
> +	of_node_init(node);
> +	node->full_name = "/";
> +
> +	prop = kcalloc(2, sizeof(*prop), GFP_KERNEL);
> +	if (!prop)
> +		return -ENOMEM;
> +
> +	val = kzalloc(sizeof(*val), GFP_KERNEL);
> +	if (!val)
> +		return -ENOMEM;
> +	*val = cpu_to_be32(sizeof(void *) / sizeof(u32));
> +
> +	prop->name = "#address-cells";
> +	prop->value = val;
> +	prop->length = sizeof(u32);
> +	of_add_property(node, prop);
> +	prop++;
> +	prop->name = "#size-cells";
> +	prop->value = val;
> +	prop->length = sizeof(u32);
> +	of_add_property(node, prop);
> +	of_root = node;
> +	for_each_of_allnodes(node)
> +		__of_attach_node_sysfs(node);
> +
> +	return 0;
> +}
> +pure_initcall(of_root_init);


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH V2 Create empty OF root 1/1] of: create empty of root
  2022-05-17  3:22   ` Frank Rowand
@ 2022-05-18  5:02     ` Lizhi Hou
  0 siblings, 0 replies; 4+ messages in thread
From: Lizhi Hou @ 2022-05-18  5:02 UTC (permalink / raw)
  To: Frank Rowand, devicetree, robh
  Cc: linux-kernel, yilun.xu, maxz, sonal.santan, larryliu,
	michal.simek, stefanos, trix, mdf, dwmw2, Max Zhen


On 5/16/22 20:22, Frank Rowand wrote:
> CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
>
>
> On 2/16/22 23:00, Lizhi Hou wrote:
>> Xilinx Alveo PCIe accelerator cards use flattened device tree to describe
>> describe apertures in its PCIe BARs. Each device tree node represents an
>> aperture and each aperture is an hardware unit which requires a driver.
>> The product detail:
>>      https://www.xilinx.com/products/boards-and-kits/alveo.html
>>
>> Thus a base device tree is required. Then the Alveo card driver can load
>> its flattened device tree and overlay it to the base tree. However device
>> tree does not always exist. To resolve this, add OF_EMPTY_ROOT config.
>> When it is selected and there is not a device tree, create an empty device
>> tree root node.
>>
> Please run scripts/get_maintainer on your patches to see who to put in
> the distribution list.
>
> I recently stumbled across this patch series and the previous related
> patch series (currently up to
> "[PATCH V3 XRT Alveo Infrastructure 0/8] XRT Alveo driver infrastructure overview")
> when I noticed it in an email archive.
Sorry about this. We will use scripts/get_maintainer to make sure the 
required maintainers are included next time.
>
> A similar need of creating an of_root if otherwise empty is being discussed
> in the thread "[PATCH 0/3] add dynamic PCI device of_node creation for overlay"
> at https://lore.kernel.org/r/20220427094502.456111-1-clement.leger@bootlin.com

Thanks a lot for your information. We investigated on adding dt node for 
PCI device as well and got some questions.

https://lore.kernel.org/lkml/79e4c876-e5a4-861f-cfbc-c75ed1a07ddd@xilinx.com/#t


Thanks,

Lizhi

>
> -Frank
>
>> Signed-off-by: Sonal Santan <sonal.santan@xilinx.com>
>> Signed-off-by: Max Zhen <max.zhen@xilinx.com>
>> Signed-off-by: Lizhi Hou <lizhi.hou@xilinx.com>
>> ---
>>   drivers/of/Kconfig         |  5 ++++
>>   drivers/of/Makefile        |  1 +
>>   drivers/of/of_empty_root.c | 51 ++++++++++++++++++++++++++++++++++++++
>>   3 files changed, 57 insertions(+)
>>   create mode 100644 drivers/of/of_empty_root.c
>>
>> diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
>> index 80b5fd44ab1c..452d2316b47b 100644
>> --- a/drivers/of/Kconfig
>> +++ b/drivers/of/Kconfig
>> @@ -94,4 +94,9 @@ config OF_DMA_DEFAULT_COHERENT
>>        # arches should select this if DMA is coherent by default for OF devices
>>        bool
>>
>> +config OF_EMPTY_ROOT
>> +     # driver which requires at least the empty base device tree to
>> +     # overlay its own device nodes should select this.
>> +     bool
>> +
>>   endif # OF
>> diff --git a/drivers/of/Makefile b/drivers/of/Makefile
>> index e0360a44306e..c65364f32935 100644
>> --- a/drivers/of/Makefile
>> +++ b/drivers/of/Makefile
>> @@ -12,6 +12,7 @@ obj-$(CONFIG_OF_RESERVED_MEM) += of_reserved_mem.o
>>   obj-$(CONFIG_OF_RESOLVE)  += resolver.o
>>   obj-$(CONFIG_OF_OVERLAY) += overlay.o
>>   obj-$(CONFIG_OF_NUMA) += of_numa.o
>> +obj-$(CONFIG_OF_EMPTY_ROOT) += of_empty_root.o
>>
>>   ifdef CONFIG_KEXEC_FILE
>>   ifdef CONFIG_OF_FLATTREE
>> diff --git a/drivers/of/of_empty_root.c b/drivers/of/of_empty_root.c
>> new file mode 100644
>> index 000000000000..5c429c7a27bd
>> --- /dev/null
>> +++ b/drivers/of/of_empty_root.c
>> @@ -0,0 +1,51 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * Copyright (C) 2022 Xilinx, Inc.
>> + */
>> +
>> +#include <linux/of.h>
>> +#include <linux/slab.h>
>> +
>> +#include "of_private.h"
>> +
>> +static int __init of_root_init(void)
>> +{
>> +     struct property *prop = NULL;
>> +     struct device_node *node;
>> +     __be32 *val = NULL;
>> +
>> +     if (of_root)
>> +             return 0;
>> +
>> +     pr_info("Create empty OF root node\n");
>> +     node = kzalloc(sizeof(*node), GFP_KERNEL);
>> +     if (!node)
>> +             return -ENOMEM;
>> +     of_node_init(node);
>> +     node->full_name = "/";
>> +
>> +     prop = kcalloc(2, sizeof(*prop), GFP_KERNEL);
>> +     if (!prop)
>> +             return -ENOMEM;
>> +
>> +     val = kzalloc(sizeof(*val), GFP_KERNEL);
>> +     if (!val)
>> +             return -ENOMEM;
>> +     *val = cpu_to_be32(sizeof(void *) / sizeof(u32));
>> +
>> +     prop->name = "#address-cells";
>> +     prop->value = val;
>> +     prop->length = sizeof(u32);
>> +     of_add_property(node, prop);
>> +     prop++;
>> +     prop->name = "#size-cells";
>> +     prop->value = val;
>> +     prop->length = sizeof(u32);
>> +     of_add_property(node, prop);
>> +     of_root = node;
>> +     for_each_of_allnodes(node)
>> +             __of_attach_node_sysfs(node);
>> +
>> +     return 0;
>> +}
>> +pure_initcall(of_root_init);

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-05-18  5:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-16  5:00 [PATCH V2 Create empty OF root 0/1] XRT Alveo driver infrastructure overview Lizhi Hou
2022-02-16  5:00 ` [PATCH V2 Create empty OF root 1/1] of: create empty of root Lizhi Hou
2022-05-17  3:22   ` Frank Rowand
2022-05-18  5:02     ` Lizhi Hou

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).