1 /* 2 * Architecture specific debugfs files 3 * 4 * Copyright (C) 2007, Intel Corp. 5 * Huang Ying <ying.huang@intel.com> 6 * 7 * This file is released under the GPLv2. 8 */ 9 #include <linux/debugfs.h> 10 #include <linux/uaccess.h> 11 #include <linux/export.h> 12 #include <linux/slab.h> 13 #include <linux/init.h> 14 #include <linux/stat.h> 15 #include <linux/io.h> 16 #include <linux/mm.h> 17 18 #include <asm/setup.h> 19 20 struct dentry *arch_debugfs_dir; 21 EXPORT_SYMBOL(arch_debugfs_dir); 22 23 #ifdef CONFIG_DEBUG_BOOT_PARAMS 24 struct setup_data_node { 25 u64 paddr; 26 u32 type; 27 u32 len; 28 }; 29 30 static ssize_t setup_data_read(struct file *file, char __user *user_buf, 31 size_t count, loff_t *ppos) 32 { 33 struct setup_data_node *node = file->private_data; 34 unsigned long remain; 35 loff_t pos = *ppos; 36 void *p; 37 u64 pa; 38 39 if (pos < 0) 40 return -EINVAL; 41 42 if (pos >= node->len) 43 return 0; 44 45 if (count > node->len - pos) 46 count = node->len - pos; 47 48 pa = node->paddr + sizeof(struct setup_data) + pos; 49 p = memremap(pa, count, MEMREMAP_WB); 50 if (!p) 51 return -ENOMEM; 52 53 remain = copy_to_user(user_buf, p, count); 54 55 memunmap(p); 56 57 if (remain) 58 return -EFAULT; 59 60 *ppos = pos + count; 61 62 return count; 63 } 64 65 static const struct file_operations fops_setup_data = { 66 .read = setup_data_read, 67 .open = simple_open, 68 .llseek = default_llseek, 69 }; 70 71 static void __init 72 create_setup_data_node(struct dentry *parent, int no, 73 struct setup_data_node *node) 74 { 75 struct dentry *d; 76 char buf[16]; 77 78 sprintf(buf, "%d", no); 79 d = debugfs_create_dir(buf, parent); 80 81 debugfs_create_x32("type", S_IRUGO, d, &node->type); 82 debugfs_create_file("data", S_IRUGO, d, node, &fops_setup_data); 83 } 84 85 static int __init create_setup_data_nodes(struct dentry *parent) 86 { 87 struct setup_data_node *node; 88 struct setup_data *data; 89 int error; 90 struct dentry *d; 91 u64 pa_data; 92 int no = 0; 93 94 d = debugfs_create_dir("setup_data", parent); 95 96 pa_data = boot_params.hdr.setup_data; 97 98 while (pa_data) { 99 node = kmalloc(sizeof(*node), GFP_KERNEL); 100 if (!node) { 101 error = -ENOMEM; 102 goto err_dir; 103 } 104 105 data = memremap(pa_data, sizeof(*data), MEMREMAP_WB); 106 if (!data) { 107 kfree(node); 108 error = -ENOMEM; 109 goto err_dir; 110 } 111 112 node->paddr = pa_data; 113 node->type = data->type; 114 node->len = data->len; 115 create_setup_data_node(d, no, node); 116 pa_data = data->next; 117 118 memunmap(data); 119 no++; 120 } 121 122 return 0; 123 124 err_dir: 125 debugfs_remove_recursive(d); 126 return error; 127 } 128 129 static struct debugfs_blob_wrapper boot_params_blob = { 130 .data = &boot_params, 131 .size = sizeof(boot_params), 132 }; 133 134 static int __init boot_params_kdebugfs_init(void) 135 { 136 struct dentry *dbp; 137 int error; 138 139 dbp = debugfs_create_dir("boot_params", arch_debugfs_dir); 140 141 debugfs_create_x16("version", S_IRUGO, dbp, &boot_params.hdr.version); 142 debugfs_create_blob("data", S_IRUGO, dbp, &boot_params_blob); 143 144 error = create_setup_data_nodes(dbp); 145 if (error) 146 debugfs_remove_recursive(dbp); 147 148 return error; 149 } 150 #endif /* CONFIG_DEBUG_BOOT_PARAMS */ 151 152 static int __init arch_kdebugfs_init(void) 153 { 154 int error = 0; 155 156 arch_debugfs_dir = debugfs_create_dir("x86", NULL); 157 158 #ifdef CONFIG_DEBUG_BOOT_PARAMS 159 error = boot_params_kdebugfs_init(); 160 #endif 161 162 return error; 163 } 164 arch_initcall(arch_kdebugfs_init); 165