xref: /linux/arch/powerpc/kernel/proc_powerpc.c (revision 25489a4f556414445d342951615178368ee45cde)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (C) 2001 Mike Corrigan & Dave Engebretsen IBM Corporation
4  */
5 
6 #include <linux/init.h>
7 #include <linux/memblock.h>
8 #include <linux/mm.h>
9 #include <linux/proc_fs.h>
10 #include <linux/kernel.h>
11 #include <linux/of.h>
12 #include <linux/string.h>
13 
14 #include <asm/machdep.h>
15 #include <asm/vdso_datapage.h>
16 #include <asm/rtas.h>
17 #include <asm/systemcfg.h>
18 #include <linux/uaccess.h>
19 
20 #ifdef CONFIG_PPC64_PROC_SYSTEMCFG
21 
22 static loff_t page_map_seek(struct file *file, loff_t off, int whence)
23 {
24 	return fixed_size_llseek(file, off, whence, PAGE_SIZE);
25 }
26 
27 static ssize_t page_map_read( struct file *file, char __user *buf, size_t nbytes,
28 			      loff_t *ppos)
29 {
30 	return simple_read_from_buffer(buf, nbytes, ppos,
31 			pde_data(file_inode(file)), PAGE_SIZE);
32 }
33 
34 static int page_map_mmap( struct file *file, struct vm_area_struct *vma )
35 {
36 	if ((vma->vm_end - vma->vm_start) > PAGE_SIZE)
37 		return -EINVAL;
38 
39 	return remap_pfn_range(vma, vma->vm_start,
40 			       __pa(pde_data(file_inode(file))) >> PAGE_SHIFT,
41 			       PAGE_SIZE, vma->vm_page_prot);
42 }
43 
44 static const struct proc_ops page_map_proc_ops = {
45 	.proc_lseek	= page_map_seek,
46 	.proc_read	= page_map_read,
47 	.proc_mmap	= page_map_mmap,
48 };
49 
50 static union {
51 	struct systemcfg	data;
52 	u8			page[PAGE_SIZE];
53 } systemcfg_data_store __page_aligned_data;
54 struct systemcfg *systemcfg = &systemcfg_data_store.data;
55 
56 static int __init proc_ppc64_init(void)
57 {
58 	struct proc_dir_entry *pde;
59 
60 	strscpy(systemcfg->eye_catcher, "SYSTEMCFG:PPC64");
61 	systemcfg->version.major = SYSTEMCFG_MAJOR;
62 	systemcfg->version.minor = SYSTEMCFG_MINOR;
63 	systemcfg->processor = mfspr(SPRN_PVR);
64 	/*
65 	 * Fake the old platform number for pSeries and add
66 	 * in LPAR bit if necessary
67 	 */
68 	systemcfg->platform = 0x100;
69 	if (firmware_has_feature(FW_FEATURE_LPAR))
70 		systemcfg->platform |= 1;
71 	systemcfg->physicalMemorySize = memblock_phys_mem_size();
72 	systemcfg->dcache_size = ppc64_caches.l1d.size;
73 	systemcfg->dcache_line_size = ppc64_caches.l1d.line_size;
74 	systemcfg->icache_size = ppc64_caches.l1i.size;
75 	systemcfg->icache_line_size = ppc64_caches.l1i.line_size;
76 
77 	pde = proc_create_data("powerpc/systemcfg", S_IFREG | 0444, NULL,
78 			       &page_map_proc_ops, systemcfg);
79 	if (!pde)
80 		return 1;
81 	proc_set_size(pde, PAGE_SIZE);
82 
83 	return 0;
84 }
85 __initcall(proc_ppc64_init);
86 
87 #endif /* CONFIG_PPC64_PROC_SYSTEMCFG */
88 
89 /*
90  * Create the ppc64 and ppc64/rtas directories early. This allows us to
91  * assume that they have been previously created in drivers.
92  */
93 static int __init proc_ppc64_create(void)
94 {
95 	struct proc_dir_entry *root;
96 
97 	root = proc_mkdir("powerpc", NULL);
98 	if (!root)
99 		return 1;
100 
101 #ifdef CONFIG_PPC64
102 	if (!proc_symlink("ppc64", NULL, "powerpc"))
103 		pr_err("Failed to create link /proc/ppc64 -> /proc/powerpc\n");
104 #endif
105 
106 	if (!of_find_node_by_path("/rtas"))
107 		return 0;
108 
109 	if (!proc_mkdir("rtas", root))
110 		return 1;
111 
112 	if (!proc_symlink("rtas", NULL, "powerpc/rtas"))
113 		return 1;
114 
115 	return 0;
116 }
117 core_initcall(proc_ppc64_create);
118