| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 |  * Copyright (C) 2001 Mike Corrigan & Dave Engebretsen IBM Corporation | 
| David Gibson | d3d2176 | 2005-11-10 15:26:20 +1100 | [diff] [blame] | 3 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 |  * This program is free software; you can redistribute it and/or modify | 
 | 5 |  * it under the terms of the GNU General Public License as published by | 
 | 6 |  * the Free Software Foundation; either version 2 of the License, or | 
 | 7 |  * (at your option) any later version. | 
| David Gibson | d3d2176 | 2005-11-10 15:26:20 +1100 | [diff] [blame] | 8 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 |  * This program is distributed in the hope that it will be useful, | 
 | 10 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
 | 11 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
 | 12 |  * GNU General Public License for more details. | 
| David Gibson | d3d2176 | 2005-11-10 15:26:20 +1100 | [diff] [blame] | 13 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 |  * You should have received a copy of the GNU General Public License | 
 | 15 |  * along with this program; if not, write to the Free Software | 
 | 16 |  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA | 
 | 17 |  */ | 
 | 18 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/init.h> | 
 | 20 | #include <linux/mm.h> | 
 | 21 | #include <linux/proc_fs.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/kernel.h> | 
 | 23 |  | 
| Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 24 | #include <asm/machdep.h> | 
| Benjamin Herrenschmidt | a7f290d | 2005-11-11 21:15:21 +1100 | [diff] [blame] | 25 | #include <asm/vdso_datapage.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <asm/rtas.h> | 
 | 27 | #include <asm/uaccess.h> | 
 | 28 | #include <asm/prom.h> | 
 | 29 |  | 
| Benjamin Herrenschmidt | 188917e | 2009-09-24 19:29:13 +0000 | [diff] [blame] | 30 | #ifdef CONFIG_PPC64 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 |  | 
 | 32 | static loff_t page_map_seek( struct file *file, loff_t off, int whence) | 
 | 33 | { | 
 | 34 | 	loff_t new; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | 	switch(whence) { | 
 | 36 | 	case 0: | 
 | 37 | 		new = off; | 
 | 38 | 		break; | 
 | 39 | 	case 1: | 
 | 40 | 		new = file->f_pos + off; | 
 | 41 | 		break; | 
 | 42 | 	case 2: | 
| Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 43 | 		new = PAGE_SIZE + off; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | 		break; | 
 | 45 | 	default: | 
 | 46 | 		return -EINVAL; | 
 | 47 | 	} | 
| Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 48 | 	if ( new < 0 || new > PAGE_SIZE ) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | 		return -EINVAL; | 
 | 50 | 	return (file->f_pos = new); | 
 | 51 | } | 
 | 52 |  | 
 | 53 | static ssize_t page_map_read( struct file *file, char __user *buf, size_t nbytes, | 
 | 54 | 			      loff_t *ppos) | 
 | 55 | { | 
| Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 56 | 	return simple_read_from_buffer(buf, nbytes, ppos, | 
 | 57 | 			PDE_DATA(file_inode(file)), PAGE_SIZE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | } | 
 | 59 |  | 
 | 60 | static int page_map_mmap( struct file *file, struct vm_area_struct *vma ) | 
 | 61 | { | 
| Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 62 | 	if ((vma->vm_end - vma->vm_start) > PAGE_SIZE) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | 		return -EINVAL; | 
 | 64 |  | 
| Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 65 | 	remap_pfn_range(vma, vma->vm_start, | 
 | 66 | 			__pa(PDE_DATA(file_inode(file))) >> PAGE_SHIFT, | 
 | 67 | 			PAGE_SIZE, vma->vm_page_prot); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | 	return 0; | 
 | 69 | } | 
 | 70 |  | 
| Benjamin Herrenschmidt | 188917e | 2009-09-24 19:29:13 +0000 | [diff] [blame] | 71 | static const struct file_operations page_map_fops = { | 
 | 72 | 	.llseek	= page_map_seek, | 
 | 73 | 	.read	= page_map_read, | 
 | 74 | 	.mmap	= page_map_mmap | 
 | 75 | }; | 
 | 76 |  | 
 | 77 |  | 
 | 78 | static int __init proc_ppc64_init(void) | 
 | 79 | { | 
 | 80 | 	struct proc_dir_entry *pde; | 
 | 81 |  | 
 | 82 | 	pde = proc_create_data("powerpc/systemcfg", S_IFREG|S_IRUGO, NULL, | 
 | 83 | 			       &page_map_fops, vdso_data); | 
 | 84 | 	if (!pde) | 
 | 85 | 		return 1; | 
| David Howells | 271a15e | 2013-04-12 00:38:51 +0100 | [diff] [blame] | 86 | 	proc_set_size(pde, PAGE_SIZE); | 
| Benjamin Herrenschmidt | 188917e | 2009-09-24 19:29:13 +0000 | [diff] [blame] | 87 |  | 
 | 88 | 	return 0; | 
 | 89 | } | 
 | 90 | __initcall(proc_ppc64_init); | 
 | 91 |  | 
 | 92 | #endif /* CONFIG_PPC64 */ | 
 | 93 |  | 
 | 94 | /* | 
 | 95 |  * Create the ppc64 and ppc64/rtas directories early. This allows us to | 
 | 96 |  * assume that they have been previously created in drivers. | 
 | 97 |  */ | 
 | 98 | static int __init proc_ppc64_create(void) | 
 | 99 | { | 
 | 100 | 	struct proc_dir_entry *root; | 
 | 101 |  | 
 | 102 | 	root = proc_mkdir("powerpc", NULL); | 
 | 103 | 	if (!root) | 
 | 104 | 		return 1; | 
 | 105 |  | 
 | 106 | #ifdef CONFIG_PPC64 | 
 | 107 | 	if (!proc_symlink("ppc64", NULL, "powerpc")) | 
 | 108 | 		pr_err("Failed to create link /proc/ppc64 -> /proc/powerpc\n"); | 
 | 109 | #endif | 
 | 110 |  | 
 | 111 | 	if (!of_find_node_by_path("/rtas")) | 
 | 112 | 		return 0; | 
 | 113 |  | 
 | 114 | 	if (!proc_mkdir("rtas", root)) | 
 | 115 | 		return 1; | 
 | 116 |  | 
 | 117 | 	if (!proc_symlink("rtas", NULL, "powerpc/rtas")) | 
 | 118 | 		return 1; | 
 | 119 |  | 
 | 120 | 	return 0; | 
 | 121 | } | 
 | 122 | core_initcall(proc_ppc64_create); |