Linux 2.6.26.3
[linux/fpc-iii.git] / arch / x86 / boot / apm.c
blob7aa6033001f9ace30ef1a4ffdb52bfd629a98f26
1 /* -*- linux-c -*- ------------------------------------------------------- *
3 * Copyright (C) 1991, 1992 Linus Torvalds
4 * Copyright 2007 rPath, Inc. - All Rights Reserved
6 * Original APM BIOS checking by Stephen Rothwell, May 1994
7 * (sfr@canb.auug.org.au)
9 * This file is part of the Linux kernel, and is made available under
10 * the terms of the GNU General Public License version 2.
12 * ----------------------------------------------------------------------- */
15 * Get APM BIOS information
18 #include "boot.h"
20 int query_apm_bios(void)
22 u16 ax, bx, cx, dx, di;
23 u32 ebx, esi;
24 u8 err;
26 /* APM BIOS installation check */
27 ax = 0x5300;
28 bx = cx = 0;
29 asm volatile("pushl %%ebp ; int $0x15 ; popl %%ebp ; setc %0"
30 : "=d" (err), "+a" (ax), "+b" (bx), "+c" (cx)
31 : : "esi", "edi");
33 if (err)
34 return -1; /* No APM BIOS */
36 if (bx != 0x504d) /* "PM" signature */
37 return -1;
39 if (!(cx & 0x02)) /* 32 bits supported? */
40 return -1;
42 /* Disconnect first, just in case */
43 ax = 0x5304;
44 bx = 0;
45 asm volatile("pushl %%ebp ; int $0x15 ; popl %%ebp"
46 : "+a" (ax), "+b" (bx)
47 : : "ecx", "edx", "esi", "edi");
49 /* Paranoia */
50 ebx = esi = 0;
51 cx = dx = di = 0;
53 /* 32-bit connect */
54 asm volatile("pushl %%ebp ; int $0x15 ; popl %%ebp ; setc %6"
55 : "=a" (ax), "+b" (ebx), "+c" (cx), "+d" (dx),
56 "+S" (esi), "+D" (di), "=m" (err)
57 : "a" (0x5303));
59 boot_params.apm_bios_info.cseg = ax;
60 boot_params.apm_bios_info.offset = ebx;
61 boot_params.apm_bios_info.cseg_16 = cx;
62 boot_params.apm_bios_info.dseg = dx;
63 boot_params.apm_bios_info.cseg_len = (u16)esi;
64 boot_params.apm_bios_info.cseg_16_len = esi >> 16;
65 boot_params.apm_bios_info.dseg_len = di;
67 if (err)
68 return -1;
70 /* Redo the installation check as the 32-bit connect;
71 some BIOSes return different flags this way... */
73 ax = 0x5300;
74 bx = cx = 0;
75 asm volatile("pushl %%ebp ; int $0x15 ; popl %%ebp ; setc %0"
76 : "=d" (err), "+a" (ax), "+b" (bx), "+c" (cx)
77 : : "esi", "edi");
79 if (err || bx != 0x504d) {
80 /* Failure with 32-bit connect, try to disconect and ignore */
81 ax = 0x5304;
82 bx = 0;
83 asm volatile("pushl %%ebp ; int $0x15 ; popl %%ebp"
84 : "+a" (ax), "+b" (bx)
85 : : "ecx", "edx", "esi", "edi");
86 return -1;
89 boot_params.apm_bios_info.version = ax;
90 boot_params.apm_bios_info.flags = cx;
91 return 0;