blob: 46e40aeae44637ddcb3c487546cbaee97adce880 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Machine specific APM BIOS functions for generic.
3 * Split out from apm.c by Osamu Tomita <tomita@cinet.co.jp>
4 */
5
H. Peter Anvin05e4d312008-10-23 00:01:39 -07006#ifndef _ASM_X86_MACH_DEFAULT_APM_H
7#define _ASM_X86_MACH_DEFAULT_APM_H
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
David Woodhousea27ede12018-02-19 10:50:54 +00009#include <asm/nospec-branch.h>
10
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#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
28static 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 */
David Woodhousea27ede12018-02-19 10:50:54 +000036 firmware_restrict_branch_speculation_start();
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 __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");
David Woodhousea27ede12018-02-19 10:50:54 +000049 firmware_restrict_branch_speculation_end();
Linus Torvalds1da177e2005-04-16 15:20:36 -070050}
51
H. Peter Anvin117780e2016-06-08 12:38:38 -070052static inline bool apm_bios_call_simple_asm(u32 func, u32 ebx_in,
53 u32 ecx_in, u32 *eax)
Linus Torvalds1da177e2005-04-16 15:20:36 -070054{
55 int cx, dx, si;
H. Peter Anvin117780e2016-06-08 12:38:38 -070056 bool error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58 /*
59 * N.B. We do NOT need a cld after the BIOS call
60 * because we always save and restore the flags.
61 */
David Woodhousea27ede12018-02-19 10:50:54 +000062 firmware_restrict_branch_speculation_start();
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 __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");
David Woodhousea27ede12018-02-19 10:50:54 +000075 firmware_restrict_branch_speculation_end();
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 return error;
77}
78
H. Peter Anvin05e4d312008-10-23 00:01:39 -070079#endif /* _ASM_X86_MACH_DEFAULT_APM_H */