Vitaly Kuznetsov | 481d663 | 2017-03-14 18:35:39 +0100 | [diff] [blame^] | 1 | #include <linux/acpi.h> |
| 2 | |
| 3 | #include <xen/hvc-console.h> |
| 4 | |
| 5 | #include <asm/io_apic.h> |
| 6 | #include <asm/hypervisor.h> |
| 7 | #include <asm/e820/api.h> |
| 8 | |
| 9 | #include <asm/xen/interface.h> |
| 10 | #include <asm/xen/hypercall.h> |
| 11 | |
| 12 | #include <xen/interface/memory.h> |
| 13 | #include <xen/interface/hvm/start_info.h> |
| 14 | |
| 15 | /* |
| 16 | * PVH variables. |
| 17 | * |
| 18 | * xen_pvh and pvh_bootparams need to live in data segment since they |
| 19 | * are used after startup_{32|64}, which clear .bss, are invoked. |
| 20 | */ |
| 21 | bool xen_pvh __attribute__((section(".data"))) = 0; |
| 22 | struct boot_params pvh_bootparams __attribute__((section(".data"))); |
| 23 | |
| 24 | struct hvm_start_info pvh_start_info; |
| 25 | unsigned int pvh_start_info_sz = sizeof(pvh_start_info); |
| 26 | |
| 27 | static void xen_pvh_arch_setup(void) |
| 28 | { |
| 29 | /* Make sure we don't fall back to (default) ACPI_IRQ_MODEL_PIC. */ |
| 30 | if (nr_ioapics == 0) |
| 31 | acpi_irq_model = ACPI_IRQ_MODEL_PLATFORM; |
| 32 | } |
| 33 | |
| 34 | static void __init init_pvh_bootparams(void) |
| 35 | { |
| 36 | struct xen_memory_map memmap; |
| 37 | unsigned int i; |
| 38 | int rc; |
| 39 | |
| 40 | memset(&pvh_bootparams, 0, sizeof(pvh_bootparams)); |
| 41 | |
| 42 | memmap.nr_entries = ARRAY_SIZE(pvh_bootparams.e820_table); |
| 43 | set_xen_guest_handle(memmap.buffer, pvh_bootparams.e820_table); |
| 44 | rc = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap); |
| 45 | if (rc) { |
| 46 | xen_raw_printk("XENMEM_memory_map failed (%d)\n", rc); |
| 47 | BUG(); |
| 48 | } |
| 49 | |
| 50 | if (memmap.nr_entries < E820_MAX_ENTRIES_ZEROPAGE - 1) { |
| 51 | pvh_bootparams.e820_table[memmap.nr_entries].addr = |
| 52 | ISA_START_ADDRESS; |
| 53 | pvh_bootparams.e820_table[memmap.nr_entries].size = |
| 54 | ISA_END_ADDRESS - ISA_START_ADDRESS; |
| 55 | pvh_bootparams.e820_table[memmap.nr_entries].type = |
| 56 | E820_TYPE_RESERVED; |
| 57 | memmap.nr_entries++; |
| 58 | } else |
| 59 | xen_raw_printk("Warning: Can fit ISA range into e820\n"); |
| 60 | |
| 61 | pvh_bootparams.e820_entries = memmap.nr_entries; |
| 62 | for (i = 0; i < pvh_bootparams.e820_entries; i++) |
| 63 | e820__range_add(pvh_bootparams.e820_table[i].addr, |
| 64 | pvh_bootparams.e820_table[i].size, |
| 65 | pvh_bootparams.e820_table[i].type); |
| 66 | |
| 67 | e820__update_table(e820_table); |
| 68 | |
| 69 | pvh_bootparams.hdr.cmd_line_ptr = |
| 70 | pvh_start_info.cmdline_paddr; |
| 71 | |
| 72 | /* The first module is always ramdisk. */ |
| 73 | if (pvh_start_info.nr_modules) { |
| 74 | struct hvm_modlist_entry *modaddr = |
| 75 | __va(pvh_start_info.modlist_paddr); |
| 76 | pvh_bootparams.hdr.ramdisk_image = modaddr->paddr; |
| 77 | pvh_bootparams.hdr.ramdisk_size = modaddr->size; |
| 78 | } |
| 79 | |
| 80 | /* |
| 81 | * See Documentation/x86/boot.txt. |
| 82 | * |
| 83 | * Version 2.12 supports Xen entry point but we will use default x86/PC |
| 84 | * environment (i.e. hardware_subarch 0). |
| 85 | */ |
| 86 | pvh_bootparams.hdr.version = 0x212; |
| 87 | pvh_bootparams.hdr.type_of_loader = (9 << 4) | 0; /* Xen loader */ |
| 88 | } |
| 89 | |
| 90 | /* |
| 91 | * This routine (and those that it might call) should not use |
| 92 | * anything that lives in .bss since that segment will be cleared later. |
| 93 | */ |
| 94 | void __init xen_prepare_pvh(void) |
| 95 | { |
| 96 | u32 msr; |
| 97 | u64 pfn; |
| 98 | |
| 99 | if (pvh_start_info.magic != XEN_HVM_START_MAGIC_VALUE) { |
| 100 | xen_raw_printk("Error: Unexpected magic value (0x%08x)\n", |
| 101 | pvh_start_info.magic); |
| 102 | BUG(); |
| 103 | } |
| 104 | |
| 105 | xen_pvh = 1; |
| 106 | |
| 107 | msr = cpuid_ebx(xen_cpuid_base() + 2); |
| 108 | pfn = __pa(hypercall_page); |
| 109 | wrmsr_safe(msr, (u32)pfn, (u32)(pfn >> 32)); |
| 110 | |
| 111 | init_pvh_bootparams(); |
| 112 | |
| 113 | x86_init.oem.arch_setup = xen_pvh_arch_setup; |
| 114 | } |