Luis R. Rodriguez | d73f821 | 2018-03-10 06:14:49 -0800 | [diff] [blame] | 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 | |
Andres Rodriguez | eb33eb0 | 2018-05-10 13:08:37 -0700 | [diff] [blame] | 8 | #include "firmware.h" |
| 9 | |
Luis R. Rodriguez | d73f821 | 2018-03-10 06:14:49 -0800 | [diff] [blame] | 10 | /** |
Andres Rodriguez | b93815d | 2018-04-25 12:25:39 -0400 | [diff] [blame] | 11 | * struct firmware_fallback_config - firmware fallback configuration settings |
Luis R. Rodriguez | d73f821 | 2018-03-10 06:14:49 -0800 | [diff] [blame] | 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. |
Luis R. Rodriguez | ceb1813 | 2018-03-10 06:14:51 -0800 | [diff] [blame] | 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. |
Luis R. Rodriguez | 2cd7a1c | 2018-03-10 06:14:52 -0800 | [diff] [blame] | 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. |
Luis R. Rodriguez | d73f821 | 2018-03-10 06:14:49 -0800 | [diff] [blame] | 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 { |
Luis R. Rodriguez | ceb1813 | 2018-03-10 06:14:51 -0800 | [diff] [blame] | 27 | unsigned int force_sysfs_fallback; |
Luis R. Rodriguez | 2cd7a1c | 2018-03-10 06:14:52 -0800 | [diff] [blame] | 28 | unsigned int ignore_sysfs_fallback; |
Luis R. Rodriguez | d73f821 | 2018-03-10 06:14:49 -0800 | [diff] [blame] | 29 | int old_timeout; |
| 30 | int loading_timeout; |
| 31 | }; |
| 32 | |
| 33 | #ifdef CONFIG_FW_LOADER_USER_HELPER |
Andres Rodriguez | cf1cde7 | 2018-05-10 13:08:39 -0700 | [diff] [blame] | 34 | int firmware_fallback_sysfs(struct firmware *fw, const char *name, |
| 35 | struct device *device, |
| 36 | enum fw_opt opt_flags, |
| 37 | int ret); |
Luis R. Rodriguez | d73f821 | 2018-03-10 06:14:49 -0800 | [diff] [blame] | 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 | #else /* CONFIG_FW_LOADER_USER_HELPER */ |
Andres Rodriguez | cf1cde7 | 2018-05-10 13:08:39 -0700 | [diff] [blame] | 46 | static inline int firmware_fallback_sysfs(struct firmware *fw, const char *name, |
| 47 | struct device *device, |
| 48 | enum fw_opt opt_flags, |
| 49 | int ret) |
Luis R. Rodriguez | d73f821 | 2018-03-10 06:14:49 -0800 | [diff] [blame] | 50 | { |
| 51 | /* Keep carrying over the same error */ |
| 52 | return ret; |
| 53 | } |
| 54 | |
| 55 | static inline void kill_pending_fw_fallback_reqs(bool only_kill_custom) { } |
| 56 | static inline void fw_fallback_set_cache_timeout(void) { } |
| 57 | static inline void fw_fallback_set_default_timeout(void) { } |
| 58 | |
| 59 | static inline int register_sysfs_loader(void) |
| 60 | { |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | static inline void unregister_sysfs_loader(void) |
| 65 | { |
| 66 | } |
| 67 | #endif /* CONFIG_FW_LOADER_USER_HELPER */ |
| 68 | |
Hans de Goede | e4c2c0f | 2020-01-15 17:35:48 +0100 | [diff] [blame] | 69 | #ifdef CONFIG_EFI_EMBEDDED_FIRMWARE |
| 70 | int firmware_fallback_platform(struct fw_priv *fw_priv, enum fw_opt opt_flags); |
| 71 | #else |
| 72 | static inline int firmware_fallback_platform(struct fw_priv *fw_priv, |
| 73 | enum fw_opt opt_flags) |
| 74 | { |
| 75 | return -ENOENT; |
| 76 | } |
| 77 | #endif |
| 78 | |
Luis R. Rodriguez | d73f821 | 2018-03-10 06:14:49 -0800 | [diff] [blame] | 79 | #endif /* __FIRMWARE_FALLBACK_H */ |