system.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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/slab.h>
  28. #include <linux/init.h>
  29. #include <linux/string.h>
  30. #include <asm/uaccess.h>
  31. #include <acpi/acpi_drivers.h>
  32. #define PREFIX "ACPI: "
  33. #define _COMPONENT ACPI_SYSTEM_COMPONENT
  34. ACPI_MODULE_NAME("system");
  35. #define ACPI_SYSTEM_CLASS "system"
  36. #define ACPI_SYSTEM_DEVICE_NAME "System"
  37. /* --------------------------------------------------------------------------
  38. FS Interface (/proc)
  39. -------------------------------------------------------------------------- */
  40. #ifdef CONFIG_ACPI_PROCFS
  41. #define ACPI_SYSTEM_FILE_INFO "info"
  42. #define ACPI_SYSTEM_FILE_EVENT "event"
  43. #define ACPI_SYSTEM_FILE_DSDT "dsdt"
  44. #define ACPI_SYSTEM_FILE_FADT "fadt"
  45. static int acpi_system_read_info(struct seq_file *seq, void *offset)
  46. {
  47. seq_printf(seq, "version: %x\n", ACPI_CA_VERSION);
  48. return 0;
  49. }
  50. static int acpi_system_info_open_fs(struct inode *inode, struct file *file)
  51. {
  52. return single_open(file, acpi_system_read_info, PDE(inode)->data);
  53. }
  54. static const struct file_operations acpi_system_info_ops = {
  55. .owner = THIS_MODULE,
  56. .open = acpi_system_info_open_fs,
  57. .read = seq_read,
  58. .llseek = seq_lseek,
  59. .release = single_release,
  60. };
  61. static ssize_t acpi_system_read_dsdt(struct file *, char __user *, size_t,
  62. loff_t *);
  63. static const struct file_operations acpi_system_dsdt_ops = {
  64. .owner = THIS_MODULE,
  65. .read = acpi_system_read_dsdt,
  66. };
  67. static ssize_t
  68. acpi_system_read_dsdt(struct file *file,
  69. char __user * buffer, size_t count, loff_t * ppos)
  70. {
  71. acpi_status status = AE_OK;
  72. struct acpi_table_header *dsdt = NULL;
  73. ssize_t res;
  74. status = acpi_get_table(ACPI_SIG_DSDT, 1, &dsdt);
  75. if (ACPI_FAILURE(status))
  76. return -ENODEV;
  77. res = simple_read_from_buffer(buffer, count, ppos, dsdt, dsdt->length);
  78. return res;
  79. }
  80. static ssize_t acpi_system_read_fadt(struct file *, char __user *, size_t,
  81. loff_t *);
  82. static const struct file_operations acpi_system_fadt_ops = {
  83. .owner = THIS_MODULE,
  84. .read = acpi_system_read_fadt,
  85. };
  86. static ssize_t
  87. acpi_system_read_fadt(struct file *file,
  88. char __user * buffer, size_t count, loff_t * ppos)
  89. {
  90. acpi_status status = AE_OK;
  91. struct acpi_table_header *fadt = NULL;
  92. ssize_t res;
  93. status = acpi_get_table(ACPI_SIG_FADT, 1, &fadt);
  94. if (ACPI_FAILURE(status))
  95. return -ENODEV;
  96. res = simple_read_from_buffer(buffer, count, ppos, fadt, fadt->length);
  97. return res;
  98. }
  99. static int acpi_system_procfs_init(void)
  100. {
  101. struct proc_dir_entry *entry;
  102. int error = 0;
  103. /* 'info' [R] */
  104. entry = proc_create(ACPI_SYSTEM_FILE_INFO, S_IRUGO, acpi_root_dir,
  105. &acpi_system_info_ops);
  106. if (!entry)
  107. goto Error;
  108. /* 'dsdt' [R] */
  109. entry = proc_create(ACPI_SYSTEM_FILE_DSDT, S_IRUSR, acpi_root_dir,
  110. &acpi_system_dsdt_ops);
  111. if (!entry)
  112. goto Error;
  113. /* 'fadt' [R] */
  114. entry = proc_create(ACPI_SYSTEM_FILE_FADT, S_IRUSR, acpi_root_dir,
  115. &acpi_system_fadt_ops);
  116. if (!entry)
  117. goto Error;
  118. Done:
  119. return error;
  120. Error:
  121. remove_proc_entry(ACPI_SYSTEM_FILE_FADT, acpi_root_dir);
  122. remove_proc_entry(ACPI_SYSTEM_FILE_DSDT, acpi_root_dir);
  123. remove_proc_entry(ACPI_SYSTEM_FILE_INFO, acpi_root_dir);
  124. error = -EFAULT;
  125. goto Done;
  126. }
  127. #else
  128. static int acpi_system_procfs_init(void)
  129. {
  130. return 0;
  131. }
  132. #endif
  133. int __init acpi_system_init(void)
  134. {
  135. int result;
  136. result = acpi_system_procfs_init();
  137. return result;
  138. }