]>
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 | ||
71 | static int setup_data_open(struct inode *inode, struct file *file) | |
72 | { | |
73 | file->private_data = inode->i_private; | |
390cd85c | 74 | |
c14b2adf HY |
75 | return 0; |
76 | } | |
77 | ||
78 | static const struct file_operations fops_setup_data = { | |
390cd85c JSR |
79 | .read = setup_data_read, |
80 | .open = setup_data_open, | |
c14b2adf HY |
81 | }; |
82 | ||
83 | static int __init | |
84 | create_setup_data_node(struct dentry *parent, int no, | |
85 | struct setup_data_node *node) | |
86 | { | |
87 | struct dentry *d, *type, *data; | |
88 | char buf[16]; | |
c14b2adf HY |
89 | |
90 | sprintf(buf, "%d", no); | |
91 | d = debugfs_create_dir(buf, parent); | |
390cd85c JSR |
92 | if (!d) |
93 | return -ENOMEM; | |
94 | ||
c14b2adf | 95 | type = debugfs_create_x32("type", S_IRUGO, d, &node->type); |
390cd85c | 96 | if (!type) |
c14b2adf | 97 | goto err_dir; |
390cd85c | 98 | |
c14b2adf | 99 | data = debugfs_create_file("data", S_IRUGO, d, node, &fops_setup_data); |
390cd85c | 100 | if (!data) |
c14b2adf | 101 | goto err_type; |
390cd85c | 102 | |
c14b2adf HY |
103 | return 0; |
104 | ||
105 | err_type: | |
106 | debugfs_remove(type); | |
107 | err_dir: | |
108 | debugfs_remove(d); | |
390cd85c | 109 | return -ENOMEM; |
c14b2adf HY |
110 | } |
111 | ||
112 | static int __init create_setup_data_nodes(struct dentry *parent) | |
113 | { | |
114 | struct setup_data_node *node; | |
115 | struct setup_data *data; | |
390cd85c | 116 | int error = -ENOMEM; |
c14b2adf HY |
117 | struct dentry *d; |
118 | struct page *pg; | |
119 | u64 pa_data; | |
390cd85c | 120 | int no = 0; |
c14b2adf HY |
121 | |
122 | d = debugfs_create_dir("setup_data", parent); | |
390cd85c JSR |
123 | if (!d) |
124 | return -ENOMEM; | |
c14b2adf HY |
125 | |
126 | pa_data = boot_params.hdr.setup_data; | |
127 | ||
128 | while (pa_data) { | |
129 | node = kmalloc(sizeof(*node), GFP_KERNEL); | |
390cd85c | 130 | if (!node) |
c14b2adf | 131 | goto err_dir; |
390cd85c | 132 | |
c14b2adf HY |
133 | pg = pfn_to_page((pa_data+sizeof(*data)-1) >> PAGE_SHIFT); |
134 | if (PageHighMem(pg)) { | |
135 | data = ioremap_cache(pa_data, sizeof(*data)); | |
136 | if (!data) { | |
f461a1d8 | 137 | kfree(node); |
c14b2adf HY |
138 | error = -ENXIO; |
139 | goto err_dir; | |
140 | } | |
390cd85c | 141 | } else |
c14b2adf | 142 | data = __va(pa_data); |
c14b2adf HY |
143 | |
144 | node->paddr = pa_data; | |
145 | node->type = data->type; | |
146 | node->len = data->len; | |
147 | error = create_setup_data_node(d, no, node); | |
148 | pa_data = data->next; | |
149 | ||
150 | if (PageHighMem(pg)) | |
151 | iounmap(data); | |
152 | if (error) | |
153 | goto err_dir; | |
154 | no++; | |
155 | } | |
390cd85c | 156 | |
c14b2adf HY |
157 | return 0; |
158 | ||
159 | err_dir: | |
160 | debugfs_remove(d); | |
c14b2adf HY |
161 | return error; |
162 | } | |
163 | ||
6d7d7433 | 164 | static struct debugfs_blob_wrapper boot_params_blob = { |
c14b2adf HY |
165 | .data = &boot_params, |
166 | .size = sizeof(boot_params), | |
6d7d7433 HY |
167 | }; |
168 | ||
169 | static int __init boot_params_kdebugfs_init(void) | |
170 | { | |
6d7d7433 | 171 | struct dentry *dbp, *version, *data; |
390cd85c | 172 | int error = -ENOMEM; |
6d7d7433 HY |
173 | |
174 | dbp = debugfs_create_dir("boot_params", NULL); | |
390cd85c JSR |
175 | if (!dbp) |
176 | return -ENOMEM; | |
177 | ||
6d7d7433 HY |
178 | version = debugfs_create_x16("version", S_IRUGO, dbp, |
179 | &boot_params.hdr.version); | |
390cd85c | 180 | if (!version) |
6d7d7433 | 181 | goto err_dir; |
390cd85c | 182 | |
6d7d7433 HY |
183 | data = debugfs_create_blob("data", S_IRUGO, dbp, |
184 | &boot_params_blob); | |
390cd85c | 185 | if (!data) |
6d7d7433 | 186 | goto err_version; |
390cd85c | 187 | |
c14b2adf HY |
188 | error = create_setup_data_nodes(dbp); |
189 | if (error) | |
190 | goto err_data; | |
390cd85c | 191 | |
6d7d7433 | 192 | return 0; |
c14b2adf HY |
193 | |
194 | err_data: | |
195 | debugfs_remove(data); | |
6d7d7433 HY |
196 | err_version: |
197 | debugfs_remove(version); | |
198 | err_dir: | |
199 | debugfs_remove(dbp); | |
6d7d7433 HY |
200 | return error; |
201 | } | |
390cd85c | 202 | #endif /* CONFIG_DEBUG_BOOT_PARAMS */ |
6d7d7433 HY |
203 | |
204 | static int __init arch_kdebugfs_init(void) | |
205 | { | |
206 | int error = 0; | |
207 | ||
ae79cdaa | 208 | arch_debugfs_dir = debugfs_create_dir("x86", NULL); |
209 | if (!arch_debugfs_dir) | |
210 | return -ENOMEM; | |
211 | ||
6d7d7433 HY |
212 | #ifdef CONFIG_DEBUG_BOOT_PARAMS |
213 | error = boot_params_kdebugfs_init(); | |
214 | #endif | |
215 | ||
216 | return error; | |
217 | } | |
6d7d7433 | 218 | arch_initcall(arch_kdebugfs_init); |