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