Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Copyright (C) 2001 Mike Corrigan & Dave Engebretsen IBM Corporation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <linux/init.h> |
| 7 | #include <linux/mm.h> |
| 8 | #include <linux/proc_fs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/kernel.h> |
| 10 | |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 11 | #include <asm/machdep.h> |
Benjamin Herrenschmidt | a7f290d | 2005-11-11 21:15:21 +1100 | [diff] [blame] | 12 | #include <asm/vdso_datapage.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <asm/rtas.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 14 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <asm/prom.h> |
| 16 | |
Benjamin Herrenschmidt | 188917e | 2009-09-24 19:29:13 +0000 | [diff] [blame] | 17 | #ifdef CONFIG_PPC64 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
Al Viro | b33159b | 2013-06-23 12:35:26 +0400 | [diff] [blame] | 19 | static loff_t page_map_seek(struct file *file, loff_t off, int whence) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | { |
Al Viro | b33159b | 2013-06-23 12:35:26 +0400 | [diff] [blame] | 21 | return fixed_size_llseek(file, off, whence, PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | static ssize_t page_map_read( struct file *file, char __user *buf, size_t nbytes, |
| 25 | loff_t *ppos) |
| 26 | { |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 27 | return simple_read_from_buffer(buf, nbytes, ppos, |
| 28 | PDE_DATA(file_inode(file)), PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | static int page_map_mmap( struct file *file, struct vm_area_struct *vma ) |
| 32 | { |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 33 | if ((vma->vm_end - vma->vm_start) > PAGE_SIZE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | return -EINVAL; |
| 35 | |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 36 | remap_pfn_range(vma, vma->vm_start, |
| 37 | __pa(PDE_DATA(file_inode(file))) >> PAGE_SHIFT, |
| 38 | PAGE_SIZE, vma->vm_page_prot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | return 0; |
| 40 | } |
| 41 | |
Alexey Dobriyan | 97a3253 | 2020-02-03 17:37:17 -0800 | [diff] [blame] | 42 | static 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 Herrenschmidt | 188917e | 2009-09-24 19:29:13 +0000 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | |
| 49 | static int __init proc_ppc64_init(void) |
| 50 | { |
| 51 | struct proc_dir_entry *pde; |
| 52 | |
Russell Currey | 57ad583f | 2017-01-12 14:54:13 +1100 | [diff] [blame] | 53 | pde = proc_create_data("powerpc/systemcfg", S_IFREG | 0444, NULL, |
Alexey Dobriyan | 97a3253 | 2020-02-03 17:37:17 -0800 | [diff] [blame] | 54 | &page_map_proc_ops, vdso_data); |
Benjamin Herrenschmidt | 188917e | 2009-09-24 19:29:13 +0000 | [diff] [blame] | 55 | if (!pde) |
| 56 | return 1; |
David Howells | 271a15e | 2013-04-12 00:38:51 +0100 | [diff] [blame] | 57 | proc_set_size(pde, PAGE_SIZE); |
Benjamin Herrenschmidt | 188917e | 2009-09-24 19:29:13 +0000 | [diff] [blame] | 58 | |
| 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 | */ |
| 69 | static 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 | } |
| 93 | core_initcall(proc_ppc64_create); |