patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / drivers / acpi / system.c
1 /*
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/init.h>
28 #include <asm/uaccess.h>
29
30 #include <acpi/acpi_drivers.h>
31
32
33 #define _COMPONENT              ACPI_SYSTEM_COMPONENT
34 ACPI_MODULE_NAME                ("acpi_system")
35
36 #define ACPI_SYSTEM_CLASS               "system"
37 #define ACPI_SYSTEM_DRIVER_NAME         "ACPI System Driver"
38 #define ACPI_SYSTEM_DEVICE_NAME         "System"
39 #define ACPI_SYSTEM_FILE_INFO           "info"
40 #define ACPI_SYSTEM_FILE_EVENT          "event"
41 #define ACPI_SYSTEM_FILE_DSDT           "dsdt"
42 #define ACPI_SYSTEM_FILE_FADT           "fadt"
43
44 extern FADT_DESCRIPTOR          acpi_fadt;
45
46 /* --------------------------------------------------------------------------
47                               FS Interface (/proc)
48    -------------------------------------------------------------------------- */
49
50 static int
51 acpi_system_read_info (
52         char                    *page,
53         char                    **start,
54         off_t                   off,
55         int                     count,
56         int                     *eof,
57         void                    *data)
58 {
59         char                    *p = page;
60         int                     size = 0;
61
62         ACPI_FUNCTION_TRACE("acpi_system_read_info");
63
64         if (off != 0)
65                 goto end;
66
67         p += sprintf(p, "version:                 %x\n", ACPI_CA_VERSION);
68
69 end:
70         size = (p - page);
71         if (size <= off+count) *eof = 1;
72         *start = page + off;
73         size -= off;
74         if (size>count) size = count;
75         if (size<0) size = 0;
76
77         return_VALUE(size);
78 }
79
80 static ssize_t acpi_system_read_dsdt (struct file*, char __user *, size_t, loff_t*);
81
82 static struct file_operations acpi_system_dsdt_ops = {
83         .read =                 acpi_system_read_dsdt,
84 };
85
86 static ssize_t
87 acpi_system_read_dsdt (
88         struct file             *file,
89         char                    __user *buffer,
90         size_t                  count,
91         loff_t                  *ppos)
92 {
93         acpi_status             status = AE_OK;
94         struct acpi_buffer      dsdt = {ACPI_ALLOCATE_BUFFER, NULL};
95         void                    *data = 0;
96         size_t                  size = 0;
97
98         ACPI_FUNCTION_TRACE("acpi_system_read_dsdt");
99
100         status = acpi_get_table(ACPI_TABLE_DSDT, 1, &dsdt);
101         if (ACPI_FAILURE(status))
102                 return_VALUE(-ENODEV);
103
104         if (*ppos < dsdt.length) {
105                 data = dsdt.pointer + file->f_pos;
106                 size = dsdt.length - file->f_pos;
107                 if (size > count)
108                         size = count;
109                 if (copy_to_user(buffer, data, size)) {
110                         acpi_os_free(dsdt.pointer);
111                         return_VALUE(-EFAULT);
112                 }
113         }
114
115         acpi_os_free(dsdt.pointer);
116
117         *ppos += size;
118
119         return_VALUE(size);
120 }
121
122
123 static ssize_t acpi_system_read_fadt (struct file*, char __user *, size_t, loff_t*);
124
125 static struct file_operations acpi_system_fadt_ops = {
126         .read =                 acpi_system_read_fadt,
127 };
128
129 static ssize_t
130 acpi_system_read_fadt (
131         struct file             *file,
132         char                    __user *buffer,
133         size_t                  count,
134         loff_t                  *ppos)
135 {
136         acpi_status             status = AE_OK;
137         struct acpi_buffer      fadt = {ACPI_ALLOCATE_BUFFER, NULL};
138         void                    *data = 0;
139         size_t                  size = 0;
140
141         ACPI_FUNCTION_TRACE("acpi_system_read_fadt");
142
143         status = acpi_get_table(ACPI_TABLE_FADT, 1, &fadt);
144         if (ACPI_FAILURE(status))
145                 return_VALUE(-ENODEV);
146
147         if (*ppos < fadt.length) {
148                 data = fadt.pointer + file->f_pos;
149                 size = fadt.length - file->f_pos;
150                 if (size > count)
151                         size = count;
152                 if (copy_to_user(buffer, data, size)) {
153                         acpi_os_free(fadt.pointer);
154                         return_VALUE(-EFAULT);
155                 }
156         }
157
158         acpi_os_free(fadt.pointer);
159
160         *ppos += size;
161
162         return_VALUE(size);
163 }
164
165
166 static int __init acpi_system_init (void)
167 {
168         struct proc_dir_entry   *entry;
169         int error = 0;
170         char * name;
171
172         ACPI_FUNCTION_TRACE("acpi_system_init");
173
174         if (acpi_disabled)
175                 return_VALUE(0);
176
177         /* 'info' [R] */
178         name = ACPI_SYSTEM_FILE_INFO;
179         entry = create_proc_read_entry(name,
180                 S_IRUGO, acpi_root_dir, acpi_system_read_info,NULL);
181         if (!entry)
182                 goto Error;
183
184         /* 'dsdt' [R] */
185         name = ACPI_SYSTEM_FILE_DSDT;
186         entry = create_proc_entry(name, S_IRUSR, acpi_root_dir);
187         if (entry)
188                 entry->proc_fops = &acpi_system_dsdt_ops;
189         else 
190                 goto Error;
191
192         /* 'fadt' [R] */
193         name = ACPI_SYSTEM_FILE_FADT;
194         entry = create_proc_entry(name, S_IRUSR, acpi_root_dir);
195         if (entry)
196                 entry->proc_fops = &acpi_system_fadt_ops;
197         else
198                 goto Error;
199
200  Done:
201         return_VALUE(error);
202
203  Error:
204         ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 
205                          "Unable to create '%s' proc fs entry\n", name));
206
207         remove_proc_entry(ACPI_SYSTEM_FILE_FADT, acpi_root_dir);
208         remove_proc_entry(ACPI_SYSTEM_FILE_DSDT, acpi_root_dir);
209         remove_proc_entry(ACPI_SYSTEM_FILE_INFO, acpi_root_dir);
210
211         error = -EFAULT;
212         goto Done;
213 }
214
215
216 subsys_initcall(acpi_system_init);