hpidebug.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /************************************************************************
  2. AudioScience HPI driver
  3. Copyright (C) 1997-2010 AudioScience Inc. <support@audioscience.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of version 2 of the GNU General Public License as
  6. published by the Free Software Foundation;
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  14. Debug macro translation.
  15. ************************************************************************/
  16. #include "hpi_internal.h"
  17. #include "hpidebug.h"
  18. /* Debug level; 0 quiet; 1 informative, 2 debug, 3 verbose debug. */
  19. int hpi_debug_level = HPI_DEBUG_LEVEL_DEFAULT;
  20. void hpi_debug_init(void)
  21. {
  22. printk(KERN_INFO "debug start\n");
  23. }
  24. int hpi_debug_level_set(int level)
  25. {
  26. int old_level;
  27. old_level = hpi_debug_level;
  28. hpi_debug_level = level;
  29. return old_level;
  30. }
  31. int hpi_debug_level_get(void)
  32. {
  33. return hpi_debug_level;
  34. }
  35. #ifdef HPIOS_DEBUG_PRINT
  36. /* implies OS has no printf-like function */
  37. #include <stdarg.h>
  38. void hpi_debug_printf(char *fmt, ...)
  39. {
  40. va_list arglist;
  41. char buffer[128];
  42. va_start(arglist, fmt);
  43. if (buffer[0])
  44. HPIOS_DEBUG_PRINT(buffer);
  45. va_end(arglist);
  46. }
  47. #endif
  48. struct treenode {
  49. void *array;
  50. unsigned int num_elements;
  51. };
  52. #define make_treenode_from_array(nodename, array) \
  53. static void *tmp_strarray_##nodename[] = array; \
  54. static struct treenode nodename = { \
  55. &tmp_strarray_##nodename, \
  56. ARRAY_SIZE(tmp_strarray_##nodename) \
  57. };
  58. #define get_treenode_elem(node_ptr, idx, type) \
  59. (&(*((type *)(node_ptr)->array)[idx]))
  60. make_treenode_from_array(hpi_control_type_strings, HPI_CONTROL_TYPE_STRINGS)
  61. make_treenode_from_array(hpi_subsys_strings, HPI_SUBSYS_STRINGS)
  62. make_treenode_from_array(hpi_adapter_strings, HPI_ADAPTER_STRINGS)
  63. make_treenode_from_array(hpi_istream_strings, HPI_ISTREAM_STRINGS)
  64. make_treenode_from_array(hpi_ostream_strings, HPI_OSTREAM_STRINGS)
  65. make_treenode_from_array(hpi_mixer_strings, HPI_MIXER_STRINGS)
  66. make_treenode_from_array(hpi_node_strings,
  67. {
  68. "NODE is invalid object"})
  69. make_treenode_from_array(hpi_control_strings, HPI_CONTROL_STRINGS)
  70. make_treenode_from_array(hpi_nvmemory_strings, HPI_OBJ_STRINGS)
  71. make_treenode_from_array(hpi_digitalio_strings, HPI_DIGITALIO_STRINGS)
  72. make_treenode_from_array(hpi_watchdog_strings, HPI_WATCHDOG_STRINGS)
  73. make_treenode_from_array(hpi_clock_strings, HPI_CLOCK_STRINGS)
  74. make_treenode_from_array(hpi_profile_strings, HPI_PROFILE_STRINGS)
  75. make_treenode_from_array(hpi_asyncevent_strings, HPI_ASYNCEVENT_STRINGS)
  76. #define HPI_FUNCTION_STRINGS \
  77. { \
  78. &hpi_subsys_strings,\
  79. &hpi_adapter_strings,\
  80. &hpi_ostream_strings,\
  81. &hpi_istream_strings,\
  82. &hpi_mixer_strings,\
  83. &hpi_node_strings,\
  84. &hpi_control_strings,\
  85. &hpi_nvmemory_strings,\
  86. &hpi_digitalio_strings,\
  87. &hpi_watchdog_strings,\
  88. &hpi_clock_strings,\
  89. &hpi_profile_strings,\
  90. &hpi_control_strings, \
  91. &hpi_asyncevent_strings \
  92. }
  93. make_treenode_from_array(hpi_function_strings, HPI_FUNCTION_STRINGS)
  94. compile_time_assert(HPI_OBJ_MAXINDEX == 14, obj_list_doesnt_match);
  95. static char *hpi_function_string(unsigned int function)
  96. {
  97. unsigned int object;
  98. struct treenode *tmp;
  99. object = function / HPI_OBJ_FUNCTION_SPACING;
  100. function = function - object * HPI_OBJ_FUNCTION_SPACING;
  101. if (object == 0 || object == HPI_OBJ_NODE
  102. || object > hpi_function_strings.num_elements)
  103. return "invalid object";
  104. tmp = get_treenode_elem(&hpi_function_strings, object - 1,
  105. struct treenode *);
  106. if (function == 0 || function > tmp->num_elements)
  107. return "invalid function";
  108. return get_treenode_elem(tmp, function - 1, char *);
  109. }
  110. void hpi_debug_message(struct hpi_message *phm, char *sz_fileline)
  111. {
  112. if (phm) {
  113. if ((phm->object <= HPI_OBJ_MAXINDEX) && phm->object) {
  114. u16 index = 0;
  115. u16 attrib = 0;
  116. int is_control = 0;
  117. index = phm->obj_index;
  118. switch (phm->object) {
  119. case HPI_OBJ_ADAPTER:
  120. case HPI_OBJ_PROFILE:
  121. break;
  122. case HPI_OBJ_MIXER:
  123. if (phm->function ==
  124. HPI_MIXER_GET_CONTROL_BY_INDEX)
  125. index = phm->u.m.control_index;
  126. break;
  127. case HPI_OBJ_OSTREAM:
  128. case HPI_OBJ_ISTREAM:
  129. break;
  130. case HPI_OBJ_CONTROLEX:
  131. case HPI_OBJ_CONTROL:
  132. if (phm->version == 1)
  133. attrib = HPI_CTL_ATTR(UNIVERSAL, 1);
  134. else
  135. attrib = phm->u.c.attribute;
  136. is_control = 1;
  137. break;
  138. default:
  139. break;
  140. }
  141. if (is_control && (attrib & 0xFF00)) {
  142. int control_type = (attrib & 0xFF00) >> 8;
  143. int attr_index = HPI_CTL_ATTR_INDEX(attrib);
  144. /* note the KERN facility level
  145. is in szFileline already */
  146. printk("%s adapter %d %s "
  147. "ctrl_index x%04x %s %d\n",
  148. sz_fileline, phm->adapter_index,
  149. hpi_function_string(phm->function),
  150. index,
  151. get_treenode_elem
  152. (&hpi_control_type_strings,
  153. control_type, char *),
  154. attr_index);
  155. } else
  156. printk("%s adapter %d %s "
  157. "idx x%04x attr x%04x \n",
  158. sz_fileline, phm->adapter_index,
  159. hpi_function_string(phm->function),
  160. index, attrib);
  161. } else {
  162. printk("adap=%d, invalid obj=%d, func=0x%x\n",
  163. phm->adapter_index, phm->object,
  164. phm->function);
  165. }
  166. } else
  167. printk(KERN_ERR
  168. "NULL message pointer to hpi_debug_message!\n");
  169. }
  170. void hpi_debug_data(u16 *pdata, u32 len)
  171. {
  172. u32 i;
  173. int j;
  174. int k;
  175. int lines;
  176. int cols = 8;
  177. lines = (len + cols - 1) / cols;
  178. if (lines > 8)
  179. lines = 8;
  180. for (i = 0, j = 0; j < lines; j++) {
  181. printk(KERN_DEBUG "%p:", (pdata + i));
  182. for (k = 0; k < cols && i < len; i++, k++)
  183. printk("%s%04x", k == 0 ? "" : " ", pdata[i]);
  184. printk("\n");
  185. }
  186. }