summaryrefslogtreecommitdiff
path: root/gxp-firmware-loader.h
blob: d081af2c751db905513d953cf36c0d93d91a0c49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* 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_ */