Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

apm.c 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright (C) 2013 Marin Hannache <ipxe@mareo.fr>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. */
  19. FILE_LICENCE ( GPL2_OR_LATER );
  20. /**
  21. * @file
  22. *
  23. * Advanced Power Management
  24. *
  25. */
  26. #include <errno.h>
  27. #include <realmode.h>
  28. #include <ipxe/reboot.h>
  29. /**
  30. * Power off the computer using APM
  31. *
  32. * @ret rc Return status code
  33. */
  34. static int apm_poweroff ( void ) {
  35. uint16_t apm_version;
  36. uint16_t apm_signature;
  37. uint16_t apm_flags;
  38. uint16_t carry;
  39. /* APM check */
  40. __asm__ __volatile__ ( REAL_CODE ( "int $0x15\n\t"
  41. "adc %%edx,0\n\t" )
  42. : "=a" ( apm_version ), "=b" ( apm_signature ),
  43. "=c" ( apm_flags ), "=d" ( carry )
  44. : "a" ( 0x5300 ), "b" ( 0x0000 ),
  45. "d" ( 0x0000 ) );
  46. if ( carry ) {
  47. DBG ( "APM not present\n" );
  48. return -ENOTSUP;
  49. }
  50. if ( apm_signature != 0x504d ) { /* signature 'PM' */
  51. DBG ( "APM not present\n" );
  52. return -ENOTSUP;
  53. }
  54. if ( apm_version < 0x0101 ) { /* Need version 1.1+ */
  55. DBG ( "APM 1.1+ not supported\n" );
  56. return -ENOTSUP;
  57. }
  58. if ( ( apm_flags & 0x8 ) == 0x8 ) {
  59. DBG ( "APM power management disabled\n" );
  60. return -EPERM;
  61. }
  62. DBG2 ( "APM check completed\n" );
  63. /* APM initialisation */
  64. __asm__ __volatile__ ( REAL_CODE ( "int $0x15\n\t"
  65. "adc %%edx,0\n\t" )
  66. : "=d" ( carry )
  67. : "a" ( 0x5301 ), "b" ( 0x0000 ),
  68. "d" ( 0x0000 ) );
  69. if ( carry ) {
  70. DBG ( "APM initialisation failed\n" );
  71. return -EIO;
  72. }
  73. DBG2 ( "APM initialisation completed\n" );
  74. /* Set APM driver version */
  75. __asm__ __volatile__ ( REAL_CODE ( "int $0x15\n\t"
  76. "adc %%edx,0\n\t" )
  77. : "=d" ( carry )
  78. : "a" ( 0x530e ), "b" ( 0x0000 ),
  79. "c" ( 0x0101 ), "d" ( 0x0000 ) );
  80. if ( carry ) {
  81. DBG ( "APM setting driver version failed\n" );
  82. return -EIO;
  83. }
  84. DBG2 ( "APM driver version set\n" );
  85. /* Setting power state to off */
  86. __asm__ __volatile__ ( REAL_CODE ( "int $0x15\n\t"
  87. "adc %%edx,0\n\t" )
  88. : "=d" ( carry )
  89. : "a" ( 0x5307 ), "b" ( 0x0001 ),
  90. "c" ( 0x0003 ), "d" ( 0x0000) );
  91. if ( carry ) {
  92. DBG ( "APM setting power state failed\n" );
  93. return -ENOTTY;
  94. }
  95. /* Should never happen */
  96. return -ECANCELED;
  97. }
  98. PROVIDE_REBOOT ( pcbios, poweroff, apm_poweroff );