From patchwork Mon Jun 24 10:22:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 18059 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f71.google.com (mail-qa0-f71.google.com [209.85.216.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7ECA225DEA for ; Mon, 24 Jun 2013 10:23:03 +0000 (UTC) Received: by mail-qa0-f71.google.com with SMTP id bv4sf5722089qab.6 for ; Mon, 24 Jun 2013 03:23:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-beenthere:x-forwarded-to:x-forwarded-for :delivered-to:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=DEqpg6jWZ9SSz1+199pWk9AQMsbKOzKL5s4It1qxIR4=; b=nEx7E2YTpE8WTkbaDoQU6ZXkBYl+HphNhQeXw0fyJ0DuWuJsKDzLB0LVsZzn0Fgm7Q CHA6IRNuk8xJvgX3ELa6O9v0LOX6wef+g/9qhAj+ZHAxL8L26Gdkn3IJTxURaeZjIsXJ kQSo2SdtZHe0IumBLUYQeyyjcluoOIa1QKZN/Wk+Zw99o+UT69J3OlsxR/BzqRcM+BKy UJgVnMh6xsa89uSkKcqR9+2dS9Wl5QQ3MyvjtGraeS6B872y8LNzQ/NRq/70lpKtc5k7 3xf1DApa39g5U+WfsqeQvh4QsoCNcvMYispY7Ip9m1FJRmeI6OkGUoTGD8llmdLpzyPC 88hw== X-Received: by 10.224.200.202 with SMTP id ex10mr25355515qab.8.1372069383331; Mon, 24 Jun 2013 03:23:03 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.82.74 with SMTP id g10ls1998796qey.60.gmail; Mon, 24 Jun 2013 03:23:03 -0700 (PDT) X-Received: by 10.52.155.71 with SMTP id vu7mr9203168vdb.65.1372069383205; Mon, 24 Jun 2013 03:23:03 -0700 (PDT) Received: from mail-vb0-x232.google.com (mail-vb0-x232.google.com [2607:f8b0:400c:c02::232]) by mx.google.com with ESMTPS id tn5si4715284vdc.13.2013.06.24.03.23.03 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 24 Jun 2013 03:23:03 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c02::232 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=2607:f8b0:400c:c02::232; Received: by mail-vb0-f50.google.com with SMTP id w16so7928764vbb.37 for ; Mon, 24 Jun 2013 03:23:03 -0700 (PDT) X-Received: by 10.52.77.5 with SMTP id o5mr5912626vdw.46.1372069383113; Mon, 24 Jun 2013 03:23:03 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.58.165.8 with SMTP id yu8csp21611veb; Mon, 24 Jun 2013 03:23:02 -0700 (PDT) X-Received: by 10.15.34.77 with SMTP id d53mr23809290eev.95.1372069380201; Mon, 24 Jun 2013 03:23:00 -0700 (PDT) Received: from mnementh.archaic.org.uk (1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.1.0.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id o46si11581377eef.35.2013.06.24.03.22.59 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 24 Jun 2013 03:23:00 -0700 (PDT) Received-SPF: neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1Ur3vE-0007yj-Ec; Mon, 24 Jun 2013 11:22:56 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Peter Crosthwaite , Alexander Graf , David Gibson Subject: [PATCH 1/2] device_tree: Add qemu_devtree_setprop_sized_cells() utility function Date: Mon, 24 Jun 2013 11:22:55 +0100 Message-Id: <1372069376-30640-2-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1372069376-30640-1-git-send-email-peter.maydell@linaro.org> References: <1372069376-30640-1-git-send-email-peter.maydell@linaro.org> X-Gm-Message-State: ALoCoQl330OdR8Vz0KUZQwsGb5q2Luf4Za8ktpUUU/GEU44KeBI3lJGPb7y7iHHPIUR0MfwvKIzt X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c02::232 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , We already have a qemu_devtree_setprop_cells() which sets a dtb property to an array of cells whose values are specified by varargs. However for the fairly common case of setting a property to a list of addresses or of address,size pairs the number of cells used by each element in the list depends on the parent's #address-cells and #size-cells properties. To make this easier we provide an analogous qemu_devtree_setprop_sized_cells() function which allows the number of cells used by each element to be specified. Signed-off-by: Peter Maydell --- device_tree.c | 48 ++++++++++++++++++++++++++++++++++++++++++ include/sysemu/device_tree.h | 29 +++++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/device_tree.c b/device_tree.c index 69be9da..15a081c 100644 --- a/device_tree.c +++ b/device_tree.c @@ -319,3 +319,51 @@ void qemu_devtree_dumpdtb(void *fdt, int size) } } + +int qemu_devtree_setprop_sized_cells(void *fdt, const char *node_path, + const char *property, ...) +{ + uint32_t *propcells; + uint32_t propsize = 0; + va_list ap; + uint32_t ncells; + uint64_t value; + int i, argnum; + + va_start(ap, property); + for (;;) { + ncells = va_arg(ap, uint32_t); + if (!ncells) { + break; + } + assert(ncells < 3); + propsize += ncells; + value = va_arg(ap, uint64_t); + } + va_end(ap); + + propcells = g_new0(uint32_t, propsize); + + i = 0; + va_start(ap, property); + for (argnum = 1; ; argnum++) { + uint32_t hival; + + ncells = va_arg(ap, uint32_t); + if (!ncells) { + break; + } + value = va_arg(ap, uint64_t); + hival = cpu_to_be32(value >> 32); + if (ncells > 1) { + propcells[i++] = hival; + } else if (hival != 0) { + return argnum; + } + propcells[i++] = cpu_to_be32(value); + } + va_end(ap); + + return qemu_devtree_setprop(fdt, node_path, property, propcells, + propsize * sizeof(uint32_t)); +} diff --git a/include/sysemu/device_tree.h b/include/sysemu/device_tree.h index f0b3f35..d7691f9 100644 --- a/include/sysemu/device_tree.h +++ b/include/sysemu/device_tree.h @@ -51,4 +51,33 @@ int qemu_devtree_add_subnode(void *fdt, const char *name); void qemu_devtree_dumpdtb(void *fdt, int size); +/** + * qemu_devtree_setprop_sized_cells: + * @fdt: device tree blob + * @node_path: node to set property on + * @property: property to set + * @...: 0-terminated list of uint32_t number-of-cells, uint64_t value pairs + * + * Set the specified property on the specified node in the device tree + * to be an array of cells. The values of the cells are specified via + * the varargs list, which alternates between "number of cells used by + * this value" and "value" (terminated when number-of-cells is zero). + * number-of-cells must be either 1 or 2 (other values will assert()). + * + * This function is useful because device tree nodes often have cell arrays + * which are either lists of addresses or lists of address,size tuples, but + * the number of cells used for each element vary depending on the + * #address-cells and #size-cells properties of their parent node. + * If you know all your cell elements are one cell wide you can use the + * simpler qemu_devtree_setprop_cells(). + * + * Return value: 0 on success, <0 if setting the property failed, + * n (for n>0) if value n wouldn't fit in the required number of cells. + * (This slightly odd convention is for the benefit of callers who might + * wish to print different error messages depending on which value + * was too large to fit, since values might be user-specified.) + */ +int qemu_devtree_setprop_sized_cells(void *fdt, const char *node_path, + const char *property, ...); + #endif /* __DEVICE_TREE_H__ */