18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef __FIRMWARE_FALLBACK_H
38c2ecf20Sopenharmony_ci#define __FIRMWARE_FALLBACK_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <linux/firmware.h>
68c2ecf20Sopenharmony_ci#include <linux/device.h>
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include "firmware.h"
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci/**
118c2ecf20Sopenharmony_ci * struct firmware_fallback_config - firmware fallback configuration settings
128c2ecf20Sopenharmony_ci *
138c2ecf20Sopenharmony_ci * Helps describe and fine tune the fallback mechanism.
148c2ecf20Sopenharmony_ci *
158c2ecf20Sopenharmony_ci * @force_sysfs_fallback: force the sysfs fallback mechanism to be used
168c2ecf20Sopenharmony_ci * 	as if one had enabled CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y.
178c2ecf20Sopenharmony_ci * 	Useful to help debug a CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y
188c2ecf20Sopenharmony_ci * 	functionality on a kernel where that config entry has been disabled.
198c2ecf20Sopenharmony_ci * @ignore_sysfs_fallback: force to disable the sysfs fallback mechanism.
208c2ecf20Sopenharmony_ci * 	This emulates the behaviour as if we had set the kernel
218c2ecf20Sopenharmony_ci * 	config CONFIG_FW_LOADER_USER_HELPER=n.
228c2ecf20Sopenharmony_ci * @old_timeout: for internal use
238c2ecf20Sopenharmony_ci * @loading_timeout: the timeout to wait for the fallback mechanism before
248c2ecf20Sopenharmony_ci * 	giving up, in seconds.
258c2ecf20Sopenharmony_ci */
268c2ecf20Sopenharmony_cistruct firmware_fallback_config {
278c2ecf20Sopenharmony_ci	unsigned int force_sysfs_fallback;
288c2ecf20Sopenharmony_ci	unsigned int ignore_sysfs_fallback;
298c2ecf20Sopenharmony_ci	int old_timeout;
308c2ecf20Sopenharmony_ci	int loading_timeout;
318c2ecf20Sopenharmony_ci};
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci#ifdef CONFIG_FW_LOADER_USER_HELPER
348c2ecf20Sopenharmony_ciint firmware_fallback_sysfs(struct firmware *fw, const char *name,
358c2ecf20Sopenharmony_ci			    struct device *device,
368c2ecf20Sopenharmony_ci			    u32 opt_flags,
378c2ecf20Sopenharmony_ci			    int ret);
388c2ecf20Sopenharmony_civoid kill_pending_fw_fallback_reqs(bool only_kill_custom);
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_civoid fw_fallback_set_cache_timeout(void);
418c2ecf20Sopenharmony_civoid fw_fallback_set_default_timeout(void);
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ciint register_sysfs_loader(void);
448c2ecf20Sopenharmony_civoid unregister_sysfs_loader(void);
458c2ecf20Sopenharmony_ci#else /* CONFIG_FW_LOADER_USER_HELPER */
468c2ecf20Sopenharmony_cistatic inline int firmware_fallback_sysfs(struct firmware *fw, const char *name,
478c2ecf20Sopenharmony_ci					  struct device *device,
488c2ecf20Sopenharmony_ci					  u32 opt_flags,
498c2ecf20Sopenharmony_ci					  int ret)
508c2ecf20Sopenharmony_ci{
518c2ecf20Sopenharmony_ci	/* Keep carrying over the same error */
528c2ecf20Sopenharmony_ci	return ret;
538c2ecf20Sopenharmony_ci}
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_cistatic inline void kill_pending_fw_fallback_reqs(bool only_kill_custom) { }
568c2ecf20Sopenharmony_cistatic inline void fw_fallback_set_cache_timeout(void) { }
578c2ecf20Sopenharmony_cistatic inline void fw_fallback_set_default_timeout(void) { }
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_cistatic inline int register_sysfs_loader(void)
608c2ecf20Sopenharmony_ci{
618c2ecf20Sopenharmony_ci	return 0;
628c2ecf20Sopenharmony_ci}
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_cistatic inline void unregister_sysfs_loader(void)
658c2ecf20Sopenharmony_ci{
668c2ecf20Sopenharmony_ci}
678c2ecf20Sopenharmony_ci#endif /* CONFIG_FW_LOADER_USER_HELPER */
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci#ifdef CONFIG_EFI_EMBEDDED_FIRMWARE
708c2ecf20Sopenharmony_ciint firmware_fallback_platform(struct fw_priv *fw_priv);
718c2ecf20Sopenharmony_ci#else
728c2ecf20Sopenharmony_cistatic inline int firmware_fallback_platform(struct fw_priv *fw_priv)
738c2ecf20Sopenharmony_ci{
748c2ecf20Sopenharmony_ci	return -ENOENT;
758c2ecf20Sopenharmony_ci}
768c2ecf20Sopenharmony_ci#endif
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci#endif /* __FIRMWARE_FALLBACK_H */
79