Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __FIRMWARE_SYSFS_H
0003 #define __FIRMWARE_SYSFS_H
0004 
0005 #include <linux/device.h>
0006 
0007 #include "firmware.h"
0008 
0009 MODULE_IMPORT_NS(FIRMWARE_LOADER_PRIVATE);
0010 
0011 extern struct firmware_fallback_config fw_fallback_config;
0012 extern struct device_attribute dev_attr_loading;
0013 
0014 #ifdef CONFIG_FW_LOADER_USER_HELPER
0015 /**
0016  * struct firmware_fallback_config - firmware fallback configuration settings
0017  *
0018  * Helps describe and fine tune the fallback mechanism.
0019  *
0020  * @force_sysfs_fallback: force the sysfs fallback mechanism to be used
0021  *  as if one had enabled CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y.
0022  *  Useful to help debug a CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y
0023  *  functionality on a kernel where that config entry has been disabled.
0024  * @ignore_sysfs_fallback: force to disable the sysfs fallback mechanism.
0025  *  This emulates the behaviour as if we had set the kernel
0026  *  config CONFIG_FW_LOADER_USER_HELPER=n.
0027  * @old_timeout: for internal use
0028  * @loading_timeout: the timeout to wait for the fallback mechanism before
0029  *  giving up, in seconds.
0030  */
0031 struct firmware_fallback_config {
0032     unsigned int force_sysfs_fallback;
0033     unsigned int ignore_sysfs_fallback;
0034     int old_timeout;
0035     int loading_timeout;
0036 };
0037 
0038 /* These getters are vetted to use int properly */
0039 static inline int __firmware_loading_timeout(void)
0040 {
0041     return fw_fallback_config.loading_timeout;
0042 }
0043 
0044 /* These setters are vetted to use int properly */
0045 static inline void __fw_fallback_set_timeout(int timeout)
0046 {
0047     fw_fallback_config.loading_timeout = timeout;
0048 }
0049 #endif
0050 
0051 #ifdef CONFIG_FW_LOADER_SYSFS
0052 int register_sysfs_loader(void);
0053 void unregister_sysfs_loader(void);
0054 #if defined(CONFIG_FW_LOADER_USER_HELPER) && defined(CONFIG_SYSCTL)
0055 int register_firmware_config_sysctl(void);
0056 void unregister_firmware_config_sysctl(void);
0057 #else
0058 static inline int register_firmware_config_sysctl(void)
0059 {
0060     return 0;
0061 }
0062 
0063 static inline void unregister_firmware_config_sysctl(void) { }
0064 #endif /* CONFIG_FW_LOADER_USER_HELPER && CONFIG_SYSCTL */
0065 #else /* CONFIG_FW_LOADER_SYSFS */
0066 static inline int register_sysfs_loader(void)
0067 {
0068     return 0;
0069 }
0070 
0071 static inline void unregister_sysfs_loader(void)
0072 {
0073 }
0074 #endif /* CONFIG_FW_LOADER_SYSFS */
0075 
0076 struct fw_sysfs {
0077     bool nowait;
0078     struct device dev;
0079     struct fw_priv *fw_priv;
0080     struct firmware *fw;
0081     void *fw_upload_priv;
0082 };
0083 
0084 static inline struct fw_sysfs *to_fw_sysfs(struct device *dev)
0085 {
0086     return container_of(dev, struct fw_sysfs, dev);
0087 }
0088 
0089 void __fw_load_abort(struct fw_priv *fw_priv);
0090 
0091 static inline void fw_load_abort(struct fw_sysfs *fw_sysfs)
0092 {
0093     struct fw_priv *fw_priv = fw_sysfs->fw_priv;
0094 
0095     __fw_load_abort(fw_priv);
0096 }
0097 
0098 struct fw_sysfs *
0099 fw_create_instance(struct firmware *firmware, const char *fw_name,
0100            struct device *device, u32 opt_flags);
0101 
0102 #ifdef CONFIG_FW_UPLOAD
0103 extern struct device_attribute dev_attr_status;
0104 extern struct device_attribute dev_attr_error;
0105 extern struct device_attribute dev_attr_cancel;
0106 extern struct device_attribute dev_attr_remaining_size;
0107 
0108 int fw_upload_start(struct fw_sysfs *fw_sysfs);
0109 void fw_upload_free(struct fw_sysfs *fw_sysfs);
0110 umode_t fw_upload_is_visible(struct kobject *kobj, struct attribute *attr, int n);
0111 #else
0112 static inline int fw_upload_start(struct fw_sysfs *fw_sysfs)
0113 {
0114     return 0;
0115 }
0116 
0117 static inline void fw_upload_free(struct fw_sysfs *fw_sysfs)
0118 {
0119 }
0120 #endif
0121 
0122 #endif /* __FIRMWARE_SYSFS_H */