Staging: phison: depends on ATA_BMDMA
[safe/jmp/linux-2.6] / drivers / base / firmware_class.c
index d351e77..3f093b0 100644 (file)
@@ -27,6 +27,52 @@ MODULE_AUTHOR("Manuel Estrada Sainz");
 MODULE_DESCRIPTION("Multi purpose firmware loading support");
 MODULE_LICENSE("GPL");
 
+/* Builtin firmware support */
+
+#ifdef CONFIG_FW_LOADER
+
+extern struct builtin_fw __start_builtin_fw[];
+extern struct builtin_fw __end_builtin_fw[];
+
+static bool fw_get_builtin_firmware(struct firmware *fw, const char *name)
+{
+       struct builtin_fw *b_fw;
+
+       for (b_fw = __start_builtin_fw; b_fw != __end_builtin_fw; b_fw++) {
+               if (strcmp(name, b_fw->name) == 0) {
+                       fw->size = b_fw->size;
+                       fw->data = b_fw->data;
+                       return true;
+               }
+       }
+
+       return false;
+}
+
+static bool fw_is_builtin_firmware(const struct firmware *fw)
+{
+       struct builtin_fw *b_fw;
+
+       for (b_fw = __start_builtin_fw; b_fw != __end_builtin_fw; b_fw++)
+               if (fw->data == b_fw->data)
+                       return true;
+
+       return false;
+}
+
+#else /* Module case - no builtin firmware support */
+
+static inline bool fw_get_builtin_firmware(struct firmware *fw, const char *name)
+{
+       return false;
+}
+
+static inline bool fw_is_builtin_firmware(const struct firmware *fw)
+{
+       return false;
+}
+#endif
+
 enum {
        FW_STATUS_LOADING,
        FW_STATUS_DONE,
@@ -40,7 +86,6 @@ static int loading_timeout = 60;      /* In seconds */
 static DEFINE_MUTEX(fw_lock);
 
 struct firmware_priv {
-       char *fw_id;
        struct completion completion;
        struct bin_attribute attr_data;
        struct firmware *fw;
@@ -48,19 +93,11 @@ struct firmware_priv {
        struct page **pages;
        int nr_pages;
        int page_array_size;
-       const char *vdata;
        struct timer_list timeout;
        bool nowait;
+       char fw_id[];
 };
 
-#ifdef CONFIG_FW_LOADER
-extern struct builtin_fw __start_builtin_fw[];
-extern struct builtin_fw __end_builtin_fw[];
-#else /* Module case. Avoid ifdefs later; it'll all optimise out */
-static struct builtin_fw *__start_builtin_fw;
-static struct builtin_fw *__end_builtin_fw;
-#endif
-
 static void
 fw_load_abort(struct firmware_priv *fw_priv)
 {
@@ -115,7 +152,6 @@ static void fw_dev_release(struct device *dev)
        for (i = 0; i < fw_priv->nr_pages; i++)
                __free_page(fw_priv->pages[i]);
        kfree(fw_priv->pages);
-       kfree(fw_priv->fw_id);
        kfree(fw_priv);
        kfree(dev);
 
@@ -242,8 +278,9 @@ static ssize_t firmware_loading_store(struct device *dev,
 static DEVICE_ATTR(loading, 0644, firmware_loading_show, firmware_loading_store);
 
 static ssize_t
-firmware_data_read(struct kobject *kobj, struct bin_attribute *bin_attr,
-                  char *buffer, loff_t offset, size_t count)
+firmware_data_read(struct file *filp, struct kobject *kobj,
+                  struct bin_attribute *bin_attr, char *buffer, loff_t offset,
+                  size_t count)
 {
        struct device *dev = to_dev(kobj);
        struct firmware_priv *fw_priv = dev_get_drvdata(dev);
@@ -326,6 +363,7 @@ fw_realloc_buffer(struct firmware_priv *fw_priv, int min_size)
 
 /**
  * firmware_data_write - write method for firmware
+ * @filp: open sysfs file
  * @kobj: kobject for the device
  * @bin_attr: bin_attr structure
  * @buffer: buffer being written
@@ -336,8 +374,9 @@ fw_realloc_buffer(struct firmware_priv *fw_priv, int min_size)
  *     the driver as a firmware image.
  **/
 static ssize_t
-firmware_data_write(struct kobject *kobj, struct bin_attribute *bin_attr,
-                   char *buffer, loff_t offset, size_t count)
+firmware_data_write(struct file* filp, struct kobject *kobj,
+                   struct bin_attribute *bin_attr, char *buffer,
+                   loff_t offset, size_t count)
 {
        struct device *dev = to_dev(kobj);
        struct firmware_priv *fw_priv = dev_get_drvdata(dev);
@@ -399,8 +438,8 @@ static int fw_register_device(struct device **dev_p, const char *fw_name,
                              struct device *device)
 {
        int retval;
-       struct firmware_priv *fw_priv = kzalloc(sizeof(*fw_priv),
-                                               GFP_KERNEL);
+       struct firmware_priv *fw_priv =
+               kzalloc(sizeof(*fw_priv) + strlen(fw_name) + 1 , GFP_KERNEL);
        struct device *f_dev = kzalloc(sizeof(*f_dev), GFP_KERNEL);
 
        *dev_p = NULL;
@@ -411,16 +450,9 @@ static int fw_register_device(struct device **dev_p, const char *fw_name,
                goto error_kfree;
        }
 
+       strcpy(fw_priv->fw_id, fw_name);
        init_completion(&fw_priv->completion);
        fw_priv->attr_data = firmware_attr_data_tmpl;
-       fw_priv->fw_id = kstrdup(fw_name, GFP_KERNEL);
-       if (!fw_priv->fw_id) {
-               dev_err(device, "%s: Firmware name allocation failed\n",
-                       __func__);
-               retval = -ENOMEM;
-               goto error_kfree;
-       }
-
        fw_priv->timeout.function = firmware_class_timeout;
        fw_priv->timeout.data = (u_long) fw_priv;
        init_timer(&fw_priv->timeout);
@@ -497,7 +529,6 @@ _request_firmware(const struct firmware **firmware_p, const char *name,
        struct device *f_dev;
        struct firmware_priv *fw_priv;
        struct firmware *firmware;
-       struct builtin_fw *builtin;
        int retval;
 
        if (!firmware_p)
@@ -511,13 +542,8 @@ _request_firmware(const struct firmware **firmware_p, const char *name,
                goto out;
        }
 
-       for (builtin = __start_builtin_fw; builtin != __end_builtin_fw;
-            builtin++) {
-               if (strcmp(name, builtin->name))
-                       continue;
+       if (fw_get_builtin_firmware(firmware, name)) {
                dev_dbg(device, "firmware: using built-in firmware %s\n", name);
-               firmware->size = builtin->size;
-               firmware->data = builtin->data;
                return 0;
        }
 
@@ -589,19 +615,11 @@ request_firmware(const struct firmware **firmware_p, const char *name,
  * release_firmware: - release the resource associated with a firmware image
  * @fw: firmware resource to release
  **/
-void
-release_firmware(const struct firmware *fw)
+void release_firmware(const struct firmware *fw)
 {
-       struct builtin_fw *builtin;
-
        if (fw) {
-               for (builtin = __start_builtin_fw; builtin != __end_builtin_fw;
-                    builtin++) {
-                       if (fw->data == builtin->data)
-                               goto free_fw;
-               }
-               firmware_free_data(fw);
-       free_fw:
+               if (!fw_is_builtin_firmware(fw))
+                       firmware_free_data(fw);
                kfree(fw);
        }
 }