blob: e4308c7a6743ba54766cac05669db2e9fd2e8c64 [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")
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#define ACPI_SYSTEM_CLASS "system"
36#define ACPI_SYSTEM_DRIVER_NAME "ACPI System Driver"
37#define ACPI_SYSTEM_DEVICE_NAME "System"
38#define ACPI_SYSTEM_FILE_INFO "info"
39#define ACPI_SYSTEM_FILE_EVENT "event"
40#define ACPI_SYSTEM_FILE_DSDT "dsdt"
41#define ACPI_SYSTEM_FILE_FADT "fadt"
Len Brown4be44fc2005-08-05 00:44:28 -040042extern FADT_DESCRIPTOR acpi_fadt;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44/* --------------------------------------------------------------------------
45 FS Interface (/proc)
46 -------------------------------------------------------------------------- */
47
Len Brown4be44fc2005-08-05 00:44:28 -040048static int acpi_system_read_info(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049{
50 ACPI_FUNCTION_TRACE("acpi_system_read_info");
51
52 seq_printf(seq, "version: %x\n", ACPI_CA_VERSION);
53 return_VALUE(0);
54}
55
56static int acpi_system_info_open_fs(struct inode *inode, struct file *file)
57{
58 return single_open(file, acpi_system_read_info, PDE(inode)->data);
59}
60
61static struct file_operations acpi_system_info_ops = {
Len Brown4be44fc2005-08-05 00:44:28 -040062 .open = acpi_system_info_open_fs,
63 .read = seq_read,
64 .llseek = seq_lseek,
65 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -070066};
67
Len Brown4be44fc2005-08-05 00:44:28 -040068static ssize_t acpi_system_read_dsdt(struct file *, char __user *, size_t,
69 loff_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71static struct file_operations acpi_system_dsdt_ops = {
Len Brown4be44fc2005-08-05 00:44:28 -040072 .read = acpi_system_read_dsdt,
Linus Torvalds1da177e2005-04-16 15:20:36 -070073};
74
75static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -040076acpi_system_read_dsdt(struct file *file,
77 char __user * buffer, size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078{
Len Brown4be44fc2005-08-05 00:44:28 -040079 acpi_status status = AE_OK;
80 struct acpi_buffer dsdt = { ACPI_ALLOCATE_BUFFER, NULL };
81 ssize_t res;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
83 ACPI_FUNCTION_TRACE("acpi_system_read_dsdt");
84
85 status = acpi_get_table(ACPI_TABLE_DSDT, 1, &dsdt);
86 if (ACPI_FAILURE(status))
87 return_VALUE(-ENODEV);
88
89 res = simple_read_from_buffer(buffer, count, ppos,
90 dsdt.pointer, dsdt.length);
91 acpi_os_free(dsdt.pointer);
92
93 return_VALUE(res);
94}
95
Len Brown4be44fc2005-08-05 00:44:28 -040096static ssize_t acpi_system_read_fadt(struct file *, char __user *, size_t,
97 loff_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
99static struct file_operations acpi_system_fadt_ops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400100 .read = acpi_system_read_fadt,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101};
102
103static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400104acpi_system_read_fadt(struct file *file,
105 char __user * buffer, size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106{
Len Brown4be44fc2005-08-05 00:44:28 -0400107 acpi_status status = AE_OK;
108 struct acpi_buffer fadt = { ACPI_ALLOCATE_BUFFER, NULL };
109 ssize_t res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
111 ACPI_FUNCTION_TRACE("acpi_system_read_fadt");
112
113 status = acpi_get_table(ACPI_TABLE_FADT, 1, &fadt);
114 if (ACPI_FAILURE(status))
115 return_VALUE(-ENODEV);
116
117 res = simple_read_from_buffer(buffer, count, ppos,
118 fadt.pointer, fadt.length);
119 acpi_os_free(fadt.pointer);
120
121 return_VALUE(res);
122}
123
Len Brown4be44fc2005-08-05 00:44:28 -0400124static int __init acpi_system_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125{
Len Brown4be44fc2005-08-05 00:44:28 -0400126 struct proc_dir_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 int error = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400128 char *name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
130 ACPI_FUNCTION_TRACE("acpi_system_init");
131
132 if (acpi_disabled)
133 return_VALUE(0);
134
135 /* 'info' [R] */
136 name = ACPI_SYSTEM_FILE_INFO;
Len Brown4be44fc2005-08-05 00:44:28 -0400137 entry = create_proc_entry(name, S_IRUGO, acpi_root_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 if (!entry)
139 goto Error;
140 else {
141 entry->proc_fops = &acpi_system_info_ops;
142 }
143
144 /* 'dsdt' [R] */
145 name = ACPI_SYSTEM_FILE_DSDT;
146 entry = create_proc_entry(name, S_IRUSR, acpi_root_dir);
147 if (entry)
148 entry->proc_fops = &acpi_system_dsdt_ops;
Len Brown4be44fc2005-08-05 00:44:28 -0400149 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 goto Error;
151
152 /* 'fadt' [R] */
153 name = ACPI_SYSTEM_FILE_FADT;
154 entry = create_proc_entry(name, S_IRUSR, acpi_root_dir);
155 if (entry)
156 entry->proc_fops = &acpi_system_fadt_ops;
157 else
158 goto Error;
159
Len Brown4be44fc2005-08-05 00:44:28 -0400160 Done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 return_VALUE(error);
162
Len Brown4be44fc2005-08-05 00:44:28 -0400163 Error:
164 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
165 "Unable to create '%s' proc fs entry\n", name));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
167 remove_proc_entry(ACPI_SYSTEM_FILE_FADT, acpi_root_dir);
168 remove_proc_entry(ACPI_SYSTEM_FILE_DSDT, acpi_root_dir);
169 remove_proc_entry(ACPI_SYSTEM_FILE_INFO, acpi_root_dir);
170
171 error = -EFAULT;
172 goto Done;
173}
174
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175subsys_initcall(acpi_system_init);