Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * firmware_class.c - Multi purpose firmware loading support |
| 3 | * |
Markus Rechberger | 87d37a4 | 2007-06-04 18:45:44 +0200 | [diff] [blame] | 4 | * Copyright (c) 2003 Manuel Estrada Sainz |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 6 | * Please see Documentation/firmware_class/ for more information. |
| 7 | * |
| 8 | */ |
| 9 | |
Randy.Dunlap | c59ede7 | 2006-01-11 12:17:46 -0800 | [diff] [blame] | 10 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Laura Garcia | cad1e55 | 2006-05-23 23:22:38 +0200 | [diff] [blame] | 18 | #include <linux/mutex.h> |
Sukadev Bhattiprolu | 563d075 | 2006-09-29 01:59:31 -0700 | [diff] [blame] | 19 | #include <linux/kthread.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
| 21 | #include <linux/firmware.h> |
| 22 | #include "base.h" |
| 23 | |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 24 | #define to_dev(obj) container_of(obj, struct device, kobj) |
| 25 | |
Markus Rechberger | 87d37a4 | 2007-06-04 18:45:44 +0200 | [diff] [blame] | 26 | MODULE_AUTHOR("Manuel Estrada Sainz"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | MODULE_DESCRIPTION("Multi purpose firmware loading support"); |
| 28 | MODULE_LICENSE("GPL"); |
| 29 | |
| 30 | enum { |
| 31 | FW_STATUS_LOADING, |
| 32 | FW_STATUS_DONE, |
| 33 | FW_STATUS_ABORT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | }; |
| 35 | |
Dave Jones | 2f65168 | 2007-01-25 15:56:15 -0500 | [diff] [blame] | 36 | static int loading_timeout = 60; /* In seconds */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | /* fw_lock could be moved to 'struct firmware_priv' but since it is just |
| 39 | * guarding for corner cases a global lock should be OK */ |
Laura Garcia | cad1e55 | 2006-05-23 23:22:38 +0200 | [diff] [blame] | 40 | static DEFINE_MUTEX(fw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
| 42 | struct firmware_priv { |
| 43 | char fw_id[FIRMWARE_NAME_MAX]; |
| 44 | struct completion completion; |
| 45 | struct bin_attribute attr_data; |
| 46 | struct firmware *fw; |
| 47 | unsigned long status; |
| 48 | int alloc_size; |
| 49 | struct timer_list timeout; |
| 50 | }; |
| 51 | |
David Woodhouse | 5658c76 | 2008-05-23 13:52:42 +0100 | [diff] [blame] | 52 | #ifdef CONFIG_FW_LOADER |
| 53 | extern struct builtin_fw __start_builtin_fw[]; |
| 54 | extern struct builtin_fw __end_builtin_fw[]; |
| 55 | #else /* Module case. Avoid ifdefs later; it'll all optimise out */ |
| 56 | static struct builtin_fw *__start_builtin_fw; |
| 57 | static struct builtin_fw *__end_builtin_fw; |
| 58 | #endif |
| 59 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 60 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | fw_load_abort(struct firmware_priv *fw_priv) |
| 62 | { |
| 63 | set_bit(FW_STATUS_ABORT, &fw_priv->status); |
| 64 | wmb(); |
| 65 | complete(&fw_priv->completion); |
| 66 | } |
| 67 | |
| 68 | static ssize_t |
| 69 | firmware_timeout_show(struct class *class, char *buf) |
| 70 | { |
| 71 | return sprintf(buf, "%d\n", loading_timeout); |
| 72 | } |
| 73 | |
| 74 | /** |
Randy Dunlap | eb8e317 | 2005-10-30 15:03:01 -0800 | [diff] [blame] | 75 | * firmware_timeout_store - set number of seconds to wait for firmware |
| 76 | * @class: device class pointer |
| 77 | * @buf: buffer to scan for timeout value |
| 78 | * @count: number of bytes in @buf |
| 79 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | * Sets the number of seconds to wait for the firmware. Once |
Randy Dunlap | eb8e317 | 2005-10-30 15:03:01 -0800 | [diff] [blame] | 81 | * this expires an error will be returned to the driver and no |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | * firmware will be provided. |
| 83 | * |
Randy Dunlap | eb8e317 | 2005-10-30 15:03:01 -0800 | [diff] [blame] | 84 | * Note: zero means 'wait forever'. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | **/ |
| 86 | static ssize_t |
| 87 | firmware_timeout_store(struct class *class, const char *buf, size_t count) |
| 88 | { |
| 89 | loading_timeout = simple_strtol(buf, NULL, 10); |
Stanislaw W. Gruszka | b92eac0 | 2005-06-28 20:44:51 -0700 | [diff] [blame] | 90 | if (loading_timeout < 0) |
| 91 | loading_timeout = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | return count; |
| 93 | } |
| 94 | |
| 95 | static CLASS_ATTR(timeout, 0644, firmware_timeout_show, firmware_timeout_store); |
| 96 | |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 97 | static void fw_dev_release(struct device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 99 | static int firmware_uevent(struct device *dev, struct kobj_uevent_env *env) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | { |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 101 | struct firmware_priv *fw_priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 103 | if (add_uevent_var(env, "FIRMWARE=%s", fw_priv->fw_id)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | return -ENOMEM; |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 105 | if (add_uevent_var(env, "TIMEOUT=%i", loading_timeout)) |
kay.sievers@vrfy.org | 6897089 | 2005-04-18 21:57:31 -0700 | [diff] [blame] | 106 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
| 108 | return 0; |
| 109 | } |
| 110 | |
Adrian Bunk | 1b81d66 | 2006-05-20 15:00:16 -0700 | [diff] [blame] | 111 | static struct class firmware_class = { |
| 112 | .name = "firmware", |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 113 | .dev_uevent = firmware_uevent, |
| 114 | .dev_release = fw_dev_release, |
Adrian Bunk | 1b81d66 | 2006-05-20 15:00:16 -0700 | [diff] [blame] | 115 | }; |
| 116 | |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 117 | static ssize_t firmware_loading_show(struct device *dev, |
| 118 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | { |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 120 | struct firmware_priv *fw_priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | int loading = test_bit(FW_STATUS_LOADING, &fw_priv->status); |
| 122 | return sprintf(buf, "%d\n", loading); |
| 123 | } |
| 124 | |
| 125 | /** |
Randy Dunlap | eb8e317 | 2005-10-30 15:03:01 -0800 | [diff] [blame] | 126 | * firmware_loading_store - set value in the 'loading' control file |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 127 | * @dev: device pointer |
Randy Dunlap | af9997e | 2006-12-22 01:06:52 -0800 | [diff] [blame] | 128 | * @attr: device attribute pointer |
Randy Dunlap | eb8e317 | 2005-10-30 15:03:01 -0800 | [diff] [blame] | 129 | * @buf: buffer to scan for loading control value |
| 130 | * @count: number of bytes in @buf |
| 131 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | * The relevant values are: |
| 133 | * |
| 134 | * 1: Start a load, discarding any previous partial load. |
Randy Dunlap | eb8e317 | 2005-10-30 15:03:01 -0800 | [diff] [blame] | 135 | * 0: Conclude the load and hand the data to the driver code. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | * -1: Conclude the load with an error and discard any written data. |
| 137 | **/ |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 138 | static ssize_t firmware_loading_store(struct device *dev, |
| 139 | struct device_attribute *attr, |
| 140 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | { |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 142 | struct firmware_priv *fw_priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | int loading = simple_strtol(buf, NULL, 10); |
| 144 | |
| 145 | switch (loading) { |
| 146 | case 1: |
Laura Garcia | cad1e55 | 2006-05-23 23:22:38 +0200 | [diff] [blame] | 147 | mutex_lock(&fw_lock); |
Stanislaw W. Gruszka | b92eac0 | 2005-06-28 20:44:51 -0700 | [diff] [blame] | 148 | if (!fw_priv->fw) { |
Laura Garcia | cad1e55 | 2006-05-23 23:22:38 +0200 | [diff] [blame] | 149 | mutex_unlock(&fw_lock); |
Stanislaw W. Gruszka | b92eac0 | 2005-06-28 20:44:51 -0700 | [diff] [blame] | 150 | break; |
| 151 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | vfree(fw_priv->fw->data); |
| 153 | fw_priv->fw->data = NULL; |
| 154 | fw_priv->fw->size = 0; |
| 155 | fw_priv->alloc_size = 0; |
| 156 | set_bit(FW_STATUS_LOADING, &fw_priv->status); |
Laura Garcia | cad1e55 | 2006-05-23 23:22:38 +0200 | [diff] [blame] | 157 | mutex_unlock(&fw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | break; |
| 159 | case 0: |
| 160 | if (test_bit(FW_STATUS_LOADING, &fw_priv->status)) { |
| 161 | complete(&fw_priv->completion); |
| 162 | clear_bit(FW_STATUS_LOADING, &fw_priv->status); |
| 163 | break; |
| 164 | } |
| 165 | /* fallthrough */ |
| 166 | default: |
Bjorn Helgaas | 266a813 | 2008-10-15 22:04:20 -0700 | [diff] [blame] | 167 | dev_err(dev, "%s: unexpected value (%d)\n", __func__, loading); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | /* fallthrough */ |
| 169 | case -1: |
| 170 | fw_load_abort(fw_priv); |
| 171 | break; |
| 172 | } |
| 173 | |
| 174 | return count; |
| 175 | } |
| 176 | |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 177 | static DEVICE_ATTR(loading, 0644, firmware_loading_show, firmware_loading_store); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
| 179 | static ssize_t |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 180 | firmware_data_read(struct kobject *kobj, struct bin_attribute *bin_attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | char *buffer, loff_t offset, size_t count) |
| 182 | { |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 183 | struct device *dev = to_dev(kobj); |
| 184 | struct firmware_priv *fw_priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | struct firmware *fw; |
Akinobu Mita | f37e661 | 2008-07-25 01:48:23 -0700 | [diff] [blame] | 186 | ssize_t ret_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
Laura Garcia | cad1e55 | 2006-05-23 23:22:38 +0200 | [diff] [blame] | 188 | mutex_lock(&fw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | fw = fw_priv->fw; |
Stanislaw W. Gruszka | b92eac0 | 2005-06-28 20:44:51 -0700 | [diff] [blame] | 190 | if (!fw || test_bit(FW_STATUS_DONE, &fw_priv->status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | ret_count = -ENODEV; |
| 192 | goto out; |
| 193 | } |
Akinobu Mita | f37e661 | 2008-07-25 01:48:23 -0700 | [diff] [blame] | 194 | ret_count = memory_read_from_buffer(buffer, count, &offset, |
| 195 | fw->data, fw->size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | out: |
Laura Garcia | cad1e55 | 2006-05-23 23:22:38 +0200 | [diff] [blame] | 197 | mutex_unlock(&fw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | return ret_count; |
| 199 | } |
Randy Dunlap | eb8e317 | 2005-10-30 15:03:01 -0800 | [diff] [blame] | 200 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | static int |
| 202 | fw_realloc_buffer(struct firmware_priv *fw_priv, int min_size) |
| 203 | { |
| 204 | u8 *new_data; |
Jeff Moyer | 30560ba | 2006-02-13 14:52:38 -0800 | [diff] [blame] | 205 | int new_size = fw_priv->alloc_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
| 207 | if (min_size <= fw_priv->alloc_size) |
| 208 | return 0; |
| 209 | |
Jeff Moyer | 30560ba | 2006-02-13 14:52:38 -0800 | [diff] [blame] | 210 | new_size = ALIGN(min_size, PAGE_SIZE); |
| 211 | new_data = vmalloc(new_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | if (!new_data) { |
Harvey Harrison | 2b3a302 | 2008-03-04 16:41:05 -0800 | [diff] [blame] | 213 | printk(KERN_ERR "%s: unable to alloc buffer\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | /* Make sure that we don't keep incomplete data */ |
| 215 | fw_load_abort(fw_priv); |
| 216 | return -ENOMEM; |
| 217 | } |
Jeff Moyer | 30560ba | 2006-02-13 14:52:38 -0800 | [diff] [blame] | 218 | fw_priv->alloc_size = new_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | if (fw_priv->fw->data) { |
| 220 | memcpy(new_data, fw_priv->fw->data, fw_priv->fw->size); |
| 221 | vfree(fw_priv->fw->data); |
| 222 | } |
| 223 | fw_priv->fw->data = new_data; |
| 224 | BUG_ON(min_size > fw_priv->alloc_size); |
| 225 | return 0; |
| 226 | } |
| 227 | |
| 228 | /** |
Randy Dunlap | eb8e317 | 2005-10-30 15:03:01 -0800 | [diff] [blame] | 229 | * firmware_data_write - write method for firmware |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 230 | * @kobj: kobject for the device |
Randy Dunlap | 42e61f4 | 2007-07-23 21:42:11 -0700 | [diff] [blame] | 231 | * @bin_attr: bin_attr structure |
Randy Dunlap | eb8e317 | 2005-10-30 15:03:01 -0800 | [diff] [blame] | 232 | * @buffer: buffer being written |
| 233 | * @offset: buffer offset for write in total data store area |
| 234 | * @count: buffer size |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | * |
Randy Dunlap | eb8e317 | 2005-10-30 15:03:01 -0800 | [diff] [blame] | 236 | * Data written to the 'data' attribute will be later handed to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | * the driver as a firmware image. |
| 238 | **/ |
| 239 | static ssize_t |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 240 | firmware_data_write(struct kobject *kobj, struct bin_attribute *bin_attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | char *buffer, loff_t offset, size_t count) |
| 242 | { |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 243 | struct device *dev = to_dev(kobj); |
| 244 | struct firmware_priv *fw_priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | struct firmware *fw; |
| 246 | ssize_t retval; |
| 247 | |
| 248 | if (!capable(CAP_SYS_RAWIO)) |
| 249 | return -EPERM; |
Stanislaw W. Gruszka | b92eac0 | 2005-06-28 20:44:51 -0700 | [diff] [blame] | 250 | |
Laura Garcia | cad1e55 | 2006-05-23 23:22:38 +0200 | [diff] [blame] | 251 | mutex_lock(&fw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | fw = fw_priv->fw; |
Stanislaw W. Gruszka | b92eac0 | 2005-06-28 20:44:51 -0700 | [diff] [blame] | 253 | if (!fw || test_bit(FW_STATUS_DONE, &fw_priv->status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | retval = -ENODEV; |
| 255 | goto out; |
| 256 | } |
| 257 | retval = fw_realloc_buffer(fw_priv, offset + count); |
| 258 | if (retval) |
| 259 | goto out; |
| 260 | |
David Woodhouse | b7a39bd | 2008-05-23 18:38:49 +0100 | [diff] [blame] | 261 | memcpy((u8 *)fw->data + offset, buffer, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | |
| 263 | fw->size = max_t(size_t, offset + count, fw->size); |
| 264 | retval = count; |
| 265 | out: |
Laura Garcia | cad1e55 | 2006-05-23 23:22:38 +0200 | [diff] [blame] | 266 | mutex_unlock(&fw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | return retval; |
| 268 | } |
Randy Dunlap | eb8e317 | 2005-10-30 15:03:01 -0800 | [diff] [blame] | 269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | static struct bin_attribute firmware_attr_data_tmpl = { |
Tejun Heo | 7b59575 | 2007-06-14 03:45:17 +0900 | [diff] [blame] | 271 | .attr = {.name = "data", .mode = 0644}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | .size = 0, |
| 273 | .read = firmware_data_read, |
| 274 | .write = firmware_data_write, |
| 275 | }; |
| 276 | |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 277 | static void fw_dev_release(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | { |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 279 | struct firmware_priv *fw_priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | |
| 281 | kfree(fw_priv); |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 282 | kfree(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | |
| 284 | module_put(THIS_MODULE); |
| 285 | } |
| 286 | |
| 287 | static void |
| 288 | firmware_class_timeout(u_long data) |
| 289 | { |
| 290 | struct firmware_priv *fw_priv = (struct firmware_priv *) data; |
| 291 | fw_load_abort(fw_priv); |
| 292 | } |
| 293 | |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 294 | static int fw_register_device(struct device **dev_p, const char *fw_name, |
| 295 | struct device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | { |
| 297 | int retval; |
Jiri Slaby | 4aed064 | 2005-09-13 01:25:01 -0700 | [diff] [blame] | 298 | struct firmware_priv *fw_priv = kzalloc(sizeof(*fw_priv), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | GFP_KERNEL); |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 300 | struct device *f_dev = kzalloc(sizeof(*f_dev), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 302 | *dev_p = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 304 | if (!fw_priv || !f_dev) { |
Bjorn Helgaas | 266a813 | 2008-10-15 22:04:20 -0700 | [diff] [blame] | 305 | dev_err(device, "%s: kmalloc failed\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | retval = -ENOMEM; |
| 307 | goto error_kfree; |
| 308 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | |
| 310 | init_completion(&fw_priv->completion); |
| 311 | fw_priv->attr_data = firmware_attr_data_tmpl; |
| 312 | strlcpy(fw_priv->fw_id, fw_name, FIRMWARE_NAME_MAX); |
| 313 | |
| 314 | fw_priv->timeout.function = firmware_class_timeout; |
| 315 | fw_priv->timeout.data = (u_long) fw_priv; |
| 316 | init_timer(&fw_priv->timeout); |
| 317 | |
Kay Sievers | 1e0b2cf | 2008-10-30 01:36:48 +0100 | [diff] [blame] | 318 | dev_set_name(f_dev, dev_name(device)); |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 319 | f_dev->parent = device; |
| 320 | f_dev->class = &firmware_class; |
| 321 | dev_set_drvdata(f_dev, fw_priv); |
Cornelia Huck | bdc4960 | 2007-03-29 11:12:14 +0200 | [diff] [blame] | 322 | f_dev->uevent_suppress = 1; |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 323 | retval = device_register(f_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | if (retval) { |
Bjorn Helgaas | 266a813 | 2008-10-15 22:04:20 -0700 | [diff] [blame] | 325 | dev_err(device, "%s: device_register failed\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | goto error_kfree; |
| 327 | } |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 328 | *dev_p = f_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | return 0; |
| 330 | |
| 331 | error_kfree: |
| 332 | kfree(fw_priv); |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 333 | kfree(f_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | return retval; |
| 335 | } |
| 336 | |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 337 | static int fw_setup_device(struct firmware *fw, struct device **dev_p, |
| 338 | const char *fw_name, struct device *device, |
| 339 | int uevent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | { |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 341 | struct device *f_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | struct firmware_priv *fw_priv; |
| 343 | int retval; |
| 344 | |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 345 | *dev_p = NULL; |
| 346 | retval = fw_register_device(&f_dev, fw_name, device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | if (retval) |
| 348 | goto out; |
| 349 | |
| 350 | /* Need to pin this module until class device is destroyed */ |
| 351 | __module_get(THIS_MODULE); |
| 352 | |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 353 | fw_priv = dev_get_drvdata(f_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
| 355 | fw_priv->fw = fw; |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 356 | retval = sysfs_create_bin_file(&f_dev->kobj, &fw_priv->attr_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | if (retval) { |
Bjorn Helgaas | 266a813 | 2008-10-15 22:04:20 -0700 | [diff] [blame] | 358 | dev_err(device, "%s: sysfs_create_bin_file failed\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | goto error_unreg; |
| 360 | } |
| 361 | |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 362 | retval = device_create_file(f_dev, &dev_attr_loading); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | if (retval) { |
Bjorn Helgaas | 266a813 | 2008-10-15 22:04:20 -0700 | [diff] [blame] | 364 | dev_err(device, "%s: device_create_file failed\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | goto error_unreg; |
| 366 | } |
| 367 | |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 368 | if (uevent) |
Cornelia Huck | bdc4960 | 2007-03-29 11:12:14 +0200 | [diff] [blame] | 369 | f_dev->uevent_suppress = 0; |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 370 | *dev_p = f_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | goto out; |
| 372 | |
| 373 | error_unreg: |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 374 | device_unregister(f_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | out: |
| 376 | return retval; |
| 377 | } |
| 378 | |
Abhay Salunke | 6e3eaab | 2005-09-06 15:17:13 -0700 | [diff] [blame] | 379 | static int |
| 380 | _request_firmware(const struct firmware **firmware_p, const char *name, |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 381 | struct device *device, int uevent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | { |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 383 | struct device *f_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | struct firmware_priv *fw_priv; |
| 385 | struct firmware *firmware; |
David Woodhouse | 5658c76 | 2008-05-23 13:52:42 +0100 | [diff] [blame] | 386 | struct builtin_fw *builtin; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | int retval; |
| 388 | |
| 389 | if (!firmware_p) |
| 390 | return -EINVAL; |
| 391 | |
Jiri Slaby | 4aed064 | 2005-09-13 01:25:01 -0700 | [diff] [blame] | 392 | *firmware_p = firmware = kzalloc(sizeof(*firmware), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | if (!firmware) { |
Bjorn Helgaas | 266a813 | 2008-10-15 22:04:20 -0700 | [diff] [blame] | 394 | dev_err(device, "%s: kmalloc(struct firmware) failed\n", |
| 395 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | retval = -ENOMEM; |
| 397 | goto out; |
| 398 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | |
David Woodhouse | 5658c76 | 2008-05-23 13:52:42 +0100 | [diff] [blame] | 400 | for (builtin = __start_builtin_fw; builtin != __end_builtin_fw; |
| 401 | builtin++) { |
| 402 | if (strcmp(name, builtin->name)) |
| 403 | continue; |
Bjorn Helgaas | 266a813 | 2008-10-15 22:04:20 -0700 | [diff] [blame] | 404 | dev_info(device, "firmware: using built-in firmware %s\n", |
| 405 | name); |
David Woodhouse | 5658c76 | 2008-05-23 13:52:42 +0100 | [diff] [blame] | 406 | firmware->size = builtin->size; |
| 407 | firmware->data = builtin->data; |
| 408 | return 0; |
| 409 | } |
| 410 | |
| 411 | if (uevent) |
Bjorn Helgaas | 266a813 | 2008-10-15 22:04:20 -0700 | [diff] [blame] | 412 | dev_info(device, "firmware: requesting %s\n", name); |
David Woodhouse | 5658c76 | 2008-05-23 13:52:42 +0100 | [diff] [blame] | 413 | |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 414 | retval = fw_setup_device(firmware, &f_dev, name, device, uevent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | if (retval) |
| 416 | goto error_kfree_fw; |
| 417 | |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 418 | fw_priv = dev_get_drvdata(f_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 420 | if (uevent) { |
Abhay Salunke | 6e3eaab | 2005-09-06 15:17:13 -0700 | [diff] [blame] | 421 | if (loading_timeout > 0) { |
| 422 | fw_priv->timeout.expires = jiffies + loading_timeout * HZ; |
| 423 | add_timer(&fw_priv->timeout); |
| 424 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 426 | kobject_uevent(&f_dev->kobj, KOBJ_ADD); |
Abhay Salunke | 6e3eaab | 2005-09-06 15:17:13 -0700 | [diff] [blame] | 427 | wait_for_completion(&fw_priv->completion); |
| 428 | set_bit(FW_STATUS_DONE, &fw_priv->status); |
| 429 | del_timer_sync(&fw_priv->timeout); |
| 430 | } else |
| 431 | wait_for_completion(&fw_priv->completion); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | |
Laura Garcia | cad1e55 | 2006-05-23 23:22:38 +0200 | [diff] [blame] | 433 | mutex_lock(&fw_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | if (!fw_priv->fw->size || test_bit(FW_STATUS_ABORT, &fw_priv->status)) { |
| 435 | retval = -ENOENT; |
| 436 | release_firmware(fw_priv->fw); |
| 437 | *firmware_p = NULL; |
| 438 | } |
| 439 | fw_priv->fw = NULL; |
Laura Garcia | cad1e55 | 2006-05-23 23:22:38 +0200 | [diff] [blame] | 440 | mutex_unlock(&fw_lock); |
Greg Kroah-Hartman | e55c879 | 2006-09-14 07:30:59 -0700 | [diff] [blame] | 441 | device_unregister(f_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | goto out; |
| 443 | |
| 444 | error_kfree_fw: |
| 445 | kfree(firmware); |
| 446 | *firmware_p = NULL; |
| 447 | out: |
| 448 | return retval; |
| 449 | } |
| 450 | |
| 451 | /** |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 452 | * request_firmware: - send firmware request and wait for it |
Randy Dunlap | eb8e317 | 2005-10-30 15:03:01 -0800 | [diff] [blame] | 453 | * @firmware_p: pointer to firmware image |
| 454 | * @name: name of firmware file |
| 455 | * @device: device for which firmware is being loaded |
| 456 | * |
| 457 | * @firmware_p will be used to return a firmware image by the name |
Abhay Salunke | 6e3eaab | 2005-09-06 15:17:13 -0700 | [diff] [blame] | 458 | * of @name for device @device. |
| 459 | * |
| 460 | * Should be called from user context where sleeping is allowed. |
| 461 | * |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 462 | * @name will be used as $FIRMWARE in the uevent environment and |
Abhay Salunke | 6e3eaab | 2005-09-06 15:17:13 -0700 | [diff] [blame] | 463 | * should be distinctive enough not to be confused with any other |
| 464 | * firmware image for this or any other device. |
| 465 | **/ |
| 466 | int |
| 467 | request_firmware(const struct firmware **firmware_p, const char *name, |
| 468 | struct device *device) |
| 469 | { |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 470 | int uevent = 1; |
| 471 | return _request_firmware(firmware_p, name, device, uevent); |
Abhay Salunke | 6e3eaab | 2005-09-06 15:17:13 -0700 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | * release_firmware: - release the resource associated with a firmware image |
Randy Dunlap | eb8e317 | 2005-10-30 15:03:01 -0800 | [diff] [blame] | 476 | * @fw: firmware resource to release |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | **/ |
| 478 | void |
| 479 | release_firmware(const struct firmware *fw) |
| 480 | { |
David Woodhouse | 5658c76 | 2008-05-23 13:52:42 +0100 | [diff] [blame] | 481 | struct builtin_fw *builtin; |
| 482 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | if (fw) { |
David Woodhouse | 5658c76 | 2008-05-23 13:52:42 +0100 | [diff] [blame] | 484 | for (builtin = __start_builtin_fw; builtin != __end_builtin_fw; |
| 485 | builtin++) { |
| 486 | if (fw->data == builtin->data) |
| 487 | goto free_fw; |
| 488 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | vfree(fw->data); |
David Woodhouse | 5658c76 | 2008-05-23 13:52:42 +0100 | [diff] [blame] | 490 | free_fw: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | kfree(fw); |
| 492 | } |
| 493 | } |
| 494 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | /* Async support */ |
| 496 | struct firmware_work { |
| 497 | struct work_struct work; |
| 498 | struct module *module; |
| 499 | const char *name; |
| 500 | struct device *device; |
| 501 | void *context; |
| 502 | void (*cont)(const struct firmware *fw, void *context); |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 503 | int uevent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | }; |
| 505 | |
| 506 | static int |
| 507 | request_firmware_work_func(void *arg) |
| 508 | { |
| 509 | struct firmware_work *fw_work = arg; |
| 510 | const struct firmware *fw; |
matthieu castet | 113fab1 | 2005-11-13 16:07:39 -0800 | [diff] [blame] | 511 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | if (!arg) { |
| 513 | WARN_ON(1); |
| 514 | return 0; |
| 515 | } |
matthieu castet | 113fab1 | 2005-11-13 16:07:39 -0800 | [diff] [blame] | 516 | ret = _request_firmware(&fw, fw_work->name, fw_work->device, |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 517 | fw_work->uevent); |
matthieu castet | 113fab1 | 2005-11-13 16:07:39 -0800 | [diff] [blame] | 518 | if (ret < 0) |
| 519 | fw_work->cont(NULL, fw_work->context); |
| 520 | else { |
| 521 | fw_work->cont(fw, fw_work->context); |
| 522 | release_firmware(fw); |
| 523 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | module_put(fw_work->module); |
| 525 | kfree(fw_work); |
matthieu castet | 113fab1 | 2005-11-13 16:07:39 -0800 | [diff] [blame] | 526 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | /** |
Randy Dunlap | eb8e317 | 2005-10-30 15:03:01 -0800 | [diff] [blame] | 530 | * request_firmware_nowait: asynchronous version of request_firmware |
| 531 | * @module: module requesting the firmware |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 532 | * @uevent: sends uevent to copy the firmware image if this flag |
Randy Dunlap | eb8e317 | 2005-10-30 15:03:01 -0800 | [diff] [blame] | 533 | * is non-zero else the firmware copy must be done manually. |
| 534 | * @name: name of firmware file |
| 535 | * @device: device for which firmware is being loaded |
| 536 | * @context: will be passed over to @cont, and |
| 537 | * @fw may be %NULL if firmware request fails. |
| 538 | * @cont: function will be called asynchronously when the firmware |
| 539 | * request is over. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | * Asynchronous variant of request_firmware() for contexts where |
| 542 | * it is not possible to sleep. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | **/ |
| 544 | int |
| 545 | request_firmware_nowait( |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 546 | struct module *module, int uevent, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | const char *name, struct device *device, void *context, |
| 548 | void (*cont)(const struct firmware *fw, void *context)) |
| 549 | { |
Sukadev Bhattiprolu | 563d075 | 2006-09-29 01:59:31 -0700 | [diff] [blame] | 550 | struct task_struct *task; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | struct firmware_work *fw_work = kmalloc(sizeof (struct firmware_work), |
| 552 | GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | |
| 554 | if (!fw_work) |
| 555 | return -ENOMEM; |
| 556 | if (!try_module_get(module)) { |
| 557 | kfree(fw_work); |
| 558 | return -EFAULT; |
| 559 | } |
| 560 | |
| 561 | *fw_work = (struct firmware_work) { |
| 562 | .module = module, |
| 563 | .name = name, |
| 564 | .device = device, |
| 565 | .context = context, |
| 566 | .cont = cont, |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 567 | .uevent = uevent, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | }; |
| 569 | |
Sukadev Bhattiprolu | 563d075 | 2006-09-29 01:59:31 -0700 | [diff] [blame] | 570 | task = kthread_run(request_firmware_work_func, fw_work, |
| 571 | "firmware/%s", name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | |
Sukadev Bhattiprolu | 563d075 | 2006-09-29 01:59:31 -0700 | [diff] [blame] | 573 | if (IS_ERR(task)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | fw_work->cont(NULL, fw_work->context); |
matthieu castet | 113fab1 | 2005-11-13 16:07:39 -0800 | [diff] [blame] | 575 | module_put(fw_work->module); |
| 576 | kfree(fw_work); |
Sukadev Bhattiprolu | 563d075 | 2006-09-29 01:59:31 -0700 | [diff] [blame] | 577 | return PTR_ERR(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | } |
| 579 | return 0; |
| 580 | } |
| 581 | |
| 582 | static int __init |
| 583 | firmware_class_init(void) |
| 584 | { |
| 585 | int error; |
| 586 | error = class_register(&firmware_class); |
| 587 | if (error) { |
Harvey Harrison | 2b3a302 | 2008-03-04 16:41:05 -0800 | [diff] [blame] | 588 | printk(KERN_ERR "%s: class_register failed\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | return error; |
| 590 | } |
| 591 | error = class_create_file(&firmware_class, &class_attr_timeout); |
| 592 | if (error) { |
| 593 | printk(KERN_ERR "%s: class_create_file failed\n", |
Harvey Harrison | 2b3a302 | 2008-03-04 16:41:05 -0800 | [diff] [blame] | 594 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | class_unregister(&firmware_class); |
| 596 | } |
| 597 | return error; |
| 598 | |
| 599 | } |
| 600 | static void __exit |
| 601 | firmware_class_exit(void) |
| 602 | { |
| 603 | class_unregister(&firmware_class); |
| 604 | } |
| 605 | |
Shaohua Li | a30a6a2 | 2006-09-27 01:50:52 -0700 | [diff] [blame] | 606 | fs_initcall(firmware_class_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | module_exit(firmware_class_exit); |
| 608 | |
| 609 | EXPORT_SYMBOL(release_firmware); |
| 610 | EXPORT_SYMBOL(request_firmware); |
| 611 | EXPORT_SYMBOL(request_firmware_nowait); |