Skip to content

Commit 44c28db

Browse files
Srinivas-Kandagatlabroonie
authored andcommitted
ASoC: qdsp6: audioreach: add basic pkt alloc support
Add basic helper functions for AudioReach. Signed-off-by: Srinivas Kandagatla <[email protected]> Reviewed-by: Pierre-Louis Bossart <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 96d0232 commit 44c28db

File tree

2 files changed

+923
-0
lines changed

2 files changed

+923
-0
lines changed

sound/soc/qcom/qdsp6/audioreach.c

Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
// Copyright (c) 2020, Linaro Limited
3+
4+
#include <linux/kernel.h>
5+
#include <linux/slab.h>
6+
#include <linux/soc/qcom/apr.h>
7+
#include <dt-bindings/soc/qcom,gpr.h>
8+
#include "audioreach.h"
9+
10+
/* SubGraph Config */
11+
struct apm_sub_graph_data {
12+
struct apm_sub_graph_cfg sub_graph_cfg;
13+
struct apm_prop_data perf_data;
14+
struct apm_sg_prop_id_perf_mode perf;
15+
struct apm_prop_data dir_data;
16+
struct apm_sg_prop_id_direction dir;
17+
struct apm_prop_data sid_data;
18+
struct apm_sg_prop_id_scenario_id sid;
19+
20+
} __packed;
21+
22+
#define APM_SUB_GRAPH_CFG_NPROP 3
23+
24+
struct apm_sub_graph_params {
25+
struct apm_module_param_data param_data;
26+
uint32_t num_sub_graphs;
27+
struct apm_sub_graph_data sg_cfg[];
28+
} __packed;
29+
30+
#define APM_SUB_GRAPH_PSIZE(p, n) ALIGN(struct_size(p, sg_cfg, n), 8)
31+
32+
/* container config */
33+
struct apm_container_obj {
34+
struct apm_container_cfg container_cfg;
35+
/* Capability ID list */
36+
struct apm_prop_data cap_data;
37+
uint32_t num_capability_id;
38+
uint32_t capability_id;
39+
40+
/* Container graph Position */
41+
struct apm_prop_data pos_data;
42+
struct apm_cont_prop_id_graph_pos pos;
43+
44+
/* Container Stack size */
45+
struct apm_prop_data stack_data;
46+
struct apm_cont_prop_id_stack_size stack;
47+
48+
/* Container proc domain id */
49+
struct apm_prop_data domain_data;
50+
struct apm_cont_prop_id_domain domain;
51+
} __packed;
52+
53+
struct apm_container_params {
54+
struct apm_module_param_data param_data;
55+
uint32_t num_containers;
56+
struct apm_container_obj cont_obj[];
57+
} __packed;
58+
59+
#define APM_CONTAINER_PSIZE(p, n) ALIGN(struct_size(p, cont_obj, n), 8)
60+
61+
/* Module List config */
62+
struct apm_mod_list_obj {
63+
/* Modules list cfg */
64+
uint32_t sub_graph_id;
65+
uint32_t container_id;
66+
uint32_t num_modules;
67+
struct apm_module_obj mod_cfg[];
68+
} __packed;
69+
70+
#define APM_MOD_LIST_OBJ_PSIZE(p, n) struct_size(p, mod_cfg, n)
71+
72+
struct apm_module_list_params {
73+
struct apm_module_param_data param_data;
74+
uint32_t num_modules_list;
75+
/* Module list config array */
76+
struct apm_mod_list_obj mod_list_obj[];
77+
} __packed;
78+
79+
80+
/* Module Properties */
81+
struct apm_mod_prop_obj {
82+
u32 instance_id;
83+
u32 num_props;
84+
struct apm_prop_data prop_data_1;
85+
struct apm_module_prop_id_port_info prop_id_port;
86+
} __packed;
87+
88+
struct apm_prop_list_params {
89+
struct apm_module_param_data param_data;
90+
u32 num_modules_prop_cfg;
91+
struct apm_mod_prop_obj mod_prop_obj[];
92+
93+
} __packed;
94+
95+
#define APM_MOD_PROP_PSIZE(p, n) ALIGN(struct_size(p, mod_prop_obj, n), 8)
96+
97+
/* Module Connections */
98+
struct apm_mod_conn_list_params {
99+
struct apm_module_param_data param_data;
100+
u32 num_connections;
101+
struct apm_module_conn_obj conn_obj[];
102+
103+
} __packed;
104+
105+
#define APM_MOD_CONN_PSIZE(p, n) ALIGN(struct_size(p, conn_obj, n), 8)
106+
107+
struct apm_graph_open_params {
108+
struct apm_cmd_header *cmd_header;
109+
struct apm_sub_graph_params *sg_data;
110+
struct apm_container_params *cont_data;
111+
struct apm_module_list_params *mod_list_data;
112+
struct apm_prop_list_params *mod_prop_data;
113+
struct apm_mod_conn_list_params *mod_conn_list_data;
114+
} __packed;
115+
116+
struct apm_pcm_module_media_fmt_cmd {
117+
struct apm_module_param_data param_data;
118+
struct param_id_pcm_output_format_cfg header;
119+
struct payload_pcm_output_format_cfg media_cfg;
120+
} __packed;
121+
122+
struct apm_rd_shmem_module_config_cmd {
123+
struct apm_module_param_data param_data;
124+
struct param_id_rd_sh_mem_cfg cfg;
125+
} __packed;
126+
127+
struct apm_sh_module_media_fmt_cmd {
128+
struct media_format header;
129+
struct payload_media_fmt_pcm cfg;
130+
} __packed;
131+
132+
#define APM_SHMEM_FMT_CFG_PSIZE(ch) ALIGN( \
133+
sizeof(struct apm_sh_module_media_fmt_cmd) + \
134+
ch * sizeof(uint8_t), 8)
135+
136+
/* num of channels as argument */
137+
#define APM_PCM_MODULE_FMT_CMD_PSIZE(ch) ALIGN( \
138+
sizeof(struct apm_pcm_module_media_fmt_cmd) + \
139+
ch * sizeof(uint8_t), 8)
140+
141+
#define APM_PCM_OUT_FMT_CFG_PSIZE(p, n) ALIGN(struct_size(p, channel_mapping, n), 4)
142+
143+
struct apm_i2s_module_intf_cfg {
144+
struct apm_module_param_data param_data;
145+
struct param_id_i2s_intf_cfg cfg;
146+
} __packed;
147+
148+
#define APM_I2S_INTF_CFG_PSIZE ALIGN(sizeof(struct apm_i2s_module_intf_cfg), 8)
149+
150+
struct apm_module_hw_ep_mf_cfg {
151+
struct apm_module_param_data param_data;
152+
struct param_id_hw_ep_mf mf;
153+
} __packed;
154+
155+
#define APM_HW_EP_CFG_PSIZE ALIGN(sizeof(struct apm_module_hw_ep_mf_cfg), 8)
156+
157+
struct apm_module_frame_size_factor_cfg {
158+
struct apm_module_param_data param_data;
159+
uint32_t frame_size_factor;
160+
} __packed;
161+
162+
#define APM_FS_CFG_PSIZE ALIGN(sizeof(struct apm_module_frame_size_factor_cfg), 8)
163+
164+
struct apm_module_hw_ep_power_mode_cfg {
165+
struct apm_module_param_data param_data;
166+
struct param_id_hw_ep_power_mode_cfg power_mode;
167+
} __packed;
168+
169+
#define APM_HW_EP_PMODE_CFG_PSIZE ALIGN(sizeof(struct apm_module_hw_ep_power_mode_cfg), 8)
170+
171+
struct apm_module_hw_ep_dma_data_align_cfg {
172+
struct apm_module_param_data param_data;
173+
struct param_id_hw_ep_dma_data_align align;
174+
} __packed;
175+
176+
#define APM_HW_EP_DALIGN_CFG_PSIZE ALIGN(sizeof(struct apm_module_hw_ep_dma_data_align_cfg), 8)
177+
178+
struct apm_gain_module_cfg {
179+
struct apm_module_param_data param_data;
180+
struct param_id_gain_cfg gain_cfg;
181+
} __packed;
182+
183+
#define APM_GAIN_CFG_PSIZE ALIGN(sizeof(struct apm_gain_module_cfg), 8)
184+
185+
struct apm_codec_dma_module_intf_cfg {
186+
struct apm_module_param_data param_data;
187+
struct param_id_codec_dma_intf_cfg cfg;
188+
} __packed;
189+
190+
#define APM_CDMA_INTF_CFG_PSIZE ALIGN(sizeof(struct apm_codec_dma_module_intf_cfg), 8)
191+
192+
static void *__audioreach_alloc_pkt(int payload_size, uint32_t opcode, uint32_t token,
193+
uint32_t src_port, uint32_t dest_port, bool has_cmd_hdr)
194+
{
195+
struct gpr_pkt *pkt;
196+
void *p;
197+
int pkt_size = GPR_HDR_SIZE + payload_size;
198+
199+
if (has_cmd_hdr)
200+
pkt_size += APM_CMD_HDR_SIZE;
201+
202+
p = kzalloc(pkt_size, GFP_KERNEL);
203+
if (!p)
204+
return ERR_PTR(-ENOMEM);
205+
206+
pkt = p;
207+
pkt->hdr.version = GPR_PKT_VER;
208+
pkt->hdr.hdr_size = GPR_PKT_HEADER_WORD_SIZE;
209+
pkt->hdr.pkt_size = pkt_size;
210+
pkt->hdr.dest_port = dest_port;
211+
pkt->hdr.src_port = src_port;
212+
213+
pkt->hdr.dest_domain = GPR_DOMAIN_ID_ADSP;
214+
pkt->hdr.src_domain = GPR_DOMAIN_ID_APPS;
215+
pkt->hdr.token = token;
216+
pkt->hdr.opcode = opcode;
217+
218+
if (has_cmd_hdr) {
219+
struct apm_cmd_header *cmd_header;
220+
221+
p = p + GPR_HDR_SIZE;
222+
cmd_header = p;
223+
cmd_header->payload_size = payload_size;
224+
}
225+
226+
return pkt;
227+
}
228+
229+
void *audioreach_alloc_pkt(int payload_size, uint32_t opcode, uint32_t token,
230+
uint32_t src_port, uint32_t dest_port)
231+
{
232+
return __audioreach_alloc_pkt(payload_size, opcode, token, src_port, dest_port, false);
233+
}
234+
EXPORT_SYMBOL_GPL(audioreach_alloc_pkt);
235+
236+
void *audioreach_alloc_apm_pkt(int pkt_size, uint32_t opcode, uint32_t token, uint32_t src_port)
237+
{
238+
return __audioreach_alloc_pkt(pkt_size, opcode, token, src_port, APM_MODULE_INSTANCE_ID,
239+
false);
240+
}
241+
EXPORT_SYMBOL_GPL(audioreach_alloc_apm_pkt);
242+
243+
void *audioreach_alloc_cmd_pkt(int payload_size, uint32_t opcode, uint32_t token,
244+
uint32_t src_port, uint32_t dest_port)
245+
{
246+
return __audioreach_alloc_pkt(payload_size, opcode, token, src_port, dest_port, true);
247+
}
248+
EXPORT_SYMBOL_GPL(audioreach_alloc_cmd_pkt);
249+
250+
void *audioreach_alloc_apm_cmd_pkt(int pkt_size, uint32_t opcode, uint32_t token)
251+
{
252+
return __audioreach_alloc_pkt(pkt_size, opcode, token, GPR_APM_MODULE_IID,
253+
APM_MODULE_INSTANCE_ID, true);
254+
}
255+
EXPORT_SYMBOL_GPL(audioreach_alloc_apm_cmd_pkt);

0 commit comments

Comments
 (0)