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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 28 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/init.h> |
Akinobu Mita | e108526 | 2008-07-23 21:26:44 -0700 | [diff] [blame] | 30 | #include <linux/string.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <asm/uaccess.h> |
| 32 | |
| 33 | #include <acpi/acpi_drivers.h> |
| 34 | |
Len Brown | a192a95 | 2009-07-28 16:45:54 -0400 | [diff] [blame] | 35 | #define PREFIX "ACPI: " |
| 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #define _COMPONENT ACPI_SYSTEM_COMPONENT |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 38 | ACPI_MODULE_NAME("system"); |
Zhang Rui | 5bb730f | 2007-01-29 11:02:42 +0800 | [diff] [blame] | 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 | |
Zhang Rui | d4c5f04 | 2007-06-14 17:43:07 +0800 | [diff] [blame] | 43 | /* -------------------------------------------------------------------------- |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | FS Interface (/proc) |
| 45 | -------------------------------------------------------------------------- */ |
Zhang Rui | 5bb730f | 2007-01-29 11:02:42 +0800 | [diff] [blame] | 46 | #ifdef CONFIG_ACPI_PROCFS |
Zhang Rui | d4c5f04 | 2007-06-14 17:43:07 +0800 | [diff] [blame] | 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" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 52 | static int acpi_system_read_info(struct seq_file *seq, void *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | seq_printf(seq, "version: %x\n", ACPI_CA_VERSION); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 56 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Arjan van de Ven | d750803 | 2006-07-04 13:06:00 -0400 | [diff] [blame] | 64 | static const struct file_operations acpi_system_info_ops = { |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 65 | .owner = THIS_MODULE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 66 | .open = acpi_system_info_open_fs, |
| 67 | .read = seq_read, |
| 68 | .llseek = seq_lseek, |
| 69 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | }; |
| 71 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 72 | static ssize_t acpi_system_read_dsdt(struct file *, char __user *, size_t, |
| 73 | loff_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
Arjan van de Ven | d750803 | 2006-07-04 13:06:00 -0400 | [diff] [blame] | 75 | static const struct file_operations acpi_system_dsdt_ops = { |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 76 | .owner = THIS_MODULE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 77 | .read = acpi_system_read_dsdt, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | static ssize_t |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 81 | acpi_system_read_dsdt(struct file *file, |
| 82 | char __user * buffer, size_t count, loff_t * ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 84 | acpi_status status = AE_OK; |
Alexey Starikovskiy | ad71860 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 85 | struct acpi_table_header *dsdt = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 86 | ssize_t res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
Alexey Starikovskiy | ad71860 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 88 | status = acpi_get_table(ACPI_SIG_DSDT, 1, &dsdt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | if (ACPI_FAILURE(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 90 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Zhang Rui | d4c5f04 | 2007-06-14 17:43:07 +0800 | [diff] [blame] | 92 | res = simple_read_from_buffer(buffer, count, ppos, dsdt, dsdt->length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 94 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 97 | static ssize_t acpi_system_read_fadt(struct file *, char __user *, size_t, |
| 98 | loff_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
Arjan van de Ven | d750803 | 2006-07-04 13:06:00 -0400 | [diff] [blame] | 100 | static const struct file_operations acpi_system_fadt_ops = { |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 101 | .owner = THIS_MODULE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 102 | .read = acpi_system_read_fadt, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | static ssize_t |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 106 | acpi_system_read_fadt(struct file *file, |
| 107 | char __user * buffer, size_t count, loff_t * ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 109 | acpi_status status = AE_OK; |
Alexey Starikovskiy | ad71860 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 110 | struct acpi_table_header *fadt = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 111 | ssize_t res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
Alexey Starikovskiy | ad71860 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 113 | status = acpi_get_table(ACPI_SIG_FADT, 1, &fadt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | if (ACPI_FAILURE(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 115 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
Zhang Rui | d4c5f04 | 2007-06-14 17:43:07 +0800 | [diff] [blame] | 117 | res = simple_read_from_buffer(buffer, count, ppos, fadt, fadt->length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 119 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Zhang Rui | d4c5f04 | 2007-06-14 17:43:07 +0800 | [diff] [blame] | 122 | static int acpi_system_procfs_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 124 | struct proc_dir_entry *entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | int error = 0; |
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 | /* 'info' [R] */ |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 128 | entry = proc_create(ACPI_SYSTEM_FILE_INFO, S_IRUGO, acpi_root_dir, |
| 129 | &acpi_system_info_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | if (!entry) |
| 131 | goto Error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
| 133 | /* 'dsdt' [R] */ |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 134 | entry = proc_create(ACPI_SYSTEM_FILE_DSDT, S_IRUSR, acpi_root_dir, |
| 135 | &acpi_system_dsdt_ops); |
| 136 | if (!entry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | goto Error; |
| 138 | |
| 139 | /* 'fadt' [R] */ |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 140 | entry = proc_create(ACPI_SYSTEM_FILE_FADT, S_IRUSR, acpi_root_dir, |
| 141 | &acpi_system_fadt_ops); |
| 142 | if (!entry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | goto Error; |
| 144 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 145 | Done: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 146 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 148 | Error: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | } |
Zhang Rui | d4c5f04 | 2007-06-14 17:43:07 +0800 | [diff] [blame] | 156 | #else |
| 157 | static int acpi_system_procfs_init(void) |
| 158 | { |
| 159 | return 0; |
| 160 | } |
| 161 | #endif |
| 162 | |
Bjorn Helgaas | 141a0af | 2009-03-24 16:49:58 -0600 | [diff] [blame] | 163 | int __init acpi_system_init(void) |
Zhang Rui | d4c5f04 | 2007-06-14 17:43:07 +0800 | [diff] [blame] | 164 | { |
Bjorn Helgaas | 141a0af | 2009-03-24 16:49:58 -0600 | [diff] [blame] | 165 | int result; |
Zhang Rui | d4c5f04 | 2007-06-14 17:43:07 +0800 | [diff] [blame] | 166 | |
| 167 | result = acpi_system_procfs_init(); |
Zhang Rui | d4c5f04 | 2007-06-14 17:43:07 +0800 | [diff] [blame] | 168 | |
| 169 | return result; |
| 170 | } |