direct-io.hg

view tools/libxc/xc_ia64_stubs.c @ 8500:dd5649730b32

Fix a couple of bogus dom0_op names:
setdomaininfo -> setvcpucontext
pincpudomain -> setvcpuaffinity

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Fri Jan 06 12:53:19 2006 +0100 (2006-01-06)
parents f7c2cbb5368f
children a51fcb5de470
line source
1 #include "xg_private.h"
2 #include "xenguest.h"
3 #include "xc_private.h"
4 #include "xc_elf.h"
5 #include <stdlib.h>
6 #include <zlib.h>
7 #include "xen/arch-ia64.h"
8 #include <xen/hvm/ioreq.h>
10 /* this is a very ugly way of getting FPSR_DEFAULT. struct ia64_fpreg is
11 * mysteriously declared in two places: /usr/include/asm/fpu.h and
12 * /usr/include/bits/sigcontext.h. The former also defines FPSR_DEFAULT,
13 * the latter doesn't but is included (indirectly) by xg_private.h */
14 #define __ASSEMBLY__
15 #include <asm/fpu.h>
16 #undef __IA64_UL
17 #define __IA64_UL(x) ((unsigned long)(x))
18 #undef __ASSEMBLY__
20 unsigned long xc_ia64_fpsr_default(void)
21 {
22 return FPSR_DEFAULT;
23 }
25 int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
26 uint32_t max_factor, uint32_t flags)
27 {
28 PERROR("xc_linux_save not implemented\n");
29 return -1;
30 }
32 int xc_linux_restore(int xc_handle, int io_fd, uint32_t dom, unsigned long nr_pfns,
33 unsigned int store_evtchn, unsigned long *store_mfn,
34 unsigned int console_evtchn, unsigned long *console_mfn)
35 {
36 PERROR("xc_linux_restore not implemented\n");
37 return -1;
38 }
40 int
41 xc_plan9_build(int xc_handle,
42 uint32_t domid,
43 const char *image_name,
44 const char *cmdline,
45 unsigned int control_evtchn, unsigned long flags)
46 {
47 PERROR("xc_plan9_build not implemented\n");
48 return -1;
49 }
51 int xc_ia64_get_pfn_list(int xc_handle,
52 uint32_t domid,
53 unsigned long *pfn_buf,
54 unsigned int start_page,
55 unsigned int nr_pages)
56 {
57 dom0_op_t op;
58 int ret;
59 unsigned long max_pfns = ((unsigned long)start_page << 32) | nr_pages;
61 op.cmd = DOM0_GETMEMLIST;
62 op.u.getmemlist.domain = (domid_t)domid;
63 op.u.getmemlist.max_pfns = max_pfns;
64 op.u.getmemlist.buffer = pfn_buf;
66 if ( (max_pfns != -1UL)
67 && mlock(pfn_buf, nr_pages * sizeof(unsigned long)) != 0 )
68 {
69 PERROR("Could not lock pfn list buffer");
70 return -1;
71 }
73 ret = do_dom0_op(xc_handle, &op);
75 if (max_pfns != -1UL)
76 (void)munlock(pfn_buf, nr_pages * sizeof(unsigned long));
78 return (ret < 0) ? -1 : op.u.getmemlist.num_pfns;
79 }
81 long xc_get_max_pages(int xc_handle, uint32_t domid)
82 {
83 dom0_op_t op;
84 op.cmd = DOM0_GETDOMAININFO;
85 op.u.getdomaininfo.domain = (domid_t)domid;
86 return (do_dom0_op(xc_handle, &op) < 0) ?
87 -1 : op.u.getdomaininfo.max_pages;
88 }
90 int xc_ia64_copy_to_domain_pages(int xc_handle, uint32_t domid,
91 void* src_page, unsigned long dst_pfn, int nr_pages)
92 {
93 // N.B. gva should be page aligned
95 unsigned long *page_array = NULL;
96 int i;
98 if ( (page_array = malloc(nr_pages * sizeof(unsigned long))) == NULL ){
99 PERROR("Could not allocate memory");
100 goto error_out;
101 }
102 if ( xc_ia64_get_pfn_list(xc_handle, domid, page_array,
103 dst_pfn>>PAGE_SHIFT, nr_pages) != nr_pages ){
104 PERROR("Could not get the page frame list");
105 goto error_out;
106 }
108 for ( i=0; i< nr_pages; i++ ){
109 if (xc_copy_to_domain_page(xc_handle, domid, page_array[i],
110 src_page + (i << PAGE_SHIFT)))
111 goto error_out;
112 }
113 free(page_array);
114 return 0;
116 error_out:
117 free(page_array);
118 return -1;
119 }
122 #define HOB_SIGNATURE 0x3436474953424f48 // "HOBSIG64"
123 #define GFW_HOB_START ((4UL<<30)-(14UL<<20)) //4G -14M
124 #define GFW_HOB_SIZE (1UL<<20) //1M
125 #define MEM_G (1UL << 30)
126 #define MEM_M (1UL << 20)
128 typedef struct {
129 unsigned long signature;
130 unsigned int type;
131 unsigned int length;
132 } HOB_GENERIC_HEADER;
134 /*
135 * INFO HOB is the first data data in one HOB list
136 * it contains the control information of the HOB list
137 */
138 typedef struct {
139 HOB_GENERIC_HEADER header;
140 unsigned long length; // current length of hob
141 unsigned long cur_pos; // current poisiton of hob
142 unsigned long buf_size; // size of hob buffer
143 }HOB_INFO;
145 typedef struct{
146 unsigned long start;
147 unsigned long size;
148 }hob_mem_t;
150 typedef enum {
151 HOB_TYPE_INFO=0,
152 HOB_TYPE_TERMINAL,
153 HOB_TYPE_MEM,
154 HOB_TYPE_PAL_BUS_GET_FEATURES_DATA,
155 HOB_TYPE_PAL_CACHE_SUMMARY,
156 HOB_TYPE_PAL_MEM_ATTRIB,
157 HOB_TYPE_PAL_CACHE_INFO,
158 HOB_TYPE_PAL_CACHE_PROT_INFO,
159 HOB_TYPE_PAL_DEBUG_INFO,
160 HOB_TYPE_PAL_FIXED_ADDR,
161 HOB_TYPE_PAL_FREQ_BASE,
162 HOB_TYPE_PAL_FREQ_RATIOS,
163 HOB_TYPE_PAL_HALT_INFO,
164 HOB_TYPE_PAL_PERF_MON_INFO,
165 HOB_TYPE_PAL_PROC_GET_FEATURES,
166 HOB_TYPE_PAL_PTCE_INFO,
167 HOB_TYPE_PAL_REGISTER_INFO,
168 HOB_TYPE_PAL_RSE_INFO,
169 HOB_TYPE_PAL_TEST_INFO,
170 HOB_TYPE_PAL_VM_SUMMARY,
171 HOB_TYPE_PAL_VM_INFO,
172 HOB_TYPE_PAL_VM_PAGE_SIZE,
173 HOB_TYPE_MAX
174 }hob_type_t;
176 static int hob_init( void *buffer ,unsigned long buf_size);
177 static int add_pal_hob(void* hob_buf);
178 static int add_mem_hob(void* hob_buf, unsigned long dom_mem_size);
179 static int build_hob (void* hob_buf, unsigned long hob_buf_size,
180 unsigned long dom_mem_size);
181 static int load_hob(int xc_handle,uint32_t dom, void *hob_buf);
183 int xc_ia64_build_hob(int xc_handle, uint32_t dom, unsigned long memsize){
185 char *hob_buf;
187 hob_buf = malloc (GFW_HOB_SIZE);
188 if (hob_buf == NULL) {
189 PERROR("Could not allocate hob");
190 return -1;
191 }
193 if ( build_hob( hob_buf, GFW_HOB_SIZE, memsize<<20) < 0){
194 free (hob_buf);
195 PERROR("Could not build hob");
196 return -1;
197 }
199 if ( load_hob( xc_handle, dom, hob_buf) <0){
200 free (hob_buf);
201 PERROR("Could not load hob");
202 return -1;
203 }
204 free (hob_buf);
205 return 0;
207 }
208 static int
209 hob_init( void *buffer ,unsigned long buf_size)
210 {
211 HOB_INFO *phit;
212 HOB_GENERIC_HEADER *terminal;
214 if (sizeof(HOB_INFO) + sizeof(HOB_GENERIC_HEADER) > buf_size){
215 // buffer too small
216 return -1;
217 }
219 phit = (HOB_INFO*)buffer;
220 phit->header.signature = HOB_SIGNATURE;
221 phit->header.type = HOB_TYPE_INFO;
222 phit->header.length = sizeof(HOB_INFO);
223 phit->length = sizeof(HOB_INFO) + sizeof(HOB_GENERIC_HEADER);
224 phit->cur_pos = 0;
225 phit->buf_size = buf_size;
227 terminal = (HOB_GENERIC_HEADER*) (buffer + sizeof(HOB_INFO));
228 terminal->signature= HOB_SIGNATURE;
229 terminal->type = HOB_TYPE_TERMINAL;
230 terminal->length = sizeof(HOB_GENERIC_HEADER);
232 return 0;
233 }
235 /*
236 * Add a new HOB to the HOB List.
237 *
238 * hob_start - start address of hob buffer
239 * type - type of the hob to be added
240 * data - data of the hob to be added
241 * data_size - size of the data
242 */
243 static int
244 hob_add(
245 void* hob_start,
246 int type,
247 void* data,
248 int data_size
249 )
250 {
251 HOB_INFO *phit;
252 HOB_GENERIC_HEADER *newhob,*tail;
254 phit = (HOB_INFO*)hob_start;
256 if (phit->length + data_size > phit->buf_size){
257 // no space for new hob
258 return -1;
259 }
261 //append new HOB
262 newhob = (HOB_GENERIC_HEADER*)
263 (hob_start + phit->length - sizeof(HOB_GENERIC_HEADER));
264 newhob->signature = HOB_SIGNATURE;
265 newhob->type = type;
266 newhob->length = data_size + sizeof(HOB_GENERIC_HEADER);
267 memcpy((void*)newhob + sizeof(HOB_GENERIC_HEADER), data, data_size);
269 // append terminal HOB
270 tail = (HOB_GENERIC_HEADER*) ( hob_start + phit->length + data_size);
271 tail->signature = HOB_SIGNATURE;
272 tail->type = HOB_TYPE_TERMINAL;
273 tail->length = sizeof(HOB_GENERIC_HEADER);
275 // adjust HOB list length
276 phit->length += sizeof(HOB_GENERIC_HEADER)+ data_size;
278 return 0;
280 }
282 int get_hob_size(void* hob_buf){
284 HOB_INFO *phit = (HOB_INFO*)hob_buf;
286 if (phit->header.signature != HOB_SIGNATURE){
287 PERROR("xc_get_hob_size:Incorrect signature");
288 return -1;
289 }
290 return phit->length;
291 }
293 int build_hob (void* hob_buf, unsigned long hob_buf_size,
294 unsigned long dom_mem_size)
295 {
296 //Init HOB List
297 if (hob_init (hob_buf, hob_buf_size)<0){
298 PERROR("buffer too small");
299 goto err_out;
300 }
302 if ( add_mem_hob( hob_buf,dom_mem_size) < 0){
303 PERROR("Add memory hob failed, buffer too small");
304 goto err_out;
305 }
307 if ( add_pal_hob( hob_buf ) < 0 ){
308 PERROR("Add PAL hob failed, buffer too small");
309 goto err_out;
310 }
312 return 0;
314 err_out:
315 return -1;
316 }
318 static int
319 load_hob(int xc_handle, uint32_t dom, void *hob_buf)
320 {
321 // hob_buf should be page aligned
322 int hob_size;
323 int nr_pages;
325 if ((hob_size = get_hob_size(hob_buf)) < 0){
326 PERROR("Invalid hob data");
327 return -1;
328 }
330 if (hob_size > GFW_HOB_SIZE){
331 PERROR("No enough memory for hob data");
332 return -1;
333 }
335 nr_pages = (hob_size + PAGE_SIZE -1) >> PAGE_SHIFT;
337 return xc_ia64_copy_to_domain_pages(xc_handle, dom,
338 hob_buf, GFW_HOB_START, nr_pages );
339 }
341 #define MIN(x, y) ((x) < (y)) ? (x) : (y)
342 static int
343 add_mem_hob(void* hob_buf, unsigned long dom_mem_size){
344 hob_mem_t memhob;
346 // less than 3G
347 memhob.start = 0;
348 memhob.size = MIN(dom_mem_size, 0xC0000000);
350 if (hob_add(hob_buf, HOB_TYPE_MEM, &memhob, sizeof(memhob)) < 0){
351 return -1;
352 }
354 if (dom_mem_size > 0xC0000000) {
355 // 4G ~ 4G+remain
356 memhob.start = 0x100000000; //4G
357 memhob.size = dom_mem_size - 0xC0000000;
358 if (hob_add(hob_buf, HOB_TYPE_MEM, &memhob, sizeof(memhob)) < 0)
359 return -1;
360 }
361 return 0;
362 }
364 unsigned char config_pal_bus_get_features_data[24] = {
365 0, 0, 0, 32, 0, 0, 240, 189, 0, 0, 0, 0, 0, 0,
366 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
367 };
368 unsigned char config_pal_cache_summary[16] = {
369 3, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0};
370 unsigned char config_pal_mem_attrib[8] = {
371 241, 0, 0, 0, 0, 0, 0, 0
372 };
373 unsigned char config_pal_cache_info[152] = {
374 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
375 6, 4, 6, 7, 255, 1, 0, 1, 0, 64, 0, 0, 12, 12,
376 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 7, 0, 1,
377 0, 1, 0, 64, 0, 0, 12, 12, 49, 0, 0, 0, 0, 0, 0,
378 0, 0, 0, 6, 8, 7, 7, 255, 7, 0, 11, 0, 0, 16, 0,
379 12, 17, 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 8, 7,
380 7, 7, 5, 9, 11, 0, 0, 4, 0, 12, 15, 49, 0, 254, 255,
381 255, 255, 255, 255, 255, 255, 2, 8, 7, 7, 7, 5, 9,
382 11, 0, 0, 4, 0, 12, 15, 49, 0, 0, 0, 0, 0, 0, 0, 0,
383 0, 3, 12, 7, 7, 7, 14, 1, 3, 0, 0, 192, 0, 12, 20, 49, 0
384 };
385 unsigned char config_pal_cache_prot_info[200] = {
386 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
387 45, 0, 16, 8, 0, 76, 12, 64, 0, 0, 0, 0, 0, 0, 0,
388 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
389 8, 0, 16, 4, 0, 76, 44, 68, 0, 0, 0, 0, 0, 0, 0, 0,
390 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32,
391 0, 16, 8, 0, 81, 44, 72, 0, 0, 0, 0, 0, 0, 0, 0, 0,
392 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0,
393 112, 12, 0, 79, 124, 76, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
394 0, 0, 0, 0, 0, 0, 254, 255, 255, 255, 255, 255, 255, 255,
395 32, 0, 112, 12, 0, 79, 124, 76, 0, 0, 0, 0, 0, 0, 0, 0, 0,
396 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 160,
397 12, 0, 84, 124, 76, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
398 0, 0, 0
399 };
400 unsigned char config_pal_debug_info[16] = {
401 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0
402 };
403 unsigned char config_pal_fixed_addr[8] = {
404 0, 0, 0, 0, 0, 0, 0, 0
405 };
406 unsigned char config_pal_freq_base[8] = {
407 109, 219, 182, 13, 0, 0, 0, 0
408 };
409 unsigned char config_pal_freq_ratios[24] = {
410 11, 1, 0, 0, 77, 7, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 4,
411 0, 0, 0, 7, 0, 0, 0
412 };
413 unsigned char config_pal_halt_info[64] = {
414 0, 0, 0, 0, 0, 0, 0, 48, 0, 0, 0, 0, 0, 0, 0, 0,
415 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
416 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
417 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
418 };
419 unsigned char config_pal_perf_mon_info[136] = {
420 12, 47, 18, 8, 0, 0, 0, 0, 241, 255, 0, 0, 255, 7, 0, 0,
421 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
422 0, 0, 0, 0, 0, 0, 0, 0, 241, 255, 0, 0, 223, 0, 255, 255,
423 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
424 0, 0, 0, 0, 0, 0, 0, 0, 240, 255, 0, 0, 0, 0, 0, 0,
425 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
426 0, 0, 0, 0, 0, 0, 0, 0, 240, 255, 0, 0, 0, 0, 0, 0,
427 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
428 0, 0, 0, 0, 0, 0, 0, 0
429 };
430 unsigned char config_pal_proc_get_features[104] = {
431 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
432 0, 0, 0, 0, 64, 6, 64, 49, 0, 0, 0, 0, 64, 6, 0, 0,
433 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0,
434 231, 0, 0, 0, 0, 0, 0, 0, 228, 0, 0, 0, 0, 0, 0, 0,
435 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0, 0, 0, 0, 0, 0,
436 63, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0,
437 0, 0, 0, 0, 0, 0, 0, 0
438 };
439 unsigned char config_pal_ptce_info[24] = {
440 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0,
441 0, 0, 0, 0, 0, 0, 0, 0
442 };
443 unsigned char config_pal_register_info[64] = {
444 255, 0, 47, 127, 17, 17, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0,
445 255, 208, 128, 238, 238, 0, 0, 248, 255, 255, 255, 255, 255, 0, 0, 7, 3,
446 251, 3, 0, 0, 0, 0, 255, 7, 3, 0, 0, 0, 0, 0, 248, 252, 4,
447 252, 255, 255, 255, 255, 2, 248, 252, 255, 255, 255, 255, 255
448 };
449 unsigned char config_pal_rse_info[16] = {
450 96, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
451 };
452 unsigned char config_pal_test_info[48] = {
453 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
454 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
455 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
456 };
457 unsigned char config_pal_vm_summary[16] = {
458 101, 18, 15, 2, 7, 7, 4, 2, 59, 18, 0, 0, 0, 0, 0, 0
459 };
460 unsigned char config_pal_vm_info[104] = {
461 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
462 32, 32, 0, 0, 0, 0, 0, 0, 112, 85, 21, 0, 0, 0, 0, 0, 0,
463 0, 0, 0, 0, 0, 0, 1, 32, 32, 0, 0, 0, 0, 0, 0, 112, 85,
464 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 128, 128, 0,
465 4, 0, 0, 0, 0, 112, 85, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
466 0, 0, 0, 1, 128, 128, 0, 4, 0, 0, 0, 0, 112, 85, 0, 0, 0, 0, 0
467 };
468 unsigned char config_pal_vm_page_size[16] = {
469 0, 112, 85, 21, 0, 0, 0, 0, 0, 112, 85, 21, 0, 0, 0, 0
470 };
472 typedef struct{
473 hob_type_t type;
474 void* data;
475 unsigned long size;
476 }hob_batch_t;
478 hob_batch_t hob_batch[]={
479 { HOB_TYPE_PAL_BUS_GET_FEATURES_DATA,
480 &config_pal_bus_get_features_data,
481 sizeof(config_pal_bus_get_features_data)
482 },
483 { HOB_TYPE_PAL_CACHE_SUMMARY,
484 &config_pal_cache_summary,
485 sizeof(config_pal_cache_summary)
486 },
487 { HOB_TYPE_PAL_MEM_ATTRIB,
488 &config_pal_mem_attrib,
489 sizeof(config_pal_mem_attrib)
490 },
491 { HOB_TYPE_PAL_CACHE_INFO,
492 &config_pal_cache_info,
493 sizeof(config_pal_cache_info)
494 },
495 { HOB_TYPE_PAL_CACHE_PROT_INFO,
496 &config_pal_cache_prot_info,
497 sizeof(config_pal_cache_prot_info)
498 },
499 { HOB_TYPE_PAL_DEBUG_INFO,
500 &config_pal_debug_info,
501 sizeof(config_pal_debug_info)
502 },
503 { HOB_TYPE_PAL_FIXED_ADDR,
504 &config_pal_fixed_addr,
505 sizeof(config_pal_fixed_addr)
506 },
507 { HOB_TYPE_PAL_FREQ_BASE,
508 &config_pal_freq_base,
509 sizeof(config_pal_freq_base)
510 },
511 { HOB_TYPE_PAL_FREQ_RATIOS,
512 &config_pal_freq_ratios,
513 sizeof(config_pal_freq_ratios)
514 },
515 { HOB_TYPE_PAL_HALT_INFO,
516 &config_pal_halt_info,
517 sizeof(config_pal_halt_info)
518 },
519 { HOB_TYPE_PAL_PERF_MON_INFO,
520 &config_pal_perf_mon_info,
521 sizeof(config_pal_perf_mon_info)
522 },
523 { HOB_TYPE_PAL_PROC_GET_FEATURES,
524 &config_pal_proc_get_features,
525 sizeof(config_pal_proc_get_features)
526 },
527 { HOB_TYPE_PAL_PTCE_INFO,
528 &config_pal_ptce_info,
529 sizeof(config_pal_ptce_info)
530 },
531 { HOB_TYPE_PAL_REGISTER_INFO,
532 &config_pal_register_info,
533 sizeof(config_pal_register_info)
534 },
535 { HOB_TYPE_PAL_RSE_INFO,
536 &config_pal_rse_info,
537 sizeof(config_pal_rse_info)
538 },
539 { HOB_TYPE_PAL_TEST_INFO,
540 &config_pal_test_info,
541 sizeof(config_pal_test_info)
542 },
543 { HOB_TYPE_PAL_VM_SUMMARY,
544 &config_pal_vm_summary,
545 sizeof(config_pal_vm_summary)
546 },
547 { HOB_TYPE_PAL_VM_INFO,
548 &config_pal_vm_info,
549 sizeof(config_pal_vm_info)
550 },
551 { HOB_TYPE_PAL_VM_PAGE_SIZE,
552 &config_pal_vm_page_size,
553 sizeof(config_pal_vm_page_size)
554 },
555 };
557 static int add_pal_hob(void* hob_buf){
558 int i;
559 for (i=0; i<sizeof(hob_batch)/sizeof(hob_batch_t); i++){
560 if (hob_add(hob_buf, hob_batch[i].type,
561 hob_batch[i].data,
562 hob_batch[i].size)<0)
563 return -1;
564 }
565 return 0;
566 }
568 static int setup_guest( int xc_handle,
569 uint32_t dom, unsigned long memsize,
570 char *image, unsigned long image_size,
571 unsigned int control_evtchn,
572 unsigned int store_evtchn,
573 unsigned long *store_mfn)
574 {
575 unsigned long page_array[2];
576 shared_iopage_t *sp;
577 // FIXME: initialize pfn list for a temp hack
578 if (xc_ia64_get_pfn_list(xc_handle, dom, NULL, -1, -1) == -1) {
579 PERROR("Could not allocate continuous memory");
580 goto error_out;
581 }
583 if ((image_size > 12 * MEM_M) || (image_size & (PAGE_SIZE - 1))) {
584 PERROR("Guest firmware size is incorrect [%ld]?", image_size);
585 return -1;
586 }
588 /* Load guest firmware */
589 if( xc_ia64_copy_to_domain_pages( xc_handle, dom,
590 image, 4*MEM_G-image_size, image_size>>PAGE_SHIFT)) {
591 PERROR("Could not load guest firmware into domain");
592 goto error_out;
593 }
595 /* Hand-off state passed to guest firmware */
596 if (xc_ia64_build_hob(xc_handle, dom, memsize) < 0){
597 PERROR("Could not build hob\n");
598 goto error_out;
599 }
601 /* Retrieve special pages like io, xenstore, etc. */
602 if ( xc_ia64_get_pfn_list(xc_handle, dom, page_array, IO_PAGE_START>>PAGE_SHIFT, 2) != 2 )
603 {
604 PERROR("Could not get the page frame list");
605 goto error_out;
606 }
608 *store_mfn = page_array[1];
609 if ((sp = (shared_iopage_t *) xc_map_foreign_range(
610 xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
611 page_array[0])) == 0)
612 goto error_out;
613 memset(sp, 0, PAGE_SIZE);
614 sp->sp_global.eport = control_evtchn;
615 munmap(sp, PAGE_SIZE);
617 return 0;
619 error_out:
620 return -1;
621 }
623 int xc_vmx_build(int xc_handle,
624 uint32_t domid,
625 int memsize,
626 const char *image_name,
627 unsigned int control_evtchn,
628 unsigned int lapic,
629 unsigned int vcpus,
630 unsigned int acpi,
631 unsigned int store_evtchn,
632 unsigned long *store_mfn)
633 {
634 dom0_op_t launch_op, op;
635 int rc ;
636 vcpu_guest_context_t st_ctxt, *ctxt = &st_ctxt;
637 char *image = NULL;
638 unsigned long image_size;
639 unsigned long nr_pages;
641 if ( (nr_pages = xc_get_max_pages(xc_handle, domid)) < 0 )
642 {
643 PERROR("Could not find total pages for domain");
644 goto error_out;
645 }
647 if ( (image = xc_read_kernel_image(image_name, &image_size)) == NULL ){
648 PERROR("Could not read guest firmware image %s",image_name);
649 goto error_out;
650 }
652 image_size = (image_size + PAGE_SIZE - 1) & PAGE_MASK;
654 if ( mlock(&st_ctxt, sizeof(st_ctxt) ) ){
655 PERROR("Unable to mlock ctxt");
656 return 1;
657 }
659 op.cmd = DOM0_GETDOMAININFO;
660 op.u.getdomaininfo.domain = (domid_t)domid;
661 if ( (do_dom0_op(xc_handle, &op) < 0) ||
662 ((uint16_t)op.u.getdomaininfo.domain != domid) ) {
663 PERROR("Could not get info on domain");
664 goto error_out;
665 }
667 if ( xc_vcpu_getcontext(xc_handle, domid, 0, ctxt) ){
668 PERROR("Could not get vcpu context");
669 goto error_out;
670 }
672 if ( !(op.u.getdomaininfo.flags & DOMFLAGS_PAUSED) ) {
673 ERROR("Domain is already constructed");
674 goto error_out;
675 }
677 if ( setup_guest(xc_handle, domid, (unsigned long)memsize, image, image_size,
678 control_evtchn, store_evtchn, store_mfn ) < 0 ){
679 ERROR("Error constructing guest OS");
680 goto error_out;
681 }
683 free(image);
685 ctxt->flags = VGCF_VMX_GUEST;
686 ctxt->regs.cr_iip = 0x80000000ffffffb0UL;
687 ctxt->vcpu.privregs = 0;
689 memset( &launch_op, 0, sizeof(launch_op) );
691 launch_op.u.setvcpucontext.domain = (domid_t)domid;
692 launch_op.u.setvcpucontext.vcpu = 0;
693 launch_op.u.setvcpucontext.ctxt = ctxt;
695 launch_op.cmd = DOM0_SETVCPUCONTEXT;
696 rc = do_dom0_op(xc_handle, &launch_op);
697 return rc;
699 error_out:
700 free(image);
701 return -1;
702 }
704 /*
705 * Local variables:
706 * mode: C
707 * c-set-style: "BSD"
708 * c-basic-offset: 4
709 * tab-width: 4
710 * indent-tabs-mode: nil
711 * End:
712 */