Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * acpi_system.c - ACPI System Driver ($Revision: 63 $) | |
3 | * | |
4 | * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> | |
5 | * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> | |
6 | * | |
7 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or (at | |
12 | * your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, but | |
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 | * General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License along | |
20 | * with this program; if not, write to the Free Software Foundation, Inc., | |
21 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
22 | * | |
23 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
24 | */ | |
25 | ||
26 | #include <linux/proc_fs.h> | |
27 | #include <linux/seq_file.h> | |
28 | #include <linux/init.h> | |
e108526e | 29 | #include <linux/string.h> |
1da177e4 LT |
30 | #include <asm/uaccess.h> |
31 | ||
32 | #include <acpi/acpi_drivers.h> | |
33 | ||
1da177e4 | 34 | #define _COMPONENT ACPI_SYSTEM_COMPONENT |
f52fd66d | 35 | ACPI_MODULE_NAME("system"); |
5bb730fd | 36 | |
1da177e4 | 37 | #define ACPI_SYSTEM_CLASS "system" |
1da177e4 | 38 | #define ACPI_SYSTEM_DEVICE_NAME "System" |
1da177e4 | 39 | |
5229e87d LB |
40 | u32 acpi_irq_handled; |
41 | ||
5bb730fd ZR |
42 | /* |
43 | * Make ACPICA version work as module param | |
44 | */ | |
d4c5f047 ZR |
45 | static int param_get_acpica_version(char *buffer, struct kernel_param *kp) |
46 | { | |
5bb730fd ZR |
47 | int result; |
48 | ||
49 | result = sprintf(buffer, "%x", ACPI_CA_VERSION); | |
50 | ||
51 | return result; | |
52 | } | |
53 | ||
54 | module_param_call(acpica_version, NULL, param_get_acpica_version, NULL, 0444); | |
55 | ||
d4c5f047 ZR |
56 | /* -------------------------------------------------------------------------- |
57 | FS Interface (/sys) | |
58 | -------------------------------------------------------------------------- */ | |
59 | static LIST_HEAD(acpi_table_attr_list); | |
a77aa28a | 60 | static struct kobject *tables_kobj; |
4658e4ef | 61 | static struct kobject *dynamic_tables_kobj; |
d4c5f047 ZR |
62 | |
63 | struct acpi_table_attr { | |
64 | struct bin_attribute attr; | |
65 | char name[8]; | |
66 | int instance; | |
67 | struct list_head node; | |
68 | }; | |
69 | ||
70 | static ssize_t acpi_table_show(struct kobject *kobj, | |
71 | struct bin_attribute *bin_attr, char *buf, | |
72 | loff_t offset, size_t count) | |
73 | { | |
74 | struct acpi_table_attr *table_attr = | |
75 | container_of(bin_attr, struct acpi_table_attr, attr); | |
76 | struct acpi_table_header *table_header = NULL; | |
77 | acpi_status status; | |
4feba70a PG |
78 | char name[ACPI_NAME_SIZE]; |
79 | ||
80 | if (strncmp(table_attr->name, "NULL", 4)) | |
81 | memcpy(name, table_attr->name, ACPI_NAME_SIZE); | |
82 | else | |
83 | memcpy(name, "\0\0\0\0", 4); | |
d4c5f047 ZR |
84 | |
85 | status = | |
4feba70a | 86 | acpi_get_table(name, table_attr->instance, |
d4c5f047 ZR |
87 | &table_header); |
88 | if (ACPI_FAILURE(status)) | |
89 | return -ENODEV; | |
90 | ||
46a21e46 AM |
91 | return memory_read_from_buffer(buf, count, &offset, |
92 | table_header, table_header->length); | |
d4c5f047 ZR |
93 | } |
94 | ||
95 | static void acpi_table_attr_init(struct acpi_table_attr *table_attr, | |
96 | struct acpi_table_header *table_header) | |
97 | { | |
98 | struct acpi_table_header *header = NULL; | |
99 | struct acpi_table_attr *attr = NULL; | |
100 | ||
4feba70a PG |
101 | if (table_header->signature[0] != '\0') |
102 | memcpy(table_attr->name, table_header->signature, | |
103 | ACPI_NAME_SIZE); | |
104 | else | |
105 | memcpy(table_attr->name, "NULL", 4); | |
d4c5f047 ZR |
106 | |
107 | list_for_each_entry(attr, &acpi_table_attr_list, node) { | |
4feba70a | 108 | if (!memcmp(table_attr->name, attr->name, ACPI_NAME_SIZE)) |
d4c5f047 ZR |
109 | if (table_attr->instance < attr->instance) |
110 | table_attr->instance = attr->instance; | |
111 | } | |
112 | table_attr->instance++; | |
113 | ||
114 | if (table_attr->instance > 1 || (table_attr->instance == 1 && | |
4feba70a PG |
115 | !acpi_get_table |
116 | (table_header->signature, 2, &header))) | |
117 | sprintf(table_attr->name + ACPI_NAME_SIZE, "%d", | |
118 | table_attr->instance); | |
d4c5f047 ZR |
119 | |
120 | table_attr->attr.size = 0; | |
121 | table_attr->attr.read = acpi_table_show; | |
122 | table_attr->attr.attr.name = table_attr->name; | |
123 | table_attr->attr.attr.mode = 0444; | |
d4c5f047 ZR |
124 | |
125 | return; | |
126 | } | |
127 | ||
4658e4ef ZR |
128 | static acpi_status |
129 | acpi_sysfs_table_handler(u32 event, void *table, void *context) | |
130 | { | |
131 | struct acpi_table_attr *table_attr; | |
132 | ||
133 | switch (event) { | |
134 | case ACPI_TABLE_EVENT_LOAD: | |
135 | table_attr = | |
136 | kzalloc(sizeof(struct acpi_table_attr), GFP_KERNEL); | |
137 | if (!table_attr) | |
138 | return AE_NO_MEMORY; | |
139 | ||
140 | acpi_table_attr_init(table_attr, table); | |
141 | if (sysfs_create_bin_file(dynamic_tables_kobj, | |
142 | &table_attr->attr)) { | |
143 | kfree(table_attr); | |
144 | return AE_ERROR; | |
145 | } else | |
146 | list_add_tail(&table_attr->node, | |
147 | &acpi_table_attr_list); | |
148 | break; | |
149 | case ACPI_TABLE_EVENT_UNLOAD: | |
150 | /* | |
151 | * we do not need to do anything right now | |
152 | * because the table is not deleted from the | |
153 | * global table list when unloading it. | |
154 | */ | |
155 | break; | |
156 | default: | |
157 | return AE_BAD_PARAMETER; | |
158 | } | |
159 | return AE_OK; | |
160 | } | |
161 | ||
d4c5f047 ZR |
162 | static int acpi_system_sysfs_init(void) |
163 | { | |
164 | struct acpi_table_attr *table_attr; | |
165 | struct acpi_table_header *table_header = NULL; | |
166 | int table_index = 0; | |
167 | int result; | |
168 | ||
a77aa28a GKH |
169 | tables_kobj = kobject_create_and_add("tables", acpi_kobj); |
170 | if (!tables_kobj) | |
4658e4ef ZR |
171 | goto err; |
172 | ||
173 | dynamic_tables_kobj = kobject_create_and_add("dynamic", tables_kobj); | |
174 | if (!dynamic_tables_kobj) | |
175 | goto err_dynamic_tables; | |
d4c5f047 ZR |
176 | |
177 | do { | |
178 | result = acpi_get_table_by_index(table_index, &table_header); | |
179 | if (!result) { | |
180 | table_index++; | |
181 | table_attr = NULL; | |
182 | table_attr = | |
183 | kzalloc(sizeof(struct acpi_table_attr), GFP_KERNEL); | |
184 | if (!table_attr) | |
185 | return -ENOMEM; | |
186 | ||
187 | acpi_table_attr_init(table_attr, table_header); | |
188 | result = | |
a77aa28a | 189 | sysfs_create_bin_file(tables_kobj, |
d4c5f047 ZR |
190 | &table_attr->attr); |
191 | if (result) { | |
192 | kfree(table_attr); | |
193 | return result; | |
194 | } else | |
195 | list_add_tail(&table_attr->node, | |
196 | &acpi_table_attr_list); | |
197 | } | |
198 | } while (!result); | |
a77aa28a | 199 | kobject_uevent(tables_kobj, KOBJ_ADD); |
4658e4ef ZR |
200 | kobject_uevent(dynamic_tables_kobj, KOBJ_ADD); |
201 | result = acpi_install_table_handler(acpi_sysfs_table_handler, NULL); | |
202 | ||
203 | return result == AE_OK ? 0 : -EINVAL; | |
204 | err_dynamic_tables: | |
205 | kobject_put(tables_kobj); | |
206 | err: | |
207 | return -ENOMEM; | |
d4c5f047 ZR |
208 | } |
209 | ||
5229e87d LB |
210 | /* |
211 | * Detailed ACPI IRQ counters in /sys/firmware/acpi/interrupts/ | |
212 | * See Documentation/ABI/testing/sysfs-firmware-acpi | |
213 | */ | |
214 | ||
215 | #define COUNT_GPE 0 | |
216 | #define COUNT_SCI 1 /* acpi_irq_handled */ | |
217 | #define COUNT_ERROR 2 /* other */ | |
218 | #define NUM_COUNTERS_EXTRA 3 | |
219 | ||
71b58cbb ZR |
220 | struct event_counter { |
221 | u32 count; | |
222 | u32 flags; | |
223 | }; | |
224 | ||
225 | static struct event_counter *all_counters; | |
5229e87d LB |
226 | static u32 num_gpes; |
227 | static u32 num_counters; | |
228 | static struct attribute **all_attrs; | |
229 | static u32 acpi_gpe_count; | |
230 | ||
231 | static struct attribute_group interrupt_stats_attr_group = { | |
232 | .name = "interrupts", | |
233 | }; | |
234 | static struct kobj_attribute *counter_attrs; | |
235 | ||
5229e87d LB |
236 | static void delete_gpe_attr_array(void) |
237 | { | |
71b58cbb | 238 | struct event_counter *tmp = all_counters; |
5229e87d LB |
239 | |
240 | all_counters = NULL; | |
241 | kfree(tmp); | |
242 | ||
243 | if (counter_attrs) { | |
244 | int i; | |
245 | ||
246 | for (i = 0; i < num_gpes; i++) | |
247 | kfree(counter_attrs[i].attr.name); | |
248 | ||
249 | kfree(counter_attrs); | |
250 | } | |
251 | kfree(all_attrs); | |
252 | ||
253 | return; | |
254 | } | |
255 | ||
256 | void acpi_os_gpe_count(u32 gpe_number) | |
257 | { | |
258 | acpi_gpe_count++; | |
259 | ||
260 | if (!all_counters) | |
261 | return; | |
262 | ||
263 | if (gpe_number < num_gpes) | |
71b58cbb | 264 | all_counters[gpe_number].count++; |
5229e87d | 265 | else |
71b58cbb ZR |
266 | all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_ERROR]. |
267 | count++; | |
5229e87d LB |
268 | |
269 | return; | |
270 | } | |
271 | ||
272 | void acpi_os_fixed_event_count(u32 event_number) | |
273 | { | |
274 | if (!all_counters) | |
275 | return; | |
276 | ||
277 | if (event_number < ACPI_NUM_FIXED_EVENTS) | |
71b58cbb | 278 | all_counters[num_gpes + event_number].count++; |
5229e87d | 279 | else |
71b58cbb ZR |
280 | all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_ERROR]. |
281 | count++; | |
5229e87d LB |
282 | |
283 | return; | |
284 | } | |
285 | ||
71b58cbb ZR |
286 | static int get_status(u32 index, acpi_event_status *status, acpi_handle *handle) |
287 | { | |
288 | int result = 0; | |
289 | ||
290 | if (index >= num_gpes + ACPI_NUM_FIXED_EVENTS) | |
291 | goto end; | |
292 | ||
293 | if (index < num_gpes) { | |
e97d6bf1 | 294 | result = acpi_get_gpe_device(index, handle); |
71b58cbb ZR |
295 | if (result) { |
296 | ACPI_EXCEPTION((AE_INFO, AE_NOT_FOUND, | |
297 | "Invalid GPE 0x%x\n", index)); | |
298 | goto end; | |
299 | } | |
300 | result = acpi_get_gpe_status(*handle, index, | |
301 | ACPI_NOT_ISR, status); | |
302 | } else if (index < (num_gpes + ACPI_NUM_FIXED_EVENTS)) | |
303 | result = acpi_get_event_status(index - num_gpes, status); | |
304 | ||
71b58cbb ZR |
305 | end: |
306 | return result; | |
307 | } | |
308 | ||
5229e87d LB |
309 | static ssize_t counter_show(struct kobject *kobj, |
310 | struct kobj_attribute *attr, char *buf) | |
311 | { | |
71b58cbb ZR |
312 | int index = attr - counter_attrs; |
313 | int size; | |
314 | acpi_handle handle; | |
315 | acpi_event_status status; | |
316 | int result = 0; | |
317 | ||
318 | all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI].count = | |
5229e87d | 319 | acpi_irq_handled; |
71b58cbb | 320 | all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_GPE].count = |
5229e87d LB |
321 | acpi_gpe_count; |
322 | ||
71b58cbb ZR |
323 | size = sprintf(buf, "%8d", all_counters[index].count); |
324 | ||
325 | /* "gpe_all" or "sci" */ | |
326 | if (index >= num_gpes + ACPI_NUM_FIXED_EVENTS) | |
327 | goto end; | |
328 | ||
329 | result = get_status(index, &status, &handle); | |
330 | if (result) | |
331 | goto end; | |
332 | ||
ed206fac ZR |
333 | if (!(status & ACPI_EVENT_FLAG_HANDLE)) |
334 | size += sprintf(buf + size, " invalid"); | |
71b58cbb | 335 | else if (status & ACPI_EVENT_FLAG_ENABLED) |
ed206fac ZR |
336 | size += sprintf(buf + size, " enabled"); |
337 | else if (status & ACPI_EVENT_FLAG_WAKE_ENABLED) | |
338 | size += sprintf(buf + size, " wake_enabled"); | |
71b58cbb | 339 | else |
ed206fac | 340 | size += sprintf(buf + size, " disabled"); |
71b58cbb ZR |
341 | |
342 | end: | |
343 | size += sprintf(buf + size, "\n"); | |
344 | return result ? result : size; | |
5229e87d LB |
345 | } |
346 | ||
347 | /* | |
348 | * counter_set() sets the specified counter. | |
349 | * setting the total "sci" file to any value clears all counters. | |
71b58cbb | 350 | * enable/disable/clear a gpe/fixed event in user space. |
5229e87d LB |
351 | */ |
352 | static ssize_t counter_set(struct kobject *kobj, | |
353 | struct kobj_attribute *attr, const char *buf, size_t size) | |
354 | { | |
355 | int index = attr - counter_attrs; | |
71b58cbb ZR |
356 | acpi_event_status status; |
357 | acpi_handle handle; | |
358 | int result = 0; | |
5229e87d LB |
359 | |
360 | if (index == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI) { | |
361 | int i; | |
362 | for (i = 0; i < num_counters; ++i) | |
71b58cbb | 363 | all_counters[i].count = 0; |
5229e87d LB |
364 | acpi_gpe_count = 0; |
365 | acpi_irq_handled = 0; | |
71b58cbb ZR |
366 | goto end; |
367 | } | |
368 | ||
369 | /* show the event status for both GPEs and Fixed Events */ | |
370 | result = get_status(index, &status, &handle); | |
371 | if (result) | |
372 | goto end; | |
373 | ||
ed206fac | 374 | if (!(status & ACPI_EVENT_FLAG_HANDLE)) { |
55ac9a01 LM |
375 | printk(KERN_WARNING PREFIX |
376 | "Can not change Invalid GPE/Fixed Event status\n"); | |
71b58cbb ZR |
377 | return -EINVAL; |
378 | } | |
5229e87d | 379 | |
71b58cbb ZR |
380 | if (index < num_gpes) { |
381 | if (!strcmp(buf, "disable\n") && | |
382 | (status & ACPI_EVENT_FLAG_ENABLED)) | |
0b7084ac | 383 | result = acpi_disable_gpe(handle, index); |
71b58cbb ZR |
384 | else if (!strcmp(buf, "enable\n") && |
385 | !(status & ACPI_EVENT_FLAG_ENABLED)) | |
0b7084ac | 386 | result = acpi_enable_gpe(handle, index); |
71b58cbb ZR |
387 | else if (!strcmp(buf, "clear\n") && |
388 | (status & ACPI_EVENT_FLAG_SET)) | |
389 | result = acpi_clear_gpe(handle, index, ACPI_NOT_ISR); | |
390 | else | |
391 | all_counters[index].count = strtoul(buf, NULL, 0); | |
392 | } else if (index < num_gpes + ACPI_NUM_FIXED_EVENTS) { | |
393 | int event = index - num_gpes; | |
394 | if (!strcmp(buf, "disable\n") && | |
395 | (status & ACPI_EVENT_FLAG_ENABLED)) | |
396 | result = acpi_disable_event(event, ACPI_NOT_ISR); | |
397 | else if (!strcmp(buf, "enable\n") && | |
398 | !(status & ACPI_EVENT_FLAG_ENABLED)) | |
399 | result = acpi_enable_event(event, ACPI_NOT_ISR); | |
400 | else if (!strcmp(buf, "clear\n") && | |
401 | (status & ACPI_EVENT_FLAG_SET)) | |
402 | result = acpi_clear_event(event); | |
403 | else | |
404 | all_counters[index].count = strtoul(buf, NULL, 0); | |
5229e87d | 405 | } else |
71b58cbb | 406 | all_counters[index].count = strtoul(buf, NULL, 0); |
5229e87d | 407 | |
71b58cbb ZR |
408 | if (ACPI_FAILURE(result)) |
409 | result = -EINVAL; | |
410 | end: | |
411 | return result ? result : size; | |
5229e87d LB |
412 | } |
413 | ||
414 | void acpi_irq_stats_init(void) | |
415 | { | |
416 | int i; | |
417 | ||
418 | if (all_counters) | |
419 | return; | |
420 | ||
e97d6bf1 | 421 | num_gpes = acpi_current_gpe_count; |
5229e87d LB |
422 | num_counters = num_gpes + ACPI_NUM_FIXED_EVENTS + NUM_COUNTERS_EXTRA; |
423 | ||
424 | all_attrs = kzalloc(sizeof(struct attribute *) * (num_counters + 1), | |
425 | GFP_KERNEL); | |
426 | if (all_attrs == NULL) | |
427 | return; | |
428 | ||
71b58cbb ZR |
429 | all_counters = kzalloc(sizeof(struct event_counter) * (num_counters), |
430 | GFP_KERNEL); | |
5229e87d LB |
431 | if (all_counters == NULL) |
432 | goto fail; | |
433 | ||
434 | counter_attrs = kzalloc(sizeof(struct kobj_attribute) * (num_counters), | |
435 | GFP_KERNEL); | |
436 | if (counter_attrs == NULL) | |
437 | goto fail; | |
438 | ||
439 | for (i = 0; i < num_counters; ++i) { | |
c8dc9de1 | 440 | char buffer[12]; |
5229e87d LB |
441 | char *name; |
442 | ||
443 | if (i < num_gpes) | |
444 | sprintf(buffer, "gpe%02X", i); | |
445 | else if (i == num_gpes + ACPI_EVENT_PMTIMER) | |
446 | sprintf(buffer, "ff_pmtimer"); | |
447 | else if (i == num_gpes + ACPI_EVENT_GLOBAL) | |
448 | sprintf(buffer, "ff_gbl_lock"); | |
449 | else if (i == num_gpes + ACPI_EVENT_POWER_BUTTON) | |
450 | sprintf(buffer, "ff_pwr_btn"); | |
451 | else if (i == num_gpes + ACPI_EVENT_SLEEP_BUTTON) | |
452 | sprintf(buffer, "ff_slp_btn"); | |
453 | else if (i == num_gpes + ACPI_EVENT_RTC) | |
454 | sprintf(buffer, "ff_rt_clk"); | |
455 | else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_GPE) | |
456 | sprintf(buffer, "gpe_all"); | |
457 | else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI) | |
458 | sprintf(buffer, "sci"); | |
459 | else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_ERROR) | |
460 | sprintf(buffer, "error"); | |
461 | else | |
462 | sprintf(buffer, "bug%02X", i); | |
463 | ||
464 | name = kzalloc(strlen(buffer) + 1, GFP_KERNEL); | |
465 | if (name == NULL) | |
466 | goto fail; | |
467 | strncpy(name, buffer, strlen(buffer) + 1); | |
468 | ||
469 | counter_attrs[i].attr.name = name; | |
470 | counter_attrs[i].attr.mode = 0644; | |
471 | counter_attrs[i].show = counter_show; | |
472 | counter_attrs[i].store = counter_set; | |
473 | ||
474 | all_attrs[i] = &counter_attrs[i].attr; | |
475 | } | |
476 | ||
477 | interrupt_stats_attr_group.attrs = all_attrs; | |
b7143156 LB |
478 | if (!sysfs_create_group(acpi_kobj, &interrupt_stats_attr_group)) |
479 | return; | |
5229e87d LB |
480 | |
481 | fail: | |
482 | delete_gpe_attr_array(); | |
483 | return; | |
484 | } | |
485 | ||
486 | static void __exit interrupt_stats_exit(void) | |
487 | { | |
488 | sysfs_remove_group(acpi_kobj, &interrupt_stats_attr_group); | |
489 | ||
490 | delete_gpe_attr_array(); | |
491 | ||
492 | return; | |
493 | } | |
494 | ||
1da177e4 LT |
495 | /* -------------------------------------------------------------------------- |
496 | FS Interface (/proc) | |
497 | -------------------------------------------------------------------------- */ | |
5bb730fd | 498 | #ifdef CONFIG_ACPI_PROCFS |
d4c5f047 ZR |
499 | #define ACPI_SYSTEM_FILE_INFO "info" |
500 | #define ACPI_SYSTEM_FILE_EVENT "event" | |
501 | #define ACPI_SYSTEM_FILE_DSDT "dsdt" | |
502 | #define ACPI_SYSTEM_FILE_FADT "fadt" | |
1da177e4 | 503 | |
4be44fcd | 504 | static int acpi_system_read_info(struct seq_file *seq, void *offset) |
1da177e4 | 505 | { |
1da177e4 LT |
506 | |
507 | seq_printf(seq, "version: %x\n", ACPI_CA_VERSION); | |
d550d98d | 508 | return 0; |
1da177e4 LT |
509 | } |
510 | ||
511 | static int acpi_system_info_open_fs(struct inode *inode, struct file *file) | |
512 | { | |
513 | return single_open(file, acpi_system_read_info, PDE(inode)->data); | |
514 | } | |
515 | ||
d7508032 | 516 | static const struct file_operations acpi_system_info_ops = { |
cf7acfab | 517 | .owner = THIS_MODULE, |
4be44fcd LB |
518 | .open = acpi_system_info_open_fs, |
519 | .read = seq_read, | |
520 | .llseek = seq_lseek, | |
521 | .release = single_release, | |
1da177e4 LT |
522 | }; |
523 | ||
4be44fcd LB |
524 | static ssize_t acpi_system_read_dsdt(struct file *, char __user *, size_t, |
525 | loff_t *); | |
1da177e4 | 526 | |
d7508032 | 527 | static const struct file_operations acpi_system_dsdt_ops = { |
cf7acfab | 528 | .owner = THIS_MODULE, |
4be44fcd | 529 | .read = acpi_system_read_dsdt, |
1da177e4 LT |
530 | }; |
531 | ||
532 | static ssize_t | |
4be44fcd LB |
533 | acpi_system_read_dsdt(struct file *file, |
534 | char __user * buffer, size_t count, loff_t * ppos) | |
1da177e4 | 535 | { |
4be44fcd | 536 | acpi_status status = AE_OK; |
ad71860a | 537 | struct acpi_table_header *dsdt = NULL; |
4be44fcd | 538 | ssize_t res; |
1da177e4 | 539 | |
ad71860a | 540 | status = acpi_get_table(ACPI_SIG_DSDT, 1, &dsdt); |
1da177e4 | 541 | if (ACPI_FAILURE(status)) |
d550d98d | 542 | return -ENODEV; |
1da177e4 | 543 | |
d4c5f047 | 544 | res = simple_read_from_buffer(buffer, count, ppos, dsdt, dsdt->length); |
1da177e4 | 545 | |
d550d98d | 546 | return res; |
1da177e4 LT |
547 | } |
548 | ||
4be44fcd LB |
549 | static ssize_t acpi_system_read_fadt(struct file *, char __user *, size_t, |
550 | loff_t *); | |
1da177e4 | 551 | |
d7508032 | 552 | static const struct file_operations acpi_system_fadt_ops = { |
cf7acfab | 553 | .owner = THIS_MODULE, |
4be44fcd | 554 | .read = acpi_system_read_fadt, |
1da177e4 LT |
555 | }; |
556 | ||
557 | static ssize_t | |
4be44fcd LB |
558 | acpi_system_read_fadt(struct file *file, |
559 | char __user * buffer, size_t count, loff_t * ppos) | |
1da177e4 | 560 | { |
4be44fcd | 561 | acpi_status status = AE_OK; |
ad71860a | 562 | struct acpi_table_header *fadt = NULL; |
4be44fcd | 563 | ssize_t res; |
1da177e4 | 564 | |
ad71860a | 565 | status = acpi_get_table(ACPI_SIG_FADT, 1, &fadt); |
1da177e4 | 566 | if (ACPI_FAILURE(status)) |
d550d98d | 567 | return -ENODEV; |
1da177e4 | 568 | |
d4c5f047 | 569 | res = simple_read_from_buffer(buffer, count, ppos, fadt, fadt->length); |
1da177e4 | 570 | |
d550d98d | 571 | return res; |
1da177e4 LT |
572 | } |
573 | ||
d4c5f047 | 574 | static int acpi_system_procfs_init(void) |
1da177e4 | 575 | { |
4be44fcd | 576 | struct proc_dir_entry *entry; |
1da177e4 | 577 | int error = 0; |
1da177e4 | 578 | |
1da177e4 | 579 | /* 'info' [R] */ |
cf7acfab DL |
580 | entry = proc_create(ACPI_SYSTEM_FILE_INFO, S_IRUGO, acpi_root_dir, |
581 | &acpi_system_info_ops); | |
1da177e4 LT |
582 | if (!entry) |
583 | goto Error; | |
1da177e4 LT |
584 | |
585 | /* 'dsdt' [R] */ | |
cf7acfab DL |
586 | entry = proc_create(ACPI_SYSTEM_FILE_DSDT, S_IRUSR, acpi_root_dir, |
587 | &acpi_system_dsdt_ops); | |
588 | if (!entry) | |
1da177e4 LT |
589 | goto Error; |
590 | ||
591 | /* 'fadt' [R] */ | |
cf7acfab DL |
592 | entry = proc_create(ACPI_SYSTEM_FILE_FADT, S_IRUSR, acpi_root_dir, |
593 | &acpi_system_fadt_ops); | |
594 | if (!entry) | |
1da177e4 LT |
595 | goto Error; |
596 | ||
4be44fcd | 597 | Done: |
d550d98d | 598 | return error; |
1da177e4 | 599 | |
4be44fcd | 600 | Error: |
1da177e4 LT |
601 | remove_proc_entry(ACPI_SYSTEM_FILE_FADT, acpi_root_dir); |
602 | remove_proc_entry(ACPI_SYSTEM_FILE_DSDT, acpi_root_dir); | |
603 | remove_proc_entry(ACPI_SYSTEM_FILE_INFO, acpi_root_dir); | |
604 | ||
605 | error = -EFAULT; | |
606 | goto Done; | |
607 | } | |
d4c5f047 ZR |
608 | #else |
609 | static int acpi_system_procfs_init(void) | |
610 | { | |
611 | return 0; | |
612 | } | |
613 | #endif | |
614 | ||
141a0af3 | 615 | int __init acpi_system_init(void) |
d4c5f047 | 616 | { |
141a0af3 | 617 | int result; |
d4c5f047 ZR |
618 | |
619 | result = acpi_system_procfs_init(); | |
620 | if (result) | |
621 | return result; | |
622 | ||
623 | result = acpi_system_sysfs_init(); | |
624 | ||
625 | return result; | |
626 | } |