Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * Copyright (C) 2001 Mike Corrigan & Dave Engebretsen IBM Corporation
0004  */
0005 
0006 #include <linux/init.h>
0007 #include <linux/mm.h>
0008 #include <linux/proc_fs.h>
0009 #include <linux/kernel.h>
0010 #include <linux/of.h>
0011 
0012 #include <asm/machdep.h>
0013 #include <asm/vdso_datapage.h>
0014 #include <asm/rtas.h>
0015 #include <linux/uaccess.h>
0016 
0017 #ifdef CONFIG_PPC64
0018 
0019 static loff_t page_map_seek(struct file *file, loff_t off, int whence)
0020 {
0021     return fixed_size_llseek(file, off, whence, PAGE_SIZE);
0022 }
0023 
0024 static ssize_t page_map_read( struct file *file, char __user *buf, size_t nbytes,
0025                   loff_t *ppos)
0026 {
0027     return simple_read_from_buffer(buf, nbytes, ppos,
0028             pde_data(file_inode(file)), PAGE_SIZE);
0029 }
0030 
0031 static int page_map_mmap( struct file *file, struct vm_area_struct *vma )
0032 {
0033     if ((vma->vm_end - vma->vm_start) > PAGE_SIZE)
0034         return -EINVAL;
0035 
0036     remap_pfn_range(vma, vma->vm_start,
0037             __pa(pde_data(file_inode(file))) >> PAGE_SHIFT,
0038             PAGE_SIZE, vma->vm_page_prot);
0039     return 0;
0040 }
0041 
0042 static const struct proc_ops page_map_proc_ops = {
0043     .proc_lseek = page_map_seek,
0044     .proc_read  = page_map_read,
0045     .proc_mmap  = page_map_mmap,
0046 };
0047 
0048 
0049 static int __init proc_ppc64_init(void)
0050 {
0051     struct proc_dir_entry *pde;
0052 
0053     pde = proc_create_data("powerpc/systemcfg", S_IFREG | 0444, NULL,
0054                    &page_map_proc_ops, vdso_data);
0055     if (!pde)
0056         return 1;
0057     proc_set_size(pde, PAGE_SIZE);
0058 
0059     return 0;
0060 }
0061 __initcall(proc_ppc64_init);
0062 
0063 #endif /* CONFIG_PPC64 */
0064 
0065 /*
0066  * Create the ppc64 and ppc64/rtas directories early. This allows us to
0067  * assume that they have been previously created in drivers.
0068  */
0069 static int __init proc_ppc64_create(void)
0070 {
0071     struct proc_dir_entry *root;
0072 
0073     root = proc_mkdir("powerpc", NULL);
0074     if (!root)
0075         return 1;
0076 
0077 #ifdef CONFIG_PPC64
0078     if (!proc_symlink("ppc64", NULL, "powerpc"))
0079         pr_err("Failed to create link /proc/ppc64 -> /proc/powerpc\n");
0080 #endif
0081 
0082     if (!of_find_node_by_path("/rtas"))
0083         return 0;
0084 
0085     if (!proc_mkdir("rtas", root))
0086         return 1;
0087 
0088     if (!proc_symlink("rtas", NULL, "powerpc/rtas"))
0089         return 1;
0090 
0091     return 0;
0092 }
0093 core_initcall(proc_ppc64_create);