From patchwork Thu Jul 5 17:00:50 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 9859 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 1E86823E1B for ; Thu, 5 Jul 2012 17:00:57 +0000 (UTC) Received: from mail-yw0-f52.google.com (mail-yw0-f52.google.com [209.85.213.52]) by fiordland.canonical.com (Postfix) with ESMTP id E30FDA18952 for ; Thu, 5 Jul 2012 17:00:56 +0000 (UTC) Received: by yhpp61 with SMTP id p61so9126247yhp.11 for ; Thu, 05 Jul 2012 10:00:56 -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=McaqjiuS0yckBbYjQqrC6FF2q4+ZbYCaJu8IGrk3TEg=; b=X1SxYnuT7om0PN+Ua7+0PuW6WVOj66XSYG93N5x9vL6GsRA4LB+RW8n0Gy3kyAv7X4 WZ+VT+tuAIKhs1dtEEjM5Whn9xKsbqGCRWRYCUm3nwrsxHNeKEL+6AqDVhEKzYR4N1kS tn0IW0eijM9rp9pbRYRuVx68gDzZqHqQrJWyu1TmkQAcT3j3tn2Kn0gzXs6rLrE1TxXi c4ymQRUDvBYhdS3NkI/X27rd9EqTasJFzBEPCSAmIVA1WTdo8XaCf1Xi4MGcgnIwIR4s BIol7f5oBwxRQIwKVJkdscoMpcH38u1yLsBpqfS3WKH/BVO4L1QHHCd3i4rnmS6qpnSu zLFg== Received: by 10.50.57.167 with SMTP id j7mr311450igq.53.1341507656182; Thu, 05 Jul 2012 10:00:56 -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.24.148 with SMTP id v20csp68393ibb; Thu, 5 Jul 2012 10:00:54 -0700 (PDT) Received: by 10.180.79.229 with SMTP id m5mr904358wix.13.1341507654324; Thu, 05 Jul 2012 10:00:54 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [81.2.115.146]) by mx.google.com with ESMTPS id n55si24341593wem.138.2012.07.05.10.00.53 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 05 Jul 2012 10:00:54 -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 1SmpQC-0005lu-Sq; Thu, 05 Jul 2012 18:00:52 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Peter Crosthwaite Subject: [PATCH 4/6] device_tree: Add support for reading device tree properties Date: Thu, 5 Jul 2012 18:00:50 +0100 Message-Id: <1341507652-22155-5-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1341507652-22155-1-git-send-email-peter.maydell@linaro.org> References: <1341507652-22155-1-git-send-email-peter.maydell@linaro.org> X-Gm-Message-State: ALoCoQk6Ey8t0keW35yd8h9XGr2V1dNhVLnEb1JvZca2wYpjuhPARLpV0mhbheFJzG5j8xd4PpEP 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);