nmi_debug.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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/sched/debug.h>
  13. #include <linux/hardirq.h>
  14. enum nmi_action {
  15. NMI_SHOW_STATE = 1 << 0,
  16. NMI_SHOW_REGS = 1 << 1,
  17. NMI_DIE = 1 << 2,
  18. NMI_DEBOUNCE = 1 << 3,
  19. };
  20. static unsigned long nmi_actions;
  21. static int nmi_debug_notify(struct notifier_block *self,
  22. unsigned long val, void *data)
  23. {
  24. struct die_args *args = data;
  25. if (likely(val != DIE_NMI))
  26. return NOTIFY_DONE;
  27. if (nmi_actions & NMI_SHOW_STATE)
  28. show_state();
  29. if (nmi_actions & NMI_SHOW_REGS)
  30. show_regs(args->regs);
  31. if (nmi_actions & NMI_DEBOUNCE)
  32. mdelay(10);
  33. if (nmi_actions & NMI_DIE)
  34. return NOTIFY_BAD;
  35. return NOTIFY_OK;
  36. }
  37. static struct notifier_block nmi_debug_nb = {
  38. .notifier_call = nmi_debug_notify,
  39. };
  40. static int __init nmi_debug_setup(char *str)
  41. {
  42. char *p, *sep;
  43. register_die_notifier(&nmi_debug_nb);
  44. if (*str != '=')
  45. return 0;
  46. for (p = str + 1; *p; p = sep + 1) {
  47. sep = strchr(p, ',');
  48. if (sep)
  49. *sep = 0;
  50. if (strcmp(p, "state") == 0)
  51. nmi_actions |= NMI_SHOW_STATE;
  52. else if (strcmp(p, "regs") == 0)
  53. nmi_actions |= NMI_SHOW_REGS;
  54. else if (strcmp(p, "debounce") == 0)
  55. nmi_actions |= NMI_DEBOUNCE;
  56. else if (strcmp(p, "die") == 0)
  57. nmi_actions |= NMI_DIE;
  58. else
  59. printk(KERN_WARNING "NMI: Unrecognized action `%s'\n",
  60. p);
  61. if (!sep)
  62. break;
  63. }
  64. return 0;
  65. }
  66. __setup("nmi_debug", nmi_debug_setup);