diff options
author | Luis R. Rodriguez <mcgrof@kernel.org> | 2016-12-16 06:10:36 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-01-11 03:42:59 -0500 |
commit | 113ccc38378b6f0b24c0993040c6044e35163a51 (patch) | |
tree | 2a1fbd9a1ad5144dc316834ccf52505a84191cb3 /Documentation/driver-api/firmware | |
parent | 880444e214cfd293a2e8cc4bd3505f7ffa6ce33a (diff) |
firmware: revamp firmware documentation
Understanding this code is getting out of control without any
notes. Give the firmware_class driver a much needed documentation love,
and while at it convert it to the new sphinx documentation format.
v2: typos and small fixes
Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'Documentation/driver-api/firmware')
-rw-r--r-- | Documentation/driver-api/firmware/built-in-fw.rst | 38 | ||||
-rw-r--r-- | Documentation/driver-api/firmware/core.rst | 16 | ||||
-rw-r--r-- | Documentation/driver-api/firmware/direct-fs-lookup.rst | 30 | ||||
-rw-r--r-- | Documentation/driver-api/firmware/fallback-mechanisms.rst | 195 | ||||
-rw-r--r-- | Documentation/driver-api/firmware/firmware_cache.rst | 51 | ||||
-rw-r--r-- | Documentation/driver-api/firmware/fw_search_path.rst | 26 | ||||
-rw-r--r-- | Documentation/driver-api/firmware/index.rst | 16 | ||||
-rw-r--r-- | Documentation/driver-api/firmware/introduction.rst | 27 | ||||
-rw-r--r-- | Documentation/driver-api/firmware/lookup-order.rst | 18 | ||||
-rw-r--r-- | Documentation/driver-api/firmware/request_firmware.rst | 56 |
10 files changed, 473 insertions, 0 deletions
diff --git a/Documentation/driver-api/firmware/built-in-fw.rst b/Documentation/driver-api/firmware/built-in-fw.rst new file mode 100644 index 000000000000..7300e66857f8 --- /dev/null +++ b/Documentation/driver-api/firmware/built-in-fw.rst | |||
@@ -0,0 +1,38 @@ | |||
1 | ================= | ||
2 | Built-in firmware | ||
3 | ================= | ||
4 | |||
5 | Firmware can be built-in to the kernel, this means building the firmware | ||
6 | into vmlinux directly, to enable avoiding having to look for firmware from | ||
7 | the filesystem. Instead, firmware can be looked for inside the kernel | ||
8 | directly. You can enable built-in firmware using the kernel configuration | ||
9 | options: | ||
10 | |||
11 | * CONFIG_EXTRA_FIRMWARE | ||
12 | * CONFIG_EXTRA_FIRMWARE_DIR | ||
13 | |||
14 | This should not be confused with CONFIG_FIRMWARE_IN_KERNEL, this is for drivers | ||
15 | which enables firmware to be built as part of the kernel build process. This | ||
16 | option, CONFIG_FIRMWARE_IN_KERNEL, will build all firmware for all drivers | ||
17 | enabled which ship its firmware inside the Linux kernel source tree. | ||
18 | |||
19 | There are a few reasons why you might want to consider building your firmware | ||
20 | into the kernel with CONFIG_EXTRA_FIRMWARE though: | ||
21 | |||
22 | * Speed | ||
23 | * Firmware is needed for accessing the boot device, and the user doesn't | ||
24 | want to stuff the firmware into the boot initramfs. | ||
25 | |||
26 | Even if you have these needs there are a few reasons why you may not be | ||
27 | able to make use of built-in firmware: | ||
28 | |||
29 | * Legalese - firmware is non-GPL compatible | ||
30 | * Some firmware may be optional | ||
31 | * Firmware upgrades are possible, therefore a new firmware would implicate | ||
32 | a complete kernel rebuild. | ||
33 | * Some firmware files may be really large in size. The remote-proc subsystem | ||
34 | is an example subsystem which deals with these sorts of firmware | ||
35 | * The firmware may need to be scraped out from some device specific location | ||
36 | dynamically, an example is calibration data for for some WiFi chipsets. This | ||
37 | calibration data can be unique per sold device. | ||
38 | |||
diff --git a/Documentation/driver-api/firmware/core.rst b/Documentation/driver-api/firmware/core.rst new file mode 100644 index 000000000000..1d1688cbc078 --- /dev/null +++ b/Documentation/driver-api/firmware/core.rst | |||
@@ -0,0 +1,16 @@ | |||
1 | ========================== | ||
2 | Firmware API core features | ||
3 | ========================== | ||
4 | |||
5 | The firmware API has a rich set of core features available. This section | ||
6 | documents these features. | ||
7 | |||
8 | .. toctree:: | ||
9 | |||
10 | fw_search_path | ||
11 | built-in-fw | ||
12 | firmware_cache | ||
13 | direct-fs-lookup | ||
14 | fallback-mechanisms | ||
15 | lookup-order | ||
16 | |||
diff --git a/Documentation/driver-api/firmware/direct-fs-lookup.rst b/Documentation/driver-api/firmware/direct-fs-lookup.rst new file mode 100644 index 000000000000..82b4d585a213 --- /dev/null +++ b/Documentation/driver-api/firmware/direct-fs-lookup.rst | |||
@@ -0,0 +1,30 @@ | |||
1 | ======================== | ||
2 | Direct filesystem lookup | ||
3 | ======================== | ||
4 | |||
5 | Direct filesystem lookup is the most common form of firmware lookup performed | ||
6 | by the kernel. The kernel looks for the firmware directly on the root | ||
7 | filesystem in the paths documented in the section 'Firmware search paths'. | ||
8 | The filesystem lookup is implemented in fw_get_filesystem_firmware(), it | ||
9 | uses common core kernel file loader facility kernel_read_file_from_path(). | ||
10 | The max path allowed is PATH_MAX -- currently this is 4096 characters. | ||
11 | |||
12 | It is recommended you keep /lib/firmware paths on your root filesystem, | ||
13 | avoid having a separate partition for them in order to avoid possible | ||
14 | races with lookups and avoid uses of the custom fallback mechanisms | ||
15 | documented below. | ||
16 | |||
17 | Firmware and initramfs | ||
18 | ---------------------- | ||
19 | |||
20 | Drivers which are built-in to the kernel should have the firmware integrated | ||
21 | also as part of the initramfs used to boot the kernel given that otherwise | ||
22 | a race is possible with loading the driver and the real rootfs not yet being | ||
23 | available. Stuffing the firmware into initramfs resolves this race issue, | ||
24 | however note that using initrd does not suffice to address the same race. | ||
25 | |||
26 | There are circumstances that justify not wanting to include firmware into | ||
27 | initramfs, such as dealing with large firmware firmware files for the | ||
28 | remote-proc subsystem. For such cases using a userspace fallback mechanism | ||
29 | is currently the only viable solution as only userspace can know for sure | ||
30 | when the real rootfs is ready and mounted. | ||
diff --git a/Documentation/driver-api/firmware/fallback-mechanisms.rst b/Documentation/driver-api/firmware/fallback-mechanisms.rst new file mode 100644 index 000000000000..d19354794e67 --- /dev/null +++ b/Documentation/driver-api/firmware/fallback-mechanisms.rst | |||
@@ -0,0 +1,195 @@ | |||
1 | =================== | ||
2 | Fallback mechanisms | ||
3 | =================== | ||
4 | |||
5 | A fallback mechanism is supported to allow to overcome failures to do a direct | ||
6 | filesystem lookup on the root filesystem or when the firmware simply cannot be | ||
7 | installed for practical reasons on the root filesystem. The kernel | ||
8 | configuration options related to supporting the firmware fallback mechanism are: | ||
9 | |||
10 | * CONFIG_FW_LOADER_USER_HELPER: enables building the firmware fallback | ||
11 | mechanism. Most distributions enable this option today. If enabled but | ||
12 | CONFIG_FW_LOADER_USER_HELPER_FALLBACK is disabled, only the custom fallback | ||
13 | mechanism is available and for the request_firmware_nowait() call. | ||
14 | * CONFIG_FW_LOADER_USER_HELPER_FALLBACK: force enables each request to | ||
15 | enable the kobject uevent fallback mechanism on all firmware API calls | ||
16 | except request_firmware_direct(). Most distributions disable this option | ||
17 | today. The call request_firmware_nowait() allows for one alternative | ||
18 | fallback mechanism: if this kconfig option is enabled and your second | ||
19 | argument to request_firmware_nowait(), uevent, is set to false you are | ||
20 | informing the kernel that you have a custom fallback mechanism and it will | ||
21 | manually load the firmware. Read below for more details. | ||
22 | |||
23 | Note that this means when having this configuration: | ||
24 | |||
25 | CONFIG_FW_LOADER_USER_HELPER=y | ||
26 | CONFIG_FW_LOADER_USER_HELPER_FALLBACK=n | ||
27 | |||
28 | the kobject uevent fallback mechanism will never take effect even | ||
29 | for request_firmware_nowait() when uevent is set to true. | ||
30 | |||
31 | Justifying the firmware fallback mechanism | ||
32 | ========================================== | ||
33 | |||
34 | Direct filesystem lookups may fail for a variety of reasons. Known reasons for | ||
35 | this are worth itemizing and documenting as it justifies the need for the | ||
36 | fallback mechanism: | ||
37 | |||
38 | * Race against access with the root filesystem upon bootup. | ||
39 | |||
40 | * Races upon resume from suspend. This is resolved by the firmware cache, but | ||
41 | the firmware cache is only supported if you use uevents, and its not | ||
42 | supported for request_firmware_into_buf(). | ||
43 | |||
44 | * Firmware is not accessible through typical means: | ||
45 | * It cannot be installed into the root filesystem | ||
46 | * The firmware provides very unique device specific data tailored for | ||
47 | the unit gathered with local information. An example is calibration | ||
48 | data for WiFi chipsets for mobile devices. This calibration data is | ||
49 | not common to all units, but tailored per unit. Such information may | ||
50 | be installed on a separate flash partition other than where the root | ||
51 | filesystem is provided. | ||
52 | |||
53 | Types of fallback mechanisms | ||
54 | ============================ | ||
55 | |||
56 | There are really two fallback mechanisms available using one shared sysfs | ||
57 | interface as a loading facility: | ||
58 | |||
59 | * Kobject uevent fallback mechanism | ||
60 | * Custom fallback mechanism | ||
61 | |||
62 | First lets document the shared sysfs loading facility. | ||
63 | |||
64 | Firmware sysfs loading facility | ||
65 | =============================== | ||
66 | |||
67 | In order to help device drivers upload firmware using a fallback mechanism | ||
68 | the firmware infrastructure creates a sysfs interface to enable userspace | ||
69 | to load and indicate when firmware is ready. The sysfs directory is created | ||
70 | via fw_create_instance(). This call creates a new struct device named after | ||
71 | the firmware requested, and establishes it in the device hierarchy by | ||
72 | associating the device used to make the request as the device's parent. | ||
73 | The sysfs directory's file attributes are defined and controlled through | ||
74 | the new device's class (firmare_class) and group (fw_dev_attr_groups). | ||
75 | This is actually where the original firmware_class.c file name comes from, | ||
76 | as originally the only firmware loading mechanism available was the | ||
77 | mechanism we now use as a fallback mechanism. | ||
78 | |||
79 | To load firmware using the sysfs interface we expose a loading indicator, | ||
80 | and a file upload firmware into: | ||
81 | |||
82 | * /sys/$DEVPATH/loading | ||
83 | * /sys/$DEVPATH/data | ||
84 | |||
85 | To upload firmware you will echo 1 onto the loading file to indicate | ||
86 | you are loading firmware. You then cat the firmware into the data file, | ||
87 | and you notify the kernel the firmware is ready by echo'ing 0 onto | ||
88 | the loading file. | ||
89 | |||
90 | The firmware device used to help load firmware using sysfs is only created if | ||
91 | direct firmware loading fails and if the fallback mechanism is enabled for your | ||
92 | firmware request, this is set up with fw_load_from_user_helper(). It is | ||
93 | important to re-iterate that no device is created if a direct filesystem lookup | ||
94 | succeeded. | ||
95 | |||
96 | Using:: | ||
97 | |||
98 | echo 1 > /sys/$DEVPATH/loading | ||
99 | |||
100 | Will clean any previous partial load at once and make the firmware API | ||
101 | return an error. When loading firmware the firmware_class grows a buffer | ||
102 | for the firmware in PAGE_SIZE increments to hold the image as it comes in. | ||
103 | |||
104 | firmware_data_read() and firmware_loading_show() are just provided for the | ||
105 | test_firmware driver for testing, they are not called in normal use or | ||
106 | expected to be used regularly by userspace. | ||
107 | |||
108 | Firmware kobject uevent fallback mechanism | ||
109 | ========================================== | ||
110 | |||
111 | Since a device is created for the sysfs interface to help load firmware as a | ||
112 | fallback mechanism userspace can be informed of the addition of the device by | ||
113 | relying on kobject uevents. The addition of the device into the device | ||
114 | hierarchy means the fallback mechanism for firmware loading has been initiated. | ||
115 | For details of implementation refer to _request_firmware_load(), in particular | ||
116 | on the use of dev_set_uevent_suppress() and kobject_uevent(). | ||
117 | |||
118 | The kernel's kobject uevent mechanism is implemented in lib/kobject_uevent.c, | ||
119 | it issues uevents to userspace. As a supplement to kobject uevents Linux | ||
120 | distributions could also enable CONFIG_UEVENT_HELPER_PATH, which makes use of | ||
121 | core kernel's usermode helper (UMH) functionality to call out to a userspace | ||
122 | helper for kobject uevents. In practice though no standard distribution has | ||
123 | ever used the CONFIG_UEVENT_HELPER_PATH. If CONFIG_UEVENT_HELPER_PATH is | ||
124 | enabled this binary would be called each time kobject_uevent_env() gets called | ||
125 | in the kernel for each kobject uevent triggered. | ||
126 | |||
127 | Different implementations have been supported in userspace to take advantage of | ||
128 | this fallback mechanism. When firmware loading was only possible using the | ||
129 | sysfs mechanism the userspace component "hotplug" provided the functionality of | ||
130 | monitoring for kobject events. Historically this was superseded be systemd's | ||
131 | udev, however firmware loading support was removed from udev as of systemd | ||
132 | commit be2ea723b1d0 ("udev: remove userspace firmware loading support") | ||
133 | as of v217 on August, 2014. This means most Linux distributions today are | ||
134 | not using or taking advantage of the firmware fallback mechanism provided | ||
135 | by kobject uevents. This is specially exacerbated due to the fact that most | ||
136 | distributions today disable CONFIG_FW_LOADER_USER_HELPER_FALLBACK. | ||
137 | |||
138 | Refer to do_firmware_uevent() for details of the kobject event variables | ||
139 | setup. Variables passwdd with a kobject add event: | ||
140 | |||
141 | * FIRMWARE=firmware name | ||
142 | * TIMEOUT=timeout value | ||
143 | * ASYNC=whether or not the API request was asynchronous | ||
144 | |||
145 | By default DEVPATH is set by the internal kernel kobject infrastructure. | ||
146 | Below is an example simple kobject uevent script:: | ||
147 | |||
148 | # Both $DEVPATH and $FIRMWARE are already provided in the environment. | ||
149 | MY_FW_DIR=/lib/firmware/ | ||
150 | echo 1 > /sys/$DEVPATH/loading | ||
151 | cat $MY_FW_DIR/$FIRMWARE > /sys/$DEVPATH/data | ||
152 | echo 0 > /sys/$DEVPATH/loading | ||
153 | |||
154 | Firmware custom fallback mechanism | ||
155 | ================================== | ||
156 | |||
157 | Users of the request_firmware_nowait() call have yet another option available | ||
158 | at their disposal: rely on the sysfs fallback mechanism but request that no | ||
159 | kobject uevents be issued to userspace. The original logic behind this | ||
160 | was that utilities other than udev might be required to lookup firmware | ||
161 | in non-traditional paths -- paths outside of the listing documented in the | ||
162 | section 'Direct filesystem lookup'. This option is not available to any of | ||
163 | the other API calls as uevents are always forced for them. | ||
164 | |||
165 | Since uevents are only meaningful if the fallback mechanism is enabled | ||
166 | in your kernel it would seem odd to enable uevents with kernels that do not | ||
167 | have the fallback mechanism enabled in their kernels. Unfortunately we also | ||
168 | rely on the uevent flag which can be disabled by request_firmware_nowait() to | ||
169 | also setup the firmware cache for firmware requests. As documented above, | ||
170 | the firmware cache is only set up if uevent is enabled for an API call. | ||
171 | Although this can disable the firmware cache for request_firmware_nowait() | ||
172 | calls, users of this API should not use it for the purposes of disabling | ||
173 | the cache as that was not the original purpose of the flag. Not setting | ||
174 | the uevent flag means you want to opt-in for the firmware fallback mechanism | ||
175 | but you want to suppress kobject uevents, as you have a custom solution which | ||
176 | will monitor for your device addition into the device hierarchy somehow and | ||
177 | load firmware for you through a custom path. | ||
178 | |||
179 | Firmware fallback timeout | ||
180 | ========================= | ||
181 | |||
182 | The firmware fallback mechanism has a timeout. If firmware is not loaded | ||
183 | onto the sysfs interface by the timeout value an error is sent to the | ||
184 | driver. By default the timeout is set to 60 seconds if uevents are | ||
185 | desirable, otherwise MAX_JIFFY_OFFSET is used (max timeout possible). | ||
186 | The logic behind using MAX_JIFFY_OFFSET for non-uevents is that a custom | ||
187 | solution will have as much time as it needs to load firmware. | ||
188 | |||
189 | You can customize the firmware timeout by echo'ing your desired timeout into | ||
190 | the following file: | ||
191 | |||
192 | * /sys/class/firmware/timeout | ||
193 | |||
194 | If you echo 0 into it means MAX_JIFFY_OFFSET will be used. The data type | ||
195 | for the timeout is an int. | ||
diff --git a/Documentation/driver-api/firmware/firmware_cache.rst b/Documentation/driver-api/firmware/firmware_cache.rst new file mode 100644 index 000000000000..2210e5bfb332 --- /dev/null +++ b/Documentation/driver-api/firmware/firmware_cache.rst | |||
@@ -0,0 +1,51 @@ | |||
1 | ============== | ||
2 | Firmware cache | ||
3 | ============== | ||
4 | |||
5 | When Linux resumes from suspend some device drivers require firmware lookups to | ||
6 | re-initialize devices. During resume there may be a period of time during which | ||
7 | firmware lookups are not possible, during this short period of time firmware | ||
8 | requests will fail. Time is of essence though, and delaying drivers to wait for | ||
9 | the root filesystem for firmware delays user experience with device | ||
10 | functionality. In order to support these requirements the firmware | ||
11 | infrastructure implements a firmware cache for device drivers for most API | ||
12 | calls, automatically behind the scenes. | ||
13 | |||
14 | The firmware cache makes using certain firmware API calls safe during a device | ||
15 | driver's suspend and resume callback. Users of these API calls needn't cache | ||
16 | the firmware by themselves for dealing with firmware loss during system resume. | ||
17 | |||
18 | The firmware cache works by requesting for firmware prior to suspend and | ||
19 | caching it in memory. Upon resume device drivers using the firmware API will | ||
20 | have access to the firmware immediately, without having to wait for the root | ||
21 | filesystem to mount or dealing with possible race issues with lookups as the | ||
22 | root filesystem mounts. | ||
23 | |||
24 | Some implementation details about the firmware cache setup: | ||
25 | |||
26 | * The firmware cache is setup by adding a devres entry for each device that | ||
27 | uses all synchronous call except :c:func:`request_firmware_into_buf`. | ||
28 | |||
29 | * If an asynchronous call is used the firmware cache is only set up for a | ||
30 | device if if the second argument (uevent) to request_firmware_nowait() is | ||
31 | true. When uevent is true it requests that a kobject uevent be sent to | ||
32 | userspace for the firmware request. For details refer to the Fackback | ||
33 | mechanism documented below. | ||
34 | |||
35 | * If the firmware cache is determined to be needed as per the above two | ||
36 | criteria the firmware cache is setup by adding a devres entry for the | ||
37 | device making the firmware request. | ||
38 | |||
39 | * The firmware devres entry is maintained throughout the lifetime of the | ||
40 | device. This means that even if you release_firmware() the firmware cache | ||
41 | will still be used on resume from suspend. | ||
42 | |||
43 | * The timeout for the fallback mechanism is temporarily reduced to 10 seconds | ||
44 | as the firmware cache is set up during suspend, the timeout is set back to | ||
45 | the old value you had configured after the cache is set up. | ||
46 | |||
47 | * Upon suspend any pending non-uevent firmware requests are killed to avoid | ||
48 | stalling the kernel, this is done with kill_requests_without_uevent(). Kernel | ||
49 | calls requiring the non-uevent therefore need to implement their own firmware | ||
50 | cache mechanism but must not use the firmware API on suspend. | ||
51 | |||
diff --git a/Documentation/driver-api/firmware/fw_search_path.rst b/Documentation/driver-api/firmware/fw_search_path.rst new file mode 100644 index 000000000000..a360f1009fa3 --- /dev/null +++ b/Documentation/driver-api/firmware/fw_search_path.rst | |||
@@ -0,0 +1,26 @@ | |||
1 | ===================== | ||
2 | Firmware search paths | ||
3 | ===================== | ||
4 | |||
5 | The following search paths are used to look for firmware on your | ||
6 | root filesystem. | ||
7 | |||
8 | * fw_path_para - module parameter - default is empty so this is ignored | ||
9 | * /lib/firmware/updates/UTS_RELEASE/ | ||
10 | * /lib/firmware/updates/ | ||
11 | * /lib/firmware/UTS_RELEASE/ | ||
12 | * /lib/firmware/ | ||
13 | |||
14 | The module parameter ''path'' can be passed to the firmware_class module | ||
15 | to activate the first optional custom fw_path_para. The custom path can | ||
16 | only be up to 256 characters long. The kernel parameter passed would be: | ||
17 | |||
18 | * 'firmware_class.path=$CUSTOMIZED_PATH' | ||
19 | |||
20 | There is an alternative to customize the path at run time after bootup, you | ||
21 | can use the file: | ||
22 | |||
23 | * /sys/module/firmware_class/parameters/path | ||
24 | |||
25 | You would echo into it your custom path and firmware requested will be | ||
26 | searched for there first. | ||
diff --git a/Documentation/driver-api/firmware/index.rst b/Documentation/driver-api/firmware/index.rst new file mode 100644 index 000000000000..1abe01793031 --- /dev/null +++ b/Documentation/driver-api/firmware/index.rst | |||
@@ -0,0 +1,16 @@ | |||
1 | ================== | ||
2 | Linux Firmware API | ||
3 | ================== | ||
4 | |||
5 | .. toctree:: | ||
6 | |||
7 | introduction | ||
8 | core | ||
9 | request_firmware | ||
10 | |||
11 | .. only:: subproject and html | ||
12 | |||
13 | Indices | ||
14 | ======= | ||
15 | |||
16 | * :ref:`genindex` | ||
diff --git a/Documentation/driver-api/firmware/introduction.rst b/Documentation/driver-api/firmware/introduction.rst new file mode 100644 index 000000000000..211cb44eb972 --- /dev/null +++ b/Documentation/driver-api/firmware/introduction.rst | |||
@@ -0,0 +1,27 @@ | |||
1 | ============ | ||
2 | Introduction | ||
3 | ============ | ||
4 | |||
5 | The firmware API enables kernel code to request files required | ||
6 | for functionality from userspace, the uses vary: | ||
7 | |||
8 | * Microcode for CPU errata | ||
9 | * Device driver firmware, required to be loaded onto device | ||
10 | microcontrollers | ||
11 | * Device driver information data (calibration data, EEPROM overrides), | ||
12 | some of which can be completely optional. | ||
13 | |||
14 | Types of firmware requests | ||
15 | ========================== | ||
16 | |||
17 | There are two types of calls: | ||
18 | |||
19 | * Synchronous | ||
20 | * Asynchronous | ||
21 | |||
22 | Which one you use vary depending on your requirements, the rule of thumb | ||
23 | however is you should strive to use the asynchronous APIs unless you also | ||
24 | are already using asynchronous initialization mechanisms which will not | ||
25 | stall or delay boot. Even if loading firmware does not take a lot of time | ||
26 | processing firmware might, and this can still delay boot or initialization, | ||
27 | as such mechanisms such as asynchronous probe can help supplement drivers. | ||
diff --git a/Documentation/driver-api/firmware/lookup-order.rst b/Documentation/driver-api/firmware/lookup-order.rst new file mode 100644 index 000000000000..88c81739683c --- /dev/null +++ b/Documentation/driver-api/firmware/lookup-order.rst | |||
@@ -0,0 +1,18 @@ | |||
1 | ===================== | ||
2 | Firmware lookup order | ||
3 | ===================== | ||
4 | |||
5 | Different functionality is available to enable firmware to be found. | ||
6 | Below is chronological order of how firmware will be looked for once | ||
7 | a driver issues a firmware API call. | ||
8 | |||
9 | * The ''Built-in firmware'' is checked first, if the firmware is present we | ||
10 | return it immediately | ||
11 | * The ''Firmware cache'' is looked at next. If the firmware is found we | ||
12 | return it immediately | ||
13 | * The ''Direct filesystem lookup'' is performed next, if found we | ||
14 | return it immediately | ||
15 | * If no firmware has been found and the fallback mechanism was enabled | ||
16 | the sysfs interface is created. After this either a kobject uevent | ||
17 | is issued or the custom firmware loading is relied upon for firmware | ||
18 | loading up to the timeout value. | ||
diff --git a/Documentation/driver-api/firmware/request_firmware.rst b/Documentation/driver-api/firmware/request_firmware.rst new file mode 100644 index 000000000000..cc0aea880824 --- /dev/null +++ b/Documentation/driver-api/firmware/request_firmware.rst | |||
@@ -0,0 +1,56 @@ | |||
1 | ==================== | ||
2 | request_firmware API | ||
3 | ==================== | ||
4 | |||
5 | You would typically load firmware and then load it into your device somehow. | ||
6 | The typical firmware work flow is reflected below:: | ||
7 | |||
8 | if(request_firmware(&fw_entry, $FIRMWARE, device) == 0) | ||
9 | copy_fw_to_device(fw_entry->data, fw_entry->size); | ||
10 | release_firmware(fw_entry); | ||
11 | |||
12 | Synchronous firmware requests | ||
13 | ============================= | ||
14 | |||
15 | Synchronous firmware requests will wait until the firmware is found or until | ||
16 | an error is returned. | ||
17 | |||
18 | request_firmware | ||
19 | ---------------- | ||
20 | .. kernel-doc:: drivers/base/firmware_class.c | ||
21 | :functions: request_firmware | ||
22 | |||
23 | request_firmware_direct | ||
24 | ----------------------- | ||
25 | .. kernel-doc:: drivers/base/firmware_class.c | ||
26 | :functions: request_firmware_direct | ||
27 | |||
28 | request_firmware_into_buf | ||
29 | ------------------------- | ||
30 | .. kernel-doc:: drivers/base/firmware_class.c | ||
31 | :functions: request_firmware_into_buf | ||
32 | |||
33 | Asynchronous firmware requests | ||
34 | ============================== | ||
35 | |||
36 | Asynchronous firmware requests allow driver code to not have to wait | ||
37 | until the firmware or an error is returned. Function callbacks are | ||
38 | provided so that when the firmware or an error is found the driver is | ||
39 | informed through the callback. request_firmware_nowait() cannot be called | ||
40 | in atomic contexts. | ||
41 | |||
42 | request_firmware_nowait | ||
43 | ----------------------- | ||
44 | .. kernel-doc:: drivers/base/firmware_class.c | ||
45 | :functions: request_firmware_nowait | ||
46 | |||
47 | request firmware API expected driver use | ||
48 | ======================================== | ||
49 | |||
50 | Once an API call returns you process the firmware and then release the | ||
51 | firmware. For example if you used request_firmware() and it returns, | ||
52 | the driver has the firmware image accessible in fw_entry->{data,size}. | ||
53 | If something went wrong request_firmware() returns non-zero and fw_entry | ||
54 | is set to NULL. Once your driver is done with processing the firmware it | ||
55 | can call call release_firmware(fw_entry) to release the firmware image | ||
56 | and any related resource. | ||