Documentation/driver-api/firmware/firmware_cache.rst GitHub 원문 ↗

Linux 6.18.37 · Driver API

Firmware cache

Suspend 전에 firmware를 memory에 cache해 resume 시 root filesystem lookup race를 피하는 조건과 생명주기를 설명합니다.

Source pathDocumentation/driver-api/firmware/firmware_cache.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약과 해설

firmware_cache.rst:1-51

Firmware cache는 suspend 전에 firmware를 memory에 확보해 resume callback에서 즉시 사용할 수 있게 합니다. Synchronous API 대부분과 `uevent=true`인 asynchronous request가 자동 cache 대상입니다.

Devres entry는 device lifetime 동안 남고, cache 구성 중 fallback timeout은 10초로 줄어듭니다. Non-uevent request는 suspend 때 종료되므로 caller가 자체 cache를 구현해야 합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 ==============
2 Firmware cache
3 ==============
4
5 When Linux resumes from suspend some device drivers require firmware lookups to
6 re-initialize devices. During resume there may be a period of time during which
7 firmware lookups are not possible, during this short period of time firmware
8 requests will fail. Time is of essence though, and delaying drivers to wait for
9 the root filesystem for firmware delays user experience with device
10 functionality. In order to support these requirements the firmware
11 infrastructure implements a firmware cache for device drivers for most API
12 calls, automatically behind the scenes.
13
14 The firmware cache makes using certain firmware API calls safe during a device
15 driver's suspend and resume callback. Users of these API calls needn't cache
16 the firmware by themselves for dealing with firmware loss during system resume.
17
18 The firmware cache works by requesting for firmware prior to suspend and
19 caching it in memory. Upon resume device drivers using the firmware API will
20 have access to the firmware immediately, without having to wait for the root
21 filesystem to mount or dealing with possible race issues with lookups as the
22 root filesystem mounts.
23
24 Some implementation details about the firmware cache setup:
25
26 * The firmware cache is setup by adding a devres entry for each device that
27 uses all synchronous call except :c:func:`request_firmware_into_buf`.
28
29 * If an asynchronous call is used the firmware cache is only set up for a
30 device if the second argument (uevent) to request_firmware_nowait() is
31 true. When uevent is true it requests that a kobject uevent be sent to
32 userspace for the firmware request through the sysfs fallback mechanism
33 if the firmware file is not found.
34
35 * If the firmware cache is determined to be needed as per the above two
36 criteria the firmware cache is setup by adding a devres entry for the
37 device making the firmware request.
38
39 * The firmware devres entry is maintained throughout the lifetime of the
40 device. This means that even if you release_firmware() the firmware cache
41 will still be used on resume from suspend.
42
43 * The timeout for the fallback mechanism is temporarily reduced to 10 seconds
44 as the firmware cache is set up during suspend, the timeout is set back to
45 the old value you had configured after the cache is set up.
46
47 * Upon suspend any pending non-uevent firmware requests are killed to avoid
48 stalling the kernel, this is done with kill_requests_without_uevent(). Kernel
49 calls requiring the non-uevent therefore need to implement their own firmware
50 cache mechanism but must not use the firmware API on suspend.
51
52

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

Firmware cache가 필요한 이유

1-12

문서 제목은 `Firmware cache`입니다.

Linux가 suspend에서 resume할 때 일부 device driver는 device를 다시 초기화하려고 firmware lookup을 수행해야 합니다. Resume 중에는 잠시 firmware lookup이 불가능할 수 있어 이 짧은 기간에 firmware request가 실패합니다.

하지만 시간은 중요합니다. Firmware를 얻기 위해 root filesystem을 기다리도록 driver를 지연하면 사용자가 device 기능을 다시 쓰기까지의 시간이 늘어납니다.

이 요구를 지원하기 위해 firmware infrastructure는 대부분의 firmware API call 뒤에서 자동으로 동작하는 device driver용 firmware cache를 구현합니다.

Suspend와 resume의 cache 생명주기

13-22

Firmware cache 덕분에 특정 firmware API call은 device driver의 suspend·resume callback 안에서도 안전하게 사용할 수 있습니다. 이 API 사용자는 system resume 때 firmware가 사라지는 상황에 대비해 firmware를 직접 cache할 필요가 없습니다.

Firmware cache는 suspend 전에 firmware를 request해 memory에 저장합니다. Resume하면 firmware API를 사용하는 device driver는 root filesystem mount를 기다리거나 mount 중 lookup race를 처리하지 않고 즉시 firmware에 접근할 수 있습니다.

Firmware cache 생명주기
Device가 firmware API 사용Suspend 전에 firmware requestFirmware를 memory cache에 보관System suspendResume callback에서 즉시 cache 접근Root filesystem mount와 독립적으로 device 재초기화

Suspend 전에 firmware를 확보해 resume 시 filesystem 의존성을 제거합니다.

Cache 설정 조건과 devres lifetime

23-41

Firmware cache 설정의 구현 세부 사항은 다음과 같습니다.

  • `request_firmware_into_buf()`를 제외한 모든 synchronous call을 사용하는 각 device에는 devres entry를 추가해 firmware cache를 설정합니다.
  • Asynchronous call을 사용할 때는 `request_firmware_nowait()`의 두 번째 argument인 `uevent`가 true인 경우에만 해당 device의 firmware cache를 설정합니다.
  • `uevent`가 true이면 firmware file을 찾지 못했을 때 sysfs fallback mechanism을 통해 firmware request용 kobject uevent를 userspace로 보내도록 요청합니다.
  • 위 두 기준으로 cache가 필요하다고 판단되면 firmware request를 수행한 device에 devres entry를 추가합니다.
  • Firmware devres entry는 device lifetime 전체에 걸쳐 유지됩니다. 따라서 `release_firmware()`를 호출해도 suspend에서 resume할 때 firmware cache를 계속 사용합니다.
Firmware API별 cache 설정
API 유형조건Automatic cache
Synchronousrequest_firmware_into_buf() 제외설정
Synchronousrequest_firmware_into_buf()미설정
Asynchronousrequest_firmware_nowait(), uevent=true설정
Asynchronousrequest_firmware_nowait(), uevent=false미설정

Call 방식과 uevent flag가 automatic cache 생성 여부를 결정합니다.

Suspend 중 timeout과 non-uevent request

42-51

Suspend 중 firmware cache를 설정하는 동안 fallback mechanism timeout을 임시로 10초로 줄입니다. Cache 설정이 끝나면 사용자가 구성했던 이전 timeout 값으로 되돌립니다.

Suspend할 때 kernel이 멈추지 않도록 pending 상태인 non-uevent firmware request를 모두 종료합니다. 이 작업은 `kill_requests_without_uevent()`가 수행합니다.

따라서 non-uevent가 필요한 kernel call은 자체 firmware cache mechanism을 구현해야 하며 suspend 중 firmware API를 사용해서는 안 됩니다.

Suspend 시 firmware request 처리
항목동작
Fallback timeoutCache 설정 중 10초로 임시 축소 후 원래 값 복원
Pending non-uevent requestkill_requests_without_uevent()로 종료
Non-uevent caller자체 cache 구현, suspend 중 firmware API 사용 금지

Cache 설정 중 timeout과 pending request 처리 규칙입니다.