Firmware loading
Single-page view · as markdown
Linux Firmware API
Peios Kernel / Hardware and drivers / Driver development / Firmware loading
Peios: File-based firmware loading has an additional Peios signature check. The development profile defaults to logging (
kacs_fwsig=log);kacs_fwsig=enforcerequires PeiosTcb trust for that path. This does not cover the separateFW_UPLOADinterface. See Peios kernel behaviour.
Built-in firmware
Peios Kernel / Hardware and drivers / Driver development / Firmware loading
Peios: File-based firmware loading has an additional Peios signature check. The development profile defaults to logging (
kacs_fwsig=log);kacs_fwsig=enforcerequires PeiosTcb trust for that path. This does not cover the separateFW_UPLOADinterface. See Peios kernel behaviour.
Firmware can be built-in to the kernel, this means building the firmware into vmlinux directly, to enable avoiding having to look for firmware from the filesystem. Instead, firmware can be looked for inside the kernel directly. You can enable built-in firmware using the kernel configuration options:
CONFIG_EXTRA_FIRMWARE
CONFIG_EXTRA_FIRMWARE_DIR
There are a few reasons why you might want to consider building your firmware into the kernel with CONFIG_EXTRA_FIRMWARE:
-
Speed
-
Firmware is needed for accessing the boot device, and the user doesn't want to stuff the firmware into the boot initramfs.
Even if you have these needs there are a few reasons why you may not be able to make use of built-in firmware:
-
Legalese - firmware is non-GPL compatible
-
Some firmware may be optional
-
Firmware upgrades are possible, therefore a new firmware would implicate a complete kernel rebuild.
-
Some firmware files may be really large in size. The remote-proc subsystem is an example subsystem which deals with these sorts of firmware
-
The firmware may need to be scraped out from some device specific location dynamically, an example is calibration data for some WiFi chipsets. This calibration data can be unique per sold device.
Firmware API core features
Peios Kernel / Hardware and drivers / Driver development / Firmware loading
Peios: File-based firmware loading has an additional Peios signature check. The development profile defaults to logging (
kacs_fwsig=log);kacs_fwsig=enforcerequires PeiosTcb trust for that path. This does not cover the separateFW_UPLOADinterface. See Peios kernel behaviour.
The firmware API has a rich set of core features available. This section documents these features.
Direct filesystem lookup
Peios Kernel / Hardware and drivers / Driver development / Firmware loading
Peios: File-based firmware loading has an additional Peios signature check. The development profile defaults to logging (
kacs_fwsig=log);kacs_fwsig=enforcerequires PeiosTcb trust for that path. This does not cover the separateFW_UPLOADinterface. See Peios kernel behaviour.
Direct filesystem lookup is the most common form of firmware lookup performed by the kernel. The kernel looks for the firmware directly on the root filesystem in the paths documented in the section 'Firmware search paths'. The filesystem lookup is implemented in fw_get_filesystem_firmware(), it uses common core kernel file loader facility kernel_read_file_from_path(). The max path allowed is PATH_MAX -- currently this is 4096 characters.
It is recommended you keep /lib/firmware paths on your root filesystem, avoid having a separate partition for them in order to avoid possible races with lookups and avoid uses of the custom fallback mechanisms documented below.
Firmware and initramfs #
Drivers which are built-in to the kernel should have the firmware integrated also as part of the initramfs used to boot the kernel given that otherwise a race is possible with loading the driver and the real rootfs not yet being available. Stuffing the firmware into initramfs resolves this race issue, however note that using initrd does not suffice to address the same race.
There are circumstances that justify not wanting to include firmware into initramfs, such as dealing with large firmware files for the remote-proc subsystem. For such cases using a userspace fallback mechanism is currently the only viable solution as only userspace can know for sure when the real rootfs is ready and mounted.
Fallback mechanisms
Peios Kernel / Hardware and drivers / Driver development / Firmware loading
Peios: File-based firmware loading has an additional Peios signature check. The development profile defaults to logging (
kacs_fwsig=log);kacs_fwsig=enforcerequires PeiosTcb trust for that path. This does not cover the separateFW_UPLOADinterface. See Peios kernel behaviour.
The Peios base configuration disables CONFIG_FW_LOADER_USER_HELPER, so the sysfs firmware-request fallback described below is not enabled in the configured build. The separate device firmware-upload facility (FW_UPLOAD) can still be enabled.
The fallback is an optional upstream mechanism for failed filesystem lookups or firmware that cannot be installed on the root filesystem. Its configuration options are:
CONFIG_FW_LOADER_USER_HELPER: enables building the firmware fallback mechanism. If enabled but CONFIG_FW_LOADER_USER_HELPER_FALLBACK is disabled, only the custom fallback mechanism is available and for the request_firmware_nowait() call.
CONFIG_FW_LOADER_USER_HELPER_FALLBACK: force enables each request to enable the kobject uevent fallback mechanism on all firmware API calls except request_firmware_direct(). The call request_firmware_nowait() allows for one alternative fallback mechanism: if this kconfig option is enabled and your second argument to request_firmware_nowait(), uevent, is set to false you are informing the kernel that you have a custom fallback mechanism and it will manually load the firmware. Read below for more details.
Note that this means when having this configuration:
CONFIG_FW_LOADER_USER_HELPER=y CONFIG_FW_LOADER_USER_HELPER_FALLBACK=n
the kobject uevent fallback mechanism will never take effect even for request_firmware_nowait() when uevent is set to true.
Justifying the firmware fallback mechanism #
Direct filesystem lookups may fail for a variety of reasons. Known reasons for this are worth itemizing and documenting as it justifies the need for the fallback mechanism:
-
Race against access with the root filesystem upon bootup.
-
Races upon resume from suspend. This is resolved by the firmware cache, but the firmware cache is only supported if you use uevents, and its not supported for request_firmware_into_buf().
-
Firmware is not accessible through typical means:
-
It cannot be installed into the root filesystem
-
The firmware provides very unique device specific data tailored for the unit gathered with local information. An example is calibration data for WiFi chipsets for mobile devices. This calibration data is not common to all units, but tailored per unit. Such information may be installed on a separate flash partition other than where the root filesystem is provided.
-
Types of fallback mechanisms #
There are really two fallback mechanisms available using one shared sysfs interface as a loading facility:
-
Kobject uevent fallback mechanism
-
Custom fallback mechanism
First lets document the shared sysfs loading facility.
Firmware sysfs loading facility #
In order to help device drivers upload firmware using a fallback mechanism the firmware infrastructure creates a sysfs interface to enable userspace to load and indicate when firmware is ready. The sysfs directory is created via fw_create_instance(). This call creates a new struct device named after the firmware requested, and establishes it in the device hierarchy by associating the device used to make the request as the device's parent. The sysfs directory's file attributes are defined and controlled through the new device's class (firmware_class) and group (fw_dev_attr_groups). This is actually where the original firmware_class module name came from, given that originally the only firmware loading mechanism available was the mechanism we now use as a fallback mechanism, which registers a struct class firmware_class. Because the attributes exposed are part of the module name, the module name firmware_class cannot be renamed in the future, to ensure backward compatibility with old userspace.
To load firmware using the sysfs interface we expose a loading indicator, and a file upload firmware into:
/sys/$DEVPATH/loading
/sys/$DEVPATH/data
To upload firmware you will echo 1 onto the loading file to indicate you are loading firmware. You then write the firmware into the data file, and you notify the kernel the firmware is ready by echo'ing 0 onto the loading file.
The firmware device used to help load firmware using sysfs is only created if direct firmware loading fails and if the fallback mechanism is enabled for your firmware request, this is set up with firmware_fallback_sysfs(). It is important to re-iterate that no device is created if a direct filesystem lookup succeeded.
Using:
echo 1 > /sys/$DEVPATH/loading
This discards any previous partial load and starts a fresh loading attempt. Writing 0 completes a load; writing -1 aborts it. When loading firmware the firmware_class grows a buffer for the firmware in PAGE_SIZE increments to hold the image as it comes in.
firmware_data_read() and firmware_loading_show() are just provided for the test_firmware driver for testing, they are not called in normal use or expected to be used regularly by userspace.
firmware_fallback_sysfs #
firmware_fallback_sysfs() #
int use the fallback mechanism to find firmware
Parameters
struct firmware *fw: pointer to firmware imageconst char *name: name of firmware file to look forstruct device *device: device for which firmware is being loadedu32 opt_flags: options to control firmware loading behaviour, as defined byenum fw_optint ret: return value from direct lookup which triggered the fallback mechanism
Description
This function is called if direct lookup for the firmware failed, it enables a fallback mechanism through userspace by exposing a sysfs loading interface. Userspace is in charge of loading the firmware through the sysfs loading interface. This sysfs fallback mechanism may be disabled completely on a system by setting the proc sysctl value ignore_sysfs_fallback to true. If this is false we check if the internal API caller set the FW_OPT_NOFALLBACK_SYSFS flag, if so it would also disable the fallback mechanism. A system may want to enforce the sysfs fallback mechanism at all times, it can do this by setting ignore_sysfs_fallback to false and force_sysfs_fallback to true. Enabling force_sysfs_fallback is functionally equivalent to build a kernel with CONFIG_FW_LOADER_USER_HELPER_FALLBACK.
Firmware kobject uevent fallback mechanism #
Since a device is created for the sysfs interface to help load firmware as a fallback mechanism userspace can be informed of the addition of the device by relying on kobject uevents. The addition of the device into the device hierarchy means the fallback mechanism for firmware loading has been initiated. For details of implementation refer to fw_load_sysfs_fallback(), in particular on the use of dev_set_uevent_suppress() and kobject_uevent().
The kernel's kobject uevent mechanism is implemented in lib/kobject_uevent.c, it issues uevents to userspace. As a supplement to kobject uevents Linux distributions could also enable CONFIG_UEVENT_HELPER_PATH, which makes use of core kernel's usermode helper (UMH) functionality to call out to a userspace helper for kobject uevents. In practice though no standard distribution has ever used the CONFIG_UEVENT_HELPER_PATH. If CONFIG_UEVENT_HELPER_PATH is enabled this binary would be called each time kobject_uevent_env() gets called in the kernel for each kobject uevent triggered.
Different implementations have been supported in userspace to take advantage of this fallback mechanism. When firmware loading was only possible using the sysfs mechanism the userspace component "hotplug" provided the functionality of monitoring for kobject events. Historically this was superseded be systemd's udev, however firmware loading support was removed from udev as of systemd commit be2ea723b1d0 ("udev: remove userspace firmware loading support") as of v217 on August, 2014. This means most Linux distributions today are not using or taking advantage of the firmware fallback mechanism provided by kobject uevents. This is specially exacerbated due to the fact that most distributions today disable CONFIG_FW_LOADER_USER_HELPER_FALLBACK.
Refer to do_firmware_uevent() for details of the kobject event variables setup. The variables currently passed to userspace with a "kobject add" event are:
-
FIRMWARE=firmware name
-
TIMEOUT=timeout value
-
ASYNC=whether or not the API request was asynchronous
By default DEVPATH is set by the internal kernel kobject infrastructure. Below is an example simple kobject uevent script:
# Both $DEVPATH and $FIRMWARE are already provided in the environment.
MY_FW_DIR=/lib/firmware/
echo 1 > /sys/$DEVPATH/loading
cat $MY_FW_DIR/$FIRMWARE > /sys/$DEVPATH/data
echo 0 > /sys/$DEVPATH/loading
Firmware custom fallback mechanism #
Users of the request_firmware_nowait() call have yet another option available at their disposal: rely on the sysfs fallback mechanism but request that no kobject uevents be issued to userspace. The original logic behind this was that utilities other than udev might be required to lookup firmware in non-traditional paths -- paths outside of the listing documented in the section 'Direct filesystem lookup'. This option is not available to any of the other API calls as uevents are always forced for them.
Since uevents are only meaningful if the fallback mechanism is enabled in your kernel it would seem odd to enable uevents with kernels that do not have the fallback mechanism enabled in their kernels. Unfortunately we also rely on the uevent flag which can be disabled by request_firmware_nowait() to also setup the firmware cache for firmware requests. As documented above, the firmware cache is only set up if uevent is enabled for an API call. Although this can disable the firmware cache for request_firmware_nowait() calls, users of this API should not use it for the purposes of disabling the cache as that was not the original purpose of the flag. Not setting the uevent flag means you want to opt-in for the firmware fallback mechanism but you want to suppress kobject uevents, as you have a custom solution which will monitor for your device addition into the device hierarchy somehow and load firmware for you through a custom path.
Firmware fallback timeout #
The firmware fallback mechanism has a timeout. If firmware is not loaded onto the sysfs interface by the timeout value an error is sent to the driver. By default the timeout is set to 60 seconds if uevents are desirable, otherwise MAX_JIFFY_OFFSET is used (max timeout possible). The logic behind using MAX_JIFFY_OFFSET for non-uevents is that a custom solution will have as much time as it needs to load firmware.
You can customize the firmware timeout by echo'ing your desired timeout into the following file:
- /sys/class/firmware/timeout
If you echo 0 into it means MAX_JIFFY_OFFSET will be used. The data type for the timeout is an int.
EFI embedded firmware fallback mechanism #
On some devices the system's EFI code / ROM may contain an embedded copy of firmware for some of the system's integrated peripheral devices and the peripheral's Linux device-driver needs to access this firmware.
Device drivers which need such firmware can use the firmware_request_platform() function for this, note that this is a separate fallback mechanism from the other fallback mechanisms and this does not use the sysfs interface.
A device driver which needs this can describe the firmware it needs using an efi_embedded_fw_desc struct:
struct efi_embedded_fw_desc #
This struct is used by the EFI embedded-fw code to search for embedded firmwares.
Definition
;
Members
name: Name to register the firmware with if foundprefix: First 8 bytes of the firmwarelength: Length of the firmware in bytes including prefixsha256: SHA256 of the firmware
The EFI embedded-fw code works by scanning all EFI_BOOT_SERVICES_CODE memory segments for an eight byte sequence matching prefix; if the prefix is found it then does a sha256 over length bytes and if that matches makes a copy of length bytes and adds that to its list with found firmwares.
To avoid doing this somewhat expensive scan on all systems, dmi matching is used. Drivers are expected to export a dmi_system_id array, with each entries' driver_data pointing to an efi_embedded_fw_desc.
To register this array with the efi-embedded-fw code, a driver needs to:
-
Always be builtin to the kernel or store the dmi_system_id array in a separate object file which always gets builtin.
-
Add an extern declaration for the dmi_system_id array to include/linux/efi_embedded_fw.h.
-
Add the dmi_system_id array to the embedded_fw_table in drivers/firmware/efi/embedded-firmware.c wrapped in a #ifdef testing that the driver is being builtin.
-
Add "select EFI_EMBEDDED_FIRMWARE if EFI_STUB" to its Kconfig entry.
The firmware_request_platform() function will always first try to load firmware with the specified name directly from the disk, so the EFI embedded-fw can always be overridden by placing a file under /lib/firmware.
Note that:
-
The code scanning for EFI embedded-firmware runs near the end of start_kernel(), just before calling rest_init(). For normal drivers and subsystems using subsys_initcall() to register themselves this does not matter. This means that code running earlier cannot use EFI embedded-firmware.
-
At the moment the EFI embedded-fw code assumes that firmwares always start at an offset which is a multiple of 8 bytes, if this is not true for your case send in a patch to fix this.
-
At the moment the EFI embedded-fw code only works on x86 because other archs free EFI_BOOT_SERVICES_CODE before the EFI embedded-fw code gets a chance to scan it.
-
The current brute-force scanning of EFI_BOOT_SERVICES_CODE is an ad-hoc brute-force solution. There has been discussion to use the UEFI Platform Initialization (PI) spec's Firmware Volume protocol. This has been rejected because the FV Protocol relies on internal interfaces of the PI spec, and: 1. The PI spec does not define peripheral firmware at all 2. The internal interfaces of the PI spec do not guarantee any backward compatibility. Any implementation details in FV may be subject to change, and may vary system to system. Supporting the FV Protocol would be difficult as it is purposely ambiguous.
Example how to check for and extract embedded firmware #
To check for, for example Silead touchscreen controller embedded firmware, do the following:
-
Boot the system with efi=debug on the kernel commandline
-
cp /sys/kernel/debug/efi/boot_services_code? to your home dir
-
Open the boot_services_code? files in a hex-editor, search for the magic prefix for Silead firmware: F0 00 00 00 02 00 00 00, this gives you the beginning address of the firmware inside the boot_services_code? file.
-
The firmware has a specific pattern, it starts with a 8 byte page-address, typically F0 00 00 00 02 00 00 00 for the first page followed by 32-bit word-address + 32-bit value pairs. With the word-address incrementing 4 bytes (1 word) for each pair until a page is complete. A complete page is followed by a new page-address, followed by more word + value pairs. This leads to a very distinct pattern. Scroll down until this pattern stops, this gives you the end of the firmware inside the boot_services_code? file.
-
"dd if=boot_services_code? of=firmware bs=1 skip=<begin-addr> count=<len>" will extract the firmware for you. Inspect the firmware file in a hexeditor to make sure you got the dd parameters correct.
-
Copy it to /lib/firmware under the expected name to test it.
-
If the extracted firmware works, you can use the found info to fill an efi_embedded_fw_desc struct to describe it, run "sha256sum firmware" to get the sha256sum to put in the sha256 field.
Firmware Guidelines
Peios Kernel / Hardware and drivers / Driver development / Firmware loading
Peios: File-based firmware loading has an additional Peios signature check. The development profile defaults to logging (
kacs_fwsig=log);kacs_fwsig=enforcerequires PeiosTcb trust for that path. This does not cover the separateFW_UPLOADinterface. See Peios kernel behaviour.
Users switching to a newer kernel should not have to install newer firmware files to keep their hardware working. At the same time updated firmware files must not cause any regressions for users of older kernel releases.
Drivers that use firmware from linux-firmware should follow the rules in this guide. (Where there is limited control of the firmware, i.e. company doesn't support Linux, firmwares sourced from misc places, then of course these rules will not apply strictly.)
-
Firmware files shall be designed in a way that it allows checking for firmware ABI version changes. It is recommended that firmware files be versioned with at least a major/minor version. It is suggested that the firmware files in linux-firmware be named with some device specific name, and just the major version. The firmware version should be stored in the firmware header, or as an exception, as part of the firmware file name, in order to let the driver detact any non-ABI fixes/changes. The firmware files in linux-firmware should be overwritten with the newest compatible major version. Newer major version firmware shall remain compatible with all kernels that load that major number.
-
If the kernel support for the hardware is normally inactive, or the hardware isn't available for public consumption, this can be ignored, until the first kernel release that enables that hardware. This means no major version bumps without the kernel retaining backwards compatibility for the older major versions. Minor version bumps should not introduce new features that newer kernels depend on non-optionally.
-
If a security fix needs lockstep firmware and kernel fixes in order to be successful, then all supported major versions in the linux-firmware repo that are required by currently supported stable/LTS kernels, should be updated with the security fix. The kernel patches should detect if the firmware is new enough to declare if the security issue is fixed. All communications around security fixes should point at both the firmware and kernel fixes. If a security fix requires deprecating old major versions, then this should only be done as a last option, and be stated clearly in all communications.
-
Firmware files that affect the User API (UAPI) shall not introduce changes that break existing userspace programs. Updates to such firmware must ensure backward compatibility with existing userspace applications. This includes maintaining consistent interfaces and behaviors that userspace programs rely on.
Firmware cache
Peios Kernel / Hardware and drivers / Driver development / Firmware loading
Peios: File-based firmware loading has an additional Peios signature check. The development profile defaults to logging (
kacs_fwsig=log);kacs_fwsig=enforcerequires PeiosTcb trust for that path. This does not cover the separateFW_UPLOADinterface. See Peios kernel behaviour.
When Linux resumes from suspend some device drivers require firmware lookups to re-initialize devices. During resume there may be a period of time during which firmware lookups are not possible, during this short period of time firmware requests will fail. Time is of essence though, and delaying drivers to wait for the root filesystem for firmware delays user experience with device functionality. In order to support these requirements the firmware infrastructure implements a firmware cache for device drivers for most API calls, automatically behind the scenes.
The firmware cache makes using certain firmware API calls safe during a device driver's suspend and resume callback. Users of these API calls needn't cache the firmware by themselves for dealing with firmware loss during system resume.
The firmware cache works by requesting for firmware prior to suspend and caching it in memory. Upon resume device drivers using the firmware API will have access to the firmware immediately, without having to wait for the root filesystem to mount or dealing with possible race issues with lookups as the root filesystem mounts.
Some implementation details about the firmware cache setup:
-
The firmware cache is setup by adding a devres entry for each device that uses all synchronous call except
request_firmware_into_buf(). -
If an asynchronous call is used the firmware cache is only set up for a device if the second argument (uevent) to request_firmware_nowait() is true. When uevent is true it requests that a kobject uevent be sent to userspace for the firmware request through the sysfs fallback mechanism if the firmware file is not found.
-
If the firmware cache is determined to be needed as per the above two criteria the firmware cache is setup by adding a devres entry for the device making the firmware request.
-
The firmware devres entry is maintained throughout the lifetime of the device. This means that even if you release_firmware() the firmware cache will still be used on resume from suspend.
-
The timeout for the fallback mechanism is temporarily reduced to 10 seconds as the firmware cache is set up during suspend, the timeout is set back to the old value you had configured after the cache is set up.
-
Upon suspend any pending non-uevent firmware requests are killed to avoid stalling the kernel, this is done with kill_requests_without_uevent(). Kernel calls requiring the non-uevent therefore need to implement their own firmware cache mechanism but must not use the firmware API on suspend.
Firmware search paths
Peios Kernel / Hardware and drivers / Driver development / Firmware loading
Peios: File-based firmware loading has an additional Peios signature check. The development profile defaults to logging (
kacs_fwsig=log);kacs_fwsig=enforcerequires PeiosTcb trust for that path. This does not cover the separateFW_UPLOADinterface. See Peios kernel behaviour.
The following search paths are used to look for firmware on your root filesystem.
-
fw_path_para - module parameter - default is empty so this is ignored
-
/lib/firmware/updates/UTS_RELEASE/
-
/lib/firmware/updates/
-
/lib/firmware/UTS_RELEASE/
-
/lib/firmware/
The module parameter ''path'' can be passed to the firmware_class module to activate the first optional custom fw_path_para. The custom path can only be up to 256 characters long. The kernel parameter passed would be:
- 'firmware_class.path=$CUSTOMIZED_PATH'
There is an alternative to customize the path at run time after bootup, you can use the file:
- /sys/module/firmware_class/parameters/path
You would echo into it your custom path and firmware requested will be searched for there first. Be aware that newline characters will be taken into account and may not produce the intended effects. For instance you might want to use:
echo -n /path/to/script > /sys/module/firmware_class/parameters/path
to ensure that your script is being used.
Firmware Upload API
Peios Kernel / Hardware and drivers / Driver development / Firmware loading
Peios: File-based firmware loading has an additional Peios signature check. The development profile defaults to logging (
kacs_fwsig=log);kacs_fwsig=enforcerequires PeiosTcb trust for that path. This does not cover the separateFW_UPLOADinterface. See Peios kernel behaviour.
A device driver that registers with the firmware loader will expose persistent sysfs nodes to enable users to initiate firmware updates for that device. It is the responsibility of the device driver and/or the device itself to perform any validation on the data received. Firmware upload uses the same loading and data sysfs files described in the documentation for firmware fallback. It also adds additional sysfs files to provide status on the transfer of the firmware image to the device.
Register for firmware upload #
A device driver registers for firmware upload by calling firmware_upload_register(). Among the parameter list is a name to identify the device under /sys/class/firmware. A user may initiate a firmware upload by echoing a 1 to the loading sysfs file for the target device. Next, the user writes the firmware image to the data sysfs file. After writing the firmware data, the user echos 0 to the loading sysfs file to signal completion. Echoing 0 to loading also triggers the transfer of the firmware to the lower-lever device driver in the context of a kernel worker thread.
To use the firmware upload API, write a driver that implements a set of ops. The probe function calls firmware_upload_register() and the remove function calls firmware_upload_unregister() such as:
static const struct fw_upload_ops m10bmc_ops = {
.prepare = m10bmc_sec_prepare,
.write = m10bmc_sec_write,
.poll_complete = m10bmc_sec_poll_complete,
.cancel = m10bmc_sec_cancel,
.cleanup = m10bmc_sec_cleanup,
};
static int m10bmc_sec_probe(struct platform_device *pdev)
{
const char *fw_name, *truncate;
struct m10bmc_sec *sec;
struct fw_upload *fwl;
unsigned int len;
sec = devm_kzalloc(&pdev->dev, sizeof(*sec), GFP_KERNEL);
if (!sec)
return -ENOMEM;
sec->dev = &pdev->dev;
sec->m10bmc = dev_get_drvdata(pdev->dev.parent);
dev_set_drvdata(&pdev->dev, sec);
fw_name = dev_name(sec->dev);
truncate = strstr(fw_name, ".auto");
len = (truncate) ? truncate - fw_name : strlen(fw_name);
sec->fw_name = kmemdup_nul(fw_name, len, GFP_KERNEL);
fwl = firmware_upload_register(THIS_MODULE, sec->dev, sec->fw_name,
&m10bmc_ops, sec);
if (IS_ERR(fwl)) {
dev_err(sec->dev, "Firmware Upload driver failed to start\n");
kfree(sec->fw_name);
return PTR_ERR(fwl);
}
sec->fwl = fwl;
return 0;
}
static int m10bmc_sec_remove(struct platform_device *pdev)
{
struct m10bmc_sec *sec = dev_get_drvdata(&pdev->dev);
firmware_upload_unregister(sec->fwl);
kfree(sec->fw_name);
return 0;
}
firmware_upload_register #
firmware_upload_register() #
struct fw_upload * register for the firmware upload sysfs API
Parameters
struct module *module: kernel module of this devicestruct device *parent: parent device instantiating firmware uploadconst char *name: firmware name to be associated with this deviceconst struct fw_upload_ops *ops: pointer to structure of firmware upload opsvoid *dd_handle: pointer to parent driver private data
Description
name must be unique among all users of firmware upload. The firmware sysfs files for this device will be found at /sys/class/firmware/name.
Return
struct fw_upload pointer or ERR_PTR()
firmware_upload_unregister #
firmware_upload_unregister() #
void Unregister firmware upload interface
Parameters
struct fw_upload *fw_upload: pointer to struct fw_upload
Firmware Upload Ops #
struct fw_upload_ops #
device specific operations to support firmware upload
Definition
;
Members
prepare: Required: Prepare secure updatewrite: Required: Thewrite()op receives the remaining size to be written and must return the actual size written or a negative error code. Thewrite()op will be called repeatedly until all data is written.poll_complete: Required: Check for the completion of the HW authentication/programming process.cancel: Required: Request cancellation of update. This op is called from the context of a different kernel thread, so race conditions need to be considered.cleanup: Optional: Complements theprepare()function and is called at the completion of the update, on success or failure, if the prepare function succeeded.
Firmware Upload Progress Codes #
The following progress codes are used internally by the firmware loader. Corresponding strings are reported through the status sysfs node that is described below and are documented in the ABI documentation.
enum fw_upload_prog #
firmware upload progress codes
Constants
FW_UPLOAD_PROG_IDLE: there is no firmware upload in progressFW_UPLOAD_PROG_RECEIVING: worker thread is receiving firmware dataFW_UPLOAD_PROG_PREPARING: target device is preparing for firmware uploadFW_UPLOAD_PROG_TRANSFERRING: data is being copied to the deviceFW_UPLOAD_PROG_PROGRAMMING: device is performing the firmware updateFW_UPLOAD_PROG_MAX: Maximum progress code marker
Firmware Upload Error Codes #
The following error codes may be returned by the driver ops in case of failure:
enum fw_upload_err #
firmware upload error codes
Constants
FW_UPLOAD_ERR_NONE: returned to indicate successFW_UPLOAD_ERR_HW_ERROR: error signalled by hardware, see kernel logFW_UPLOAD_ERR_TIMEOUT: SW timed out on handshake with HW/firmwareFW_UPLOAD_ERR_CANCELED: upload was cancelled by the userFW_UPLOAD_ERR_BUSY: there is an upload operation already in progressFW_UPLOAD_ERR_INVALID_SIZE: invalid firmware image sizeFW_UPLOAD_ERR_RW_ERROR: read or write to HW failed, see kernel logFW_UPLOAD_ERR_WEAROUT: FLASH device is approaching wear-out, wait & retryFW_UPLOAD_ERR_FW_INVALID: invalid firmware fileFW_UPLOAD_ERR_MAX: Maximum error code marker
Sysfs Attributes #
In addition to the loading and data sysfs files, there are additional sysfs files to monitor the status of the data transfer to the target device and to determine the final pass/fail status of the transfer. Depending on the device and the size of the firmware image, a firmware update could take milliseconds or minutes.
The additional sysfs files are:
-
status - provides an indication of the progress of a firmware update
-
error - provides error information for a failed firmware update
-
remaining_size - tracks the data transfer portion of an update
-
cancel - echo 1 to this file to cancel the update
Introduction
Peios Kernel / Hardware and drivers / Driver development / Firmware loading
Peios: File-based firmware loading has an additional Peios signature check. The development profile defaults to logging (
kacs_fwsig=log);kacs_fwsig=enforcerequires PeiosTcb trust for that path. This does not cover the separateFW_UPLOADinterface. See Peios kernel behaviour.
The firmware API enables kernel code to request files required for functionality from userspace, the uses vary:
-
Microcode for CPU errata
-
Device driver firmware, required to be loaded onto device microcontrollers
-
Device driver information data (calibration data, EEPROM overrides), some of which can be completely optional.
Types of firmware requests #
There are two types of calls:
-
Synchronous
-
Asynchronous
Which one you use vary depending on your requirements, the rule of thumb however is you should strive to use the asynchronous APIs unless you also are already using asynchronous initialization mechanisms which will not stall or delay boot. Even if loading firmware does not take a lot of time processing firmware might, and this can still delay boot or initialization, as such mechanisms such as asynchronous probe can help supplement drivers.
Firmware lookup order
Peios Kernel / Hardware and drivers / Driver development / Firmware loading
Peios: File-based firmware loading has an additional Peios signature check. The development profile defaults to logging (
kacs_fwsig=log);kacs_fwsig=enforcerequires PeiosTcb trust for that path. This does not cover the separateFW_UPLOADinterface. See Peios kernel behaviour.
Different functionality is available to enable firmware to be found. Below is chronological order of how firmware will be looked for once a driver issues a firmware API call.
-
The ''Built-in firmware'' is checked first, if the firmware is present we return it immediately
-
The ''Firmware cache'' is looked at next. If the firmware is found we return it immediately
-
The ''Direct filesystem lookup'' is performed next, if found we return it immediately
-
The ''Platform firmware fallback'' is performed next, but only when firmware_request_platform() is used, if found we return it immediately
-
If no firmware has been found and the fallback mechanism was enabled the sysfs interface is created. After this either a kobject uevent is issued or the custom firmware loading is relied upon for firmware loading up to the timeout value.
Other Firmware Interfaces
Peios Kernel / Hardware and drivers / Driver development / Firmware loading
Peios: File-based firmware loading has an additional Peios signature check. The development profile defaults to logging (
kacs_fwsig=log);kacs_fwsig=enforcerequires PeiosTcb trust for that path. This does not cover the separateFW_UPLOADinterface. See Peios kernel behaviour.
DMI Interfaces #
dmi_check_system() #
int check system DMI data
Parameters
const struct dmi_system_id *list: array of dmi_system_id structures to match against All non-null elements of the list must match their slot's (field index's) data (i.e., each list string must be a substring of the specified DMI slot's string data) to be considered a successful match.
Description
Walk the blacklist table running matching functions until someone returns non zero or we hit the end. Callback function is called for each successful match. Returns the number of matches.
dmi_setup must be called before this function is called.
dmi_first_match() #
const struct dmi_system_id * find dmi_system_id structure matching system DMI data
Parameters
const struct dmi_system_id *list: array of dmi_system_id structures to match against All non-null elements of the list must match their slot's (field index's) data (i.e., each list string must be a substring of the specified DMI slot's string data) to be considered a successful match.
Description
Walk the blacklist table until the first match is found. Return the pointer to the matching entry or NULL if there's no match.
dmi_setup must be called before this function is called.
dmi_get_system_info() #
const char * return DMI data value
Parameters
int field: data index (see enum dmi_field)
Description
Returns one DMI data value, can be used to perform complex DMI data checks.
dmi_name_in_vendors() #
int Check if string is in the DMI system or board vendor name
Parameters
const char *str: Case sensitive Name
dmi_find_device() #
const struct dmi_device * find onboard device by type/name
Parameters
int type: device type orDMI_DEV_TYPE_ANYto match all device typesconst char *name: device name string orNULLto match allconst struct dmi_device *from: previous device found in search, orNULLfor new search.
Description
Iterates through the list of known onboard devices. If a device is
found with a matching type and name, a pointer to its device
structure is returned. Otherwise, NULL is returned.
A new search is initiated by passing NULL as the from argument.
If from is not NULL, searches continue from next device.
dmi_get_date() #
bool parse a DMI date
Parameters
int field: data index (see enum dmi_field)int *yearp: optional out parameter for the yearint *monthp: optional out parameter for the monthint *dayp: optional out parameter for the day
Description
The date field is assumed to be in the form resembling [mm[/dd]]/yy[yy] and the result is stored in the out parameters any or all of which can be omitted.
If the field doesn't exist, all out parameters are set to zero and false is returned. Otherwise, true is returned with any invalid part of date set to zero.
On return, year, month and day are guaranteed to be in the range of [0,9999], [0,12] and [0,31] respectively.
dmi_get_bios_year() #
int get a year out of DMI_BIOS_DATE field
Parameters
void: no arguments
Description
Returns year on success, -ENXIO if DMI is not selected, or a different negative error code if DMI field is not present or not parseable.
dmi_walk() #
int Walk the DMI table and get called back for every record
Parameters
void (*decode)(const struct dmi_header *, void *): Callback functionvoid *private_data: Private data to be passed to the callback function
Description
Returns 0 on success, -ENXIO if DMI is not selected or not present, or a different negative error code if DMI walking fails.
dmi_match() #
bool compare a string to the dmi field (if exists)
Parameters
enum dmi_field f: DMI field identifierconst char *str: string to compare the DMI field to
Description
Returns true if the requested field equals to the str (including NULL).
dmi_memdev_type() #
u8 get the memory type
Parameters
u16 handle: DMI structure handle
Description
Return the DMI memory type of the module in the slot associated with the given DMI handle, or 0x0 if no such DMI handle exists.
dmi_memdev_handle() #
u16 get the DMI handle of a memory slot
Parameters
int slot: slot number
Description
Return the DMI handle associated with a given memory slot, or 0xFFFF
if there is no such slot.
EDD Interfaces #
edd_show_raw_data() #
ssize_t copies raw data to buffer for userspace to parse
Parameters
struct edd_device *edev: target edd_devicechar *buf: output buffer
Return
number of bytes written, or -EINVAL on failure
edd_release() #
void free edd structure
Parameters
struct kobject * kobj: kobject of edd structure
Description
This is called when the refcount of the edd structure reaches 0. This should happen right after we unregister, but just in case, we use the release callback anyway.
edd_dev_is_type() #
int is this EDD device a 'type' device?
Parameters
struct edd_device *edev: target edd_deviceconst char *type: a host bus or interface identifier string per the EDD spec
Description
Returns 1 (TRUE) if it is a 'type' device, 0 otherwise.
edd_get_pci_dev() #
struct pci_dev * finds pci_dev that matches edev
Parameters
struct edd_device *edev: edd_device
Description
Returns pci_dev if found, or NULL
edd_init() #
int creates sysfs tree of EDD data
Parameters
void: no arguments
Generic System Framebuffers Interface #
sysfb_disable() #
void disable the Generic System Framebuffers support
Parameters
struct device *dev: the device to check if non-NULL
Description
This disables the registration of system framebuffer devices that match the generic drivers that make use of the system framebuffer set up by firmware.
It also unregisters a device if this was already registered by sysfb_init().
Context
The function can sleep. A disable_lock mutex is acquired to serialize
against sysfb_init(), that registers a system framebuffer device.
sysfb_handles_screen_info() #
bool reports if sysfb handles the global screen_info
Parameters
void: no arguments
Description
Callers can use sysfb_handles_screen_info() to determine whether the Generic
System Framebuffers (sysfb) can handle the global screen_info data structure
or not. Drivers might need this information to know if they have to setup the
system framebuffer, or if they have to delegate this action to sysfb instead.
Return
True if sysfb handles the global screen_info data structure.
Intel Stratix10 SoC Service Layer #
Some features of the Intel Stratix10 SoC require a level of privilege higher than the kernel is granted. Such secure features include FPGA programming. In terms of the ARMv8 architecture, the kernel runs at Exception Level 1 (EL1), access to the features requires Exception Level 3 (EL3).
The Intel Stratix10 SoC service layer provides an in kernel API for drivers to request access to the secure features. The requests are queued and processed one by one. ARM’s SMCCC is used to pass the execution of the requests on to a secure monitor (EL3).
enum stratix10_svc_command_code #
supported service commands
Constants
COMMAND_NOOP: do 'dummy' request for integration/debug/trouble-shootingCOMMAND_RECONFIG: ask for FPGA configuration preparation, return status is SVC_STATUS_OKCOMMAND_RECONFIG_DATA_SUBMIT: submit buffer(s) of bit-stream data for the FPGA configuration, return status is SVC_STATUS_SUBMITTED or SVC_STATUS_ERRORCOMMAND_RECONFIG_DATA_CLAIM: check the status of the configuration, return status is SVC_STATUS_COMPLETED, or SVC_STATUS_BUSY, or SVC_STATUS_ERRORCOMMAND_RECONFIG_STATUS: check the status of the configuration, return status is SVC_STATUS_COMPLETED, or SVC_STATUS_BUSY, or SVC_STATUS_ERRORCOMMAND_RSU_STATUS: request remote system update boot log, return status is log data or SVC_STATUS_RSU_ERRORCOMMAND_RSU_UPDATE: set the offset of the bitstream to boot after reboot, return status is SVC_STATUS_OK or SVC_STATUS_ERRORCOMMAND_RSU_NOTIFY: report the status of hard processor system software to firmware, return status is SVC_STATUS_OK or SVC_STATUS_ERRORCOMMAND_RSU_RETRY: query firmware for the current image's retry counter, return status is SVC_STATUS_OK or SVC_STATUS_ERRORCOMMAND_RSU_MAX_RETRY: query firmware for the max retry value, return status is SVC_STATUS_OK or SVC_STATUS_ERRORCOMMAND_RSU_DCMF_VERSION: query firmware for the DCMF version, return status is SVC_STATUS_OK or SVC_STATUS_ERRORCOMMAND_RSU_DCMF_STATUS: query firmware for the DCMF status return status is SVC_STATUS_OK or SVC_STATUS_ERRORCOMMAND_FIRMWARE_VERSION: query running firmware version, return status is SVC_STATUS_OK or SVC_STATUS_ERRORCOMMAND_RSU_GET_SPT_TABLE: query firmware for SPT table return status is SVC_STATUS_OK or SVC_STATUS_ERRORCOMMAND_FCS_REQUEST_SERVICE: request validation of image from firmware, return status is SVC_STATUS_OK, SVC_STATUS_INVALID_PARAMCOMMAND_FCS_SEND_CERTIFICATE: send a certificate, return status is SVC_STATUS_OK, SVC_STATUS_INVALID_PARAM, SVC_STATUS_ERRORCOMMAND_FCS_GET_PROVISION_DATA: read the provisioning data, return status is SVC_STATUS_OK, SVC_STATUS_INVALID_PARAM, SVC_STATUS_ERRORCOMMAND_FCS_DATA_ENCRYPTION: encrypt the data, return status is SVC_STATUS_OK, SVC_STATUS_INVALID_PARAM, SVC_STATUS_ERRORCOMMAND_FCS_DATA_DECRYPTION: decrypt the data, return status is SVC_STATUS_OK, SVC_STATUS_INVALID_PARAM, SVC_STATUS_ERRORCOMMAND_FCS_RANDOM_NUMBER_GEN: generate a random number, return status is SVC_STATUS_OK, SVC_STATUS_ERRORCOMMAND_POLL_SERVICE_STATUS: poll if the service request is complete, return statis is SVC_STATUS_OK, SVC_STATUS_ERROR or SVC_STATUS_BUSYCOMMAND_MBOX_SEND_CMD: send generic mailbox command, return status is SVC_STATUS_OK or SVC_STATUS_ERRORCOMMAND_SMC_SVC_VERSION: Non-mailbox SMC SVC API Version, return status is SVC_STATUS_OKCOMMAND_HWMON_READTEMP: query the temperature from the hardware monitor, return status is SVC_STATUS_OK or SVC_STATUS_ERRORCOMMAND_HWMON_READVOLT: query the voltage from the hardware monitor, return status is SVC_STATUS_OK or SVC_STATUS_ERROR
struct stratix10_svc_client_msg #
message sent by client to service
Definition
;
Members
payload: starting address of data need be processedpayload_length: to be processed data size in bytespayload_output: starting address of processed datapayload_length_output: processed data size in bytescommand: service commandarg: args to be passed via registers and not physically mapped buffers
struct stratix10_svc_command_config_type #
config type
Definition
;
Members
flags: flag bit for the type of FPGA configuration
struct stratix10_svc_cb_data #
callback data structure from service layer
Definition
;
Members
status: the status of sent commandkaddr1: address of 1st completed data blockkaddr2: address of 2nd completed data blockkaddr3: address of 3rd completed data block
struct stratix10_svc_client #
service client structure
Definition
;
Members
dev: the client devicereceive_cb: callback to provide service client the received datapriv: client private data
stratix10_svc_request_channel_byname() #
struct stratix10_svc_chan * request a service channel
Parameters
struct stratix10_svc_client *client: pointer to service clientconst char *name: service client name
Description
This function is used by service client to request a service channel.
Return
a pointer to channel assigned to the client on success,
or ERR_PTR() on error.
stratix10_svc_add_async_client() #
int Add an asynchronous client to the Stratix10 service channel.
Parameters
struct stratix10_svc_chan *chan: Pointer to the Stratix10 service channel structure.bool use_unique_clientid: Boolean flag indicating whether to use a unique client ID.
Description
This function adds an asynchronous client to the specified
Stratix10 service channel. If the use_unique_clientid flag is
set to true, a unique client ID is allocated for the asynchronous
channel. Otherwise, a common asynchronous channel is used.
Return
0 on success, or a negative error code on failure: -EINVAL if the channel is NULL or the async controller is not initialized. -EALREADY if the async channel is already allocated. -ENOMEM if memory allocation fails. Other negative values if ID allocation fails.
stratix10_svc_remove_async_client() #
int Remove an asynchronous client from the Stratix10 service channel.
Parameters
struct stratix10_svc_chan *chan: Pointer to the Stratix10 service channel structure.
Description
This function removes an asynchronous client associated with the given service channel. It checks if the channel and the asynchronous channel are valid, and then proceeds to decrement the reference count for the common asynchronous channel if applicable. If the reference count reaches zero, it destroys the job ID pool and deallocates the asynchronous client ID. For non-common asynchronous channels, it directly destroys the job ID pool, deallocates the asynchronous client ID, and frees the memory allocated for the asynchronous channel.
Return
0 on success, -EINVAL if the channel or asynchronous channel is invalid.
stratix10_svc_async_send() #
int Send an asynchronous message to the Stratix10 service
Parameters
struct stratix10_svc_chan *chan: Pointer to the service channel structurevoid *msg: Pointer to the message to be sentvoid **handler: Pointer to the handler for the asynchronous message used by caller for later reference.async_callback_t cb: Callback function to be called upon completionvoid *cb_arg: Argument to be passed to the callback function
Description
This function sends an asynchronous message to the SDM mailbox in EL3 secure firmware. It performs various checks and setups, including allocating a job ID, setting up the transaction ID and packaging it to El3 firmware. The function handles different commands by setting up the appropriate arguments for the SMC call. If the SMC call is successful, the handler is set up and the function returns 0. If the SMC call fails, appropriate error handling is performed along with cleanup of resources.
Return
0 on success, -EINVAL for invalid argument, -ENOMEM if memory is not available, -EAGAIN if EL3 firmware is busy, -EBADF if the message is rejected by EL3 firmware and -EIO on other errors from EL3 firmware.
stratix10_svc_async_poll() #
int Polls the status of an asynchronous transaction.
Parameters
struct stratix10_svc_chan *chan: Pointer to the service channel structure.void *tx_handle: Handle to the transaction being polled.struct stratix10_svc_cb_data *data: Pointer to the callback data structure.
Description
This function polls the status of an asynchronous transaction identified by the given transaction handle. It ensures that the necessary structures are initialized and valid before proceeding with the poll operation. The function sets up the necessary arguments for the SMC call, invokes the call, and prepares the response data if the call is successful. If the call fails, the function returns the error mapped to the SVC status error.
Return
0 on success, -EINVAL if any input parameter is invalid, -EAGAIN if the transaction is still in progress, -EPERM if the command is invalid, or other negative error codes on failure.
stratix10_svc_async_done() #
int Completes an asynchronous transaction.
Parameters
struct stratix10_svc_chan *chan: Pointer to the service channel structure.void *tx_handle: Handle to the transaction being completed.
Description
This function completes an asynchronous transaction identified by the given transaction handle. It ensures that the necessary structures are initialized and valid before proceeding with the completion operation. The function deallocates the transaction ID, frees the memory allocated for the handler, and removes the handler from the transaction list.
Return
0 on success, -EINVAL if any input parameter is invalid, or other negative error codes on failure.
stratix10_svc_free_channel() #
void free service channel
Parameters
struct stratix10_svc_chan *chan: service channel to be freed
Description
This function is used by service client to free a service channel.
stratix10_svc_send() #
int send a message data to the remote
Parameters
struct stratix10_svc_chan *chan: service channel assigned to the clientvoid *msg: message data to be sent, in the format of "struct stratix10_svc_client_msg"
Description
This function is used by service client to add a message to the service layer driver's queue for being sent to the secure world.
Return
0 for success, -ENOMEM or -ENOBUFS on error.
stratix10_svc_done() #
void complete service request transactions
Parameters
struct stratix10_svc_chan *chan: service channel assigned to the client
Description
This function should be called when client has finished its request or there is an error in the request process. It allows the service layer to stop the running thread to have maximize savings in kernel resources.
stratix10_svc_allocate_memory() #
void * allocate memory
Parameters
struct stratix10_svc_chan *chan: service channel assigned to the clientsize_t size: memory size requested by a specific service client
Description
Service layer allocates the requested number of bytes buffer from the memory pool, service client uses this function to get allocated buffers.
Return
address of allocated memory on success, or ERR_PTR() on error.
stratix10_svc_free_memory() #
void free allocated memory
Parameters
struct stratix10_svc_chan *chan: service channel assigned to the clientvoid *kaddr: memory to be freed
Description
This function is used by service client to free allocated buffers.
request_firmware API
Peios Kernel / Hardware and drivers / Driver development / Firmware loading
Peios: File-based firmware loading has an additional Peios signature check. The development profile defaults to logging (
kacs_fwsig=log);kacs_fwsig=enforcerequires PeiosTcb trust for that path. This does not cover the separateFW_UPLOADinterface. See Peios kernel behaviour.
You would typically load firmware and then load it into your device somehow. The typical firmware work flow is reflected below:
if(request_firmware(&fw_entry, $FIRMWARE, device) == 0)
copy_fw_to_device(fw_entry->data, fw_entry->size);
release_firmware(fw_entry);
Synchronous firmware requests #
Synchronous firmware requests will wait until the firmware is found or until an error is returned.
request_firmware #
request_firmware() #
int send firmware request and wait for it
Parameters
const struct firmware **firmware_p: pointer to firmware imageconst char *name: name of firmware filestruct device *device: device for which firmware is being loaded
Description
firmware_p will be used to return a firmware image by the name of name for device device.
Should be called from user context where sleeping is allowed.
name will be used as $FIRMWARE in the uevent environment and should be distinctive enough not to be confused with any other firmware image for this or any other device. It must not contain any ".." path components - "foo/bar..bin" is allowed, but "foo/../bar.bin" is not.
Caller must hold the reference count of device.
The function can be called safely inside device's suspend and resume callback.
firmware_request_nowarn #
firmware_request_nowarn() #
int request for an optional fw module
Parameters
const struct firmware **firmware: pointer to firmware imageconst char *name: name of firmware filestruct device *device: device for which firmware is being loaded
Description
This function is similar in behaviour to request_firmware(), except it
doesn't produce warning messages when the file is not found. The sysfs
fallback mechanism is enabled if direct filesystem lookup fails. However,
failures to find the firmware file with it are still suppressed. It is
therefore up to the driver to check for the return value of this call and to
decide when to inform the users of errors.
firmware_request_platform #
firmware_request_platform() #
int request firmware with platform-fw fallback
Parameters
const struct firmware **firmware: pointer to firmware imageconst char *name: name of firmware filestruct device *device: device for which firmware is being loaded
Description
This function is similar in behaviour to request_firmware, except that if direct filesystem lookup fails, it will fallback to looking for a copy of the requested firmware embedded in the platform's main (e.g. UEFI) firmware.
request_firmware_direct #
request_firmware_direct() #
int load firmware directly without usermode helper
Parameters
const struct firmware **firmware_p: pointer to firmware imageconst char *name: name of firmware filestruct device *device: device for which firmware is being loaded
Description
This function works pretty much like request_firmware(), but this doesn't
fall back to usermode helper even if the firmware couldn't be loaded
directly from fs. Hence it's useful for loading optional firmwares, which
aren't always present, without extra long timeouts of udev.
request_firmware_into_buf #
request_firmware_into_buf() #
int load firmware into a previously allocated buffer
Parameters
const struct firmware **firmware_p: pointer to firmware imageconst char *name: name of firmware filestruct device *device: device for which firmware is being loaded and DMA region allocatedvoid *buf: address of buffer to load firmware intosize_t size: size of buffer
Description
This function works pretty much like request_firmware(), but it doesn't
allocate a buffer to hold the firmware data. Instead, the firmware
is loaded directly into the buffer pointed to by buf and the firmware_p
data member is pointed at buf.
This function doesn't cache firmware either.
Asynchronous firmware requests #
Asynchronous firmware requests allow driver code to not have to wait until the firmware or an error is returned. Function callbacks are provided so that when the firmware or an error is found the driver is informed through the callback. request_firmware_nowait() cannot be called in atomic contexts.
request_firmware_nowait #
request_firmware_nowait() #
int asynchronous version of request_firmware
Parameters
struct module *module: module requesting the firmwarebool uevent: sends uevent to copy the firmware image if this flag is non-zero else the firmware copy must be done manually.const char *name: name of firmware filestruct device *device: device for which firmware is being loadedgfp_t gfp: allocation flagsvoid *context: will be passed over to cont, and fw may beNULLif firmware request fails.void (*cont)(const struct firmware *fw, void *context): function will be called asynchronously when the firmware request is over.
Description
Caller must hold the reference count of device.
- Asynchronous variant of
request_firmware()for user contexts:-
sleep for as small periods as possible since it may increase kernel boot time of built-in device drivers requesting firmware in their ->
probe()methods, if gfp is GFP_KERNEL. -
can't sleep at all if gfp is GFP_ATOMIC.
-
Special optimizations on reboot #
Some devices have an optimization in place to enable the firmware to be retained during system reboot. When such optimizations are used the driver author must ensure the firmware is still available on resume from suspend, this can be done with firmware_request_cache() instead of requesting for the firmware to be loaded.
firmware_request_cache() #
firmware_request_cache() #
int cache firmware for suspend so resume can use it
Parameters
struct device *device: device for which firmware should be cached forconst char *name: name of firmware file
Description
There are some devices with an optimization that enables the device to not
require loading firmware on system reboot. This optimization may still
require the firmware present on resume from suspend. This routine can be
used to ensure the firmware is present on resume from suspend in these
situations. This helper is not compatible with drivers which use
request_firmware_into_buf() or request_firmware_nowait() with no uevent set.
request firmware API expected driver use #
Once an API call returns you process the firmware and then release the firmware. For example if you used request_firmware() and it returns, the driver has the firmware image accessible in fw_entry->{data,size}. If something went wrong request_firmware() returns non-zero and fw_entry is set to NULL. Once your driver is done with processing the firmware it can call release_firmware(fw_entry) to release the firmware image and any related resource.