firmware.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 request_firmware_nowait(
  36. struct module *module, bool uevent,
  37. const char *name, struct device *device, gfp_t gfp, void *context,
  38. void (*cont)(const struct firmware *fw, void *context));
  39. int request_firmware_direct(const struct firmware **fw, const char *name,
  40. struct device *device);
  41. int request_firmware_into_buf(const struct firmware **firmware_p,
  42. const char *name, struct device *device, void *buf, size_t size);
  43. void release_firmware(const struct firmware *fw);
  44. #else
  45. static inline int request_firmware(const struct firmware **fw,
  46. const char *name,
  47. struct device *device)
  48. {
  49. return -EINVAL;
  50. }
  51. static inline int request_firmware_nowait(
  52. struct module *module, bool uevent,
  53. const char *name, struct device *device, gfp_t gfp, void *context,
  54. void (*cont)(const struct firmware *fw, void *context))
  55. {
  56. return -EINVAL;
  57. }
  58. static inline void release_firmware(const struct firmware *fw)
  59. {
  60. }
  61. static inline int request_firmware_direct(const struct firmware **fw,
  62. const char *name,
  63. struct device *device)
  64. {
  65. return -EINVAL;
  66. }
  67. static inline int request_firmware_into_buf(const struct firmware **firmware_p,
  68. const char *name, struct device *device, void *buf, size_t size)
  69. {
  70. return -EINVAL;
  71. }
  72. #endif
  73. int firmware_request_cache(struct device *device, const char *name);
  74. #endif