debug.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Ultra Wide Band
  3. * Debug Support
  4. *
  5. * Copyright (C) 2005-2006 Intel Corporation
  6. * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License version
  10. * 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  20. * 02110-1301, USA.
  21. *
  22. *
  23. * FIXME: doc
  24. * Invoke like:
  25. *
  26. * #define D_LOCAL 4
  27. * #include <linux/uwb/debug.h>
  28. *
  29. * At the end of your include files.
  30. */
  31. #include <linux/types.h>
  32. struct device;
  33. extern void dump_bytes(struct device *dev, const void *_buf, size_t rsize);
  34. /* Master debug switch; !0 enables, 0 disables */
  35. #define D_MASTER (!0)
  36. /* Local (per-file) debug switch; #define before #including */
  37. #ifndef D_LOCAL
  38. #define D_LOCAL 0
  39. #endif
  40. #undef __d_printf
  41. #undef d_fnstart
  42. #undef d_fnend
  43. #undef d_printf
  44. #undef d_dump
  45. #define __d_printf(l, _tag, _dev, f, a...) \
  46. do { \
  47. struct device *__dev = (_dev); \
  48. if (D_MASTER && D_LOCAL >= (l)) { \
  49. char __head[64] = ""; \
  50. if (_dev != NULL) { \
  51. if ((unsigned long)__dev < 4096) \
  52. printk(KERN_ERR "E: Corrupt dev %p\n", \
  53. __dev); \
  54. else \
  55. snprintf(__head, sizeof(__head), \
  56. "%s %s: ", \
  57. dev_driver_string(__dev), \
  58. dev_name(__dev)); \
  59. } \
  60. printk(KERN_ERR "%s%s" _tag ": " f, __head, \
  61. __func__, ## a); \
  62. } \
  63. } while (0 && _dev)
  64. #define d_fnstart(l, _dev, f, a...) \
  65. __d_printf(l, " FNSTART", _dev, f, ## a)
  66. #define d_fnend(l, _dev, f, a...) \
  67. __d_printf(l, " FNEND", _dev, f, ## a)
  68. #define d_printf(l, _dev, f, a...) \
  69. __d_printf(l, "", _dev, f, ## a)
  70. #define d_dump(l, _dev, ptr, size) \
  71. do { \
  72. struct device *__dev = _dev; \
  73. if (D_MASTER && D_LOCAL >= (l)) \
  74. dump_bytes(__dev, ptr, size); \
  75. } while (0 && _dev)
  76. #define d_test(l) (D_MASTER && D_LOCAL >= (l))