ctcm_dbug.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright IBM Corp. 2001, 2007
  4. * Authors: Peter Tiedemann (ptiedem@de.ibm.com)
  5. *
  6. */
  7. #include <linux/stddef.h>
  8. #include <linux/string.h>
  9. #include <linux/kernel.h>
  10. #include <linux/errno.h>
  11. #include <linux/ctype.h>
  12. #include <linux/sysctl.h>
  13. #include <linux/module.h>
  14. #include <linux/init.h>
  15. #include <linux/fs.h>
  16. #include <linux/debugfs.h>
  17. #include "ctcm_dbug.h"
  18. /*
  19. * Debug Facility Stuff
  20. */
  21. struct ctcm_dbf_info ctcm_dbf[CTCM_DBF_INFOS] = {
  22. [CTCM_DBF_SETUP] = {"ctc_setup", 8, 1, 64, CTC_DBF_INFO, NULL},
  23. [CTCM_DBF_ERROR] = {"ctc_error", 8, 1, 64, CTC_DBF_ERROR, NULL},
  24. [CTCM_DBF_TRACE] = {"ctc_trace", 8, 1, 64, CTC_DBF_ERROR, NULL},
  25. [CTCM_DBF_MPC_SETUP] = {"mpc_setup", 8, 1, 80, CTC_DBF_INFO, NULL},
  26. [CTCM_DBF_MPC_ERROR] = {"mpc_error", 8, 1, 80, CTC_DBF_ERROR, NULL},
  27. [CTCM_DBF_MPC_TRACE] = {"mpc_trace", 8, 1, 80, CTC_DBF_ERROR, NULL},
  28. };
  29. void ctcm_unregister_dbf_views(void)
  30. {
  31. int x;
  32. for (x = 0; x < CTCM_DBF_INFOS; x++) {
  33. debug_unregister(ctcm_dbf[x].id);
  34. ctcm_dbf[x].id = NULL;
  35. }
  36. }
  37. int ctcm_register_dbf_views(void)
  38. {
  39. int x;
  40. for (x = 0; x < CTCM_DBF_INFOS; x++) {
  41. /* register the areas */
  42. ctcm_dbf[x].id = debug_register(ctcm_dbf[x].name,
  43. ctcm_dbf[x].pages,
  44. ctcm_dbf[x].areas,
  45. ctcm_dbf[x].len);
  46. if (ctcm_dbf[x].id == NULL) {
  47. ctcm_unregister_dbf_views();
  48. return -ENOMEM;
  49. }
  50. /* register a view */
  51. debug_register_view(ctcm_dbf[x].id, &debug_hex_ascii_view);
  52. /* set a passing level */
  53. debug_set_level(ctcm_dbf[x].id, ctcm_dbf[x].level);
  54. }
  55. return 0;
  56. }
  57. void ctcm_dbf_longtext(enum ctcm_dbf_names dbf_nix, int level, char *fmt, ...)
  58. {
  59. char dbf_txt_buf[64];
  60. va_list args;
  61. if (!debug_level_enabled(ctcm_dbf[dbf_nix].id, level))
  62. return;
  63. va_start(args, fmt);
  64. vsnprintf(dbf_txt_buf, sizeof(dbf_txt_buf), fmt, args);
  65. va_end(args);
  66. debug_text_event(ctcm_dbf[dbf_nix].id, level, dbf_txt_buf);
  67. }