blob: 877817471e3c12f657e18aab19e49c654674993c [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Copyright (C) 2001 Mike Corrigan & Dave Engebretsen IBM Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 */
5
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#include <linux/init.h>
7#include <linux/mm.h>
8#include <linux/proc_fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/kernel.h>
10
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +110011#include <asm/machdep.h>
Benjamin Herrenschmidta7f290d2005-11-11 21:15:21 +110012#include <asm/vdso_datapage.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <asm/rtas.h>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080014#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <asm/prom.h>
16
Benjamin Herrenschmidt188917e2009-09-24 19:29:13 +000017#ifdef CONFIG_PPC64
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
Al Virob33159b2013-06-23 12:35:26 +040019static loff_t page_map_seek(struct file *file, loff_t off, int whence)
Linus Torvalds1da177e2005-04-16 15:20:36 -070020{
Al Virob33159b2013-06-23 12:35:26 +040021 return fixed_size_llseek(file, off, whence, PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070022}
23
24static ssize_t page_map_read( struct file *file, char __user *buf, size_t nbytes,
25 loff_t *ppos)
26{
Al Virod9dda782013-03-31 18:16:14 -040027 return simple_read_from_buffer(buf, nbytes, ppos,
28 PDE_DATA(file_inode(file)), PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070029}
30
31static int page_map_mmap( struct file *file, struct vm_area_struct *vma )
32{
Al Virod9dda782013-03-31 18:16:14 -040033 if ((vma->vm_end - vma->vm_start) > PAGE_SIZE)
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 return -EINVAL;
35
Al Virod9dda782013-03-31 18:16:14 -040036 remap_pfn_range(vma, vma->vm_start,
37 __pa(PDE_DATA(file_inode(file))) >> PAGE_SHIFT,
38 PAGE_SIZE, vma->vm_page_prot);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 return 0;
40}
41
Alexey Dobriyan97a32532020-02-03 17:37:17 -080042static const struct proc_ops page_map_proc_ops = {
43 .proc_lseek = page_map_seek,
44 .proc_read = page_map_read,
45 .proc_mmap = page_map_mmap,
Benjamin Herrenschmidt188917e2009-09-24 19:29:13 +000046};
47
48
49static int __init proc_ppc64_init(void)
50{
51 struct proc_dir_entry *pde;
52
Russell Currey57ad583f2017-01-12 14:54:13 +110053 pde = proc_create_data("powerpc/systemcfg", S_IFREG | 0444, NULL,
Alexey Dobriyan97a32532020-02-03 17:37:17 -080054 &page_map_proc_ops, vdso_data);
Benjamin Herrenschmidt188917e2009-09-24 19:29:13 +000055 if (!pde)
56 return 1;
David Howells271a15e2013-04-12 00:38:51 +010057 proc_set_size(pde, PAGE_SIZE);
Benjamin Herrenschmidt188917e2009-09-24 19:29:13 +000058
59 return 0;
60}
61__initcall(proc_ppc64_init);
62
63#endif /* CONFIG_PPC64 */
64
65/*
66 * Create the ppc64 and ppc64/rtas directories early. This allows us to
67 * assume that they have been previously created in drivers.
68 */
69static int __init proc_ppc64_create(void)
70{
71 struct proc_dir_entry *root;
72
73 root = proc_mkdir("powerpc", NULL);
74 if (!root)
75 return 1;
76
77#ifdef CONFIG_PPC64
78 if (!proc_symlink("ppc64", NULL, "powerpc"))
79 pr_err("Failed to create link /proc/ppc64 -> /proc/powerpc\n");
80#endif
81
82 if (!of_find_node_by_path("/rtas"))
83 return 0;
84
85 if (!proc_mkdir("rtas", root))
86 return 1;
87
88 if (!proc_symlink("rtas", NULL, "powerpc/rtas"))
89 return 1;
90
91 return 0;
92}
93core_initcall(proc_ppc64_create);