Skip to content

Commit

Permalink
x86/trampoline: Move the trampoline declarations out of <asm/config.h>
Browse files Browse the repository at this point in the history
asm/config.h is included in every translation unit (via xen/config.h), while
only a handful of functions actually interact with the trampoline.

Move the infrastructure into its own header, and take the opportunity to
document everything.

Change trampoline_realmode_entry() and wakeup_start() to be nocall functions,
rather than char arrays.  Also switch to fixed width integers which are less
likely to diverge from the asm declaration.

No functional change.

Signed-off-by: Andrew Cooper <[email protected]>
Reviewed-by: Jan Beulich <[email protected]>
  • Loading branch information
andyhhp committed Sep 6, 2024
1 parent b34d5e3 commit 65e4bc5
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 19 deletions.
2 changes: 2 additions & 0 deletions xen/arch/x86/acpi/power.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <asm/microcode.h>
#include <asm/prot-key.h>
#include <asm/spec_ctrl.h>
#include <asm/trampoline.h>

#include <acpi/cpufreq/cpufreq.h>

uint32_t system_reset_counter = 1;
Expand Down
2 changes: 2 additions & 0 deletions xen/arch/x86/cpu/intel.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <asm/mpspec.h>
#include <asm/apic.h>
#include <asm/i387.h>
#include <asm/trampoline.h>

#include <mach_apic.h>

#include "cpu.h"
Expand Down
1 change: 1 addition & 0 deletions xen/arch/x86/efi/efi-boot.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <asm/microcode.h>
#include <asm/msr.h>
#include <asm/setup.h>
#include <asm/trampoline.h>

static struct file __initdata ucode;
static multiboot_info_t __initdata mbi = {
Expand Down
1 change: 1 addition & 0 deletions xen/arch/x86/guest/xen/pvh-boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <asm/e820.h>
#include <asm/guest.h>
#include <asm/trampoline.h>

#include <public/arch-x86/hvm/start_info.h>

Expand Down
19 changes: 0 additions & 19 deletions xen/arch/x86/include/asm/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,6 @@
#define LIST_POISON1 ((void *)0x0100100100100100UL)
#define LIST_POISON2 ((void *)0x0200200200200200UL)

#ifndef __ASSEMBLY__
extern unsigned long trampoline_phys;
#define bootsym_phys(sym) \
(((unsigned long)&(sym)-(unsigned long)&trampoline_start)+trampoline_phys)
#define bootsym(sym) \
(*((typeof(sym) *)__va(bootsym_phys(sym))))

extern char trampoline_start[], trampoline_end[];
extern char trampoline_realmode_entry[];
extern unsigned int trampoline_xen_phys_start;
extern unsigned char trampoline_cpu_started;
extern char wakeup_start[];

extern unsigned char video_flags;

extern unsigned short boot_edid_caps;
extern unsigned char boot_edid_info[128];
#endif

#include <xen/const.h>

#define PML4_ENTRY_BITS 39
Expand Down
95 changes: 95 additions & 0 deletions xen/arch/x86/include/asm/trampoline.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
#ifndef X86_ASM_TRAMPOLINE_H
#define X86_ASM_TRAMPOLINE_H

/*
* Data in or about the low memory trampoline.
*
* x86 systems software typically needs a block of logic below the 1M
* boundary, commonly called the trampoline, containing 16-bit logic. Xen has
* a combined trampoline of all necessary 16-bit logic, formed of two parts.
*
* 1) The permanent trampoline; a single 4k page containing:
*
* - The INIT-SIPI-SIPI entrypoint for APs, and
* - The S3 wakeup vector.
*
* Both of these are 16-bit entrypoints, responsible for activating paging
* and getting into 64-bit mode. This requires the permanent trampoline to
* be identity mapped in idle_pg_table[].
*
* The SIPI64 spec deprecates the 16-bit AP entrypoint, while S0ix (also
* called Low Power Idle or Connected Standby) deprecates S3.
*
* 2) The boot trampoline:
*
* This is used by the BSP to drop into 16-bit mode, make various BIOS
* calls to obtain E820/EDID/etc. It follows the permanent and exceeds 4k,
* but is only used in 16-bit and 32-bit unpaged mode so does not need
* mapping in pagetables.
*
* When the BIOS calls are complete, execution does join back with the AP
* path, and becomes subject to the same paging requirements. This path is
* not needed for non-BIOS boots.
*
* The location of trampoline is not fixed. The layout of low memory varies
* greatly from platform to platform. Therefore, the trampoline is relocated
* manually as part of placement.
*/

#include <xen/compiler.h>
#include <xen/types.h>

/*
* Start and end of the trampoline section, as linked into Xen. It is within
* the .init section and reclaimed after boot.
*/
/* SAF-0-safe */
extern char trampoline_start[], trampoline_end[];

/*
* The physical address of trampoline_start[] in low memory. It must be below
* the 1M boundary (as the trampoline contains 16-bit code), and must be 4k
* aligned (SIPI requirement for APs).
*/
extern unsigned long trampoline_phys;

/*
* Calculate the physical address of a symbol in the trampoline.
*
* Should only be used on symbols declared later in this header. Specifying
* other symbols will compile but malfunction when used, as will using this
* helper before the trampoline is placed.
*/
#define bootsym_phys(sym) \
(trampoline_phys + ((unsigned long)&(sym) - \
(unsigned long)trampoline_start))

/* Given a trampoline symbol, construct a pointer to it in the directmap. */
#define bootsym(sym) (*((typeof(sym) *)__va(bootsym_phys(sym))))

/* The INIT-SIPI-SIPI entrypoint. 16-bit code. */
void nocall trampoline_realmode_entry(void);

/* The S3 wakeup vector. 16-bit code. */
void nocall wakeup_start(void);

/*
* A variable in the trampoline, containing Xen's physical address. Amongst
* other things, it is used to find idle_pg_table[] in order to enable paging
* and activate 64-bit mode. This variable needs keeping in sync with
* xen_phys_start.
*/
extern uint32_t trampoline_xen_phys_start;

/* A semaphore to indicate signs-of-life at the start of the AP boot path. */
extern uint8_t trampoline_cpu_started;

/* Quirks about video mode-setting on S3 resume. */
extern uint8_t video_flags;

/* Extended Display Identification Data, gathered from the BIOS. */
extern uint16_t boot_edid_caps;
extern uint8_t boot_edid_info[128];

#endif /* X86_ASM_TRAMPOLINE_H */
1 change: 1 addition & 0 deletions xen/arch/x86/mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
#include <asm/guest.h>
#include <asm/pv/domain.h>
#include <asm/pv/mm.h>
#include <asm/trampoline.h>

#ifdef CONFIG_PV
#include "pv/mm.h"
Expand Down
2 changes: 2 additions & 0 deletions xen/arch/x86/platform_hypercall.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include <asm/mtrr.h>
#include <asm/io_apic.h>
#include <asm/setup.h>
#include <asm/trampoline.h>

#include "cpu/mcheck/mce.h"
#include "cpu/mtrr/mtrr.h"
#include <xsm/xsm.h>
Expand Down
1 change: 1 addition & 0 deletions xen/arch/x86/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
#include <asm/microcode.h>
#include <asm/prot-key.h>
#include <asm/pv/domain.h>
#include <asm/trampoline.h>

/* opt_nosmp: If true, secondary processors are ignored. */
static bool __initdata opt_nosmp;
Expand Down
1 change: 1 addition & 0 deletions xen/arch/x86/smpboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <asm/spec_ctrl.h>
#include <asm/time.h>
#include <asm/tboot.h>
#include <asm/trampoline.h>
#include <irq_vectors.h>
#include <mach_apic.h>

Expand Down
2 changes: 2 additions & 0 deletions xen/arch/x86/tboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <asm/e820.h>
#include <asm/tboot.h>
#include <asm/setup.h>
#include <asm/trampoline.h>

#include <crypto/vmac.h>

/* tboot=<physical address of shared page> */
Expand Down
2 changes: 2 additions & 0 deletions xen/arch/x86/x86_64/mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ EMIT_FILE;
#include <asm/numa.h>
#include <asm/mem_paging.h>
#include <asm/mem_sharing.h>
#include <asm/trampoline.h>

#include <public/memory.h>

#ifdef CONFIG_PV32
Expand Down

0 comments on commit 65e4bc5

Please sign in to comment.