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,
34 return p[3]<<24 | p[2]<<16 | p[1]<<8 | p[0];
41 if(write(fd, &u, sizeof u) < 0)
42 sysfatal("write: %r");
44 if(read(fd, &u, sizeof u) < 0)
47 sysfatal("apm: %lux", (u.ax>>8) & 0xFF);
60 t = malloc(sizeof(*t));
61 if((n = readn(fd, t, Tblsz)) <= 0)
69 t = realloc(t, sizeof(*t) + l);
70 if(readn(fd, t->data, l) != l)
72 if(memcmp("DSDT", t->sig, 4) == 0)
74 else if(memcmp("SSDT", t->sig, 4) == 0)
76 else if(memcmp("FACP", t->sig, 4) == 0){
77 PM1a_CNT_BLK = get32(((uchar*)t) + 64);
78 PM1b_CNT_BLK = get32(((uchar*)t) + 68);
81 if(amleval(amlwalk(amlroot, "_S5"), "", &r) < 0)
83 if(amltag(r) != 'p' || amllen(r) < 2)
86 SLP_TYPa = amlint(rr[0]);
87 SLP_TYPb = amlint(rr[1]);
92 outw(long addr, ushort val)
100 pwrite(iofd, buf, 2, addr);
109 snprint(buf, sizeof(buf), "/proc/%d/ctl", getpid());
110 if((ctl = open(buf, OWRITE)) < 0){
111 snprint(buf, sizeof(buf), "#p/%d/ctl", getpid());
112 if((ctl = open(buf, OWRITE)) < 0)
115 write(ctl, "wired 0", 7);
124 if((fd = open("/dev/apm", ORDWR)) < 0)
125 if((fd = open("#P/apm", ORDWR)) < 0)
138 if((fd = open("/dev/acpitbls", OREAD)) < 0)
139 if((fd = open("#P/acpitbls", OREAD)) < 0)
141 if((iofd = open("/dev/iow", OWRITE)) < 0)
142 if((iofd = open("#P/iow", OWRITE)) < 0)
147 outw(PM1a_CNT_BLK, ((SLP_TYPa << 10) & SLP_TM) | SLP_EN);
148 outw(PM1b_CNT_BLK, ((SLP_TYPb << 10) & SLP_TM) | SLP_EN);
152 * The SetSystemSleeping() example from the ACPI spec
153 * writes the same value in both registers. But Linux/BSD
154 * write distinct values from the _Sx package (like the
155 * code above). The _S5 package on a HP DC5700 is
156 * Package(0x2){0x0, 0x7} and writing SLP_TYPa of 0 to
157 * PM1a_CNT_BLK seems to have no effect but 0x7 seems
158 * to work fine. So trying the following as a last effort.
160 SLP_TYPa |= SLP_TYPb;
161 outw(PM1a_CNT_BLK, ((SLP_TYPa << 10) & SLP_TM) | SLP_EN);
162 outw(PM1b_CNT_BLK, ((SLP_TYPa << 10) & SLP_TM) | SLP_EN);