From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LAtAH-0007ZN-FM for qemu-devel@nongnu.org; Thu, 11 Dec 2008 16:33:45 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LAtAG-0007Yi-Hw for qemu-devel@nongnu.org; Thu, 11 Dec 2008 16:33:45 -0500 Received: from [199.232.76.173] (port=35021 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LAtAG-0007Yf-Cj for qemu-devel@nongnu.org; Thu, 11 Dec 2008 16:33:44 -0500 Received: from yw-out-1718.google.com ([74.125.46.157]:64159) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LAtAF-00032p-OP for qemu-devel@nongnu.org; Thu, 11 Dec 2008 16:33:44 -0500 Received: by yw-out-1718.google.com with SMTP id 6so530612ywa.82 for ; Thu, 11 Dec 2008 13:33:42 -0800 (PST) Message-ID: <49418732.4060206@codemonkey.ws> Date: Thu, 11 Dec 2008 15:33:38 -0600 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH 4/6] Implement device tree support needed for Bamboo emulation References: <1229028752-9480-1-git-send-email-hollisb@us.ibm.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kvm-ppc@vger.kernel.org Hollis Blanchard wrote: > diff --git a/device_tree.c b/device_tree.c > new file mode 100644 > index 0000000..d7350e3 > --- /dev/null > +++ b/device_tree.c > @@ -0,0 +1,116 @@ > +/* > + * Functions to help device tree manipulation using libfdt. > + * It also provides functions to read entries from device tree proc > + * interface. > + * > + * Copyright 2008 IBM Corporation. > + * Authors: Jerone Young > + * Hollis Blanchard > + * > + * This work is licensed under the GNU GPL license version 2 or later. > + * > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include "config.h" > +#include "qemu-common.h" > +#include "sysemu.h" > +#include "device_tree.h" > + > +#include "libfdt.h" > #include > +void *load_device_tree(const char *filename_path, void *load_addr) > +{ > + int dt_file_size; > + int dt_file_load_size; > + int new_dt_size; > + int ret; > + void *dt_file = NULL; > + void *fdt; > + > + dt_file_size = get_image_size(filename_path); > + if (dt_file_size < 0) { > + printf("Unable to get size of device tree file '%s'\n", > + filename_path); > + goto fail; > + } > + > + /* First allocate space in qemu for device tree */ > + dt_file = qemu_malloc(dt_file_size); > + if (dt_file == NULL) { > + printf("Unable to allocate memory in qemu for device tree\n"); > + goto fail; > + } > + memset(dt_file, 0, dt_file_size); > > qemu_mallocz(). Indent is still bad. > + dt_file_load_size = load_image(filename_path, dt_file); > + > + /* Second we place new copy of 2x size in guest memory > + * This give us enough room for manipulation. > + */ > + new_dt_size = dt_file_size * 2; > + > + fdt = load_addr; > + ret = fdt_open_into(dt_file, fdt, new_dt_size); > + if (ret) { > + printf("Unable to copy device tree in memory\n"); > + goto fail; > + } > + > + /* Check sanity of device tree */ > + if (fdt_check_header(fdt)) { > + printf ("Device tree file loaded into memory is invalid: %s\n", > + filename_path); > + goto fail; > + } > + /* free qemu memory with old device tree */ > + qemu_free(dt_file); > + return fdt; > + > +fail: > + if (dt_file) > + qemu_free(dt_file); > free() can safely take a NULL value. > + return NULL; > +} > + > +int qemu_devtree_setprop(void *fdt, const char *node_path, > + const char *property, uint32_t *val_array, int size) > +{ > + int offset; > + > + offset = fdt_path_offset(fdt, node_path); > + if (offset < 0) > + return offset; > This is just goofy :-) > diff --git a/device_tree.h b/device_tree.h > new file mode 100644 > index 0000000..9e6ef3d > --- /dev/null > +++ b/device_tree.h > @@ -0,0 +1,26 @@ > +/* > + * Header with function prototypes to help device tree manipulation using > + * libfdt. It also provides functions to read entries from device tree proc > + * interface. > + * > + * Copyright 2008 IBM Corporation. > + * Authors: Jerone Young > + * Hollis Blanchard > + * > + * This work is licensed under the GNU GPL license version 2 or later. > + * > + */ > + > +#ifndef __DEVICE_TREE_H__ > +#define __DEVICE_TREE_H__ > + > +void *load_device_tree(const char *filename_path, void *load_addr); > + > +int qemu_devtree_setprop(void *fdt, const char *node_path, > + const char *property, uint32_t *val_array, int size); > +int qemu_devtree_setprop_cell(void *fdt, const char *node_path, > + const char *property, uint32_t val); > +int qemu_devtree_setprop_string(void *fdt, const char *node_path, > + const char *property, const char *string); > + > +#endif /* __DEVICE_TREE_H__ */ > diff --git a/libfdt_env.h b/libfdt_env.h > new file mode 100644 > index 0000000..59f2536 > --- /dev/null > +++ b/libfdt_env.h > Missing copyright? Regards, Anthony Liguori