Commit 498efe94 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] ppc64: Tidy up the mf_proc code, from Stephen Rothwell

From: Anton Blanchard <anton@samba.org>

Tidy up the mf_proc code, from Stephen Rothwell
parent 008d0de4
......@@ -36,7 +36,6 @@
#include <asm/nvram.h>
#include <asm/time.h>
#include <asm/iSeries/ItSpCommArea.h>
#include <asm/iSeries/mf_proc.h>
#include <asm/iSeries/iSeries_proc.h>
#include <asm/uaccess.h>
#include <linux/pci.h>
......
......@@ -16,137 +16,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* Change Activity: */
/* End Change Activity */
#ifndef _MF_PROC_H
#include <asm/iSeries/mf_proc.h>
#endif
#ifndef MF_H_INCLUDED
#include <asm/iSeries/mf.h>
#endif
#include <asm/uaccess.h>
#include <asm/iSeries/mf.h>
static struct proc_dir_entry *mf_proc_root = NULL;
int proc_mf_dump_cmdline
(char *page, char **start, off_t off, int count, int *eof, void *data);
int proc_mf_dump_vmlinux
(char *page, char **start, off_t off, int count, int *eof, void *data);
int proc_mf_dump_side
(char *page, char **start, off_t off, int count, int *eof, void *data);
int proc_mf_change_side
(struct file *file, const char *buffer, unsigned long count, void *data);
int proc_mf_dump_src
(char *page, char **start, off_t off, int count, int *eof, void *data);
int proc_mf_change_src (struct file *file, const char *buffer, unsigned long count, void *data);
int proc_mf_change_cmdline(struct file *file, const char *buffer, unsigned long count, void *data);
int proc_mf_change_vmlinux(struct file *file, const char *buffer, unsigned long count, void *data);
void mf_proc_init(struct proc_dir_entry *iSeries_proc)
{
struct proc_dir_entry *ent = NULL;
struct proc_dir_entry *mf_a = NULL;
struct proc_dir_entry *mf_b = NULL;
struct proc_dir_entry *mf_c = NULL;
struct proc_dir_entry *mf_d = NULL;
mf_proc_root = proc_mkdir("mf", iSeries_proc);
if (!mf_proc_root) return;
mf_a = proc_mkdir("A", mf_proc_root);
if (!mf_a) return;
ent = create_proc_entry("cmdline", S_IFREG|S_IRUSR|S_IWUSR, mf_a);
if (!ent) return;
ent->nlink = 1;
ent->data = (void *)0;
ent->read_proc = proc_mf_dump_cmdline;
ent->write_proc = proc_mf_change_cmdline;
ent = create_proc_entry("vmlinux", S_IFREG|S_IWUSR, mf_a);
if (!ent) return;
ent->nlink = 1;
ent->data = (void *)0;
ent->write_proc = proc_mf_change_vmlinux;
ent->read_proc = NULL;
mf_b = proc_mkdir("B", mf_proc_root);
if (!mf_b) return;
ent = create_proc_entry("cmdline", S_IFREG|S_IRUSR|S_IWUSR, mf_b);
if (!ent) return;
ent->nlink = 1;
ent->data = (void *)1;
ent->read_proc = proc_mf_dump_cmdline;
ent->write_proc = proc_mf_change_cmdline;
ent = create_proc_entry("vmlinux", S_IFREG|S_IWUSR, mf_b);
if (!ent) return;
ent->nlink = 1;
ent->data = (void *)1;
ent->write_proc = proc_mf_change_vmlinux;
ent->read_proc = NULL;
mf_c = proc_mkdir("C", mf_proc_root);
if (!mf_c) return;
ent = create_proc_entry("cmdline", S_IFREG|S_IRUSR|S_IWUSR, mf_c);
if (!ent) return;
ent->nlink = 1;
ent->data = (void *)2;
ent->read_proc = proc_mf_dump_cmdline;
ent->write_proc = proc_mf_change_cmdline;
ent = create_proc_entry("vmlinux", S_IFREG|S_IWUSR, mf_c);
if (!ent) return;
ent->nlink = 1;
ent->data = (void *)2;
ent->write_proc = proc_mf_change_vmlinux;
ent->read_proc = NULL;
mf_d = proc_mkdir("D", mf_proc_root);
if (!mf_d) return;
ent = create_proc_entry("cmdline", S_IFREG|S_IRUSR|S_IWUSR, mf_d);
if (!ent) return;
ent->nlink = 1;
ent->data = (void *)3;
ent->read_proc = proc_mf_dump_cmdline;
ent->write_proc = proc_mf_change_cmdline;
#if 0
ent = create_proc_entry("vmlinux", S_IFREG|S_IRUSR, mf_d);
if (!ent) return;
ent->nlink = 1;
ent->data = (void *)3;
ent->read_proc = proc_mf_dump_vmlinux;
ent->write_proc = NULL;
#endif
ent = create_proc_entry("side", S_IFREG|S_IRUSR|S_IWUSR, mf_proc_root);
if (!ent) return;
ent->nlink = 1;
ent->data = (void *)0;
ent->read_proc = proc_mf_dump_side;
ent->write_proc = proc_mf_change_side;
ent = create_proc_entry("src", S_IFREG|S_IRUSR|S_IWUSR, mf_proc_root);
if (!ent) return;
ent->nlink = 1;
ent->data = (void *)0;
ent->read_proc = proc_mf_dump_src;
ent->write_proc = proc_mf_change_src;
}
int proc_mf_dump_cmdline
(char *page, char **start, off_t off, int count, int *eof, void *data)
static int proc_mf_dump_cmdline(char *page, char **start, off_t off,
int count, int *eof, void *data)
{
int len = count;
char *p;
......@@ -154,13 +30,13 @@ int proc_mf_dump_cmdline
len = mf_getCmdLine(page, &len, (u64)data);
p = page + len - 1;
while ( p > page ) {
if ( (*p == 0) || (*p == ' ') )
while (p > page) {
if ((*p == 0) || (*p == ' '))
--p;
else
break;
}
if ( *p != '\n' ) {
if (*p != '\n') {
++p;
*p = '\n';
}
......@@ -179,61 +55,62 @@ int proc_mf_dump_cmdline
return len;
}
int proc_mf_dump_vmlinux
(char *page, char **start, off_t off, int count, int *eof, void *data)
#if 0
static int proc_mf_dump_vmlinux(char *page, char **start, off_t off,
int count, int *eof, void *data)
{
int sizeToGet = count;
if (!capable(CAP_SYS_ADMIN))
return -EACCES;
if (mf_getVmlinuxChunk(page, &sizeToGet, off, (u64)data) == 0)
{
if (sizeToGet != 0)
{
if (mf_getVmlinuxChunk(page, &sizeToGet, off, (u64)data) == 0) {
if (sizeToGet != 0) {
*start = page + off;
return sizeToGet;
} else {
}
*eof = 1;
return 0;
}
} else {
*eof = 1;
return 0;
}
}
#endif
int proc_mf_dump_side
(char *page, char **start, off_t off, int count, int *eof, void *data)
static int proc_mf_dump_side(char *page, char **start, off_t off,
int count, int *eof, void *data)
{
int len = 0;
int len;
char mf_current_side = mf_getSide();
len = sprintf(page, "%c\n", mf_current_side);
if (len <= off+count) *eof = 1;
if (len <= (off + count))
*eof = 1;
*start = page + off;
len -= off;
if (len>count) len = count;
if (len<0) len = 0;
if (len > count)
len = count;
if (len < 0)
len = 0;
return len;
}
int proc_mf_change_side(struct file *file, const char *buffer, unsigned long count, void *data)
static int proc_mf_change_side(struct file *file, const char __user *buffer,
unsigned long count, void *data)
{
char stkbuf[10];
if (!capable(CAP_SYS_ADMIN))
return -EACCES;
if (count > 9) count = 9;
if (copy_from_user (stkbuf, buffer, count)) {
if (count > (sizeof(stkbuf) - 1))
count = sizeof(stkbuf) - 1;
if (copy_from_user(stkbuf, buffer, count))
return -EFAULT;
}
stkbuf[count] = 0;
if ((*stkbuf != 'A') &&
(*stkbuf != 'B') &&
(*stkbuf != 'C') &&
(*stkbuf != 'D'))
{
if ((*stkbuf != 'A') && (*stkbuf != 'B') &&
(*stkbuf != 'C') && (*stkbuf != 'D')) {
printk(KERN_ERR "mf_proc.c: proc_mf_change_side: invalid side\n");
return -EINVAL;
}
......@@ -243,10 +120,11 @@ int proc_mf_change_side(struct file *file, const char *buffer, unsigned long cou
return count;
}
int proc_mf_dump_src
(char *page, char **start, off_t off, int count, int *eof, void *data)
static int proc_mf_dump_src(char *page, char **start, off_t off,
int count, int *eof, void *data)
{
int len = 0;
int len;
mf_getSrcHistory(page, count);
len = count;
len -= off;
......@@ -260,34 +138,34 @@ int proc_mf_dump_src
return len;
}
int proc_mf_change_src(struct file *file, const char *buffer, unsigned long count, void *data)
static int proc_mf_change_src(struct file *file, const char __user *buffer,
unsigned long count, void *data)
{
char stkbuf[10];
if (!capable(CAP_SYS_ADMIN))
return -EACCES;
if ((count < 4) && (count != 1))
{
if ((count < 4) && (count != 1)) {
printk(KERN_ERR "mf_proc: invalid src\n");
return -EINVAL;
}
if (count > 9) count = 9;
if (copy_from_user (stkbuf, buffer, count)) {
if (count > (sizeof(stkbuf) - 1))
count = sizeof(stkbuf) - 1;
if (copy_from_user(stkbuf, buffer, count))
return -EFAULT;
}
if ((count == 1) && ((*stkbuf) == '\0'))
{
if ((count == 1) && (*stkbuf == '\0'))
mf_clearSrc();
} else {
else
mf_displaySrc(*(u32 *)stkbuf);
}
return count;
}
int proc_mf_change_cmdline(struct file *file, const char *buffer, unsigned long count, void *data)
static int proc_mf_change_cmdline(struct file *file, const char *buffer,
unsigned long count, void *data)
{
if (!capable(CAP_SYS_ADMIN))
return -EACCES;
......@@ -297,7 +175,8 @@ int proc_mf_change_cmdline(struct file *file, const char *buffer, unsigned long
return count;
}
int proc_mf_change_vmlinux(struct file *file, const char *buffer, unsigned long count, void *data)
static int proc_mf_change_vmlinux(struct file *file, const char *buffer,
unsigned long count, void *data)
{
if (!capable(CAP_SYS_ADMIN))
return -EACCES;
......@@ -307,3 +186,70 @@ int proc_mf_change_vmlinux(struct file *file, const char *buffer, unsigned long
return count;
}
void mf_proc_init(struct proc_dir_entry *iSeries_proc)
{
struct proc_dir_entry *ent;
struct proc_dir_entry *mf;
char name[2];
int i;
mf_proc_root = proc_mkdir("mf", iSeries_proc);
if (!mf_proc_root)
return;
name[1] = '\0';
for (i = 0; i < 4; i++) {
name[0] = 'A' + i;
mf = proc_mkdir(name, mf_proc_root);
if (!mf)
return;
ent = create_proc_entry("cmdline", S_IFREG|S_IRUSR|S_IWUSR, mf);
if (!ent)
return;
ent->nlink = 1;
ent->data = (void *)(long)i;
ent->read_proc = proc_mf_dump_cmdline;
ent->write_proc = proc_mf_change_cmdline;
if (i == 3) /* no vmlinux entry for 'D' */
continue;
ent = create_proc_entry("vmlinux", S_IFREG|S_IWUSR, mf);
if (!ent)
return;
ent->nlink = 1;
ent->data = (void *)(long)i;
#if 0
if (i == 3) {
/*
* if we had a 'D' vmlinux entry, it would only
* be readable.
*/
ent->read_proc = proc_mf_dump_vmlinux;
ent->write_proc = NULL;
} else
#endif
{
ent->write_proc = proc_mf_change_vmlinux;
ent->read_proc = NULL;
}
}
ent = create_proc_entry("side", S_IFREG|S_IRUSR|S_IWUSR, mf_proc_root);
if (!ent)
return;
ent->nlink = 1;
ent->data = (void *)0;
ent->read_proc = proc_mf_dump_side;
ent->write_proc = proc_mf_change_side;
ent = create_proc_entry("src", S_IFREG|S_IRUSR|S_IWUSR, mf_proc_root);
if (!ent)
return;
ent->nlink = 1;
ent->data = (void *)0;
ent->read_proc = proc_mf_dump_src;
ent->write_proc = proc_mf_change_src;
}
......@@ -23,61 +23,50 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef MF_H_INCLUDED
#define MF_H_INCLUDED
#include <linux/proc_fs.h>
#include <asm/iSeries/HvTypes.h>
#include <asm/iSeries/HvLpEvent.h>
struct rtc_time;
typedef void (*MFCompleteHandler)( void * clientToken, int returnCode );
extern void mf_allocateLpEvents( HvLpIndex targetLp,
HvLpEvent_Type type,
unsigned size,
unsigned amount,
MFCompleteHandler hdlr,
void * userToken );
typedef void (*MFCompleteHandler)(void *clientToken, int returnCode);
extern void mf_deallocateLpEvents( HvLpIndex targetLp,
HvLpEvent_Type type,
unsigned count,
MFCompleteHandler hdlr,
void * userToken );
extern void mf_allocateLpEvents(HvLpIndex targetLp, HvLpEvent_Type type,
unsigned size, unsigned amount, MFCompleteHandler hdlr,
void *userToken);
extern void mf_deallocateLpEvents(HvLpIndex targetLp, HvLpEvent_Type type,
unsigned count, MFCompleteHandler hdlr, void *userToken);
extern void mf_powerOff( void );
extern void mf_powerOff(void);
extern void mf_reboot(void);
extern void mf_reboot( void );
extern void mf_displaySrc(u32 word);
extern void mf_displayProgress(u16 value);
extern void mf_clearSrc(void);
extern void mf_displaySrc( u32 word );
extern void mf_displayProgress( u16 value );
extern void mf_clearSrc( void );
extern void mf_init( void );
extern void mf_init(void);
extern void mf_setSide(char side);
extern char mf_getSide(void);
extern void mf_setCmdLine(const char *cmdline, int size, u64 side);
extern int mf_getCmdLine(char *cmdline, int *size, u64 side);
extern void mf_getSrcHistory(char *buffer, int size);
extern int mf_setVmlinuxChunk(const char *buffer, int size, int offset, u64 side);
extern int mf_setVmlinuxChunk(const char *buffer, int size, int offset,
u64 side);
extern int mf_getVmlinuxChunk(char *buffer, int *size, int offset, u64 side);
extern int mf_setRtcTime(unsigned long time);
extern int mf_getRtcTime(unsigned long *time);
extern int mf_getRtc( struct rtc_time * tm );
extern int mf_setRtc( struct rtc_time * tm );
extern void mf_proc_init(struct proc_dir_entry *iSeries_proc);
#endif /* MF_H_INCLUDED */
/*
* mf_proc.h
* Copyright (C) 2001 Kyle A. Lucke IBM Corporation
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* Change Activity: */
/* End Change Activity */
#ifndef _MF_PROC_H
#define _MF_PROC_H
#include <linux/proc_fs.h>
void mf_proc_init(struct proc_dir_entry *iSeries_proc);
#endif /* _MF_PROC_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment