~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/sound/soc/sof/ipc3-loader.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /sound/soc/sof/ipc3-loader.c (Version linux-6.12-rc7) and /sound/soc/sof/ipc3-loader.c (Version linux-5.19.17)


  1 // SPDX-License-Identifier: (GPL-2.0-only OR B      1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
  2 //                                                  2 //
  3 // This file is provided under a dual BSD/GPLv      3 // This file is provided under a dual BSD/GPLv2 license.  When using or
  4 // redistributing this file, you may do so und      4 // redistributing this file, you may do so under either license.
  5 //                                                  5 //
  6 // Copyright(c) 2022 Intel Corporation         !!   6 // Copyright(c) 2022 Intel Corporation. All rights reserved.
  7                                                     7 
  8 #include <linux/firmware.h>                         8 #include <linux/firmware.h>
  9 #include "sof-priv.h"                               9 #include "sof-priv.h"
 10 #include "sof-audio.h"                             10 #include "sof-audio.h"
 11 #include "ipc3-priv.h"                             11 #include "ipc3-priv.h"
 12 #include "ops.h"                                   12 #include "ops.h"
 13                                                    13 
 14 static int ipc3_fw_ext_man_get_version(struct      14 static int ipc3_fw_ext_man_get_version(struct snd_sof_dev *sdev,
 15                                        const s     15                                        const struct sof_ext_man_elem_header *hdr)
 16 {                                                  16 {
 17         const struct sof_ext_man_fw_version *v     17         const struct sof_ext_man_fw_version *v =
 18                 container_of(hdr, struct sof_e     18                 container_of(hdr, struct sof_ext_man_fw_version, hdr);
 19                                                    19 
 20         memcpy(&sdev->fw_ready.version, &v->ve     20         memcpy(&sdev->fw_ready.version, &v->version, sizeof(v->version));
 21         sdev->fw_ready.flags = v->flags;           21         sdev->fw_ready.flags = v->flags;
 22                                                    22 
 23         /* log ABI versions and check FW compa     23         /* log ABI versions and check FW compatibility */
 24         return sof_ipc3_validate_fw_version(sd     24         return sof_ipc3_validate_fw_version(sdev);
 25 }                                                  25 }
 26                                                    26 
 27 static int ipc3_fw_ext_man_get_windows(struct      27 static int ipc3_fw_ext_man_get_windows(struct snd_sof_dev *sdev,
 28                                        const s     28                                        const struct sof_ext_man_elem_header *hdr)
 29 {                                                  29 {
 30         const struct sof_ext_man_window *w;        30         const struct sof_ext_man_window *w;
 31                                                    31 
 32         w = container_of(hdr, struct sof_ext_m     32         w = container_of(hdr, struct sof_ext_man_window, hdr);
 33                                                    33 
 34         return sof_ipc3_get_ext_windows(sdev,      34         return sof_ipc3_get_ext_windows(sdev, &w->ipc_window.ext_hdr);
 35 }                                                  35 }
 36                                                    36 
 37 static int ipc3_fw_ext_man_get_cc_info(struct      37 static int ipc3_fw_ext_man_get_cc_info(struct snd_sof_dev *sdev,
 38                                        const s     38                                        const struct sof_ext_man_elem_header *hdr)
 39 {                                                  39 {
 40         const struct sof_ext_man_cc_version *c     40         const struct sof_ext_man_cc_version *cc;
 41                                                    41 
 42         cc = container_of(hdr, struct sof_ext_     42         cc = container_of(hdr, struct sof_ext_man_cc_version, hdr);
 43                                                    43 
 44         return sof_ipc3_get_cc_info(sdev, &cc-     44         return sof_ipc3_get_cc_info(sdev, &cc->cc_version.ext_hdr);
 45 }                                                  45 }
 46                                                    46 
 47 static int ipc3_fw_ext_man_get_dbg_abi_info(st     47 static int ipc3_fw_ext_man_get_dbg_abi_info(struct snd_sof_dev *sdev,
 48                                             co     48                                             const struct sof_ext_man_elem_header *hdr)
 49 {                                                  49 {
 50         const struct ext_man_dbg_abi *dbg_abi      50         const struct ext_man_dbg_abi *dbg_abi =
 51                 container_of(hdr, struct ext_m     51                 container_of(hdr, struct ext_man_dbg_abi, hdr);
 52                                                    52 
 53         if (sdev->first_boot)                      53         if (sdev->first_boot)
 54                 dev_dbg(sdev->dev,                 54                 dev_dbg(sdev->dev,
 55                         "Firmware: DBG_ABI %d:     55                         "Firmware: DBG_ABI %d:%d:%d\n",
 56                         SOF_ABI_VERSION_MAJOR(     56                         SOF_ABI_VERSION_MAJOR(dbg_abi->dbg_abi.abi_dbg_version),
 57                         SOF_ABI_VERSION_MINOR(     57                         SOF_ABI_VERSION_MINOR(dbg_abi->dbg_abi.abi_dbg_version),
 58                         SOF_ABI_VERSION_PATCH(     58                         SOF_ABI_VERSION_PATCH(dbg_abi->dbg_abi.abi_dbg_version));
 59                                                    59 
 60         return 0;                                  60         return 0;
 61 }                                                  61 }
 62                                                    62 
 63 static int ipc3_fw_ext_man_get_config_data(str     63 static int ipc3_fw_ext_man_get_config_data(struct snd_sof_dev *sdev,
 64                                            con     64                                            const struct sof_ext_man_elem_header *hdr)
 65 {                                                  65 {
 66         const struct sof_ext_man_config_data *     66         const struct sof_ext_man_config_data *config =
 67                 container_of(hdr, struct sof_e     67                 container_of(hdr, struct sof_ext_man_config_data, hdr);
 68         const struct sof_config_elem *elem;        68         const struct sof_config_elem *elem;
 69         int elems_counter;                         69         int elems_counter;
 70         int elems_size;                            70         int elems_size;
 71         int ret = 0;                               71         int ret = 0;
 72         int i;                                     72         int i;
 73                                                    73 
 74         /* calculate elements counter */           74         /* calculate elements counter */
 75         elems_size = config->hdr.size - sizeof     75         elems_size = config->hdr.size - sizeof(struct sof_ext_man_elem_header);
 76         elems_counter = elems_size / sizeof(st     76         elems_counter = elems_size / sizeof(struct sof_config_elem);
 77                                                    77 
 78         dev_dbg(sdev->dev, "manifest can hold  !!  78         dev_dbg(sdev->dev, "%s can hold up to %d config elements\n",
                                                   >>  79                 __func__, elems_counter);
 79                                                    80 
 80         for (i = 0; i < elems_counter; ++i) {      81         for (i = 0; i < elems_counter; ++i) {
 81                 elem = &config->elems[i];          82                 elem = &config->elems[i];
 82                 dev_dbg(sdev->dev, "get index  !!  83                 dev_dbg(sdev->dev, "%s get index %d token %d val %d\n",
 83                         i, elem->token, elem-> !!  84                         __func__, i, elem->token, elem->value);
 84                 switch (elem->token) {             85                 switch (elem->token) {
 85                 case SOF_EXT_MAN_CONFIG_EMPTY:     86                 case SOF_EXT_MAN_CONFIG_EMPTY:
 86                         /* unused memory space     87                         /* unused memory space is zero filled - mapped to EMPTY elements */
 87                         break;                     88                         break;
 88                 case SOF_EXT_MAN_CONFIG_IPC_MS     89                 case SOF_EXT_MAN_CONFIG_IPC_MSG_SIZE:
 89                         /* TODO: use ipc msg s     90                         /* TODO: use ipc msg size from config data */
 90                         break;                     91                         break;
 91                 case SOF_EXT_MAN_CONFIG_MEMORY     92                 case SOF_EXT_MAN_CONFIG_MEMORY_USAGE_SCAN:
 92                         if (sdev->first_boot &     93                         if (sdev->first_boot && elem->value)
 93                                 ret = snd_sof_     94                                 ret = snd_sof_dbg_memory_info_init(sdev);
 94                         break;                     95                         break;
 95                 default:                           96                 default:
 96                         dev_info(sdev->dev,        97                         dev_info(sdev->dev,
 97                                  "Unknown firm     98                                  "Unknown firmware configuration token %d value %d",
 98                                  elem->token,      99                                  elem->token, elem->value);
 99                         break;                    100                         break;
100                 }                                 101                 }
101                 if (ret < 0) {                    102                 if (ret < 0) {
102                         dev_err(sdev->dev,        103                         dev_err(sdev->dev,
103                                 "%s: processin    104                                 "%s: processing failed for token %d value %#x, %d\n",
104                                 __func__, elem    105                                 __func__, elem->token, elem->value, ret);
105                         return ret;               106                         return ret;
106                 }                                 107                 }
107         }                                         108         }
108                                                   109 
109         return 0;                                 110         return 0;
110 }                                                 111 }
111                                                   112 
112 static ssize_t ipc3_fw_ext_man_size(struct snd !! 113 static ssize_t ipc3_fw_ext_man_size(const struct firmware *fw)
113 {                                                 114 {
114         const struct sof_ext_man_header *head;    115         const struct sof_ext_man_header *head;
115                                                   116 
116         head = (struct sof_ext_man_header *)fw    117         head = (struct sof_ext_man_header *)fw->data;
117                                                   118 
118         /*                                        119         /*
119          * assert fw size is big enough to con    120          * assert fw size is big enough to contain extended manifest header,
120          * it prevents from reading unallocate    121          * it prevents from reading unallocated memory from `head` in following
121          * step.                                  122          * step.
122          */                                       123          */
123         if (fw->size < sizeof(*head))             124         if (fw->size < sizeof(*head))
124                 return -EINVAL;                   125                 return -EINVAL;
125                                                   126 
126         /*                                        127         /*
127          * When fw points to extended manifest    128          * When fw points to extended manifest,
128          * then first u32 must be equal SOF_EX    129          * then first u32 must be equal SOF_EXT_MAN_MAGIC_NUMBER.
129          */                                       130          */
130         if (head->magic == SOF_EXT_MAN_MAGIC_N    131         if (head->magic == SOF_EXT_MAN_MAGIC_NUMBER)
131                 return head->full_size;           132                 return head->full_size;
132                                                   133 
133         /* otherwise given fw don't have an ex    134         /* otherwise given fw don't have an extended manifest */
134         dev_dbg(sdev->dev, "Unexpected extende << 
135                 head->magic);                  << 
136         return 0;                                 135         return 0;
137 }                                                 136 }
138                                                   137 
139 static size_t sof_ipc3_fw_parse_ext_man(struct    138 static size_t sof_ipc3_fw_parse_ext_man(struct snd_sof_dev *sdev)
140 {                                                 139 {
141         const struct firmware *fw = sdev->base !! 140         struct snd_sof_pdata *plat_data = sdev->pdata;
                                                   >> 141         const struct firmware *fw = plat_data->fw;
142         const struct sof_ext_man_elem_header *    142         const struct sof_ext_man_elem_header *elem_hdr;
143         const struct sof_ext_man_header *head;    143         const struct sof_ext_man_header *head;
144         ssize_t ext_man_size;                     144         ssize_t ext_man_size;
145         ssize_t remaining;                        145         ssize_t remaining;
146         uintptr_t iptr;                           146         uintptr_t iptr;
147         int ret = 0;                              147         int ret = 0;
148                                                   148 
149         head = (struct sof_ext_man_header *)fw    149         head = (struct sof_ext_man_header *)fw->data;
150         remaining = head->full_size - head->he    150         remaining = head->full_size - head->header_size;
151         if (remaining < 0 || remaining > sdev- !! 151         ext_man_size = ipc3_fw_ext_man_size(fw);
152                 return -EINVAL;                << 
153         ext_man_size = ipc3_fw_ext_man_size(sd << 
154                                                   152 
155         /* Assert firmware starts with extende    153         /* Assert firmware starts with extended manifest */
156         if (ext_man_size <= 0)                    154         if (ext_man_size <= 0)
157                 return ext_man_size;              155                 return ext_man_size;
158                                                   156 
159         /* incompatible version */                157         /* incompatible version */
160         if (SOF_EXT_MAN_VERSION_INCOMPATIBLE(S    158         if (SOF_EXT_MAN_VERSION_INCOMPATIBLE(SOF_EXT_MAN_VERSION,
161                                              h    159                                              head->header_version)) {
162                 dev_err(sdev->dev,                160                 dev_err(sdev->dev,
163                         "extended manifest ver    161                         "extended manifest version %#x differ from used %#x\n",
164                         head->header_version,     162                         head->header_version, SOF_EXT_MAN_VERSION);
165                 return -EINVAL;                   163                 return -EINVAL;
166         }                                         164         }
167                                                   165 
168         /* get first extended manifest element    166         /* get first extended manifest element header */
169         iptr = (uintptr_t)fw->data + head->hea    167         iptr = (uintptr_t)fw->data + head->header_size;
170                                                   168 
171         while (remaining > sizeof(*elem_hdr))     169         while (remaining > sizeof(*elem_hdr)) {
172                 elem_hdr = (struct sof_ext_man    170                 elem_hdr = (struct sof_ext_man_elem_header *)iptr;
173                                                   171 
174                 dev_dbg(sdev->dev, "found sof_    172                 dev_dbg(sdev->dev, "found sof_ext_man header type %d size %#x\n",
175                         elem_hdr->type, elem_h    173                         elem_hdr->type, elem_hdr->size);
176                                                   174 
177                 if (elem_hdr->size < sizeof(*e    175                 if (elem_hdr->size < sizeof(*elem_hdr) ||
178                     elem_hdr->size > remaining    176                     elem_hdr->size > remaining) {
179                         dev_err(sdev->dev,        177                         dev_err(sdev->dev,
180                                 "invalid sof_e    178                                 "invalid sof_ext_man header size, type %d size %#x\n",
181                                 elem_hdr->type    179                                 elem_hdr->type, elem_hdr->size);
182                         return -EINVAL;           180                         return -EINVAL;
183                 }                                 181                 }
184                                                   182 
185                 /* process structure data */      183                 /* process structure data */
186                 switch (elem_hdr->type) {         184                 switch (elem_hdr->type) {
187                 case SOF_EXT_MAN_ELEM_FW_VERSI    185                 case SOF_EXT_MAN_ELEM_FW_VERSION:
188                         ret = ipc3_fw_ext_man_    186                         ret = ipc3_fw_ext_man_get_version(sdev, elem_hdr);
189                         break;                    187                         break;
190                 case SOF_EXT_MAN_ELEM_WINDOW:     188                 case SOF_EXT_MAN_ELEM_WINDOW:
191                         ret = ipc3_fw_ext_man_    189                         ret = ipc3_fw_ext_man_get_windows(sdev, elem_hdr);
192                         break;                    190                         break;
193                 case SOF_EXT_MAN_ELEM_CC_VERSI    191                 case SOF_EXT_MAN_ELEM_CC_VERSION:
194                         ret = ipc3_fw_ext_man_    192                         ret = ipc3_fw_ext_man_get_cc_info(sdev, elem_hdr);
195                         break;                    193                         break;
196                 case SOF_EXT_MAN_ELEM_DBG_ABI:    194                 case SOF_EXT_MAN_ELEM_DBG_ABI:
197                         ret = ipc3_fw_ext_man_    195                         ret = ipc3_fw_ext_man_get_dbg_abi_info(sdev, elem_hdr);
198                         break;                    196                         break;
199                 case SOF_EXT_MAN_ELEM_CONFIG_D    197                 case SOF_EXT_MAN_ELEM_CONFIG_DATA:
200                         ret = ipc3_fw_ext_man_    198                         ret = ipc3_fw_ext_man_get_config_data(sdev, elem_hdr);
201                         break;                    199                         break;
202                 case SOF_EXT_MAN_ELEM_PLATFORM    200                 case SOF_EXT_MAN_ELEM_PLATFORM_CONFIG_DATA:
203                         ret = snd_sof_dsp_pars    201                         ret = snd_sof_dsp_parse_platform_ext_manifest(sdev, elem_hdr);
204                         break;                    202                         break;
205                 default:                          203                 default:
206                         dev_info(sdev->dev,       204                         dev_info(sdev->dev,
207                                  "unknown sof_    205                                  "unknown sof_ext_man header type %d size %#x\n",
208                                  elem_hdr->typ    206                                  elem_hdr->type, elem_hdr->size);
209                         break;                    207                         break;
210                 }                                 208                 }
211                                                   209 
212                 if (ret < 0) {                    210                 if (ret < 0) {
213                         dev_err(sdev->dev,        211                         dev_err(sdev->dev,
214                                 "failed to par    212                                 "failed to parse sof_ext_man header type %d size %#x\n",
215                                 elem_hdr->type    213                                 elem_hdr->type, elem_hdr->size);
216                         return ret;               214                         return ret;
217                 }                                 215                 }
218                                                   216 
219                 remaining -= elem_hdr->size;      217                 remaining -= elem_hdr->size;
220                 iptr += elem_hdr->size;           218                 iptr += elem_hdr->size;
221         }                                         219         }
222                                                   220 
223         if (remaining) {                          221         if (remaining) {
224                 dev_err(sdev->dev, "error: sof    222                 dev_err(sdev->dev, "error: sof_ext_man header is inconsistent\n");
225                 return -EINVAL;                   223                 return -EINVAL;
226         }                                         224         }
227                                                   225 
228         return ext_man_size;                      226         return ext_man_size;
229 }                                                 227 }
230                                                   228 
231 /* generic module parser for mmaped DSPs */       229 /* generic module parser for mmaped DSPs */
232 static int sof_ipc3_parse_module_memcpy(struct    230 static int sof_ipc3_parse_module_memcpy(struct snd_sof_dev *sdev,
233                                         struct    231                                         struct snd_sof_mod_hdr *module)
234 {                                                 232 {
235         struct snd_sof_blk_hdr *block;            233         struct snd_sof_blk_hdr *block;
236         int count, ret;                           234         int count, ret;
237         u32 offset;                               235         u32 offset;
238         size_t remaining;                         236         size_t remaining;
239                                                   237 
240         dev_dbg(sdev->dev, "new module size %#    238         dev_dbg(sdev->dev, "new module size %#x blocks %#x type %#x\n",
241                 module->size, module->num_bloc    239                 module->size, module->num_blocks, module->type);
242                                                   240 
243         block = (struct snd_sof_blk_hdr *)((u8    241         block = (struct snd_sof_blk_hdr *)((u8 *)module + sizeof(*module));
244                                                   242 
245         /* module->size doesn't include header    243         /* module->size doesn't include header size */
246         remaining = module->size;                 244         remaining = module->size;
247         for (count = 0; count < module->num_bl    245         for (count = 0; count < module->num_blocks; count++) {
248                 /* check for wrap */              246                 /* check for wrap */
249                 if (remaining < sizeof(*block)    247                 if (remaining < sizeof(*block)) {
250                         dev_err(sdev->dev, "no    248                         dev_err(sdev->dev, "not enough data remaining\n");
251                         return -EINVAL;           249                         return -EINVAL;
252                 }                                 250                 }
253                                                   251 
254                 /* minus header size of block     252                 /* minus header size of block */
255                 remaining -= sizeof(*block);      253                 remaining -= sizeof(*block);
256                                                   254 
257                 if (block->size == 0) {           255                 if (block->size == 0) {
258                         dev_warn(sdev->dev,       256                         dev_warn(sdev->dev,
259                                  "warning: blo    257                                  "warning: block %d size zero\n", count);
260                         dev_warn(sdev->dev, "     258                         dev_warn(sdev->dev, " type %#x offset %#x\n",
261                                  block->type,     259                                  block->type, block->offset);
262                         continue;                 260                         continue;
263                 }                                 261                 }
264                                                   262 
265                 switch (block->type) {            263                 switch (block->type) {
266                 case SOF_FW_BLK_TYPE_RSRVD0:      264                 case SOF_FW_BLK_TYPE_RSRVD0:
267                 case SOF_FW_BLK_TYPE_ROM...SOF    265                 case SOF_FW_BLK_TYPE_ROM...SOF_FW_BLK_TYPE_RSRVD14:
268                         continue;       /* not    266                         continue;       /* not handled atm */
269                 case SOF_FW_BLK_TYPE_IRAM:        267                 case SOF_FW_BLK_TYPE_IRAM:
270                 case SOF_FW_BLK_TYPE_DRAM:        268                 case SOF_FW_BLK_TYPE_DRAM:
271                 case SOF_FW_BLK_TYPE_SRAM:        269                 case SOF_FW_BLK_TYPE_SRAM:
272                         offset = block->offset    270                         offset = block->offset;
273                         break;                    271                         break;
274                 default:                          272                 default:
275                         dev_err(sdev->dev, "%s    273                         dev_err(sdev->dev, "%s: bad type %#x for block %#x\n",
276                                 __func__, bloc    274                                 __func__, block->type, count);
277                         return -EINVAL;           275                         return -EINVAL;
278                 }                                 276                 }
279                                                   277 
280                 dev_dbg(sdev->dev, "block %d t    278                 dev_dbg(sdev->dev, "block %d type %#x size %#x ==>  offset %#x\n",
281                         count, block->type, bl    279                         count, block->type, block->size, offset);
282                                                   280 
283                 /* checking block->size to avo    281                 /* checking block->size to avoid unaligned access */
284                 if (block->size % sizeof(u32))    282                 if (block->size % sizeof(u32)) {
285                         dev_err(sdev->dev, "%s    283                         dev_err(sdev->dev, "%s: invalid block size %#x\n",
286                                 __func__, bloc    284                                 __func__, block->size);
287                         return -EINVAL;           285                         return -EINVAL;
288                 }                                 286                 }
289                 ret = snd_sof_dsp_block_write(    287                 ret = snd_sof_dsp_block_write(sdev, block->type, offset,
290                                                   288                                               block + 1, block->size);
291                 if (ret < 0) {                    289                 if (ret < 0) {
292                         dev_err(sdev->dev, "%s    290                         dev_err(sdev->dev, "%s: write to block type %#x failed\n",
293                                 __func__, bloc    291                                 __func__, block->type);
294                         return ret;               292                         return ret;
295                 }                                 293                 }
296                                                   294 
297                 if (remaining < block->size) {    295                 if (remaining < block->size) {
298                         dev_err(sdev->dev, "%s    296                         dev_err(sdev->dev, "%s: not enough data remaining\n", __func__);
299                         return -EINVAL;           297                         return -EINVAL;
300                 }                                 298                 }
301                                                   299 
302                 /* minus body size of block */    300                 /* minus body size of block */
303                 remaining -= block->size;         301                 remaining -= block->size;
304                 /* next block */                  302                 /* next block */
305                 block = (struct snd_sof_blk_hd    303                 block = (struct snd_sof_blk_hdr *)((u8 *)block + sizeof(*block)
306                         + block->size);           304                         + block->size);
307         }                                         305         }
308                                                   306 
309         return 0;                                 307         return 0;
310 }                                                 308 }
311                                                   309 
312 static int sof_ipc3_load_fw_to_dsp(struct snd_    310 static int sof_ipc3_load_fw_to_dsp(struct snd_sof_dev *sdev)
313 {                                                 311 {
314         u32 payload_offset = sdev->basefw.payl !! 312         struct snd_sof_pdata *plat_data = sdev->pdata;
315         const struct firmware *fw = sdev->base !! 313         const struct firmware *fw = plat_data->fw;
316         struct snd_sof_fw_header *header;         314         struct snd_sof_fw_header *header;
317         struct snd_sof_mod_hdr *module;           315         struct snd_sof_mod_hdr *module;
318         int (*load_module)(struct snd_sof_dev     316         int (*load_module)(struct snd_sof_dev *sof_dev, struct snd_sof_mod_hdr *hdr);
319         size_t remaining;                         317         size_t remaining;
320         int ret, count;                           318         int ret, count;
321                                                   319 
322         if (!fw)                               !! 320         if (!plat_data->fw)
323                 return -EINVAL;                   321                 return -EINVAL;
324                                                   322 
325         header = (struct snd_sof_fw_header *)( !! 323         header = (struct snd_sof_fw_header *)(fw->data + plat_data->fw_offset);
326         load_module = sof_ops(sdev)->load_modu    324         load_module = sof_ops(sdev)->load_module;
327         if (!load_module) {                       325         if (!load_module) {
328                 dev_dbg(sdev->dev, "Using gene !! 326                 dev_dbg(sdev->dev, "%s: Using generic module loading\n", __func__);
329                 load_module = sof_ipc3_parse_m    327                 load_module = sof_ipc3_parse_module_memcpy;
330         } else {                                  328         } else {
331                 dev_dbg(sdev->dev, "Using cust !! 329                 dev_dbg(sdev->dev, "%s: Using custom module loading\n", __func__);
332         }                                         330         }
333                                                   331 
334         /* parse each module */                   332         /* parse each module */
335         module = (struct snd_sof_mod_hdr *)(fw !! 333         module = (struct snd_sof_mod_hdr *)(fw->data + plat_data->fw_offset +
336         remaining = fw->size - sizeof(*header) !! 334                                             sizeof(*header));
                                                   >> 335         remaining = fw->size - sizeof(*header) - plat_data->fw_offset;
337         /* check for wrap */                      336         /* check for wrap */
338         if (remaining > fw->size) {               337         if (remaining > fw->size) {
339                 dev_err(sdev->dev, "%s: fw siz    338                 dev_err(sdev->dev, "%s: fw size smaller than header size\n", __func__);
340                 return -EINVAL;                   339                 return -EINVAL;
341         }                                         340         }
342                                                   341 
343         for (count = 0; count < header->num_mo    342         for (count = 0; count < header->num_modules; count++) {
344                 /* check for wrap */              343                 /* check for wrap */
345                 if (remaining < sizeof(*module    344                 if (remaining < sizeof(*module)) {
346                         dev_err(sdev->dev, "%s    345                         dev_err(sdev->dev, "%s: not enough data for a module\n",
347                                 __func__);        346                                 __func__);
348                         return -EINVAL;           347                         return -EINVAL;
349                 }                                 348                 }
350                                                   349 
351                 /* minus header size of module    350                 /* minus header size of module */
352                 remaining -= sizeof(*module);     351                 remaining -= sizeof(*module);
353                                                   352 
354                 /* module */                      353                 /* module */
355                 ret = load_module(sdev, module    354                 ret = load_module(sdev, module);
356                 if (ret < 0) {                    355                 if (ret < 0) {
357                         dev_err(sdev->dev, "%s    356                         dev_err(sdev->dev, "%s: invalid module %d\n", __func__, count);
358                         return ret;               357                         return ret;
359                 }                                 358                 }
360                                                   359 
361                 if (remaining < module->size)     360                 if (remaining < module->size) {
362                         dev_err(sdev->dev, "%s    361                         dev_err(sdev->dev, "%s: not enough data remaining\n", __func__);
363                         return -EINVAL;           362                         return -EINVAL;
364                 }                                 363                 }
365                                                   364 
366                 /* minus body size of module *    365                 /* minus body size of module */
367                 remaining -=  module->size;       366                 remaining -=  module->size;
368                 module = (struct snd_sof_mod_h    367                 module = (struct snd_sof_mod_hdr *)((u8 *)module +
369                          sizeof(*module) + mod    368                          sizeof(*module) + module->size);
370         }                                         369         }
371                                                   370 
372         return 0;                                 371         return 0;
373 }                                                 372 }
374                                                   373 
375 static int sof_ipc3_validate_firmware(struct s    374 static int sof_ipc3_validate_firmware(struct snd_sof_dev *sdev)
376 {                                                 375 {
377         u32 payload_offset = sdev->basefw.payl !! 376         struct snd_sof_pdata *plat_data = sdev->pdata;
378         const struct firmware *fw = sdev->base !! 377         const struct firmware *fw = plat_data->fw;
379         struct snd_sof_fw_header *header;         378         struct snd_sof_fw_header *header;
380         size_t fw_size = fw->size - payload_of !! 379         size_t fw_size = fw->size - plat_data->fw_offset;
381                                                   380 
382         if (fw->size <= payload_offset) {      !! 381         if (fw->size <= plat_data->fw_offset) {
383                 dev_err(sdev->dev,                382                 dev_err(sdev->dev,
384                         "firmware size must be    383                         "firmware size must be greater than firmware offset\n");
385                 return -EINVAL;                   384                 return -EINVAL;
386         }                                         385         }
387                                                   386 
388         /* Read the header information from th    387         /* Read the header information from the data pointer */
389         header = (struct snd_sof_fw_header *)( !! 388         header = (struct snd_sof_fw_header *)(fw->data + plat_data->fw_offset);
390                                                   389 
391         /* verify FW sig */                       390         /* verify FW sig */
392         if (strncmp(header->sig, SND_SOF_FW_SI    391         if (strncmp(header->sig, SND_SOF_FW_SIG, SND_SOF_FW_SIG_SIZE) != 0) {
393                 dev_err(sdev->dev, "invalid fi    392                 dev_err(sdev->dev, "invalid firmware signature\n");
394                 return -EINVAL;                   393                 return -EINVAL;
395         }                                         394         }
396                                                   395 
397         /* check size is valid */                 396         /* check size is valid */
398         if (fw_size != header->file_size + siz    397         if (fw_size != header->file_size + sizeof(*header)) {
399                 dev_err(sdev->dev,                398                 dev_err(sdev->dev,
400                         "invalid filesize mism    399                         "invalid filesize mismatch got 0x%zx expected 0x%zx\n",
401                         fw_size, header->file_    400                         fw_size, header->file_size + sizeof(*header));
402                 return -EINVAL;                   401                 return -EINVAL;
403         }                                         402         }
404                                                   403 
405         dev_dbg(sdev->dev, "header size=0x%x m    404         dev_dbg(sdev->dev, "header size=0x%x modules=0x%x abi=0x%x size=%zu\n",
406                 header->file_size, header->num    405                 header->file_size, header->num_modules,
407                 header->abi, sizeof(*header));    406                 header->abi, sizeof(*header));
408                                                   407 
409         return 0;                                 408         return 0;
410 }                                                 409 }
411                                                   410 
412 const struct sof_ipc_fw_loader_ops ipc3_loader    411 const struct sof_ipc_fw_loader_ops ipc3_loader_ops = {
413         .validate = sof_ipc3_validate_firmware    412         .validate = sof_ipc3_validate_firmware,
414         .parse_ext_manifest = sof_ipc3_fw_pars    413         .parse_ext_manifest = sof_ipc3_fw_parse_ext_man,
415         .load_fw_to_dsp = sof_ipc3_load_fw_to_    414         .load_fw_to_dsp = sof_ipc3_load_fw_to_dsp,
416 };                                                415 };
417                                                   416 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php