blob: 436c4f003e17fc398cb23ed4aa5928ac3b6c8bc1 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Vitaly Kuznetsov481d6632017-03-14 18:35:39 +01002#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>
9
10#include <asm/xen/interface.h>
11#include <asm/xen/hypercall.h>
12
13#include <xen/interface/memory.h>
14#include <xen/interface/hvm/start_info.h>
15
16/*
17 * PVH variables.
18 *
19 * xen_pvh and pvh_bootparams need to live in data segment since they
20 * are used after startup_{32|64}, which clear .bss, are invoked.
21 */
22bool xen_pvh __attribute__((section(".data"))) = 0;
23struct boot_params pvh_bootparams __attribute__((section(".data")));
24
25struct hvm_start_info pvh_start_info;
26unsigned int pvh_start_info_sz = sizeof(pvh_start_info);
27
Vitaly Kuznetsov481d6632017-03-14 18:35:39 +010028static void __init init_pvh_bootparams(void)
29{
30 struct xen_memory_map memmap;
Vitaly Kuznetsov481d6632017-03-14 18:35:39 +010031 int rc;
32
33 memset(&pvh_bootparams, 0, sizeof(pvh_bootparams));
34
35 memmap.nr_entries = ARRAY_SIZE(pvh_bootparams.e820_table);
36 set_xen_guest_handle(memmap.buffer, pvh_bootparams.e820_table);
37 rc = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap);
38 if (rc) {
39 xen_raw_printk("XENMEM_memory_map failed (%d)\n", rc);
40 BUG();
41 }
Boris Ostrovsky5f6a1612017-04-21 11:13:14 -040042 pvh_bootparams.e820_entries = memmap.nr_entries;
Vitaly Kuznetsov481d6632017-03-14 18:35:39 +010043
Boris Ostrovsky5f6a1612017-04-21 11:13:14 -040044 if (pvh_bootparams.e820_entries < E820_MAX_ENTRIES_ZEROPAGE - 1) {
45 pvh_bootparams.e820_table[pvh_bootparams.e820_entries].addr =
Vitaly Kuznetsov481d6632017-03-14 18:35:39 +010046 ISA_START_ADDRESS;
Boris Ostrovsky5f6a1612017-04-21 11:13:14 -040047 pvh_bootparams.e820_table[pvh_bootparams.e820_entries].size =
Vitaly Kuznetsov481d6632017-03-14 18:35:39 +010048 ISA_END_ADDRESS - ISA_START_ADDRESS;
Boris Ostrovsky5f6a1612017-04-21 11:13:14 -040049 pvh_bootparams.e820_table[pvh_bootparams.e820_entries].type =
Vitaly Kuznetsov481d6632017-03-14 18:35:39 +010050 E820_TYPE_RESERVED;
Boris Ostrovsky5f6a1612017-04-21 11:13:14 -040051 pvh_bootparams.e820_entries++;
Vitaly Kuznetsov481d6632017-03-14 18:35:39 +010052 } else
53 xen_raw_printk("Warning: Can fit ISA range into e820\n");
54
Vitaly Kuznetsov481d6632017-03-14 18:35:39 +010055 pvh_bootparams.hdr.cmd_line_ptr =
56 pvh_start_info.cmdline_paddr;
57
58 /* The first module is always ramdisk. */
59 if (pvh_start_info.nr_modules) {
60 struct hvm_modlist_entry *modaddr =
61 __va(pvh_start_info.modlist_paddr);
62 pvh_bootparams.hdr.ramdisk_image = modaddr->paddr;
63 pvh_bootparams.hdr.ramdisk_size = modaddr->size;
64 }
65
66 /*
67 * See Documentation/x86/boot.txt.
68 *
69 * Version 2.12 supports Xen entry point but we will use default x86/PC
70 * environment (i.e. hardware_subarch 0).
71 */
72 pvh_bootparams.hdr.version = 0x212;
73 pvh_bootparams.hdr.type_of_loader = (9 << 4) | 0; /* Xen loader */
74}
75
76/*
77 * This routine (and those that it might call) should not use
78 * anything that lives in .bss since that segment will be cleared later.
79 */
80void __init xen_prepare_pvh(void)
81{
82 u32 msr;
83 u64 pfn;
84
85 if (pvh_start_info.magic != XEN_HVM_START_MAGIC_VALUE) {
86 xen_raw_printk("Error: Unexpected magic value (0x%08x)\n",
87 pvh_start_info.magic);
88 BUG();
89 }
90
91 xen_pvh = 1;
92
93 msr = cpuid_ebx(xen_cpuid_base() + 2);
94 pfn = __pa(hypercall_page);
95 wrmsr_safe(msr, (u32)pfn, (u32)(pfn >> 32));
96
97 init_pvh_bootparams();
Vitaly Kuznetsov481d6632017-03-14 18:35:39 +010098}