]>
Commit | Line | Data |
---|---|---|
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> | |
5a0e3ad6 | 28 | #include <linux/slab.h> |
1da177e4 | 29 | #include <linux/init.h> |
e108526e | 30 | #include <linux/string.h> |
1da177e4 LT |
31 | #include <asm/uaccess.h> |
32 | ||
33 | #include <acpi/acpi_drivers.h> | |
34 | ||
a192a958 LB |
35 | #define PREFIX "ACPI: " |
36 | ||
1da177e4 | 37 | #define _COMPONENT ACPI_SYSTEM_COMPONENT |
f52fd66d | 38 | ACPI_MODULE_NAME("system"); |
5bb730fd | 39 | |
1da177e4 | 40 | #define ACPI_SYSTEM_CLASS "system" |
1da177e4 | 41 | #define ACPI_SYSTEM_DEVICE_NAME "System" |
1da177e4 LT |
42 | |
43 | /* -------------------------------------------------------------------------- | |
44 | FS Interface (/proc) | |
45 | -------------------------------------------------------------------------- */ | |
5bb730fd | 46 | #ifdef CONFIG_ACPI_PROCFS |
d4c5f047 ZR |
47 | #define ACPI_SYSTEM_FILE_INFO "info" |
48 | #define ACPI_SYSTEM_FILE_EVENT "event" | |
49 | #define ACPI_SYSTEM_FILE_DSDT "dsdt" | |
50 | #define ACPI_SYSTEM_FILE_FADT "fadt" | |
1da177e4 | 51 | |
4be44fcd | 52 | static int acpi_system_read_info(struct seq_file *seq, void *offset) |
1da177e4 | 53 | { |
1da177e4 LT |
54 | |
55 | seq_printf(seq, "version: %x\n", ACPI_CA_VERSION); | |
d550d98d | 56 | return 0; |
1da177e4 LT |
57 | } |
58 | ||
59 | static int acpi_system_info_open_fs(struct inode *inode, struct file *file) | |
60 | { | |
61 | return single_open(file, acpi_system_read_info, PDE(inode)->data); | |
62 | } | |
63 | ||
d7508032 | 64 | static const struct file_operations acpi_system_info_ops = { |
cf7acfab | 65 | .owner = THIS_MODULE, |
4be44fcd LB |
66 | .open = acpi_system_info_open_fs, |
67 | .read = seq_read, | |
68 | .llseek = seq_lseek, | |
69 | .release = single_release, | |
1da177e4 LT |
70 | }; |
71 | ||
4be44fcd LB |
72 | static ssize_t acpi_system_read_dsdt(struct file *, char __user *, size_t, |
73 | loff_t *); | |
1da177e4 | 74 | |
d7508032 | 75 | static const struct file_operations acpi_system_dsdt_ops = { |
cf7acfab | 76 | .owner = THIS_MODULE, |
4be44fcd | 77 | .read = acpi_system_read_dsdt, |
1da177e4 LT |
78 | }; |
79 | ||
80 | static ssize_t | |
4be44fcd LB |
81 | acpi_system_read_dsdt(struct file *file, |
82 | char __user * buffer, size_t count, loff_t * ppos) | |
1da177e4 | 83 | { |
4be44fcd | 84 | acpi_status status = AE_OK; |
ad71860a | 85 | struct acpi_table_header *dsdt = NULL; |
4be44fcd | 86 | ssize_t res; |
1da177e4 | 87 | |
ad71860a | 88 | status = acpi_get_table(ACPI_SIG_DSDT, 1, &dsdt); |
1da177e4 | 89 | if (ACPI_FAILURE(status)) |
d550d98d | 90 | return -ENODEV; |
1da177e4 | 91 | |
d4c5f047 | 92 | res = simple_read_from_buffer(buffer, count, ppos, dsdt, dsdt->length); |
1da177e4 | 93 | |
d550d98d | 94 | return res; |
1da177e4 LT |
95 | } |
96 | ||
4be44fcd LB |
97 | static ssize_t acpi_system_read_fadt(struct file *, char __user *, size_t, |
98 | loff_t *); | |
1da177e4 | 99 | |
d7508032 | 100 | static const struct file_operations acpi_system_fadt_ops = { |
cf7acfab | 101 | .owner = THIS_MODULE, |
4be44fcd | 102 | .read = acpi_system_read_fadt, |
1da177e4 LT |
103 | }; |
104 | ||
105 | static ssize_t | |
4be44fcd LB |
106 | acpi_system_read_fadt(struct file *file, |
107 | char __user * buffer, size_t count, loff_t * ppos) | |
1da177e4 | 108 | { |
4be44fcd | 109 | acpi_status status = AE_OK; |
ad71860a | 110 | struct acpi_table_header *fadt = NULL; |
4be44fcd | 111 | ssize_t res; |
1da177e4 | 112 | |
ad71860a | 113 | status = acpi_get_table(ACPI_SIG_FADT, 1, &fadt); |
1da177e4 | 114 | if (ACPI_FAILURE(status)) |
d550d98d | 115 | return -ENODEV; |
1da177e4 | 116 | |
d4c5f047 | 117 | res = simple_read_from_buffer(buffer, count, ppos, fadt, fadt->length); |
1da177e4 | 118 | |
d550d98d | 119 | return res; |
1da177e4 LT |
120 | } |
121 | ||
d4c5f047 | 122 | static int acpi_system_procfs_init(void) |
1da177e4 | 123 | { |
4be44fcd | 124 | struct proc_dir_entry *entry; |
1da177e4 | 125 | int error = 0; |
1da177e4 | 126 | |
1da177e4 | 127 | /* 'info' [R] */ |
cf7acfab DL |
128 | entry = proc_create(ACPI_SYSTEM_FILE_INFO, S_IRUGO, acpi_root_dir, |
129 | &acpi_system_info_ops); | |
1da177e4 LT |
130 | if (!entry) |
131 | goto Error; | |
1da177e4 LT |
132 | |
133 | /* 'dsdt' [R] */ | |
cf7acfab DL |
134 | entry = proc_create(ACPI_SYSTEM_FILE_DSDT, S_IRUSR, acpi_root_dir, |
135 | &acpi_system_dsdt_ops); | |
136 | if (!entry) | |
1da177e4 LT |
137 | goto Error; |
138 | ||
139 | /* 'fadt' [R] */ | |
cf7acfab DL |
140 | entry = proc_create(ACPI_SYSTEM_FILE_FADT, S_IRUSR, acpi_root_dir, |
141 | &acpi_system_fadt_ops); | |
142 | if (!entry) | |
1da177e4 LT |
143 | goto Error; |
144 | ||
4be44fcd | 145 | Done: |
d550d98d | 146 | return error; |
1da177e4 | 147 | |
4be44fcd | 148 | Error: |
1da177e4 LT |
149 | remove_proc_entry(ACPI_SYSTEM_FILE_FADT, acpi_root_dir); |
150 | remove_proc_entry(ACPI_SYSTEM_FILE_DSDT, acpi_root_dir); | |
151 | remove_proc_entry(ACPI_SYSTEM_FILE_INFO, acpi_root_dir); | |
152 | ||
153 | error = -EFAULT; | |
154 | goto Done; | |
155 | } | |
d4c5f047 ZR |
156 | #else |
157 | static int acpi_system_procfs_init(void) | |
158 | { | |
159 | return 0; | |
160 | } | |
161 | #endif | |
162 | ||
141a0af3 | 163 | int __init acpi_system_init(void) |
d4c5f047 | 164 | { |
141a0af3 | 165 | int result; |
d4c5f047 ZR |
166 | |
167 | result = acpi_system_procfs_init(); | |
d4c5f047 ZR |
168 | |
169 | return result; | |
170 | } |