From patchwork Mon Jul 16 13:24:14 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 10011 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id C1A6123F2A for ; Mon, 16 Jul 2012 13:24:29 +0000 (UTC) Received: from mail-gg0-f180.google.com (mail-gg0-f180.google.com [209.85.161.180]) by fiordland.canonical.com (Postfix) with ESMTP id 91EF0A188AE for ; Mon, 16 Jul 2012 13:24:29 +0000 (UTC) Received: by mail-gg0-f180.google.com with SMTP id f1so5363090ggn.11 for ; Mon, 16 Jul 2012 06:24:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=KxcwhYRtIiVojwT+78uNXV02pskKlw7hVhSys7EDi4I=; b=jPTj+wxQNY7D1g/fz5ch6uOGVdLeTyqkVuu1Qrm7HXzm3m9z2zCGpuqb0mYD3TQu1V MkewhFYuTNIFjJgv6Uav0Vwbb+WklosWBPZEsd69puelREs9T2Rdk03vKOFWiOwy46u1 LHcStl/LUI9cLcJwWMd1MMOLc+WqAwDeab8EagtT/WGaHTnrMox0oVW8PGxOUmQzjOqG XmFWJkkvFESGsmUxRsqBkQAl0qrRnJF8yp95KPD2aW58xmFExI2+fK529eVPuFtdhL22 q3tr2KLxlme3VdH1GFwilJF6gwp1u9LE/cpdTrs1yaWyPiG5lB0fopH4jLNBJgyazn2G gxPA== Received: by 10.50.46.232 with SMTP id y8mr5077021igm.57.1342445069207; Mon, 16 Jul 2012 06:24:29 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.241.2 with SMTP id lc2csp7939ibb; Mon, 16 Jul 2012 06:24:28 -0700 (PDT) Received: by 10.180.81.165 with SMTP id b5mr18192983wiy.17.1342445067914; Mon, 16 Jul 2012 06:24:27 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [81.2.115.146]) by mx.google.com with ESMTPS id r6si23909307wiw.0.2012.07.16.06.24.27 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 16 Jul 2012 06:24:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) client-ip=81.2.115.146; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) smtp.mail=pm215@archaic.org.uk Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1SqlHd-0002No-7E; Mon, 16 Jul 2012 14:24:17 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Peter Crosthwaite Subject: [PATCH v2 4/6] device_tree: Add support for reading device tree properties Date: Mon, 16 Jul 2012 14:24:14 +0100 Message-Id: <1342445056-9129-5-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1342445056-9129-1-git-send-email-peter.maydell@linaro.org> References: <1342445056-9129-1-git-send-email-peter.maydell@linaro.org> X-Gm-Message-State: ALoCoQn8BMskYhtnLxz/+XS/018K96CpkkQ3gof3Is4/PLVrYxWE9gdx2CcP9IMfur6ZNhWbE0Yj Add support for reading device tree properties (both generic and single-cell ones) to QEMU's convenience wrapper layer. Signed-off-by: Peter Maydell Reviewed-by: Peter A. G. Crosthwaite --- device_tree.c | 30 ++++++++++++++++++++++++++++++ device_tree.h | 4 ++++ 2 files changed, 34 insertions(+), 0 deletions(-) diff --git a/device_tree.c b/device_tree.c index b366fdd..d7a9b6b 100644 --- a/device_tree.c +++ b/device_tree.c @@ -178,6 +178,36 @@ int qemu_devtree_setprop_string(void *fdt, const char *node_path, return r; } +const void *qemu_devtree_getprop(void *fdt, const char *node_path, + const char *property, int *lenp) +{ + int len; + const void *r; + if (!lenp) { + lenp = &len; + } + r = fdt_getprop(fdt, findnode_nofail(fdt, node_path), property, lenp); + if (!r) { + fprintf(stderr, "%s: Couldn't get %s/%s: %s\n", __func__, + node_path, property, fdt_strerror(*lenp)); + exit(1); + } + return r; +} + +uint32_t qemu_devtree_getprop_cell(void *fdt, const char *node_path, + const char *property) +{ + int len; + const uint32_t *p = qemu_devtree_getprop(fdt, node_path, property, &len); + if (len != 4) { + fprintf(stderr, "%s: %s/%s not 4 bytes long (not a cell?)\n", + __func__, node_path, property); + exit(1); + } + return be32_to_cpu(*p); +} + uint32_t qemu_devtree_get_phandle(void *fdt, const char *path) { uint32_t r; diff --git a/device_tree.h b/device_tree.h index 2244270..f7a3e6c 100644 --- a/device_tree.h +++ b/device_tree.h @@ -28,6 +28,10 @@ int qemu_devtree_setprop_string(void *fdt, const char *node_path, int qemu_devtree_setprop_phandle(void *fdt, const char *node_path, const char *property, const char *target_node_path); +const void *qemu_devtree_getprop(void *fdt, const char *node_path, + const char *property, int *lenp); +uint32_t qemu_devtree_getprop_cell(void *fdt, const char *node_path, + const char *property); uint32_t qemu_devtree_get_phandle(void *fdt, const char *path); uint32_t qemu_devtree_alloc_phandle(void *fdt); int qemu_devtree_nop_node(void *fdt, const char *node_path);