2 * acpi_system.c - ACPI System Driver ($Revision: 63 $)
4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
5 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
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.
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.
23 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
26 #include <linux/proc_fs.h>
27 #include <linux/seq_file.h>
28 #include <linux/init.h>
29 #include <asm/uaccess.h>
31 #include <acpi/acpi_drivers.h>
33 #define _COMPONENT ACPI_SYSTEM_COMPONENT
34 ACPI_MODULE_NAME("system");
35 #ifdef MODULE_PARAM_PREFIX
36 #undef MODULE_PARAM_PREFIX
38 #define MODULE_PARAM_PREFIX "acpi."
40 #define ACPI_SYSTEM_CLASS "system"
41 #define ACPI_SYSTEM_DEVICE_NAME "System"
46 * Make ACPICA version work as module param
48 static int param_get_acpica_version(char *buffer, struct kernel_param *kp)
52 result = sprintf(buffer, "%x", ACPI_CA_VERSION);
57 module_param_call(acpica_version, NULL, param_get_acpica_version, NULL, 0444);
59 /* --------------------------------------------------------------------------
61 -------------------------------------------------------------------------- */
62 static LIST_HEAD(acpi_table_attr_list);
63 static struct kobject *tables_kobj;
65 struct acpi_table_attr {
66 struct bin_attribute attr;
69 struct list_head node;
72 static ssize_t acpi_table_show(struct kobject *kobj,
73 struct bin_attribute *bin_attr, char *buf,
74 loff_t offset, size_t count)
76 struct acpi_table_attr *table_attr =
77 container_of(bin_attr, struct acpi_table_attr, attr);
78 struct acpi_table_header *table_header = NULL;
80 ssize_t ret_count = count;
83 acpi_get_table(table_attr->name, table_attr->instance,
85 if (ACPI_FAILURE(status))
88 if (offset >= table_header->length) {
93 if (offset + ret_count > table_header->length)
94 ret_count = table_header->length - offset;
96 memcpy(buf, ((char *)table_header) + offset, ret_count);
102 static void acpi_table_attr_init(struct acpi_table_attr *table_attr,
103 struct acpi_table_header *table_header)
105 struct acpi_table_header *header = NULL;
106 struct acpi_table_attr *attr = NULL;
108 memcpy(table_attr->name, table_header->signature, ACPI_NAME_SIZE);
110 list_for_each_entry(attr, &acpi_table_attr_list, node) {
111 if (!memcmp(table_header->signature, attr->name,
113 if (table_attr->instance < attr->instance)
114 table_attr->instance = attr->instance;
116 table_attr->instance++;
118 if (table_attr->instance > 1 || (table_attr->instance == 1 &&
119 !acpi_get_table(table_header->
122 sprintf(table_attr->name + 4, "%d", table_attr->instance);
124 table_attr->attr.size = 0;
125 table_attr->attr.read = acpi_table_show;
126 table_attr->attr.attr.name = table_attr->name;
127 table_attr->attr.attr.mode = 0444;
128 table_attr->attr.attr.owner = THIS_MODULE;
133 static int acpi_system_sysfs_init(void)
135 struct acpi_table_attr *table_attr;
136 struct acpi_table_header *table_header = NULL;
140 tables_kobj = kobject_create_and_add("tables", acpi_kobj);
145 result = acpi_get_table_by_index(table_index, &table_header);
150 kzalloc(sizeof(struct acpi_table_attr), GFP_KERNEL);
154 acpi_table_attr_init(table_attr, table_header);
156 sysfs_create_bin_file(tables_kobj,
162 list_add_tail(&table_attr->node,
163 &acpi_table_attr_list);
166 kobject_uevent(tables_kobj, KOBJ_ADD);
172 * Detailed ACPI IRQ counters in /sys/firmware/acpi/interrupts/
173 * See Documentation/ABI/testing/sysfs-firmware-acpi
177 #define COUNT_SCI 1 /* acpi_irq_handled */
178 #define COUNT_ERROR 2 /* other */
179 #define NUM_COUNTERS_EXTRA 3
181 static u32 *all_counters;
183 static u32 num_counters;
184 static struct attribute **all_attrs;
185 static u32 acpi_gpe_count;
187 static struct attribute_group interrupt_stats_attr_group = {
188 .name = "interrupts",
190 static struct kobj_attribute *counter_attrs;
192 static int count_num_gpes(void)
195 struct acpi_gpe_xrupt_info *gpe_xrupt_info;
196 struct acpi_gpe_block_info *gpe_block;
197 acpi_cpu_flags flags;
199 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
201 gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head;
202 while (gpe_xrupt_info) {
203 gpe_block = gpe_xrupt_info->gpe_block_list_head;
205 count += gpe_block->register_count *
206 ACPI_GPE_REGISTER_WIDTH;
207 gpe_block = gpe_block->next;
209 gpe_xrupt_info = gpe_xrupt_info->next;
211 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
216 static void delete_gpe_attr_array(void)
218 u32 *tmp = all_counters;
226 for (i = 0; i < num_gpes; i++)
227 kfree(counter_attrs[i].attr.name);
229 kfree(counter_attrs);
236 void acpi_os_gpe_count(u32 gpe_number)
243 if (gpe_number < num_gpes)
244 all_counters[gpe_number]++;
246 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_ERROR]++;
251 void acpi_os_fixed_event_count(u32 event_number)
256 if (event_number < ACPI_NUM_FIXED_EVENTS)
257 all_counters[num_gpes + event_number]++;
259 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_ERROR]++;
264 static ssize_t counter_show(struct kobject *kobj,
265 struct kobj_attribute *attr, char *buf)
267 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI] =
269 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_GPE] =
272 return sprintf(buf, "%d\n", all_counters[attr - counter_attrs]);
276 * counter_set() sets the specified counter.
277 * setting the total "sci" file to any value clears all counters.
279 static ssize_t counter_set(struct kobject *kobj,
280 struct kobj_attribute *attr, const char *buf, size_t size)
282 int index = attr - counter_attrs;
284 if (index == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI) {
286 for (i = 0; i < num_counters; ++i)
289 acpi_irq_handled = 0;
292 all_counters[index] = strtoul(buf, NULL, 0);
297 void acpi_irq_stats_init(void)
304 num_gpes = count_num_gpes();
305 num_counters = num_gpes + ACPI_NUM_FIXED_EVENTS + NUM_COUNTERS_EXTRA;
307 all_attrs = kzalloc(sizeof(struct attribute *) * (num_counters + 1),
309 if (all_attrs == NULL)
312 all_counters = kzalloc(sizeof(u32) * (num_counters), GFP_KERNEL);
313 if (all_counters == NULL)
316 counter_attrs = kzalloc(sizeof(struct kobj_attribute) * (num_counters),
318 if (counter_attrs == NULL)
321 for (i = 0; i < num_counters; ++i) {
326 sprintf(buffer, "gpe%02X", i);
327 else if (i == num_gpes + ACPI_EVENT_PMTIMER)
328 sprintf(buffer, "ff_pmtimer");
329 else if (i == num_gpes + ACPI_EVENT_GLOBAL)
330 sprintf(buffer, "ff_gbl_lock");
331 else if (i == num_gpes + ACPI_EVENT_POWER_BUTTON)
332 sprintf(buffer, "ff_pwr_btn");
333 else if (i == num_gpes + ACPI_EVENT_SLEEP_BUTTON)
334 sprintf(buffer, "ff_slp_btn");
335 else if (i == num_gpes + ACPI_EVENT_RTC)
336 sprintf(buffer, "ff_rt_clk");
337 else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_GPE)
338 sprintf(buffer, "gpe_all");
339 else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI)
340 sprintf(buffer, "sci");
341 else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_ERROR)
342 sprintf(buffer, "error");
344 sprintf(buffer, "bug%02X", i);
346 name = kzalloc(strlen(buffer) + 1, GFP_KERNEL);
349 strncpy(name, buffer, strlen(buffer) + 1);
351 counter_attrs[i].attr.name = name;
352 counter_attrs[i].attr.mode = 0644;
353 counter_attrs[i].show = counter_show;
354 counter_attrs[i].store = counter_set;
356 all_attrs[i] = &counter_attrs[i].attr;
359 interrupt_stats_attr_group.attrs = all_attrs;
360 if (!sysfs_create_group(acpi_kobj, &interrupt_stats_attr_group))
364 delete_gpe_attr_array();
368 static void __exit interrupt_stats_exit(void)
370 sysfs_remove_group(acpi_kobj, &interrupt_stats_attr_group);
372 delete_gpe_attr_array();
377 /* --------------------------------------------------------------------------
379 -------------------------------------------------------------------------- */
380 #ifdef CONFIG_ACPI_PROCFS
381 #define ACPI_SYSTEM_FILE_INFO "info"
382 #define ACPI_SYSTEM_FILE_EVENT "event"
383 #define ACPI_SYSTEM_FILE_DSDT "dsdt"
384 #define ACPI_SYSTEM_FILE_FADT "fadt"
386 static int acpi_system_read_info(struct seq_file *seq, void *offset)
389 seq_printf(seq, "version: %x\n", ACPI_CA_VERSION);
393 static int acpi_system_info_open_fs(struct inode *inode, struct file *file)
395 return single_open(file, acpi_system_read_info, PDE(inode)->data);
398 static const struct file_operations acpi_system_info_ops = {
399 .owner = THIS_MODULE,
400 .open = acpi_system_info_open_fs,
403 .release = single_release,
406 static ssize_t acpi_system_read_dsdt(struct file *, char __user *, size_t,
409 static const struct file_operations acpi_system_dsdt_ops = {
410 .owner = THIS_MODULE,
411 .read = acpi_system_read_dsdt,
415 acpi_system_read_dsdt(struct file *file,
416 char __user * buffer, size_t count, loff_t * ppos)
418 acpi_status status = AE_OK;
419 struct acpi_table_header *dsdt = NULL;
422 status = acpi_get_table(ACPI_SIG_DSDT, 1, &dsdt);
423 if (ACPI_FAILURE(status))
426 res = simple_read_from_buffer(buffer, count, ppos, dsdt, dsdt->length);
431 static ssize_t acpi_system_read_fadt(struct file *, char __user *, size_t,
434 static const struct file_operations acpi_system_fadt_ops = {
435 .owner = THIS_MODULE,
436 .read = acpi_system_read_fadt,
440 acpi_system_read_fadt(struct file *file,
441 char __user * buffer, size_t count, loff_t * ppos)
443 acpi_status status = AE_OK;
444 struct acpi_table_header *fadt = NULL;
447 status = acpi_get_table(ACPI_SIG_FADT, 1, &fadt);
448 if (ACPI_FAILURE(status))
451 res = simple_read_from_buffer(buffer, count, ppos, fadt, fadt->length);
456 static int acpi_system_procfs_init(void)
458 struct proc_dir_entry *entry;
462 entry = proc_create(ACPI_SYSTEM_FILE_INFO, S_IRUGO, acpi_root_dir,
463 &acpi_system_info_ops);
468 entry = proc_create(ACPI_SYSTEM_FILE_DSDT, S_IRUSR, acpi_root_dir,
469 &acpi_system_dsdt_ops);
474 entry = proc_create(ACPI_SYSTEM_FILE_FADT, S_IRUSR, acpi_root_dir,
475 &acpi_system_fadt_ops);
483 remove_proc_entry(ACPI_SYSTEM_FILE_FADT, acpi_root_dir);
484 remove_proc_entry(ACPI_SYSTEM_FILE_DSDT, acpi_root_dir);
485 remove_proc_entry(ACPI_SYSTEM_FILE_INFO, acpi_root_dir);
491 static int acpi_system_procfs_init(void)
497 static int __init acpi_system_init(void)
504 result = acpi_system_procfs_init();
508 result = acpi_system_sysfs_init();
513 subsys_initcall(acpi_system_init);