README 3.6 KB

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