3 * Copyright (C) 2001 Kyle A. Lucke IBM Corporation
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.
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
)
34 len
= mf_getCmdLine(page
, &len
, (u64
)data
);
37 while (len
< (count
- 1)) {
38 if (!*p
|| *p
== '\n')
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
))
59 if (mf_getVmlinuxChunk(page
, &sizeToGet
, off
, (u64
)data
) == 0) {
72 static int proc_mf_dump_side(char *page
, char **start
, off_t off
,
73 int count
, int *eof
, void *data
)
76 char mf_current_side
= mf_getSide();
78 len
= sprintf(page
, "%c\n", mf_current_side
);
80 if (len
<= (off
+ count
))
91 static int proc_mf_change_side(struct file
*file
, const char __user
*buffer
,
92 unsigned long count
, void *data
)
96 if (!capable(CAP_SYS_ADMIN
))
99 if (count
> (sizeof(stkbuf
) - 1))
100 count
= sizeof(stkbuf
) - 1;
101 if (copy_from_user(stkbuf
, buffer
, count
))
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");
115 static int proc_mf_dump_src(char *page
, char **start
, off_t off
,
116 int count
, int *eof
, void *data
)
120 mf_getSrcHistory(page
, count
);
133 static int proc_mf_change_src(struct file
*file
, const char __user
*buffer
,
134 unsigned long count
, void *data
)
138 if (!capable(CAP_SYS_ADMIN
))
141 if ((count
< 4) && (count
!= 1)) {
142 printk(KERN_ERR
"mf_proc: invalid src\n");
146 if (count
> (sizeof(stkbuf
) - 1))
147 count
= sizeof(stkbuf
) - 1;
148 if (copy_from_user(stkbuf
, buffer
, count
))
151 if ((count
== 1) && (*stkbuf
== '\0'))
154 mf_displaySrc(*(u32
*)stkbuf
);
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
))
165 mf_setCmdLine(buffer
, count
, (u64
)data
);
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
);
177 if (!capable(CAP_SYS_ADMIN
))
180 rc
= mf_setVmlinuxChunk(buf
, count
, *ppos
, (u64
)dp
->data
);
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
;
201 mf_proc_root
= proc_mkdir("iSeries/mf", NULL
);
206 for (i
= 0; i
< 4; i
++) {
208 mf
= proc_mkdir(name
, mf_proc_root
);
212 ent
= create_proc_entry("cmdline", S_IFREG
|S_IRUSR
|S_IWUSR
, mf
);
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' */
223 ent
= create_proc_entry("vmlinux", S_IFREG
|S_IWUSR
, mf
);
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
);
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
);
243 ent
->data
= (void *)0;
244 ent
->read_proc
= proc_mf_dump_src
;
245 ent
->write_proc
= proc_mf_change_src
;
250 __initcall(mf_proc_init
);