Skip to content

Commit

Permalink
firmware: move core data structures to the top of file
Browse files Browse the repository at this point in the history
Move main core data structures used internally for firmware to the top
of the file. This will allow us to use them earlier later in helpers as
we extend their use.

Signed-off-by: Luis R. Rodriguez <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
mcgrof authored and gregkh committed Nov 29, 2017
1 parent 31034f2 commit be8d462
Showing 1 changed file with 95 additions and 95 deletions.
190 changes: 95 additions & 95 deletions drivers/base/firmware_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,101 @@ MODULE_AUTHOR("Manuel Estrada Sainz");
MODULE_DESCRIPTION("Multi purpose firmware loading support");
MODULE_LICENSE("GPL");

enum fw_status {
FW_STATUS_UNKNOWN,
FW_STATUS_LOADING,
FW_STATUS_DONE,
FW_STATUS_ABORTED,
};

/*
* Concurrent request_firmware() for the same firmware need to be
* serialized. struct fw_state is simple state machine which hold the
* state of the firmware loading.
*/
struct fw_state {
struct completion completion;
enum fw_status status;
};

/* firmware behavior options */
#define FW_OPT_UEVENT (1U << 0)
#define FW_OPT_NOWAIT (1U << 1)
#ifdef CONFIG_FW_LOADER_USER_HELPER
#define FW_OPT_USERHELPER (1U << 2)
#else
#define FW_OPT_USERHELPER 0
#endif
#ifdef CONFIG_FW_LOADER_USER_HELPER_FALLBACK
#define FW_OPT_FALLBACK FW_OPT_USERHELPER
#else
#define FW_OPT_FALLBACK 0
#endif
#define FW_OPT_NO_WARN (1U << 3)
#define FW_OPT_NOCACHE (1U << 4)

struct firmware_cache {
/* firmware_buf instance will be added into the below list */
spinlock_t lock;
struct list_head head;
int state;

#ifdef CONFIG_PM_SLEEP
/*
* Names of firmware images which have been cached successfully
* will be added into the below list so that device uncache
* helper can trace which firmware images have been cached
* before.
*/
spinlock_t name_lock;
struct list_head fw_names;

struct delayed_work work;

struct notifier_block pm_notify;
#endif
};

struct fw_priv {
struct kref ref;
struct list_head list;
struct firmware_cache *fwc;
struct fw_state fw_st;
void *data;
size_t size;
size_t allocated_size;
#ifdef CONFIG_FW_LOADER_USER_HELPER
bool is_paged_buf;
bool need_uevent;
struct page **pages;
int nr_pages;
int page_array_size;
struct list_head pending_list;
#endif
const char *fw_name;
};

struct fw_cache_entry {
struct list_head list;
const char *name;
};

struct fw_name_devm {
unsigned long magic;
const char *name;
};

#define to_fw_priv(d) container_of(d, struct fw_priv, ref)

#define FW_LOADER_NO_CACHE 0
#define FW_LOADER_START_CACHE 1

/* fw_lock could be moved to 'struct fw_sysfs' but since it is just
* guarding for corner cases a global lock should be OK */
static DEFINE_MUTEX(fw_lock);

static struct firmware_cache fw_cache;

/* Builtin firmware support */

#ifdef CONFIG_FW_LOADER
Expand Down Expand Up @@ -93,30 +188,13 @@ static inline bool fw_is_builtin_firmware(const struct firmware *fw)
}
#endif

enum fw_status {
FW_STATUS_UNKNOWN,
FW_STATUS_LOADING,
FW_STATUS_DONE,
FW_STATUS_ABORTED,
};

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

static inline long firmware_loading_timeout(void)
{
return loading_timeout > 0 ? loading_timeout * HZ : MAX_JIFFY_OFFSET;
}

/*
* Concurrent request_firmware() for the same firmware need to be
* serialized. struct fw_state is simple state machine which hold the
* state of the firmware loading.
*/
struct fw_state {
struct completion completion;
enum fw_status status;
};

static void fw_state_init(struct fw_state *fw_st)
{
init_completion(&fw_st->completion);
Expand Down Expand Up @@ -180,86 +258,8 @@ static int __fw_state_check(struct fw_state *fw_st, enum fw_status status)

#endif /* CONFIG_FW_LOADER_USER_HELPER */

/* firmware behavior options */
#define FW_OPT_UEVENT (1U << 0)
#define FW_OPT_NOWAIT (1U << 1)
#ifdef CONFIG_FW_LOADER_USER_HELPER
#define FW_OPT_USERHELPER (1U << 2)
#else
#define FW_OPT_USERHELPER 0
#endif
#ifdef CONFIG_FW_LOADER_USER_HELPER_FALLBACK
#define FW_OPT_FALLBACK FW_OPT_USERHELPER
#else
#define FW_OPT_FALLBACK 0
#endif
#define FW_OPT_NO_WARN (1U << 3)
#define FW_OPT_NOCACHE (1U << 4)

struct firmware_cache {
/* firmware_buf instance will be added into the below list */
spinlock_t lock;
struct list_head head;
int state;

#ifdef CONFIG_PM_SLEEP
/*
* Names of firmware images which have been cached successfully
* will be added into the below list so that device uncache
* helper can trace which firmware images have been cached
* before.
*/
spinlock_t name_lock;
struct list_head fw_names;

struct delayed_work work;

struct notifier_block pm_notify;
#endif
};

struct fw_priv {
struct kref ref;
struct list_head list;
struct firmware_cache *fwc;
struct fw_state fw_st;
void *data;
size_t size;
size_t allocated_size;
#ifdef CONFIG_FW_LOADER_USER_HELPER
bool is_paged_buf;
bool need_uevent;
struct page **pages;
int nr_pages;
int page_array_size;
struct list_head pending_list;
#endif
const char *fw_name;
};

struct fw_cache_entry {
struct list_head list;
const char *name;
};

struct fw_name_devm {
unsigned long magic;
const char *name;
};

#define to_fw_priv(d) container_of(d, struct fw_priv, ref)

#define FW_LOADER_NO_CACHE 0
#define FW_LOADER_START_CACHE 1

static int fw_cache_piggyback_on_request(const char *name);

/* fw_lock could be moved to 'struct fw_sysfs' but since it is just
* guarding for corner cases a global lock should be OK */
static DEFINE_MUTEX(fw_lock);

static struct firmware_cache fw_cache;

static struct fw_priv *__allocate_fw_priv(const char *fw_name,
struct firmware_cache *fwc,
void *dbuf, size_t size)
Expand Down

0 comments on commit be8d462

Please sign in to comment.