]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/man/man9/firmware.9
bhnd(9): Fix a few mandoc related issues
[FreeBSD/FreeBSD.git] / share / man / man9 / firmware.9
1 .\" Copyright (c) 2006 Max Laier <mlaier@FreeBSD.org>
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
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.
12 .\"
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.
23 .\"
24 .\" $FreeBSD$
25 .\"
26 .Dd March 14, 2019
27 .Dt FIRMWARE 9
28 .Os
29 .Sh NAME
30 .Nm firmware_register ,
31 .Nm firmware_unregister ,
32 .Nm firmware_get ,
33 .Nm firmware_put
34 .Nd firmware image loading and management
35 .Sh SYNOPSIS
36 .In sys/param.h
37 .In sys/systm.h
38 .In sys/linker.h
39 .In sys/firmware.h
40 .Bd -literal
41 struct firmware {
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 */
46 };
47 .Ed
48 .Ft "const struct firmware *"
49 .Fo firmware_register
50 .Fa "const char *imagename"
51 .Fa "const void *data"
52 .Fa "size_t datasize"
53 .Fa "unsigned int version"
54 .Fa "const struct firmware *parent"
55 .Fc
56 .Ft int
57 .Fn firmware_unregister "const char *imagename"
58 .Ft "const struct firmware *"
59 .Fn firmware_get "const char *imagename"
60 .Ft void
61 .Fn firmware_put "const struct firmware *fp" "int flags"
62 .Sh DESCRIPTION
63 The
64 .Nm firmware
65 abstraction provides a convenient interface for loading
66 .Nm firmware images
67 into the kernel, and for accessing such images from kernel components.
68 .Pp
69 A
70 .Nm firmware image
71 (or
72 .Nm image
73 for brevity)
74 is an opaque block of data residing in kernel memory.
75 It is associated to a unique
76 .Nm imagename
77 which constitutes a search key, and to an integer
78 .Nm version
79 number, which is also an opaque piece of information for the
80 firmware subsystem.
81 .Pp
82 An image is registered with the
83 .Nm firmware
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
91 .Nm /boot/loader ,
92 manually at runtime, or on demand by the firmware subsystem.
93 .Pp
94 .Nm Clients
95 of the firmware subsystem can request access to a given image
96 by calling the function
97 .Fn firmware_get
98 with the
99 .Nm imagename
100 they want as an argument.
101 If a matching image is not already registered,
102 the firmware subsystem will try to load it using the
103 mechanisms specified below (typically, a kernel module
104 with
105 .Nm
106 the same name
107 as the image).
108 .Sh API DESCRIPTION
109 The kernel
110 .Nm
111 firmware API
112 is made of the following functions:
113 .Pp
114 .Fn firmware_register
115 registers with the kernel an image of size
116 .Nm datasize
117 located at address
118 .Nm data ,
119 under the name
120 .Nm imagename .
121 .Pp
122 The function returns NULL on error (e.g. because an
123 image with the same name already exists, or the image
124 table is full), or a
125 .Ft const struct firmware *
126 pointer to the image requested.
127 .Pp
128 .Fn firmware_unregister
129 tries to unregister the firmware image
130 .Nm imagename
131 from the system.
132 The function is successful and returns 0
133 if there are no pending references to the image, otherwise
134 it does not unregister the image and returns EBUSY.
135 .Pp
136 .Fn firmware_get
137 returns the requested firmware image.
138 If the image is not yet registered with the system,
139 the function tries to load it.
140 This involves the linker subsystem and disk access, so
141 .Fn firmware_get
142 must not be called with any locks (except for
143 .Va Giant ) .
144 Note also that if the firmware image is loaded from a filesystem
145 it must already be mounted.
146 In particular this means that it may be necessary to defer requests
147 from a driver attach method unless it is known the root filesystem is
148 already mounted.
149 .Pp
150 On success,
151 .Fn firmware_get
152 returns a pointer to the image description and increases the reference count
153 for this image.
154 On failure, the function returns NULL.
155 .Pp
156 .Fn firmware_put
157 drops a reference to a firmware image.
158 The
159 .Fa flags
160 argument may be set to
161 .Dv FIRMWARE_UNLOAD
162 to indicate that
163 firmware_put is free to reclaim resources associated with
164 the firmware image if this is the last reference.
165 By default a firmware image will be deferred to a
166 .Xr taskqueue 9
167 thread so the call may be done while holding a lock.
168 In certain cases, such as on driver detach, this cannot be allowed.
169 .Sh FIRMWARE LOADING MECHANISMS
170 As mentioned before, any component of the system can register
171 firmware images at any time by simply calling
172 .Fn firmware_register .
173 .Pp
174 This is typically done when a module containing
175 a firmware image is given control,
176 whether compiled in, or preloaded by
177 .Nm /boot/loader ,
178 or manually loaded with
179 .Xr kldload 8 .
180 However, a system can implement additional mechanisms to bring
181 these images in memory before calling
182 .Fn firmware_register .
183 .Pp
184 When
185 .Fn firmware_get
186 does not find the requested image, it tries to load it using
187 one of the available loading mechanisms.
188 At the moment, there is only one, namely
189 .Nm Loadable kernel modules :
190 .Pp
191 A firmware image named
192 .Nm foo
193 is looked up by trying to load the module named
194 .Nm foo.ko ,
195 using the facilities described in
196 .Xr kld 4 .
197 In particular, images are looked up in the directories specified
198 by the sysctl variable
199 .Nm kern.module_path
200 which on most systems defaults to
201 .Nm /boot/kernel;/boot/modules .
202 .Pp
203 Note that in case a module contains multiple images,
204 the caller should first request a
205 .Fn firmware_get
206 for the first image contained in the module, followed by requests
207 for the other images.
208 .Sh BUILDING FIRMWARE LOADABLE MODULES
209 A firmware module is built by embedding the
210 .Nm firmware image
211 into a suitable loadable kernel module that calls
212 .Fn firmware_register
213 on loading, and
214 .Fn firmware_unregister
215 on unloading.
216 .Pp
217 Various system scripts and makefiles let you build a module
218 by simply writing a Makefile with the following entries:
219 .Bd -literal
220
221         KMOD=   imagename
222         FIRMWS= image_file:imagename[:version]
223         .include <bsd.kmod.mk>
224
225 .Ed
226 where KMOD is the basename of the module; FIRMWS is a list of
227 colon-separated tuples indicating the image_file's to be embedded
228 in the module, the imagename and version of each firmware image.
229 .Pp
230 If you need to embed firmware images into a system, you should write
231 appropriate entries in the <files.arch> file, e.g. this example is
232 from
233 .Nm sys/arm/xscale/ixp425/files.ixp425 :
234 .Bd -literal
235 ixp425_npe_fw.c                         optional npe_fw                 \\
236         compile-with    "${AWK} -f $S/tools/fw_stub.awk                 \\
237                         IxNpeMicrocode.dat:npe_fw -mnpe -c${.TARGET}"   \\
238         no-implicit-rule before-depend local                            \\
239         clean           "ixp425_npe_fw.c"
240 #
241 # NB: ld encodes the path in the binary symbols generated for the
242 #     firmware image so link the file to the object directory to
243 #     get known values for reference in the _fw.c file.
244 #
245 IxNpeMicrocode.fwo  optional npe_fw                                     \\
246         dependency      "IxNpeMicrocode.dat"                            \\
247         compile-with    "${LD} -b binary -d -warn-common                \\
248                             -r -d -o ${.TARGET} IxNpeMicrocode.dat"     \\
249         no-implicit-rule                                                \\
250         clean           "IxNpeMicrocode.fwo"
251 .Ed
252 .Pp
253 Firmware was previously committed to the source tree as uuencoded files,
254 but this is no longer required; the binary firmware file should be committed
255 to the tree as provided by the vendor.
256 .Pp
257 Note that generating the firmware modules in this way requires
258 the availability of the following tools:
259 .Xr awk 1 ,
260 .Xr make 1 ,
261 the compiler and the linker.
262 .Sh SEE ALSO
263 .Xr kld 4 ,
264 .Xr module 9
265 .Pp
266 .Pa /usr/share/examples/kld/firmware
267 .Sh HISTORY
268 The
269 .Nm firmware
270 system was introduced in
271 .Fx 6.1 .
272 .Sh AUTHORS
273 This manual page was written by
274 .An Max Laier Aq Mt mlaier@FreeBSD.org .