blob: 2d425d8458218ca4a417ca54f12d7ff484883be2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Torvalds1da177e2005-04-16 15:20:36 -070033#define _COMPONENT ACPI_SYSTEM_COMPONENT
Len Brown4be44fc2005-08-05 00:44:28 -040034ACPI_MODULE_NAME("acpi_system")
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#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"
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43/* --------------------------------------------------------------------------
44 FS Interface (/proc)
45 -------------------------------------------------------------------------- */
46
Len Brown4be44fc2005-08-05 00:44:28 -040047static int acpi_system_read_info(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070048{
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50 seq_printf(seq, "version: %x\n", ACPI_CA_VERSION);
Patrick Mocheld550d982006-06-27 00:41:40 -040051 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052}
53
54static int acpi_system_info_open_fs(struct inode *inode, struct file *file)
55{
56 return single_open(file, acpi_system_read_info, PDE(inode)->data);
57}
58
Arjan van de Vend7508032006-07-04 13:06:00 -040059static const struct file_operations acpi_system_info_ops = {
Len Brown4be44fc2005-08-05 00:44:28 -040060 .open = acpi_system_info_open_fs,
61 .read = seq_read,
62 .llseek = seq_lseek,
63 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -070064};
65
Len Brown4be44fc2005-08-05 00:44:28 -040066static ssize_t acpi_system_read_dsdt(struct file *, char __user *, size_t,
67 loff_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Arjan van de Vend7508032006-07-04 13:06:00 -040069static const struct file_operations acpi_system_dsdt_ops = {
Len Brown4be44fc2005-08-05 00:44:28 -040070 .read = acpi_system_read_dsdt,
Linus Torvalds1da177e2005-04-16 15:20:36 -070071};
72
73static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -040074acpi_system_read_dsdt(struct file *file,
75 char __user * buffer, size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076{
Len Brown4be44fc2005-08-05 00:44:28 -040077 acpi_status status = AE_OK;
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +030078 struct acpi_table_header *dsdt = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -040079 ssize_t res;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +030082 status = acpi_get_table(ACPI_SIG_DSDT, 1, &dsdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -040084 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
86 res = simple_read_from_buffer(buffer, count, ppos,
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +030087 dsdt, dsdt->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Patrick Mocheld550d982006-06-27 00:41:40 -040089 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090}
91
Len Brown4be44fc2005-08-05 00:44:28 -040092static ssize_t acpi_system_read_fadt(struct file *, char __user *, size_t,
93 loff_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Arjan van de Vend7508032006-07-04 13:06:00 -040095static const struct file_operations acpi_system_fadt_ops = {
Len Brown4be44fc2005-08-05 00:44:28 -040096 .read = acpi_system_read_fadt,
Linus Torvalds1da177e2005-04-16 15:20:36 -070097};
98
99static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400100acpi_system_read_fadt(struct file *file,
101 char __user * buffer, size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102{
Len Brown4be44fc2005-08-05 00:44:28 -0400103 acpi_status status = AE_OK;
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300104 struct acpi_table_header *fadt = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400105 ssize_t res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300108 status = acpi_get_table(ACPI_SIG_FADT, 1, &fadt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400110 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
112 res = simple_read_from_buffer(buffer, count, ppos,
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300113 fadt, fadt->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Patrick Mocheld550d982006-06-27 00:41:40 -0400115 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116}
117
Len Brown4be44fc2005-08-05 00:44:28 -0400118static int __init acpi_system_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119{
Len Brown4be44fc2005-08-05 00:44:28 -0400120 struct proc_dir_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 int error = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400122 char *name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
125 if (acpi_disabled)
Patrick Mocheld550d982006-06-27 00:41:40 -0400126 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128 /* 'info' [R] */
129 name = ACPI_SYSTEM_FILE_INFO;
Len Brown4be44fc2005-08-05 00:44:28 -0400130 entry = create_proc_entry(name, S_IRUGO, acpi_root_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 if (!entry)
132 goto Error;
133 else {
134 entry->proc_fops = &acpi_system_info_ops;
135 }
136
137 /* 'dsdt' [R] */
138 name = ACPI_SYSTEM_FILE_DSDT;
139 entry = create_proc_entry(name, S_IRUSR, acpi_root_dir);
140 if (entry)
141 entry->proc_fops = &acpi_system_dsdt_ops;
Len Brown4be44fc2005-08-05 00:44:28 -0400142 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 goto Error;
144
145 /* 'fadt' [R] */
146 name = ACPI_SYSTEM_FILE_FADT;
147 entry = create_proc_entry(name, S_IRUSR, acpi_root_dir);
148 if (entry)
149 entry->proc_fops = &acpi_system_fadt_ops;
150 else
151 goto Error;
152
Len Brown4be44fc2005-08-05 00:44:28 -0400153 Done:
Patrick Mocheld550d982006-06-27 00:41:40 -0400154 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Len Brown4be44fc2005-08-05 00:44:28 -0400156 Error:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 remove_proc_entry(ACPI_SYSTEM_FILE_FADT, acpi_root_dir);
158 remove_proc_entry(ACPI_SYSTEM_FILE_DSDT, acpi_root_dir);
159 remove_proc_entry(ACPI_SYSTEM_FILE_INFO, acpi_root_dir);
160
161 error = -EFAULT;
162 goto Done;
163}
164
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165subsys_initcall(acpi_system_init);