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