Linux Audio

Check our new training course

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