kernel-fxtec-pro1x/arch/alpha/kernel/srm_env.c

301 lines
6.8 KiB
C
Raw Normal View History

/*
* srm_env.c - Access to SRM environment
* variables through linux' procfs
*
* (C) 2001,2002,2006 by Jan-Benedict Glaw <jbglaw@lug-owl.de>
*
* This driver is a modified version of Erik Mouw's example proc
* interface, so: thank you, Erik! He can be reached via email at
* <J.A.K.Mouw@its.tudelft.nl>. It is based on an idea
* provided by DEC^WCompaq^WIntel's "Jumpstart" CD. They
* included a patch like this as well. Thanks for idea!
*
* This program is free software; you can redistribute
* it and/or modify it under the terms of the GNU General
* Public License version 2 as published by the Free Software
* Foundation.
*
* 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
*
*/
#include <linux/kernel.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 02:04:11 -06:00
#include <linux/gfp.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <asm/console.h>
#include <asm/uaccess.h>
#include <asm/machvec.h>
#define BASE_DIR "srm_environment" /* Subdir in /proc/ */
#define NAMED_DIR "named_variables" /* Subdir for known variables */
#define NUMBERED_DIR "numbered_variables" /* Subdir for all variables */
#define VERSION "0.0.6" /* Module version */
#define NAME "srm_env" /* Module name */
MODULE_AUTHOR("Jan-Benedict Glaw <jbglaw@lug-owl.de>");
MODULE_DESCRIPTION("Accessing Alpha SRM environment through procfs interface");
MODULE_LICENSE("GPL");
typedef struct _srm_env {
char *name;
unsigned long id;
struct proc_dir_entry *proc_entry;
} srm_env_t;
static struct proc_dir_entry *base_dir;
static struct proc_dir_entry *named_dir;
static struct proc_dir_entry *numbered_dir;
static char number[256][4];
static srm_env_t srm_named_entries[] = {
{ "auto_action", ENV_AUTO_ACTION },
{ "boot_dev", ENV_BOOT_DEV },
{ "bootdef_dev", ENV_BOOTDEF_DEV },
{ "booted_dev", ENV_BOOTED_DEV },
{ "boot_file", ENV_BOOT_FILE },
{ "booted_file", ENV_BOOTED_FILE },
{ "boot_osflags", ENV_BOOT_OSFLAGS },
{ "booted_osflags", ENV_BOOTED_OSFLAGS },
{ "boot_reset", ENV_BOOT_RESET },
{ "dump_dev", ENV_DUMP_DEV },
{ "enable_audit", ENV_ENABLE_AUDIT },
{ "license", ENV_LICENSE },
{ "char_set", ENV_CHAR_SET },
{ "language", ENV_LANGUAGE },
{ "tty_dev", ENV_TTY_DEV },
{ NULL, 0 },
};
static srm_env_t srm_numbered_entries[256];
static int srm_env_proc_show(struct seq_file *m, void *v)
{
unsigned long ret;
srm_env_t *entry;
char *page;
entry = m->private;
page = (char *)__get_free_page(GFP_USER);
if (!page)
return -ENOMEM;
ret = callback_getenv(entry->id, page, PAGE_SIZE);
if ((ret >> 61) == 0) {
seq_write(m, page, ret);
ret = 0;
} else
ret = -EFAULT;
free_page((unsigned long)page);
return ret;
}
static int srm_env_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, srm_env_proc_show, PDE(inode)->data);
}
static ssize_t srm_env_proc_write(struct file *file, const char __user *buffer,
size_t count, loff_t *pos)
{
int res;
srm_env_t *entry = PDE(file->f_path.dentry->d_inode)->data;
char *buf = (char *) __get_free_page(GFP_USER);
unsigned long ret1, ret2;
if (!buf)
return -ENOMEM;
res = -EINVAL;
if (count >= PAGE_SIZE)
goto out;
res = -EFAULT;
if (copy_from_user(buf, buffer, count))
goto out;
buf[count] = '\0';
ret1 = callback_setenv(entry->id, buf, count);
if ((ret1 >> 61) == 0) {
do
ret2 = callback_save_env();
while((ret2 >> 61) == 1);
res = (int) ret1;
}
out:
free_page((unsigned long)buf);
return res;
}
static const struct file_operations srm_env_proc_fops = {
.owner = THIS_MODULE,
.open = srm_env_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
.write = srm_env_proc_write,
};
static void
srm_env_cleanup(void)
{
srm_env_t *entry;
unsigned long var_num;
if (base_dir) {
/*
* Remove named entries
*/
if (named_dir) {
entry = srm_named_entries;
while (entry->name != NULL && entry->id != 0) {
if (entry->proc_entry) {
remove_proc_entry(entry->name,
named_dir);
entry->proc_entry = NULL;
}
entry++;
}
remove_proc_entry(NAMED_DIR, base_dir);
}
/*
* Remove numbered entries
*/
if (numbered_dir) {
for (var_num = 0; var_num <= 255; var_num++) {
entry = &srm_numbered_entries[var_num];
if (entry->proc_entry) {
remove_proc_entry(entry->name,
numbered_dir);
entry->proc_entry = NULL;
entry->name = NULL;
}
}
remove_proc_entry(NUMBERED_DIR, base_dir);
}
remove_proc_entry(BASE_DIR, NULL);
}
return;
}
static int __init
srm_env_init(void)
{
srm_env_t *entry;
unsigned long var_num;
/*
* Check system
*/
if (!alpha_using_srm) {
printk(KERN_INFO "%s: This Alpha system doesn't "
"know about SRM (or you've booted "
"SRM->MILO->Linux, which gets "
"misdetected)...\n", __func__);
return -ENODEV;
}
/*
* Init numbers
*/
for (var_num = 0; var_num <= 255; var_num++)
sprintf(number[var_num], "%ld", var_num);
/*
* Create base directory
*/
base_dir = proc_mkdir(BASE_DIR, NULL);
if (!base_dir) {
printk(KERN_ERR "Couldn't create base dir /proc/%s\n",
BASE_DIR);
goto cleanup;
}
/*
* Create per-name subdirectory
*/
named_dir = proc_mkdir(NAMED_DIR, base_dir);
if (!named_dir) {
printk(KERN_ERR "Couldn't create dir /proc/%s/%s\n",
BASE_DIR, NAMED_DIR);
goto cleanup;
}
/*
* Create per-number subdirectory
*/
numbered_dir = proc_mkdir(NUMBERED_DIR, base_dir);
if (!numbered_dir) {
printk(KERN_ERR "Couldn't create dir /proc/%s/%s\n",
BASE_DIR, NUMBERED_DIR);
goto cleanup;
}
/*
* Create all named nodes
*/
entry = srm_named_entries;
while (entry->name && entry->id) {
entry->proc_entry = proc_create_data(entry->name, 0644, named_dir,
&srm_env_proc_fops, entry);
if (!entry->proc_entry)
goto cleanup;
entry++;
}
/*
* Create all numbered nodes
*/
for (var_num = 0; var_num <= 255; var_num++) {
entry = &srm_numbered_entries[var_num];
entry->name = number[var_num];
entry->proc_entry = proc_create_data(entry->name, 0644, numbered_dir,
&srm_env_proc_fops, entry);
if (!entry->proc_entry)
goto cleanup;
entry->id = var_num;
}
printk(KERN_INFO "%s: version %s loaded successfully\n", NAME,
VERSION);
return 0;
cleanup:
srm_env_cleanup();
return -ENOMEM;
}
static void __exit
srm_env_exit(void)
{
srm_env_cleanup();
printk(KERN_INFO "%s: unloaded successfully\n", NAME);
return;
}
module_init(srm_env_init);
module_exit(srm_env_exit);