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