blob: edead9e9faa0c27eb65a7d8c38311f65b5949972 [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 Brownf52fd662007-02-12 22:42:12 -050034ACPI_MODULE_NAME("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"
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Zhang Rui5bb730f2007-01-29 11:02:42 +080048/*
49 * Make ACPICA version work as module param
50 */
51static int param_get_acpica_version(char *buffer, struct kernel_param *kp) {
52 int result;
53
54 result = sprintf(buffer, "%x", ACPI_CA_VERSION);
55
56 return result;
57}
58
59module_param_call(acpica_version, NULL, param_get_acpica_version, NULL, 0444);
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061/* --------------------------------------------------------------------------
62 FS Interface (/proc)
63 -------------------------------------------------------------------------- */
Zhang Rui5bb730f2007-01-29 11:02:42 +080064#ifdef CONFIG_ACPI_PROCFS
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Len Brown4be44fc2005-08-05 00:44:28 -040066static int acpi_system_read_info(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067{
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69 seq_printf(seq, "version: %x\n", ACPI_CA_VERSION);
Patrick Mocheld550d982006-06-27 00:41:40 -040070 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071}
72
73static int acpi_system_info_open_fs(struct inode *inode, struct file *file)
74{
75 return single_open(file, acpi_system_read_info, PDE(inode)->data);
76}
77
Arjan van de Vend7508032006-07-04 13:06:00 -040078static const struct file_operations acpi_system_info_ops = {
Len Brown4be44fc2005-08-05 00:44:28 -040079 .open = acpi_system_info_open_fs,
80 .read = seq_read,
81 .llseek = seq_lseek,
82 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -070083};
Zhang Rui5bb730f2007-01-29 11:02:42 +080084#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Len Brown4be44fc2005-08-05 00:44:28 -040086static ssize_t acpi_system_read_dsdt(struct file *, char __user *, size_t,
87 loff_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Arjan van de Vend7508032006-07-04 13:06:00 -040089static const struct file_operations acpi_system_dsdt_ops = {
Len Brown4be44fc2005-08-05 00:44:28 -040090 .read = acpi_system_read_dsdt,
Linus Torvalds1da177e2005-04-16 15:20:36 -070091};
92
93static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -040094acpi_system_read_dsdt(struct file *file,
95 char __user * buffer, size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096{
Len Brown4be44fc2005-08-05 00:44:28 -040097 acpi_status status = AE_OK;
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +030098 struct acpi_table_header *dsdt = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -040099 ssize_t res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300102 status = acpi_get_table(ACPI_SIG_DSDT, 1, &dsdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400104 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
106 res = simple_read_from_buffer(buffer, count, ppos,
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300107 dsdt, dsdt->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Patrick Mocheld550d982006-06-27 00:41:40 -0400109 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110}
111
Len Brown4be44fc2005-08-05 00:44:28 -0400112static ssize_t acpi_system_read_fadt(struct file *, char __user *, size_t,
113 loff_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Arjan van de Vend7508032006-07-04 13:06:00 -0400115static const struct file_operations acpi_system_fadt_ops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400116 .read = acpi_system_read_fadt,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117};
118
119static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400120acpi_system_read_fadt(struct file *file,
121 char __user * buffer, size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122{
Len Brown4be44fc2005-08-05 00:44:28 -0400123 acpi_status status = AE_OK;
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300124 struct acpi_table_header *fadt = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400125 ssize_t res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300128 status = acpi_get_table(ACPI_SIG_FADT, 1, &fadt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400130 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132 res = simple_read_from_buffer(buffer, count, ppos,
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300133 fadt, fadt->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Patrick Mocheld550d982006-06-27 00:41:40 -0400135 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136}
137
Len Brown4be44fc2005-08-05 00:44:28 -0400138static int __init acpi_system_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139{
Len Brown4be44fc2005-08-05 00:44:28 -0400140 struct proc_dir_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 int error = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400142 char *name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
145 if (acpi_disabled)
Patrick Mocheld550d982006-06-27 00:41:40 -0400146 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Zhang Rui5bb730f2007-01-29 11:02:42 +0800148#ifdef CONFIG_ACPI_PROCFS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 /* 'info' [R] */
150 name = ACPI_SYSTEM_FILE_INFO;
Len Brown4be44fc2005-08-05 00:44:28 -0400151 entry = create_proc_entry(name, S_IRUGO, acpi_root_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 if (!entry)
153 goto Error;
154 else {
155 entry->proc_fops = &acpi_system_info_ops;
156 }
Zhang Rui5bb730f2007-01-29 11:02:42 +0800157#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
159 /* 'dsdt' [R] */
160 name = ACPI_SYSTEM_FILE_DSDT;
161 entry = create_proc_entry(name, S_IRUSR, acpi_root_dir);
162 if (entry)
163 entry->proc_fops = &acpi_system_dsdt_ops;
Len Brown4be44fc2005-08-05 00:44:28 -0400164 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 goto Error;
166
167 /* 'fadt' [R] */
168 name = ACPI_SYSTEM_FILE_FADT;
169 entry = create_proc_entry(name, S_IRUSR, acpi_root_dir);
170 if (entry)
171 entry->proc_fops = &acpi_system_fadt_ops;
172 else
173 goto Error;
174
Len Brown4be44fc2005-08-05 00:44:28 -0400175 Done:
Patrick Mocheld550d982006-06-27 00:41:40 -0400176 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
Len Brown4be44fc2005-08-05 00:44:28 -0400178 Error:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 remove_proc_entry(ACPI_SYSTEM_FILE_FADT, acpi_root_dir);
180 remove_proc_entry(ACPI_SYSTEM_FILE_DSDT, acpi_root_dir);
Zhang Rui5bb730f2007-01-29 11:02:42 +0800181#ifdef CONFIG_ACPI_PROCFS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 remove_proc_entry(ACPI_SYSTEM_FILE_INFO, acpi_root_dir);
Zhang Rui5bb730f2007-01-29 11:02:42 +0800183#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
185 error = -EFAULT;
186 goto Done;
187}
188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189subsys_initcall(acpi_system_init);