From mboxrd@z Thu Jan 1 00:00:00 1970 From: Anthony Liguori Date: Thu, 11 Dec 2008 21:33:38 +0000 Subject: Re: [Qemu-devel] [PATCH 4/6] Implement device tree support needed Message-Id: <49418732.4060206@codemonkey.ws> List-Id: References: <1229028752-9480-1-git-send-email-hollisb@us.ibm.com> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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