Commit a25ee9200eef07377e1703697afbb5d81f89e500

Authored by Zhang Rui
Committed by Len Brown
1 parent 9fe6206f40

ACPI: introduce drivers/acpi/debugfs.c

Introduce drivers/acpi/debugfs.c.

Code for ACPI debugfs I/F,
i.e. /sys/kernel/debug/acpi/custom_method,
is moved to this file.

And make ACPI debugfs always built in,
even if CONFIG_ACPI_DEBUG is cleared.

BTW:this adds about 400bytes code to ACPI, when
CONFIG_ACPI_DEBUG is cleared.

[uaccess.h build fix from Andrew Morton <akpm@linux-foundation.org>]

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>

Showing 5 changed files with 93 additions and 75 deletions Side-by-side Diff

drivers/acpi/Makefile
... ... @@ -39,6 +39,7 @@
39 39 acpi-y += power.o
40 40 acpi-y += system.o event.o
41 41 acpi-$(CONFIG_ACPI_DEBUG) += debug.o
  42 +acpi-$(CONFIG_DEBUG_FS) += debugfs.o
42 43 acpi-$(CONFIG_ACPI_NUMA) += numa.o
43 44 acpi-$(CONFIG_ACPI_PROCFS_POWER) += cm_sbs.o
44 45 ifdef CONFIG_ACPI_VIDEO
... ... @@ -1036,6 +1036,7 @@
1036 1036 acpi_power_init();
1037 1037 acpi_system_init();
1038 1038 acpi_debug_init();
  1039 + acpi_debugfs_init();
1039 1040 acpi_sleep_proc_init();
1040 1041 acpi_wakeup_device_init();
1041 1042 return result;
drivers/acpi/debug.c
... ... @@ -198,80 +198,6 @@
198 198 NULL, 0644);
199 199  
200 200 /* --------------------------------------------------------------------------
201   - DebugFS Interface
202   - -------------------------------------------------------------------------- */
203   -
204   -static ssize_t cm_write(struct file *file, const char __user *user_buf,
205   - size_t count, loff_t *ppos)
206   -{
207   - static char *buf;
208   - static int uncopied_bytes;
209   - struct acpi_table_header table;
210   - acpi_status status;
211   -
212   - if (!(*ppos)) {
213   - /* parse the table header to get the table length */
214   - if (count <= sizeof(struct acpi_table_header))
215   - return -EINVAL;
216   - if (copy_from_user(&table, user_buf,
217   - sizeof(struct acpi_table_header)))
218   - return -EFAULT;
219   - uncopied_bytes = table.length;
220   - buf = kzalloc(uncopied_bytes, GFP_KERNEL);
221   - if (!buf)
222   - return -ENOMEM;
223   - }
224   -
225   - if (uncopied_bytes < count) {
226   - kfree(buf);
227   - return -EINVAL;
228   - }
229   -
230   - if (copy_from_user(buf + (*ppos), user_buf, count)) {
231   - kfree(buf);
232   - return -EFAULT;
233   - }
234   -
235   - uncopied_bytes -= count;
236   - *ppos += count;
237   -
238   - if (!uncopied_bytes) {
239   - status = acpi_install_method(buf);
240   - kfree(buf);
241   - if (ACPI_FAILURE(status))
242   - return -EINVAL;
243   - add_taint(TAINT_OVERRIDDEN_ACPI_TABLE);
244   - }
245   -
246   - return count;
247   -}
248   -
249   -static const struct file_operations cm_fops = {
250   - .write = cm_write,
251   -};
252   -
253   -static int acpi_debugfs_init(void)
254   -{
255   - struct dentry *acpi_dir, *cm_dentry;
256   -
257   - acpi_dir = debugfs_create_dir("acpi", NULL);
258   - if (!acpi_dir)
259   - goto err;
260   -
261   - cm_dentry = debugfs_create_file("custom_method", S_IWUGO,
262   - acpi_dir, NULL, &cm_fops);
263   - if (!cm_dentry)
264   - goto err;
265   -
266   - return 0;
267   -
268   -err:
269   - if (acpi_dir)
270   - debugfs_remove(acpi_dir);
271   - return -EINVAL;
272   -}
273   -
274   -/* --------------------------------------------------------------------------
275 201 FS Interface (/proc)
276 202 -------------------------------------------------------------------------- */
277 203 #ifdef CONFIG_ACPI_PROCFS
... ... @@ -400,7 +326,6 @@
400 326  
401 327 int __init acpi_debug_init(void)
402 328 {
403   - acpi_debugfs_init();
404 329 acpi_procfs_init();
405 330 return 0;
406 331 }
drivers/acpi/debugfs.c
  1 +/*
  2 + * debugfs.c - ACPI debugfs interface to userspace.
  3 + */
  4 +
  5 +#include <linux/init.h>
  6 +#include <linux/module.h>
  7 +#include <linux/kernel.h>
  8 +#include <linux/uaccess.h>
  9 +#include <linux/debugfs.h>
  10 +#include <acpi/acpi_drivers.h>
  11 +
  12 +#define _COMPONENT ACPI_SYSTEM_COMPONENT
  13 +ACPI_MODULE_NAME("debugfs");
  14 +
  15 +/* /sys/kernel/debug/acpi/custom_method */
  16 +
  17 +static ssize_t cm_write(struct file *file, const char __user * user_buf,
  18 + size_t count, loff_t *ppos)
  19 +{
  20 + static char *buf;
  21 + static int uncopied_bytes;
  22 + struct acpi_table_header table;
  23 + acpi_status status;
  24 +
  25 + if (!(*ppos)) {
  26 + /* parse the table header to get the table length */
  27 + if (count <= sizeof(struct acpi_table_header))
  28 + return -EINVAL;
  29 + if (copy_from_user(&table, user_buf,
  30 + sizeof(struct acpi_table_header)))
  31 + return -EFAULT;
  32 + uncopied_bytes = table.length;
  33 + buf = kzalloc(uncopied_bytes, GFP_KERNEL);
  34 + if (!buf)
  35 + return -ENOMEM;
  36 + }
  37 +
  38 + if (uncopied_bytes < count) {
  39 + kfree(buf);
  40 + return -EINVAL;
  41 + }
  42 +
  43 + if (copy_from_user(buf + (*ppos), user_buf, count)) {
  44 + kfree(buf);
  45 + return -EFAULT;
  46 + }
  47 +
  48 + uncopied_bytes -= count;
  49 + *ppos += count;
  50 +
  51 + if (!uncopied_bytes) {
  52 + status = acpi_install_method(buf);
  53 + kfree(buf);
  54 + if (ACPI_FAILURE(status))
  55 + return -EINVAL;
  56 + add_taint(TAINT_OVERRIDDEN_ACPI_TABLE);
  57 + }
  58 +
  59 + return count;
  60 +}
  61 +
  62 +static const struct file_operations cm_fops = {
  63 + .write = cm_write,
  64 +};
  65 +
  66 +int __init acpi_debugfs_init(void)
  67 +{
  68 + struct dentry *acpi_dir, *cm_dentry;
  69 +
  70 + acpi_dir = debugfs_create_dir("acpi", NULL);
  71 + if (!acpi_dir)
  72 + goto err;
  73 +
  74 + cm_dentry = debugfs_create_file("custom_method", S_IWUGO,
  75 + acpi_dir, NULL, &cm_fops);
  76 + if (!cm_dentry)
  77 + goto err;
  78 +
  79 + return 0;
  80 +
  81 +err:
  82 + if (acpi_dir)
  83 + debugfs_remove(acpi_dir);
  84 + return -EINVAL;
  85 +}
drivers/acpi/internal.h
... ... @@ -30,6 +30,12 @@
30 30 static inline int acpi_debug_init(void) { return 0; }
31 31 #endif
32 32  
  33 +#ifdef CONFIG_DEBUG_FS
  34 +int acpi_debugfs_init(void);
  35 +#else
  36 +static inline int acpi_debugfs_init(void) { return 0; }
  37 +#endif
  38 +
33 39 /* --------------------------------------------------------------------------
34 40 Power Resource
35 41 -------------------------------------------------------------------------- */