drivers/firmware/microchip/mpfs-auto-update.c
Source file repositories/reference/linux-study-clean/drivers/firmware/microchip/mpfs-auto-update.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/firmware/microchip/mpfs-auto-update.c- Extension
.c- Size
- 15260 bytes
- Lines
- 470
- Domain
- Driver Families
- Bucket
- drivers/firmware
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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/cleanup.hlinux/debugfs.hlinux/firmware.hlinux/math.hlinux/module.hlinux/mtd/mtd.hlinux/platform_device.hlinux/sizes.hsoc/microchip/mpfs.h
Detected Declarations
struct mpfs_auto_update_privfunction mpfs_auto_update_is_bitstream_infofunction mpfs_auto_update_preparefunction mpfs_auto_update_cancelfunction mpfs_auto_update_poll_completefunction mpfs_auto_update_verify_imagefunction mpfs_auto_update_set_image_addressfunction mpfs_auto_update_write_bitstreamfunction mpfs_auto_update_writefunction mpfs_auto_update_availablefunction mpfs_auto_update_probefunction mpfs_auto_update_remove
Annotated Snippet
struct mpfs_auto_update_priv {
struct mpfs_sys_controller *sys_controller;
struct device *dev;
struct mtd_info *flash;
struct fw_upload *fw_uploader;
size_t size_per_bitstream;
bool cancel_request;
};
static bool mpfs_auto_update_is_bitstream_info(const u8 *data, u32 size)
{
if (size < 4)
return false;
if (data[0] == 0x4d && data[1] == 0x43 && data[2] == 0x48 && data[3] == 0x50)
return true;
return false;
}
static enum fw_upload_err mpfs_auto_update_prepare(struct fw_upload *fw_uploader, const u8 *data,
u32 size)
{
struct mpfs_auto_update_priv *priv = fw_uploader->dd_handle;
size_t erase_size = AUTO_UPDATE_DIRECTORY_SIZE;
/*
* Verifying the Golden Image is idealistic. It will be evaluated
* against the currently programmed image and thus may fail - due to
* either rollback protection (if its an older version than that in use)
* or if the version is the same as that of the in-use image.
* Extracting the information as to why a failure occurred is not
* currently possible due to limitations of the system controller
* driver. If those are fixed, verification of the Golden Image should
* be added here.
*/
erase_size = round_up(erase_size, (u64)priv->flash->erasesize);
/*
* We need to calculate if we have enough space in the flash for the
* new image.
* First, chop off the first 1 KiB as it's reserved for the directory.
* The 1 MiB reserved for design info needs to be ignored also.
* All that remains is carved into 3 & rounded down to the erasesize.
* If this is smaller than the image size, we abort.
* There's also no need to consume more than 20 MiB per image.
*/
priv->size_per_bitstream = priv->flash->size - SZ_1K - SZ_1M;
priv->size_per_bitstream = round_down(priv->size_per_bitstream / 3, erase_size);
if (priv->size_per_bitstream > 20 * SZ_1M)
priv->size_per_bitstream = 20 * SZ_1M;
if (priv->size_per_bitstream < size) {
dev_err(priv->dev,
"flash device has insufficient capacity to store this bitstream\n");
return FW_UPLOAD_ERR_INVALID_SIZE;
}
priv->cancel_request = false;
return FW_UPLOAD_ERR_NONE;
}
static void mpfs_auto_update_cancel(struct fw_upload *fw_uploader)
{
struct mpfs_auto_update_priv *priv = fw_uploader->dd_handle;
priv->cancel_request = true;
}
static enum fw_upload_err mpfs_auto_update_poll_complete(struct fw_upload *fw_uploader)
{
return FW_UPLOAD_ERR_NONE;
}
static int mpfs_auto_update_verify_image(struct fw_upload *fw_uploader)
{
struct mpfs_auto_update_priv *priv = fw_uploader->dd_handle;
u32 *response_msg __free(kfree) =
kzalloc(AUTO_UPDATE_FEATURE_RESP_SIZE * sizeof(*response_msg), GFP_KERNEL);
struct mpfs_mss_response *response __free(kfree) =
kzalloc_obj(struct mpfs_mss_response);
struct mpfs_mss_msg *message __free(kfree) =
kzalloc_obj(struct mpfs_mss_msg);
int ret;
if (!response_msg || !response || !message)
return -ENOMEM;
Annotation
- Immediate include surface: `linux/cleanup.h`, `linux/debugfs.h`, `linux/firmware.h`, `linux/math.h`, `linux/module.h`, `linux/mtd/mtd.h`, `linux/platform_device.h`, `linux/sizes.h`.
- Detected declarations: `struct mpfs_auto_update_priv`, `function mpfs_auto_update_is_bitstream_info`, `function mpfs_auto_update_prepare`, `function mpfs_auto_update_cancel`, `function mpfs_auto_update_poll_complete`, `function mpfs_auto_update_verify_image`, `function mpfs_auto_update_set_image_address`, `function mpfs_auto_update_write_bitstream`, `function mpfs_auto_update_write`, `function mpfs_auto_update_available`.
- Atlas domain: Driver Families / drivers/firmware.
- Implementation status: source 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.