From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:55864) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sh3ts-0001mE-7o for qemu-devel@nongnu.org; Tue, 19 Jun 2012 15:15:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sh3tp-0004jG-FQ for qemu-devel@nongnu.org; Tue, 19 Jun 2012 15:15:39 -0400 From: Alexander Graf Date: Tue, 19 Jun 2012 21:15:23 +0200 Message-Id: <1340133324-352-31-git-send-email-agraf@suse.de> In-Reply-To: <1340133324-352-1-git-send-email-agraf@suse.de> References: <1340133324-352-1-git-send-email-agraf@suse.de> Subject: [Qemu-devel] [PATCH 30/31] dt: Add global option to set phandle start offset List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel qemu-devel Cc: qemu-ppc Mailing List If anyone outside of QEMU wants to mess with a QEMU generated device tree, he needs to know which range phandles are valid in. So let's expose a machine option that an external program can use to set the start allocate id for phandles in QEMU. Signed-off-by: Alexander Graf --- v2 -> v3: - add correct header includes --- device_tree.c | 28 +++++++++++++++++++++++++++- qemu-config.c | 4 ++++ 2 files changed, 31 insertions(+), 1 deletions(-) diff --git a/device_tree.c b/device_tree.c index cc83f0f..acae53e 100644 --- a/device_tree.c +++ b/device_tree.c @@ -22,6 +22,8 @@ #include "qemu-common.h" #include "device_tree.h" #include "hw/loader.h" +#include "qemu-option.h" +#include "qemu-config.h" #include @@ -200,7 +202,31 @@ int qemu_devtree_setprop_phandle(void *fdt, const char *node_path, uint32_t qemu_devtree_alloc_phandle(void *fdt) { - static int phandle = 0x8000; + static int phandle = 0x0; + + /* + * We need to find out if the user gave us special instruction at + * which phandle id to start allocting phandles. + */ + if (!phandle) { + QemuOpts *machine_opts; + machine_opts = qemu_opts_find(qemu_find_opts("machine"), 0); + if (machine_opts) { + const char *phandle_start; + phandle_start = qemu_opt_get(machine_opts, "phandle_start"); + if (phandle_start) { + phandle = strtoul(phandle_start, NULL, 0); + } + } + } + + if (!phandle) { + /* + * None or invalid phandle given on the command line, so fall back to + * default starting point. + */ + phandle = 0x8000; + } return phandle++; } diff --git a/qemu-config.c b/qemu-config.c index 5bbebaf..2cd2726 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -587,6 +587,10 @@ static QemuOptsList qemu_machine_opts = { .name = "dumpdtb", .type = QEMU_OPT_STRING, .help = "Dump current dtb to a file and quit", + }, { + .name = "phandle_start", + .type = QEMU_OPT_STRING, + .help = "The first phandle ID we may generate dynamically", }, { /* End of list */ } }, -- 1.6.0.2