iPXE
Functions
acpipwr.h File Reference

ACPI power off. More...

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
int acpi_poweroff (void)
 Power off the computer using ACPI. More...
 

Detailed Description

ACPI power off.

Definition in file acpipwr.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ acpi_poweroff()

int acpi_poweroff ( void  )

Power off the computer using ACPI.

Return values
rcReturn status code

Definition at line 113 of file acpipwr.c.

113  {
114  struct acpi_fadt fadtab;
115  userptr_t fadt;
116  unsigned int pm1a_cnt_blk;
117  unsigned int pm1b_cnt_blk;
118  unsigned int pm1a_cnt;
119  unsigned int pm1b_cnt;
120  unsigned int slp_typa;
121  unsigned int slp_typb;
122  unsigned int s5;
123  int rc;
124 
125  /* Locate FADT */
126  fadt = acpi_table ( FADT_SIGNATURE, 0 );
127  if ( ! fadt ) {
128  DBGC ( colour, "ACPI could not find FADT\n" );
129  return -ENOENT;
130  }
131 
132  /* Read FADT */
133  copy_from_user ( &fadtab, fadt, 0, sizeof ( fadtab ) );
134  pm1a_cnt_blk = le32_to_cpu ( fadtab.pm1a_cnt_blk );
135  pm1b_cnt_blk = le32_to_cpu ( fadtab.pm1b_cnt_blk );
136  pm1a_cnt = ( pm1a_cnt_blk + ACPI_PM1_CNT );
137  pm1b_cnt = ( pm1b_cnt_blk + ACPI_PM1_CNT );
138 
139  /* Extract \_S5 from DSDT or any SSDT */
140  if ( ( rc = acpi_extract ( S5_SIGNATURE, &s5,
141  acpi_extract_sx ) ) != 0 ) {
142  DBGC ( colour, "ACPI could not extract \\_S5: %s\n",
143  strerror ( rc ) );
144  return rc;
145  }
146 
147  /* Power off system */
148  if ( pm1a_cnt_blk ) {
149  slp_typa = ( ( s5 >> 0 ) & 0xff );
150  DBGC ( colour, "ACPI PM1a sleep type %#x => %04x\n",
151  slp_typa, pm1a_cnt );
152  outw ( ( ACPI_PM1_CNT_SLP_TYP ( slp_typa ) |
153  ACPI_PM1_CNT_SLP_EN ), pm1a_cnt );
154  }
155  if ( pm1b_cnt_blk ) {
156  slp_typb = ( ( s5 >> 8 ) & 0xff );
157  DBGC ( colour, "ACPI PM1b sleep type %#x => %04x\n",
158  slp_typb, pm1b_cnt );
159  outw ( ( ACPI_PM1_CNT_SLP_TYP ( slp_typb ) |
160  ACPI_PM1_CNT_SLP_EN ), pm1b_cnt );
161  }
162 
163  /* On some systems, execution will continue briefly. Delay to
164  * avoid potentially confusing log messages.
165  */
166  mdelay ( 1000 );
167 
168  DBGC ( colour, "ACPI power off failed\n" );
169  return -EPROTO;
170 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define le32_to_cpu(value)
Definition: byteswap.h:113
#define outw(data, io_addr)
Definition: io.h:319
#define ACPI_PM1_CNT
ACPI PM1 Control Register (within PM1a_CNT_BLK or PM1A_CNT_BLK)
Definition: acpi.h:264
static int acpi_extract_sx(userptr_t zsdt, size_t len, size_t offset, void *data)
Extract _Sx value from DSDT/SSDT.
Definition: acpipwr.c:65
static __always_inline void copy_from_user(void *dest, userptr_t src, off_t src_off, size_t len)
Copy data from user buffer.
Definition: uaccess.h:337
#define DBGC(...)
Definition: compiler.h:505
userptr_t acpi_table(uint32_t signature, unsigned int index)
Locate ACPI table.
Definition: acpi.c:98
#define ENOENT
No such file or directory.
Definition: errno.h:514
#define colour
Colour for debug messages.
Definition: acpipwr.c:40
int acpi_extract(uint32_t signature, void *data, int(*extract)(userptr_t zsdt, size_t len, size_t offset, void *data))
Extract value from DSDT/SSDT.
Definition: acpi.c:240
Fixed ACPI Description Table (FADT)
Definition: acpi.h:244
#define FADT_SIGNATURE
Fixed ACPI Description Table (FADT) signature.
Definition: acpi.h:241
uint32_t pm1a_cnt_blk
PM1a Control Register Block.
Definition: acpi.h:254
#define ACPI_PM1_CNT_SLP_EN
Sleep enable.
Definition: acpi.h:266
#define EPROTO
Protocol error.
Definition: errno.h:624
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
#define ACPI_PM1_CNT_SLP_TYP(x)
Sleep type.
Definition: acpi.h:265
uint32_t pm1b_cnt_blk
PM1b Control Register Block.
Definition: acpi.h:256
#define S5_SIGNATURE
S5 signature
Definition: acpipwr.c:43
unsigned long userptr_t
A pointer to a user buffer.
Definition: uaccess.h:33

References acpi_extract(), acpi_extract_sx(), ACPI_PM1_CNT, ACPI_PM1_CNT_SLP_EN, ACPI_PM1_CNT_SLP_TYP, acpi_table(), colour, copy_from_user(), DBGC, ENOENT, EPROTO, FADT_SIGNATURE, le32_to_cpu, mdelay(), outw, acpi_fadt::pm1a_cnt_blk, acpi_fadt::pm1b_cnt_blk, rc, S5_SIGNATURE, and strerror().

Referenced by bios_poweroff().