2 #include </386/include/ureg.h>
8 ulong PM1a_CNT_BLK, PM1b_CNT_BLK, SLP_TYPa, SLP_TYPb;
14 typedef struct Tbl Tbl;
29 Tblsz = 4+4+1+1+6+8+4+4+4,
44 return p[3]<<24 | p[2]<<16 | p[1]<<8 | p[0];
51 if(write(fd, &u, sizeof u) < 0)
52 sysfatal("write: %r");
54 if(read(fd, &u, sizeof u) < 0)
57 sysfatal("apm: %lux", (u.ax>>8) & 0xFF);
70 t = malloc(sizeof(*t));
71 if((n = readn(fd, t, Tblsz)) <= 0)
79 t = realloc(t, sizeof(*t) + l);
80 if(readn(fd, t->data, l) != l)
82 if(memcmp("DSDT", t->sig, 4) == 0)
84 else if(memcmp("SSDT", t->sig, 4) == 0)
86 else if(memcmp("FACP", t->sig, 4) == 0){
87 PM1a_CNT_BLK = get32(((uchar*)t) + 64);
88 PM1b_CNT_BLK = get32(((uchar*)t) + 68);
91 if(amleval(amlwalk(amlroot, "_S5"), "", &r) < 0)
93 if(amltag(r) != 'p' || amllen(r) < 2)
96 SLP_TYPa = amlint(rr[0]);
97 SLP_TYPb = amlint(rr[1]);
102 outw(long addr, ushort val)
110 pwrite(iofd, buf, 2, addr);
119 snprint(buf, sizeof(buf), "/proc/%d/ctl", getpid());
120 if((ctl = open(buf, OWRITE)) < 0){
121 snprint(buf, sizeof(buf), "#p/%d/ctl", getpid());
122 if((ctl = open(buf, OWRITE)) < 0)
125 write(ctl, "wired 0", 7);
134 if((fd = open("/dev/apm", ORDWR)) < 0)
135 if((fd = open("#P/apm", ORDWR)) < 0)
148 if((fd = open("/dev/acpitbls", OREAD)) < 0)
149 if((fd = open("#P/acpitbls", OREAD)) < 0)
151 if((iofd = open("/dev/iow", OWRITE)) < 0)
152 if((iofd = open("#P/iow", OWRITE)) < 0)
157 outw(PM1a_CNT_BLK, ((SLP_TYPa << 10) & SLP_TM) | SLP_EN);
158 outw(PM1b_CNT_BLK, ((SLP_TYPb << 10) & SLP_TM) | SLP_EN);
162 * The SetSystemSleeping() example from the ACPI spec
163 * writes the same value in both registers. But Linux/BSD
164 * write distinct values from the _Sx package (like the
165 * code above). The _S5 package on a HP DC5700 is
166 * Package(0x2){0x0, 0x7} and writing SLP_TYPa of 0 to
167 * PM1a_CNT_BLK seems to have no effect but 0x7 seems
168 * to work fine. So trying the following as a last effort.
170 SLP_TYPa |= SLP_TYPb;
171 outw(PM1a_CNT_BLK, ((SLP_TYPa << 10) & SLP_TM) | SLP_EN);
172 outw(PM1b_CNT_BLK, ((SLP_TYPa << 10) & SLP_TM) | SLP_EN);