From 3e83b579d0e9368f0f8223c24eac9898b9623aa2 Mon Sep 17 00:00:00 2001
From: Sheng Yang <sheng.yang@intel.com>
Date: Fri, 14 Sep 2007 09:51:54 +0800
Subject: [PATCH] Add a slot for apic access usage, not elegant but no choice

---
 user/kvmctl.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/user/kvmctl.c b/user/kvmctl.c
index f358dc1..7e75945 100644
--- a/user/kvmctl.c
+++ b/user/kvmctl.c
@@ -248,6 +248,7 @@ int kvm_create(kvm_context_t kvm, unsigned long phys_mem_bytes, void **vm_mem)
 	unsigned long dosmem = 0xa0000;
 	unsigned long exmem = 0xc0000;
 	unsigned long pcimem = 0xf0000000;
+	unsigned long apicmem= 0xfee00000;
 	unsigned long memory = (phys_mem_bytes + PAGE_SIZE - 1) & PAGE_MASK;
 	int fd = kvm->fd;
 	int zfd;
@@ -267,6 +268,11 @@ int kvm_create(kvm_context_t kvm, unsigned long phys_mem_bytes, void **vm_mem)
 		.memory_size = memory < pcimem ? 0 : memory - pcimem,
 		.guest_phys_addr = 0x100000000,
 	};
+	struct kvm_memory_region apic_memory = {
+		.slot = 5,
+		.memory_size = PAGE_SIZE,
+		.guest_phys_addr = apicmem,
+	};
 
 	if (memory >= pcimem)
 		extended_memory.memory_size = pcimem - exmem;
@@ -302,9 +308,16 @@ int kvm_create(kvm_context_t kvm, unsigned long phys_mem_bytes, void **vm_mem)
 		}
 	}
 
+	r = ioctl(fd, KVM_SET_MEMORY_REGION, &apic_memory);
+	if (r == -1) {
+		fprintf(stderr, "kvm_create_memory_region: %m\n");
+		return -1;
+	}
+
 	kvm_memory_region_save_params(kvm, &low_memory);
 	kvm_memory_region_save_params(kvm, &extended_memory);
 	kvm_memory_region_save_params(kvm, &above_4g_memory);
+	kvm_memory_region_save_params(kvm, &apic_memory);
 
 	*vm_mem = mmap(NULL, memory, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
 	if (*vm_mem == MAP_FAILED) {
-- 
1.5.2

