adsp_err.c 4.5 KB

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