blob: c356098b6fb92b8ff7d42b2fd813c2a8551d3db1 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Machine specific APM BIOS functions for generic.
4 * Split out from apm.c by Osamu Tomita <tomita@cinet.co.jp>
5 */
6
H. Peter Anvin05e4d312008-10-23 00:01:39 -07007#ifndef _ASM_X86_MACH_DEFAULT_APM_H
8#define _ASM_X86_MACH_DEFAULT_APM_H
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
David Woodhousedd844412018-02-19 10:50:54 +000010#include <asm/nospec-branch.h>
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#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
29static 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 */
David Woodhousedd844412018-02-19 10:50:54 +000037 firmware_restrict_branch_speculation_start();
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 __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");
David Woodhousedd844412018-02-19 10:50:54 +000050 firmware_restrict_branch_speculation_end();
Linus Torvalds1da177e2005-04-16 15:20:36 -070051}
52
H. Peter Anvin117780e2016-06-08 12:38:38 -070053static inline bool apm_bios_call_simple_asm(u32 func, u32 ebx_in,
54 u32 ecx_in, u32 *eax)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055{
56 int cx, dx, si;
H. Peter Anvin117780e2016-06-08 12:38:38 -070057 bool error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59 /*
60 * N.B. We do NOT need a cld after the BIOS call
61 * because we always save and restore the flags.
62 */
David Woodhousedd844412018-02-19 10:50:54 +000063 firmware_restrict_branch_speculation_start();
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 __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");
David Woodhousedd844412018-02-19 10:50:54 +000076 firmware_restrict_branch_speculation_end();
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 return error;
78}
79
H. Peter Anvin05e4d312008-10-23 00:01:39 -070080#endif /* _ASM_X86_MACH_DEFAULT_APM_H */