1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef __FIRMWARE_SYSFS_H 3 #define __FIRMWARE_SYSFS_H 4 5 #include <linux/device.h> 6 7 #include "firmware.h" 8 9 MODULE_IMPORT_NS(FIRMWARE_LOADER_PRIVATE); 10 11 extern struct firmware_fallback_config fw_fallback_config; 12 extern struct device_attribute dev_attr_loading; 13 14 #ifdef CONFIG_FW_LOADER_USER_HELPER 15 /** 16 * struct firmware_fallback_config - firmware fallback configuration settings 17 * 18 * Helps describe and fine tune the fallback mechanism. 19 * 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. 30 */ 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; 36 }; 37 38 /* These getters are vetted to use int properly */ 39 static inline int __firmware_loading_timeout(void) 40 { 41 return fw_fallback_config.loading_timeout; 42 } 43 44 /* These setters are vetted to use int properly */ 45 static inline void __fw_fallback_set_timeout(int timeout) 46 { 47 fw_fallback_config.loading_timeout = timeout; 48 } 49 #endif 50 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) 59 { 60 return 0; 61 } 62 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) 67 { 68 return 0; 69 } 70 71 static inline void unregister_sysfs_loader(void) 72 { 73 } 74 #endif /* CONFIG_FW_LOADER_SYSFS */ 75 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; 82 }; 83 #define to_fw_sysfs(__dev) container_of_const(__dev, struct fw_sysfs, dev) 84 85 void __fw_load_abort(struct fw_priv *fw_priv); 86 87 static inline void fw_load_abort(struct fw_sysfs *fw_sysfs) 88 { 89 struct fw_priv *fw_priv = fw_sysfs->fw_priv; 90 91 __fw_load_abort(fw_priv); 92 } 93 94 struct fw_sysfs * 95 fw_create_instance(struct firmware *firmware, const char *fw_name, 96 struct device *device, u32 opt_flags); 97 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; 103 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) 109 { 110 return 0; 111 } 112 113 static inline void fw_upload_free(struct fw_sysfs *fw_sysfs) 114 { 115 } 116 #endif 117 118 #endif /* __FIRMWARE_SYSFS_H */ 119