system.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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 = kobject_create_and_add("tables", acpi_kobj);
  115. if (!tables_kobj)
  116. return -ENOMEM;
  117. do {
  118. result = acpi_get_table_by_index(table_index, &table_header);
  119. if (!result) {
  120. table_index++;
  121. table_attr = NULL;
  122. table_attr =
  123. kzalloc(sizeof(struct acpi_table_attr), GFP_KERNEL);
  124. if (!table_attr)
  125. return -ENOMEM;
  126. acpi_table_attr_init(table_attr, table_header);
  127. result =
  128. sysfs_create_bin_file(tables_kobj,
  129. &table_attr->attr);
  130. if (result) {
  131. kfree(table_attr);
  132. return result;
  133. } else
  134. list_add_tail(&table_attr->node,
  135. &acpi_table_attr_list);
  136. }
  137. } while (!result);
  138. kobject_uevent(tables_kobj, KOBJ_ADD);
  139. return 0;
  140. }
  141. /* --------------------------------------------------------------------------
  142. FS Interface (/proc)
  143. -------------------------------------------------------------------------- */
  144. #ifdef CONFIG_ACPI_PROCFS
  145. #define ACPI_SYSTEM_FILE_INFO "info"
  146. #define ACPI_SYSTEM_FILE_EVENT "event"
  147. #define ACPI_SYSTEM_FILE_DSDT "dsdt"
  148. #define ACPI_SYSTEM_FILE_FADT "fadt"
  149. static int acpi_system_read_info(struct seq_file *seq, void *offset)
  150. {
  151. seq_printf(seq, "version: %x\n", ACPI_CA_VERSION);
  152. return 0;
  153. }
  154. static int acpi_system_info_open_fs(struct inode *inode, struct file *file)
  155. {
  156. return single_open(file, acpi_system_read_info, PDE(inode)->data);
  157. }
  158. static const struct file_operations acpi_system_info_ops = {
  159. .open = acpi_system_info_open_fs,
  160. .read = seq_read,
  161. .llseek = seq_lseek,
  162. .release = single_release,
  163. };
  164. static ssize_t acpi_system_read_dsdt(struct file *, char __user *, size_t,
  165. loff_t *);
  166. static const struct file_operations acpi_system_dsdt_ops = {
  167. .read = acpi_system_read_dsdt,
  168. };
  169. static ssize_t
  170. acpi_system_read_dsdt(struct file *file,
  171. char __user * buffer, size_t count, loff_t * ppos)
  172. {
  173. acpi_status status = AE_OK;
  174. struct acpi_table_header *dsdt = NULL;
  175. ssize_t res;
  176. status = acpi_get_table(ACPI_SIG_DSDT, 1, &dsdt);
  177. if (ACPI_FAILURE(status))
  178. return -ENODEV;
  179. res = simple_read_from_buffer(buffer, count, ppos, dsdt, dsdt->length);
  180. return res;
  181. }
  182. static ssize_t acpi_system_read_fadt(struct file *, char __user *, size_t,
  183. loff_t *);
  184. static const struct file_operations acpi_system_fadt_ops = {
  185. .read = acpi_system_read_fadt,
  186. };
  187. static ssize_t
  188. acpi_system_read_fadt(struct file *file,
  189. char __user * buffer, size_t count, loff_t * ppos)
  190. {
  191. acpi_status status = AE_OK;
  192. struct acpi_table_header *fadt = NULL;
  193. ssize_t res;
  194. status = acpi_get_table(ACPI_SIG_FADT, 1, &fadt);
  195. if (ACPI_FAILURE(status))
  196. return -ENODEV;
  197. res = simple_read_from_buffer(buffer, count, ppos, fadt, fadt->length);
  198. return res;
  199. }
  200. static int acpi_system_procfs_init(void)
  201. {
  202. struct proc_dir_entry *entry;
  203. int error = 0;
  204. char *name;
  205. /* 'info' [R] */
  206. name = ACPI_SYSTEM_FILE_INFO;
  207. entry = create_proc_entry(name, S_IRUGO, acpi_root_dir);
  208. if (!entry)
  209. goto Error;
  210. else {
  211. entry->proc_fops = &acpi_system_info_ops;
  212. }
  213. /* 'dsdt' [R] */
  214. name = ACPI_SYSTEM_FILE_DSDT;
  215. entry = create_proc_entry(name, S_IRUSR, acpi_root_dir);
  216. if (entry)
  217. entry->proc_fops = &acpi_system_dsdt_ops;
  218. else
  219. goto Error;
  220. /* 'fadt' [R] */
  221. name = ACPI_SYSTEM_FILE_FADT;
  222. entry = create_proc_entry(name, S_IRUSR, acpi_root_dir);
  223. if (entry)
  224. entry->proc_fops = &acpi_system_fadt_ops;
  225. else
  226. goto Error;
  227. Done:
  228. return error;
  229. Error:
  230. remove_proc_entry(ACPI_SYSTEM_FILE_FADT, acpi_root_dir);
  231. remove_proc_entry(ACPI_SYSTEM_FILE_DSDT, acpi_root_dir);
  232. remove_proc_entry(ACPI_SYSTEM_FILE_INFO, acpi_root_dir);
  233. error = -EFAULT;
  234. goto Done;
  235. }
  236. #else
  237. static int acpi_system_procfs_init(void)
  238. {
  239. return 0;
  240. }
  241. #endif
  242. static int __init acpi_system_init(void)
  243. {
  244. int result = 0;
  245. if (acpi_disabled)
  246. return 0;
  247. result = acpi_system_procfs_init();
  248. if (result)
  249. return result;
  250. result = acpi_system_sysfs_init();
  251. return result;
  252. }
  253. subsys_initcall(acpi_system_init);