blob: dd7001cacf75cfc09040b05961c39bb7c0471cfd [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Copyright (C) 2001 Mike Corrigan & Dave Engebretsen IBM Corporation
David Gibsond3d21762005-11-10 15:26:20 +11003 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * 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 Gibsond3d21762005-11-10 15:26:20 +11008 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * 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 Gibsond3d21762005-11-10 15:26:20 +110013 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 * 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 Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/init.h>
20#include <linux/mm.h>
21#include <linux/proc_fs.h>
22#include <linux/slab.h>
23#include <linux/kernel.h>
24
Benjamin Herrenschmidte8222502006-03-28 23:15:54 +110025#include <asm/machdep.h>
Benjamin Herrenschmidta7f290d2005-11-11 21:15:21 +110026#include <asm/vdso_datapage.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <asm/rtas.h>
28#include <asm/uaccess.h>
29#include <asm/prom.h>
30
31static loff_t page_map_seek( struct file *file, loff_t off, int whence);
32static ssize_t page_map_read( struct file *file, char __user *buf, size_t nbytes,
33 loff_t *ppos);
34static int page_map_mmap( struct file *file, struct vm_area_struct *vma );
35
36static struct file_operations page_map_fops = {
37 .llseek = page_map_seek,
38 .read = page_map_read,
39 .mmap = page_map_mmap
40};
41
42/*
43 * Create the ppc64 and ppc64/rtas directories early. This allows us to
44 * assume that they have been previously created in drivers.
45 */
46static int __init proc_ppc64_create(void)
47{
48 struct proc_dir_entry *root;
49
50 root = proc_mkdir("ppc64", NULL);
51 if (!root)
52 return 1;
53
mostrows@watson.ibm.com9dabbfb2006-05-15 08:51:07 -040054 if (!of_find_node_by_path("/rtas"))
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 return 0;
56
57 if (!proc_mkdir("rtas", root))
58 return 1;
59
60 if (!proc_symlink("rtas", NULL, "ppc64/rtas"))
61 return 1;
62
63 return 0;
64}
65core_initcall(proc_ppc64_create);
66
67static int __init proc_ppc64_init(void)
68{
69 struct proc_dir_entry *pde;
70
71 pde = create_proc_entry("ppc64/systemcfg", S_IFREG|S_IRUGO, NULL);
72 if (!pde)
73 return 1;
74 pde->nlink = 1;
Benjamin Herrenschmidta7f290d2005-11-11 21:15:21 +110075 pde->data = vdso_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 pde->size = PAGE_SIZE;
77 pde->proc_fops = &page_map_fops;
78
79 return 0;
80}
81__initcall(proc_ppc64_init);
82
83static loff_t page_map_seek( struct file *file, loff_t off, int whence)
84{
85 loff_t new;
Josef Sipekb4d1ab52006-12-08 02:37:30 -080086 struct proc_dir_entry *dp = PDE(file->f_path.dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88 switch(whence) {
89 case 0:
90 new = off;
91 break;
92 case 1:
93 new = file->f_pos + off;
94 break;
95 case 2:
96 new = dp->size + off;
97 break;
98 default:
99 return -EINVAL;
100 }
101 if ( new < 0 || new > dp->size )
102 return -EINVAL;
103 return (file->f_pos = new);
104}
105
106static ssize_t page_map_read( struct file *file, char __user *buf, size_t nbytes,
107 loff_t *ppos)
108{
Josef Sipekb4d1ab52006-12-08 02:37:30 -0800109 struct proc_dir_entry *dp = PDE(file->f_path.dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 return simple_read_from_buffer(buf, nbytes, ppos, dp->data, dp->size);
111}
112
113static int page_map_mmap( struct file *file, struct vm_area_struct *vma )
114{
Josef Sipekb4d1ab52006-12-08 02:37:30 -0800115 struct proc_dir_entry *dp = PDE(file->f_path.dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 if ((vma->vm_end - vma->vm_start) > dp->size)
118 return -EINVAL;
119
120 remap_pfn_range(vma, vma->vm_start, __pa(dp->data) >> PAGE_SHIFT,
121 dp->size, vma->vm_page_prot);
122 return 0;
123}
124