| 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" | 
|  | 42 | #define ACPI_SYSTEM_FILE_INFO		"info" | 
|  | 43 | #define ACPI_SYSTEM_FILE_EVENT		"event" | 
|  | 44 | #define ACPI_SYSTEM_FILE_DSDT		"dsdt" | 
|  | 45 | #define ACPI_SYSTEM_FILE_FADT		"fadt" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 |  | 
| Zhang Rui | 5bb730f | 2007-01-29 11:02:42 +0800 | [diff] [blame] | 47 | /* | 
|  | 48 | * Make ACPICA version work as module param | 
|  | 49 | */ | 
|  | 50 | static int param_get_acpica_version(char *buffer, struct kernel_param *kp) { | 
|  | 51 | int result; | 
|  | 52 |  | 
|  | 53 | result = sprintf(buffer, "%x", ACPI_CA_VERSION); | 
|  | 54 |  | 
|  | 55 | return result; | 
|  | 56 | } | 
|  | 57 |  | 
|  | 58 | module_param_call(acpica_version, NULL, param_get_acpica_version, NULL, 0444); | 
|  | 59 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | /* -------------------------------------------------------------------------- | 
|  | 61 | FS Interface (/proc) | 
|  | 62 | -------------------------------------------------------------------------- */ | 
| Zhang Rui | 5bb730f | 2007-01-29 11:02:42 +0800 | [diff] [blame] | 63 | #ifdef CONFIG_ACPI_PROCFS | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 65 | static int acpi_system_read_info(struct seq_file *seq, void *offset) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 |  | 
|  | 68 | seq_printf(seq, "version:                 %x\n", ACPI_CA_VERSION); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 69 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | } | 
|  | 71 |  | 
|  | 72 | static int acpi_system_info_open_fs(struct inode *inode, struct file *file) | 
|  | 73 | { | 
|  | 74 | return single_open(file, acpi_system_read_info, PDE(inode)->data); | 
|  | 75 | } | 
|  | 76 |  | 
| Arjan van de Ven | d750803 | 2006-07-04 13:06:00 -0400 | [diff] [blame] | 77 | static const struct file_operations acpi_system_info_ops = { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 78 | .open = acpi_system_info_open_fs, | 
|  | 79 | .read = seq_read, | 
|  | 80 | .llseek = seq_lseek, | 
|  | 81 | .release = single_release, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | }; | 
| Zhang Rui | 5bb730f | 2007-01-29 11:02:42 +0800 | [diff] [blame] | 83 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 85 | static ssize_t acpi_system_read_dsdt(struct file *, char __user *, size_t, | 
|  | 86 | loff_t *); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 |  | 
| Arjan van de Ven | d750803 | 2006-07-04 13:06:00 -0400 | [diff] [blame] | 88 | static const struct file_operations acpi_system_dsdt_ops = { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 89 | .read = acpi_system_read_dsdt, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | }; | 
|  | 91 |  | 
|  | 92 | static ssize_t | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 93 | acpi_system_read_dsdt(struct file *file, | 
|  | 94 | char __user * buffer, size_t count, loff_t * ppos) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 96 | acpi_status status = AE_OK; | 
| Alexey Starikovskiy | ad71860 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 97 | struct acpi_table_header *dsdt = NULL; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 98 | ssize_t res; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 |  | 
| Alexey Starikovskiy | ad71860 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 101 | status = acpi_get_table(ACPI_SIG_DSDT, 1, &dsdt); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | if (ACPI_FAILURE(status)) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 103 | return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 |  | 
|  | 105 | res = simple_read_from_buffer(buffer, count, ppos, | 
| Alexey Starikovskiy | ad71860 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 106 | dsdt, dsdt->length); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 108 | return res; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | } | 
|  | 110 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 111 | static ssize_t acpi_system_read_fadt(struct file *, char __user *, size_t, | 
|  | 112 | loff_t *); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 |  | 
| Arjan van de Ven | d750803 | 2006-07-04 13:06:00 -0400 | [diff] [blame] | 114 | static const struct file_operations acpi_system_fadt_ops = { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 115 | .read = acpi_system_read_fadt, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | }; | 
|  | 117 |  | 
|  | 118 | static ssize_t | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 119 | acpi_system_read_fadt(struct file *file, | 
|  | 120 | char __user * buffer, size_t count, loff_t * ppos) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 122 | acpi_status status = AE_OK; | 
| Alexey Starikovskiy | ad71860 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 123 | struct acpi_table_header *fadt = NULL; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 124 | ssize_t res; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 |  | 
| Alexey Starikovskiy | ad71860 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 127 | status = acpi_get_table(ACPI_SIG_FADT, 1, &fadt); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | if (ACPI_FAILURE(status)) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 129 | return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 |  | 
|  | 131 | res = simple_read_from_buffer(buffer, count, ppos, | 
| Alexey Starikovskiy | ad71860 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 132 | fadt, fadt->length); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 134 | return res; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | } | 
|  | 136 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 137 | static int __init acpi_system_init(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 139 | struct proc_dir_entry *entry; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | int error = 0; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 141 | char *name; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 |  | 
|  | 144 | if (acpi_disabled) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 145 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 |  | 
| Zhang Rui | 5bb730f | 2007-01-29 11:02:42 +0800 | [diff] [blame] | 147 | #ifdef CONFIG_ACPI_PROCFS | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | /* 'info' [R] */ | 
|  | 149 | name = ACPI_SYSTEM_FILE_INFO; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 150 | entry = create_proc_entry(name, S_IRUGO, acpi_root_dir); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | if (!entry) | 
|  | 152 | goto Error; | 
|  | 153 | else { | 
|  | 154 | entry->proc_fops = &acpi_system_info_ops; | 
|  | 155 | } | 
| Zhang Rui | 5bb730f | 2007-01-29 11:02:42 +0800 | [diff] [blame] | 156 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 |  | 
|  | 158 | /* 'dsdt' [R] */ | 
|  | 159 | name = ACPI_SYSTEM_FILE_DSDT; | 
|  | 160 | entry = create_proc_entry(name, S_IRUSR, acpi_root_dir); | 
|  | 161 | if (entry) | 
|  | 162 | entry->proc_fops = &acpi_system_dsdt_ops; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 163 | else | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | goto Error; | 
|  | 165 |  | 
|  | 166 | /* 'fadt' [R] */ | 
|  | 167 | name = ACPI_SYSTEM_FILE_FADT; | 
|  | 168 | entry = create_proc_entry(name, S_IRUSR, acpi_root_dir); | 
|  | 169 | if (entry) | 
|  | 170 | entry->proc_fops = &acpi_system_fadt_ops; | 
|  | 171 | else | 
|  | 172 | goto Error; | 
|  | 173 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 174 | Done: | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 175 | return error; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 177 | Error: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | remove_proc_entry(ACPI_SYSTEM_FILE_FADT, acpi_root_dir); | 
|  | 179 | remove_proc_entry(ACPI_SYSTEM_FILE_DSDT, acpi_root_dir); | 
| Zhang Rui | 5bb730f | 2007-01-29 11:02:42 +0800 | [diff] [blame] | 180 | #ifdef CONFIG_ACPI_PROCFS | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | remove_proc_entry(ACPI_SYSTEM_FILE_INFO, acpi_root_dir); | 
| Zhang Rui | 5bb730f | 2007-01-29 11:02:42 +0800 | [diff] [blame] | 182 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 |  | 
|  | 184 | error = -EFAULT; | 
|  | 185 | goto Done; | 
|  | 186 | } | 
|  | 187 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | subsys_initcall(acpi_system_init); |