firmware.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #ifndef _LINUX_FIRMWARE_H
  2. #define _LINUX_FIRMWARE_H
  3. #include <linux/types.h>
  4. #include <linux/compiler.h>
  5. #include <linux/gfp.h>
  6. #define FW_ACTION_NOHOTPLUG 0
  7. #define FW_ACTION_HOTPLUG 1
  8. struct firmware {
  9. size_t size;
  10. const u8 *data;
  11. struct page **pages;
  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 request_firmware_nowait(
  35. struct module *module, bool uevent,
  36. const char *name, struct device *device, gfp_t gfp, void *context,
  37. void (*cont)(const struct firmware *fw, void *context));
  38. int request_firmware_direct(const char *name, struct device *device,
  39. phys_addr_t dest_addr, size_t dest_size,
  40. void * (*map_fw_mem)(phys_addr_t phys,
  41. size_t size),
  42. void (*unmap_fw_mem)(void *virt));
  43. int request_firmware_nowait_direct(
  44. struct module *module, bool uevent,
  45. const char *name, struct device *device, gfp_t gfp, void *context,
  46. void (*cont)(const struct firmware *fw, void *context),
  47. phys_addr_t dest_addr, size_t dest_size,
  48. void * (*map_fw_mem)(phys_addr_t phys, size_t size),
  49. void (*unmap_fw_mem)(void *virt));
  50. void release_firmware(const struct firmware *fw);
  51. int cache_firmware(const char *name);
  52. int uncache_firmware(const char *name);
  53. #else
  54. static inline int request_firmware(const struct firmware **fw,
  55. const char *name,
  56. struct device *device)
  57. {
  58. return -EINVAL;
  59. }
  60. static inline int request_firmware_direct(const char *name,
  61. struct device *device,
  62. phys_addr_t dest_addr,
  63. size_t dest_size,
  64. void * (*map_fw_mem)(phys_addr_t phys,
  65. size_t size),
  66. void (*unmap_fw_mem)(void *virt))
  67. {
  68. return -EINVAL;
  69. }
  70. static inline int request_firmware_nowait(
  71. struct module *module, bool uevent,
  72. const char *name, struct device *device, gfp_t gfp, void *context,
  73. void (*cont)(const struct firmware *fw, void *context))
  74. {
  75. return -EINVAL;
  76. }
  77. static inline int request_firmware_nowait_direct(
  78. struct module *module, bool uevent,
  79. const char *name, struct device *device, gfp_t gfp, void *context,
  80. void (*cont)(const struct firmware *fw, void *context),
  81. phys_addr_t dest_addr, size_t dest_size,
  82. void * (*map_fw_mem)(phys_addr_t phys, size_t size),
  83. void (*unmap_fw_mem)(void *virt))
  84. {
  85. return -EINVAL;
  86. }
  87. static inline void release_firmware(const struct firmware *fw)
  88. {
  89. }
  90. static inline int cache_firmware(const char *name)
  91. {
  92. return -ENOENT;
  93. }
  94. static inline int uncache_firmware(const char *name)
  95. {
  96. return -EINVAL;
  97. }
  98. #endif
  99. #endif