From owner-freebsd-ppc@FreeBSD.ORG Mon Oct 17 14:22:22 2011 Return-Path: Delivered-To: freebsd-ppc@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AC886106566B; Mon, 17 Oct 2011 14:22:22 +0000 (UTC) (envelope-from c.jayachandran@gmail.com) Received: from mail-ww0-f50.google.com (mail-ww0-f50.google.com [74.125.82.50]) by mx1.freebsd.org (Postfix) with ESMTP id 091A38FC13; Mon, 17 Oct 2011 14:22:21 +0000 (UTC) Received: by wwi18 with SMTP id 18so3158292wwi.31 for ; Mon, 17 Oct 2011 07:22:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:date:x-google-sender-auth:message-id:subject :from:to:content-type:content-transfer-encoding; bh=oBTOZi9ypJVnTnvgxiknMq6J+iMS1Ikm2Ix+I5b6PBw=; b=bUefdqpFcxAmAVlofwId/1r5CaJUfWDZFxrdKHsMYc7xKMrqTtdzaqGcAzyDKvOYWf /INAo6pg8WKZ7gh6R1nQpNj4L19sRyFMu3Whwfh3MlR2LTGF7YgOg3c6fHZjlFH8PFL9 vbMt33oQszokIIuBK5J4wS/mUT1/X2Qxi1ZP8= MIME-Version: 1.0 Received: by 10.216.198.224 with SMTP id v74mr3162973wen.41.1318859476912; Mon, 17 Oct 2011 06:51:16 -0700 (PDT) Sender: c.jayachandran@gmail.com Received: by 10.216.188.3 with HTTP; Mon, 17 Oct 2011 06:51:16 -0700 (PDT) Date: Mon, 17 Oct 2011 19:21:16 +0530 X-Google-Sender-Auth: a3ghgUd5ioAW4ZIwHsc8zhq5n6E Message-ID: From: "Jayachandran C." To: freebsd-arm@freebsd.org, freebsd-ppc@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: Subject: HEADSUP: FDT phandle change. [svn commit: r226466] X-BeenThere: freebsd-ppc@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting FreeBSD to the PowerPC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Oct 2011 14:22:22 -0000 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. 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. */