[Xen-changelog] [xen-unstable] merge with xen-unstable.hg

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[Xen-changelog] [xen-unstable] merge with xen-unstable.hg

Xen patchbot-unstable
# HG changeset patch
# User [hidden email]
# Date 1171573779 25200
# Node ID 9529d667d0426eb02077cb33abdc6e434e27d293
# Parent  ac18d251df63401e67c63b83d3face99f5a9aeb3
# Parent  9af0c7e4ff513c02f9bd1548f21612e9cf59b022
merge with xen-unstable.hg
---
 tools/libxc/xc_dom_powerpc64.c                              |  100 -
 tools/python/xen/xend/FlatDeviceTree.py                     |  359 ---
 xen/arch/powerpc/elf32.c                                    |    7
 xen/arch/powerpc/of_handler/strncpy.c                       |   54
 linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c           |    5
 linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c            |    5
 linux-2.6-xen-sparse/drivers/xen/core/reboot.c              |    3
 linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c           |    2
 linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c        |    6
 tools/libxc/Makefile                                        |    7
 tools/libxc/powerpc64/Makefile                              |    1
 tools/libxc/powerpc64/flatdevtree.c                         |    7
 tools/libxc/powerpc64/flatdevtree.h                         |    2
 tools/libxc/powerpc64/mk_flatdevtree.c                      |  650 ++++++
 tools/libxc/powerpc64/mk_flatdevtree.h                      |   47
 tools/libxc/powerpc64/utils.c                               |   25
 tools/libxc/powerpc64/utils.h                               |    3
 tools/libxc/powerpc64/xc_linux_build.c                      |  270 +-
 tools/libxc/powerpc64/xc_prose_build.c                      |  124 -
 tools/libxc/xc_dom.h                                        |    5
 tools/libxc/xenguest.h                                      |    3
 tools/libxc/xg_private.c                                    |   12
 tools/python/xen/lowlevel/xc/xc.c                           |   27
 tools/python/xen/xend/image.py                              |   56
 unmodified_drivers/linux-2.6/platform-pci/platform-compat.c |    6
 xen/arch/powerpc/Makefile                                   |    4
 xen/arch/powerpc/backtrace.c                                |    1
 xen/arch/powerpc/boot_of.c                                  |   43
 xen/arch/powerpc/domain.c                                   |   35
 xen/arch/powerpc/domain_build.c                             |  214 --
 xen/arch/powerpc/hcalls.c                                   |    6
 xen/arch/powerpc/memory.c                                   |  150 -
 xen/arch/powerpc/mm.c                                       |    1
 xen/arch/powerpc/of-devtree.c                               |    2
 xen/arch/powerpc/of-devtree.h                               |    3
 xen/arch/powerpc/of_handler/Makefile                        |    2
 xen/arch/powerpc/of_handler/strlcpy.c                       |   58
 xen/arch/powerpc/ofd_fixup.c                                |   11
 xen/arch/powerpc/papr/xlate.c                               |   17
 xen/arch/powerpc/powerpc64/asm-offsets.c                    |    2
 xen/arch/powerpc/powerpc64/exceptions.S                     |    8
 xen/arch/powerpc/powerpc64/ppc970.c                         |    7
 xen/arch/powerpc/powerpc64/ppc970_scom.c                    |    4
 xen/arch/powerpc/powerpc64/traps.c                          |   10
 xen/arch/powerpc/setup.c                                    |   23
 xen/arch/powerpc/sysctl.c                                   |   10
 xen/arch/powerpc/time.c                                     |    6
 xen/arch/powerpc/xen.lds.S                                  |   23
 xen/arch/x86/domain.c                                       |   52
 xen/arch/x86/domain_build.c                                 |   10
 xen/arch/x86/domctl.c                                       |   11
 xen/arch/x86/hvm/hvm.c                                      |    9
 xen/arch/x86/hvm/io.c                                       |    2
 xen/arch/x86/hvm/platform.c                                 |   41
 xen/arch/x86/hvm/svm/intr.c                                 |    2
 xen/arch/x86/hvm/svm/svm.c                                  |   32
 xen/arch/x86/hvm/svm/vmcb.c                                 |    4
 xen/arch/x86/hvm/vlapic.c                                   |    1
 xen/arch/x86/hvm/vmx/vmcs.c                                 |    2
 xen/arch/x86/hvm/vmx/vmx.c                                  |   34
 xen/arch/x86/mm.c                                           |  107 -
 xen/arch/x86/mm/Makefile                                    |    3
 xen/arch/x86/mm/p2m.c                                       |  699 +++++++
 xen/arch/x86/mm/paging.c                                    |  143 +
 xen/arch/x86/mm/shadow/common.c                             | 1197 +++---------
 xen/arch/x86/mm/shadow/multi.c                              |  245 +-
 xen/arch/x86/mm/shadow/multi.h                              |    2
 xen/arch/x86/mm/shadow/page-guest32.h                       |    5
 xen/arch/x86/mm/shadow/private.h                            |  107 -
 xen/arch/x86/mm/shadow/types.h                              |   12
 xen/arch/x86/setup.c                                        |    2
 xen/arch/x86/sysctl.c                                       |    1
 xen/arch/x86/traps.c                                        |   10
 xen/arch/x86/x86_32/domain_page.c                           |    1
 xen/arch/x86/x86_64/traps.c                                 |    1
 xen/common/libelf/libelf-dominfo.c                          |  557 ++---
 xen/common/libelf/libelf-loader.c                           |  125 -
 xen/common/libelf/libelf-private.h                          |   26
 xen/common/libelf/libelf-relocate.c                         |  375 +--
 xen/common/libelf/libelf-tools.c                            |  153 -
 xen/include/asm-powerpc/config.h                            |    5
 xen/include/asm-powerpc/domain.h                            |    7
 xen/include/asm-powerpc/init.h                              |   10
 xen/include/asm-powerpc/mm.h                                |    3
 xen/include/asm-powerpc/nmi.h                               |    6
 xen/include/asm-powerpc/processor.h                         |    1
 xen/include/asm-x86/domain.h                                |   96
 xen/include/asm-x86/mm.h                                    |   63
 xen/include/asm-x86/p2m.h                                   |  142 +
 xen/include/asm-x86/page.h                                  |    5
 xen/include/asm-x86/paging.h                                |  376 +++
 xen/include/asm-x86/shadow.h                                |  375 ---
 xen/include/public/arch-ia64.h                              |    1
 xen/include/public/arch-powerpc.h                           |   22
 xen/include/public/arch-x86/xen.h                           |    1
 95 files changed, 4112 insertions(+), 3398 deletions(-)

diff -r ac18d251df63 -r 9529d667d042 linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c
--- a/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c Thu Feb 15 13:13:36 2007 -0700
+++ b/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c Thu Feb 15 14:09:39 2007 -0700
@@ -344,7 +344,7 @@ static void frontend_changed(struct xenb
  switch (frontend_state) {
  case XenbusStateInitialising:
  if (dev->state == XenbusStateClosed) {
- printk("%s: %s: prepare for reconnect\n",
+ printk(KERN_INFO "%s: %s: prepare for reconnect\n",
        __FUNCTION__, dev->nodename);
  xenbus_switch_state(dev, XenbusStateInitWait);
  }
@@ -488,7 +488,8 @@ static int connect_ring(struct backend_i
  xenbus_dev_fatal(dev, err, "unknown fe protocol %s", protocol);
  return -1;
  }
- printk("blkback: ring-ref %ld, event-channel %d, protocol %d (%s)\n",
+ printk(KERN_INFO
+       "blkback: ring-ref %ld, event-channel %d, protocol %d (%s)\n",
        ring_ref, evtchn, be->blkif->blk_protocol, protocol);
 
  /* Map the shared frame, irq etc. */
diff -r ac18d251df63 -r 9529d667d042 linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c
--- a/linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c Thu Feb 15 13:13:36 2007 -0700
+++ b/linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c Thu Feb 15 14:09:39 2007 -0700
@@ -272,7 +272,7 @@ static void tap_frontend_changed(struct
  switch (frontend_state) {
  case XenbusStateInitialising:
  if (dev->state == XenbusStateClosed) {
- printk("%s: %s: prepare for reconnect\n",
+ printk(KERN_INFO "%s: %s: prepare for reconnect\n",
        __FUNCTION__, dev->nodename);
  xenbus_switch_state(dev, XenbusStateInitWait);
  }
@@ -369,7 +369,8 @@ static int connect_ring(struct backend_i
  xenbus_dev_fatal(dev, err, "unknown fe protocol %s", protocol);
  return -1;
  }
- printk("blktap: ring-ref %ld, event-channel %d, protocol %d (%s)\n",
+ printk(KERN_INFO
+       "blktap: ring-ref %ld, event-channel %d, protocol %d (%s)\n",
        ring_ref, evtchn, be->blkif->blk_protocol, protocol);
 
  /* Map the shared frame, irq etc. */
diff -r ac18d251df63 -r 9529d667d042 linux-2.6-xen-sparse/drivers/xen/core/reboot.c
--- a/linux-2.6-xen-sparse/drivers/xen/core/reboot.c Thu Feb 15 13:13:36 2007 -0700
+++ b/linux-2.6-xen-sparse/drivers/xen/core/reboot.c Thu Feb 15 14:09:39 2007 -0700
@@ -100,6 +100,7 @@ static void shutdown_handler(struct xenb
 static void shutdown_handler(struct xenbus_watch *watch,
      const char **vec, unsigned int len)
 {
+ extern void ctrl_alt_del(void);
  char *str;
  struct xenbus_transaction xbt;
  int err;
@@ -129,7 +130,7 @@ static void shutdown_handler(struct xenb
  if (strcmp(str, "poweroff") == 0)
  shutting_down = SHUTDOWN_POWEROFF;
  else if (strcmp(str, "reboot") == 0)
- kill_proc(1, SIGINT, 1); /* interrupt init */
+ ctrl_alt_del();
  else if (strcmp(str, "suspend") == 0)
  shutting_down = SHUTDOWN_SUSPEND;
  else if (strcmp(str, "halt") == 0)
diff -r ac18d251df63 -r 9529d667d042 linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c
--- a/linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c Thu Feb 15 13:13:36 2007 -0700
+++ b/linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c Thu Feb 15 14:09:39 2007 -0700
@@ -217,7 +217,7 @@ static void frontend_changed(struct xenb
  switch (frontend_state) {
  case XenbusStateInitialising:
  if (dev->state == XenbusStateClosed) {
- printk("%s: %s: prepare for reconnect\n",
+ printk(KERN_INFO "%s: %s: prepare for reconnect\n",
        __FUNCTION__, dev->nodename);
  if (be->netif) {
  netif_disconnect(be->netif);
diff -r ac18d251df63 -r 9529d667d042 linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c
--- a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c Thu Feb 15 13:13:36 2007 -0700
+++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c Thu Feb 15 14:09:39 2007 -0700
@@ -1505,7 +1505,7 @@ static void netif_release_rx_bufs(struct
  int id, ref;
 
  if (np->copying_receiver) {
- printk("%s: fix me for copying receiver.\n", __FUNCTION__);
+ WPRINTK("%s: fix me for copying receiver.\n", __FUNCTION__);
  return;
  }
 
@@ -1555,8 +1555,8 @@ static void netif_release_rx_bufs(struct
  xfer++;
  }
 
- printk("%s: %d xfer, %d noxfer, %d unused\n",
-       __FUNCTION__, xfer, noxfer, unused);
+ IPRINTK("%s: %d xfer, %d noxfer, %d unused\n",
+ __FUNCTION__, xfer, noxfer, unused);
 
  if (xfer) {
  /* Some pages are no longer absent... */
diff -r ac18d251df63 -r 9529d667d042 tools/libxc/Makefile
--- a/tools/libxc/Makefile Thu Feb 15 13:13:36 2007 -0700
+++ b/tools/libxc/Makefile Thu Feb 15 14:09:39 2007 -0700
@@ -49,15 +49,8 @@ GUEST_SRCS-y += xc_dom_core.c xc_dom_boo
 GUEST_SRCS-y += xc_dom_core.c xc_dom_boot.c
 GUEST_SRCS-y += xc_dom_elfloader.c
 GUEST_SRCS-y += xc_dom_binloader.c
-
-ifeq ($(CONFIG_POWERPC),y)
-# big endian boxes
-GUEST_SRCS-y += xc_dom_powerpc64.c
-else
-# little endian boxes
 GUEST_SRCS-y += xc_dom_x86.c
 GUEST_SRCS-y += xc_dom_ia64.c
-endif
 
 GUEST_SRCS-$(CONFIG_X86)     += xc_dom_compat_linux.c
 GUEST_SRCS-$(CONFIG_IA64)    += xc_dom_compat_linux.c
diff -r ac18d251df63 -r 9529d667d042 tools/libxc/powerpc64/Makefile
--- a/tools/libxc/powerpc64/Makefile Thu Feb 15 13:13:36 2007 -0700
+++ b/tools/libxc/powerpc64/Makefile Thu Feb 15 14:09:39 2007 -0700
@@ -1,4 +1,5 @@ GUEST_SRCS-y += powerpc64/flatdevtree.c
 GUEST_SRCS-y += powerpc64/flatdevtree.c
+GUEST_SRCS-y += powerpc64/mk_flatdevtree.c
 GUEST_SRCS-y += powerpc64/xc_linux_build.c
 GUEST_SRCS-y += powerpc64/xc_prose_build.c
 GUEST_SRCS-y += powerpc64/utils.c
diff -r ac18d251df63 -r 9529d667d042 tools/libxc/powerpc64/flatdevtree.c
--- a/tools/libxc/powerpc64/flatdevtree.c Thu Feb 15 13:13:36 2007 -0700
+++ b/tools/libxc/powerpc64/flatdevtree.c Thu Feb 15 14:09:39 2007 -0700
@@ -14,7 +14,7 @@
  * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  *
  * Copyright Pantelis Antoniou 2006
- * Copyright (C) IBM Corporation 2006
+ * Copyright IBM Corporation 2006, 2007
  * 2006 (c) MontaVista, Software, Inc.
  *
  * Authors: Pantelis Antoniou <[hidden email]>
@@ -209,7 +209,7 @@ void ft_add_rsvmap(struct ft_cxt *cxt, u
  ((u64 *) cxt->pres)[0] = cpu_to_be64(physaddr); /* phys = 0, size = 0, terminate */
  ((u64 *) cxt->pres)[1] = cpu_to_be64(size);
 
- cxt->pres += 18; /* advance */
+ cxt->pres += 16; /* advance two u64s worth */
 
  ((u64 *) cxt->pres)[0] = 0; /* phys = 0, size = 0, terminate */
  ((u64 *) cxt->pres)[1] = 0;
@@ -317,6 +317,9 @@ int ft_end_tree(struct ft_cxt *cxt)
  /* the new strings start */
  cxt->pstr_begin = cxt->p_begin + cxt->struct_size;
  cxt->pstr = cxt->pstr_begin + cxt->strings_size;
+
+ /* mark the size of string structure in bph */
+ bph->size_dt_strings = cxt->strings_size;
 
  return 0;
 }
diff -r ac18d251df63 -r 9529d667d042 tools/libxc/powerpc64/flatdevtree.h
--- a/tools/libxc/powerpc64/flatdevtree.h Thu Feb 15 13:13:36 2007 -0700
+++ b/tools/libxc/powerpc64/flatdevtree.h Thu Feb 15 14:09:39 2007 -0700
@@ -40,7 +40,7 @@ struct boot_param_header {
  /* version 2 fields below */
  u32 boot_cpuid_phys;    /* Physical CPU id we're booting on */
  /* version 3 fields below */
- u32 dt_strings_size;    /* size of the DT strings block */
+ u32 size_dt_strings;    /* size of the DT strings block */
 };
 
 struct ft_cxt {
diff -r ac18d251df63 -r 9529d667d042 tools/libxc/powerpc64/mk_flatdevtree.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/libxc/powerpc64/mk_flatdevtree.c Thu Feb 15 14:09:39 2007 -0700
@@ -0,0 +1,650 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright IBM Corporation 2007
+ *
+ * Authors: Ryan Harper <[hidden email]>
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <libgen.h>    
+#include <inttypes.h>
+#include <math.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/dir.h>
+#include <sys/stat.h>
+#include <sys/param.h>
+
+#include <xc_private.h> /* for PERROR() */
+
+#include "mk_flatdevtree.h"
+
+static uint32_t current_phandle = 0;
+
+static uint32_t get_phandle(void)
+{
+   return current_phandle++;
+}
+
+static int readfile(const char *fullpath, void *data, int len)
+{
+    struct stat st;
+    int saved_errno;
+    int rc = -1;
+    int fd;
+  
+    if ((fd = open(fullpath, O_RDONLY)) == -1) {
+        PERROR("%s: failed to open file %s", __func__, fullpath);
+        return -1;
+    }
+
+    if ((rc = fstat(fd, &st)) == -1) {
+        PERROR("%s: failed to stat fd %d", __func__, fd);
+        goto error;
+    }
+
+    if (S_ISREG(st.st_mode))
+        rc = read(fd, data, len);
+
+    close(fd);
+    return rc;
+
+error:
+    saved_errno = errno;
+    close(fd);
+    errno = saved_errno;
+    return -1;
+}
+
+/*
+ * @property - string to check against the filter list
+ * @filter   - NULL terminated list of strings
+ *
+ * compare @property string to each string in @filter
+ *
+ * return 1 if @property matches any filter, otherwise 0
+ *
+ */
+static int match(const char *property, const char **filter)
+{
+    int i;
+    
+    for (i=0; filter[i] != NULL; i++) {
+        /* compare the filter to property */
+        if (strncmp(property, filter[i], strlen(filter[i])) == 0)
+            return 1;
+    }
+
+    return 0;
+}
+
+/*
+ * copy the node at @dirpath filtering out any properties that match in @propfilter
+ */
+static int copynode(struct ft_cxt *cxt, const char *dirpath, const char **propfilter)
+{  
+    struct dirent *tree;
+    struct stat st;
+    DIR *dir;
+    char fullpath[MAX_PATH];
+    char *bname = NULL;
+    char *basec = NULL;
+    int saved_errno;
+
+    if ((dir = opendir(dirpath)) == NULL) {
+        PERROR("%s: failed to open dir %s", __func__, dirpath);
+        return -1;
+    }
+
+    while (1) {
+        if ((tree = readdir(dir)) == NULL)
+            break;  /* reached end of directory entries */
+
+        /* ignore . and .. */
+        if (strcmp(tree->d_name,"." ) == 0 || strcmp(tree->d_name,"..") == 0)
+            continue;
+
+        /* build full path name of the file, for stat() */
+        if (snprintf(fullpath, sizeof(fullpath), "%s/%s", dirpath,
+                     tree->d_name) >= sizeof(fullpath)) {
+            PERROR("%s: failed to build full path", __func__);
+            goto error;
+        }
+
+        /* stat the entry */
+        if (stat(fullpath, &st) < 0) {
+            PERROR("%s: failed to stat file %s", __func__, fullpath);
+            goto error;
+        }
+
+        if (S_ISDIR(st.st_mode)) {
+            /* start a new node for a dir */
+            ft_begin_node(cxt, tree->d_name);
+
+            /* copy everything in this dir */
+            if (copynode(cxt, fullpath, propfilter) < 0) {
+                PERROR("%s: failed to copy node @ %s", __func__, fullpath);
+                goto error;
+            }
+
+            /* end the node */
+            ft_end_node(cxt);
+        }
+        /* add files in dir as properties */
+        else if (S_ISREG(st.st_mode)) {
+
+            if ((basec = strdup(fullpath)) == NULL) {
+                PERROR("%s: failed to dupe string", __func__);
+                goto error;
+            }
+
+            if ((bname = basename(basec)) == NULL) {
+                PERROR("%s: basename() failed", __func__);
+                goto error;
+            }
+
+            /* only add files that don't match the property filter string */
+            if (!match(bname, propfilter)) {
+                char data[BUFSIZE];
+                int len;
+
+                /* snarf the data and push into the property */
+                if ((len = readfile(fullpath, data, sizeof(data))) < 0) {
+                    PERROR("%s: failed to read data from file %s", __func__,
+                                                                   fullpath);
+                    goto error;
+                }
+                ft_prop(cxt, tree->d_name, data, len);
+
+            }
+
+            /* strdup mallocs memory */
+            if (basec != NULL ) {
+                free(basec);
+                basec = NULL;
+            }
+
+        }
+    }
+
+    closedir(dir);
+    return 0;
+
+error:
+    saved_errno = errno;
+
+    /* strdup mallocs memory */
+    if (basec != NULL ) {
+        free(basec);
+        basec = NULL;
+    }
+
+    closedir(dir);
+
+    errno = saved_errno;
+    return -1;
+}
+
+static int find_cpu0(char *cpupath, int len)
+{  
+    const char path[] = "/proc/device-tree/cpus";
+    const char device[] = "device_type";
+    const char dev_cpu[] = "cpu";
+    const char reg[] = "reg";
+    char data[sizeof(dev_cpu)];
+    char prop[MAX_PATH];
+    char node[MAX_PATH];
+    struct dirent *tree;
+    struct stat st;
+    DIR* dir;
+    int saved_errno;
+    int found = 0;
+
+    if ((dir = opendir(path)) == NULL) {
+        PERROR("%s: failed to open directory %s", __func__, path);
+        return -1;
+    }    
+
+    while (!found) {
+
+        if ((tree = readdir(dir)) == NULL)
+            break;  /* reached end of directory entries */
+
+        /* ignore ., .. */
+        if (strcmp(tree->d_name,"." ) == 0 || strcmp(tree->d_name,"..") == 0)
+            continue;
+
+        /* build full path name of the file, for stat() */
+        if (snprintf(node, sizeof(node), "%s/%s", path,
+                     tree->d_name) >= sizeof(node)) {
+            PERROR("%s: failed to concat strings", __func__);
+            goto error;
+        }
+
+        /* stat the entry */
+        if (stat(node, &st) < 0) {
+            PERROR("%s: failed to stat file %s", __func__, node);
+            /* something funny happen in /proc/device-tree, but march onward */
+            continue;
+        }
+
+        /* for each dir, check the device_type property until we find 'cpu'*/
+        if (S_ISDIR(st.st_mode)) {
+
+            /* construct path to device_type */
+            if (snprintf(prop, sizeof(prop), "%s/%s", node,
+                         device) >= sizeof(prop)) {
+                PERROR("%s: failed to concat strings", __func__);
+                goto error;
+            }
+
+            /* read device_type into buffer */
+            if ((readfile(prop, data, sizeof(data))) < 0) {
+                PERROR("%s: failed to read data from file %s", __func__, prop);
+                goto error;
+            }
+
+            /* if the device_type is 'cpu',  and reg is 0
+             * return the path where we found it */
+            if (strcmp(data, "cpu") == 0) {
+
+                /* construct path to reg */
+                if (snprintf(prop, sizeof(prop), "%s/%s", node,
+                             reg) >= sizeof(prop)) {
+                    PERROR("%s: failed to concat strings", __func__);
+                    goto error;
+                }
+
+                /* using data buffer since reg and device_type values have same size */
+                if ((readfile(prop, data, sizeof(data))) < 0) {
+                    PERROR("%s: failed to read data from file %s", __func__, prop);
+                    goto error;
+                }
+
+                /* now check property "reg" for value 0 */
+                if ((u32)*data == 0) {
+                    if (snprintf(cpupath, len, "%s", node) >= len) {
+                        PERROR("%s: failed to copy cpupath", __func__);
+                        goto error;
+                    }
+                    found = 1;
+                }
+            }
+        }
+    }
+
+    closedir(dir);
+    return found;
+
+error:
+    saved_errno = errno;
+    closedir(dir);
+    errno = saved_errno;
+    return -1;
+}
+
+void free_devtree(struct ft_cxt *root)
+{
+    if ((root != NULL) && root->bph != NULL) {
+        free(root->bph);
+        root->bph = NULL;
+    }
+}
+
+int make_devtree(struct ft_cxt *root,
+                 uint32_t domid,
+                 uint32_t mem_mb,
+                 unsigned long rma_bytes,
+                 unsigned long shadow_mb,
+                 unsigned long initrd_base,
+                 unsigned long initrd_len,
+                 const char *bootargs,
+                 uint64_t shared_info_paddr,
+                 unsigned long console_evtchn,
+                 uint64_t console_paddr,
+                 unsigned long store_evtchn,
+                 uint64_t store_paddr)
+{
+    struct boot_param_header *bph = NULL;
+    uint64_t val[2];
+    uint32_t val32[2];
+    unsigned long remaining;
+    unsigned long initrd_end = initrd_base + initrd_len;
+    int64_t shadow_mb_log;
+    uint64_t pft_size;
+    char cpupath[MAX_PATH];
+    const char *propfilter[] = { "ibm", "linux,", NULL };
+    char *cpupath_copy = NULL;
+    char *cpuname = NULL;
+    int saved_errno;
+    int dtb_fd = -1;
+    uint32_t cpu0_phandle = get_phandle();
+    uint32_t xen_phandle = get_phandle();
+    uint32_t rma_phandle = get_phandle();
+
+    /* initialize bph to prevent double free on error path */
+    root->bph = NULL;
+
+    /* carve out space for bph */
+    if ((bph = (struct boot_param_header *)malloc(BPH_SIZE)) == NULL) {
+        PERROR("%s: Failed to malloc bph buffer size", __func__);
+        goto error;
+    }
+
+    /* NB: struct ft_cxt root defined at top of file */
+    /* root = Tree() */
+    ft_begin(root, bph, BPH_SIZE);
+
+    /* you MUST set reservations BEFORE _starting_the_tree_ */
+
+    /* reserve shared_info_t page */
+    if (shared_info_paddr) {
+        val[0] = cpu_to_be64((u64) shared_info_paddr);
+        val[1] = cpu_to_be64((u64) PAGE_SIZE);
+        ft_add_rsvmap(root, val[0], val[1]);
+    }
+
+    /* reserve console page for domU */
+    if (console_paddr) {
+        val[0] = cpu_to_be64((u64) console_paddr);
+        val[1] = cpu_to_be64((u64) PAGE_SIZE);
+        ft_add_rsvmap(root, val[0], val[1]);
+    }
+
+    /* reserve xen store page for domU */
+    if (store_paddr) {
+        val[0] = cpu_to_be64((u64) store_paddr);
+        val[1] = cpu_to_be64((u64) PAGE_SIZE);
+        ft_add_rsvmap(root, val[0], val[1]);
+    }
+
+    /* reserve space for initrd if needed */
+    if ( initrd_len > 0 )  {
+        val[0] = cpu_to_be64((u64) initrd_base);
+        val[1] = cpu_to_be64((u64) initrd_len);
+        ft_add_rsvmap(root, val[0], val[1]);
+    }
+
+    /* NB: ft_add_rsvmap() already terminates with a NULL reservation for us */
+
+    /* done with reservations, _starting_the_tree_ */
+    ft_begin_tree(root);
+
+    /* make root node */
+    ft_begin_node(root, "");
+
+    /* root.addprop('device_type', 'chrp-but-not-really\0') */
+    ft_prop_str(root, "device_type", "chrp-but-not-really");
+
+    /* root.addprop('#size-cells', 2) */
+    ft_prop_int(root, "#size-cells", 2);
+
+    /* root.addprop('#address-cells', 2) */
+    ft_prop_int(root, "#address-cells", 2);
+
+    /* root.addprop('model', 'Momentum,Maple-D\0') */
+    ft_prop_str(root, "model", "Momentum,Maple-D");
+
+    /* root.addprop('compatible', 'Momentum,Maple\0') */
+    ft_prop_str(root, "compatible", "Momentum,Maple");
+
+    /* start chosen node */
+    ft_begin_node(root, "chosen");
+
+    /* chosen.addprop('cpu', cpu0.get_phandle()) */
+    ft_prop_int(root, "cpu", cpu0_phandle);
+
+    /* chosen.addprop('rma', rma.get_phandle()) */
+    ft_prop_int(root, "memory", rma_phandle);
+
+    /* chosen.addprop('linux,stdout-path', '/xen/console\0') */
+    ft_prop_str(root, "linux,stdout-path", "/xen/console");
+
+    /* chosen.addprop('interrupt-controller, xen.get_phandle()) */
+    ft_prop_int(root, "interrupt-controller", xen_phandle);
+
+    /* chosen.addprop('bootargs', imghandler.cmdline + '\0') */
+    if ( bootargs != NULL )
+        ft_prop_str(root, "bootargs", bootargs);
+
+    /* mark where the initrd is, if present */
+    if ( initrd_len > 0 ) {
+        val[0] = cpu_to_be64((u64) initrd_base);
+        val[1] = cpu_to_be64((u64) initrd_end);
+        ft_prop(root, "linux,initrd-start", &(val[0]), sizeof(val[0]));
+        ft_prop(root, "linux,initrd-end", &(val[1]), sizeof(val[1]));
+    }
+
+    /* end chosen node */
+    ft_end_node(root);
+
+    /* xen = root.addnode('xen') */
+    ft_begin_node(root, "xen");
+
+    /*  xen.addprop('version', 'Xen-3.0-unstable\0') */
+    ft_prop_str(root, "compatible", "Xen-3.0-unstable");
+
+    /* xen.addprop('reg', long(imghandler.vm.domid), long(0)) */
+    val[0] = cpu_to_be64((u64) domid);
+    val[1] = cpu_to_be64((u64) 0);
+    ft_prop(root, "reg", val, sizeof(val));
+
+    /* point to shared_info_t page base addr */
+    val[0] = cpu_to_be64((u64) shared_info_paddr);
+    val[1] = cpu_to_be64((u64) PAGE_SIZE);
+    ft_prop(root, "shared-info", val, sizeof(val));
+
+    /* xen.addprop('domain-name', imghandler.vm.getName() + '\0') */
+    /* libxc doesn't know the domain name, that is purely a xend thing */
+    /* ft_prop_str(root, "domain-name", domain_name); */
+
+    /* add xen/linux,phandle for chosen/interrupt-controller */
+    ft_prop_int(root, "linux,phandle", xen_phandle);
+
+    if (console_paddr != 0) {
+        /* xencons = xen.addnode('console') */
+        ft_begin_node(root, "console");
+
+        /* console_paddr */
+        val[0] = cpu_to_be64((u64) console_paddr);
+        val[1] = cpu_to_be64((u64) PAGE_SIZE);
+        ft_prop(root, "reg", val, sizeof(val));
+
+        /* xencons.addprop('interrupts', console_evtchn, 0) */
+        val32[0] = cpu_to_be32((u32) console_evtchn);
+        val32[1] = cpu_to_be32((u32) 0);
+        ft_prop(root, "interrupts", val32, sizeof(val32));
+
+        /* end of console */
+        ft_end_node(root);
+    }
+
+    if (store_paddr != 0) {
+        /* start store node */
+        ft_begin_node(root, "store");
+
+        /* store paddr */
+        val[0] = cpu_to_be64((u64) store_paddr);
+        val[1] = cpu_to_be64((u64) PAGE_SIZE);
+        ft_prop(root, "reg", val, sizeof(val));
+
+        /* store event channel */
+        val32[0] = cpu_to_be32((u32) store_evtchn);
+        val32[1] = cpu_to_be32((u32) 0);
+        ft_prop(root, "interrupts", val32, sizeof(val32));
+
+        /* end of store */
+        ft_end_node(root);
+    }
+
+    /* end of xen node */
+    ft_end_node(root);
+
+    /* rma = root.addnode('memory@0') */
+    ft_begin_node(root, "memory@0");
+
+    /* rma.addprop('reg', long(0), long(rma_bytes)) */
+    val[0] = cpu_to_be64((u64) 0);
+    val[1] = cpu_to_be64((u64) rma_bytes);
+    ft_prop(root, "reg", val, sizeof(val));
+
+    /* rma.addprop('device_type', 'memory\0') */
+    ft_prop_str(root, "device_type", "memory");
+
+    /* add linux,phandle for chosen/rma node */
+    ft_prop_int(root, "linux,phandle", rma_phandle);
+
+    /* end of memory@0 */
+    ft_end_node(root);
+
+    /* calculate remaining bytes from total - rma size */
+    remaining = (mem_mb * 1024 * 1024) - rma_bytes;
+
+    /* memory@<rma_bytes> is all remaining memory after RMA */
+    if (remaining > 0)
+    {
+        char mem[MAX_PATH];
+        
+        if (snprintf(mem, sizeof(mem), "memory@%lx",
+                     rma_bytes) >= sizeof(mem)) {
+            PERROR("%s: failed to build memory string", __func__);
+            goto error;
+        }
+
+        /* memory@<rma_bytes> is all remaining memory after RMA */
+        ft_begin_node(root, mem);
+
+        /* mem.addprop('reg', long(rma_bytes), long(remaining)) */
+        val[0] = cpu_to_be64((u64) rma_bytes);
+        val[1] = cpu_to_be64((u64) remaining);
+        ft_prop(root, "reg", val, sizeof(val));
+
+        /* mem.addprop('device_type', 'memory\0') */
+        ft_prop_str(root, "device_type", "memory");
+
+        /* end memory@<rma_bytes> node */
+        ft_end_node(root);
+    }
+
+    /* add CPU nodes */
+    /* cpus = root.addnode('cpus') */
+    ft_begin_node(root, "cpus");
+
+    /* cpus.addprop('smp-enabled') */
+    ft_prop(root, "smp-enabled", NULL, 0);
+
+    /* cpus.addprop('#size-cells', 0) */
+    ft_prop_int(root, "#size-cells", 0);
+
+    /* cpus.addprop('#address-cells', 1) */
+    ft_prop_int(root, "#address-cells", 1);
+
+    /*
+     * Copy all properties the system firmware gave us from a
+     * CPU node in the device tree.
+     */
+    if (find_cpu0(cpupath, sizeof(cpupath)) <= 0) {
+        PERROR("%s: failed find cpu0 node in host devtree", __func__);
+        goto error;
+    }
+
+    /* get the basename from path to cpu device */
+    if ((cpupath_copy = strdup(cpupath)) == NULL) {
+        PERROR("%s: failed to dupe string", __func__);
+        goto error;
+    }
+    if ((cpuname = basename(cpupath_copy)) == NULL) {
+        PERROR("%s: basename() failed", __func__);
+        goto error;
+    }
+    
+    /* start node for the cpu */
+    ft_begin_node(root, cpuname);
+
+    /* strdup() mallocs memory */
+    if ( cpupath_copy != NULL ) {
+        free(cpupath_copy);
+        cpupath_copy = NULL;
+    }
+
+    /* copy over most properties from host tree for cpu */
+    if (copynode(root, cpupath, propfilter) < 0) {
+        PERROR("%s: failed to copy node", __func__);
+            goto error;
+    }
+
+    /* calculate the pft-size */
+    shadow_mb_log = (int)log2((double)shadow_mb);
+    pft_size = shadow_mb_log + 20;
+
+    val32[0] = cpu_to_be32((u32) 0);
+    val32[1] = cpu_to_be32((u32) pft_size);
+    ft_prop(root, "ibm,pft-size", val32, sizeof(val32));
+
+    /* make phandle for cpu0 */
+    ft_prop_int(root, "linux,phandle", cpu0_phandle);
+
+    /* end <cpuname> node */
+    ft_end_node(root);
+
+    /* end cpus node */
+    ft_end_node(root);
+
+    /* end root node */
+    ft_end_node(root);
+
+    /* end of the tree */
+    if (ft_end_tree(root) != 0) {
+        PERROR("%s: failed to end tree", __func__);
+        goto error;
+    }
+
+    /* write a copy of the tree to a file */
+    if ((dtb_fd = open(DTB_FILE , O_RDWR)) == -1) {
+        PERROR("%s: failed to open file %s", __func__, DTB_FILE);
+        goto error;
+    }
+
+    if (write(dtb_fd, (const void *)bph, bph->totalsize) != bph->totalsize) {
+        PERROR("%s: failed to write blob to file", __func__);
+        goto error;
+    }
+
+    return 0;
+
+error:
+    saved_errno = errno;
+
+    /* strdup() mallocs memory */
+    if ( cpupath_copy != NULL ) {
+        free(cpupath_copy);
+        cpupath_copy = NULL;
+    }
+
+    /* free bph buffer */
+    free_devtree(root);
+
+    if (dtb_fd)
+        close(dtb_fd);
+
+    errno = saved_errno;
+    return -1;
+}
diff -r ac18d251df63 -r 9529d667d042 tools/libxc/powerpc64/mk_flatdevtree.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/libxc/powerpc64/mk_flatdevtree.h Thu Feb 15 14:09:39 2007 -0700
@@ -0,0 +1,47 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright IBM Corporation 2007
+ *
+ * Authors: Ryan Harper <[hidden email]>
+ */
+
+#ifndef MK_FLATDEVTREE_H
+#define MK_FLATDEVTREE_H
+
+#include "flatdevtree_env.h"
+#include "flatdevtree.h"
+
+extern void free_devtree(struct ft_cxt *root);
+extern int make_devtree(struct ft_cxt *root,
+                        uint32_t domid,
+                        uint32_t mem_mb,
+                        unsigned long rma_bytes,
+                        unsigned long shadow_mb,
+                        unsigned long initrd_base,
+                        unsigned long initrd_len,
+                        const char *bootargs,
+                        uint64_t shared_info_paddr,
+                        unsigned long console_evtchn,
+                        uint64_t console_paddr,
+                        unsigned long store_evtchn,
+                        uint64_t store_paddr);
+
+#define MAX_PATH 200
+#define BUFSIZE 1024
+#define BPH_SIZE 16*1024
+#define DTB_FILE "/tmp/domU.dtb"
+
+#endif /* MK_FLATDEVTREE_H */
diff -r ac18d251df63 -r 9529d667d042 tools/libxc/powerpc64/utils.c
--- a/tools/libxc/powerpc64/utils.c Thu Feb 15 13:13:36 2007 -0700
+++ b/tools/libxc/powerpc64/utils.c Thu Feb 15 14:09:39 2007 -0700
@@ -13,7 +13,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  *
- * Copyright (C) IBM Corporation 2006
+ * Copyright IBM Corporation 2006, 2007
  *
  * Authors: Hollis Blanchard <[hidden email]>
  *          Jimi Xenidis <[hidden email]>
@@ -36,29 +36,6 @@
 #include "flatdevtree_env.h"
 #include "flatdevtree.h"
 #include "utils.h"
-
-unsigned long get_rma_pages(void *devtree)
-{
-    void *rma;
-    uint64_t rma_reg[2];
-    int rc;
-
-    rma = ft_find_node(devtree, "/memory@0");
-    if (rma == NULL) {
-        DPRINTF("couldn't find /memory@0\n");
-        return 0;
-    }
-    rc = ft_get_prop(devtree, rma, "reg", rma_reg, sizeof(rma_reg));
-    if (rc < 0) {
-        DPRINTF("couldn't get /memory@0/reg\n");
-        return 0;
-    }
-    if (rma_reg[0] != 0) {
-        DPRINTF("RMA did not start at 0\n");
-        return 0;
-    }
-    return rma_reg[1] >> PAGE_SHIFT;
-}
 
 int get_rma_page_array(int xc_handle, int domid, xen_pfn_t **page_array,
        unsigned long nr_pages)
diff -r ac18d251df63 -r 9529d667d042 tools/libxc/powerpc64/utils.h
--- a/tools/libxc/powerpc64/utils.h Thu Feb 15 13:13:36 2007 -0700
+++ b/tools/libxc/powerpc64/utils.h Thu Feb 15 14:09:39 2007 -0700
@@ -13,13 +13,12 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  *
- * Copyright (C) IBM Corporation 2006
+ * Copyright IBM Corporation 2006, 2007
  *
  * Authors: Hollis Blanchard <[hidden email]>
  *          Jimi Xenidis <[hidden email]>
  */
 
-extern unsigned long get_rma_pages(void *devtree);
 extern int get_rma_page_array(int xc_handle, int domid, xen_pfn_t **page_array,
       unsigned long nr_pages);
 extern int install_image(int xc_handle, int domid, xen_pfn_t *page_array,
diff -r ac18d251df63 -r 9529d667d042 tools/libxc/powerpc64/xc_linux_build.c
--- a/tools/libxc/powerpc64/xc_linux_build.c Thu Feb 15 13:13:36 2007 -0700
+++ b/tools/libxc/powerpc64/xc_linux_build.c Thu Feb 15 14:09:39 2007 -0700
@@ -13,9 +13,10 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  *
- * Copyright (C) IBM Corporation 2006
+ * Copyright IBM Corporation 2006, 2007
  *
  * Authors: Hollis Blanchard <[hidden email]>
+ *          Ryan Harper <[hidden email]>
  */
 
 #include <stdio.h>
@@ -32,10 +33,12 @@
 #include <xc_private.h>
 #include <xg_private.h>
 #include <xenctrl.h>
+#include <xen/arch-powerpc.h>
 
 #include "flatdevtree_env.h"
 #include "flatdevtree.h"
 #include "utils.h"
+#include "mk_flatdevtree.h"
 
 #define INITRD_ADDR (24UL << 20)
 #define DEVTREE_ADDR (16UL << 20)
@@ -78,85 +81,6 @@ static int init_boot_vcpu(
     return rc;
 }
 
-static int load_devtree(
-    int xc_handle,
-    int domid,
-    xen_pfn_t *page_array,
-    void *devtree,
-    unsigned long devtree_addr,
-    uint64_t initrd_base,
-    unsigned long initrd_len,
-    start_info_t *start_info __attribute__((unused)),
-    unsigned long start_info_addr)
-{
-    uint32_t si[4] = {0, start_info_addr, 0, 0x1000};
-    struct boot_param_header *header;
-    void *chosen;
-    void *xen;
-    uint64_t initrd_end = initrd_base + initrd_len;
-    unsigned int devtree_size;
-    int rc = 0;
-
-    DPRINTF("adding initrd props\n");
-
-    chosen = ft_find_node(devtree, "/chosen");
-    if (chosen == NULL) {
-        DPRINTF("couldn't find /chosen\n");
-        return -1;
-    }
-
-    xen = ft_find_node(devtree, "/xen");
-    if (xen == NULL) {
-        DPRINTF("couldn't find /xen\n");
-        return -1;
-    }
-
-    /* initrd-start */
-    rc = ft_set_prop(&devtree, chosen, "linux,initrd-start",
-            &initrd_base, sizeof(initrd_base));
-    if (rc < 0) {
-        DPRINTF("couldn't set /chosen/linux,initrd-start\n");
-        return rc;
-    }
-
-    /* initrd-end */
-    rc = ft_set_prop(&devtree, chosen, "linux,initrd-end",
-            &initrd_end, sizeof(initrd_end));
-    if (rc < 0) {
-        DPRINTF("couldn't set /chosen/linux,initrd-end\n");
-        return rc;
-    }
-
-    rc = ft_set_rsvmap(devtree, 1, initrd_base, initrd_len);
-    if (rc < 0) {
-        DPRINTF("couldn't set initrd reservation\n");
-        return ~0UL;
-    }
-
-    /* start-info (XXX being removed soon) */
-    rc = ft_set_prop(&devtree, xen, "start-info", si, sizeof(si));
-    if (rc < 0) {
-        DPRINTF("couldn't set /xen/start-info\n");
-        return rc;
-    }
-
-    header = devtree;
-    devtree_size = header->totalsize;
-    {
-        static const char dtb[] = "/tmp/xc_domU.dtb";
-        int dfd = creat(dtb, 0666);
-        if (dfd != -1) {
-            write(dfd, devtree, devtree_size);
-            close(dfd);
-        } else
-            DPRINTF("could not open(\"%s\")\n", dtb);
-    }
-
-    DPRINTF("copying device tree to 0x%lx[0x%x]\n", DEVTREE_ADDR, devtree_size);
-    return install_image(xc_handle, domid, page_array, devtree, DEVTREE_ADDR,
-                       devtree_size);
-}
-
 static int load_initrd(
     int xc_handle,
     int domid,
@@ -186,46 +110,46 @@ out:
     return rc;
 }
 
-static unsigned long create_start_info(
- void *devtree, start_info_t *start_info,
-        unsigned int console_evtchn, unsigned int store_evtchn,
- unsigned long nr_pages, unsigned long rma_pages)
-{
-    unsigned long start_info_addr;
-    uint64_t rma_top;
-    int rc;
-
-    memset(start_info, 0, sizeof(*start_info));
-    snprintf(start_info->magic, sizeof(start_info->magic),
-             "xen-%d.%d-powerpc64HV", 3, 0);
-
-    rma_top = rma_pages << PAGE_SHIFT;
-    DPRINTF("RMA top = 0x%"PRIX64"\n", rma_top);
-
-    start_info->nr_pages = nr_pages;
-    start_info->shared_info = rma_top - PAGE_SIZE;
-    start_info->store_mfn = (rma_top >> PAGE_SHIFT) - 2;
-    start_info->store_evtchn = store_evtchn;
-    start_info->console.domU.mfn = (rma_top >> PAGE_SHIFT) - 3;
-    start_info->console.domU.evtchn = console_evtchn;
-    start_info_addr = rma_top - 4*PAGE_SIZE;
-
-    rc = ft_set_rsvmap(devtree, 0, start_info_addr, 4*PAGE_SIZE);
-    if (rc < 0) {
-        DPRINTF("couldn't set start_info reservation\n");
-        return ~0UL;
-    }
-
-
-    return start_info_addr;
-}
-
 static void free_page_array(xen_pfn_t *page_array)
 {
     free(page_array);
 }
 
-
+static int check_memory_config(int rma_log, unsigned int mem_mb)
+{
+    u64 mem_kb = (mem_mb << 10);
+    u64 rma_kb = (1 << rma_log) >> 10;
+
+    switch(rma_log)
+    {
+        case 26:
+        case 27:
+        case 28:
+        case 30:
+        case 34:
+        case 38:
+            if (mem_kb < rma_kb) {
+                DPRINTF("Domain memory must be at least %dMB\n",
+                        (1 << rma_log)>>20);
+                break;
+            }
+
+            if (mem_kb % (16 << 10)) {
+                DPRINTF("Domain memory %dMB must be a multiple of 16MB\n",
+                        mem_mb);
+                      
+                break;
+            }
+
+            /* rma_log and mem_mb OK */
+            return 0;
+
+        default:
+            DPRINTF("Invalid rma_log (%d)\n", rma_log);
+    }
+
+    return 1;
+}
 
 int xc_linux_build(int xc_handle,
                    uint32_t domid,
@@ -238,10 +162,8 @@ int xc_linux_build(int xc_handle,
                    unsigned int store_evtchn,
                    unsigned long *store_mfn,
                    unsigned int console_evtchn,
-                   unsigned long *console_mfn,
-                   void *devtree)
-{
-    start_info_t start_info;
+                   unsigned long *console_mfn)
+{
     struct domain_setup_info dsi;
     xen_pfn_t *page_array = NULL;
     unsigned long nr_pages;
@@ -249,19 +171,59 @@ int xc_linux_build(int xc_handle,
     unsigned long kern_addr;
     unsigned long initrd_base = 0;
     unsigned long initrd_len = 0;
-    unsigned long start_info_addr;
     unsigned long rma_pages;
+    unsigned long shadow_mb;
+    u64 shared_info_paddr;
+    u64 store_paddr;
+    u64 console_paddr;
+    u32 remaining_kb;
+    u32 extent_order;
+    u64 nr_extents;
+    int rma_log = 26;  /* 64MB RMA */
     int rc = 0;
+    int op;
+    struct ft_cxt devtree;
 
     DPRINTF("%s\n", __func__);
 
     nr_pages = mem_mb << (20 - PAGE_SHIFT);
     DPRINTF("nr_pages 0x%lx\n", nr_pages);
 
-    rma_pages = get_rma_pages(devtree);
+    rma_pages = (1 << rma_log) >> PAGE_SHIFT;
     if (rma_pages == 0) {
-    rc = -1;
-    goto out;
+        rc = -1;
+        goto out;
+    }
+
+    /* validate rma_log and domain memory config */
+    if (check_memory_config(rma_log, mem_mb)) {
+        rc = -1;
+        goto out;
+    }
+    
+    /* alloc RMA */
+    if (xc_alloc_real_mode_area(xc_handle, domid, rma_log)) {
+        rc = -1;
+        goto out;
+    }
+
+    /* subtract already allocated RMA to determine remaining KB to alloc */
+    remaining_kb = (nr_pages - rma_pages) * (PAGE_SIZE / 1024);
+    DPRINTF("totalmem - RMA = %dKB\n", remaining_kb);
+
+    /* to allocate in 16MB chunks, we need to determine the order of
+     * the number of PAGE_SIZE pages contained in 16MB. */
+    extent_order = 24 - 12; /* extent_order = log2((1 << 24) - (1 << 12)) */
+    nr_extents = (remaining_kb / (PAGE_SIZE/1024)) >> extent_order;
+    DPRINTF("allocating memory in %llu chunks of %luMB\n", nr_extents,
+            (((1 << extent_order) >> 10) * PAGE_SIZE) >> 10);
+
+    /* now allocate the remaining memory as large-order allocations */
+    DPRINTF("increase_reservation(%u, %llu, %u)\n", domid, nr_extents, extent_order);
+    if (xc_domain_memory_increase_reservation(xc_handle, domid, nr_extents,
+                                              extent_order, 0, NULL)) {
+        rc = -1;
+        goto out;
     }
 
     if (get_rma_page_array(xc_handle, domid, &page_array, rma_pages)) {
@@ -285,27 +247,46 @@ int xc_linux_build(int xc_handle,
         }
     }
 
-    /* start_info stuff: about to be removed  */
-    start_info_addr = create_start_info(devtree, &start_info, console_evtchn,
-                                        store_evtchn, nr_pages, rma_pages);
-    *console_mfn = page_array[start_info.console.domU.mfn];
-    *store_mfn = page_array[start_info.store_mfn];
-    if (install_image(xc_handle, domid, page_array, &start_info,
-                      start_info_addr, sizeof(start_info_t))) {
-        rc = -1;
-        goto out;
-    }
-
-    if (devtree) {
-        DPRINTF("loading flattened device tree\n");
-        devtree_addr = DEVTREE_ADDR;
-        if (load_devtree(xc_handle, domid, page_array, devtree, devtree_addr,
-                         initrd_base, initrd_len, &start_info,
-                         start_info_addr)) {
-            DPRINTF("couldn't load flattened device tree.\n");
-            rc = -1;
-            goto out;
-        }
+    /* fetch the current shadow_memory value for this domain */
+    op = XEN_DOMCTL_SHADOW_OP_GET_ALLOCATION;
+    if (xc_shadow_control(xc_handle, domid, op, NULL, 0,
+                          &shadow_mb, 0, NULL) < 0 ) {
+        rc = -1;
+        goto out;
+    }
+
+    /* determine shared_info, console, and store paddr */
+    shared_info_paddr = (rma_pages << PAGE_SHIFT) -
+                        (RMA_SHARED_INFO * PAGE_SIZE);
+    console_paddr = (rma_pages << PAGE_SHIFT) - (RMA_CONSOLE * PAGE_SIZE);
+    store_paddr = (rma_pages << PAGE_SHIFT) - (RMA_STORE * PAGE_SIZE);
+
+    /* map paddrs to mfns */
+    *store_mfn = page_array[(xen_pfn_t)(store_paddr >> PAGE_SHIFT)];
+    *console_mfn = page_array[(xen_pfn_t)(console_paddr >> PAGE_SHIFT)];
+    DPRINTF("console_mfn->%08lx store_mfn->%08lx\n", *console_mfn,
+            *store_mfn);
+
+    /* build the devtree here */
+    DPRINTF("constructing devtree\n");
+    if (make_devtree(&devtree, domid, mem_mb, (rma_pages << PAGE_SHIFT),
+                     shadow_mb, initrd_base, initrd_len, cmdline,
+                     shared_info_paddr, console_evtchn, console_paddr,
+                     store_evtchn, store_paddr) < 0) {
+        DPRINTF("failed to create flattened device tree\n");
+        rc = -1;
+        goto out;
+    }
+
+    devtree_addr = DEVTREE_ADDR;
+    DPRINTF("loading flattened device tree to 0x%lx[0x%x]\n",
+            devtree_addr, devtree.bph->totalsize);
+
+    if (install_image(xc_handle, domid, page_array, (void *)devtree.bph,
+                      devtree_addr, devtree.bph->totalsize)) {
+        DPRINTF("couldn't load flattened device tree.\n");
+        rc = -1;
+        goto out;
     }
 
     if (init_boot_vcpu(xc_handle, domid, &dsi, devtree_addr, kern_addr)) {
@@ -314,6 +295,7 @@ int xc_linux_build(int xc_handle,
     }
 
 out:
+    free_devtree(&devtree);
     free_page_array(page_array);
     return rc;
 }
diff -r ac18d251df63 -r 9529d667d042 tools/libxc/powerpc64/xc_prose_build.c
--- a/tools/libxc/powerpc64/xc_prose_build.c Thu Feb 15 13:13:36 2007 -0700
+++ b/tools/libxc/powerpc64/xc_prose_build.c Thu Feb 15 14:09:39 2007 -0700
@@ -13,7 +13,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  *
- * Copyright (C) IBM Corporation 2006
+ * Copyright IBM Corporation 2006, 2007
  *
  * Authors: Hollis Blanchard <[hidden email]>
  *          Jonathan Appavoo <[hidden email]>
@@ -34,18 +34,14 @@
 #include <xg_private.h>
 #include <xenctrl.h>
 
-#include "flatdevtree_env.h"
-#include "flatdevtree.h"
 #include "utils.h"
 
 #define INITRD_ADDR (24UL << 20)
-#define DEVTREE_ADDR (16UL << 20)
 
 static int init_boot_vcpu(
     int xc_handle,
     int domid,
     struct domain_setup_info *dsi,
-    unsigned long devtree_addr,
     unsigned long kern_addr)
 {
     vcpu_guest_context_t ctxt;
@@ -55,7 +51,7 @@ static int init_boot_vcpu(
     ctxt.user_regs.pc = dsi->v_kernentry;
     ctxt.user_regs.msr = 0;
     ctxt.user_regs.gprs[1] = 0; /* Linux uses its own stack */
-    ctxt.user_regs.gprs[3] = devtree_addr;
+    ctxt.user_regs.gprs[3] = 0;
     ctxt.user_regs.gprs[4] = kern_addr;
     ctxt.user_regs.gprs[5] = 0; /* reserved for specifying OF handler */
     /* There is a buggy kernel that does not zero the "local_paca", so
@@ -79,85 +75,6 @@ static int init_boot_vcpu(
     return rc;
 }
 
-static int load_devtree(
-    int xc_handle,
-    int domid,
-    xen_pfn_t *page_array,
-    void *devtree,
-    unsigned long devtree_addr,
-    uint64_t initrd_base,
-    unsigned long initrd_len,
-    start_info_t *start_info __attribute__((unused)),
-    unsigned long start_info_addr)
-{
-    uint32_t si[4] = {0, start_info_addr, 0, 0x1000};
-    struct boot_param_header *header;
-    void *chosen;
-    void *xen;
-    uint64_t initrd_end = initrd_base + initrd_len;
-    unsigned int devtree_size;
-    int rc = 0;
-
-    DPRINTF("adding initrd props\n");
-
-    chosen = ft_find_node(devtree, "/chosen");
-    if (chosen == NULL) {
-        DPRINTF("couldn't find /chosen\n");
-        return -1;
-    }
-
-    xen = ft_find_node(devtree, "/xen");
-    if (xen == NULL) {
-        DPRINTF("couldn't find /xen\n");
-        return -1;
-    }
-
-    /* initrd-start */
-    rc = ft_set_prop(&devtree, chosen, "linux,initrd-start",
-            &initrd_base, sizeof(initrd_base));
-    if (rc < 0) {
-        DPRINTF("couldn't set /chosen/linux,initrd-start\n");
-        return rc;
-    }
-
-    /* initrd-end */
-    rc = ft_set_prop(&devtree, chosen, "linux,initrd-end",
-            &initrd_end, sizeof(initrd_end));
-    if (rc < 0) {
-        DPRINTF("couldn't set /chosen/linux,initrd-end\n");
-        return rc;
-    }
-
-    rc = ft_set_rsvmap(devtree, 1, initrd_base, initrd_len);
-    if (rc < 0) {
-        DPRINTF("couldn't set initrd reservation\n");
-        return ~0UL;
-    }
-
-    /* start-info (XXX being removed soon) */
-    rc = ft_set_prop(&devtree, xen, "start-info", si, sizeof(si));
-    if (rc < 0) {
-        DPRINTF("couldn't set /xen/start-info\n");
-        return rc;
-    }
-
-    header = devtree;
-    devtree_size = header->totalsize;
-    {
-        static const char dtb[] = "/tmp/xc_domU.dtb";
-        int dfd = creat(dtb, 0666);
-        if (dfd != -1) {
-            write(dfd, devtree, devtree_size);
-            close(dfd);
-        } else
-            DPRINTF("could not open(\"%s\")\n", dtb);
-    }
-
-    DPRINTF("copying device tree to 0x%lx[0x%x]\n", DEVTREE_ADDR, devtree_size);
-    return install_image(xc_handle, domid, page_array, devtree, DEVTREE_ADDR,
-                       devtree_size);
-}
-
 static int load_initrd(
     int xc_handle,
     int domid,
@@ -188,13 +105,12 @@ out:
 }
 
 static unsigned long create_start_info(
- void *devtree, start_info_t *start_info,
+ start_info_t *start_info,
         unsigned int console_evtchn, unsigned int store_evtchn,
  unsigned long nr_pages, unsigned long rma_pages, const char *cmdline)
 {
     unsigned long start_info_addr;
     uint64_t rma_top;
-    int rc;
 
     memset(start_info, 0, sizeof(*start_info));
     snprintf(start_info->magic, sizeof(start_info->magic),
@@ -213,12 +129,6 @@ static unsigned long create_start_info(
     /* just in case we truncated cmdline with strncpy add 0 at the end */
     start_info->cmd_line[MAX_GUEST_CMDLINE-1]=0;
     start_info_addr = rma_top - 4*PAGE_SIZE;
-
-    rc = ft_set_rsvmap(devtree, 0, start_info_addr, 4*PAGE_SIZE);
-    if (rc < 0) {
-        DPRINTF("couldn't set start_info reservation\n");
-        return ~0UL;
-    }
 
     return start_info_addr;
 }
@@ -239,14 +149,12 @@ int xc_prose_build(int xc_handle,
                    unsigned int store_evtchn,
                    unsigned long *store_mfn,
                    unsigned int console_evtchn,
-                   unsigned long *console_mfn,
-                   void *devtree)
+                   unsigned long *console_mfn)
 {
     start_info_t start_info;
     struct domain_setup_info dsi;
     xen_pfn_t *page_array = NULL;
     unsigned long nr_pages;
-    unsigned long devtree_addr = 0;
     unsigned long kern_addr;
     unsigned long initrd_base = 0;
     unsigned long initrd_len = 0;
@@ -261,11 +169,7 @@ int xc_prose_build(int xc_handle,
     nr_pages = mem_mb << (20 - PAGE_SHIFT);
     DPRINTF("nr_pages 0x%lx\n", nr_pages);
 
-    rma_pages = get_rma_pages(devtree);
-    if (rma_pages == 0) {
-    rc = -1;
-    goto out;
-    }
+    rma_pages = (1 << 26) >> PAGE_SHIFT; /* 64 MB */
 
     if (get_rma_page_array(xc_handle, domid, &page_array, rma_pages)) {
         rc = -1;
@@ -289,9 +193,9 @@ int xc_prose_build(int xc_handle,
     }
 
     /* start_info stuff: about to be removed  */
-    start_info_addr = create_start_info(devtree, &start_info, console_evtchn,
+    start_info_addr = create_start_info(&start_info, console_evtchn,
                                         store_evtchn, nr_pages,
- rma_pages, cmdline);
+                                        rma_pages, cmdline);
     *console_mfn = page_array[start_info.console.domU.mfn];
     *store_mfn = page_array[start_info.store_mfn];
     if (install_image(xc_handle, domid, page_array, &start_info,
@@ -300,19 +204,7 @@ int xc_prose_build(int xc_handle,
         goto out;
     }
 
-    if (devtree) {
-        DPRINTF("loading flattened device tree\n");
-        devtree_addr = DEVTREE_ADDR;
-        if (load_devtree(xc_handle, domid, page_array, devtree, devtree_addr,
-                         initrd_base, initrd_len, &start_info,
-                         start_info_addr)) {
-            DPRINTF("couldn't load flattened device tree.\n");
-            rc = -1;
-            goto out;
-        }
-    }
-
-    if (init_boot_vcpu(xc_handle, domid, &dsi, devtree_addr, kern_addr)) {
+    if (init_boot_vcpu(xc_handle, domid, &dsi, kern_addr)) {
         rc = -1;
         goto out;
     }
diff -r ac18d251df63 -r 9529d667d042 tools/libxc/xc_dom.h
--- a/tools/libxc/xc_dom.h Thu Feb 15 13:13:36 2007 -0700
+++ b/tools/libxc/xc_dom.h Thu Feb 15 14:09:39 2007 -0700
@@ -6,11 +6,6 @@
 
 typedef uint64_t xen_vaddr_t;
 typedef uint64_t xen_paddr_t;
-
-/* FIXME: temporary hack ... */
-#ifndef PRIpfn
-#define PRIpfn "lx"
-#endif
 
 struct xc_dom_seg {
     xen_vaddr_t vstart;
diff -r ac18d251df63 -r 9529d667d042 tools/libxc/xc_dom_powerpc64.c
--- a/tools/libxc/xc_dom_powerpc64.c Thu Feb 15 13:13:36 2007 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,100 +0,0 @@
-/*
- * Xen domain builder -- ia64 bits.
- *
- * Most architecture-specific code for ia64 goes here.
- *   - fill architecture-specific structs.
- *
- * This code is licenced under the GPL.
- * written 2006 by Gerd Hoffmann <[hidden email]>.
- *
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <inttypes.h>
-
-#include <xen/xen.h>
-
-#include "xg_private.h"
-#include "xc_dom.h"
-
-/* ------------------------------------------------------------------------ */
-
-static int alloc_magic_pages(struct xc_dom_image *dom)
-{
-    /* allocate special pages */
-    dom->low_top--; /* shared_info */
-    dom->xenstore_pfn = --dom->low_top;
-    dom->console_pfn = --dom->low_top;
-    dom->start_info_pfn = --dom->low_top;
-    return 0;
-}
-
-static int start_info(struct xc_dom_image *dom)
-{
-    start_info_t *si =
- xc_dom_pfn_to_ptr(dom, dom->start_info_pfn, 1);
-
-    xc_dom_printf("%s\n", __FUNCTION__);
-
-    snprintf(si->magic, sizeof(si->magic), "xen-%d.%d-powerpc64HV", 3, 0);
-
-    si->nr_pages = dom->total_pages;
-    si->shared_info = (dom->total_pages - 1) << PAGE_SHIFT;
-    si->store_mfn = dom->xenstore_pfn;
-    si->store_evtchn = dom->store_evtchn;
-    si->console.domU.mfn = dom->console_pfn;
-    si->console.domU.evtchn = dom->console_evtchn;
-    return 0;
-}
-
-static int shared_info(struct xc_dom_image *dom, void *ptr)
-{
-    shared_info_t *shared_info = ptr;
-    int i;
-
-    xc_dom_printf("%s: called\n", __FUNCTION__);
-
-    memset(shared_info, 0, sizeof(*shared_info));
-    return 0;
-}
-
-static int vcpu(struct xc_dom_image *dom, void *ptr)
-{
-    vcpu_guest_context_t *ctxt = ptr;
-
-    xc_dom_printf("%s: called\n", __FUNCTION__);
-
-    /* clear everything */
-    memset(ctxt, 0, sizeof(*ctxt));
-
-    memset(&ctxt->user_regs, 0x55, sizeof(ctxt.user_regs));
-    ctxt->user_regs.pc = dsi->v_kernentry;
-    ctxt->user_regs.msr = 0;
-    ctxt->user_regs.gprs[1] = 0; /* Linux uses its own stack */
-    ctxt->user_regs.gprs[3] = devtree_addr;
-    ctxt->user_regs.gprs[4] = kern_addr;
-    ctxt->user_regs.gprs[5] = 0;
-
-    /* There is a buggy kernel that does not zero the "local_paca", so
-     * we must make sure this register is 0 */
-    ctxt->user_regs.gprs[13] = 0;
-
-    return 0;
-}
-
-/* ------------------------------------------------------------------------ */
-
-static struct xc_dom_arch xc_dom_arch = {
-    .guest_type = "xen-3.0-powerpc64",
-    .page_shift = FIXME,
-    .alloc_magic_pages = alloc_magic_pages,
-    .start_info = start_info,
-    .shared_info = shared_info,
-    .vcpu = vcpu,
-};
-
-static void __init register_arch_hooks(void)
-{
-    xc_dom_register_arch_hooks(&xc_dom_arch);
-}
diff -r ac18d251df63 -r 9529d667d042 tools/libxc/xenguest.h
--- a/tools/libxc/xenguest.h Thu Feb 15 13:13:36 2007 -0700
+++ b/tools/libxc/xenguest.h Thu Feb 15 14:09:39 2007 -0700
@@ -153,7 +153,6 @@ int xc_prose_build(int xc_handle,
                    unsigned int store_evtchn,
                    unsigned long *store_mfn,
                    unsigned int console_evtchn,
-                   unsigned long *console_mfn,
-                   void *arch_args);
+                   unsigned long *console_mfn);
 
 #endif /* XENGUEST_H */
diff -r ac18d251df63 -r 9529d667d042 tools/libxc/xg_private.c
--- a/tools/libxc/xg_private.c Thu Feb 15 13:13:36 2007 -0700
+++ b/tools/libxc/xg_private.c Thu Feb 15 14:09:39 2007 -0700
@@ -216,3 +216,15 @@ int xc_hvm_restore(int xc_handle, int io
     errno = ENOSYS;
     return -1;
 }
+
+__attribute__((weak)) int xc_get_hvm_param(
+    int handle, domid_t dom, int param, unsigned long *value)
+{
+    return -ENOSYS;
+}
+
+__attribute__((weak)) int xc_set_hvm_param(
+    int handle, domid_t dom, int param, unsigned long value)
+{
+    return -ENOSYS;
+}
diff -r ac18d251df63 -r 9529d667d042 tools/python/xen/lowlevel/xc/xc.c
--- a/tools/python/xen/lowlevel/xc/xc.c Thu Feb 15 13:13:36 2007 -0700
+++ b/tools/python/xen/lowlevel/xc/xc.c Thu Feb 15 14:09:39 2007 -0700
@@ -966,7 +966,7 @@ static PyObject *pyxc_alloc_real_mode_ar
         return NULL;
 
     if ( xc_alloc_real_mode_area(self->xc_handle, dom, log) )
-        return PyErr_SetFromErrno(xc_error);
+        return pyxc_error_to_exception();
 
     Py_INCREF(zero);
     return zero;
@@ -980,33 +980,32 @@ static PyObject *pyxc_prose_build(XcObje
     char *image, *ramdisk = NULL, *cmdline = "", *features = NULL;
     int flags = 0;
     int store_evtchn, console_evtchn;
+    unsigned int mem_mb;
     unsigned long store_mfn = 0;
     unsigned long console_mfn = 0;
-    void