README 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. "/lib/firmware/updates/" UTS_RELEASE,
  20. "/lib/firmware/updates",
  21. "/lib/firmware/" UTS_RELEASE,
  22. "/lib/firmware"
  23. - If found, goto 7), else goto 2)
  24. 2), userspace:
  25. - /sys/class/firmware/xxx/{loading,data} appear.
  26. - hotplug gets called with a firmware identifier in $FIRMWARE
  27. and the usual hotplug environment.
  28. - hotplug: echo 1 > /sys/class/firmware/xxx/loading
  29. 3), kernel: Discard any previous partial load.
  30. 4), userspace:
  31. - hotplug: cat appropriate_firmware_image > \
  32. /sys/class/firmware/xxx/data
  33. 5), kernel: grows a buffer in PAGE_SIZE increments to hold the image as it
  34. comes in.
  35. 6), userspace:
  36. - hotplug: echo 0 > /sys/class/firmware/xxx/loading
  37. 7), kernel: request_firmware() returns and the driver has the firmware
  38. image in fw_entry->{data,size}. If something went wrong
  39. request_firmware() returns non-zero and fw_entry is set to
  40. NULL.
  41. 8), kernel(driver): Driver code calls release_firmware(fw_entry) releasing
  42. the firmware image and any related resource.
  43. High level behavior (driver code):
  44. ==================================
  45. if(request_firmware(&fw_entry, $FIRMWARE, device) == 0)
  46. copy_fw_to_device(fw_entry->data, fw_entry->size);
  47. release(fw_entry);
  48. Sample/simple hotplug script:
  49. ============================
  50. # Both $DEVPATH and $FIRMWARE are already provided in the environment.
  51. HOTPLUG_FW_DIR=/usr/lib/hotplug/firmware/
  52. echo 1 > /sys/$DEVPATH/loading
  53. cat $HOTPLUG_FW_DIR/$FIRMWARE > /sysfs/$DEVPATH/data
  54. echo 0 > /sys/$DEVPATH/loading
  55. Random notes:
  56. ============
  57. - "echo -1 > /sys/class/firmware/xxx/loading" will cancel the load at
  58. once and make request_firmware() return with error.
  59. - firmware_data_read() and firmware_loading_show() are just provided
  60. for testing and completeness, they are not called in normal use.
  61. - There is also /sys/class/firmware/timeout which holds a timeout in
  62. seconds for the whole load operation.
  63. - request_firmware_nowait() is also provided for convenience in
  64. user contexts to request firmware asynchronously, but can't be called
  65. in atomic contexts.
  66. about in-kernel persistence:
  67. ---------------------------
  68. Under some circumstances, as explained below, it would be interesting to keep
  69. firmware images in non-swappable kernel memory or even in the kernel image
  70. (probably within initramfs).
  71. Note that this functionality has not been implemented.
  72. - Why OPTIONAL in-kernel persistence may be a good idea sometimes:
  73. - If the device that needs the firmware is needed to access the
  74. filesystem. When upon some error the device has to be reset and the
  75. firmware reloaded, it won't be possible to get it from userspace.
  76. e.g.:
  77. - A diskless client with a network card that needs firmware.
  78. - The filesystem is stored in a disk behind an scsi device
  79. that needs firmware.
  80. - Replacing buggy DSDT/SSDT ACPI tables on boot.
  81. Note: this would require the persistent objects to be included
  82. within the kernel image, probably within initramfs.
  83. And the same device can be needed to access the filesystem or not depending
  84. on the setup, so I think that the choice on what firmware to make
  85. persistent should be left to userspace.