linux/drivers/base/firmware_loader/firmware.h

/* SPDX-License-Identifier: GPL-2.0 */
#ifndef __FIRMWARE_LOADER_H
#define __FIRMWARE_LOADER_H

#include <linux/bitops.h>
#include <linux/firmware.h>
#include <linux/types.h>
#include <linux/kref.h>
#include <linux/list.h>
#include <linux/completion.h>

/**
 * enum fw_opt - options to control firmware loading behaviour
 *
 * @FW_OPT_UEVENT: Enables the fallback mechanism to send a kobject uevent
 *	when the firmware is not found. Userspace is in charge to load the
 *	firmware using the sysfs loading facility.
 * @FW_OPT_NOWAIT: Used to describe the firmware request is asynchronous.
 * @FW_OPT_USERHELPER: Enable the fallback mechanism, in case the direct
 *	filesystem lookup fails at finding the firmware.  For details refer to
 *	firmware_fallback_sysfs().
 * @FW_OPT_NO_WARN: Quiet, avoid printing warning messages.
 * @FW_OPT_NOCACHE: Disables firmware caching. Firmware caching is used to
 *	cache the firmware upon suspend, so that upon resume races against the
 *	firmware file lookup on storage is avoided. Used for calls where the
 *	file may be too big, or where the driver takes charge of its own
 *	firmware caching mechanism.
 * @FW_OPT_NOFALLBACK_SYSFS: Disable the sysfs fallback mechanism. Takes
 *	precedence over &FW_OPT_UEVENT and &FW_OPT_USERHELPER.
 * @FW_OPT_FALLBACK_PLATFORM: Enable fallback to device fw copy embedded in
 *	the platform's main firmware. If both this fallback and the sysfs
 *      fallback are enabled, then this fallback will be tried first.
 * @FW_OPT_PARTIAL: Allow partial read of firmware instead of needing to read
 *	entire file.
 */
enum fw_opt {};

enum fw_status {};

/*
 * 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 fw_priv {};

extern struct mutex fw_lock;
extern struct firmware_cache fw_cache;
extern bool fw_load_abort_all;

static inline bool __fw_state_check(struct fw_priv *fw_priv,
				    enum fw_status status)
{}

static inline int __fw_state_wait_common(struct fw_priv *fw_priv, long timeout)
{}

static inline void __fw_state_set(struct fw_priv *fw_priv,
				  enum fw_status status)
{}

static inline void fw_state_aborted(struct fw_priv *fw_priv)
{}

static inline bool fw_state_is_aborted(struct fw_priv *fw_priv)
{}

static inline void fw_state_start(struct fw_priv *fw_priv)
{}

static inline void fw_state_done(struct fw_priv *fw_priv)
{}

static inline bool fw_state_is_done(struct fw_priv *fw_priv)
{}

static inline bool fw_state_is_loading(struct fw_priv *fw_priv)
{}

int alloc_lookup_fw_priv(const char *fw_name, struct firmware_cache *fwc,
			 struct fw_priv **fw_priv, void *dbuf, size_t size,
			 size_t offset, u32 opt_flags);
int assign_fw(struct firmware *fw, struct device *device);
void free_fw_priv(struct fw_priv *fw_priv);
void fw_state_init(struct fw_priv *fw_priv);

#ifdef CONFIG_FW_LOADER
bool firmware_is_builtin(const struct firmware *fw);
bool firmware_request_builtin_buf(struct firmware *fw, const char *name,
				  void *buf, size_t size);
#else /* module case */
static inline bool firmware_is_builtin(const struct firmware *fw)
{
	return false;
}
static inline bool firmware_request_builtin_buf(struct firmware *fw,
						const char *name,
						void *buf, size_t size)
{
	return false;
}
#endif

#ifdef CONFIG_FW_LOADER_PAGED_BUF
void fw_free_paged_buf(struct fw_priv *fw_priv);
int fw_grow_paged_buf(struct fw_priv *fw_priv, int pages_needed);
int fw_map_paged_buf(struct fw_priv *fw_priv);
bool fw_is_paged_buf(struct fw_priv *fw_priv);
#else
static inline void fw_free_paged_buf(struct fw_priv *fw_priv) {}
static inline int fw_grow_paged_buf(struct fw_priv *fw_priv, int pages_needed) { return -ENXIO; }
static inline int fw_map_paged_buf(struct fw_priv *fw_priv) { return -ENXIO; }
static inline bool fw_is_paged_buf(struct fw_priv *fw_priv) { return false; }
#endif

#endif /* __FIRMWARE_LOADER_H */