ACPI: add ACPICA version in sysfs
[deliverable/linux.git] / drivers / acpi / system.c
CommitLineData
1da177e4
LT
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
1da177e4 33#define _COMPONENT ACPI_SYSTEM_COMPONENT
4be44fcd 34ACPI_MODULE_NAME("acpi_system")
5bb730fd
ZR
35#ifdef MODULE_PARAM_PREFIX
36#undef MODULE_PARAM_PREFIX
37#endif
38#define MODULE_PARAM_PREFIX "acpi."
39
1da177e4
LT
40#define ACPI_SYSTEM_CLASS "system"
41#define ACPI_SYSTEM_DRIVER_NAME "ACPI System Driver"
42#define ACPI_SYSTEM_DEVICE_NAME "System"
43#define ACPI_SYSTEM_FILE_INFO "info"
44#define ACPI_SYSTEM_FILE_EVENT "event"
45#define ACPI_SYSTEM_FILE_DSDT "dsdt"
46#define ACPI_SYSTEM_FILE_FADT "fadt"
793c2388 47extern struct fadt_descriptor acpi_fadt;
1da177e4 48
5bb730fd
ZR
49/*
50 * Make ACPICA version work as module param
51 */
52static int param_get_acpica_version(char *buffer, struct kernel_param *kp) {
53 int result;
54
55 result = sprintf(buffer, "%x", ACPI_CA_VERSION);
56
57 return result;
58}
59
60module_param_call(acpica_version, NULL, param_get_acpica_version, NULL, 0444);
61
1da177e4
LT
62/* --------------------------------------------------------------------------
63 FS Interface (/proc)
64 -------------------------------------------------------------------------- */
5bb730fd 65#ifdef CONFIG_ACPI_PROCFS
1da177e4 66
4be44fcd 67static int acpi_system_read_info(struct seq_file *seq, void *offset)
1da177e4 68{
1da177e4
LT
69
70 seq_printf(seq, "version: %x\n", ACPI_CA_VERSION);
d550d98d 71 return 0;
1da177e4
LT
72}
73
74static int acpi_system_info_open_fs(struct inode *inode, struct file *file)
75{
76 return single_open(file, acpi_system_read_info, PDE(inode)->data);
77}
78
d7508032 79static const struct file_operations acpi_system_info_ops = {
4be44fcd
LB
80 .open = acpi_system_info_open_fs,
81 .read = seq_read,
82 .llseek = seq_lseek,
83 .release = single_release,
1da177e4 84};
5bb730fd 85#endif
1da177e4 86
4be44fcd
LB
87static ssize_t acpi_system_read_dsdt(struct file *, char __user *, size_t,
88 loff_t *);
1da177e4 89
d7508032 90static const struct file_operations acpi_system_dsdt_ops = {
4be44fcd 91 .read = acpi_system_read_dsdt,
1da177e4
LT
92};
93
94static ssize_t
4be44fcd
LB
95acpi_system_read_dsdt(struct file *file,
96 char __user * buffer, size_t count, loff_t * ppos)
1da177e4 97{
4be44fcd
LB
98 acpi_status status = AE_OK;
99 struct acpi_buffer dsdt = { ACPI_ALLOCATE_BUFFER, NULL };
100 ssize_t res;
1da177e4 101
1da177e4 102
b229cf92 103 status = acpi_get_table(ACPI_TABLE_ID_DSDT, 1, &dsdt);
1da177e4 104 if (ACPI_FAILURE(status))
d550d98d 105 return -ENODEV;
1da177e4
LT
106
107 res = simple_read_from_buffer(buffer, count, ppos,
108 dsdt.pointer, dsdt.length);
02438d87 109 kfree(dsdt.pointer);
1da177e4 110
d550d98d 111 return res;
1da177e4
LT
112}
113
4be44fcd
LB
114static ssize_t acpi_system_read_fadt(struct file *, char __user *, size_t,
115 loff_t *);
1da177e4 116
d7508032 117static const struct file_operations acpi_system_fadt_ops = {
4be44fcd 118 .read = acpi_system_read_fadt,
1da177e4
LT
119};
120
121static ssize_t
4be44fcd
LB
122acpi_system_read_fadt(struct file *file,
123 char __user * buffer, size_t count, loff_t * ppos)
1da177e4 124{
4be44fcd
LB
125 acpi_status status = AE_OK;
126 struct acpi_buffer fadt = { ACPI_ALLOCATE_BUFFER, NULL };
127 ssize_t res;
1da177e4 128
1da177e4 129
b229cf92 130 status = acpi_get_table(ACPI_TABLE_ID_FADT, 1, &fadt);
1da177e4 131 if (ACPI_FAILURE(status))
d550d98d 132 return -ENODEV;
1da177e4
LT
133
134 res = simple_read_from_buffer(buffer, count, ppos,
135 fadt.pointer, fadt.length);
02438d87 136 kfree(fadt.pointer);
1da177e4 137
d550d98d 138 return res;
1da177e4
LT
139}
140
4be44fcd 141static int __init acpi_system_init(void)
1da177e4 142{
4be44fcd 143 struct proc_dir_entry *entry;
1da177e4 144 int error = 0;
4be44fcd 145 char *name;
1da177e4 146
1da177e4
LT
147
148 if (acpi_disabled)
d550d98d 149 return 0;
1da177e4 150
5bb730fd 151#ifdef CONFIG_ACPI_PROCFS
1da177e4
LT
152 /* 'info' [R] */
153 name = ACPI_SYSTEM_FILE_INFO;
4be44fcd 154 entry = create_proc_entry(name, S_IRUGO, acpi_root_dir);
1da177e4
LT
155 if (!entry)
156 goto Error;
157 else {
158 entry->proc_fops = &acpi_system_info_ops;
159 }
5bb730fd 160#endif
1da177e4
LT
161
162 /* 'dsdt' [R] */
163 name = ACPI_SYSTEM_FILE_DSDT;
164 entry = create_proc_entry(name, S_IRUSR, acpi_root_dir);
165 if (entry)
166 entry->proc_fops = &acpi_system_dsdt_ops;
4be44fcd 167 else
1da177e4
LT
168 goto Error;
169
170 /* 'fadt' [R] */
171 name = ACPI_SYSTEM_FILE_FADT;
172 entry = create_proc_entry(name, S_IRUSR, acpi_root_dir);
173 if (entry)
174 entry->proc_fops = &acpi_system_fadt_ops;
175 else
176 goto Error;
177
4be44fcd 178 Done:
d550d98d 179 return error;
1da177e4 180
4be44fcd 181 Error:
1da177e4
LT
182 remove_proc_entry(ACPI_SYSTEM_FILE_FADT, acpi_root_dir);
183 remove_proc_entry(ACPI_SYSTEM_FILE_DSDT, acpi_root_dir);
5bb730fd 184#ifdef CONFIG_ACPI_PROCFS
1da177e4 185 remove_proc_entry(ACPI_SYSTEM_FILE_INFO, acpi_root_dir);
5bb730fd 186#endif
1da177e4
LT
187
188 error = -EFAULT;
189 goto Done;
190}
191
1da177e4 192subsys_initcall(acpi_system_init);
This page took 0.142931 seconds and 5 git commands to generate.