firmware.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. struct page **pages;
  13. /* firmware loader private fields */
  14. void *priv;
  15. };
  16. struct module;
  17. struct device;
  18. struct builtin_fw {
  19. char *name;
  20. void *data;
  21. unsigned long size;
  22. };
  23. /* We have to play tricks here much like stringify() to get the
  24. __COUNTER__ macro to be expanded as we want it */
  25. #define __fw_concat1(x, y) x##y
  26. #define __fw_concat(x, y) __fw_concat1(x, y)
  27. #define DECLARE_BUILTIN_FIRMWARE(name, blob) \
  28. DECLARE_BUILTIN_FIRMWARE_SIZE(name, &(blob), sizeof(blob))
  29. #define DECLARE_BUILTIN_FIRMWARE_SIZE(name, blob, size) \
  30. static const struct builtin_fw __fw_concat(__builtin_fw,__COUNTER__) \
  31. __used __section(.builtin_fw) = { name, blob, size }
  32. #if defined(CONFIG_FW_LOADER) || (defined(CONFIG_FW_LOADER_MODULE) && defined(MODULE))
  33. int request_firmware(const struct firmware **fw, const char *name,
  34. struct device *device);
  35. int firmware_request_nowarn(const struct firmware **fw, const char *name,
  36. struct device *device);
  37. int request_firmware_nowait(
  38. struct module *module, bool uevent,
  39. const char *name, struct device *device, gfp_t gfp, void *context,
  40. void (*cont)(const struct firmware *fw, void *context));
  41. int request_firmware_direct(const struct firmware **fw, const char *name,
  42. struct device *device);
  43. int request_firmware_into_buf(const struct firmware **firmware_p,
  44. const char *name, struct device *device, void *buf, size_t size);
  45. void release_firmware(const struct firmware *fw);
  46. #else
  47. static inline int request_firmware(const struct firmware **fw,
  48. const char *name,
  49. struct device *device)
  50. {
  51. return -EINVAL;
  52. }
  53. static inline int firmware_request_nowarn(const struct firmware **fw,
  54. const char *name,
  55. struct device *device)
  56. {
  57. return -EINVAL;
  58. }
  59. static inline int request_firmware_nowait(
  60. struct module *module, bool uevent,
  61. const char *name, struct device *device, gfp_t gfp, void *context,
  62. void (*cont)(const struct firmware *fw, void *context))
  63. {
  64. return -EINVAL;
  65. }
  66. static inline void release_firmware(const struct firmware *fw)
  67. {
  68. }
  69. static inline int request_firmware_direct(const struct firmware **fw,
  70. const char *name,
  71. struct device *device)
  72. {
  73. return -EINVAL;
  74. }
  75. static inline int request_firmware_into_buf(const struct firmware **firmware_p,
  76. const char *name, struct device *device, void *buf, size_t size)
  77. {
  78. return -EINVAL;
  79. }
  80. #endif
  81. int firmware_request_cache(struct device *device, const char *name);
  82. #endif