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)  * Jailhouse paravirt_ops implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (c) Siemens AG, 2015-2017
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Authors:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *  Jan Kiszka <jan.kiszka@siemens.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/acpi_pmtmr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/serial_8250.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <asm/apic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <asm/io_apic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <asm/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <asm/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <asm/hypervisor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <asm/i8259.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <asm/irqdomain.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <asm/pci_x86.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <asm/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <asm/jailhouse_para.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) static struct jailhouse_setup_data setup_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define SETUP_DATA_V1_LEN	(sizeof(setup_data.hdr) + sizeof(setup_data.v1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define SETUP_DATA_V2_LEN	(SETUP_DATA_V1_LEN + sizeof(setup_data.v2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static unsigned int precalibrated_tsc_khz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static void jailhouse_setup_irq(unsigned int irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	struct mpc_intsrc mp_irq = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		.type		= MP_INTSRC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		.irqtype	= mp_INT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		.irqflag	= MP_IRQPOL_ACTIVE_HIGH | MP_IRQTRIG_EDGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		.srcbusirq	= irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		.dstirq		= irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	mp_save_irq(&mp_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) static uint32_t jailhouse_cpuid_base(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	if (boot_cpu_data.cpuid_level < 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	    !boot_cpu_has(X86_FEATURE_HYPERVISOR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	return hypervisor_cpuid_base("Jailhouse\0\0\0", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) static uint32_t __init jailhouse_detect(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	return jailhouse_cpuid_base();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) static void jailhouse_get_wallclock(struct timespec64 *now)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	memset(now, 0, sizeof(*now));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) static void __init jailhouse_timer_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	lapic_timer_period = setup_data.v1.apic_khz * (1000 / HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) static unsigned long jailhouse_get_tsc(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	return precalibrated_tsc_khz;
^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) static void __init jailhouse_x2apic_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) #ifdef CONFIG_X86_X2APIC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	if (!x2apic_enabled())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	 * We do not have access to IR inside Jailhouse non-root cells.  So
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	 * we have to run in physical mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	x2apic_phys = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	 * This will trigger the switch to apic_x2apic_phys.  Empty OEM IDs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	 * ensure that only this APIC driver picks up the call.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	default_acpi_madt_oem_check("", "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) static void __init jailhouse_get_smp_config(unsigned int early)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	struct ioapic_domain_cfg ioapic_cfg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		.type = IOAPIC_DOMAIN_STRICT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		.ops = &mp_ioapic_irqdomain_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	unsigned int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	jailhouse_x2apic_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	register_lapic_address(0xfee00000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	for (cpu = 0; cpu < setup_data.v1.num_cpus; cpu++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		generic_processor_info(setup_data.v1.cpu_ids[cpu],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 				       boot_cpu_apic_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	smp_found_config = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	if (setup_data.v1.standard_ioapic) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		mp_register_ioapic(0, 0xfec00000, gsi_top, &ioapic_cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		if (IS_ENABLED(CONFIG_SERIAL_8250) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		    setup_data.hdr.version < 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			/* Register 1:1 mapping for legacy UART IRQs 3 and 4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 			jailhouse_setup_irq(3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 			jailhouse_setup_irq(4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	}
^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) static void jailhouse_no_restart(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	pr_notice("Jailhouse: Restart not supported, halting\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	machine_halt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static int __init jailhouse_pci_arch_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	pci_direct_init(1);
^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) 	 * There are no bridges on the virtual PCI root bus under Jailhouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	 * thus no other way to discover all devices than a full scan.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	 * Respect any overrides via the command line, though.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	if (pcibios_last_bus < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		pcibios_last_bus = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) #ifdef CONFIG_PCI_MMCONFIG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	if (setup_data.v1.pci_mmconfig_base) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		pci_mmconfig_add(0, 0, pcibios_last_bus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 				 setup_data.v1.pci_mmconfig_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		pci_mmcfg_arch_init();
^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) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) #ifdef CONFIG_SERIAL_8250
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static inline bool jailhouse_uart_enabled(unsigned int uart_nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	return setup_data.v2.flags & BIT(uart_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static void jailhouse_serial_fixup(int port, struct uart_port *up,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 				   u32 *capabilities)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	static const u16 pcuart_base[] = {0x3f8, 0x2f8, 0x3e8, 0x2e8};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	unsigned int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	for (n = 0; n < ARRAY_SIZE(pcuart_base); n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		if (pcuart_base[n] != up->iobase)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		if (jailhouse_uart_enabled(n)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 			pr_info("Enabling UART%u (port 0x%lx)\n", n,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 				up->iobase);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			jailhouse_setup_irq(up->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 			/* Deactivate UART if access isn't allowed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 			up->iobase = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) static void __init jailhouse_serial_workaround(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	 * There are flags inside setup_data that indicate availability of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	 * platform UARTs since setup data version 2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	 * In case of version 1, we don't know which UARTs belong Linux. In
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	 * this case, unconditionally register 1:1 mapping for legacy UART IRQs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	 * 3 and 4.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	if (setup_data.hdr.version > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		serial8250_set_isa_configurator(jailhouse_serial_fixup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) #else /* !CONFIG_SERIAL_8250 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) static inline void jailhouse_serial_workaround(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) #endif /* CONFIG_SERIAL_8250 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) static void __init jailhouse_init_platform(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	u64 pa_data = boot_params.hdr.setup_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	unsigned long setup_data_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	struct setup_data header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	void *mapping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	x86_init.irqs.pre_vector_init	= x86_init_noop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	x86_init.timers.timer_init	= jailhouse_timer_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	x86_init.mpparse.get_smp_config	= jailhouse_get_smp_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	x86_init.pci.arch_init		= jailhouse_pci_arch_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	x86_platform.calibrate_cpu	= jailhouse_get_tsc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	x86_platform.calibrate_tsc	= jailhouse_get_tsc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	x86_platform.get_wallclock	= jailhouse_get_wallclock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	x86_platform.legacy.rtc		= 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	x86_platform.legacy.warm_reset	= 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	x86_platform.legacy.i8042	= X86_LEGACY_I8042_PLATFORM_ABSENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	legacy_pic			= &null_legacy_pic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	machine_ops.emergency_restart	= jailhouse_no_restart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	while (pa_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		mapping = early_memremap(pa_data, sizeof(header));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		memcpy(&header, mapping, sizeof(header));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		early_memunmap(mapping, sizeof(header));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		if (header.type == SETUP_JAILHOUSE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		pa_data = header.next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	if (!pa_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		panic("Jailhouse: No valid setup data found");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	/* setup data must at least contain the header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	if (header.len < sizeof(setup_data.hdr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		goto unsupported;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	pa_data += offsetof(struct setup_data, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	setup_data_len = min_t(unsigned long, sizeof(setup_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 			       (unsigned long)header.len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	mapping = early_memremap(pa_data, setup_data_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	memcpy(&setup_data, mapping, setup_data_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	early_memunmap(mapping, setup_data_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	if (setup_data.hdr.version == 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	    setup_data.hdr.compatible_version !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		JAILHOUSE_SETUP_REQUIRED_VERSION ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	    (setup_data.hdr.version == 1 && header.len < SETUP_DATA_V1_LEN) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	    (setup_data.hdr.version >= 2 && header.len < SETUP_DATA_V2_LEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		goto unsupported;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	pmtmr_ioport = setup_data.v1.pm_timer_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	pr_debug("Jailhouse: PM-Timer IO Port: %#x\n", pmtmr_ioport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	precalibrated_tsc_khz = setup_data.v1.tsc_khz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	pci_probe = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	 * Avoid that the kernel complains about missing ACPI tables - there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	 * are none in a non-root cell.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	disable_acpi();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	jailhouse_serial_workaround();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) unsupported:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	panic("Jailhouse: Unsupported setup data structure");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) bool jailhouse_paravirt(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	return jailhouse_cpuid_base() != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) static bool __init jailhouse_x2apic_available(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	 * The x2APIC is only available if the root cell enabled it. Jailhouse
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	 * does not support switching between xAPIC and x2APIC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	return x2apic_enabled();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) const struct hypervisor_x86 x86_hyper_jailhouse __refconst = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	.name			= "Jailhouse",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	.detect			= jailhouse_detect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	.init.init_platform	= jailhouse_init_platform,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	.init.x2apic_available	= jailhouse_x2apic_available,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	.ignore_nopv		= true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) };