]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/acpi/system.c
Pull bay into test branch
[linux-2.6-omap-h63xx.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/seq_file.h>
28 #include <linux/init.h>
29 #include <asm/uaccess.h>
30
31 #include <acpi/acpi_drivers.h>
32
33 #define _COMPONENT              ACPI_SYSTEM_COMPONENT
34 ACPI_MODULE_NAME("acpi_system")
35 #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"
42
43 /* --------------------------------------------------------------------------
44                               FS Interface (/proc)
45    -------------------------------------------------------------------------- */
46
47 static int acpi_system_read_info(struct seq_file *seq, void *offset)
48 {
49
50         seq_printf(seq, "version:                 %x\n", ACPI_CA_VERSION);
51         return 0;
52 }
53
54 static int acpi_system_info_open_fs(struct inode *inode, struct file *file)
55 {
56         return single_open(file, acpi_system_read_info, PDE(inode)->data);
57 }
58
59 static const struct file_operations acpi_system_info_ops = {
60         .open = acpi_system_info_open_fs,
61         .read = seq_read,
62         .llseek = seq_lseek,
63         .release = single_release,
64 };
65
66 static ssize_t acpi_system_read_dsdt(struct file *, char __user *, size_t,
67                                      loff_t *);
68
69 static const struct file_operations acpi_system_dsdt_ops = {
70         .read = acpi_system_read_dsdt,
71 };
72
73 static ssize_t
74 acpi_system_read_dsdt(struct file *file,
75                       char __user * buffer, size_t count, loff_t * ppos)
76 {
77         acpi_status status = AE_OK;
78         struct acpi_table_header *dsdt = NULL;
79         ssize_t res;
80
81
82         status = acpi_get_table(ACPI_SIG_DSDT, 1, &dsdt);
83         if (ACPI_FAILURE(status))
84                 return -ENODEV;
85
86         res = simple_read_from_buffer(buffer, count, ppos,
87                                       dsdt, dsdt->length);
88
89         return res;
90 }
91
92 static ssize_t acpi_system_read_fadt(struct file *, char __user *, size_t,
93                                      loff_t *);
94
95 static const struct file_operations acpi_system_fadt_ops = {
96         .read = acpi_system_read_fadt,
97 };
98
99 static ssize_t
100 acpi_system_read_fadt(struct file *file,
101                       char __user * buffer, size_t count, loff_t * ppos)
102 {
103         acpi_status status = AE_OK;
104         struct acpi_table_header *fadt = NULL;
105         ssize_t res;
106
107
108         status = acpi_get_table(ACPI_SIG_FADT, 1, &fadt);
109         if (ACPI_FAILURE(status))
110                 return -ENODEV;
111
112         res = simple_read_from_buffer(buffer, count, ppos,
113                                       fadt, fadt->length);
114
115         return res;
116 }
117
118 static int __init acpi_system_init(void)
119 {
120         struct proc_dir_entry *entry;
121         int error = 0;
122         char *name;
123
124
125         if (acpi_disabled)
126                 return 0;
127
128         /* 'info' [R] */
129         name = ACPI_SYSTEM_FILE_INFO;
130         entry = create_proc_entry(name, S_IRUGO, acpi_root_dir);
131         if (!entry)
132                 goto Error;
133         else {
134                 entry->proc_fops = &acpi_system_info_ops;
135         }
136
137         /* 'dsdt' [R] */
138         name = ACPI_SYSTEM_FILE_DSDT;
139         entry = create_proc_entry(name, S_IRUSR, acpi_root_dir);
140         if (entry)
141                 entry->proc_fops = &acpi_system_dsdt_ops;
142         else
143                 goto Error;
144
145         /* 'fadt' [R] */
146         name = ACPI_SYSTEM_FILE_FADT;
147         entry = create_proc_entry(name, S_IRUSR, acpi_root_dir);
148         if (entry)
149                 entry->proc_fops = &acpi_system_fadt_ops;
150         else
151                 goto Error;
152
153       Done:
154         return error;
155
156       Error:
157         remove_proc_entry(ACPI_SYSTEM_FILE_FADT, acpi_root_dir);
158         remove_proc_entry(ACPI_SYSTEM_FILE_DSDT, acpi_root_dir);
159         remove_proc_entry(ACPI_SYSTEM_FILE_INFO, acpi_root_dir);
160
161         error = -EFAULT;
162         goto Done;
163 }
164
165 subsys_initcall(acpi_system_init);