iPXE
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.

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 )
extern

Power off the computer using ACPI.

Return values
rcReturn status code

Definition at line 115 of file acpipwr.c.

115 {
116 const struct acpi_fadt *fadt;
117 unsigned int pm1a_cnt_blk;
118 unsigned int pm1b_cnt_blk;
119 unsigned int pm1a_cnt;
120 unsigned int pm1b_cnt;
121 unsigned int slp_typa;
122 unsigned int slp_typb;
123 unsigned int s5;
124 int rc;
125
126 /* Locate FADT */
127 fadt = container_of ( acpi_table ( FADT_SIGNATURE, 0 ),
128 struct acpi_fadt, acpi );
129 if ( ! fadt ) {
130 DBGC ( colour, "ACPI could not find FADT\n" );
131 return -ENOENT;
132 }
133
134 /* Read FADT */
137 pm1a_cnt = ( pm1a_cnt_blk + ACPI_PM1_CNT );
138 pm1b_cnt = ( pm1b_cnt_blk + ACPI_PM1_CNT );
139
140 /* Extract \_S5 from DSDT or any SSDT */
141 if ( ( rc = acpi_extract ( S5_SIGNATURE, &s5,
142 acpi_extract_sx ) ) != 0 ) {
143 DBGC ( colour, "ACPI could not extract \\_S5: %s\n",
144 strerror ( rc ) );
145 return rc;
146 }
147
148 /* Power off system */
149 if ( pm1a_cnt_blk ) {
150 slp_typa = ( ( s5 >> 0 ) & 0xff );
151 DBGC ( colour, "ACPI PM1a sleep type %#x => %04x\n",
152 slp_typa, pm1a_cnt );
153 outw ( ( ACPI_PM1_CNT_SLP_TYP ( slp_typa ) |
154 ACPI_PM1_CNT_SLP_EN ), pm1a_cnt );
155 }
156 if ( pm1b_cnt_blk ) {
157 slp_typb = ( ( s5 >> 8 ) & 0xff );
158 DBGC ( colour, "ACPI PM1b sleep type %#x => %04x\n",
159 slp_typb, pm1b_cnt );
160 outw ( ( ACPI_PM1_CNT_SLP_TYP ( slp_typb ) |
161 ACPI_PM1_CNT_SLP_EN ), pm1b_cnt );
162 }
163
164 /* On some systems, execution will continue briefly. Delay to
165 * avoid potentially confusing log messages.
166 */
167 mdelay ( 1000 );
168
169 DBGC ( colour, "ACPI power off failed\n" );
170 return -EPROTO;
171}
const struct acpi_header * acpi_table(uint32_t signature, unsigned int index)
Locate ACPI table.
Definition acpi.c:93
#define colour
Colour for debug messages.
Definition acpi.c:42
int acpi_extract(uint32_t signature, void *data, int(*extract)(const struct acpi_header *zsdt, size_t len, size_t offset, void *data))
Extract value from DSDT/SSDT.
Definition acpi.c:228
#define S5_SIGNATURE
S5 signature
Definition acpipwr.c:44
static int acpi_extract_sx(const struct acpi_header *zsdt, size_t len, size_t offset, void *data)
Extract _Sx value from DSDT/SSDT.
Definition acpipwr.c:66
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
static EFI_ACPI_TABLE_PROTOCOL * acpi
ACPI table protocol protocol.
Definition efi_block.c:67
#define DBGC(...)
Definition compiler.h:505
#define ENOENT
No such file or directory.
Definition errno.h:515
#define EPROTO
Protocol error.
Definition errno.h:625
#define le32_to_cpu(value)
Definition byteswap.h:114
#define FADT_SIGNATURE
Fixed ACPI Description Table (FADT) signature.
Definition acpi.h:258
#define ACPI_PM1_CNT_SLP_TYP(x)
Sleep type.
Definition acpi.h:282
#define ACPI_PM1_CNT_SLP_EN
Sleep enable.
Definition acpi.h:283
#define ACPI_PM1_CNT
ACPI PM1 Control Register (within PM1a_CNT_BLK or PM1A_CNT_BLK)
Definition acpi.h:281
#define outw(data, io_addr)
Definition io.h:320
#define container_of(ptr, type, field)
Get containing structure.
Definition stddef.h:36
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
Fixed ACPI Description Table (FADT)
Definition acpi.h:261
uint32_t pm1a_cnt_blk
PM1a Control Register Block.
Definition acpi.h:271
uint32_t pm1b_cnt_blk
PM1b Control Register Block.
Definition acpi.h:273
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition timer.c:79

References acpi, acpi_extract(), acpi_extract_sx(), ACPI_PM1_CNT, ACPI_PM1_CNT_SLP_EN, ACPI_PM1_CNT_SLP_TYP, acpi_table(), colour, container_of, 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().