blob: f2401569ccbe931882de3b8e0443fa7b95a83bdb [file] [log] [blame]
Meng Wang688a8672019-01-29 13:43:33 +08001// SPDX-License-Identifier: GPL-2.0-only
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05302/*
3 * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05304 */
5
6#include <linux/errno.h>
7#include <linux/uaccess.h>
8#include <linux/debugfs.h>
Laxminath Kasam605b42f2017-08-01 22:02:15 +05309#include <dsp/apr_audio-v2.h>
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +053010
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 Kasam8b1366a2017-10-05 01:44:16 +053058#if IS_ENABLED(CONFIG_SND_SOC_QDSP_DEBUG)
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +053059static bool adsp_err_panic;
60
61#ifdef CONFIG_DEBUG_FS
62static struct dentry *debugfs_adsp_err;
63
64static 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
80static const struct file_operations adsp_err_debug_ops = {
81 .write = adsp_err_debug_write,
82};
83#endif
84#endif
85
86struct adsp_err_code {
87 int lnx_err_code;
88 char *adsp_err_str;
89};
90
91
92static 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 Kasam8b1366a2017-10-05 01:44:16 +0530118#if IS_ENABLED(CONFIG_SND_SOC_QDSP_DEBUG)
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530119static 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
125static inline void adsp_err_check_panic(u32 adsp_error) {}
126#endif
127
128int 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
138char *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 Kasam8b1366a2017-10-05 01:44:16 +0530146#if IS_ENABLED(CONFIG_SND_SOC_QDSP_DEBUG) && defined(CONFIG_DEBUG_FS)
147int __init adsp_err_init(void)
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530148{
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 Kasam8b1366a2017-10-05 01:44:16 +0530157#else
158int __init adsp_err_init(void) { return 0; }
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530159
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530160#endif
Laxminath Kasam8b1366a2017-10-05 01:44:16 +0530161
Asish Bhattacharya5faacb32017-12-04 17:23:15 +0530162void adsp_err_exit(void)
Laxminath Kasam8b1366a2017-10-05 01:44:16 +0530163{
164 return;
165}