1188917e1SBenjamin Herrenschmidt /* 2188917e1SBenjamin Herrenschmidt * Copyright (C) 2001 Mike Corrigan & Dave Engebretsen IBM Corporation 3188917e1SBenjamin Herrenschmidt * 4188917e1SBenjamin Herrenschmidt * This program is free software; you can redistribute it and/or modify 5188917e1SBenjamin Herrenschmidt * it under the terms of the GNU General Public License as published by 6188917e1SBenjamin Herrenschmidt * the Free Software Foundation; either version 2 of the License, or 7188917e1SBenjamin Herrenschmidt * (at your option) any later version. 8188917e1SBenjamin Herrenschmidt * 9188917e1SBenjamin Herrenschmidt * This program is distributed in the hope that it will be useful, 10188917e1SBenjamin Herrenschmidt * but WITHOUT ANY WARRANTY; without even the implied warranty of 11188917e1SBenjamin Herrenschmidt * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12188917e1SBenjamin Herrenschmidt * GNU General Public License for more details. 13188917e1SBenjamin Herrenschmidt * 14188917e1SBenjamin Herrenschmidt * You should have received a copy of the GNU General Public License 15188917e1SBenjamin Herrenschmidt * along with this program; if not, write to the Free Software 16188917e1SBenjamin Herrenschmidt * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17188917e1SBenjamin Herrenschmidt */ 18188917e1SBenjamin Herrenschmidt 19188917e1SBenjamin Herrenschmidt #include <linux/init.h> 20188917e1SBenjamin Herrenschmidt #include <linux/mm.h> 21188917e1SBenjamin Herrenschmidt #include <linux/proc_fs.h> 22188917e1SBenjamin Herrenschmidt #include <linux/kernel.h> 23188917e1SBenjamin Herrenschmidt 24188917e1SBenjamin Herrenschmidt #include <asm/machdep.h> 25188917e1SBenjamin Herrenschmidt #include <asm/vdso_datapage.h> 26188917e1SBenjamin Herrenschmidt #include <asm/rtas.h> 27188917e1SBenjamin Herrenschmidt #include <asm/uaccess.h> 28188917e1SBenjamin Herrenschmidt #include <asm/prom.h> 29188917e1SBenjamin Herrenschmidt 30188917e1SBenjamin Herrenschmidt #ifdef CONFIG_PPC64 31188917e1SBenjamin Herrenschmidt 32188917e1SBenjamin Herrenschmidt static loff_t page_map_seek(struct file *file, loff_t off, int whence) 33188917e1SBenjamin Herrenschmidt { 34*b33159b7SAl Viro return fixed_size_llseek(file, off, whence, PAGE_SIZE); 35188917e1SBenjamin Herrenschmidt } 36188917e1SBenjamin Herrenschmidt 37188917e1SBenjamin Herrenschmidt static ssize_t page_map_read( struct file *file, char __user *buf, size_t nbytes, 38188917e1SBenjamin Herrenschmidt loff_t *ppos) 39188917e1SBenjamin Herrenschmidt { 40d9dda78bSAl Viro return simple_read_from_buffer(buf, nbytes, ppos, 41d9dda78bSAl Viro PDE_DATA(file_inode(file)), PAGE_SIZE); 42188917e1SBenjamin Herrenschmidt } 43188917e1SBenjamin Herrenschmidt 44188917e1SBenjamin Herrenschmidt static int page_map_mmap( struct file *file, struct vm_area_struct *vma ) 45188917e1SBenjamin Herrenschmidt { 46d9dda78bSAl Viro if ((vma->vm_end - vma->vm_start) > PAGE_SIZE) 47188917e1SBenjamin Herrenschmidt return -EINVAL; 48188917e1SBenjamin Herrenschmidt 49d9dda78bSAl Viro remap_pfn_range(vma, vma->vm_start, 50d9dda78bSAl Viro __pa(PDE_DATA(file_inode(file))) >> PAGE_SHIFT, 51d9dda78bSAl Viro PAGE_SIZE, vma->vm_page_prot); 52188917e1SBenjamin Herrenschmidt return 0; 53188917e1SBenjamin Herrenschmidt } 54188917e1SBenjamin Herrenschmidt 55188917e1SBenjamin Herrenschmidt static const struct file_operations page_map_fops = { 56188917e1SBenjamin Herrenschmidt .llseek = page_map_seek, 57188917e1SBenjamin Herrenschmidt .read = page_map_read, 58188917e1SBenjamin Herrenschmidt .mmap = page_map_mmap 59188917e1SBenjamin Herrenschmidt }; 60188917e1SBenjamin Herrenschmidt 61188917e1SBenjamin Herrenschmidt 62188917e1SBenjamin Herrenschmidt static int __init proc_ppc64_init(void) 63188917e1SBenjamin Herrenschmidt { 64188917e1SBenjamin Herrenschmidt struct proc_dir_entry *pde; 65188917e1SBenjamin Herrenschmidt 66188917e1SBenjamin Herrenschmidt pde = proc_create_data("powerpc/systemcfg", S_IFREG|S_IRUGO, NULL, 67188917e1SBenjamin Herrenschmidt &page_map_fops, vdso_data); 68188917e1SBenjamin Herrenschmidt if (!pde) 69188917e1SBenjamin Herrenschmidt return 1; 70271a15eaSDavid Howells proc_set_size(pde, PAGE_SIZE); 71188917e1SBenjamin Herrenschmidt 72188917e1SBenjamin Herrenschmidt return 0; 73188917e1SBenjamin Herrenschmidt } 74188917e1SBenjamin Herrenschmidt __initcall(proc_ppc64_init); 75188917e1SBenjamin Herrenschmidt 76188917e1SBenjamin Herrenschmidt #endif /* CONFIG_PPC64 */ 77188917e1SBenjamin Herrenschmidt 78188917e1SBenjamin Herrenschmidt /* 79188917e1SBenjamin Herrenschmidt * Create the ppc64 and ppc64/rtas directories early. This allows us to 80188917e1SBenjamin Herrenschmidt * assume that they have been previously created in drivers. 81188917e1SBenjamin Herrenschmidt */ 82188917e1SBenjamin Herrenschmidt static int __init proc_ppc64_create(void) 83188917e1SBenjamin Herrenschmidt { 84188917e1SBenjamin Herrenschmidt struct proc_dir_entry *root; 85188917e1SBenjamin Herrenschmidt 86188917e1SBenjamin Herrenschmidt root = proc_mkdir("powerpc", NULL); 87188917e1SBenjamin Herrenschmidt if (!root) 88188917e1SBenjamin Herrenschmidt return 1; 89188917e1SBenjamin Herrenschmidt 90188917e1SBenjamin Herrenschmidt #ifdef CONFIG_PPC64 91188917e1SBenjamin Herrenschmidt if (!proc_symlink("ppc64", NULL, "powerpc")) 92188917e1SBenjamin Herrenschmidt pr_err("Failed to create link /proc/ppc64 -> /proc/powerpc\n"); 93188917e1SBenjamin Herrenschmidt #endif 94188917e1SBenjamin Herrenschmidt 95188917e1SBenjamin Herrenschmidt if (!of_find_node_by_path("/rtas")) 96188917e1SBenjamin Herrenschmidt return 0; 97188917e1SBenjamin Herrenschmidt 98188917e1SBenjamin Herrenschmidt if (!proc_mkdir("rtas", root)) 99188917e1SBenjamin Herrenschmidt return 1; 100188917e1SBenjamin Herrenschmidt 101188917e1SBenjamin Herrenschmidt if (!proc_symlink("rtas", NULL, "powerpc/rtas")) 102188917e1SBenjamin Herrenschmidt return 1; 103188917e1SBenjamin Herrenschmidt 104188917e1SBenjamin Herrenschmidt return 0; 105188917e1SBenjamin Herrenschmidt } 106188917e1SBenjamin Herrenschmidt core_initcall(proc_ppc64_create); 107