MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / acpi / system.c
blob9919e76d7d49ccde3585b14a1263ec0d0e5b5758
1 /*
2 * acpi_system.c - ACPI System Driver ($Revision: 63 $)
4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
5 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
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.
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.
23 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
26 #include <linux/proc_fs.h>
27 #include <linux/init.h>
28 #include <asm/uaccess.h>
30 #include <acpi/acpi_drivers.h>
33 #define _COMPONENT ACPI_SYSTEM_COMPONENT
34 ACPI_MODULE_NAME ("acpi_system")
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"
44 extern FADT_DESCRIPTOR acpi_fadt;
46 /* --------------------------------------------------------------------------
47 FS Interface (/proc)
48 -------------------------------------------------------------------------- */
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)
59 char *p = page;
60 int size = 0;
62 ACPI_FUNCTION_TRACE("acpi_system_read_info");
64 if (off != 0)
65 goto end;
67 p += sprintf(p, "version: %x\n", ACPI_CA_VERSION);
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;
77 return_VALUE(size);
80 static ssize_t acpi_system_read_dsdt (struct file*, char __user *, size_t, loff_t*);
82 static struct file_operations acpi_system_dsdt_ops = {
83 .read = acpi_system_read_dsdt,
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)
93 acpi_status status = AE_OK;
94 struct acpi_buffer dsdt = {ACPI_ALLOCATE_BUFFER, NULL};
95 ssize_t res;
97 ACPI_FUNCTION_TRACE("acpi_system_read_dsdt");
99 status = acpi_get_table(ACPI_TABLE_DSDT, 1, &dsdt);
100 if (ACPI_FAILURE(status))
101 return_VALUE(-ENODEV);
103 res = simple_read_from_buffer(buffer, count, ppos,
104 dsdt.pointer, dsdt.length);
105 acpi_os_free(dsdt.pointer);
107 return_VALUE(res);
111 static ssize_t acpi_system_read_fadt (struct file*, char __user *, size_t, loff_t*);
113 static struct file_operations acpi_system_fadt_ops = {
114 .read = acpi_system_read_fadt,
117 static ssize_t
118 acpi_system_read_fadt (
119 struct file *file,
120 char __user *buffer,
121 size_t count,
122 loff_t *ppos)
124 acpi_status status = AE_OK;
125 struct acpi_buffer fadt = {ACPI_ALLOCATE_BUFFER, NULL};
126 ssize_t res;
128 ACPI_FUNCTION_TRACE("acpi_system_read_fadt");
130 status = acpi_get_table(ACPI_TABLE_FADT, 1, &fadt);
131 if (ACPI_FAILURE(status))
132 return_VALUE(-ENODEV);
134 res = simple_read_from_buffer(buffer, count, ppos,
135 fadt.pointer, fadt.length);
136 acpi_os_free(fadt.pointer);
138 return_VALUE(res);
142 static int __init acpi_system_init (void)
144 struct proc_dir_entry *entry;
145 int error = 0;
146 char * name;
148 ACPI_FUNCTION_TRACE("acpi_system_init");
150 if (acpi_disabled)
151 return_VALUE(0);
153 /* 'info' [R] */
154 name = ACPI_SYSTEM_FILE_INFO;
155 entry = create_proc_read_entry(name,
156 S_IRUGO, acpi_root_dir, acpi_system_read_info,NULL);
157 if (!entry)
158 goto Error;
160 /* 'dsdt' [R] */
161 name = ACPI_SYSTEM_FILE_DSDT;
162 entry = create_proc_entry(name, S_IRUSR, acpi_root_dir);
163 if (entry)
164 entry->proc_fops = &acpi_system_dsdt_ops;
165 else
166 goto Error;
168 /* 'fadt' [R] */
169 name = ACPI_SYSTEM_FILE_FADT;
170 entry = create_proc_entry(name, S_IRUSR, acpi_root_dir);
171 if (entry)
172 entry->proc_fops = &acpi_system_fadt_ops;
173 else
174 goto Error;
176 Done:
177 return_VALUE(error);
179 Error:
180 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
181 "Unable to create '%s' proc fs entry\n", name));
183 remove_proc_entry(ACPI_SYSTEM_FILE_FADT, acpi_root_dir);
184 remove_proc_entry(ACPI_SYSTEM_FILE_DSDT, acpi_root_dir);
185 remove_proc_entry(ACPI_SYSTEM_FILE_INFO, acpi_root_dir);
187 error = -EFAULT;
188 goto Done;
192 subsys_initcall(acpi_system_init);