| 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 | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 34 | ACPI_MODULE_NAME("acpi_system") | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #define ACPI_SYSTEM_CLASS		"system" | 
|  | 36 | #define ACPI_SYSTEM_DRIVER_NAME		"ACPI System Driver" | 
|  | 37 | #define ACPI_SYSTEM_DEVICE_NAME		"System" | 
|  | 38 | #define ACPI_SYSTEM_FILE_INFO		"info" | 
|  | 39 | #define ACPI_SYSTEM_FILE_EVENT		"event" | 
|  | 40 | #define ACPI_SYSTEM_FILE_DSDT		"dsdt" | 
|  | 41 | #define ACPI_SYSTEM_FILE_FADT		"fadt" | 
| Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 42 | extern struct fadt_descriptor acpi_fadt; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 |  | 
|  | 44 | /* -------------------------------------------------------------------------- | 
|  | 45 | FS Interface (/proc) | 
|  | 46 | -------------------------------------------------------------------------- */ | 
|  | 47 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 48 | static int acpi_system_read_info(struct seq_file *seq, void *offset) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 |  | 
|  | 51 | seq_printf(seq, "version:                 %x\n", ACPI_CA_VERSION); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 52 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | } | 
|  | 54 |  | 
|  | 55 | static int acpi_system_info_open_fs(struct inode *inode, struct file *file) | 
|  | 56 | { | 
|  | 57 | return single_open(file, acpi_system_read_info, PDE(inode)->data); | 
|  | 58 | } | 
|  | 59 |  | 
| Arjan van de Ven | d750803 | 2006-07-04 13:06:00 -0400 | [diff] [blame] | 60 | static const struct file_operations acpi_system_info_ops = { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 61 | .open = acpi_system_info_open_fs, | 
|  | 62 | .read = seq_read, | 
|  | 63 | .llseek = seq_lseek, | 
|  | 64 | .release = single_release, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | }; | 
|  | 66 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 67 | static ssize_t acpi_system_read_dsdt(struct file *, char __user *, size_t, | 
|  | 68 | loff_t *); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 |  | 
| Arjan van de Ven | d750803 | 2006-07-04 13:06:00 -0400 | [diff] [blame] | 70 | static const struct file_operations acpi_system_dsdt_ops = { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 71 | .read = acpi_system_read_dsdt, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | }; | 
|  | 73 |  | 
|  | 74 | static ssize_t | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 75 | acpi_system_read_dsdt(struct file *file, | 
|  | 76 | char __user * buffer, size_t count, loff_t * ppos) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 78 | acpi_status status = AE_OK; | 
|  | 79 | struct acpi_buffer dsdt = { ACPI_ALLOCATE_BUFFER, NULL }; | 
|  | 80 | ssize_t res; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 83 | status = acpi_get_table(ACPI_TABLE_ID_DSDT, 1, &dsdt); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | if (ACPI_FAILURE(status)) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 85 | return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 |  | 
|  | 87 | res = simple_read_from_buffer(buffer, count, ppos, | 
|  | 88 | dsdt.pointer, dsdt.length); | 
| Len Brown | 02438d8 | 2006-06-30 03:19:10 -0400 | [diff] [blame] | 89 | kfree(dsdt.pointer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 91 | return res; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | } | 
|  | 93 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 94 | static ssize_t acpi_system_read_fadt(struct file *, char __user *, size_t, | 
|  | 95 | loff_t *); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 |  | 
| Arjan van de Ven | d750803 | 2006-07-04 13:06:00 -0400 | [diff] [blame] | 97 | static const struct file_operations acpi_system_fadt_ops = { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 98 | .read = acpi_system_read_fadt, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | }; | 
|  | 100 |  | 
|  | 101 | static ssize_t | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 102 | acpi_system_read_fadt(struct file *file, | 
|  | 103 | char __user * buffer, size_t count, loff_t * ppos) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 105 | acpi_status status = AE_OK; | 
|  | 106 | struct acpi_buffer fadt = { ACPI_ALLOCATE_BUFFER, NULL }; | 
|  | 107 | ssize_t res; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 110 | status = acpi_get_table(ACPI_TABLE_ID_FADT, 1, &fadt); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | if (ACPI_FAILURE(status)) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 112 | return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 |  | 
|  | 114 | res = simple_read_from_buffer(buffer, count, ppos, | 
|  | 115 | fadt.pointer, fadt.length); | 
| Len Brown | 02438d8 | 2006-06-30 03:19:10 -0400 | [diff] [blame] | 116 | kfree(fadt.pointer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 118 | return res; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | } | 
|  | 120 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 121 | static int __init acpi_system_init(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 123 | struct proc_dir_entry *entry; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | int error = 0; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 125 | char *name; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 |  | 
|  | 128 | if (acpi_disabled) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 129 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 |  | 
|  | 131 | /* 'info' [R] */ | 
|  | 132 | name = ACPI_SYSTEM_FILE_INFO; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 133 | entry = create_proc_entry(name, S_IRUGO, acpi_root_dir); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | if (!entry) | 
|  | 135 | goto Error; | 
|  | 136 | else { | 
|  | 137 | entry->proc_fops = &acpi_system_info_ops; | 
|  | 138 | } | 
|  | 139 |  | 
|  | 140 | /* 'dsdt' [R] */ | 
|  | 141 | name = ACPI_SYSTEM_FILE_DSDT; | 
|  | 142 | entry = create_proc_entry(name, S_IRUSR, acpi_root_dir); | 
|  | 143 | if (entry) | 
|  | 144 | entry->proc_fops = &acpi_system_dsdt_ops; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 145 | else | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | goto Error; | 
|  | 147 |  | 
|  | 148 | /* 'fadt' [R] */ | 
|  | 149 | name = ACPI_SYSTEM_FILE_FADT; | 
|  | 150 | entry = create_proc_entry(name, S_IRUSR, acpi_root_dir); | 
|  | 151 | if (entry) | 
|  | 152 | entry->proc_fops = &acpi_system_fadt_ops; | 
|  | 153 | else | 
|  | 154 | goto Error; | 
|  | 155 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 156 | Done: | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 157 | return error; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 159 | Error: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | remove_proc_entry(ACPI_SYSTEM_FILE_FADT, acpi_root_dir); | 
|  | 161 | remove_proc_entry(ACPI_SYSTEM_FILE_DSDT, acpi_root_dir); | 
|  | 162 | remove_proc_entry(ACPI_SYSTEM_FILE_INFO, acpi_root_dir); | 
|  | 163 |  | 
|  | 164 | error = -EFAULT; | 
|  | 165 | goto Done; | 
|  | 166 | } | 
|  | 167 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | subsys_initcall(acpi_system_init); |