/*
* arch/s390/kernel/debug.c
* S/390 debug facility
*
* Copyright (C) 1999, 2000 IBM Deutschland Entwicklung GmbH,
* IBM Corporation
* Author(s): Michael Holzheu (holzheu@de.ibm.com),
* Holger Smolinski (Holger.Smolinski@de.ibm.com)
*
* Bugreports to: <Linux390@de.ibm.com>
*/
#define KMSG_COMPONENT "s390dbf"
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
#include <linux/stddef.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/slab.h>
#include <linux/ctype.h>
#include <linux/sysctl.h>
#include <asm/uaccess.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/debugfs.h>
#include <asm/debug.h>
#define DEBUG_PROLOG_ENTRY -1
#define ALL_AREAS 0 /* copy all debug areas */
#define NO_AREAS 1 /* copy no debug areas */
/* typedefs */
typedef struct file_private_info {
loff_t offset; /* offset of last read in file */
int act_area; /* number of last formated area */
int act_page; /* act page in given area */
int act_entry; /* last formated entry (offset */
/* relative to beginning of last */
/* formated page) */
size_t act_entry_offset; /* up to this offset we copied */
/* in last read the last formated */
/* entry to userland */
char temp_buf[2048]; /* buffer for output */
debug_info_t *debug_info_org; /* original debug information */
debug_info_t *debug_info_snap; /* snapshot of debug information */
struct debug_view *view; /* used view of debug info */
} file_private_info_t;
typedef struct
{
char *string;
/*
* This assumes that all args are converted into longs
* on L/390 this is the case for all types of parameter
* except of floats, and long long (32 bit)
*
*/
long args[0];
} debug_sprintf_entry_t;
/* internal function prototyes */
static int debug_init(void);
static ssize_t debug_output(struct file *file, char __user *user_buf,
size_t user_len, loff_t * offset);
static ssize_t debug_input(struct file *file, const char __user *user_buf,
size_t user_len, loff_t * offset);
static int debug_open(struct inode *inode, struct file *file);
static int debug_close(struct inode *inode, struct file *file);
static debug_info_t *debug_info_create(const char *name, int pages_per_area,
int nr_areas, int buf_size, mode_t mode);
static void debug_info_get(debug_info_t *);
static void debug_info_put(debug_info_t *);
static int debug_prolog_level_fn(debug_info_t * id,
struct debug_view *view, char *out_buf);
static int debug_input_level_fn(debug_info_t * id, struct debug_view *view,
struct file *file, const char __user *user_buf,
size_t user_buf_size, loff_t * offset);
static int debug_prolog_pages_fn(debug_info_t * id,
struct debug_view *view, char *out_buf);
static int debug_input_pages_fn(debug_info_t * id, struct debug_view *view,
struct file *file, const char __user *user_buf,
size_t user_buf_size, loff_t * offset);
static int debug_input_flush_fn(debug_info_t * id, struct debug_view *view,
struct file *file, const char __user *user_buf,
size_t user_buf_size, loff_t * offset);
static int debug_hex_ascii_format_fn(debug_info_t * id, struct debug_view *view,
char *out_buf, const char *in_buf);
static int debug_raw_format_fn(debug_info_t * id,
struct debug_view *view, char *out_buf,
const char *in_buf);
static int debug_raw_header_fn(debug_info_t * id, struct debug_view *view,
int area, debug_entry_t * entry, char *out_buf);
static int debug_sprintf_format_fn(debug_info_t * id, struct debug_view *view,
char *out_buf, debug_sprintf_entry_t *curr_event);
/* globals */
struct debug_view debug_raw_view = {
"raw",
NULL,
&debug_raw_header_fn,
&debug_raw_format_fn,
NULL,
NULL
};
struct debug_view debug_hex_ascii_view = {
"hex_ascii",
NULL,
&debug_dflt_header_fn,
&debug_hex_ascii_format_fn,
NULL,
NULL
};
static struct debug_view debug_level_view = {
"level",
&debug_prolog_level_fn,
NULL,
NULL,
&debug_input_level_fn,
NULL
};
static struct debug_view debug_pages_view = {
"pages",
&debug_prolog_pages_fn,
NULL,
NULL,
&debug_input_pages_fn,
NULL
};
static struct debug_view debug_flush_view = {
"flush",
NULL,
NULL,
NULL,
&debug_input_flush_fn,
NULL
};
struct debug_view debug_sprintf_view = {
"sprintf",
NULL,
&debug_dflt_header_fn,
(debug_format_proc_t*)&debug_sprintf_format_fn,
NULL,
NULL
};
/* used by dump analysis tools to determine version of debug feature */
static unsigned int __used debug_feature_version = __DEBUG_FEATURE_VERSION;
/* static globals */
static debug_info_t *debug_area_first = NULL;
static debug_info_t *debug_area_last = NULL;
static DEFINE_MUTEX(debug_mutex);
static int initialized;
static const struct file_operations debug_file_ops = {
.owner = THIS_MODULE,
.read = debug_output,
.write = debug_input,
.open = debug_open,
.release = debug_close,
};
static struct dentry *debug_debugfs_root_entry;
/* functions */
/*
* debug_areas_alloc
* - Debug areas are implemented as a threedimensonal array:
* areas[areanumber][pagenumber][pageoffset]
*/
static debug_entry_t***
debug_areas_alloc(int pages_per_area, int nr_areas)
{
debug_entry_t*** areas;
int i,j;
areas = kmalloc(nr_areas *
sizeof(debug_entry_t**),
GFP_KERNEL);
if (!areas)
goto fail_malloc_areas;
for (i = 0; i < nr_areas; i++) {
areas[i] = kmalloc(pages_per_area *
sizeof(debug_entry_t*),GFP_KERNEL);
if (!areas[i]) {
goto fail_malloc_areas2;
}
for(j = 0; j < pages_per_area; j++) {
areas[i][j] = kzalloc(PAGE_SIZE, GFP_KERNEL);
if(!areas[i][j]) {
for(j--; j >=0 ; j--) {
kfree(areas[i][j]);
}
kfree(areas[i]);
goto fail_malloc_areas2;
}
}
}
return areas;
fail_malloc_areas2:
for(i--; i >= 0; i--){
for(j=0; j < pages_per_area;j++){
kfree(areas[i][j]);
}
kfree(areas[i]);
}
kfree(areas);
fail_malloc_areas:
return NULL;
}
/*
* debug_info_alloc
* - alloc new debug-info
*/
static debug_info_t*
debug_info_alloc(const char *name, int pages_per_area, int nr_areas,
int buf_size, int level, int mode)
{
debug_info_t* rc;
/* alloc everything */
rc = kmalloc(sizeof(debug_info_t), GFP_KERNEL);
if(!rc)
goto fail_malloc_rc;
rc->active_entries = kcalloc(nr_areas, sizeof(int), GFP_KERNEL);
if(!rc->active_entries)
goto fail_malloc_active_entries;
rc->active_pages = kcalloc(nr_areas, sizeof(int), GFP_KERNEL);
if(!rc->active_pages)
goto fail_malloc_active_pages;
if((mode == ALL_AREAS) && (pages_per_area != 0)){
rc->areas = debug_areas_alloc(pages_per_area, nr_areas);
if(!rc->areas)
goto fail_malloc_areas;
} else {
rc->areas = NULL;
}
/* initialize members */
spin_lock_init(&rc->lock);
rc->pages_per_area = pages_per_a
|