-
Notifications
You must be signed in to change notification settings - Fork 0
/
devacpi.c
206 lines (180 loc) · 2.78 KB
/
devacpi.c
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
* ACPI driver
* currently only poweroff command
*/
#include "u.h"
#include "../port/lib.h"
#include "mem.h"
#include "dat.h"
#include "fns.h"
#include "io.h"
#include "../port/error.h"
void init_acpi();
unsigned int *acpi_check_rsd_ptr(unsigned int *ptr);
unsigned int *acpi_get_rsd_ptr();
int acpi_check_headr(unsigned int *ptr, char *sig);
int acpi_enable();
void acpi_poweroff();
ulong *SMI_CMD;
uchar ACPI_ENABLE;
uchar ACPI_DISABLE;
ulong *PM1a_CNT;
ulong *PM1b_CNT;
uint SLP_TYPa;
uint SLP_TYPb;
uint SLP_EN;
uint SCI_EN;
uchar PM1_CNT_LEN;
struct rsdptr
{
uchar signature[8];
uchar checksum;
uchar oemid[6];
uchar revision;
ulong *rsdtaddr;
};
struct facp
{
uchar signature[4];
ulong length;
uchar unneded1[40-8];
ulong *dsdt;
uchar unneded2[48-44];
ulong *SMI_CMD;
uchar ACPI_ENABLE;
uchar ACPI_DISABLE;
uchar unneded3[64-54];
ulong *PM1a_CNT_BLK;
ulong *PM1b_CNT_BLK;
uchar unneded4[89-72];
uchar PM1_CNT_LEN;
};
void
do_poweroff(int n, char *va)
{
acpi_enable();
acpi_poweroff();
return;
}
enum {
Qdir,
Qpoweroff,
};
static Dirtab acpidir[] = {
".", {Qdir, 0, QTDIR}, 0, DMDIR|055,
"poweroff", {Qpoweroff}, 0, 0777,
};
static void
acpireset(void)
{
init_acpi();
}
static void
acpiinit(void)
{
init_acpi();
}
static Chan*
acpiattach(char *spec)
{
return devattach('A', spec);
}
static Walkqid*
acpiwalk(Chan *c, Chan *nc, char **name, int nname)
{
return devwalk(c, nc, name, nname, acpidir, nelem(acpidir), devgen);
}
static int
acpistat(Chan *c, uchar *dp, int n)
{
return devstat(c, dp, n, acpidir, nelem(acpidir), devgen);
}
static Chan*
acpiopen(Chan *c, int omode)
{
if( !iseve() ) {
error( Eperm );
}
return devopen( c, omode, acpidir, nelem(acpidir), devgen);
}
static void
acpiclose(Chan *c)
{
if( c->aux ) {
free( c->aux );
c->aux = nil;
}
return;
}
static long
acpiread(Chan *c, void *va, long n, vlong off)
{
switch( (ulong)c->qid.path ) {
case Qdir:
return devdirread( c, va, n, acpidir, nelem(acpidir), devgen);
break;
case Qpoweroff:
n = readstr(off, va, n, "power is on.. maybe");
break;
default:
break;
}
return n;
}
static long
acpiwrite(Chan *c, void *va, long n, vlong)
{
switch( (ulong)c->qid.path ) {
case Qdir:
error( Eisdir );
break;
case Qpoweroff:
do_poweroff(n, va);
break;
default:
break;
}
return n;
}
Dev acpidevtab = {
'A',
"acpi",
devreset,
devinit,
devshutdown,
acpiattach,
acpiwalk,
acpistat,
acpiopen,
devcreate,
acpiclose,
acpiread,
devbread,
acpiwrite,
devbwrite,
devremove,
devwstat,
};
void
init_acpi()
{
}
unsigned int *
acpi_check_rsd_ptr(unsigned int *ptr)
{
}
unsigned int*
acpi_get_rsd_ptr()
{
}
int
acpi_check_headr(unsigned int *ptr, char *sig)
{
}
int
acpi_enable(){
}
void
acpi_poweroff()
{
}