1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _LINUX_FIRMWARE_H 3 #define _LINUX_FIRMWARE_H 4 5 #include <linux/types.h> 6 #include <linux/compiler.h> 7 #include <linux/gfp.h> 8 9 #define FW_ACTION_NOUEVENT 0 10 #define FW_ACTION_UEVENT 1 11 12 struct firmware { 13 size_t size; 14 const u8 *data; 15 16 /* firmware loader private fields */ 17 void *priv; 18 }; 19 20 struct module; 21 struct device; 22 23 /* 24 * Built-in firmware functionality is only available if FW_LOADER=y, but not 25 * FW_LOADER=m 26 */ 27 #ifdef CONFIG_FW_LOADER 28 struct builtin_fw { 29 char *name; 30 void *data; 31 unsigned long size; 32 }; 33 34 bool firmware_request_builtin(struct firmware *fw, const char *name); 35 36 /* We have to play tricks here much like stringify() to get the 37 __COUNTER__ macro to be expanded as we want it */ 38 #define __fw_concat1(x, y) x##y 39 #define __fw_concat(x, y) __fw_concat1(x, y) 40 41 #define DECLARE_BUILTIN_FIRMWARE(name, blob) \ 42 DECLARE_BUILTIN_FIRMWARE_SIZE(name, &(blob), sizeof(blob)) 43 44 #define DECLARE_BUILTIN_FIRMWARE_SIZE(name, blob, size) \ 45 static const struct builtin_fw __fw_concat(__builtin_fw,__COUNTER__) \ 46 __used __section(".builtin_fw") = { name, blob, size } 47 48 #else 49 static inline bool firmware_request_builtin(struct firmware *fw, 50 const char *name) 51 { 52 return false; 53 } 54 #endif 55 56 #if defined(CONFIG_FW_LOADER) || (defined(CONFIG_FW_LOADER_MODULE) && defined(MODULE)) 57 int request_firmware(const struct firmware **fw, const char *name, 58 struct device *device); 59 int firmware_request_nowarn(const struct firmware **fw, const char *name, 60 struct device *device); 61 int firmware_request_platform(const struct firmware **fw, const char *name, 62 struct device *device); 63 int request_firmware_nowait( 64 struct module *module, bool uevent, 65 const char *name, struct device *device, gfp_t gfp, void *context, 66 void (*cont)(const struct firmware *fw, void *context)); 67 int request_firmware_direct(const struct firmware **fw, const char *name, 68 struct device *device); 69 int request_firmware_into_buf(const struct firmware **firmware_p, 70 const char *name, struct device *device, void *buf, size_t size); 71 int request_partial_firmware_into_buf(const struct firmware **firmware_p, 72 const char *name, struct device *device, 73 void *buf, size_t size, size_t offset); 74 75 void release_firmware(const struct firmware *fw); 76 #else 77 static inline int request_firmware(const struct firmware **fw, 78 const char *name, 79 struct device *device) 80 { 81 return -EINVAL; 82 } 83 84 static inline int firmware_request_nowarn(const struct firmware **fw, 85 const char *name, 86 struct device *device) 87 { 88 return -EINVAL; 89 } 90 91 static inline int firmware_request_platform(const struct firmware **fw, 92 const char *name, 93 struct device *device) 94 { 95 return -EINVAL; 96 } 97 98 static inline int request_firmware_nowait( 99 struct module *module, bool uevent, 100 const char *name, struct device *device, gfp_t gfp, void *context, 101 void (*cont)(const struct firmware *fw, void *context)) 102 { 103 return -EINVAL; 104 } 105 106 static inline void release_firmware(const struct firmware *fw) 107 { 108 } 109 110 static inline int request_firmware_direct(const struct firmware **fw, 111 const char *name, 112 struct device *device) 113 { 114 return -EINVAL; 115 } 116 117 static inline int request_firmware_into_buf(const struct firmware **firmware_p, 118 const char *name, struct device *device, void *buf, size_t size) 119 { 120 return -EINVAL; 121 } 122 123 static inline int request_partial_firmware_into_buf 124 (const struct firmware **firmware_p, 125 const char *name, 126 struct device *device, 127 void *buf, size_t size, size_t offset) 128 { 129 return -EINVAL; 130 } 131 132 #endif 133 134 int firmware_request_cache(struct device *device, const char *name); 135 136 #endif 137