nmi_debug.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 <asm/irq.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 (nmi_enable()) {
  44. printk(KERN_WARNING "Unable to enable NMI.\n");
  45. return 0;
  46. }
  47. if (*str != '=')
  48. return 0;
  49. for (p = str + 1; *p; p = sep + 1) {
  50. sep = strchr(p, ',');
  51. if (sep)
  52. *sep = 0;
  53. if (strcmp(p, "state") == 0)
  54. nmi_actions |= NMI_SHOW_STATE;
  55. else if (strcmp(p, "regs") == 0)
  56. nmi_actions |= NMI_SHOW_REGS;
  57. else if (strcmp(p, "debounce") == 0)
  58. nmi_actions |= NMI_DEBOUNCE;
  59. else if (strcmp(p, "die") == 0)
  60. nmi_actions |= NMI_DIE;
  61. else
  62. printk(KERN_WARNING "NMI: Unrecognized action `%s'\n",
  63. p);
  64. if (!sep)
  65. break;
  66. }
  67. return 0;
  68. }
  69. __setup("nmi_debug", nmi_debug_setup);