Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #define _COMPONENT ACPI_SYSTEM_COMPONENT |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 34 | ACPI_MODULE_NAME("system"); |
Zhang Rui | 5bb730f | 2007-01-29 11:02:42 +0800 | [diff] [blame] | 35 | #ifdef MODULE_PARAM_PREFIX |
| 36 | #undef MODULE_PARAM_PREFIX |
| 37 | #endif |
| 38 | #define MODULE_PARAM_PREFIX "acpi." |
| 39 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #define ACPI_SYSTEM_CLASS "system" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #define ACPI_SYSTEM_DEVICE_NAME "System" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
Len Brown | 5229e87 | 2008-02-06 01:26:55 -0500 | [diff] [blame] | 43 | u32 acpi_irq_handled; |
| 44 | |
Zhang Rui | 5bb730f | 2007-01-29 11:02:42 +0800 | [diff] [blame] | 45 | /* |
| 46 | * Make ACPICA version work as module param |
| 47 | */ |
Zhang Rui | d4c5f04 | 2007-06-14 17:43:07 +0800 | [diff] [blame] | 48 | static int param_get_acpica_version(char *buffer, struct kernel_param *kp) |
| 49 | { |
Zhang Rui | 5bb730f | 2007-01-29 11:02:42 +0800 | [diff] [blame] | 50 | int result; |
| 51 | |
| 52 | result = sprintf(buffer, "%x", ACPI_CA_VERSION); |
| 53 | |
| 54 | return result; |
| 55 | } |
| 56 | |
| 57 | module_param_call(acpica_version, NULL, param_get_acpica_version, NULL, 0444); |
| 58 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | /* -------------------------------------------------------------------------- |
Zhang Rui | d4c5f04 | 2007-06-14 17:43:07 +0800 | [diff] [blame] | 60 | FS Interface (/sys) |
| 61 | -------------------------------------------------------------------------- */ |
| 62 | static LIST_HEAD(acpi_table_attr_list); |
Greg Kroah-Hartman | a77aa28 | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 63 | static struct kobject *tables_kobj; |
Zhang Rui | d4c5f04 | 2007-06-14 17:43:07 +0800 | [diff] [blame] | 64 | |
| 65 | struct acpi_table_attr { |
| 66 | struct bin_attribute attr; |
| 67 | char name[8]; |
| 68 | int instance; |
| 69 | struct list_head node; |
| 70 | }; |
| 71 | |
| 72 | static ssize_t acpi_table_show(struct kobject *kobj, |
| 73 | struct bin_attribute *bin_attr, char *buf, |
| 74 | loff_t offset, size_t count) |
| 75 | { |
| 76 | struct acpi_table_attr *table_attr = |
| 77 | container_of(bin_attr, struct acpi_table_attr, attr); |
| 78 | struct acpi_table_header *table_header = NULL; |
| 79 | acpi_status status; |
Zhang Rui | d4c5f04 | 2007-06-14 17:43:07 +0800 | [diff] [blame] | 80 | |
| 81 | status = |
| 82 | acpi_get_table(table_attr->name, table_attr->instance, |
| 83 | &table_header); |
| 84 | if (ACPI_FAILURE(status)) |
| 85 | return -ENODEV; |
| 86 | |
Akinobu Mita | 46a21e4 | 2008-06-09 16:22:26 -0700 | [diff] [blame] | 87 | return memory_read_from_buffer(buf, count, &offset, |
| 88 | table_header, table_header->length); |
Zhang Rui | d4c5f04 | 2007-06-14 17:43:07 +0800 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | static void acpi_table_attr_init(struct acpi_table_attr *table_attr, |
| 92 | struct acpi_table_header *table_header) |
| 93 | { |
| 94 | struct acpi_table_header *header = NULL; |
| 95 | struct acpi_table_attr *attr = NULL; |
| 96 | |
| 97 | memcpy(table_attr->name, table_header->signature, ACPI_NAME_SIZE); |
| 98 | |
| 99 | list_for_each_entry(attr, &acpi_table_attr_list, node) { |
| 100 | if (!memcmp(table_header->signature, attr->name, |
| 101 | ACPI_NAME_SIZE)) |
| 102 | if (table_attr->instance < attr->instance) |
| 103 | table_attr->instance = attr->instance; |
| 104 | } |
| 105 | table_attr->instance++; |
| 106 | |
| 107 | if (table_attr->instance > 1 || (table_attr->instance == 1 && |
| 108 | !acpi_get_table(table_header-> |
| 109 | signature, 2, |
| 110 | &header))) |
| 111 | sprintf(table_attr->name + 4, "%d", table_attr->instance); |
| 112 | |
| 113 | table_attr->attr.size = 0; |
| 114 | table_attr->attr.read = acpi_table_show; |
| 115 | table_attr->attr.attr.name = table_attr->name; |
| 116 | table_attr->attr.attr.mode = 0444; |
| 117 | table_attr->attr.attr.owner = THIS_MODULE; |
| 118 | |
| 119 | return; |
| 120 | } |
| 121 | |
| 122 | static int acpi_system_sysfs_init(void) |
| 123 | { |
| 124 | struct acpi_table_attr *table_attr; |
| 125 | struct acpi_table_header *table_header = NULL; |
| 126 | int table_index = 0; |
| 127 | int result; |
| 128 | |
Greg Kroah-Hartman | a77aa28 | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 129 | tables_kobj = kobject_create_and_add("tables", acpi_kobj); |
| 130 | if (!tables_kobj) |
| 131 | return -ENOMEM; |
Zhang Rui | d4c5f04 | 2007-06-14 17:43:07 +0800 | [diff] [blame] | 132 | |
| 133 | do { |
| 134 | result = acpi_get_table_by_index(table_index, &table_header); |
| 135 | if (!result) { |
| 136 | table_index++; |
| 137 | table_attr = NULL; |
| 138 | table_attr = |
| 139 | kzalloc(sizeof(struct acpi_table_attr), GFP_KERNEL); |
| 140 | if (!table_attr) |
| 141 | return -ENOMEM; |
| 142 | |
| 143 | acpi_table_attr_init(table_attr, table_header); |
| 144 | result = |
Greg Kroah-Hartman | a77aa28 | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 145 | sysfs_create_bin_file(tables_kobj, |
Zhang Rui | d4c5f04 | 2007-06-14 17:43:07 +0800 | [diff] [blame] | 146 | &table_attr->attr); |
| 147 | if (result) { |
| 148 | kfree(table_attr); |
| 149 | return result; |
| 150 | } else |
| 151 | list_add_tail(&table_attr->node, |
| 152 | &acpi_table_attr_list); |
| 153 | } |
| 154 | } while (!result); |
Greg Kroah-Hartman | a77aa28 | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 155 | kobject_uevent(tables_kobj, KOBJ_ADD); |
Zhang Rui | d4c5f04 | 2007-06-14 17:43:07 +0800 | [diff] [blame] | 156 | |
| 157 | return 0; |
| 158 | } |
| 159 | |
Len Brown | 5229e87 | 2008-02-06 01:26:55 -0500 | [diff] [blame] | 160 | /* |
| 161 | * Detailed ACPI IRQ counters in /sys/firmware/acpi/interrupts/ |
| 162 | * See Documentation/ABI/testing/sysfs-firmware-acpi |
| 163 | */ |
| 164 | |
| 165 | #define COUNT_GPE 0 |
| 166 | #define COUNT_SCI 1 /* acpi_irq_handled */ |
| 167 | #define COUNT_ERROR 2 /* other */ |
| 168 | #define NUM_COUNTERS_EXTRA 3 |
| 169 | |
| 170 | static u32 *all_counters; |
| 171 | static u32 num_gpes; |
| 172 | static u32 num_counters; |
| 173 | static struct attribute **all_attrs; |
| 174 | static u32 acpi_gpe_count; |
| 175 | |
| 176 | static struct attribute_group interrupt_stats_attr_group = { |
| 177 | .name = "interrupts", |
| 178 | }; |
| 179 | static struct kobj_attribute *counter_attrs; |
| 180 | |
| 181 | static int count_num_gpes(void) |
| 182 | { |
| 183 | int count = 0; |
| 184 | struct acpi_gpe_xrupt_info *gpe_xrupt_info; |
| 185 | struct acpi_gpe_block_info *gpe_block; |
| 186 | acpi_cpu_flags flags; |
| 187 | |
| 188 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); |
| 189 | |
| 190 | gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head; |
| 191 | while (gpe_xrupt_info) { |
| 192 | gpe_block = gpe_xrupt_info->gpe_block_list_head; |
| 193 | while (gpe_block) { |
| 194 | count += gpe_block->register_count * |
| 195 | ACPI_GPE_REGISTER_WIDTH; |
| 196 | gpe_block = gpe_block->next; |
| 197 | } |
| 198 | gpe_xrupt_info = gpe_xrupt_info->next; |
| 199 | } |
| 200 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); |
| 201 | |
| 202 | return count; |
| 203 | } |
| 204 | |
| 205 | static void delete_gpe_attr_array(void) |
| 206 | { |
| 207 | u32 *tmp = all_counters; |
| 208 | |
| 209 | all_counters = NULL; |
| 210 | kfree(tmp); |
| 211 | |
| 212 | if (counter_attrs) { |
| 213 | int i; |
| 214 | |
| 215 | for (i = 0; i < num_gpes; i++) |
| 216 | kfree(counter_attrs[i].attr.name); |
| 217 | |
| 218 | kfree(counter_attrs); |
| 219 | } |
| 220 | kfree(all_attrs); |
| 221 | |
| 222 | return; |
| 223 | } |
| 224 | |
| 225 | void acpi_os_gpe_count(u32 gpe_number) |
| 226 | { |
| 227 | acpi_gpe_count++; |
| 228 | |
| 229 | if (!all_counters) |
| 230 | return; |
| 231 | |
| 232 | if (gpe_number < num_gpes) |
| 233 | all_counters[gpe_number]++; |
| 234 | else |
| 235 | all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_ERROR]++; |
| 236 | |
| 237 | return; |
| 238 | } |
| 239 | |
| 240 | void acpi_os_fixed_event_count(u32 event_number) |
| 241 | { |
| 242 | if (!all_counters) |
| 243 | return; |
| 244 | |
| 245 | if (event_number < ACPI_NUM_FIXED_EVENTS) |
| 246 | all_counters[num_gpes + event_number]++; |
| 247 | else |
| 248 | all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_ERROR]++; |
| 249 | |
| 250 | return; |
| 251 | } |
| 252 | |
| 253 | static ssize_t counter_show(struct kobject *kobj, |
| 254 | struct kobj_attribute *attr, char *buf) |
| 255 | { |
| 256 | all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI] = |
| 257 | acpi_irq_handled; |
| 258 | all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_GPE] = |
| 259 | acpi_gpe_count; |
| 260 | |
| 261 | return sprintf(buf, "%d\n", all_counters[attr - counter_attrs]); |
| 262 | } |
| 263 | |
| 264 | /* |
| 265 | * counter_set() sets the specified counter. |
| 266 | * setting the total "sci" file to any value clears all counters. |
| 267 | */ |
| 268 | static ssize_t counter_set(struct kobject *kobj, |
| 269 | struct kobj_attribute *attr, const char *buf, size_t size) |
| 270 | { |
| 271 | int index = attr - counter_attrs; |
| 272 | |
| 273 | if (index == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI) { |
| 274 | int i; |
| 275 | for (i = 0; i < num_counters; ++i) |
| 276 | all_counters[i] = 0; |
| 277 | acpi_gpe_count = 0; |
| 278 | acpi_irq_handled = 0; |
| 279 | |
| 280 | } else |
| 281 | all_counters[index] = strtoul(buf, NULL, 0); |
| 282 | |
| 283 | return size; |
| 284 | } |
| 285 | |
| 286 | void acpi_irq_stats_init(void) |
| 287 | { |
| 288 | int i; |
| 289 | |
| 290 | if (all_counters) |
| 291 | return; |
| 292 | |
| 293 | num_gpes = count_num_gpes(); |
| 294 | num_counters = num_gpes + ACPI_NUM_FIXED_EVENTS + NUM_COUNTERS_EXTRA; |
| 295 | |
| 296 | all_attrs = kzalloc(sizeof(struct attribute *) * (num_counters + 1), |
| 297 | GFP_KERNEL); |
| 298 | if (all_attrs == NULL) |
| 299 | return; |
| 300 | |
| 301 | all_counters = kzalloc(sizeof(u32) * (num_counters), GFP_KERNEL); |
| 302 | if (all_counters == NULL) |
| 303 | goto fail; |
| 304 | |
| 305 | counter_attrs = kzalloc(sizeof(struct kobj_attribute) * (num_counters), |
| 306 | GFP_KERNEL); |
| 307 | if (counter_attrs == NULL) |
| 308 | goto fail; |
| 309 | |
| 310 | for (i = 0; i < num_counters; ++i) { |
Johann Felix Soden | c8dc9de | 2008-03-11 16:44:26 +0100 | [diff] [blame] | 311 | char buffer[12]; |
Len Brown | 5229e87 | 2008-02-06 01:26:55 -0500 | [diff] [blame] | 312 | char *name; |
| 313 | |
| 314 | if (i < num_gpes) |
| 315 | sprintf(buffer, "gpe%02X", i); |
| 316 | else if (i == num_gpes + ACPI_EVENT_PMTIMER) |
| 317 | sprintf(buffer, "ff_pmtimer"); |
| 318 | else if (i == num_gpes + ACPI_EVENT_GLOBAL) |
| 319 | sprintf(buffer, "ff_gbl_lock"); |
| 320 | else if (i == num_gpes + ACPI_EVENT_POWER_BUTTON) |
| 321 | sprintf(buffer, "ff_pwr_btn"); |
| 322 | else if (i == num_gpes + ACPI_EVENT_SLEEP_BUTTON) |
| 323 | sprintf(buffer, "ff_slp_btn"); |
| 324 | else if (i == num_gpes + ACPI_EVENT_RTC) |
| 325 | sprintf(buffer, "ff_rt_clk"); |
| 326 | else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_GPE) |
| 327 | sprintf(buffer, "gpe_all"); |
| 328 | else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI) |
| 329 | sprintf(buffer, "sci"); |
| 330 | else if (i == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_ERROR) |
| 331 | sprintf(buffer, "error"); |
| 332 | else |
| 333 | sprintf(buffer, "bug%02X", i); |
| 334 | |
| 335 | name = kzalloc(strlen(buffer) + 1, GFP_KERNEL); |
| 336 | if (name == NULL) |
| 337 | goto fail; |
| 338 | strncpy(name, buffer, strlen(buffer) + 1); |
| 339 | |
| 340 | counter_attrs[i].attr.name = name; |
| 341 | counter_attrs[i].attr.mode = 0644; |
| 342 | counter_attrs[i].show = counter_show; |
| 343 | counter_attrs[i].store = counter_set; |
| 344 | |
| 345 | all_attrs[i] = &counter_attrs[i].attr; |
| 346 | } |
| 347 | |
| 348 | interrupt_stats_attr_group.attrs = all_attrs; |
Len Brown | b714315 | 2008-02-07 04:24:01 -0500 | [diff] [blame] | 349 | if (!sysfs_create_group(acpi_kobj, &interrupt_stats_attr_group)) |
| 350 | return; |
Len Brown | 5229e87 | 2008-02-06 01:26:55 -0500 | [diff] [blame] | 351 | |
| 352 | fail: |
| 353 | delete_gpe_attr_array(); |
| 354 | return; |
| 355 | } |
| 356 | |
| 357 | static void __exit interrupt_stats_exit(void) |
| 358 | { |
| 359 | sysfs_remove_group(acpi_kobj, &interrupt_stats_attr_group); |
| 360 | |
| 361 | delete_gpe_attr_array(); |
| 362 | |
| 363 | return; |
| 364 | } |
| 365 | |
Zhang Rui | d4c5f04 | 2007-06-14 17:43:07 +0800 | [diff] [blame] | 366 | /* -------------------------------------------------------------------------- |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | FS Interface (/proc) |
| 368 | -------------------------------------------------------------------------- */ |
Zhang Rui | 5bb730f | 2007-01-29 11:02:42 +0800 | [diff] [blame] | 369 | #ifdef CONFIG_ACPI_PROCFS |
Zhang Rui | d4c5f04 | 2007-06-14 17:43:07 +0800 | [diff] [blame] | 370 | #define ACPI_SYSTEM_FILE_INFO "info" |
| 371 | #define ACPI_SYSTEM_FILE_EVENT "event" |
| 372 | #define ACPI_SYSTEM_FILE_DSDT "dsdt" |
| 373 | #define ACPI_SYSTEM_FILE_FADT "fadt" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 375 | static int acpi_system_read_info(struct seq_file *seq, void *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | |
| 378 | seq_printf(seq, "version: %x\n", ACPI_CA_VERSION); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 379 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | static int acpi_system_info_open_fs(struct inode *inode, struct file *file) |
| 383 | { |
| 384 | return single_open(file, acpi_system_read_info, PDE(inode)->data); |
| 385 | } |
| 386 | |
Arjan van de Ven | d750803 | 2006-07-04 13:06:00 -0400 | [diff] [blame] | 387 | static const struct file_operations acpi_system_info_ops = { |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 388 | .owner = THIS_MODULE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 389 | .open = acpi_system_info_open_fs, |
| 390 | .read = seq_read, |
| 391 | .llseek = seq_lseek, |
| 392 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | }; |
| 394 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 395 | static ssize_t acpi_system_read_dsdt(struct file *, char __user *, size_t, |
| 396 | loff_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | |
Arjan van de Ven | d750803 | 2006-07-04 13:06:00 -0400 | [diff] [blame] | 398 | static const struct file_operations acpi_system_dsdt_ops = { |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 399 | .owner = THIS_MODULE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 400 | .read = acpi_system_read_dsdt, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | }; |
| 402 | |
| 403 | static ssize_t |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 404 | acpi_system_read_dsdt(struct file *file, |
| 405 | char __user * buffer, size_t count, loff_t * ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 407 | acpi_status status = AE_OK; |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 408 | struct acpi_table_header *dsdt = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 409 | ssize_t res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 411 | status = acpi_get_table(ACPI_SIG_DSDT, 1, &dsdt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | if (ACPI_FAILURE(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 413 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
Zhang Rui | d4c5f04 | 2007-06-14 17:43:07 +0800 | [diff] [blame] | 415 | res = simple_read_from_buffer(buffer, count, ppos, dsdt, dsdt->length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 417 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | } |
| 419 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 420 | static ssize_t acpi_system_read_fadt(struct file *, char __user *, size_t, |
| 421 | loff_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | |
Arjan van de Ven | d750803 | 2006-07-04 13:06:00 -0400 | [diff] [blame] | 423 | static const struct file_operations acpi_system_fadt_ops = { |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 424 | .owner = THIS_MODULE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 425 | .read = acpi_system_read_fadt, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | }; |
| 427 | |
| 428 | static ssize_t |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 429 | acpi_system_read_fadt(struct file *file, |
| 430 | char __user * buffer, size_t count, loff_t * ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 432 | acpi_status status = AE_OK; |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 433 | struct acpi_table_header *fadt = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 434 | ssize_t res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 436 | status = acpi_get_table(ACPI_SIG_FADT, 1, &fadt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | if (ACPI_FAILURE(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 438 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | |
Zhang Rui | d4c5f04 | 2007-06-14 17:43:07 +0800 | [diff] [blame] | 440 | res = simple_read_from_buffer(buffer, count, ppos, fadt, fadt->length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 442 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | } |
| 444 | |
Zhang Rui | d4c5f04 | 2007-06-14 17:43:07 +0800 | [diff] [blame] | 445 | static int acpi_system_procfs_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 447 | struct proc_dir_entry *entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | int error = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | /* 'info' [R] */ |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 451 | entry = proc_create(ACPI_SYSTEM_FILE_INFO, S_IRUGO, acpi_root_dir, |
| 452 | &acpi_system_info_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | if (!entry) |
| 454 | goto Error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | |
| 456 | /* 'dsdt' [R] */ |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 457 | entry = proc_create(ACPI_SYSTEM_FILE_DSDT, S_IRUSR, acpi_root_dir, |
| 458 | &acpi_system_dsdt_ops); |
| 459 | if (!entry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | goto Error; |
| 461 | |
| 462 | /* 'fadt' [R] */ |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 463 | entry = proc_create(ACPI_SYSTEM_FILE_FADT, S_IRUSR, acpi_root_dir, |
| 464 | &acpi_system_fadt_ops); |
| 465 | if (!entry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | goto Error; |
| 467 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 468 | Done: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 469 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 471 | Error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | remove_proc_entry(ACPI_SYSTEM_FILE_FADT, acpi_root_dir); |
| 473 | remove_proc_entry(ACPI_SYSTEM_FILE_DSDT, acpi_root_dir); |
| 474 | remove_proc_entry(ACPI_SYSTEM_FILE_INFO, acpi_root_dir); |
| 475 | |
| 476 | error = -EFAULT; |
| 477 | goto Done; |
| 478 | } |
Zhang Rui | d4c5f04 | 2007-06-14 17:43:07 +0800 | [diff] [blame] | 479 | #else |
| 480 | static int acpi_system_procfs_init(void) |
| 481 | { |
| 482 | return 0; |
| 483 | } |
| 484 | #endif |
| 485 | |
| 486 | static int __init acpi_system_init(void) |
| 487 | { |
| 488 | int result = 0; |
| 489 | |
| 490 | if (acpi_disabled) |
| 491 | return 0; |
| 492 | |
| 493 | result = acpi_system_procfs_init(); |
| 494 | if (result) |
| 495 | return result; |
| 496 | |
| 497 | result = acpi_system_sysfs_init(); |
| 498 | |
| 499 | return result; |
| 500 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | subsys_initcall(acpi_system_init); |