1113ccc38SLuis R. Rodriguez============== 2113ccc38SLuis R. RodriguezFirmware cache 3113ccc38SLuis R. Rodriguez============== 4113ccc38SLuis R. Rodriguez 5113ccc38SLuis R. RodriguezWhen Linux resumes from suspend some device drivers require firmware lookups to 6113ccc38SLuis R. Rodriguezre-initialize devices. During resume there may be a period of time during which 7113ccc38SLuis R. Rodriguezfirmware lookups are not possible, during this short period of time firmware 8113ccc38SLuis R. Rodriguezrequests will fail. Time is of essence though, and delaying drivers to wait for 9113ccc38SLuis R. Rodriguezthe root filesystem for firmware delays user experience with device 10113ccc38SLuis R. Rodriguezfunctionality. In order to support these requirements the firmware 11113ccc38SLuis R. Rodriguezinfrastructure implements a firmware cache for device drivers for most API 12113ccc38SLuis R. Rodriguezcalls, automatically behind the scenes. 13113ccc38SLuis R. Rodriguez 14113ccc38SLuis R. RodriguezThe firmware cache makes using certain firmware API calls safe during a device 15113ccc38SLuis R. Rodriguezdriver's suspend and resume callback. Users of these API calls needn't cache 16113ccc38SLuis R. Rodriguezthe firmware by themselves for dealing with firmware loss during system resume. 17113ccc38SLuis R. Rodriguez 18113ccc38SLuis R. RodriguezThe firmware cache works by requesting for firmware prior to suspend and 19113ccc38SLuis R. Rodriguezcaching it in memory. Upon resume device drivers using the firmware API will 20113ccc38SLuis R. Rodriguezhave access to the firmware immediately, without having to wait for the root 21113ccc38SLuis R. Rodriguezfilesystem to mount or dealing with possible race issues with lookups as the 22113ccc38SLuis R. Rodriguezroot filesystem mounts. 23113ccc38SLuis R. Rodriguez 24113ccc38SLuis R. RodriguezSome implementation details about the firmware cache setup: 25113ccc38SLuis R. Rodriguez 26113ccc38SLuis R. Rodriguez* The firmware cache is setup by adding a devres entry for each device that 27113ccc38SLuis R. Rodriguez uses all synchronous call except :c:func:`request_firmware_into_buf`. 28113ccc38SLuis R. Rodriguez 29113ccc38SLuis R. Rodriguez* If an asynchronous call is used the firmware cache is only set up for a 30*20b33f84SRandy Dunlap device if the second argument (uevent) to request_firmware_nowait() is 31113ccc38SLuis R. Rodriguez true. When uevent is true it requests that a kobject uevent be sent to 324fde24d4SLuis R. Rodriguez userspace for the firmware request through the sysfs fallback mechanism 334fde24d4SLuis R. Rodriguez if the firmware file is not found. 34113ccc38SLuis R. Rodriguez 35113ccc38SLuis R. Rodriguez* If the firmware cache is determined to be needed as per the above two 36113ccc38SLuis R. Rodriguez criteria the firmware cache is setup by adding a devres entry for the 37113ccc38SLuis R. Rodriguez device making the firmware request. 38113ccc38SLuis R. Rodriguez 39113ccc38SLuis R. Rodriguez* The firmware devres entry is maintained throughout the lifetime of the 40113ccc38SLuis R. Rodriguez device. This means that even if you release_firmware() the firmware cache 41113ccc38SLuis R. Rodriguez will still be used on resume from suspend. 42113ccc38SLuis R. Rodriguez 43113ccc38SLuis R. Rodriguez* The timeout for the fallback mechanism is temporarily reduced to 10 seconds 44113ccc38SLuis R. Rodriguez as the firmware cache is set up during suspend, the timeout is set back to 45113ccc38SLuis R. Rodriguez the old value you had configured after the cache is set up. 46113ccc38SLuis R. Rodriguez 47113ccc38SLuis R. Rodriguez* Upon suspend any pending non-uevent firmware requests are killed to avoid 48113ccc38SLuis R. Rodriguez stalling the kernel, this is done with kill_requests_without_uevent(). Kernel 49113ccc38SLuis R. Rodriguez calls requiring the non-uevent therefore need to implement their own firmware 50113ccc38SLuis R. Rodriguez cache mechanism but must not use the firmware API on suspend. 51113ccc38SLuis R. Rodriguez 52