Merge tag 'clk-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux.git] / drivers / base / firmware_loader / sysfs.h
blob1cabea544a40bc5391e347ceaf02d46381b46318
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __FIRMWARE_SYSFS_H
3 #define __FIRMWARE_SYSFS_H
5 #include <linux/device.h>
7 #include "firmware.h"
9 MODULE_IMPORT_NS("FIRMWARE_LOADER_PRIVATE");
11 extern struct firmware_fallback_config fw_fallback_config;
12 extern struct device_attribute dev_attr_loading;
14 #ifdef CONFIG_FW_LOADER_USER_HELPER
15 /**
16 * struct firmware_fallback_config - firmware fallback configuration settings
18 * Helps describe and fine tune the fallback mechanism.
20 * @force_sysfs_fallback: force the sysfs fallback mechanism to be used
21 * as if one had enabled CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y.
22 * Useful to help debug a CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y
23 * functionality on a kernel where that config entry has been disabled.
24 * @ignore_sysfs_fallback: force to disable the sysfs fallback mechanism.
25 * This emulates the behaviour as if we had set the kernel
26 * config CONFIG_FW_LOADER_USER_HELPER=n.
27 * @old_timeout: for internal use
28 * @loading_timeout: the timeout to wait for the fallback mechanism before
29 * giving up, in seconds.
31 struct firmware_fallback_config {
32 unsigned int force_sysfs_fallback;
33 unsigned int ignore_sysfs_fallback;
34 int old_timeout;
35 int loading_timeout;
38 /* These getters are vetted to use int properly */
39 static inline int __firmware_loading_timeout(void)
41 return fw_fallback_config.loading_timeout;
44 /* These setters are vetted to use int properly */
45 static inline void __fw_fallback_set_timeout(int timeout)
47 fw_fallback_config.loading_timeout = timeout;
49 #endif
51 #ifdef CONFIG_FW_LOADER_SYSFS
52 int register_sysfs_loader(void);
53 void unregister_sysfs_loader(void);
54 #if defined(CONFIG_FW_LOADER_USER_HELPER) && defined(CONFIG_SYSCTL)
55 int register_firmware_config_sysctl(void);
56 void unregister_firmware_config_sysctl(void);
57 #else
58 static inline int register_firmware_config_sysctl(void)
60 return 0;
63 static inline void unregister_firmware_config_sysctl(void) { }
64 #endif /* CONFIG_FW_LOADER_USER_HELPER && CONFIG_SYSCTL */
65 #else /* CONFIG_FW_LOADER_SYSFS */
66 static inline int register_sysfs_loader(void)
68 return 0;
71 static inline void unregister_sysfs_loader(void)
74 #endif /* CONFIG_FW_LOADER_SYSFS */
76 struct fw_sysfs {
77 bool nowait;
78 struct device dev;
79 struct fw_priv *fw_priv;
80 struct firmware *fw;
81 void *fw_upload_priv;
83 #define to_fw_sysfs(__dev) container_of_const(__dev, struct fw_sysfs, dev)
85 void __fw_load_abort(struct fw_priv *fw_priv);
87 static inline void fw_load_abort(struct fw_sysfs *fw_sysfs)
89 struct fw_priv *fw_priv = fw_sysfs->fw_priv;
91 __fw_load_abort(fw_priv);
94 struct fw_sysfs *
95 fw_create_instance(struct firmware *firmware, const char *fw_name,
96 struct device *device, u32 opt_flags);
98 #ifdef CONFIG_FW_UPLOAD
99 extern struct device_attribute dev_attr_status;
100 extern struct device_attribute dev_attr_error;
101 extern struct device_attribute dev_attr_cancel;
102 extern struct device_attribute dev_attr_remaining_size;
104 int fw_upload_start(struct fw_sysfs *fw_sysfs);
105 void fw_upload_free(struct fw_sysfs *fw_sysfs);
106 umode_t fw_upload_is_visible(struct kobject *kobj, struct attribute *attr, int n);
107 #else
108 static inline int fw_upload_start(struct fw_sysfs *fw_sysfs)
110 return 0;
113 static inline void fw_upload_free(struct fw_sysfs *fw_sysfs)
116 #endif
118 #endif /* __FIRMWARE_SYSFS_H */