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