1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2001 Mike Corrigan & Dave Engebretsen IBM Corporation
6 #include <linux/init.h>
7 #include <linux/memblock.h>
9 #include <linux/proc_fs.h>
10 #include <linux/kernel.h>
13 #include <asm/machdep.h>
14 #include <asm/vdso_datapage.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
,
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
)
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
,
50 struct systemcfg data
;
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
);
80 proc_set_size(pde
, PAGE_SIZE
);
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
);
101 if (!proc_symlink("ppc64", NULL
, "powerpc"))
102 pr_err("Failed to create link /proc/ppc64 -> /proc/powerpc\n");
105 if (!of_find_node_by_path("/rtas"))
108 if (!proc_mkdir("rtas", root
))
111 if (!proc_symlink("rtas", NULL
, "powerpc/rtas"))
116 core_initcall(proc_ppc64_create
);