1b2441318SGreg Kroah-Hartman/* SPDX-License-Identifier: GPL-2.0 */
2b17ed480SThomas Gleixner/*
3b17ed480SThomas Gleixner * EFI call stub for IA32.
4b17ed480SThomas Gleixner *
5b17ed480SThomas Gleixner * This stub allows us to make EFI calls in physical mode with interrupts
6b17ed480SThomas Gleixner * turned off.
7b17ed480SThomas Gleixner */
8b17ed480SThomas Gleixner
9b17ed480SThomas Gleixner#include <linux/linkage.h>
10a46d6740SArd Biesheuvel#include <linux/init.h>
1159f2a619SArd Biesheuvel#include <asm/asm-offsets.h>
12b17ed480SThomas Gleixner#include <asm/page_types.h>
13b17ed480SThomas Gleixner
14a46d6740SArd Biesheuvel	__INIT
15a46d6740SArd BiesheuvelSYM_FUNC_START(efi_call_svam)
1659f2a619SArd Biesheuvel	push	%ebp
1759f2a619SArd Biesheuvel	movl	%esp, %ebp
1859f2a619SArd Biesheuvel	push	%ebx
1959f2a619SArd Biesheuvel
2059f2a619SArd Biesheuvel	push	16(%esp)
2159f2a619SArd Biesheuvel	push	16(%esp)
22a46d6740SArd Biesheuvel	push	%ecx
23a46d6740SArd Biesheuvel	push	%edx
2459f2a619SArd Biesheuvel	movl	%eax, %ebx		// &systab_phys->runtime
25b17ed480SThomas Gleixner
26b17ed480SThomas Gleixner	/*
27a46d6740SArd Biesheuvel	 * Switch to the flat mapped alias of this routine, by jumping to the
28a46d6740SArd Biesheuvel	 * address of label '1' after subtracting PAGE_OFFSET from it.
29b17ed480SThomas Gleixner	 */
30b17ed480SThomas Gleixner	movl	$1f, %edx
31b17ed480SThomas Gleixner	subl	$__PAGE_OFFSET, %edx
32b17ed480SThomas Gleixner	jmp	*%edx
33b17ed480SThomas Gleixner1:
34b17ed480SThomas Gleixner
35a46d6740SArd Biesheuvel	/* disable paging */
36b17ed480SThomas Gleixner	movl	%cr0, %edx
37b17ed480SThomas Gleixner	andl	$0x7fffffff, %edx
38b17ed480SThomas Gleixner	movl	%edx, %cr0
39b17ed480SThomas Gleixner
40a46d6740SArd Biesheuvel	/* convert the stack pointer to a flat mapped address */
41b17ed480SThomas Gleixner	subl	$__PAGE_OFFSET, %esp
42b17ed480SThomas Gleixner
43a46d6740SArd Biesheuvel	/* call the EFI routine */
4459f2a619SArd Biesheuvel	movl	(%eax), %eax
4559f2a619SArd Biesheuvel	call	*EFI_svam(%eax)
46b17ed480SThomas Gleixner
4759f2a619SArd Biesheuvel	/* grab the virtually remapped EFI runtime services table pointer */
4859f2a619SArd Biesheuvel	movl	(%ebx), %ecx
4959f2a619SArd Biesheuvel	movl	36(%esp), %edx		// &efi.runtime
5059f2a619SArd Biesheuvel	movl	%ecx, (%edx)
51b17ed480SThomas Gleixner
52a46d6740SArd Biesheuvel	/* re-enable paging */
53b17ed480SThomas Gleixner	movl	%cr0, %edx
54b17ed480SThomas Gleixner	orl	$0x80000000, %edx
55b17ed480SThomas Gleixner	movl	%edx, %cr0
56b17ed480SThomas Gleixner
5757648adbSArd Biesheuvel	movl	16(%esp), %ebx
5859f2a619SArd Biesheuvel	leave
59*14b476e0SPeter Zijlstra	RET
60a46d6740SArd BiesheuvelSYM_FUNC_END(efi_call_svam)
61