1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#include <stdio.h>
#include <errno.h>
#include <inttypes.h>
#include <stdlib.h>
#include <sys/io.h>
#include <mach.h>
#include "acpi_shutdown.h"
void disappear_via_acpi(void)
{
uint16_t i, pm1a_ctl, smi_cmd;
uint8_t regbuf[2], acpi_en;
FILE *facp;
/* Open the ACPI FADT table */
facp = fopen(SERVERS_ACPI_FADT, "r");
if (!facp)
exit(errno);
/* Grab value to write to SMI_CMD to enable ACPI */
fseek(facp, SMI_EN_OFFSET, SEEK_SET);
fread(&acpi_en, 1, 1, facp);
/* Grab SMI_CMD I/O port */
fseek(facp, SMI_CMD_OFFSET, SEEK_SET);
fread(regbuf, 2, 1, facp);
smi_cmd = (uint16_t)regbuf[0] |
((uint16_t)regbuf[1] << 8);
/* Grab PM1a Control I/O port */
fseek(facp, PM1A_CTL_OFFSET, SEEK_SET);
fread(regbuf, 2, 1, facp);
pm1a_ctl = (uint16_t)regbuf[0] |
((uint16_t)regbuf[1] << 8);
/* Close the ACPI FADT table */
fclose(facp);
/* Get I/O permissions */
if (ioperm(smi_cmd, 2, 1)) {
mach_print("EPERM on ioperm(smi_cmd)\n");
return;
}
if (ioperm(pm1a_ctl, 2, 1)) {
mach_print("EPERM on ioperm(pm1a_ctl)\n");
return;
}
/* Enable ACPI */
outb(acpi_en, smi_cmd);
for (i = 0; i < 300; i++)
{
if ( (inw(pm1a_ctl) & SCI_EN) == SCI_EN)
break;
}
/* Kill machine */
/* try sleep state 5 first */
outw(SLP_TYP5 | SLP_EN, pm1a_ctl);
/* if we reach here then above did not work */
outw(SLP_TYP0 | SLP_EN, pm1a_ctl);
/* Never reached */
}
|