aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
authorDharageswari R <dharageswari.r@intel.com>2016-09-22 04:30:37 -0400
committerMark Brown <broonie@kernel.org>2016-09-24 14:26:24 -0400
commit700a9a63f9c1bc13abaa956eacc0bfcaf3a201c2 (patch)
tree427b291810c2caa35082e542fe1be4a70cd4313e /sound
parentdde53bcc3ea054a72b6d42a6fe56beb4b1a914f2 (diff)
ASoC: Intel: Skylake: Add module instance id generation APIs
Driver needs to send unique module instance id to firmware while creating the module and uses this id to communicate with DSP for setting parameters while audio use case is ongoing. But, we have upper bound of instance ID. The current IDs are coming from topology but it doesn't know the upper bound and can't assign unique id's subject to upper bounds as we can create a big graph but not all parts running at same time. This patch adds a 128bit unique id management routines which are built on top of ffz() for faster implementation. Unfortunately ffz() works on 32bits values, so additional code is added on top of ffz() to create a 128bit unique id. Signed-off-by: Dharageswari R <dharageswari.r@intel.com> Signed-off-by: Vinod Koul <vinod.koul@intel.com> Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'sound')
-rw-r--r--sound/soc/intel/skylake/skl-sst-dsp.h4
-rw-r--r--sound/soc/intel/skylake/skl-sst-utils.c115
-rw-r--r--sound/soc/intel/skylake/skl-topology.h1
3 files changed, 120 insertions, 0 deletions
diff --git a/sound/soc/intel/skylake/skl-sst-dsp.h b/sound/soc/intel/skylake/skl-sst-dsp.h
index 6ad5cab4b0d5..b61bd03ee4f0 100644
--- a/sound/soc/intel/skylake/skl-sst-dsp.h
+++ b/sound/soc/intel/skylake/skl-sst-dsp.h
@@ -215,6 +215,10 @@ int snd_skl_get_module_info(struct skl_sst *ctx,
215 struct skl_module_cfg *mconfig); 215 struct skl_module_cfg *mconfig);
216int snd_skl_parse_uuids(struct sst_dsp *ctx, const struct firmware *fw, 216int snd_skl_parse_uuids(struct sst_dsp *ctx, const struct firmware *fw,
217 unsigned int offset, int index); 217 unsigned int offset, int index);
218int skl_get_pvt_id(struct skl_sst *ctx,
219 struct skl_module_cfg *mconfig);
220int skl_put_pvt_id(struct skl_sst *ctx,
221 struct skl_module_cfg *mconfig);
218void skl_freeup_uuid_list(struct skl_sst *ctx); 222void skl_freeup_uuid_list(struct skl_sst *ctx);
219 223
220int skl_dsp_strip_extended_manifest(struct firmware *fw); 224int skl_dsp_strip_extended_manifest(struct firmware *fw);
diff --git a/sound/soc/intel/skylake/skl-sst-utils.c b/sound/soc/intel/skylake/skl-sst-utils.c
index 9ce93e9a03b5..5f1c203a448e 100644
--- a/sound/soc/intel/skylake/skl-sst-utils.c
+++ b/sound/soc/intel/skylake/skl-sst-utils.c
@@ -94,10 +94,14 @@ struct adsp_fw_hdr {
94 u32 load_offset; 94 u32 load_offset;
95} __packed; 95} __packed;
96 96
97#define MAX_INSTANCE_BUFF 2
98
97struct uuid_module { 99struct uuid_module {
98 uuid_le uuid; 100 uuid_le uuid;
99 int id; 101 int id;
100 int is_loadable; 102 int is_loadable;
103 int max_instance;
104 u64 pvt_id[MAX_INSTANCE_BUFF];
101 105
102 struct list_head list; 106 struct list_head list;
103}; 107};
@@ -131,6 +135,116 @@ int snd_skl_get_module_info(struct skl_sst *ctx,
131} 135}
132EXPORT_SYMBOL_GPL(snd_skl_get_module_info); 136EXPORT_SYMBOL_GPL(snd_skl_get_module_info);
133 137
138static inline int skl_getid_32(struct uuid_module *module, u64 *val,
139 int word1_mask, int word2_mask)
140{
141 int index, max_inst, pvt_id;
142 u32 mask_val;
143
144 max_inst = module->max_instance;
145 mask_val = (u32)(*val >> word1_mask);
146
147 if (mask_val != 0xffffffff) {
148 index = ffz(mask_val);
149 pvt_id = index + word1_mask + word2_mask;
150 if (pvt_id <= (max_inst - 1)) {
151 *val |= 1 << (index + word1_mask);
152 return pvt_id;
153 }
154 }
155
156 return -EINVAL;
157}
158
159static inline int skl_pvtid_128(struct uuid_module *module)
160{
161 int j, i, word1_mask, word2_mask = 0, pvt_id;
162
163 for (j = 0; j < MAX_INSTANCE_BUFF; j++) {
164 word1_mask = 0;
165
166 for (i = 0; i < 2; i++) {
167 pvt_id = skl_getid_32(module, &module->pvt_id[j],
168 word1_mask, word2_mask);
169 if (pvt_id >= 0)
170 return pvt_id;
171
172 word1_mask += 32;
173 if ((word1_mask + word2_mask) >= module->max_instance)
174 return -EINVAL;
175 }
176
177 word2_mask += 64;
178 if (word2_mask >= module->max_instance)
179 return -EINVAL;
180 }
181
182 return -EINVAL;
183}
184
185/**
186 * skl_get_pvt_id: generate a private id for use as module id
187 *
188 * @ctx: driver context
189 * @mconfig: module configuration data
190 *
191 * This generates a 128 bit private unique id for a module TYPE so that
192 * module instance is unique
193 */
194int skl_get_pvt_id(struct skl_sst *ctx, struct skl_module_cfg *mconfig)
195{
196 struct uuid_module *module;
197 uuid_le *uuid_mod;
198 int pvt_id;
199
200 uuid_mod = (uuid_le *)mconfig->guid;
201
202 list_for_each_entry(module, &ctx->uuid_list, list) {
203 if (uuid_le_cmp(*uuid_mod, module->uuid) == 0) {
204
205 pvt_id = skl_pvtid_128(module);
206 if (pvt_id >= 0)
207 return pvt_id;
208 }
209 }
210
211 return -EINVAL;
212}
213EXPORT_SYMBOL_GPL(skl_get_pvt_id);
214
215/**
216 * skl_put_pvt_id: free up the private id allocated
217 *
218 * @ctx: driver context
219 * @mconfig: module configuration data
220 *
221 * This frees a 128 bit private unique id previously generated
222 */
223int skl_put_pvt_id(struct skl_sst *ctx, struct skl_module_cfg *mconfig)
224{
225 int i;
226 uuid_le *uuid_mod;
227 struct uuid_module *module;
228
229 uuid_mod = (uuid_le *)mconfig->guid;
230 list_for_each_entry(module, &ctx->uuid_list, list) {
231 if (uuid_le_cmp(*uuid_mod, module->uuid) == 0) {
232
233 if (mconfig->id.pvt_id != 0)
234 i = (mconfig->id.pvt_id) / 64;
235 else
236 i = 0;
237
238 module->pvt_id[i] &= ~(1 << (mconfig->id.pvt_id));
239 mconfig->id.pvt_id = -1;
240 return 0;
241 }
242 }
243
244 return -EINVAL;
245}
246EXPORT_SYMBOL_GPL(skl_put_pvt_id);
247
134/* 248/*
135 * Parse the firmware binary to get the UUID, module id 249 * Parse the firmware binary to get the UUID, module id
136 * and loadable flags 250 * and loadable flags
@@ -203,6 +317,7 @@ int snd_skl_parse_uuids(struct sst_dsp *ctx, const struct firmware *fw,
203 317
204 module->id = (i | (index << 12)); 318 module->id = (i | (index << 12));
205 module->is_loadable = mod_entry->type.load_type; 319 module->is_loadable = mod_entry->type.load_type;
320 module->max_instance = mod_entry->instance_max_count;
206 321
207 list_add_tail(&module->list, &skl->uuid_list); 322 list_add_tail(&module->list, &skl->uuid_list);
208 323
diff --git a/sound/soc/intel/skylake/skl-topology.h b/sound/soc/intel/skylake/skl-topology.h
index 37f45cc32a44..def03912b1bd 100644
--- a/sound/soc/intel/skylake/skl-topology.h
+++ b/sound/soc/intel/skylake/skl-topology.h
@@ -218,6 +218,7 @@ struct skl_module_cfg;
218struct skl_module_inst_id { 218struct skl_module_inst_id {
219 int module_id; 219 int module_id;
220 u32 instance_id; 220 u32 instance_id;
221 int pvt_id;
221}; 222};
222 223
223enum skl_module_pin_state { 224enum skl_module_pin_state {