bcmdhd: do not turn off mmc at probe
[linux-2.6.git] / lib / dynamic_debug.c
index a687d90..75ca78f 100644 (file)
@@ -7,6 +7,7 @@
  * Copyright (C) 2008 Jason Baron <jbaron@redhat.com>
  * By Greg Banks <gnb@melbourne.sgi.com>
  * Copyright (c) 2008 Silicon Graphics Inc.  All Rights Reserved.
+ * Copyright (C) 2011 Bart Van Assche.  All Rights Reserved.
  */
 
 #include <linux/kernel.h>
 #include <linux/dynamic_debug.h>
 #include <linux/debugfs.h>
 #include <linux/slab.h>
+#include <linux/jump_label.h>
+#include <linux/hardirq.h>
+#include <linux/sched.h>
 
 extern struct _ddebug __start___verbose[];
 extern struct _ddebug __stop___verbose[];
 
-/* dynamic_debug_enabled, and dynamic_debug_enabled2 are bitmasks in which
- * bit n is set to 1 if any modname hashes into the bucket n, 0 otherwise. They
- * use independent hash functions, to reduce the chance of false positives.
- */
-long long dynamic_debug_enabled;
-EXPORT_SYMBOL_GPL(dynamic_debug_enabled);
-long long dynamic_debug_enabled2;
-EXPORT_SYMBOL_GPL(dynamic_debug_enabled2);
-
 struct ddebug_table {
        struct list_head link;
        char *mod_name;
@@ -71,15 +66,25 @@ static inline const char *basename(const char *path)
        return tail ? tail+1 : path;
 }
 
+static struct { unsigned flag:8; char opt_char; } opt_array[] = {
+       { _DPRINTK_FLAGS_PRINT, 'p' },
+       { _DPRINTK_FLAGS_INCL_MODNAME, 'm' },
+       { _DPRINTK_FLAGS_INCL_FUNCNAME, 'f' },
+       { _DPRINTK_FLAGS_INCL_LINENO, 'l' },
+       { _DPRINTK_FLAGS_INCL_TID, 't' },
+};
+
 /* format a string into buf[] which describes the _ddebug's flags */
 static char *ddebug_describe_flags(struct _ddebug *dp, char *buf,
                                    size_t maxlen)
 {
        char *p = buf;
+       int i;
 
        BUG_ON(maxlen < 4);
-       if (dp->flags & _DPRINTK_FLAGS_PRINT)
-               *p++ = 'p';
+       for (i = 0; i < ARRAY_SIZE(opt_array); ++i)
+               if (dp->flags & opt_array[i].flag)
+                       *p++ = opt_array[i].opt_char;
        if (p == buf)
                *p++ = '-';
        *p = '\0';
@@ -88,26 +93,6 @@ static char *ddebug_describe_flags(struct _ddebug *dp, char *buf,
 }
 
 /*
- * must be called with ddebug_lock held
- */
-
-static int disabled_hash(char hash, bool first_table)
-{
-       struct ddebug_table *dt;
-       char table_hash_value;
-
-       list_for_each_entry(dt, &ddebug_tables, link) {
-               if (first_table)
-                       table_hash_value = dt->ddebugs->primary_hash;
-               else
-                       table_hash_value = dt->ddebugs->secondary_hash;
-               if (dt->num_enabled && (hash == table_hash_value))
-                       return 0;
-       }
-       return 1;
-}
-
-/*
  * Search the tables for _ddebug's which match the given
  * `query' and apply the `flags' and `mask' to them.  Tells
  * the user which ddebug's were changed, or whether none
@@ -169,19 +154,10 @@ static void ddebug_change(const struct ddebug_query *query,
                        else if (!dp->flags)
                                dt->num_enabled++;
                        dp->flags = newflags;
-                       if (newflags) {
-                               dynamic_debug_enabled |=
-                                               (1LL << dp->primary_hash);
-                               dynamic_debug_enabled2 |=
-                                               (1LL << dp->secondary_hash);
-                       } else {
-                               if (disabled_hash(dp->primary_hash, true))
-                                       dynamic_debug_enabled &=
-                                               ~(1LL << dp->primary_hash);
-                               if (disabled_hash(dp->secondary_hash, false))
-                                       dynamic_debug_enabled2 &=
-                                               ~(1LL << dp->secondary_hash);
-                       }
+                       if (newflags)
+                               dp->enabled = 1;
+                       else
+                               dp->enabled = 0;
                        if (verbose)
                                printk(KERN_INFO
                                        "ddebug: changed %s:%d [%s]%s %s\n",
@@ -380,7 +356,7 @@ static int ddebug_parse_flags(const char *str, unsigned int *flagsp,
                               unsigned int *maskp)
 {
        unsigned flags = 0;
-       int op = '=';
+       int op = '=', i;
 
        switch (*str) {
        case '+':
@@ -395,13 +371,14 @@ static int ddebug_parse_flags(const char *str, unsigned int *flagsp,
                printk(KERN_INFO "%s: op='%c'\n", __func__, op);
 
        for ( ; *str ; ++str) {
-               switch (*str) {
-               case 'p':
-                       flags |= _DPRINTK_FLAGS_PRINT;
-                       break;
-               default:
-                       return -EINVAL;
+               for (i = ARRAY_SIZE(opt_array) - 1; i >= 0; i--) {
+                       if (*str == opt_array[i].opt_char) {
+                               flags |= opt_array[i].flag;
+                               break;
+                       }
                }
+               if (i < 0)
+                       return -EINVAL;
        }
        if (flags == 0)
                return -EINVAL;
@@ -450,6 +427,35 @@ static int ddebug_exec_query(char *query_string)
        return 0;
 }
 
+int __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...)
+{
+       va_list args;
+       int res;
+
+       BUG_ON(!descriptor);
+       BUG_ON(!fmt);
+
+       va_start(args, fmt);
+       res = printk(KERN_DEBUG);
+       if (descriptor->flags & _DPRINTK_FLAGS_INCL_TID) {
+               if (in_interrupt())
+                       res += printk(KERN_CONT "<intr> ");
+               else
+                       res += printk(KERN_CONT "[%d] ", task_pid_vnr(current));
+       }
+       if (descriptor->flags & _DPRINTK_FLAGS_INCL_MODNAME)
+               res += printk(KERN_CONT "%s:", descriptor->modname);
+       if (descriptor->flags & _DPRINTK_FLAGS_INCL_FUNCNAME)
+               res += printk(KERN_CONT "%s:", descriptor->function);
+       if (descriptor->flags & _DPRINTK_FLAGS_INCL_LINENO)
+               res += printk(KERN_CONT "%d ", descriptor->lineno);
+       res += vprintk(fmt, args);
+       va_end(args);
+
+       return res;
+}
+EXPORT_SYMBOL(__dynamic_pr_debug);
+
 static __initdata char ddebug_setup_string[1024];
 static __init int ddebug_setup_query(char *str)
 {