Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 353723
b: refs/heads/master
c: 7b1269f
h: refs/heads/master
i:
  353721: 35449eb
  353719: 26554fc
v: v3
  • Loading branch information
Takashi Iwai authored and Greg Kroah-Hartman committed Feb 4, 2013
1 parent 7f8e4eb commit caf42b5
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 14 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 4e0c92d015235d1dc65f9668a10cef2cea468ba2
refs/heads/master: 7b1269f778782d2f42994a74bf4014d0cbebbf9f
11 changes: 11 additions & 0 deletions trunk/drivers/base/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@ config EXTRA_FIRMWARE_DIR
this option you can point it elsewhere, such as /lib/firmware/ or
some other directory containing the firmware files.

config FW_LOADER_USER_HELPER
bool "Fallback user-helper invocation for firmware loading"
depends on FW_LOADER
default y
help
This option enables / disables the invocation of user-helper
(e.g. udev) for loading firmware files as a fallback after the
direct file loading in kernel fails. The user-mode helper is
no longer required unless you have a special firmware file that
resides in a non-standard path.

config DEBUG_DRIVER
bool "Driver Core verbose debug messages"
depends on DEBUG_KERNEL
Expand Down
57 changes: 44 additions & 13 deletions trunk/drivers/base/firmware_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,12 @@ enum {
FW_STATUS_ABORT,
};

#ifdef CONFIG_FW_LOADER_USER_HELPER
enum fw_buf_fmt {
VMALLOC_BUF, /* used in direct loading */
PAGE_BUF, /* used in loading via userspace */
};
#endif /* CONFIG_FW_LOADER_USER_HELPER */

static int loading_timeout = 60; /* In seconds */

Expand Down Expand Up @@ -128,12 +130,14 @@ struct firmware_buf {
struct completion completion;
struct firmware_cache *fwc;
unsigned long status;
enum fw_buf_fmt fmt;
void *data;
size_t size;
#ifdef CONFIG_FW_LOADER_USER_HELPER
enum fw_buf_fmt fmt;
struct page **pages;
int nr_pages;
int page_array_size;
#endif
char fw_id[];
};

Expand All @@ -142,13 +146,15 @@ struct fw_cache_entry {
char name[];
};

#ifdef CONFIG_FW_LOADER_USER_HELPER
struct firmware_priv {
struct delayed_work timeout_work;
bool nowait;
struct device dev;
struct firmware_buf *buf;
struct firmware *fw;
};
#endif

struct fw_name_devm {
unsigned long magic;
Expand Down Expand Up @@ -182,7 +188,9 @@ static struct firmware_buf *__allocate_fw_buf(const char *fw_name,
strcpy(buf->fw_id, fw_name);
buf->fwc = fwc;
init_completion(&buf->completion);
#ifdef CONFIG_FW_LOADER_USER_HELPER
buf->fmt = VMALLOC_BUF;
#endif

pr_debug("%s: fw-%s buf=%p\n", __func__, fw_name, buf);

Expand Down Expand Up @@ -240,7 +248,6 @@ static void __fw_free_buf(struct kref *ref)
{
struct firmware_buf *buf = to_fwbuf(ref);
struct firmware_cache *fwc = buf->fwc;
int i;

pr_debug("%s: fw-%s buf=%p data=%p size=%u\n",
__func__, buf->fw_id, buf, buf->data,
Expand All @@ -250,12 +257,15 @@ static void __fw_free_buf(struct kref *ref)
spin_unlock(&fwc->lock);


#ifdef CONFIG_FW_LOADER_USER_HELPER
if (buf->fmt == PAGE_BUF) {
int i;
vunmap(buf->data);
for (i = 0; i < buf->nr_pages; i++)
__free_page(buf->pages[i]);
kfree(buf->pages);
} else
#endif
vfree(buf->data);
kfree(buf);
}
Expand Down Expand Up @@ -357,6 +367,19 @@ static bool fw_get_filesystem_firmware(struct device *device,
return success;
}

/* firmware holds the ownership of pages */
static void firmware_free_data(const struct firmware *fw)
{
/* Loaded directly? */
if (!fw->priv) {
vfree(fw->data);
return;
}
fw_free_buf(fw->priv);
}

#ifdef CONFIG_FW_LOADER_USER_HELPER

static struct firmware_priv *to_firmware_priv(struct device *dev)
{
return container_of(dev, struct firmware_priv, dev);
Expand Down Expand Up @@ -446,17 +469,6 @@ static ssize_t firmware_loading_show(struct device *dev,
return sprintf(buf, "%d\n", loading);
}

/* firmware holds the ownership of pages */
static void firmware_free_data(const struct firmware *fw)
{
/* Loaded directly? */
if (!fw->priv) {
vfree(fw->data);
return;
}
fw_free_buf(fw->priv);
}

/* Some architectures don't have PAGE_KERNEL_RO */
#ifndef PAGE_KERNEL_RO
#define PAGE_KERNEL_RO PAGE_KERNEL
Expand Down Expand Up @@ -737,12 +749,15 @@ fw_create_instance(struct firmware *firmware, const char *fw_name,
exit:
return fw_priv;
}
#endif /* CONFIG_FW_LOADER_USER_HELPER */

/* store the pages buffer info firmware from buf */
static void fw_set_page_data(struct firmware_buf *buf, struct firmware *fw)
{
fw->priv = buf;
#ifdef CONFIG_FW_LOADER_USER_HELPER
fw->pages = buf->pages;
#endif
fw->size = buf->size;
fw->data = buf->data;

Expand Down Expand Up @@ -906,6 +921,7 @@ static int assign_firmware_buf(struct firmware *fw, struct device *device)
return 0;
}

#ifdef CONFIG_FW_LOADER_USER_HELPER
/* load a firmware via user helper */
static int _request_firmware_load(struct firmware_priv *fw_priv, bool uevent,
long timeout)
Expand Down Expand Up @@ -978,6 +994,15 @@ static int fw_load_from_user_helper(struct firmware *firmware,
fw_priv->buf = firmware->priv;
return _request_firmware_load(fw_priv, uevent, timeout);
}
#else /* CONFIG_FW_LOADER_USER_HELPER */
static inline int
fw_load_from_user_helper(struct firmware *firmware, const char *name,
struct device *device, bool uevent, bool nowait,
long timeout)
{
return -ENOENT;
}
#endif /* CONFIG_FW_LOADER_USER_HELPER */

/* called from request_firmware() and request_firmware_work_func() */
static int
Expand Down Expand Up @@ -1495,7 +1520,11 @@ static void __init fw_cache_init(void)
static int __init firmware_class_init(void)
{
fw_cache_init();
#ifdef CONFIG_FW_LOADER_USER_HELPER
return class_register(&firmware_class);
#else
return 0;
#endif
}

static void __exit firmware_class_exit(void)
Expand All @@ -1504,7 +1533,9 @@ static void __exit firmware_class_exit(void)
unregister_syscore_ops(&fw_syscore_ops);
unregister_pm_notifier(&fw_cache.pm_notify);
#endif
#ifdef CONFIG_FW_LOADER_USER_HELPER
class_unregister(&firmware_class);
#endif
}

fs_initcall(firmware_class_init);
Expand Down

0 comments on commit caf42b5

Please sign in to comment.