apm.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* -*- linux-c -*- ------------------------------------------------------- *
  2. *
  3. * Copyright (C) 1991, 1992 Linus Torvalds
  4. * Copyright 2007 rPath, Inc. - All Rights Reserved
  5. *
  6. * Original APM BIOS checking by Stephen Rothwell, May 1994
  7. * (sfr@canb.auug.org.au)
  8. *
  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.
  11. *
  12. * ----------------------------------------------------------------------- */
  13. /*
  14. * arch/i386/boot/apm.c
  15. *
  16. * Get APM BIOS information
  17. */
  18. #include "boot.h"
  19. #if defined(CONFIG_APM) || defined(CONFIG_APM_MODULE)
  20. int query_apm_bios(void)
  21. {
  22. u16 ax, bx, cx, dx, di;
  23. u32 ebx, esi;
  24. u8 err;
  25. /* APM BIOS installation check */
  26. ax = 0x5300;
  27. bx = cx = 0;
  28. asm volatile("pushl %%ebp ; int $0x15 ; popl %%ebp ; setc %0"
  29. : "=d" (err), "+a" (ax), "+b" (bx), "+c" (cx)
  30. : : "esi", "edi");
  31. if (err)
  32. return -1; /* No APM BIOS */
  33. if (bx != 0x504d) /* "PM" signature */
  34. return -1;
  35. if (!(cx & 0x02)) /* 32 bits supported? */
  36. return -1;
  37. /* Disconnect first, just in case */
  38. ax = 0x5304;
  39. bx = 0;
  40. asm volatile("pushl %%ebp ; int $0x15 ; popl %%ebp"
  41. : "+a" (ax), "+b" (bx)
  42. : : "ecx", "edx", "esi", "edi");
  43. /* Paranoia */
  44. ebx = esi = 0;
  45. cx = dx = di = 0;
  46. /* 32-bit connect */
  47. asm volatile("pushl %%ebp ; int $0x15 ; popl %%ebp ; setc %6"
  48. : "=a" (ax), "+b" (ebx), "+c" (cx), "+d" (dx),
  49. "+S" (esi), "+D" (di), "=m" (err)
  50. : "a" (0x5303));
  51. boot_params.apm_bios_info.cseg = ax;
  52. boot_params.apm_bios_info.offset = ebx;
  53. boot_params.apm_bios_info.cseg_16 = cx;
  54. boot_params.apm_bios_info.dseg = dx;
  55. boot_params.apm_bios_info.cseg_len = (u16)esi;
  56. boot_params.apm_bios_info.cseg_16_len = esi >> 16;
  57. boot_params.apm_bios_info.dseg_len = di;
  58. if (err)
  59. return -1;
  60. /* Redo the installation check as the 32-bit connect;
  61. some BIOSes return different flags this way... */
  62. ax = 0x5300;
  63. bx = cx = 0;
  64. asm volatile("pushl %%ebp ; int $0x15 ; popl %%ebp ; setc %0"
  65. : "=d" (err), "+a" (ax), "+b" (bx), "+c" (cx)
  66. : : "esi", "edi");
  67. if (err || bx != 0x504d) {
  68. /* Failure with 32-bit connect, try to disconect and ignore */
  69. ax = 0x5304;
  70. bx = 0;
  71. asm volatile("pushl %%ebp ; int $0x15 ; popl %%ebp"
  72. : "+a" (ax), "+b" (bx)
  73. : : "ecx", "edx", "esi", "edi");
  74. return -1;
  75. }
  76. boot_params.apm_bios_info.version = ax;
  77. boot_params.apm_bios_info.flags = cx;
  78. return 0;
  79. }
  80. #endif