ia64/xen-unstable

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