File: bootinfo_proc.c

package info (click to toggle)
linux 6.1.139-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 1,495,880 kB
  • sloc: ansic: 23,469,452; asm: 266,614; sh: 110,522; makefile: 49,887; python: 36,990; perl: 36,834; cpp: 6,056; yacc: 4,908; lex: 2,725; awk: 1,440; ruby: 25; sed: 5
file content (79 lines) | stat: -rw-r--r-- 1,705 bytes parent folder | download | duplicates (20)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// SPDX-License-Identifier: GPL-2.0
/*
 * Based on arch/arm/kernel/atags_proc.c
 */

#include <linux/fs.h>
#include <linux/init.h>
#include <linux/printk.h>
#include <linux/proc_fs.h>
#include <linux/slab.h>
#include <linux/string.h>

#include <asm/bootinfo.h>
#include <asm/byteorder.h>


static char bootinfo_tmp[1536] __initdata;

static void *bootinfo_copy;
static size_t bootinfo_size;

static ssize_t bootinfo_read(struct file *file, char __user *buf,
			  size_t count, loff_t *ppos)
{
	return simple_read_from_buffer(buf, count, ppos, bootinfo_copy,
				       bootinfo_size);
}

static const struct proc_ops bootinfo_proc_ops = {
	.proc_read	= bootinfo_read,
	.proc_lseek	= default_llseek,
};

void __init save_bootinfo(const struct bi_record *bi)
{
	const void *start = bi;
	size_t size = sizeof(bi->tag);

	while (be16_to_cpu(bi->tag) != BI_LAST) {
		uint16_t n = be16_to_cpu(bi->size);
		size += n;
		bi = (struct bi_record *)((unsigned long)bi + n);
	}

	if (size > sizeof(bootinfo_tmp)) {
		pr_err("Cannot save %zu bytes of bootinfo\n", size);
		return;
	}

	pr_info("Saving %zu bytes of bootinfo\n", size);
	memcpy(bootinfo_tmp, start, size);
	bootinfo_size = size;
}

static int __init init_bootinfo_procfs(void)
{
	/*
	 * This cannot go into save_bootinfo() because kmalloc and proc don't
	 * work yet when it is called.
	 */
	struct proc_dir_entry *pde;

	if (!bootinfo_size)
		return -EINVAL;

	bootinfo_copy = kmemdup(bootinfo_tmp, bootinfo_size, GFP_KERNEL);
	if (!bootinfo_copy)
		return -ENOMEM;

	pde = proc_create_data("bootinfo", 0400, NULL, &bootinfo_proc_ops, NULL);
	if (!pde) {
		kfree(bootinfo_copy);
		return -ENOMEM;
	}

	return 0;
}

arch_initcall(init_bootinfo_procfs);