lib/pldmfw/pldmfw.c
Source file repositories/reference/linux-study-clean/lib/pldmfw/pldmfw.c
File Facts
- System
- Linux kernel
- Corpus path
lib/pldmfw/pldmfw.c- Extension
.c- Size
- 24827 bytes
- Lines
- 893
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/unaligned.hlinux/crc32.hlinux/device.hlinux/firmware.hlinux/kernel.hlinux/module.hlinux/pci.hlinux/pldmfw.hlinux/slab.hlinux/uuid.hpldmfw_private.h
Detected Declarations
struct pldmfw_privstruct pldm_pci_record_idfunction pldm_check_fw_spacefunction pldm_move_fw_offsetfunction pldm_parse_headerfunction pldm_check_desc_tlv_lenfunction pldm_parse_desc_tlvsfunction pldm_for_each_desc_tlvfunction pldm_parse_one_recordfunction pldm_parse_recordsfunction pldm_for_each_recordfunction pldm_parse_componentsfunction pldm_for_each_componentfunction pldm_verify_header_crcfunction pldmfw_free_privfunction list_for_each_entry_safefunction list_for_each_entry_safefunction pldm_parse_imagefunction pldmfw_op_pci_match_recordfunction list_for_each_entryfunction pldm_find_matching_recordfunction list_for_each_entryfunction pldm_send_package_datafunction pldm_send_component_tablesfunction list_for_each_entryfunction pldm_flash_componentsfunction list_for_each_entryfunction pldm_finalize_updatefunction pldmfw_flash_imageexport pldmfw_op_pci_match_recordexport pldmfw_flash_image
Annotated Snippet
struct pldmfw_priv {
struct pldmfw *context;
const struct firmware *fw;
/* current offset of firmware image */
size_t offset;
struct list_head records;
struct list_head components;
/* PLDM Firmware Package Header */
const struct __pldm_header *header;
u16 total_header_size;
/* length of the component bitmap */
u16 component_bitmap_len;
u16 bitmap_size;
/* Start of the component image information */
u16 component_count;
const u8 *component_start;
/* Start pf the firmware device id records */
const u8 *record_start;
u8 record_count;
/* The CRC at the end of the package header */
u32 header_crc;
struct pldmfw_record *matching_record;
};
/**
* pldm_check_fw_space - Verify that the firmware image has space left
* @data: pointer to private data
* @offset: offset to start from
* @length: length to check for
*
* Verify that the firmware data can hold a chunk of bytes with the specified
* offset and length.
*
* Returns: zero on success, or -EFAULT if the image does not have enough
* space left to fit the expected length.
*/
static int
pldm_check_fw_space(struct pldmfw_priv *data, size_t offset, size_t length)
{
size_t expected_size = offset + length;
struct device *dev = data->context->dev;
if (data->fw->size < expected_size) {
dev_dbg(dev, "Firmware file size smaller than expected. Got %zu bytes, needed %zu bytes\n",
data->fw->size, expected_size);
return -EFAULT;
}
return 0;
}
/**
* pldm_move_fw_offset - Move the current firmware offset forward
* @data: pointer to private data
* @bytes_to_move: number of bytes to move the offset forward by
*
* Check that there is enough space past the current offset, and then move the
* offset forward by this amount.
*
* Returns: zero on success, or -EFAULT if the image is too small to fit the
* expected length.
*/
static int
pldm_move_fw_offset(struct pldmfw_priv *data, size_t bytes_to_move)
{
int err;
err = pldm_check_fw_space(data, data->offset, bytes_to_move);
if (err)
return err;
data->offset += bytes_to_move;
return 0;
}
/**
* pldm_parse_header - Validate and extract details about the PLDM header
* @data: pointer to private data
*
* Performs initial basic verification of the PLDM image, up to the first
* firmware record.
Annotation
- Immediate include surface: `linux/unaligned.h`, `linux/crc32.h`, `linux/device.h`, `linux/firmware.h`, `linux/kernel.h`, `linux/module.h`, `linux/pci.h`, `linux/pldmfw.h`.
- Detected declarations: `struct pldmfw_priv`, `struct pldm_pci_record_id`, `function pldm_check_fw_space`, `function pldm_move_fw_offset`, `function pldm_parse_header`, `function pldm_check_desc_tlv_len`, `function pldm_parse_desc_tlvs`, `function pldm_for_each_desc_tlv`, `function pldm_parse_one_record`, `function pldm_parse_records`.
- Atlas domain: Kernel Services / lib.
- Implementation status: integration implementation candidate.
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.