.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * skl-sst-utils.c - SKL sst utils functions |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2016 Intel Corp |
---|
5 | | - * |
---|
6 | | - * This program is free software; you can redistribute it and/or modify |
---|
7 | | - * it under the terms of the GNU General Public License as version 2, as |
---|
8 | | - * published by the Free Software Foundation. |
---|
9 | | - * |
---|
10 | | - * This program is distributed in the hope that it will be useful, but |
---|
11 | | - * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
13 | | - * General Public License for more details. |
---|
14 | 6 | */ |
---|
15 | 7 | |
---|
16 | 8 | #include <linux/device.h> |
---|
17 | 9 | #include <linux/slab.h> |
---|
18 | 10 | #include <linux/uuid.h> |
---|
19 | | -#include "skl-sst-dsp.h" |
---|
20 | 11 | #include "../common/sst-dsp.h" |
---|
21 | 12 | #include "../common/sst-dsp-priv.h" |
---|
22 | | -#include "skl-sst-ipc.h" |
---|
| 13 | +#include "skl.h" |
---|
23 | 14 | |
---|
24 | | - |
---|
25 | | -#define UUID_STR_SIZE 37 |
---|
26 | 15 | #define DEFAULT_HASH_SHA256_LEN 32 |
---|
27 | 16 | |
---|
28 | 17 | /* FW Extended Manifest Header id = $AE1 */ |
---|
29 | 18 | #define SKL_EXT_MANIFEST_HEADER_MAGIC 0x31454124 |
---|
30 | | - |
---|
31 | | -struct UUID { |
---|
32 | | - u8 id[16]; |
---|
33 | | -}; |
---|
34 | 19 | |
---|
35 | 20 | union seg_flags { |
---|
36 | 21 | u32 ul; |
---|
.. | .. |
---|
65 | 50 | struct adsp_module_entry { |
---|
66 | 51 | u32 struct_id; |
---|
67 | 52 | u8 name[8]; |
---|
68 | | - struct UUID uuid; |
---|
| 53 | + u8 uuid[16]; |
---|
69 | 54 | struct module_type type; |
---|
70 | 55 | u8 hash1[DEFAULT_HASH_SHA256_LEN]; |
---|
71 | 56 | u32 entry_point; |
---|
.. | .. |
---|
113 | 98 | return -EINVAL; |
---|
114 | 99 | } |
---|
115 | 100 | |
---|
116 | | -int skl_get_pvt_instance_id_map(struct skl_sst *ctx, |
---|
| 101 | +int skl_get_pvt_instance_id_map(struct skl_dev *skl, |
---|
117 | 102 | int module_id, int instance_id) |
---|
118 | 103 | { |
---|
119 | 104 | struct uuid_module *module; |
---|
120 | 105 | |
---|
121 | | - list_for_each_entry(module, &ctx->uuid_list, list) { |
---|
| 106 | + list_for_each_entry(module, &skl->uuid_list, list) { |
---|
122 | 107 | if (module->id == module_id) |
---|
123 | 108 | return skl_get_pvtid_map(module, instance_id); |
---|
124 | 109 | } |
---|
.. | .. |
---|
177 | 162 | /** |
---|
178 | 163 | * skl_get_pvt_id: generate a private id for use as module id |
---|
179 | 164 | * |
---|
180 | | - * @ctx: driver context |
---|
| 165 | + * @skl: driver context |
---|
181 | 166 | * @uuid_mod: module's uuid |
---|
182 | 167 | * @instance_id: module's instance id |
---|
183 | 168 | * |
---|
184 | 169 | * This generates a 128 bit private unique id for a module TYPE so that |
---|
185 | 170 | * module instance is unique |
---|
186 | 171 | */ |
---|
187 | | -int skl_get_pvt_id(struct skl_sst *ctx, uuid_le *uuid_mod, int instance_id) |
---|
| 172 | +int skl_get_pvt_id(struct skl_dev *skl, guid_t *uuid_mod, int instance_id) |
---|
188 | 173 | { |
---|
189 | 174 | struct uuid_module *module; |
---|
190 | 175 | int pvt_id; |
---|
191 | 176 | |
---|
192 | | - list_for_each_entry(module, &ctx->uuid_list, list) { |
---|
193 | | - if (uuid_le_cmp(*uuid_mod, module->uuid) == 0) { |
---|
| 177 | + list_for_each_entry(module, &skl->uuid_list, list) { |
---|
| 178 | + if (guid_equal(uuid_mod, &module->uuid)) { |
---|
194 | 179 | |
---|
195 | 180 | pvt_id = skl_pvtid_128(module); |
---|
196 | 181 | if (pvt_id >= 0) { |
---|
.. | .. |
---|
208 | 193 | /** |
---|
209 | 194 | * skl_put_pvt_id: free up the private id allocated |
---|
210 | 195 | * |
---|
211 | | - * @ctx: driver context |
---|
| 196 | + * @skl: driver context |
---|
212 | 197 | * @uuid_mod: module's uuid |
---|
213 | 198 | * @pvt_id: module pvt id |
---|
214 | 199 | * |
---|
215 | 200 | * This frees a 128 bit private unique id previously generated |
---|
216 | 201 | */ |
---|
217 | | -int skl_put_pvt_id(struct skl_sst *ctx, uuid_le *uuid_mod, int *pvt_id) |
---|
| 202 | +int skl_put_pvt_id(struct skl_dev *skl, guid_t *uuid_mod, int *pvt_id) |
---|
218 | 203 | { |
---|
219 | 204 | int i; |
---|
220 | 205 | struct uuid_module *module; |
---|
221 | 206 | |
---|
222 | | - list_for_each_entry(module, &ctx->uuid_list, list) { |
---|
223 | | - if (uuid_le_cmp(*uuid_mod, module->uuid) == 0) { |
---|
| 207 | + list_for_each_entry(module, &skl->uuid_list, list) { |
---|
| 208 | + if (guid_equal(uuid_mod, &module->uuid)) { |
---|
224 | 209 | |
---|
225 | 210 | if (*pvt_id != 0) |
---|
226 | 211 | i = (*pvt_id) / 64; |
---|
.. | .. |
---|
247 | 232 | struct adsp_fw_hdr *adsp_hdr; |
---|
248 | 233 | struct adsp_module_entry *mod_entry; |
---|
249 | 234 | int i, num_entry, size; |
---|
250 | | - uuid_le *uuid_bin; |
---|
251 | 235 | const char *buf; |
---|
252 | | - struct skl_sst *skl = ctx->thread_context; |
---|
| 236 | + struct skl_dev *skl = ctx->thread_context; |
---|
253 | 237 | struct uuid_module *module; |
---|
254 | 238 | struct firmware stripped_fw; |
---|
255 | 239 | unsigned int safe_file; |
---|
256 | | - int ret = 0; |
---|
| 240 | + int ret; |
---|
257 | 241 | |
---|
258 | 242 | /* Get the FW pointer to derive ADSP header */ |
---|
259 | 243 | stripped_fw.data = fw->data; |
---|
.. | .. |
---|
279 | 263 | return -EINVAL; |
---|
280 | 264 | } |
---|
281 | 265 | |
---|
282 | | - mod_entry = (struct adsp_module_entry *) |
---|
283 | | - (buf + offset + adsp_hdr->len); |
---|
| 266 | + mod_entry = (struct adsp_module_entry *)(buf + offset + adsp_hdr->len); |
---|
284 | 267 | |
---|
285 | 268 | num_entry = adsp_hdr->num_modules; |
---|
286 | 269 | |
---|
.. | .. |
---|
307 | 290 | goto free_uuid_list; |
---|
308 | 291 | } |
---|
309 | 292 | |
---|
310 | | - uuid_bin = (uuid_le *)mod_entry->uuid.id; |
---|
311 | | - memcpy(&module->uuid, uuid_bin, sizeof(module->uuid)); |
---|
| 293 | + import_guid(&module->uuid, mod_entry->uuid); |
---|
312 | 294 | |
---|
313 | 295 | module->id = (i | (index << 12)); |
---|
314 | 296 | module->is_loadable = mod_entry->type.load_type; |
---|
.. | .. |
---|
334 | 316 | return ret; |
---|
335 | 317 | } |
---|
336 | 318 | |
---|
337 | | -void skl_freeup_uuid_list(struct skl_sst *ctx) |
---|
| 319 | +void skl_freeup_uuid_list(struct skl_dev *skl) |
---|
338 | 320 | { |
---|
339 | 321 | struct uuid_module *uuid, *_uuid; |
---|
340 | 322 | |
---|
341 | | - list_for_each_entry_safe(uuid, _uuid, &ctx->uuid_list, list) { |
---|
| 323 | + list_for_each_entry_safe(uuid, _uuid, &skl->uuid_list, list) { |
---|
342 | 324 | list_del(&uuid->list); |
---|
343 | 325 | kfree(uuid); |
---|
344 | 326 | } |
---|
.. | .. |
---|
372 | 354 | } |
---|
373 | 355 | |
---|
374 | 356 | int skl_sst_ctx_init(struct device *dev, int irq, const char *fw_name, |
---|
375 | | - struct skl_dsp_loader_ops dsp_ops, struct skl_sst **dsp, |
---|
| 357 | + struct skl_dsp_loader_ops dsp_ops, struct skl_dev **dsp, |
---|
376 | 358 | struct sst_dsp_device *skl_dev) |
---|
377 | 359 | { |
---|
378 | | - struct skl_sst *skl; |
---|
| 360 | + struct skl_dev *skl = *dsp; |
---|
379 | 361 | struct sst_dsp *sst; |
---|
380 | | - |
---|
381 | | - skl = devm_kzalloc(dev, sizeof(*skl), GFP_KERNEL); |
---|
382 | | - if (skl == NULL) |
---|
383 | | - return -ENOMEM; |
---|
384 | 362 | |
---|
385 | 363 | skl->dev = dev; |
---|
386 | 364 | skl_dev->thread_context = skl; |
---|
.. | .. |
---|
398 | 376 | INIT_LIST_HEAD(&sst->module_list); |
---|
399 | 377 | |
---|
400 | 378 | skl->is_first_boot = true; |
---|
401 | | - if (dsp) |
---|
402 | | - *dsp = skl; |
---|
403 | 379 | |
---|
404 | 380 | return 0; |
---|
405 | 381 | } |
---|
406 | 382 | |
---|
407 | | -int skl_prepare_lib_load(struct skl_sst *skl, struct skl_lib_info *linfo, |
---|
| 383 | +int skl_prepare_lib_load(struct skl_dev *skl, struct skl_lib_info *linfo, |
---|
408 | 384 | struct firmware *stripped_fw, |
---|
409 | 385 | unsigned int hdr_offset, int index) |
---|
410 | 386 | { |
---|