initial commit with v2.6.9
[linux-2.6.9-moxart.git] / arch / ppc64 / kernel / mf_proc.c
blobf98f35569dee313b8e2ff8ae0f158dd09c4b0040
1 /*
2 * mf_proc.c
3 * Copyright (C) 2001 Kyle A. Lucke IBM Corporation
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include <linux/init.h>
20 #include <asm/uaccess.h>
21 #include <asm/iSeries/mf.h>
23 static int proc_mf_dump_cmdline(char *page, char **start, off_t off,
24 int count, int *eof, void *data)
26 int len = count;
27 char *p;
29 if (off) {
30 *eof = 1;
31 return 0;
34 len = mf_getCmdLine(page, &len, (u64)data);
36 p = page;
37 while (len < (count - 1)) {
38 if (!*p || *p == '\n')
39 break;
40 p++;
41 len++;
43 *p = '\n';
44 p++;
45 *p = 0;
47 return p - page;
50 #if 0
51 static int proc_mf_dump_vmlinux(char *page, char **start, off_t off,
52 int count, int *eof, void *data)
54 int sizeToGet = count;
56 if (!capable(CAP_SYS_ADMIN))
57 return -EACCES;
59 if (mf_getVmlinuxChunk(page, &sizeToGet, off, (u64)data) == 0) {
60 if (sizeToGet != 0) {
61 *start = page + off;
62 return sizeToGet;
64 *eof = 1;
65 return 0;
67 *eof = 1;
68 return 0;
70 #endif
72 static int proc_mf_dump_side(char *page, char **start, off_t off,
73 int count, int *eof, void *data)
75 int len;
76 char mf_current_side = mf_getSide();
78 len = sprintf(page, "%c\n", mf_current_side);
80 if (len <= (off + count))
81 *eof = 1;
82 *start = page + off;
83 len -= off;
84 if (len > count)
85 len = count;
86 if (len < 0)
87 len = 0;
88 return len;
91 static int proc_mf_change_side(struct file *file, const char __user *buffer,
92 unsigned long count, void *data)
94 char stkbuf[10];
96 if (!capable(CAP_SYS_ADMIN))
97 return -EACCES;
99 if (count > (sizeof(stkbuf) - 1))
100 count = sizeof(stkbuf) - 1;
101 if (copy_from_user(stkbuf, buffer, count))
102 return -EFAULT;
103 stkbuf[count] = 0;
104 if ((*stkbuf != 'A') && (*stkbuf != 'B') &&
105 (*stkbuf != 'C') && (*stkbuf != 'D')) {
106 printk(KERN_ERR "mf_proc.c: proc_mf_change_side: invalid side\n");
107 return -EINVAL;
110 mf_setSide(*stkbuf);
112 return count;
115 static int proc_mf_dump_src(char *page, char **start, off_t off,
116 int count, int *eof, void *data)
118 int len;
120 mf_getSrcHistory(page, count);
121 len = count;
122 len -= off;
123 if (len < count) {
124 *eof = 1;
125 if (len <= 0)
126 return 0;
127 } else
128 len = count;
129 *start = page + off;
130 return len;
133 static int proc_mf_change_src(struct file *file, const char __user *buffer,
134 unsigned long count, void *data)
136 char stkbuf[10];
138 if (!capable(CAP_SYS_ADMIN))
139 return -EACCES;
141 if ((count < 4) && (count != 1)) {
142 printk(KERN_ERR "mf_proc: invalid src\n");
143 return -EINVAL;
146 if (count > (sizeof(stkbuf) - 1))
147 count = sizeof(stkbuf) - 1;
148 if (copy_from_user(stkbuf, buffer, count))
149 return -EFAULT;
151 if ((count == 1) && (*stkbuf == '\0'))
152 mf_clearSrc();
153 else
154 mf_displaySrc(*(u32 *)stkbuf);
156 return count;
159 static int proc_mf_change_cmdline(struct file *file, const char *buffer,
160 unsigned long count, void *data)
162 if (!capable(CAP_SYS_ADMIN))
163 return -EACCES;
165 mf_setCmdLine(buffer, count, (u64)data);
167 return count;
170 static ssize_t proc_mf_change_vmlinux(struct file *file,
171 const char __user *buf,
172 size_t count, loff_t *ppos)
174 struct inode * inode = file->f_dentry->d_inode;
175 struct proc_dir_entry * dp = PDE(inode);
176 int rc;
177 if (!capable(CAP_SYS_ADMIN))
178 return -EACCES;
180 rc = mf_setVmlinuxChunk(buf, count, *ppos, (u64)dp->data);
181 if (rc < 0)
182 return rc;
184 *ppos += count;
186 return count;
189 static struct file_operations proc_vmlinux_operations = {
190 .write = proc_mf_change_vmlinux,
193 static int __init mf_proc_init(void)
195 struct proc_dir_entry *mf_proc_root;
196 struct proc_dir_entry *ent;
197 struct proc_dir_entry *mf;
198 char name[2];
199 int i;
201 mf_proc_root = proc_mkdir("iSeries/mf", NULL);
202 if (!mf_proc_root)
203 return 1;
205 name[1] = '\0';
206 for (i = 0; i < 4; i++) {
207 name[0] = 'A' + i;
208 mf = proc_mkdir(name, mf_proc_root);
209 if (!mf)
210 return 1;
212 ent = create_proc_entry("cmdline", S_IFREG|S_IRUSR|S_IWUSR, mf);
213 if (!ent)
214 return 1;
215 ent->nlink = 1;
216 ent->data = (void *)(long)i;
217 ent->read_proc = proc_mf_dump_cmdline;
218 ent->write_proc = proc_mf_change_cmdline;
220 if (i == 3) /* no vmlinux entry for 'D' */
221 continue;
223 ent = create_proc_entry("vmlinux", S_IFREG|S_IWUSR, mf);
224 if (!ent)
225 return 1;
226 ent->nlink = 1;
227 ent->data = (void *)(long)i;
228 ent->proc_fops = &proc_vmlinux_operations;
231 ent = create_proc_entry("side", S_IFREG|S_IRUSR|S_IWUSR, mf_proc_root);
232 if (!ent)
233 return 1;
234 ent->nlink = 1;
235 ent->data = (void *)0;
236 ent->read_proc = proc_mf_dump_side;
237 ent->write_proc = proc_mf_change_side;
239 ent = create_proc_entry("src", S_IFREG|S_IRUSR|S_IWUSR, mf_proc_root);
240 if (!ent)
241 return 1;
242 ent->nlink = 1;
243 ent->data = (void *)0;
244 ent->read_proc = proc_mf_dump_src;
245 ent->write_proc = proc_mf_change_src;
247 return 0;
250 __initcall(mf_proc_init);