mt_printk_ctrl.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include <linux/proc_fs.h>
  2. #include <linux/sched.h>
  3. #include <linux/kallsyms.h>
  4. #include <linux/utsname.h>
  5. #include <asm/uaccess.h>
  6. #include <linux/module.h>
  7. #include <linux/pid.h>
  8. #include <linux/irq.h>
  9. #include <linux/interrupt.h>
  10. #include <linux/stacktrace.h>
  11. #include <linux/printk.h>
  12. #include "internal.h"
  13. /* //////////////////////////////////////////////////////// */
  14. /* --------------------------------------------------- */
  15. /* Real work */
  16. /* --------------------------------------------------- */
  17. /* Define Proc entry */
  18. /* --------------------------------------------------- */
  19. MT_DEBUG_ENTRY(printk_ctrl);
  20. int mt_need_uart_console;
  21. static int mt_printk_ctrl_show(struct seq_file *m, void *v)
  22. {
  23. SEQ_printf(m, "=== mt printk controller ===\n");
  24. SEQ_printf(m, "mt_need_uart_console:%d, printk_disable_uart:%d.\n ",
  25. mt_need_uart_console, printk_disable_uart);
  26. SEQ_printf(m, "printk too much eandble:%d,detect line count: %d.\n",
  27. get_logtoomuch_enable(), get_detect_count());
  28. return 0;
  29. }
  30. static ssize_t mt_printk_ctrl_write(struct file *filp, const char *ubuf, size_t cnt, loff_t *data)
  31. {
  32. char buf[64];
  33. /* int val; --modified code */
  34. long val;
  35. int ret;
  36. if (cnt >= sizeof(buf))
  37. return -EINVAL;
  38. if (copy_from_user(&buf, ubuf, cnt))
  39. return -EFAULT;
  40. buf[cnt] = 0;
  41. ret = kstrtoul(buf, 10, (unsigned long *)&val);
  42. if (val == 0)
  43. mt_disable_uart();
  44. else if (val == 1) {
  45. mt_need_uart_console = 1;
  46. mt_enable_uart();
  47. pr_err("need uart log\n");
  48. } else if (val == 2)
  49. set_logtoomuch_enable(1);
  50. else if (val == 3)
  51. set_logtoomuch_enable(0);
  52. else if (val == 4)
  53. set_detect_count(100);
  54. else if (val == 5)
  55. set_detect_count(200);
  56. if (ret < 0)
  57. return ret;
  58. pr_err(" %ld\n", val);
  59. return cnt;
  60. }
  61. static int __init init_mt_printk_ctrl(void)
  62. {
  63. struct proc_dir_entry *pe;
  64. mt_need_uart_console = 0; /* default, no uart */
  65. pe = proc_create("mtprintk", 0664, NULL, &mt_printk_ctrl_fops);
  66. if (!pe)
  67. return -ENOMEM;
  68. return 0;
  69. }
  70. device_initcall(init_mt_printk_ctrl);