system.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * acpi_system.c - ACPI System Driver ($Revision: 1.1.1.1 $)
  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. #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"
  42. /*
  43. * Make ACPICA version work as module param
  44. */
  45. static int param_get_acpica_version(char *buffer, struct kernel_param *kp) {
  46. int result;
  47. result = sprintf(buffer, "%x", ACPI_CA_VERSION);
  48. return result;
  49. }
  50. module_param_call(acpica_version, NULL, param_get_acpica_version, NULL, 0444);
  51. /* --------------------------------------------------------------------------
  52. FS Interface (/proc)
  53. -------------------------------------------------------------------------- */
  54. #ifdef CONFIG_ACPI_PROCFS
  55. static int acpi_system_read_info(struct seq_file *seq, void *offset)
  56. {
  57. seq_printf(seq, "version: %x\n", ACPI_CA_VERSION);
  58. return 0;
  59. }
  60. static int acpi_system_info_open_fs(struct inode *inode, struct file *file)
  61. {
  62. return single_open(file, acpi_system_read_info, PDE(inode)->data);
  63. }
  64. static const struct file_operations acpi_system_info_ops = {
  65. .open = acpi_system_info_open_fs,
  66. .read = seq_read,
  67. .llseek = seq_lseek,
  68. .release = single_release,
  69. };
  70. #endif
  71. static ssize_t acpi_system_read_dsdt(struct file *, char __user *, size_t,
  72. loff_t *);
  73. static const struct file_operations acpi_system_dsdt_ops = {
  74. .read = acpi_system_read_dsdt,
  75. };
  76. static ssize_t
  77. acpi_system_read_dsdt(struct file *file,
  78. char __user * buffer, size_t count, loff_t * ppos)
  79. {
  80. acpi_status status = AE_OK;
  81. struct acpi_table_header *dsdt = NULL;
  82. ssize_t res;
  83. status = acpi_get_table(ACPI_SIG_DSDT, 1, &dsdt);
  84. if (ACPI_FAILURE(status))
  85. return -ENODEV;
  86. res = simple_read_from_buffer(buffer, count, ppos,
  87. dsdt, dsdt->length);
  88. return res;
  89. }
  90. static ssize_t acpi_system_read_fadt(struct file *, char __user *, size_t,
  91. loff_t *);
  92. static const struct file_operations acpi_system_fadt_ops = {
  93. .read = acpi_system_read_fadt,
  94. };
  95. static ssize_t
  96. acpi_system_read_fadt(struct file *file,
  97. char __user * buffer, size_t count, loff_t * ppos)
  98. {
  99. acpi_status status = AE_OK;
  100. struct acpi_table_header *fadt = NULL;
  101. ssize_t res;
  102. status = acpi_get_table(ACPI_SIG_FADT, 1, &fadt);
  103. if (ACPI_FAILURE(status))
  104. return -ENODEV;
  105. res = simple_read_from_buffer(buffer, count, ppos,
  106. fadt, fadt->length);
  107. return res;
  108. }
  109. static int __init acpi_system_init(void)
  110. {
  111. struct proc_dir_entry *entry;
  112. int error = 0;
  113. char *name;
  114. if (acpi_disabled)
  115. return 0;
  116. #ifdef CONFIG_ACPI_PROCFS
  117. /* 'info' [R] */
  118. name = ACPI_SYSTEM_FILE_INFO;
  119. entry = create_proc_entry(name, S_IRUGO, acpi_root_dir);
  120. if (!entry)
  121. goto Error;
  122. else {
  123. entry->proc_fops = &acpi_system_info_ops;
  124. }
  125. #endif
  126. /* 'dsdt' [R] */
  127. name = ACPI_SYSTEM_FILE_DSDT;
  128. entry = create_proc_entry(name, S_IRUSR, acpi_root_dir);
  129. if (entry)
  130. entry->proc_fops = &acpi_system_dsdt_ops;
  131. else
  132. goto Error;
  133. /* 'fadt' [R] */
  134. name = ACPI_SYSTEM_FILE_FADT;
  135. entry = create_proc_entry(name, S_IRUSR, acpi_root_dir);
  136. if (entry)
  137. entry->proc_fops = &acpi_system_fadt_ops;
  138. else
  139. goto Error;
  140. Done:
  141. return error;
  142. Error:
  143. remove_proc_entry(ACPI_SYSTEM_FILE_FADT, acpi_root_dir);
  144. remove_proc_entry(ACPI_SYSTEM_FILE_DSDT, acpi_root_dir);
  145. #ifdef CONFIG_ACPI_PROCFS
  146. remove_proc_entry(ACPI_SYSTEM_FILE_INFO, acpi_root_dir);
  147. #endif
  148. error = -EFAULT;
  149. goto Done;
  150. }
  151. subsys_initcall(acpi_system_init);