xref: /kernel/linux/linux-5.10/arch/x86/include/asm/apm.h (revision 8c2ecf20)
18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  Machine specific APM BIOS functions for generic.
48c2ecf20Sopenharmony_ci *  Split out from apm.c by Osamu Tomita <tomita@cinet.co.jp>
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#ifndef _ASM_X86_MACH_DEFAULT_APM_H
88c2ecf20Sopenharmony_ci#define _ASM_X86_MACH_DEFAULT_APM_H
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#ifdef APM_ZERO_SEGS
118c2ecf20Sopenharmony_ci#	define APM_DO_ZERO_SEGS \
128c2ecf20Sopenharmony_ci		"pushl %%ds\n\t" \
138c2ecf20Sopenharmony_ci		"pushl %%es\n\t" \
148c2ecf20Sopenharmony_ci		"xorl %%edx, %%edx\n\t" \
158c2ecf20Sopenharmony_ci		"mov %%dx, %%ds\n\t" \
168c2ecf20Sopenharmony_ci		"mov %%dx, %%es\n\t" \
178c2ecf20Sopenharmony_ci		"mov %%dx, %%fs\n\t" \
188c2ecf20Sopenharmony_ci		"mov %%dx, %%gs\n\t"
198c2ecf20Sopenharmony_ci#	define APM_DO_POP_SEGS \
208c2ecf20Sopenharmony_ci		"popl %%es\n\t" \
218c2ecf20Sopenharmony_ci		"popl %%ds\n\t"
228c2ecf20Sopenharmony_ci#else
238c2ecf20Sopenharmony_ci#	define APM_DO_ZERO_SEGS
248c2ecf20Sopenharmony_ci#	define APM_DO_POP_SEGS
258c2ecf20Sopenharmony_ci#endif
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_cistatic inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
288c2ecf20Sopenharmony_ci					u32 *eax, u32 *ebx, u32 *ecx,
298c2ecf20Sopenharmony_ci					u32 *edx, u32 *esi)
308c2ecf20Sopenharmony_ci{
318c2ecf20Sopenharmony_ci	/*
328c2ecf20Sopenharmony_ci	 * N.B. We do NOT need a cld after the BIOS call
338c2ecf20Sopenharmony_ci	 * because we always save and restore the flags.
348c2ecf20Sopenharmony_ci	 */
358c2ecf20Sopenharmony_ci	__asm__ __volatile__(APM_DO_ZERO_SEGS
368c2ecf20Sopenharmony_ci		"pushl %%edi\n\t"
378c2ecf20Sopenharmony_ci		"pushl %%ebp\n\t"
388c2ecf20Sopenharmony_ci		"lcall *%%cs:apm_bios_entry\n\t"
398c2ecf20Sopenharmony_ci		"setc %%al\n\t"
408c2ecf20Sopenharmony_ci		"popl %%ebp\n\t"
418c2ecf20Sopenharmony_ci		"popl %%edi\n\t"
428c2ecf20Sopenharmony_ci		APM_DO_POP_SEGS
438c2ecf20Sopenharmony_ci		: "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx),
448c2ecf20Sopenharmony_ci		  "=S" (*esi)
458c2ecf20Sopenharmony_ci		: "a" (func), "b" (ebx_in), "c" (ecx_in)
468c2ecf20Sopenharmony_ci		: "memory", "cc");
478c2ecf20Sopenharmony_ci}
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_cistatic inline bool apm_bios_call_simple_asm(u32 func, u32 ebx_in,
508c2ecf20Sopenharmony_ci					    u32 ecx_in, u32 *eax)
518c2ecf20Sopenharmony_ci{
528c2ecf20Sopenharmony_ci	int	cx, dx, si;
538c2ecf20Sopenharmony_ci	bool	error;
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci	/*
568c2ecf20Sopenharmony_ci	 * N.B. We do NOT need a cld after the BIOS call
578c2ecf20Sopenharmony_ci	 * because we always save and restore the flags.
588c2ecf20Sopenharmony_ci	 */
598c2ecf20Sopenharmony_ci	__asm__ __volatile__(APM_DO_ZERO_SEGS
608c2ecf20Sopenharmony_ci		"pushl %%edi\n\t"
618c2ecf20Sopenharmony_ci		"pushl %%ebp\n\t"
628c2ecf20Sopenharmony_ci		"lcall *%%cs:apm_bios_entry\n\t"
638c2ecf20Sopenharmony_ci		"setc %%bl\n\t"
648c2ecf20Sopenharmony_ci		"popl %%ebp\n\t"
658c2ecf20Sopenharmony_ci		"popl %%edi\n\t"
668c2ecf20Sopenharmony_ci		APM_DO_POP_SEGS
678c2ecf20Sopenharmony_ci		: "=a" (*eax), "=b" (error), "=c" (cx), "=d" (dx),
688c2ecf20Sopenharmony_ci		  "=S" (si)
698c2ecf20Sopenharmony_ci		: "a" (func), "b" (ebx_in), "c" (ecx_in)
708c2ecf20Sopenharmony_ci		: "memory", "cc");
718c2ecf20Sopenharmony_ci	return error;
728c2ecf20Sopenharmony_ci}
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci#endif /* _ASM_X86_MACH_DEFAULT_APM_H */
75