apm.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* -*- linux-c -*- ------------------------------------------------------- *
  2. *
  3. * Copyright (C) 1991, 1992 Linus Torvalds
  4. * Copyright 2007 rPath, Inc. - All Rights Reserved
  5. * Copyright 2009 Intel Corporation; author H. Peter Anvin
  6. *
  7. * Original APM BIOS checking by Stephen Rothwell, May 1994
  8. * (sfr@canb.auug.org.au)
  9. *
  10. * This file is part of the Linux kernel, and is made available under
  11. * the terms of the GNU General Public License version 2.
  12. *
  13. * ----------------------------------------------------------------------- */
  14. /*
  15. * Get APM BIOS information
  16. */
  17. #include "boot.h"
  18. int query_apm_bios(void)
  19. {
  20. struct biosregs ireg, oreg;
  21. /* APM BIOS installation check */
  22. initregs(&ireg);
  23. ireg.ah = 0x53;
  24. intcall(0x15, &ireg, &oreg);
  25. if (oreg.flags & X86_EFLAGS_CF)
  26. return -1; /* No APM BIOS */
  27. if (oreg.bx != 0x504d) /* "PM" signature */
  28. return -1;
  29. if (!(oreg.cx & 0x02)) /* 32 bits supported? */
  30. return -1;
  31. /* Disconnect first, just in case */
  32. ireg.al = 0x04;
  33. intcall(0x15, &ireg, NULL);
  34. /* 32-bit connect */
  35. ireg.al = 0x03;
  36. intcall(0x15, &ireg, &oreg);
  37. boot_params.apm_bios_info.cseg = oreg.ax;
  38. boot_params.apm_bios_info.offset = oreg.ebx;
  39. boot_params.apm_bios_info.cseg_16 = oreg.cx;
  40. boot_params.apm_bios_info.dseg = oreg.dx;
  41. boot_params.apm_bios_info.cseg_len = oreg.si;
  42. boot_params.apm_bios_info.cseg_16_len = oreg.hsi;
  43. boot_params.apm_bios_info.dseg_len = oreg.di;
  44. if (oreg.flags & X86_EFLAGS_CF)
  45. return -1;
  46. /* Redo the installation check as the 32-bit connect;
  47. some BIOSes return different flags this way... */
  48. ireg.al = 0x00;
  49. intcall(0x15, &ireg, &oreg);
  50. if ((oreg.eflags & X86_EFLAGS_CF) || oreg.bx != 0x504d) {
  51. /* Failure with 32-bit connect, try to disconect and ignore */
  52. ireg.al = 0x04;
  53. intcall(0x15, &ireg, NULL);
  54. return -1;
  55. }
  56. boot_params.apm_bios_info.version = oreg.ax;
  57. boot_params.apm_bios_info.flags = oreg.cx;
  58. return 0;
  59. }