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"
44 * Make ACPICA version work as module param
46 static int param_get_acpica_version(char *buffer, struct kernel_param *kp)
50 result = sprintf(buffer, "%x", ACPI_CA_VERSION);
55 module_param_call(acpica_version, NULL, param_get_acpica_version, NULL, 0444);
57 /* --------------------------------------------------------------------------
59 -------------------------------------------------------------------------- */
60 static LIST_HEAD(acpi_table_attr_list);
61 static struct kobject *tables_kobj;
63 struct acpi_table_attr {
64 struct bin_attribute attr;
67 struct list_head node;
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)
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;
78 ssize_t ret_count = count;
81 acpi_get_table(table_attr->name, table_attr->instance,
83 if (ACPI_FAILURE(status))
86 if (offset >= table_header->length) {
91 if (offset + ret_count > table_header->length)
92 ret_count = table_header->length - offset;
94 memcpy(buf, ((char *)table_header) + offset, ret_count);
100 static void acpi_table_attr_init(struct acpi_table_attr *table_attr,
101 struct acpi_table_header *table_header)
103 struct acpi_table_header *header = NULL;
104 struct acpi_table_attr *attr = NULL;
106 memcpy(table_attr->name, table_header->signature, ACPI_NAME_SIZE);
108 list_for_each_entry(attr, &acpi_table_attr_list, node) {
109 if (!memcmp(table_header->signature, attr->name,
111 if (table_attr->instance < attr->instance)
112 table_attr->instance = attr->instance;
114 table_attr->instance++;
116 if (table_attr->instance > 1 || (table_attr->instance == 1 &&
117 !acpi_get_table(table_header->
120 sprintf(table_attr->name + 4, "%d", table_attr->instance);
122 table_attr->attr.size = 0;
123 table_attr->attr.read = acpi_table_show;
124 table_attr->attr.attr.name = table_attr->name;
125 table_attr->attr.attr.mode = 0444;
126 table_attr->attr.attr.owner = THIS_MODULE;
131 static int acpi_system_sysfs_init(void)
133 struct acpi_table_attr *table_attr;
134 struct acpi_table_header *table_header = NULL;
138 tables_kobj = kobject_create_and_add("tables", acpi_kobj);
143 result = acpi_get_table_by_index(table_index, &table_header);
148 kzalloc(sizeof(struct acpi_table_attr), GFP_KERNEL);
152 acpi_table_attr_init(table_attr, table_header);
154 sysfs_create_bin_file(tables_kobj,
160 list_add_tail(&table_attr->node,
161 &acpi_table_attr_list);
164 kobject_uevent(tables_kobj, KOBJ_ADD);
169 /* --------------------------------------------------------------------------
171 -------------------------------------------------------------------------- */
172 #ifdef CONFIG_ACPI_PROCFS
173 #define ACPI_SYSTEM_FILE_INFO "info"
174 #define ACPI_SYSTEM_FILE_EVENT "event"
175 #define ACPI_SYSTEM_FILE_DSDT "dsdt"
176 #define ACPI_SYSTEM_FILE_FADT "fadt"
178 static int acpi_system_read_info(struct seq_file *seq, void *offset)
181 seq_printf(seq, "version: %x\n", ACPI_CA_VERSION);
185 static int acpi_system_info_open_fs(struct inode *inode, struct file *file)
187 return single_open(file, acpi_system_read_info, PDE(inode)->data);
190 static const struct file_operations acpi_system_info_ops = {
191 .open = acpi_system_info_open_fs,
194 .release = single_release,
197 static ssize_t acpi_system_read_dsdt(struct file *, char __user *, size_t,
200 static const struct file_operations acpi_system_dsdt_ops = {
201 .read = acpi_system_read_dsdt,
205 acpi_system_read_dsdt(struct file *file,
206 char __user * buffer, size_t count, loff_t * ppos)
208 acpi_status status = AE_OK;
209 struct acpi_table_header *dsdt = NULL;
212 status = acpi_get_table(ACPI_SIG_DSDT, 1, &dsdt);
213 if (ACPI_FAILURE(status))
216 res = simple_read_from_buffer(buffer, count, ppos, dsdt, dsdt->length);
221 static ssize_t acpi_system_read_fadt(struct file *, char __user *, size_t,
224 static const struct file_operations acpi_system_fadt_ops = {
225 .read = acpi_system_read_fadt,
229 acpi_system_read_fadt(struct file *file,
230 char __user * buffer, size_t count, loff_t * ppos)
232 acpi_status status = AE_OK;
233 struct acpi_table_header *fadt = NULL;
236 status = acpi_get_table(ACPI_SIG_FADT, 1, &fadt);
237 if (ACPI_FAILURE(status))
240 res = simple_read_from_buffer(buffer, count, ppos, fadt, fadt->length);
245 static int acpi_system_procfs_init(void)
247 struct proc_dir_entry *entry;
252 name = ACPI_SYSTEM_FILE_INFO;
253 entry = create_proc_entry(name, S_IRUGO, acpi_root_dir);
257 entry->proc_fops = &acpi_system_info_ops;
261 name = ACPI_SYSTEM_FILE_DSDT;
262 entry = create_proc_entry(name, S_IRUSR, acpi_root_dir);
264 entry->proc_fops = &acpi_system_dsdt_ops;
269 name = ACPI_SYSTEM_FILE_FADT;
270 entry = create_proc_entry(name, S_IRUSR, acpi_root_dir);
272 entry->proc_fops = &acpi_system_fadt_ops;
280 remove_proc_entry(ACPI_SYSTEM_FILE_FADT, acpi_root_dir);
281 remove_proc_entry(ACPI_SYSTEM_FILE_DSDT, acpi_root_dir);
282 remove_proc_entry(ACPI_SYSTEM_FILE_INFO, acpi_root_dir);
288 static int acpi_system_procfs_init(void)
294 static int __init acpi_system_init(void)
301 result = acpi_system_procfs_init();
305 result = acpi_system_sysfs_init();
310 subsys_initcall(acpi_system_init);