2 #include </386/include/ureg.h>
8 ulong PM1a_CNT_BLK, PM1b_CNT_BLK, SLP_TYPa, SLP_TYPb;
14 typedef struct Tbl Tbl;
40 return p[3]<<24 | p[2]<<16 | p[1]<<8 | p[0];
47 if(write(fd, &u, sizeof u) < 0)
48 sysfatal("write: %r");
50 if(read(fd, &u, sizeof u) < 0)
53 sysfatal("apm: %lux", (u.ax>>8) & 0xFF);
66 t = malloc(sizeof(*t));
67 if((n = readn(fd, t, sizeof(*t))) <= 0)
76 if(readn(fd, t->data, l) != l)
78 if(memcmp("DSDT", t->sig, 4) == 0)
80 else if(memcmp("SSDT", t->sig, 4) == 0)
82 else if(memcmp("FACP", t->sig, 4) == 0){
83 PM1a_CNT_BLK = get32(((uchar*)t) + 64);
84 PM1b_CNT_BLK = get32(((uchar*)t) + 68);
87 if(amleval(amlwalk(amlroot, "_S5"), "", &r) < 0)
89 if(amltag(r) != 'p' || amllen(r) < 2)
92 SLP_TYPa = amlint(rr[0]);
93 SLP_TYPb = amlint(rr[1]);
98 outw(long addr, ushort val)
106 pwrite(iofd, buf, 2, addr);
115 snprint(buf, sizeof(buf), "/proc/%d/ctl", getpid());
116 if((ctl = open(buf, OWRITE)) < 0){
117 snprint(buf, sizeof(buf), "#p/%d/ctl", getpid());
118 if((ctl = open(buf, OWRITE)) < 0)
121 write(ctl, "wired 0", 7);
130 if((fd = open("/dev/apm", ORDWR)) < 0)
131 if((fd = open("#P/apm", ORDWR)) < 0)
144 if((fd = open("/dev/acpitbls", OREAD)) < 0)
145 if((fd = open("#P/acpitbls", OREAD)) < 0)
147 if((iofd = open("/dev/iow", OWRITE)) < 0)
148 if((iofd = open("#P/iow", OWRITE)) < 0)
153 outw(PM1a_CNT_BLK, ((SLP_TYPa << 10) & SLP_TM) | SLP_EN);
154 outw(PM1b_CNT_BLK, ((SLP_TYPb << 10) & SLP_TM) | SLP_EN);
158 * The SetSystemSleeping() example from the ACPI spec
159 * writes the same value in both registers. But Linux/BSD
160 * write distinct values from the _Sx package (like the
161 * code above). The _S5 package on a HP DC5700 is
162 * Package(0x2){0x0, 0x7} and writing SLP_TYPa of 0 to
163 * PM1a_CNT_BLK seems to have no effect but 0x7 seems
164 * to work fine. So trying the following as a last effort.
166 SLP_TYPa |= SLP_TYPb;
167 outw(PM1a_CNT_BLK, ((SLP_TYPa << 10) & SLP_TM) | SLP_EN);
168 outw(PM1b_CNT_BLK, ((SLP_TYPa << 10) & SLP_TM) | SLP_EN);