ia64/xen-unstable

annotate tools/libxc/powerpc64/xc_prose_build.c @ 13939:09b3fd488726

[XEND][POWERPC] Remove FlatDeviceTree.py, eliminate devtree from prose builder.

Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
Signed-off-by: Jimi Xenidis <jimix@watson.ibm.com>
author Jimi Xenidis <jimix@watson.ibm.com>
date Sun Jan 21 08:15:39 2007 -0500 (2007-01-21)
parents a510c94ceaa3
children
rev   line source
jimix@12951 1 /*
jimix@12951 2 * This program is free software; you can redistribute it and/or modify
jimix@12951 3 * it under the terms of the GNU General Public License as published by
jimix@12951 4 * the Free Software Foundation; either version 2 of the License, or
jimix@12951 5 * (at your option) any later version.
jimix@12951 6 *
jimix@12951 7 * This program is distributed in the hope that it will be useful,
jimix@12951 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jimix@12951 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
jimix@12951 10 * GNU General Public License for more details.
jimix@12951 11 *
jimix@12951 12 * You should have received a copy of the GNU General Public License
jimix@12951 13 * along with this program; if not, write to the Free Software
jimix@12951 14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
jimix@12951 15 *
jimix@13939 16 * Copyright IBM Corporation 2006, 2007
jimix@12951 17 *
jimix@12951 18 * Authors: Hollis Blanchard <hollisb@us.ibm.com>
jimix@12955 19 * Jonathan Appavoo <jappavoo@us.ibm.com>
jimix@12951 20 */
jimix@12951 21
jimix@12951 22 #include <stdio.h>
jimix@12951 23 #include <stdint.h>
jimix@12951 24 #include <stdlib.h>
jimix@12951 25 #include <string.h>
jimix@12951 26 #include <unistd.h>
jimix@12951 27 #include <fcntl.h>
jimix@12951 28 #include <sys/types.h>
jimix@12951 29 #include <inttypes.h>
jimix@12951 30
jimix@12951 31 #include <xen/xen.h>
jimix@12951 32 #include <xen/memory.h>
jimix@12951 33 #include <xc_private.h>
jimix@12951 34 #include <xg_private.h>
jimix@12951 35 #include <xenctrl.h>
jimix@12951 36
jimix@12953 37 #include "utils.h"
jimix@12951 38
jimix@12951 39 #define INITRD_ADDR (24UL << 20)
jimix@12951 40
jimix@12951 41 static int init_boot_vcpu(
jimix@12951 42 int xc_handle,
jimix@12951 43 int domid,
jimix@12951 44 struct domain_setup_info *dsi,
jimix@12951 45 unsigned long kern_addr)
jimix@12951 46 {
jimix@12951 47 vcpu_guest_context_t ctxt;
jimix@12951 48 int rc;
jimix@12951 49
jimix@12951 50 memset(&ctxt.user_regs, 0x55, sizeof(ctxt.user_regs));
jimix@12951 51 ctxt.user_regs.pc = dsi->v_kernentry;
jimix@12951 52 ctxt.user_regs.msr = 0;
jimix@12951 53 ctxt.user_regs.gprs[1] = 0; /* Linux uses its own stack */
jimix@13939 54 ctxt.user_regs.gprs[3] = 0;
jimix@12951 55 ctxt.user_regs.gprs[4] = kern_addr;
jimix@12951 56 ctxt.user_regs.gprs[5] = 0; /* reserved for specifying OF handler */
jimix@12951 57 /* There is a buggy kernel that does not zero the "local_paca", so
jimix@12951 58 * we must make sure this register is 0 */
jimix@12951 59 ctxt.user_regs.gprs[13] = 0;
jimix@12951 60
jimix@12951 61 DPRINTF("xc_vcpu_setvcpucontext:\n"
jimix@12951 62 " pc 0x%016"PRIx64", msr 0x%016"PRIx64"\n"
jimix@12951 63 " r1-5 %016"PRIx64" %016"PRIx64" %016"PRIx64" %016"PRIx64
jimix@12951 64 " %016"PRIx64"\n",
jimix@12951 65 ctxt.user_regs.pc, ctxt.user_regs.msr,
jimix@12951 66 ctxt.user_regs.gprs[1],
jimix@12951 67 ctxt.user_regs.gprs[2],
jimix@12951 68 ctxt.user_regs.gprs[3],
jimix@12951 69 ctxt.user_regs.gprs[4],
jimix@12951 70 ctxt.user_regs.gprs[5]);
jimix@12951 71 rc = xc_vcpu_setcontext(xc_handle, domid, 0, &ctxt);
jimix@12951 72 if (rc < 0)
jimix@12951 73 perror("setdomaininfo");
jimix@12951 74
jimix@12951 75 return rc;
jimix@12951 76 }
jimix@12951 77
jimix@12951 78 static int load_initrd(
jimix@12951 79 int xc_handle,
jimix@12951 80 int domid,
jimix@12951 81 xen_pfn_t *page_array,
jimix@12951 82 const char *initrd_path,
jimix@12951 83 unsigned long *base,
jimix@12951 84 unsigned long *len)
jimix@12951 85 {
jimix@12951 86 uint8_t *initrd_img;
jimix@12951 87 int rc = -1;
jimix@12951 88
jimix@12951 89 /* load the initrd file */
jimix@12951 90 initrd_img = load_file(initrd_path, len);
jimix@12951 91 if (initrd_img == NULL)
jimix@12951 92 return -1;
jimix@12951 93
jimix@12951 94 DPRINTF("copying initrd to 0x%lx[0x%lx]\n", INITRD_ADDR, *len);
jimix@12951 95 if (install_image(xc_handle, domid, page_array, initrd_img, INITRD_ADDR,
jimix@12951 96 *len))
jimix@12951 97 goto out;
jimix@12951 98
jimix@12951 99 *base = INITRD_ADDR;
jimix@12951 100 rc = 0;
jimix@12951 101
jimix@12951 102 out:
jimix@12951 103 free(initrd_img);
jimix@12951 104 return rc;
jimix@12951 105 }
jimix@12951 106
jimix@12953 107 static unsigned long create_start_info(
jimix@13939 108 start_info_t *start_info,
jimix@12951 109 unsigned int console_evtchn, unsigned int store_evtchn,
jimix@12953 110 unsigned long nr_pages, unsigned long rma_pages, const char *cmdline)
jimix@12951 111 {
jimix@12952 112 unsigned long start_info_addr;
jimix@12951 113 uint64_t rma_top;
jimix@12951 114
jimix@12952 115 memset(start_info, 0, sizeof(*start_info));
jimix@12952 116 snprintf(start_info->magic, sizeof(start_info->magic),
jimix@12952 117 "xen-%d.%d-powerpc64HV", 3, 0);
jimix@12951 118
jimix@12953 119 rma_top = rma_pages << PAGE_SHIFT;
jimix@12951 120 DPRINTF("RMA top = 0x%"PRIX64"\n", rma_top);
jimix@12951 121
jimix@12952 122 start_info->nr_pages = nr_pages;
jimix@12952 123 start_info->shared_info = rma_top - PAGE_SIZE;
jimix@12952 124 start_info->store_mfn = (rma_top >> PAGE_SHIFT) - 2;
jimix@12952 125 start_info->store_evtchn = store_evtchn;
jimix@12952 126 start_info->console.domU.mfn = (rma_top >> PAGE_SHIFT) - 3;
jimix@12952 127 start_info->console.domU.evtchn = console_evtchn;
jimix@12955 128 strncpy((char *)start_info->cmd_line, cmdline, MAX_GUEST_CMDLINE);
jimix@12955 129 /* just in case we truncated cmdline with strncpy add 0 at the end */
jimix@12955 130 start_info->cmd_line[MAX_GUEST_CMDLINE-1]=0;
jimix@12952 131 start_info_addr = rma_top - 4*PAGE_SIZE;
jimix@12951 132
jimix@12952 133 return start_info_addr;
jimix@12951 134 }
jimix@12951 135
jimix@12951 136 static void free_page_array(xen_pfn_t *page_array)
jimix@12951 137 {
jimix@12951 138 free(page_array);
jimix@12951 139 }
jimix@12951 140
jimix@12951 141 int xc_prose_build(int xc_handle,
jimix@12951 142 uint32_t domid,
hollisb@12976 143 unsigned int mem_mb,
jimix@12951 144 const char *image_name,
jimix@12951 145 const char *initrd_name,
jimix@12951 146 const char *cmdline,
jimix@12951 147 const char *features,
jimix@12951 148 unsigned long flags,
jimix@12951 149 unsigned int store_evtchn,
jimix@12951 150 unsigned long *store_mfn,
jimix@12951 151 unsigned int console_evtchn,
jimix@13939 152 unsigned long *console_mfn)
jimix@12951 153 {
jimix@12952 154 start_info_t start_info;
jimix@12951 155 struct domain_setup_info dsi;
jimix@12951 156 xen_pfn_t *page_array = NULL;
jimix@12951 157 unsigned long nr_pages;
jimix@12951 158 unsigned long kern_addr;
jimix@12951 159 unsigned long initrd_base = 0;
jimix@12951 160 unsigned long initrd_len = 0;
jimix@12952 161 unsigned long start_info_addr;
jimix@12953 162 unsigned long rma_pages;
jimix@12951 163 int rc = 0;
jimix@12951 164
jimix@12951 165 DPRINTF("%s\n", __func__);
jimix@12951 166
jimix@12951 167 DPRINTF("cmdline=%s\n", cmdline);
jimix@12951 168
hollisb@12976 169 nr_pages = mem_mb << (20 - PAGE_SHIFT);
jimix@12953 170 DPRINTF("nr_pages 0x%lx\n", nr_pages);
jimix@12953 171
jimix@13939 172 rma_pages = (1 << 26) >> PAGE_SHIFT; /* 64 MB */
jimix@12953 173
jimix@12953 174 if (get_rma_page_array(xc_handle, domid, &page_array, rma_pages)) {
jimix@12951 175 rc = -1;
jimix@12951 176 goto out;
jimix@12951 177 }
jimix@12951 178
jimix@12951 179 DPRINTF("loading image '%s'\n", image_name);
jimix@12953 180 if (load_elf_kernel(xc_handle, domid, image_name, &dsi, page_array)) {
jimix@12951 181 rc = -1;
jimix@12951 182 goto out;
jimix@12951 183 }
jimix@12951 184 kern_addr = 0;
jimix@12951 185
jimix@12951 186 if (initrd_name && initrd_name[0] != '\0') {
jimix@12951 187 DPRINTF("loading initrd '%s'\n", initrd_name);
jimix@12951 188 if (load_initrd(xc_handle, domid, page_array, initrd_name,
jimix@12951 189 &initrd_base, &initrd_len)) {
jimix@12951 190 rc = -1;
jimix@12951 191 goto out;
jimix@12951 192 }
jimix@12951 193 }
jimix@12951 194
jimix@12951 195 /* start_info stuff: about to be removed */
jimix@13939 196 start_info_addr = create_start_info(&start_info, console_evtchn,
jimix@12953 197 store_evtchn, nr_pages,
jimix@13939 198 rma_pages, cmdline);
jimix@12952 199 *console_mfn = page_array[start_info.console.domU.mfn];
jimix@12952 200 *store_mfn = page_array[start_info.store_mfn];
jimix@12952 201 if (install_image(xc_handle, domid, page_array, &start_info,
jimix@12952 202 start_info_addr, sizeof(start_info_t))) {
jimix@12951 203 rc = -1;
jimix@12951 204 goto out;
jimix@12951 205 }
jimix@12951 206
jimix@13939 207 if (init_boot_vcpu(xc_handle, domid, &dsi, kern_addr)) {
jimix@12951 208 rc = -1;
jimix@12951 209 goto out;
jimix@12951 210 }
jimix@12951 211
jimix@12951 212 out:
jimix@12951 213 free_page_array(page_array);
jimix@12951 214 return rc;
jimix@12951 215 }