All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/2] fdt: add support the ePAPR "phandle" property
@ 2011-05-06 17:56 Timur Tabi
  2011-05-06 17:56 ` [U-Boot] [PATCH 2/2] powerpc/85xx: " Timur Tabi
  2011-05-06 18:46 ` [U-Boot] [PATCH 1/2] fdt: " Grant Likely
  0 siblings, 2 replies; 4+ messages in thread
From: Timur Tabi @ 2011-05-06 17:56 UTC (permalink / raw)
  To: u-boot

The ePAPR specification says that phandle properties should be called
"phandle", and not "linux,phandle".  To facilitate the migration from
"linux,phandle" to "phandle", we update some functions to support both
properties.

Signed-off-by: Timur Tabi <timur@freescale.com>
---
 common/fdt_support.c |    6 ++++++
 include/libfdt.h     |   10 ++++++++++
 lib/libfdt/fdt_ro.c  |   18 ++++++++++++++++++
 3 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/common/fdt_support.c b/common/fdt_support.c
index 496040b..85715ff 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -1187,6 +1187,12 @@ int fdt_alloc_phandle(void *blob)
 
 	for (offset = fdt_next_node(blob, -1, NULL); offset >= 0;
 	     offset = fdt_next_node(blob, offset, NULL)) {
+		/* Check the ePAPR-compliant "phandle" property name */
+		val = fdt_getprop(blob, offset, "phandle", &len);
+		if (val)
+			phandle = max(*val, phandle);
+
+		/* Also check the deprecated "linux,phandle" property name */
 		val = fdt_getprop(blob, offset, "linux,phandle", &len);
 		if (val)
 			phandle = max(*val, phandle);
diff --git a/include/libfdt.h b/include/libfdt.h
index d23d40e..092dd34 100644
--- a/include/libfdt.h
+++ b/include/libfdt.h
@@ -452,6 +452,11 @@ static inline void *fdt_getprop_w(void *fdt, int nodeoffset,
  * fdt_get_phandle() retrieves the phandle of the device tree node at
  * structure block offset nodeoffset.
  *
+ * Both the ePAPR "phandle" property as well as the legacy "linux,phandle"
+ * property are supported.  If the device tree node contains both properties,
+ * then "phandle" is used.  However, it is considered an error if the two
+ * properties contain different values.
+ *
  * returns:
  *	the phandle of the node at nodeoffset, on success (!= 0, != -1)
  *	0, if the node has no phandle, or another error occurs
@@ -662,6 +667,11 @@ int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle);
  * 'compatible' property with the given string as one of its elements,
  * it returns non-zero otherwise, or on error.
  *
+ * Both the ePAPR "phandle" property as well as the legacy "linux,phandle"
+ * property are supported.  If the device tree node contains both properties,
+ * then "phandle" is used.  However, it is considered an error if the two
+ * properties contain different values.
+ *
  * returns:
  *	0, if the node has a 'compatible' property listing the given string
  *	1, if the node has a 'compatible' property, but it does not list
diff --git a/lib/libfdt/fdt_ro.c b/lib/libfdt/fdt_ro.c
index 1e1e322..57a901f 100644
--- a/lib/libfdt/fdt_ro.c
+++ b/lib/libfdt/fdt_ro.c
@@ -278,6 +278,14 @@ uint32_t fdt_get_phandle(const void *fdt, int nodeoffset)
 	const uint32_t *php;
 	int len;
 
+	/* First, check the "phandle" property */
+	php = fdt_getprop(fdt, nodeoffset, "phandle", &len);
+	if (php) {
+		/* If the property exists, then use it if it's valid */
+		return len == sizeof(*php) ? fdt32_to_cpu(*php) : 0;
+	}
+
+	/* No "phandle", so check "linux,phandle" */
 	php = fdt_getprop(fdt, nodeoffset, "linux,phandle", &len);
 	if (!php || (len != sizeof(*php)))
 		return 0;
@@ -440,9 +448,19 @@ int fdt_node_offset_by_prop_value(const void *fdt, int startoffset,
 
 int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle)
 {
+	int ret;
+
 	if ((phandle == 0) || (phandle == -1))
 		return -FDT_ERR_BADPHANDLE;
 	phandle = cpu_to_fdt32(phandle);
+
+	/* First check for a matching "phandle" property */
+	ret = fdt_node_offset_by_prop_value(fdt, -1, "phandle",
+					    &phandle, sizeof(phandle));
+	if (ret > 0)
+		return ret;
+
+	/* No "phandle", so check "linux,phandle" */
 	return fdt_node_offset_by_prop_value(fdt, -1, "linux,phandle",
 					     &phandle, sizeof(phandle));
 }
-- 
1.7.3.4

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

* [U-Boot] [PATCH 2/2] powerpc/85xx: add support the ePAPR "phandle" property
  2011-05-06 17:56 [U-Boot] [PATCH 1/2] fdt: add support the ePAPR "phandle" property Timur Tabi
@ 2011-05-06 17:56 ` Timur Tabi
  2011-05-06 18:46 ` [U-Boot] [PATCH 1/2] fdt: " Grant Likely
  1 sibling, 0 replies; 4+ messages in thread
From: Timur Tabi @ 2011-05-06 17:56 UTC (permalink / raw)
  To: u-boot

The ePAPR specification says that phandle properties should be called
"phandle", and not "linux,phandle".  To facilitate the migration from
"linux,phandle" to "phandle", we update fdt_qportal() to support both
properties.

Signed-off-by: Timur Tabi <timur@freescale.com>
---
 arch/powerpc/cpu/mpc85xx/portals.c |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/cpu/mpc85xx/portals.c b/arch/powerpc/cpu/mpc85xx/portals.c
index c014163..bb0ae70 100644
--- a/arch/powerpc/cpu/mpc85xx/portals.c
+++ b/arch/powerpc/cpu/mpc85xx/portals.c
@@ -151,8 +151,19 @@ static int fdt_qportal(void *blob, int off, int id, char *name,
 			dev_handle = fdt_get_phandle(blob, dev_off);
 			if (dev_handle <= 0) {
 				dev_handle = fdt_alloc_phandle(blob);
-				fdt_setprop_cell(blob, dev_off,
+				ret = fdt_setprop_cell(blob, dev_off,
+					"phandle", dev_handle);
+				if (ret < 0)
+					return ret;
+				/*
+				 * For now, also set the deprecated
+				 * "linux,phandle" property, so that we don't
+				 * break older kernels.
+				 */
+				ret = fdt_setprop_cell(blob, dev_off,
 					"linux,phandle", dev_handle);
+				if (ret < 0)
+					return ret;
 			}
 
 			ret = fdt_setprop(blob, childoff, "dev-handle",
-- 
1.7.3.4

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

* [U-Boot] [PATCH 1/2] fdt: add support the ePAPR "phandle" property
  2011-05-06 17:56 [U-Boot] [PATCH 1/2] fdt: add support the ePAPR "phandle" property Timur Tabi
  2011-05-06 17:56 ` [U-Boot] [PATCH 2/2] powerpc/85xx: " Timur Tabi
@ 2011-05-06 18:46 ` Grant Likely
  2011-05-06 18:53   ` Timur Tabi
  1 sibling, 1 reply; 4+ messages in thread
From: Grant Likely @ 2011-05-06 18:46 UTC (permalink / raw)
  To: u-boot

On Fri, May 6, 2011 at 11:56 AM, Timur Tabi <timur@freescale.com> wrote:
> The ePAPR specification says that phandle properties should be called
> "phandle", and not "linux,phandle". ?To facilitate the migration from
> "linux,phandle" to "phandle", we update some functions to support both
> properties.
>
> Signed-off-by: Timur Tabi <timur@freescale.com>

As discussed on IRC, upstream libfdt already supports the "phandle"
property, so u-boot needs to be updated to the latest version from the
dtc.git repo on git.jdl.com.  You'll still need the change to
common/fdt_support.c though.

g.

> ---
> ?common/fdt_support.c | ? ?6 ++++++
> ?include/libfdt.h ? ? | ? 10 ++++++++++
> ?lib/libfdt/fdt_ro.c ?| ? 18 ++++++++++++++++++
> ?3 files changed, 34 insertions(+), 0 deletions(-)
>
> diff --git a/common/fdt_support.c b/common/fdt_support.c
> index 496040b..85715ff 100644
> --- a/common/fdt_support.c
> +++ b/common/fdt_support.c
> @@ -1187,6 +1187,12 @@ int fdt_alloc_phandle(void *blob)
>
> ? ? ? ?for (offset = fdt_next_node(blob, -1, NULL); offset >= 0;
> ? ? ? ? ? ? offset = fdt_next_node(blob, offset, NULL)) {
> + ? ? ? ? ? ? ? /* Check the ePAPR-compliant "phandle" property name */
> + ? ? ? ? ? ? ? val = fdt_getprop(blob, offset, "phandle", &len);
> + ? ? ? ? ? ? ? if (val)
> + ? ? ? ? ? ? ? ? ? ? ? phandle = max(*val, phandle);
> +
> + ? ? ? ? ? ? ? /* Also check the deprecated "linux,phandle" property name */
> ? ? ? ? ? ? ? ?val = fdt_getprop(blob, offset, "linux,phandle", &len);
> ? ? ? ? ? ? ? ?if (val)
> ? ? ? ? ? ? ? ? ? ? ? ?phandle = max(*val, phandle);
> diff --git a/include/libfdt.h b/include/libfdt.h
> index d23d40e..092dd34 100644
> --- a/include/libfdt.h
> +++ b/include/libfdt.h
> @@ -452,6 +452,11 @@ static inline void *fdt_getprop_w(void *fdt, int nodeoffset,
> ?* fdt_get_phandle() retrieves the phandle of the device tree node at
> ?* structure block offset nodeoffset.
> ?*
> + * Both the ePAPR "phandle" property as well as the legacy "linux,phandle"
> + * property are supported. ?If the device tree node contains both properties,
> + * then "phandle" is used. ?However, it is considered an error if the two
> + * properties contain different values.
> + *
> ?* returns:
> ?* ? ? the phandle of the node at nodeoffset, on success (!= 0, != -1)
> ?* ? ? 0, if the node has no phandle, or another error occurs
> @@ -662,6 +667,11 @@ int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle);
> ?* 'compatible' property with the given string as one of its elements,
> ?* it returns non-zero otherwise, or on error.
> ?*
> + * Both the ePAPR "phandle" property as well as the legacy "linux,phandle"
> + * property are supported. ?If the device tree node contains both properties,
> + * then "phandle" is used. ?However, it is considered an error if the two
> + * properties contain different values.
> + *
> ?* returns:
> ?* ? ? 0, if the node has a 'compatible' property listing the given string
> ?* ? ? 1, if the node has a 'compatible' property, but it does not list
> diff --git a/lib/libfdt/fdt_ro.c b/lib/libfdt/fdt_ro.c
> index 1e1e322..57a901f 100644
> --- a/lib/libfdt/fdt_ro.c
> +++ b/lib/libfdt/fdt_ro.c
> @@ -278,6 +278,14 @@ uint32_t fdt_get_phandle(const void *fdt, int nodeoffset)
> ? ? ? ?const uint32_t *php;
> ? ? ? ?int len;
>
> + ? ? ? /* First, check the "phandle" property */
> + ? ? ? php = fdt_getprop(fdt, nodeoffset, "phandle", &len);
> + ? ? ? if (php) {
> + ? ? ? ? ? ? ? /* If the property exists, then use it if it's valid */
> + ? ? ? ? ? ? ? return len == sizeof(*php) ? fdt32_to_cpu(*php) : 0;
> + ? ? ? }
> +
> + ? ? ? /* No "phandle", so check "linux,phandle" */
> ? ? ? ?php = fdt_getprop(fdt, nodeoffset, "linux,phandle", &len);
> ? ? ? ?if (!php || (len != sizeof(*php)))
> ? ? ? ? ? ? ? ?return 0;
> @@ -440,9 +448,19 @@ int fdt_node_offset_by_prop_value(const void *fdt, int startoffset,
>
> ?int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle)
> ?{
> + ? ? ? int ret;
> +
> ? ? ? ?if ((phandle == 0) || (phandle == -1))
> ? ? ? ? ? ? ? ?return -FDT_ERR_BADPHANDLE;
> ? ? ? ?phandle = cpu_to_fdt32(phandle);
> +
> + ? ? ? /* First check for a matching "phandle" property */
> + ? ? ? ret = fdt_node_offset_by_prop_value(fdt, -1, "phandle",
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? &phandle, sizeof(phandle));
> + ? ? ? if (ret > 0)
> + ? ? ? ? ? ? ? return ret;
> +
> + ? ? ? /* No "phandle", so check "linux,phandle" */
> ? ? ? ?return fdt_node_offset_by_prop_value(fdt, -1, "linux,phandle",
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? &phandle, sizeof(phandle));
> ?}
> --
> 1.7.3.4
>
>
>



-- 
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

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

* [U-Boot] [PATCH 1/2] fdt: add support the ePAPR "phandle" property
  2011-05-06 18:46 ` [U-Boot] [PATCH 1/2] fdt: " Grant Likely
@ 2011-05-06 18:53   ` Timur Tabi
  0 siblings, 0 replies; 4+ messages in thread
From: Timur Tabi @ 2011-05-06 18:53 UTC (permalink / raw)
  To: u-boot

Grant Likely wrote:
> As discussed on IRC, upstream libfdt already supports the "phandle"
> property, so u-boot needs to be updated to the latest version from the
> dtc.git repo on git.jdl.com.  You'll still need the change to
> common/fdt_support.c though.

Upstream libfdt was fixed back in 2009.  Why is U-Boot and Linux so outdated?
Shouldn't there be a regular plan to update U-boot and Linux as libfdt is
updated?  I don't see how an 18-month backlog is acceptable.

No offense, but this sounds like something the U-boot fdt maintainer is supposed
to be doing regularly.

-- 
Timur Tabi
Linux kernel developer at Freescale

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

end of thread, other threads:[~2011-05-06 18:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-06 17:56 [U-Boot] [PATCH 1/2] fdt: add support the ePAPR "phandle" property Timur Tabi
2011-05-06 17:56 ` [U-Boot] [PATCH 2/2] powerpc/85xx: " Timur Tabi
2011-05-06 18:46 ` [U-Boot] [PATCH 1/2] fdt: " Grant Likely
2011-05-06 18:53   ` Timur Tabi

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.