ia64/xen-unstable

changeset 14509:2c087916aaba

[LIBXC][POWERPC] Use new domain builder.
Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
author Hollis Blanchard <hollisb@us.ibm.com>
date Wed Mar 21 17:03:00 2007 -0500 (2007-03-21)
parents 265e257388b5
children 49ec3725d0c0
files tools/libxc/Makefile tools/libxc/powerpc64/Makefile tools/libxc/powerpc64/mk_flatdevtree.c tools/libxc/powerpc64/mk_flatdevtree.h tools/libxc/powerpc64/utils.c tools/libxc/powerpc64/utils.h tools/libxc/powerpc64/xc_linux_build.c tools/libxc/xc_dom.h tools/libxc/xc_dom_compat_linux.c tools/libxc/xc_dom_powerpc.c
line diff
     1.1 --- a/tools/libxc/Makefile	Wed Mar 21 17:03:00 2007 -0500
     1.2 +++ b/tools/libxc/Makefile	Wed Mar 21 17:03:00 2007 -0500
     1.3 @@ -48,9 +48,11 @@ GUEST_SRCS-y += $(LIBELF_SRCS)
     1.4  GUEST_SRCS-y += xc_dom_core.c xc_dom_boot.c
     1.5  GUEST_SRCS-y += xc_dom_elfloader.c
     1.6  GUEST_SRCS-y += xc_dom_binloader.c
     1.7 +GUEST_SRCS-y += xc_dom_compat_linux.c
     1.8  
     1.9 -GUEST_SRCS-$(CONFIG_X86)     += xc_dom_x86.c xc_dom_compat_linux.c
    1.10 -GUEST_SRCS-$(CONFIG_IA64)    += xc_dom_ia64.c xc_dom_compat_linux.c
    1.11 +GUEST_SRCS-$(CONFIG_X86)     += xc_dom_x86.c
    1.12 +GUEST_SRCS-$(CONFIG_IA64)    += xc_dom_ia64.c
    1.13 +GUEST_SRCS-$(CONFIG_POWERPC) += xc_dom_powerpc.c
    1.14  
    1.15  -include $(XEN_TARGET_ARCH)/Makefile
    1.16  
     2.1 --- a/tools/libxc/powerpc64/Makefile	Wed Mar 21 17:03:00 2007 -0500
     2.2 +++ b/tools/libxc/powerpc64/Makefile	Wed Mar 21 17:03:00 2007 -0500
     2.3 @@ -1,6 +1,4 @@
     2.4  GUEST_SRCS-y += powerpc64/flatdevtree.c
     2.5  GUEST_SRCS-y += powerpc64/mk_flatdevtree.c
     2.6 -GUEST_SRCS-y += powerpc64/xc_linux_build.c
     2.7 -GUEST_SRCS-y += powerpc64/utils.c
     2.8  
     2.9  CTRL_SRCS-y += powerpc64/xc_memory.c
     3.1 --- a/tools/libxc/powerpc64/mk_flatdevtree.c	Wed Mar 21 17:03:00 2007 -0500
     3.2 +++ b/tools/libxc/powerpc64/mk_flatdevtree.c	Wed Mar 21 17:03:00 2007 -0500
     3.3 @@ -34,6 +34,7 @@
     3.4  #include <sys/param.h>
     3.5  
     3.6  #include <xc_private.h> /* for PERROR() */
     3.7 +#include <xc_dom.h>
     3.8  
     3.9  #include "mk_flatdevtree.h"
    3.10  
    3.11 @@ -310,24 +311,19 @@ void free_devtree(struct ft_cxt *root)
    3.12  }
    3.13  
    3.14  int make_devtree(struct ft_cxt *root,
    3.15 -                 uint32_t domid, 
    3.16 -                 uint32_t mem_mb,
    3.17 -                 unsigned long rma_bytes,
    3.18 -                 unsigned long shadow_mb,
    3.19 -                 unsigned long initrd_base,
    3.20 -                 unsigned long initrd_len,
    3.21 -                 const char *bootargs,
    3.22 -                 uint64_t shared_info_paddr,
    3.23 -                 unsigned long console_evtchn,
    3.24 -                 uint64_t console_paddr,
    3.25 -                 unsigned long store_evtchn,
    3.26 -                 uint64_t store_paddr)
    3.27 +                 struct xc_dom_image *dom,
    3.28 +                 unsigned long shadow_mb)
    3.29  {
    3.30      struct boot_param_header *bph = NULL;
    3.31      uint64_t val[2];
    3.32      uint32_t val32[2];
    3.33 -    unsigned long remaining;
    3.34 -    unsigned long initrd_end = initrd_base + initrd_len;
    3.35 +    uint64_t shared_info_paddr = dom->shared_info_pfn << PAGE_SHIFT;
    3.36 +    uint64_t xenstore_paddr = dom->xenstore_pfn << PAGE_SHIFT;
    3.37 +    uint64_t console_paddr = dom->console_pfn << PAGE_SHIFT;
    3.38 +    long remaining;
    3.39 +    unsigned long ramdisk_start;
    3.40 +    unsigned long ramdisk_size;
    3.41 +    unsigned long rma_bytes = 1 << dom->realmodearea_log;
    3.42      int64_t shadow_mb_log;
    3.43      uint64_t pft_size;
    3.44      char cpupath[MAX_PATH];
    3.45 @@ -370,16 +366,18 @@ int make_devtree(struct ft_cxt *root,
    3.46      }
    3.47  
    3.48      /* reserve xen store page for domU */
    3.49 -    if (store_paddr) {
    3.50 -        val[0] = cpu_to_be64((u64) store_paddr);
    3.51 +    if (xenstore_paddr) {
    3.52 +        val[0] = cpu_to_be64((u64) xenstore_paddr);
    3.53          val[1] = cpu_to_be64((u64) PAGE_SIZE);
    3.54          ft_add_rsvmap(root, val[0], val[1]);
    3.55      }
    3.56  
    3.57      /* reserve space for initrd if needed */
    3.58 -    if ( initrd_len > 0 )  {
    3.59 -        val[0] = cpu_to_be64((u64) initrd_base);
    3.60 -        val[1] = cpu_to_be64((u64) initrd_len);
    3.61 +    ramdisk_start = dom->ramdisk_seg.pfn << PAGE_SHIFT;
    3.62 +    ramdisk_size = dom->ramdisk_seg.vend - dom->ramdisk_seg.vstart;
    3.63 +    if (ramdisk_size > 0) {
    3.64 +        val[0] = cpu_to_be64((u64) ramdisk_start);
    3.65 +        val[1] = cpu_to_be64((u64) ramdisk_size);
    3.66          ft_add_rsvmap(root, val[0], val[1]);
    3.67      }
    3.68  
    3.69 @@ -422,13 +420,13 @@ int make_devtree(struct ft_cxt *root,
    3.70      ft_prop_int(root, "interrupt-controller", xen_phandle);
    3.71  
    3.72      /* chosen.addprop('bootargs', imghandler.cmdline + '\0') */
    3.73 -    if ( bootargs != NULL )
    3.74 -        ft_prop_str(root, "bootargs", bootargs);
    3.75 +    if (dom->cmdline != NULL)
    3.76 +        ft_prop_str(root, "bootargs", dom->cmdline);
    3.77  
    3.78      /* mark where the initrd is, if present */
    3.79 -    if ( initrd_len > 0 ) {
    3.80 -        val[0] = cpu_to_be64((u64) initrd_base);
    3.81 -        val[1] = cpu_to_be64((u64) initrd_end);
    3.82 +    if (ramdisk_size > 0) {
    3.83 +        val[0] = cpu_to_be64((u64) ramdisk_start);
    3.84 +        val[1] = cpu_to_be64((u64) ramdisk_start + ramdisk_size);
    3.85          ft_prop(root, "linux,initrd-start", &(val[0]), sizeof(val[0]));
    3.86          ft_prop(root, "linux,initrd-end", &(val[1]), sizeof(val[1]));
    3.87      }
    3.88 @@ -443,7 +441,7 @@ int make_devtree(struct ft_cxt *root,
    3.89      ft_prop_str(root, "compatible", "Xen-3.0-unstable");
    3.90  
    3.91      /* xen.addprop('reg', long(imghandler.vm.domid), long(0)) */
    3.92 -    val[0] = cpu_to_be64((u64) domid);
    3.93 +    val[0] = cpu_to_be64((u64) dom->guest_domid);
    3.94      val[1] = cpu_to_be64((u64) 0);
    3.95      ft_prop(root, "reg", val, sizeof(val));
    3.96  
    3.97 @@ -469,7 +467,7 @@ int make_devtree(struct ft_cxt *root,
    3.98          ft_prop(root, "reg", val, sizeof(val));
    3.99  
   3.100          /* xencons.addprop('interrupts', console_evtchn, 0) */
   3.101 -        val32[0] = cpu_to_be32((u32) console_evtchn);
   3.102 +        val32[0] = cpu_to_be32((u32) dom->console_evtchn);
   3.103          val32[1] = cpu_to_be32((u32) 0);
   3.104          ft_prop(root, "interrupts", val32, sizeof(val32));
   3.105  
   3.106 @@ -477,17 +475,17 @@ int make_devtree(struct ft_cxt *root,
   3.107          ft_end_node(root);
   3.108      }
   3.109  
   3.110 -    if (store_paddr != 0) {
   3.111 +    if (xenstore_paddr != 0) {
   3.112          /* start store node */
   3.113          ft_begin_node(root, "store");
   3.114  
   3.115          /* store paddr */
   3.116 -        val[0] = cpu_to_be64((u64) store_paddr);
   3.117 +        val[0] = cpu_to_be64((u64) xenstore_paddr);
   3.118          val[1] = cpu_to_be64((u64) PAGE_SIZE);
   3.119          ft_prop(root, "reg", val, sizeof(val));
   3.120  
   3.121          /* store event channel */
   3.122 -        val32[0] = cpu_to_be32((u32) store_evtchn);
   3.123 +        val32[0] = cpu_to_be32((u32) dom->xenstore_evtchn);
   3.124          val32[1] = cpu_to_be32((u32) 0);
   3.125          ft_prop(root, "interrupts", val32, sizeof(val32));
   3.126  
   3.127 @@ -516,7 +514,7 @@ int make_devtree(struct ft_cxt *root,
   3.128      ft_end_node(root);
   3.129  
   3.130      /* calculate remaining bytes from total - rma size */
   3.131 -    remaining = (mem_mb * 1024 * 1024) - rma_bytes;
   3.132 +    remaining = (dom->total_pages << PAGE_SHIFT) - rma_bytes;
   3.133  
   3.134      /* memory@<rma_bytes> is all remaining memory after RMA */
   3.135      if (remaining > 0)
     4.1 --- a/tools/libxc/powerpc64/mk_flatdevtree.h	Wed Mar 21 17:03:00 2007 -0500
     4.2 +++ b/tools/libxc/powerpc64/mk_flatdevtree.h	Wed Mar 21 17:03:00 2007 -0500
     4.3 @@ -26,18 +26,8 @@
     4.4  
     4.5  extern void free_devtree(struct ft_cxt *root);
     4.6  extern int make_devtree(struct ft_cxt *root,
     4.7 -                        uint32_t domid, 
     4.8 -                        uint32_t mem_mb,
     4.9 -                        unsigned long rma_bytes,
    4.10 -                        unsigned long shadow_mb,
    4.11 -                        unsigned long initrd_base,
    4.12 -                        unsigned long initrd_len,
    4.13 -                        const char *bootargs,
    4.14 -                        uint64_t shared_info_paddr,
    4.15 -                        unsigned long console_evtchn,
    4.16 -                        uint64_t console_paddr,
    4.17 -                        unsigned long store_evtchn,
    4.18 -                        uint64_t store_paddr);
    4.19 +                        struct xc_dom_image *dom,
    4.20 +                        unsigned long shadow_mb);
    4.21  
    4.22  #define MAX_PATH 200
    4.23  #define BUFSIZE 1024
     5.1 --- a/tools/libxc/powerpc64/utils.c	Wed Mar 21 17:03:00 2007 -0500
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,188 +0,0 @@
     5.4 -/*
     5.5 - * This program is free software; you can redistribute it and/or modify
     5.6 - * it under the terms of the GNU General Public License as published by
     5.7 - * the Free Software Foundation; either version 2 of the License, or
     5.8 - * (at your option) any later version.
     5.9 - *
    5.10 - * This program is distributed in the hope that it will be useful,
    5.11 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.12 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.13 - * GNU General Public License for more details.
    5.14 - *
    5.15 - * You should have received a copy of the GNU General Public License
    5.16 - * along with this program; if not, write to the Free Software
    5.17 - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    5.18 - *
    5.19 - * Copyright IBM Corporation 2006, 2007
    5.20 - *
    5.21 - * Authors: Hollis Blanchard <hollisb@us.ibm.com>
    5.22 - *          Jimi Xenidis <jimix@watson.ibm.com>
    5.23 - */
    5.24 -#include <stdio.h>
    5.25 -#include <stdint.h>
    5.26 -#include <stdlib.h>
    5.27 -#include <string.h>
    5.28 -#include <unistd.h>
    5.29 -#include <fcntl.h>
    5.30 -#include <sys/types.h>
    5.31 -#include <inttypes.h>
    5.32 -
    5.33 -#include <xen/xen.h>
    5.34 -#include <xen/memory.h>
    5.35 -#include <xc_private.h>
    5.36 -#include <xg_private.h>
    5.37 -#include <xenctrl.h>
    5.38 -
    5.39 -#include "flatdevtree_env.h"
    5.40 -#include "flatdevtree.h"
    5.41 -#include "utils.h"
    5.42 -
    5.43 -int get_rma_page_array(int xc_handle, int domid, xen_pfn_t **page_array,
    5.44 -		       unsigned long nr_pages)
    5.45 -{
    5.46 -    int rc;
    5.47 -    int i;
    5.48 -    xen_pfn_t *p;
    5.49 -
    5.50 -    *page_array = malloc(nr_pages * sizeof(xen_pfn_t));
    5.51 -    if (*page_array == NULL) {
    5.52 -        perror("malloc");
    5.53 -        return -1;
    5.54 -    }
    5.55 -
    5.56 -    DPRINTF("xc_get_pfn_list\n");
    5.57 -    /* We know that the RMA is machine contiguous so lets just get the
    5.58 -     * first MFN and fill the rest in ourselves */
    5.59 -    rc = xc_get_pfn_list(xc_handle, domid, (uint64_t *)*page_array, 1);
    5.60 -    if (rc == -1) {
    5.61 -        perror("Could not get the page frame list");
    5.62 -        return -1;
    5.63 -    }
    5.64 -    p = *page_array;
    5.65 -    for (i = 1; i < nr_pages; i++)
    5.66 -        p[i] = p[i - 1] + 1;
    5.67 -    return 0;
    5.68 -}
    5.69 -
    5.70 -int install_image(
    5.71 -        int xc_handle,
    5.72 -        int domid,
    5.73 -        xen_pfn_t *page_array,
    5.74 -        void *image,
    5.75 -        unsigned long paddr,
    5.76 -        unsigned long size)
    5.77 -{
    5.78 -    uint8_t *img = image;
    5.79 -    int i;
    5.80 -    int rc = 0;
    5.81 -
    5.82 -    if (paddr & ~PAGE_MASK) {
    5.83 -        printf("*** unaligned address\n");
    5.84 -        return -1;
    5.85 -    }
    5.86 -
    5.87 -    for (i = 0; i < size; i += PAGE_SIZE) {
    5.88 -        void *page = img + i;
    5.89 -        xen_pfn_t pfn = (paddr + i) >> PAGE_SHIFT;
    5.90 -        xen_pfn_t mfn = page_array[pfn];
    5.91 -
    5.92 -        rc = xc_copy_to_domain_page(xc_handle, domid, mfn, page);
    5.93 -        if (rc < 0) {
    5.94 -            perror("xc_copy_to_domain_page");
    5.95 -            break;
    5.96 -        }
    5.97 -    }
    5.98 -    return rc;
    5.99 -}
   5.100 -
   5.101 -void *load_file(const char *path, unsigned long *filesize)
   5.102 -{
   5.103 -    void *img;
   5.104 -    ssize_t size;
   5.105 -    int fd;
   5.106 -
   5.107 -    DPRINTF("load_file(%s)\n", path);
   5.108 -
   5.109 -    fd = open(path, O_RDONLY);
   5.110 -    if (fd < 0) {
   5.111 -        perror(path);
   5.112 -        return NULL;
   5.113 -    }
   5.114 -
   5.115 -    size = lseek(fd, 0, SEEK_END);
   5.116 -    if (size < 0) {
   5.117 -        perror(path);
   5.118 -        close(fd);
   5.119 -        return NULL;
   5.120 -    }
   5.121 -    lseek(fd, 0, SEEK_SET);
   5.122 -
   5.123 -    img = malloc(size);
   5.124 -    if (img == NULL) {
   5.125 -        perror(path);
   5.126 -        close(fd);
   5.127 -        return NULL;
   5.128 -    }
   5.129 -
   5.130 -    size = read(fd, img, size);
   5.131 -    if (size <= 0) {
   5.132 -        perror(path);
   5.133 -        close(fd);
   5.134 -        free(img);
   5.135 -        return NULL;
   5.136 -    }
   5.137 -
   5.138 -    if (filesize)
   5.139 -        *filesize = size;
   5.140 -    close(fd);
   5.141 -    return img;
   5.142 -}
   5.143 -
   5.144 -int load_elf_kernel(
   5.145 -    int xc_handle,
   5.146 -    int domid,
   5.147 -    const char *kernel_path,
   5.148 -    struct domain_setup_info *dsi,
   5.149 -    xen_pfn_t *page_array)
   5.150 -{
   5.151 -    struct load_funcs load_funcs;
   5.152 -    char *kernel_img;
   5.153 -    unsigned long kernel_size;
   5.154 -    int rc;
   5.155 -
   5.156 -    /* load the kernel ELF file */
   5.157 -    kernel_img = load_file(kernel_path, &kernel_size);
   5.158 -    if (kernel_img == NULL) {
   5.159 -        rc = -1;
   5.160 -        goto out;
   5.161 -    }
   5.162 -
   5.163 -    DPRINTF("probe_elf\n");
   5.164 -    rc = probe_elf(kernel_img, kernel_size, &load_funcs);
   5.165 -    if (rc < 0) {
   5.166 -        rc = -1;
   5.167 -        printf("%s is not an ELF file\n", kernel_path);
   5.168 -        goto out;
   5.169 -    }
   5.170 -
   5.171 -    DPRINTF("parseimage\n");
   5.172 -    rc = (load_funcs.parseimage)(kernel_img, kernel_size, dsi);
   5.173 -    if (rc < 0) {
   5.174 -        rc = -1;
   5.175 -        goto out;
   5.176 -    }
   5.177 -
   5.178 -    DPRINTF("loadimage\n");
   5.179 -    (load_funcs.loadimage)(kernel_img, kernel_size, xc_handle, domid,
   5.180 -            page_array, dsi);
   5.181 -
   5.182 -    DPRINTF("  v_start     %016"PRIx64"\n", dsi->v_start);
   5.183 -    DPRINTF("  v_end       %016"PRIx64"\n", dsi->v_end);
   5.184 -    DPRINTF("  v_kernstart %016"PRIx64"\n", dsi->v_kernstart);
   5.185 -    DPRINTF("  v_kernend   %016"PRIx64"\n", dsi->v_kernend);
   5.186 -    DPRINTF("  v_kernentry %016"PRIx64"\n", dsi->v_kernentry);
   5.187 -
   5.188 -out:
   5.189 -    free(kernel_img);
   5.190 -    return rc;
   5.191 -}
     6.1 --- a/tools/libxc/powerpc64/utils.h	Wed Mar 21 17:03:00 2007 -0500
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,37 +0,0 @@
     6.4 -/*
     6.5 - * This program is free software; you can redistribute it and/or modify
     6.6 - * it under the terms of the GNU General Public License as published by
     6.7 - * the Free Software Foundation; either version 2 of the License, or
     6.8 - * (at your option) any later version.
     6.9 - *
    6.10 - * This program is distributed in the hope that it will be useful,
    6.11 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.12 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    6.13 - * GNU General Public License for more details.
    6.14 - *
    6.15 - * You should have received a copy of the GNU General Public License
    6.16 - * along with this program; if not, write to the Free Software
    6.17 - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    6.18 - *
    6.19 - * Copyright IBM Corporation 2006, 2007
    6.20 - *
    6.21 - * Authors: Hollis Blanchard <hollisb@us.ibm.com>
    6.22 - *          Jimi Xenidis <jimix@watson.ibm.com>
    6.23 - */
    6.24 -
    6.25 -extern int get_rma_page_array(int xc_handle, int domid, xen_pfn_t **page_array,
    6.26 -			      unsigned long nr_pages);
    6.27 -extern int install_image(int xc_handle, int domid, xen_pfn_t *page_array,
    6.28 -			 void *image, unsigned long paddr, unsigned long size);
    6.29 -extern void *load_file(const char *path, unsigned long *filesize);
    6.30 -extern int load_elf_kernel(int xc_handle, int domid,  const char *kernel_path,
    6.31 -			   struct domain_setup_info *dsi,
    6.32 -			   xen_pfn_t *page_array);
    6.33 -
    6.34 -#define ALIGN_UP(addr,size) (((addr)+((size)-1))&(~((size)-1)))
    6.35 -
    6.36 -#define max(x,y) ({ \
    6.37 -        const typeof(x) _x = (x);       \
    6.38 -        const typeof(y) _y = (y);       \
    6.39 -        (void) (&_x == &_y);            \
    6.40 -        _x > _y ? _x : _y; })
     7.1 --- a/tools/libxc/powerpc64/xc_linux_build.c	Wed Mar 21 17:03:00 2007 -0500
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,336 +0,0 @@
     7.4 -/*
     7.5 - * This program is free software; you can redistribute it and/or modify
     7.6 - * it under the terms of the GNU General Public License as published by
     7.7 - * the Free Software Foundation; either version 2 of the License, or
     7.8 - * (at your option) any later version.
     7.9 - *
    7.10 - * This program is distributed in the hope that it will be useful,
    7.11 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.12 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    7.13 - * GNU General Public License for more details.
    7.14 - *
    7.15 - * You should have received a copy of the GNU General Public License
    7.16 - * along with this program; if not, write to the Free Software
    7.17 - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    7.18 - *
    7.19 - * Copyright IBM Corporation 2006, 2007
    7.20 - *
    7.21 - * Authors: Hollis Blanchard <hollisb@us.ibm.com>
    7.22 - *          Ryan Harper <ryanh@us.ibm.com>
    7.23 - */
    7.24 -
    7.25 -#include <stdio.h>
    7.26 -#include <stdint.h>
    7.27 -#include <stdlib.h>
    7.28 -#include <string.h>
    7.29 -#include <unistd.h>
    7.30 -#include <fcntl.h>
    7.31 -#include <sys/types.h>
    7.32 -#include <inttypes.h>
    7.33 -
    7.34 -#include <xen/xen.h>
    7.35 -#include <xen/memory.h>
    7.36 -#include <xc_private.h>
    7.37 -#include <xg_private.h>
    7.38 -#include <xenctrl.h>
    7.39 -
    7.40 -#include "flatdevtree_env.h"
    7.41 -#include "flatdevtree.h"
    7.42 -#include "utils.h"
    7.43 -#include "mk_flatdevtree.h"
    7.44 -
    7.45 -/* Use 16MB extents to match PowerPC's large page size. */
    7.46 -#define EXTENT_SHIFT 24
    7.47 -#define EXTENT_ORDER (EXTENT_SHIFT - PAGE_SHIFT)
    7.48 -
    7.49 -#define INITRD_ADDR (24UL << 20)
    7.50 -#define DEVTREE_ADDR (16UL << 20)
    7.51 -
    7.52 -static int init_boot_vcpu(
    7.53 -    int xc_handle,
    7.54 -    int domid,
    7.55 -    struct domain_setup_info *dsi,
    7.56 -    unsigned long devtree_addr,
    7.57 -    unsigned long kern_addr)
    7.58 -{
    7.59 -    vcpu_guest_context_t ctxt;
    7.60 -    int rc;
    7.61 -
    7.62 -    memset(&ctxt.user_regs, 0x55, sizeof(ctxt.user_regs));
    7.63 -    ctxt.user_regs.pc = dsi->v_kernentry;
    7.64 -    ctxt.user_regs.msr = 0;
    7.65 -    ctxt.user_regs.gprs[1] = 0; /* Linux uses its own stack */
    7.66 -    ctxt.user_regs.gprs[3] = devtree_addr;
    7.67 -    ctxt.user_regs.gprs[4] = kern_addr;
    7.68 -    ctxt.user_regs.gprs[5] = 0;
    7.69 -    /* There is a buggy kernel that does not zero the "local_paca", so
    7.70 -     * we must make sure this register is 0 */
    7.71 -    ctxt.user_regs.gprs[13] = 0;
    7.72 -
    7.73 -    DPRINTF("xc_vcpu_setvcpucontext:\n"
    7.74 -                 "  pc 0x%016"PRIx64", msr 0x%016"PRIx64"\n"
    7.75 -                 "  r1-5 %016"PRIx64" %016"PRIx64" %016"PRIx64" %016"PRIx64
    7.76 -                 " %016"PRIx64"\n",
    7.77 -                 ctxt.user_regs.pc, ctxt.user_regs.msr,
    7.78 -                 ctxt.user_regs.gprs[1],
    7.79 -                 ctxt.user_regs.gprs[2],
    7.80 -                 ctxt.user_regs.gprs[3],
    7.81 -                 ctxt.user_regs.gprs[4],
    7.82 -                 ctxt.user_regs.gprs[5]);
    7.83 -    rc = xc_vcpu_setcontext(xc_handle, domid, 0, &ctxt);
    7.84 -    if (rc < 0)
    7.85 -        perror("setdomaininfo");
    7.86 -
    7.87 -    return rc;
    7.88 -}
    7.89 -
    7.90 -static int load_initrd(
    7.91 -    int xc_handle,
    7.92 -    int domid,
    7.93 -    xen_pfn_t *page_array,
    7.94 -    const char *initrd_path,
    7.95 -    unsigned long *base,
    7.96 -    unsigned long *len)
    7.97 -{
    7.98 -    uint8_t *initrd_img;
    7.99 -    int rc = -1;
   7.100 -
   7.101 -    /* load the initrd file */
   7.102 -    initrd_img = load_file(initrd_path, len);
   7.103 -    if (initrd_img == NULL)
   7.104 -        return -1;
   7.105 -
   7.106 -    DPRINTF("copying initrd to 0x%lx[0x%lx]\n", INITRD_ADDR, *len);
   7.107 -    if (install_image(xc_handle, domid, page_array, initrd_img, INITRD_ADDR,
   7.108 -                *len))
   7.109 -        goto out;
   7.110 -
   7.111 -    *base = INITRD_ADDR;
   7.112 -    rc = 0;
   7.113 -
   7.114 -out:
   7.115 -    free(initrd_img);
   7.116 -    return rc;
   7.117 -}
   7.118 -
   7.119 -static void free_page_array(xen_pfn_t *page_array)
   7.120 -{
   7.121 -    free(page_array);
   7.122 -}
   7.123 -
   7.124 -static int check_memory_config(int rma_log, unsigned int mem_mb)
   7.125 -{
   7.126 -    u64 mem_kb = (mem_mb << 10);
   7.127 -    u64 rma_kb = (1 << rma_log) >> 10;
   7.128 -
   7.129 -    switch(rma_log)
   7.130 -    {
   7.131 -        case 26:
   7.132 -        case 27:
   7.133 -        case 28:
   7.134 -        case 30:
   7.135 -        case 34:
   7.136 -        case 38:
   7.137 -            if (mem_kb < rma_kb) {
   7.138 -                DPRINTF("Domain memory must be at least %dMB\n", 
   7.139 -                        (1 << rma_log)>>20);
   7.140 -                break;
   7.141 -            }
   7.142 -
   7.143 -            if (mem_kb % (16 << 10)) {
   7.144 -                DPRINTF("Domain memory %dMB must be a multiple of 16MB\n",
   7.145 -                        mem_mb);
   7.146 -                       
   7.147 -                break;
   7.148 -            }
   7.149 -
   7.150 -            /* rma_log and mem_mb OK */
   7.151 -            return 0;
   7.152 -
   7.153 -        default:
   7.154 -            DPRINTF("Invalid rma_log (%d)\n", rma_log);
   7.155 -    }
   7.156 -
   7.157 -    return 1;
   7.158 -}
   7.159 -
   7.160 -static int alloc_memory(int xc_handle, domid_t domid, ulong nr_pages,
   7.161 -                        ulong rma_pages)
   7.162 -{
   7.163 -    xen_pfn_t *extent_pfn_arry;
   7.164 -    ulong nr_extents;
   7.165 -    ulong start_pfn = rma_pages;
   7.166 -    int i;
   7.167 -    int j;
   7.168 -    int rc = 0;
   7.169 -
   7.170 -    nr_extents = (nr_pages - rma_pages) >> EXTENT_ORDER;
   7.171 -    DPRINTF("allocating memory in %lu chunks of %luMB\n", nr_extents,
   7.172 -            1UL >> (20 - EXTENT_ORDER));
   7.173 -
   7.174 -    /* populate_physmap requires an array of PFNs that determine where the
   7.175 -     * guest mapping of the new MFNs. */
   7.176 -    extent_pfn_arry = malloc((1<<EXTENT_ORDER) * sizeof(xen_pfn_t));
   7.177 -    if (extent_pfn_arry == NULL) {
   7.178 -        PERROR("Couldn't allocate extent PFN array.\n");
   7.179 -        return -ENOMEM;
   7.180 -    }
   7.181 -
   7.182 -    /* Now allocate the remaining memory as large-order extents. */
   7.183 -    for (i = 0; i < nr_extents; i++) {
   7.184 -        /* Initialize the extent PFN array. */
   7.185 -        for (j = 0; j < (1 << EXTENT_ORDER); j++)
   7.186 -            extent_pfn_arry[j] = start_pfn++;
   7.187 -
   7.188 -        DPRINTF("populate_physmap(Dom%u, order %u, starting_pfn %llx)\n",
   7.189 -                domid, EXTENT_ORDER, extent_pfn_arry[0]);
   7.190 -
   7.191 -        if (xc_domain_memory_populate_physmap(xc_handle, domid, 1, EXTENT_ORDER,
   7.192 -                                               0, extent_pfn_arry))
   7.193 -        {
   7.194 -            PERROR("Could not allocate extents\n");
   7.195 -            rc = -1;
   7.196 -            break;
   7.197 -        }
   7.198 -    }
   7.199 -
   7.200 -    free(extent_pfn_arry);
   7.201 -    return rc;
   7.202 -}
   7.203 -
   7.204 -int xc_linux_build(int xc_handle,
   7.205 -                   uint32_t domid,
   7.206 -                   unsigned int mem_mb,
   7.207 -                   const char *image_name,
   7.208 -                   const char *initrd_name,
   7.209 -                   const char *cmdline,
   7.210 -                   const char *features,
   7.211 -                   unsigned long flags,
   7.212 -                   unsigned int store_evtchn,
   7.213 -                   unsigned long *store_mfn,
   7.214 -                   unsigned int console_evtchn,
   7.215 -                   unsigned long *console_mfn)
   7.216 -{
   7.217 -    struct domain_setup_info dsi;
   7.218 -    xen_pfn_t *page_array = NULL;
   7.219 -    unsigned long nr_pages;
   7.220 -    unsigned long devtree_addr = 0;
   7.221 -    unsigned long kern_addr;
   7.222 -    unsigned long initrd_base = 0;
   7.223 -    unsigned long initrd_len = 0;
   7.224 -    unsigned long rma_pages;
   7.225 -    unsigned long shadow_mb;
   7.226 -    u64 shared_info_paddr;
   7.227 -    u64 store_paddr;
   7.228 -    u64 console_paddr;
   7.229 -    int rma_log = 26;  /* 64MB RMA */
   7.230 -    int rc = 0;
   7.231 -    int op;
   7.232 -    struct ft_cxt devtree;
   7.233 -
   7.234 -    DPRINTF("%s\n", __func__);
   7.235 -
   7.236 -    nr_pages = mem_mb << (20 - PAGE_SHIFT);
   7.237 -    DPRINTF("nr_pages 0x%lx\n", nr_pages);
   7.238 -
   7.239 -    rma_pages = (1 << rma_log) >> PAGE_SHIFT;
   7.240 -    if (rma_pages == 0) {
   7.241 -        rc = -1;
   7.242 -        goto out;
   7.243 -    }
   7.244 -
   7.245 -    /* validate rma_log and domain memory config */
   7.246 -    if (check_memory_config(rma_log, mem_mb)) {
   7.247 -        rc = -1;
   7.248 -        goto out;
   7.249 -    }
   7.250 -    
   7.251 -    /* Allocate the RMA. */
   7.252 -    DPRINTF("RMA: 0x%lx pages\n", rma_pages);
   7.253 -    if (xc_alloc_real_mode_area(xc_handle, domid, rma_log)) {
   7.254 -        rc = -1;
   7.255 -        goto out;
   7.256 -    }
   7.257 -
   7.258 -    /* Get the MFN mapping (for RMA only -- we only load data into the RMA). */
   7.259 -    if (get_rma_page_array(xc_handle, domid, &page_array, rma_pages)) {
   7.260 -        rc = -1;
   7.261 -        goto out;
   7.262 -    }
   7.263 -
   7.264 -    /* Allocate the non-RMA memory. */
   7.265 -    rc = alloc_memory(xc_handle, domid, nr_pages, rma_pages);
   7.266 -    if (rc) {
   7.267 -        goto out;
   7.268 -    }
   7.269 -
   7.270 -    /* Load kernel. */
   7.271 -    DPRINTF("loading image '%s'\n", image_name);
   7.272 -    if (load_elf_kernel(xc_handle, domid, image_name, &dsi, page_array)) {
   7.273 -        rc = -1;
   7.274 -        goto out;
   7.275 -    }
   7.276 -    kern_addr = 0;
   7.277 -
   7.278 -    /* Load initrd. */
   7.279 -    if (initrd_name && initrd_name[0] != '\0') {
   7.280 -        DPRINTF("loading initrd '%s'\n", initrd_name);
   7.281 -        if (load_initrd(xc_handle, domid, page_array, initrd_name,
   7.282 -                &initrd_base, &initrd_len)) {
   7.283 -            rc = -1;
   7.284 -            goto out;
   7.285 -        }
   7.286 -    }
   7.287 -
   7.288 -    /* fetch the current shadow_memory value for this domain */
   7.289 -    op = XEN_DOMCTL_SHADOW_OP_GET_ALLOCATION;
   7.290 -    if (xc_shadow_control(xc_handle, domid, op, NULL, 0, 
   7.291 -                          &shadow_mb, 0, NULL) < 0) {
   7.292 -        rc = -1;
   7.293 -        goto out;
   7.294 -    }
   7.295 -
   7.296 -    /* determine shared_info, console, and store paddr */
   7.297 -    shared_info_paddr = (rma_pages << PAGE_SHIFT) - PAGE_SIZE;
   7.298 -    console_paddr = shared_info_paddr - PAGE_SIZE;
   7.299 -    store_paddr = console_paddr - PAGE_SIZE;
   7.300 -
   7.301 -    /* map paddrs to mfns */
   7.302 -    *store_mfn = page_array[(xen_pfn_t)(store_paddr >> PAGE_SHIFT)];
   7.303 -    *console_mfn = page_array[(xen_pfn_t)(console_paddr >> PAGE_SHIFT)];
   7.304 -    DPRINTF("console_mfn->%08lx store_mfn->%08lx\n", *console_mfn,
   7.305 -            *store_mfn);
   7.306 -
   7.307 -    /* build the devtree here */
   7.308 -    DPRINTF("constructing devtree\n");
   7.309 -    if (make_devtree(&devtree, domid, mem_mb, (rma_pages << PAGE_SHIFT),
   7.310 -                     shadow_mb, initrd_base, initrd_len, cmdline, 
   7.311 -                     shared_info_paddr, console_evtchn, console_paddr,
   7.312 -                     store_evtchn, store_paddr) < 0) {
   7.313 -        DPRINTF("failed to create flattened device tree\n");
   7.314 -        rc = -1;
   7.315 -        goto out;
   7.316 -    }
   7.317 -
   7.318 -    devtree_addr = DEVTREE_ADDR;
   7.319 -    DPRINTF("loading flattened device tree to 0x%lx[0x%x]\n",
   7.320 -            devtree_addr, devtree.bph->totalsize);
   7.321 -
   7.322 -    if (install_image(xc_handle, domid, page_array, (void *)devtree.bph,
   7.323 -                      devtree_addr, devtree.bph->totalsize)) {
   7.324 -        DPRINTF("couldn't load flattened device tree.\n");
   7.325 -        rc = -1;
   7.326 -        goto out2;
   7.327 -    }
   7.328 -
   7.329 -    if (init_boot_vcpu(xc_handle, domid, &dsi, devtree_addr, kern_addr)) {
   7.330 -        rc = -1;
   7.331 -        goto out2;
   7.332 -    }
   7.333 -
   7.334 -out2:
   7.335 -    free_devtree(&devtree);
   7.336 -out:
   7.337 -    free_page_array(page_array);
   7.338 -    return rc;
   7.339 -}
     8.1 --- a/tools/libxc/xc_dom.h	Wed Mar 21 17:03:00 2007 -0500
     8.2 +++ b/tools/libxc/xc_dom.h	Wed Mar 21 17:03:00 2007 -0500
     8.3 @@ -49,6 +49,7 @@ struct xc_dom_image {
     8.4      struct xc_dom_seg ramdisk_seg;
     8.5      struct xc_dom_seg p2m_seg;
     8.6      struct xc_dom_seg pgtables_seg;
     8.7 +    struct xc_dom_seg devicetree_seg;
     8.8      xen_pfn_t start_info_pfn;
     8.9      xen_pfn_t console_pfn;
    8.10      xen_pfn_t xenstore_pfn;
    8.11 @@ -75,6 +76,7 @@ struct xc_dom_image {
    8.12      /* physical memory */
    8.13      xen_pfn_t total_pages;
    8.14      struct xc_dom_phys *phys_pages;
    8.15 +    int realmodearea_log;
    8.16  
    8.17      /* malloc memory pool */
    8.18      struct xc_dom_mem *memblocks;
     9.1 --- a/tools/libxc/xc_dom_compat_linux.c	Wed Mar 21 17:03:00 2007 -0500
     9.2 +++ b/tools/libxc/xc_dom_compat_linux.c	Wed Mar 21 17:03:00 2007 -0500
     9.3 @@ -32,6 +32,10 @@ static int xc_linux_build_internal(struc
     9.4  {
     9.5      int rc;
     9.6  
     9.7 +    dom->flags = flags;
     9.8 +    dom->console_evtchn = console_evtchn;
     9.9 +    dom->xenstore_evtchn = store_evtchn;
    9.10 +
    9.11      if ( (rc = xc_dom_boot_xen_init(dom, xc_handle, domid)) != 0 )
    9.12          goto out;
    9.13      if ( (rc = xc_dom_parse_image(dom)) != 0 )
    9.14 @@ -42,12 +46,7 @@ static int xc_linux_build_internal(struc
    9.15          goto out;
    9.16      if ( (rc = xc_dom_build_image(dom)) != 0 )
    9.17          goto out;
    9.18 -
    9.19 -    dom->flags = flags;
    9.20 -    dom->console_evtchn = console_evtchn;
    9.21 -    dom->xenstore_evtchn = store_evtchn;
    9.22 -    rc = xc_dom_boot_image(dom);
    9.23 -    if ( rc != 0 )
    9.24 +    if ( (rc = xc_dom_boot_image(dom)) != 0 )
    9.25          goto out;
    9.26  
    9.27      *console_mfn = xc_dom_p2m_host(dom, dom->console_pfn);
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/tools/libxc/xc_dom_powerpc.c	Wed Mar 21 17:03:00 2007 -0500
    10.3 @@ -0,0 +1,236 @@
    10.4 +/*
    10.5 + * Xen domain builder -- powerpc bits.
    10.6 + *
    10.7 + * Most architecture-specific code for powerpc goes here.
    10.8 + *
    10.9 + * This code is licenced under the GPL.
   10.10 + * written 2006 by Gerd Hoffmann <kraxel@suse.de>.
   10.11 + *
   10.12 + * Copyright IBM Corp. 2007
   10.13 + *
   10.14 + * Authors: Gerd Hoffmann <kraxel@suse.de>
   10.15 + *          Hollis Blanchard <hollisb@us.ibm.com>
   10.16 + *
   10.17 + */
   10.18 +#include <stdio.h>
   10.19 +#include <stdlib.h>
   10.20 +#include <string.h>
   10.21 +#include <inttypes.h>
   10.22 +
   10.23 +#include <xen/xen.h>
   10.24 +
   10.25 +#include "xg_private.h"
   10.26 +#include "xc_dom.h"
   10.27 +#include "powerpc64/flatdevtree.h"
   10.28 +#include "powerpc64/mk_flatdevtree.h"
   10.29 +
   10.30 +#define RMA_LOG 26 /* 64 MB */
   10.31 +#define EXTENT_LOG 24 /* 16 MB */
   10.32 +#define EXTENT_ORDER (EXTENT_LOG - PAGE_SHIFT)
   10.33 +
   10.34 +/* ------------------------------------------------------------------------ */
   10.35 +
   10.36 +static int alloc_magic_pages(struct xc_dom_image *dom)
   10.37 +{
   10.38 +    struct ft_cxt devtree;
   10.39 +    void *guest_devtree;
   10.40 +    unsigned long shadow_mb;
   10.41 +    int rma_pages;
   10.42 +    int rc;
   10.43 +
   10.44 +    /* Allocate special pages from the end of the RMA. */
   10.45 +    rma_pages = 1 << (dom->realmodearea_log - PAGE_SHIFT);
   10.46 +    dom->shared_info_pfn = --rma_pages;
   10.47 +    dom->console_pfn = --rma_pages;
   10.48 +    dom->xenstore_pfn = --rma_pages;
   10.49 +
   10.50 +    /* Gather shadow allocation info for the device tree. */
   10.51 +    rc = xc_shadow_control(dom->guest_xc, dom->guest_domid,
   10.52 +                           XEN_DOMCTL_SHADOW_OP_GET_ALLOCATION, NULL, 0, 
   10.53 +                           &shadow_mb, 0, NULL);
   10.54 +    if (rc < 0 || shadow_mb == 0) {
   10.55 +        xc_dom_printf("Couldn't get shadow allocation size or it was 0.\n");
   10.56 +        return rc;
   10.57 +    }
   10.58 +
   10.59 +    /* Build device tree. */
   10.60 +    rc = make_devtree(&devtree, dom, shadow_mb);
   10.61 +    if (rc < 0) {
   10.62 +        xc_dom_printf("Failed to create flattened device tree.\n");
   10.63 +        return rc;
   10.64 +    }
   10.65 +
   10.66 +    /* Find a spot for it. */
   10.67 +    rc = xc_dom_alloc_segment(dom, &dom->devicetree_seg, "devtree", 0,
   10.68 +                              devtree.bph->totalsize);
   10.69 +    if (rc)
   10.70 +        goto out;
   10.71 +
   10.72 +    /* Copy the device tree into place. */
   10.73 +    guest_devtree = xc_dom_seg_to_ptr(dom, &dom->devicetree_seg);
   10.74 +    if (!guest_devtree) {
   10.75 +        xc_dom_printf("Couldn't map guest memory for device tree.\n");
   10.76 +        rc = -1;
   10.77 +        goto out;
   10.78 +    }
   10.79 +    memcpy(guest_devtree, devtree.bph, devtree.bph->totalsize);
   10.80 +
   10.81 +out:
   10.82 +    free_devtree(&devtree);
   10.83 +    return rc;
   10.84 +}
   10.85 +
   10.86 +static int shared_info(struct xc_dom_image *dom, void *ptr)
   10.87 +{
   10.88 +    shared_info_t *shared_info = ptr;
   10.89 +
   10.90 +    xc_dom_printf("%s: called\n", __FUNCTION__);
   10.91 +
   10.92 +    memset(shared_info, 0, sizeof(*shared_info));
   10.93 +    return 0;
   10.94 +}
   10.95 +
   10.96 +static int vcpu(struct xc_dom_image *dom, void *ptr)
   10.97 +{
   10.98 +    vcpu_guest_context_t *ctxt = ptr;
   10.99 +
  10.100 +    memset(ctxt, 0x55, sizeof(*ctxt));
  10.101 +    ctxt->user_regs.pc = dom->parms.virt_entry;
  10.102 +    ctxt->user_regs.msr = 0;
  10.103 +    ctxt->user_regs.gprs[1] = 0; /* Linux uses its own stack */
  10.104 +    ctxt->user_regs.gprs[3] = dom->devicetree_seg.pfn << PAGE_SHIFT;
  10.105 +    ctxt->user_regs.gprs[4] = dom->kernel_seg.pfn << PAGE_SHIFT;
  10.106 +    ctxt->user_regs.gprs[5] = 0;
  10.107 +
  10.108 +    /* There is a buggy kernel that does not zero the "local_paca", so
  10.109 +     * we must make sure this register is 0 */
  10.110 +    ctxt->user_regs.gprs[13] = 0;
  10.111 +
  10.112 +    xc_dom_printf("%s: initial vcpu:\n", __FUNCTION__);
  10.113 +    xc_dom_printf("  pc 0x%016"PRIx64", msr 0x%016"PRIx64"\n"
  10.114 +                  "  r1-5 %016"PRIx64" %016"PRIx64" %016"PRIx64" %016"PRIx64
  10.115 +                  " %016"PRIx64"\n",
  10.116 +                  ctxt->user_regs.pc, ctxt->user_regs.msr,
  10.117 +                  ctxt->user_regs.gprs[1],
  10.118 +                  ctxt->user_regs.gprs[2],
  10.119 +                  ctxt->user_regs.gprs[3],
  10.120 +                  ctxt->user_regs.gprs[4],
  10.121 +                  ctxt->user_regs.gprs[5]);
  10.122 +
  10.123 +    return 0;
  10.124 +}
  10.125 +
  10.126 +/* ------------------------------------------------------------------------ */
  10.127 +
  10.128 +static struct xc_dom_arch xc_dom_arch = {
  10.129 +    .guest_type = "xen-3.0-powerpc64",
  10.130 +    .page_shift = PAGE_SHIFT,
  10.131 +    .alloc_magic_pages = alloc_magic_pages,
  10.132 +    .shared_info = shared_info,
  10.133 +    .vcpu = vcpu,
  10.134 +};
  10.135 +
  10.136 +static void __init register_arch_hooks(void)
  10.137 +{
  10.138 +    xc_dom_register_arch_hooks(&xc_dom_arch);
  10.139 +}
  10.140 +
  10.141 +int arch_setup_meminit(struct xc_dom_image *dom)
  10.142 +{
  10.143 +    xen_pfn_t *extent_list;
  10.144 +    unsigned long total_mem = dom->total_pages << PAGE_SHIFT;
  10.145 +    unsigned long rma_bytes;
  10.146 +    unsigned long rma_nr_pages;
  10.147 +    unsigned long nr_extents;
  10.148 +    int rc = 0;
  10.149 +    int i;
  10.150 +
  10.151 +    /* XXX RMA size is processor-dependent. */
  10.152 +    dom->realmodearea_log = RMA_LOG;
  10.153 +    rma_bytes = 1 << dom->realmodearea_log;
  10.154 +    rma_nr_pages = rma_bytes >> PAGE_SHIFT;
  10.155 +
  10.156 +    xc_dom_printf("dom%u memory: %lu MB RMA, %lu MB additional.\n",
  10.157 +            dom->guest_domid, rma_bytes >> 20, (total_mem - rma_bytes) >> 20);
  10.158 +
  10.159 +    if (total_mem < rma_bytes) {
  10.160 +        xc_dom_printf("Domain must have at least %lu MB\n", rma_bytes >> 20);
  10.161 +        return -EINVAL;
  10.162 +    }
  10.163 +
  10.164 +    /* Allocate the first chunk of memory. */
  10.165 +    rc = xc_alloc_real_mode_area(dom->guest_xc, dom->guest_domid,
  10.166 +                                 dom->realmodearea_log);
  10.167 +    if (rc) {
  10.168 +        xc_dom_printf("Failed to allocate real mode area.\n");
  10.169 +        return rc;
  10.170 +    }
  10.171 +
  10.172 +    /* Allocate p2m map. */
  10.173 +    dom->p2m_host = xc_dom_malloc(dom, sizeof(xen_pfn_t) * dom->total_pages);
  10.174 +    if (dom->p2m_host == NULL) {
  10.175 +        xc_dom_printf("Couldn't allocate p2m map.\n");
  10.176 +        return -ENOMEM;
  10.177 +    }
  10.178 +
  10.179 +    nr_extents = (dom->total_pages - rma_nr_pages) >> EXTENT_ORDER;
  10.180 +    if (nr_extents) {
  10.181 +        /* Allocate extent list for populate_physmap() call. */
  10.182 +        extent_list = xc_dom_malloc(dom, sizeof(xen_pfn_t) * nr_extents);
  10.183 +        if (extent_list == NULL) {
  10.184 +            xc_dom_printf("Couldn't allocate extent list.\n");
  10.185 +            return -ENOMEM;
  10.186 +        }
  10.187 +
  10.188 +        /* Allocate the remaining (non-RMA) memory. */
  10.189 +        for (i = 0; i < nr_extents; i++) {
  10.190 +            /* Use PFNs above the RMA memory we already allocated. */
  10.191 +            extent_list[i] = rma_nr_pages + i * (1<<EXTENT_ORDER);
  10.192 +        }
  10.193 +        rc = xc_domain_memory_populate_physmap(dom->guest_xc, dom->guest_domid,
  10.194 +                                               nr_extents, EXTENT_ORDER, 0,
  10.195 +                                               extent_list);
  10.196 +        if (rc < 0) {
  10.197 +            xc_dom_printf("populate_physmap(0x%lx extents order %u) -> 0x%x\n",
  10.198 +                          nr_extents, EXTENT_ORDER, rc);
  10.199 +            return rc;
  10.200 +        }
  10.201 +    }
  10.202 +
  10.203 +    /* Populate the p2m map. */
  10.204 +    rc = xc_get_pfn_list(dom->guest_xc, dom->guest_domid, dom->p2m_host,
  10.205 +                         dom->total_pages);
  10.206 +    if (rc < 0) {
  10.207 +        xc_dom_printf("Couldn't get p2m translation.\n");
  10.208 +        return rc;
  10.209 +    }
  10.210 +
  10.211 +    xc_dom_printf("%s: success\n", __func__);
  10.212 +
  10.213 +    return 0;
  10.214 +}
  10.215 +
  10.216 +int arch_setup_bootearly(struct xc_dom_image *dom)
  10.217 +{
  10.218 +    xc_dom_printf("%s: doing nothing\n", __FUNCTION__);
  10.219 +    return 0;
  10.220 +}
  10.221 +
  10.222 +int arch_setup_bootlate(struct xc_dom_image *dom)
  10.223 +{
  10.224 +    unsigned int page_size = XC_DOM_PAGE_SIZE(dom);
  10.225 +    shared_info_t *shared_info;
  10.226 +
  10.227 +    /* setup shared_info page */
  10.228 +    xc_dom_printf("%s: shared_info: mfn 0x%" PRIpfn "\n",
  10.229 +                  __FUNCTION__, dom->shared_info_mfn);
  10.230 +    shared_info = xc_map_foreign_range(dom->guest_xc, dom->guest_domid,
  10.231 +                                       page_size,
  10.232 +                                       PROT_READ | PROT_WRITE,
  10.233 +                                       dom->shared_info_mfn);
  10.234 +    if ( shared_info == NULL )
  10.235 +        return -1;
  10.236 +    dom->arch_hooks->shared_info(dom, shared_info);
  10.237 +    munmap(shared_info, page_size);
  10.238 +    return 0;
  10.239 +}