iPXE
Macros | Functions
acpipwr.c File Reference

ACPI power off. More...

#include <unistd.h>
#include <errno.h>
#include <byteswap.h>
#include <ipxe/io.h>
#include <ipxe/acpi.h>
#include <ipxe/acpipwr.h>

Go to the source code of this file.

Macros

#define colour   FADT_SIGNATURE
 Colour for debug messages. More...
 
#define S5_SIGNATURE   ACPI_SIGNATURE ( '_', 'S', '5', '_' )
 S5 signature More...
 

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

Macro Definition Documentation

◆ colour

#define colour   FADT_SIGNATURE

Colour for debug messages.

Definition at line 40 of file acpipwr.c.

◆ S5_SIGNATURE

#define S5_SIGNATURE   ACPI_SIGNATURE ( '_', 'S', '5', '_' )

S5 signature

Definition at line 43 of file acpipwr.c.

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 50 of file acpipwr.c.

50  {
51  struct acpi_fadt fadtab;
52  userptr_t fadt;
53  unsigned int pm1a_cnt_blk;
54  unsigned int pm1b_cnt_blk;
55  unsigned int pm1a_cnt;
56  unsigned int pm1b_cnt;
57  unsigned int slp_typa;
58  unsigned int slp_typb;
59  int s5;
60  int rc;
61 
62  /* Locate FADT */
63  fadt = acpi_find ( FADT_SIGNATURE, 0 );
64  if ( ! fadt ) {
65  DBGC ( colour, "ACPI could not find FADT\n" );
66  return -ENOENT;
67  }
68 
69  /* Read FADT */
70  copy_from_user ( &fadtab, fadt, 0, sizeof ( fadtab ) );
71  pm1a_cnt_blk = le32_to_cpu ( fadtab.pm1a_cnt_blk );
72  pm1b_cnt_blk = le32_to_cpu ( fadtab.pm1b_cnt_blk );
73  pm1a_cnt = ( pm1a_cnt_blk + ACPI_PM1_CNT );
74  pm1b_cnt = ( pm1b_cnt_blk + ACPI_PM1_CNT );
75 
76  /* Extract \_S5 from DSDT or any SSDT */
77  s5 = acpi_sx ( S5_SIGNATURE );
78  if ( s5 < 0 ) {
79  rc = s5;
80  DBGC ( colour, "ACPI could not extract \\_S5: %s\n",
81  strerror ( rc ) );
82  return rc;
83  }
84 
85  /* Power off system */
86  if ( pm1a_cnt_blk ) {
87  slp_typa = ( ( s5 >> 0 ) & 0xff );
88  DBGC ( colour, "ACPI PM1a sleep type %#x => %04x\n",
89  slp_typa, pm1a_cnt );
90  outw ( ( ACPI_PM1_CNT_SLP_TYP ( slp_typa ) |
91  ACPI_PM1_CNT_SLP_EN ), pm1a_cnt );
92  }
93  if ( pm1b_cnt_blk ) {
94  slp_typb = ( ( s5 >> 8 ) & 0xff );
95  DBGC ( colour, "ACPI PM1b sleep type %#x => %04x\n",
96  slp_typb, pm1b_cnt );
97  outw ( ( ACPI_PM1_CNT_SLP_TYP ( slp_typb ) |
98  ACPI_PM1_CNT_SLP_EN ), pm1b_cnt );
99  }
100 
101  /* On some systems, execution will continue briefly. Delay to
102  * avoid potentially confusing log messages.
103  */
104  mdelay ( 1000 );
105 
106  DBGC ( colour, "ACPI power off failed\n" );
107  return -EPROTO;
108 }
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:129
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
#define ENOENT
No such file or directory.
Definition: errno.h:514
#define colour
Colour for debug messages.
Definition: acpipwr.c:40
Fixed ACPI Description Table (FADT)
Definition: acpi.h:109
#define FADT_SIGNATURE
Fixed ACPI Description Table (FADT) signature.
Definition: acpi.h:106
uint32_t pm1a_cnt_blk
PM1a Control Register Block.
Definition: acpi.h:119
#define ACPI_PM1_CNT_SLP_EN
Sleep enable.
Definition: acpi.h:131
#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:130
uint32_t pm1b_cnt_blk
PM1b Control Register Block.
Definition: acpi.h:121
#define S5_SIGNATURE
S5 signature
Definition: acpipwr.c:43
userptr_t acpi_find(uint32_t signature, unsigned int index)
Locate ACPI table.
Definition: acpi.c:89
int acpi_sx(uint32_t signature)
Extract _Sx value from DSDT/SSDT.
Definition: acpi.c:257
unsigned long userptr_t
A pointer to a user buffer.
Definition: uaccess.h:33

References acpi_find(), ACPI_PM1_CNT, ACPI_PM1_CNT_SLP_EN, ACPI_PM1_CNT_SLP_TYP, acpi_sx(), 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().