system.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. #include <linux/proc_fs.h>
  26. #include <linux/seq_file.h>
  27. #include <linux/init.h>
  28. #include <asm/uaccess.h>
  29. #include <acpi/acpi_drivers.h>
  30. #define _COMPONENT ACPI_SYSTEM_COMPONENT
  31. ACPI_MODULE_NAME("system");
  32. #ifdef MODULE_PARAM_PREFIX
  33. #undef MODULE_PARAM_PREFIX
  34. #endif
  35. #define MODULE_PARAM_PREFIX "acpi."
  36. #define ACPI_SYSTEM_CLASS "system"
  37. #define ACPI_SYSTEM_DEVICE_NAME "System"
  38. /*
  39. * Make ACPICA version work as module param
  40. */
  41. static int param_get_acpica_version(char *buffer, struct kernel_param *kp)
  42. {
  43. int result;
  44. result = sprintf(buffer, "%x", ACPI_CA_VERSION);
  45. return result;
  46. }
  47. module_param_call(acpica_version, NULL, param_get_acpica_version, NULL, 0444);
  48. /* --------------------------------------------------------------------------
  49. FS Interface (/sys)
  50. -------------------------------------------------------------------------- */
  51. static LIST_HEAD(acpi_table_attr_list);
  52. static struct kobject tables_kobj;
  53. struct acpi_table_attr {
  54. struct bin_attribute attr;
  55. char name[8];
  56. int instance;
  57. struct list_head node;
  58. };
  59. static ssize_t acpi_table_show(struct kobject *kobj,
  60. struct bin_attribute *bin_attr, char *buf,
  61. loff_t offset, size_t count)
  62. {
  63. struct acpi_table_attr *table_attr =
  64. container_of(bin_attr, struct acpi_table_attr, attr);
  65. struct acpi_table_header *table_header = NULL;
  66. acpi_status status;
  67. ssize_t ret_count = count;
  68. status =
  69. acpi_get_table(table_attr->name, table_attr->instance,
  70. &table_header);
  71. if (ACPI_FAILURE(status))
  72. return -ENODEV;
  73. if (offset >= table_header->length) {
  74. ret_count = 0;
  75. goto end;
  76. }
  77. if (offset + ret_count > table_header->length)
  78. ret_count = table_header->length - offset;
  79. memcpy(buf, ((char *)table_header) + offset, ret_count);
  80. end:
  81. return ret_count;
  82. }
  83. static void acpi_table_attr_init(struct acpi_table_attr *table_attr,
  84. struct acpi_table_header *table_header)
  85. {
  86. struct acpi_table_header *header = NULL;
  87. struct acpi_table_attr *attr = NULL;
  88. memcpy(table_attr->name, table_header->signature, ACPI_NAME_SIZE);
  89. list_for_each_entry(attr, &acpi_table_attr_list, node) {
  90. if (!memcmp(table_header->signature, attr->name,
  91. ACPI_NAME_SIZE))
  92. if (table_attr->instance < attr->instance)
  93. table_attr->instance = attr->instance;
  94. }
  95. table_attr->instance++;
  96. if (table_attr->instance > 1 || (table_attr->instance == 1 &&
  97. !acpi_get_table(table_header->
  98. signature, 2,
  99. &header)))
  100. sprintf(table_attr->name + 4, "%d", table_attr->instance);
  101. table_attr->attr.size = 0;
  102. table_attr->attr.read = acpi_table_show;
  103. table_attr->attr.attr.name = table_attr->name;
  104. table_attr->attr.attr.mode = 0444;
  105. table_attr->attr.attr.owner = THIS_MODULE;
  106. return;
  107. }
  108. static int acpi_system_sysfs_init(void)
  109. {
  110. struct acpi_table_attr *table_attr;
  111. struct acpi_table_header *table_header = NULL;
  112. int table_index = 0;
  113. int result;
  114. tables_kobj.parent = &acpi_subsys.kobj;
  115. kobject_set_name(&tables_kobj, "tables");
  116. result = kobject_register(&tables_kobj);
  117. if (result)
  118. return result;
  119. do {
  120. result = acpi_get_table_by_index(table_index, &table_header);
  121. if (!result) {
  122. table_index++;
  123. table_attr = NULL;
  124. table_attr =
  125. kzalloc(sizeof(struct acpi_table_attr), GFP_KERNEL);
  126. if (!table_attr)
  127. return -ENOMEM;
  128. acpi_table_attr_init(table_attr, table_header);
  129. result =
  130. sysfs_create_bin_file(&tables_kobj,
  131. &table_attr->attr);
  132. if (result) {
  133. kfree(table_attr);
  134. return result;
  135. } else
  136. list_add_tail(&table_attr->node,
  137. &acpi_table_attr_list);
  138. }
  139. } while (!result);
  140. return 0;
  141. }
  142. /* --------------------------------------------------------------------------
  143. FS Interface (/proc)
  144. -------------------------------------------------------------------------- */
  145. #ifdef CONFIG_ACPI_PROCFS
  146. #define ACPI_SYSTEM_FILE_INFO "info"
  147. #define ACPI_SYSTEM_FILE_EVENT "event"
  148. #define ACPI_SYSTEM_FILE_DSDT "dsdt"
  149. #define ACPI_SYSTEM_FILE_FADT "fadt"
  150. static int acpi_system_read_info(struct seq_file *seq, void *offset)
  151. {
  152. seq_printf(seq, "version: %x\n", ACPI_CA_VERSION);
  153. return 0;
  154. }
  155. static int acpi_system_info_open_fs(struct inode *inode, struct file *file)
  156. {
  157. return single_open(file, acpi_system_read_info, PDE(inode)->data);
  158. }
  159. static const struct file_operations acpi_system_info_ops = {
  160. .open = acpi_system_info_open_fs,
  161. .read = seq_read,
  162. .llseek = seq_lseek,
  163. .release = single_release,
  164. };
  165. static ssize_t acpi_system_read_dsdt(struct file *, char __user *, size_t,
  166. loff_t *);
  167. static const struct file_operations acpi_system_dsdt_ops = {
  168. .read = acpi_system_read_dsdt,
  169. };
  170. static ssize_t
  171. acpi_system_read_dsdt(struct file *file,
  172. char __user * buffer, size_t count, loff_t * ppos)
  173. {
  174. acpi_status status = AE_OK;
  175. struct acpi_table_header *dsdt = NULL;
  176. ssize_t res;
  177. status = acpi_get_table(ACPI_SIG_DSDT, 1, &dsdt);
  178. if (ACPI_FAILURE(status))
  179. return -ENODEV;
  180. res = simple_read_from_buffer(buffer, count, ppos, dsdt, dsdt->length);
  181. return res;
  182. }
  183. static ssize_t acpi_system_read_fadt(struct file *, char __user *, size_t,
  184. loff_t *);
  185. static const struct file_operations acpi_system_fadt_ops = {
  186. .read = acpi_system_read_fadt,
  187. };
  188. static ssize_t
  189. acpi_system_read_fadt(struct file *file,
  190. char __user * buffer, size_t count, loff_t * ppos)
  191. {
  192. acpi_status status = AE_OK;
  193. struct acpi_table_header *fadt = NULL;
  194. ssize_t res;
  195. status = acpi_get_table(ACPI_SIG_FADT, 1, &fadt);
  196. if (ACPI_FAILURE(status))
  197. return -ENODEV;
  198. res = simple_read_from_buffer(buffer, count, ppos, fadt, fadt->length);
  199. return res;
  200. }
  201. static int acpi_system_procfs_init(void)
  202. {
  203. struct proc_dir_entry *entry;
  204. int error = 0;
  205. char *name;
  206. /* 'info' [R] */
  207. name = ACPI_SYSTEM_FILE_INFO;
  208. entry = create_proc_entry(name, S_IRUGO, acpi_root_dir);
  209. if (!entry)
  210. goto Error;
  211. else {
  212. entry->proc_fops = &acpi_system_info_ops;
  213. }
  214. /* 'dsdt' [R] */
  215. name = ACPI_SYSTEM_FILE_DSDT;
  216. entry = create_proc_entry(name, S_IRUSR, acpi_root_dir);
  217. if (entry)
  218. entry->proc_fops = &acpi_system_dsdt_ops;
  219. else
  220. goto Error;
  221. /* 'fadt' [R] */
  222. name = ACPI_SYSTEM_FILE_FADT;
  223. entry = create_proc_entry(name, S_IRUSR, acpi_root_dir);
  224. if (entry)
  225. entry->proc_fops = &acpi_system_fadt_ops;
  226. else
  227. goto Error;
  228. Done:
  229. return error;
  230. Error:
  231. remove_proc_entry(ACPI_SYSTEM_FILE_FADT, acpi_root_dir);
  232. remove_proc_entry(ACPI_SYSTEM_FILE_DSDT, acpi_root_dir);
  233. remove_proc_entry(ACPI_SYSTEM_FILE_INFO, acpi_root_dir);
  234. error = -EFAULT;
  235. goto Done;
  236. }
  237. #else
  238. static int acpi_system_procfs_init(void)
  239. {
  240. return 0;
  241. }
  242. #endif
  243. static int __init acpi_system_init(void)
  244. {
  245. int result = 0;
  246. if (acpi_disabled)
  247. return 0;
  248. result = acpi_system_procfs_init();
  249. if (result)
  250. return result;
  251. result = acpi_system_sysfs_init();
  252. return result;
  253. }
  254. subsys_initcall(acpi_system_init);