Linux Audio

Check our new training course

Loading...
v6.2
 1// SPDX-License-Identifier: GPL-2.0
 2#include <linux/acpi.h>
 3#include <linux/export.h>
 
 4
 5#include <xen/hvc-console.h>
 6
 
 7#include <asm/io_apic.h>
 8#include <asm/hypervisor.h>
 9#include <asm/e820/api.h>
10
11#include <xen/xen.h>
12#include <asm/xen/interface.h>
13#include <asm/xen/hypercall.h>
14
15#include <xen/interface/memory.h>
16
17#include "xen-ops.h"
18
19/*
20 * PVH variables.
21 *
22 * The variable xen_pvh needs to live in a data segment since it is used
23 * after startup_{32|64} is invoked, which will clear the .bss segment.
24 */
25bool __ro_after_init xen_pvh;
26EXPORT_SYMBOL_GPL(xen_pvh);
27
28void __init xen_pvh_init(struct boot_params *boot_params)
29{
30	u32 msr;
31	u64 pfn;
32
33	xen_pvh = 1;
34	xen_domain_type = XEN_HVM_DOMAIN;
35	xen_start_flags = pvh_start_info.flags;
36
37	msr = cpuid_ebx(xen_cpuid_base() + 2);
38	pfn = __pa(hypercall_page);
39	wrmsr_safe(msr, (u32)pfn, (u32)(pfn >> 32));
40
41	if (xen_initial_domain())
42		x86_init.oem.arch_setup = xen_add_preferred_consoles;
43	x86_init.oem.banner = xen_banner;
44
45	xen_efi_init(boot_params);
 
 
 
 
 
 
 
 
 
 
 
 
 
46}
47
48void __init mem_map_via_hcall(struct boot_params *boot_params_p)
49{
50	struct xen_memory_map memmap;
51	int rc;
52
53	memmap.nr_entries = ARRAY_SIZE(boot_params_p->e820_table);
54	set_xen_guest_handle(memmap.buffer, boot_params_p->e820_table);
55	rc = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap);
56	if (rc) {
57		xen_raw_printk("XENMEM_memory_map failed (%d)\n", rc);
58		BUG();
59	}
60	boot_params_p->e820_entries = memmap.nr_entries;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61}
v6.9.4
  1// SPDX-License-Identifier: GPL-2.0
  2#include <linux/acpi.h>
  3#include <linux/export.h>
  4#include <linux/mm.h>
  5
  6#include <xen/hvc-console.h>
  7
  8#include <asm/bootparam.h>
  9#include <asm/io_apic.h>
 10#include <asm/hypervisor.h>
 11#include <asm/e820/api.h>
 12
 13#include <xen/xen.h>
 14#include <asm/xen/interface.h>
 15#include <asm/xen/hypercall.h>
 16
 17#include <xen/interface/memory.h>
 18
 19#include "xen-ops.h"
 20
 21/*
 22 * PVH variables.
 23 *
 24 * The variable xen_pvh needs to live in a data segment since it is used
 25 * after startup_{32|64} is invoked, which will clear the .bss segment.
 26 */
 27bool __ro_after_init xen_pvh;
 28EXPORT_SYMBOL_GPL(xen_pvh);
 29
 30void __init xen_pvh_init(struct boot_params *boot_params)
 31{
 32	u32 msr;
 33	u64 pfn;
 34
 35	xen_pvh = 1;
 36	xen_domain_type = XEN_HVM_DOMAIN;
 37	xen_start_flags = pvh_start_info.flags;
 38
 39	msr = cpuid_ebx(xen_cpuid_base() + 2);
 40	pfn = __pa(hypercall_page);
 41	wrmsr_safe(msr, (u32)pfn, (u32)(pfn >> 32));
 42
 43	if (xen_initial_domain())
 44		x86_init.oem.arch_setup = xen_add_preferred_consoles;
 45	x86_init.oem.banner = xen_banner;
 46
 47	xen_efi_init(boot_params);
 48
 49	if (xen_initial_domain()) {
 50		struct xen_platform_op op = {
 51			.cmd = XENPF_get_dom0_console,
 52		};
 53		int ret = HYPERVISOR_platform_op(&op);
 54
 55		if (ret > 0)
 56			xen_init_vga(&op.u.dom0_console,
 57				     min(ret * sizeof(char),
 58					 sizeof(op.u.dom0_console)),
 59				     &boot_params->screen_info);
 60	}
 61}
 62
 63void __init mem_map_via_hcall(struct boot_params *boot_params_p)
 64{
 65	struct xen_memory_map memmap;
 66	int rc;
 67
 68	memmap.nr_entries = ARRAY_SIZE(boot_params_p->e820_table);
 69	set_xen_guest_handle(memmap.buffer, boot_params_p->e820_table);
 70	rc = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap);
 71	if (rc) {
 72		xen_raw_printk("XENMEM_memory_map failed (%d)\n", rc);
 73		BUG();
 74	}
 75	boot_params_p->e820_entries = memmap.nr_entries;
 76}
 77
 78/*
 79 * Reserve e820 UNUSABLE regions to inflate the memory balloon.
 80 *
 81 * On PVH dom0 the host memory map is used, RAM regions available to dom0 are
 82 * located as the same place as in the native memory map, but since dom0 gets
 83 * less memory than the total amount of host RAM the ranges that can't be
 84 * populated are converted from RAM -> UNUSABLE.  Use such regions (up to the
 85 * ratio signaled in EXTRA_MEM_RATIO) in order to inflate the balloon driver at
 86 * boot.  Doing so prevents the guest (even if just temporary) from using holes
 87 * in the memory map in order to map grants or foreign addresses, and
 88 * hopefully limits the risk of a clash with a device MMIO region.  Ideally the
 89 * hypervisor should notify us which memory ranges are suitable for creating
 90 * foreign mappings, but that's not yet implemented.
 91 */
 92void __init xen_reserve_extra_memory(struct boot_params *bootp)
 93{
 94	unsigned int i, ram_pages = 0, extra_pages;
 95
 96	for (i = 0; i < bootp->e820_entries; i++) {
 97		struct boot_e820_entry *e = &bootp->e820_table[i];
 98
 99		if (e->type != E820_TYPE_RAM)
100			continue;
101		ram_pages += PFN_DOWN(e->addr + e->size) - PFN_UP(e->addr);
102	}
103
104	/* Max amount of extra memory. */
105	extra_pages = EXTRA_MEM_RATIO * ram_pages;
106
107	/*
108	 * Convert UNUSABLE ranges to RAM and reserve them for foreign mapping
109	 * purposes.
110	 */
111	for (i = 0; i < bootp->e820_entries && extra_pages; i++) {
112		struct boot_e820_entry *e = &bootp->e820_table[i];
113		unsigned long pages;
114
115		if (e->type != E820_TYPE_UNUSABLE)
116			continue;
117
118		pages = min(extra_pages,
119			PFN_DOWN(e->addr + e->size) - PFN_UP(e->addr));
120
121		if (pages != (PFN_DOWN(e->addr + e->size) - PFN_UP(e->addr))) {
122			struct boot_e820_entry *next;
123
124			if (bootp->e820_entries ==
125			    ARRAY_SIZE(bootp->e820_table))
126				/* No space left to split - skip region. */
127				continue;
128
129			/* Split entry. */
130			next = e + 1;
131			memmove(next, e,
132				(bootp->e820_entries - i) * sizeof(*e));
133			bootp->e820_entries++;
134			next->addr = PAGE_ALIGN(e->addr) + PFN_PHYS(pages);
135			e->size = next->addr - e->addr;
136			next->size -= e->size;
137		}
138		e->type = E820_TYPE_RAM;
139		extra_pages -= pages;
140
141		xen_add_extra_mem(PFN_UP(e->addr), pages);
142	}
143}