xref: /openbmc/linux/sound/soc/intel/avs/messages.c (revision 9a87ffc99ec8eb8d35eed7c4f816d75f5cc9662e)
1cb1eb6b5SCezary Rojewski // SPDX-License-Identifier: GPL-2.0-only
2cb1eb6b5SCezary Rojewski //
3cb1eb6b5SCezary Rojewski // Copyright(c) 2021-2022 Intel Corporation. All rights reserved.
4cb1eb6b5SCezary Rojewski //
5cb1eb6b5SCezary Rojewski // Authors: Cezary Rojewski <cezary.rojewski@intel.com>
6cb1eb6b5SCezary Rojewski //          Amadeusz Slawinski <amadeuszx.slawinski@linux.intel.com>
7cb1eb6b5SCezary Rojewski //
8cb1eb6b5SCezary Rojewski 
9f14a1c5aSCezary Rojewski #include <linux/slab.h>
10cb1eb6b5SCezary Rojewski #include "avs.h"
11cb1eb6b5SCezary Rojewski #include "messages.h"
12cb1eb6b5SCezary Rojewski 
13cb1eb6b5SCezary Rojewski #define AVS_CL_TIMEOUT_MS	5000
14cb1eb6b5SCezary Rojewski 
avs_ipc_set_boot_config(struct avs_dev * adev,u32 dma_id,u32 purge)1525f414fcSCezary Rojewski int avs_ipc_set_boot_config(struct avs_dev *adev, u32 dma_id, u32 purge)
1625f414fcSCezary Rojewski {
1725f414fcSCezary Rojewski 	union avs_global_msg msg = AVS_GLOBAL_REQUEST(ROM_CONTROL);
1825f414fcSCezary Rojewski 	struct avs_ipc_msg request = {{0}};
1925f414fcSCezary Rojewski 	int ret;
2025f414fcSCezary Rojewski 
2125f414fcSCezary Rojewski 	msg.boot_cfg.rom_ctrl_msg_type = AVS_ROM_SET_BOOT_CONFIG;
2225f414fcSCezary Rojewski 	msg.boot_cfg.dma_id = dma_id;
2325f414fcSCezary Rojewski 	msg.boot_cfg.purge_request = purge;
2425f414fcSCezary Rojewski 	request.header = msg.val;
2525f414fcSCezary Rojewski 
2625f414fcSCezary Rojewski 	ret = avs_dsp_send_rom_msg(adev, &request);
2725f414fcSCezary Rojewski 	if (ret)
2825f414fcSCezary Rojewski 		avs_ipc_err(adev, &request, "set boot config", ret);
2925f414fcSCezary Rojewski 
3025f414fcSCezary Rojewski 	return ret;
3125f414fcSCezary Rojewski }
3225f414fcSCezary Rojewski 
avs_ipc_load_modules(struct avs_dev * adev,u16 * mod_ids,u32 num_mod_ids)33cb1eb6b5SCezary Rojewski int avs_ipc_load_modules(struct avs_dev *adev, u16 *mod_ids, u32 num_mod_ids)
34cb1eb6b5SCezary Rojewski {
35cb1eb6b5SCezary Rojewski 	union avs_global_msg msg = AVS_GLOBAL_REQUEST(LOAD_MULTIPLE_MODULES);
36cb1eb6b5SCezary Rojewski 	struct avs_ipc_msg request;
37cb1eb6b5SCezary Rojewski 	int ret;
38cb1eb6b5SCezary Rojewski 
39cb1eb6b5SCezary Rojewski 	msg.load_multi_mods.mod_cnt = num_mod_ids;
40cb1eb6b5SCezary Rojewski 	request.header = msg.val;
41cb1eb6b5SCezary Rojewski 	request.data = mod_ids;
42cb1eb6b5SCezary Rojewski 	request.size = sizeof(*mod_ids) * num_mod_ids;
43cb1eb6b5SCezary Rojewski 
44cb1eb6b5SCezary Rojewski 	ret = avs_dsp_send_msg_timeout(adev, &request, NULL, AVS_CL_TIMEOUT_MS);
45cb1eb6b5SCezary Rojewski 	if (ret)
46cb1eb6b5SCezary Rojewski 		avs_ipc_err(adev, &request, "load multiple modules", ret);
47cb1eb6b5SCezary Rojewski 
48cb1eb6b5SCezary Rojewski 	return ret;
49cb1eb6b5SCezary Rojewski }
50cb1eb6b5SCezary Rojewski 
avs_ipc_unload_modules(struct avs_dev * adev,u16 * mod_ids,u32 num_mod_ids)51cb1eb6b5SCezary Rojewski int avs_ipc_unload_modules(struct avs_dev *adev, u16 *mod_ids, u32 num_mod_ids)
52cb1eb6b5SCezary Rojewski {
53cb1eb6b5SCezary Rojewski 	union avs_global_msg msg = AVS_GLOBAL_REQUEST(UNLOAD_MULTIPLE_MODULES);
54cb1eb6b5SCezary Rojewski 	struct avs_ipc_msg request;
55cb1eb6b5SCezary Rojewski 	int ret;
56cb1eb6b5SCezary Rojewski 
57cb1eb6b5SCezary Rojewski 	msg.load_multi_mods.mod_cnt = num_mod_ids;
58cb1eb6b5SCezary Rojewski 	request.header = msg.val;
59cb1eb6b5SCezary Rojewski 	request.data = mod_ids;
60cb1eb6b5SCezary Rojewski 	request.size = sizeof(*mod_ids) * num_mod_ids;
61cb1eb6b5SCezary Rojewski 
628758ae88SCezary Rojewski 	ret = avs_dsp_send_msg(adev, &request, NULL);
63cb1eb6b5SCezary Rojewski 	if (ret)
64cb1eb6b5SCezary Rojewski 		avs_ipc_err(adev, &request, "unload multiple modules", ret);
65cb1eb6b5SCezary Rojewski 
66cb1eb6b5SCezary Rojewski 	return ret;
67cb1eb6b5SCezary Rojewski }
68cb1eb6b5SCezary Rojewski 
avs_ipc_load_library(struct avs_dev * adev,u32 dma_id,u32 lib_id)69cb1eb6b5SCezary Rojewski int avs_ipc_load_library(struct avs_dev *adev, u32 dma_id, u32 lib_id)
70cb1eb6b5SCezary Rojewski {
71cb1eb6b5SCezary Rojewski 	union avs_global_msg msg = AVS_GLOBAL_REQUEST(LOAD_LIBRARY);
72cb1eb6b5SCezary Rojewski 	struct avs_ipc_msg request = {{0}};
73cb1eb6b5SCezary Rojewski 	int ret;
74cb1eb6b5SCezary Rojewski 
75cb1eb6b5SCezary Rojewski 	msg.load_lib.dma_id = dma_id;
76cb1eb6b5SCezary Rojewski 	msg.load_lib.lib_id = lib_id;
77cb1eb6b5SCezary Rojewski 	request.header = msg.val;
78cb1eb6b5SCezary Rojewski 
79cb1eb6b5SCezary Rojewski 	ret = avs_dsp_send_msg_timeout(adev, &request, NULL, AVS_CL_TIMEOUT_MS);
80cb1eb6b5SCezary Rojewski 	if (ret)
81cb1eb6b5SCezary Rojewski 		avs_ipc_err(adev, &request, "load library", ret);
82cb1eb6b5SCezary Rojewski 
83cb1eb6b5SCezary Rojewski 	return ret;
84cb1eb6b5SCezary Rojewski }
85b956b27bSCezary Rojewski 
avs_ipc_create_pipeline(struct avs_dev * adev,u16 req_size,u8 priority,u8 instance_id,bool lp,u16 attributes)86b956b27bSCezary Rojewski int avs_ipc_create_pipeline(struct avs_dev *adev, u16 req_size, u8 priority,
87b956b27bSCezary Rojewski 			    u8 instance_id, bool lp, u16 attributes)
88b956b27bSCezary Rojewski {
89b956b27bSCezary Rojewski 	union avs_global_msg msg = AVS_GLOBAL_REQUEST(CREATE_PIPELINE);
90b956b27bSCezary Rojewski 	struct avs_ipc_msg request = {{0}};
91b956b27bSCezary Rojewski 	int ret;
92b956b27bSCezary Rojewski 
93b956b27bSCezary Rojewski 	msg.create_ppl.ppl_mem_size = req_size;
94b956b27bSCezary Rojewski 	msg.create_ppl.ppl_priority = priority;
95b956b27bSCezary Rojewski 	msg.create_ppl.instance_id = instance_id;
96b956b27bSCezary Rojewski 	msg.ext.create_ppl.lp = lp;
97b956b27bSCezary Rojewski 	msg.ext.create_ppl.attributes = attributes;
98b956b27bSCezary Rojewski 	request.header = msg.val;
99b956b27bSCezary Rojewski 
100b956b27bSCezary Rojewski 	ret = avs_dsp_send_msg(adev, &request, NULL);
101b956b27bSCezary Rojewski 	if (ret)
102b956b27bSCezary Rojewski 		avs_ipc_err(adev, &request, "create pipeline", ret);
103b956b27bSCezary Rojewski 
104b956b27bSCezary Rojewski 	return ret;
105b956b27bSCezary Rojewski }
106b956b27bSCezary Rojewski 
avs_ipc_delete_pipeline(struct avs_dev * adev,u8 instance_id)107b956b27bSCezary Rojewski int avs_ipc_delete_pipeline(struct avs_dev *adev, u8 instance_id)
108b956b27bSCezary Rojewski {
109b956b27bSCezary Rojewski 	union avs_global_msg msg = AVS_GLOBAL_REQUEST(DELETE_PIPELINE);
110b956b27bSCezary Rojewski 	struct avs_ipc_msg request = {{0}};
111b956b27bSCezary Rojewski 	int ret;
112b956b27bSCezary Rojewski 
113b956b27bSCezary Rojewski 	msg.ppl.instance_id = instance_id;
114b956b27bSCezary Rojewski 	request.header = msg.val;
115b956b27bSCezary Rojewski 
116b956b27bSCezary Rojewski 	ret = avs_dsp_send_msg(adev, &request, NULL);
117b956b27bSCezary Rojewski 	if (ret)
118b956b27bSCezary Rojewski 		avs_ipc_err(adev, &request, "delete pipeline", ret);
119b956b27bSCezary Rojewski 
120b956b27bSCezary Rojewski 	return ret;
121b956b27bSCezary Rojewski }
122b956b27bSCezary Rojewski 
avs_ipc_set_pipeline_state(struct avs_dev * adev,u8 instance_id,enum avs_pipeline_state state)123b956b27bSCezary Rojewski int avs_ipc_set_pipeline_state(struct avs_dev *adev, u8 instance_id,
124b956b27bSCezary Rojewski 			       enum avs_pipeline_state state)
125b956b27bSCezary Rojewski {
126b956b27bSCezary Rojewski 	union avs_global_msg msg = AVS_GLOBAL_REQUEST(SET_PIPELINE_STATE);
127b956b27bSCezary Rojewski 	struct avs_ipc_msg request = {{0}};
128b956b27bSCezary Rojewski 	int ret;
129b956b27bSCezary Rojewski 
130b956b27bSCezary Rojewski 	msg.set_ppl_state.ppl_id = instance_id;
131b956b27bSCezary Rojewski 	msg.set_ppl_state.state = state;
132b956b27bSCezary Rojewski 	request.header = msg.val;
133b956b27bSCezary Rojewski 
134b956b27bSCezary Rojewski 	ret = avs_dsp_send_msg(adev, &request, NULL);
135b956b27bSCezary Rojewski 	if (ret)
136b956b27bSCezary Rojewski 		avs_ipc_err(adev, &request, "set pipeline state", ret);
137b956b27bSCezary Rojewski 
138b956b27bSCezary Rojewski 	return ret;
139b956b27bSCezary Rojewski }
140b956b27bSCezary Rojewski 
avs_ipc_get_pipeline_state(struct avs_dev * adev,u8 instance_id,enum avs_pipeline_state * state)141b956b27bSCezary Rojewski int avs_ipc_get_pipeline_state(struct avs_dev *adev, u8 instance_id,
142b956b27bSCezary Rojewski 			       enum avs_pipeline_state *state)
143b956b27bSCezary Rojewski {
144b956b27bSCezary Rojewski 	union avs_global_msg msg = AVS_GLOBAL_REQUEST(GET_PIPELINE_STATE);
145b956b27bSCezary Rojewski 	struct avs_ipc_msg request = {{0}};
146b956b27bSCezary Rojewski 	struct avs_ipc_msg reply = {{0}};
147b956b27bSCezary Rojewski 	int ret;
148b956b27bSCezary Rojewski 
149b956b27bSCezary Rojewski 	msg.get_ppl_state.ppl_id = instance_id;
150b956b27bSCezary Rojewski 	request.header = msg.val;
151b956b27bSCezary Rojewski 
152b956b27bSCezary Rojewski 	ret = avs_dsp_send_msg(adev, &request, &reply);
153b956b27bSCezary Rojewski 	if (ret) {
154b956b27bSCezary Rojewski 		avs_ipc_err(adev, &request, "get pipeline state", ret);
155b956b27bSCezary Rojewski 		return ret;
156b956b27bSCezary Rojewski 	}
157b956b27bSCezary Rojewski 
158b956b27bSCezary Rojewski 	*state = reply.rsp.ext.get_ppl_state.state;
159b956b27bSCezary Rojewski 	return ret;
160b956b27bSCezary Rojewski }
161f14a1c5aSCezary Rojewski 
162f14a1c5aSCezary Rojewski /*
163f14a1c5aSCezary Rojewski  * avs_ipc_init_instance - Initialize module instance
164f14a1c5aSCezary Rojewski  *
165f14a1c5aSCezary Rojewski  * @adev: Driver context
166f14a1c5aSCezary Rojewski  * @module_id: Module-type id
167f14a1c5aSCezary Rojewski  * @instance_id: Unique module instance id
168f14a1c5aSCezary Rojewski  * @ppl_id: Parent pipeline id
169f14a1c5aSCezary Rojewski  * @core_id: DSP core to allocate module on
170f14a1c5aSCezary Rojewski  * @domain: Processing domain (low latency or data processing)
171f14a1c5aSCezary Rojewski  * @param: Module-type specific configuration
172f14a1c5aSCezary Rojewski  * @param_size: Size of @param in bytes
173f14a1c5aSCezary Rojewski  *
174f14a1c5aSCezary Rojewski  * Argument verification, as well as pipeline state checks are done by the
175f14a1c5aSCezary Rojewski  * firmware.
176f14a1c5aSCezary Rojewski  *
177f14a1c5aSCezary Rojewski  * Note: @ppl_id and @core_id are independent of each other as single pipeline
178f14a1c5aSCezary Rojewski  * can be composed of module instances located on different DSP cores.
179f14a1c5aSCezary Rojewski  */
avs_ipc_init_instance(struct avs_dev * adev,u16 module_id,u8 instance_id,u8 ppl_id,u8 core_id,u8 domain,void * param,u32 param_size)180f14a1c5aSCezary Rojewski int avs_ipc_init_instance(struct avs_dev *adev, u16 module_id, u8 instance_id,
181f14a1c5aSCezary Rojewski 			  u8 ppl_id, u8 core_id, u8 domain,
182f14a1c5aSCezary Rojewski 			  void *param, u32 param_size)
183f14a1c5aSCezary Rojewski {
184f14a1c5aSCezary Rojewski 	union avs_module_msg msg = AVS_MODULE_REQUEST(INIT_INSTANCE);
185f14a1c5aSCezary Rojewski 	struct avs_ipc_msg request;
186f14a1c5aSCezary Rojewski 	int ret;
187f14a1c5aSCezary Rojewski 
188f14a1c5aSCezary Rojewski 	msg.module_id = module_id;
189f14a1c5aSCezary Rojewski 	msg.instance_id = instance_id;
190f14a1c5aSCezary Rojewski 	/* firmware expects size provided in dwords */
191f14a1c5aSCezary Rojewski 	msg.ext.init_instance.param_block_size = DIV_ROUND_UP(param_size, sizeof(u32));
192f14a1c5aSCezary Rojewski 	msg.ext.init_instance.ppl_instance_id = ppl_id;
193f14a1c5aSCezary Rojewski 	msg.ext.init_instance.core_id = core_id;
194f14a1c5aSCezary Rojewski 	msg.ext.init_instance.proc_domain = domain;
195f14a1c5aSCezary Rojewski 
196f14a1c5aSCezary Rojewski 	request.header = msg.val;
197f14a1c5aSCezary Rojewski 	request.data = param;
198f14a1c5aSCezary Rojewski 	request.size = param_size;
199f14a1c5aSCezary Rojewski 
200f14a1c5aSCezary Rojewski 	ret = avs_dsp_send_msg(adev, &request, NULL);
201f14a1c5aSCezary Rojewski 	if (ret)
202f14a1c5aSCezary Rojewski 		avs_ipc_err(adev, &request, "init instance", ret);
203f14a1c5aSCezary Rojewski 
204f14a1c5aSCezary Rojewski 	return ret;
205f14a1c5aSCezary Rojewski }
206f14a1c5aSCezary Rojewski 
207f14a1c5aSCezary Rojewski /*
208f14a1c5aSCezary Rojewski  * avs_ipc_delete_instance - Delete module instance
209f14a1c5aSCezary Rojewski  *
210f14a1c5aSCezary Rojewski  * @adev: Driver context
211f14a1c5aSCezary Rojewski  * @module_id: Module-type id
212f14a1c5aSCezary Rojewski  * @instance_id: Unique module instance id
213f14a1c5aSCezary Rojewski  *
214f14a1c5aSCezary Rojewski  * Argument verification, as well as pipeline state checks are done by the
215f14a1c5aSCezary Rojewski  * firmware.
216f14a1c5aSCezary Rojewski  *
217f14a1c5aSCezary Rojewski  * Note: only standalone modules i.e. without a parent pipeline shall be
218f14a1c5aSCezary Rojewski  * deleted using this IPC message. In all other cases, pipeline owning the
219f14a1c5aSCezary Rojewski  * modules performs cleanup automatically when it is deleted.
220f14a1c5aSCezary Rojewski  */
avs_ipc_delete_instance(struct avs_dev * adev,u16 module_id,u8 instance_id)221f14a1c5aSCezary Rojewski int avs_ipc_delete_instance(struct avs_dev *adev, u16 module_id, u8 instance_id)
222f14a1c5aSCezary Rojewski {
223f14a1c5aSCezary Rojewski 	union avs_module_msg msg = AVS_MODULE_REQUEST(DELETE_INSTANCE);
224f14a1c5aSCezary Rojewski 	struct avs_ipc_msg request = {{0}};
225f14a1c5aSCezary Rojewski 	int ret;
226f14a1c5aSCezary Rojewski 
227f14a1c5aSCezary Rojewski 	msg.module_id = module_id;
228f14a1c5aSCezary Rojewski 	msg.instance_id = instance_id;
229f14a1c5aSCezary Rojewski 	request.header = msg.val;
230f14a1c5aSCezary Rojewski 
231f14a1c5aSCezary Rojewski 	ret = avs_dsp_send_msg(adev, &request, NULL);
232f14a1c5aSCezary Rojewski 	if (ret)
233f14a1c5aSCezary Rojewski 		avs_ipc_err(adev, &request, "delete instance", ret);
234f14a1c5aSCezary Rojewski 
235f14a1c5aSCezary Rojewski 	return ret;
236f14a1c5aSCezary Rojewski }
237f14a1c5aSCezary Rojewski 
238f14a1c5aSCezary Rojewski /*
239f14a1c5aSCezary Rojewski  * avs_ipc_bind - Bind two module instances
240f14a1c5aSCezary Rojewski  *
241f14a1c5aSCezary Rojewski  * @adev: Driver context
242f14a1c5aSCezary Rojewski  * @module_id: Source module-type id
243f14a1c5aSCezary Rojewski  * @instance_id: Source module instance id
244f14a1c5aSCezary Rojewski  * @dst_module_id: Sink module-type id
245f14a1c5aSCezary Rojewski  * @dst_instance_id: Sink module instance id
246f14a1c5aSCezary Rojewski  * @dst_queue: Sink module pin to bind @src_queue with
247f14a1c5aSCezary Rojewski  * @src_queue: Source module pin to bind @dst_queue with
248f14a1c5aSCezary Rojewski  */
avs_ipc_bind(struct avs_dev * adev,u16 module_id,u8 instance_id,u16 dst_module_id,u8 dst_instance_id,u8 dst_queue,u8 src_queue)249f14a1c5aSCezary Rojewski int avs_ipc_bind(struct avs_dev *adev, u16 module_id, u8 instance_id,
250f14a1c5aSCezary Rojewski 		 u16 dst_module_id, u8 dst_instance_id,
251f14a1c5aSCezary Rojewski 		 u8 dst_queue, u8 src_queue)
252f14a1c5aSCezary Rojewski {
253f14a1c5aSCezary Rojewski 	union avs_module_msg msg = AVS_MODULE_REQUEST(BIND);
254f14a1c5aSCezary Rojewski 	struct avs_ipc_msg request = {{0}};
255f14a1c5aSCezary Rojewski 	int ret;
256f14a1c5aSCezary Rojewski 
257f14a1c5aSCezary Rojewski 	msg.module_id = module_id;
258f14a1c5aSCezary Rojewski 	msg.instance_id = instance_id;
259f14a1c5aSCezary Rojewski 	msg.ext.bind_unbind.dst_module_id = dst_module_id;
260f14a1c5aSCezary Rojewski 	msg.ext.bind_unbind.dst_instance_id = dst_instance_id;
261f14a1c5aSCezary Rojewski 	msg.ext.bind_unbind.dst_queue = dst_queue;
262f14a1c5aSCezary Rojewski 	msg.ext.bind_unbind.src_queue = src_queue;
263f14a1c5aSCezary Rojewski 	request.header = msg.val;
264f14a1c5aSCezary Rojewski 
265f14a1c5aSCezary Rojewski 	ret = avs_dsp_send_msg(adev, &request, NULL);
266f14a1c5aSCezary Rojewski 	if (ret)
267f14a1c5aSCezary Rojewski 		avs_ipc_err(adev, &request, "bind modules", ret);
268f14a1c5aSCezary Rojewski 
269f14a1c5aSCezary Rojewski 	return ret;
270f14a1c5aSCezary Rojewski }
271f14a1c5aSCezary Rojewski 
272f14a1c5aSCezary Rojewski /*
273f14a1c5aSCezary Rojewski  * avs_ipc_unbind - Unbind two module instances
274f14a1c5aSCezary Rojewski  *
275f14a1c5aSCezary Rojewski  * @adev: Driver context
276f14a1c5aSCezary Rojewski  * @module_id: Source module-type id
277f14a1c5aSCezary Rojewski  * @instance_id: Source module instance id
278f14a1c5aSCezary Rojewski  * @dst_module_id: Sink module-type id
279f14a1c5aSCezary Rojewski  * @dst_instance_id: Sink module instance id
280f14a1c5aSCezary Rojewski  * @dst_queue: Sink module pin to unbind @src_queue from
281f14a1c5aSCezary Rojewski  * @src_queue: Source module pin to unbind @dst_queue from
282f14a1c5aSCezary Rojewski  */
avs_ipc_unbind(struct avs_dev * adev,u16 module_id,u8 instance_id,u16 dst_module_id,u8 dst_instance_id,u8 dst_queue,u8 src_queue)283f14a1c5aSCezary Rojewski int avs_ipc_unbind(struct avs_dev *adev, u16 module_id, u8 instance_id,
284f14a1c5aSCezary Rojewski 		   u16 dst_module_id, u8 dst_instance_id,
285f14a1c5aSCezary Rojewski 		   u8 dst_queue, u8 src_queue)
286f14a1c5aSCezary Rojewski {
287f14a1c5aSCezary Rojewski 	union avs_module_msg msg = AVS_MODULE_REQUEST(UNBIND);
288f14a1c5aSCezary Rojewski 	struct avs_ipc_msg request = {{0}};
289f14a1c5aSCezary Rojewski 	int ret;
290f14a1c5aSCezary Rojewski 
291f14a1c5aSCezary Rojewski 	msg.module_id = module_id;
292f14a1c5aSCezary Rojewski 	msg.instance_id = instance_id;
293f14a1c5aSCezary Rojewski 	msg.ext.bind_unbind.dst_module_id = dst_module_id;
294f14a1c5aSCezary Rojewski 	msg.ext.bind_unbind.dst_instance_id = dst_instance_id;
295f14a1c5aSCezary Rojewski 	msg.ext.bind_unbind.dst_queue = dst_queue;
296f14a1c5aSCezary Rojewski 	msg.ext.bind_unbind.src_queue = src_queue;
297f14a1c5aSCezary Rojewski 	request.header = msg.val;
298f14a1c5aSCezary Rojewski 
299f14a1c5aSCezary Rojewski 	ret = avs_dsp_send_msg(adev, &request, NULL);
300f14a1c5aSCezary Rojewski 	if (ret)
301f14a1c5aSCezary Rojewski 		avs_ipc_err(adev, &request, "unbind modules", ret);
302f14a1c5aSCezary Rojewski 
303f14a1c5aSCezary Rojewski 	return ret;
304f14a1c5aSCezary Rojewski }
305f14a1c5aSCezary Rojewski 
__avs_ipc_set_large_config(struct avs_dev * adev,u16 module_id,u8 instance_id,u8 param_id,bool init_block,bool final_block,u8 * request_data,size_t request_size,size_t off_size)306f14a1c5aSCezary Rojewski static int __avs_ipc_set_large_config(struct avs_dev *adev, u16 module_id, u8 instance_id,
307f14a1c5aSCezary Rojewski 				      u8 param_id, bool init_block, bool final_block,
308f14a1c5aSCezary Rojewski 				      u8 *request_data, size_t request_size, size_t off_size)
309f14a1c5aSCezary Rojewski {
310f14a1c5aSCezary Rojewski 	union avs_module_msg msg = AVS_MODULE_REQUEST(LARGE_CONFIG_SET);
311f14a1c5aSCezary Rojewski 	struct avs_ipc_msg request;
312f14a1c5aSCezary Rojewski 	int ret;
313f14a1c5aSCezary Rojewski 
314f14a1c5aSCezary Rojewski 	msg.module_id = module_id;
315f14a1c5aSCezary Rojewski 	msg.instance_id = instance_id;
316f14a1c5aSCezary Rojewski 	msg.ext.large_config.data_off_size = off_size;
317f14a1c5aSCezary Rojewski 	msg.ext.large_config.large_param_id = param_id;
318f14a1c5aSCezary Rojewski 	msg.ext.large_config.final_block = final_block;
319f14a1c5aSCezary Rojewski 	msg.ext.large_config.init_block = init_block;
320f14a1c5aSCezary Rojewski 
321f14a1c5aSCezary Rojewski 	request.header = msg.val;
322f14a1c5aSCezary Rojewski 	request.data = request_data;
323f14a1c5aSCezary Rojewski 	request.size = request_size;
324f14a1c5aSCezary Rojewski 
325f14a1c5aSCezary Rojewski 	ret = avs_dsp_send_msg(adev, &request, NULL);
326f14a1c5aSCezary Rojewski 	if (ret)
327f14a1c5aSCezary Rojewski 		avs_ipc_err(adev, &request, "large config set", ret);
328f14a1c5aSCezary Rojewski 
329f14a1c5aSCezary Rojewski 	return ret;
330f14a1c5aSCezary Rojewski }
331f14a1c5aSCezary Rojewski 
avs_ipc_set_large_config(struct avs_dev * adev,u16 module_id,u8 instance_id,u8 param_id,u8 * request,size_t request_size)332f14a1c5aSCezary Rojewski int avs_ipc_set_large_config(struct avs_dev *adev, u16 module_id,
333f14a1c5aSCezary Rojewski 			     u8 instance_id, u8 param_id,
334f14a1c5aSCezary Rojewski 			     u8 *request, size_t request_size)
335f14a1c5aSCezary Rojewski {
336f14a1c5aSCezary Rojewski 	size_t remaining, tx_size;
337f14a1c5aSCezary Rojewski 	bool final;
338f14a1c5aSCezary Rojewski 	int ret;
339f14a1c5aSCezary Rojewski 
340f14a1c5aSCezary Rojewski 	remaining = request_size;
341f14a1c5aSCezary Rojewski 	tx_size = min_t(size_t, AVS_MAILBOX_SIZE, remaining);
342f14a1c5aSCezary Rojewski 	final = (tx_size == remaining);
343f14a1c5aSCezary Rojewski 
344f14a1c5aSCezary Rojewski 	/* Initial request states total payload size. */
345f14a1c5aSCezary Rojewski 	ret = __avs_ipc_set_large_config(adev, module_id, instance_id,
346f14a1c5aSCezary Rojewski 					 param_id, 1, final, request, tx_size,
347f14a1c5aSCezary Rojewski 					 request_size);
348f14a1c5aSCezary Rojewski 	if (ret)
349f14a1c5aSCezary Rojewski 		return ret;
350f14a1c5aSCezary Rojewski 
351f14a1c5aSCezary Rojewski 	remaining -= tx_size;
352f14a1c5aSCezary Rojewski 
353f14a1c5aSCezary Rojewski 	/* Loop the rest only when payload exceeds mailbox's size. */
354f14a1c5aSCezary Rojewski 	while (remaining) {
355f14a1c5aSCezary Rojewski 		size_t offset;
356f14a1c5aSCezary Rojewski 
357f14a1c5aSCezary Rojewski 		offset = request_size - remaining;
358f14a1c5aSCezary Rojewski 		tx_size = min_t(size_t, AVS_MAILBOX_SIZE, remaining);
359f14a1c5aSCezary Rojewski 		final = (tx_size == remaining);
360f14a1c5aSCezary Rojewski 
361f14a1c5aSCezary Rojewski 		ret = __avs_ipc_set_large_config(adev, module_id, instance_id,
362f14a1c5aSCezary Rojewski 						 param_id, 0, final,
363f14a1c5aSCezary Rojewski 						 request + offset, tx_size,
364f14a1c5aSCezary Rojewski 						 offset);
365f14a1c5aSCezary Rojewski 		if (ret)
366f14a1c5aSCezary Rojewski 			return ret;
367f14a1c5aSCezary Rojewski 
368f14a1c5aSCezary Rojewski 		remaining -= tx_size;
369f14a1c5aSCezary Rojewski 	}
370f14a1c5aSCezary Rojewski 
371f14a1c5aSCezary Rojewski 	return 0;
372f14a1c5aSCezary Rojewski }
373f14a1c5aSCezary Rojewski 
avs_ipc_get_large_config(struct avs_dev * adev,u16 module_id,u8 instance_id,u8 param_id,u8 * request_data,size_t request_size,u8 ** reply_data,size_t * reply_size)374f14a1c5aSCezary Rojewski int avs_ipc_get_large_config(struct avs_dev *adev, u16 module_id, u8 instance_id,
375f14a1c5aSCezary Rojewski 			     u8 param_id, u8 *request_data, size_t request_size,
376f14a1c5aSCezary Rojewski 			     u8 **reply_data, size_t *reply_size)
377f14a1c5aSCezary Rojewski {
378f14a1c5aSCezary Rojewski 	union avs_module_msg msg = AVS_MODULE_REQUEST(LARGE_CONFIG_GET);
379f14a1c5aSCezary Rojewski 	struct avs_ipc_msg request;
380f14a1c5aSCezary Rojewski 	struct avs_ipc_msg reply = {{0}};
381f14a1c5aSCezary Rojewski 	void *buf;
382f14a1c5aSCezary Rojewski 	int ret;
383f14a1c5aSCezary Rojewski 
384f14a1c5aSCezary Rojewski 	reply.data = kzalloc(AVS_MAILBOX_SIZE, GFP_KERNEL);
385f14a1c5aSCezary Rojewski 	if (!reply.data)
386f14a1c5aSCezary Rojewski 		return -ENOMEM;
387f14a1c5aSCezary Rojewski 
388f14a1c5aSCezary Rojewski 	msg.module_id = module_id;
389f14a1c5aSCezary Rojewski 	msg.instance_id = instance_id;
390f14a1c5aSCezary Rojewski 	msg.ext.large_config.data_off_size = request_size;
391f14a1c5aSCezary Rojewski 	msg.ext.large_config.large_param_id = param_id;
392f14a1c5aSCezary Rojewski 	/* final_block is always 0 on request. Updated by fw on reply. */
393f14a1c5aSCezary Rojewski 	msg.ext.large_config.final_block = 0;
394f14a1c5aSCezary Rojewski 	msg.ext.large_config.init_block = 1;
395f14a1c5aSCezary Rojewski 
396f14a1c5aSCezary Rojewski 	request.header = msg.val;
397f14a1c5aSCezary Rojewski 	request.data = request_data;
398f14a1c5aSCezary Rojewski 	request.size = request_size;
399f14a1c5aSCezary Rojewski 	reply.size = AVS_MAILBOX_SIZE;
400f14a1c5aSCezary Rojewski 
401f14a1c5aSCezary Rojewski 	ret = avs_dsp_send_msg(adev, &request, &reply);
402f14a1c5aSCezary Rojewski 	if (ret) {
403f14a1c5aSCezary Rojewski 		avs_ipc_err(adev, &request, "large config get", ret);
404f14a1c5aSCezary Rojewski 		kfree(reply.data);
405f14a1c5aSCezary Rojewski 		return ret;
406f14a1c5aSCezary Rojewski 	}
407f14a1c5aSCezary Rojewski 
4083c1923a1SCezary Rojewski 	buf = krealloc(reply.data, reply.size, GFP_KERNEL);
409f14a1c5aSCezary Rojewski 	if (!buf) {
410f14a1c5aSCezary Rojewski 		kfree(reply.data);
411f14a1c5aSCezary Rojewski 		return -ENOMEM;
412f14a1c5aSCezary Rojewski 	}
413f14a1c5aSCezary Rojewski 
414f14a1c5aSCezary Rojewski 	*reply_data = buf;
4153c1923a1SCezary Rojewski 	*reply_size = reply.size;
416f14a1c5aSCezary Rojewski 
417f14a1c5aSCezary Rojewski 	return 0;
418f14a1c5aSCezary Rojewski }
419469e87caSCezary Rojewski 
avs_ipc_set_dx(struct avs_dev * adev,u32 core_mask,bool powerup)420469e87caSCezary Rojewski int avs_ipc_set_dx(struct avs_dev *adev, u32 core_mask, bool powerup)
421469e87caSCezary Rojewski {
422469e87caSCezary Rojewski 	union avs_module_msg msg = AVS_MODULE_REQUEST(SET_DX);
423469e87caSCezary Rojewski 	struct avs_ipc_msg request;
424469e87caSCezary Rojewski 	struct avs_dxstate_info dx;
425469e87caSCezary Rojewski 	int ret;
426469e87caSCezary Rojewski 
427469e87caSCezary Rojewski 	dx.core_mask = core_mask;
428469e87caSCezary Rojewski 	dx.dx_mask = powerup ? core_mask : 0;
429469e87caSCezary Rojewski 	request.header = msg.val;
430469e87caSCezary Rojewski 	request.data = &dx;
431469e87caSCezary Rojewski 	request.size = sizeof(dx);
432469e87caSCezary Rojewski 
433335c4cbdSCezary Rojewski 	ret = avs_dsp_send_pm_msg(adev, &request, NULL, true);
434469e87caSCezary Rojewski 	if (ret)
435469e87caSCezary Rojewski 		avs_ipc_err(adev, &request, "set dx", ret);
436469e87caSCezary Rojewski 
437469e87caSCezary Rojewski 	return ret;
438469e87caSCezary Rojewski }
439469e87caSCezary Rojewski 
440469e87caSCezary Rojewski /*
441469e87caSCezary Rojewski  * avs_ipc_set_d0ix - Set power gating policy (entering D0IX substates)
442469e87caSCezary Rojewski  *
443469e87caSCezary Rojewski  * @enable_pg: Whether to enable or disable power gating
444469e87caSCezary Rojewski  * @streaming: Whether a stream is running when transitioning
445469e87caSCezary Rojewski  */
avs_ipc_set_d0ix(struct avs_dev * adev,bool enable_pg,bool streaming)446469e87caSCezary Rojewski int avs_ipc_set_d0ix(struct avs_dev *adev, bool enable_pg, bool streaming)
447469e87caSCezary Rojewski {
448469e87caSCezary Rojewski 	union avs_module_msg msg = AVS_MODULE_REQUEST(SET_D0IX);
449469e87caSCezary Rojewski 	struct avs_ipc_msg request = {{0}};
450469e87caSCezary Rojewski 	int ret;
451469e87caSCezary Rojewski 
452469e87caSCezary Rojewski 	msg.ext.set_d0ix.wake = enable_pg;
453469e87caSCezary Rojewski 	msg.ext.set_d0ix.streaming = streaming;
454469e87caSCezary Rojewski 
455469e87caSCezary Rojewski 	request.header = msg.val;
456469e87caSCezary Rojewski 
457335c4cbdSCezary Rojewski 	ret = avs_dsp_send_pm_msg(adev, &request, NULL, false);
458469e87caSCezary Rojewski 	if (ret)
459469e87caSCezary Rojewski 		avs_ipc_err(adev, &request, "set d0ix", ret);
460469e87caSCezary Rojewski 
461469e87caSCezary Rojewski 	return ret;
462469e87caSCezary Rojewski }
4633322e168SCezary Rojewski 
avs_ipc_get_fw_config(struct avs_dev * adev,struct avs_fw_cfg * cfg)4643322e168SCezary Rojewski int avs_ipc_get_fw_config(struct avs_dev *adev, struct avs_fw_cfg *cfg)
4653322e168SCezary Rojewski {
4663322e168SCezary Rojewski 	struct avs_tlv *tlv;
4673322e168SCezary Rojewski 	size_t payload_size;
4683322e168SCezary Rojewski 	size_t offset = 0;
4693322e168SCezary Rojewski 	u8 *payload;
4703322e168SCezary Rojewski 	int ret;
4713322e168SCezary Rojewski 
4723322e168SCezary Rojewski 	ret = avs_ipc_get_large_config(adev, AVS_BASEFW_MOD_ID, AVS_BASEFW_INST_ID,
4733322e168SCezary Rojewski 				       AVS_BASEFW_FIRMWARE_CONFIG, NULL, 0,
4743322e168SCezary Rojewski 				       &payload, &payload_size);
4753322e168SCezary Rojewski 	if (ret)
4763322e168SCezary Rojewski 		return ret;
47700566ad4SCezary Rojewski 	/* Non-zero payload expected for FIRMWARE_CONFIG. */
47800566ad4SCezary Rojewski 	if (!payload_size)
47900566ad4SCezary Rojewski 		return -EREMOTEIO;
4803322e168SCezary Rojewski 
4813322e168SCezary Rojewski 	while (offset < payload_size) {
4823322e168SCezary Rojewski 		tlv = (struct avs_tlv *)(payload + offset);
4833322e168SCezary Rojewski 
4843322e168SCezary Rojewski 		switch (tlv->type) {
4853322e168SCezary Rojewski 		case AVS_FW_CFG_FW_VERSION:
4863322e168SCezary Rojewski 			memcpy(&cfg->fw_version, tlv->value, sizeof(cfg->fw_version));
4873322e168SCezary Rojewski 			break;
4883322e168SCezary Rojewski 
4893322e168SCezary Rojewski 		case AVS_FW_CFG_MEMORY_RECLAIMED:
4903322e168SCezary Rojewski 			cfg->memory_reclaimed = *tlv->value;
4913322e168SCezary Rojewski 			break;
4923322e168SCezary Rojewski 
4933322e168SCezary Rojewski 		case AVS_FW_CFG_SLOW_CLOCK_FREQ_HZ:
4943322e168SCezary Rojewski 			cfg->slow_clock_freq_hz = *tlv->value;
4953322e168SCezary Rojewski 			break;
4963322e168SCezary Rojewski 
4973322e168SCezary Rojewski 		case AVS_FW_CFG_FAST_CLOCK_FREQ_HZ:
4983322e168SCezary Rojewski 			cfg->fast_clock_freq_hz = *tlv->value;
4993322e168SCezary Rojewski 			break;
5003322e168SCezary Rojewski 
5013322e168SCezary Rojewski 		case AVS_FW_CFG_ALH_SUPPORT_LEVEL:
5023322e168SCezary Rojewski 			cfg->alh_support = *tlv->value;
5033322e168SCezary Rojewski 			break;
5043322e168SCezary Rojewski 
5053322e168SCezary Rojewski 		case AVS_FW_CFG_IPC_DL_MAILBOX_BYTES:
5063322e168SCezary Rojewski 			cfg->ipc_dl_mailbox_bytes = *tlv->value;
5073322e168SCezary Rojewski 			break;
5083322e168SCezary Rojewski 
5093322e168SCezary Rojewski 		case AVS_FW_CFG_IPC_UL_MAILBOX_BYTES:
5103322e168SCezary Rojewski 			cfg->ipc_ul_mailbox_bytes = *tlv->value;
5113322e168SCezary Rojewski 			break;
5123322e168SCezary Rojewski 
5133322e168SCezary Rojewski 		case AVS_FW_CFG_TRACE_LOG_BYTES:
5143322e168SCezary Rojewski 			cfg->trace_log_bytes = *tlv->value;
5153322e168SCezary Rojewski 			break;
5163322e168SCezary Rojewski 
5173322e168SCezary Rojewski 		case AVS_FW_CFG_MAX_PPL_COUNT:
5183322e168SCezary Rojewski 			cfg->max_ppl_count = *tlv->value;
5193322e168SCezary Rojewski 			break;
5203322e168SCezary Rojewski 
5213322e168SCezary Rojewski 		case AVS_FW_CFG_MAX_ASTATE_COUNT:
5223322e168SCezary Rojewski 			cfg->max_astate_count = *tlv->value;
5233322e168SCezary Rojewski 			break;
5243322e168SCezary Rojewski 
5253322e168SCezary Rojewski 		case AVS_FW_CFG_MAX_MODULE_PIN_COUNT:
5263322e168SCezary Rojewski 			cfg->max_module_pin_count = *tlv->value;
5273322e168SCezary Rojewski 			break;
5283322e168SCezary Rojewski 
5293322e168SCezary Rojewski 		case AVS_FW_CFG_MODULES_COUNT:
5303322e168SCezary Rojewski 			cfg->modules_count = *tlv->value;
5313322e168SCezary Rojewski 			break;
5323322e168SCezary Rojewski 
5333322e168SCezary Rojewski 		case AVS_FW_CFG_MAX_MOD_INST_COUNT:
5343322e168SCezary Rojewski 			cfg->max_mod_inst_count = *tlv->value;
5353322e168SCezary Rojewski 			break;
5363322e168SCezary Rojewski 
5373322e168SCezary Rojewski 		case AVS_FW_CFG_MAX_LL_TASKS_PER_PRI_COUNT:
5383322e168SCezary Rojewski 			cfg->max_ll_tasks_per_pri_count = *tlv->value;
5393322e168SCezary Rojewski 			break;
5403322e168SCezary Rojewski 
5413322e168SCezary Rojewski 		case AVS_FW_CFG_LL_PRI_COUNT:
5423322e168SCezary Rojewski 			cfg->ll_pri_count = *tlv->value;
5433322e168SCezary Rojewski 			break;
5443322e168SCezary Rojewski 
5453322e168SCezary Rojewski 		case AVS_FW_CFG_MAX_DP_TASKS_COUNT:
5463322e168SCezary Rojewski 			cfg->max_dp_tasks_count = *tlv->value;
5473322e168SCezary Rojewski 			break;
5483322e168SCezary Rojewski 
5493322e168SCezary Rojewski 		case AVS_FW_CFG_MAX_LIBS_COUNT:
5503322e168SCezary Rojewski 			cfg->max_libs_count = *tlv->value;
5513322e168SCezary Rojewski 			break;
5523322e168SCezary Rojewski 
5533322e168SCezary Rojewski 		case AVS_FW_CFG_XTAL_FREQ_HZ:
5543322e168SCezary Rojewski 			cfg->xtal_freq_hz = *tlv->value;
5553322e168SCezary Rojewski 			break;
5563322e168SCezary Rojewski 
5573322e168SCezary Rojewski 		case AVS_FW_CFG_POWER_GATING_POLICY:
5583322e168SCezary Rojewski 			cfg->power_gating_policy = *tlv->value;
5593322e168SCezary Rojewski 			break;
5603322e168SCezary Rojewski 
5613322e168SCezary Rojewski 		/* Known but not useful to us. */
5623322e168SCezary Rojewski 		case AVS_FW_CFG_DMA_BUFFER_CONFIG:
5633322e168SCezary Rojewski 		case AVS_FW_CFG_SCHEDULER_CONFIG:
5643322e168SCezary Rojewski 		case AVS_FW_CFG_CLOCKS_CONFIG:
56579c351fbSCezary Rojewski 		case AVS_FW_CFG_RESERVED:
5663322e168SCezary Rojewski 			break;
5673322e168SCezary Rojewski 
5683322e168SCezary Rojewski 		default:
5693322e168SCezary Rojewski 			dev_info(adev->dev, "Unrecognized fw param: %d\n", tlv->type);
5703322e168SCezary Rojewski 			break;
5713322e168SCezary Rojewski 		}
5723322e168SCezary Rojewski 
5733322e168SCezary Rojewski 		offset += sizeof(*tlv) + tlv->length;
5743322e168SCezary Rojewski 	}
5753322e168SCezary Rojewski 
5763322e168SCezary Rojewski 	/* No longer needed, free it as it's owned by the get_large_config() caller. */
5773322e168SCezary Rojewski 	kfree(payload);
5783322e168SCezary Rojewski 	return ret;
5793322e168SCezary Rojewski }
5803322e168SCezary Rojewski 
avs_ipc_get_hw_config(struct avs_dev * adev,struct avs_hw_cfg * cfg)5813322e168SCezary Rojewski int avs_ipc_get_hw_config(struct avs_dev *adev, struct avs_hw_cfg *cfg)
5823322e168SCezary Rojewski {
5833322e168SCezary Rojewski 	struct avs_tlv *tlv;
5843322e168SCezary Rojewski 	size_t payload_size;
5853322e168SCezary Rojewski 	size_t size, offset = 0;
5863322e168SCezary Rojewski 	u8 *payload;
5873322e168SCezary Rojewski 	int ret;
5883322e168SCezary Rojewski 
5893322e168SCezary Rojewski 	ret = avs_ipc_get_large_config(adev, AVS_BASEFW_MOD_ID, AVS_BASEFW_INST_ID,
5903322e168SCezary Rojewski 				       AVS_BASEFW_HARDWARE_CONFIG, NULL, 0,
5913322e168SCezary Rojewski 				       &payload, &payload_size);
5923322e168SCezary Rojewski 	if (ret)
5933322e168SCezary Rojewski 		return ret;
59400566ad4SCezary Rojewski 	/* Non-zero payload expected for HARDWARE_CONFIG. */
59500566ad4SCezary Rojewski 	if (!payload_size)
59600566ad4SCezary Rojewski 		return -EREMOTEIO;
5973322e168SCezary Rojewski 
5983322e168SCezary Rojewski 	while (offset < payload_size) {
5993322e168SCezary Rojewski 		tlv = (struct avs_tlv *)(payload + offset);
6003322e168SCezary Rojewski 
6013322e168SCezary Rojewski 		switch (tlv->type) {
6023322e168SCezary Rojewski 		case AVS_HW_CFG_AVS_VER:
6033322e168SCezary Rojewski 			cfg->avs_version = *tlv->value;
6043322e168SCezary Rojewski 			break;
6053322e168SCezary Rojewski 
6063322e168SCezary Rojewski 		case AVS_HW_CFG_DSP_CORES:
6073322e168SCezary Rojewski 			cfg->dsp_cores = *tlv->value;
6083322e168SCezary Rojewski 			break;
6093322e168SCezary Rojewski 
6103322e168SCezary Rojewski 		case AVS_HW_CFG_MEM_PAGE_BYTES:
6113322e168SCezary Rojewski 			cfg->mem_page_bytes = *tlv->value;
6123322e168SCezary Rojewski 			break;
6133322e168SCezary Rojewski 
6143322e168SCezary Rojewski 		case AVS_HW_CFG_TOTAL_PHYS_MEM_PAGES:
6153322e168SCezary Rojewski 			cfg->total_phys_mem_pages = *tlv->value;
6163322e168SCezary Rojewski 			break;
6173322e168SCezary Rojewski 
6183322e168SCezary Rojewski 		case AVS_HW_CFG_I2S_CAPS:
6193322e168SCezary Rojewski 			cfg->i2s_caps.i2s_version = tlv->value[0];
6203322e168SCezary Rojewski 			size = tlv->value[1];
6213322e168SCezary Rojewski 			cfg->i2s_caps.ctrl_count = size;
6223322e168SCezary Rojewski 			if (!size)
6233322e168SCezary Rojewski 				break;
6243322e168SCezary Rojewski 
6253322e168SCezary Rojewski 			/* Multiply to get entire array size. */
6263322e168SCezary Rojewski 			size *= sizeof(*cfg->i2s_caps.ctrl_base_addr);
6273322e168SCezary Rojewski 			cfg->i2s_caps.ctrl_base_addr = devm_kmemdup(adev->dev,
6283322e168SCezary Rojewski 								    &tlv->value[2],
6293322e168SCezary Rojewski 								    size, GFP_KERNEL);
6303322e168SCezary Rojewski 			if (!cfg->i2s_caps.ctrl_base_addr) {
6313322e168SCezary Rojewski 				ret = -ENOMEM;
6323322e168SCezary Rojewski 				goto exit;
6333322e168SCezary Rojewski 			}
6343322e168SCezary Rojewski 			break;
6353322e168SCezary Rojewski 
6363322e168SCezary Rojewski 		case AVS_HW_CFG_GATEWAY_COUNT:
6373322e168SCezary Rojewski 			cfg->gateway_count = *tlv->value;
6383322e168SCezary Rojewski 			break;
6393322e168SCezary Rojewski 
6403322e168SCezary Rojewski 		case AVS_HW_CFG_HP_EBB_COUNT:
6413322e168SCezary Rojewski 			cfg->hp_ebb_count = *tlv->value;
6423322e168SCezary Rojewski 			break;
6433322e168SCezary Rojewski 
6443322e168SCezary Rojewski 		case AVS_HW_CFG_LP_EBB_COUNT:
6453322e168SCezary Rojewski 			cfg->lp_ebb_count = *tlv->value;
6463322e168SCezary Rojewski 			break;
6473322e168SCezary Rojewski 
6483322e168SCezary Rojewski 		case AVS_HW_CFG_EBB_SIZE_BYTES:
6493322e168SCezary Rojewski 			cfg->ebb_size_bytes = *tlv->value;
6503322e168SCezary Rojewski 			break;
6513322e168SCezary Rojewski 
6523322e168SCezary Rojewski 		case AVS_HW_CFG_GPDMA_CAPS:
6533322e168SCezary Rojewski 			break;
6543322e168SCezary Rojewski 
6553322e168SCezary Rojewski 		default:
6563322e168SCezary Rojewski 			dev_info(adev->dev, "Unrecognized hw config: %d\n", tlv->type);
6573322e168SCezary Rojewski 			break;
6583322e168SCezary Rojewski 		}
6593322e168SCezary Rojewski 
6603322e168SCezary Rojewski 		offset += sizeof(*tlv) + tlv->length;
6613322e168SCezary Rojewski 	}
6623322e168SCezary Rojewski 
6633322e168SCezary Rojewski exit:
6643322e168SCezary Rojewski 	/* No longer needed, free it as it's owned by the get_large_config() caller. */
6653322e168SCezary Rojewski 	kfree(payload);
6663322e168SCezary Rojewski 	return ret;
6673322e168SCezary Rojewski }
6683322e168SCezary Rojewski 
avs_ipc_get_modules_info(struct avs_dev * adev,struct avs_mods_info ** info)6693322e168SCezary Rojewski int avs_ipc_get_modules_info(struct avs_dev *adev, struct avs_mods_info **info)
6703322e168SCezary Rojewski {
6713322e168SCezary Rojewski 	size_t payload_size;
6723322e168SCezary Rojewski 	u8 *payload;
6733322e168SCezary Rojewski 	int ret;
6743322e168SCezary Rojewski 
6753322e168SCezary Rojewski 	ret = avs_ipc_get_large_config(adev, AVS_BASEFW_MOD_ID, AVS_BASEFW_INST_ID,
6763322e168SCezary Rojewski 				       AVS_BASEFW_MODULES_INFO, NULL, 0,
6773322e168SCezary Rojewski 				       &payload, &payload_size);
6783322e168SCezary Rojewski 	if (ret)
6793322e168SCezary Rojewski 		return ret;
68000566ad4SCezary Rojewski 	/* Non-zero payload expected for MODULES_INFO. */
68100566ad4SCezary Rojewski 	if (!payload_size)
68200566ad4SCezary Rojewski 		return -EREMOTEIO;
6833322e168SCezary Rojewski 
6843322e168SCezary Rojewski 	*info = (struct avs_mods_info *)payload;
6853322e168SCezary Rojewski 	return 0;
6863322e168SCezary Rojewski }
687580a5912SCezary Rojewski 
avs_ipc_copier_set_sink_format(struct avs_dev * adev,u16 module_id,u8 instance_id,u32 sink_id,const struct avs_audio_format * src_fmt,const struct avs_audio_format * sink_fmt)688b3eefa5dSCezary Rojewski int avs_ipc_copier_set_sink_format(struct avs_dev *adev, u16 module_id,
689b3eefa5dSCezary Rojewski 				   u8 instance_id, u32 sink_id,
690b3eefa5dSCezary Rojewski 				   const struct avs_audio_format *src_fmt,
691b3eefa5dSCezary Rojewski 				   const struct avs_audio_format *sink_fmt)
692b3eefa5dSCezary Rojewski {
693b3eefa5dSCezary Rojewski 	struct avs_copier_sink_format cpr_fmt;
694b3eefa5dSCezary Rojewski 
695b3eefa5dSCezary Rojewski 	cpr_fmt.sink_id = sink_id;
696b3eefa5dSCezary Rojewski 	/* Firmware expects driver to resend copier's input format. */
697b3eefa5dSCezary Rojewski 	cpr_fmt.src_fmt = *src_fmt;
698b3eefa5dSCezary Rojewski 	cpr_fmt.sink_fmt = *sink_fmt;
699b3eefa5dSCezary Rojewski 
700b3eefa5dSCezary Rojewski 	return avs_ipc_set_large_config(adev, module_id, instance_id,
701b3eefa5dSCezary Rojewski 					AVS_COPIER_SET_SINK_FORMAT,
702b3eefa5dSCezary Rojewski 					(u8 *)&cpr_fmt, sizeof(cpr_fmt));
703b3eefa5dSCezary Rojewski }
704b3eefa5dSCezary Rojewski 
avs_ipc_peakvol_set_volume(struct avs_dev * adev,u16 module_id,u8 instance_id,struct avs_volume_cfg * vol)705*905ea24fSAmadeusz Sławiński int avs_ipc_peakvol_set_volume(struct avs_dev *adev, u16 module_id, u8 instance_id,
706*905ea24fSAmadeusz Sławiński 			       struct avs_volume_cfg *vol)
707*905ea24fSAmadeusz Sławiński {
708*905ea24fSAmadeusz Sławiński 	return avs_ipc_set_large_config(adev, module_id, instance_id, AVS_PEAKVOL_VOLUME, (u8 *)vol,
709*905ea24fSAmadeusz Sławiński 					sizeof(*vol));
710*905ea24fSAmadeusz Sławiński }
711*905ea24fSAmadeusz Sławiński 
avs_ipc_peakvol_get_volume(struct avs_dev * adev,u16 module_id,u8 instance_id,struct avs_volume_cfg ** vols,size_t * num_vols)712*905ea24fSAmadeusz Sławiński int avs_ipc_peakvol_get_volume(struct avs_dev *adev, u16 module_id, u8 instance_id,
713*905ea24fSAmadeusz Sławiński 			       struct avs_volume_cfg **vols, size_t *num_vols)
714*905ea24fSAmadeusz Sławiński {
715*905ea24fSAmadeusz Sławiński 	size_t payload_size;
716*905ea24fSAmadeusz Sławiński 	u8 *payload;
717*905ea24fSAmadeusz Sławiński 	int ret;
718*905ea24fSAmadeusz Sławiński 
719*905ea24fSAmadeusz Sławiński 	ret = avs_ipc_get_large_config(adev, module_id, instance_id, AVS_PEAKVOL_VOLUME, NULL, 0,
720*905ea24fSAmadeusz Sławiński 				       &payload, &payload_size);
721*905ea24fSAmadeusz Sławiński 	if (ret)
722*905ea24fSAmadeusz Sławiński 		return ret;
723*905ea24fSAmadeusz Sławiński 
724*905ea24fSAmadeusz Sławiński 	/* Non-zero payload expected for PEAKVOL_VOLUME. */
725*905ea24fSAmadeusz Sławiński 	if (!payload_size)
726*905ea24fSAmadeusz Sławiński 		return -EREMOTEIO;
727*905ea24fSAmadeusz Sławiński 
728*905ea24fSAmadeusz Sławiński 	*vols = (struct avs_volume_cfg *)payload;
729*905ea24fSAmadeusz Sławiński 	*num_vols = payload_size / sizeof(**vols);
730*905ea24fSAmadeusz Sławiński 
731*905ea24fSAmadeusz Sławiński 	return 0;
732*905ea24fSAmadeusz Sławiński }
733*905ea24fSAmadeusz Sławiński 
734b3eefa5dSCezary Rojewski #ifdef CONFIG_DEBUG_FS
avs_ipc_set_enable_logs(struct avs_dev * adev,u8 * log_info,size_t size)7354b86115cSCezary Rojewski int avs_ipc_set_enable_logs(struct avs_dev *adev, u8 *log_info, size_t size)
7364b86115cSCezary Rojewski {
73765edda60SCezary Rojewski 	return avs_ipc_set_large_config(adev, AVS_BASEFW_MOD_ID, AVS_BASEFW_INST_ID,
7384b86115cSCezary Rojewski 					AVS_BASEFW_ENABLE_LOGS, log_info, size);
7394b86115cSCezary Rojewski }
7404b86115cSCezary Rojewski 
avs_ipc_set_system_time(struct avs_dev * adev)7414b86115cSCezary Rojewski int avs_ipc_set_system_time(struct avs_dev *adev)
7424b86115cSCezary Rojewski {
7434b86115cSCezary Rojewski 	struct avs_sys_time sys_time;
7444b86115cSCezary Rojewski 	u64 us;
7454b86115cSCezary Rojewski 
7464b86115cSCezary Rojewski 	/* firmware expects UTC time in micro seconds */
7474b86115cSCezary Rojewski 	us = ktime_to_us(ktime_get());
7484b86115cSCezary Rojewski 	sys_time.val_l = us & UINT_MAX;
7494b86115cSCezary Rojewski 	sys_time.val_u = us >> 32;
7504b86115cSCezary Rojewski 
75165edda60SCezary Rojewski 	return avs_ipc_set_large_config(adev, AVS_BASEFW_MOD_ID, AVS_BASEFW_INST_ID,
7524b86115cSCezary Rojewski 					AVS_BASEFW_SYSTEM_TIME, (u8 *)&sys_time, sizeof(sys_time));
7534b86115cSCezary Rojewski }
754dab8d000SCezary Rojewski 
avs_ipc_probe_get_dma(struct avs_dev * adev,struct avs_probe_dma ** dmas,size_t * num_dmas)755dab8d000SCezary Rojewski int avs_ipc_probe_get_dma(struct avs_dev *adev, struct avs_probe_dma **dmas, size_t *num_dmas)
756dab8d000SCezary Rojewski {
757dab8d000SCezary Rojewski 	size_t payload_size;
758dab8d000SCezary Rojewski 	u32 module_id;
759dab8d000SCezary Rojewski 	u8 *payload;
760dab8d000SCezary Rojewski 	int ret;
761dab8d000SCezary Rojewski 
762dab8d000SCezary Rojewski 	module_id = avs_get_module_id(adev, &AVS_PROBE_MOD_UUID);
763dab8d000SCezary Rojewski 
764dab8d000SCezary Rojewski 	ret = avs_ipc_get_large_config(adev, module_id, AVS_PROBE_INST_ID, AVS_PROBE_INJECTION_DMA,
765dab8d000SCezary Rojewski 				       NULL, 0, &payload, &payload_size);
766dab8d000SCezary Rojewski 	if (ret)
767dab8d000SCezary Rojewski 		return ret;
768dab8d000SCezary Rojewski 
769dab8d000SCezary Rojewski 	*dmas = (struct avs_probe_dma *)payload;
770dab8d000SCezary Rojewski 	*num_dmas = payload_size / sizeof(**dmas);
771dab8d000SCezary Rojewski 
772dab8d000SCezary Rojewski 	return 0;
773dab8d000SCezary Rojewski }
774dab8d000SCezary Rojewski 
avs_ipc_probe_attach_dma(struct avs_dev * adev,struct avs_probe_dma * dmas,size_t num_dmas)775dab8d000SCezary Rojewski int avs_ipc_probe_attach_dma(struct avs_dev *adev, struct avs_probe_dma *dmas, size_t num_dmas)
776dab8d000SCezary Rojewski {
777dab8d000SCezary Rojewski 	u32 module_id = avs_get_module_id(adev, &AVS_PROBE_MOD_UUID);
778dab8d000SCezary Rojewski 
779dab8d000SCezary Rojewski 	return avs_ipc_set_large_config(adev, module_id, AVS_PROBE_INST_ID, AVS_PROBE_INJECTION_DMA,
780dab8d000SCezary Rojewski 					(u8 *)dmas, array_size(sizeof(*dmas), num_dmas));
781dab8d000SCezary Rojewski }
782dab8d000SCezary Rojewski 
avs_ipc_probe_detach_dma(struct avs_dev * adev,union avs_connector_node_id * node_ids,size_t num_node_ids)783dab8d000SCezary Rojewski int avs_ipc_probe_detach_dma(struct avs_dev *adev, union avs_connector_node_id *node_ids,
784dab8d000SCezary Rojewski 			     size_t num_node_ids)
785dab8d000SCezary Rojewski {
786dab8d000SCezary Rojewski 	u32 module_id = avs_get_module_id(adev, &AVS_PROBE_MOD_UUID);
787dab8d000SCezary Rojewski 
788dab8d000SCezary Rojewski 	return avs_ipc_set_large_config(adev, module_id, AVS_PROBE_INST_ID,
789dab8d000SCezary Rojewski 					AVS_PROBE_INJECTION_DMA_DETACH, (u8 *)node_ids,
790dab8d000SCezary Rojewski 					array_size(sizeof(*node_ids), num_node_ids));
791dab8d000SCezary Rojewski }
792dab8d000SCezary Rojewski 
avs_ipc_probe_get_points(struct avs_dev * adev,struct avs_probe_point_desc ** descs,size_t * num_descs)793dab8d000SCezary Rojewski int avs_ipc_probe_get_points(struct avs_dev *adev, struct avs_probe_point_desc **descs,
794dab8d000SCezary Rojewski 			     size_t *num_descs)
795dab8d000SCezary Rojewski {
796dab8d000SCezary Rojewski 	size_t payload_size;
797dab8d000SCezary Rojewski 	u32 module_id;
798dab8d000SCezary Rojewski 	u8 *payload;
799dab8d000SCezary Rojewski 	int ret;
800dab8d000SCezary Rojewski 
801dab8d000SCezary Rojewski 	module_id = avs_get_module_id(adev, &AVS_PROBE_MOD_UUID);
802dab8d000SCezary Rojewski 
803dab8d000SCezary Rojewski 	ret = avs_ipc_get_large_config(adev, module_id, AVS_PROBE_INST_ID, AVS_PROBE_POINTS, NULL,
804dab8d000SCezary Rojewski 				       0, &payload, &payload_size);
805dab8d000SCezary Rojewski 	if (ret)
806dab8d000SCezary Rojewski 		return ret;
807dab8d000SCezary Rojewski 
808dab8d000SCezary Rojewski 	*descs = (struct avs_probe_point_desc *)payload;
809dab8d000SCezary Rojewski 	*num_descs = payload_size / sizeof(**descs);
810dab8d000SCezary Rojewski 
811dab8d000SCezary Rojewski 	return 0;
812dab8d000SCezary Rojewski }
813dab8d000SCezary Rojewski 
avs_ipc_probe_connect_points(struct avs_dev * adev,struct avs_probe_point_desc * descs,size_t num_descs)814dab8d000SCezary Rojewski int avs_ipc_probe_connect_points(struct avs_dev *adev, struct avs_probe_point_desc *descs,
815dab8d000SCezary Rojewski 				 size_t num_descs)
816dab8d000SCezary Rojewski {
817dab8d000SCezary Rojewski 	u32 module_id = avs_get_module_id(adev, &AVS_PROBE_MOD_UUID);
818dab8d000SCezary Rojewski 
819dab8d000SCezary Rojewski 	return avs_ipc_set_large_config(adev, module_id, AVS_PROBE_INST_ID, AVS_PROBE_POINTS,
820dab8d000SCezary Rojewski 					(u8 *)descs, array_size(sizeof(*descs), num_descs));
821dab8d000SCezary Rojewski }
822dab8d000SCezary Rojewski 
avs_ipc_probe_disconnect_points(struct avs_dev * adev,union avs_probe_point_id * ids,size_t num_ids)823dab8d000SCezary Rojewski int avs_ipc_probe_disconnect_points(struct avs_dev *adev, union avs_probe_point_id *ids,
824dab8d000SCezary Rojewski 				    size_t num_ids)
825dab8d000SCezary Rojewski {
826dab8d000SCezary Rojewski 	u32 module_id = avs_get_module_id(adev, &AVS_PROBE_MOD_UUID);
827dab8d000SCezary Rojewski 
828dab8d000SCezary Rojewski 	return avs_ipc_set_large_config(adev, module_id, AVS_PROBE_INST_ID,
829dab8d000SCezary Rojewski 					AVS_PROBE_POINTS_DISCONNECT, (u8 *)ids,
830dab8d000SCezary Rojewski 					array_size(sizeof(*ids), num_ids));
831dab8d000SCezary Rojewski }
832b3eefa5dSCezary Rojewski #endif
833