forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 1f93a7dfd1f8d5ff7a5c53246c7534fe2332d6f4
kernel/sound/soc/intel/skylake/skl-sst-utils.c
....@@ -1,36 +1,21 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * skl-sst-utils.c - SKL sst utils functions
34 *
45 * 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.
146 */
157
168 #include <linux/device.h>
179 #include <linux/slab.h>
1810 #include <linux/uuid.h>
19
-#include "skl-sst-dsp.h"
2011 #include "../common/sst-dsp.h"
2112 #include "../common/sst-dsp-priv.h"
22
-#include "skl-sst-ipc.h"
13
+#include "skl.h"
2314
24
-
25
-#define UUID_STR_SIZE 37
2615 #define DEFAULT_HASH_SHA256_LEN 32
2716
2817 /* FW Extended Manifest Header id = $AE1 */
2918 #define SKL_EXT_MANIFEST_HEADER_MAGIC 0x31454124
30
-
31
-struct UUID {
32
- u8 id[16];
33
-};
3419
3520 union seg_flags {
3621 u32 ul;
....@@ -65,7 +50,7 @@
6550 struct adsp_module_entry {
6651 u32 struct_id;
6752 u8 name[8];
68
- struct UUID uuid;
53
+ u8 uuid[16];
6954 struct module_type type;
7055 u8 hash1[DEFAULT_HASH_SHA256_LEN];
7156 u32 entry_point;
....@@ -113,12 +98,12 @@
11398 return -EINVAL;
11499 }
115100
116
-int skl_get_pvt_instance_id_map(struct skl_sst *ctx,
101
+int skl_get_pvt_instance_id_map(struct skl_dev *skl,
117102 int module_id, int instance_id)
118103 {
119104 struct uuid_module *module;
120105
121
- list_for_each_entry(module, &ctx->uuid_list, list) {
106
+ list_for_each_entry(module, &skl->uuid_list, list) {
122107 if (module->id == module_id)
123108 return skl_get_pvtid_map(module, instance_id);
124109 }
....@@ -177,20 +162,20 @@
177162 /**
178163 * skl_get_pvt_id: generate a private id for use as module id
179164 *
180
- * @ctx: driver context
165
+ * @skl: driver context
181166 * @uuid_mod: module's uuid
182167 * @instance_id: module's instance id
183168 *
184169 * This generates a 128 bit private unique id for a module TYPE so that
185170 * module instance is unique
186171 */
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)
188173 {
189174 struct uuid_module *module;
190175 int pvt_id;
191176
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)) {
194179
195180 pvt_id = skl_pvtid_128(module);
196181 if (pvt_id >= 0) {
....@@ -208,19 +193,19 @@
208193 /**
209194 * skl_put_pvt_id: free up the private id allocated
210195 *
211
- * @ctx: driver context
196
+ * @skl: driver context
212197 * @uuid_mod: module's uuid
213198 * @pvt_id: module pvt id
214199 *
215200 * This frees a 128 bit private unique id previously generated
216201 */
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)
218203 {
219204 int i;
220205 struct uuid_module *module;
221206
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)) {
224209
225210 if (*pvt_id != 0)
226211 i = (*pvt_id) / 64;
....@@ -247,13 +232,12 @@
247232 struct adsp_fw_hdr *adsp_hdr;
248233 struct adsp_module_entry *mod_entry;
249234 int i, num_entry, size;
250
- uuid_le *uuid_bin;
251235 const char *buf;
252
- struct skl_sst *skl = ctx->thread_context;
236
+ struct skl_dev *skl = ctx->thread_context;
253237 struct uuid_module *module;
254238 struct firmware stripped_fw;
255239 unsigned int safe_file;
256
- int ret = 0;
240
+ int ret;
257241
258242 /* Get the FW pointer to derive ADSP header */
259243 stripped_fw.data = fw->data;
....@@ -279,8 +263,7 @@
279263 return -EINVAL;
280264 }
281265
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);
284267
285268 num_entry = adsp_hdr->num_modules;
286269
....@@ -307,8 +290,7 @@
307290 goto free_uuid_list;
308291 }
309292
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);
312294
313295 module->id = (i | (index << 12));
314296 module->is_loadable = mod_entry->type.load_type;
....@@ -334,11 +316,11 @@
334316 return ret;
335317 }
336318
337
-void skl_freeup_uuid_list(struct skl_sst *ctx)
319
+void skl_freeup_uuid_list(struct skl_dev *skl)
338320 {
339321 struct uuid_module *uuid, *_uuid;
340322
341
- list_for_each_entry_safe(uuid, _uuid, &ctx->uuid_list, list) {
323
+ list_for_each_entry_safe(uuid, _uuid, &skl->uuid_list, list) {
342324 list_del(&uuid->list);
343325 kfree(uuid);
344326 }
....@@ -372,15 +354,11 @@
372354 }
373355
374356 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,
376358 struct sst_dsp_device *skl_dev)
377359 {
378
- struct skl_sst *skl;
360
+ struct skl_dev *skl = *dsp;
379361 struct sst_dsp *sst;
380
-
381
- skl = devm_kzalloc(dev, sizeof(*skl), GFP_KERNEL);
382
- if (skl == NULL)
383
- return -ENOMEM;
384362
385363 skl->dev = dev;
386364 skl_dev->thread_context = skl;
....@@ -398,13 +376,11 @@
398376 INIT_LIST_HEAD(&sst->module_list);
399377
400378 skl->is_first_boot = true;
401
- if (dsp)
402
- *dsp = skl;
403379
404380 return 0;
405381 }
406382
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,
408384 struct firmware *stripped_fw,
409385 unsigned int hdr_offset, int index)
410386 {