blob: c90bd2f70b3fa0b9df9297ec5293f21533fd2351 [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"
Bob Moore793c2382006-03-31 00:00:00 -050042extern struct fadt_descriptor acpi_fadt;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44/* --------------------------------------------------------------------------
45 FS Interface (/proc)
46 -------------------------------------------------------------------------- */
47
Len Brown4be44fc2005-08-05 00:44:28 -040048static int acpi_system_read_info(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049{
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51 seq_printf(seq, "version: %x\n", ACPI_CA_VERSION);
Patrick Mocheld550d982006-06-27 00:41:40 -040052 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053}
54
55static 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
60static struct file_operations acpi_system_info_ops = {
Len Brown4be44fc2005-08-05 00:44:28 -040061 .open = acpi_system_info_open_fs,
62 .read = seq_read,
63 .llseek = seq_lseek,
64 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -070065};
66
Len Brown4be44fc2005-08-05 00:44:28 -040067static ssize_t acpi_system_read_dsdt(struct file *, char __user *, size_t,
68 loff_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70static struct file_operations acpi_system_dsdt_ops = {
Len Brown4be44fc2005-08-05 00:44:28 -040071 .read = acpi_system_read_dsdt,
Linus Torvalds1da177e2005-04-16 15:20:36 -070072};
73
74static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -040075acpi_system_read_dsdt(struct file *file,
76 char __user * buffer, size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077{
Len Brown4be44fc2005-08-05 00:44:28 -040078 acpi_status status = AE_OK;
79 struct acpi_buffer dsdt = { ACPI_ALLOCATE_BUFFER, NULL };
80 ssize_t res;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Bob Mooreb229cf92006-04-21 17:15:00 -040083 status = acpi_get_table(ACPI_TABLE_ID_DSDT, 1, &dsdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -040085 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87 res = simple_read_from_buffer(buffer, count, ppos,
88 dsdt.pointer, dsdt.length);
89 acpi_os_free(dsdt.pointer);
90
Patrick Mocheld550d982006-06-27 00:41:40 -040091 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092}
93
Len Brown4be44fc2005-08-05 00:44:28 -040094static ssize_t acpi_system_read_fadt(struct file *, char __user *, size_t,
95 loff_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
97static struct file_operations acpi_system_fadt_ops = {
Len Brown4be44fc2005-08-05 00:44:28 -040098 .read = acpi_system_read_fadt,
Linus Torvalds1da177e2005-04-16 15:20:36 -070099};
100
101static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400102acpi_system_read_fadt(struct file *file,
103 char __user * buffer, size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104{
Len Brown4be44fc2005-08-05 00:44:28 -0400105 acpi_status status = AE_OK;
106 struct acpi_buffer fadt = { ACPI_ALLOCATE_BUFFER, NULL };
107 ssize_t res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Bob Mooreb229cf92006-04-21 17:15:00 -0400110 status = acpi_get_table(ACPI_TABLE_ID_FADT, 1, &fadt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400112 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114 res = simple_read_from_buffer(buffer, count, ppos,
115 fadt.pointer, fadt.length);
116 acpi_os_free(fadt.pointer);
117
Patrick Mocheld550d982006-06-27 00:41:40 -0400118 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119}
120
Len Brown4be44fc2005-08-05 00:44:28 -0400121static int __init acpi_system_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122{
Len Brown4be44fc2005-08-05 00:44:28 -0400123 struct proc_dir_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 int error = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400125 char *name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128 if (acpi_disabled)
Patrick Mocheld550d982006-06-27 00:41:40 -0400129 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
131 /* 'info' [R] */
132 name = ACPI_SYSTEM_FILE_INFO;
Len Brown4be44fc2005-08-05 00:44:28 -0400133 entry = create_proc_entry(name, S_IRUGO, acpi_root_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 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 Brown4be44fc2005-08-05 00:44:28 -0400145 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 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 Brown4be44fc2005-08-05 00:44:28 -0400156 Done:
Patrick Mocheld550d982006-06-27 00:41:40 -0400157 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
Len Brown4be44fc2005-08-05 00:44:28 -0400159 Error:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 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 Torvalds1da177e2005-04-16 15:20:36 -0700168subsys_initcall(acpi_system_init);