console.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Simple kernel console driver for STM devices
  4. * Copyright (c) 2014, Intel Corporation.
  5. *
  6. * STM console will send kernel messages over STM devices to a trace host.
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/module.h>
  10. #include <linux/console.h>
  11. #include <linux/slab.h>
  12. #include <linux/stm.h>
  13. static int stm_console_link(struct stm_source_data *data);
  14. static void stm_console_unlink(struct stm_source_data *data);
  15. static struct stm_console {
  16. struct stm_source_data data;
  17. struct console console;
  18. } stm_console = {
  19. .data = {
  20. .name = "console",
  21. .nr_chans = 1,
  22. .link = stm_console_link,
  23. .unlink = stm_console_unlink,
  24. },
  25. };
  26. static void
  27. stm_console_write(struct console *con, const char *buf, unsigned len)
  28. {
  29. struct stm_console *sc = container_of(con, struct stm_console, console);
  30. stm_source_write(&sc->data, 0, buf, len);
  31. }
  32. static int stm_console_link(struct stm_source_data *data)
  33. {
  34. struct stm_console *sc = container_of(data, struct stm_console, data);
  35. strcpy(sc->console.name, "stm_console");
  36. sc->console.write = stm_console_write;
  37. sc->console.flags = CON_ENABLED | CON_PRINTBUFFER;
  38. register_console(&sc->console);
  39. return 0;
  40. }
  41. static void stm_console_unlink(struct stm_source_data *data)
  42. {
  43. struct stm_console *sc = container_of(data, struct stm_console, data);
  44. unregister_console(&sc->console);
  45. }
  46. static int stm_console_init(void)
  47. {
  48. return stm_source_register_device(NULL, &stm_console.data);
  49. }
  50. static void stm_console_exit(void)
  51. {
  52. stm_source_unregister_device(&stm_console.data);
  53. }
  54. module_init(stm_console_init);
  55. module_exit(stm_console_exit);
  56. MODULE_LICENSE("GPL v2");
  57. MODULE_DESCRIPTION("stm_console driver");
  58. MODULE_AUTHOR("Alexander Shishkin <alexander.shishkin@linux.intel.com>");