system.c 5.0 KB

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