ftrace.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Simple kernel driver to link kernel Ftrace and an STM device
  3. * Copyright (c) 2016, Linaro Ltd.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * STM Ftrace will be registered as a trace_export.
  15. */
  16. #include <linux/module.h>
  17. #include <linux/stm.h>
  18. #include <linux/trace.h>
  19. #define STM_FTRACE_NR_CHANNELS 1
  20. #define STM_FTRACE_CHAN 0
  21. static int stm_ftrace_link(struct stm_source_data *data);
  22. static void stm_ftrace_unlink(struct stm_source_data *data);
  23. static struct stm_ftrace {
  24. struct stm_source_data data;
  25. struct trace_export ftrace;
  26. } stm_ftrace = {
  27. .data = {
  28. .name = "ftrace",
  29. .nr_chans = STM_FTRACE_NR_CHANNELS,
  30. .link = stm_ftrace_link,
  31. .unlink = stm_ftrace_unlink,
  32. },
  33. };
  34. /**
  35. * stm_ftrace_write() - write data to STM via 'stm_ftrace' source
  36. * @buf: buffer containing the data packet
  37. * @len: length of the data packet
  38. */
  39. static void notrace
  40. stm_ftrace_write(struct trace_export *export, const void *buf, unsigned int len)
  41. {
  42. struct stm_ftrace *stm = container_of(export, struct stm_ftrace, ftrace);
  43. stm_source_write(&stm->data, STM_FTRACE_CHAN, buf, len);
  44. }
  45. static int stm_ftrace_link(struct stm_source_data *data)
  46. {
  47. struct stm_ftrace *sf = container_of(data, struct stm_ftrace, data);
  48. sf->ftrace.write = stm_ftrace_write;
  49. return register_ftrace_export(&sf->ftrace);
  50. }
  51. static void stm_ftrace_unlink(struct stm_source_data *data)
  52. {
  53. struct stm_ftrace *sf = container_of(data, struct stm_ftrace, data);
  54. unregister_ftrace_export(&sf->ftrace);
  55. }
  56. static int __init stm_ftrace_init(void)
  57. {
  58. int ret;
  59. ret = stm_source_register_device(NULL, &stm_ftrace.data);
  60. if (ret)
  61. pr_err("Failed to register stm_source - ftrace.\n");
  62. return ret;
  63. }
  64. static void __exit stm_ftrace_exit(void)
  65. {
  66. stm_source_unregister_device(&stm_ftrace.data);
  67. }
  68. module_init(stm_ftrace_init);
  69. module_exit(stm_ftrace_exit);
  70. MODULE_LICENSE("GPL v2");
  71. MODULE_DESCRIPTION("stm_ftrace driver");
  72. MODULE_AUTHOR("Chunyan Zhang <zhang.chunyan@linaro.org>");