apm.c 1.8 KB

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