]>
Commit | Line | Data |
---|---|---|
6d7d7433 HY |
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 | */ | |
6d7d7433 | 9 | #include <linux/debugfs.h> |
c14b2adf | 10 | #include <linux/uaccess.h> |
390cd85c | 11 | #include <linux/module.h> |
5a0e3ad6 | 12 | #include <linux/slab.h> |
6d7d7433 | 13 | #include <linux/init.h> |
390cd85c | 14 | #include <linux/stat.h> |
c14b2adf HY |
15 | #include <linux/io.h> |
16 | #include <linux/mm.h> | |
6d7d7433 HY |
17 | |
18 | #include <asm/setup.h> | |
19 | ||
ae79cdaa | 20 | struct dentry *arch_debugfs_dir; |
21 | EXPORT_SYMBOL(arch_debugfs_dir); | |
22 | ||
6d7d7433 | 23 | #ifdef CONFIG_DEBUG_BOOT_PARAMS |
c14b2adf HY |
24 | struct setup_data_node { |
25 | u64 paddr; | |
26 | u32 type; | |
27 | u32 len; | |
28 | }; | |
29 | ||
390cd85c JSR |
30 | static ssize_t setup_data_read(struct file *file, char __user *user_buf, |
31 | size_t count, loff_t *ppos) | |
c14b2adf HY |
32 | { |
33 | struct setup_data_node *node = file->private_data; | |
34 | unsigned long remain; | |
35 | loff_t pos = *ppos; | |
36 | struct page *pg; | |
37 | void *p; | |
38 | u64 pa; | |
39 | ||
40 | if (pos < 0) | |
41 | return -EINVAL; | |
390cd85c | 42 | |
c14b2adf HY |
43 | if (pos >= node->len) |
44 | return 0; | |
45 | ||
46 | if (count > node->len - pos) | |
47 | count = node->len - pos; | |
390cd85c | 48 | |
c14b2adf HY |
49 | pa = node->paddr + sizeof(struct setup_data) + pos; |
50 | pg = pfn_to_page((pa + count - 1) >> PAGE_SHIFT); | |
51 | if (PageHighMem(pg)) { | |
52 | p = ioremap_cache(pa, count); | |
53 | if (!p) | |
54 | return -ENXIO; | |
390cd85c | 55 | } else |
c14b2adf | 56 | p = __va(pa); |
c14b2adf HY |
57 | |
58 | remain = copy_to_user(user_buf, p, count); | |
59 | ||
60 | if (PageHighMem(pg)) | |
61 | iounmap(p); | |
62 | ||
63 | if (remain) | |
64 | return -EFAULT; | |
65 | ||
66 | *ppos = pos + count; | |
67 | ||
68 | return count; | |
69 | } | |
70 | ||
c14b2adf | 71 | static const struct file_operations fops_setup_data = { |
390cd85c | 72 | .read = setup_data_read, |
234e3405 | 73 | .open = simple_open, |
6038f373 | 74 | .llseek = default_llseek, |
c14b2adf HY |
75 | }; |
76 | ||
77 | static int __init | |
78 | create_setup_data_node(struct dentry *parent, int no, | |
79 | struct setup_data_node *node) | |
80 | { | |
81 | struct dentry *d, *type, *data; | |
82 | char buf[16]; | |
c14b2adf HY |
83 | |
84 | sprintf(buf, "%d", no); | |
85 | d = debugfs_create_dir(buf, parent); | |
390cd85c JSR |
86 | if (!d) |
87 | return -ENOMEM; | |
88 | ||
c14b2adf | 89 | type = debugfs_create_x32("type", S_IRUGO, d, &node->type); |
390cd85c | 90 | if (!type) |
c14b2adf | 91 | goto err_dir; |
390cd85c | 92 | |
c14b2adf | 93 | data = debugfs_create_file("data", S_IRUGO, d, node, &fops_setup_data); |
390cd85c | 94 | if (!data) |
c14b2adf | 95 | goto err_type; |
390cd85c | 96 | |
c14b2adf HY |
97 | return 0; |
98 | ||
99 | err_type: | |
100 | debugfs_remove(type); | |
101 | err_dir: | |
102 | debugfs_remove(d); | |
390cd85c | 103 | return -ENOMEM; |
c14b2adf HY |
104 | } |
105 | ||
106 | static int __init create_setup_data_nodes(struct dentry *parent) | |
107 | { | |
108 | struct setup_data_node *node; | |
109 | struct setup_data *data; | |
390cd85c | 110 | int error = -ENOMEM; |
c14b2adf HY |
111 | struct dentry *d; |
112 | struct page *pg; | |
113 | u64 pa_data; | |
390cd85c | 114 | int no = 0; |
c14b2adf HY |
115 | |
116 | d = debugfs_create_dir("setup_data", parent); | |
390cd85c JSR |
117 | if (!d) |
118 | return -ENOMEM; | |
c14b2adf HY |
119 | |
120 | pa_data = boot_params.hdr.setup_data; | |
121 | ||
122 | while (pa_data) { | |
123 | node = kmalloc(sizeof(*node), GFP_KERNEL); | |
390cd85c | 124 | if (!node) |
c14b2adf | 125 | goto err_dir; |
390cd85c | 126 | |
c14b2adf HY |
127 | pg = pfn_to_page((pa_data+sizeof(*data)-1) >> PAGE_SHIFT); |
128 | if (PageHighMem(pg)) { | |
129 | data = ioremap_cache(pa_data, sizeof(*data)); | |
130 | if (!data) { | |
f461a1d8 | 131 | kfree(node); |
c14b2adf HY |
132 | error = -ENXIO; |
133 | goto err_dir; | |
134 | } | |
390cd85c | 135 | } else |
c14b2adf | 136 | data = __va(pa_data); |
c14b2adf HY |
137 | |
138 | node->paddr = pa_data; | |
139 | node->type = data->type; | |
140 | node->len = data->len; | |
141 | error = create_setup_data_node(d, no, node); | |
142 | pa_data = data->next; | |
143 | ||
144 | if (PageHighMem(pg)) | |
145 | iounmap(data); | |
146 | if (error) | |
147 | goto err_dir; | |
148 | no++; | |
149 | } | |
390cd85c | 150 | |
c14b2adf HY |
151 | return 0; |
152 | ||
153 | err_dir: | |
154 | debugfs_remove(d); | |
c14b2adf HY |
155 | return error; |
156 | } | |
157 | ||
6d7d7433 | 158 | static struct debugfs_blob_wrapper boot_params_blob = { |
c14b2adf HY |
159 | .data = &boot_params, |
160 | .size = sizeof(boot_params), | |
6d7d7433 HY |
161 | }; |
162 | ||
163 | static int __init boot_params_kdebugfs_init(void) | |
164 | { | |
6d7d7433 | 165 | struct dentry *dbp, *version, *data; |
390cd85c | 166 | int error = -ENOMEM; |
6d7d7433 HY |
167 | |
168 | dbp = debugfs_create_dir("boot_params", NULL); | |
390cd85c JSR |
169 | if (!dbp) |
170 | return -ENOMEM; | |
171 | ||
6d7d7433 HY |
172 | version = debugfs_create_x16("version", S_IRUGO, dbp, |
173 | &boot_params.hdr.version); | |
390cd85c | 174 | if (!version) |
6d7d7433 | 175 | goto err_dir; |
390cd85c | 176 | |
6d7d7433 HY |
177 | data = debugfs_create_blob("data", S_IRUGO, dbp, |
178 | &boot_params_blob); | |
390cd85c | 179 | if (!data) |
6d7d7433 | 180 | goto err_version; |
390cd85c | 181 | |
c14b2adf HY |
182 | error = create_setup_data_nodes(dbp); |
183 | if (error) | |
184 | goto err_data; | |
390cd85c | 185 | |
6d7d7433 | 186 | return 0; |
c14b2adf HY |
187 | |
188 | err_data: | |
189 | debugfs_remove(data); | |
6d7d7433 HY |
190 | err_version: |
191 | debugfs_remove(version); | |
192 | err_dir: | |
193 | debugfs_remove(dbp); | |
6d7d7433 HY |
194 | return error; |
195 | } | |
390cd85c | 196 | #endif /* CONFIG_DEBUG_BOOT_PARAMS */ |
6d7d7433 HY |
197 | |
198 | static int __init arch_kdebugfs_init(void) | |
199 | { | |
200 | int error = 0; | |
201 | ||
ae79cdaa | 202 | arch_debugfs_dir = debugfs_create_dir("x86", NULL); |
203 | if (!arch_debugfs_dir) | |
204 | return -ENOMEM; | |
205 | ||
6d7d7433 HY |
206 | #ifdef CONFIG_DEBUG_BOOT_PARAMS |
207 | error = boot_params_kdebugfs_init(); | |
208 | #endif | |
209 | ||
210 | return error; | |
211 | } | |
6d7d7433 | 212 | arch_initcall(arch_kdebugfs_init); |