3 // Copyright (C) 2011 Citrix Systems.
5 // This file may be distributed under the terms of the GNU LGPLv3 license.
10 #include "memmap.h" // add_e820
11 #include "types.h" // ASM32FLAT
12 #include "util.h" // copy_acpi_rsdp
14 #define INFO_PHYSICAL_ADDRESS 0x00001000
16 u32 xen_cpuid_base = 0;
18 struct xen_seabios_info {
19 char signature[14]; /* XenHVMSeaBIOS\0 */
20 u8 length; /* Length of this struct */
21 u8 checksum; /* Set such that the sum over bytes 0..length == 0 */
23 * Physical address of an array of tables_nr elements.
25 * Each element is a 32 bit value contianing the physical address
31 * Physical address of the e820 table, contains e820_nr entries.
37 static void validate_info(struct xen_seabios_info *t)
39 if ( memcmp(t->signature, "XenHVMSeaBIOS", 14) )
40 panic("Bad Xen info signature\n");
42 if ( t->length < sizeof(struct xen_seabios_info) )
43 panic("Bad Xen info length\n");
45 if (checksum(t, t->length) != 0)
46 panic("Bad Xen info checksum\n");
51 u32 base, eax, ebx, ecx, edx;
57 for (base = 0x40000000; base < 0x40010000; base += 0x100) {
58 cpuid(base, &eax, &ebx, &ecx, &edx);
59 memcpy(signature + 0, &ebx, 4);
60 memcpy(signature + 4, &ecx, 4);
61 memcpy(signature + 8, &edx, 4);
64 dprintf(1, "Found hypervisor signature \"%s\" at %x\n",
66 if (strcmp(signature, "XenVMMXenVMM") == 0) {
68 panic("Insufficient Xen cpuid leaves. eax=%x at base %x\n",
70 xen_cpuid_base = base;
76 static int hypercall_xen_version( int cmd, void *arg)
78 return _hypercall2(int, xen_version, cmd, arg);
81 /* Fill in hypercall transfer pages. */
82 void xen_init_hypercalls(void)
84 u32 eax, ebx, ecx, edx;
85 xen_extraversion_t extraversion;
91 cpuid(xen_cpuid_base + 2, &eax, &ebx, &ecx, &edx);
93 xen_hypercall_page = (unsigned long)memalign_high(PAGE_SIZE, eax*PAGE_SIZE);
94 if (!xen_hypercall_page)
95 panic("unable to allocate Xen hypercall page\n");
97 dprintf(1, "Allocated Xen hypercall page at %lx\n", xen_hypercall_page);
98 for ( i = 0; i < eax; i++ )
99 wrmsr(ebx, xen_hypercall_page + (i << 12) + i);
101 /* Print version information. */
102 cpuid(xen_cpuid_base + 1, &eax, &ebx, &ecx, &edx);
103 hypercall_xen_version(XENVER_extraversion, extraversion);
104 dprintf(1, "Detected Xen v%u.%u%s\n", eax >> 16, eax & 0xffff, extraversion);
107 void xen_copy_biostables(void)
109 struct xen_seabios_info *info = (void *)INFO_PHYSICAL_ADDRESS;
110 u32 *tables = (u32 *)info->tables;
113 dprintf(1, "xen: copy BIOS tables...\n");
114 for (i=0; i<info->tables_nr; i++) {
115 void *table = (void *)tables[i];
116 copy_acpi_rsdp(table);
125 u64 maxram = 0, maxram_over4G = 0;
127 struct xen_seabios_info *info = (void *)INFO_PHYSICAL_ADDRESS;
128 struct e820entry *e820 = (struct e820entry *)info->e820;
131 dprintf(1, "xen: copy e820...\n");
133 for (i = 0; i < info->e820_nr; i++) {
134 struct e820entry *e = &e820[i];
135 if (e->type == E820_ACPI || e->type == E820_RAM) {
136 u64 end = e->start + e->size;
137 if (end > 0x100000000ull) {
138 end -= 0x100000000ull;
139 if (end > maxram_over4G)
141 } else if (end > maxram)
144 add_e820(e->start, e->size, e->type);
148 RamSizeOver4G = maxram_over4G;