ia64/xen-unstable

changeset 14513:be1017157768

merge with xen-unstable.hg
author awilliam@xenbuild2.aw
date Thu Mar 22 09:30:54 2007 -0600 (2007-03-22)
parents 93e11f6d6791 6519867be0fe
children fa77ec03afd6 2cecfa20ffa9
files tools/libxc/powerpc64/utils.c tools/libxc/powerpc64/utils.h tools/libxc/powerpc64/xc_linux_build.c tools/libxc/powerpc64/xc_prose_build.c
line diff
     1.1 --- a/linux-2.6-xen-sparse/arch/x86_64/kernel/head64-xen.c	Thu Mar 22 09:28:05 2007 -0600
     1.2 +++ b/linux-2.6-xen-sparse/arch/x86_64/kernel/head64-xen.c	Thu Mar 22 09:30:54 2007 -0600
     1.3 @@ -105,13 +105,11 @@ void __init x86_64_start_kernel(char * r
     1.4  	int i;
     1.5  
     1.6  	xen_start_info = (struct start_info *)real_mode_data;
     1.7 -	if (!xen_feature(XENFEAT_auto_translated_physmap)) {
     1.8 +	if (!xen_feature(XENFEAT_auto_translated_physmap))
     1.9  		phys_to_machine_mapping =
    1.10  			(unsigned long *)xen_start_info->mfn_list;
    1.11 -		start_pfn = (__pa(xen_start_info->pt_base) >> PAGE_SHIFT) +
    1.12 -			xen_start_info->nr_pt_frames;
    1.13 -	}
    1.14 -
    1.15 +	start_pfn = (__pa(xen_start_info->pt_base) >> PAGE_SHIFT) +
    1.16 +		xen_start_info->nr_pt_frames;
    1.17  
    1.18  	machine_to_phys_mapping = (unsigned long *)MACH2PHYS_VIRT_START;
    1.19  	machine_to_phys_nr_ents = MACH2PHYS_NR_ENTRIES;
     2.1 --- a/tools/libxc/Makefile	Thu Mar 22 09:28:05 2007 -0600
     2.2 +++ b/tools/libxc/Makefile	Thu Mar 22 09:30:54 2007 -0600
     2.3 @@ -8,6 +8,7 @@ CTRL_SRCS-y       :=
     2.4  CTRL_SRCS-y       += xc_core.c
     2.5  CTRL_SRCS-$(CONFIG_X86) += xc_core_x86.c
     2.6  CTRL_SRCS-$(CONFIG_IA64) += xc_core_ia64.c
     2.7 +CTRL_SRCS-$(CONFIG_POWERPC) += xc_core_powerpc.c
     2.8  CTRL_SRCS-y       += xc_domain.c
     2.9  CTRL_SRCS-y       += xc_evtchn.c
    2.10  CTRL_SRCS-y       += xc_misc.c
    2.11 @@ -47,11 +48,11 @@ GUEST_SRCS-y += $(LIBELF_SRCS)
    2.12  GUEST_SRCS-y += xc_dom_core.c xc_dom_boot.c
    2.13  GUEST_SRCS-y += xc_dom_elfloader.c
    2.14  GUEST_SRCS-y += xc_dom_binloader.c
    2.15 -GUEST_SRCS-y += xc_dom_x86.c
    2.16 -GUEST_SRCS-y += xc_dom_ia64.c
    2.17 +GUEST_SRCS-y += xc_dom_compat_linux.c
    2.18  
    2.19 -GUEST_SRCS-$(CONFIG_X86)     += xc_dom_compat_linux.c
    2.20 -GUEST_SRCS-$(CONFIG_IA64)    += xc_dom_compat_linux.c
    2.21 +GUEST_SRCS-$(CONFIG_X86)     += xc_dom_x86.c
    2.22 +GUEST_SRCS-$(CONFIG_IA64)    += xc_dom_ia64.c
    2.23 +GUEST_SRCS-$(CONFIG_POWERPC) += xc_dom_powerpc.c
    2.24  
    2.25  -include $(XEN_TARGET_ARCH)/Makefile
    2.26  
     3.1 --- a/tools/libxc/powerpc64/Makefile	Thu Mar 22 09:28:05 2007 -0600
     3.2 +++ b/tools/libxc/powerpc64/Makefile	Thu Mar 22 09:30:54 2007 -0600
     3.3 @@ -1,7 +1,4 @@
     3.4  GUEST_SRCS-y += powerpc64/flatdevtree.c
     3.5  GUEST_SRCS-y += powerpc64/mk_flatdevtree.c
     3.6 -GUEST_SRCS-y += powerpc64/xc_linux_build.c
     3.7 -GUEST_SRCS-y += powerpc64/xc_prose_build.c
     3.8 -GUEST_SRCS-y += powerpc64/utils.c
     3.9  
    3.10  CTRL_SRCS-y += powerpc64/xc_memory.c
     4.1 --- a/tools/libxc/powerpc64/mk_flatdevtree.c	Thu Mar 22 09:28:05 2007 -0600
     4.2 +++ b/tools/libxc/powerpc64/mk_flatdevtree.c	Thu Mar 22 09:30:54 2007 -0600
     4.3 @@ -34,6 +34,7 @@
     4.4  #include <sys/param.h>
     4.5  
     4.6  #include <xc_private.h> /* for PERROR() */
     4.7 +#include <xc_dom.h>
     4.8  
     4.9  #include "mk_flatdevtree.h"
    4.10  
    4.11 @@ -310,24 +311,19 @@ void free_devtree(struct ft_cxt *root)
    4.12  }
    4.13  
    4.14  int make_devtree(struct ft_cxt *root,
    4.15 -                 uint32_t domid, 
    4.16 -                 uint32_t mem_mb,
    4.17 -                 unsigned long rma_bytes,
    4.18 -                 unsigned long shadow_mb,
    4.19 -                 unsigned long initrd_base,
    4.20 -                 unsigned long initrd_len,
    4.21 -                 const char *bootargs,
    4.22 -                 uint64_t shared_info_paddr,
    4.23 -                 unsigned long console_evtchn,
    4.24 -                 uint64_t console_paddr,
    4.25 -                 unsigned long store_evtchn,
    4.26 -                 uint64_t store_paddr)
    4.27 +                 struct xc_dom_image *dom,
    4.28 +                 unsigned long shadow_mb)
    4.29  {
    4.30      struct boot_param_header *bph = NULL;
    4.31      uint64_t val[2];
    4.32      uint32_t val32[2];
    4.33 -    unsigned long remaining;
    4.34 -    unsigned long initrd_end = initrd_base + initrd_len;
    4.35 +    uint64_t shared_info_paddr = dom->shared_info_pfn << PAGE_SHIFT;
    4.36 +    uint64_t xenstore_paddr = dom->xenstore_pfn << PAGE_SHIFT;
    4.37 +    uint64_t console_paddr = dom->console_pfn << PAGE_SHIFT;
    4.38 +    long remaining;
    4.39 +    unsigned long ramdisk_start;
    4.40 +    unsigned long ramdisk_size;
    4.41 +    unsigned long rma_bytes = 1 << dom->realmodearea_log;
    4.42      int64_t shadow_mb_log;
    4.43      uint64_t pft_size;
    4.44      char cpupath[MAX_PATH];
    4.45 @@ -370,16 +366,18 @@ int make_devtree(struct ft_cxt *root,
    4.46      }
    4.47  
    4.48      /* reserve xen store page for domU */
    4.49 -    if (store_paddr) {
    4.50 -        val[0] = cpu_to_be64((u64) store_paddr);
    4.51 +    if (xenstore_paddr) {
    4.52 +        val[0] = cpu_to_be64((u64) xenstore_paddr);
    4.53          val[1] = cpu_to_be64((u64) PAGE_SIZE);
    4.54          ft_add_rsvmap(root, val[0], val[1]);
    4.55      }
    4.56  
    4.57      /* reserve space for initrd if needed */
    4.58 -    if ( initrd_len > 0 )  {
    4.59 -        val[0] = cpu_to_be64((u64) initrd_base);
    4.60 -        val[1] = cpu_to_be64((u64) initrd_len);
    4.61 +    ramdisk_start = dom->ramdisk_seg.pfn << PAGE_SHIFT;
    4.62 +    ramdisk_size = dom->ramdisk_seg.vend - dom->ramdisk_seg.vstart;
    4.63 +    if (ramdisk_size > 0) {
    4.64 +        val[0] = cpu_to_be64((u64) ramdisk_start);
    4.65 +        val[1] = cpu_to_be64((u64) ramdisk_size);
    4.66          ft_add_rsvmap(root, val[0], val[1]);
    4.67      }
    4.68  
    4.69 @@ -422,13 +420,13 @@ int make_devtree(struct ft_cxt *root,
    4.70      ft_prop_int(root, "interrupt-controller", xen_phandle);
    4.71  
    4.72      /* chosen.addprop('bootargs', imghandler.cmdline + '\0') */
    4.73 -    if ( bootargs != NULL )
    4.74 -        ft_prop_str(root, "bootargs", bootargs);
    4.75 +    if (dom->cmdline != NULL)
    4.76 +        ft_prop_str(root, "bootargs", dom->cmdline);
    4.77  
    4.78      /* mark where the initrd is, if present */
    4.79 -    if ( initrd_len > 0 ) {
    4.80 -        val[0] = cpu_to_be64((u64) initrd_base);
    4.81 -        val[1] = cpu_to_be64((u64) initrd_end);
    4.82 +    if (ramdisk_size > 0) {
    4.83 +        val[0] = cpu_to_be64((u64) ramdisk_start);
    4.84 +        val[1] = cpu_to_be64((u64) ramdisk_start + ramdisk_size);
    4.85          ft_prop(root, "linux,initrd-start", &(val[0]), sizeof(val[0]));
    4.86          ft_prop(root, "linux,initrd-end", &(val[1]), sizeof(val[1]));
    4.87      }
    4.88 @@ -443,7 +441,7 @@ int make_devtree(struct ft_cxt *root,
    4.89      ft_prop_str(root, "compatible", "Xen-3.0-unstable");
    4.90  
    4.91      /* xen.addprop('reg', long(imghandler.vm.domid), long(0)) */
    4.92 -    val[0] = cpu_to_be64((u64) domid);
    4.93 +    val[0] = cpu_to_be64((u64) dom->guest_domid);
    4.94      val[1] = cpu_to_be64((u64) 0);
    4.95      ft_prop(root, "reg", val, sizeof(val));
    4.96  
    4.97 @@ -469,7 +467,7 @@ int make_devtree(struct ft_cxt *root,
    4.98          ft_prop(root, "reg", val, sizeof(val));
    4.99  
   4.100          /* xencons.addprop('interrupts', console_evtchn, 0) */
   4.101 -        val32[0] = cpu_to_be32((u32) console_evtchn);
   4.102 +        val32[0] = cpu_to_be32((u32) dom->console_evtchn);
   4.103          val32[1] = cpu_to_be32((u32) 0);
   4.104          ft_prop(root, "interrupts", val32, sizeof(val32));
   4.105  
   4.106 @@ -477,17 +475,17 @@ int make_devtree(struct ft_cxt *root,
   4.107          ft_end_node(root);
   4.108      }
   4.109  
   4.110 -    if (store_paddr != 0) {
   4.111 +    if (xenstore_paddr != 0) {
   4.112          /* start store node */
   4.113          ft_begin_node(root, "store");
   4.114  
   4.115          /* store paddr */
   4.116 -        val[0] = cpu_to_be64((u64) store_paddr);
   4.117 +        val[0] = cpu_to_be64((u64) xenstore_paddr);
   4.118          val[1] = cpu_to_be64((u64) PAGE_SIZE);
   4.119          ft_prop(root, "reg", val, sizeof(val));
   4.120  
   4.121          /* store event channel */
   4.122 -        val32[0] = cpu_to_be32((u32) store_evtchn);
   4.123 +        val32[0] = cpu_to_be32((u32) dom->xenstore_evtchn);
   4.124          val32[1] = cpu_to_be32((u32) 0);
   4.125          ft_prop(root, "interrupts", val32, sizeof(val32));
   4.126  
   4.127 @@ -516,7 +514,7 @@ int make_devtree(struct ft_cxt *root,
   4.128      ft_end_node(root);
   4.129  
   4.130      /* calculate remaining bytes from total - rma size */
   4.131 -    remaining = (mem_mb * 1024 * 1024) - rma_bytes;
   4.132 +    remaining = (dom->total_pages << PAGE_SHIFT) - rma_bytes;
   4.133  
   4.134      /* memory@<rma_bytes> is all remaining memory after RMA */
   4.135      if (remaining > 0)
     5.1 --- a/tools/libxc/powerpc64/mk_flatdevtree.h	Thu Mar 22 09:28:05 2007 -0600
     5.2 +++ b/tools/libxc/powerpc64/mk_flatdevtree.h	Thu Mar 22 09:30:54 2007 -0600
     5.3 @@ -26,18 +26,8 @@
     5.4  
     5.5  extern void free_devtree(struct ft_cxt *root);
     5.6  extern int make_devtree(struct ft_cxt *root,
     5.7 -                        uint32_t domid, 
     5.8 -                        uint32_t mem_mb,
     5.9 -                        unsigned long rma_bytes,
    5.10 -                        unsigned long shadow_mb,
    5.11 -                        unsigned long initrd_base,
    5.12 -                        unsigned long initrd_len,
    5.13 -                        const char *bootargs,
    5.14 -                        uint64_t shared_info_paddr,
    5.15 -                        unsigned long console_evtchn,
    5.16 -                        uint64_t console_paddr,
    5.17 -                        unsigned long store_evtchn,
    5.18 -                        uint64_t store_paddr);
    5.19 +                        struct xc_dom_image *dom,
    5.20 +                        unsigned long shadow_mb);
    5.21  
    5.22  #define MAX_PATH 200
    5.23  #define BUFSIZE 1024
     6.1 --- a/tools/libxc/powerpc64/utils.c	Thu Mar 22 09:28:05 2007 -0600
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,188 +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 -#include <stdio.h>
    6.25 -#include <stdint.h>
    6.26 -#include <stdlib.h>
    6.27 -#include <string.h>
    6.28 -#include <unistd.h>
    6.29 -#include <fcntl.h>
    6.30 -#include <sys/types.h>
    6.31 -#include <inttypes.h>
    6.32 -
    6.33 -#include <xen/xen.h>
    6.34 -#include <xen/memory.h>
    6.35 -#include <xc_private.h>
    6.36 -#include <xg_private.h>
    6.37 -#include <xenctrl.h>
    6.38 -
    6.39 -#include "flatdevtree_env.h"
    6.40 -#include "flatdevtree.h"
    6.41 -#include "utils.h"
    6.42 -
    6.43 -int get_rma_page_array(int xc_handle, int domid, xen_pfn_t **page_array,
    6.44 -		       unsigned long nr_pages)
    6.45 -{
    6.46 -    int rc;
    6.47 -    int i;
    6.48 -    xen_pfn_t *p;
    6.49 -
    6.50 -    *page_array = malloc(nr_pages * sizeof(xen_pfn_t));
    6.51 -    if (*page_array == NULL) {
    6.52 -        perror("malloc");
    6.53 -        return -1;
    6.54 -    }
    6.55 -
    6.56 -    DPRINTF("xc_get_pfn_list\n");
    6.57 -    /* We know that the RMA is machine contiguous so lets just get the
    6.58 -     * first MFN and fill the rest in ourselves */
    6.59 -    rc = xc_get_pfn_list(xc_handle, domid, (uint64_t *)*page_array, 1);
    6.60 -    if (rc == -1) {
    6.61 -        perror("Could not get the page frame list");
    6.62 -        return -1;
    6.63 -    }
    6.64 -    p = *page_array;
    6.65 -    for (i = 1; i < nr_pages; i++)
    6.66 -        p[i] = p[i - 1] + 1;
    6.67 -    return 0;
    6.68 -}
    6.69 -
    6.70 -int install_image(
    6.71 -        int xc_handle,
    6.72 -        int domid,
    6.73 -        xen_pfn_t *page_array,
    6.74 -        void *image,
    6.75 -        unsigned long paddr,
    6.76 -        unsigned long size)
    6.77 -{
    6.78 -    uint8_t *img = image;
    6.79 -    int i;
    6.80 -    int rc = 0;
    6.81 -
    6.82 -    if (paddr & ~PAGE_MASK) {
    6.83 -        printf("*** unaligned address\n");
    6.84 -        return -1;
    6.85 -    }
    6.86 -
    6.87 -    for (i = 0; i < size; i += PAGE_SIZE) {
    6.88 -        void *page = img + i;
    6.89 -        xen_pfn_t pfn = (paddr + i) >> PAGE_SHIFT;
    6.90 -        xen_pfn_t mfn = page_array[pfn];
    6.91 -
    6.92 -        rc = xc_copy_to_domain_page(xc_handle, domid, mfn, page);
    6.93 -        if (rc < 0) {
    6.94 -            perror("xc_copy_to_domain_page");
    6.95 -            break;
    6.96 -        }
    6.97 -    }
    6.98 -    return rc;
    6.99 -}
   6.100 -
   6.101 -void *load_file(const char *path, unsigned long *filesize)
   6.102 -{
   6.103 -    void *img;
   6.104 -    ssize_t size;
   6.105 -    int fd;
   6.106 -
   6.107 -    DPRINTF("load_file(%s)\n", path);
   6.108 -
   6.109 -    fd = open(path, O_RDONLY);
   6.110 -    if (fd < 0) {
   6.111 -        perror(path);
   6.112 -        return NULL;
   6.113 -    }
   6.114 -
   6.115 -    size = lseek(fd, 0, SEEK_END);
   6.116 -    if (size < 0) {
   6.117 -        perror(path);
   6.118 -        close(fd);
   6.119 -        return NULL;
   6.120 -    }
   6.121 -    lseek(fd, 0, SEEK_SET);
   6.122 -
   6.123 -    img = malloc(size);
   6.124 -    if (img == NULL) {
   6.125 -        perror(path);
   6.126 -        close(fd);
   6.127 -        return NULL;
   6.128 -    }
   6.129 -
   6.130 -    size = read(fd, img, size);
   6.131 -    if (size <= 0) {
   6.132 -        perror(path);
   6.133 -        close(fd);
   6.134 -        free(img);
   6.135 -        return NULL;
   6.136 -    }
   6.137 -
   6.138 -    if (filesize)
   6.139 -        *filesize = size;
   6.140 -    close(fd);
   6.141 -    return img;
   6.142 -}
   6.143 -
   6.144 -int load_elf_kernel(
   6.145 -    int xc_handle,
   6.146 -    int domid,
   6.147 -    const char *kernel_path,
   6.148 -    struct domain_setup_info *dsi,
   6.149 -    xen_pfn_t *page_array)
   6.150 -{
   6.151 -    struct load_funcs load_funcs;
   6.152 -    char *kernel_img;
   6.153 -    unsigned long kernel_size;
   6.154 -    int rc;
   6.155 -
   6.156 -    /* load the kernel ELF file */
   6.157 -    kernel_img = load_file(kernel_path, &kernel_size);
   6.158 -    if (kernel_img == NULL) {
   6.159 -        rc = -1;
   6.160 -        goto out;
   6.161 -    }
   6.162 -
   6.163 -    DPRINTF("probe_elf\n");
   6.164 -    rc = probe_elf(kernel_img, kernel_size, &load_funcs);
   6.165 -    if (rc < 0) {
   6.166 -        rc = -1;
   6.167 -        printf("%s is not an ELF file\n", kernel_path);
   6.168 -        goto out;
   6.169 -    }
   6.170 -
   6.171 -    DPRINTF("parseimage\n");
   6.172 -    rc = (load_funcs.parseimage)(kernel_img, kernel_size, dsi);
   6.173 -    if (rc < 0) {
   6.174 -        rc = -1;
   6.175 -        goto out;
   6.176 -    }
   6.177 -
   6.178 -    DPRINTF("loadimage\n");
   6.179 -    (load_funcs.loadimage)(kernel_img, kernel_size, xc_handle, domid,
   6.180 -            page_array, dsi);
   6.181 -
   6.182 -    DPRINTF("  v_start     %016"PRIx64"\n", dsi->v_start);
   6.183 -    DPRINTF("  v_end       %016"PRIx64"\n", dsi->v_end);
   6.184 -    DPRINTF("  v_kernstart %016"PRIx64"\n", dsi->v_kernstart);
   6.185 -    DPRINTF("  v_kernend   %016"PRIx64"\n", dsi->v_kernend);
   6.186 -    DPRINTF("  v_kernentry %016"PRIx64"\n", dsi->v_kernentry);
   6.187 -
   6.188 -out:
   6.189 -    free(kernel_img);
   6.190 -    return rc;
   6.191 -}
     7.1 --- a/tools/libxc/powerpc64/utils.h	Thu Mar 22 09:28:05 2007 -0600
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,37 +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 - *          Jimi Xenidis <jimix@watson.ibm.com>
    7.23 - */
    7.24 -
    7.25 -extern int get_rma_page_array(int xc_handle, int domid, xen_pfn_t **page_array,
    7.26 -			      unsigned long nr_pages);
    7.27 -extern int install_image(int xc_handle, int domid, xen_pfn_t *page_array,
    7.28 -			 void *image, unsigned long paddr, unsigned long size);
    7.29 -extern void *load_file(const char *path, unsigned long *filesize);
    7.30 -extern int load_elf_kernel(int xc_handle, int domid,  const char *kernel_path,
    7.31 -			   struct domain_setup_info *dsi,
    7.32 -			   xen_pfn_t *page_array);
    7.33 -
    7.34 -#define ALIGN_UP(addr,size) (((addr)+((size)-1))&(~((size)-1)))
    7.35 -
    7.36 -#define max(x,y) ({ \
    7.37 -        const typeof(x) _x = (x);       \
    7.38 -        const typeof(y) _y = (y);       \
    7.39 -        (void) (&_x == &_y);            \
    7.40 -        _x > _y ? _x : _y; })
     8.1 --- a/tools/libxc/powerpc64/xc_linux_build.c	Thu Mar 22 09:28:05 2007 -0600
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,336 +0,0 @@
     8.4 -/*
     8.5 - * This program is free software; you can redistribute it and/or modify
     8.6 - * it under the terms of the GNU General Public License as published by
     8.7 - * the Free Software Foundation; either version 2 of the License, or
     8.8 - * (at your option) any later version.
     8.9 - *
    8.10 - * This program is distributed in the hope that it will be useful,
    8.11 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.12 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    8.13 - * GNU General Public License for more details.
    8.14 - *
    8.15 - * You should have received a copy of the GNU General Public License
    8.16 - * along with this program; if not, write to the Free Software
    8.17 - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    8.18 - *
    8.19 - * Copyright IBM Corporation 2006, 2007
    8.20 - *
    8.21 - * Authors: Hollis Blanchard <hollisb@us.ibm.com>
    8.22 - *          Ryan Harper <ryanh@us.ibm.com>
    8.23 - */
    8.24 -
    8.25 -#include <stdio.h>
    8.26 -#include <stdint.h>
    8.27 -#include <stdlib.h>
    8.28 -#include <string.h>
    8.29 -#include <unistd.h>
    8.30 -#include <fcntl.h>
    8.31 -#include <sys/types.h>
    8.32 -#include <inttypes.h>
    8.33 -
    8.34 -#include <xen/xen.h>
    8.35 -#include <xen/memory.h>
    8.36 -#include <xc_private.h>
    8.37 -#include <xg_private.h>
    8.38 -#include <xenctrl.h>
    8.39 -
    8.40 -#include "flatdevtree_env.h"
    8.41 -#include "flatdevtree.h"
    8.42 -#include "utils.h"
    8.43 -#include "mk_flatdevtree.h"
    8.44 -
    8.45 -/* Use 16MB extents to match PowerPC's large page size. */
    8.46 -#define EXTENT_SHIFT 24
    8.47 -#define EXTENT_ORDER (EXTENT_SHIFT - PAGE_SHIFT)
    8.48 -
    8.49 -#define INITRD_ADDR (24UL << 20)
    8.50 -#define DEVTREE_ADDR (16UL << 20)
    8.51 -
    8.52 -static int init_boot_vcpu(
    8.53 -    int xc_handle,
    8.54 -    int domid,
    8.55 -    struct domain_setup_info *dsi,
    8.56 -    unsigned long devtree_addr,
    8.57 -    unsigned long kern_addr)
    8.58 -{
    8.59 -    vcpu_guest_context_t ctxt;
    8.60 -    int rc;
    8.61 -
    8.62 -    memset(&ctxt.user_regs, 0x55, sizeof(ctxt.user_regs));
    8.63 -    ctxt.user_regs.pc = dsi->v_kernentry;
    8.64 -    ctxt.user_regs.msr = 0;
    8.65 -    ctxt.user_regs.gprs[1] = 0; /* Linux uses its own stack */
    8.66 -    ctxt.user_regs.gprs[3] = devtree_addr;
    8.67 -    ctxt.user_regs.gprs[4] = kern_addr;
    8.68 -    ctxt.user_regs.gprs[5] = 0;
    8.69 -    /* There is a buggy kernel that does not zero the "local_paca", so
    8.70 -     * we must make sure this register is 0 */
    8.71 -    ctxt.user_regs.gprs[13] = 0;
    8.72 -
    8.73 -    DPRINTF("xc_vcpu_setvcpucontext:\n"
    8.74 -                 "  pc 0x%016"PRIx64", msr 0x%016"PRIx64"\n"
    8.75 -                 "  r1-5 %016"PRIx64" %016"PRIx64" %016"PRIx64" %016"PRIx64
    8.76 -                 " %016"PRIx64"\n",
    8.77 -                 ctxt.user_regs.pc, ctxt.user_regs.msr,
    8.78 -                 ctxt.user_regs.gprs[1],
    8.79 -                 ctxt.user_regs.gprs[2],
    8.80 -                 ctxt.user_regs.gprs[3],
    8.81 -                 ctxt.user_regs.gprs[4],
    8.82 -                 ctxt.user_regs.gprs[5]);
    8.83 -    rc = xc_vcpu_setcontext(xc_handle, domid, 0, &ctxt);
    8.84 -    if (rc < 0)
    8.85 -        perror("setdomaininfo");
    8.86 -
    8.87 -    return rc;
    8.88 -}
    8.89 -
    8.90 -static int load_initrd(
    8.91 -    int xc_handle,
    8.92 -    int domid,
    8.93 -    xen_pfn_t *page_array,
    8.94 -    const char *initrd_path,
    8.95 -    unsigned long *base,
    8.96 -    unsigned long *len)
    8.97 -{
    8.98 -    uint8_t *initrd_img;
    8.99 -    int rc = -1;
   8.100 -
   8.101 -    /* load the initrd file */
   8.102 -    initrd_img = load_file(initrd_path, len);
   8.103 -    if (initrd_img == NULL)
   8.104 -        return -1;
   8.105 -
   8.106 -    DPRINTF("copying initrd to 0x%lx[0x%lx]\n", INITRD_ADDR, *len);
   8.107 -    if (install_image(xc_handle, domid, page_array, initrd_img, INITRD_ADDR,
   8.108 -                *len))
   8.109 -        goto out;
   8.110 -
   8.111 -    *base = INITRD_ADDR;
   8.112 -    rc = 0;
   8.113 -
   8.114 -out:
   8.115 -    free(initrd_img);
   8.116 -    return rc;
   8.117 -}
   8.118 -
   8.119 -static void free_page_array(xen_pfn_t *page_array)
   8.120 -{
   8.121 -    free(page_array);
   8.122 -}
   8.123 -
   8.124 -static int check_memory_config(int rma_log, unsigned int mem_mb)
   8.125 -{
   8.126 -    u64 mem_kb = (mem_mb << 10);
   8.127 -    u64 rma_kb = (1 << rma_log) >> 10;
   8.128 -
   8.129 -    switch(rma_log)
   8.130 -    {
   8.131 -        case 26:
   8.132 -        case 27:
   8.133 -        case 28:
   8.134 -        case 30:
   8.135 -        case 34:
   8.136 -        case 38:
   8.137 -            if (mem_kb < rma_kb) {
   8.138 -                DPRINTF("Domain memory must be at least %dMB\n", 
   8.139 -                        (1 << rma_log)>>20);
   8.140 -                break;
   8.141 -            }
   8.142 -
   8.143 -            if (mem_kb % (16 << 10)) {
   8.144 -                DPRINTF("Domain memory %dMB must be a multiple of 16MB\n",
   8.145 -                        mem_mb);
   8.146 -                       
   8.147 -                break;
   8.148 -            }
   8.149 -
   8.150 -            /* rma_log and mem_mb OK */
   8.151 -            return 0;
   8.152 -
   8.153 -        default:
   8.154 -            DPRINTF("Invalid rma_log (%d)\n", rma_log);
   8.155 -    }
   8.156 -
   8.157 -    return 1;
   8.158 -}
   8.159 -
   8.160 -static int alloc_memory(int xc_handle, domid_t domid, ulong nr_pages,
   8.161 -                        ulong rma_pages)
   8.162 -{
   8.163 -    xen_pfn_t *extent_pfn_arry;
   8.164 -    ulong nr_extents;
   8.165 -    ulong start_pfn = rma_pages;
   8.166 -    int i;
   8.167 -    int j;
   8.168 -    int rc = 0;
   8.169 -
   8.170 -    nr_extents = (nr_pages - rma_pages) >> EXTENT_ORDER;
   8.171 -    DPRINTF("allocating memory in %lu chunks of %luMB\n", nr_extents,
   8.172 -            1UL >> (20 - EXTENT_ORDER));
   8.173 -
   8.174 -    /* populate_physmap requires an array of PFNs that determine where the
   8.175 -     * guest mapping of the new MFNs. */
   8.176 -    extent_pfn_arry = malloc((1<<EXTENT_ORDER) * sizeof(xen_pfn_t));
   8.177 -    if (extent_pfn_arry == NULL) {
   8.178 -        PERROR("Couldn't allocate extent PFN array.\n");
   8.179 -        return -ENOMEM;
   8.180 -    }
   8.181 -
   8.182 -    /* Now allocate the remaining memory as large-order extents. */
   8.183 -    for (i = 0; i < nr_extents; i++) {
   8.184 -        /* Initialize the extent PFN array. */
   8.185 -        for (j = 0; j < (1 << EXTENT_ORDER); j++)
   8.186 -            extent_pfn_arry[j] = start_pfn++;
   8.187 -
   8.188 -        DPRINTF("populate_physmap(Dom%u, order %u, starting_pfn %llx)\n",
   8.189 -                domid, EXTENT_ORDER, extent_pfn_arry[0]);
   8.190 -
   8.191 -        if (xc_domain_memory_populate_physmap(xc_handle, domid, 1, EXTENT_ORDER,
   8.192 -                                               0, extent_pfn_arry))
   8.193 -        {
   8.194 -            PERROR("Could not allocate extents\n");
   8.195 -            rc = -1;
   8.196 -            break;
   8.197 -        }
   8.198 -    }
   8.199 -
   8.200 -    free(extent_pfn_arry);
   8.201 -    return rc;
   8.202 -}
   8.203 -
   8.204 -int xc_linux_build(int xc_handle,
   8.205 -                   uint32_t domid,
   8.206 -                   unsigned int mem_mb,
   8.207 -                   const char *image_name,
   8.208 -                   const char *initrd_name,
   8.209 -                   const char *cmdline,
   8.210 -                   const char *features,
   8.211 -                   unsigned long flags,
   8.212 -                   unsigned int store_evtchn,
   8.213 -                   unsigned long *store_mfn,
   8.214 -                   unsigned int console_evtchn,
   8.215 -                   unsigned long *console_mfn)
   8.216 -{
   8.217 -    struct domain_setup_info dsi;
   8.218 -    xen_pfn_t *page_array = NULL;
   8.219 -    unsigned long nr_pages;
   8.220 -    unsigned long devtree_addr = 0;
   8.221 -    unsigned long kern_addr;
   8.222 -    unsigned long initrd_base = 0;
   8.223 -    unsigned long initrd_len = 0;
   8.224 -    unsigned long rma_pages;
   8.225 -    unsigned long shadow_mb;
   8.226 -    u64 shared_info_paddr;
   8.227 -    u64 store_paddr;
   8.228 -    u64 console_paddr;
   8.229 -    int rma_log = 26;  /* 64MB RMA */
   8.230 -    int rc = 0;
   8.231 -    int op;
   8.232 -    struct ft_cxt devtree;
   8.233 -
   8.234 -    DPRINTF("%s\n", __func__);
   8.235 -
   8.236 -    nr_pages = mem_mb << (20 - PAGE_SHIFT);
   8.237 -    DPRINTF("nr_pages 0x%lx\n", nr_pages);
   8.238 -
   8.239 -    rma_pages = (1 << rma_log) >> PAGE_SHIFT;
   8.240 -    if (rma_pages == 0) {
   8.241 -        rc = -1;
   8.242 -        goto out;
   8.243 -    }
   8.244 -
   8.245 -    /* validate rma_log and domain memory config */
   8.246 -    if (check_memory_config(rma_log, mem_mb)) {
   8.247 -        rc = -1;
   8.248 -        goto out;
   8.249 -    }
   8.250 -    
   8.251 -    /* Allocate the RMA. */
   8.252 -    DPRINTF("RMA: 0x%lx pages\n", rma_pages);
   8.253 -    if (xc_alloc_real_mode_area(xc_handle, domid, rma_log)) {
   8.254 -        rc = -1;
   8.255 -        goto out;
   8.256 -    }
   8.257 -
   8.258 -    /* Get the MFN mapping (for RMA only -- we only load data into the RMA). */
   8.259 -    if (get_rma_page_array(xc_handle, domid, &page_array, rma_pages)) {
   8.260 -        rc = -1;
   8.261 -        goto out;
   8.262 -    }
   8.263 -
   8.264 -    /* Allocate the non-RMA memory. */
   8.265 -    rc = alloc_memory(xc_handle, domid, nr_pages, rma_pages);
   8.266 -    if (rc) {
   8.267 -        goto out;
   8.268 -    }
   8.269 -
   8.270 -    /* Load kernel. */
   8.271 -    DPRINTF("loading image '%s'\n", image_name);
   8.272 -    if (load_elf_kernel(xc_handle, domid, image_name, &dsi, page_array)) {
   8.273 -        rc = -1;
   8.274 -        goto out;
   8.275 -    }
   8.276 -    kern_addr = 0;
   8.277 -
   8.278 -    /* Load initrd. */
   8.279 -    if (initrd_name && initrd_name[0] != '\0') {
   8.280 -        DPRINTF("loading initrd '%s'\n", initrd_name);
   8.281 -        if (load_initrd(xc_handle, domid, page_array, initrd_name,
   8.282 -                &initrd_base, &initrd_len)) {
   8.283 -            rc = -1;
   8.284 -            goto out;
   8.285 -        }
   8.286 -    }
   8.287 -
   8.288 -    /* fetch the current shadow_memory value for this domain */
   8.289 -    op = XEN_DOMCTL_SHADOW_OP_GET_ALLOCATION;
   8.290 -    if (xc_shadow_control(xc_handle, domid, op, NULL, 0, 
   8.291 -                          &shadow_mb, 0, NULL) < 0) {
   8.292 -        rc = -1;
   8.293 -        goto out;
   8.294 -    }
   8.295 -
   8.296 -    /* determine shared_info, console, and store paddr */
   8.297 -    shared_info_paddr = (rma_pages << PAGE_SHIFT) - PAGE_SIZE;
   8.298 -    console_paddr = shared_info_paddr - PAGE_SIZE;
   8.299 -    store_paddr = console_paddr - PAGE_SIZE;
   8.300 -
   8.301 -    /* map paddrs to mfns */
   8.302 -    *store_mfn = page_array[(xen_pfn_t)(store_paddr >> PAGE_SHIFT)];
   8.303 -    *console_mfn = page_array[(xen_pfn_t)(console_paddr >> PAGE_SHIFT)];
   8.304 -    DPRINTF("console_mfn->%08lx store_mfn->%08lx\n", *console_mfn,
   8.305 -            *store_mfn);
   8.306 -
   8.307 -    /* build the devtree here */
   8.308 -    DPRINTF("constructing devtree\n");
   8.309 -    if (make_devtree(&devtree, domid, mem_mb, (rma_pages << PAGE_SHIFT),
   8.310 -                     shadow_mb, initrd_base, initrd_len, cmdline, 
   8.311 -                     shared_info_paddr, console_evtchn, console_paddr,
   8.312 -                     store_evtchn, store_paddr) < 0) {
   8.313 -        DPRINTF("failed to create flattened device tree\n");
   8.314 -        rc = -1;
   8.315 -        goto out;
   8.316 -    }
   8.317 -
   8.318 -    devtree_addr = DEVTREE_ADDR;
   8.319 -    DPRINTF("loading flattened device tree to 0x%lx[0x%x]\n",
   8.320 -            devtree_addr, devtree.bph->totalsize);
   8.321 -
   8.322 -    if (install_image(xc_handle, domid, page_array, (void *)devtree.bph,
   8.323 -                      devtree_addr, devtree.bph->totalsize)) {
   8.324 -        DPRINTF("couldn't load flattened device tree.\n");
   8.325 -        rc = -1;
   8.326 -        goto out2;
   8.327 -    }
   8.328 -
   8.329 -    if (init_boot_vcpu(xc_handle, domid, &dsi, devtree_addr, kern_addr)) {
   8.330 -        rc = -1;
   8.331 -        goto out2;
   8.332 -    }
   8.333 -
   8.334 -out2:
   8.335 -    free_devtree(&devtree);
   8.336 -out:
   8.337 -    free_page_array(page_array);
   8.338 -    return rc;
   8.339 -}
     9.1 --- a/tools/libxc/powerpc64/xc_prose_build.c	Thu Mar 22 09:28:05 2007 -0600
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,215 +0,0 @@
     9.4 -/*
     9.5 - * This program is free software; you can redistribute it and/or modify
     9.6 - * it under the terms of the GNU General Public License as published by
     9.7 - * the Free Software Foundation; either version 2 of the License, or
     9.8 - * (at your option) any later version.
     9.9 - *
    9.10 - * This program is distributed in the hope that it will be useful,
    9.11 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    9.12 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    9.13 - * GNU General Public License for more details.
    9.14 - *
    9.15 - * You should have received a copy of the GNU General Public License
    9.16 - * along with this program; if not, write to the Free Software
    9.17 - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    9.18 - *
    9.19 - * Copyright IBM Corporation 2006, 2007
    9.20 - *
    9.21 - * Authors: Hollis Blanchard <hollisb@us.ibm.com>
    9.22 - *          Jonathan Appavoo <jappavoo@us.ibm.com>
    9.23 - */
    9.24 -
    9.25 -#include <stdio.h>
    9.26 -#include <stdint.h>
    9.27 -#include <stdlib.h>
    9.28 -#include <string.h>
    9.29 -#include <unistd.h>
    9.30 -#include <fcntl.h>
    9.31 -#include <sys/types.h>
    9.32 -#include <inttypes.h>
    9.33 -
    9.34 -#include <xen/xen.h>
    9.35 -#include <xen/memory.h>
    9.36 -#include <xc_private.h>
    9.37 -#include <xg_private.h>
    9.38 -#include <xenctrl.h>
    9.39 -
    9.40 -#include "utils.h"
    9.41 -
    9.42 -#define INITRD_ADDR (24UL << 20)
    9.43 -
    9.44 -static int init_boot_vcpu(
    9.45 -    int xc_handle,
    9.46 -    int domid,
    9.47 -    struct domain_setup_info *dsi,
    9.48 -    unsigned long kern_addr)
    9.49 -{
    9.50 -    vcpu_guest_context_t ctxt;
    9.51 -    int rc;
    9.52 -
    9.53 -    memset(&ctxt.user_regs, 0x55, sizeof(ctxt.user_regs));
    9.54 -    ctxt.user_regs.pc = dsi->v_kernentry;
    9.55 -    ctxt.user_regs.msr = 0;
    9.56 -    ctxt.user_regs.gprs[1] = 0; /* Linux uses its own stack */
    9.57 -    ctxt.user_regs.gprs[3] = 0;
    9.58 -    ctxt.user_regs.gprs[4] = kern_addr;
    9.59 -    ctxt.user_regs.gprs[5] = 0; /* reserved for specifying OF handler */
    9.60 -    /* There is a buggy kernel that does not zero the "local_paca", so
    9.61 -     * we must make sure this register is 0 */
    9.62 -    ctxt.user_regs.gprs[13] = 0;
    9.63 -
    9.64 -    DPRINTF("xc_vcpu_setvcpucontext:\n"
    9.65 -                 "  pc 0x%016"PRIx64", msr 0x%016"PRIx64"\n"
    9.66 -                 "  r1-5 %016"PRIx64" %016"PRIx64" %016"PRIx64" %016"PRIx64
    9.67 -                 " %016"PRIx64"\n",
    9.68 -                 ctxt.user_regs.pc, ctxt.user_regs.msr,
    9.69 -                 ctxt.user_regs.gprs[1],
    9.70 -                 ctxt.user_regs.gprs[2],
    9.71 -                 ctxt.user_regs.gprs[3],
    9.72 -                 ctxt.user_regs.gprs[4],
    9.73 -                 ctxt.user_regs.gprs[5]);
    9.74 -    rc = xc_vcpu_setcontext(xc_handle, domid, 0, &ctxt);
    9.75 -    if (rc < 0)
    9.76 -        perror("setdomaininfo");
    9.77 -
    9.78 -    return rc;
    9.79 -}
    9.80 -
    9.81 -static int load_initrd(
    9.82 -    int xc_handle,
    9.83 -    int domid,
    9.84 -    xen_pfn_t *page_array,
    9.85 -    const char *initrd_path,
    9.86 -    unsigned long *base,
    9.87 -    unsigned long *len)
    9.88 -{
    9.89 -    uint8_t *initrd_img;
    9.90 -    int rc = -1;
    9.91 -
    9.92 -    /* load the initrd file */
    9.93 -    initrd_img = load_file(initrd_path, len);
    9.94 -    if (initrd_img == NULL)
    9.95 -        return -1;
    9.96 -
    9.97 -    DPRINTF("copying initrd to 0x%lx[0x%lx]\n", INITRD_ADDR, *len);
    9.98 -    if (install_image(xc_handle, domid, page_array, initrd_img, INITRD_ADDR,
    9.99 -                *len))
   9.100 -        goto out;
   9.101 -
   9.102 -    *base = INITRD_ADDR;
   9.103 -    rc = 0;
   9.104 -
   9.105 -out:
   9.106 -    free(initrd_img);
   9.107 -    return rc;
   9.108 -}
   9.109 -
   9.110 -static unsigned long create_start_info(
   9.111 -	start_info_t *start_info,
   9.112 -        unsigned int console_evtchn, unsigned int store_evtchn,
   9.113 -	unsigned long nr_pages, unsigned long rma_pages, const char *cmdline)
   9.114 -{
   9.115 -    unsigned long start_info_addr;
   9.116 -    uint64_t rma_top;
   9.117 -
   9.118 -    memset(start_info, 0, sizeof(*start_info));
   9.119 -    snprintf(start_info->magic, sizeof(start_info->magic),
   9.120 -             "xen-%d.%d-powerpc64HV", 3, 0);
   9.121 -
   9.122 -    rma_top = rma_pages << PAGE_SHIFT;
   9.123 -    DPRINTF("RMA top = 0x%"PRIX64"\n", rma_top);
   9.124 -
   9.125 -    start_info->nr_pages = nr_pages;
   9.126 -    start_info->shared_info = rma_top - PAGE_SIZE;
   9.127 -    start_info->store_mfn = (rma_top >> PAGE_SHIFT) - 2;
   9.128 -    start_info->store_evtchn = store_evtchn;
   9.129 -    start_info->console.domU.mfn = (rma_top >> PAGE_SHIFT) - 3;
   9.130 -    start_info->console.domU.evtchn = console_evtchn;
   9.131 -    strncpy((char *)start_info->cmd_line, cmdline, MAX_GUEST_CMDLINE);
   9.132 -    /* just in case we truncated cmdline with strncpy add 0 at the end */
   9.133 -    start_info->cmd_line[MAX_GUEST_CMDLINE-1]=0;
   9.134 -    start_info_addr = rma_top - 4*PAGE_SIZE;
   9.135 -
   9.136 -    return start_info_addr;
   9.137 -}
   9.138 -
   9.139 -static void free_page_array(xen_pfn_t *page_array)
   9.140 -{
   9.141 -    free(page_array);
   9.142 -}
   9.143 -
   9.144 -int xc_prose_build(int xc_handle,
   9.145 -                   uint32_t domid,
   9.146 -                   unsigned int mem_mb,
   9.147 -                   const char *image_name,
   9.148 -                   const char *initrd_name,
   9.149 -                   const char *cmdline,
   9.150 -                   const char *features,
   9.151 -                   unsigned long flags,
   9.152 -                   unsigned int store_evtchn,
   9.153 -                   unsigned long *store_mfn,
   9.154 -                   unsigned int console_evtchn,
   9.155 -                   unsigned long *console_mfn)
   9.156 -{
   9.157 -    start_info_t start_info;
   9.158 -    struct domain_setup_info dsi;
   9.159 -    xen_pfn_t *page_array = NULL;
   9.160 -    unsigned long nr_pages;
   9.161 -    unsigned long kern_addr;
   9.162 -    unsigned long initrd_base = 0;
   9.163 -    unsigned long initrd_len = 0;
   9.164 -    unsigned long start_info_addr;
   9.165 -    unsigned long rma_pages;
   9.166 -    int rc = 0;
   9.167 -
   9.168 -    DPRINTF("%s\n", __func__);
   9.169 -
   9.170 -    DPRINTF("cmdline=%s\n", cmdline);
   9.171 -
   9.172 -    nr_pages = mem_mb << (20 - PAGE_SHIFT);
   9.173 -    DPRINTF("nr_pages 0x%lx\n", nr_pages);
   9.174 -
   9.175 -    rma_pages = (1 << 26) >> PAGE_SHIFT; /* 64 MB */
   9.176 -
   9.177 -    if (get_rma_page_array(xc_handle, domid, &page_array, rma_pages)) {
   9.178 -        rc = -1;
   9.179 -        goto out;
   9.180 -    }
   9.181 -
   9.182 -    DPRINTF("loading image '%s'\n", image_name);
   9.183 -    if (load_elf_kernel(xc_handle, domid, image_name, &dsi, page_array)) {
   9.184 -        rc = -1;
   9.185 -        goto out;
   9.186 -    }
   9.187 -    kern_addr = 0;
   9.188 -
   9.189 -    if (initrd_name && initrd_name[0] != '\0') {
   9.190 -        DPRINTF("loading initrd '%s'\n", initrd_name);
   9.191 -        if (load_initrd(xc_handle, domid, page_array, initrd_name,
   9.192 -                &initrd_base, &initrd_len)) {
   9.193 -            rc = -1;
   9.194 -            goto out;
   9.195 -        }
   9.196 -    }
   9.197 -
   9.198 -    /* start_info stuff: about to be removed  */
   9.199 -    start_info_addr = create_start_info(&start_info, console_evtchn,
   9.200 -                                        store_evtchn, nr_pages,
   9.201 -                                        rma_pages, cmdline);
   9.202 -    *console_mfn = page_array[start_info.console.domU.mfn];
   9.203 -    *store_mfn = page_array[start_info.store_mfn];
   9.204 -    if (install_image(xc_handle, domid, page_array, &start_info,
   9.205 -                      start_info_addr, sizeof(start_info_t))) {
   9.206 -        rc = -1;
   9.207 -        goto out;
   9.208 -    }
   9.209 -
   9.210 -    if (init_boot_vcpu(xc_handle, domid, &dsi, kern_addr)) {
   9.211 -        rc = -1;
   9.212 -        goto out;
   9.213 -    }
   9.214 -
   9.215 -out:
   9.216 -    free_page_array(page_array);
   9.217 -    return rc;
   9.218 -}
    10.1 --- a/tools/libxc/xc_core.h	Thu Mar 22 09:28:05 2007 -0600
    10.2 +++ b/tools/libxc/xc_core.h	Thu Mar 22 09:30:54 2007 -0600
    10.3 @@ -144,6 +144,8 @@ int xc_core_arch_map_p2m(int xc_handle, 
    10.4  # include "xc_core_x86.h"
    10.5  #elif defined (__ia64__)
    10.6  # include "xc_core_ia64.h"
    10.7 +#elif defined (__powerpc__)
    10.8 +# include "xc_core_powerpc.h"
    10.9  #else
   10.10  # error "unsupported architecture"
   10.11  #endif
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/tools/libxc/xc_core_powerpc.c	Thu Mar 22 09:30:54 2007 -0600
    11.3 @@ -0,0 +1,79 @@
    11.4 +/*
    11.5 + * This program is free software; you can redistribute it and/or modify
    11.6 + * it under the terms of the GNU General Public License as published by
    11.7 + * the Free Software Foundation; either version 2 of the License, or
    11.8 + * (at your option) any later version.
    11.9 + *
   11.10 + * This program is distributed in the hope that it will be useful,
   11.11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   11.12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11.13 + * GNU General Public License for more details.
   11.14 + *
   11.15 + * You should have received a copy of the GNU General Public License
   11.16 + * along with this program; if not, write to the Free Software
   11.17 + * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
   11.18 + *
   11.19 + * Copyright (c) 2007 Isaku Yamahata <yamahata at valinux co jp>
   11.20 + *                    VA Linux Systems Japan K.K.
   11.21 + * Copyright IBM Corp. 2007
   11.22 + *
   11.23 + * Authors: Isaku Yamahata <yamahata at valinux co jp>
   11.24 + *          Hollis Blanchard <hollisb@us.ibm.com>
   11.25 + *
   11.26 + */
   11.27 +
   11.28 +#include "xg_private.h"
   11.29 +#include "xc_core.h"
   11.30 +
   11.31 +int
   11.32 +xc_core_arch_auto_translated_physmap(const xc_dominfo_t *info)
   11.33 +{
   11.34 +	/* All PowerPC domU are autotranslated. */
   11.35 +	return 1;
   11.36 +}
   11.37 +
   11.38 +int
   11.39 +xc_core_arch_map_p2m(int xc_handle, xc_dominfo_t *info,
   11.40 +                     shared_info_t *live_shinfo, xen_pfn_t **live_p2m,
   11.41 +                     unsigned long *pfnp)
   11.42 +{
   11.43 +	/* All PowerPC domU are autotranslated. */
   11.44 +    errno = ENOSYS;
   11.45 +    return -1;
   11.46 +}
   11.47 +
   11.48 +int
   11.49 +xc_core_arch_memory_map_get(int xc_handle, xc_dominfo_t *info,
   11.50 +                            shared_info_t *live_shinfo,
   11.51 +                            xc_core_memory_map_t **mapp,
   11.52 +                            unsigned int *nr_entries)
   11.53 +{
   11.54 +    xc_core_memory_map_t *map = NULL;
   11.55 +
   11.56 +    map = malloc(sizeof(*map));
   11.57 +    if (!map) {
   11.58 +        PERROR("Could not allocate memory");
   11.59 +        goto out;
   11.60 +    }
   11.61 +
   11.62 +    map->addr = 0;
   11.63 +    map->size = info->max_memkb * 1024;
   11.64 +
   11.65 +    *mapp = map;
   11.66 +    *nr_entries = 1;
   11.67 +    return 0;
   11.68 +
   11.69 +out:
   11.70 +    free(map);
   11.71 +    return -1;
   11.72 +}
   11.73 +
   11.74 +/*
   11.75 + * Local variables:
   11.76 + * mode: C
   11.77 + * c-set-style: "BSD"
   11.78 + * c-basic-offset: 4
   11.79 + * tab-width: 4
   11.80 + * indent-tabs-mode: nil
   11.81 + * End:
   11.82 + */
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/tools/libxc/xc_core_powerpc.h	Thu Mar 22 09:30:54 2007 -0600
    12.3 @@ -0,0 +1,57 @@
    12.4 +/*
    12.5 + * This program is free software; you can redistribute it and/or modify
    12.6 + * it under the terms of the GNU General Public License as published by
    12.7 + * the Free Software Foundation; either version 2 of the License, or
    12.8 + * (at your option) any later version.
    12.9 + *
   12.10 + * This program is distributed in the hope that it will be useful,
   12.11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12.13 + * GNU General Public License for more details.
   12.14 + *
   12.15 + * You should have received a copy of the GNU General Public License
   12.16 + * along with this program; if not, write to the Free Software
   12.17 + * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
   12.18 + *
   12.19 + * Copyright (c) 2007 Isaku Yamahata <yamahata at valinux co jp>
   12.20 + *                    VA Linux Systems Japan K.K.
   12.21 + *
   12.22 + */
   12.23 +
   12.24 +#ifndef XC_CORE_POWERPC_H
   12.25 +#define XC_CORE_POWERPC_H
   12.26 +
   12.27 +#define ELF_ARCH_DATA           ELFDATA2MSB
   12.28 +#define ELF_ARCH_MACHINE        EM_PPC64
   12.29 +
   12.30 +struct xc_core_arch_context {
   12.31 +    /* nothing */
   12.32 +};
   12.33 +
   12.34 +#define xc_core_arch_context_init(arch_ctxt)            do {} while (0)
   12.35 +#define xc_core_arch_context_free(arch_ctxt)            do {} while (0)
   12.36 +#define xc_core_arch_context_get(arch_ctxt, ctxt, xc_handle, domid) \
   12.37 +                                                                (0)
   12.38 +#define xc_core_arch_context_dump(arch_ctxt, args, dump_rtn)    (0)
   12.39 +
   12.40 +static inline int
   12.41 +xc_core_arch_context_get_shdr(struct xc_core_arch_context *arch_ctxt, 
   12.42 +                              struct xc_core_section_headers *sheaders,
   12.43 +                              struct xc_core_strtab *strtab,
   12.44 +                              uint64_t *filesz, uint64_t offset)
   12.45 +{
   12.46 +    *filesz = 0;
   12.47 +    return 0;
   12.48 +}
   12.49 +
   12.50 +#endif /* XC_CORE_POWERPC_H */
   12.51 +
   12.52 +/*
   12.53 + * Local variables:
   12.54 + * mode: C
   12.55 + * c-set-style: "BSD"
   12.56 + * c-basic-offset: 4
   12.57 + * tab-width: 4
   12.58 + * indent-tabs-mode: nil
   12.59 + * End:
   12.60 + */
    13.1 --- a/tools/libxc/xc_dom.h	Thu Mar 22 09:28:05 2007 -0600
    13.2 +++ b/tools/libxc/xc_dom.h	Thu Mar 22 09:30:54 2007 -0600
    13.3 @@ -49,6 +49,7 @@ struct xc_dom_image {
    13.4      struct xc_dom_seg ramdisk_seg;
    13.5      struct xc_dom_seg p2m_seg;
    13.6      struct xc_dom_seg pgtables_seg;
    13.7 +    struct xc_dom_seg devicetree_seg;
    13.8      xen_pfn_t start_info_pfn;
    13.9      xen_pfn_t console_pfn;
   13.10      xen_pfn_t xenstore_pfn;
   13.11 @@ -75,6 +76,7 @@ struct xc_dom_image {
   13.12      /* physical memory */
   13.13      xen_pfn_t total_pages;
   13.14      struct xc_dom_phys *phys_pages;
   13.15 +    int realmodearea_log;
   13.16  
   13.17      /* malloc memory pool */
   13.18      struct xc_dom_mem *memblocks;
   13.19 @@ -253,6 +255,10 @@ static inline xen_pfn_t xc_dom_p2m_guest
   13.20  
   13.21  /* --- arch bits --------------------------------------------------- */
   13.22  
   13.23 +int arch_setup_meminit(struct xc_dom_image *dom);
   13.24 +int arch_setup_bootearly(struct xc_dom_image *dom);
   13.25 +int arch_setup_bootlate(struct xc_dom_image *dom);
   13.26 +
   13.27  /*
   13.28   * Local variables:
   13.29   * mode: C
    14.1 --- a/tools/libxc/xc_dom_boot.c	Thu Mar 22 09:28:05 2007 -0600
    14.2 +++ b/tools/libxc/xc_dom_boot.c	Thu Mar 22 09:30:54 2007 -0600
    14.3 @@ -83,293 +83,6 @@ static int clear_page(struct xc_dom_imag
    14.4      return rc;
    14.5  }
    14.6  
    14.7 -/* ------------------------------------------------------------------------ */
    14.8 -/* arch stuff: x86 bits                                                     */
    14.9 -
   14.10 -#if defined(__i386__) || defined(__x86_64__)
   14.11 -
   14.12 -
   14.13 -static int x86_compat(int xc, domid_t domid, char *guest_type)
   14.14 -{
   14.15 -    static const struct {
   14.16 -        char           *guest;
   14.17 -        uint32_t        size;
   14.18 -    } types[] = {
   14.19 -        { "xen-3.0-x86_32p", 32 },
   14.20 -        { "xen-3.0-x86_64",  64 },
   14.21 -    };
   14.22 -    DECLARE_DOMCTL;
   14.23 -    int i,rc;
   14.24 -
   14.25 -    memset(&domctl, 0, sizeof(domctl));
   14.26 -    domctl.domain = domid;
   14.27 -    domctl.cmd    = XEN_DOMCTL_set_address_size;
   14.28 -    for ( i = 0; i < sizeof(types)/sizeof(types[0]); i++ )
   14.29 -        if ( !strcmp(types[i].guest, guest_type) )
   14.30 -            domctl.u.address_size.size = types[i].size;
   14.31 -    if ( domctl.u.address_size.size == 0 )
   14.32 -        /* nothing to do */
   14.33 -        return 0;
   14.34 -
   14.35 -    xc_dom_printf("%s: guest %s, address size %" PRId32 "\n", __FUNCTION__,
   14.36 -                  guest_type, domctl.u.address_size.size);
   14.37 -    rc = do_domctl(xc, &domctl);
   14.38 -    if ( rc != 0 )
   14.39 -        xc_dom_printf("%s: warning: failed (rc=%d)\n",
   14.40 -                      __FUNCTION__, rc);
   14.41 -    return rc;
   14.42 -}
   14.43 -
   14.44 -
   14.45 -static int x86_shadow(int xc, domid_t domid)
   14.46 -{
   14.47 -    int rc, mode;
   14.48 -
   14.49 -    xc_dom_printf("%s: called\n", __FUNCTION__);
   14.50 -
   14.51 -    mode = XEN_DOMCTL_SHADOW_ENABLE_REFCOUNT |
   14.52 -        XEN_DOMCTL_SHADOW_ENABLE_TRANSLATE;
   14.53 -
   14.54 -    rc = xc_shadow_control(xc, domid,
   14.55 -                           XEN_DOMCTL_SHADOW_OP_ENABLE,
   14.56 -                           NULL, 0, NULL, mode, NULL);
   14.57 -    if ( rc != 0 )
   14.58 -    {
   14.59 -        xc_dom_panic(XC_INTERNAL_ERROR,
   14.60 -                     "%s: SHADOW_OP_ENABLE (mode=0x%x) failed (rc=%d)\n",
   14.61 -                     __FUNCTION__, mode, rc);
   14.62 -        return rc;
   14.63 -    }
   14.64 -    xc_dom_printf("%s: shadow enabled (mode=0x%x)\n", __FUNCTION__, mode);
   14.65 -    return rc;
   14.66 -}
   14.67 -
   14.68 -static int arch_setup_meminit(struct xc_dom_image *dom)
   14.69 -{
   14.70 -    int rc = 0;
   14.71 -
   14.72 -    x86_compat(dom->guest_xc, dom->guest_domid, dom->guest_type);
   14.73 -    if ( xc_dom_feature_translated(dom) )
   14.74 -    {
   14.75 -        dom->shadow_enabled = 1;
   14.76 -        rc = x86_shadow(dom->guest_xc, dom->guest_domid);
   14.77 -    }
   14.78 -    return rc;
   14.79 -}
   14.80 -
   14.81 -static int arch_setup_bootearly(struct xc_dom_image *dom)
   14.82 -{
   14.83 -    xc_dom_printf("%s: doing nothing\n", __FUNCTION__);
   14.84 -    return 0;
   14.85 -}
   14.86 -
   14.87 -static int arch_setup_bootlate(struct xc_dom_image *dom)
   14.88 -{
   14.89 -    static const struct {
   14.90 -        char *guest;
   14.91 -        unsigned long pgd_type;
   14.92 -    } types[] = {
   14.93 -        { "xen-3.0-x86_32",  MMUEXT_PIN_L2_TABLE},
   14.94 -        { "xen-3.0-x86_32p", MMUEXT_PIN_L3_TABLE},
   14.95 -        { "xen-3.0-x86_64",  MMUEXT_PIN_L4_TABLE},
   14.96 -    };
   14.97 -    unsigned long pgd_type = 0;
   14.98 -    shared_info_t *shared_info;
   14.99 -    xen_pfn_t shinfo;
  14.100 -    int i, rc;
  14.101 -
  14.102 -    for ( i = 0; i < sizeof(types) / sizeof(types[0]); i++ )
  14.103 -        if ( !strcmp(types[i].guest, dom->guest_type) )
  14.104 -            pgd_type = types[i].pgd_type;
  14.105 -
  14.106 -    if ( !xc_dom_feature_translated(dom) )
  14.107 -    {
  14.108 -        /* paravirtualized guest */
  14.109 -        xc_dom_unmap_one(dom, dom->pgtables_seg.pfn);
  14.110 -        rc = pin_table(dom->guest_xc, pgd_type,
  14.111 -                       xc_dom_p2m_host(dom, dom->pgtables_seg.pfn),
  14.112 -                       dom->guest_domid);
  14.113 -        if ( rc != 0 )
  14.114 -        {
  14.115 -            xc_dom_panic(XC_INTERNAL_ERROR,
  14.116 -                         "%s: pin_table failed (pfn 0x%" PRIpfn ", rc=%d)\n",
  14.117 -                         __FUNCTION__, dom->pgtables_seg.pfn, rc);
  14.118 -            return rc;
  14.119 -        }
  14.120 -        shinfo = dom->shared_info_mfn;
  14.121 -    }
  14.122 -    else
  14.123 -    {
  14.124 -        /* paravirtualized guest with auto-translation */
  14.125 -        struct xen_add_to_physmap xatp;
  14.126 -        int i;
  14.127 -
  14.128 -        /* Map shared info frame into guest physmap. */
  14.129 -        xatp.domid = dom->guest_domid;
  14.130 -        xatp.space = XENMAPSPACE_shared_info;
  14.131 -        xatp.idx = 0;
  14.132 -        xatp.gpfn = dom->shared_info_pfn;
  14.133 -        rc = xc_memory_op(dom->guest_xc, XENMEM_add_to_physmap, &xatp);
  14.134 -        if ( rc != 0 )
  14.135 -        {
  14.136 -            xc_dom_panic(XC_INTERNAL_ERROR, "%s: mapping shared_info failed "
  14.137 -                         "(pfn=0x%" PRIpfn ", rc=%d)\n",
  14.138 -                         __FUNCTION__, xatp.gpfn, rc);
  14.139 -            return rc;
  14.140 -        }
  14.141 -
  14.142 -        /* Map grant table frames into guest physmap. */
  14.143 -        for ( i = 0; ; i++ )
  14.144 -        {
  14.145 -            xatp.domid = dom->guest_domid;
  14.146 -            xatp.space = XENMAPSPACE_grant_table;
  14.147 -            xatp.idx = i;
  14.148 -            xatp.gpfn = dom->total_pages + i;
  14.149 -            rc = xc_memory_op(dom->guest_xc, XENMEM_add_to_physmap, &xatp);
  14.150 -            if ( rc != 0 )
  14.151 -            {
  14.152 -                if ( (i > 0) && (errno == EINVAL) )
  14.153 -                {
  14.154 -                    xc_dom_printf("%s: %d grant tables mapped\n", __FUNCTION__,
  14.155 -                                  i);
  14.156 -                    break;
  14.157 -                }
  14.158 -                xc_dom_panic(XC_INTERNAL_ERROR,
  14.159 -                             "%s: mapping grant tables failed " "(pfn=0x%"
  14.160 -                             PRIpfn ", rc=%d)\n", __FUNCTION__, xatp.gpfn, rc);
  14.161 -                return rc;
  14.162 -            }
  14.163 -        }
  14.164 -        shinfo = dom->shared_info_pfn;
  14.165 -    }
  14.166 -
  14.167 -    /* setup shared_info page */
  14.168 -    xc_dom_printf("%s: shared_info: pfn 0x%" PRIpfn ", mfn 0x%" PRIpfn "\n",
  14.169 -                  __FUNCTION__, dom->shared_info_pfn, dom->shared_info_mfn);
  14.170 -    shared_info = xc_map_foreign_range(dom->guest_xc, dom->guest_domid,
  14.171 -                                       PAGE_SIZE_X86,
  14.172 -                                       PROT_READ | PROT_WRITE,
  14.173 -                                       shinfo);
  14.174 -    if ( shared_info == NULL )
  14.175 -        return -1;
  14.176 -    dom->arch_hooks->shared_info(dom, shared_info);
  14.177 -    munmap(shared_info, PAGE_SIZE_X86);
  14.178 -
  14.179 -    return 0;
  14.180 -}
  14.181 -
  14.182 -/* ------------------------------------------------------------------------ */
  14.183 -/* arch stuff: ia64                                                         */
  14.184 -
  14.185 -#elif defined(__ia64__)
  14.186 -
  14.187 -static int arch_setup_meminit(struct xc_dom_image *dom)
  14.188 -{
  14.189 -    xc_dom_printf("%s: doing nothing\n", __FUNCTION__);
  14.190 -    return 0;
  14.191 -}
  14.192 -
  14.193 -static int arch_setup_bootearly(struct xc_dom_image *dom)
  14.194 -{
  14.195 -    DECLARE_DOMCTL;
  14.196 -    int rc;
  14.197 -
  14.198 -    xc_dom_printf("%s: setup firmware\n", __FUNCTION__);
  14.199 -
  14.200 -    memset(&domctl, 0, sizeof(domctl));
  14.201 -    domctl.cmd = XEN_DOMCTL_arch_setup;
  14.202 -    domctl.domain = dom->guest_domid;
  14.203 -    domctl.u.arch_setup.flags = 0;
  14.204 -
  14.205 -    domctl.u.arch_setup.bp = (dom->start_info_pfn << PAGE_SHIFT)
  14.206 -        + sizeof(start_info_t);
  14.207 -    /* 3 = start info page, xenstore page and console page */
  14.208 -    domctl.u.arch_setup.maxmem = (dom->total_pages - 3) << PAGE_SHIFT;
  14.209 -    rc = do_domctl(dom->guest_xc, &domctl);
  14.210 -    return rc;
  14.211 -}
  14.212 -
  14.213 -static int arch_setup_bootlate(struct xc_dom_image *dom)
  14.214 -{
  14.215 -    unsigned int page_size = XC_DOM_PAGE_SIZE(dom);
  14.216 -    shared_info_t *shared_info;
  14.217 -
  14.218 -    /* setup shared_info page */
  14.219 -    xc_dom_printf("%s: shared_info: mfn 0x%" PRIpfn "\n",
  14.220 -                  __FUNCTION__, dom->shared_info_mfn);
  14.221 -    shared_info = xc_map_foreign_range(dom->guest_xc, dom->guest_domid,
  14.222 -                                       page_size,
  14.223 -                                       PROT_READ | PROT_WRITE,
  14.224 -                                       dom->shared_info_mfn);
  14.225 -    if ( shared_info == NULL )
  14.226 -        return -1;
  14.227 -    dom->arch_hooks->shared_info(dom, shared_info);
  14.228 -    munmap(shared_info, page_size);
  14.229 -    return 0;
  14.230 -}
  14.231 -
  14.232 -/* ------------------------------------------------------------------------ */
  14.233 -/* arch stuff: powerpc                                                      */
  14.234 -
  14.235 -#elif defined(__powerpc64__)
  14.236 -
  14.237 -static int arch_setup_meminit(struct xc_dom_image *dom)
  14.238 -{
  14.239 -    xc_dom_printf("%s: doing nothing\n", __FUNCTION__);
  14.240 -    return 0;
  14.241 -}
  14.242 -
  14.243 -static int arch_setup_bootearly(struct xc_dom_image *dom)
  14.244 -{
  14.245 -    xc_dom_printf("%s: doing nothing\n", __FUNCTION__);
  14.246 -    return 0;
  14.247 -}
  14.248 -
  14.249 -static int arch_setup_bootlate(struct xc_dom_image *dom)
  14.250 -{
  14.251 -    start_info_t *si =
  14.252 -        xc_dom_pfn_to_ptr(dom, dom->start_info_pfn, 1);
  14.253 -
  14.254 -    xc_dom_printf("%s: TODO: setup devtree\n", __FUNCTION__);
  14.255 -
  14.256 -#if 0
  14.257 -    load_devtree(dom->guest_xc,
  14.258 -                 dom->guest_domid,
  14.259 -                 dom->p2m_host,
  14.260 -                 devtree,           // FIXME
  14.261 -                 devtree_addr,      // FIXME
  14.262 -                 dom->ramdisk_seg.vstart,
  14.263 -                 dom->ramdisk_seg.vend - dom->ramdisk_seg.vstart,
  14.264 -                 si,
  14.265 -                 dom->start_info_pfn << PAGE_SHIFT);
  14.266 -#endif
  14.267 -    return rc;
  14.268 -}
  14.269 -
  14.270 -/* ------------------------------------------------------------------------ */
  14.271 -/* arch stuff: other                                                        */
  14.272 -
  14.273 -#else
  14.274 -
  14.275 -static int arch_setup_meminit(struct xc_dom_image *dom)
  14.276 -{
  14.277 -    xc_dom_printf("%s: doing nothing\n", __FUNCTION__);
  14.278 -    return 0;
  14.279 -}
  14.280 -
  14.281 -static int arch_setup_bootearly(struct xc_dom_image *dom)
  14.282 -{
  14.283 -    xc_dom_printf("%s: doing nothing\n", __FUNCTION__);
  14.284 -    return 0;
  14.285 -}
  14.286 -
  14.287 -static int arch_setup_bootlate(struct xc_dom_image *dom)
  14.288 -{
  14.289 -    xc_dom_printf("%s: doing nothing\n", __FUNCTION__);
  14.290 -    return 0;
  14.291 -}
  14.292 -
  14.293 -#endif /* arch stuff */
  14.294  
  14.295  /* ------------------------------------------------------------------------ */
  14.296  
  14.297 @@ -420,13 +133,7 @@ int xc_dom_boot_mem_init(struct xc_dom_i
  14.298  
  14.299      xc_dom_printf("%s: called\n", __FUNCTION__);
  14.300  
  14.301 -    if ( (rc = arch_setup_meminit(dom)) != 0 )
  14.302 -        return rc;
  14.303 -
  14.304 -    /* allocate guest memory */
  14.305 -    rc = xc_domain_memory_populate_physmap(dom->guest_xc, dom->guest_domid,
  14.306 -                                           dom->total_pages, 0, 0,
  14.307 -                                           dom->p2m_host);
  14.308 +    rc = arch_setup_meminit(dom);
  14.309      if ( rc != 0 )
  14.310      {
  14.311          xc_dom_panic(XC_OUT_OF_MEMORY,
    15.1 --- a/tools/libxc/xc_dom_compat_linux.c	Thu Mar 22 09:28:05 2007 -0600
    15.2 +++ b/tools/libxc/xc_dom_compat_linux.c	Thu Mar 22 09:30:54 2007 -0600
    15.3 @@ -32,6 +32,10 @@ static int xc_linux_build_internal(struc
    15.4  {
    15.5      int rc;
    15.6  
    15.7 +    dom->flags = flags;
    15.8 +    dom->console_evtchn = console_evtchn;
    15.9 +    dom->xenstore_evtchn = store_evtchn;
   15.10 +
   15.11      if ( (rc = xc_dom_boot_xen_init(dom, xc_handle, domid)) != 0 )
   15.12          goto out;
   15.13      if ( (rc = xc_dom_parse_image(dom)) != 0 )
   15.14 @@ -42,12 +46,7 @@ static int xc_linux_build_internal(struc
   15.15          goto out;
   15.16      if ( (rc = xc_dom_build_image(dom)) != 0 )
   15.17          goto out;
   15.18 -
   15.19 -    dom->flags = flags;
   15.20 -    dom->console_evtchn = console_evtchn;
   15.21 -    dom->xenstore_evtchn = store_evtchn;
   15.22 -    rc = xc_dom_boot_image(dom);
   15.23 -    if ( rc != 0 )
   15.24 +    if ( (rc = xc_dom_boot_image(dom)) != 0 )
   15.25          goto out;
   15.26  
   15.27      *console_mfn = xc_dom_p2m_host(dom, dom->console_pfn);
    16.1 --- a/tools/libxc/xc_dom_core.c	Thu Mar 22 09:28:05 2007 -0600
    16.2 +++ b/tools/libxc/xc_dom_core.c	Thu Mar 22 09:30:54 2007 -0600
    16.3 @@ -639,7 +639,7 @@ int xc_dom_parse_image(struct xc_dom_ima
    16.4  int xc_dom_mem_init(struct xc_dom_image *dom, unsigned int mem_mb)
    16.5  {
    16.6      unsigned int page_shift;
    16.7 -    xen_pfn_t nr_pages, pfn;
    16.8 +    xen_pfn_t nr_pages;
    16.9  
   16.10      dom->arch_hooks = xc_dom_find_arch_hooks(dom->guest_type);
   16.11      if ( dom->arch_hooks == NULL )
   16.12 @@ -659,10 +659,6 @@ int xc_dom_mem_init(struct xc_dom_image 
   16.13      xc_dom_printf("%s: 0x%" PRIpfn " pages\n",
   16.14                    __FUNCTION__, dom->total_pages);
   16.15  
   16.16 -    /* setup initial p2m */
   16.17 -    dom->p2m_host = xc_dom_malloc(dom, sizeof(xen_pfn_t) * dom->total_pages);
   16.18 -    for ( pfn = 0; pfn < dom->total_pages; pfn++ )
   16.19 -        dom->p2m_host[pfn] = pfn;
   16.20      return 0;
   16.21  }
   16.22  
    17.1 --- a/tools/libxc/xc_dom_ia64.c	Thu Mar 22 09:28:05 2007 -0600
    17.2 +++ b/tools/libxc/xc_dom_ia64.c	Thu Mar 22 09:30:54 2007 -0600
    17.3 @@ -18,6 +18,7 @@
    17.4  
    17.5  #include "xg_private.h"
    17.6  #include "xc_dom.h"
    17.7 +#include "xenctrl.h"
    17.8  
    17.9  /* ------------------------------------------------------------------------ */
   17.10  
   17.11 @@ -128,6 +129,62 @@ static void __init register_arch_hooks(v
   17.12      xc_dom_register_arch_hooks(&xc_dom_arch_ia64be);
   17.13  }
   17.14  
   17.15 +int arch_setup_meminit(struct xc_dom_image *dom)
   17.16 +{
   17.17 +    xen_pfn_t pfn;
   17.18 +    int rc;
   17.19 +
   17.20 +    /* setup initial p2m */
   17.21 +    dom->p2m_host = xc_dom_malloc(dom, sizeof(xen_pfn_t) * dom->total_pages);
   17.22 +    for ( pfn = 0; pfn < dom->total_pages; pfn++ )
   17.23 +        dom->p2m_host[pfn] = pfn;
   17.24 +
   17.25 +    /* allocate guest memory */
   17.26 +    rc = xc_domain_memory_populate_physmap(dom->guest_xc, dom->guest_domid,
   17.27 +                                           dom->total_pages, 0, 0,
   17.28 +                                           dom->p2m_host);
   17.29 +    return rc;
   17.30 +}
   17.31 +
   17.32 +int arch_setup_bootearly(struct xc_dom_image *dom)
   17.33 +{
   17.34 +    DECLARE_DOMCTL;
   17.35 +    int rc;
   17.36 +
   17.37 +    xc_dom_printf("%s: setup firmware\n", __FUNCTION__);
   17.38 +
   17.39 +    memset(&domctl, 0, sizeof(domctl));
   17.40 +    domctl.cmd = XEN_DOMCTL_arch_setup;
   17.41 +    domctl.domain = dom->guest_domid;
   17.42 +    domctl.u.arch_setup.flags = 0;
   17.43 +
   17.44 +    domctl.u.arch_setup.bp = (dom->start_info_pfn << PAGE_SHIFT)
   17.45 +        + sizeof(start_info_t);
   17.46 +    /* 3 = start info page, xenstore page and console page */
   17.47 +    domctl.u.arch_setup.maxmem = (dom->total_pages - 3) << PAGE_SHIFT;
   17.48 +    rc = do_domctl(dom->guest_xc, &domctl);
   17.49 +    return rc;
   17.50 +}
   17.51 +
   17.52 +int arch_setup_bootlate(struct xc_dom_image *dom)
   17.53 +{
   17.54 +    unsigned int page_size = XC_DOM_PAGE_SIZE(dom);
   17.55 +    shared_info_t *shared_info;
   17.56 +
   17.57 +    /* setup shared_info page */
   17.58 +    xc_dom_printf("%s: shared_info: mfn 0x%" PRIpfn "\n",
   17.59 +                  __FUNCTION__, dom->shared_info_mfn);
   17.60 +    shared_info = xc_map_foreign_range(dom->guest_xc, dom->guest_domid,
   17.61 +                                       page_size,
   17.62 +                                       PROT_READ | PROT_WRITE,
   17.63 +                                       dom->shared_info_mfn);
   17.64 +    if ( shared_info == NULL )
   17.65 +        return -1;
   17.66 +    dom->arch_hooks->shared_info(dom, shared_info);
   17.67 +    munmap(shared_info, page_size);
   17.68 +    return 0;
   17.69 +}
   17.70 +
   17.71  /*
   17.72   * Local variables:
   17.73   * mode: C
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/tools/libxc/xc_dom_powerpc.c	Thu Mar 22 09:30:54 2007 -0600
    18.3 @@ -0,0 +1,236 @@
    18.4 +/*
    18.5 + * Xen domain builder -- powerpc bits.
    18.6 + *
    18.7 + * Most architecture-specific code for powerpc goes here.
    18.8 + *
    18.9 + * This code is licenced under the GPL.
   18.10 + * written 2006 by Gerd Hoffmann <kraxel@suse.de>.
   18.11 + *
   18.12 + * Copyright IBM Corp. 2007
   18.13 + *
   18.14 + * Authors: Gerd Hoffmann <kraxel@suse.de>
   18.15 + *          Hollis Blanchard <hollisb@us.ibm.com>
   18.16 + *
   18.17 + */
   18.18 +#include <stdio.h>
   18.19 +#include <stdlib.h>
   18.20 +#include <string.h>
   18.21 +#include <inttypes.h>
   18.22 +
   18.23 +#include <xen/xen.h>
   18.24 +
   18.25 +#include "xg_private.h"
   18.26 +#include "xc_dom.h"
   18.27 +#include "powerpc64/flatdevtree.h"
   18.28 +#include "powerpc64/mk_flatdevtree.h"
   18.29 +
   18.30 +#define RMA_LOG 26 /* 64 MB */
   18.31 +#define EXTENT_LOG 24 /* 16 MB */
   18.32 +#define EXTENT_ORDER (EXTENT_LOG - PAGE_SHIFT)
   18.33 +
   18.34 +/* ------------------------------------------------------------------------ */
   18.35 +
   18.36 +static int alloc_magic_pages(struct xc_dom_image *dom)
   18.37 +{
   18.38 +    struct ft_cxt devtree;
   18.39 +    void *guest_devtree;
   18.40 +    unsigned long shadow_mb;
   18.41 +    int rma_pages;
   18.42 +    int rc;
   18.43 +
   18.44 +    /* Allocate special pages from the end of the RMA. */
   18.45 +    rma_pages = 1 << (dom->realmodearea_log - PAGE_SHIFT);
   18.46 +    dom->shared_info_pfn = --rma_pages;
   18.47 +    dom->console_pfn = --rma_pages;
   18.48 +    dom->xenstore_pfn = --rma_pages;
   18.49 +
   18.50 +    /* Gather shadow allocation info for the device tree. */
   18.51 +    rc = xc_shadow_control(dom->guest_xc, dom->guest_domid,
   18.52 +                           XEN_DOMCTL_SHADOW_OP_GET_ALLOCATION, NULL, 0, 
   18.53 +                           &shadow_mb, 0, NULL);
   18.54 +    if (rc < 0 || shadow_mb == 0) {
   18.55 +        xc_dom_printf("Couldn't get shadow allocation size or it was 0.\n");
   18.56 +        return rc;
   18.57 +    }
   18.58 +
   18.59 +    /* Build device tree. */
   18.60 +    rc = make_devtree(&devtree, dom, shadow_mb);
   18.61 +    if (rc < 0) {
   18.62 +        xc_dom_printf("Failed to create flattened device tree.\n");
   18.63 +        return rc;
   18.64 +    }
   18.65 +
   18.66 +    /* Find a spot for it. */
   18.67 +    rc = xc_dom_alloc_segment(dom, &dom->devicetree_seg, "devtree", 0,
   18.68 +                              devtree.bph->totalsize);
   18.69 +    if (rc)
   18.70 +        goto out;
   18.71 +
   18.72 +    /* Copy the device tree into place. */
   18.73 +    guest_devtree = xc_dom_seg_to_ptr(dom, &dom->devicetree_seg);
   18.74 +    if (!guest_devtree) {
   18.75 +        xc_dom_printf("Couldn't map guest memory for device tree.\n");
   18.76 +        rc = -1;
   18.77 +        goto out;
   18.78 +    }
   18.79 +    memcpy(guest_devtree, devtree.bph, devtree.bph->totalsize);
   18.80 +
   18.81 +out:
   18.82 +    free_devtree(&devtree);
   18.83 +    return rc;
   18.84 +}
   18.85 +
   18.86 +static int shared_info(struct xc_dom_image *dom, void *ptr)
   18.87 +{
   18.88 +    shared_info_t *shared_info = ptr;
   18.89 +
   18.90 +    xc_dom_printf("%s: called\n", __FUNCTION__);
   18.91 +
   18.92 +    memset(shared_info, 0, sizeof(*shared_info));
   18.93 +    return 0;
   18.94 +}
   18.95 +
   18.96 +static int vcpu(struct xc_dom_image *dom, void *ptr)
   18.97 +{
   18.98 +    vcpu_guest_context_t *ctxt = ptr;
   18.99 +
  18.100 +    memset(ctxt, 0x55, sizeof(*ctxt));
  18.101 +    ctxt->user_regs.pc = dom->parms.virt_entry;
  18.102 +    ctxt->user_regs.msr = 0;
  18.103 +    ctxt->user_regs.gprs[1] = 0; /* Linux uses its own stack */
  18.104 +    ctxt->user_regs.gprs[3] = dom->devicetree_seg.pfn << PAGE_SHIFT;
  18.105 +    ctxt->user_regs.gprs[4] = dom->kernel_seg.pfn << PAGE_SHIFT;
  18.106 +    ctxt->user_regs.gprs[5] = 0;
  18.107 +
  18.108 +    /* There is a buggy kernel that does not zero the "local_paca", so
  18.109 +     * we must make sure this register is 0 */
  18.110 +    ctxt->user_regs.gprs[13] = 0;
  18.111 +
  18.112 +    xc_dom_printf("%s: initial vcpu:\n", __FUNCTION__);
  18.113 +    xc_dom_printf("  pc 0x%016"PRIx64", msr 0x%016"PRIx64"\n"
  18.114 +                  "  r1-5 %016"PRIx64" %016"PRIx64" %016"PRIx64" %016"PRIx64
  18.115 +                  " %016"PRIx64"\n",
  18.116 +                  ctxt->user_regs.pc, ctxt->user_regs.msr,
  18.117 +                  ctxt->user_regs.gprs[1],
  18.118 +                  ctxt->user_regs.gprs[2],
  18.119 +                  ctxt->user_regs.gprs[3],
  18.120 +                  ctxt->user_regs.gprs[4],
  18.121 +                  ctxt->user_regs.gprs[5]);
  18.122 +
  18.123 +    return 0;
  18.124 +}
  18.125 +
  18.126 +/* ------------------------------------------------------------------------ */
  18.127 +
  18.128 +static struct xc_dom_arch xc_dom_arch = {
  18.129 +    .guest_type = "xen-3.0-powerpc64",
  18.130 +    .page_shift = PAGE_SHIFT,
  18.131 +    .alloc_magic_pages = alloc_magic_pages,
  18.132 +    .shared_info = shared_info,
  18.133 +    .vcpu = vcpu,
  18.134 +};
  18.135 +
  18.136 +static void __init register_arch_hooks(void)
  18.137 +{
  18.138 +    xc_dom_register_arch_hooks(&xc_dom_arch);
  18.139 +}
  18.140 +
  18.141 +int arch_setup_meminit(struct xc_dom_image *dom)
  18.142 +{
  18.143 +    xen_pfn_t *extent_list;
  18.144 +    unsigned long total_mem = dom->total_pages << PAGE_SHIFT;
  18.145 +    unsigned long rma_bytes;
  18.146 +    unsigned long rma_nr_pages;
  18.147 +    unsigned long nr_extents;
  18.148 +    int rc = 0;
  18.149 +    int i;
  18.150 +
  18.151 +    /* XXX RMA size is processor-dependent. */
  18.152 +    dom->realmodearea_log = RMA_LOG;
  18.153 +    rma_bytes = 1 << dom->realmodearea_log;
  18.154 +    rma_nr_pages = rma_bytes >> PAGE_SHIFT;
  18.155 +
  18.156 +    xc_dom_printf("dom%u memory: %lu MB RMA, %lu MB additional.\n",
  18.157 +            dom->guest_domid, rma_bytes >> 20, (total_mem - rma_bytes) >> 20);
  18.158 +
  18.159 +    if (total_mem < rma_bytes) {
  18.160 +        xc_dom_printf("Domain must have at least %lu MB\n", rma_bytes >> 20);
  18.161 +        return -EINVAL;
  18.162 +    }
  18.163 +
  18.164 +    /* Allocate the first chunk of memory. */
  18.165 +    rc = xc_alloc_real_mode_area(dom->guest_xc, dom->guest_domid,
  18.166 +                                 dom->realmodearea_log);
  18.167 +    if (rc) {
  18.168 +        xc_dom_printf("Failed to allocate real mode area.\n");
  18.169 +        return rc;
  18.170 +    }
  18.171 +
  18.172 +    /* Allocate p2m map. */
  18.173 +    dom->p2m_host = xc_dom_malloc(dom, sizeof(xen_pfn_t) * dom->total_pages);
  18.174 +    if (dom->p2m_host == NULL) {
  18.175 +        xc_dom_printf("Couldn't allocate p2m map.\n");
  18.176 +        return -ENOMEM;
  18.177 +    }
  18.178 +
  18.179 +    nr_extents = (dom->total_pages - rma_nr_pages) >> EXTENT_ORDER;
  18.180 +    if (nr_extents) {
  18.181 +        /* Allocate extent list for populate_physmap() call. */
  18.182 +        extent_list = xc_dom_malloc(dom, sizeof(xen_pfn_t) * nr_extents);
  18.183 +        if (extent_list == NULL) {
  18.184 +            xc_dom_printf("Couldn't allocate extent list.\n");
  18.185 +            return -ENOMEM;
  18.186 +        }
  18.187 +
  18.188 +        /* Allocate the remaining (non-RMA) memory. */
  18.189 +        for (i = 0; i < nr_extents; i++) {
  18.190 +            /* Use PFNs above the RMA memory we already allocated. */
  18.191 +            extent_list[i] = rma_nr_pages + i * (1<<EXTENT_ORDER);
  18.192 +        }
  18.193 +        rc = xc_domain_memory_populate_physmap(dom->guest_xc, dom->guest_domid,
  18.194 +                                               nr_extents, EXTENT_ORDER, 0,
  18.195 +                                               extent_list);
  18.196 +        if (rc < 0) {
  18.197 +            xc_dom_printf("populate_physmap(0x%lx extents order %u) -> 0x%x\n",
  18.198 +                          nr_extents, EXTENT_ORDER, rc);
  18.199 +            return rc;
  18.200 +        }
  18.201 +    }
  18.202 +
  18.203 +    /* Populate the p2m map. */
  18.204 +    rc = xc_get_pfn_list(dom->guest_xc, dom->guest_domid, dom->p2m_host,
  18.205 +                         dom->total_pages);
  18.206 +    if (rc < 0) {
  18.207 +        xc_dom_printf("Couldn't get p2m translation.\n");
  18.208 +        return rc;
  18.209 +    }
  18.210 +
  18.211 +    xc_dom_printf("%s: success\n", __func__);
  18.212 +
  18.213 +    return 0;
  18.214 +}
  18.215 +
  18.216 +int arch_setup_bootearly(struct xc_dom_image *dom)
  18.217 +{
  18.218 +    xc_dom_printf("%s: doing nothing\n", __FUNCTION__);
  18.219 +    return 0;
  18.220 +}
  18.221 +
  18.222 +int arch_setup_bootlate(struct xc_dom_image *dom)
  18.223 +{
  18.224 +    unsigned int page_size = XC_DOM_PAGE_SIZE(dom);
  18.225 +    shared_info_t *shared_info;
  18.226 +
  18.227 +    /* setup shared_info page */
  18.228 +    xc_dom_printf("%s: shared_info: mfn 0x%" PRIpfn "\n",
  18.229 +                  __FUNCTION__, dom->shared_info_mfn);
  18.230 +    shared_info = xc_map_foreign_range(dom->guest_xc, dom->guest_domid,
  18.231 +                                       page_size,
  18.232 +                                       PROT_READ | PROT_WRITE,
  18.233 +                                       dom->shared_info_mfn);
  18.234 +    if ( shared_info == NULL )
  18.235 +        return -1;
  18.236 +    dom->arch_hooks->shared_info(dom, shared_info);
  18.237 +    munmap(shared_info, page_size);
  18.238 +    return 0;
  18.239 +}
    19.1 --- a/tools/libxc/xc_dom_x86.c	Thu Mar 22 09:28:05 2007 -0600
    19.2 +++ b/tools/libxc/xc_dom_x86.c	Thu Mar 22 09:30:54 2007 -0600
    19.3 @@ -22,6 +22,7 @@
    19.4  
    19.5  #include "xg_private.h"
    19.6  #include "xc_dom.h"
    19.7 +#include "xenctrl.h"
    19.8  
    19.9  /* ------------------------------------------------------------------------ */
   19.10  
   19.11 @@ -547,6 +548,188 @@ static void __init register_arch_hooks(v
   19.12      xc_dom_register_arch_hooks(&xc_dom_64);
   19.13  }
   19.14  
   19.15 +static int x86_compat(int xc, domid_t domid, char *guest_type)
   19.16 +{
   19.17 +    static const struct {
   19.18 +        char           *guest;
   19.19 +        uint32_t        size;
   19.20 +    } types[] = {
   19.21 +        { "xen-3.0-x86_32p", 32 },
   19.22 +        { "xen-3.0-x86_64",  64 },
   19.23 +    };
   19.24 +    DECLARE_DOMCTL;
   19.25 +    int i,rc;
   19.26 +
   19.27 +    memset(&domctl, 0, sizeof(domctl));
   19.28 +    domctl.domain = domid;
   19.29 +    domctl.cmd    = XEN_DOMCTL_set_address_size;
   19.30 +    for ( i = 0; i < sizeof(types)/sizeof(types[0]); i++ )
   19.31 +        if ( !strcmp(types[i].guest, guest_type) )
   19.32 +            domctl.u.address_size.size = types[i].size;
   19.33 +    if ( domctl.u.address_size.size == 0 )
   19.34 +        /* nothing to do */
   19.35 +        return 0;
   19.36 +
   19.37 +    xc_dom_printf("%s: guest %s, address size %" PRId32 "\n", __FUNCTION__,
   19.38 +                  guest_type, domctl.u.address_size.size);
   19.39 +    rc = do_domctl(xc, &domctl);
   19.40 +    if ( rc != 0 )
   19.41 +        xc_dom_printf("%s: warning: failed (rc=%d)\n",
   19.42 +                      __FUNCTION__, rc);
   19.43 +    return rc;
   19.44 +}
   19.45 +
   19.46 +
   19.47 +static int x86_shadow(int xc, domid_t domid)
   19.48 +{
   19.49 +    int rc, mode;
   19.50 +
   19.51 +    xc_dom_printf("%s: called\n", __FUNCTION__);
   19.52 +
   19.53 +    mode = XEN_DOMCTL_SHADOW_ENABLE_REFCOUNT |
   19.54 +        XEN_DOMCTL_SHADOW_ENABLE_TRANSLATE;
   19.55 +
   19.56 +    rc = xc_shadow_control(xc, domid,
   19.57 +                           XEN_DOMCTL_SHADOW_OP_ENABLE,
   19.58 +                           NULL, 0, NULL, mode, NULL);
   19.59 +    if ( rc != 0 )
   19.60 +    {
   19.61 +        xc_dom_panic(XC_INTERNAL_ERROR,
   19.62 +                     "%s: SHADOW_OP_ENABLE (mode=0x%x) failed (rc=%d)\n",
   19.63 +                     __FUNCTION__, mode, rc);
   19.64 +        return rc;
   19.65 +    }
   19.66 +    xc_dom_printf("%s: shadow enabled (mode=0x%x)\n", __FUNCTION__, mode);
   19.67 +    return rc;
   19.68 +}
   19.69 +
   19.70 +int arch_setup_meminit(struct xc_dom_image *dom)
   19.71 +{
   19.72 +    int rc;
   19.73 +    xen_pfn_t pfn;
   19.74 +
   19.75 +    x86_compat(dom->guest_xc, dom->guest_domid, dom->guest_type);
   19.76 +    if ( xc_dom_feature_translated(dom) )
   19.77 +    {
   19.78 +        dom->shadow_enabled = 1;
   19.79 +        rc = x86_shadow(dom->guest_xc, dom->guest_domid);
   19.80 +        if ( rc )
   19.81 +            return rc;
   19.82 +    }
   19.83 +
   19.84 +    /* setup initial p2m */
   19.85 +    dom->p2m_host = xc_dom_malloc(dom, sizeof(xen_pfn_t) * dom->total_pages);
   19.86 +    for ( pfn = 0; pfn < dom->total_pages; pfn++ )
   19.87 +        dom->p2m_host[pfn] = pfn;
   19.88 +
   19.89 +    /* allocate guest memory */
   19.90 +    rc = xc_domain_memory_populate_physmap(dom->guest_xc, dom->guest_domid,
   19.91 +                                           dom->total_pages, 0, 0,
   19.92 +                                           dom->p2m_host);
   19.93 +    return rc;
   19.94 +}
   19.95 +
   19.96 +int arch_setup_bootearly(struct xc_dom_image *dom)
   19.97 +{
   19.98 +    xc_dom_printf("%s: doing nothing\n", __FUNCTION__);
   19.99 +    return 0;
  19.100 +}
  19.101 +
  19.102 +int arch_setup_bootlate(struct xc_dom_image *dom)
  19.103 +{
  19.104 +    static const struct {
  19.105 +        char *guest;
  19.106 +        unsigned long pgd_type;
  19.107 +    } types[] = {
  19.108 +        { "xen-3.0-x86_32",  MMUEXT_PIN_L2_TABLE},
  19.109 +        { "xen-3.0-x86_32p", MMUEXT_PIN_L3_TABLE},
  19.110 +        { "xen-3.0-x86_64",  MMUEXT_PIN_L4_TABLE},
  19.111 +    };
  19.112 +    unsigned long pgd_type = 0;
  19.113 +    shared_info_t *shared_info;
  19.114 +    xen_pfn_t shinfo;
  19.115 +    int i, rc;
  19.116 +
  19.117 +    for ( i = 0; i < sizeof(types) / sizeof(types[0]); i++ )
  19.118 +        if ( !strcmp(types[i].guest, dom->guest_type) )
  19.119 +            pgd_type = types[i].pgd_type;
  19.120 +
  19.121 +    if ( !xc_dom_feature_translated(dom) )
  19.122 +    {
  19.123 +        /* paravirtualized guest */
  19.124 +        xc_dom_unmap_one(dom, dom->pgtables_seg.pfn);
  19.125 +        rc = pin_table(dom->guest_xc, pgd_type,
  19.126 +                       xc_dom_p2m_host(dom, dom->pgtables_seg.pfn),
  19.127 +                       dom->guest_domid);
  19.128 +        if ( rc != 0 )
  19.129 +        {
  19.130 +            xc_dom_panic(XC_INTERNAL_ERROR,
  19.131 +                         "%s: pin_table failed (pfn 0x%" PRIpfn ", rc=%d)\n",
  19.132 +                         __FUNCTION__, dom->pgtables_seg.pfn, rc);
  19.133 +            return rc;
  19.134 +        }
  19.135 +        shinfo = dom->shared_info_mfn;
  19.136 +    }
  19.137 +    else
  19.138 +    {
  19.139 +        /* paravirtualized guest with auto-translation */
  19.140 +        struct xen_add_to_physmap xatp;
  19.141 +        int i;
  19.142 +
  19.143 +        /* Map shared info frame into guest physmap. */
  19.144 +        xatp.domid = dom->guest_domid;
  19.145 +        xatp.space = XENMAPSPACE_shared_info;
  19.146 +        xatp.idx = 0;
  19.147 +        xatp.gpfn = dom->shared_info_pfn;
  19.148 +        rc = xc_memory_op(dom->guest_xc, XENMEM_add_to_physmap, &xatp);
  19.149 +        if ( rc != 0 )
  19.150 +        {
  19.151 +            xc_dom_panic(XC_INTERNAL_ERROR, "%s: mapping shared_info failed "
  19.152 +                         "(pfn=0x%" PRIpfn ", rc=%d)\n",
  19.153 +                         __FUNCTION__, xatp.gpfn, rc);
  19.154 +            return rc;
  19.155 +        }
  19.156 +
  19.157 +        /* Map grant table frames into guest physmap. */
  19.158 +        for ( i = 0; ; i++ )
  19.159 +        {
  19.160 +            xatp.domid = dom->guest_domid;
  19.161 +            xatp.space = XENMAPSPACE_grant_table;
  19.162 +            xatp.idx = i;
  19.163 +            xatp.gpfn = dom->total_pages + i;
  19.164 +            rc = xc_memory_op(dom->guest_xc, XENMEM_add_to_physmap, &xatp);
  19.165 +            if ( rc != 0 )
  19.166 +            {
  19.167 +                if ( (i > 0) && (errno == EINVAL) )
  19.168 +                {
  19.169 +                    xc_dom_printf("%s: %d grant tables mapped\n", __FUNCTION__,
  19.170 +                                  i);
  19.171 +                    break;
  19.172 +                }
  19.173 +                xc_dom_panic(XC_INTERNAL_ERROR,
  19.174 +                             "%s: mapping grant tables failed " "(pfn=0x%"
  19.175 +                             PRIpfn ", rc=%d)\n", __FUNCTION__, xatp.gpfn, rc);
  19.176 +                return rc;
  19.177 +            }
  19.178 +        }
  19.179 +        shinfo = dom->shared_info_pfn;
  19.180 +    }
  19.181 +
  19.182 +    /* setup shared_info page */
  19.183 +    xc_dom_printf("%s: shared_info: pfn 0x%" PRIpfn ", mfn 0x%" PRIpfn "\n",
  19.184 +                  __FUNCTION__, dom->shared_info_pfn, dom->shared_info_mfn);
  19.185 +    shared_info = xc_map_foreign_range(dom->guest_xc, dom->guest_domid,
  19.186 +                                       PAGE_SIZE_X86,
  19.187 +                                       PROT_READ | PROT_WRITE,
  19.188 +                                       shinfo);
  19.189 +    if ( shared_info == NULL )
  19.190 +        return -1;
  19.191 +    dom->arch_hooks->shared_info(dom, shared_info);
  19.192 +    munmap(shared_info, PAGE_SIZE_X86);
  19.193 +
  19.194 +    return 0;
  19.195 +}
  19.196 +
  19.197  /*
  19.198   * Local variables:
  19.199   * mode: C
    20.1 --- a/tools/python/xen/lowlevel/xc/xc.c	Thu Mar 22 09:28:05 2007 -0600
    20.2 +++ b/tools/python/xen/lowlevel/xc/xc.c	Thu Mar 22 09:30:54 2007 -0600
    20.3 @@ -1072,46 +1072,6 @@ static PyObject *pyxc_alloc_real_mode_ar
    20.4      Py_INCREF(zero);
    20.5      return zero;
    20.6  }
    20.7 -
    20.8 -static PyObject *pyxc_prose_build(XcObject *self,
    20.9 -                                  PyObject *args,
   20.10 -                                  PyObject *kwds)
   20.11 -{
   20.12 -    uint32_t dom;
   20.13 -    char *image, *ramdisk = NULL, *cmdline = "", *features = NULL;
   20.14 -    int flags = 0;
   20.15 -    int store_evtchn, console_evtchn;
   20.16 -    unsigned int mem_mb;
   20.17 -    unsigned long store_mfn = 0;
   20.18 -    unsigned long console_mfn = 0;
   20.19 -    int unused;
   20.20 -
   20.21 -    static char *kwd_list[] = { "dom", "store_evtchn",
   20.22 -                                "console_evtchn", "image", "memsize",
   20.23 -                                /* optional */
   20.24 -                                "ramdisk", "cmdline", "flags",
   20.25 -                                "features", NULL };
   20.26 -
   20.27 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiiis|ssis#", kwd_list,
   20.28 -                                      &dom, &store_evtchn, &mem_mb,
   20.29 -                                      &console_evtchn, &image,
   20.30 -                                      /* optional */
   20.31 -                                      &ramdisk, &cmdline, &flags,
   20.32 -                                      &features, &unused) )
   20.33 -        return NULL;
   20.34 -
   20.35 -    if ( xc_prose_build(self->xc_handle, dom, mem_mb, image,
   20.36 -                        ramdisk, cmdline, features, flags,
   20.37 -                        store_evtchn, &store_mfn,
   20.38 -                        console_evtchn, &console_mfn) != 0 ) {
   20.39 -        if (!errno)
   20.40 -             errno = EINVAL;
   20.41 -        return pyxc_error_to_exception();
   20.42 -    }
   20.43 -    return Py_BuildValue("{s:i,s:i}", 
   20.44 -                         "store_mfn", store_mfn,
   20.45 -                         "console_mfn", console_mfn);
   20.46 -}
   20.47  #endif /* powerpc */
   20.48  
   20.49  static PyMethodDef pyxc_methods[] = {
   20.50 @@ -1464,17 +1424,6 @@ static PyMethodDef pyxc_methods[] = {
   20.51        " dom [int]: Identifier of domain.\n"
   20.52        " log [int]: Specifies the area's size.\n"
   20.53        "Returns: [int] 0 on success; -1 on error.\n" },
   20.54 -
   20.55 -    { "arch_prose_build", 
   20.56 -      (PyCFunction)pyxc_prose_build, 
   20.57 -      METH_VARARGS | METH_KEYWORDS, "\n"
   20.58 -      "Build a new Linux guest OS.\n"
   20.59 -      " dom     [int]:      Identifier of domain to build into.\n"
   20.60 -      " image   [str]:      Name of kernel image file. May be gzipped.\n"
   20.61 -      " ramdisk [str, n/a]: Name of ramdisk file, if any.\n"
   20.62 -      " cmdline [str, n/a]: Kernel parameters, if any.\n\n"
   20.63 -      " vcpus   [int, 1]:   Number of Virtual CPUS in domain.\n\n"
   20.64 -      "Returns: [int] 0 on success; -1 on error.\n" },
   20.65  #endif /* __powerpc */
   20.66  
   20.67      { NULL, NULL, 0, NULL }
    21.1 --- a/tools/python/xen/xend/XendAPI.py	Thu Mar 22 09:28:05 2007 -0600
    21.2 +++ b/tools/python/xen/xend/XendAPI.py	Thu Mar 22 09:30:54 2007 -0600
    21.3 @@ -665,6 +665,7 @@ class XendAPI(object):
    21.4                      ('add_to_other_config', None),
    21.5                      ('remove_from_other_config', None),
    21.6                      ('dmesg', 'String'),
    21.7 +                    ('dmesg_clear', 'String'),
    21.8                      ('get_log', 'String'),
    21.9                      ('send_debug_keys', None)]
   21.10      
   21.11 @@ -742,11 +743,11 @@ class XendAPI(object):
   21.12              return xen_api_error(XEND_ERROR_HOST_RUNNING)
   21.13          return xen_api_error(XEND_ERROR_UNSUPPORTED)        
   21.14  
   21.15 -    def host_dmesg(self, session, host_ref, clear):
   21.16 -        if clear:
   21.17 -            return xen_api_success(XendDmesg.instance().clear())
   21.18 -        else:
   21.19 -            return xen_api_success(XendDmesg.instance().info())
   21.20 +    def host_dmesg(self, session, host_ref):
   21.21 +        return xen_api_success(XendDmesg.instance().info())
   21.22 +
   21.23 +    def host_dmesg_clear(self, session, host_ref):
   21.24 +        return xen_api_success(XendDmesg.instance().clear())
   21.25  
   21.26      def host_get_log(self, session, host_ref):
   21.27          log_file = open(XendLogging.getLogFilename())
    22.1 --- a/tools/python/xen/xend/XendDmesg.py	Thu Mar 22 09:28:05 2007 -0600
    22.2 +++ b/tools/python/xen/xend/XendDmesg.py	Thu Mar 22 09:30:54 2007 -0600
    22.3 @@ -13,6 +13,7 @@
    22.4  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    22.5  #============================================================================
    22.6  # Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
    22.7 +# Copyright (C) 2007       XenSource Inc.
    22.8  #============================================================================
    22.9  
   22.10  """Get dmesg output for this node.
   22.11 @@ -28,7 +29,7 @@ class XendDmesg:
   22.12          return self.xc.readconsolering()
   22.13  
   22.14      def clear(self):
   22.15 -        self.xc.readconsolering(True)
   22.16 +        return self.xc.readconsolering(True)
   22.17  
   22.18  def instance():
   22.19      global inst
    23.1 --- a/tools/python/xen/xend/image.py	Thu Mar 22 09:28:05 2007 -0600
    23.2 +++ b/tools/python/xen/xend/image.py	Thu Mar 22 09:30:54 2007 -0600
    23.3 @@ -228,35 +228,6 @@ class PPC_LinuxImageHandler(LinuxImageHa
    23.4  
    23.5  
    23.6  
    23.7 -class PPC_ProseImageHandler(PPC_LinuxImageHandler):
    23.8 -
    23.9 -    ostype = "prose"
   23.10 -
   23.11 -    def buildDomain(self):
   23.12 -        store_evtchn = self.vm.getStorePort()
   23.13 -        console_evtchn = self.vm.getConsolePort()
   23.14 -
   23.15 -        mem_mb = self.getRequiredInitialReservation() / 1024
   23.16 -
   23.17 -        log.debug("dom            = %d", self.vm.getDomid())
   23.18 -        log.debug("memsize        = %d", mem_mb)
   23.19 -        log.debug("image          = %s", self.kernel)
   23.20 -        log.debug("store_evtchn   = %d", store_evtchn)
   23.21 -        log.debug("console_evtchn = %d", console_evtchn)
   23.22 -        log.debug("cmdline        = %s", self.cmdline)
   23.23 -        log.debug("ramdisk        = %s", self.ramdisk)
   23.24 -        log.debug("vcpus          = %d", self.vm.getVCpuCount())
   23.25 -        log.debug("features       = %s", self.vm.getFeatures())
   23.26 -
   23.27 -        return xc.arch_prose_build(dom            = self.vm.getDomid(),
   23.28 -                                   memsize        = mem_mb,
   23.29 -                                   image          = self.kernel,
   23.30 -                                   store_evtchn   = store_evtchn,
   23.31 -                                   console_evtchn = console_evtchn,
   23.32 -                                   cmdline        = self.cmdline,
   23.33 -                                   ramdisk        = self.ramdisk,
   23.34 -                                   features       = self.vm.getFeatures())
   23.35 -
   23.36  class HVMImageHandler(ImageHandler):
   23.37  
   23.38      ostype = "hvm"
   23.39 @@ -613,7 +584,6 @@ class X86_Linux_ImageHandler(LinuxImageH
   23.40  _handlers = {
   23.41      "powerpc": {
   23.42          "linux": PPC_LinuxImageHandler,
   23.43 -        "prose": PPC_ProseImageHandler,
   23.44      },
   23.45      "ia64": {
   23.46          "linux": LinuxImageHandler,
    24.1 --- a/tools/python/xen/xm/main.py	Thu Mar 22 09:28:05 2007 -0600
    24.2 +++ b/tools/python/xen/xm/main.py	Thu Mar 22 09:30:54 2007 -0600
    24.3 @@ -217,7 +217,7 @@ SUBCOMMAND_OPTIONS = {
    24.4         ('-q', '--quiet', 'Do not print an error message if the domain does not exist'),
    24.5      ),
    24.6      'dmesg': (
    24.7 -       ('-c', '--clear', 'Clear dmesg buffer'),
    24.8 +       ('-c', '--clear', 'Clear dmesg buffer as well as printing it'),
    24.9      ),
   24.10      'vnet-list': (
   24.11         ('-l', '--long', 'List Vnets as SXP'),
   24.12 @@ -1587,17 +1587,16 @@ def xm_dmesg(args):
   24.13          usage('dmesg')
   24.14  
   24.15      if serverType == SERVER_XEN_API:
   24.16 -        if not use_clear:
   24.17 -            print server.xenapi.host.dmesg(
   24.18 -                server.xenapi.session.get_this_host(),0)
   24.19 +        host = server.xenapi.session.get_this_host()
   24.20 +        if use_clear:
   24.21 +            print server.xenapi.host.dmesg_clear(host),
   24.22          else:
   24.23 -            server.xenapi.host.dmesg(
   24.24 -                server.xenapi.session.get_this_host(),1)
   24.25 +            print server.xenapi.host.dmesg(host),
   24.26      else:
   24.27          if not use_clear:
   24.28 -            print server.xend.node.dmesg.info()
   24.29 +            print server.xend.node.dmesg.info(),
   24.30          else:
   24.31 -            server.xend.node.dmesg.clear()
   24.32 +            print server.xend.node.dmesg.clear(),
   24.33  
   24.34  def xm_log(args):
   24.35      arg_check(args, "log", 0)
    25.1 --- a/xen/arch/powerpc/backtrace.c	Thu Mar 22 09:28:05 2007 -0600
    25.2 +++ b/xen/arch/powerpc/backtrace.c	Thu Mar 22 09:30:54 2007 -0600
    25.3 @@ -222,8 +222,7 @@ void __warn(char *file, int line)
    25.4  
    25.5  void dump_execution_state(void)
    25.6  {
    25.7 -    struct vcpu *v = current;
    25.8 -    struct cpu_user_regs *regs = &v->arch.ctxt;
    25.9 +    struct cpu_user_regs *regs = guest_cpu_user_regs();
   25.10  
   25.11      show_registers(regs);
   25.12      if (regs->msr & MSR_HV) {
    26.1 --- a/xen/arch/powerpc/mm.c	Thu Mar 22 09:28:05 2007 -0600
    26.2 +++ b/xen/arch/powerpc/mm.c	Thu Mar 22 09:30:54 2007 -0600
    26.3 @@ -401,9 +401,13 @@ int allocate_rma(struct domain *d, unsig
    26.4  
    26.5  void free_rma_check(struct page_info *page)
    26.6  {
    26.7 -    if (test_bit(_PGC_page_RMA, &page->count_info) &&
    26.8 -        !test_bit(_DOMF_dying, &page_get_owner(page)->domain_flags))
    26.9 -        panic("Attempt to free an RMA page: 0x%lx\n", page_to_mfn(page));
   26.10 +    if (test_bit(_PGC_page_RMA, &page->count_info)) {
   26.11 +        if (!test_bit(_DOMF_dying, &page_get_owner(page)->domain_flags)) {
   26.12 +            panic("Attempt to free an RMA page: 0x%lx\n", page_to_mfn(page));
   26.13 +        } else {
   26.14 +            clear_bit(_PGC_page_RMA, &page->count_info);
   26.15 +        }
   26.16 +    }
   26.17  }
   26.18  
   26.19  ulong pfn2mfn(struct domain *d, ulong pfn, int *type)
    27.1 --- a/xen/arch/powerpc/setup.c	Thu Mar 22 09:28:05 2007 -0600
    27.2 +++ b/xen/arch/powerpc/setup.c	Thu Mar 22 09:30:54 2007 -0600
    27.3 @@ -37,6 +37,7 @@
    27.4  #include <xen/keyhandler.h>
    27.5  #include <xen/numa.h>
    27.6  #include <xen/rcupdate.h>
    27.7 +#include <xen/version.h>
    27.8  #include <acm/acm_hooks.h>
    27.9  #include <public/version.h>
   27.10  #include <asm/mpic.h>
   27.11 @@ -450,6 +451,14 @@ void __init __start_xen_ppc(
   27.12  extern void arch_get_xen_caps(xen_capabilities_info_t *info);
   27.13  void arch_get_xen_caps(xen_capabilities_info_t *info)
   27.14  {
   27.15 +    int major = xen_major_version();
   27.16 +    int minor = xen_minor_version();
   27.17 +    char s[32];
   27.18 +
   27.19 +    (*info)[0] = '\0';
   27.20 +
   27.21 +    snprintf(s, sizeof(s), "xen-%d.%d-powerpc64 ", major, minor);
   27.22 +    safe_strcat(*info, s);
   27.23  }
   27.24  
   27.25  
    28.1 --- a/xen/arch/powerpc/smp-tbsync.c	Thu Mar 22 09:28:05 2007 -0600
    28.2 +++ b/xen/arch/powerpc/smp-tbsync.c	Thu Mar 22 09:30:54 2007 -0600
    28.3 @@ -32,6 +32,13 @@
    28.4  
    28.5  #define NUM_ITER		300
    28.6  
    28.7 +#undef DEBUG
    28.8 +#ifdef DEBUG
    28.9 +#define DBG(fmt...) printk(fmt)
   28.10 +#else
   28.11 +#define DBG(fmt...)
   28.12 +#endif
   28.13 +
   28.14  enum {
   28.15  	kExit=0, kSetAndTest, kTest
   28.16  };
   28.17 @@ -128,7 +135,7 @@ void __devinit smp_generic_give_timebase
   28.18  {
   28.19  	int i, score, score2, old, min=0, max=5000, offset=1000;
   28.20  
   28.21 -	printk("Synchronizing timebase\n");
   28.22 +	printk("Synchronizing timebase...\n");
   28.23  
   28.24  	/* if this fails then this kernel won't work anyway... */
   28.25  	tbsync = kmalloc( sizeof(*tbsync), GFP_KERNEL );
   28.26 @@ -139,13 +146,13 @@ void __devinit smp_generic_give_timebase
   28.27  	while (!tbsync->ack)
   28.28  		barrier();
   28.29  
   28.30 -	printk("Got ack\n");
   28.31 +	DBG("Got ack\n");
   28.32  
   28.33  	/* binary search */
   28.34  	for (old = -1; old != offset ; offset = (min+max) / 2) {
   28.35  		score = start_contest(kSetAndTest, offset, NUM_ITER);
   28.36  
   28.37 -		printk("score %d, offset %d\n", score, offset );
   28.38 +		DBG("score %d, offset %d\n", score, offset );
   28.39  
   28.40  		if( score > 0 )
   28.41  			max = offset;
   28.42 @@ -156,7 +163,7 @@ void __devinit smp_generic_give_timebase
   28.43  	score = start_contest(kSetAndTest, min, NUM_ITER);
   28.44  	score2 = start_contest(kSetAndTest, max, NUM_ITER);
   28.45  
   28.46 -	printk("Min %d (score %d), Max %d (score %d)\n",
   28.47 +	DBG("Min %d (score %d), Max %d (score %d)\n",
   28.48  	       min, score, max, score2);
   28.49  	score = abs(score);
   28.50  	score2 = abs(score2);
   28.51 @@ -171,7 +178,7 @@ void __devinit smp_generic_give_timebase
   28.52  		if (score2 <= score || score2 < 20)
   28.53  			break;
   28.54  	}
   28.55 -	printk("Final offset: %d (%d/%d)\n", offset, score2, NUM_ITER );
   28.56 +	DBG("Final offset: %d (%d/%d)\n", offset, score2, NUM_ITER );
   28.57  
   28.58  	/* exiting */
   28.59  	tbsync->cmd = kExit;
    29.1 --- a/xen/arch/x86/mm/shadow/types.h	Thu Mar 22 09:28:05 2007 -0600
    29.2 +++ b/xen/arch/x86/mm/shadow/types.h	Thu Mar 22 09:30:54 2007 -0600
    29.3 @@ -597,7 +597,7 @@ accumulate_guest_flags(struct vcpu *v, w
    29.4   * have reserved bits that we can use for this.
    29.5   */
    29.6  
    29.7 -#define SH_L1E_MAGIC 0xffffffff00000000ULL
    29.8 +#define SH_L1E_MAGIC 0xffffffff00000001ULL
    29.9  static inline int sh_l1e_is_magic(shadow_l1e_t sl1e)
   29.10  {
   29.11      return ((sl1e.l1 & SH_L1E_MAGIC) == SH_L1E_MAGIC);