2005-04-17 06:20:36 +08:00
|
|
|
|
/*
|
|
|
|
|
* IBM ASM Service Processor Device Driver
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) IBM Corporation, 2004
|
|
|
|
|
*
|
2007-07-17 19:03:58 +08:00
|
|
|
|
* Author: Max Asb<EFBFBD>ck <amax@us.ibm.com>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
2007-07-17 19:03:58 +08:00
|
|
|
|
* Parts of this code are based on an article by Jonathan Corbet
|
2005-04-17 06:20:36 +08:00
|
|
|
|
* that appeared in Linux Weekly News.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The IBMASM file virtual filesystem. It creates the following hierarchy
|
|
|
|
|
* dymamically when mounted from user space:
|
|
|
|
|
*
|
|
|
|
|
* /ibmasm
|
|
|
|
|
* |-- 0
|
|
|
|
|
* | |-- command
|
|
|
|
|
* | |-- event
|
|
|
|
|
* | |-- reverse_heartbeat
|
|
|
|
|
* | `-- remote_video
|
|
|
|
|
* | |-- depth
|
|
|
|
|
* | |-- height
|
|
|
|
|
* | `-- width
|
|
|
|
|
* .
|
|
|
|
|
* .
|
|
|
|
|
* .
|
|
|
|
|
* `-- n
|
|
|
|
|
* |-- command
|
|
|
|
|
* |-- event
|
|
|
|
|
* |-- reverse_heartbeat
|
|
|
|
|
* `-- remote_video
|
|
|
|
|
* |-- depth
|
|
|
|
|
* |-- height
|
|
|
|
|
* `-- width
|
|
|
|
|
*
|
|
|
|
|
* For each service processor the following files are created:
|
|
|
|
|
*
|
|
|
|
|
* command: execute dot commands
|
2007-07-17 19:03:58 +08:00
|
|
|
|
* write: execute a dot command on the service processor
|
|
|
|
|
* read: return the result of a previously executed dot command
|
2005-04-17 06:20:36 +08:00
|
|
|
|
*
|
|
|
|
|
* events: listen for service processor events
|
2007-07-17 19:03:58 +08:00
|
|
|
|
* read: sleep (interruptible) until an event occurs
|
2005-04-17 06:20:36 +08:00
|
|
|
|
* write: wakeup sleeping event listener
|
|
|
|
|
*
|
|
|
|
|
* reverse_heartbeat: send a heartbeat to the service processor
|
2007-07-17 19:03:58 +08:00
|
|
|
|
* read: sleep (interruptible) until the reverse heartbeat fails
|
2005-04-17 06:20:36 +08:00
|
|
|
|
* write: wakeup sleeping heartbeat listener
|
|
|
|
|
*
|
|
|
|
|
* remote_video/width
|
|
|
|
|
* remote_video/height
|
|
|
|
|
* remote_video/width: control remote display settings
|
2007-07-17 19:03:58 +08:00
|
|
|
|
* write: set value
|
|
|
|
|
* read: read value
|
2005-04-17 06:20:36 +08:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <linux/fs.h>
|
|
|
|
|
#include <linux/pagemap.h>
|
|
|
|
|
#include <asm/uaccess.h>
|
|
|
|
|
#include <asm/io.h>
|
|
|
|
|
#include "ibmasm.h"
|
|
|
|
|
#include "remote.h"
|
|
|
|
|
#include "dot_command.h"
|
|
|
|
|
|
|
|
|
|
#define IBMASMFS_MAGIC 0x66726f67
|
|
|
|
|
|
|
|
|
|
static LIST_HEAD(service_processors);
|
|
|
|
|
|
|
|
|
|
static struct inode *ibmasmfs_make_inode(struct super_block *sb, int mode);
|
|
|
|
|
static void ibmasmfs_create_files (struct super_block *sb, struct dentry *root);
|
|
|
|
|
static int ibmasmfs_fill_super (struct super_block *sb, void *data, int silent);
|
|
|
|
|
|
|
|
|
|
|
[PATCH] VFS: Permit filesystem to override root dentry on mount
Extend the get_sb() filesystem operation to take an extra argument that
permits the VFS to pass in the target vfsmount that defines the mountpoint.
The filesystem is then required to manually set the superblock and root dentry
pointers. For most filesystems, this should be done with simple_set_mnt()
which will set the superblock pointer and then set the root dentry to the
superblock's s_root (as per the old default behaviour).
The get_sb() op now returns an integer as there's now no need to return the
superblock pointer.
This patch permits a superblock to be implicitly shared amongst several mount
points, such as can be done with NFS to avoid potential inode aliasing. In
such a case, simple_set_mnt() would not be called, and instead the mnt_root
and mnt_sb would be set directly.
The patch also makes the following changes:
(*) the get_sb_*() convenience functions in the core kernel now take a vfsmount
pointer argument and return an integer, so most filesystems have to change
very little.
(*) If one of the convenience function is not used, then get_sb() should
normally call simple_set_mnt() to instantiate the vfsmount. This will
always return 0, and so can be tail-called from get_sb().
(*) generic_shutdown_super() now calls shrink_dcache_sb() to clean up the
dcache upon superblock destruction rather than shrink_dcache_anon().
This is required because the superblock may now have multiple trees that
aren't actually bound to s_root, but that still need to be cleaned up. The
currently called functions assume that the whole tree is rooted at s_root,
and that anonymous dentries are not the roots of trees which results in
dentries being left unculled.
However, with the way NFS superblock sharing are currently set to be
implemented, these assumptions are violated: the root of the filesystem is
simply a dummy dentry and inode (the real inode for '/' may well be
inaccessible), and all the vfsmounts are rooted on anonymous[*] dentries
with child trees.
[*] Anonymous until discovered from another tree.
(*) The documentation has been adjusted, including the additional bit of
changing ext2_* into foo_* in the documentation.
[akpm@osdl.org: convert ipath_fs, do other stuff]
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Al Viro <viro@zeniv.linux.org.uk>
Cc: Nathan Scott <nathans@sgi.com>
Cc: Roland Dreier <rolandd@cisco.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-06-23 17:02:57 +08:00
|
|
|
|
static int ibmasmfs_get_super(struct file_system_type *fst,
|
|
|
|
|
int flags, const char *name, void *data,
|
|
|
|
|
struct vfsmount *mnt)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
{
|
[PATCH] VFS: Permit filesystem to override root dentry on mount
Extend the get_sb() filesystem operation to take an extra argument that
permits the VFS to pass in the target vfsmount that defines the mountpoint.
The filesystem is then required to manually set the superblock and root dentry
pointers. For most filesystems, this should be done with simple_set_mnt()
which will set the superblock pointer and then set the root dentry to the
superblock's s_root (as per the old default behaviour).
The get_sb() op now returns an integer as there's now no need to return the
superblock pointer.
This patch permits a superblock to be implicitly shared amongst several mount
points, such as can be done with NFS to avoid potential inode aliasing. In
such a case, simple_set_mnt() would not be called, and instead the mnt_root
and mnt_sb would be set directly.
The patch also makes the following changes:
(*) the get_sb_*() convenience functions in the core kernel now take a vfsmount
pointer argument and return an integer, so most filesystems have to change
very little.
(*) If one of the convenience function is not used, then get_sb() should
normally call simple_set_mnt() to instantiate the vfsmount. This will
always return 0, and so can be tail-called from get_sb().
(*) generic_shutdown_super() now calls shrink_dcache_sb() to clean up the
dcache upon superblock destruction rather than shrink_dcache_anon().
This is required because the superblock may now have multiple trees that
aren't actually bound to s_root, but that still need to be cleaned up. The
currently called functions assume that the whole tree is rooted at s_root,
and that anonymous dentries are not the roots of trees which results in
dentries being left unculled.
However, with the way NFS superblock sharing are currently set to be
implemented, these assumptions are violated: the root of the filesystem is
simply a dummy dentry and inode (the real inode for '/' may well be
inaccessible), and all the vfsmounts are rooted on anonymous[*] dentries
with child trees.
[*] Anonymous until discovered from another tree.
(*) The documentation has been adjusted, including the additional bit of
changing ext2_* into foo_* in the documentation.
[akpm@osdl.org: convert ipath_fs, do other stuff]
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Al Viro <viro@zeniv.linux.org.uk>
Cc: Nathan Scott <nathans@sgi.com>
Cc: Roland Dreier <rolandd@cisco.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-06-23 17:02:57 +08:00
|
|
|
|
return get_sb_single(fst, flags, data, ibmasmfs_fill_super, mnt);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct super_operations ibmasmfs_s_ops = {
|
|
|
|
|
.statfs = simple_statfs,
|
|
|
|
|
.drop_inode = generic_delete_inode,
|
|
|
|
|
};
|
|
|
|
|
|
2006-03-28 17:56:42 +08:00
|
|
|
|
static const struct file_operations *ibmasmfs_dir_ops = &simple_dir_operations;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
|
static struct file_system_type ibmasmfs_type = {
|
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
|
.name = "ibmasmfs",
|
|
|
|
|
.get_sb = ibmasmfs_get_super,
|
|
|
|
|
.kill_sb = kill_litter_super,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int ibmasmfs_fill_super (struct super_block *sb, void *data, int silent)
|
|
|
|
|
{
|
|
|
|
|
struct inode *root;
|
|
|
|
|
struct dentry *root_dentry;
|
|
|
|
|
|
|
|
|
|
sb->s_blocksize = PAGE_CACHE_SIZE;
|
|
|
|
|
sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
|
|
|
|
|
sb->s_magic = IBMASMFS_MAGIC;
|
|
|
|
|
sb->s_op = &ibmasmfs_s_ops;
|
|
|
|
|
sb->s_time_gran = 1;
|
|
|
|
|
|
|
|
|
|
root = ibmasmfs_make_inode (sb, S_IFDIR | 0500);
|
|
|
|
|
if (!root)
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
|
|
root->i_op = &simple_dir_inode_operations;
|
|
|
|
|
root->i_fop = ibmasmfs_dir_ops;
|
|
|
|
|
|
|
|
|
|
root_dentry = d_alloc_root(root);
|
|
|
|
|
if (!root_dentry) {
|
|
|
|
|
iput(root);
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
}
|
|
|
|
|
sb->s_root = root_dentry;
|
|
|
|
|
|
|
|
|
|
ibmasmfs_create_files(sb, root_dentry);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct inode *ibmasmfs_make_inode(struct super_block *sb, int mode)
|
|
|
|
|
{
|
|
|
|
|
struct inode *ret = new_inode(sb);
|
|
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
|
ret->i_mode = mode;
|
|
|
|
|
ret->i_atime = ret->i_mtime = ret->i_ctime = CURRENT_TIME;
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct dentry *ibmasmfs_create_file (struct super_block *sb,
|
|
|
|
|
struct dentry *parent,
|
2007-07-17 19:03:58 +08:00
|
|
|
|
const char *name,
|
2007-02-12 16:55:34 +08:00
|
|
|
|
const struct file_operations *fops,
|
2005-04-17 06:20:36 +08:00
|
|
|
|
void *data,
|
|
|
|
|
int mode)
|
|
|
|
|
{
|
|
|
|
|
struct dentry *dentry;
|
|
|
|
|
struct inode *inode;
|
|
|
|
|
|
|
|
|
|
dentry = d_alloc_name(parent, name);
|
|
|
|
|
if (!dentry)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
inode = ibmasmfs_make_inode(sb, S_IFREG | mode);
|
|
|
|
|
if (!inode) {
|
|
|
|
|
dput(dentry);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inode->i_fop = fops;
|
2006-09-27 16:50:46 +08:00
|
|
|
|
inode->i_private = data;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
|
d_add(dentry, inode);
|
|
|
|
|
return dentry;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct dentry *ibmasmfs_create_dir (struct super_block *sb,
|
|
|
|
|
struct dentry *parent,
|
|
|
|
|
const char *name)
|
|
|
|
|
{
|
|
|
|
|
struct dentry *dentry;
|
|
|
|
|
struct inode *inode;
|
|
|
|
|
|
|
|
|
|
dentry = d_alloc_name(parent, name);
|
|
|
|
|
if (!dentry)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
inode = ibmasmfs_make_inode(sb, S_IFDIR | 0500);
|
|
|
|
|
if (!inode) {
|
|
|
|
|
dput(dentry);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inode->i_op = &simple_dir_inode_operations;
|
|
|
|
|
inode->i_fop = ibmasmfs_dir_ops;
|
|
|
|
|
|
|
|
|
|
d_add(dentry, inode);
|
|
|
|
|
return dentry;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ibmasmfs_register(void)
|
|
|
|
|
{
|
|
|
|
|
return register_filesystem(&ibmasmfs_type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ibmasmfs_unregister(void)
|
|
|
|
|
{
|
|
|
|
|
unregister_filesystem(&ibmasmfs_type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ibmasmfs_add_sp(struct service_processor *sp)
|
|
|
|
|
{
|
|
|
|
|
list_add(&sp->node, &service_processors);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* struct to save state between command file operations */
|
|
|
|
|
struct ibmasmfs_command_data {
|
|
|
|
|
struct service_processor *sp;
|
|
|
|
|
struct command *command;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* struct to save state between event file operations */
|
|
|
|
|
struct ibmasmfs_event_data {
|
|
|
|
|
struct service_processor *sp;
|
|
|
|
|
struct event_reader reader;
|
|
|
|
|
int active;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* struct to save state between reverse heartbeat file operations */
|
|
|
|
|
struct ibmasmfs_heartbeat_data {
|
|
|
|
|
struct service_processor *sp;
|
|
|
|
|
struct reverse_heartbeat heartbeat;
|
|
|
|
|
int active;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int command_file_open(struct inode *inode, struct file *file)
|
|
|
|
|
{
|
|
|
|
|
struct ibmasmfs_command_data *command_data;
|
|
|
|
|
|
2006-09-27 16:50:46 +08:00
|
|
|
|
if (!inode->i_private)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
|
|
command_data = kmalloc(sizeof(struct ibmasmfs_command_data), GFP_KERNEL);
|
|
|
|
|
if (!command_data)
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
|
|
command_data->command = NULL;
|
2006-09-27 16:50:46 +08:00
|
|
|
|
command_data->sp = inode->i_private;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
file->private_data = command_data;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int command_file_close(struct inode *inode, struct file *file)
|
|
|
|
|
{
|
|
|
|
|
struct ibmasmfs_command_data *command_data = file->private_data;
|
|
|
|
|
|
|
|
|
|
if (command_data->command)
|
2007-07-17 19:03:58 +08:00
|
|
|
|
command_put(command_data->command);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
|
kfree(command_data);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ssize_t command_file_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
|
|
|
|
|
{
|
|
|
|
|
struct ibmasmfs_command_data *command_data = file->private_data;
|
|
|
|
|
struct command *cmd;
|
|
|
|
|
int len;
|
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
|
|
if (*offset < 0)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
if (count == 0 || count > IBMASM_CMD_MAX_BUFFER_SIZE)
|
|
|
|
|
return 0;
|
|
|
|
|
if (*offset != 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
spin_lock_irqsave(&command_data->sp->lock, flags);
|
|
|
|
|
cmd = command_data->command;
|
|
|
|
|
if (cmd == NULL) {
|
|
|
|
|
spin_unlock_irqrestore(&command_data->sp->lock, flags);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
command_data->command = NULL;
|
|
|
|
|
spin_unlock_irqrestore(&command_data->sp->lock, flags);
|
|
|
|
|
|
|
|
|
|
if (cmd->status != IBMASM_CMD_COMPLETE) {
|
|
|
|
|
command_put(cmd);
|
|
|
|
|
return -EIO;
|
|
|
|
|
}
|
|
|
|
|
len = min(count, cmd->buffer_size);
|
|
|
|
|
if (copy_to_user(buf, cmd->buffer, len)) {
|
|
|
|
|
command_put(cmd);
|
|
|
|
|
return -EFAULT;
|
|
|
|
|
}
|
|
|
|
|
command_put(cmd);
|
|
|
|
|
|
|
|
|
|
return len;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ssize_t command_file_write(struct file *file, const char __user *ubuff, size_t count, loff_t *offset)
|
|
|
|
|
{
|
|
|
|
|
struct ibmasmfs_command_data *command_data = file->private_data;
|
|
|
|
|
struct command *cmd;
|
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
|
|
if (*offset < 0)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
if (count == 0 || count > IBMASM_CMD_MAX_BUFFER_SIZE)
|
|
|
|
|
return 0;
|
|
|
|
|
if (*offset != 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
/* commands are executed sequentially, only one command at a time */
|
|
|
|
|
if (command_data->command)
|
|
|
|
|
return -EAGAIN;
|
|
|
|
|
|
2005-06-22 08:16:36 +08:00
|
|
|
|
cmd = ibmasm_new_command(command_data->sp, count);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
if (!cmd)
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
|
|
if (copy_from_user(cmd->buffer, ubuff, count)) {
|
|
|
|
|
command_put(cmd);
|
|
|
|
|
return -EFAULT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
spin_lock_irqsave(&command_data->sp->lock, flags);
|
|
|
|
|
if (command_data->command) {
|
|
|
|
|
spin_unlock_irqrestore(&command_data->sp->lock, flags);
|
|
|
|
|
command_put(cmd);
|
|
|
|
|
return -EAGAIN;
|
|
|
|
|
}
|
|
|
|
|
command_data->command = cmd;
|
|
|
|
|
spin_unlock_irqrestore(&command_data->sp->lock, flags);
|
|
|
|
|
|
|
|
|
|
ibmasm_exec_command(command_data->sp, cmd);
|
|
|
|
|
ibmasm_wait_for_response(cmd, get_dot_command_timeout(cmd->buffer));
|
|
|
|
|
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int event_file_open(struct inode *inode, struct file *file)
|
|
|
|
|
{
|
|
|
|
|
struct ibmasmfs_event_data *event_data;
|
2007-07-17 19:03:58 +08:00
|
|
|
|
struct service_processor *sp;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
2006-09-27 16:50:46 +08:00
|
|
|
|
if (!inode->i_private)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
2006-09-27 16:50:46 +08:00
|
|
|
|
sp = inode->i_private;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
|
event_data = kmalloc(sizeof(struct ibmasmfs_event_data), GFP_KERNEL);
|
|
|
|
|
if (!event_data)
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
|
|
ibmasm_event_reader_register(sp, &event_data->reader);
|
|
|
|
|
|
|
|
|
|
event_data->sp = sp;
|
2005-06-22 08:16:33 +08:00
|
|
|
|
event_data->active = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
file->private_data = event_data;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int event_file_close(struct inode *inode, struct file *file)
|
|
|
|
|
{
|
|
|
|
|
struct ibmasmfs_event_data *event_data = file->private_data;
|
|
|
|
|
|
|
|
|
|
ibmasm_event_reader_unregister(event_data->sp, &event_data->reader);
|
|
|
|
|
kfree(event_data);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ssize_t event_file_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
|
|
|
|
|
{
|
|
|
|
|
struct ibmasmfs_event_data *event_data = file->private_data;
|
|
|
|
|
struct event_reader *reader = &event_data->reader;
|
2005-06-22 08:16:33 +08:00
|
|
|
|
struct service_processor *sp = event_data->sp;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
int ret;
|
2005-06-22 08:16:33 +08:00
|
|
|
|
unsigned long flags;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
|
if (*offset < 0)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
if (count == 0 || count > IBMASM_EVENT_MAX_SIZE)
|
|
|
|
|
return 0;
|
|
|
|
|
if (*offset != 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2005-06-22 08:16:33 +08:00
|
|
|
|
spin_lock_irqsave(&sp->lock, flags);
|
|
|
|
|
if (event_data->active) {
|
|
|
|
|
spin_unlock_irqrestore(&sp->lock, flags);
|
|
|
|
|
return -EBUSY;
|
|
|
|
|
}
|
|
|
|
|
event_data->active = 1;
|
|
|
|
|
spin_unlock_irqrestore(&sp->lock, flags);
|
|
|
|
|
|
|
|
|
|
ret = ibmasm_get_next_event(sp, reader);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
if (ret <= 0)
|
2005-06-22 08:16:33 +08:00
|
|
|
|
goto out;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
2005-06-22 08:16:33 +08:00
|
|
|
|
if (count < reader->data_size) {
|
|
|
|
|
ret = -EINVAL;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
2005-06-22 08:16:33 +08:00
|
|
|
|
if (copy_to_user(buf, reader->data, reader->data_size)) {
|
|
|
|
|
ret = -EFAULT;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
ret = reader->data_size;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
2005-06-22 08:16:33 +08:00
|
|
|
|
out:
|
|
|
|
|
event_data->active = 0;
|
|
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ssize_t event_file_write(struct file *file, const char __user *buf, size_t count, loff_t *offset)
|
|
|
|
|
{
|
|
|
|
|
struct ibmasmfs_event_data *event_data = file->private_data;
|
|
|
|
|
|
|
|
|
|
if (*offset < 0)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
if (count != 1)
|
|
|
|
|
return 0;
|
|
|
|
|
if (*offset != 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2005-06-22 08:16:33 +08:00
|
|
|
|
ibmasm_cancel_next_event(&event_data->reader);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int r_heartbeat_file_open(struct inode *inode, struct file *file)
|
|
|
|
|
{
|
|
|
|
|
struct ibmasmfs_heartbeat_data *rhbeat;
|
|
|
|
|
|
2006-09-27 16:50:46 +08:00
|
|
|
|
if (!inode->i_private)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
|
|
rhbeat = kmalloc(sizeof(struct ibmasmfs_heartbeat_data), GFP_KERNEL);
|
|
|
|
|
if (!rhbeat)
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
2006-09-27 16:50:46 +08:00
|
|
|
|
rhbeat->sp = inode->i_private;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
rhbeat->active = 0;
|
|
|
|
|
ibmasm_init_reverse_heartbeat(rhbeat->sp, &rhbeat->heartbeat);
|
|
|
|
|
file->private_data = rhbeat;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int r_heartbeat_file_close(struct inode *inode, struct file *file)
|
|
|
|
|
{
|
|
|
|
|
struct ibmasmfs_heartbeat_data *rhbeat = file->private_data;
|
|
|
|
|
|
|
|
|
|
kfree(rhbeat);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ssize_t r_heartbeat_file_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
|
|
|
|
|
{
|
|
|
|
|
struct ibmasmfs_heartbeat_data *rhbeat = file->private_data;
|
|
|
|
|
unsigned long flags;
|
|
|
|
|
int result;
|
|
|
|
|
|
|
|
|
|
if (*offset < 0)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
if (count == 0 || count > 1024)
|
|
|
|
|
return 0;
|
|
|
|
|
if (*offset != 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
/* allow only one reverse heartbeat per process */
|
|
|
|
|
spin_lock_irqsave(&rhbeat->sp->lock, flags);
|
|
|
|
|
if (rhbeat->active) {
|
|
|
|
|
spin_unlock_irqrestore(&rhbeat->sp->lock, flags);
|
|
|
|
|
return -EBUSY;
|
|
|
|
|
}
|
|
|
|
|
rhbeat->active = 1;
|
|
|
|
|
spin_unlock_irqrestore(&rhbeat->sp->lock, flags);
|
|
|
|
|
|
|
|
|
|
result = ibmasm_start_reverse_heartbeat(rhbeat->sp, &rhbeat->heartbeat);
|
|
|
|
|
rhbeat->active = 0;
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ssize_t r_heartbeat_file_write(struct file *file, const char __user *buf, size_t count, loff_t *offset)
|
|
|
|
|
{
|
|
|
|
|
struct ibmasmfs_heartbeat_data *rhbeat = file->private_data;
|
|
|
|
|
|
|
|
|
|
if (*offset < 0)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
if (count != 1)
|
|
|
|
|
return 0;
|
|
|
|
|
if (*offset != 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (rhbeat->active)
|
|
|
|
|
ibmasm_stop_reverse_heartbeat(&rhbeat->heartbeat);
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int remote_settings_file_open(struct inode *inode, struct file *file)
|
|
|
|
|
{
|
2006-09-27 16:50:46 +08:00
|
|
|
|
file->private_data = inode->i_private;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int remote_settings_file_close(struct inode *inode, struct file *file)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ssize_t remote_settings_file_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
|
|
|
|
|
{
|
|
|
|
|
void __iomem *address = (void __iomem *)file->private_data;
|
|
|
|
|
unsigned char *page;
|
|
|
|
|
int retval;
|
|
|
|
|
int len = 0;
|
|
|
|
|
unsigned int value;
|
|
|
|
|
|
|
|
|
|
if (*offset < 0)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
if (count == 0 || count > 1024)
|
|
|
|
|
return 0;
|
|
|
|
|
if (*offset != 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
page = (unsigned char *)__get_free_page(GFP_KERNEL);
|
|
|
|
|
if (!page)
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
|
|
value = readl(address);
|
|
|
|
|
len = sprintf(page, "%d\n", value);
|
|
|
|
|
|
|
|
|
|
if (copy_to_user(buf, page, len)) {
|
|
|
|
|
retval = -EFAULT;
|
|
|
|
|
goto exit;
|
|
|
|
|
}
|
|
|
|
|
*offset += len;
|
|
|
|
|
retval = len;
|
|
|
|
|
|
|
|
|
|
exit:
|
|
|
|
|
free_page((unsigned long)page);
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ssize_t remote_settings_file_write(struct file *file, const char __user *ubuff, size_t count, loff_t *offset)
|
|
|
|
|
{
|
|
|
|
|
void __iomem *address = (void __iomem *)file->private_data;
|
|
|
|
|
char *buff;
|
|
|
|
|
unsigned int value;
|
|
|
|
|
|
|
|
|
|
if (*offset < 0)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
if (count == 0 || count > 1024)
|
|
|
|
|
return 0;
|
|
|
|
|
if (*offset != 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
some kmalloc/memset ->kzalloc (tree wide)
Transform some calls to kmalloc/memset to a single kzalloc (or kcalloc).
Here is a short excerpt of the semantic patch performing
this transformation:
@@
type T2;
expression x;
identifier f,fld;
expression E;
expression E1,E2;
expression e1,e2,e3,y;
statement S;
@@
x =
- kmalloc
+ kzalloc
(E1,E2)
... when != \(x->fld=E;\|y=f(...,x,...);\|f(...,x,...);\|x=E;\|while(...) S\|for(e1;e2;e3) S\)
- memset((T2)x,0,E1);
@@
expression E1,E2,E3;
@@
- kzalloc(E1 * E2,E3)
+ kcalloc(E1,E2,E3)
[akpm@linux-foundation.org: get kcalloc args the right way around]
Signed-off-by: Yoann Padioleau <padator@wanadoo.fr>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Acked-by: Russell King <rmk@arm.linux.org.uk>
Cc: Bryan Wu <bryan.wu@analog.com>
Acked-by: Jiri Slaby <jirislaby@gmail.com>
Cc: Dave Airlie <airlied@linux.ie>
Acked-by: Roland Dreier <rolandd@cisco.com>
Cc: Jiri Kosina <jkosina@suse.cz>
Acked-by: Dmitry Torokhov <dtor@mail.ru>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Acked-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Acked-by: Pierre Ossman <drzeus-list@drzeus.cx>
Cc: Jeff Garzik <jeff@garzik.org>
Cc: "David S. Miller" <davem@davemloft.net>
Acked-by: Greg KH <greg@kroah.com>
Cc: James Bottomley <James.Bottomley@steeleye.com>
Cc: "Antonino A. Daplas" <adaplas@pol.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-19 16:49:03 +08:00
|
|
|
|
buff = kzalloc (count + 1, GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
if (!buff)
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (copy_from_user(buff, ubuff, count)) {
|
|
|
|
|
kfree(buff);
|
|
|
|
|
return -EFAULT;
|
|
|
|
|
}
|
2007-07-17 19:03:58 +08:00
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
|
value = simple_strtoul(buff, NULL, 10);
|
|
|
|
|
writel(value, address);
|
|
|
|
|
kfree(buff);
|
|
|
|
|
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-12 16:55:34 +08:00
|
|
|
|
static const struct file_operations command_fops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
|
.open = command_file_open,
|
|
|
|
|
.release = command_file_close,
|
|
|
|
|
.read = command_file_read,
|
|
|
|
|
.write = command_file_write,
|
|
|
|
|
};
|
|
|
|
|
|
2007-02-12 16:55:34 +08:00
|
|
|
|
static const struct file_operations event_fops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
|
.open = event_file_open,
|
|
|
|
|
.release = event_file_close,
|
|
|
|
|
.read = event_file_read,
|
|
|
|
|
.write = event_file_write,
|
|
|
|
|
};
|
|
|
|
|
|
2007-02-12 16:55:34 +08:00
|
|
|
|
static const struct file_operations r_heartbeat_fops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
|
.open = r_heartbeat_file_open,
|
|
|
|
|
.release = r_heartbeat_file_close,
|
|
|
|
|
.read = r_heartbeat_file_read,
|
|
|
|
|
.write = r_heartbeat_file_write,
|
|
|
|
|
};
|
|
|
|
|
|
2007-02-12 16:55:34 +08:00
|
|
|
|
static const struct file_operations remote_settings_fops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
|
.open = remote_settings_file_open,
|
|
|
|
|
.release = remote_settings_file_close,
|
|
|
|
|
.read = remote_settings_file_read,
|
|
|
|
|
.write = remote_settings_file_write,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void ibmasmfs_create_files (struct super_block *sb, struct dentry *root)
|
|
|
|
|
{
|
|
|
|
|
struct list_head *entry;
|
|
|
|
|
struct service_processor *sp;
|
|
|
|
|
|
|
|
|
|
list_for_each(entry, &service_processors) {
|
|
|
|
|
struct dentry *dir;
|
|
|
|
|
struct dentry *remote_dir;
|
|
|
|
|
sp = list_entry(entry, struct service_processor, node);
|
|
|
|
|
dir = ibmasmfs_create_dir(sb, root, sp->dirname);
|
|
|
|
|
if (!dir)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
ibmasmfs_create_file(sb, dir, "command", &command_fops, sp, S_IRUSR|S_IWUSR);
|
|
|
|
|
ibmasmfs_create_file(sb, dir, "event", &event_fops, sp, S_IRUSR|S_IWUSR);
|
|
|
|
|
ibmasmfs_create_file(sb, dir, "reverse_heartbeat", &r_heartbeat_fops, sp, S_IRUSR|S_IWUSR);
|
|
|
|
|
|
|
|
|
|
remote_dir = ibmasmfs_create_dir(sb, dir, "remote_video");
|
|
|
|
|
if (!remote_dir)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
ibmasmfs_create_file(sb, remote_dir, "width", &remote_settings_fops, (void *)display_width(sp), S_IRUSR|S_IWUSR);
|
|
|
|
|
ibmasmfs_create_file(sb, remote_dir, "height", &remote_settings_fops, (void *)display_height(sp), S_IRUSR|S_IWUSR);
|
|
|
|
|
ibmasmfs_create_file(sb, remote_dir, "depth", &remote_settings_fops, (void *)display_depth(sp), S_IRUSR|S_IWUSR);
|
|
|
|
|
}
|
|
|
|
|
}
|