xref: /openbmc/linux/arch/x86/include/asm/apm.h (revision 82e6fdd6)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  *  Machine specific APM BIOS functions for generic.
4  *  Split out from apm.c by Osamu Tomita <tomita@cinet.co.jp>
5  */
6 
7 #ifndef _ASM_X86_MACH_DEFAULT_APM_H
8 #define _ASM_X86_MACH_DEFAULT_APM_H
9 
10 #include <asm/nospec-branch.h>
11 
12 #ifdef APM_ZERO_SEGS
13 #	define APM_DO_ZERO_SEGS \
14 		"pushl %%ds\n\t" \
15 		"pushl %%es\n\t" \
16 		"xorl %%edx, %%edx\n\t" \
17 		"mov %%dx, %%ds\n\t" \
18 		"mov %%dx, %%es\n\t" \
19 		"mov %%dx, %%fs\n\t" \
20 		"mov %%dx, %%gs\n\t"
21 #	define APM_DO_POP_SEGS \
22 		"popl %%es\n\t" \
23 		"popl %%ds\n\t"
24 #else
25 #	define APM_DO_ZERO_SEGS
26 #	define APM_DO_POP_SEGS
27 #endif
28 
29 static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
30 					u32 *eax, u32 *ebx, u32 *ecx,
31 					u32 *edx, u32 *esi)
32 {
33 	/*
34 	 * N.B. We do NOT need a cld after the BIOS call
35 	 * because we always save and restore the flags.
36 	 */
37 	firmware_restrict_branch_speculation_start();
38 	__asm__ __volatile__(APM_DO_ZERO_SEGS
39 		"pushl %%edi\n\t"
40 		"pushl %%ebp\n\t"
41 		"lcall *%%cs:apm_bios_entry\n\t"
42 		"setc %%al\n\t"
43 		"popl %%ebp\n\t"
44 		"popl %%edi\n\t"
45 		APM_DO_POP_SEGS
46 		: "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx),
47 		  "=S" (*esi)
48 		: "a" (func), "b" (ebx_in), "c" (ecx_in)
49 		: "memory", "cc");
50 	firmware_restrict_branch_speculation_end();
51 }
52 
53 static inline bool apm_bios_call_simple_asm(u32 func, u32 ebx_in,
54 					    u32 ecx_in, u32 *eax)
55 {
56 	int	cx, dx, si;
57 	bool	error;
58 
59 	/*
60 	 * N.B. We do NOT need a cld after the BIOS call
61 	 * because we always save and restore the flags.
62 	 */
63 	firmware_restrict_branch_speculation_start();
64 	__asm__ __volatile__(APM_DO_ZERO_SEGS
65 		"pushl %%edi\n\t"
66 		"pushl %%ebp\n\t"
67 		"lcall *%%cs:apm_bios_entry\n\t"
68 		"setc %%bl\n\t"
69 		"popl %%ebp\n\t"
70 		"popl %%edi\n\t"
71 		APM_DO_POP_SEGS
72 		: "=a" (*eax), "=b" (error), "=c" (cx), "=d" (dx),
73 		  "=S" (si)
74 		: "a" (func), "b" (ebx_in), "c" (ecx_in)
75 		: "memory", "cc");
76 	firmware_restrict_branch_speculation_end();
77 	return error;
78 }
79 
80 #endif /* _ASM_X86_MACH_DEFAULT_APM_H */
81