Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / arch / powerpc / kernel / proc_powerpc.c
blob3816a2bf2b844ff49f6fd22cc42e733d5ef72b36
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2001 Mike Corrigan & Dave Engebretsen IBM Corporation
4 */
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>
13 #include <asm/machdep.h>
14 #include <asm/vdso_datapage.h>
15 #include <asm/rtas.h>
16 #include <asm/systemcfg.h>
17 #include <linux/uaccess.h>
19 #ifdef CONFIG_PPC64_PROC_SYSTEMCFG
21 static loff_t page_map_seek(struct file *file, loff_t off, int whence)
23 return fixed_size_llseek(file, off, whence, PAGE_SIZE);
26 static ssize_t page_map_read( struct file *file, char __user *buf, size_t nbytes,
27 loff_t *ppos)
29 return simple_read_from_buffer(buf, nbytes, ppos,
30 pde_data(file_inode(file)), PAGE_SIZE);
33 static int page_map_mmap( struct file *file, struct vm_area_struct *vma )
35 if ((vma->vm_end - vma->vm_start) > PAGE_SIZE)
36 return -EINVAL;
38 return remap_pfn_range(vma, vma->vm_start,
39 __pa(pde_data(file_inode(file))) >> PAGE_SHIFT,
40 PAGE_SIZE, vma->vm_page_prot);
43 static const struct proc_ops page_map_proc_ops = {
44 .proc_lseek = page_map_seek,
45 .proc_read = page_map_read,
46 .proc_mmap = page_map_mmap,
49 static union {
50 struct systemcfg data;
51 u8 page[PAGE_SIZE];
52 } systemcfg_data_store __page_aligned_data;
53 struct systemcfg *systemcfg = &systemcfg_data_store.data;
55 static int __init proc_ppc64_init(void)
57 struct proc_dir_entry *pde;
59 strcpy((char *)systemcfg->eye_catcher, "SYSTEMCFG:PPC64");
60 systemcfg->version.major = SYSTEMCFG_MAJOR;
61 systemcfg->version.minor = SYSTEMCFG_MINOR;
62 systemcfg->processor = mfspr(SPRN_PVR);
64 * Fake the old platform number for pSeries and add
65 * in LPAR bit if necessary
67 systemcfg->platform = 0x100;
68 if (firmware_has_feature(FW_FEATURE_LPAR))
69 systemcfg->platform |= 1;
70 systemcfg->physicalMemorySize = memblock_phys_mem_size();
71 systemcfg->dcache_size = ppc64_caches.l1d.size;
72 systemcfg->dcache_line_size = ppc64_caches.l1d.line_size;
73 systemcfg->icache_size = ppc64_caches.l1i.size;
74 systemcfg->icache_line_size = ppc64_caches.l1i.line_size;
76 pde = proc_create_data("powerpc/systemcfg", S_IFREG | 0444, NULL,
77 &page_map_proc_ops, systemcfg);
78 if (!pde)
79 return 1;
80 proc_set_size(pde, PAGE_SIZE);
82 return 0;
84 __initcall(proc_ppc64_init);
86 #endif /* CONFIG_PPC64_PROC_SYSTEMCFG */
89 * Create the ppc64 and ppc64/rtas directories early. This allows us to
90 * assume that they have been previously created in drivers.
92 static int __init proc_ppc64_create(void)
94 struct proc_dir_entry *root;
96 root = proc_mkdir("powerpc", NULL);
97 if (!root)
98 return 1;
100 #ifdef CONFIG_PPC64
101 if (!proc_symlink("ppc64", NULL, "powerpc"))
102 pr_err("Failed to create link /proc/ppc64 -> /proc/powerpc\n");
103 #endif
105 if (!of_find_node_by_path("/rtas"))
106 return 0;
108 if (!proc_mkdir("rtas", root))
109 return 1;
111 if (!proc_symlink("rtas", NULL, "powerpc/rtas"))
112 return 1;
114 return 0;
116 core_initcall(proc_ppc64_create);