blob: da51f05ef8d8038bb0390fe3136d4700d0b7b74f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Akinobu Mitae108526e2008-07-23 21:26:44 -070029#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <asm/uaccess.h>
31
32#include <acpi/acpi_drivers.h>
33
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#define _COMPONENT ACPI_SYSTEM_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050035ACPI_MODULE_NAME("system");
Zhang Rui5bb730f2007-01-29 11:02:42 +080036
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#define ACPI_SYSTEM_CLASS "system"
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#define ACPI_SYSTEM_DEVICE_NAME "System"
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Len Brown5229e872008-02-06 01:26:55 -050040u32 acpi_irq_handled;
41
Zhang Rui5bb730f2007-01-29 11:02:42 +080042/*
43 * Make ACPICA version work as module param
44 */
Zhang Ruid4c5f042007-06-14 17:43:07 +080045static int param_get_acpica_version(char *buffer, struct kernel_param *kp)
46{
Zhang Rui5bb730f2007-01-29 11:02:42 +080047 int result;
48
49 result = sprintf(buffer, "%x", ACPI_CA_VERSION);
50
51 return result;
52}
53
54module_param_call(acpica_version, NULL, param_get_acpica_version, NULL, 0444);
55
Linus Torvalds1da177e2005-04-16 15:20:36 -070056/* --------------------------------------------------------------------------
Zhang Ruid4c5f042007-06-14 17:43:07 +080057 FS Interface (/sys)
58 -------------------------------------------------------------------------- */
59static LIST_HEAD(acpi_table_attr_list);
Greg Kroah-Hartmana77aa282007-12-17 15:54:39 -040060static struct kobject *tables_kobj;
Zhang Rui4658e4e2009-02-26 11:27:23 +080061static struct kobject *dynamic_tables_kobj;
Zhang Ruid4c5f042007-06-14 17:43:07 +080062
63struct acpi_table_attr {
64 struct bin_attribute attr;
65 char name[8];
66 int instance;
67 struct list_head node;
68};
69
70static 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;
Peter Gruber4feba702008-10-27 23:59:36 -040078 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);
Zhang Ruid4c5f042007-06-14 17:43:07 +080084
85 status =
Peter Gruber4feba702008-10-27 23:59:36 -040086 acpi_get_table(name, table_attr->instance,
Zhang Ruid4c5f042007-06-14 17:43:07 +080087 &table_header);
88 if (ACPI_FAILURE(status))
89 return -ENODEV;
90
Akinobu Mita46a21e42008-06-09 16:22:26 -070091 return memory_read_from_buffer(buf, count, &offset,
92 table_header, table_header->length);
Zhang Ruid4c5f042007-06-14 17:43:07 +080093}
94
95static 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
Peter Gruber4feba702008-10-27 23:59:36 -0400101 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);
Zhang Ruid4c5f042007-06-14 17:43:07 +0800106
107 list_for_each_entry(attr, &acpi_table_attr_list, node) {
Peter Gruber4feba702008-10-27 23:59:36 -0400108 if (!memcmp(table_attr->name, attr->name, ACPI_NAME_SIZE))
Zhang Ruid4c5f042007-06-14 17:43:07 +0800109 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 &&
Peter Gruber4feba702008-10-27 23:59:36 -0400115 !acpi_get_table
116 (table_header->signature, 2, &header)))
117 sprintf(table_attr->name + ACPI_NAME_SIZE, "%d",
118 table_attr->instance);
Zhang Ruid4c5f042007-06-14 17:43:07 +0800119
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;
Zhang Ruid4c5f042007-06-14 17:43:07 +0800124
125 return;
126}
127
Zhang Rui4658e4e2009-02-26 11:27:23 +0800128static acpi_status
129acpi_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
Zhang Ruid4c5f042007-06-14 17:43:07 +0800162static 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
Greg Kroah-Hartmana77aa282007-12-17 15:54:39 -0400169 tables_kobj = kobject_create_and_add("tables", acpi_kobj);
170 if (!tables_kobj)
Zhang Rui4658e4e2009-02-26 11:27:23 +0800171 goto err;
172
173 dynamic_tables_kobj = kobject_create_and_add("dynamic", tables_kobj);
174 if (!dynamic_tables_kobj)
175 goto err_dynamic_tables;
Zhang Ruid4c5f042007-06-14 17:43:07 +0800176
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 =
Greg Kroah-Hartmana77aa282007-12-17 15:54:39 -0400189 sysfs_create_bin_file(tables_kobj,
Zhang Ruid4c5f042007-06-14 17:43:07 +0800190 &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);
Greg Kroah-Hartmana77aa282007-12-17 15:54:39 -0400199 kobject_uevent(tables_kobj, KOBJ_ADD);
Zhang Rui4658e4e2009-02-26 11:27:23 +0800200 kobject_uevent(dynamic_tables_kobj, KOBJ_ADD);
201 result = acpi_install_table_handler(acpi_sysfs_table_handler, NULL);
Zhang Ruid4c5f042007-06-14 17:43:07 +0800202
Zhang Rui4658e4e2009-02-26 11:27:23 +0800203 return result == AE_OK ? 0 : -EINVAL;
204err_dynamic_tables:
205 kobject_put(tables_kobj);
206err:
207 return -ENOMEM;
Zhang Ruid4c5f042007-06-14 17:43:07 +0800208}
209
Len Brown5229e872008-02-06 01:26:55 -0500210/*
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
Zhang Rui71b58cb2008-06-20 09:42:47 +0800220struct event_counter {
221 u32 count;
222 u32 flags;
223};
224
225static struct event_counter *all_counters;
Len Brown5229e872008-02-06 01:26:55 -0500226static u32 num_gpes;
227static u32 num_counters;
228static struct attribute **all_attrs;
229static u32 acpi_gpe_count;
230
231static struct attribute_group interrupt_stats_attr_group = {
232 .name = "interrupts",
233};
234static struct kobj_attribute *counter_attrs;
235
Len Brown5229e872008-02-06 01:26:55 -0500236static void delete_gpe_attr_array(void)
237{
Zhang Rui71b58cb2008-06-20 09:42:47 +0800238 struct event_counter *tmp = all_counters;
Len Brown5229e872008-02-06 01:26:55 -0500239
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
256void 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)
Zhang Rui71b58cb2008-06-20 09:42:47 +0800264 all_counters[gpe_number].count++;
Len Brown5229e872008-02-06 01:26:55 -0500265 else
Zhang Rui71b58cb2008-06-20 09:42:47 +0800266 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_ERROR].
267 count++;
Len Brown5229e872008-02-06 01:26:55 -0500268
269 return;
270}
271
272void acpi_os_fixed_event_count(u32 event_number)
273{
274 if (!all_counters)
275 return;
276
277 if (event_number < ACPI_NUM_FIXED_EVENTS)
Zhang Rui71b58cb2008-06-20 09:42:47 +0800278 all_counters[num_gpes + event_number].count++;
Len Brown5229e872008-02-06 01:26:55 -0500279 else
Zhang Rui71b58cb2008-06-20 09:42:47 +0800280 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_ERROR].
281 count++;
Len Brown5229e872008-02-06 01:26:55 -0500282
283 return;
284}
285
Zhang Rui71b58cb2008-06-20 09:42:47 +0800286static 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) {
Bob Mooree97d6bf2008-12-30 09:45:17 +0800294 result = acpi_get_gpe_device(index, handle);
Zhang Rui71b58cb2008-06-20 09:42:47 +0800295 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
Zhang Rui71b58cb2008-06-20 09:42:47 +0800305end:
306 return result;
307}
308
Len Brown5229e872008-02-06 01:26:55 -0500309static ssize_t counter_show(struct kobject *kobj,
310 struct kobj_attribute *attr, char *buf)
311{
Zhang Rui71b58cb2008-06-20 09:42:47 +0800312 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 =
Len Brown5229e872008-02-06 01:26:55 -0500319 acpi_irq_handled;
Zhang Rui71b58cb2008-06-20 09:42:47 +0800320 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_GPE].count =
Len Brown5229e872008-02-06 01:26:55 -0500321 acpi_gpe_count;
322
Zhang Rui71b58cb2008-06-20 09:42:47 +0800323 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
Zhang Ruied206fa2008-10-27 14:01:02 -0700333 if (!(status & ACPI_EVENT_FLAG_HANDLE))
334 size += sprintf(buf + size, " invalid");
Zhang Rui71b58cb2008-06-20 09:42:47 +0800335 else if (status & ACPI_EVENT_FLAG_ENABLED)
Zhang Ruied206fa2008-10-27 14:01:02 -0700336 size += sprintf(buf + size, " enabled");
337 else if (status & ACPI_EVENT_FLAG_WAKE_ENABLED)
338 size += sprintf(buf + size, " wake_enabled");
Zhang Rui71b58cb2008-06-20 09:42:47 +0800339 else
Zhang Ruied206fa2008-10-27 14:01:02 -0700340 size += sprintf(buf + size, " disabled");
Zhang Rui71b58cb2008-06-20 09:42:47 +0800341
342end:
343 size += sprintf(buf + size, "\n");
344 return result ? result : size;
Len Brown5229e872008-02-06 01:26:55 -0500345}
346
347/*
348 * counter_set() sets the specified counter.
349 * setting the total "sci" file to any value clears all counters.
Zhang Rui71b58cb2008-06-20 09:42:47 +0800350 * enable/disable/clear a gpe/fixed event in user space.
Len Brown5229e872008-02-06 01:26:55 -0500351 */
352static 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;
Zhang Rui71b58cb2008-06-20 09:42:47 +0800356 acpi_event_status status;
357 acpi_handle handle;
358 int result = 0;
Len Brown5229e872008-02-06 01:26:55 -0500359
360 if (index == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI) {
361 int i;
362 for (i = 0; i < num_counters; ++i)
Zhang Rui71b58cb2008-06-20 09:42:47 +0800363 all_counters[i].count = 0;
Len Brown5229e872008-02-06 01:26:55 -0500364 acpi_gpe_count = 0;
365 acpi_irq_handled = 0;
Zhang Rui71b58cb2008-06-20 09:42:47 +0800366 goto end;
367 }
Len Brown5229e872008-02-06 01:26:55 -0500368
Zhang Rui71b58cb2008-06-20 09:42:47 +0800369 /* show the event status for both GPEs and Fixed Events */
370 result = get_status(index, &status, &handle);
371 if (result)
372 goto end;
373
Zhang Ruied206fa2008-10-27 14:01:02 -0700374 if (!(status & ACPI_EVENT_FLAG_HANDLE)) {
Lin Ming55ac9a02008-09-28 14:51:56 +0800375 printk(KERN_WARNING PREFIX
376 "Can not change Invalid GPE/Fixed Event status\n");
Zhang Rui71b58cb2008-06-20 09:42:47 +0800377 return -EINVAL;
378 }
379
380 if (index < num_gpes) {
381 if (!strcmp(buf, "disable\n") &&
382 (status & ACPI_EVENT_FLAG_ENABLED))
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400383 result = acpi_disable_gpe(handle, index);
Zhang Rui71b58cb2008-06-20 09:42:47 +0800384 else if (!strcmp(buf, "enable\n") &&
385 !(status & ACPI_EVENT_FLAG_ENABLED))
Alexey Starikovskiy0b7084a2008-10-25 21:48:46 +0400386 result = acpi_enable_gpe(handle, index);
Zhang Rui71b58cb2008-06-20 09:42:47 +0800387 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);
Len Brown5229e872008-02-06 01:26:55 -0500405 } else
Zhang Rui71b58cb2008-06-20 09:42:47 +0800406 all_counters[index].count = strtoul(buf, NULL, 0);
Len Brown5229e872008-02-06 01:26:55 -0500407
Zhang Rui71b58cb2008-06-20 09:42:47 +0800408 if (ACPI_FAILURE(result))
409 result = -EINVAL;
410end:
411 return result ? result : size;
Len Brown5229e872008-02-06 01:26:55 -0500412}
413
414void acpi_irq_stats_init(void)
415{
416 int i;
417
418 if (all_counters)
419 return;
420
Bob Mooree97d6bf2008-12-30 09:45:17 +0800421 num_gpes = acpi_current_gpe_count;
Len Brown5229e872008-02-06 01:26:55 -0500422 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
Zhang Rui71b58cb2008-06-20 09:42:47 +0800429 all_counters = kzalloc(sizeof(struct event_counter) * (num_counters),
430 GFP_KERNEL);
Len Brown5229e872008-02-06 01:26:55 -0500431 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) {
Johann Felix Sodenc8dc9de2008-03-11 16:44:26 +0100440 char buffer[12];
Len Brown5229e872008-02-06 01:26:55 -0500441 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;
Len Brownb7143152008-02-07 04:24:01 -0500478 if (!sysfs_create_group(acpi_kobj, &interrupt_stats_attr_group))
479 return;
Len Brown5229e872008-02-06 01:26:55 -0500480
481fail:
482 delete_gpe_attr_array();
483 return;
484}
485
486static 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
Zhang Ruid4c5f042007-06-14 17:43:07 +0800495/* --------------------------------------------------------------------------
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 FS Interface (/proc)
497 -------------------------------------------------------------------------- */
Zhang Rui5bb730f2007-01-29 11:02:42 +0800498#ifdef CONFIG_ACPI_PROCFS
Zhang Ruid4c5f042007-06-14 17:43:07 +0800499#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"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
Len Brown4be44fc2005-08-05 00:44:28 -0400504static int acpi_system_read_info(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
507 seq_printf(seq, "version: %x\n", ACPI_CA_VERSION);
Patrick Mocheld550d982006-06-27 00:41:40 -0400508 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509}
510
511static 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
Arjan van de Vend7508032006-07-04 13:06:00 -0400516static const struct file_operations acpi_system_info_ops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700517 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400518 .open = acpi_system_info_open_fs,
519 .read = seq_read,
520 .llseek = seq_lseek,
521 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522};
523
Len Brown4be44fc2005-08-05 00:44:28 -0400524static ssize_t acpi_system_read_dsdt(struct file *, char __user *, size_t,
525 loff_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
Arjan van de Vend7508032006-07-04 13:06:00 -0400527static const struct file_operations acpi_system_dsdt_ops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700528 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400529 .read = acpi_system_read_dsdt,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530};
531
532static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400533acpi_system_read_dsdt(struct file *file,
534 char __user * buffer, size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535{
Len Brown4be44fc2005-08-05 00:44:28 -0400536 acpi_status status = AE_OK;
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300537 struct acpi_table_header *dsdt = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400538 ssize_t res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300540 status = acpi_get_table(ACPI_SIG_DSDT, 1, &dsdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400542 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
Zhang Ruid4c5f042007-06-14 17:43:07 +0800544 res = simple_read_from_buffer(buffer, count, ppos, dsdt, dsdt->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
Patrick Mocheld550d982006-06-27 00:41:40 -0400546 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547}
548
Len Brown4be44fc2005-08-05 00:44:28 -0400549static ssize_t acpi_system_read_fadt(struct file *, char __user *, size_t,
550 loff_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
Arjan van de Vend7508032006-07-04 13:06:00 -0400552static const struct file_operations acpi_system_fadt_ops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700553 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400554 .read = acpi_system_read_fadt,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555};
556
557static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400558acpi_system_read_fadt(struct file *file,
559 char __user * buffer, size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560{
Len Brown4be44fc2005-08-05 00:44:28 -0400561 acpi_status status = AE_OK;
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300562 struct acpi_table_header *fadt = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400563 ssize_t res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300565 status = acpi_get_table(ACPI_SIG_FADT, 1, &fadt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400567 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
Zhang Ruid4c5f042007-06-14 17:43:07 +0800569 res = simple_read_from_buffer(buffer, count, ppos, fadt, fadt->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
Patrick Mocheld550d982006-06-27 00:41:40 -0400571 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572}
573
Zhang Ruid4c5f042007-06-14 17:43:07 +0800574static int acpi_system_procfs_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575{
Len Brown4be44fc2005-08-05 00:44:28 -0400576 struct proc_dir_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 int error = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 /* 'info' [R] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700580 entry = proc_create(ACPI_SYSTEM_FILE_INFO, S_IRUGO, acpi_root_dir,
581 &acpi_system_info_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 if (!entry)
583 goto Error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
585 /* 'dsdt' [R] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700586 entry = proc_create(ACPI_SYSTEM_FILE_DSDT, S_IRUSR, acpi_root_dir,
587 &acpi_system_dsdt_ops);
588 if (!entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 goto Error;
590
591 /* 'fadt' [R] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700592 entry = proc_create(ACPI_SYSTEM_FILE_FADT, S_IRUSR, acpi_root_dir,
593 &acpi_system_fadt_ops);
594 if (!entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 goto Error;
596
Len Brown4be44fc2005-08-05 00:44:28 -0400597 Done:
Patrick Mocheld550d982006-06-27 00:41:40 -0400598 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
Len Brown4be44fc2005-08-05 00:44:28 -0400600 Error:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 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}
Zhang Ruid4c5f042007-06-14 17:43:07 +0800608#else
609static int acpi_system_procfs_init(void)
610{
611 return 0;
612}
613#endif
614
Bjorn Helgaas141a0af2009-03-24 16:49:58 -0600615int __init acpi_system_init(void)
Zhang Ruid4c5f042007-06-14 17:43:07 +0800616{
Bjorn Helgaas141a0af2009-03-24 16:49:58 -0600617 int result;
Zhang Ruid4c5f042007-06-14 17:43:07 +0800618
619 result = acpi_system_procfs_init();
620 if (result)
621 return result;
622
623 result = acpi_system_sysfs_init();
624
625 return result;
626}