Received: from eggs.gnu.org ([2001:4830:134:3::10]:34816) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Urn0c-0000nv-Eh for qemu-devel@nongnu.org; Wed, 26 Jun 2013 06:31:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Urn0b-00046k-0M for qemu-devel@nongnu.org; Wed, 26 Jun 2013 06:31:30 -0400 Received: from cantor2.suse.de ([195.135.220.15]:39778 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Urn0a-00046c-O8 for qemu-devel@nongnu.org; Wed, 26 Jun 2013 06:31:28 -0400 Mime-Version: 1.0 (Apple Message framework v1278) Content-Type: text/plain; charset=us-ascii From: Alexander Graf In-Reply-To: Date: Wed, 26 Jun 2013 12:31:25 +0200 Content-Transfer-Encoding: quoted-printable Message-Id: References: <1372069376-30640-1-git-send-email-peter.maydell@linaro.org> <1372069376-30640-2-git-send-email-peter.maydell@linaro.org> <3708A7FB-9BEF-494C-B5A2-B1A97C1F78C4@suse.de> <20130625233850.GG25265@voom.fritz.box> Subject: Re: [Qemu-devel] [PATCH 1/2] device_tree: Add qemu_devtree_setprop_sized_cells() utility function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: Peter Crosthwaite , patches@linaro.org, qemu-devel@nongnu.org, David Gibson On 26.06.2013, at 10:49, Peter Maydell wrote: > On 26 June 2013 00:38, David Gibson = wrote: >> On Mon, Jun 24, 2013 at 12:02:39PM +0100, Peter Maydell wrote: >>> On 24 June 2013 11:56, Alexander Graf wrote: >>>> This looks pretty complicated for something actually quite >>>> simple: All you want is to pass in a number of 64bit values, >>>> rather than 32bit ones, right? >>>=20 >>> Nope. If the device tree blob says #address-cells is 1 >>> and #size-cells is 1, then I want to pass in values to >>> go in 32 bit cells. If it says #address-cells is 2 but >>> #size-cells is still 1, then I want to pass in a value >>> for a 64 bit cell then one for a 32 bit cell. If they're >>> both 2 then I want to pass in values for two 64 bit >>> cells. >>=20 >> Hmm.. the property certainly needs to be constructed that way. But I >> think Alex's point is that you could make the arguments all 64-bit, >> and then truncate them in the generated property. >=20 > Er, the arguments *are* all 64 bits and truncated > in the generated property: > + * @...: 0-terminated list of uint32_t number-of-cells, uint64_t = value pairs >=20 >> There's a bigger problem, though, that exists with both versions. In >> general people expect integer arguments like this not to care too = much >> about the exact integer type, because it will be promoted to the = right >> thing. Except with varargs it won't. So if you ever have a >> notionally 64-bit address that happens to fit in a 32-bit variable = and >> you pass that it, this function will be broken. And the worst of it >> is, it'll work most of the time, until you happen to hit the wrong = ABI >> and parameter combination :(. >=20 > Do you have a suggested improvement to the API to avoid this? I think it makes sense to make this API special-purpose for "reg". We = currently have a generic "put any number of 32bit values into the = property" function (qemu_devtree_setprop_cells). Can't we also just add a qemu_devtree_setprop_reg() that walks the tree = downwards in search for #address-cells and #size-cells and assembles the = correct reg property from a list of 64bit arguments? qemu_devtree_setprop_reg(fdt, "/foo/bar", region[0].offset, = region[0].size, region[1].offset, region[1].size); Maybe we could even make it more generic to also cover "ranges". Alex