direct-io.hg

changeset 7535:935a81f86348

Image builder for ia64/vti domain, together with a example config file.

Signed-off-by Ke Yu <ke.yu@intel.com>
Signed-off-by Anthony Xu <anthony.xu@intel.com>
Signed-off-by Kevin Tian <kevin.tian@intel.com>
author djm@kirby.fc.hp.com
date Mon Oct 24 20:56:53 2005 -0600 (2005-10-24)
parents ebc92fd2fac8
children 8928c89a8d0a
files tools/examples/Makefile tools/libxc/xc_ia64_stubs.c
line diff
     1.1 --- a/tools/examples/Makefile	Mon Oct 24 11:41:27 2005 -0600
     1.2 +++ b/tools/examples/Makefile	Mon Oct 24 20:56:53 2005 -0600
     1.3 @@ -16,6 +16,7 @@ XEN_CONFIGS = xend-config.sxp
     1.4  XEN_CONFIGS += xmexample1 
     1.5  XEN_CONFIGS += xmexample2
     1.6  XEN_CONFIGS += xmexample.vmx
     1.7 +XEN_CONFIGS += xmexample.vti
     1.8  
     1.9  # Xen script dir and scripts to go there.
    1.10  XEN_SCRIPT_DIR = /etc/xen/scripts
     2.1 --- a/tools/libxc/xc_ia64_stubs.c	Mon Oct 24 11:41:27 2005 -0600
     2.2 +++ b/tools/libxc/xc_ia64_stubs.c	Mon Oct 24 20:56:53 2005 -0600
     2.3 @@ -1,5 +1,11 @@
     2.4  #include "xg_private.h"
     2.5  #include "xenguest.h"
     2.6 +#include "xc_private.h"
     2.7 +#include "xc_elf.h"
     2.8 +#include <stdlib.h>
     2.9 +#include <zlib.h>
    2.10 +#include "xen/arch-ia64.h"
    2.11 +#include <xen/io/ioreq.h>
    2.12  
    2.13  int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters, 
    2.14                    uint32_t max_factor, uint32_t flags)
    2.15 @@ -16,20 +22,6 @@ int xc_linux_restore(int xc_handle, int 
    2.16      return -1;
    2.17  }
    2.18  
    2.19 -int xc_vmx_build(int xc_handle,
    2.20 -                 uint32_t domid,
    2.21 -                 int memsize,
    2.22 -                 const char *image_name,
    2.23 -                 unsigned int control_evtchn,
    2.24 -                 unsigned long flags,
    2.25 -                 unsigned int vcpus,
    2.26 -                 unsigned int store_evtchn,
    2.27 -                 unsigned long *store_mfn)
    2.28 -{
    2.29 -    PERROR("xc_vmx_build not implemented\n");
    2.30 -    return -1;
    2.31 -}
    2.32 -
    2.33  int
    2.34  xc_plan9_build(int xc_handle,
    2.35                 uint32_t domid,
    2.36 @@ -41,6 +33,653 @@ xc_plan9_build(int xc_handle,
    2.37      return -1;
    2.38  }
    2.39  
    2.40 +int xc_ia64_get_pfn_list(int xc_handle,
    2.41 +                         uint32_t domid, 
    2.42 +                         unsigned long *pfn_buf, 
    2.43 +                         unsigned int start_page,
    2.44 +                         unsigned int nr_pages)
    2.45 +{
    2.46 +    dom0_op_t op;
    2.47 +    int ret;
    2.48 +    unsigned long max_pfns = ((unsigned long)start_page << 32) | nr_pages;
    2.49 +
    2.50 +    op.cmd = DOM0_GETMEMLIST;
    2.51 +    op.u.getmemlist.domain   = (domid_t)domid;
    2.52 +    op.u.getmemlist.max_pfns = max_pfns;
    2.53 +    op.u.getmemlist.buffer   = pfn_buf;
    2.54 +
    2.55 +    if ( (max_pfns != -1UL)
    2.56 +		&& mlock(pfn_buf, nr_pages * sizeof(unsigned long)) != 0 )
    2.57 +    {
    2.58 +        PERROR("Could not lock pfn list buffer");
    2.59 +        return -1;
    2.60 +    }    
    2.61 +
    2.62 +    ret = do_dom0_op(xc_handle, &op);
    2.63 +
    2.64 +    if (max_pfns != -1UL)
    2.65 +    	(void)munlock(pfn_buf, nr_pages * sizeof(unsigned long));
    2.66 +
    2.67 +    return (ret < 0) ? -1 : op.u.getmemlist.num_pfns;
    2.68 +}
    2.69 +
    2.70 +long xc_get_max_pages(int xc_handle, uint32_t domid)
    2.71 +{
    2.72 +    dom0_op_t op;
    2.73 +    op.cmd = DOM0_GETDOMAININFO;
    2.74 +    op.u.getdomaininfo.domain = (domid_t)domid;
    2.75 +    return (do_dom0_op(xc_handle, &op) < 0) ? 
    2.76 +        -1 : op.u.getdomaininfo.max_pages;
    2.77 +}
    2.78 +
    2.79 +int xc_ia64_copy_to_domain_pages(int xc_handle, uint32_t domid,
    2.80 +        void* src_page, unsigned long dst_pfn, int nr_pages)
    2.81 +{
    2.82 +    // N.B. gva should be page aligned
    2.83 +    
    2.84 +    unsigned long *page_array=NULL;
    2.85 +    int i;
    2.86 +
    2.87 +    if ( (page_array = malloc(nr_pages * sizeof(unsigned long))) == NULL ){
    2.88 +        PERROR("Could not allocate memory");
    2.89 +        goto error_out;
    2.90 +    }
    2.91 +    if ( xc_ia64_get_pfn_list(xc_handle, domid, page_array,
    2.92 +                dst_pfn>>PAGE_SHIFT, nr_pages) != nr_pages ){
    2.93 +        PERROR("Could not get the page frame list");
    2.94 +        goto error_out;
    2.95 +    }
    2.96 +
    2.97 +    for ( i=0; i< nr_pages; i++ ){
    2.98 +	if (xc_copy_to_domain_page(xc_handle, domid, page_array[i],
    2.99 +			src_page + (i << PAGE_SHIFT)))
   2.100 +	    goto error_out;
   2.101 +    }
   2.102 +    free(page_array);
   2.103 +    return 0;
   2.104 +    
   2.105 +error_out:
   2.106 +    if (page_array)
   2.107 +        free(page_array);
   2.108 +    return -1;
   2.109 +}
   2.110 +
   2.111 +
   2.112 +#define HOB_SIGNATURE 0x3436474953424f48 // "HOBSIG64"
   2.113 +#define GFW_HOB_START    ((4UL<<30)-(14UL<<20))    //4G -14M
   2.114 +#define GFW_HOB_SIZE     (1UL<<20)              //1M
   2.115 +#define MEM_G   (1UL << 30) 
   2.116 +#define MEM_M   (1UL << 20) 
   2.117 +
   2.118 +typedef struct {
   2.119 +    unsigned long signature;
   2.120 +    unsigned int  type;
   2.121 +    unsigned int  length;
   2.122 +} HOB_GENERIC_HEADER;
   2.123 +
   2.124 +/*
   2.125 + * INFO HOB is the first data data in one HOB list
   2.126 + * it contains the control information of the HOB list
   2.127 + */
   2.128 +typedef struct { 
   2.129 +    HOB_GENERIC_HEADER  header;
   2.130 +    unsigned long       length;    // current length of hob
   2.131 +    unsigned long       cur_pos;   // current poisiton of hob
   2.132 +    unsigned long       buf_size;  // size of hob buffer
   2.133 +}HOB_INFO;
   2.134 +
   2.135 +typedef struct{
   2.136 +    unsigned long start;
   2.137 +    unsigned long size;
   2.138 +}hob_mem_t;
   2.139 +
   2.140 +typedef enum {
   2.141 +    HOB_TYPE_INFO=0,
   2.142 +    HOB_TYPE_TERMINAL,
   2.143 +    HOB_TYPE_MEM,
   2.144 +    HOB_TYPE_PAL_BUS_GET_FEATURES_DATA,
   2.145 +    HOB_TYPE_PAL_CACHE_SUMMARY,
   2.146 +    HOB_TYPE_PAL_MEM_ATTRIB,
   2.147 +    HOB_TYPE_PAL_CACHE_INFO,
   2.148 +    HOB_TYPE_PAL_CACHE_PROT_INFO,
   2.149 +    HOB_TYPE_PAL_DEBUG_INFO,
   2.150 +    HOB_TYPE_PAL_FIXED_ADDR,
   2.151 +    HOB_TYPE_PAL_FREQ_BASE,
   2.152 +    HOB_TYPE_PAL_FREQ_RATIOS,
   2.153 +    HOB_TYPE_PAL_HALT_INFO,
   2.154 +    HOB_TYPE_PAL_PERF_MON_INFO,
   2.155 +    HOB_TYPE_PAL_PROC_GET_FEATURES,
   2.156 +    HOB_TYPE_PAL_PTCE_INFO,
   2.157 +    HOB_TYPE_PAL_REGISTER_INFO,
   2.158 +    HOB_TYPE_PAL_RSE_INFO,
   2.159 +    HOB_TYPE_PAL_TEST_INFO,
   2.160 +    HOB_TYPE_PAL_VM_SUMMARY,
   2.161 +    HOB_TYPE_PAL_VM_INFO,
   2.162 +    HOB_TYPE_PAL_VM_PAGE_SIZE,
   2.163 +    HOB_TYPE_MAX
   2.164 +}hob_type_t;
   2.165 +
   2.166 +static int hob_init( void  *buffer ,unsigned long buf_size);
   2.167 +static int add_pal_hob(void* hob_buf);
   2.168 +static int add_mem_hob(void* hob_buf, unsigned long dom_mem_size);
   2.169 +static int build_hob (void* hob_buf, unsigned long hob_buf_size,
   2.170 +                  unsigned long dom_mem_size);
   2.171 +static int load_hob(int xc_handle,uint32_t dom, void *hob_buf);
   2.172 +
   2.173 +int xc_ia64_build_hob(int xc_handle, uint32_t dom, unsigned long memsize){
   2.174 +
   2.175 +    char   hob_buf[GFW_HOB_SIZE];
   2.176 +
   2.177 +    if ( build_hob( hob_buf, GFW_HOB_SIZE, memsize<<20) < 0){
   2.178 +        PERROR("Could not build hob");
   2.179 +        return -1;
   2.180 +    }
   2.181 +
   2.182 +    if ( load_hob( xc_handle, dom, hob_buf) <0){
   2.183 +        PERROR("Could not load hob");
   2.184 +       return -1;
   2.185 +    }
   2.186 +
   2.187 +    return 0;
   2.188 +
   2.189 +}
   2.190 +static int
   2.191 +hob_init( void  *buffer ,unsigned long buf_size)
   2.192 +{
   2.193 +    HOB_INFO *phit;
   2.194 +    HOB_GENERIC_HEADER     *terminal;
   2.195 +
   2.196 +    if (sizeof(HOB_INFO) + sizeof(HOB_GENERIC_HEADER) > buf_size){
   2.197 +        // buffer too small
   2.198 +        return -1;
   2.199 +    }
   2.200 +    
   2.201 +    phit = (HOB_INFO*)buffer;
   2.202 +    phit->header.signature = HOB_SIGNATURE;
   2.203 +    phit->header.type = HOB_TYPE_INFO;
   2.204 +    phit->header.length = sizeof(HOB_INFO);
   2.205 +    phit->length = sizeof(HOB_INFO) + sizeof(HOB_GENERIC_HEADER);
   2.206 +    phit->cur_pos = 0;
   2.207 +    phit->buf_size = buf_size;
   2.208 +    
   2.209 +    terminal = (HOB_GENERIC_HEADER*) (buffer + sizeof(HOB_INFO));
   2.210 +    terminal->signature= HOB_SIGNATURE;
   2.211 +    terminal->type = HOB_TYPE_TERMINAL;
   2.212 +    terminal->length = sizeof(HOB_GENERIC_HEADER);
   2.213 +
   2.214 +    return 0;
   2.215 +}
   2.216 +
   2.217 +/*
   2.218 + *  Add a new HOB to the HOB List.
   2.219 + *       
   2.220 + *  hob_start  -  start address of hob buffer
   2.221 + *  type       -  type of the hob to be added
   2.222 + *  data       -  data of the hob to be added
   2.223 + *  data_size  -  size of the data
   2.224 + */
   2.225 +static int
   2.226 +hob_add(
   2.227 +     void*  hob_start,
   2.228 +     int    type,
   2.229 +     void*  data,
   2.230 +     int    data_size
   2.231 +)
   2.232 +{
   2.233 +    HOB_INFO *phit;
   2.234 +    HOB_GENERIC_HEADER     *newhob,*tail;   
   2.235 +    
   2.236 +    phit = (HOB_INFO*)hob_start;
   2.237 +
   2.238 +    if (phit->length + data_size > phit->buf_size){
   2.239 +        // no space for new hob
   2.240 +        return -1;
   2.241 +    }
   2.242 +
   2.243 +    //append new HOB 
   2.244 +    newhob = (HOB_GENERIC_HEADER*)
   2.245 +        (hob_start + phit->length - sizeof(HOB_GENERIC_HEADER));
   2.246 +    newhob->signature = HOB_SIGNATURE;
   2.247 +    newhob->type = type;
   2.248 +    newhob->length = data_size + sizeof(HOB_GENERIC_HEADER);
   2.249 +    memcpy((void*)newhob + sizeof(HOB_GENERIC_HEADER), data, data_size);
   2.250 +
   2.251 +    // append terminal HOB  
   2.252 +    tail = (HOB_GENERIC_HEADER*) ( hob_start + phit->length + data_size);
   2.253 +    tail->signature = HOB_SIGNATURE;
   2.254 +    tail->type = HOB_TYPE_TERMINAL;
   2.255 +    tail->length = sizeof(HOB_GENERIC_HEADER);
   2.256 +
   2.257 +    // adjust HOB list length
   2.258 +    phit->length += sizeof(HOB_GENERIC_HEADER)+ data_size;
   2.259 +
   2.260 +    return 0;
   2.261 +
   2.262 +}
   2.263 +
   2.264 +int get_hob_size(void* hob_buf){
   2.265 +    
   2.266 +    HOB_INFO *phit = (HOB_INFO*)hob_buf;
   2.267 +    
   2.268 +    if (phit->header.signature != HOB_SIGNATURE){
   2.269 +        PERROR("xc_get_hob_size:Incorrect signature");
   2.270 +        return -1;
   2.271 +    }
   2.272 +    return phit->length;
   2.273 +}
   2.274 +
   2.275 +int build_hob (void* hob_buf, unsigned long hob_buf_size,
   2.276 +                  unsigned long dom_mem_size)
   2.277 +{   
   2.278 +    //Init HOB List 
   2.279 +    if (hob_init (hob_buf, hob_buf_size)<0){
   2.280 +        PERROR("buffer too small");
   2.281 +        goto err_out;
   2.282 +    }
   2.283 +    
   2.284 +    if ( add_mem_hob( hob_buf,dom_mem_size) < 0){
   2.285 +        PERROR("Add memory hob failed, buffer too small");
   2.286 +        goto err_out;
   2.287 +    }
   2.288 +    
   2.289 +    if ( add_pal_hob( hob_buf ) < 0 ){
   2.290 +        PERROR("Add PAL hob failed, buffer too small");
   2.291 +        goto err_out;
   2.292 +    }
   2.293 +    
   2.294 +    return 0;
   2.295 +
   2.296 +err_out:
   2.297 +    return -1;  
   2.298 +}
   2.299 +
   2.300 +static int 
   2.301 +load_hob(int xc_handle, uint32_t dom, void *hob_buf)
   2.302 +{
   2.303 +    // hob_buf should be page aligned
   2.304 +    int hob_size;
   2.305 +    int nr_pages;
   2.306 +
   2.307 +    if ((hob_size = get_hob_size(hob_buf)) < 0){
   2.308 +        PERROR("Invalid hob data");
   2.309 +        return -1;
   2.310 +    }
   2.311 +
   2.312 +    if (hob_size > GFW_HOB_SIZE){
   2.313 +        PERROR("No enough memory for hob data");
   2.314 +        return -1;
   2.315 +    }
   2.316 +
   2.317 +    nr_pages = (hob_size + PAGE_SIZE -1) >> PAGE_SHIFT;
   2.318 +    
   2.319 +    return xc_ia64_copy_to_domain_pages(xc_handle, dom,
   2.320 +            hob_buf, GFW_HOB_START, nr_pages );
   2.321 +}
   2.322 +
   2.323 +#define MIN(x, y) ((x) < (y)) ? (x) : (y)
   2.324 +static int 
   2.325 +add_mem_hob(void* hob_buf, unsigned long dom_mem_size){
   2.326 +    hob_mem_t memhob;
   2.327 +
   2.328 +    // less than 3G
   2.329 +    memhob.start = 0;
   2.330 +    memhob.size = MIN(dom_mem_size, 0xC0000000);
   2.331 +    
   2.332 +    if (hob_add(hob_buf, HOB_TYPE_MEM, &memhob, sizeof(memhob)) < 0){
   2.333 +	return -1;
   2.334 +    }
   2.335 +
   2.336 +    if (dom_mem_size > 0xC0000000) {
   2.337 +        // 4G ~ 4G+remain
   2.338 +        memhob.start = 0x100000000; //4G
   2.339 +        memhob.size = dom_mem_size - 0xC0000000;
   2.340 +        if (hob_add(hob_buf, HOB_TYPE_MEM, &memhob, sizeof(memhob)) < 0)
   2.341 +            return -1;
   2.342 +    }
   2.343 +    return 0;
   2.344 +}
   2.345 +
   2.346 +unsigned char config_pal_bus_get_features_data[24] = {
   2.347 +    0, 0, 0, 32, 0, 0, 240, 189, 0, 0, 0, 0, 0, 0,
   2.348 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0
   2.349 +};
   2.350 +unsigned char config_pal_cache_summary[16] = {
   2.351 +    3, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0};
   2.352 +unsigned char config_pal_mem_attrib[8] =    {
   2.353 +    241, 0, 0, 0, 0, 0, 0, 0
   2.354 +};
   2.355 +unsigned char config_pal_cache_info[152] = {
   2.356 +    3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   2.357 +    6, 4, 6, 7, 255, 1, 0, 1, 0, 64, 0, 0, 12, 12, 
   2.358 +    49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 7, 0, 1,
   2.359 +    0, 1, 0, 64, 0, 0, 12, 12, 49, 0, 0, 0, 0, 0, 0, 
   2.360 +    0, 0, 0, 6, 8, 7, 7, 255, 7, 0, 11, 0, 0, 16, 0, 
   2.361 +    12, 17, 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 8, 7, 
   2.362 +    7, 7, 5, 9, 11, 0, 0, 4, 0, 12, 15, 49, 0, 254, 255,
   2.363 +    255, 255, 255, 255, 255, 255, 2, 8, 7, 7, 7, 5, 9, 
   2.364 +    11, 0, 0, 4, 0, 12, 15, 49, 0, 0, 0, 0, 0, 0, 0, 0, 
   2.365 +    0, 3, 12, 7, 7, 7, 14, 1, 3, 0, 0, 192, 0, 12, 20, 49, 0
   2.366 +};
   2.367 +unsigned char config_pal_cache_prot_info[200] = {
   2.368 +    3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
   2.369 +    45, 0, 16, 8, 0, 76, 12, 64, 0, 0, 0, 0, 0, 0, 0,
   2.370 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
   2.371 +    8, 0, 16, 4, 0, 76, 44, 68, 0, 0, 0, 0, 0, 0, 0, 0, 
   2.372 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 
   2.373 +    0, 16, 8, 0, 81, 44, 72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
   2.374 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0,
   2.375 +    112, 12, 0, 79, 124, 76, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
   2.376 +    0, 0, 0, 0, 0, 0, 254, 255, 255, 255, 255, 255, 255, 255, 
   2.377 +    32, 0, 112, 12, 0, 79, 124, 76, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   2.378 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 160, 
   2.379 +    12, 0, 84, 124, 76, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
   2.380 +    0, 0, 0
   2.381 +};
   2.382 +unsigned char config_pal_debug_info[16] = {
   2.383 +    2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0
   2.384 +};
   2.385 +unsigned char config_pal_fixed_addr[8] = {
   2.386 +    0, 0, 0, 0, 0, 0, 0, 0
   2.387 +};
   2.388 +unsigned char config_pal_freq_base[8] = {
   2.389 +    109, 219, 182, 13, 0, 0, 0, 0
   2.390 +};
   2.391 +unsigned char config_pal_freq_ratios[24] = {
   2.392 +    11, 1, 0, 0, 77, 7, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 4, 
   2.393 +    0, 0, 0, 7, 0, 0, 0
   2.394 +};
   2.395 +unsigned char config_pal_halt_info[64] = {
   2.396 +    0, 0, 0, 0, 0, 0, 0, 48, 0, 0, 0, 0, 0, 0, 0, 0, 
   2.397 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   2.398 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
   2.399 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
   2.400 +};
   2.401 +unsigned char config_pal_perf_mon_info[136] = {
   2.402 +    12, 47, 18, 8, 0, 0, 0, 0, 241, 255, 0, 0, 255, 7, 0, 0, 
   2.403 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
   2.404 +    0, 0, 0, 0, 0, 0, 0, 0, 241, 255, 0, 0, 223, 0, 255, 255, 
   2.405 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
   2.406 +    0, 0, 0, 0, 0, 0, 0, 0, 240, 255, 0, 0, 0, 0, 0, 0, 
   2.407 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
   2.408 +    0, 0, 0, 0, 0, 0, 0, 0, 240, 255, 0, 0, 0, 0, 0, 0, 
   2.409 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
   2.410 +    0, 0, 0, 0, 0, 0, 0, 0
   2.411 +};
   2.412 +unsigned char config_pal_proc_get_features[104] = {
   2.413 +    3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
   2.414 +    0, 0, 0, 0, 64, 6, 64, 49, 0, 0, 0, 0, 64, 6, 0, 0, 
   2.415 +    0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 
   2.416 +    231, 0, 0, 0, 0, 0, 0, 0, 228, 0, 0, 0, 0, 0, 0, 0, 
   2.417 +    0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0, 0, 0, 0, 0, 0, 
   2.418 +    63, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0,
   2.419 +    0, 0, 0, 0, 0, 0, 0, 0
   2.420 +};
   2.421 +unsigned char config_pal_ptce_info[24] = {
   2.422 +    0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 
   2.423 +    0, 0, 0, 0, 0, 0, 0, 0
   2.424 +};
   2.425 +unsigned char config_pal_register_info[64] = {
   2.426 +    255, 0, 47, 127, 17, 17, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0,
   2.427 +    255, 208, 128, 238, 238, 0, 0, 248, 255, 255, 255, 255, 255, 0, 0, 7, 3,
   2.428 +    251, 3, 0, 0, 0, 0, 255, 7, 3, 0, 0, 0, 0, 0, 248, 252, 4,
   2.429 +    252, 255, 255, 255, 255, 2, 248, 252, 255, 255, 255, 255, 255
   2.430 +};
   2.431 +unsigned char config_pal_rse_info[16] = {
   2.432 +    96, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
   2.433 +};
   2.434 +unsigned char config_pal_test_info[48] = {
   2.435 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   2.436 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   2.437 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
   2.438 +};
   2.439 +unsigned char config_pal_vm_summary[16] = {
   2.440 +    101, 18, 15, 2, 7, 7, 4, 2, 59, 18, 0, 0, 0, 0, 0, 0
   2.441 +};
   2.442 +unsigned char config_pal_vm_info[104] = {
   2.443 +    2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
   2.444 +    32, 32, 0, 0, 0, 0, 0, 0, 112, 85, 21, 0, 0, 0, 0, 0, 0,
   2.445 +    0, 0, 0, 0, 0, 0, 1, 32, 32, 0, 0, 0, 0, 0, 0, 112, 85,
   2.446 +    21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 128, 128, 0,
   2.447 +    4, 0, 0, 0, 0, 112, 85, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   2.448 +    0, 0, 0, 1, 128, 128, 0, 4, 0, 0, 0, 0, 112, 85, 0, 0, 0, 0, 0
   2.449 +};
   2.450 +unsigned char config_pal_vm_page_size[16] = {
   2.451 +    0, 112, 85, 21, 0, 0, 0, 0, 0, 112, 85, 21, 0, 0, 0, 0
   2.452 +};
   2.453 +
   2.454 +typedef struct{
   2.455 +    hob_type_t type;
   2.456 +    void* data;
   2.457 +    unsigned long size;     
   2.458 +}hob_batch_t;
   2.459 +
   2.460 +hob_batch_t hob_batch[]={
   2.461 +    {  HOB_TYPE_PAL_BUS_GET_FEATURES_DATA,
   2.462 +        &config_pal_bus_get_features_data,
   2.463 +        sizeof(config_pal_bus_get_features_data)
   2.464 +    },
   2.465 +    {  HOB_TYPE_PAL_CACHE_SUMMARY,
   2.466 +        &config_pal_cache_summary,
   2.467 +        sizeof(config_pal_cache_summary)
   2.468 +    },
   2.469 +    {  HOB_TYPE_PAL_MEM_ATTRIB,
   2.470 +        &config_pal_mem_attrib,
   2.471 +        sizeof(config_pal_mem_attrib)
   2.472 +    },
   2.473 +    {  HOB_TYPE_PAL_CACHE_INFO,
   2.474 +        &config_pal_cache_info,
   2.475 +        sizeof(config_pal_cache_info)
   2.476 +    },
   2.477 +    {  HOB_TYPE_PAL_CACHE_PROT_INFO,
   2.478 +        &config_pal_cache_prot_info,
   2.479 +        sizeof(config_pal_cache_prot_info)
   2.480 +    },
   2.481 +    {  HOB_TYPE_PAL_DEBUG_INFO,
   2.482 +        &config_pal_debug_info,
   2.483 +        sizeof(config_pal_debug_info)
   2.484 +    },
   2.485 +    {  HOB_TYPE_PAL_FIXED_ADDR,
   2.486 +        &config_pal_fixed_addr,
   2.487 +        sizeof(config_pal_fixed_addr)
   2.488 +    },
   2.489 +    {  HOB_TYPE_PAL_FREQ_BASE,
   2.490 +        &config_pal_freq_base,
   2.491 +        sizeof(config_pal_freq_base)
   2.492 +    },
   2.493 +    {  HOB_TYPE_PAL_FREQ_RATIOS,
   2.494 +        &config_pal_freq_ratios,
   2.495 +        sizeof(config_pal_freq_ratios)
   2.496 +    },
   2.497 +    {  HOB_TYPE_PAL_HALT_INFO,
   2.498 +        &config_pal_halt_info,
   2.499 +        sizeof(config_pal_halt_info)
   2.500 +    },
   2.501 +    {  HOB_TYPE_PAL_PERF_MON_INFO,
   2.502 +        &config_pal_perf_mon_info,
   2.503 +        sizeof(config_pal_perf_mon_info)
   2.504 +    },
   2.505 +    {  HOB_TYPE_PAL_PROC_GET_FEATURES,
   2.506 +        &config_pal_proc_get_features,
   2.507 +        sizeof(config_pal_proc_get_features)
   2.508 +    },
   2.509 +    {  HOB_TYPE_PAL_PTCE_INFO,
   2.510 +        &config_pal_ptce_info,
   2.511 +        sizeof(config_pal_ptce_info)
   2.512 +    },
   2.513 +    {  HOB_TYPE_PAL_REGISTER_INFO,
   2.514 +        &config_pal_register_info,
   2.515 +        sizeof(config_pal_register_info)
   2.516 +    },
   2.517 +    {  HOB_TYPE_PAL_RSE_INFO,
   2.518 +        &config_pal_rse_info,
   2.519 +        sizeof(config_pal_rse_info)
   2.520 +    },
   2.521 +    {  HOB_TYPE_PAL_TEST_INFO,
   2.522 +        &config_pal_test_info,
   2.523 +        sizeof(config_pal_test_info)
   2.524 +    },
   2.525 +    {  HOB_TYPE_PAL_VM_SUMMARY,
   2.526 +        &config_pal_vm_summary,
   2.527 +        sizeof(config_pal_vm_summary)
   2.528 +    },
   2.529 +    {  HOB_TYPE_PAL_VM_INFO,
   2.530 +        &config_pal_vm_info,
   2.531 +        sizeof(config_pal_vm_info)
   2.532 +    },
   2.533 +    {  HOB_TYPE_PAL_VM_PAGE_SIZE,
   2.534 +        &config_pal_vm_page_size,
   2.535 +        sizeof(config_pal_vm_page_size)
   2.536 +    },      
   2.537 +};
   2.538 +
   2.539 +static int add_pal_hob(void* hob_buf){
   2.540 +    int i;
   2.541 +    for (i=0; i<sizeof(hob_batch)/sizeof(hob_batch_t); i++){
   2.542 +        if (hob_add(hob_buf, hob_batch[i].type, 
   2.543 +                    hob_batch[i].data,
   2.544 +                    hob_batch[i].size)<0)
   2.545 +            return -1;
   2.546 +    }
   2.547 +    return 0;
   2.548 +}
   2.549 +
   2.550 +static int setup_guest(  int xc_handle,
   2.551 +                         uint32_t dom, unsigned long memsize,
   2.552 +                         char *image, unsigned long image_size,
   2.553 +                         unsigned int control_evtchn,
   2.554 +                         unsigned int store_evtchn,
   2.555 +                         unsigned long *store_mfn)
   2.556 +{
   2.557 +    unsigned long page_array[2];
   2.558 +    shared_iopage_t *sp;
   2.559 +    // FIXME: initialize pfn list for a temp hack
   2.560 +    if (xc_ia64_get_pfn_list(xc_handle, dom, NULL, -1, -1) == -1) {
   2.561 +	PERROR("Could not allocate continuous memory");
   2.562 +	goto error_out;
   2.563 +    }
   2.564 +    
   2.565 +    if ((image_size > 12 * MEM_M) || (image_size & (PAGE_SIZE - 1))) {
   2.566 +        PERROR("Guest firmware size is incorrect [%ld]?", image_size);
   2.567 +        return -1;
   2.568 +    }
   2.569 +
   2.570 +    /* Load guest firmware */
   2.571 +    if( xc_ia64_copy_to_domain_pages( xc_handle, dom, 
   2.572 +            image, 4*MEM_G-image_size, image_size>>PAGE_SHIFT)) {
   2.573 +        PERROR("Could not load guest firmware into domain");
   2.574 +        goto error_out;
   2.575 +    }
   2.576 +
   2.577 +    /* Hand-off state passed to guest firmware */
   2.578 +    if (xc_ia64_build_hob(xc_handle, dom, memsize) < 0){
   2.579 +        PERROR("Could not build hob\n");
   2.580 +       goto error_out;
   2.581 +    }
   2.582 +
   2.583 +    /* Retrieve special pages like io, xenstore, etc. */
   2.584 +    if ( xc_ia64_get_pfn_list(xc_handle, dom, page_array, IO_PAGE_START>>PAGE_SHIFT, 2) != 2 )
   2.585 +    {
   2.586 +        PERROR("Could not get the page frame list");
   2.587 +        goto error_out;
   2.588 +    }
   2.589 +
   2.590 +    *store_mfn = page_array[1];
   2.591 +    if ((sp = (shared_iopage_t *) xc_map_foreign_range(
   2.592 +		xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
   2.593 +		page_array[0])) == 0)
   2.594 +	goto error_out;
   2.595 +    memset(sp, 0, PAGE_SIZE);
   2.596 +    sp->sp_global.eport = control_evtchn;
   2.597 +    munmap(sp, PAGE_SIZE);
   2.598 +
   2.599 +    return 0;
   2.600 +
   2.601 + error_out:
   2.602 +    return -1;
   2.603 +}
   2.604 +
   2.605 +int xc_vmx_build(int xc_handle,
   2.606 +                 uint32_t domid,
   2.607 +                 int memsize,
   2.608 +                 const char *image_name,
   2.609 +                 unsigned int control_evtchn,
   2.610 +                 unsigned int vcpus,
   2.611 +                 unsigned int store_evtchn,
   2.612 +                 unsigned long *store_mfn)
   2.613 +{
   2.614 +    dom0_op_t launch_op, op;
   2.615 +    int rc ;
   2.616 +    vcpu_guest_context_t st_ctxt, *ctxt = &st_ctxt;
   2.617 +    char         *image = NULL;
   2.618 +    unsigned long image_size;
   2.619 +    unsigned long nr_pages;
   2.620 +
   2.621 +    if ( (nr_pages = xc_get_max_pages(xc_handle, domid)) < 0 )
   2.622 +    {
   2.623 +        PERROR("Could not find total pages for domain");
   2.624 +        goto error_out;
   2.625 +    }
   2.626 +
   2.627 +    if ( (image = xc_read_kernel_image(image_name, &image_size)) == NULL ){
   2.628 +        PERROR("Could not read guest firmware image %s",image_name);
   2.629 +        goto error_out;
   2.630 +    }
   2.631 +
   2.632 +    image_size = (image_size + PAGE_SIZE - 1) & PAGE_MASK;
   2.633 +
   2.634 +    if ( mlock(&st_ctxt, sizeof(st_ctxt) ) ){   
   2.635 +        PERROR("Unable to mlock ctxt");
   2.636 +        return 1;
   2.637 +    }
   2.638 +
   2.639 +    op.cmd = DOM0_GETDOMAININFO;
   2.640 +    op.u.getdomaininfo.domain = (domid_t)domid;
   2.641 +    if ( (do_dom0_op(xc_handle, &op) < 0) || 
   2.642 +         ((uint16_t)op.u.getdomaininfo.domain != domid) ) {
   2.643 +        PERROR("Could not get info on domain");
   2.644 +        goto error_out;
   2.645 +    }
   2.646 +
   2.647 +    if ( xc_domain_get_vcpu_context(xc_handle, domid, 0, ctxt) ){
   2.648 +        PERROR("Could not get vcpu context");
   2.649 +        goto error_out;
   2.650 +    }
   2.651 +
   2.652 +    if ( !(op.u.getdomaininfo.flags & DOMFLAGS_PAUSED) ) {
   2.653 +        ERROR("Domain is already constructed");
   2.654 +        goto error_out;
   2.655 +    }
   2.656 +
   2.657 +    if ( setup_guest(xc_handle, domid, (unsigned long)memsize, image, image_size, 
   2.658 +                       control_evtchn, store_evtchn, store_mfn ) < 0 ){
   2.659 +        ERROR("Error constructing guest OS");
   2.660 +        goto error_out;
   2.661 +    }
   2.662 +
   2.663 +    if ( image != NULL )
   2.664 +        free(image);
   2.665 +
   2.666 +    ctxt->flags = VGCF_VMX_GUEST;
   2.667 +    ctxt->regs.cr_iip = 0x80000000ffffffb0UL;
   2.668 +    ctxt->vcpu.privregs = 0;
   2.669 +
   2.670 +    memset( &launch_op, 0, sizeof(launch_op) );
   2.671 +
   2.672 +    launch_op.u.setdomaininfo.domain = (domid_t)domid;
   2.673 +    launch_op.u.setdomaininfo.vcpu   = 0;
   2.674 +    launch_op.u.setdomaininfo.ctxt   = ctxt;
   2.675 +
   2.676 +    launch_op.cmd = DOM0_SETDOMAININFO;
   2.677 +    rc = do_dom0_op(xc_handle, &launch_op);
   2.678 +    return rc;
   2.679 +
   2.680 + error_out:
   2.681 +    if ( image != NULL )
   2.682 +        free(image);
   2.683 +
   2.684 +    return -1;
   2.685 +}
   2.686 +
   2.687  /*
   2.688   * Local variables:
   2.689   * mode: C