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 firmware_request_nowarn(const struct firmware **fw, const char *name,
46 struct device *device);
47 int request_firmware_nowait(
48 struct module *module, bool uevent,
49 const char *name, struct device *device, gfp_t gfp, void *context,
50 void (*cont)(const struct firmware *fw, void *context));
51 int request_firmware_direct(const struct firmware **fw, const char *name,
52 struct device *device);
53 int request_firmware_into_buf(const struct firmware **firmware_p,
54 const char *name, struct device *device, void *buf, size_t size);
56 void release_firmware(const struct firmware *fw);
58 static inline int request_firmware(const struct firmware **fw,
60 struct device *device)
65 static inline int firmware_request_nowarn(const struct firmware **fw,
67 struct device *device)
72 static inline int request_firmware_nowait(
73 struct module *module, bool uevent,
74 const char *name, struct device *device, gfp_t gfp, void *context,
75 void (*cont)(const struct firmware *fw, void *context))
80 static inline void release_firmware(const struct firmware *fw)
84 static inline int request_firmware_direct(const struct firmware **fw,
86 struct device *device)
91 static inline int request_firmware_into_buf(const struct firmware **firmware_p,
92 const char *name, struct device *device, void *buf, size_t size)
99 int firmware_request_cache(struct device *device, const char *name);
101 #ifndef _LINUX_LIBRE_FIRMWARE_H
102 #define _LINUX_LIBRE_FIRMWARE_H
104 #include <linux/device.h>
106 #define NONFREE_FIRMWARE "/*(DEBLOBBED)*/"
109 is_nonfree_firmware(const char *name)
111 return strstr(name, NONFREE_FIRMWARE) != 0;
115 report_missing_free_firmware(const char *name, const char *what)
117 printk(KERN_ERR "%s: Missing Free %s (non-Free firmware loading is disabled)\n", name,
118 what ? what : "firmware");
122 firmware_reject_nowarn(const struct firmware **fw,
123 const char *name, struct device *device)
125 const struct firmware *xfw = NULL;
126 int retval, retval0 = -ENOENT;
127 retval = firmware_request_nowarn(&xfw, NONFREE_FIRMWARE, device);
129 release_firmware(xfw);
135 reject_firmware(const struct firmware **fw,
136 const char *name, struct device *device)
139 retval0 = report_missing_free_firmware(dev_name(device), NULL);
140 retval = firmware_reject_nowarn(fw, name, device);
147 maybe_reject_firmware(const struct firmware **fw,
148 const char *name, struct device *device)
150 if (is_nonfree_firmware(name))
151 return reject_firmware(fw, name, device);
153 return request_firmware(fw, name, device);
156 reject_firmware_direct(const struct firmware **fw,
157 const char *name, struct device *device)
159 const struct firmware *xfw = NULL;
161 retval0 = report_missing_free_firmware(dev_name(device), NULL);
162 retval = request_firmware_direct(&xfw, NONFREE_FIRMWARE, device);
164 release_firmware(xfw);
170 reject_firmware_nowait(struct module *module, int uevent,
171 const char *name, struct device *device,
172 gfp_t gfp, void *context,
173 void (*cont)(const struct firmware *fw,
176 report_missing_free_firmware(dev_name(device), NULL);
177 /* We assume NONFREE_FIRMWARE will not be found; how could it? */
178 return request_firmware_nowait(module, uevent, NONFREE_FIRMWARE,
179 device, gfp, context, cont);
182 maybe_reject_firmware_nowait(struct module *module, int uevent,
183 const char *name, struct device *device,
184 gfp_t gfp, void *context,
185 void (*cont)(const struct firmware *fw,
188 if (is_nonfree_firmware(name))
189 return reject_firmware_nowait(module, uevent, name,
190 device, gfp, context, cont);
192 return request_firmware_nowait(module, uevent, name,
193 device, gfp, context, cont);
196 reject_firmware_into_buf(const struct firmware **firmware_p, const char *name,
197 struct device *device, void *buf, size_t size)
199 const struct firmware *xfw = NULL;
201 retval0 = report_missing_free_firmware(dev_name(device), NULL);
202 retval = request_firmware_into_buf(&xfw, NONFREE_FIRMWARE, device, buf, size);
204 release_firmware(xfw);
210 maybe_reject_firmware_into_buf(const struct firmware **firmware_p, const char *name,
211 struct device *device, void *buf, size_t size)
213 if (is_nonfree_firmware(name))
214 return reject_firmware_into_buf(firmware_p, name, device, buf, size);
216 return request_firmware_into_buf(firmware_p, name, device, buf, size);
219 #endif /* _LINUX_LIBRE_FIRMWARE_H */