2019-05-27 13:55:05 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* IBM ASM Service Processor Device Driver
|
|
|
|
*
|
|
|
|
* Copyright (C) IBM Corporation, 2004
|
|
|
|
*
|
2011-12-30 05:09:01 +07:00
|
|
|
* Author: Max Asböck <amax@us.ibm.com>
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2007-07-17 18:03:58 +07:00
|
|
|
* Parts of this code are based on an article by Jonathan Corbet
|
2005-04-17 05:20:36 +07:00
|
|
|
* that appeared in Linux Weekly News.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The IBMASM file virtual filesystem. It creates the following hierarchy
|
2011-04-08 22:23:23 +07:00
|
|
|
* dynamically when mounted from user space:
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
* /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 18:03:58 +07:00
|
|
|
* write: execute a dot command on the service processor
|
|
|
|
* read: return the result of a previously executed dot command
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
* events: listen for service processor events
|
2007-07-17 18:03:58 +07:00
|
|
|
* read: sleep (interruptible) until an event occurs
|
2005-04-17 05:20:36 +07:00
|
|
|
* write: wakeup sleeping event listener
|
|
|
|
*
|
|
|
|
* reverse_heartbeat: send a heartbeat to the service processor
|
2007-07-17 18:03:58 +07:00
|
|
|
* read: sleep (interruptible) until the reverse heartbeat fails
|
2005-04-17 05:20:36 +07:00
|
|
|
* write: wakeup sleeping heartbeat listener
|
|
|
|
*
|
|
|
|
* remote_video/width
|
|
|
|
* remote_video/height
|
|
|
|
* remote_video/width: control remote display settings
|
2007-07-17 18:03:58 +07:00
|
|
|
* write: set value
|
|
|
|
* read: read value
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/fs.h>
|
2019-03-25 23:38:29 +07:00
|
|
|
#include <linux/fs_context.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/pagemap.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2016-12-25 02:46:01 +07:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#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);
|
2012-02-13 10:08:01 +07:00
|
|
|
static void ibmasmfs_create_files (struct super_block *sb);
|
2019-03-25 23:38:29 +07:00
|
|
|
static int ibmasmfs_fill_super(struct super_block *sb, struct fs_context *fc);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2019-03-25 23:38:29 +07:00
|
|
|
static int ibmasmfs_get_tree(struct fs_context *fc)
|
|
|
|
{
|
|
|
|
return get_tree_single(fc, ibmasmfs_fill_super);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct fs_context_operations ibmasmfs_context_ops = {
|
|
|
|
.get_tree = ibmasmfs_get_tree,
|
|
|
|
};
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2019-03-25 23:38:29 +07:00
|
|
|
static int ibmasmfs_init_fs_context(struct fs_context *fc)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2019-03-25 23:38:29 +07:00
|
|
|
fc->ops = &ibmasmfs_context_ops;
|
|
|
|
return 0;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2009-09-22 07:01:09 +07:00
|
|
|
static const struct super_operations ibmasmfs_s_ops = {
|
2005-04-17 05:20:36 +07:00
|
|
|
.statfs = simple_statfs,
|
|
|
|
.drop_inode = generic_delete_inode,
|
|
|
|
};
|
|
|
|
|
2006-03-28 16:56:42 +07:00
|
|
|
static const struct file_operations *ibmasmfs_dir_ops = &simple_dir_operations;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
static struct file_system_type ibmasmfs_type = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = "ibmasmfs",
|
2019-03-25 23:38:29 +07:00
|
|
|
.init_fs_context = ibmasmfs_init_fs_context,
|
2005-04-17 05:20:36 +07:00
|
|
|
.kill_sb = kill_litter_super,
|
|
|
|
};
|
2013-03-03 10:39:14 +07:00
|
|
|
MODULE_ALIAS_FS("ibmasmfs");
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2019-03-25 23:38:29 +07:00
|
|
|
static int ibmasmfs_fill_super(struct super_block *sb, struct fs_context *fc)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct inode *root;
|
|
|
|
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 19:29:47 +07:00
|
|
|
sb->s_blocksize = PAGE_SIZE;
|
|
|
|
sb->s_blocksize_bits = PAGE_SHIFT;
|
2005-04-17 05:20:36 +07:00
|
|
|
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;
|
|
|
|
|
2012-02-13 10:08:01 +07:00
|
|
|
sb->s_root = d_make_root(root);
|
|
|
|
if (!sb->s_root)
|
2005-04-17 05:20:36 +07:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2012-02-13 10:08:01 +07:00
|
|
|
ibmasmfs_create_files(sb);
|
2005-04-17 05:20:36 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct inode *ibmasmfs_make_inode(struct super_block *sb, int mode)
|
|
|
|
{
|
|
|
|
struct inode *ret = new_inode(sb);
|
|
|
|
|
|
|
|
if (ret) {
|
2010-10-23 22:19:54 +07:00
|
|
|
ret->i_ino = get_next_ino();
|
2005-04-17 05:20:36 +07:00
|
|
|
ret->i_mode = mode;
|
2016-09-14 21:48:04 +07:00
|
|
|
ret->i_atime = ret->i_mtime = ret->i_ctime = current_time(ret);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-07-19 21:09:56 +07:00
|
|
|
static struct dentry *ibmasmfs_create_file(struct dentry *parent,
|
2007-07-17 18:03:58 +07:00
|
|
|
const char *name,
|
2007-02-12 15:55:34 +07:00
|
|
|
const struct file_operations *fops,
|
2005-04-17 05:20:36 +07:00
|
|
|
void *data,
|
|
|
|
int mode)
|
|
|
|
{
|
|
|
|
struct dentry *dentry;
|
|
|
|
struct inode *inode;
|
|
|
|
|
|
|
|
dentry = d_alloc_name(parent, name);
|
|
|
|
if (!dentry)
|
|
|
|
return NULL;
|
|
|
|
|
2013-07-19 21:09:56 +07:00
|
|
|
inode = ibmasmfs_make_inode(parent->d_sb, S_IFREG | mode);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (!inode) {
|
|
|
|
dput(dentry);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
inode->i_fop = fops;
|
2006-09-27 15:50:46 +07:00
|
|
|
inode->i_private = data;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
d_add(dentry, inode);
|
|
|
|
return dentry;
|
|
|
|
}
|
|
|
|
|
2013-07-19 21:09:56 +07:00
|
|
|
static struct dentry *ibmasmfs_create_dir(struct dentry *parent,
|
2005-04-17 05:20:36 +07:00
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
struct dentry *dentry;
|
|
|
|
struct inode *inode;
|
|
|
|
|
|
|
|
dentry = d_alloc_name(parent, name);
|
|
|
|
if (!dentry)
|
|
|
|
return NULL;
|
|
|
|
|
2013-07-19 21:09:56 +07:00
|
|
|
inode = ibmasmfs_make_inode(parent->d_sb, S_IFDIR | 0500);
|
2005-04-17 05:20:36 +07:00
|
|
|
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 15:50:46 +07:00
|
|
|
if (!inode->i_private)
|
2005-04-17 05:20:36 +07: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 15:50:46 +07:00
|
|
|
command_data->sp = inode->i_private;
|
2005-04-17 05:20:36 +07: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 18:03:58 +07:00
|
|
|
command_put(command_data->command);
|
2005-04-17 05:20:36 +07: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 07:16:36 +07:00
|
|
|
cmd = ibmasm_new_command(command_data->sp, count);
|
2005-04-17 05:20:36 +07: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 18:03:58 +07:00
|
|
|
struct service_processor *sp;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2006-09-27 15:50:46 +07:00
|
|
|
if (!inode->i_private)
|
2005-04-17 05:20:36 +07:00
|
|
|
return -ENODEV;
|
|
|
|
|
2006-09-27 15:50:46 +07:00
|
|
|
sp = inode->i_private;
|
2005-04-17 05:20:36 +07: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 07:16:33 +07:00
|
|
|
event_data->active = 0;
|
2005-04-17 05:20:36 +07: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 07:16:33 +07:00
|
|
|
struct service_processor *sp = event_data->sp;
|
2005-04-17 05:20:36 +07:00
|
|
|
int ret;
|
2005-06-22 07:16:33 +07:00
|
|
|
unsigned long flags;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
if (*offset < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
if (count == 0 || count > IBMASM_EVENT_MAX_SIZE)
|
|
|
|
return 0;
|
|
|
|
if (*offset != 0)
|
|
|
|
return 0;
|
|
|
|
|
2005-06-22 07:16:33 +07: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 05:20:36 +07:00
|
|
|
if (ret <= 0)
|
2005-06-22 07:16:33 +07:00
|
|
|
goto out;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2005-06-22 07:16:33 +07:00
|
|
|
if (count < reader->data_size) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2005-06-22 07:16:33 +07:00
|
|
|
if (copy_to_user(buf, reader->data, reader->data_size)) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
ret = reader->data_size;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2005-06-22 07:16:33 +07:00
|
|
|
out:
|
|
|
|
event_data->active = 0;
|
|
|
|
return ret;
|
2005-04-17 05:20:36 +07: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 07:16:33 +07:00
|
|
|
ibmasm_cancel_next_event(&event_data->reader);
|
2005-04-17 05:20:36 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int r_heartbeat_file_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
struct ibmasmfs_heartbeat_data *rhbeat;
|
|
|
|
|
2006-09-27 15:50:46 +07:00
|
|
|
if (!inode->i_private)
|
2005-04-17 05:20:36 +07:00
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
rhbeat = kmalloc(sizeof(struct ibmasmfs_heartbeat_data), GFP_KERNEL);
|
|
|
|
if (!rhbeat)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2006-09-27 15:50:46 +07:00
|
|
|
rhbeat->sp = inode->i_private;
|
2005-04-17 05:20:36 +07: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_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;
|
|
|
|
int len = 0;
|
|
|
|
unsigned int value;
|
2018-07-07 09:16:33 +07:00
|
|
|
char lbuf[20];
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
value = readl(address);
|
2018-07-07 09:16:33 +07:00
|
|
|
len = snprintf(lbuf, sizeof(lbuf), "%d\n", value);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2018-07-07 09:16:33 +07:00
|
|
|
return simple_read_from_buffer(buf, count, offset, lbuf, len);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
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 15:49:03 +07:00
|
|
|
buff = kzalloc (count + 1, GFP_KERNEL);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (!buff)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
|
|
|
|
if (copy_from_user(buff, ubuff, count)) {
|
|
|
|
kfree(buff);
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
2007-07-17 18:03:58 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
value = simple_strtoul(buff, NULL, 10);
|
|
|
|
writel(value, address);
|
|
|
|
kfree(buff);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2007-02-12 15:55:34 +07:00
|
|
|
static const struct file_operations command_fops = {
|
2005-04-17 05:20:36 +07:00
|
|
|
.open = command_file_open,
|
|
|
|
.release = command_file_close,
|
|
|
|
.read = command_file_read,
|
|
|
|
.write = command_file_write,
|
2010-07-07 03:54:51 +07:00
|
|
|
.llseek = generic_file_llseek,
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
2007-02-12 15:55:34 +07:00
|
|
|
static const struct file_operations event_fops = {
|
2005-04-17 05:20:36 +07:00
|
|
|
.open = event_file_open,
|
|
|
|
.release = event_file_close,
|
|
|
|
.read = event_file_read,
|
|
|
|
.write = event_file_write,
|
2010-07-07 03:54:51 +07:00
|
|
|
.llseek = generic_file_llseek,
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
2007-02-12 15:55:34 +07:00
|
|
|
static const struct file_operations r_heartbeat_fops = {
|
2005-04-17 05:20:36 +07:00
|
|
|
.open = r_heartbeat_file_open,
|
|
|
|
.release = r_heartbeat_file_close,
|
|
|
|
.read = r_heartbeat_file_read,
|
|
|
|
.write = r_heartbeat_file_write,
|
2010-07-07 03:54:51 +07:00
|
|
|
.llseek = generic_file_llseek,
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
2007-02-12 15:55:34 +07:00
|
|
|
static const struct file_operations remote_settings_fops = {
|
2012-04-06 04:25:11 +07:00
|
|
|
.open = simple_open,
|
2005-04-17 05:20:36 +07:00
|
|
|
.release = remote_settings_file_close,
|
|
|
|
.read = remote_settings_file_read,
|
|
|
|
.write = remote_settings_file_write,
|
2010-07-07 03:54:51 +07:00
|
|
|
.llseek = generic_file_llseek,
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-02-13 10:08:01 +07:00
|
|
|
static void ibmasmfs_create_files (struct super_block *sb)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
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);
|
2013-07-19 21:09:56 +07:00
|
|
|
dir = ibmasmfs_create_dir(sb->s_root, sp->dirname);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (!dir)
|
|
|
|
continue;
|
|
|
|
|
2013-07-19 21:09:56 +07:00
|
|
|
ibmasmfs_create_file(dir, "command", &command_fops, sp, S_IRUSR|S_IWUSR);
|
|
|
|
ibmasmfs_create_file(dir, "event", &event_fops, sp, S_IRUSR|S_IWUSR);
|
|
|
|
ibmasmfs_create_file(dir, "reverse_heartbeat", &r_heartbeat_fops, sp, S_IRUSR|S_IWUSR);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2013-07-19 21:09:56 +07:00
|
|
|
remote_dir = ibmasmfs_create_dir(dir, "remote_video");
|
2005-04-17 05:20:36 +07:00
|
|
|
if (!remote_dir)
|
|
|
|
continue;
|
|
|
|
|
2013-07-19 21:09:56 +07:00
|
|
|
ibmasmfs_create_file(remote_dir, "width", &remote_settings_fops, (void *)display_width(sp), S_IRUSR|S_IWUSR);
|
|
|
|
ibmasmfs_create_file(remote_dir, "height", &remote_settings_fops, (void *)display_height(sp), S_IRUSR|S_IWUSR);
|
|
|
|
ibmasmfs_create_file(remote_dir, "depth", &remote_settings_fops, (void *)display_depth(sp), S_IRUSR|S_IWUSR);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
}
|