Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

apm.c 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. * You can also choose to distribute this program under the terms of
  20. * the Unmodified Binary Distribution Licence (as given in the file
  21. * COPYING.UBDL), provided that you have satisfied its requirements.
  22. */
  23. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  24. /**
  25. * @file
  26. *
  27. * Advanced Power Management
  28. *
  29. */
  30. #include <errno.h>
  31. #include <realmode.h>
  32. #include <ipxe/reboot.h>
  33. /**
  34. * Power off the computer using APM
  35. *
  36. * @ret rc Return status code
  37. */
  38. static int apm_poweroff ( void ) {
  39. uint16_t apm_version;
  40. uint16_t apm_signature;
  41. uint16_t apm_flags;
  42. uint16_t carry;
  43. /* APM check */
  44. __asm__ __volatile__ ( REAL_CODE ( "int $0x15\n\t"
  45. "adc %%edx,0\n\t" )
  46. : "=a" ( apm_version ), "=b" ( apm_signature ),
  47. "=c" ( apm_flags ), "=d" ( carry )
  48. : "a" ( 0x5300 ), "b" ( 0x0000 ),
  49. "d" ( 0x0000 ) );
  50. if ( carry ) {
  51. DBG ( "APM not present\n" );
  52. return -ENOTSUP;
  53. }
  54. if ( apm_signature != 0x504d ) { /* signature 'PM' */
  55. DBG ( "APM not present\n" );
  56. return -ENOTSUP;
  57. }
  58. if ( apm_version < 0x0101 ) { /* Need version 1.1+ */
  59. DBG ( "APM 1.1+ not supported\n" );
  60. return -ENOTSUP;
  61. }
  62. if ( ( apm_flags & 0x8 ) == 0x8 ) {
  63. DBG ( "APM power management disabled\n" );
  64. return -EPERM;
  65. }
  66. DBG2 ( "APM check completed\n" );
  67. /* APM initialisation */
  68. __asm__ __volatile__ ( REAL_CODE ( "int $0x15\n\t"
  69. "adc %%edx,0\n\t" )
  70. : "=d" ( carry )
  71. : "a" ( 0x5301 ), "b" ( 0x0000 ),
  72. "d" ( 0x0000 ) );
  73. if ( carry ) {
  74. DBG ( "APM initialisation failed\n" );
  75. return -EIO;
  76. }
  77. DBG2 ( "APM initialisation completed\n" );
  78. /* Set APM driver version */
  79. __asm__ __volatile__ ( REAL_CODE ( "int $0x15\n\t"
  80. "adc %%edx,0\n\t" )
  81. : "=d" ( carry )
  82. : "a" ( 0x530e ), "b" ( 0x0000 ),
  83. "c" ( 0x0101 ), "d" ( 0x0000 ) );
  84. if ( carry ) {
  85. DBG ( "APM setting driver version failed\n" );
  86. return -EIO;
  87. }
  88. DBG2 ( "APM driver version set\n" );
  89. /* Setting power state to off */
  90. __asm__ __volatile__ ( REAL_CODE ( "int $0x15\n\t"
  91. "adc %%edx,0\n\t" )
  92. : "=d" ( carry )
  93. : "a" ( 0x5307 ), "b" ( 0x0001 ),
  94. "c" ( 0x0003 ), "d" ( 0x0000) );
  95. if ( carry ) {
  96. DBG ( "APM setting power state failed\n" );
  97. return -ENOTTY;
  98. }
  99. /* Should never happen */
  100. return -ECANCELED;
  101. }
  102. PROVIDE_REBOOT ( pcbios, poweroff, apm_poweroff );