README 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. request_firmware() hotplug interface:
  2. ------------------------------------
  3. Copyright (C) 2003 Manuel Estrada Sainz
  4. Why:
  5. ---
  6. Today, the most extended way to use firmware in the Linux kernel is linking
  7. it statically in a header file. Which has political and technical issues:
  8. 1) Some firmware is not legal to redistribute.
  9. 2) The firmware occupies memory permanently, even though it often is just
  10. used once.
  11. 3) Some people, like the Debian crowd, don't consider some firmware free
  12. enough and remove entire drivers (e.g.: keyspan).
  13. High level behavior (mixed):
  14. ============================
  15. 1), kernel(driver):
  16. - calls request_firmware(&fw_entry, $FIRMWARE, device)
  17. - kernel searchs the fimware image with name $FIRMWARE directly
  18. in the below search path of root filesystem:
  19. User customized search path by module parameter 'path'[1]
  20. "/lib/firmware/updates/" UTS_RELEASE,
  21. "/lib/firmware/updates",
  22. "/lib/firmware/" UTS_RELEASE,
  23. "/lib/firmware"
  24. - If found, goto 7), else goto 2)
  25. [1], the 'path' is a string parameter which length should be less
  26. than 256, user should pass 'firmware_class.path=$CUSTOMIZED_PATH'
  27. if firmware_class is built in kernel(the general situation)
  28. 2), userspace:
  29. - /sys/class/firmware/xxx/{loading,data} appear.
  30. - hotplug gets called with a firmware identifier in $FIRMWARE
  31. and the usual hotplug environment.
  32. - hotplug: echo 1 > /sys/class/firmware/xxx/loading
  33. 3), kernel: Discard any previous partial load.
  34. 4), userspace:
  35. - hotplug: cat appropriate_firmware_image > \
  36. /sys/class/firmware/xxx/data
  37. 5), kernel: grows a buffer in PAGE_SIZE increments to hold the image as it
  38. comes in.
  39. 6), userspace:
  40. - hotplug: echo 0 > /sys/class/firmware/xxx/loading
  41. 7), kernel: request_firmware() returns and the driver has the firmware
  42. image in fw_entry->{data,size}. If something went wrong
  43. request_firmware() returns non-zero and fw_entry is set to
  44. NULL.
  45. 8), kernel(driver): Driver code calls release_firmware(fw_entry) releasing
  46. the firmware image and any related resource.
  47. High level behavior (driver code):
  48. ==================================
  49. if(request_firmware(&fw_entry, $FIRMWARE, device) == 0)
  50. copy_fw_to_device(fw_entry->data, fw_entry->size);
  51. release_firmware(fw_entry);
  52. Sample/simple hotplug script:
  53. ============================
  54. # Both $DEVPATH and $FIRMWARE are already provided in the environment.
  55. HOTPLUG_FW_DIR=/usr/lib/hotplug/firmware/
  56. echo 1 > /sys/$DEVPATH/loading
  57. cat $HOTPLUG_FW_DIR/$FIRMWARE > /sys/$DEVPATH/data
  58. echo 0 > /sys/$DEVPATH/loading
  59. Random notes:
  60. ============
  61. - "echo -1 > /sys/class/firmware/xxx/loading" will cancel the load at
  62. once and make request_firmware() return with error.
  63. - firmware_data_read() and firmware_loading_show() are just provided
  64. for testing and completeness, they are not called in normal use.
  65. - There is also /sys/class/firmware/timeout which holds a timeout in
  66. seconds for the whole load operation.
  67. - request_firmware_nowait() is also provided for convenience in
  68. user contexts to request firmware asynchronously, but can't be called
  69. in atomic contexts.
  70. about in-kernel persistence:
  71. ---------------------------
  72. Under some circumstances, as explained below, it would be interesting to keep
  73. firmware images in non-swappable kernel memory or even in the kernel image
  74. (probably within initramfs).
  75. Note that this functionality has not been implemented.
  76. - Why OPTIONAL in-kernel persistence may be a good idea sometimes:
  77. - If the device that needs the firmware is needed to access the
  78. filesystem. When upon some error the device has to be reset and the
  79. firmware reloaded, it won't be possible to get it from userspace.
  80. e.g.:
  81. - A diskless client with a network card that needs firmware.
  82. - The filesystem is stored in a disk behind an scsi device
  83. that needs firmware.
  84. - Replacing buggy DSDT/SSDT ACPI tables on boot.
  85. Note: this would require the persistent objects to be included
  86. within the kernel image, probably within initramfs.
  87. And the same device can be needed to access the filesystem or not depending
  88. on the setup, so I think that the choice on what firmware to make
  89. persistent should be left to userspace.
  90. about firmware cache:
  91. --------------------
  92. After firmware cache mechanism is introduced during system sleep,
  93. request_firmware can be called safely inside device's suspend and
  94. resume callback, and callers needn't cache the firmware by
  95. themselves any more for dealing with firmware loss during system
  96. resume.