2 * firmware_class.c - Multi purpose firmware loading support
4 * Copyright (c) 2003 Manuel Estrada Sainz
6 * Please see Documentation/firmware_class/ for more information.
10 #include <linux/capability.h>
11 #include <linux/device.h>
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/timer.h>
15 #include <linux/vmalloc.h>
16 #include <linux/interrupt.h>
17 #include <linux/bitops.h>
18 #include <linux/mutex.h>
19 #include <linux/workqueue.h>
20 #include <linux/highmem.h>
21 #include <linux/firmware.h>
22 #include <linux/slab.h>
23 #include <linux/sched.h>
24 #include <linux/file.h>
25 #include <linux/list.h>
27 #include <linux/async.h>
29 #include <linux/suspend.h>
30 #include <linux/syscore_ops.h>
31 #include <linux/reboot.h>
32 #include <linux/security.h>
33 #include <linux/swait.h>
35 #include <generated/utsrelease.h>
39 MODULE_AUTHOR("Manuel Estrada Sainz");
40 MODULE_DESCRIPTION("Multi purpose firmware loading support");
41 MODULE_LICENSE("GPL");
43 /* Builtin firmware support */
45 #ifdef CONFIG_FW_LOADER
47 extern struct builtin_fw __start_builtin_fw
[];
48 extern struct builtin_fw __end_builtin_fw
[];
50 static bool fw_get_builtin_firmware(struct firmware
*fw
, const char *name
,
51 void *buf
, size_t size
)
53 struct builtin_fw
*b_fw
;
55 for (b_fw
= __start_builtin_fw
; b_fw
!= __end_builtin_fw
; b_fw
++) {
56 if (strcmp(name
, b_fw
->name
) == 0) {
57 fw
->size
= b_fw
->size
;
58 fw
->data
= b_fw
->data
;
60 if (buf
&& fw
->size
<= size
)
61 memcpy(buf
, fw
->data
, fw
->size
);
69 static bool fw_is_builtin_firmware(const struct firmware
*fw
)
71 struct builtin_fw
*b_fw
;
73 for (b_fw
= __start_builtin_fw
; b_fw
!= __end_builtin_fw
; b_fw
++)
74 if (fw
->data
== b_fw
->data
)
80 #else /* Module case - no builtin firmware support */
82 static inline bool fw_get_builtin_firmware(struct firmware
*fw
,
83 const char *name
, void *buf
,
89 static inline bool fw_is_builtin_firmware(const struct firmware
*fw
)
102 static int loading_timeout
= 60; /* In seconds */
104 static inline long firmware_loading_timeout(void)
106 return loading_timeout
> 0 ? loading_timeout
* HZ
: MAX_JIFFY_OFFSET
;
110 * Concurrent request_firmware() for the same firmware need to be
111 * serialized. struct fw_state is simple state machine which hold the
112 * state of the firmware loading.
115 struct swait_queue_head wq
;
116 enum fw_status status
;
119 static void fw_state_init(struct fw_state
*fw_st
)
121 init_swait_queue_head(&fw_st
->wq
);
122 fw_st
->status
= FW_STATUS_UNKNOWN
;
125 static inline bool __fw_state_is_done(enum fw_status status
)
127 return status
== FW_STATUS_DONE
|| status
== FW_STATUS_ABORTED
;
130 static int __fw_state_wait_common(struct fw_state
*fw_st
, long timeout
)
134 ret
= swait_event_interruptible_timeout(fw_st
->wq
,
135 __fw_state_is_done(READ_ONCE(fw_st
->status
)),
137 if (ret
!= 0 && fw_st
->status
== FW_STATUS_ABORTED
)
142 return ret
< 0 ? ret
: 0;
145 static void __fw_state_set(struct fw_state
*fw_st
,
146 enum fw_status status
)
148 WRITE_ONCE(fw_st
->status
, status
);
150 if (status
== FW_STATUS_DONE
|| status
== FW_STATUS_ABORTED
)
151 swake_up(&fw_st
->wq
);
154 #define fw_state_start(fw_st) \
155 __fw_state_set(fw_st, FW_STATUS_LOADING)
156 #define fw_state_done(fw_st) \
157 __fw_state_set(fw_st, FW_STATUS_DONE)
158 #define fw_state_wait(fw_st) \
159 __fw_state_wait_common(fw_st, MAX_SCHEDULE_TIMEOUT)
161 #ifndef CONFIG_FW_LOADER_USER_HELPER
163 #define fw_state_is_aborted(fw_st) false
165 #else /* CONFIG_FW_LOADER_USER_HELPER */
167 static int __fw_state_check(struct fw_state
*fw_st
, enum fw_status status
)
169 return fw_st
->status
== status
;
172 #define fw_state_aborted(fw_st) \
173 __fw_state_set(fw_st, FW_STATUS_ABORTED)
174 #define fw_state_is_done(fw_st) \
175 __fw_state_check(fw_st, FW_STATUS_DONE)
176 #define fw_state_is_loading(fw_st) \
177 __fw_state_check(fw_st, FW_STATUS_LOADING)
178 #define fw_state_is_aborted(fw_st) \
179 __fw_state_check(fw_st, FW_STATUS_ABORTED)
180 #define fw_state_wait_timeout(fw_st, timeout) \
181 __fw_state_wait_common(fw_st, timeout)
183 #endif /* CONFIG_FW_LOADER_USER_HELPER */
185 /* firmware behavior options */
186 #define FW_OPT_UEVENT (1U << 0)
187 #define FW_OPT_NOWAIT (1U << 1)
188 #ifdef CONFIG_FW_LOADER_USER_HELPER
189 #define FW_OPT_USERHELPER (1U << 2)
191 #define FW_OPT_USERHELPER 0
193 #ifdef CONFIG_FW_LOADER_USER_HELPER_FALLBACK
194 #define FW_OPT_FALLBACK FW_OPT_USERHELPER
196 #define FW_OPT_FALLBACK 0
198 #define FW_OPT_NO_WARN (1U << 3)
199 #define FW_OPT_NOCACHE (1U << 4)
201 struct firmware_cache
{
202 /* firmware_buf instance will be added into the below list */
204 struct list_head head
;
207 #ifdef CONFIG_PM_SLEEP
209 * Names of firmware images which have been cached successfully
210 * will be added into the below list so that device uncache
211 * helper can trace which firmware images have been cached
214 spinlock_t name_lock
;
215 struct list_head fw_names
;
217 struct delayed_work work
;
219 struct notifier_block pm_notify
;
223 struct firmware_buf
{
225 struct list_head list
;
226 struct firmware_cache
*fwc
;
227 struct fw_state fw_st
;
230 size_t allocated_size
;
231 #ifdef CONFIG_FW_LOADER_USER_HELPER
237 struct list_head pending_list
;
242 struct fw_cache_entry
{
243 struct list_head list
;
247 struct fw_name_devm
{
252 #define to_fwbuf(d) container_of(d, struct firmware_buf, ref)
254 #define FW_LOADER_NO_CACHE 0
255 #define FW_LOADER_START_CACHE 1
257 static int fw_cache_piggyback_on_request(const char *name
);
259 /* fw_lock could be moved to 'struct firmware_priv' but since it is just
260 * guarding for corner cases a global lock should be OK */
261 static DEFINE_MUTEX(fw_lock
);
263 static struct firmware_cache fw_cache
;
265 static struct firmware_buf
*__allocate_fw_buf(const char *fw_name
,
266 struct firmware_cache
*fwc
,
267 void *dbuf
, size_t size
)
269 struct firmware_buf
*buf
;
271 buf
= kzalloc(sizeof(*buf
), GFP_ATOMIC
);
275 buf
->fw_id
= kstrdup_const(fw_name
, GFP_ATOMIC
);
281 kref_init(&buf
->ref
);
284 buf
->allocated_size
= size
;
285 fw_state_init(&buf
->fw_st
);
286 #ifdef CONFIG_FW_LOADER_USER_HELPER
287 INIT_LIST_HEAD(&buf
->pending_list
);
290 pr_debug("%s: fw-%s buf=%p\n", __func__
, fw_name
, buf
);
295 static struct firmware_buf
*__fw_lookup_buf(const char *fw_name
)
297 struct firmware_buf
*tmp
;
298 struct firmware_cache
*fwc
= &fw_cache
;
300 list_for_each_entry(tmp
, &fwc
->head
, list
)
301 if (!strcmp(tmp
->fw_id
, fw_name
))
306 static int fw_lookup_and_allocate_buf(const char *fw_name
,
307 struct firmware_cache
*fwc
,
308 struct firmware_buf
**buf
, void *dbuf
,
311 struct firmware_buf
*tmp
;
313 spin_lock(&fwc
->lock
);
314 tmp
= __fw_lookup_buf(fw_name
);
317 spin_unlock(&fwc
->lock
);
321 tmp
= __allocate_fw_buf(fw_name
, fwc
, dbuf
, size
);
323 list_add(&tmp
->list
, &fwc
->head
);
324 spin_unlock(&fwc
->lock
);
328 return tmp
? 0 : -ENOMEM
;
331 static void __fw_free_buf(struct kref
*ref
)
332 __releases(&fwc
->lock
)
334 struct firmware_buf
*buf
= to_fwbuf(ref
);
335 struct firmware_cache
*fwc
= buf
->fwc
;
337 pr_debug("%s: fw-%s buf=%p data=%p size=%u\n",
338 __func__
, buf
->fw_id
, buf
, buf
->data
,
339 (unsigned int)buf
->size
);
341 list_del(&buf
->list
);
342 spin_unlock(&fwc
->lock
);
344 #ifdef CONFIG_FW_LOADER_USER_HELPER
345 if (buf
->is_paged_buf
) {
348 for (i
= 0; i
< buf
->nr_pages
; i
++)
349 __free_page(buf
->pages
[i
]);
353 if (!buf
->allocated_size
)
355 kfree_const(buf
->fw_id
);
359 static void fw_free_buf(struct firmware_buf
*buf
)
361 struct firmware_cache
*fwc
= buf
->fwc
;
362 spin_lock(&fwc
->lock
);
363 if (!kref_put(&buf
->ref
, __fw_free_buf
))
364 spin_unlock(&fwc
->lock
);
367 /* direct firmware loading support */
368 static char fw_path_para
[256];
369 static const char * const fw_path
[] = {
371 "/lib/firmware/updates/" UTS_RELEASE
,
372 "/lib/firmware/updates",
373 "/lib/firmware/" UTS_RELEASE
,
378 * Typical usage is that passing 'firmware_class.path=$CUSTOMIZED_PATH'
379 * from kernel command line because firmware_class is generally built in
380 * kernel instead of module.
382 module_param_string(path
, fw_path_para
, sizeof(fw_path_para
), 0644);
383 MODULE_PARM_DESC(path
, "customized firmware image search path with a higher priority than default path");
386 fw_get_filesystem_firmware(struct device
*device
, struct firmware_buf
*buf
)
392 enum kernel_read_file_id id
= READING_FIRMWARE
;
393 size_t msize
= INT_MAX
;
395 /* Already populated data member means we're loading into a buffer */
397 id
= READING_FIRMWARE_PREALLOC_BUFFER
;
398 msize
= buf
->allocated_size
;
405 for (i
= 0; i
< ARRAY_SIZE(fw_path
); i
++) {
406 /* skip the unset customized path */
410 len
= snprintf(path
, PATH_MAX
, "%s/%s",
411 fw_path
[i
], buf
->fw_id
);
412 if (len
>= PATH_MAX
) {
418 rc
= kernel_read_file_from_path(path
, &buf
->data
, &size
, msize
,
422 dev_dbg(device
, "loading %s failed with error %d\n",
425 dev_warn(device
, "loading %s failed with error %d\n",
429 dev_dbg(device
, "direct-loading %s\n", buf
->fw_id
);
431 fw_state_done(&buf
->fw_st
);
439 /* firmware holds the ownership of pages */
440 static void firmware_free_data(const struct firmware
*fw
)
442 /* Loaded directly? */
447 fw_free_buf(fw
->priv
);
450 /* store the pages buffer info firmware from buf */
451 static void fw_set_page_data(struct firmware_buf
*buf
, struct firmware
*fw
)
454 #ifdef CONFIG_FW_LOADER_USER_HELPER
455 fw
->pages
= buf
->pages
;
457 fw
->size
= buf
->size
;
458 fw
->data
= buf
->data
;
460 pr_debug("%s: fw-%s buf=%p data=%p size=%u\n",
461 __func__
, buf
->fw_id
, buf
, buf
->data
,
462 (unsigned int)buf
->size
);
465 #ifdef CONFIG_PM_SLEEP
466 static void fw_name_devm_release(struct device
*dev
, void *res
)
468 struct fw_name_devm
*fwn
= res
;
470 if (fwn
->magic
== (unsigned long)&fw_cache
)
471 pr_debug("%s: fw_name-%s devm-%p released\n",
472 __func__
, fwn
->name
, res
);
473 kfree_const(fwn
->name
);
476 static int fw_devm_match(struct device
*dev
, void *res
,
479 struct fw_name_devm
*fwn
= res
;
481 return (fwn
->magic
== (unsigned long)&fw_cache
) &&
482 !strcmp(fwn
->name
, match_data
);
485 static struct fw_name_devm
*fw_find_devm_name(struct device
*dev
,
488 struct fw_name_devm
*fwn
;
490 fwn
= devres_find(dev
, fw_name_devm_release
,
491 fw_devm_match
, (void *)name
);
495 /* add firmware name into devres list */
496 static int fw_add_devm_name(struct device
*dev
, const char *name
)
498 struct fw_name_devm
*fwn
;
500 fwn
= fw_find_devm_name(dev
, name
);
504 fwn
= devres_alloc(fw_name_devm_release
, sizeof(struct fw_name_devm
),
508 fwn
->name
= kstrdup_const(name
, GFP_KERNEL
);
514 fwn
->magic
= (unsigned long)&fw_cache
;
515 devres_add(dev
, fwn
);
520 static int fw_add_devm_name(struct device
*dev
, const char *name
)
528 * user-mode helper code
530 #ifdef CONFIG_FW_LOADER_USER_HELPER
531 struct firmware_priv
{
534 struct firmware_buf
*buf
;
538 static struct firmware_priv
*to_firmware_priv(struct device
*dev
)
540 return container_of(dev
, struct firmware_priv
, dev
);
543 static void __fw_load_abort(struct firmware_buf
*buf
)
546 * There is a small window in which user can write to 'loading'
547 * between loading done and disappearance of 'loading'
549 if (fw_state_is_done(&buf
->fw_st
))
552 list_del_init(&buf
->pending_list
);
553 fw_state_aborted(&buf
->fw_st
);
556 static void fw_load_abort(struct firmware_priv
*fw_priv
)
558 struct firmware_buf
*buf
= fw_priv
->buf
;
560 __fw_load_abort(buf
);
563 static LIST_HEAD(pending_fw_head
);
565 /* reboot notifier for avoid deadlock with usermode_lock */
566 static int fw_shutdown_notify(struct notifier_block
*unused1
,
567 unsigned long unused2
, void *unused3
)
569 mutex_lock(&fw_lock
);
570 while (!list_empty(&pending_fw_head
))
571 __fw_load_abort(list_first_entry(&pending_fw_head
,
574 mutex_unlock(&fw_lock
);
578 static struct notifier_block fw_shutdown_nb
= {
579 .notifier_call
= fw_shutdown_notify
,
582 static ssize_t
timeout_show(struct class *class, struct class_attribute
*attr
,
585 return sprintf(buf
, "%d\n", loading_timeout
);
589 * firmware_timeout_store - set number of seconds to wait for firmware
590 * @class: device class pointer
591 * @attr: device attribute pointer
592 * @buf: buffer to scan for timeout value
593 * @count: number of bytes in @buf
595 * Sets the number of seconds to wait for the firmware. Once
596 * this expires an error will be returned to the driver and no
597 * firmware will be provided.
599 * Note: zero means 'wait forever'.
601 static ssize_t
timeout_store(struct class *class, struct class_attribute
*attr
,
602 const char *buf
, size_t count
)
604 loading_timeout
= simple_strtol(buf
, NULL
, 10);
605 if (loading_timeout
< 0)
610 static CLASS_ATTR_RW(timeout
);
612 static struct attribute
*firmware_class_attrs
[] = {
613 &class_attr_timeout
.attr
,
616 ATTRIBUTE_GROUPS(firmware_class
);
618 static void fw_dev_release(struct device
*dev
)
620 struct firmware_priv
*fw_priv
= to_firmware_priv(dev
);
625 static int do_firmware_uevent(struct firmware_priv
*fw_priv
, struct kobj_uevent_env
*env
)
627 if (add_uevent_var(env
, "FIRMWARE=%s", fw_priv
->buf
->fw_id
))
629 if (add_uevent_var(env
, "TIMEOUT=%i", loading_timeout
))
631 if (add_uevent_var(env
, "ASYNC=%d", fw_priv
->nowait
))
637 static int firmware_uevent(struct device
*dev
, struct kobj_uevent_env
*env
)
639 struct firmware_priv
*fw_priv
= to_firmware_priv(dev
);
642 mutex_lock(&fw_lock
);
644 err
= do_firmware_uevent(fw_priv
, env
);
645 mutex_unlock(&fw_lock
);
649 static struct class firmware_class
= {
651 .class_groups
= firmware_class_groups
,
652 .dev_uevent
= firmware_uevent
,
653 .dev_release
= fw_dev_release
,
656 static ssize_t
firmware_loading_show(struct device
*dev
,
657 struct device_attribute
*attr
, char *buf
)
659 struct firmware_priv
*fw_priv
= to_firmware_priv(dev
);
662 mutex_lock(&fw_lock
);
664 loading
= fw_state_is_loading(&fw_priv
->buf
->fw_st
);
665 mutex_unlock(&fw_lock
);
667 return sprintf(buf
, "%d\n", loading
);
670 /* Some architectures don't have PAGE_KERNEL_RO */
671 #ifndef PAGE_KERNEL_RO
672 #define PAGE_KERNEL_RO PAGE_KERNEL
675 /* one pages buffer should be mapped/unmapped only once */
676 static int fw_map_pages_buf(struct firmware_buf
*buf
)
678 if (!buf
->is_paged_buf
)
682 buf
->data
= vmap(buf
->pages
, buf
->nr_pages
, 0, PAGE_KERNEL_RO
);
689 * firmware_loading_store - set value in the 'loading' control file
690 * @dev: device pointer
691 * @attr: device attribute pointer
692 * @buf: buffer to scan for loading control value
693 * @count: number of bytes in @buf
695 * The relevant values are:
697 * 1: Start a load, discarding any previous partial load.
698 * 0: Conclude the load and hand the data to the driver code.
699 * -1: Conclude the load with an error and discard any written data.
701 static ssize_t
firmware_loading_store(struct device
*dev
,
702 struct device_attribute
*attr
,
703 const char *buf
, size_t count
)
705 struct firmware_priv
*fw_priv
= to_firmware_priv(dev
);
706 struct firmware_buf
*fw_buf
;
707 ssize_t written
= count
;
708 int loading
= simple_strtol(buf
, NULL
, 10);
711 mutex_lock(&fw_lock
);
712 fw_buf
= fw_priv
->buf
;
713 if (fw_state_is_aborted(&fw_buf
->fw_st
))
718 /* discarding any previous partial load */
719 if (!fw_state_is_done(&fw_buf
->fw_st
)) {
720 for (i
= 0; i
< fw_buf
->nr_pages
; i
++)
721 __free_page(fw_buf
->pages
[i
]);
722 vfree(fw_buf
->pages
);
723 fw_buf
->pages
= NULL
;
724 fw_buf
->page_array_size
= 0;
725 fw_buf
->nr_pages
= 0;
726 fw_state_start(&fw_buf
->fw_st
);
730 if (fw_state_is_loading(&fw_buf
->fw_st
)) {
734 * Several loading requests may be pending on
735 * one same firmware buf, so let all requests
736 * see the mapped 'buf->data' once the loading
739 rc
= fw_map_pages_buf(fw_buf
);
741 dev_err(dev
, "%s: map pages failed\n",
744 rc
= security_kernel_post_read_file(NULL
,
745 fw_buf
->data
, fw_buf
->size
,
749 * Same logic as fw_load_abort, only the DONE bit
750 * is ignored and we set ABORT only on failure.
752 list_del_init(&fw_buf
->pending_list
);
754 fw_state_aborted(&fw_buf
->fw_st
);
757 fw_state_done(&fw_buf
->fw_st
);
763 dev_err(dev
, "%s: unexpected value (%d)\n", __func__
, loading
);
766 fw_load_abort(fw_priv
);
770 mutex_unlock(&fw_lock
);
774 static DEVICE_ATTR(loading
, 0644, firmware_loading_show
, firmware_loading_store
);
776 static void firmware_rw_buf(struct firmware_buf
*buf
, char *buffer
,
777 loff_t offset
, size_t count
, bool read
)
780 memcpy(buffer
, buf
->data
+ offset
, count
);
782 memcpy(buf
->data
+ offset
, buffer
, count
);
785 static void firmware_rw(struct firmware_buf
*buf
, char *buffer
,
786 loff_t offset
, size_t count
, bool read
)
790 int page_nr
= offset
>> PAGE_SHIFT
;
791 int page_ofs
= offset
& (PAGE_SIZE
-1);
792 int page_cnt
= min_t(size_t, PAGE_SIZE
- page_ofs
, count
);
794 page_data
= kmap(buf
->pages
[page_nr
]);
797 memcpy(buffer
, page_data
+ page_ofs
, page_cnt
);
799 memcpy(page_data
+ page_ofs
, buffer
, page_cnt
);
801 kunmap(buf
->pages
[page_nr
]);
808 static ssize_t
firmware_data_read(struct file
*filp
, struct kobject
*kobj
,
809 struct bin_attribute
*bin_attr
,
810 char *buffer
, loff_t offset
, size_t count
)
812 struct device
*dev
= kobj_to_dev(kobj
);
813 struct firmware_priv
*fw_priv
= to_firmware_priv(dev
);
814 struct firmware_buf
*buf
;
817 mutex_lock(&fw_lock
);
819 if (!buf
|| fw_state_is_done(&buf
->fw_st
)) {
823 if (offset
> buf
->size
) {
827 if (count
> buf
->size
- offset
)
828 count
= buf
->size
- offset
;
833 firmware_rw_buf(buf
, buffer
, offset
, count
, true);
835 firmware_rw(buf
, buffer
, offset
, count
, true);
838 mutex_unlock(&fw_lock
);
842 static int fw_realloc_buffer(struct firmware_priv
*fw_priv
, int min_size
)
844 struct firmware_buf
*buf
= fw_priv
->buf
;
845 int pages_needed
= PAGE_ALIGN(min_size
) >> PAGE_SHIFT
;
847 /* If the array of pages is too small, grow it... */
848 if (buf
->page_array_size
< pages_needed
) {
849 int new_array_size
= max(pages_needed
,
850 buf
->page_array_size
* 2);
851 struct page
**new_pages
;
853 new_pages
= vmalloc(new_array_size
* sizeof(void *));
855 fw_load_abort(fw_priv
);
858 memcpy(new_pages
, buf
->pages
,
859 buf
->page_array_size
* sizeof(void *));
860 memset(&new_pages
[buf
->page_array_size
], 0, sizeof(void *) *
861 (new_array_size
- buf
->page_array_size
));
863 buf
->pages
= new_pages
;
864 buf
->page_array_size
= new_array_size
;
867 while (buf
->nr_pages
< pages_needed
) {
868 buf
->pages
[buf
->nr_pages
] =
869 alloc_page(GFP_KERNEL
| __GFP_HIGHMEM
);
871 if (!buf
->pages
[buf
->nr_pages
]) {
872 fw_load_abort(fw_priv
);
881 * firmware_data_write - write method for firmware
882 * @filp: open sysfs file
883 * @kobj: kobject for the device
884 * @bin_attr: bin_attr structure
885 * @buffer: buffer being written
886 * @offset: buffer offset for write in total data store area
887 * @count: buffer size
889 * Data written to the 'data' attribute will be later handed to
890 * the driver as a firmware image.
892 static ssize_t
firmware_data_write(struct file
*filp
, struct kobject
*kobj
,
893 struct bin_attribute
*bin_attr
,
894 char *buffer
, loff_t offset
, size_t count
)
896 struct device
*dev
= kobj_to_dev(kobj
);
897 struct firmware_priv
*fw_priv
= to_firmware_priv(dev
);
898 struct firmware_buf
*buf
;
901 if (!capable(CAP_SYS_RAWIO
))
904 mutex_lock(&fw_lock
);
906 if (!buf
|| fw_state_is_done(&buf
->fw_st
)) {
912 if (offset
+ count
> buf
->allocated_size
) {
916 firmware_rw_buf(buf
, buffer
, offset
, count
, false);
919 retval
= fw_realloc_buffer(fw_priv
, offset
+ count
);
924 firmware_rw(buf
, buffer
, offset
, count
, false);
927 buf
->size
= max_t(size_t, offset
+ count
, buf
->size
);
929 mutex_unlock(&fw_lock
);
933 static struct bin_attribute firmware_attr_data
= {
934 .attr
= { .name
= "data", .mode
= 0644 },
936 .read
= firmware_data_read
,
937 .write
= firmware_data_write
,
940 static struct attribute
*fw_dev_attrs
[] = {
941 &dev_attr_loading
.attr
,
945 static struct bin_attribute
*fw_dev_bin_attrs
[] = {
950 static const struct attribute_group fw_dev_attr_group
= {
951 .attrs
= fw_dev_attrs
,
952 .bin_attrs
= fw_dev_bin_attrs
,
955 static const struct attribute_group
*fw_dev_attr_groups
[] = {
960 static struct firmware_priv
*
961 fw_create_instance(struct firmware
*firmware
, const char *fw_name
,
962 struct device
*device
, unsigned int opt_flags
)
964 struct firmware_priv
*fw_priv
;
965 struct device
*f_dev
;
967 fw_priv
= kzalloc(sizeof(*fw_priv
), GFP_KERNEL
);
969 fw_priv
= ERR_PTR(-ENOMEM
);
973 fw_priv
->nowait
= !!(opt_flags
& FW_OPT_NOWAIT
);
974 fw_priv
->fw
= firmware
;
975 f_dev
= &fw_priv
->dev
;
977 device_initialize(f_dev
);
978 dev_set_name(f_dev
, "%s", fw_name
);
979 f_dev
->parent
= device
;
980 f_dev
->class = &firmware_class
;
981 f_dev
->groups
= fw_dev_attr_groups
;
986 /* load a firmware via user helper */
987 static int _request_firmware_load(struct firmware_priv
*fw_priv
,
988 unsigned int opt_flags
, long timeout
)
991 struct device
*f_dev
= &fw_priv
->dev
;
992 struct firmware_buf
*buf
= fw_priv
->buf
;
994 /* fall back on userspace loading */
996 buf
->is_paged_buf
= true;
998 dev_set_uevent_suppress(f_dev
, true);
1000 retval
= device_add(f_dev
);
1002 dev_err(f_dev
, "%s: device_register failed\n", __func__
);
1006 mutex_lock(&fw_lock
);
1007 list_add(&buf
->pending_list
, &pending_fw_head
);
1008 mutex_unlock(&fw_lock
);
1010 if (opt_flags
& FW_OPT_UEVENT
) {
1011 buf
->need_uevent
= true;
1012 dev_set_uevent_suppress(f_dev
, false);
1013 dev_dbg(f_dev
, "firmware: requesting %s\n", buf
->fw_id
);
1014 kobject_uevent(&fw_priv
->dev
.kobj
, KOBJ_ADD
);
1016 timeout
= MAX_JIFFY_OFFSET
;
1019 retval
= fw_state_wait_timeout(&buf
->fw_st
, timeout
);
1021 mutex_lock(&fw_lock
);
1022 fw_load_abort(fw_priv
);
1023 mutex_unlock(&fw_lock
);
1026 if (fw_state_is_aborted(&buf
->fw_st
))
1028 else if (buf
->is_paged_buf
&& !buf
->data
)
1037 static int fw_load_from_user_helper(struct firmware
*firmware
,
1038 const char *name
, struct device
*device
,
1039 unsigned int opt_flags
, long timeout
)
1041 struct firmware_priv
*fw_priv
;
1043 fw_priv
= fw_create_instance(firmware
, name
, device
, opt_flags
);
1044 if (IS_ERR(fw_priv
))
1045 return PTR_ERR(fw_priv
);
1047 fw_priv
->buf
= firmware
->priv
;
1048 return _request_firmware_load(fw_priv
, opt_flags
, timeout
);
1051 #ifdef CONFIG_PM_SLEEP
1052 /* kill pending requests without uevent to avoid blocking suspend */
1053 static void kill_requests_without_uevent(void)
1055 struct firmware_buf
*buf
;
1056 struct firmware_buf
*next
;
1058 mutex_lock(&fw_lock
);
1059 list_for_each_entry_safe(buf
, next
, &pending_fw_head
, pending_list
) {
1060 if (!buf
->need_uevent
)
1061 __fw_load_abort(buf
);
1063 mutex_unlock(&fw_lock
);
1067 #else /* CONFIG_FW_LOADER_USER_HELPER */
1069 fw_load_from_user_helper(struct firmware
*firmware
, const char *name
,
1070 struct device
*device
, unsigned int opt_flags
,
1076 #ifdef CONFIG_PM_SLEEP
1077 static inline void kill_requests_without_uevent(void) { }
1080 #endif /* CONFIG_FW_LOADER_USER_HELPER */
1082 /* prepare firmware and firmware_buf structs;
1083 * return 0 if a firmware is already assigned, 1 if need to load one,
1084 * or a negative error code
1087 _request_firmware_prepare(struct firmware
**firmware_p
, const char *name
,
1088 struct device
*device
, void *dbuf
, size_t size
)
1090 struct firmware
*firmware
;
1091 struct firmware_buf
*buf
;
1094 *firmware_p
= firmware
= kzalloc(sizeof(*firmware
), GFP_KERNEL
);
1096 dev_err(device
, "%s: kmalloc(struct firmware) failed\n",
1101 if (fw_get_builtin_firmware(firmware
, name
, dbuf
, size
)) {
1102 dev_dbg(device
, "using built-in %s\n", name
);
1103 return 0; /* assigned */
1106 ret
= fw_lookup_and_allocate_buf(name
, &fw_cache
, &buf
, dbuf
, size
);
1109 * bind with 'buf' now to avoid warning in failure path
1110 * of requesting firmware.
1112 firmware
->priv
= buf
;
1115 ret
= fw_state_wait(&buf
->fw_st
);
1117 fw_set_page_data(buf
, firmware
);
1118 return 0; /* assigned */
1124 return 1; /* need to load */
1127 static int assign_firmware_buf(struct firmware
*fw
, struct device
*device
,
1128 unsigned int opt_flags
)
1130 struct firmware_buf
*buf
= fw
->priv
;
1132 mutex_lock(&fw_lock
);
1133 if (!buf
->size
|| fw_state_is_aborted(&buf
->fw_st
)) {
1134 mutex_unlock(&fw_lock
);
1139 * add firmware name into devres list so that we can auto cache
1140 * and uncache firmware for device.
1142 * device may has been deleted already, but the problem
1143 * should be fixed in devres or driver core.
1145 /* don't cache firmware handled without uevent */
1146 if (device
&& (opt_flags
& FW_OPT_UEVENT
) &&
1147 !(opt_flags
& FW_OPT_NOCACHE
))
1148 fw_add_devm_name(device
, buf
->fw_id
);
1151 * After caching firmware image is started, let it piggyback
1152 * on request firmware.
1154 if (!(opt_flags
& FW_OPT_NOCACHE
) &&
1155 buf
->fwc
->state
== FW_LOADER_START_CACHE
) {
1156 if (fw_cache_piggyback_on_request(buf
->fw_id
))
1157 kref_get(&buf
->ref
);
1160 /* pass the pages buffer to driver at the last minute */
1161 fw_set_page_data(buf
, fw
);
1162 mutex_unlock(&fw_lock
);
1166 /* called from request_firmware() and request_firmware_work_func() */
1168 _request_firmware(const struct firmware
**firmware_p
, const char *name
,
1169 struct device
*device
, void *buf
, size_t size
,
1170 unsigned int opt_flags
)
1172 struct firmware
*fw
= NULL
;
1179 if (!name
|| name
[0] == '\0') {
1184 ret
= _request_firmware_prepare(&fw
, name
, device
, buf
, size
);
1185 if (ret
<= 0) /* error or already assigned */
1189 timeout
= firmware_loading_timeout();
1190 if (opt_flags
& FW_OPT_NOWAIT
) {
1191 timeout
= usermodehelper_read_lock_wait(timeout
);
1193 dev_dbg(device
, "firmware: %s loading timed out\n",
1199 ret
= usermodehelper_read_trylock();
1201 dev_err(device
, "firmware: %s will not be loaded\n",
1207 ret
= fw_get_filesystem_firmware(device
, fw
->priv
);
1209 if (!(opt_flags
& FW_OPT_NO_WARN
))
1211 "Direct firmware load for %s failed with error %d\n",
1213 if (opt_flags
& FW_OPT_USERHELPER
) {
1214 dev_warn(device
, "Falling back to user helper\n");
1215 ret
= fw_load_from_user_helper(fw
, name
, device
,
1216 opt_flags
, timeout
);
1221 ret
= assign_firmware_buf(fw
, device
, opt_flags
);
1223 usermodehelper_read_unlock();
1227 release_firmware(fw
);
1236 * request_firmware: - send firmware request and wait for it
1237 * @firmware_p: pointer to firmware image
1238 * @name: name of firmware file
1239 * @device: device for which firmware is being loaded
1241 * @firmware_p will be used to return a firmware image by the name
1242 * of @name for device @device.
1244 * Should be called from user context where sleeping is allowed.
1246 * @name will be used as $FIRMWARE in the uevent environment and
1247 * should be distinctive enough not to be confused with any other
1248 * firmware image for this or any other device.
1250 * Caller must hold the reference count of @device.
1252 * The function can be called safely inside device's suspend and
1256 request_firmware(const struct firmware
**firmware_p
, const char *name
,
1257 struct device
*device
)
1261 /* Need to pin this module until return */
1262 __module_get(THIS_MODULE
);
1263 ret
= _request_firmware(firmware_p
, name
, device
, NULL
, 0,
1264 FW_OPT_UEVENT
| FW_OPT_FALLBACK
);
1265 module_put(THIS_MODULE
);
1268 EXPORT_SYMBOL(request_firmware
);
1271 * request_firmware_direct: - load firmware directly without usermode helper
1272 * @firmware_p: pointer to firmware image
1273 * @name: name of firmware file
1274 * @device: device for which firmware is being loaded
1276 * This function works pretty much like request_firmware(), but this doesn't
1277 * fall back to usermode helper even if the firmware couldn't be loaded
1278 * directly from fs. Hence it's useful for loading optional firmwares, which
1279 * aren't always present, without extra long timeouts of udev.
1281 int request_firmware_direct(const struct firmware
**firmware_p
,
1282 const char *name
, struct device
*device
)
1286 __module_get(THIS_MODULE
);
1287 ret
= _request_firmware(firmware_p
, name
, device
, NULL
, 0,
1288 FW_OPT_UEVENT
| FW_OPT_NO_WARN
);
1289 module_put(THIS_MODULE
);
1292 EXPORT_SYMBOL_GPL(request_firmware_direct
);
1295 * request_firmware_into_buf - load firmware into a previously allocated buffer
1296 * @firmware_p: pointer to firmware image
1297 * @name: name of firmware file
1298 * @device: device for which firmware is being loaded and DMA region allocated
1299 * @buf: address of buffer to load firmware into
1300 * @size: size of buffer
1302 * This function works pretty much like request_firmware(), but it doesn't
1303 * allocate a buffer to hold the firmware data. Instead, the firmware
1304 * is loaded directly into the buffer pointed to by @buf and the @firmware_p
1305 * data member is pointed at @buf.
1307 * This function doesn't cache firmware either.
1310 request_firmware_into_buf(const struct firmware
**firmware_p
, const char *name
,
1311 struct device
*device
, void *buf
, size_t size
)
1315 __module_get(THIS_MODULE
);
1316 ret
= _request_firmware(firmware_p
, name
, device
, buf
, size
,
1317 FW_OPT_UEVENT
| FW_OPT_FALLBACK
|
1319 module_put(THIS_MODULE
);
1322 EXPORT_SYMBOL(request_firmware_into_buf
);
1325 * release_firmware: - release the resource associated with a firmware image
1326 * @fw: firmware resource to release
1328 void release_firmware(const struct firmware
*fw
)
1331 if (!fw_is_builtin_firmware(fw
))
1332 firmware_free_data(fw
);
1336 EXPORT_SYMBOL(release_firmware
);
1339 struct firmware_work
{
1340 struct work_struct work
;
1341 struct module
*module
;
1343 struct device
*device
;
1345 void (*cont
)(const struct firmware
*fw
, void *context
);
1346 unsigned int opt_flags
;
1349 static void request_firmware_work_func(struct work_struct
*work
)
1351 struct firmware_work
*fw_work
;
1352 const struct firmware
*fw
;
1354 fw_work
= container_of(work
, struct firmware_work
, work
);
1356 _request_firmware(&fw
, fw_work
->name
, fw_work
->device
, NULL
, 0,
1357 fw_work
->opt_flags
);
1358 fw_work
->cont(fw
, fw_work
->context
);
1359 put_device(fw_work
->device
); /* taken in request_firmware_nowait() */
1361 module_put(fw_work
->module
);
1362 kfree_const(fw_work
->name
);
1367 * request_firmware_nowait - asynchronous version of request_firmware
1368 * @module: module requesting the firmware
1369 * @uevent: sends uevent to copy the firmware image if this flag
1370 * is non-zero else the firmware copy must be done manually.
1371 * @name: name of firmware file
1372 * @device: device for which firmware is being loaded
1373 * @gfp: allocation flags
1374 * @context: will be passed over to @cont, and
1375 * @fw may be %NULL if firmware request fails.
1376 * @cont: function will be called asynchronously when the firmware
1379 * Caller must hold the reference count of @device.
1381 * Asynchronous variant of request_firmware() for user contexts:
1382 * - sleep for as small periods as possible since it may
1383 * increase kernel boot time of built-in device drivers
1384 * requesting firmware in their ->probe() methods, if
1385 * @gfp is GFP_KERNEL.
1387 * - can't sleep at all if @gfp is GFP_ATOMIC.
1390 request_firmware_nowait(
1391 struct module
*module
, bool uevent
,
1392 const char *name
, struct device
*device
, gfp_t gfp
, void *context
,
1393 void (*cont
)(const struct firmware
*fw
, void *context
))
1395 struct firmware_work
*fw_work
;
1397 fw_work
= kzalloc(sizeof(struct firmware_work
), gfp
);
1401 fw_work
->module
= module
;
1402 fw_work
->name
= kstrdup_const(name
, gfp
);
1403 if (!fw_work
->name
) {
1407 fw_work
->device
= device
;
1408 fw_work
->context
= context
;
1409 fw_work
->cont
= cont
;
1410 fw_work
->opt_flags
= FW_OPT_NOWAIT
| FW_OPT_FALLBACK
|
1411 (uevent
? FW_OPT_UEVENT
: FW_OPT_USERHELPER
);
1413 if (!try_module_get(module
)) {
1414 kfree_const(fw_work
->name
);
1419 get_device(fw_work
->device
);
1420 INIT_WORK(&fw_work
->work
, request_firmware_work_func
);
1421 schedule_work(&fw_work
->work
);
1424 EXPORT_SYMBOL(request_firmware_nowait
);
1426 #ifdef CONFIG_PM_SLEEP
1427 static ASYNC_DOMAIN_EXCLUSIVE(fw_cache_domain
);
1430 * cache_firmware - cache one firmware image in kernel memory space
1431 * @fw_name: the firmware image name
1433 * Cache firmware in kernel memory so that drivers can use it when
1434 * system isn't ready for them to request firmware image from userspace.
1435 * Once it returns successfully, driver can use request_firmware or its
1436 * nowait version to get the cached firmware without any interacting
1439 * Return 0 if the firmware image has been cached successfully
1440 * Return !0 otherwise
1443 static int cache_firmware(const char *fw_name
)
1446 const struct firmware
*fw
;
1448 pr_debug("%s: %s\n", __func__
, fw_name
);
1450 ret
= request_firmware(&fw
, fw_name
, NULL
);
1454 pr_debug("%s: %s ret=%d\n", __func__
, fw_name
, ret
);
1459 static struct firmware_buf
*fw_lookup_buf(const char *fw_name
)
1461 struct firmware_buf
*tmp
;
1462 struct firmware_cache
*fwc
= &fw_cache
;
1464 spin_lock(&fwc
->lock
);
1465 tmp
= __fw_lookup_buf(fw_name
);
1466 spin_unlock(&fwc
->lock
);
1472 * uncache_firmware - remove one cached firmware image
1473 * @fw_name: the firmware image name
1475 * Uncache one firmware image which has been cached successfully
1478 * Return 0 if the firmware cache has been removed successfully
1479 * Return !0 otherwise
1482 static int uncache_firmware(const char *fw_name
)
1484 struct firmware_buf
*buf
;
1487 pr_debug("%s: %s\n", __func__
, fw_name
);
1489 if (fw_get_builtin_firmware(&fw
, fw_name
, NULL
, 0))
1492 buf
= fw_lookup_buf(fw_name
);
1501 static struct fw_cache_entry
*alloc_fw_cache_entry(const char *name
)
1503 struct fw_cache_entry
*fce
;
1505 fce
= kzalloc(sizeof(*fce
), GFP_ATOMIC
);
1509 fce
->name
= kstrdup_const(name
, GFP_ATOMIC
);
1519 static int __fw_entry_found(const char *name
)
1521 struct firmware_cache
*fwc
= &fw_cache
;
1522 struct fw_cache_entry
*fce
;
1524 list_for_each_entry(fce
, &fwc
->fw_names
, list
) {
1525 if (!strcmp(fce
->name
, name
))
1531 static int fw_cache_piggyback_on_request(const char *name
)
1533 struct firmware_cache
*fwc
= &fw_cache
;
1534 struct fw_cache_entry
*fce
;
1537 spin_lock(&fwc
->name_lock
);
1538 if (__fw_entry_found(name
))
1541 fce
= alloc_fw_cache_entry(name
);
1544 list_add(&fce
->list
, &fwc
->fw_names
);
1545 pr_debug("%s: fw: %s\n", __func__
, name
);
1548 spin_unlock(&fwc
->name_lock
);
1552 static void free_fw_cache_entry(struct fw_cache_entry
*fce
)
1554 kfree_const(fce
->name
);
1558 static void __async_dev_cache_fw_image(void *fw_entry
,
1559 async_cookie_t cookie
)
1561 struct fw_cache_entry
*fce
= fw_entry
;
1562 struct firmware_cache
*fwc
= &fw_cache
;
1565 ret
= cache_firmware(fce
->name
);
1567 spin_lock(&fwc
->name_lock
);
1568 list_del(&fce
->list
);
1569 spin_unlock(&fwc
->name_lock
);
1571 free_fw_cache_entry(fce
);
1575 /* called with dev->devres_lock held */
1576 static void dev_create_fw_entry(struct device
*dev
, void *res
,
1579 struct fw_name_devm
*fwn
= res
;
1580 const char *fw_name
= fwn
->name
;
1581 struct list_head
*head
= data
;
1582 struct fw_cache_entry
*fce
;
1584 fce
= alloc_fw_cache_entry(fw_name
);
1586 list_add(&fce
->list
, head
);
1589 static int devm_name_match(struct device
*dev
, void *res
,
1592 struct fw_name_devm
*fwn
= res
;
1593 return (fwn
->magic
== (unsigned long)match_data
);
1596 static void dev_cache_fw_image(struct device
*dev
, void *data
)
1599 struct fw_cache_entry
*fce
;
1600 struct fw_cache_entry
*fce_next
;
1601 struct firmware_cache
*fwc
= &fw_cache
;
1603 devres_for_each_res(dev
, fw_name_devm_release
,
1604 devm_name_match
, &fw_cache
,
1605 dev_create_fw_entry
, &todo
);
1607 list_for_each_entry_safe(fce
, fce_next
, &todo
, list
) {
1608 list_del(&fce
->list
);
1610 spin_lock(&fwc
->name_lock
);
1611 /* only one cache entry for one firmware */
1612 if (!__fw_entry_found(fce
->name
)) {
1613 list_add(&fce
->list
, &fwc
->fw_names
);
1615 free_fw_cache_entry(fce
);
1618 spin_unlock(&fwc
->name_lock
);
1621 async_schedule_domain(__async_dev_cache_fw_image
,
1627 static void __device_uncache_fw_images(void)
1629 struct firmware_cache
*fwc
= &fw_cache
;
1630 struct fw_cache_entry
*fce
;
1632 spin_lock(&fwc
->name_lock
);
1633 while (!list_empty(&fwc
->fw_names
)) {
1634 fce
= list_entry(fwc
->fw_names
.next
,
1635 struct fw_cache_entry
, list
);
1636 list_del(&fce
->list
);
1637 spin_unlock(&fwc
->name_lock
);
1639 uncache_firmware(fce
->name
);
1640 free_fw_cache_entry(fce
);
1642 spin_lock(&fwc
->name_lock
);
1644 spin_unlock(&fwc
->name_lock
);
1648 * device_cache_fw_images - cache devices' firmware
1650 * If one device called request_firmware or its nowait version
1651 * successfully before, the firmware names are recored into the
1652 * device's devres link list, so device_cache_fw_images can call
1653 * cache_firmware() to cache these firmwares for the device,
1654 * then the device driver can load its firmwares easily at
1655 * time when system is not ready to complete loading firmware.
1657 static void device_cache_fw_images(void)
1659 struct firmware_cache
*fwc
= &fw_cache
;
1663 pr_debug("%s\n", __func__
);
1665 /* cancel uncache work */
1666 cancel_delayed_work_sync(&fwc
->work
);
1669 * use small loading timeout for caching devices' firmware
1670 * because all these firmware images have been loaded
1671 * successfully at lease once, also system is ready for
1672 * completing firmware loading now. The maximum size of
1673 * firmware in current distributions is about 2M bytes,
1674 * so 10 secs should be enough.
1676 old_timeout
= loading_timeout
;
1677 loading_timeout
= 10;
1679 mutex_lock(&fw_lock
);
1680 fwc
->state
= FW_LOADER_START_CACHE
;
1681 dpm_for_each_dev(NULL
, dev_cache_fw_image
);
1682 mutex_unlock(&fw_lock
);
1684 /* wait for completion of caching firmware for all devices */
1685 async_synchronize_full_domain(&fw_cache_domain
);
1687 loading_timeout
= old_timeout
;
1691 * device_uncache_fw_images - uncache devices' firmware
1693 * uncache all firmwares which have been cached successfully
1694 * by device_uncache_fw_images earlier
1696 static void device_uncache_fw_images(void)
1698 pr_debug("%s\n", __func__
);
1699 __device_uncache_fw_images();
1702 static void device_uncache_fw_images_work(struct work_struct
*work
)
1704 device_uncache_fw_images();
1708 * device_uncache_fw_images_delay - uncache devices firmwares
1709 * @delay: number of milliseconds to delay uncache device firmwares
1711 * uncache all devices's firmwares which has been cached successfully
1712 * by device_cache_fw_images after @delay milliseconds.
1714 static void device_uncache_fw_images_delay(unsigned long delay
)
1716 queue_delayed_work(system_power_efficient_wq
, &fw_cache
.work
,
1717 msecs_to_jiffies(delay
));
1720 static int fw_pm_notify(struct notifier_block
*notify_block
,
1721 unsigned long mode
, void *unused
)
1724 case PM_HIBERNATION_PREPARE
:
1725 case PM_SUSPEND_PREPARE
:
1726 case PM_RESTORE_PREPARE
:
1727 kill_requests_without_uevent();
1728 device_cache_fw_images();
1731 case PM_POST_SUSPEND
:
1732 case PM_POST_HIBERNATION
:
1733 case PM_POST_RESTORE
:
1735 * In case that system sleep failed and syscore_suspend is
1738 mutex_lock(&fw_lock
);
1739 fw_cache
.state
= FW_LOADER_NO_CACHE
;
1740 mutex_unlock(&fw_lock
);
1742 device_uncache_fw_images_delay(10 * MSEC_PER_SEC
);
1749 /* stop caching firmware once syscore_suspend is reached */
1750 static int fw_suspend(void)
1752 fw_cache
.state
= FW_LOADER_NO_CACHE
;
1756 static struct syscore_ops fw_syscore_ops
= {
1757 .suspend
= fw_suspend
,
1760 static int fw_cache_piggyback_on_request(const char *name
)
1766 static void __init
fw_cache_init(void)
1768 spin_lock_init(&fw_cache
.lock
);
1769 INIT_LIST_HEAD(&fw_cache
.head
);
1770 fw_cache
.state
= FW_LOADER_NO_CACHE
;
1772 #ifdef CONFIG_PM_SLEEP
1773 spin_lock_init(&fw_cache
.name_lock
);
1774 INIT_LIST_HEAD(&fw_cache
.fw_names
);
1776 INIT_DELAYED_WORK(&fw_cache
.work
,
1777 device_uncache_fw_images_work
);
1779 fw_cache
.pm_notify
.notifier_call
= fw_pm_notify
;
1780 register_pm_notifier(&fw_cache
.pm_notify
);
1782 register_syscore_ops(&fw_syscore_ops
);
1786 static int __init
firmware_class_init(void)
1789 #ifdef CONFIG_FW_LOADER_USER_HELPER
1790 register_reboot_notifier(&fw_shutdown_nb
);
1791 return class_register(&firmware_class
);
1797 static void __exit
firmware_class_exit(void)
1799 #ifdef CONFIG_PM_SLEEP
1800 unregister_syscore_ops(&fw_syscore_ops
);
1801 unregister_pm_notifier(&fw_cache
.pm_notify
);
1803 #ifdef CONFIG_FW_LOADER_USER_HELPER
1804 unregister_reboot_notifier(&fw_shutdown_nb
);
1805 class_unregister(&firmware_class
);
1809 fs_initcall(firmware_class_init
);
1810 module_exit(firmware_class_exit
);