compat: Fix autoconf probe for pcie_mpss
[~emulex/for-vlad/old/compat.git] / compat / compat_firmware_class.c
1 /*
2  * firmware_class.c - Multi purpose firmware loading support
3  *
4  * Copyright (c) 2003 Manuel Estrada Sainz
5  *
6  * Please see Documentation/firmware_class/ for more information.
7  *
8  */
9
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/kthread.h>
20 #include <linux/highmem.h>
21 #include <linux/firmware.h>
22 #include <linux/slab.h>
23
24 #define backport_firmware_to_dev(obj) container_of(obj, struct device, kobj)
25
26 MODULE_AUTHOR("Manuel Estrada Sainz");
27 MODULE_DESCRIPTION("Multi purpose firmware loading support");
28 MODULE_LICENSE("GPL");
29
30 /* Builtin firmware support */
31
32 //#ifdef CONFIG_FW_LOADER
33 #if 0
34
35 extern struct builtin_fw __start_builtin_fw[];
36 extern struct builtin_fw __end_builtin_fw[];
37
38 static bool fw_get_builtin_firmware(struct firmware *fw, const char *name)
39 {
40         struct builtin_fw *b_fw;
41
42         for (b_fw = __start_builtin_fw; b_fw != __end_builtin_fw; b_fw++) {
43                 if (strcmp(name, b_fw->name) == 0) {
44                         fw->size = b_fw->size;
45                         fw->data = b_fw->data;
46                         return true;
47                 }
48         }
49
50         return false;
51 }
52
53 static bool fw_is_builtin_firmware(const struct firmware *fw)
54 {
55         struct builtin_fw *b_fw;
56
57         for (b_fw = __start_builtin_fw; b_fw != __end_builtin_fw; b_fw++)
58                 if (fw->data == b_fw->data)
59                         return true;
60
61         return false;
62 }
63
64 #else /* Module case - no builtin firmware support */
65
66 static inline bool fw_get_builtin_firmware(struct firmware *fw, const char *name)
67 {
68         return false;
69 }
70
71 static inline bool fw_is_builtin_firmware(const struct firmware *fw)
72 {
73         return false;
74 }
75 #endif
76
77 enum {
78         FW_STATUS_LOADING,
79         FW_STATUS_DONE,
80         FW_STATUS_ABORT,
81 };
82
83 static int loading_timeout = 60;        /* In seconds */
84
85 /* fw_lock could be moved to 'struct firmware_priv' but since it is just
86  * guarding for corner cases a global lock should be OK */
87 static DEFINE_MUTEX(fw_lock);
88
89 struct firmware_priv {
90         struct completion completion;
91         struct firmware *fw;
92         unsigned long status;
93         struct page **pages;
94         int nr_pages;
95         int page_array_size;
96         struct timer_list timeout;
97         struct device dev;
98         bool nowait;
99         char fw_id[];
100 };
101
102 static struct firmware_priv *to_firmware_priv(struct device *dev)
103 {
104         return container_of(dev, struct firmware_priv, dev);
105 }
106
107 static void fw_load_abort(struct firmware_priv *fw_priv)
108 {
109         set_bit(FW_STATUS_ABORT, &fw_priv->status);
110         wmb();
111         complete(&fw_priv->completion);
112 }
113
114 static ssize_t firmware_timeout_show(struct class *class,
115                                      char *buf)
116 {
117         return sprintf(buf, "%d\n", loading_timeout);
118 }
119
120 /**
121  * firmware_timeout_store - set number of seconds to wait for firmware
122  * @class: device class pointer
123  * @buf: buffer to scan for timeout value
124  * @count: number of bytes in @buf
125  *
126  *      Sets the number of seconds to wait for the firmware.  Once
127  *      this expires an error will be returned to the driver and no
128  *      firmware will be provided.
129  *
130  *      Note: zero means 'wait forever'.
131  **/
132 static ssize_t firmware_timeout_store(struct class *class,
133                                       const char *buf, size_t count)
134 {
135         loading_timeout = simple_strtol(buf, NULL, 10);
136         if (loading_timeout < 0)
137                 loading_timeout = 0;
138
139         return count;
140 }
141
142 static struct class_attribute firmware_class_attrs[] = {
143         __ATTR(timeout, S_IWUSR | S_IRUGO,
144                 firmware_timeout_show, firmware_timeout_store),
145         __ATTR_NULL
146 };
147
148 static void fw_dev_release(struct device *dev)
149 {
150         struct firmware_priv *fw_priv = to_firmware_priv(dev);
151         int i;
152
153         for (i = 0; i < fw_priv->nr_pages; i++)
154                 __free_page(fw_priv->pages[i]);
155         kfree(fw_priv->pages);
156         kfree(fw_priv);
157
158         module_put(THIS_MODULE);
159 }
160
161 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24))
162 static int firmware_uevent(struct device *dev, struct kobj_uevent_env *env)
163 {
164         struct firmware_priv *fw_priv = to_firmware_priv(dev);
165
166         if (add_uevent_var(env, "FIRMWARE=%s", fw_priv->fw_id))
167                 return -ENOMEM;
168         if (add_uevent_var(env, "TIMEOUT=%i", loading_timeout))
169                 return -ENOMEM;
170         if (add_uevent_var(env, "ASYNC=%d", fw_priv->nowait))
171                 return -ENOMEM;
172
173         return 0;
174 }
175 #else
176 static int firmware_uevent(struct device *dev, char **envp,
177                            int num_envp, char *buf, int size)
178 {
179         struct firmware_priv *fw_priv = to_firmware_priv(dev);
180         int error, len = 0, i = 0;
181
182         error = add_uevent_var(envp, num_envp, &i,
183                                buf, size, &len,
184                                "FIRMWARE=%s", fw_priv->fw_id);
185         if (error)
186                 goto exit;
187
188         error = add_uevent_var(envp, num_envp, &i,
189                                buf, size, &len,
190                                "TIMEOUT=%i", loading_timeout);
191         if (error)
192                 goto exit;
193         error = add_uevent_var(envp, num_envp, &i,
194                                buf, size, &len,
195                                "ASYNC=%i", fw_priv->nowait);
196         if (error)
197                 goto exit;
198
199         return 0;
200 exit:
201         envp[i] = NULL;
202         return error;
203 }
204 #endif
205
206 static struct class firmware_class = {
207         .name           = "compat_firmware",
208         .class_attrs    = firmware_class_attrs,
209         .dev_uevent     = firmware_uevent,
210         .dev_release    = fw_dev_release,
211 };
212
213 static ssize_t firmware_loading_show(struct device *dev,
214                                      struct device_attribute *attr, char *buf)
215 {
216         struct firmware_priv *fw_priv = to_firmware_priv(dev);
217         int loading = test_bit(FW_STATUS_LOADING, &fw_priv->status);
218
219         return sprintf(buf, "%d\n", loading);
220 }
221
222 static void firmware_free_data(const struct firmware *fw)
223 {
224 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
225         int i;
226         vunmap(fw->data);
227         if (fw->pages) {
228                 for (i = 0; i < PFN_UP(fw->size); i++)
229                         __free_page(fw->pages[i]);
230                 kfree(fw->pages);
231         }
232 #else
233         vunmap(fw->data);
234 #endif
235 }
236
237 /* Some architectures don't have PAGE_KERNEL_RO */
238 #ifndef PAGE_KERNEL_RO
239 #define PAGE_KERNEL_RO PAGE_KERNEL
240 #endif
241 /**
242  * firmware_loading_store - set value in the 'loading' control file
243  * @dev: device pointer
244  * @buf: buffer to scan for loading control value
245  * @count: number of bytes in @buf
246  *
247  *      The relevant values are:
248  *
249  *       1: Start a load, discarding any previous partial load.
250  *       0: Conclude the load and hand the data to the driver code.
251  *      -1: Conclude the load with an error and discard any written data.
252  **/
253 static ssize_t firmware_loading_store(struct device *dev,
254                                       struct device_attribute *attr,
255                                       const char *buf, size_t count)
256 {
257         struct firmware_priv *fw_priv = to_firmware_priv(dev);
258         int loading = simple_strtol(buf, NULL, 10);
259         int i;
260
261         switch (loading) {
262         case 1:
263                 mutex_lock(&fw_lock);
264                 if (!fw_priv->fw) {
265                         mutex_unlock(&fw_lock);
266                         break;
267                 }
268                 firmware_free_data(fw_priv->fw);
269                 memset(fw_priv->fw, 0, sizeof(struct firmware));
270                 /* If the pages are not owned by 'struct firmware' */
271                 for (i = 0; i < fw_priv->nr_pages; i++)
272                         __free_page(fw_priv->pages[i]);
273                 kfree(fw_priv->pages);
274                 fw_priv->pages = NULL;
275                 fw_priv->page_array_size = 0;
276                 fw_priv->nr_pages = 0;
277                 set_bit(FW_STATUS_LOADING, &fw_priv->status);
278                 mutex_unlock(&fw_lock);
279                 break;
280         case 0:
281                 if (test_bit(FW_STATUS_LOADING, &fw_priv->status)) {
282                         vunmap(fw_priv->fw->data);
283                         fw_priv->fw->data = vmap(fw_priv->pages,
284                                                  fw_priv->nr_pages,
285                                                  0, PAGE_KERNEL_RO);
286                         if (!fw_priv->fw->data) {
287                                 dev_err(dev, "%s: vmap() failed\n", __func__);
288                                 goto err;
289                         }
290                         /* Pages are now owned by 'struct firmware' */
291 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
292                         fw_priv->fw->pages = fw_priv->pages;
293                         fw_priv->pages = NULL;
294 #endif
295
296                         fw_priv->page_array_size = 0;
297                         fw_priv->nr_pages = 0;
298                         complete(&fw_priv->completion);
299                         clear_bit(FW_STATUS_LOADING, &fw_priv->status);
300                         break;
301                 }
302                 /* fallthrough */
303         default:
304                 dev_err(dev, "%s: unexpected value (%d)\n", __func__, loading);
305                 /* fallthrough */
306         case -1:
307         err:
308                 fw_load_abort(fw_priv);
309                 break;
310         }
311
312         return count;
313 }
314
315 static DEVICE_ATTR(loading, 0644, firmware_loading_show, firmware_loading_store);
316
317 #if defined(CONFIG_COMPAT_FIRMWARE_DATA_RW_NEEDS_FILP)
318 static ssize_t firmware_data_read(struct file *filp, struct kobject *kobj,
319                                   struct bin_attribute *bin_attr,
320                                   char *buffer, loff_t offset, size_t count)
321 #else
322 static ssize_t firmware_data_read(struct kobject *kobj,
323                                   struct bin_attribute *bin_attr,
324                                   char *buffer, loff_t offset, size_t count)
325 #endif
326 {
327         struct device *dev = backport_firmware_to_dev(kobj);
328         struct firmware_priv *fw_priv = to_firmware_priv(dev);
329         struct firmware *fw;
330         ssize_t ret_count;
331
332         mutex_lock(&fw_lock);
333         fw = fw_priv->fw;
334         if (!fw || test_bit(FW_STATUS_DONE, &fw_priv->status)) {
335                 ret_count = -ENODEV;
336                 goto out;
337         }
338         if (offset > fw->size) {
339                 ret_count = 0;
340                 goto out;
341         }
342         if (count > fw->size - offset)
343                 count = fw->size - offset;
344
345         ret_count = count;
346
347         while (count) {
348                 void *page_data;
349                 int page_nr = offset >> PAGE_SHIFT;
350                 int page_ofs = offset & (PAGE_SIZE-1);
351                 int page_cnt = min_t(size_t, PAGE_SIZE - page_ofs, count);
352
353                 page_data = kmap(fw_priv->pages[page_nr]);
354
355                 memcpy(buffer, page_data + page_ofs, page_cnt);
356
357                 kunmap(fw_priv->pages[page_nr]);
358                 buffer += page_cnt;
359                 offset += page_cnt;
360                 count -= page_cnt;
361         }
362 out:
363         mutex_unlock(&fw_lock);
364         return ret_count;
365 }
366
367 static int fw_realloc_buffer(struct firmware_priv *fw_priv, int min_size)
368 {
369         int pages_needed = ALIGN(min_size, PAGE_SIZE) >> PAGE_SHIFT;
370
371         /* If the array of pages is too small, grow it... */
372         if (fw_priv->page_array_size < pages_needed) {
373                 int new_array_size = max(pages_needed,
374                                          fw_priv->page_array_size * 2);
375                 struct page **new_pages;
376
377                 new_pages = kmalloc(new_array_size * sizeof(void *),
378                                     GFP_KERNEL);
379                 if (!new_pages) {
380                         fw_load_abort(fw_priv);
381                         return -ENOMEM;
382                 }
383                 memcpy(new_pages, fw_priv->pages,
384                        fw_priv->page_array_size * sizeof(void *));
385                 memset(&new_pages[fw_priv->page_array_size], 0, sizeof(void *) *
386                        (new_array_size - fw_priv->page_array_size));
387                 kfree(fw_priv->pages);
388                 fw_priv->pages = new_pages;
389                 fw_priv->page_array_size = new_array_size;
390         }
391
392         while (fw_priv->nr_pages < pages_needed) {
393                 fw_priv->pages[fw_priv->nr_pages] =
394                         alloc_page(GFP_KERNEL | __GFP_HIGHMEM);
395
396                 if (!fw_priv->pages[fw_priv->nr_pages]) {
397                         fw_load_abort(fw_priv);
398                         return -ENOMEM;
399                 }
400                 fw_priv->nr_pages++;
401         }
402         return 0;
403 }
404
405 /**
406  * firmware_data_write - write method for firmware
407  * @kobj: kobject for the device
408  * @bin_attr: bin_attr structure
409  * @buffer: buffer being written
410  * @offset: buffer offset for write in total data store area
411  * @count: buffer size
412  *
413  *      Data written to the 'data' attribute will be later handed to
414  *      the driver as a firmware image.
415  **/
416 #if defined(CONFIG_COMPAT_FIRMWARE_DATA_RW_NEEDS_FILP)
417 static ssize_t firmware_data_write(struct file *filp, struct kobject *kobj,
418                                    struct bin_attribute *bin_attr,
419                                    char *buffer, loff_t offset, size_t count)
420 #else
421 static ssize_t firmware_data_write(struct kobject *kobj,
422                                    struct bin_attribute *bin_attr,
423                                    char *buffer, loff_t offset, size_t count)
424 #endif
425 {
426         struct device *dev = backport_firmware_to_dev(kobj);
427         struct firmware_priv *fw_priv = to_firmware_priv(dev);
428         struct firmware *fw;
429         ssize_t retval;
430
431         if (!capable(CAP_SYS_RAWIO))
432                 return -EPERM;
433
434         mutex_lock(&fw_lock);
435         fw = fw_priv->fw;
436         if (!fw || test_bit(FW_STATUS_DONE, &fw_priv->status)) {
437                 retval = -ENODEV;
438                 goto out;
439         }
440         retval = fw_realloc_buffer(fw_priv, offset + count);
441         if (retval)
442                 goto out;
443
444         retval = count;
445
446         while (count) {
447                 void *page_data;
448                 int page_nr = offset >> PAGE_SHIFT;
449                 int page_ofs = offset & (PAGE_SIZE - 1);
450                 int page_cnt = min_t(size_t, PAGE_SIZE - page_ofs, count);
451
452                 page_data = kmap(fw_priv->pages[page_nr]);
453
454                 memcpy(page_data + page_ofs, buffer, page_cnt);
455
456                 kunmap(fw_priv->pages[page_nr]);
457                 buffer += page_cnt;
458                 offset += page_cnt;
459                 count -= page_cnt;
460         }
461
462         fw->size = max_t(size_t, offset, fw->size);
463 out:
464         mutex_unlock(&fw_lock);
465         return retval;
466 }
467
468 static struct bin_attribute firmware_attr_data = {
469         .attr = { .name = "data", .mode = 0644 },
470         .size = 0,
471         .read = firmware_data_read,
472         .write = firmware_data_write,
473 };
474
475 static void firmware_class_timeout(u_long data)
476 {
477         struct firmware_priv *fw_priv = (struct firmware_priv *) data;
478
479         fw_load_abort(fw_priv);
480 }
481
482 static struct firmware_priv *
483 fw_create_instance(struct firmware *firmware, const char *fw_name,
484                    struct device *device, bool uevent, bool nowait)
485 {
486         struct firmware_priv *fw_priv;
487         struct device *f_dev;
488         int error;
489
490         fw_priv = kzalloc(sizeof(*fw_priv) + strlen(fw_name) + 1 , GFP_KERNEL);
491         if (!fw_priv) {
492                 dev_err(device, "%s: kmalloc failed\n", __func__);
493                 error = -ENOMEM;
494                 goto err_out;
495         }
496
497         fw_priv->fw = firmware;
498         fw_priv->nowait = nowait;
499         strcpy(fw_priv->fw_id, fw_name);
500         init_completion(&fw_priv->completion);
501         setup_timer(&fw_priv->timeout,
502                     firmware_class_timeout, (u_long) fw_priv);
503
504         f_dev = &fw_priv->dev;
505
506         device_initialize(f_dev);
507         dev_set_name(f_dev, "%s", dev_name(device));
508         f_dev->parent = device;
509         f_dev->class = &firmware_class;
510
511         dev_set_uevent_suppress(f_dev, true);
512
513         /* Need to pin this module until class device is destroyed */
514         __module_get(THIS_MODULE);
515
516         error = device_add(f_dev);
517         if (error) {
518                 dev_err(device, "%s: device_register failed\n", __func__);
519                 goto err_put_dev;
520         }
521
522         error = device_create_bin_file(f_dev, &firmware_attr_data);
523         if (error) {
524                 dev_err(device, "%s: sysfs_create_bin_file failed\n", __func__);
525                 goto err_del_dev;
526         }
527
528         error = device_create_file(f_dev, &dev_attr_loading);
529         if (error) {
530                 dev_err(device, "%s: device_create_file failed\n", __func__);
531                 goto err_del_bin_attr;
532         }
533
534         if (uevent)
535                 dev_set_uevent_suppress(f_dev, false);
536
537         return fw_priv;
538
539 err_del_bin_attr:
540         device_remove_bin_file(f_dev, &firmware_attr_data);
541 err_del_dev:
542         device_del(f_dev);
543 err_put_dev:
544         put_device(f_dev);
545 err_out:
546         return ERR_PTR(error);
547 }
548
549 static void fw_destroy_instance(struct firmware_priv *fw_priv)
550 {
551         struct device *f_dev = &fw_priv->dev;
552
553         device_remove_file(f_dev, &dev_attr_loading);
554         device_remove_bin_file(f_dev, &firmware_attr_data);
555         device_unregister(f_dev);
556 }
557
558 static int _request_firmware(const struct firmware **firmware_p,
559                              const char *name, struct device *device,
560                              bool uevent, bool nowait)
561 {
562         struct firmware_priv *fw_priv;
563         struct firmware *firmware;
564         int retval = 0;
565
566         if (!firmware_p)
567                 return -EINVAL;
568
569         *firmware_p = firmware = kzalloc(sizeof(*firmware), GFP_KERNEL);
570         if (!firmware) {
571                 dev_err(device, "%s: kmalloc(struct firmware) failed\n",
572                         __func__);
573                 retval = -ENOMEM;
574                 goto out;
575         }
576
577         if (fw_get_builtin_firmware(firmware, name)) {
578                 dev_dbg(device, "firmware: using built-in firmware %s\n", name);
579                 return 0;
580         }
581
582         if (uevent)
583                 dev_dbg(device, "firmware: requesting %s\n", name);
584
585         fw_priv = fw_create_instance(firmware, name, device, uevent, nowait);
586         if (IS_ERR(fw_priv)) {
587                 retval = PTR_ERR(fw_priv);
588                 goto out;
589         }
590
591         if (uevent) {
592                 if (loading_timeout > 0)
593                         mod_timer(&fw_priv->timeout,
594                                   round_jiffies_up(jiffies +
595                                                    loading_timeout * HZ));
596
597                 kobject_uevent(&fw_priv->dev.kobj, KOBJ_ADD);
598         }
599
600         wait_for_completion(&fw_priv->completion);
601
602         set_bit(FW_STATUS_DONE, &fw_priv->status);
603         del_timer_sync(&fw_priv->timeout);
604
605         mutex_lock(&fw_lock);
606         if (!fw_priv->fw->size || test_bit(FW_STATUS_ABORT, &fw_priv->status))
607                 retval = -ENOENT;
608         fw_priv->fw = NULL;
609         mutex_unlock(&fw_lock);
610
611         fw_destroy_instance(fw_priv);
612
613 out:
614         if (retval) {
615                 release_firmware(firmware);
616                 *firmware_p = NULL;
617         }
618
619         return retval;
620 }
621
622 /**
623  * request_firmware: - send firmware request and wait for it
624  * @firmware_p: pointer to firmware image
625  * @name: name of firmware file
626  * @device: device for which firmware is being loaded
627  *
628  *      @firmware_p will be used to return a firmware image by the name
629  *      of @name for device @device.
630  *
631  *      Should be called from user context where sleeping is allowed.
632  *
633  *      @name will be used as $FIRMWARE in the uevent environment and
634  *      should be distinctive enough not to be confused with any other
635  *      firmware image for this or any other device.
636  **/
637 int
638 request_firmware(const struct firmware **firmware_p, const char *name,
639                  struct device *device)
640 {
641         int uevent = 1;
642         return _request_firmware(firmware_p, name, device, uevent, false);
643 }
644
645 /**
646  * release_firmware: - release the resource associated with a firmware image
647  * @fw: firmware resource to release
648  **/
649 void release_firmware(const struct firmware *fw)
650 {
651         if (fw) {
652                 if (!fw_is_builtin_firmware(fw))
653                         firmware_free_data(fw);
654                 kfree(fw);
655         }
656 }
657
658 /* Async support */
659 struct firmware_work {
660         struct work_struct work;
661         struct module *module;
662         const char *name;
663         struct device *device;
664         void *context;
665         void (*cont)(const struct firmware *fw, void *context);
666         int uevent;
667 };
668
669 static int request_firmware_work_func(void *arg)
670 {
671         struct firmware_work *fw_work = arg;
672         const struct firmware *fw;
673         int ret;
674
675         if (!arg) {
676                 WARN_ON(1);
677                 return 0;
678         }
679
680         ret = _request_firmware(&fw, fw_work->name, fw_work->device,
681                                 fw_work->uevent, true);
682         fw_work->cont(fw, fw_work->context);
683
684         module_put(fw_work->module);
685         kfree(fw_work);
686
687         return ret;
688 }
689
690 /**
691  * request_firmware_nowait - asynchronous version of request_firmware
692  * @module: module requesting the firmware
693  * @uevent: sends uevent to copy the firmware image if this flag
694  *      is non-zero else the firmware copy must be done manually.
695  * @name: name of firmware file
696  * @device: device for which firmware is being loaded
697  * @gfp: allocation flags
698  * @context: will be passed over to @cont, and
699  *      @fw may be %NULL if firmware request fails.
700  * @cont: function will be called asynchronously when the firmware
701  *      request is over.
702  *
703  *      Asynchronous variant of request_firmware() for user contexts where
704  *      it is not possible to sleep for long time. It can't be called
705  *      in atomic contexts.
706  **/
707 int
708 backport_request_firmware_nowait(
709         struct module *module, int uevent,
710         const char *name, struct device *device, gfp_t gfp, void *context,
711         void (*cont)(const struct firmware *fw, void *context))
712 {
713         struct task_struct *task;
714         struct firmware_work *fw_work;
715
716         fw_work = kzalloc(sizeof (struct firmware_work), gfp);
717         if (!fw_work)
718                 return -ENOMEM;
719
720         fw_work->module = module;
721         fw_work->name = name;
722         fw_work->device = device;
723         fw_work->context = context;
724         fw_work->cont = cont;
725         fw_work->uevent = uevent;
726
727         if (!try_module_get(module)) {
728                 kfree(fw_work);
729                 return -EFAULT;
730         }
731
732         task = kthread_run(request_firmware_work_func, fw_work,
733                             "firmware/%s", name);
734         if (IS_ERR(task)) {
735                 fw_work->cont(NULL, fw_work->context);
736                 module_put(fw_work->module);
737                 kfree(fw_work);
738                 return PTR_ERR(task);
739         }
740
741         return 0;
742 }
743
744 static int __init firmware_class_init(void)
745 {
746         return class_register(&firmware_class);
747 }
748
749 static void __exit firmware_class_exit(void)
750 {
751         class_unregister(&firmware_class);
752 }
753
754 fs_initcall(firmware_class_init);
755 module_exit(firmware_class_exit);
756
757 EXPORT_SYMBOL_GPL(release_firmware);
758 EXPORT_SYMBOL_GPL(request_firmware);
759 EXPORT_SYMBOL_GPL(backport_request_firmware_nowait);