1 // SPDX-License-Identifier: BSD-3-Clause
2 //
3 // Copyright(c) 2020 Intel Corporation. All rights reserved.
4 //
5 // Author: Jaroslaw Stelter <jaroslaw.stelter@linux.intel.com>
6
7 #include <iadk_module_adapter.h>
8 #include <system_error.h>
9 #include <errno.h>
10
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14
15 typedef intel_adsp::ProcessingModuleInterface::ErrorCode::Type IntelErrorCode;
16
17 namespace dsp_fw
18 {
19
IadkModuleAdapter(intel_adsp::ProcessingModuleInterface & processing_module,void * comp_dev_instance,uint32_t module_id,uint32_t instance_id,uint32_t core_id,size_t module_size)20 IadkModuleAdapter::IadkModuleAdapter(intel_adsp::ProcessingModuleInterface& processing_module,
21 void *comp_dev_instance,
22 uint32_t module_id,
23 uint32_t instance_id,
24 uint32_t core_id,
25 size_t module_size)
26 :processing_module_(processing_module)
27 {
28 }
29
IadkModuleAdapter_Init(void)30 int IadkModuleAdapter::IadkModuleAdapter_Init(void)
31 {
32 return processing_module_.Init();
33 }
34
IadkModuleAdapter_Prepare(void)35 int IadkModuleAdapter::IadkModuleAdapter_Prepare(void)
36 {
37 return 0;
38 }
39
IadkModuleAdapter_Process(struct input_stream_buffer * input_buffers,int num_input_buffers,struct output_stream_buffer * output_buffers,int num_output_buffers)40 uint32_t IadkModuleAdapter::IadkModuleAdapter_Process(struct input_stream_buffer *input_buffers,
41 int num_input_buffers,
42 struct output_stream_buffer *output_buffers,
43 int num_output_buffers)
44 {
45 uint32_t ret = 0;
46 if ((num_input_buffers > 0) && (num_output_buffers > 0)) {
47 intel_adsp::InputStreamBuffer input_stream_buffers[INPUT_PIN_COUNT];
48 intel_adsp::OutputStreamBuffer output_stream_buffers[OUTPUT_PIN_COUNT];
49 for (int i = 0; i < (int)num_input_buffers; i++) {
50 intel_adsp::InputStreamFlags flags = {};
51 flags.end_of_stream = input_buffers[i].end_of_stream;
52 const intel_adsp::InputStreamBuffer isb_data(
53 (uint8_t *)input_buffers[i].data,
54 input_buffers[i].size,
55 flags);
56 new (&input_stream_buffers[i]) intel_adsp::InputStreamBuffer(isb_data);
57 }
58
59 for (int i = 0; i < (int)num_output_buffers; i++) {
60 const intel_adsp::OutputStreamBuffer osb_data(
61 (uint8_t *)output_buffers[i].data,
62 output_buffers[i].size);
63 new (&output_stream_buffers[i]) intel_adsp::OutputStreamBuffer(osb_data);
64 }
65
66 ret = processing_module_.Process(input_stream_buffers, output_stream_buffers);
67
68 for (int i = 0; i < (int)num_input_buffers; i++) {
69 input_buffers[i].consumed = input_buffers[i].size;
70 }
71
72 for (int i = 0; i < (int)num_output_buffers; i++) {
73 output_buffers[i].size = output_stream_buffers[i].size;
74 }
75 }
76 return ret;
77 }
78
79 AdspErrorCode
IadkModuleAdapter_SetConfiguration(uint32_t config_id,enum module_cfg_fragment_position pos,uint32_t data_offset_size,const uint8_t * fragment_buffer,size_t fragment_size,uint8_t * response,size_t & response_size)80 IadkModuleAdapter::IadkModuleAdapter_SetConfiguration(uint32_t config_id,
81 enum module_cfg_fragment_position pos,
82 uint32_t data_offset_size,
83 const uint8_t *fragment_buffer,
84 size_t fragment_size,
85 uint8_t *response,
86 size_t &response_size)
87 {
88 intel_adsp::ConfigurationFragmentPosition fragment_position =
89 (intel_adsp::ConfigurationFragmentPosition::Enum) pos;
90
91 return processing_module_.SetConfiguration(config_id, fragment_position,
92 data_offset_size, fragment_buffer,
93 fragment_size, response, response_size);
94 }
95
96 AdspErrorCode
IadkModuleAdapter_GetConfiguration(uint32_t config_id,enum module_cfg_fragment_position pos,uint32_t data_offset_size,uint8_t * fragment_buffer,size_t fragment_size)97 IadkModuleAdapter::IadkModuleAdapter_GetConfiguration(uint32_t config_id,
98 enum module_cfg_fragment_position pos,
99 uint32_t data_offset_size,
100 uint8_t *fragment_buffer,
101 size_t fragment_size)
102 {
103 intel_adsp::ConfigurationFragmentPosition fragment_position =
104 (intel_adsp::ConfigurationFragmentPosition::Enum) pos;
105
106 return processing_module_.GetConfiguration(config_id, fragment_position,
107 data_offset_size, fragment_buffer,
108 fragment_size);
109 }
110
111
IadkModuleAdapter_SetProcessingMode(enum module_processing_mode sof_mode)112 void IadkModuleAdapter::IadkModuleAdapter_SetProcessingMode(enum module_processing_mode sof_mode)
113 {
114 intel_adsp::ProcessingMode mode;
115 sof_mode == MODULE_PROCESSING_NORMAL ?
116 (mode = intel_adsp::ProcessingMode::NORMAL) :
117 (mode = intel_adsp::ProcessingMode::BYPASS);
118 processing_module_.SetProcessingMode(mode);
119 }
120
121
IadkModuleAdapter_Reset(void)122 void IadkModuleAdapter::IadkModuleAdapter_Reset(void)
123 {
124 processing_module_.Reset();
125 }
126
IadkModuleAdapter_GetProcessingMode(void)127 enum module_processing_mode IadkModuleAdapter::IadkModuleAdapter_GetProcessingMode(void)
128 {
129 enum module_processing_mode sof_mode;
130 intel_adsp::ProcessingMode mode = processing_module_.GetProcessingMode();
131 mode == intel_adsp::ProcessingMode::NORMAL ?
132 (sof_mode = MODULE_PROCESSING_NORMAL) : (sof_mode = MODULE_PROCESSING_BYPASS);
133 return sof_mode;
134 }
135
136 /* C wrappers for C++ ProcessingModuleInterface() methods. */
IadkModuleAdapter_Free(void)137 int IadkModuleAdapter::IadkModuleAdapter_Free(void)
138 {
139 return processing_module_.Delete();
140 }
141
142
iadk_wrapper_init(void * md)143 int iadk_wrapper_init(void *md)
144 {
145 struct IadkModuleAdapter *mod_adp = (struct IadkModuleAdapter *) md;
146 return mod_adp->IadkModuleAdapter_Init();
147 }
148
iadk_wrapper_prepare(void * md)149 int iadk_wrapper_prepare(void *md)
150 {
151 struct IadkModuleAdapter *mod_adp = (struct IadkModuleAdapter *) md;
152 return mod_adp->IadkModuleAdapter_Prepare();
153 }
154
iadk_wrapper_set_processing_mode(void * md,enum module_processing_mode mode)155 int iadk_wrapper_set_processing_mode(void *md,
156 enum module_processing_mode mode)
157 {
158 struct IadkModuleAdapter *mod_adp = (struct IadkModuleAdapter *) md;
159 mod_adp->IadkModuleAdapter_SetProcessingMode(mode);
160 return 0;
161 }
162
iadk_wrapper_get_processing_mode(void * md)163 enum module_processing_mode iadk_wrapper_get_processing_mode(void *md)
164 {
165 struct IadkModuleAdapter *mod_adp = (struct IadkModuleAdapter *) md;
166 return mod_adp->IadkModuleAdapter_GetProcessingMode();
167 }
168
iadk_wrapper_reset(void * md)169 int iadk_wrapper_reset(void *md)
170 {
171 struct IadkModuleAdapter *mod_adp = (struct IadkModuleAdapter *) md;
172 mod_adp->IadkModuleAdapter_Reset();
173 return 0;
174 }
175
iadk_wrapper_free(void * md)176 int iadk_wrapper_free(void *md)
177 {
178 struct IadkModuleAdapter *mod_adp = (struct IadkModuleAdapter *) md;
179 return mod_adp->IadkModuleAdapter_Free();
180 }
181
iadk_wrapper_set_configuration(void * md,uint32_t config_id,enum module_cfg_fragment_position pos,uint32_t data_offset_size,const uint8_t * fragment,size_t fragment_size,uint8_t * response,size_t response_size)182 int iadk_wrapper_set_configuration(void *md, uint32_t config_id,
183 enum module_cfg_fragment_position pos,
184 uint32_t data_offset_size,
185 const uint8_t *fragment, size_t fragment_size,
186 uint8_t *response, size_t response_size)
187 {
188 struct IadkModuleAdapter *mod_adp = (struct IadkModuleAdapter *) md;
189 return mod_adp->IadkModuleAdapter_SetConfiguration(config_id, pos,
190 data_offset_size,
191 fragment, fragment_size,
192 response, response_size);
193 }
194
iadk_wrapper_get_configuration(void * md,uint32_t config_id,enum module_cfg_fragment_position pos,uint32_t data_offset_size,uint8_t * fragment,size_t fragment_size)195 int iadk_wrapper_get_configuration(void *md, uint32_t config_id,
196 enum module_cfg_fragment_position pos,
197 uint32_t data_offset_size,
198 uint8_t *fragment, size_t fragment_size)
199 {
200 struct IadkModuleAdapter *mod_adp = (struct IadkModuleAdapter *) md;
201 return mod_adp->IadkModuleAdapter_GetConfiguration(config_id, pos,
202 data_offset_size,
203 fragment,
204 fragment_size);
205 }
206
207
iadk_wrapper_process(void * md,struct input_stream_buffer * input_buffers,int num_input_buffers,struct output_stream_buffer * output_buffers,int num_output_buffers)208 int iadk_wrapper_process(void *md, struct input_stream_buffer *input_buffers,
209 int num_input_buffers, struct output_stream_buffer *output_buffers,
210 int num_output_buffers)
211 {
212 struct IadkModuleAdapter *mod_adp = (struct IadkModuleAdapter *) md;
213 return mod_adp->IadkModuleAdapter_Process(input_buffers, num_input_buffers,
214 output_buffers, num_output_buffers);
215 }
216 } /* namespace dsp_fw */
217
218 #ifdef __cplusplus
219 } /* extern "C" */
220 #endif
221
222 #ifdef __cplusplus
operator new(size_t size,intel_adsp::InputStreamBuffer * placeholder)223 void* operator new(size_t size, intel_adsp::InputStreamBuffer* placeholder) throw()
224 {
225 return placeholder;
226 }
227
operator new(size_t size,intel_adsp::OutputStreamBuffer * placeholder)228 void* operator new(size_t size, intel_adsp::OutputStreamBuffer* placeholder) throw()
229 {
230 return placeholder;
231 }
232 #endif
233
234