xref: /linux/drivers/base/firmware_loader/fallback.h (revision a4eb44a6435d6d8f9e642407a4a06f65eb90ca04)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __FIRMWARE_FALLBACK_H
3 #define __FIRMWARE_FALLBACK_H
4 
5 #include <linux/firmware.h>
6 #include <linux/device.h>
7 
8 #include "firmware.h"
9 
10 /**
11  * struct firmware_fallback_config - firmware fallback configuration settings
12  *
13  * Helps describe and fine tune the fallback mechanism.
14  *
15  * @force_sysfs_fallback: force the sysfs fallback mechanism to be used
16  * 	as if one had enabled CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y.
17  * 	Useful to help debug a CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y
18  * 	functionality on a kernel where that config entry has been disabled.
19  * @ignore_sysfs_fallback: force to disable the sysfs fallback mechanism.
20  * 	This emulates the behaviour as if we had set the kernel
21  * 	config CONFIG_FW_LOADER_USER_HELPER=n.
22  * @old_timeout: for internal use
23  * @loading_timeout: the timeout to wait for the fallback mechanism before
24  * 	giving up, in seconds.
25  */
26 struct firmware_fallback_config {
27 	unsigned int force_sysfs_fallback;
28 	unsigned int ignore_sysfs_fallback;
29 	int old_timeout;
30 	int loading_timeout;
31 };
32 
33 #ifdef CONFIG_FW_LOADER_USER_HELPER
34 int firmware_fallback_sysfs(struct firmware *fw, const char *name,
35 			    struct device *device,
36 			    u32 opt_flags,
37 			    int ret);
38 void kill_pending_fw_fallback_reqs(bool only_kill_custom);
39 
40 void fw_fallback_set_cache_timeout(void);
41 void fw_fallback_set_default_timeout(void);
42 
43 int register_sysfs_loader(void);
44 void unregister_sysfs_loader(void);
45 #ifdef CONFIG_SYSCTL
46 extern int register_firmware_config_sysctl(void);
47 extern void unregister_firmware_config_sysctl(void);
48 #else
49 static inline int register_firmware_config_sysctl(void)
50 {
51 	return 0;
52 }
53 static inline void unregister_firmware_config_sysctl(void) { }
54 #endif /* CONFIG_SYSCTL */
55 
56 #else /* CONFIG_FW_LOADER_USER_HELPER */
57 static inline int firmware_fallback_sysfs(struct firmware *fw, const char *name,
58 					  struct device *device,
59 					  u32 opt_flags,
60 					  int ret)
61 {
62 	/* Keep carrying over the same error */
63 	return ret;
64 }
65 
66 static inline void kill_pending_fw_fallback_reqs(bool only_kill_custom) { }
67 static inline void fw_fallback_set_cache_timeout(void) { }
68 static inline void fw_fallback_set_default_timeout(void) { }
69 
70 static inline int register_sysfs_loader(void)
71 {
72 	return 0;
73 }
74 
75 static inline void unregister_sysfs_loader(void)
76 {
77 }
78 #endif /* CONFIG_FW_LOADER_USER_HELPER */
79 
80 #ifdef CONFIG_EFI_EMBEDDED_FIRMWARE
81 int firmware_fallback_platform(struct fw_priv *fw_priv);
82 #else
83 static inline int firmware_fallback_platform(struct fw_priv *fw_priv)
84 {
85 	return -ENOENT;
86 }
87 #endif
88 
89 #endif /* __FIRMWARE_FALLBACK_H */
90