162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci#ifndef __FIRMWARE_SYSFS_H 362306a36Sopenharmony_ci#define __FIRMWARE_SYSFS_H 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci#include <linux/device.h> 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci#include "firmware.h" 862306a36Sopenharmony_ci 962306a36Sopenharmony_ciMODULE_IMPORT_NS(FIRMWARE_LOADER_PRIVATE); 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ciextern struct firmware_fallback_config fw_fallback_config; 1262306a36Sopenharmony_ciextern struct device_attribute dev_attr_loading; 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci#ifdef CONFIG_FW_LOADER_USER_HELPER 1562306a36Sopenharmony_ci/** 1662306a36Sopenharmony_ci * struct firmware_fallback_config - firmware fallback configuration settings 1762306a36Sopenharmony_ci * 1862306a36Sopenharmony_ci * Helps describe and fine tune the fallback mechanism. 1962306a36Sopenharmony_ci * 2062306a36Sopenharmony_ci * @force_sysfs_fallback: force the sysfs fallback mechanism to be used 2162306a36Sopenharmony_ci * as if one had enabled CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y. 2262306a36Sopenharmony_ci * Useful to help debug a CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y 2362306a36Sopenharmony_ci * functionality on a kernel where that config entry has been disabled. 2462306a36Sopenharmony_ci * @ignore_sysfs_fallback: force to disable the sysfs fallback mechanism. 2562306a36Sopenharmony_ci * This emulates the behaviour as if we had set the kernel 2662306a36Sopenharmony_ci * config CONFIG_FW_LOADER_USER_HELPER=n. 2762306a36Sopenharmony_ci * @old_timeout: for internal use 2862306a36Sopenharmony_ci * @loading_timeout: the timeout to wait for the fallback mechanism before 2962306a36Sopenharmony_ci * giving up, in seconds. 3062306a36Sopenharmony_ci */ 3162306a36Sopenharmony_cistruct firmware_fallback_config { 3262306a36Sopenharmony_ci unsigned int force_sysfs_fallback; 3362306a36Sopenharmony_ci unsigned int ignore_sysfs_fallback; 3462306a36Sopenharmony_ci int old_timeout; 3562306a36Sopenharmony_ci int loading_timeout; 3662306a36Sopenharmony_ci}; 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci/* These getters are vetted to use int properly */ 3962306a36Sopenharmony_cistatic inline int __firmware_loading_timeout(void) 4062306a36Sopenharmony_ci{ 4162306a36Sopenharmony_ci return fw_fallback_config.loading_timeout; 4262306a36Sopenharmony_ci} 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ci/* These setters are vetted to use int properly */ 4562306a36Sopenharmony_cistatic inline void __fw_fallback_set_timeout(int timeout) 4662306a36Sopenharmony_ci{ 4762306a36Sopenharmony_ci fw_fallback_config.loading_timeout = timeout; 4862306a36Sopenharmony_ci} 4962306a36Sopenharmony_ci#endif 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci#ifdef CONFIG_FW_LOADER_SYSFS 5262306a36Sopenharmony_ciint register_sysfs_loader(void); 5362306a36Sopenharmony_civoid unregister_sysfs_loader(void); 5462306a36Sopenharmony_ci#if defined(CONFIG_FW_LOADER_USER_HELPER) && defined(CONFIG_SYSCTL) 5562306a36Sopenharmony_ciint register_firmware_config_sysctl(void); 5662306a36Sopenharmony_civoid unregister_firmware_config_sysctl(void); 5762306a36Sopenharmony_ci#else 5862306a36Sopenharmony_cistatic inline int register_firmware_config_sysctl(void) 5962306a36Sopenharmony_ci{ 6062306a36Sopenharmony_ci return 0; 6162306a36Sopenharmony_ci} 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_cistatic inline void unregister_firmware_config_sysctl(void) { } 6462306a36Sopenharmony_ci#endif /* CONFIG_FW_LOADER_USER_HELPER && CONFIG_SYSCTL */ 6562306a36Sopenharmony_ci#else /* CONFIG_FW_LOADER_SYSFS */ 6662306a36Sopenharmony_cistatic inline int register_sysfs_loader(void) 6762306a36Sopenharmony_ci{ 6862306a36Sopenharmony_ci return 0; 6962306a36Sopenharmony_ci} 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_cistatic inline void unregister_sysfs_loader(void) 7262306a36Sopenharmony_ci{ 7362306a36Sopenharmony_ci} 7462306a36Sopenharmony_ci#endif /* CONFIG_FW_LOADER_SYSFS */ 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_cistruct fw_sysfs { 7762306a36Sopenharmony_ci bool nowait; 7862306a36Sopenharmony_ci struct device dev; 7962306a36Sopenharmony_ci struct fw_priv *fw_priv; 8062306a36Sopenharmony_ci struct firmware *fw; 8162306a36Sopenharmony_ci void *fw_upload_priv; 8262306a36Sopenharmony_ci}; 8362306a36Sopenharmony_ci#define to_fw_sysfs(__dev) container_of_const(__dev, struct fw_sysfs, dev) 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_civoid __fw_load_abort(struct fw_priv *fw_priv); 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_cistatic inline void fw_load_abort(struct fw_sysfs *fw_sysfs) 8862306a36Sopenharmony_ci{ 8962306a36Sopenharmony_ci struct fw_priv *fw_priv = fw_sysfs->fw_priv; 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ci __fw_load_abort(fw_priv); 9262306a36Sopenharmony_ci} 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_cistruct fw_sysfs * 9562306a36Sopenharmony_cifw_create_instance(struct firmware *firmware, const char *fw_name, 9662306a36Sopenharmony_ci struct device *device, u32 opt_flags); 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ci#ifdef CONFIG_FW_UPLOAD 9962306a36Sopenharmony_ciextern struct device_attribute dev_attr_status; 10062306a36Sopenharmony_ciextern struct device_attribute dev_attr_error; 10162306a36Sopenharmony_ciextern struct device_attribute dev_attr_cancel; 10262306a36Sopenharmony_ciextern struct device_attribute dev_attr_remaining_size; 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_ciint fw_upload_start(struct fw_sysfs *fw_sysfs); 10562306a36Sopenharmony_civoid fw_upload_free(struct fw_sysfs *fw_sysfs); 10662306a36Sopenharmony_ciumode_t fw_upload_is_visible(struct kobject *kobj, struct attribute *attr, int n); 10762306a36Sopenharmony_ci#else 10862306a36Sopenharmony_cistatic inline int fw_upload_start(struct fw_sysfs *fw_sysfs) 10962306a36Sopenharmony_ci{ 11062306a36Sopenharmony_ci return 0; 11162306a36Sopenharmony_ci} 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_cistatic inline void fw_upload_free(struct fw_sysfs *fw_sysfs) 11462306a36Sopenharmony_ci{ 11562306a36Sopenharmony_ci} 11662306a36Sopenharmony_ci#endif 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_ci#endif /* __FIRMWARE_SYSFS_H */ 119