ia64/xen-unstable

annotate xen/arch/ia64/vmx/vmx_init.c @ 6878:babbdd896024

Remove all CONFIG_VTI, VTI now works dynamically
1.remove vcpu_set_regs and element regs,which are never used
2.remove ia64_prepare_handle_privop,ia64_prepare_handle_break, ia64_prepare_handle_reflection, which are never used.
3.modify related macros for adapting to three level physical to machine table
4.remove all CONFIG_VIT
5.merge ia64_switch_to

Signed-off-by Anthony Xu <Anthony.xu@intel.com>
author djm@kirby.fc.hp.com
date Thu Sep 22 06:59:57 2005 -0600 (2005-09-22)
parents 52d2d5208575
children 06d84bf87159
rev   line source
djm@6458 1 /* -*- Mode:C; c-basic-offset:4; tab-width:4; indent-tabs-mode:nil -*- */
djm@6458 2 /*
djm@6458 3 * vmx_init.c: initialization work for vt specific domain
djm@6458 4 * Copyright (c) 2005, Intel Corporation.
djm@6458 5 * Kun Tian (Kevin Tian) <kevin.tian@intel.com>
djm@6458 6 * Xuefei Xu (Anthony Xu) <anthony.xu@intel.com>
djm@6458 7 * Fred Yang <fred.yang@intel.com>
djm@6458 8 *
djm@6458 9 * This program is free software; you can redistribute it and/or modify it
djm@6458 10 * under the terms and conditions of the GNU General Public License,
djm@6458 11 * version 2, as published by the Free Software Foundation.
djm@6458 12 *
djm@6458 13 * This program is distributed in the hope it will be useful, but WITHOUT
djm@6458 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
djm@6458 15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
djm@6458 16 * more details.
djm@6458 17 *
djm@6458 18 * You should have received a copy of the GNU General Public License along with
djm@6458 19 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
djm@6458 20 * Place - Suite 330, Boston, MA 02111-1307 USA.
djm@6458 21 *
djm@6458 22 */
djm@6458 23
djm@6458 24 /*
djm@6458 25 * 05/08/16 Kun tian (Kevin Tian) <kevin.tian@intel.com>:
djm@6458 26 * Disable doubling mapping
djm@6458 27 *
djm@6458 28 * 05/03/23 Kun Tian (Kevin Tian) <kevin.tian@intel.com>:
djm@6458 29 * Simplied design in first step:
djm@6458 30 * - One virtual environment
djm@6458 31 * - Domain is bound to one LP
djm@6458 32 * Later to support guest SMP:
djm@6458 33 * - Need interface to handle VP scheduled to different LP
djm@6458 34 */
djm@6458 35 #include <xen/config.h>
djm@6458 36 #include <xen/types.h>
djm@6458 37 #include <xen/sched.h>
djm@6458 38 #include <asm/pal.h>
djm@6458 39 #include <asm/page.h>
djm@6458 40 #include <asm/processor.h>
djm@6458 41 #include <asm/vmx_vcpu.h>
djm@6458 42 #include <xen/lib.h>
djm@6458 43 #include <asm/vmmu.h>
djm@6458 44 #include <public/arch-ia64.h>
djm@6458 45 #include <public/io/ioreq.h>
djm@6458 46 #include <asm/vmx_phy_mode.h>
djm@6458 47 #include <asm/processor.h>
djm@6458 48 #include <asm/vmx.h>
djm@6458 49 #include <xen/mm.h>
djm@6458 50
djm@6458 51 /* Global flag to identify whether Intel vmx feature is on */
djm@6458 52 u32 vmx_enabled = 0;
djm@6458 53 static u32 vm_order;
djm@6458 54 static u64 buffer_size;
djm@6458 55 static u64 vp_env_info;
djm@6458 56 static u64 vm_buffer = 0; /* Buffer required to bring up VMX feature */
djm@6458 57 u64 __vsa_base = 0; /* Run-time service base of VMX */
djm@6458 58
djm@6458 59 /* Check whether vt feature is enabled or not. */
djm@6458 60 void
djm@6458 61 identify_vmx_feature(void)
djm@6458 62 {
djm@6458 63 pal_status_t ret;
djm@6458 64 u64 avail = 1, status = 1, control = 1;
djm@6458 65
djm@6458 66 vmx_enabled = 0;
djm@6458 67 /* Check VT-i feature */
djm@6458 68 ret = ia64_pal_proc_get_features(&avail, &status, &control);
djm@6458 69 if (ret != PAL_STATUS_SUCCESS) {
djm@6458 70 printk("Get proc features failed.\n");
djm@6458 71 goto no_vti;
djm@6458 72 }
djm@6458 73
djm@6458 74 /* FIXME: do we need to check status field, to see whether
djm@6458 75 * PSR.vm is actually enabled? If yes, aonther call to
djm@6458 76 * ia64_pal_proc_set_features may be reuqired then.
djm@6458 77 */
djm@6458 78 printk("avail:0x%lx, status:0x%lx,control:0x%lx, vm?0x%lx\n",
djm@6458 79 avail, status, control, avail & PAL_PROC_VM_BIT);
djm@6458 80 if (!(avail & PAL_PROC_VM_BIT)) {
djm@6458 81 printk("No VT feature supported.\n");
djm@6458 82 goto no_vti;
djm@6458 83 }
djm@6458 84
djm@6458 85 ret = ia64_pal_vp_env_info(&buffer_size, &vp_env_info);
djm@6458 86 if (ret != PAL_STATUS_SUCCESS) {
djm@6458 87 printk("Get vp environment info failed.\n");
djm@6458 88 goto no_vti;
djm@6458 89 }
djm@6458 90
djm@6458 91 /* Does xen has ability to decode itself? */
djm@6458 92 if (!(vp_env_info & VP_OPCODE))
djm@6458 93 printk("WARNING: no opcode provided from hardware(%lx)!!!\n", vp_env_info);
djm@6458 94 vm_order = get_order(buffer_size);
djm@6458 95 printk("vm buffer size: %d, order: %d\n", buffer_size, vm_order);
djm@6458 96
djm@6458 97 vmx_enabled = 1;
djm@6458 98 no_vti:
djm@6458 99 return;
djm@6458 100 }
djm@6458 101
djm@6458 102 /*
djm@6458 103 * Init virtual environment on current LP
djm@6458 104 * vsa_base is the indicator whether it's first LP to be initialized
djm@6458 105 * for current domain.
djm@6458 106 */
djm@6458 107 void
djm@6458 108 vmx_init_env(void)
djm@6458 109 {
djm@6458 110 u64 status, tmp_base;
djm@6458 111
djm@6458 112 if (!vm_buffer) {
djm@6458 113 vm_buffer = alloc_xenheap_pages(vm_order);
djm@6458 114 ASSERT(vm_buffer);
djm@6458 115 printk("vm_buffer: 0x%lx\n", vm_buffer);
djm@6458 116 }
djm@6458 117
djm@6458 118 status=ia64_pal_vp_init_env(__vsa_base ? VP_INIT_ENV : VP_INIT_ENV_INITALIZE,
djm@6458 119 __pa(vm_buffer),
djm@6458 120 vm_buffer,
djm@6458 121 &tmp_base);
djm@6458 122
djm@6458 123 if (status != PAL_STATUS_SUCCESS) {
djm@6458 124 printk("ia64_pal_vp_init_env failed.\n");
djm@6458 125 return -1;
djm@6458 126 }
djm@6458 127
djm@6458 128 if (!__vsa_base)
djm@6458 129 __vsa_base = tmp_base;
djm@6458 130 else
djm@6458 131 ASSERT(tmp_base != __vsa_base);
djm@6458 132
djm@6458 133 #ifdef XEN_DBL_MAPPING
djm@6458 134 /* Init stub for rr7 switch */
djm@6458 135 vmx_init_double_mapping_stub();
djm@6458 136 #endif
djm@6458 137 }
djm@6458 138
djm@6458 139 void vmx_setup_platform(struct vcpu *v, struct vcpu_guest_context *c)
djm@6458 140 {
djm@6458 141 struct domain *d = v->domain;
djm@6458 142 shared_iopage_t *sp;
djm@6458 143
djm@6458 144 ASSERT(d != dom0); /* only for non-privileged vti domain */
djm@6458 145 d->arch.vmx_platform.shared_page_va = __va(c->share_io_pg);
djm@6458 146 sp = get_sp(d);
djm@6458 147 memset((char *)sp,0,PAGE_SIZE);
djm@6458 148 /* FIXME: temp due to old CP */
djm@6458 149 sp->sp_global.eport = 2;
djm@6458 150 #ifdef V_IOSAPIC_READY
djm@6458 151 sp->vcpu_number = 1;
djm@6458 152 #endif
djm@6458 153 /* TEMP */
djm@6458 154 d->arch.vmx_platform.pib_base = 0xfee00000UL;
djm@6458 155
djm@6458 156 /* One more step to enable interrupt assist */
djm@6458 157 set_bit(ARCH_VMX_INTR_ASSIST, &v->arch.arch_vmx.flags);
djm@6458 158 /* Only open one port for I/O and interrupt emulation */
djm@6458 159 if (v == d->vcpu[0]) {
djm@6458 160 memset(&d->shared_info->evtchn_mask[0], 0xff,
djm@6458 161 sizeof(d->shared_info->evtchn_mask));
djm@6458 162 clear_bit(iopacket_port(d), &d->shared_info->evtchn_mask[0]);
djm@6458 163 }
djm@6458 164
djm@6458 165 /* FIXME: only support PMT table continuously by far */
djm@6878 166 // d->arch.pmt = __va(c->pt_base);
djm@6878 167
djm@6458 168
djm@6458 169 vmx_final_setup_domain(d);
djm@6458 170 }
djm@6458 171
djm@6458 172 typedef union {
djm@6458 173 u64 value;
djm@6458 174 struct {
djm@6458 175 u64 number : 8;
djm@6458 176 u64 revision : 8;
djm@6458 177 u64 model : 8;
djm@6458 178 u64 family : 8;
djm@6458 179 u64 archrev : 8;
djm@6458 180 u64 rv : 24;
djm@6458 181 };
djm@6458 182 } cpuid3_t;
djm@6458 183
djm@6458 184 /* Allocate vpd from xenheap */
djm@6458 185 static vpd_t *alloc_vpd(void)
djm@6458 186 {
djm@6458 187 int i;
djm@6458 188 cpuid3_t cpuid3;
djm@6458 189 vpd_t *vpd;
djm@6458 190
djm@6458 191 vpd = alloc_xenheap_pages(get_order(VPD_SIZE));
djm@6458 192 if (!vpd) {
djm@6458 193 printk("VPD allocation failed.\n");
djm@6458 194 return NULL;
djm@6458 195 }
djm@6458 196
djm@6458 197 printk("vpd base: 0x%lx, vpd size:%d\n", vpd, sizeof(vpd_t));
djm@6458 198 memset(vpd, 0, VPD_SIZE);
djm@6458 199 /* CPUID init */
djm@6458 200 for (i = 0; i < 5; i++)
djm@6458 201 vpd->vcpuid[i] = ia64_get_cpuid(i);
djm@6458 202
djm@6458 203 /* Limit the CPUID number to 5 */
djm@6458 204 cpuid3.value = vpd->vcpuid[3];
djm@6458 205 cpuid3.number = 4; /* 5 - 1 */
djm@6458 206 vpd->vcpuid[3] = cpuid3.value;
djm@6458 207
djm@6458 208 vpd->vdc.d_vmsw = 1;
djm@6458 209 return vpd;
djm@6458 210 }
djm@6458 211
djm@6458 212
djm@6458 213 /*
djm@6458 214 * Create a VP on intialized VMX environment.
djm@6458 215 */
djm@6458 216 static void
djm@6458 217 vmx_create_vp(struct vcpu *v)
djm@6458 218 {
djm@6458 219 u64 ret;
djm@6801 220 vpd_t *vpd = v->arch.privregs;
djm@6458 221 u64 ivt_base;
djm@6458 222 extern char vmx_ia64_ivt;
djm@6458 223 /* ia64_ivt is function pointer, so need this tranlation */
djm@6458 224 ivt_base = (u64) &vmx_ia64_ivt;
djm@6458 225 printk("ivt_base: 0x%lx\n", ivt_base);
djm@6458 226 ret = ia64_pal_vp_create(vpd, ivt_base, 0);
djm@6458 227 if (ret != PAL_STATUS_SUCCESS)
djm@6458 228 panic("ia64_pal_vp_create failed. \n");
djm@6458 229 }
djm@6458 230
djm@6458 231 #ifdef XEN_DBL_MAPPING
djm@6458 232 void vmx_init_double_mapping_stub(void)
djm@6458 233 {
djm@6458 234 u64 base, psr;
djm@6458 235 extern void vmx_switch_rr7(void);
djm@6458 236
djm@6458 237 base = (u64) &vmx_switch_rr7;
djm@6458 238 base = *((u64*)base);
djm@6458 239
djm@6458 240 psr = ia64_clear_ic();
djm@6458 241 ia64_itr(0x1, IA64_TR_RR7_SWITCH_STUB, XEN_RR7_SWITCH_STUB,
djm@6458 242 pte_val(pfn_pte(__pa(base) >> PAGE_SHIFT, PAGE_KERNEL)),
djm@6458 243 RR7_SWITCH_SHIFT);
djm@6458 244 ia64_set_psr(psr);
djm@6458 245 ia64_srlz_i();
djm@6458 246 printk("Add TR mapping for rr7 switch stub, with physical: 0x%lx\n", (u64)(__pa(base)));
djm@6458 247 }
djm@6458 248 #endif
djm@6458 249
djm@6458 250 /* Other non-context related tasks can be done in context switch */
djm@6458 251 void
djm@6458 252 vmx_save_state(struct vcpu *v)
djm@6458 253 {
djm@6458 254 u64 status, psr;
djm@6458 255 u64 old_rr0, dom_rr7, rr0_xen_start, rr0_vhpt;
djm@6458 256
djm@6458 257 /* FIXME: about setting of pal_proc_vector... time consuming */
djm@6801 258 status = ia64_pal_vp_save(v->arch.privregs, 0);
djm@6458 259 if (status != PAL_STATUS_SUCCESS)
djm@6458 260 panic("Save vp status failed\n");
djm@6458 261
djm@6458 262 #ifdef XEN_DBL_MAPPING
djm@6458 263 /* FIXME: Do we really need purge double mapping for old vcpu?
djm@6458 264 * Since rid is completely different between prev and next,
djm@6458 265 * it's not overlap and thus no MCA possible... */
djm@6458 266 dom_rr7 = vmx_vrrtomrr(v, VMX(v, vrr[7]));
djm@6458 267 vmx_purge_double_mapping(dom_rr7, KERNEL_START,
djm@6458 268 (u64)v->arch.vtlb->ts->vhpt->hash);
djm@6458 269 #endif
djm@6458 270
djm@6458 271 /* Need to save KR when domain switch, though HV itself doesn;t
djm@6458 272 * use them.
djm@6458 273 */
djm@6458 274 v->arch.arch_vmx.vkr[0] = ia64_get_kr(0);
djm@6458 275 v->arch.arch_vmx.vkr[1] = ia64_get_kr(1);
djm@6458 276 v->arch.arch_vmx.vkr[2] = ia64_get_kr(2);
djm@6458 277 v->arch.arch_vmx.vkr[3] = ia64_get_kr(3);
djm@6458 278 v->arch.arch_vmx.vkr[4] = ia64_get_kr(4);
djm@6458 279 v->arch.arch_vmx.vkr[5] = ia64_get_kr(5);
djm@6458 280 v->arch.arch_vmx.vkr[6] = ia64_get_kr(6);
djm@6458 281 v->arch.arch_vmx.vkr[7] = ia64_get_kr(7);
djm@6458 282 }
djm@6458 283
djm@6458 284 /* Even guest is in physical mode, we still need such double mapping */
djm@6458 285 void
djm@6458 286 vmx_load_state(struct vcpu *v)
djm@6458 287 {
djm@6458 288 u64 status, psr;
djm@6458 289 u64 old_rr0, dom_rr7, rr0_xen_start, rr0_vhpt;
djm@6458 290 u64 pte_xen, pte_vhpt;
djm@6458 291 int i;
djm@6458 292
djm@6801 293 status = ia64_pal_vp_restore(v->arch.privregs, 0);
djm@6458 294 if (status != PAL_STATUS_SUCCESS)
djm@6458 295 panic("Restore vp status failed\n");
djm@6458 296
djm@6458 297 #ifdef XEN_DBL_MAPPING
djm@6458 298 dom_rr7 = vmx_vrrtomrr(v, VMX(v, vrr[7]));
djm@6458 299 pte_xen = pte_val(pfn_pte((xen_pstart >> PAGE_SHIFT), PAGE_KERNEL));
djm@6458 300 pte_vhpt = pte_val(pfn_pte((__pa(v->arch.vtlb->ts->vhpt->hash) >> PAGE_SHIFT), PAGE_KERNEL));
djm@6458 301 vmx_insert_double_mapping(dom_rr7, KERNEL_START,
djm@6458 302 (u64)v->arch.vtlb->ts->vhpt->hash,
djm@6458 303 pte_xen, pte_vhpt);
djm@6458 304 #endif
djm@6458 305
djm@6458 306 ia64_set_kr(0, v->arch.arch_vmx.vkr[0]);
djm@6458 307 ia64_set_kr(1, v->arch.arch_vmx.vkr[1]);
djm@6458 308 ia64_set_kr(2, v->arch.arch_vmx.vkr[2]);
djm@6458 309 ia64_set_kr(3, v->arch.arch_vmx.vkr[3]);
djm@6458 310 ia64_set_kr(4, v->arch.arch_vmx.vkr[4]);
djm@6458 311 ia64_set_kr(5, v->arch.arch_vmx.vkr[5]);
djm@6458 312 ia64_set_kr(6, v->arch.arch_vmx.vkr[6]);
djm@6458 313 ia64_set_kr(7, v->arch.arch_vmx.vkr[7]);
djm@6458 314 /* Guest vTLB is not required to be switched explicitly, since
djm@6458 315 * anchored in vcpu */
djm@6458 316 }
djm@6458 317
djm@6458 318 #ifdef XEN_DBL_MAPPING
djm@6458 319 /* Purge old double mapping and insert new one, due to rr7 change */
djm@6458 320 void
djm@6458 321 vmx_change_double_mapping(struct vcpu *v, u64 oldrr7, u64 newrr7)
djm@6458 322 {
djm@6458 323 u64 pte_xen, pte_vhpt, vhpt_base;
djm@6458 324
djm@6458 325 vhpt_base = (u64)v->arch.vtlb->ts->vhpt->hash;
djm@6458 326 vmx_purge_double_mapping(oldrr7, KERNEL_START,
djm@6458 327 vhpt_base);
djm@6458 328
djm@6458 329 pte_xen = pte_val(pfn_pte((xen_pstart >> PAGE_SHIFT), PAGE_KERNEL));
djm@6458 330 pte_vhpt = pte_val(pfn_pte((__pa(vhpt_base) >> PAGE_SHIFT), PAGE_KERNEL));
djm@6458 331 vmx_insert_double_mapping(newrr7, KERNEL_START,
djm@6458 332 vhpt_base,
djm@6458 333 pte_xen, pte_vhpt);
djm@6458 334 }
djm@6458 335 #endif // XEN_DBL_MAPPING
djm@6458 336
djm@6458 337 /*
djm@6458 338 * Initialize VMX envirenment for guest. Only the 1st vp/vcpu
djm@6458 339 * is registered here.
djm@6458 340 */
djm@6458 341 void
djm@6458 342 vmx_final_setup_domain(struct domain *d)
djm@6458 343 {
djm@6458 344 struct vcpu *v = d->vcpu[0];
djm@6458 345 vpd_t *vpd;
djm@6458 346
djm@6458 347 /* Allocate resources for vcpu 0 */
djm@6458 348 //memset(&v->arch.arch_vmx, 0, sizeof(struct arch_vmx_struct));
djm@6458 349
djm@6458 350 vpd = alloc_vpd();
djm@6458 351 ASSERT(vpd);
djm@6458 352
djm@6801 353 // v->arch.arch_vmx.vpd = vpd;
djm@6801 354 v->arch.privregs = vpd;
djm@6458 355 vpd->virt_env_vaddr = vm_buffer;
djm@6458 356
djm@6878 357 /* Per-domain vTLB and vhpt implementation. Now vmx domain will stick
djm@6878 358 * to this solution. Maybe it can be deferred until we know created
djm@6878 359 * one as vmx domain */
djm@6878 360 v->arch.vtlb = init_domain_tlb(v);
djm@6878 361
djm@6458 362 /* v->arch.schedule_tail = arch_vmx_do_launch; */
djm@6458 363 vmx_create_vp(v);
djm@6458 364
djm@6458 365 /* Set this ed to be vmx */
djm@6458 366 set_bit(ARCH_VMX_VMCS_LOADED, &v->arch.arch_vmx.flags);
djm@6458 367
djm@6458 368 /* Physical mode emulation initialization, including
djm@6458 369 * emulation ID allcation and related memory request
djm@6458 370 */
djm@6458 371 physical_mode_init(v);
djm@6458 372
djm@6458 373 vlsapic_reset(v);
djm@6458 374 vtm_init(v);
djm@6458 375
djm@6458 376 /* Other vmx specific initialization work */
djm@6458 377 }
djm@6799 378
djm@6799 379 /*
djm@6799 380 * Following stuff should really move to domain builder. However currently
djm@6799 381 * XEN/IA64 doesn't export physical -> machine page table to domain builder,
djm@6799 382 * instead only the copy. Also there's no hypercall to notify hypervisor
djm@6799 383 * IO ranges by far. Let's enhance it later.
djm@6799 384 */
djm@6799 385
djm@6799 386 #define MEM_G (1UL << 30)
djm@6799 387 #define MEM_M (1UL << 20)
djm@6799 388
djm@6799 389 #define MMIO_START (3 * MEM_G)
djm@6799 390 #define MMIO_SIZE (512 * MEM_M)
djm@6799 391
djm@6799 392 #define VGA_IO_START 0xA0000UL
djm@6799 393 #define VGA_IO_SIZE 0x20000
djm@6799 394
djm@6799 395 #define LEGACY_IO_START (MMIO_START + MMIO_SIZE)
djm@6799 396 #define LEGACY_IO_SIZE (64*MEM_M)
djm@6799 397
djm@6799 398 #define IO_PAGE_START (LEGACY_IO_START + LEGACY_IO_SIZE)
djm@6799 399 #define IO_PAGE_SIZE PAGE_SIZE
djm@6799 400
djm@6799 401 #define STORE_PAGE_START (IO_PAGE_START + IO_PAGE_SIZE)
djm@6799 402 #define STORE_PAGE_SIZE PAGE_SIZE
djm@6799 403
djm@6799 404 #define IO_SAPIC_START 0xfec00000UL
djm@6799 405 #define IO_SAPIC_SIZE 0x100000
djm@6799 406
djm@6799 407 #define PIB_START 0xfee00000UL
djm@6799 408 #define PIB_SIZE 0x100000
djm@6799 409
djm@6799 410 #define GFW_START (4*MEM_G -16*MEM_M)
djm@6799 411 #define GFW_SIZE (16*MEM_M)
djm@6799 412
djm@6799 413 typedef struct io_range {
djm@6799 414 unsigned long start;
djm@6799 415 unsigned long size;
djm@6799 416 unsigned long type;
djm@6799 417 } io_range_t;
djm@6799 418
djm@6799 419 io_range_t io_ranges[] = {
djm@6799 420 {VGA_IO_START, VGA_IO_SIZE, GPFN_FRAME_BUFFER},
djm@6799 421 {MMIO_START, MMIO_SIZE, GPFN_LOW_MMIO},
djm@6799 422 {LEGACY_IO_START, LEGACY_IO_SIZE, GPFN_LEGACY_IO},
djm@6799 423 {IO_SAPIC_START, IO_SAPIC_SIZE, GPFN_IOSAPIC},
djm@6799 424 {PIB_START, PIB_SIZE, GPFN_PIB},
djm@6799 425 };
djm@6799 426
djm@6799 427 #define VMX_SYS_PAGES (2 + GFW_SIZE >> PAGE_SHIFT)
djm@6799 428 #define VMX_CONFIG_PAGES(d) ((d)->max_pages - VMX_SYS_PAGES)
djm@6799 429
djm@6799 430 int vmx_alloc_contig_pages(struct domain *d)
djm@6799 431 {
djm@6799 432 unsigned int order, i, j;
djm@6799 433 unsigned long start, end, pgnr, conf_nr;
djm@6799 434 struct pfn_info *page;
djm@6799 435 struct vcpu *v = d->vcpu[0];
djm@6799 436
djm@6799 437 ASSERT(!test_bit(ARCH_VMX_CONTIG_MEM, &v->arch.arch_vmx.flags));
djm@6799 438
djm@6799 439 conf_nr = VMX_CONFIG_PAGES(d);
djm@6799 440 order = get_order_from_pages(conf_nr);
djm@6799 441 if (unlikely((page = alloc_domheap_pages(d, order, 0)) == NULL)) {
djm@6799 442 printk("Could not allocate order=%d pages for vmx contig alloc\n",
djm@6799 443 order);
djm@6799 444 return -1;
djm@6799 445 }
djm@6799 446
djm@6799 447 /* Map normal memory below 3G */
djm@6799 448 pgnr = page_to_pfn(page);
djm@6799 449 end = conf_nr << PAGE_SHIFT;
djm@6799 450 for (i = 0;
djm@6799 451 i < (end < MMIO_START ? end : MMIO_START);
djm@6799 452 i += PAGE_SIZE, pgnr++)
djm@6799 453 map_domain_page(d, i, pgnr << PAGE_SHIFT);
djm@6799 454
djm@6799 455 /* Map normal memory beyond 4G */
djm@6799 456 if (unlikely(end > MMIO_START)) {
djm@6799 457 start = 4 * MEM_G;
djm@6799 458 end = start + (end - 3 * MEM_G);
djm@6799 459 for (i = start; i < end; i += PAGE_SIZE, pgnr++)
djm@6799 460 map_domain_page(d, i, pgnr << PAGE_SHIFT);
djm@6799 461 }
djm@6799 462
djm@6799 463 d->arch.max_pfn = end >> PAGE_SHIFT;
djm@6799 464
djm@6799 465 order = get_order_from_pages(VMX_SYS_PAGES);
djm@6799 466 if (unlikely((page = alloc_domheap_pages(d, order, 0)) == NULL)) {
djm@6799 467 printk("Could not allocate order=%d pages for vmx contig alloc\n",
djm@6799 468 order);
djm@6799 469 return -1;
djm@6799 470 }
djm@6799 471
djm@6799 472 /* Map for shared I/O page and xenstore */
djm@6799 473 pgnr = page_to_pfn(page);
djm@6799 474 map_domain_page(d, IO_PAGE_START, pgnr << PAGE_SHIFT);
djm@6799 475 pgnr++;
djm@6799 476 map_domain_page(d, STORE_PAGE_START, pgnr << PAGE_SHIFT);
djm@6799 477 pgnr++;
djm@6799 478
djm@6799 479 /* Map guest firmware */
djm@6799 480 for (i = GFW_START; i < GFW_START + GFW_SIZE; i += PAGE_SIZE, pgnr++)
djm@6799 481 map_domain_page(d, i, pgnr << PAGE_SHIFT);
djm@6799 482
djm@6799 483 /* Mark I/O ranges */
djm@6799 484 for (i = 0; i < (sizeof(io_ranges) / sizeof(io_range_t)); i++) {
djm@6799 485 for (j = io_ranges[i].start;
djm@6799 486 j < io_ranges[i].start + io_ranges[i].size;
djm@6799 487 j += PAGE_SIZE)
djm@6878 488 map_domain_page(d, j, io_ranges[i].type);
djm@6799 489 }
djm@6799 490
djm@6799 491 set_bit(ARCH_VMX_CONTIG_MEM, &v->arch.arch_vmx.flags);
djm@6799 492 return 0;
djm@6799 493 }