xref: /linux-6.15/include/linux/firmware.h (revision e520ecf4)
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 #else
36 static inline bool firmware_request_builtin(struct firmware *fw,
37 					    const char *name)
38 {
39 	return false;
40 }
41 #endif
42 
43 #if defined(CONFIG_FW_LOADER) || (defined(CONFIG_FW_LOADER_MODULE) && defined(MODULE))
44 int request_firmware(const struct firmware **fw, const char *name,
45 		     struct device *device);
46 int firmware_request_nowarn(const struct firmware **fw, const char *name,
47 			    struct device *device);
48 int firmware_request_platform(const struct firmware **fw, const char *name,
49 			      struct device *device);
50 int request_firmware_nowait(
51 	struct module *module, bool uevent,
52 	const char *name, struct device *device, gfp_t gfp, void *context,
53 	void (*cont)(const struct firmware *fw, void *context));
54 int request_firmware_direct(const struct firmware **fw, const char *name,
55 			    struct device *device);
56 int request_firmware_into_buf(const struct firmware **firmware_p,
57 	const char *name, struct device *device, void *buf, size_t size);
58 int request_partial_firmware_into_buf(const struct firmware **firmware_p,
59 				      const char *name, struct device *device,
60 				      void *buf, size_t size, size_t offset);
61 
62 void release_firmware(const struct firmware *fw);
63 #else
64 static inline int request_firmware(const struct firmware **fw,
65 				   const char *name,
66 				   struct device *device)
67 {
68 	return -EINVAL;
69 }
70 
71 static inline int firmware_request_nowarn(const struct firmware **fw,
72 					  const char *name,
73 					  struct device *device)
74 {
75 	return -EINVAL;
76 }
77 
78 static inline int firmware_request_platform(const struct firmware **fw,
79 					    const char *name,
80 					    struct device *device)
81 {
82 	return -EINVAL;
83 }
84 
85 static inline int request_firmware_nowait(
86 	struct module *module, bool uevent,
87 	const char *name, struct device *device, gfp_t gfp, void *context,
88 	void (*cont)(const struct firmware *fw, void *context))
89 {
90 	return -EINVAL;
91 }
92 
93 static inline void release_firmware(const struct firmware *fw)
94 {
95 }
96 
97 static inline int request_firmware_direct(const struct firmware **fw,
98 					  const char *name,
99 					  struct device *device)
100 {
101 	return -EINVAL;
102 }
103 
104 static inline int request_firmware_into_buf(const struct firmware **firmware_p,
105 	const char *name, struct device *device, void *buf, size_t size)
106 {
107 	return -EINVAL;
108 }
109 
110 static inline int request_partial_firmware_into_buf
111 					(const struct firmware **firmware_p,
112 					 const char *name,
113 					 struct device *device,
114 					 void *buf, size_t size, size_t offset)
115 {
116 	return -EINVAL;
117 }
118 
119 #endif
120 
121 int firmware_request_cache(struct device *device, const char *name);
122 
123 #endif
124