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 | |
| 19 | #include <linux/config.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/mm.h> |
| 22 | #include <linux/proc_fs.h> |
| 23 | #include <linux/slab.h> |
| 24 | #include <linux/kernel.h> |
| 25 | |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame^] | 26 | #include <asm/machdep.h> |
Benjamin Herrenschmidt | a7f290d | 2005-11-11 21:15:21 +1100 | [diff] [blame] | 27 | #include <asm/vdso_datapage.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <asm/rtas.h> |
| 29 | #include <asm/uaccess.h> |
| 30 | #include <asm/prom.h> |
| 31 | |
| 32 | static loff_t page_map_seek( struct file *file, loff_t off, int whence); |
| 33 | static ssize_t page_map_read( struct file *file, char __user *buf, size_t nbytes, |
| 34 | loff_t *ppos); |
| 35 | static int page_map_mmap( struct file *file, struct vm_area_struct *vma ); |
| 36 | |
| 37 | static struct file_operations page_map_fops = { |
| 38 | .llseek = page_map_seek, |
| 39 | .read = page_map_read, |
| 40 | .mmap = page_map_mmap |
| 41 | }; |
| 42 | |
| 43 | /* |
| 44 | * Create the ppc64 and ppc64/rtas directories early. This allows us to |
| 45 | * assume that they have been previously created in drivers. |
| 46 | */ |
| 47 | static int __init proc_ppc64_create(void) |
| 48 | { |
| 49 | struct proc_dir_entry *root; |
| 50 | |
| 51 | root = proc_mkdir("ppc64", NULL); |
| 52 | if (!root) |
| 53 | return 1; |
| 54 | |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame^] | 55 | if (!machine_is(pseries) && !machine_is(cell)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | return 0; |
| 57 | |
| 58 | if (!proc_mkdir("rtas", root)) |
| 59 | return 1; |
| 60 | |
| 61 | if (!proc_symlink("rtas", NULL, "ppc64/rtas")) |
| 62 | return 1; |
| 63 | |
| 64 | return 0; |
| 65 | } |
| 66 | core_initcall(proc_ppc64_create); |
| 67 | |
| 68 | static int __init proc_ppc64_init(void) |
| 69 | { |
| 70 | struct proc_dir_entry *pde; |
| 71 | |
| 72 | pde = create_proc_entry("ppc64/systemcfg", S_IFREG|S_IRUGO, NULL); |
| 73 | if (!pde) |
| 74 | return 1; |
| 75 | pde->nlink = 1; |
Benjamin Herrenschmidt | a7f290d | 2005-11-11 21:15:21 +1100 | [diff] [blame] | 76 | pde->data = vdso_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | pde->size = PAGE_SIZE; |
| 78 | pde->proc_fops = &page_map_fops; |
| 79 | |
| 80 | return 0; |
| 81 | } |
| 82 | __initcall(proc_ppc64_init); |
| 83 | |
| 84 | static loff_t page_map_seek( struct file *file, loff_t off, int whence) |
| 85 | { |
| 86 | loff_t new; |
| 87 | struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode); |
| 88 | |
| 89 | switch(whence) { |
| 90 | case 0: |
| 91 | new = off; |
| 92 | break; |
| 93 | case 1: |
| 94 | new = file->f_pos + off; |
| 95 | break; |
| 96 | case 2: |
| 97 | new = dp->size + off; |
| 98 | break; |
| 99 | default: |
| 100 | return -EINVAL; |
| 101 | } |
| 102 | if ( new < 0 || new > dp->size ) |
| 103 | return -EINVAL; |
| 104 | return (file->f_pos = new); |
| 105 | } |
| 106 | |
| 107 | static ssize_t page_map_read( struct file *file, char __user *buf, size_t nbytes, |
| 108 | loff_t *ppos) |
| 109 | { |
| 110 | struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode); |
| 111 | return simple_read_from_buffer(buf, nbytes, ppos, dp->data, dp->size); |
| 112 | } |
| 113 | |
| 114 | static int page_map_mmap( struct file *file, struct vm_area_struct *vma ) |
| 115 | { |
| 116 | struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode); |
| 117 | |
| 118 | vma->vm_flags |= VM_SHM | VM_LOCKED; |
| 119 | |
| 120 | if ((vma->vm_end - vma->vm_start) > dp->size) |
| 121 | return -EINVAL; |
| 122 | |
| 123 | remap_pfn_range(vma, vma->vm_start, __pa(dp->data) >> PAGE_SHIFT, |
| 124 | dp->size, vma->vm_page_prot); |
| 125 | return 0; |
| 126 | } |
| 127 | |