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