Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Machine specific APM BIOS functions for generic. |
| 4 | * Split out from apm.c by Osamu Tomita <tomita@cinet.co.jp> |
| 5 | */ |
| 6 | |
H. Peter Anvin | 05e4d31 | 2008-10-23 00:01:39 -0700 | [diff] [blame] | 7 | #ifndef _ASM_X86_MACH_DEFAULT_APM_H |
| 8 | #define _ASM_X86_MACH_DEFAULT_APM_H |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
David Woodhouse | dd84441 | 2018-02-19 10:50:54 +0000 | [diff] [blame] | 10 | #include <asm/nospec-branch.h> |
| 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | */ |
David Woodhouse | dd84441 | 2018-02-19 10:50:54 +0000 | [diff] [blame] | 37 | firmware_restrict_branch_speculation_start(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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"); |
David Woodhouse | dd84441 | 2018-02-19 10:50:54 +0000 | [diff] [blame] | 50 | firmware_restrict_branch_speculation_end(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | } |
| 52 | |
H. Peter Anvin | 117780e | 2016-06-08 12:38:38 -0700 | [diff] [blame] | 53 | static inline bool apm_bios_call_simple_asm(u32 func, u32 ebx_in, |
| 54 | u32 ecx_in, u32 *eax) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | { |
| 56 | int cx, dx, si; |
H. Peter Anvin | 117780e | 2016-06-08 12:38:38 -0700 | [diff] [blame] | 57 | bool error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | */ |
David Woodhouse | dd84441 | 2018-02-19 10:50:54 +0000 | [diff] [blame] | 63 | firmware_restrict_branch_speculation_start(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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"); |
David Woodhouse | dd84441 | 2018-02-19 10:50:54 +0000 | [diff] [blame] | 76 | firmware_restrict_branch_speculation_end(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | return error; |
| 78 | } |
| 79 | |
H. Peter Anvin | 05e4d31 | 2008-10-23 00:01:39 -0700 | [diff] [blame] | 80 | #endif /* _ASM_X86_MACH_DEFAULT_APM_H */ |