blob: d70481f32c89055db212cd104494557626e96310 [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090028#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/init.h>
Akinobu Mitae1085262008-07-23 21:26:44 -070030#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <asm/uaccess.h>
32
33#include <acpi/acpi_drivers.h>
34
Len Browna192a952009-07-28 16:45:54 -040035#define PREFIX "ACPI: "
36
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#define _COMPONENT ACPI_SYSTEM_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050038ACPI_MODULE_NAME("system");
Zhang Rui5bb730f2007-01-29 11:02:42 +080039
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#define ACPI_SYSTEM_CLASS "system"
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#define ACPI_SYSTEM_DEVICE_NAME "System"
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Zhang Ruid4c5f042007-06-14 17:43:07 +080043/* --------------------------------------------------------------------------
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 FS Interface (/proc)
45 -------------------------------------------------------------------------- */
Zhang Rui5bb730f2007-01-29 11:02:42 +080046#ifdef CONFIG_ACPI_PROCFS
Zhang Ruid4c5f042007-06-14 17:43:07 +080047#define ACPI_SYSTEM_FILE_INFO "info"
48#define ACPI_SYSTEM_FILE_EVENT "event"
49#define ACPI_SYSTEM_FILE_DSDT "dsdt"
50#define ACPI_SYSTEM_FILE_FADT "fadt"
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Len Brown4be44fc2005-08-05 00:44:28 -040052static int acpi_system_read_info(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053{
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55 seq_printf(seq, "version: %x\n", ACPI_CA_VERSION);
Patrick Mocheld550d982006-06-27 00:41:40 -040056 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057}
58
59static int acpi_system_info_open_fs(struct inode *inode, struct file *file)
60{
61 return single_open(file, acpi_system_read_info, PDE(inode)->data);
62}
63
Arjan van de Vend7508032006-07-04 13:06:00 -040064static const struct file_operations acpi_system_info_ops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -070065 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -040066 .open = acpi_system_info_open_fs,
67 .read = seq_read,
68 .llseek = seq_lseek,
69 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -070070};
71
Len Brown4be44fc2005-08-05 00:44:28 -040072static ssize_t acpi_system_read_dsdt(struct file *, char __user *, size_t,
73 loff_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Arjan van de Vend7508032006-07-04 13:06:00 -040075static const struct file_operations acpi_system_dsdt_ops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -070076 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -040077 .read = acpi_system_read_dsdt,
Linus Torvalds1da177e2005-04-16 15:20:36 -070078};
79
80static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -040081acpi_system_read_dsdt(struct file *file,
82 char __user * buffer, size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083{
Len Brown4be44fc2005-08-05 00:44:28 -040084 acpi_status status = AE_OK;
Alexey Starikovskiyad718602007-02-02 19:48:19 +030085 struct acpi_table_header *dsdt = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -040086 ssize_t res;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
Alexey Starikovskiyad718602007-02-02 19:48:19 +030088 status = acpi_get_table(ACPI_SIG_DSDT, 1, &dsdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -040090 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Zhang Ruid4c5f042007-06-14 17:43:07 +080092 res = simple_read_from_buffer(buffer, count, ppos, dsdt, dsdt->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Patrick Mocheld550d982006-06-27 00:41:40 -040094 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095}
96
Len Brown4be44fc2005-08-05 00:44:28 -040097static ssize_t acpi_system_read_fadt(struct file *, char __user *, size_t,
98 loff_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Arjan van de Vend7508032006-07-04 13:06:00 -0400100static const struct file_operations acpi_system_fadt_ops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700101 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400102 .read = acpi_system_read_fadt,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103};
104
105static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400106acpi_system_read_fadt(struct file *file,
107 char __user * buffer, size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108{
Len Brown4be44fc2005-08-05 00:44:28 -0400109 acpi_status status = AE_OK;
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300110 struct acpi_table_header *fadt = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400111 ssize_t res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300113 status = acpi_get_table(ACPI_SIG_FADT, 1, &fadt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400115 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Zhang Ruid4c5f042007-06-14 17:43:07 +0800117 res = simple_read_from_buffer(buffer, count, ppos, fadt, fadt->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Patrick Mocheld550d982006-06-27 00:41:40 -0400119 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120}
121
Zhang Ruid4c5f042007-06-14 17:43:07 +0800122static int acpi_system_procfs_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123{
Len Brown4be44fc2005-08-05 00:44:28 -0400124 struct proc_dir_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 int error = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 /* 'info' [R] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700128 entry = proc_create(ACPI_SYSTEM_FILE_INFO, S_IRUGO, acpi_root_dir,
129 &acpi_system_info_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 if (!entry)
131 goto Error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133 /* 'dsdt' [R] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700134 entry = proc_create(ACPI_SYSTEM_FILE_DSDT, S_IRUSR, acpi_root_dir,
135 &acpi_system_dsdt_ops);
136 if (!entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 goto Error;
138
139 /* 'fadt' [R] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700140 entry = proc_create(ACPI_SYSTEM_FILE_FADT, S_IRUSR, acpi_root_dir,
141 &acpi_system_fadt_ops);
142 if (!entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 goto Error;
144
Len Brown4be44fc2005-08-05 00:44:28 -0400145 Done:
Patrick Mocheld550d982006-06-27 00:41:40 -0400146 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Len Brown4be44fc2005-08-05 00:44:28 -0400148 Error:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 remove_proc_entry(ACPI_SYSTEM_FILE_FADT, acpi_root_dir);
150 remove_proc_entry(ACPI_SYSTEM_FILE_DSDT, acpi_root_dir);
151 remove_proc_entry(ACPI_SYSTEM_FILE_INFO, acpi_root_dir);
152
153 error = -EFAULT;
154 goto Done;
155}
Zhang Ruid4c5f042007-06-14 17:43:07 +0800156#else
157static int acpi_system_procfs_init(void)
158{
159 return 0;
160}
161#endif
162
Bjorn Helgaas141a0af2009-03-24 16:49:58 -0600163int __init acpi_system_init(void)
Zhang Ruid4c5f042007-06-14 17:43:07 +0800164{
Bjorn Helgaas141a0af2009-03-24 16:49:58 -0600165 int result;
Zhang Ruid4c5f042007-06-14 17:43:07 +0800166
167 result = acpi_system_procfs_init();
Zhang Ruid4c5f042007-06-14 17:43:07 +0800168
169 return result;
170}