| /* SPDX-License-Identifier: GPL-2.0-only */ |
| /* |
| * GXP firmware loading management. |
| * |
| * Copyright (C) 2023 Google LLC |
| */ |
| |
| #ifndef __GXP_FIRMWARE_LOADER_H_ |
| #define __GXP_FIRMWARE_LOADER_H_ |
| |
| #include <gcip/gcip-image-config.h> |
| |
| #include "gxp-config.h" |
| #include "gxp-internal.h" |
| |
| struct gxp_firmware_loader_manager { |
| const struct firmware *core_firmware[GXP_NUM_CORES]; |
| char *core_firmware_name; |
| /* |
| * Cached core 0 firmware image config, for easier fetching config entries. |
| * Not a pointer to the firmware buffer because we want to forcely change the |
| * privilege level to NS. |
| * Only valid on the firmware loaded. |
| */ |
| struct gcip_image_config core_img_cfg; |
| #if GXP_HAS_MCU |
| const struct firmware *mcu_firmware; |
| char *mcu_firmware_name; |
| #endif |
| bool is_loaded; |
| /* Protects above fields */ |
| struct mutex lock; |
| }; |
| |
| /* |
| * Initializes the firmware loader subsystem. |
| */ |
| int gxp_firmware_loader_init(struct gxp_dev *gxp); |
| |
| /* |
| * Tears down the firmware loader subsystem. |
| */ |
| void gxp_firmware_loader_destroy(struct gxp_dev *gxp); |
| |
| /* |
| * Requests and loads all firmware only if firmware is not loaded. |
| * |
| * Returns 0 on success, a negative errno on failure. |
| */ |
| int gxp_firmware_loader_load_if_needed(struct gxp_dev *gxp); |
| |
| /* |
| * Unloads firmware. |
| */ |
| void gxp_firmware_loader_unload(struct gxp_dev *gxp); |
| |
| /* |
| * Returns a copied core firmware name prefix, the caller needs to release it by |
| * kfree. |
| */ |
| char *gxp_firmware_loader_get_core_fw_name(struct gxp_dev *gxp); |
| |
| /* |
| * Set the core firmware name prefix to be requested in |
| * `gxp_firmware_loader_load_if_needed()`. |
| * It's safe for caller to release @fw_name after calling this function. |
| */ |
| void gxp_firmware_loader_set_core_fw_name(struct gxp_dev *gxp, |
| const char *fw_name); |
| /* |
| * |
| * Returns a copied MCU firmware name, the caller needs to release it by |
| * kfree. |
| */ |
| char *gxp_firmware_loader_get_mcu_fw_name(struct gxp_dev *gxp); |
| |
| /* |
| * Set the MCU firmware name to be requested in |
| * `gxp_firmware_loader_load_if_needed()`. |
| * It's safe for caller to release @fw_name after calling this function. |
| */ |
| void gxp_firmware_loader_set_mcu_fw_name(struct gxp_dev *gxp, |
| const char *fw_name); |
| |
| #endif /* __GXP_FIRMWARE_LOADER_H_ */ |