test_dynamic_debug.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Kernel module for testing dynamic_debug
  4. *
  5. * Authors:
  6. * Jim Cromie <[email protected]>
  7. */
  8. #define pr_fmt(fmt) "test_dd: " fmt
  9. #include <linux/module.h>
  10. /* run tests by reading or writing sysfs node: do_prints */
  11. static void do_prints(void); /* device under test */
  12. static int param_set_do_prints(const char *instr, const struct kernel_param *kp)
  13. {
  14. do_prints();
  15. return 0;
  16. }
  17. static int param_get_do_prints(char *buffer, const struct kernel_param *kp)
  18. {
  19. do_prints();
  20. return scnprintf(buffer, PAGE_SIZE, "did do_prints\n");
  21. }
  22. static const struct kernel_param_ops param_ops_do_prints = {
  23. .set = param_set_do_prints,
  24. .get = param_get_do_prints,
  25. };
  26. module_param_cb(do_prints, &param_ops_do_prints, NULL, 0600);
  27. /*
  28. * Using the CLASSMAP api:
  29. * - classmaps must have corresponding enum
  30. * - enum symbols must match/correlate with class-name strings in the map.
  31. * - base must equal enum's 1st value
  32. * - multiple maps must set their base to share the 0-30 class_id space !!
  33. * (build-bug-on tips welcome)
  34. * Additionally, here:
  35. * - tie together sysname, mapname, bitsname, flagsname
  36. */
  37. #define DD_SYS_WRAP(_model, _flags) \
  38. static unsigned long bits_##_model; \
  39. static struct ddebug_class_param _flags##_model = { \
  40. .bits = &bits_##_model, \
  41. .flags = #_flags, \
  42. .map = &map_##_model, \
  43. }; \
  44. module_param_cb(_flags##_##_model, &param_ops_dyndbg_classes, &_flags##_model, 0600)
  45. /* numeric input, independent bits */
  46. enum cat_disjoint_bits {
  47. D2_CORE = 0,
  48. D2_DRIVER,
  49. D2_KMS,
  50. D2_PRIME,
  51. D2_ATOMIC,
  52. D2_VBL,
  53. D2_STATE,
  54. D2_LEASE,
  55. D2_DP,
  56. D2_DRMRES };
  57. DECLARE_DYNDBG_CLASSMAP(map_disjoint_bits, DD_CLASS_TYPE_DISJOINT_BITS, 0,
  58. "D2_CORE",
  59. "D2_DRIVER",
  60. "D2_KMS",
  61. "D2_PRIME",
  62. "D2_ATOMIC",
  63. "D2_VBL",
  64. "D2_STATE",
  65. "D2_LEASE",
  66. "D2_DP",
  67. "D2_DRMRES");
  68. DD_SYS_WRAP(disjoint_bits, p);
  69. DD_SYS_WRAP(disjoint_bits, T);
  70. /* symbolic input, independent bits */
  71. enum cat_disjoint_names { LOW = 11, MID, HI };
  72. DECLARE_DYNDBG_CLASSMAP(map_disjoint_names, DD_CLASS_TYPE_DISJOINT_NAMES, 10,
  73. "LOW", "MID", "HI");
  74. DD_SYS_WRAP(disjoint_names, p);
  75. DD_SYS_WRAP(disjoint_names, T);
  76. /* numeric verbosity, V2 > V1 related */
  77. enum cat_level_num { V0 = 14, V1, V2, V3, V4, V5, V6, V7 };
  78. DECLARE_DYNDBG_CLASSMAP(map_level_num, DD_CLASS_TYPE_LEVEL_NUM, 14,
  79. "V0", "V1", "V2", "V3", "V4", "V5", "V6", "V7");
  80. DD_SYS_WRAP(level_num, p);
  81. DD_SYS_WRAP(level_num, T);
  82. /* symbolic verbosity */
  83. enum cat_level_names { L0 = 22, L1, L2, L3, L4, L5, L6, L7 };
  84. DECLARE_DYNDBG_CLASSMAP(map_level_names, DD_CLASS_TYPE_LEVEL_NAMES, 22,
  85. "L0", "L1", "L2", "L3", "L4", "L5", "L6", "L7");
  86. DD_SYS_WRAP(level_names, p);
  87. DD_SYS_WRAP(level_names, T);
  88. /* stand-in for all pr_debug etc */
  89. #define prdbg(SYM) __pr_debug_cls(SYM, #SYM " msg\n")
  90. static void do_cats(void)
  91. {
  92. pr_debug("doing categories\n");
  93. prdbg(LOW);
  94. prdbg(MID);
  95. prdbg(HI);
  96. prdbg(D2_CORE);
  97. prdbg(D2_DRIVER);
  98. prdbg(D2_KMS);
  99. prdbg(D2_PRIME);
  100. prdbg(D2_ATOMIC);
  101. prdbg(D2_VBL);
  102. prdbg(D2_STATE);
  103. prdbg(D2_LEASE);
  104. prdbg(D2_DP);
  105. prdbg(D2_DRMRES);
  106. }
  107. static void do_levels(void)
  108. {
  109. pr_debug("doing levels\n");
  110. prdbg(V1);
  111. prdbg(V2);
  112. prdbg(V3);
  113. prdbg(V4);
  114. prdbg(V5);
  115. prdbg(V6);
  116. prdbg(V7);
  117. prdbg(L1);
  118. prdbg(L2);
  119. prdbg(L3);
  120. prdbg(L4);
  121. prdbg(L5);
  122. prdbg(L6);
  123. prdbg(L7);
  124. }
  125. static void do_prints(void)
  126. {
  127. do_cats();
  128. do_levels();
  129. }
  130. static int __init test_dynamic_debug_init(void)
  131. {
  132. pr_debug("init start\n");
  133. do_prints();
  134. pr_debug("init done\n");
  135. return 0;
  136. }
  137. static void __exit test_dynamic_debug_exit(void)
  138. {
  139. pr_debug("exited\n");
  140. }
  141. module_init(test_dynamic_debug_init);
  142. module_exit(test_dynamic_debug_exit);
  143. MODULE_AUTHOR("Jim Cromie <[email protected]>");
  144. MODULE_LICENSE("GPL");