sysfs.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __FIRMWARE_SYSFS_H
  3. #define __FIRMWARE_SYSFS_H
  4. #include <linux/device.h>
  5. #include "firmware.h"
  6. MODULE_IMPORT_NS(FIRMWARE_LOADER_PRIVATE);
  7. extern struct firmware_fallback_config fw_fallback_config;
  8. extern struct device_attribute dev_attr_loading;
  9. #ifdef CONFIG_FW_LOADER_USER_HELPER
  10. /**
  11. * struct firmware_fallback_config - firmware fallback configuration settings
  12. *
  13. * Helps describe and fine tune the fallback mechanism.
  14. *
  15. * @force_sysfs_fallback: force the sysfs fallback mechanism to be used
  16. * as if one had enabled CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y.
  17. * Useful to help debug a CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y
  18. * functionality on a kernel where that config entry has been disabled.
  19. * @ignore_sysfs_fallback: force to disable the sysfs fallback mechanism.
  20. * This emulates the behaviour as if we had set the kernel
  21. * config CONFIG_FW_LOADER_USER_HELPER=n.
  22. * @old_timeout: for internal use
  23. * @loading_timeout: the timeout to wait for the fallback mechanism before
  24. * giving up, in seconds.
  25. */
  26. struct firmware_fallback_config {
  27. unsigned int force_sysfs_fallback;
  28. unsigned int ignore_sysfs_fallback;
  29. int old_timeout;
  30. int loading_timeout;
  31. };
  32. /* These getters are vetted to use int properly */
  33. static inline int __firmware_loading_timeout(void)
  34. {
  35. return fw_fallback_config.loading_timeout;
  36. }
  37. /* These setters are vetted to use int properly */
  38. static inline void __fw_fallback_set_timeout(int timeout)
  39. {
  40. fw_fallback_config.loading_timeout = timeout;
  41. }
  42. #endif
  43. #ifdef CONFIG_FW_LOADER_SYSFS
  44. int register_sysfs_loader(void);
  45. void unregister_sysfs_loader(void);
  46. #if defined(CONFIG_FW_LOADER_USER_HELPER) && defined(CONFIG_SYSCTL)
  47. int register_firmware_config_sysctl(void);
  48. void unregister_firmware_config_sysctl(void);
  49. #else
  50. static inline int register_firmware_config_sysctl(void)
  51. {
  52. return 0;
  53. }
  54. static inline void unregister_firmware_config_sysctl(void) { }
  55. #endif /* CONFIG_FW_LOADER_USER_HELPER && CONFIG_SYSCTL */
  56. #else /* CONFIG_FW_LOADER_SYSFS */
  57. static inline int register_sysfs_loader(void)
  58. {
  59. return 0;
  60. }
  61. static inline void unregister_sysfs_loader(void)
  62. {
  63. }
  64. #endif /* CONFIG_FW_LOADER_SYSFS */
  65. struct fw_sysfs {
  66. bool nowait;
  67. struct device dev;
  68. struct fw_priv *fw_priv;
  69. struct firmware *fw;
  70. void *fw_upload_priv;
  71. };
  72. static inline struct fw_sysfs *to_fw_sysfs(struct device *dev)
  73. {
  74. return container_of(dev, struct fw_sysfs, dev);
  75. }
  76. void __fw_load_abort(struct fw_priv *fw_priv);
  77. static inline void fw_load_abort(struct fw_sysfs *fw_sysfs)
  78. {
  79. struct fw_priv *fw_priv = fw_sysfs->fw_priv;
  80. __fw_load_abort(fw_priv);
  81. }
  82. struct fw_sysfs *
  83. fw_create_instance(struct firmware *firmware, const char *fw_name,
  84. struct device *device, u32 opt_flags);
  85. #ifdef CONFIG_FW_UPLOAD
  86. extern struct device_attribute dev_attr_status;
  87. extern struct device_attribute dev_attr_error;
  88. extern struct device_attribute dev_attr_cancel;
  89. extern struct device_attribute dev_attr_remaining_size;
  90. int fw_upload_start(struct fw_sysfs *fw_sysfs);
  91. void fw_upload_free(struct fw_sysfs *fw_sysfs);
  92. umode_t fw_upload_is_visible(struct kobject *kobj, struct attribute *attr, int n);
  93. #else
  94. static inline int fw_upload_start(struct fw_sysfs *fw_sysfs)
  95. {
  96. return 0;
  97. }
  98. static inline void fw_upload_free(struct fw_sysfs *fw_sysfs)
  99. {
  100. }
  101. #endif
  102. #endif /* __FIRMWARE_SYSFS_H */