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