Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #include <linux/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/kexec.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/memblock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <xen/features.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <xen/events.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <xen/interface/memory.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <asm/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <asm/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <asm/io_apic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <asm/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <asm/idtentry.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <asm/hypervisor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <asm/e820/api.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <asm/early_ioremap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <asm/xen/cpuid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <asm/xen/hypervisor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <asm/xen/page.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include "xen-ops.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include "mmu.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include "smp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) static unsigned long shared_info_pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) void xen_hvm_init_shared_info(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	struct xen_add_to_physmap xatp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	xatp.domid = DOMID_SELF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	xatp.idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	xatp.space = XENMAPSPACE_shared_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	xatp.gpfn = shared_info_pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	if (HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) static void __init reserve_shared_info(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	u64 pa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	 * Search for a free page starting at 4kB physical address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	 * Low memory is preferred to avoid an EPT large page split up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	 * by the mapping.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	 * Starting below X86_RESERVE_LOW (usually 64kB) is fine as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	 * the BIOS used for HVM guests is well behaved and won't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	 * clobber memory other than the first 4kB.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	for (pa = PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	     !e820__mapped_all(pa, pa + PAGE_SIZE, E820_TYPE_RAM) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	     memblock_is_reserved(pa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	     pa += PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	shared_info_pfn = PHYS_PFN(pa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	memblock_reserve(pa, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	HYPERVISOR_shared_info = early_memremap(pa, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) static void __init xen_hvm_init_mem_mapping(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	early_memunmap(HYPERVISOR_shared_info, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	HYPERVISOR_shared_info = __va(PFN_PHYS(shared_info_pfn));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	 * The virtual address of the shared_info page has changed, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	 * the vcpu_info pointer for VCPU 0 is now stale.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	 * The prepare_boot_cpu callback will re-initialize it via
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	 * xen_vcpu_setup, but we can't rely on that to be called for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	 * old Xen versions (xen_have_vector_callback == 0).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	 * It is, in any case, bad to have a stale vcpu_info pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	 * so reset it now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	xen_vcpu_info_reset(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) static void __init init_hvm_pv_info(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	int major, minor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	uint32_t eax, ebx, ecx, edx, base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	base = xen_cpuid_base();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	eax = cpuid_eax(base + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	major = eax >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	minor = eax & 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	printk(KERN_INFO "Xen version %d.%d.\n", major, minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	xen_domain_type = XEN_HVM_DOMAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	/* PVH set up hypercall page in xen_prepare_pvh(). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	if (xen_pvh_domain())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		pv_info.name = "Xen PVH";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		u64 pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		uint32_t msr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		pv_info.name = "Xen HVM";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		msr = cpuid_ebx(base + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		pfn = __pa(hypercall_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		wrmsr_safe(msr, (u32)pfn, (u32)(pfn >> 32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	xen_setup_features();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	cpuid(base + 4, &eax, &ebx, &ecx, &edx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	if (eax & XEN_HVM_CPUID_VCPU_ID_PRESENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		this_cpu_write(xen_vcpu_id, ebx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		this_cpu_write(xen_vcpu_id, smp_processor_id());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) DEFINE_IDTENTRY_SYSVEC(sysvec_xen_hvm_callback)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	struct pt_regs *old_regs = set_irq_regs(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	inc_irq_stat(irq_hv_callback_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	xen_hvm_evtchn_do_upcall();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	set_irq_regs(old_regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) #ifdef CONFIG_KEXEC_CORE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static void xen_hvm_shutdown(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	native_machine_shutdown();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	if (kexec_in_progress)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		xen_reboot(SHUTDOWN_soft_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static void xen_hvm_crash_shutdown(struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	native_machine_crash_shutdown(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	xen_reboot(SHUTDOWN_soft_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static int xen_cpu_up_prepare_hvm(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	 * This can happen if CPU was offlined earlier and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	 * offlining timed out in common_cpu_die().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	if (cpu_report_state(cpu) == CPU_DEAD_FROZEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		xen_smp_intr_free(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		xen_uninit_lock_cpu(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	if (cpu_acpi_id(cpu) != U32_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		per_cpu(xen_vcpu_id, cpu) = cpu_acpi_id(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		per_cpu(xen_vcpu_id, cpu) = cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	rc = xen_vcpu_setup(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	if (xen_have_vector_callback && xen_feature(XENFEAT_hvm_safe_pvclock))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		xen_setup_timer(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	rc = xen_smp_intr_init(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		WARN(1, "xen_smp_intr_init() for CPU %d failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		     cpu, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) static int xen_cpu_dead_hvm(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	xen_smp_intr_free(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	if (xen_have_vector_callback && xen_feature(XENFEAT_hvm_safe_pvclock))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		xen_teardown_timer(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)        return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) static bool no_vector_callback __initdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) static void __init xen_hvm_guest_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	if (xen_pv_domain())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	init_hvm_pv_info();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	reserve_shared_info();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	xen_hvm_init_shared_info();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	 * xen_vcpu is a pointer to the vcpu_info struct in the shared_info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	 * page, we use it in the event channel upcall and in some pvclock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	 * related functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	xen_vcpu_info_reset(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	xen_panic_handler_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	if (!no_vector_callback && xen_feature(XENFEAT_hvm_callback_vector))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		xen_have_vector_callback = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	xen_hvm_smp_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	WARN_ON(xen_cpuhp_setup(xen_cpu_up_prepare_hvm, xen_cpu_dead_hvm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	xen_unplug_emulated_devices();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	x86_init.irqs.intr_init = xen_init_IRQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	xen_hvm_init_time_ops();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	xen_hvm_init_mmu_ops();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) #ifdef CONFIG_KEXEC_CORE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	machine_ops.shutdown = xen_hvm_shutdown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	machine_ops.crash_shutdown = xen_hvm_crash_shutdown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) static __init int xen_parse_nopv(char *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	pr_notice("\"xen_nopv\" is deprecated, please use \"nopv\" instead\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	if (xen_cpuid_base())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		nopv = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) early_param("xen_nopv", xen_parse_nopv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) static __init int xen_parse_no_vector_callback(char *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	no_vector_callback = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) early_param("xen_no_vector_callback", xen_parse_no_vector_callback);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) bool __init xen_hvm_need_lapic(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	if (xen_pv_domain())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	if (!xen_hvm_domain())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	if (xen_feature(XENFEAT_hvm_pirqs) && xen_have_vector_callback)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) static __init void xen_hvm_guest_late_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) #ifdef CONFIG_XEN_PVH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	/* Test for PVH domain (PVH boot path taken overrides ACPI flags). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	if (!xen_pvh &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	    (x86_platform.legacy.rtc || !x86_platform.legacy.no_vga))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	/* PVH detected. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	xen_pvh = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	if (nopv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		panic("\"nopv\" and \"xen_nopv\" parameters are unsupported in PVH guest.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	/* Make sure we don't fall back to (default) ACPI_IRQ_MODEL_PIC. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	if (!nr_ioapics && acpi_irq_model == ACPI_IRQ_MODEL_PIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		acpi_irq_model = ACPI_IRQ_MODEL_PLATFORM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	machine_ops.emergency_restart = xen_emergency_restart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	pv_info.name = "Xen PVH";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) static uint32_t __init xen_platform_hvm(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	uint32_t xen_domain = xen_cpuid_base();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	struct x86_hyper_init *h = &x86_hyper_xen_hvm.init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	if (xen_pv_domain())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	if (xen_pvh_domain() && nopv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		/* Guest booting via the Xen-PVH boot entry goes here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		pr_info("\"nopv\" parameter is ignored in PVH guest\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		nopv = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	} else if (nopv && xen_domain) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		 * Guest booting via normal boot entry (like via grub2) goes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		 * here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		 * Use interface functions for bare hardware if nopv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		 * xen_hvm_guest_late_init is an exception as we need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		 * detect PVH and panic there.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		h->init_platform = x86_init_noop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		h->x2apic_available = bool_x86_init_noop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		h->init_mem_mapping = x86_init_noop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		h->init_after_bootmem = x86_init_noop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		h->guest_late_init = xen_hvm_guest_late_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		x86_hyper_xen_hvm.runtime.pin_vcpu = x86_op_int_noop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	return xen_domain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) struct hypervisor_x86 x86_hyper_xen_hvm __initdata = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	.name                   = "Xen HVM",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	.detect                 = xen_platform_hvm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	.type			= X86_HYPER_XEN_HVM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	.init.init_platform     = xen_hvm_guest_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	.init.x2apic_available  = xen_x2apic_para_available,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	.init.init_mem_mapping	= xen_hvm_init_mem_mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	.init.guest_late_init	= xen_hvm_guest_late_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	.runtime.pin_vcpu       = xen_pin_vcpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	.ignore_nopv            = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) };