1
0
Fork 0

firmware loader: split out builtin firmware handling

Split builtin firmware handling into separate functions to clean up the
main body of code.

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
hifive-unleashed-5.1
Dmitry Torokhov 2010-03-13 23:49:18 -08:00 committed by Greg Kroah-Hartman
parent 673fae90d5
commit bcb9bd18e3
1 changed files with 50 additions and 26 deletions

View File

@ -27,6 +27,52 @@ MODULE_AUTHOR("Manuel Estrada Sainz");
MODULE_DESCRIPTION("Multi purpose firmware loading support"); MODULE_DESCRIPTION("Multi purpose firmware loading support");
MODULE_LICENSE("GPL"); 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 { enum {
FW_STATUS_LOADING, FW_STATUS_LOADING,
FW_STATUS_DONE, FW_STATUS_DONE,
@ -53,14 +99,6 @@ struct firmware_priv {
bool nowait; bool nowait;
}; };
#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 static void
fw_load_abort(struct firmware_priv *fw_priv) fw_load_abort(struct firmware_priv *fw_priv)
{ {
@ -497,7 +535,6 @@ _request_firmware(const struct firmware **firmware_p, const char *name,
struct device *f_dev; struct device *f_dev;
struct firmware_priv *fw_priv; struct firmware_priv *fw_priv;
struct firmware *firmware; struct firmware *firmware;
struct builtin_fw *builtin;
int retval; int retval;
if (!firmware_p) if (!firmware_p)
@ -511,13 +548,8 @@ _request_firmware(const struct firmware **firmware_p, const char *name,
goto out; goto out;
} }
for (builtin = __start_builtin_fw; builtin != __end_builtin_fw; if (fw_get_builtin_firmware(firmware, name)) {
builtin++) {
if (strcmp(name, builtin->name))
continue;
dev_dbg(device, "firmware: using built-in firmware %s\n", name); dev_dbg(device, "firmware: using built-in firmware %s\n", name);
firmware->size = builtin->size;
firmware->data = builtin->data;
return 0; return 0;
} }
@ -589,19 +621,11 @@ request_firmware(const struct firmware **firmware_p, const char *name,
* release_firmware: - release the resource associated with a firmware image * release_firmware: - release the resource associated with a firmware image
* @fw: firmware resource to release * @fw: firmware resource to release
**/ **/
void void release_firmware(const struct firmware *fw)
release_firmware(const struct firmware *fw)
{ {
struct builtin_fw *builtin;
if (fw) { if (fw) {
for (builtin = __start_builtin_fw; builtin != __end_builtin_fw; if (!fw_is_builtin_firmware(fw))
builtin++) { firmware_free_data(fw);
if (fw->data == builtin->data)
goto free_fw;
}
firmware_free_data(fw);
free_fw:
kfree(fw); kfree(fw);
} }
} }