drivers/base/firmware_loader/main.c
Source file repositories/reference/linux-study-clean/drivers/base/firmware_loader/main.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/base/firmware_loader/main.c- Extension
.c- Size
- 44500 bytes
- Lines
- 1746
- Domain
- Driver Families
- Bucket
- drivers/base
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/capability.hlinux/device.hlinux/kernel_read_file.hlinux/module.hlinux/init.hlinux/initrd.hlinux/timer.hlinux/vmalloc.hlinux/interrupt.hlinux/bitops.hlinux/mutex.hlinux/workqueue.hlinux/highmem.hlinux/firmware.hlinux/slab.hlinux/sched.hlinux/file.hlinux/list.hlinux/fs.hlinux/async.hlinux/pm.hlinux/suspend.hlinux/syscore_ops.hlinux/reboot.hlinux/security.hlinux/zstd.hlinux/xz.hgenerated/utsrelease.h../base.hfirmware.hfallback.hcrypto/sha2.h
Detected Declarations
struct firmware_cachestruct fw_cache_entrystruct fw_name_devmstruct firmware_workfunction fw_state_initfunction fw_state_waitfunction alloc_lookup_fw_privfunction __free_fw_privfunction free_fw_privfunction fw_is_paged_buffunction fw_free_paged_buffunction fw_grow_paged_buffunction fw_map_paged_buffunction fw_decompress_zstdfunction fw_decompress_xz_errorfunction fw_decompress_xz_singlefunction fw_decompress_xz_pagesfunction fw_decompress_xzfunction fw_get_filesystem_firmwarefunction firmware_free_datafunction fw_set_page_datafunction fw_name_devm_releasefunction fw_devm_matchfunction fw_cache_is_setupfunction fw_add_devm_namefunction fw_cache_is_setupfunction fw_add_devm_namefunction assign_fwfunction _request_firmware_preparefunction release_firmwarefunction fw_log_firmware_infofunction fw_log_firmware_infofunction request_firmwarefunction firmware_request_nowarnfunction request_firmware_directfunction firmware_request_platformfunction firmware_request_cachefunction request_firmware_into_buffunction request_partial_firmware_into_buffunction release_firmwarefunction firmware_work_freefunction request_firmware_work_funcfunction _request_firmware_nowaitfunction request_firmware_nowaitfunction firmware_request_nowait_nowarnfunction request_firmware_nowait_cancelfunction cache_firmwarefunction uncache_firmware
Annotated Snippet
struct firmware_cache {
/* firmware_buf instance will be added into the below list */
spinlock_t lock;
struct list_head head;
int state;
#ifdef CONFIG_FW_CACHE
/*
* Names of firmware images which have been cached successfully
* will be added into the below list so that device uncache
* helper can trace which firmware images have been cached
* before.
*/
spinlock_t name_lock;
struct list_head fw_names;
struct delayed_work work;
struct notifier_block pm_notify;
#endif
};
struct fw_cache_entry {
struct list_head list;
const char *name;
};
struct fw_name_devm {
unsigned long magic;
const char *name;
};
static inline struct fw_priv *to_fw_priv(struct kref *ref)
{
return container_of(ref, struct fw_priv, ref);
}
#define FW_LOADER_NO_CACHE 0
#define FW_LOADER_START_CACHE 1
/* fw_lock could be moved to 'struct fw_sysfs' but since it is just
* guarding for corner cases a global lock should be OK */
DEFINE_MUTEX(fw_lock);
struct firmware_cache fw_cache;
bool fw_load_abort_all;
void fw_state_init(struct fw_priv *fw_priv)
{
struct fw_state *fw_st = &fw_priv->fw_st;
init_completion(&fw_st->completion);
fw_st->status = FW_STATUS_UNKNOWN;
}
static inline int fw_state_wait(struct fw_priv *fw_priv)
{
return __fw_state_wait_common(fw_priv, MAX_SCHEDULE_TIMEOUT);
}
static void fw_cache_piggyback_on_request(struct fw_priv *fw_priv);
static struct fw_priv *__allocate_fw_priv(const char *fw_name,
struct firmware_cache *fwc,
void *dbuf,
size_t size,
size_t offset,
u32 opt_flags)
{
struct fw_priv *fw_priv;
/* For a partial read, the buffer must be preallocated. */
if ((opt_flags & FW_OPT_PARTIAL) && !dbuf)
return NULL;
/* Only partial reads are allowed to use an offset. */
if (offset != 0 && !(opt_flags & FW_OPT_PARTIAL))
return NULL;
fw_priv = kzalloc_obj(*fw_priv, GFP_ATOMIC);
if (!fw_priv)
return NULL;
fw_priv->fw_name = kstrdup_const(fw_name, GFP_ATOMIC);
if (!fw_priv->fw_name) {
kfree(fw_priv);
return NULL;
}
kref_init(&fw_priv->ref);
Annotation
- Immediate include surface: `linux/capability.h`, `linux/device.h`, `linux/kernel_read_file.h`, `linux/module.h`, `linux/init.h`, `linux/initrd.h`, `linux/timer.h`, `linux/vmalloc.h`.
- Detected declarations: `struct firmware_cache`, `struct fw_cache_entry`, `struct fw_name_devm`, `struct firmware_work`, `function fw_state_init`, `function fw_state_wait`, `function alloc_lookup_fw_priv`, `function __free_fw_priv`, `function free_fw_priv`, `function fw_is_paged_buf`.
- Atlas domain: Driver Families / drivers/base.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.