firmware.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_FIRMWARE_H
  3. #define _LINUX_FIRMWARE_H
  4. #include <linux/types.h>
  5. #include <linux/compiler.h>
  6. #include <linux/gfp.h>
  7. #define FW_ACTION_NOHOTPLUG 0
  8. #define FW_ACTION_HOTPLUG 1
  9. struct firmware {
  10. size_t size;
  11. const u8 *data;
  12. /* firmware loader private fields */
  13. void *priv;
  14. };
  15. struct module;
  16. struct device;
  17. struct builtin_fw {
  18. char *name;
  19. void *data;
  20. unsigned long size;
  21. };
  22. /* We have to play tricks here much like stringify() to get the
  23. __COUNTER__ macro to be expanded as we want it */
  24. #define __fw_concat1(x, y) x##y
  25. #define __fw_concat(x, y) __fw_concat1(x, y)
  26. #define DECLARE_BUILTIN_FIRMWARE(name, blob) \
  27. DECLARE_BUILTIN_FIRMWARE_SIZE(name, &(blob), sizeof(blob))
  28. #define DECLARE_BUILTIN_FIRMWARE_SIZE(name, blob, size) \
  29. static const struct builtin_fw __fw_concat(__builtin_fw,__COUNTER__) \
  30. __used __section(".builtin_fw") = { name, blob, size }
  31. #if defined(CONFIG_FW_LOADER) || (defined(CONFIG_FW_LOADER_MODULE) && defined(MODULE))
  32. int request_firmware(const struct firmware **fw, const char *name,
  33. struct device *device);
  34. int firmware_request_nowarn(const struct firmware **fw, const char *name,
  35. struct device *device);
  36. int firmware_request_platform(const struct firmware **fw, const char *name,
  37. struct device *device);
  38. int request_firmware_nowait(
  39. struct module *module, bool uevent,
  40. const char *name, struct device *device, gfp_t gfp, void *context,
  41. void (*cont)(const struct firmware *fw, void *context));
  42. int request_firmware_direct(const struct firmware **fw, const char *name,
  43. struct device *device);
  44. int request_firmware_into_buf(const struct firmware **firmware_p,
  45. const char *name, struct device *device, void *buf, size_t size);
  46. int request_partial_firmware_into_buf(const struct firmware **firmware_p,
  47. const char *name, struct device *device,
  48. void *buf, size_t size, size_t offset);
  49. void release_firmware(const struct firmware *fw);
  50. #else
  51. static inline int request_firmware(const struct firmware **fw,
  52. const char *name,
  53. struct device *device)
  54. {
  55. return -EINVAL;
  56. }
  57. static inline int firmware_request_nowarn(const struct firmware **fw,
  58. const char *name,
  59. struct device *device)
  60. {
  61. return -EINVAL;
  62. }
  63. static inline int firmware_request_platform(const struct firmware **fw,
  64. const char *name,
  65. struct device *device)
  66. {
  67. return -EINVAL;
  68. }
  69. static inline int request_firmware_nowait(
  70. struct module *module, bool uevent,
  71. const char *name, struct device *device, gfp_t gfp, void *context,
  72. void (*cont)(const struct firmware *fw, void *context))
  73. {
  74. return -EINVAL;
  75. }
  76. static inline void release_firmware(const struct firmware *fw)
  77. {
  78. }
  79. static inline int request_firmware_direct(const struct firmware **fw,
  80. const char *name,
  81. struct device *device)
  82. {
  83. return -EINVAL;
  84. }
  85. static inline int request_firmware_into_buf(const struct firmware **firmware_p,
  86. const char *name, struct device *device, void *buf, size_t size)
  87. {
  88. return -EINVAL;
  89. }
  90. static inline int request_partial_firmware_into_buf
  91. (const struct firmware **firmware_p,
  92. const char *name,
  93. struct device *device,
  94. void *buf, size_t size, size_t offset)
  95. {
  96. return -EINVAL;
  97. }
  98. #endif
  99. int firmware_request_cache(struct device *device, const char *name);
  100. #endif