adsp_err.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 and
  6. * only version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <linux/errno.h>
  14. #include <linux/uaccess.h>
  15. #include <linux/debugfs.h>
  16. #include <dsp/apr_audio-v2.h>
  17. /* ERROR STRING */
  18. /* Success. The operation completed with no errors. */
  19. #define ADSP_EOK_STR "ADSP_EOK"
  20. /* General failure. */
  21. #define ADSP_EFAILED_STR "ADSP_EFAILED"
  22. /* Bad operation parameter. */
  23. #define ADSP_EBADPARAM_STR "ADSP_EBADPARAM"
  24. /* Unsupported routine or operation. */
  25. #define ADSP_EUNSUPPORTED_STR "ADSP_EUNSUPPORTED"
  26. /* Unsupported version. */
  27. #define ADSP_EVERSION_STR "ADSP_EVERSION"
  28. /* Unexpected problem encountered. */
  29. #define ADSP_EUNEXPECTED_STR "ADSP_EUNEXPECTED"
  30. /* Unhandled problem occurred. */
  31. #define ADSP_EPANIC_STR "ADSP_EPANIC"
  32. /* Unable to allocate resource. */
  33. #define ADSP_ENORESOURCE_STR "ADSP_ENORESOURCE"
  34. /* Invalid handle. */
  35. #define ADSP_EHANDLE_STR "ADSP_EHANDLE"
  36. /* Operation is already processed. */
  37. #define ADSP_EALREADY_STR "ADSP_EALREADY"
  38. /* Operation is not ready to be processed. */
  39. #define ADSP_ENOTREADY_STR "ADSP_ENOTREADY"
  40. /* Operation is pending completion. */
  41. #define ADSP_EPENDING_STR "ADSP_EPENDING"
  42. /* Operation could not be accepted or processed. */
  43. #define ADSP_EBUSY_STR "ADSP_EBUSY"
  44. /* Operation aborted due to an error. */
  45. #define ADSP_EABORTED_STR "ADSP_EABORTED"
  46. /* Operation preempted by a higher priority. */
  47. #define ADSP_EPREEMPTED_STR "ADSP_EPREEMPTED"
  48. /* Operation requests intervention to complete. */
  49. #define ADSP_ECONTINUE_STR "ADSP_ECONTINUE"
  50. /* Operation requests immediate intervention to complete. */
  51. #define ADSP_EIMMEDIATE_STR "ADSP_EIMMEDIATE"
  52. /* Operation is not implemented. */
  53. #define ADSP_ENOTIMPL_STR "ADSP_ENOTIMPL"
  54. /* Operation needs more data or resources. */
  55. #define ADSP_ENEEDMORE_STR "ADSP_ENEEDMORE"
  56. /* Operation does not have memory. */
  57. #define ADSP_ENOMEMORY_STR "ADSP_ENOMEMORY"
  58. /* Item does not exist. */
  59. #define ADSP_ENOTEXIST_STR "ADSP_ENOTEXIST"
  60. /* Unexpected error code. */
  61. #define ADSP_ERR_MAX_STR "ADSP_ERR_MAX"
  62. #if IS_ENABLED(CONFIG_SND_SOC_QDSP_DEBUG)
  63. static bool adsp_err_panic;
  64. #ifdef CONFIG_DEBUG_FS
  65. static struct dentry *debugfs_adsp_err;
  66. static ssize_t adsp_err_debug_write(struct file *filp,
  67. const char __user *ubuf, size_t cnt, loff_t *ppos)
  68. {
  69. char cmd;
  70. if (copy_from_user(&cmd, ubuf, 1))
  71. return -EFAULT;
  72. if (cmd == '0')
  73. adsp_err_panic = false;
  74. else
  75. adsp_err_panic = true;
  76. return cnt;
  77. }
  78. static const struct file_operations adsp_err_debug_ops = {
  79. .write = adsp_err_debug_write,
  80. };
  81. #endif
  82. #endif
  83. struct adsp_err_code {
  84. int lnx_err_code;
  85. char *adsp_err_str;
  86. };
  87. static struct adsp_err_code adsp_err_code_info[ADSP_ERR_MAX+1] = {
  88. { 0, ADSP_EOK_STR},
  89. { -ENOTRECOVERABLE, ADSP_EFAILED_STR},
  90. { -EINVAL, ADSP_EBADPARAM_STR},
  91. { -EOPNOTSUPP, ADSP_EUNSUPPORTED_STR},
  92. { -ENOPROTOOPT, ADSP_EVERSION_STR},
  93. { -ENOTRECOVERABLE, ADSP_EUNEXPECTED_STR},
  94. { -ENOTRECOVERABLE, ADSP_EPANIC_STR},
  95. { -ENOSPC, ADSP_ENORESOURCE_STR},
  96. { -EBADR, ADSP_EHANDLE_STR},
  97. { -EALREADY, ADSP_EALREADY_STR},
  98. { -EPERM, ADSP_ENOTREADY_STR},
  99. { -EINPROGRESS, ADSP_EPENDING_STR},
  100. { -EBUSY, ADSP_EBUSY_STR},
  101. { -ECANCELED, ADSP_EABORTED_STR},
  102. { -EAGAIN, ADSP_EPREEMPTED_STR},
  103. { -EAGAIN, ADSP_ECONTINUE_STR},
  104. { -EAGAIN, ADSP_EIMMEDIATE_STR},
  105. { -EAGAIN, ADSP_ENOTIMPL_STR},
  106. { -ENODATA, ADSP_ENEEDMORE_STR},
  107. { -EADV, ADSP_ERR_MAX_STR},
  108. { -ENOMEM, ADSP_ENOMEMORY_STR},
  109. { -ENODEV, ADSP_ENOTEXIST_STR},
  110. { -EADV, ADSP_ERR_MAX_STR},
  111. };
  112. #if IS_ENABLED(CONFIG_SND_SOC_QDSP_DEBUG)
  113. static inline void adsp_err_check_panic(u32 adsp_error)
  114. {
  115. if (adsp_err_panic && adsp_error != ADSP_EALREADY)
  116. panic("%s: encounter adsp_err=0x%x\n", __func__, adsp_error);
  117. }
  118. #else
  119. static inline void adsp_err_check_panic(u32 adsp_error) {}
  120. #endif
  121. int adsp_err_get_lnx_err_code(u32 adsp_error)
  122. {
  123. adsp_err_check_panic(adsp_error);
  124. if (adsp_error > ADSP_ERR_MAX)
  125. return adsp_err_code_info[ADSP_ERR_MAX].lnx_err_code;
  126. else
  127. return adsp_err_code_info[adsp_error].lnx_err_code;
  128. }
  129. char *adsp_err_get_err_str(u32 adsp_error)
  130. {
  131. if (adsp_error > ADSP_ERR_MAX)
  132. return adsp_err_code_info[ADSP_ERR_MAX].adsp_err_str;
  133. else
  134. return adsp_err_code_info[adsp_error].adsp_err_str;
  135. }
  136. #if IS_ENABLED(CONFIG_SND_SOC_QDSP_DEBUG) && defined(CONFIG_DEBUG_FS)
  137. int __init adsp_err_init(void)
  138. {
  139. debugfs_adsp_err = debugfs_create_file("msm_adsp_audio_debug",
  140. S_IFREG | 0444, NULL, NULL,
  141. &adsp_err_debug_ops);
  142. return 0;
  143. }
  144. #else
  145. int __init adsp_err_init(void) { return 0; }
  146. #endif
  147. void adsp_err_exit(void)
  148. {
  149. return;
  150. }