blob: 407b0e0281dbcace9fe9b5177efde67e21e454b7 [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>
29#include <asm/uaccess.h>
30
31#include <acpi/acpi_drivers.h>
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#define _COMPONENT ACPI_SYSTEM_COMPONENT
Len Brown4be44fc2005-08-05 00:44:28 -040034ACPI_MODULE_NAME("acpi_system")
Zhang Rui5bb730f2007-01-29 11:02:42 +080035#ifdef MODULE_PARAM_PREFIX
36#undef MODULE_PARAM_PREFIX
37#endif
38#define MODULE_PARAM_PREFIX "acpi."
39
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#define ACPI_SYSTEM_CLASS "system"
41#define ACPI_SYSTEM_DRIVER_NAME "ACPI System Driver"
42#define ACPI_SYSTEM_DEVICE_NAME "System"
43#define ACPI_SYSTEM_FILE_INFO "info"
44#define ACPI_SYSTEM_FILE_EVENT "event"
45#define ACPI_SYSTEM_FILE_DSDT "dsdt"
46#define ACPI_SYSTEM_FILE_FADT "fadt"
Bob Moore793c2382006-03-31 00:00:00 -050047extern struct fadt_descriptor acpi_fadt;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Zhang Rui5bb730f2007-01-29 11:02:42 +080049/*
50 * Make ACPICA version work as module param
51 */
52static int param_get_acpica_version(char *buffer, struct kernel_param *kp) {
53 int result;
54
55 result = sprintf(buffer, "%x", ACPI_CA_VERSION);
56
57 return result;
58}
59
60module_param_call(acpica_version, NULL, param_get_acpica_version, NULL, 0444);
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062/* --------------------------------------------------------------------------
63 FS Interface (/proc)
64 -------------------------------------------------------------------------- */
Zhang Rui5bb730f2007-01-29 11:02:42 +080065#ifdef CONFIG_ACPI_PROCFS
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Len Brown4be44fc2005-08-05 00:44:28 -040067static int acpi_system_read_info(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70 seq_printf(seq, "version: %x\n", ACPI_CA_VERSION);
Patrick Mocheld550d982006-06-27 00:41:40 -040071 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072}
73
74static int acpi_system_info_open_fs(struct inode *inode, struct file *file)
75{
76 return single_open(file, acpi_system_read_info, PDE(inode)->data);
77}
78
Arjan van de Vend7508032006-07-04 13:06:00 -040079static const struct file_operations acpi_system_info_ops = {
Len Brown4be44fc2005-08-05 00:44:28 -040080 .open = acpi_system_info_open_fs,
81 .read = seq_read,
82 .llseek = seq_lseek,
83 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -070084};
Zhang Rui5bb730f2007-01-29 11:02:42 +080085#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Len Brown4be44fc2005-08-05 00:44:28 -040087static ssize_t acpi_system_read_dsdt(struct file *, char __user *, size_t,
88 loff_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Arjan van de Vend7508032006-07-04 13:06:00 -040090static const struct file_operations acpi_system_dsdt_ops = {
Len Brown4be44fc2005-08-05 00:44:28 -040091 .read = acpi_system_read_dsdt,
Linus Torvalds1da177e2005-04-16 15:20:36 -070092};
93
94static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -040095acpi_system_read_dsdt(struct file *file,
96 char __user * buffer, size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097{
Len Brown4be44fc2005-08-05 00:44:28 -040098 acpi_status status = AE_OK;
99 struct acpi_buffer dsdt = { ACPI_ALLOCATE_BUFFER, NULL };
100 ssize_t res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
Bob Mooreb229cf92006-04-21 17:15:00 -0400103 status = acpi_get_table(ACPI_TABLE_ID_DSDT, 1, &dsdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400105 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
107 res = simple_read_from_buffer(buffer, count, ppos,
108 dsdt.pointer, dsdt.length);
Len Brown02438d82006-06-30 03:19:10 -0400109 kfree(dsdt.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Patrick Mocheld550d982006-06-27 00:41:40 -0400111 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112}
113
Len Brown4be44fc2005-08-05 00:44:28 -0400114static ssize_t acpi_system_read_fadt(struct file *, char __user *, size_t,
115 loff_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Arjan van de Vend7508032006-07-04 13:06:00 -0400117static const struct file_operations acpi_system_fadt_ops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400118 .read = acpi_system_read_fadt,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119};
120
121static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400122acpi_system_read_fadt(struct file *file,
123 char __user * buffer, size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
Len Brown4be44fc2005-08-05 00:44:28 -0400125 acpi_status status = AE_OK;
126 struct acpi_buffer fadt = { ACPI_ALLOCATE_BUFFER, NULL };
127 ssize_t res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Bob Mooreb229cf92006-04-21 17:15:00 -0400130 status = acpi_get_table(ACPI_TABLE_ID_FADT, 1, &fadt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400132 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134 res = simple_read_from_buffer(buffer, count, ppos,
135 fadt.pointer, fadt.length);
Len Brown02438d82006-06-30 03:19:10 -0400136 kfree(fadt.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
Patrick Mocheld550d982006-06-27 00:41:40 -0400138 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139}
140
Len Brown4be44fc2005-08-05 00:44:28 -0400141static int __init acpi_system_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142{
Len Brown4be44fc2005-08-05 00:44:28 -0400143 struct proc_dir_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 int error = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400145 char *name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148 if (acpi_disabled)
Patrick Mocheld550d982006-06-27 00:41:40 -0400149 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
Zhang Rui5bb730f2007-01-29 11:02:42 +0800151#ifdef CONFIG_ACPI_PROCFS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 /* 'info' [R] */
153 name = ACPI_SYSTEM_FILE_INFO;
Len Brown4be44fc2005-08-05 00:44:28 -0400154 entry = create_proc_entry(name, S_IRUGO, acpi_root_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 if (!entry)
156 goto Error;
157 else {
158 entry->proc_fops = &acpi_system_info_ops;
159 }
Zhang Rui5bb730f2007-01-29 11:02:42 +0800160#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
162 /* 'dsdt' [R] */
163 name = ACPI_SYSTEM_FILE_DSDT;
164 entry = create_proc_entry(name, S_IRUSR, acpi_root_dir);
165 if (entry)
166 entry->proc_fops = &acpi_system_dsdt_ops;
Len Brown4be44fc2005-08-05 00:44:28 -0400167 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 goto Error;
169
170 /* 'fadt' [R] */
171 name = ACPI_SYSTEM_FILE_FADT;
172 entry = create_proc_entry(name, S_IRUSR, acpi_root_dir);
173 if (entry)
174 entry->proc_fops = &acpi_system_fadt_ops;
175 else
176 goto Error;
177
Len Brown4be44fc2005-08-05 00:44:28 -0400178 Done:
Patrick Mocheld550d982006-06-27 00:41:40 -0400179 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
Len Brown4be44fc2005-08-05 00:44:28 -0400181 Error:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 remove_proc_entry(ACPI_SYSTEM_FILE_FADT, acpi_root_dir);
183 remove_proc_entry(ACPI_SYSTEM_FILE_DSDT, acpi_root_dir);
Zhang Rui5bb730f2007-01-29 11:02:42 +0800184#ifdef CONFIG_ACPI_PROCFS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 remove_proc_entry(ACPI_SYSTEM_FILE_INFO, acpi_root_dir);
Zhang Rui5bb730f2007-01-29 11:02:42 +0800186#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
188 error = -EFAULT;
189 goto Done;
190}
191
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192subsys_initcall(acpi_system_init);