1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_FIRMWARE_H
3 #define _LINUX_FIRMWARE_H
5 #include <linux/types.h>
6 #include <linux/compiler.h>
9 #define FW_ACTION_NOHOTPLUG 0
10 #define FW_ACTION_HOTPLUG 1
17 /* firmware loader private fields */
30 /* We have to play tricks here much like stringify() to get the
31 __COUNTER__ macro to be expanded as we want it */
32 #define __fw_concat1(x, y) x##y
33 #define __fw_concat(x, y) __fw_concat1(x, y)
35 #define DECLARE_BUILTIN_FIRMWARE(name, blob) \
36 DECLARE_BUILTIN_FIRMWARE_SIZE(name, &(blob), sizeof(blob))
38 #define DECLARE_BUILTIN_FIRMWARE_SIZE(name, blob, size) \
39 static const struct builtin_fw __fw_concat(__builtin_fw,__COUNTER__) \
40 __used __section(.builtin_fw) = { name, blob, size }
42 #if defined(CONFIG_FW_LOADER) || (defined(CONFIG_FW_LOADER_MODULE) && defined(MODULE))
43 int request_firmware(const struct firmware **fw, const char *name,
44 struct device *device);
45 int request_firmware_nowait(
46 struct module *module, bool uevent,
47 const char *name, struct device *device, gfp_t gfp, void *context,
48 void (*cont)(const struct firmware *fw, void *context));
49 int request_firmware_direct(const struct firmware **fw, const char *name,
50 struct device *device);
51 int request_firmware_into_buf(const struct firmware **firmware_p,
52 const char *name, struct device *device, void *buf, size_t size);
54 void release_firmware(const struct firmware *fw);
56 static inline int request_firmware(const struct firmware **fw,
58 struct device *device)
62 static inline int request_firmware_nowait(
63 struct module *module, bool uevent,
64 const char *name, struct device *device, gfp_t gfp, void *context,
65 void (*cont)(const struct firmware *fw, void *context))
70 static inline void release_firmware(const struct firmware *fw)
74 static inline int request_firmware_direct(const struct firmware **fw,
76 struct device *device)
81 static inline int request_firmware_into_buf(const struct firmware **firmware_p,
82 const char *name, struct device *device, void *buf, size_t size)
88 #ifndef _LINUX_LIBRE_FIRMWARE_H
89 #define _LINUX_LIBRE_FIRMWARE_H
91 #include <linux/device.h>
93 #define NONFREE_FIRMWARE "/*(DEBLOBBED)*/"
96 is_nonfree_firmware(const char *name)
98 return strstr(name, NONFREE_FIRMWARE) != 0;
102 report_missing_free_firmware(const char *name, const char *what)
104 printk(KERN_ERR "%s: Missing Free %s (non-Free firmware loading is disabled)\n", name,
105 what ? what : "firmware");
109 reject_firmware(const struct firmware **fw,
110 const char *name, struct device *device)
112 const struct firmware *xfw = NULL;
114 report_missing_free_firmware(dev_name(device), NULL);
115 retval = request_firmware(&xfw, NONFREE_FIRMWARE, device);
117 release_firmware(xfw);
121 maybe_reject_firmware(const struct firmware **fw,
122 const char *name, struct device *device)
124 if (is_nonfree_firmware(name))
125 return reject_firmware(fw, name, device);
127 return request_firmware(fw, name, device);
130 reject_firmware_direct(const struct firmware **fw,
131 const char *name, struct device *device)
133 const struct firmware *xfw = NULL;
135 report_missing_free_firmware(dev_name(device), NULL);
136 retval = request_firmware_direct(&xfw, NONFREE_FIRMWARE, device);
138 release_firmware(xfw);
142 discard_rejected_firmware(const struct firmware *fw, void *context)
144 release_firmware(fw);
147 reject_firmware_nowait(struct module *module, int uevent,
148 const char *name, struct device *device,
149 gfp_t gfp, void *context,
150 void (*cont)(const struct firmware *fw,
154 report_missing_free_firmware(dev_name(device), NULL);
155 retval = request_firmware_nowait(module, uevent, NONFREE_FIRMWARE,
157 discard_rejected_firmware);
163 maybe_reject_firmware_nowait(struct module *module, int uevent,
164 const char *name, struct device *device,
165 gfp_t gfp, void *context,
166 void (*cont)(const struct firmware *fw,
169 if (is_nonfree_firmware(name))
170 return reject_firmware_nowait(module, uevent, name,
171 device, gfp, context, cont);
173 return request_firmware_nowait(module, uevent, name,
174 device, gfp, context, cont);
177 reject_firmware_into_buf(const struct firmware **firmware_p, const char *name,
178 struct device *device, void *buf, size_t size)
180 const struct firmware *xfw = NULL;
182 report_missing_free_firmware(dev_name(device), NULL);
183 retval = request_firmware_into_buf(&xfw, NONFREE_FIRMWARE, device, buf, size);
185 release_firmware(xfw);
189 maybe_reject_firmware_into_buf(const struct firmware **firmware_p, const char *name,
190 struct device *device, void *buf, size_t size)
192 if (is_nonfree_firmware(name))
193 return reject_firmware_into_buf(firmware_p, name, device, buf, size);
195 return request_firmware_into_buf(firmware_p, name, device, buf, size);
198 #endif /* _LINUX_LIBRE_FIRMWARE_H */