iPXE
Functions
apm.h File Reference

Advanced Power Management. More...

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
int apm_poweroff (void)
 Power off the computer using APM. More...
 

Detailed Description

Advanced Power Management.

Definition in file apm.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ apm_poweroff()

int apm_poweroff ( void  )

Power off the computer using APM.

Return values
rcReturn status code

Definition at line 42 of file apm.c.

42  {
43  uint16_t apm_version;
44  uint16_t apm_signature;
45  uint16_t apm_flags;
47 
48  /* APM check */
49  __asm__ __volatile__ ( REAL_CODE ( "int $0x15\n\t"
50  "adc %%edx,0\n\t" )
51  : "=a" ( apm_version ), "=b" ( apm_signature ),
52  "=c" ( apm_flags ), "=d" ( carry )
53  : "a" ( 0x5300 ), "b" ( 0x0000 ),
54  "d" ( 0x0000 ) );
55  if ( carry ) {
56  DBG ( "APM not present\n" );
57  return -ENOTSUP;
58  }
59  if ( apm_signature != 0x504d ) { /* signature 'PM' */
60  DBG ( "APM not present\n" );
61  return -ENOTSUP;
62  }
63  if ( apm_version < 0x0101 ) { /* Need version 1.1+ */
64  DBG ( "APM 1.1+ not supported\n" );
65  return -ENOTSUP;
66  }
67  if ( ( apm_flags & 0x8 ) == 0x8 ) {
68  DBG ( "APM power management disabled\n" );
69  return -EPERM;
70  }
71  DBG2 ( "APM check completed\n" );
72 
73  /* APM initialisation */
74  __asm__ __volatile__ ( REAL_CODE ( "int $0x15\n\t"
75  "adc %%edx,0\n\t" )
76  : "=d" ( carry )
77  : "a" ( 0x5301 ), "b" ( 0x0000 ),
78  "d" ( 0x0000 ) );
79  if ( carry ) {
80  DBG ( "APM initialisation failed\n" );
81  return -EIO;
82  }
83  DBG2 ( "APM initialisation completed\n" );
84 
85  /* Set APM driver version */
86  __asm__ __volatile__ ( REAL_CODE ( "int $0x15\n\t"
87  "adc %%edx,0\n\t" )
88  : "=d" ( carry )
89  : "a" ( 0x530e ), "b" ( 0x0000 ),
90  "c" ( 0x0101 ), "d" ( 0x0000 ) );
91  if ( carry ) {
92  DBG ( "APM setting driver version failed\n" );
93  return -EIO;
94  }
95  DBG2 ( "APM driver version set\n" );
96 
97  /* Setting power state to off */
98  __asm__ __volatile__ ( REAL_CODE ( "int $0x15\n\t"
99  "adc %%edx,0\n\t" )
100  : "=d" ( carry )
101  : "a" ( 0x5307 ), "b" ( 0x0001 ),
102  "c" ( 0x0003 ), "d" ( 0x0000) );
103  if ( carry ) {
104  DBG ( "APM setting power state failed\n" );
105  return -ENOTTY;
106  }
107 
108  /* Should never happen */
109  return -ECANCELED;
110 }
unsigned short uint16_t
Definition: stdint.h:11
#define ECANCELED
Operation canceled.
Definition: errno.h:343
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
static const uint32_t uint32_t uint32_t * carry
Definition: bigint.h:316
__asm__ __volatile__("call *%9" :"=a"(result), "=c"(discard_ecx), "=d"(discard_edx) :"d"(0), "a"(code), "b"(0), "c"(in_phys), "D"(0), "S"(out_phys), "m"(hypercall))
#define EPERM
Operation not permitted.
Definition: errno.h:614
__asm__(".section \".rodata\", \"a\", " PROGBITS "\n\t" "\nprivate_key_data:\n\t" ".size private_key_data, ( . - private_key_data )\n\t" ".equ private_key_len, ( . - private_key_data )\n\t" ".previous\n\t")
#define ENOTTY
Inappropriate I/O control operation.
Definition: errno.h:594
#define EIO
Input/output error.
Definition: errno.h:433
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define REAL_CODE(asm_code_str)
Definition: libkir.h:226
#define DBG2(...)
Definition: compiler.h:515

References __asm__(), __volatile__(), carry, DBG, DBG2, ECANCELED, EIO, ENOTSUP, ENOTTY, EPERM, and REAL_CODE.

Referenced by bios_poweroff().