nmi_debug.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright (C) 2007 Atmel Corporation
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #include <linux/delay.h>
  9. #include <linux/kdebug.h>
  10. #include <linux/notifier.h>
  11. #include <linux/sched.h>
  12. #include <linux/hardirq.h>
  13. enum nmi_action {
  14. NMI_SHOW_STATE = 1 << 0,
  15. NMI_SHOW_REGS = 1 << 1,
  16. NMI_DIE = 1 << 2,
  17. NMI_DEBOUNCE = 1 << 3,
  18. };
  19. static unsigned long nmi_actions;
  20. static int nmi_debug_notify(struct notifier_block *self,
  21. unsigned long val, void *data)
  22. {
  23. struct die_args *args = data;
  24. if (likely(val != DIE_NMI))
  25. return NOTIFY_DONE;
  26. if (nmi_actions & NMI_SHOW_STATE)
  27. show_state();
  28. if (nmi_actions & NMI_SHOW_REGS)
  29. show_regs(args->regs);
  30. if (nmi_actions & NMI_DEBOUNCE)
  31. mdelay(10);
  32. if (nmi_actions & NMI_DIE)
  33. return NOTIFY_BAD;
  34. return NOTIFY_OK;
  35. }
  36. static struct notifier_block nmi_debug_nb = {
  37. .notifier_call = nmi_debug_notify,
  38. };
  39. static int __init nmi_debug_setup(char *str)
  40. {
  41. char *p, *sep;
  42. register_die_notifier(&nmi_debug_nb);
  43. if (*str != '=')
  44. return 0;
  45. for (p = str + 1; *p; p = sep + 1) {
  46. sep = strchr(p, ',');
  47. if (sep)
  48. *sep = 0;
  49. if (strcmp(p, "state") == 0)
  50. nmi_actions |= NMI_SHOW_STATE;
  51. else if (strcmp(p, "regs") == 0)
  52. nmi_actions |= NMI_SHOW_REGS;
  53. else if (strcmp(p, "debounce") == 0)
  54. nmi_actions |= NMI_DEBOUNCE;
  55. else if (strcmp(p, "die") == 0)
  56. nmi_actions |= NMI_DIE;
  57. else
  58. printk(KERN_WARNING "NMI: Unrecognized action `%s'\n",
  59. p);
  60. if (!sep)
  61. break;
  62. }
  63. return 0;
  64. }
  65. __setup("nmi_debug", nmi_debug_setup);