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