Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 17 Oct 2011 19:21:16 +0530
From:      "Jayachandran C." <jchandra@freebsd.org>
To:        freebsd-arm@freebsd.org, freebsd-ppc@freebsd.org
Subject:   HEADSUP: FDT phandle change. [svn commit: r226466]
Message-ID:  <CA%2B7sy7BDNg4-aEXH=F7gEWdhjLqRUYxkv4u8_zin30mYNcT--w@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
I have committed this revision that changes the way phandle is
represented for FDT.  The old representation was a pointer,  which
would not work on 64bit - and the new representation is as an offset.

This should not affect the FDT users, but if there is any breakage on
ARM or PPC due to this please let me know.

Thanks,
JC.


---------- Forwarded message ----------
From: Jayachandran C. <jchandra@freebsd.org>
Date: Mon, Oct 17, 2011 at 7:14 PM
Subject: svn commit: r226466 - head/sys/dev/ofw
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
svn-src-head@freebsd.org


Author: jchandra
Date: Mon Oct 17 13:44:33 2011
New Revision: 226466
URL: http://svn.freebsd.org/changeset/base/226466

Log:
=A0FDT changes for 64 bit kernel

=A0Use the offset into the device tree from fdtp as the phandle instead
=A0of using pointer into the device tree. =A0This will make sure that the
=A0phandle fits into a uint32_t type, even when compiled for 64bit.

=A0Reviewed by: =A0raj, nathanw, marcel

Modified:
=A0head/sys/dev/ofw/ofw_fdt.c

Modified: head/sys/dev/ofw/ofw_fdt.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- head/sys/dev/ofw/ofw_fdt.c =A0Mon Oct 17 13:12:47 2011 =A0 =A0 =A0 =A0(=
r226465)
+++ head/sys/dev/ofw/ofw_fdt.c =A0Mon Oct 17 13:44:33 2011 =A0 =A0 =A0 =A0(=
r226466)
@@ -109,22 +109,48 @@ ofw_fdt_init(ofw_t ofw, void *data)
=A0}

=A0/*
- * Device tree functions
+ * Device tree functions.
+ *
+ * We use the offset from fdtp to the node as the 'phandle' in OF interfac=
e.
+ *
+ * phandle is a u32 value, therefore we cannot use the pointer to node as
+ * phandle in 64 bit. We also do not use the usual fdt offset as phandle,
+ * as it can be 0, and the OF interface has special meaning for phandle 0.
=A0*/

+static phandle_t
+fdt_offset_phandle(int offset)
+{
+ =A0 =A0 =A0 if (offset < 0)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (0);
+ =A0 =A0 =A0 return ((phandle_t)offset + fdt_off_dt_struct(fdtp));
+}
+
=A0static int
=A0fdt_phandle_offset(phandle_t p)
=A0{
- =A0 =A0 =A0 const char *dt_struct;
+ =A0 =A0 =A0 int pint =3D (int)p;
+ =A0 =A0 =A0 int dtoff =3D fdt_off_dt_struct(fdtp);
+
+ =A0 =A0 =A0 if (pint < dtoff)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (-1);
+ =A0 =A0 =A0 return (pint - dtoff);
+}
+
+static int
+fdt_pointer_offset(const void *ptr)
+{
+ =A0 =A0 =A0 uintptr_t dt_struct, p;
=A0 =A0 =A0 =A0int offset;

- =A0 =A0 =A0 dt_struct =3D (const char *)fdtp + fdt_off_dt_struct(fdtp);
+ =A0 =A0 =A0 p =3D (uintptr_t)ptr;
+ =A0 =A0 =A0 dt_struct =3D (uintptr_t)fdtp + fdt_off_dt_struct(fdtp);

- =A0 =A0 =A0 if (((const char *)p < dt_struct) ||
- =A0 =A0 =A0 =A0 =A0 (const char *)p > (dt_struct + fdt_size_dt_struct(fdt=
p)))
+ =A0 =A0 =A0 if ((p < dt_struct) ||
+ =A0 =A0 =A0 =A0 =A0 p > (dt_struct + fdt_size_dt_struct(fdtp)))
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return (-1);

- =A0 =A0 =A0 offset =3D (const char *)p - dt_struct;
+ =A0 =A0 =A0 offset =3D p - dt_struct;
=A0 =A0 =A0 =A0if (offset < 0)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return (-1);

@@ -135,15 +161,13 @@ fdt_phandle_offset(phandle_t p)
=A0static phandle_t
=A0ofw_fdt_peer(ofw_t ofw, phandle_t node)
=A0{
- =A0 =A0 =A0 phandle_t p;
=A0 =A0 =A0 =A0int depth, offset;

=A0 =A0 =A0 =A0if (node =3D=3D 0) {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* Find root node */
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0offset =3D fdt_path_offset(fdtp, "/");
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 p =3D (phandle_t)fdt_offset_ptr(fdtp, offset,=
 sizeof(p));

- =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (p);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (fdt_offset_phandle(offset));
=A0 =A0 =A0 =A0}

=A0 =A0 =A0 =A0offset =3D fdt_phandle_offset(node);
@@ -155,10 +179,8 @@ ofw_fdt_peer(ofw_t ofw, phandle_t node)
=A0 =A0 =A0 =A0 =A0 =A0offset =3D fdt_next_node(fdtp, offset, &depth)) {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (depth < 0)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return (0);
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (depth =3D=3D 1) {
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 p =3D (phandle_t)fdt_offset_p=
tr(fdtp, offset, sizeof(p));
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (p);
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (depth =3D=3D 1)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (fdt_offset_phandle(of=
fset));
=A0 =A0 =A0 =A0}

=A0 =A0 =A0 =A0return (0);
@@ -168,7 +190,6 @@ ofw_fdt_peer(ofw_t ofw, phandle_t node)
=A0static phandle_t
=A0ofw_fdt_child(ofw_t ofw, phandle_t node)
=A0{
- =A0 =A0 =A0 phandle_t p;
=A0 =A0 =A0 =A0int depth, offset;

=A0 =A0 =A0 =A0offset =3D fdt_phandle_offset(node);
@@ -180,10 +201,8 @@ ofw_fdt_child(ofw_t ofw, phandle_t node)
=A0 =A0 =A0 =A0 =A0 =A0offset =3D fdt_next_node(fdtp, offset, &depth)) {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (depth < 0)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return (0);
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (depth =3D=3D 1) {
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 p =3D (phandle_t)fdt_offset_p=
tr(fdtp, offset, sizeof(p));
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (p);
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (depth =3D=3D 1)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return (fdt_offset_phandle(of=
fset));
=A0 =A0 =A0 =A0}

=A0 =A0 =A0 =A0return (0);
@@ -193,7 +212,6 @@ ofw_fdt_child(ofw_t ofw, phandle_t node)
=A0static phandle_t
=A0ofw_fdt_parent(ofw_t ofw, phandle_t node)
=A0{
- =A0 =A0 =A0 phandle_t p;
=A0 =A0 =A0 =A0int offset, paroffset;

=A0 =A0 =A0 =A0offset =3D fdt_phandle_offset(node);
@@ -201,15 +219,13 @@ ofw_fdt_parent(ofw_t ofw, phandle_t node
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return (0);

=A0 =A0 =A0 =A0paroffset =3D fdt_parent_offset(fdtp, offset);
- =A0 =A0 =A0 p =3D (phandle_t)fdt_offset_ptr(fdtp, paroffset, sizeof(phand=
le_t));
- =A0 =A0 =A0 return (p);
+ =A0 =A0 =A0 return (fdt_offset_phandle(paroffset));
=A0}

=A0/* Return the package handle that corresponds to an instance handle. */
=A0static phandle_t
=A0ofw_fdt_instance_to_package(ofw_t ofw, ihandle_t instance)
=A0{
- =A0 =A0 =A0 phandle_t p;
=A0 =A0 =A0 =A0int offset;

=A0 =A0 =A0 =A0/*
@@ -223,8 +239,7 @@ ofw_fdt_instance_to_package(ofw_t ofw, i
=A0 =A0 =A0 =A0if (offset < 0)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return (-1);

- =A0 =A0 =A0 p =3D (phandle_t)fdt_offset_ptr(fdtp, offset, sizeof(phandle_=
t));
- =A0 =A0 =A0 return (p);
+ =A0 =A0 =A0 return (fdt_offset_phandle(offset));
=A0}

=A0/* Get the length of a property of a package. */
@@ -343,7 +358,7 @@ ofw_fdt_nextprop(ofw_t ofw, phandle_t pa
=A0 =A0 =A0 =A0if (prop =3D=3D NULL)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return (-1);

- =A0 =A0 =A0 offset =3D fdt_phandle_offset((phandle_t)prop);
+ =A0 =A0 =A0 offset =3D fdt_pointer_offset(prop);
=A0 =A0 =A0 =A0rv =3D fdt_nextprop(offset, buf, size);
=A0 =A0 =A0 =A0return (rv);
=A0}
@@ -374,14 +389,10 @@ ofw_fdt_canon(ofw_t ofw, const char *dev
=A0static phandle_t
=A0ofw_fdt_finddevice(ofw_t ofw, const char *device)
=A0{
- =A0 =A0 =A0 phandle_t p;
=A0 =A0 =A0 =A0int offset;

=A0 =A0 =A0 =A0offset =3D fdt_path_offset(fdtp, device);
-
- =A0 =A0 =A0 p =3D (phandle_t)fdt_offset_ptr(fdtp, offset, sizeof(p));
-
- =A0 =A0 =A0 return (p);
+ =A0 =A0 =A0 return (fdt_offset_phandle(offset));
=A0}

=A0/* Return the fully qualified pathname corresponding to an instance. */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CA%2B7sy7BDNg4-aEXH=F7gEWdhjLqRUYxkv4u8_zin30mYNcT--w>