1 .\" Copyright (c) 2006 Max Laier <mlaier@FreeBSD.org>
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
13 .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
14 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 .\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
17 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 .Nm firmware_register ,
31 .Nm firmware_unregister ,
34 .Nd firmware image loading and management
42 const char *name; /* system-wide name */
43 const void *data; /* location of image */
44 size_t datasize; /* size of image in bytes */
45 unsigned int version; /* version of the image */
48 .Ft "const struct firmware *"
50 .Fa "const char *imagename"
51 .Fa "const void *data"
53 .Fa "unsigned int version"
54 .Fa "const struct firmware *parent"
57 .Fn firmware_unregister "const char *imagename"
58 .Ft "const struct firmware *"
59 .Fn firmware_get "const char *imagename"
61 .Fn firmware_put "const struct firmware *fp" "int flags"
65 abstraction provides a convenient interface for loading
67 into the kernel, and for accessing such images from kernel components.
74 is an opaque block of data residing in kernel memory.
75 It is associated to a unique
77 which constitutes a search key, and to an integer
79 number, which is also an opaque piece of information for the
82 An image is registered with the
84 subsystem by calling the function
85 .Fn firmware_register ,
86 and unregistered by calling
87 .Fn firmware_unregister .
88 These functions are usually (but not exclusively) called by
89 specially crafted kernel modules that contain the firmware image.
90 The modules can be statically compiled in the kernel, or loaded by
92 manually at runtime, or on demand by the firmware subsystem.
95 of the firmware subsystem can request access to a given image
96 by calling the function
100 they want as an argument. If a matching image is not already registered,
101 the firmware subsystem will try to load it using the
102 mechanisms specified below (typically, a kernel module
111 is made of the following functions:
113 .Fn firmware_register
114 registers with the kernel an image of size
121 The function returns NULL on error (e.g. because an
122 image with the same name already exists, or the image
124 .Ft const struct firmware *
125 pointer to the image requested.
127 .Fn firmware_unregister
128 tries to unregister the firmware image
130 from the system. The function is successful and returns 0
131 if there are no pending references to the image, otherwise
132 it does not unregister the image and returns EBUSY.
135 returns the requested firmware image.
136 If the image is not yet registered with the system,
137 the function tries to load it.
138 This involves the linker subsystem and disk access, so
140 must not be called with any locks (except for
142 Note also that if the firmware image is loaded from a filesystem
143 it must already be mounted.
144 In particular this means that it may be necessary to defer requests
145 from a driver attach method unless it is known the root filesystem is
150 returns a pointer to the image description and increases the reference count
151 for this image. On failure, the function returns NULL.
154 drops a reference to a firmware image.
157 argument may be set to
160 firmware_put is free to reclaim resources associated with
161 the firmware image if this is the last reference.
162 By default a firmware image will be deferred to a
164 thread so the call may be done while holding a lock.
165 In certain cases, such as on driver detach, this cannot be allowed.
166 .Sh FIRMWARE LOADING MECHANISMS
167 As mentioned before, any component of the system can register
168 firmware images at any time by simply calling
169 .Fn firmware_register .
171 This is typically done when a module containing
172 a firmware image is given control,
173 whether compiled in, or preloaded by
175 or manually loaded with
177 However, a system can implement additional mechanisms to bring
178 these images in memory before calling
179 .Fn firmware_register .
183 does not find the requested image, it tries to load it using
184 one of the available loading mechanisms.
185 At the moment, there is only one, namely
186 .Nm Loadable kernel modules :
188 A firmware image named
190 is looked up by trying to load the module named
192 using the facilities described in
194 In particular, images are looked up in the directories specified
195 by the sysctl variable
197 which on most systems defaults to
198 .Nm /boot/kernel;/boot/modules .
200 Note that in case a module contains multiple images,
201 the caller should first request a
203 for the first image contained in the module, followed by requests
204 for the other images.
205 .Sh BUILDING FIRMWARE LOADABLE MODULES
206 A firmware module is built by embedding the
208 into a suitable loadable kernel module that calls
209 .Fn firmware_register
211 .Fn firmware_unregister
214 Various system scripts and makefiles let you build a module
215 by simply writing a Makefile with the following entries:
219 FIRMWS= image_file:imagename[:version]
220 .include <bsd.kmod.mk>
223 where KMOD is the basename of the module; FIRMWS is a list of
224 colon-separated tuples indicating the image_file's to be embedded
225 in the module, the imagename and version of each firmware image.
227 If you need to embed firmware images into a system, you should write
228 appropriate entries in the <files.arch> file, e.g. this example is
230 .Nm sys/arm/xscale/ixp425/files.ixp425 :
232 ixp425_npe_fw.c optional npe_fw \\
233 compile-with "${AWK} -f $S/tools/fw_stub.awk \\
234 IxNpeMicrocode.dat:npe_fw -mnpe -c${.TARGET}" \\
235 no-implicit-rule before-depend local \\
236 clean "ixp425_npe_fw.c"
238 # NB: ld encodes the path in the binary symbols generated for the
239 # firmware image so link the file to the object directory to
240 # get known values for reference in the _fw.c file.
242 IxNpeMicrocode.fwo optional npe_fw \\
243 dependency "IxNpeMicrocode.dat" \\
244 compile-with "${LD} -b binary -d -warn-common \\
245 -r -d -o ${.TARGET} IxNpeMicrocode.dat" \\
247 clean "IxNpeMicrocode.fwo"
248 IxNpeMicrocode.dat optional npe_fw \\
249 dependency ".PHONY" \\
250 compile-with "uudecode < $S/contrib/dev/npe/IxNpeMicrocode.dat.uu" \\
251 no-obj no-implicit-rule \\
252 clean "IxNpeMicrocode.dat"
255 Note that generating the firmware modules in this way requires
256 the availability of the following tools:
259 the compiler and the linker.
264 .Pa /usr/share/examples/kld/firmware
268 system was introduced in
271 This manual page was written by
272 .An Max Laier Aq mlaier@FreeBSD.org .