2 * skl-sst-utils.c - SKL sst utils functions
4 * Copyright (C) 2016 Intel Corp
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.
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.
16 #include <linux/device.h>
17 #include <linux/slab.h>
18 #include <linux/uuid.h>
19 #include "skl-sst-dsp.h"
20 #include "../common/sst-dsp.h"
21 #include "../common/sst-dsp-priv.h"
22 #include "skl-sst-ipc.h"
25 #define UUID_STR_SIZE 37
26 #define DEFAULT_HASH_SHA256_LEN 32
28 /* FW Extended Manifest Header id = $AE1 */
29 #define SKL_EXT_MANIFEST_HEADER_MAGIC 0x31454124
31 struct skl_dfw_module_mod
{
33 struct skl_dfw_module skl_dfw_mod
;
57 union seg_flags flags
;
70 struct adsp_module_entry
{
74 struct module_type type
;
75 u8 hash1
[DEFAULT_HASH_SHA256_LEN
];
80 u16 instance_max_count
;
81 u16 instance_bss_size
;
82 struct segment_desc segments
[3];
89 u32 preload_page_count
;
107 struct list_head list
;
110 struct skl_ext_manifest_hdr
{
118 int snd_skl_get_module_info(struct skl_sst
*ctx
, u8
*uuid
,
119 struct skl_dfw_module
*dfw_config
)
121 struct uuid_module
*module
;
124 uuid_mod
= (uuid_le
*)uuid
;
126 if (list_empty(&ctx
->uuid_list
)) {
127 dev_err(ctx
->dev
, "Module list is empty\n");
131 list_for_each_entry(module
, &ctx
->uuid_list
, list
) {
132 if (uuid_le_cmp(*uuid_mod
, module
->uuid
) == 0) {
133 dfw_config
->module_id
= module
->id
;
134 dfw_config
->is_loadable
= module
->is_loadable
;
142 EXPORT_SYMBOL_GPL(snd_skl_get_module_info
);
145 * Parse the firmware binary to get the UUID, module id
148 int snd_skl_parse_uuids(struct sst_dsp
*ctx
, unsigned int offset
)
150 struct adsp_fw_hdr
*adsp_hdr
;
151 struct adsp_module_entry
*mod_entry
;
155 struct skl_sst
*skl
= ctx
->thread_context
;
156 struct uuid_module
*module
;
157 struct firmware stripped_fw
;
158 unsigned int safe_file
;
160 /* Get the FW pointer to derive ADSP header */
161 stripped_fw
.data
= ctx
->fw
->data
;
162 stripped_fw
.size
= ctx
->fw
->size
;
164 skl_dsp_strip_extended_manifest(&stripped_fw
);
166 buf
= stripped_fw
.data
;
168 /* check if we have enough space in file to move to header */
169 safe_file
= sizeof(*adsp_hdr
) + offset
;
170 if (stripped_fw
.size
<= safe_file
) {
171 dev_err(ctx
->dev
, "Small fw file size, No space for hdr\n");
175 adsp_hdr
= (struct adsp_fw_hdr
*)(buf
+ offset
);
177 /* check 1st module entry is in file */
178 safe_file
+= adsp_hdr
->len
+ sizeof(*mod_entry
);
179 if (stripped_fw
.size
<= safe_file
) {
180 dev_err(ctx
->dev
, "Small fw file size, No module entry\n");
184 mod_entry
= (struct adsp_module_entry
*)
185 (buf
+ offset
+ adsp_hdr
->len
);
187 num_entry
= adsp_hdr
->num_modules
;
189 /* check all entries are in file */
190 safe_file
+= num_entry
* sizeof(*mod_entry
);
191 if (stripped_fw
.size
<= safe_file
) {
192 dev_err(ctx
->dev
, "Small fw file size, No modules\n");
198 * Read the UUID(GUID) from FW Manifest.
200 * The 16 byte UUID format is: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX
201 * Populate the UUID table to store module_id and loadable flags
205 for (i
= 0; i
< num_entry
; i
++, mod_entry
++) {
206 module
= kzalloc(sizeof(*module
), GFP_KERNEL
);
210 uuid_bin
= (uuid_le
*)mod_entry
->uuid
.id
;
211 memcpy(&module
->uuid
, uuid_bin
, sizeof(module
->uuid
));
214 module
->is_loadable
= mod_entry
->type
.load_type
;
216 list_add_tail(&module
->list
, &skl
->uuid_list
);
219 "Adding uuid :%pUL mod id: %d Loadable: %d\n",
220 &module
->uuid
, module
->id
, module
->is_loadable
);
226 void skl_freeup_uuid_list(struct skl_sst
*ctx
)
228 struct uuid_module
*uuid
, *_uuid
;
230 list_for_each_entry_safe(uuid
, _uuid
, &ctx
->uuid_list
, list
) {
231 list_del(&uuid
->list
);
237 * some firmware binary contains some extended manifest. This needs
238 * to be stripped in that case before we load and use that image.
240 * Get the module id for the module by checking
241 * the table for the UUID for the module
243 int skl_dsp_strip_extended_manifest(struct firmware
*fw
)
245 struct skl_ext_manifest_hdr
*hdr
;
247 /* check if fw file is greater than header we are looking */
248 if (fw
->size
< sizeof(hdr
)) {
249 pr_err("%s: Firmware file small, no hdr\n", __func__
);
253 hdr
= (struct skl_ext_manifest_hdr
*)fw
->data
;
255 if (hdr
->id
== SKL_EXT_MANIFEST_HEADER_MAGIC
) {
256 fw
->size
-= hdr
->len
;
257 fw
->data
+= hdr
->len
;