system.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. #define ACPI_SYSTEM_CLASS "system"
  33. #define ACPI_SYSTEM_DRIVER_NAME "ACPI System Driver"
  34. #define ACPI_SYSTEM_DEVICE_NAME "System"
  35. #define ACPI_SYSTEM_FILE_INFO "info"
  36. #define ACPI_SYSTEM_FILE_EVENT "event"
  37. #define ACPI_SYSTEM_FILE_DSDT "dsdt"
  38. #define ACPI_SYSTEM_FILE_FADT "fadt"
  39. extern FADT_DESCRIPTOR acpi_fadt;
  40. /* --------------------------------------------------------------------------
  41. FS Interface (/proc)
  42. -------------------------------------------------------------------------- */
  43. static int
  44. acpi_system_read_info (struct seq_file *seq, void *offset)
  45. {
  46. ACPI_FUNCTION_TRACE("acpi_system_read_info");
  47. seq_printf(seq, "version: %x\n", ACPI_CA_VERSION);
  48. return_VALUE(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 struct file_operations acpi_system_info_ops = {
  55. .open = acpi_system_info_open_fs,
  56. .read = seq_read,
  57. .llseek = seq_lseek,
  58. .release = single_release,
  59. };
  60. static ssize_t acpi_system_read_dsdt (struct file*, char __user *, size_t, loff_t*);
  61. static struct file_operations acpi_system_dsdt_ops = {
  62. .read = acpi_system_read_dsdt,
  63. };
  64. static ssize_t
  65. acpi_system_read_dsdt (
  66. struct file *file,
  67. char __user *buffer,
  68. size_t count,
  69. loff_t *ppos)
  70. {
  71. acpi_status status = AE_OK;
  72. struct acpi_buffer dsdt = {ACPI_ALLOCATE_BUFFER, NULL};
  73. ssize_t res;
  74. ACPI_FUNCTION_TRACE("acpi_system_read_dsdt");
  75. status = acpi_get_table(ACPI_TABLE_DSDT, 1, &dsdt);
  76. if (ACPI_FAILURE(status))
  77. return_VALUE(-ENODEV);
  78. res = simple_read_from_buffer(buffer, count, ppos,
  79. dsdt.pointer, dsdt.length);
  80. acpi_os_free(dsdt.pointer);
  81. return_VALUE(res);
  82. }
  83. static ssize_t acpi_system_read_fadt (struct file*, char __user *, size_t, loff_t*);
  84. static struct file_operations acpi_system_fadt_ops = {
  85. .read = acpi_system_read_fadt,
  86. };
  87. static ssize_t
  88. acpi_system_read_fadt (
  89. struct file *file,
  90. char __user *buffer,
  91. size_t count,
  92. loff_t *ppos)
  93. {
  94. acpi_status status = AE_OK;
  95. struct acpi_buffer fadt = {ACPI_ALLOCATE_BUFFER, NULL};
  96. ssize_t res;
  97. ACPI_FUNCTION_TRACE("acpi_system_read_fadt");
  98. status = acpi_get_table(ACPI_TABLE_FADT, 1, &fadt);
  99. if (ACPI_FAILURE(status))
  100. return_VALUE(-ENODEV);
  101. res = simple_read_from_buffer(buffer, count, ppos,
  102. fadt.pointer, fadt.length);
  103. acpi_os_free(fadt.pointer);
  104. return_VALUE(res);
  105. }
  106. static int __init acpi_system_init (void)
  107. {
  108. struct proc_dir_entry *entry;
  109. int error = 0;
  110. char * name;
  111. ACPI_FUNCTION_TRACE("acpi_system_init");
  112. if (acpi_disabled)
  113. return_VALUE(0);
  114. /* 'info' [R] */
  115. name = ACPI_SYSTEM_FILE_INFO;
  116. entry = create_proc_entry(name,
  117. S_IRUGO, acpi_root_dir);
  118. if (!entry)
  119. goto Error;
  120. else {
  121. entry->proc_fops = &acpi_system_info_ops;
  122. }
  123. /* 'dsdt' [R] */
  124. name = ACPI_SYSTEM_FILE_DSDT;
  125. entry = create_proc_entry(name, S_IRUSR, acpi_root_dir);
  126. if (entry)
  127. entry->proc_fops = &acpi_system_dsdt_ops;
  128. else
  129. goto Error;
  130. /* 'fadt' [R] */
  131. name = ACPI_SYSTEM_FILE_FADT;
  132. entry = create_proc_entry(name, S_IRUSR, acpi_root_dir);
  133. if (entry)
  134. entry->proc_fops = &acpi_system_fadt_ops;
  135. else
  136. goto Error;
  137. Done:
  138. return_VALUE(error);
  139. Error:
  140. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  141. "Unable to create '%s' proc fs entry\n", name));
  142. remove_proc_entry(ACPI_SYSTEM_FILE_FADT, acpi_root_dir);
  143. remove_proc_entry(ACPI_SYSTEM_FILE_DSDT, acpi_root_dir);
  144. remove_proc_entry(ACPI_SYSTEM_FILE_INFO, acpi_root_dir);
  145. error = -EFAULT;
  146. goto Done;
  147. }
  148. subsys_initcall(acpi_system_init);