1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __FIRMWARE_SYSFS_H
3 #define __FIRMWARE_SYSFS_H
5 #include <linux/device.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
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
;
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
;
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);
58 static inline int register_firmware_config_sysctl(void)
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)
71 static inline void unregister_sysfs_loader(void)
74 #endif /* CONFIG_FW_LOADER_SYSFS */
79 struct fw_priv
*fw_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
);
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
);
108 static inline int fw_upload_start(struct fw_sysfs
*fw_sysfs
)
113 static inline void fw_upload_free(struct fw_sysfs
*fw_sysfs
)
118 #endif /* __FIRMWARE_SYSFS_H */