Lines Matching +full:firmware +full:- +full:name

1 // SPDX-License-Identifier: GPL-2.0
3 * main.c - Multi purpose firmware loading support
7 * Please see Documentation/driver-api/firmware/ for more information.
26 #include <linux/firmware.h>
44 #include "firmware.h"
48 MODULE_DESCRIPTION("Multi purpose firmware loading support");
59 * Names of firmware images which have been cached successfully
61 * helper can trace which firmware images have been cached
75 const char *name; member
80 const char *name; member
100 struct fw_state *fw_st = &fw_priv->fw_st; in fw_state_init()
102 init_completion(&fw_st->completion); in fw_state_init()
103 fw_st->status = FW_STATUS_UNKNOWN; in fw_state_init()
134 fw_priv->fw_name = kstrdup_const(fw_name, GFP_ATOMIC); in __allocate_fw_priv()
135 if (!fw_priv->fw_name) { in __allocate_fw_priv()
140 kref_init(&fw_priv->ref); in __allocate_fw_priv()
141 fw_priv->fwc = fwc; in __allocate_fw_priv()
142 fw_priv->data = dbuf; in __allocate_fw_priv()
143 fw_priv->allocated_size = size; in __allocate_fw_priv()
144 fw_priv->offset = offset; in __allocate_fw_priv()
145 fw_priv->opt_flags = opt_flags; in __allocate_fw_priv()
148 INIT_LIST_HEAD(&fw_priv->pending_list); in __allocate_fw_priv()
151 pr_debug("%s: fw-%s fw_priv=%p\n", __func__, fw_name, fw_priv); in __allocate_fw_priv()
161 list_for_each_entry(tmp, &fwc->head, list) in __lookup_fw_priv()
162 if (!strcmp(tmp->fw_name, fw_name)) in __lookup_fw_priv()
167 /* Returns 1 for batching firmware requests with the same name */
174 spin_lock(&fwc->lock); in alloc_lookup_fw_priv()
176 * Do not merge requests that are marked to be non-cached or in alloc_lookup_fw_priv()
182 kref_get(&tmp->ref); in alloc_lookup_fw_priv()
183 spin_unlock(&fwc->lock); in alloc_lookup_fw_priv()
185 pr_debug("batched request - sharing the same struct fw_priv and lookup for multiple requests\n"); in alloc_lookup_fw_priv()
192 INIT_LIST_HEAD(&tmp->list); in alloc_lookup_fw_priv()
194 list_add(&tmp->list, &fwc->head); in alloc_lookup_fw_priv()
196 spin_unlock(&fwc->lock); in alloc_lookup_fw_priv()
200 return tmp ? 0 : -ENOMEM; in alloc_lookup_fw_priv()
204 __releases(&fwc->lock) in __free_fw_priv()
207 struct firmware_cache *fwc = fw_priv->fwc; in __free_fw_priv()
209 pr_debug("%s: fw-%s fw_priv=%p data=%p size=%u\n", in __free_fw_priv()
210 __func__, fw_priv->fw_name, fw_priv, fw_priv->data, in __free_fw_priv()
211 (unsigned int)fw_priv->size); in __free_fw_priv()
213 list_del(&fw_priv->list); in __free_fw_priv()
214 spin_unlock(&fwc->lock); in __free_fw_priv()
218 else if (!fw_priv->allocated_size) in __free_fw_priv()
219 vfree(fw_priv->data); in __free_fw_priv()
221 kfree_const(fw_priv->fw_name); in __free_fw_priv()
227 struct firmware_cache *fwc = fw_priv->fwc; in free_fw_priv()
228 spin_lock(&fwc->lock); in free_fw_priv()
229 if (!kref_put(&fw_priv->ref, __free_fw_priv)) in free_fw_priv()
230 spin_unlock(&fwc->lock); in free_fw_priv()
236 return fw_priv->is_paged_buf; in fw_is_paged_buf()
243 if (!fw_priv->pages) in fw_free_paged_buf()
246 vunmap(fw_priv->data); in fw_free_paged_buf()
248 for (i = 0; i < fw_priv->nr_pages; i++) in fw_free_paged_buf()
249 __free_page(fw_priv->pages[i]); in fw_free_paged_buf()
250 kvfree(fw_priv->pages); in fw_free_paged_buf()
251 fw_priv->pages = NULL; in fw_free_paged_buf()
252 fw_priv->page_array_size = 0; in fw_free_paged_buf()
253 fw_priv->nr_pages = 0; in fw_free_paged_buf()
254 fw_priv->data = NULL; in fw_free_paged_buf()
255 fw_priv->size = 0; in fw_free_paged_buf()
261 if (fw_priv->page_array_size < pages_needed) { in fw_grow_paged_buf()
263 fw_priv->page_array_size * 2); in fw_grow_paged_buf()
269 return -ENOMEM; in fw_grow_paged_buf()
270 memcpy(new_pages, fw_priv->pages, in fw_grow_paged_buf()
271 fw_priv->page_array_size * sizeof(void *)); in fw_grow_paged_buf()
272 memset(&new_pages[fw_priv->page_array_size], 0, sizeof(void *) * in fw_grow_paged_buf()
273 (new_array_size - fw_priv->page_array_size)); in fw_grow_paged_buf()
274 kvfree(fw_priv->pages); in fw_grow_paged_buf()
275 fw_priv->pages = new_pages; in fw_grow_paged_buf()
276 fw_priv->page_array_size = new_array_size; in fw_grow_paged_buf()
279 while (fw_priv->nr_pages < pages_needed) { in fw_grow_paged_buf()
280 fw_priv->pages[fw_priv->nr_pages] = in fw_grow_paged_buf()
283 if (!fw_priv->pages[fw_priv->nr_pages]) in fw_grow_paged_buf()
284 return -ENOMEM; in fw_grow_paged_buf()
285 fw_priv->nr_pages++; in fw_grow_paged_buf()
294 if (!fw_priv->pages) in fw_map_paged_buf()
297 vunmap(fw_priv->data); in fw_map_paged_buf()
298 fw_priv->data = vmap(fw_priv->pages, fw_priv->nr_pages, 0, in fw_map_paged_buf()
300 if (!fw_priv->data) in fw_map_paged_buf()
301 return -ENOMEM; in fw_map_paged_buf()
308 * ZSTD-compressed firmware support
319 if (fw_priv->allocated_size) { in fw_decompress_zstd()
320 out_size = fw_priv->allocated_size; in fw_decompress_zstd()
321 out_buf = fw_priv->data; in fw_decompress_zstd()
328 return -EINVAL; in fw_decompress_zstd()
333 return -ENOMEM; in fw_decompress_zstd()
339 err = -ENOMEM; in fw_decompress_zstd()
346 err = -EINVAL; in fw_decompress_zstd()
354 err = -EINVAL; in fw_decompress_zstd()
358 if (!fw_priv->allocated_size) in fw_decompress_zstd()
359 fw_priv->data = out_buf; in fw_decompress_zstd()
360 fw_priv->size = len; in fw_decompress_zstd()
365 if (err && !fw_priv->allocated_size) in fw_decompress_zstd()
372 * XZ-compressed firmware support
380 return xz_ret == XZ_MEM_ERROR ? -ENOMEM : -EINVAL; in fw_decompress_xz_error()
385 /* single-shot decompression onto the pre-allocated buffer */
393 xz_dec = xz_dec_init(XZ_SINGLE, (u32)-1); in fw_decompress_xz_single()
395 return -ENOMEM; in fw_decompress_xz_single()
400 xz_buf.out_size = fw_priv->allocated_size; in fw_decompress_xz_single()
401 xz_buf.out = fw_priv->data; in fw_decompress_xz_single()
407 fw_priv->size = xz_buf.out_pos; in fw_decompress_xz_single()
421 xz_dec = xz_dec_init(XZ_DYNALLOC, (u32)-1); in fw_decompress_xz_pages()
423 return -ENOMEM; in fw_decompress_xz_pages()
429 fw_priv->is_paged_buf = true; in fw_decompress_xz_pages()
430 fw_priv->size = 0; in fw_decompress_xz_pages()
432 if (fw_grow_paged_buf(fw_priv, fw_priv->nr_pages + 1)) { in fw_decompress_xz_pages()
433 err = -ENOMEM; in fw_decompress_xz_pages()
438 page = fw_priv->pages[fw_priv->nr_pages - 1]; in fw_decompress_xz_pages()
444 fw_priv->size += xz_buf.out_pos; in fw_decompress_xz_pages()
462 /* if the buffer is pre-allocated, we can perform in single-shot mode */ in fw_decompress_xz()
463 if (fw_priv->data) in fw_decompress_xz()
470 /* direct firmware loading support */
474 "/lib/firmware/updates/" UTS_RELEASE,
475 "/lib/firmware/updates",
476 "/lib/firmware/" UTS_RELEASE,
477 "/lib/firmware"
486 MODULE_PARM_DESC(path, "customized firmware image search path with a higher priority than default p…
498 int rc = -ENOENT; in fw_get_filesystem_firmware()
504 if (!decompress && fw_priv->data) { in fw_get_filesystem_firmware()
505 buffer = fw_priv->data; in fw_get_filesystem_firmware()
506 msize = fw_priv->allocated_size; in fw_get_filesystem_firmware()
511 return -ENOMEM; in fw_get_filesystem_firmware()
527 maxlen = nt - fw_path[i]; in fw_get_filesystem_firmware()
532 fw_priv->fw_name, suffix); in fw_get_filesystem_firmware()
534 rc = -ENAMETOOLONG; in fw_get_filesystem_firmware()
538 fw_priv->size = 0; in fw_get_filesystem_firmware()
543 * firmware was not completely loaded. in fw_get_filesystem_firmware()
545 if ((fw_priv->opt_flags & FW_OPT_PARTIAL) && buffer) in fw_get_filesystem_firmware()
548 /* load firmware files from the mount namespace of init */ in fw_get_filesystem_firmware()
549 rc = kernel_read_file_from_path_initns(path, fw_priv->offset, in fw_get_filesystem_firmware()
554 if (!(fw_priv->opt_flags & FW_OPT_NO_WARN)) { in fw_get_filesystem_firmware()
555 if (rc != -ENOENT) in fw_get_filesystem_firmware()
569 dev_dbg(device, "Loading firmware from %s\n", path); in fw_get_filesystem_firmware()
572 fw_priv->fw_name); in fw_get_filesystem_firmware()
582 dev_dbg(device, "direct-loading %s\n", in fw_get_filesystem_firmware()
583 fw_priv->fw_name); in fw_get_filesystem_firmware()
584 if (!fw_priv->data) in fw_get_filesystem_firmware()
585 fw_priv->data = buffer; in fw_get_filesystem_firmware()
586 fw_priv->size = size; in fw_get_filesystem_firmware()
596 /* firmware holds the ownership of pages */
597 static void firmware_free_data(const struct firmware *fw) in firmware_free_data()
600 if (!fw->priv) { in firmware_free_data()
601 vfree(fw->data); in firmware_free_data()
604 free_fw_priv(fw->priv); in firmware_free_data()
607 /* store the pages buffer info firmware from buf */
608 static void fw_set_page_data(struct fw_priv *fw_priv, struct firmware *fw) in fw_set_page_data()
610 fw->priv = fw_priv; in fw_set_page_data()
611 fw->size = fw_priv->size; in fw_set_page_data()
612 fw->data = fw_priv->data; in fw_set_page_data()
614 pr_debug("%s: fw-%s fw_priv=%p data=%p size=%u\n", in fw_set_page_data()
615 __func__, fw_priv->fw_name, fw_priv, fw_priv->data, in fw_set_page_data()
616 (unsigned int)fw_priv->size); in fw_set_page_data()
624 if (fwn->magic == (unsigned long)&fw_cache) in fw_name_devm_release()
625 pr_debug("%s: fw_name-%s devm-%p released\n", in fw_name_devm_release()
626 __func__, fwn->name, res); in fw_name_devm_release()
627 kfree_const(fwn->name); in fw_name_devm_release()
635 return (fwn->magic == (unsigned long)&fw_cache) && in fw_devm_match()
636 !strcmp(fwn->name, match_data); in fw_devm_match()
640 const char *name) in fw_find_devm_name() argument
645 fw_devm_match, (void *)name); in fw_find_devm_name()
649 static bool fw_cache_is_setup(struct device *dev, const char *name) in fw_cache_is_setup() argument
653 fwn = fw_find_devm_name(dev, name); in fw_cache_is_setup()
660 /* add firmware name into devres list */
661 static int fw_add_devm_name(struct device *dev, const char *name) in fw_add_devm_name() argument
665 if (fw_cache_is_setup(dev, name)) in fw_add_devm_name()
671 return -ENOMEM; in fw_add_devm_name()
672 fwn->name = kstrdup_const(name, GFP_KERNEL); in fw_add_devm_name()
673 if (!fwn->name) { in fw_add_devm_name()
675 return -ENOMEM; in fw_add_devm_name()
678 fwn->magic = (unsigned long)&fw_cache; in fw_add_devm_name()
684 static bool fw_cache_is_setup(struct device *dev, const char *name) in fw_cache_is_setup() argument
689 static int fw_add_devm_name(struct device *dev, const char *name) in fw_add_devm_name() argument
695 int assign_fw(struct firmware *fw, struct device *device) in assign_fw()
697 struct fw_priv *fw_priv = fw->priv; in assign_fw()
701 if (!fw_priv->size || fw_state_is_aborted(fw_priv)) { in assign_fw()
703 return -ENOENT; in assign_fw()
707 * add firmware name into devres list so that we can auto cache in assign_fw()
708 * and uncache firmware for device. in assign_fw()
713 /* don't cache firmware handled without uevent */ in assign_fw()
714 if (device && (fw_priv->opt_flags & FW_OPT_UEVENT) && in assign_fw()
715 !(fw_priv->opt_flags & FW_OPT_NOCACHE)) { in assign_fw()
716 ret = fw_add_devm_name(device, fw_priv->fw_name); in assign_fw()
724 * After caching firmware image is started, let it piggyback in assign_fw()
725 * on request firmware. in assign_fw()
727 if (!(fw_priv->opt_flags & FW_OPT_NOCACHE) && in assign_fw()
728 fw_priv->fwc->state == FW_LOADER_START_CACHE) in assign_fw()
737 /* prepare firmware and firmware_buf structs;
738 * return 0 if a firmware is already assigned, 1 if need to load one,
742 _request_firmware_prepare(struct firmware **firmware_p, const char *name, in _request_firmware_prepare() argument
746 struct firmware *firmware; in _request_firmware_prepare() local
750 *firmware_p = firmware = kzalloc(sizeof(*firmware), GFP_KERNEL); in _request_firmware_prepare()
751 if (!firmware) { in _request_firmware_prepare()
752 dev_err(device, "%s: kmalloc(struct firmware) failed\n", in _request_firmware_prepare()
754 return -ENOMEM; in _request_firmware_prepare()
757 if (firmware_request_builtin_buf(firmware, name, dbuf, size)) { in _request_firmware_prepare()
758 dev_dbg(device, "using built-in %s\n", name); in _request_firmware_prepare()
762 ret = alloc_lookup_fw_priv(name, &fw_cache, &fw_priv, dbuf, size, in _request_firmware_prepare()
767 * of requesting firmware. in _request_firmware_prepare()
769 firmware->priv = fw_priv; in _request_firmware_prepare()
774 fw_set_page_data(fw_priv, firmware); in _request_firmware_prepare()
793 static void fw_abort_batch_reqs(struct firmware *fw) in fw_abort_batch_reqs()
798 if (!fw || !fw->priv) in fw_abort_batch_reqs()
801 fw_priv = fw->priv; in fw_abort_batch_reqs()
812 static void fw_log_firmware_info(const struct firmware *fw, const char *name, struct device *device) in fw_log_firmware_info() argument
829 shash->tfm = alg; in fw_log_firmware_info()
831 if (crypto_shash_digest(shash, fw->data, fw->size, sha256buf) < 0) in fw_log_firmware_info()
837 dev_dbg(device, "Loaded FW: %s, sha256: %s\n", name, outbuf); in fw_log_firmware_info()
847 static void fw_log_firmware_info(const struct firmware *fw, const char *name, in fw_log_firmware_info() argument
853 * Reject firmware file names with ".." path components.
854 * There are drivers that construct firmware file names from device-supplied
856 * be sent my firmware from ../../../etc/shadow, please".
860 * This intentionally only looks at the firmware name, not at the firmware base
863 static bool name_contains_dotdot(const char *name) in name_contains_dotdot() argument
865 size_t name_len = strlen(name); in name_contains_dotdot()
867 return strcmp(name, "..") == 0 || strncmp(name, "../", 3) == 0 || in name_contains_dotdot()
868 strstr(name, "/../") != NULL || in name_contains_dotdot()
869 (name_len >= 3 && strcmp(name+name_len-3, "/..") == 0); in name_contains_dotdot()
874 _request_firmware(const struct firmware **firmware_p, const char *name, in _request_firmware() argument
878 struct firmware *fw = NULL; in _request_firmware()
885 return -EINVAL; in _request_firmware()
887 if (!name || name[0] == '\0') { in _request_firmware()
888 ret = -EINVAL; in _request_firmware()
892 if (name_contains_dotdot(name)) { in _request_firmware()
894 "Firmware load for '%s' refused, path contains '..' component\n", in _request_firmware()
895 name); in _request_firmware()
896 ret = -EINVAL; in _request_firmware()
900 ret = _request_firmware_prepare(&fw, name, device, buf, size, in _request_firmware()
906 * We are about to try to access the firmware file. Because we may have been in _request_firmware()
912 ret = -ENOMEM; in _request_firmware()
917 ret = fw_get_filesystem_firmware(device, fw->priv, "", NULL); in _request_firmware()
924 if (ret == -ENOENT && nondirect) in _request_firmware()
925 ret = fw_get_filesystem_firmware(device, fw->priv, ".zst", in _request_firmware()
929 if (ret == -ENOENT && nondirect) in _request_firmware()
930 ret = fw_get_filesystem_firmware(device, fw->priv, ".xz", in _request_firmware()
933 if (ret == -ENOENT && nondirect) in _request_firmware()
934 ret = firmware_fallback_platform(fw->priv); in _request_firmware()
939 "Direct firmware load for %s failed with error %d\n", in _request_firmware()
940 name, ret); in _request_firmware()
942 ret = firmware_fallback_sysfs(fw, name, device, in _request_firmware()
956 fw_log_firmware_info(fw, name, device); in _request_firmware()
964 * request_firmware() - send firmware request and wait for it
965 * @firmware_p: pointer to firmware image
966 * @name: name of firmware file
967 * @device: device for which firmware is being loaded
969 * @firmware_p will be used to return a firmware image by the name
970 * of @name for device @device.
974 * @name will be used as $FIRMWARE in the uevent environment and
976 * firmware image for this or any other device.
977 * It must not contain any ".." path components - "foo/bar..bin" is
986 request_firmware(const struct firmware **firmware_p, const char *name, in request_firmware() argument
993 ret = _request_firmware(firmware_p, name, device, NULL, 0, 0, in request_firmware()
1001 * firmware_request_nowarn() - request for an optional fw module
1002 * @firmware: pointer to firmware image
1003 * @name: name of firmware file
1004 * @device: device for which firmware is being loaded
1009 * failures to find the firmware file with it are still suppressed. It is
1013 int firmware_request_nowarn(const struct firmware **firmware, const char *name, in firmware_request_nowarn() argument
1020 ret = _request_firmware(firmware, name, device, NULL, 0, 0, in firmware_request_nowarn()
1028 * request_firmware_direct() - load firmware directly without usermode helper
1029 * @firmware_p: pointer to firmware image
1030 * @name: name of firmware file
1031 * @device: device for which firmware is being loaded
1034 * fall back to usermode helper even if the firmware couldn't be loaded
1038 int request_firmware_direct(const struct firmware **firmware_p, in request_firmware_direct()
1039 const char *name, struct device *device) in request_firmware_direct() argument
1044 ret = _request_firmware(firmware_p, name, device, NULL, 0, 0, in request_firmware_direct()
1053 * firmware_request_platform() - request firmware with platform-fw fallback
1054 * @firmware: pointer to firmware image
1055 * @name: name of firmware file
1056 * @device: device for which firmware is being loaded
1060 * requested firmware embedded in the platform's main (e.g. UEFI) firmware.
1062 int firmware_request_platform(const struct firmware **firmware, in firmware_request_platform() argument
1063 const char *name, struct device *device) in firmware_request_platform() argument
1069 ret = _request_firmware(firmware, name, device, NULL, 0, 0, in firmware_request_platform()
1077 * firmware_request_cache() - cache firmware for suspend so resume can use it
1078 * @name: name of firmware file
1079 * @device: device for which firmware should be cached for
1082 * require loading firmware on system reboot. This optimization may still
1083 * require the firmware present on resume from suspend. This routine can be
1084 * used to ensure the firmware is present on resume from suspend in these
1088 int firmware_request_cache(struct device *device, const char *name) in firmware_request_cache() argument
1093 ret = fw_add_devm_name(device, name); in firmware_request_cache()
1101 * request_firmware_into_buf() - load firmware into a previously allocated buffer
1102 * @firmware_p: pointer to firmware image
1103 * @name: name of firmware file
1104 * @device: device for which firmware is being loaded and DMA region allocated
1105 * @buf: address of buffer to load firmware into
1109 * allocate a buffer to hold the firmware data. Instead, the firmware
1113 * This function doesn't cache firmware either.
1116 request_firmware_into_buf(const struct firmware **firmware_p, const char *name, in request_firmware_into_buf() argument
1121 if (fw_cache_is_setup(device, name)) in request_firmware_into_buf()
1122 return -EOPNOTSUPP; in request_firmware_into_buf()
1125 ret = _request_firmware(firmware_p, name, device, buf, size, 0, in request_firmware_into_buf()
1133 * request_partial_firmware_into_buf() - load partial firmware into a previously allocated buffer
1134 * @firmware_p: pointer to firmware image
1135 * @name: name of firmware file
1136 * @device: device for which firmware is being loaded and DMA region allocated
1137 * @buf: address of buffer to load firmware into
1145 request_partial_firmware_into_buf(const struct firmware **firmware_p, in request_partial_firmware_into_buf()
1146 const char *name, struct device *device, in request_partial_firmware_into_buf() argument
1151 if (fw_cache_is_setup(device, name)) in request_partial_firmware_into_buf()
1152 return -EOPNOTSUPP; in request_partial_firmware_into_buf()
1155 ret = _request_firmware(firmware_p, name, device, buf, size, offset, in request_partial_firmware_into_buf()
1164 * release_firmware() - release the resource associated with a firmware image
1165 * @fw: firmware resource to release
1167 void release_firmware(const struct firmware *fw) in release_firmware()
1181 const char *name; member
1184 void (*cont)(const struct firmware *fw, void *context);
1191 const struct firmware *fw; in request_firmware_work_func()
1195 _request_firmware(&fw, fw_work->name, fw_work->device, NULL, 0, 0, in request_firmware_work_func()
1196 fw_work->opt_flags); in request_firmware_work_func()
1197 fw_work->cont(fw, fw_work->context); in request_firmware_work_func()
1198 put_device(fw_work->device); /* taken in request_firmware_nowait() */ in request_firmware_work_func()
1200 module_put(fw_work->module); in request_firmware_work_func()
1201 kfree_const(fw_work->name); in request_firmware_work_func()
1208 const char *name, struct device *device, gfp_t gfp, void *context, in _request_firmware_nowait() argument
1209 void (*cont)(const struct firmware *fw, void *context), bool nowarn) in _request_firmware_nowait()
1215 return -ENOMEM; in _request_firmware_nowait()
1217 fw_work->module = module; in _request_firmware_nowait()
1218 fw_work->name = kstrdup_const(name, gfp); in _request_firmware_nowait()
1219 if (!fw_work->name) { in _request_firmware_nowait()
1221 return -ENOMEM; in _request_firmware_nowait()
1223 fw_work->device = device; in _request_firmware_nowait()
1224 fw_work->context = context; in _request_firmware_nowait()
1225 fw_work->cont = cont; in _request_firmware_nowait()
1226 fw_work->opt_flags = FW_OPT_NOWAIT | in _request_firmware_nowait()
1230 if (!uevent && fw_cache_is_setup(device, name)) { in _request_firmware_nowait()
1231 kfree_const(fw_work->name); in _request_firmware_nowait()
1233 return -EOPNOTSUPP; in _request_firmware_nowait()
1237 kfree_const(fw_work->name); in _request_firmware_nowait()
1239 return -EFAULT; in _request_firmware_nowait()
1242 get_device(fw_work->device); in _request_firmware_nowait()
1243 INIT_WORK(&fw_work->work, request_firmware_work_func); in _request_firmware_nowait()
1244 schedule_work(&fw_work->work); in _request_firmware_nowait()
1249 * request_firmware_nowait() - asynchronous version of request_firmware
1250 * @module: module requesting the firmware
1251 * @uevent: sends uevent to copy the firmware image if this flag
1252 * is non-zero else the firmware copy must be done manually.
1253 * @name: name of firmware file
1254 * @device: device for which firmware is being loaded
1257 * @fw may be %NULL if firmware request fails.
1258 * @cont: function will be called asynchronously when the firmware
1264 * - sleep for as small periods as possible since it may
1265 * increase kernel boot time of built-in device drivers
1266 * requesting firmware in their ->probe() methods, if
1269 * - can't sleep at all if @gfp is GFP_ATOMIC.
1273 const char *name, struct device *device, gfp_t gfp, void *context, in request_firmware_nowait() argument
1274 void (*cont)(const struct firmware *fw, void *context)) in request_firmware_nowait()
1276 return _request_firmware_nowait(module, uevent, name, device, gfp, in request_firmware_nowait()
1283 * firmware_request_nowait_nowarn() - async version of request_firmware_nowarn
1284 * @module: module requesting the firmware
1285 * @name: name of firmware file
1286 * @device: device for which firmware is being loaded
1289 * @fw may be %NULL if firmware request fails.
1290 * @cont: function will be called asynchronously when the firmware
1294 * when the firmware file could not be found and always sends a uevent to copy
1295 * the firmware image.
1298 struct module *module, const char *name, in firmware_request_nowait_nowarn() argument
1300 void (*cont)(const struct firmware *fw, void *context)) in firmware_request_nowait_nowarn()
1302 return _request_firmware_nowait(module, FW_ACTION_UEVENT, name, device, in firmware_request_nowait_nowarn()
1311 * cache_firmware() - cache one firmware image in kernel memory space
1312 * @fw_name: the firmware image name
1314 * Cache firmware in kernel memory so that drivers can use it when
1315 * system isn't ready for them to request firmware image from userspace.
1317 * nowait version to get the cached firmware without any interacting
1320 * Return 0 if the firmware image has been cached successfully
1327 const struct firmware *fw; in cache_firmware()
1345 spin_lock(&fwc->lock); in lookup_fw_priv()
1347 spin_unlock(&fwc->lock); in lookup_fw_priv()
1353 * uncache_firmware() - remove one cached firmware image
1354 * @fw_name: the firmware image name
1356 * Uncache one firmware image which has been cached successfully
1359 * Return 0 if the firmware cache has been removed successfully
1366 struct firmware fw; in uncache_firmware()
1379 return -EINVAL; in uncache_firmware()
1382 static struct fw_cache_entry *alloc_fw_cache_entry(const char *name) in alloc_fw_cache_entry() argument
1390 fce->name = kstrdup_const(name, GFP_ATOMIC); in alloc_fw_cache_entry()
1391 if (!fce->name) { in alloc_fw_cache_entry()
1400 static int __fw_entry_found(const char *name) in __fw_entry_found() argument
1405 list_for_each_entry(fce, &fwc->fw_names, list) { in __fw_entry_found()
1406 if (!strcmp(fce->name, name)) in __fw_entry_found()
1414 const char *name = fw_priv->fw_name; in fw_cache_piggyback_on_request() local
1415 struct firmware_cache *fwc = fw_priv->fwc; in fw_cache_piggyback_on_request()
1418 spin_lock(&fwc->name_lock); in fw_cache_piggyback_on_request()
1419 if (__fw_entry_found(name)) in fw_cache_piggyback_on_request()
1422 fce = alloc_fw_cache_entry(name); in fw_cache_piggyback_on_request()
1424 list_add(&fce->list, &fwc->fw_names); in fw_cache_piggyback_on_request()
1425 kref_get(&fw_priv->ref); in fw_cache_piggyback_on_request()
1426 pr_debug("%s: fw: %s\n", __func__, name); in fw_cache_piggyback_on_request()
1429 spin_unlock(&fwc->name_lock); in fw_cache_piggyback_on_request()
1434 kfree_const(fce->name); in free_fw_cache_entry()
1445 ret = cache_firmware(fce->name); in __async_dev_cache_fw_image()
1447 spin_lock(&fwc->name_lock); in __async_dev_cache_fw_image()
1448 list_del(&fce->list); in __async_dev_cache_fw_image()
1449 spin_unlock(&fwc->name_lock); in __async_dev_cache_fw_image()
1455 /* called with dev->devres_lock held */
1460 const char *fw_name = fwn->name; in dev_create_fw_entry()
1466 list_add(&fce->list, head); in dev_create_fw_entry()
1473 return (fwn->magic == (unsigned long)match_data); in devm_name_match()
1488 list_del(&fce->list); in dev_cache_fw_image()
1490 spin_lock(&fwc->name_lock); in dev_cache_fw_image()
1491 /* only one cache entry for one firmware */ in dev_cache_fw_image()
1492 if (!__fw_entry_found(fce->name)) { in dev_cache_fw_image()
1493 list_add(&fce->list, &fwc->fw_names); in dev_cache_fw_image()
1498 spin_unlock(&fwc->name_lock); in dev_cache_fw_image()
1512 spin_lock(&fwc->name_lock); in __device_uncache_fw_images()
1513 while (!list_empty(&fwc->fw_names)) { in __device_uncache_fw_images()
1514 fce = list_entry(fwc->fw_names.next, in __device_uncache_fw_images()
1516 list_del(&fce->list); in __device_uncache_fw_images()
1517 spin_unlock(&fwc->name_lock); in __device_uncache_fw_images()
1519 uncache_firmware(fce->name); in __device_uncache_fw_images()
1522 spin_lock(&fwc->name_lock); in __device_uncache_fw_images()
1524 spin_unlock(&fwc->name_lock); in __device_uncache_fw_images()
1528 * device_cache_fw_images() - cache devices' firmware
1531 * successfully before, the firmware names are recored into the
1535 * time when system is not ready to complete loading firmware.
1545 cancel_delayed_work_sync(&fwc->work); in device_cache_fw_images()
1550 fwc->state = FW_LOADER_START_CACHE; in device_cache_fw_images()
1554 /* wait for completion of caching firmware for all devices */ in device_cache_fw_images()
1561 * device_uncache_fw_images() - uncache devices' firmware
1578 * device_uncache_fw_images_delay() - uncache devices firmwares
1599 * non-uevent firmware request to avoid stalling suspend. in fw_pm_notify()
1623 /* stop caching firmware once syscore_suspend is reached */