2 * Architecture specific debugfs files
4 * Copyright (C) 2007, Intel Corp.
5 * Huang Ying <ying.huang@intel.com>
7 * This file is released under the GPLv2.
9 #include <linux/debugfs.h>
10 #include <linux/uaccess.h>
11 #include <linux/module.h>
12 #include <linux/slab.h>
13 #include <linux/init.h>
14 #include <linux/stat.h>
18 #include <asm/setup.h>
20 struct dentry
*arch_debugfs_dir
;
21 EXPORT_SYMBOL(arch_debugfs_dir
);
23 #ifdef CONFIG_DEBUG_BOOT_PARAMS
24 struct setup_data_node
{
30 static ssize_t
setup_data_read(struct file
*file
, char __user
*user_buf
,
31 size_t count
, loff_t
*ppos
)
33 struct setup_data_node
*node
= file
->private_data
;
46 if (count
> node
->len
- pos
)
47 count
= node
->len
- pos
;
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
);
58 remain
= copy_to_user(user_buf
, p
, count
);
71 static int setup_data_open(struct inode
*inode
, struct file
*file
)
73 file
->private_data
= inode
->i_private
;
78 static const struct file_operations fops_setup_data
= {
79 .read
= setup_data_read
,
80 .open
= setup_data_open
,
81 .llseek
= default_llseek
,
85 create_setup_data_node(struct dentry
*parent
, int no
,
86 struct setup_data_node
*node
)
88 struct dentry
*d
, *type
, *data
;
91 sprintf(buf
, "%d", no
);
92 d
= debugfs_create_dir(buf
, parent
);
96 type
= debugfs_create_x32("type", S_IRUGO
, d
, &node
->type
);
100 data
= debugfs_create_file("data", S_IRUGO
, d
, node
, &fops_setup_data
);
107 debugfs_remove(type
);
113 static int __init
create_setup_data_nodes(struct dentry
*parent
)
115 struct setup_data_node
*node
;
116 struct setup_data
*data
;
123 d
= debugfs_create_dir("setup_data", parent
);
127 pa_data
= boot_params
.hdr
.setup_data
;
130 node
= kmalloc(sizeof(*node
), GFP_KERNEL
);
134 pg
= pfn_to_page((pa_data
+sizeof(*data
)-1) >> PAGE_SHIFT
);
135 if (PageHighMem(pg
)) {
136 data
= ioremap_cache(pa_data
, sizeof(*data
));
143 data
= __va(pa_data
);
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
;
165 static struct debugfs_blob_wrapper boot_params_blob
= {
166 .data
= &boot_params
,
167 .size
= sizeof(boot_params
),
170 static int __init
boot_params_kdebugfs_init(void)
172 struct dentry
*dbp
, *version
, *data
;
175 dbp
= debugfs_create_dir("boot_params", NULL
);
179 version
= debugfs_create_x16("version", S_IRUGO
, dbp
,
180 &boot_params
.hdr
.version
);
184 data
= debugfs_create_blob("data", S_IRUGO
, dbp
,
189 error
= create_setup_data_nodes(dbp
);
196 debugfs_remove(data
);
198 debugfs_remove(version
);
203 #endif /* CONFIG_DEBUG_BOOT_PARAMS */
205 static int __init
arch_kdebugfs_init(void)
209 arch_debugfs_dir
= debugfs_create_dir("x86", NULL
);
210 if (!arch_debugfs_dir
)
213 #ifdef CONFIG_DEBUG_BOOT_PARAMS
214 error
= boot_params_kdebugfs_init();
219 arch_initcall(arch_kdebugfs_init
);